NIHVIVO-874 Merge 5357 from the branch.
This commit is contained in:
parent
d565eca6b6
commit
60f6f401f3
9 changed files with 149 additions and 47 deletions
|
@ -12,11 +12,12 @@ import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
* Adjust any individual that has a thumbnail with no main image.
|
* Adjust any individual that has a thumbnail with no main image.
|
||||||
*/
|
*/
|
||||||
public class AllThumbsAdjuster extends FsuScanner {
|
public class AllThumbsAdjuster extends FsuScanner {
|
||||||
protected final File imageDirectory;
|
private ImageDirectoryWithBackup imageDirectoryWithBackup;
|
||||||
|
|
||||||
public AllThumbsAdjuster(FSUController controller) {
|
public AllThumbsAdjuster(FSUController controller) {
|
||||||
super(controller);
|
super(controller);
|
||||||
this.imageDirectory = controller.getImageDirectory();
|
this.imageDirectoryWithBackup = controller
|
||||||
|
.getImageDirectoryWithBackup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,8 +57,9 @@ public class AllThumbsAdjuster extends FsuScanner {
|
||||||
+ "' to match the thumbnail at '" + thumbFilename + "'");
|
+ "' to match the thumbnail at '" + thumbFilename + "'");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File thumbFile = new File(imageDirectory, thumbFilename);
|
File thumbFile = imageDirectoryWithBackup
|
||||||
File mainFile = new File(imageDirectory, mainFilename);
|
.getExistingFile(thumbFilename);
|
||||||
|
File mainFile = imageDirectoryWithBackup.getNewfile(mainFilename);
|
||||||
mainFile = checkNameConflicts(mainFile);
|
mainFile = checkNameConflicts(mainFile);
|
||||||
FileUtil.copyFile(thumbFile, mainFile);
|
FileUtil.copyFile(thumbFile, mainFile);
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,12 @@ import com.hp.hpl.jena.rdf.model.Statement;
|
||||||
* don't actually exist.
|
* don't actually exist.
|
||||||
*/
|
*/
|
||||||
public class DeadEndPropertyRemover extends FsuScanner {
|
public class DeadEndPropertyRemover extends FsuScanner {
|
||||||
protected final File imageDirectory;
|
private ImageDirectoryWithBackup imageDirectoryWithBackup;
|
||||||
|
|
||||||
public DeadEndPropertyRemover(FSUController controller) {
|
public DeadEndPropertyRemover(FSUController controller) {
|
||||||
super(controller);
|
super(controller);
|
||||||
this.imageDirectory = controller.getImageDirectory();
|
this.imageDirectoryWithBackup = controller
|
||||||
|
.getImageDirectoryWithBackup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,10 +60,12 @@ public class DeadEndPropertyRemover extends FsuScanner {
|
||||||
RDFNode node = stmt.getObject();
|
RDFNode node = stmt.getObject();
|
||||||
if (node.isLiteral()) {
|
if (node.isLiteral()) {
|
||||||
String filename = ((Literal) node).getString();
|
String filename = ((Literal) node).getString();
|
||||||
File file = new File(imageDirectory, filename);
|
File file = imageDirectoryWithBackup.getExistingFile(filename);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
updateLog.warn(resource, "removing link to " + label + " '"
|
updateLog.warn(
|
||||||
+ filename + "': file does not exist at '"
|
resource,
|
||||||
|
"removing link to " + label + " '" + filename
|
||||||
|
+ "': file does not exist at '"
|
||||||
+ file.getAbsolutePath() + "'.");
|
+ file.getAbsolutePath() + "'.");
|
||||||
model.remove(stmt);
|
model.remove(stmt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@ public interface FSUController {
|
||||||
/** The update log. */
|
/** The update log. */
|
||||||
FSULog getUpdateLog();
|
FSULog getUpdateLog();
|
||||||
|
|
||||||
/** The directory where the old-style images were stored. */
|
/** The place to find or to create image files. */
|
||||||
File getImageDirectory();
|
ImageDirectoryWithBackup getImageDirectoryWithBackup();
|
||||||
|
|
||||||
/** The file storage system. */
|
/** The file storage system. */
|
||||||
FileStorage getFileStorage();
|
FileStorage getFileStorage();
|
||||||
|
|
|
@ -106,18 +106,21 @@ public class FileStorageUpdater implements FSUController {
|
||||||
|
|
||||||
private final FileStorage fileStorage;
|
private final FileStorage fileStorage;
|
||||||
private final FileModelHelper fileModelHelper;
|
private final FileModelHelper fileModelHelper;
|
||||||
private final File imageDirectory;
|
private final ImageDirectoryWithBackup imageDirectoryWithBackup;
|
||||||
private final File upgradeDirectory;
|
private final File upgradeDirectory;
|
||||||
|
|
||||||
private FSULog updateLog;
|
private FSULog updateLog;
|
||||||
|
|
||||||
public FileStorageUpdater(WebappDaoFactory wadf, Model model,
|
public FileStorageUpdater(WebappDaoFactory wadf, Model model,
|
||||||
FileStorage fileStorage, File uploadDirectory) {
|
FileStorage fileStorage, File uploadDirectory,
|
||||||
|
File webappImageDirectory) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.fileStorage = fileStorage;
|
this.fileStorage = fileStorage;
|
||||||
this.fileModelHelper = new FileModelHelper(wadf);
|
this.fileModelHelper = new FileModelHelper(wadf);
|
||||||
this.imageDirectory = new File(uploadDirectory, "images");
|
|
||||||
this.upgradeDirectory = new File(uploadDirectory, "upgrade");
|
this.upgradeDirectory = new File(uploadDirectory, "upgrade");
|
||||||
|
|
||||||
|
this.imageDirectoryWithBackup = new ImageDirectoryWithBackup(new File(
|
||||||
|
uploadDirectory, "images"), webappImageDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -256,9 +259,8 @@ public class FileStorageUpdater implements FSUController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getImageDirectory() {
|
public ImageDirectoryWithBackup getImageDirectoryWithBackup() {
|
||||||
return this.imageDirectory;
|
return this.imageDirectoryWithBackup;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -12,13 +12,15 @@ import java.util.Collection;
|
||||||
* referenced.
|
* referenced.
|
||||||
*/
|
*/
|
||||||
public class ImageDirectoryCleaner extends FsuScanner {
|
public class ImageDirectoryCleaner extends FsuScanner {
|
||||||
protected final File imageDirectory;
|
private final ImageDirectoryWithBackup imageDirectoryWithBackup;
|
||||||
protected final File translatedDirectory;
|
protected final File translatedDirectory;
|
||||||
protected final File unreferencedDirectory;
|
protected final File unreferencedDirectory;
|
||||||
|
|
||||||
public ImageDirectoryCleaner(FSUController controller) {
|
public ImageDirectoryCleaner(FSUController controller) {
|
||||||
super(controller);
|
super(controller);
|
||||||
this.imageDirectory = controller.getImageDirectory();
|
this.imageDirectoryWithBackup = controller
|
||||||
|
.getImageDirectoryWithBackup();
|
||||||
|
|
||||||
this.translatedDirectory = controller.getTranslatedDirectory();
|
this.translatedDirectory = controller.getTranslatedDirectory();
|
||||||
this.unreferencedDirectory = controller.getUnreferencedDirectory();
|
this.unreferencedDirectory = controller.getUnreferencedDirectory();
|
||||||
}
|
}
|
||||||
|
@ -33,7 +35,8 @@ public class ImageDirectoryCleaner extends FsuScanner {
|
||||||
|
|
||||||
updateLog.section("Cleaning the old image directory of "
|
updateLog.section("Cleaning the old image directory of "
|
||||||
+ "files that were not referenced.");
|
+ "files that were not referenced.");
|
||||||
removeRemainingFiles(imageDirectory);
|
removeRemainingFiles(imageDirectoryWithBackup
|
||||||
|
.getPrimaryImageDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,9 +44,11 @@ public class ImageDirectoryCleaner extends FsuScanner {
|
||||||
*/
|
*/
|
||||||
private void removeTranslatedFiles(Collection<String> translatedFiles) {
|
private void removeTranslatedFiles(Collection<String> translatedFiles) {
|
||||||
for (String path : translatedFiles) {
|
for (String path : translatedFiles) {
|
||||||
|
File oldFile = new File(
|
||||||
|
imageDirectoryWithBackup.getPrimaryImageDirectory(), path);
|
||||||
|
if (oldFile.exists()) {
|
||||||
updateLog.log("moving image file '" + path
|
updateLog.log("moving image file '" + path
|
||||||
+ "' to the 'translated' directory.");
|
+ "' to the 'translated' directory.");
|
||||||
File oldFile = new File(imageDirectory, path);
|
|
||||||
File deletedFile = new File(translatedDirectory, path);
|
File deletedFile = new File(translatedDirectory, path);
|
||||||
try {
|
try {
|
||||||
FileUtil.moveFile(oldFile, deletedFile);
|
FileUtil.moveFile(oldFile, deletedFile);
|
||||||
|
@ -51,6 +56,11 @@ public class ImageDirectoryCleaner extends FsuScanner {
|
||||||
updateLog.error("Failed to move translated file '"
|
updateLog.error("Failed to move translated file '"
|
||||||
+ oldFile.getAbsolutePath() + "'");
|
+ oldFile.getAbsolutePath() + "'");
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
updateLog.log("Not moving image file '" + path
|
||||||
|
+ "' to the 'translated' directory -- "
|
||||||
|
+ "found it in the backup directory.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +83,8 @@ public class ImageDirectoryCleaner extends FsuScanner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
updateLog.error("Failed to clean images directory '"
|
updateLog.error(
|
||||||
|
"Failed to clean images directory '"
|
||||||
+ directory.getAbsolutePath() + "'", e);
|
+ directory.getAbsolutePath() + "'", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,8 +100,9 @@ public class ImageDirectoryCleaner extends FsuScanner {
|
||||||
File newFile = new File(targetDirectory, file.getName());
|
File newFile = new File(targetDirectory, file.getName());
|
||||||
FileUtil.moveFile(file, newFile);
|
FileUtil.moveFile(file, newFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
updateLog.error("Can't move unreferenced file '"
|
updateLog.error(
|
||||||
+ file.getAbsolutePath() + "'", e);
|
"Can't move unreferenced file '" + file.getAbsolutePath()
|
||||||
|
+ "'", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +111,8 @@ public class ImageDirectoryCleaner extends FsuScanner {
|
||||||
* corresponding directory in the "unreferenced" area.
|
* corresponding directory in the "unreferenced" area.
|
||||||
*/
|
*/
|
||||||
private File makeCorrespondingDirectory(File directory) throws IOException {
|
private File makeCorrespondingDirectory(File directory) throws IOException {
|
||||||
String imagesPath = imageDirectory.getAbsolutePath();
|
String imagesPath = imageDirectoryWithBackup.getPrimaryImageDirectory()
|
||||||
|
.getAbsolutePath();
|
||||||
String thisPath = directory.getAbsolutePath();
|
String thisPath = directory.getAbsolutePath();
|
||||||
|
|
||||||
if (!thisPath.startsWith(imagesPath)) {
|
if (!thisPath.startsWith(imagesPath)) {
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.filestorage.updater;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A way to look for files in TOMCAT_WEBAPP/vivo/images, if they are not found
|
||||||
|
* in upload.directory/images.
|
||||||
|
*/
|
||||||
|
public class ImageDirectoryWithBackup {
|
||||||
|
private static final Log log = LogFactory
|
||||||
|
.getLog(ImageDirectoryWithBackup.class);
|
||||||
|
|
||||||
|
/** The primary image directory, where we do most of the manipulation. */
|
||||||
|
private final File uploadImageDirectory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If we are looking for a file and don't find it in the primary directory,
|
||||||
|
* look for it here.
|
||||||
|
*/
|
||||||
|
private final File webappImageDirectory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Be careful! webappImageDirectory may be null.
|
||||||
|
*/
|
||||||
|
public ImageDirectoryWithBackup(File uploadImageDirectory,
|
||||||
|
File webappImageDirectory) {
|
||||||
|
this.uploadImageDirectory = uploadImageDirectory;
|
||||||
|
this.webappImageDirectory = webappImageDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When looking to read a file, start by looking in the
|
||||||
|
* {@link #uploadImageDirectory}.
|
||||||
|
*
|
||||||
|
* If the file isn't found there, look in the {@link #webappImageDirectory}
|
||||||
|
* as a fallback.
|
||||||
|
*
|
||||||
|
* If not there either, return the pointer to the nonexistent file in the
|
||||||
|
* {@link #uploadImageDirectory}.
|
||||||
|
*/
|
||||||
|
File getExistingFile(String relativePath) {
|
||||||
|
File file1 = new File(uploadImageDirectory, relativePath);
|
||||||
|
if (file1.exists()) {
|
||||||
|
log.trace("Found file: " + file1.getAbsolutePath());
|
||||||
|
return file1;
|
||||||
|
}
|
||||||
|
if (webappImageDirectory != null) {
|
||||||
|
File file2 = new File(webappImageDirectory, relativePath);
|
||||||
|
if (file2.exists()) {
|
||||||
|
log.trace("Found file: " + file2.getAbsolutePath());
|
||||||
|
return file2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.trace("Didn't find file: " + file1.getAbsolutePath());
|
||||||
|
return file1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New files will always be created in the primary directory.
|
||||||
|
*/
|
||||||
|
File getNewfile(String relativePath) {
|
||||||
|
return new File(uploadImageDirectory, relativePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* You can get a direct reference to the primary image directory, but it
|
||||||
|
* should only be used for directory-base operations, like final cleanup.
|
||||||
|
*/
|
||||||
|
public File getPrimaryImageDirectory() {
|
||||||
|
return uploadImageDirectory;
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,13 +26,14 @@ import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorage;
|
||||||
* yet, in case someone else is referring to them also.
|
* yet, in case someone else is referring to them also.
|
||||||
*/
|
*/
|
||||||
public class ImageSchemaTranslater extends FsuScanner {
|
public class ImageSchemaTranslater extends FsuScanner {
|
||||||
protected final File imageDirectory;
|
private final ImageDirectoryWithBackup imageDirectoryWithBackup;
|
||||||
protected final FileModelHelper fileModelHelper;
|
protected final FileModelHelper fileModelHelper;
|
||||||
protected final FileStorage fileStorage;
|
protected final FileStorage fileStorage;
|
||||||
|
|
||||||
public ImageSchemaTranslater(FSUController controller) {
|
public ImageSchemaTranslater(FSUController controller) {
|
||||||
super(controller);
|
super(controller);
|
||||||
this.imageDirectory = controller.getImageDirectory();
|
this.imageDirectoryWithBackup = controller
|
||||||
|
.getImageDirectoryWithBackup();
|
||||||
this.fileStorage = controller.getFileStorage();
|
this.fileStorage = controller.getFileStorage();
|
||||||
this.fileModelHelper = controller.getFileModelHelper();
|
this.fileModelHelper = controller.getFileModelHelper();
|
||||||
}
|
}
|
||||||
|
@ -126,7 +127,7 @@ public class ImageSchemaTranslater extends FsuScanner {
|
||||||
*/
|
*/
|
||||||
private Individual translateFile(Resource resource, String path,
|
private Individual translateFile(Resource resource, String path,
|
||||||
String label) {
|
String label) {
|
||||||
File oldFile = new File(imageDirectory, path);
|
File oldFile = imageDirectoryWithBackup.getExistingFile(path);
|
||||||
String filename = getSimpleFilename(path);
|
String filename = getSimpleFilename(path);
|
||||||
String mimeType = guessMimeType(resource, filename);
|
String mimeType = guessMimeType(resource, filename);
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,12 @@ import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
* Adjust any individual that has a main image but no thumbnail.
|
* Adjust any individual that has a main image but no thumbnail.
|
||||||
*/
|
*/
|
||||||
public class NoThumbsAdjuster extends FsuScanner {
|
public class NoThumbsAdjuster extends FsuScanner {
|
||||||
protected final File imageDirectory;
|
private ImageDirectoryWithBackup imageDirectoryWithBackup;
|
||||||
|
|
||||||
public NoThumbsAdjuster(FSUController controller) {
|
public NoThumbsAdjuster(FSUController controller) {
|
||||||
super(controller);
|
super(controller);
|
||||||
this.imageDirectory = controller.getImageDirectory();
|
this.imageDirectoryWithBackup = controller
|
||||||
|
.getImageDirectoryWithBackup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,8 +60,8 @@ public class NoThumbsAdjuster extends FsuScanner {
|
||||||
updateLog.log(resource, "creating a thumbnail at '" + thumbFilename
|
updateLog.log(resource, "creating a thumbnail at '" + thumbFilename
|
||||||
+ "' from the main image at '" + mainFilename + "'");
|
+ "' from the main image at '" + mainFilename + "'");
|
||||||
|
|
||||||
File mainFile = new File(imageDirectory, mainFilename);
|
File mainFile = imageDirectoryWithBackup.getExistingFile(mainFilename);
|
||||||
File thumbFile = new File(imageDirectory, thumbFilename);
|
File thumbFile = imageDirectoryWithBackup.getNewfile(thumbFilename);
|
||||||
thumbFile = checkNameConflicts(thumbFile);
|
thumbFile = checkNameConflicts(thumbFile);
|
||||||
try {
|
try {
|
||||||
generateThumbnailImage(mainFile, thumbFile,
|
generateThumbnailImage(mainFile, thumbFile,
|
||||||
|
|
|
@ -17,7 +17,6 @@ import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDao;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorage;
|
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorage;
|
||||||
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup;
|
import edu.cornell.mannlib.vitro.webapp.filestorage.backend.FileStorageSetup;
|
||||||
import edu.cornell.mannlib.vitro.webapp.filestorage.updater.FileStorageUpdater;
|
import edu.cornell.mannlib.vitro.webapp.filestorage.updater.FileStorageUpdater;
|
||||||
|
@ -97,8 +96,12 @@ public class UpdateUploadedFiles implements ServletContextListener {
|
||||||
+ "' does not exist.");
|
+ "' does not exist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String webappImagePath = ctx.getRealPath("images");
|
||||||
|
File webappImageDirectory = (webappImagePath == null) ? null
|
||||||
|
: new File(webappImagePath);
|
||||||
|
|
||||||
FileStorageUpdater fsu = new FileStorageUpdater(wadf, jenaOntModel,
|
FileStorageUpdater fsu = new FileStorageUpdater(wadf, jenaOntModel,
|
||||||
fileStorage, uploadDirectory);
|
fileStorage, uploadDirectory, webappImageDirectory);
|
||||||
fsu.update();
|
fsu.update();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unknown problem", e);
|
log.error("Unknown problem", e);
|
||||||
|
|
Loading…
Add table
Reference in a new issue