diff options
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/db/ImageProcessor.java')
-rw-r--r-- | src/main/java/org/openslx/imagemaster/db/ImageProcessor.java | 78 |
1 files changed, 40 insertions, 38 deletions
diff --git a/src/main/java/org/openslx/imagemaster/db/ImageProcessor.java b/src/main/java/org/openslx/imagemaster/db/ImageProcessor.java index de545ae..d0ac5c6 100644 --- a/src/main/java/org/openslx/imagemaster/db/ImageProcessor.java +++ b/src/main/java/org/openslx/imagemaster/db/ImageProcessor.java @@ -7,49 +7,51 @@ import org.apache.log4j.Logger; import org.openslx.imagemaster.Globals; import org.openslx.imagemaster.thrift.iface.ImageData; -public class ImageProcessor { +public class ImageProcessor +{ - private static Logger log = Logger.getLogger(ImageProcessor.class); + private static Logger log = Logger.getLogger( ImageProcessor.class ); private static HashMap<String, ImageData> images = new HashMap<>(); - /** * Processes an image after upload + * * @param username the user that uploaded the file * @param filename the name of the file that was uploaded (_no_ absolute path) * @return */ - public static boolean processImageAfterUpload(String username, String filename) { - if (!images.containsKey(username)) { + public static boolean processImageAfterUpload( String username, String filename ) + { + if ( !images.containsKey( username ) ) { return false; } - - log.info("Will now process '" + filename + "' from user '" + username - + "'"); + + log.info( "Will now process '" + filename + "' from user '" + username + + "'" ); // move image to right location String oldFileName = Globals.getPropertyString( Globals.PropString.FTPBASEDIR ) + "/" + username + "/" + filename; - String newFileName = Globals.getPropertyString( Globals.PropString.IMAGEDIR ) + "/" + images.get(username).uuid; - - File imageFile = new File(oldFileName); - - if (!imageFile.exists()) { + String newFileName = Globals.getPropertyString( Globals.PropString.IMAGEDIR ) + "/" + images.get( username ).uuid; + + File imageFile = new File( oldFileName ); + + if ( !imageFile.exists() ) { // image file does not exist return false; } - - imageFile.renameTo( new File(newFileName) ); - - log.info("Moved file from " + oldFileName + " to " + newFileName ); - - File tempUserDir = new File (Globals.getPropertyString( Globals.PropString.FTPBASEDIR ) + "/" + username); + + imageFile.renameTo( new File( newFileName ) ); + + log.info( "Moved file from " + oldFileName + " to " + newFileName ); + + File tempUserDir = new File( Globals.getPropertyString( Globals.PropString.FTPBASEDIR ) + "/" + username ); tempUserDir.delete(); - + // update database - DbImage.update(images.get(username), newFileName); - log.info("Updated db: " + images.get(username).uuid); - - images.remove(username); + DbImage.update( images.get( username ), newFileName ); + log.info( "Updated db: " + images.get( username ).uuid ); + + images.remove( username ); return true; } @@ -57,31 +59,31 @@ public class ImageProcessor { * Try to add imageData to database. * * @param imageData - * the data for the image to add + * the data for the image to add * @return false if submit fails */ - public static boolean addImageDataToProcess(ImageData imageData, - String username) { - log.info("Adding image to process list: " + imageData.imageName + ", submitted by " + username); - - if (imageData.uuid.isEmpty() || imageData.imageName.isEmpty() + public static boolean addImageDataToProcess( ImageData imageData, String username ) + { + log.info( "Adding image to process list: " + imageData.imageName + ", submitted by " + username ); + + if ( imageData.uuid.isEmpty() || imageData.imageName.isEmpty() || imageData.imageOwner.isEmpty() || imageData.conentOperatingSystem.isEmpty() || imageData.imageShortDescription.isEmpty() - || imageData.imageLongDescription.isEmpty()) { + || imageData.imageLongDescription.isEmpty() ) { return false; } - + // TODO: check some regex? - - if (DbImage.exists(imageData)) { + + if ( DbImage.exists( imageData ) ) { return false; } - + // if everything went fine, add image to db - DbImage.insert(imageData); - + DbImage.insert( imageData ); + // and to processinglist - images.put(username, imageData); + images.put( username, imageData ); return true; } } |