From 868ecf5310926d1d5a1082ce8add0a7527190198 Mon Sep 17 00:00:00 2001 From: jeb228 Date: Tue, 13 Jul 2010 19:46:57 +0000 Subject: [PATCH] NIHVIVO-161 - Bug fix: check the dimensions on the current image, not on a previous one. --- .../freemarker/ImageUploadController.java | 59 +++++++++++-------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ImageUploadController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ImageUploadController.java index 16b90928a..5efe25e2b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ImageUploadController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/freemarker/ImageUploadController.java @@ -278,32 +278,16 @@ public class ImageUploadController extends FreeMarkerHttpServlet { * image (and thumbnail), and attach the new main image. */ private ResponseValues doUploadImage(VitroRequest vreq, Individual entity) { - ImageUploadHelper helper = new ImageUploadHelper(fileStorage, - vreq.getFullWebappDaoFactory()); + ImageUploadHelper helper = new ImageUploadHelper(fileStorage, vreq + .getFullWebappDaoFactory()); // Did they provide a file to upload? If not, show an error. FileItem fileItem; - Dimensions mainImageSize; try { fileItem = helper.validateImageFromRequest(vreq); - mainImageSize = helper.getMainImageSize(entity); - if ((mainImageSize.height < THUMBNAIL_HEIGHT) - || (mainImageSize.width < THUMBNAIL_WIDTH)) { - throw new UserMistakeException( - "The uploaded image should be at least " - + THUMBNAIL_HEIGHT + " pixels high and " - + THUMBNAIL_WIDTH + " pixels wide."); - } } catch (UserMistakeException e) { - String thumbUrl = getThumbnailUrl(entity); - String message = e.getMessage(); - if (thumbUrl == null) { - return showAddImagePageWithError(vreq, entity, message); - } else { - return showReplaceImagePageWithError(vreq, entity, thumbUrl, - message); - } + return showErrorMessage(vreq, entity, e.getMessage()); } // Remove the old main image (if any) and store the new one. @@ -312,22 +296,47 @@ public class ImageUploadController extends FreeMarkerHttpServlet { // The entity Individual is stale - get another one; String entityUri = entity.getURI(); - entity = vreq.getFullWebappDaoFactory().getIndividualDao().getIndividualByURI( - entityUri); + entity = vreq.getFullWebappDaoFactory().getIndividualDao() + .getIndividualByURI(entityUri); + + Dimensions mainImageSize = helper.getMainImageSize(entity); + + if ((mainImageSize.height < THUMBNAIL_HEIGHT) + || (mainImageSize.width < THUMBNAIL_WIDTH)) { + String message = "The uploaded image should be at least " + + THUMBNAIL_HEIGHT + " pixels high and " + THUMBNAIL_WIDTH + + " pixels wide."; + return showErrorMessage(vreq, entity, message); + } // Go to the cropping page. return showCropImagePage(vreq, entity, getMainImageUrl(entity), mainImageSize); } + /** + * Are we writing the error message to the "Add" page or to the "Replace" + * page? + */ + private ResponseValues showErrorMessage(VitroRequest vreq, + Individual entity, String message) { + String thumbUrl = getThumbnailUrl(entity); + if (thumbUrl == null) { + return showAddImagePageWithError(vreq, entity, message); + } else { + return showReplaceImagePageWithError(vreq, entity, thumbUrl, + message); + } + } + /** * The user has specified how to crop the thumbnail. Crop it and attach it * to the main image. */ private ResponseValues doCreateThumbnail(VitroRequest vreq, Individual entity) { - ImageUploadHelper helper = new ImageUploadHelper(fileStorage, - vreq.getFullWebappDaoFactory()); + ImageUploadHelper helper = new ImageUploadHelper(fileStorage, vreq + .getFullWebappDaoFactory()); validateMainImage(entity); CropRectangle crop = validateCropCoordinates(vreq); @@ -342,8 +351,8 @@ public class ImageUploadController extends FreeMarkerHttpServlet { * Delete the main image and the thumbnail from the individual. */ private ResponseValues doDeleteImage(VitroRequest vreq, Individual entity) { - ImageUploadHelper helper = new ImageUploadHelper(fileStorage, - vreq.getFullWebappDaoFactory()); + ImageUploadHelper helper = new ImageUploadHelper(fileStorage, vreq + .getFullWebappDaoFactory()); helper.removeExistingImage(entity);