NIHVIVO-161 - Bug fix: check the dimensions on the current image, not on a previous one.
This commit is contained in:
parent
ef86bd7875
commit
868ecf5310
1 changed files with 34 additions and 25 deletions
|
@ -278,32 +278,16 @@ public class ImageUploadController extends FreeMarkerHttpServlet {
|
||||||
* image (and thumbnail), and attach the new main image.
|
* image (and thumbnail), and attach the new main image.
|
||||||
*/
|
*/
|
||||||
private ResponseValues doUploadImage(VitroRequest vreq, Individual entity) {
|
private ResponseValues doUploadImage(VitroRequest vreq, Individual entity) {
|
||||||
ImageUploadHelper helper = new ImageUploadHelper(fileStorage,
|
ImageUploadHelper helper = new ImageUploadHelper(fileStorage, vreq
|
||||||
vreq.getFullWebappDaoFactory());
|
.getFullWebappDaoFactory());
|
||||||
|
|
||||||
// Did they provide a file to upload? If not, show an error.
|
// Did they provide a file to upload? If not, show an error.
|
||||||
FileItem fileItem;
|
FileItem fileItem;
|
||||||
Dimensions mainImageSize;
|
|
||||||
try {
|
try {
|
||||||
fileItem = helper.validateImageFromRequest(vreq);
|
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) {
|
} catch (UserMistakeException e) {
|
||||||
String thumbUrl = getThumbnailUrl(entity);
|
return showErrorMessage(vreq, entity, e.getMessage());
|
||||||
String message = e.getMessage();
|
|
||||||
if (thumbUrl == null) {
|
|
||||||
return showAddImagePageWithError(vreq, entity, message);
|
|
||||||
} else {
|
|
||||||
return showReplaceImagePageWithError(vreq, entity, thumbUrl,
|
|
||||||
message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the old main image (if any) and store the new one.
|
// 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;
|
// The entity Individual is stale - get another one;
|
||||||
String entityUri = entity.getURI();
|
String entityUri = entity.getURI();
|
||||||
entity = vreq.getFullWebappDaoFactory().getIndividualDao().getIndividualByURI(
|
entity = vreq.getFullWebappDaoFactory().getIndividualDao()
|
||||||
entityUri);
|
.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.
|
// Go to the cropping page.
|
||||||
return showCropImagePage(vreq, entity, getMainImageUrl(entity),
|
return showCropImagePage(vreq, entity, getMainImageUrl(entity),
|
||||||
mainImageSize);
|
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
|
* The user has specified how to crop the thumbnail. Crop it and attach it
|
||||||
* to the main image.
|
* to the main image.
|
||||||
*/
|
*/
|
||||||
private ResponseValues doCreateThumbnail(VitroRequest vreq,
|
private ResponseValues doCreateThumbnail(VitroRequest vreq,
|
||||||
Individual entity) {
|
Individual entity) {
|
||||||
ImageUploadHelper helper = new ImageUploadHelper(fileStorage,
|
ImageUploadHelper helper = new ImageUploadHelper(fileStorage, vreq
|
||||||
vreq.getFullWebappDaoFactory());
|
.getFullWebappDaoFactory());
|
||||||
|
|
||||||
validateMainImage(entity);
|
validateMainImage(entity);
|
||||||
CropRectangle crop = validateCropCoordinates(vreq);
|
CropRectangle crop = validateCropCoordinates(vreq);
|
||||||
|
@ -342,8 +351,8 @@ public class ImageUploadController extends FreeMarkerHttpServlet {
|
||||||
* Delete the main image and the thumbnail from the individual.
|
* Delete the main image and the thumbnail from the individual.
|
||||||
*/
|
*/
|
||||||
private ResponseValues doDeleteImage(VitroRequest vreq, Individual entity) {
|
private ResponseValues doDeleteImage(VitroRequest vreq, Individual entity) {
|
||||||
ImageUploadHelper helper = new ImageUploadHelper(fileStorage,
|
ImageUploadHelper helper = new ImageUploadHelper(fileStorage, vreq
|
||||||
vreq.getFullWebappDaoFactory());
|
.getFullWebappDaoFactory());
|
||||||
|
|
||||||
helper.removeExistingImage(entity);
|
helper.removeExistingImage(entity);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue