diff options
Diffstat (limited to 'src/main/java/org/openslx/imagemaster/db')
| -rw-r--r-- | src/main/java/org/openslx/imagemaster/db/ImageProcessor.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/imagemaster/db/ImageProcessor.java b/src/main/java/org/openslx/imagemaster/db/ImageProcessor.java new file mode 100644 index 0000000..804e4b9 --- /dev/null +++ b/src/main/java/org/openslx/imagemaster/db/ImageProcessor.java @@ -0,0 +1,57 @@ +package org.openslx.imagemaster.db; + +import java.io.File; +import java.util.HashMap; + +import org.apache.log4j.Logger; +import org.openslx.imagemaster.Globals; +import org.openslx.imagemaster.thrift.iface.ImageData; + +public class ImageProcessor { + + private static Logger log = Logger.getLogger(ImageProcessor.class); + private static HashMap<String, ImageData> images = new HashMap<>(); + + public static void processImageAfterUpload(String username, String filename) { + /* + * TODO: Process the image after download + */ + log.info("Will now process '" + filename + "' from user '" + username + + "'"); + + // look for database entry, update it and move image to right location + String oldFileName = Globals.properties.getProperty("ftp_base_dir") + "/" + username + + "/" + filename; + File imageFile = new File(oldFileName); + if (!imageFile.exists()) { + // image file does not exist?? + return; + } + String newFileName = Globals.properties.getProperty("image_dir") + "/" + images.get(username).imageName; + imageFile.renameTo( new File(newFileName) ); + log.info("Moved file from " + oldFileName + " to " + newFileName ); + + File tempUserDir = new File (Globals.properties.getProperty("ftp_base_dir") + "/" + username); + tempUserDir.delete(); + } + + /** + * Try to add imageData to db + * + * @param imageData + * the data for the image to add + * @return false if submit fails + */ + public static boolean addImageDataToProcess(ImageData imageData, + String username) { + /* + * TODO: + * check if imagedata is correct + * check if image is already in db + */ + + // if everything went fine, add image to processing list + images.put(username, imageData); + return true; + } +} |
