From 826a2e6ebd6233e7c209eefd032b8f2f7a84b81f Mon Sep 17 00:00:00 2001 From: MPDLBreddin Date: Wed, 8 Jan 2020 15:06:24 +0100 Subject: [PATCH] #1158 Provide meaningful user error messages for concurrency errors (part 3) - Refactored ReloadBeforeSaveException (extends now ImejiExceptionWithUserMessage) - Refactored ImejiExceptionWithUserMessage --- .../ImejiExceptionWithUserMessage.java | 13 ++++-- .../exceptions/ReloadBeforeSaveException.java | 42 ++++++++++++++++--- .../de/mpg/imeji/logic/model/Properties.java | 2 - .../imeji/logic/model/aspects/CloneURI.java | 10 ++++- .../pwdreset/PasswordResetController.java | 12 ++++-- .../de/mpg/imeji/logic/util/ObjectHelper.java | 39 +++++++++++++++++ .../collection/CollectionActionMenu.java | 9 ++-- .../collection/CreateCollectionBean.java | 4 +- .../collection/EditCollectionBean.java | 10 +---- .../collection/share/ShareBean.java | 4 +- .../subcollection/SubCollectionFormBean.java | 8 ++-- .../presentation/item/browse/ItemsBean.java | 12 ++++-- .../presentation/item/details/ItemBean.java | 13 +++--- .../item/edit/EditMetadataAbstract.java | 2 +- .../item/edit/batch/EditItemsBatchBean.java | 6 +-- .../edit/selected/EditItemsSelectedBean.java | 6 +-- .../item/license/ItemsEditLicenseBean.java | 2 +- .../presentation/item/move/MoveItemsBean.java | 9 ++-- .../presentation/item/upload/UploadBean.java | 2 +- .../search/facet/CreateFacetBean.java | 2 +- .../search/facet/EditFacetBean.java | 6 +-- .../presentation/search/facet/FacetsBean.java | 4 +- .../statement/StatementCreateBean.java | 2 +- .../statement/StatementEditBean.java | 2 +- .../statement/StatementsBean.java | 2 +- .../mpg/imeji/presentation/user/UserBean.java | 21 ++++------ .../presentation/user/UserCreationBean.java | 2 +- .../imeji/presentation/user/UsersBean.java | 35 ++++++---------- .../user/registration/RegistrationBean.java | 4 +- .../user/subscription/SubscriptionBean.java | 10 ++--- .../presentation/userGroup/UserGroupBean.java | 10 ++--- .../userGroup/UserGroupsBean.java | 2 +- 32 files changed, 187 insertions(+), 120 deletions(-) diff --git a/src/main/java/de/mpg/imeji/exceptions/ImejiExceptionWithUserMessage.java b/src/main/java/de/mpg/imeji/exceptions/ImejiExceptionWithUserMessage.java index d492a99c4..a609d3494 100644 --- a/src/main/java/de/mpg/imeji/exceptions/ImejiExceptionWithUserMessage.java +++ b/src/main/java/de/mpg/imeji/exceptions/ImejiExceptionWithUserMessage.java @@ -1,5 +1,9 @@ package de.mpg.imeji.exceptions; +import java.util.Locale; + +import de.mpg.imeji.logic.config.Imeji; + /** * Inherit this class if you want to show a user error message in GUI. * @@ -19,7 +23,7 @@ public abstract class ImejiExceptionWithUserMessage extends ImejiException{ * * @see files src/main/resources/messages_*.properties */ - private final String userMessageLabel; + protected final String userMessageLabel; public ImejiExceptionWithUserMessage(String messageLabel) { super(); @@ -36,11 +40,12 @@ public ImejiExceptionWithUserMessage(String messageLabel, Throwable e) { this.userMessageLabel = messageLabel; } - public String getMessageLabel() { + public String getUserMessage(Locale locale) { if(this.userMessageLabel == null) { - return ""; + return " "; } - return this.userMessageLabel; + String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(this.userMessageLabel, locale); + return userMessage; } diff --git a/src/main/java/de/mpg/imeji/exceptions/ReloadBeforeSaveException.java b/src/main/java/de/mpg/imeji/exceptions/ReloadBeforeSaveException.java index db6142156..75ec1af9a 100644 --- a/src/main/java/de/mpg/imeji/exceptions/ReloadBeforeSaveException.java +++ b/src/main/java/de/mpg/imeji/exceptions/ReloadBeforeSaveException.java @@ -1,23 +1,43 @@ package de.mpg.imeji.exceptions; +import java.util.Locale; + +import de.mpg.imeji.logic.config.Imeji; +import de.mpg.imeji.logic.util.ObjectHelper; + /** * Exception will be thrown if a process (user session) tries to update an object in store that has - * been changed since it was last read by that process. This can happen when another process (user - * session) updates the object after it is read from database by our process and before it is - * written back. Context: Multiple processes access shared data resources (i.e. collection, item). + * been changed since it was last read by that same process. This can happen when another process (user + * session) updates the object after it was read from database by our process and before it is + * written back. Context: Multiple processes (users) access shared data resources (i.e. collection, item). * * The latest version of the object in store can be retrieved from the Exception. * + * A user readable error message (in different languages) is available. + * * @author breddin * */ -public class ReloadBeforeSaveException extends ImejiException { +public class ReloadBeforeSaveException extends ImejiExceptionWithUserMessage { private static final long serialVersionUID = -2208211062675780202L; + + /** + * Current (latest) version of the object in store + */ private Object latestDataObject; + + /** + * User readable name of the object that needs to be reloaded + * for GUI error message + */ + private String objectLabel; + public ReloadBeforeSaveException(Object latestDataObject) { - super("Object has been altered in store. Reload before saving."); + + super("reload_before_save"); + this.objectLabel = ObjectHelper.getGUILabel(latestDataObject); this.latestDataObject = latestDataObject; } @@ -25,4 +45,16 @@ public Object getLatestDataObject() { return this.latestDataObject; } + + /** + * Creates a user readable error message. + * @return error message + */ + @Override + public String getUserMessage(Locale locale) { + String userMessage = + Imeji.RESOURCE_BUNDLE.getLabel(this.objectLabel, locale) + " " + + Imeji.RESOURCE_BUNDLE.getMessage(this.userMessageLabel, locale); + return userMessage; + } } diff --git a/src/main/java/de/mpg/imeji/logic/model/Properties.java b/src/main/java/de/mpg/imeji/logic/model/Properties.java index 1c6188c0a..fc6d77c47 100644 --- a/src/main/java/de/mpg/imeji/logic/model/Properties.java +++ b/src/main/java/de/mpg/imeji/logic/model/Properties.java @@ -46,8 +46,6 @@ public class Properties implements Serializable, ResourceLastModified, AccessMem private static final Logger LOGGER = LogManager.getLogger(Properties.class); - - @XmlEnum(String.class) public enum Status { PENDING(new String(ImejiNamespaces.STATUS + "#PENDING")), diff --git a/src/main/java/de/mpg/imeji/logic/model/aspects/CloneURI.java b/src/main/java/de/mpg/imeji/logic/model/aspects/CloneURI.java index bfa6beea0..a7e8d230a 100644 --- a/src/main/java/de/mpg/imeji/logic/model/aspects/CloneURI.java +++ b/src/main/java/de/mpg/imeji/logic/model/aspects/CloneURI.java @@ -1,13 +1,19 @@ package de.mpg.imeji.logic.model.aspects; /** - * To be implemented by model classes. Given a data model object, create a new empty data model - * object of the same class and initialize it with the URI of the original data model object. + * Interface can be implemented by model classes. Creates a new object of the same type as the given object. + * Copies the URI of the given object to the new object. Useful when reading data from Jena. * * @author breddin * */ public interface CloneURI { +/** + * "Clone" the given object: Return a new object of the same type as the given object + * with all fields empty/default except the URI field. + * URI of cloned object is set to URI of the given object. + * @return clone + */ public Object cloneURI(); } diff --git a/src/main/java/de/mpg/imeji/logic/security/user/pwdreset/PasswordResetController.java b/src/main/java/de/mpg/imeji/logic/security/user/pwdreset/PasswordResetController.java index 428f56d40..41c0d0d69 100644 --- a/src/main/java/de/mpg/imeji/logic/security/user/pwdreset/PasswordResetController.java +++ b/src/main/java/de/mpg/imeji/logic/security/user/pwdreset/PasswordResetController.java @@ -65,17 +65,21 @@ public boolean isValidToken(String tokenString) { * @param password * @return * @throws UnprocessableError + * @throws ReloadBeforeSaveException */ - public User resetPassword(String tokenString, String password) throws UnprocessableError { + public User resetPassword(String tokenString, String password) throws UnprocessableError, ReloadBeforeSaveException { try { PasswordResetToken token = retrieveToken(tokenString); User userWithNewPassword = resetPassword(token.getUser(), password); tokenStore.delete(token.getEncryptedToken()); return userWithNewPassword; - } catch (ReloadBeforeSaveException reloadBeforeException) { - throw new UnprocessableError("User properties have changed in store. Reload user and reset password again."); + } + catch (ReloadBeforeSaveException reloadBeforeException) { + // re-throw ReloadBeforeSaveException + throw reloadBeforeException; } catch (Exception e) { - throw new UnprocessableError("The token or the user was not found"); + // all other exceptions: throw UnprocessableError + throw new UnprocessableError("The token or the user was not found"); } } diff --git a/src/main/java/de/mpg/imeji/logic/util/ObjectHelper.java b/src/main/java/de/mpg/imeji/logic/util/ObjectHelper.java index 5f367a46d..00d83e53b 100644 --- a/src/main/java/de/mpg/imeji/logic/util/ObjectHelper.java +++ b/src/main/java/de/mpg/imeji/logic/util/ObjectHelper.java @@ -14,6 +14,12 @@ import de.mpg.imeji.j2j.annotations.j2jModel; import de.mpg.imeji.j2j.annotations.j2jResource; +import de.mpg.imeji.logic.model.CollectionImeji; +import de.mpg.imeji.logic.model.Item; +import de.mpg.imeji.logic.model.Statement; +import de.mpg.imeji.logic.model.User; +import de.mpg.imeji.logic.model.UserGroup; +import de.mpg.imeji.logic.search.facet.model.Facet; /** * Helper for imeji {@link Object} @@ -187,4 +193,37 @@ public static void copyAllFields(Object obj1, Object obj2) { } } } + + /** + * Function returns the GUI label of the given object, i.e. "Collection" for a CollectionImeji object. + * See src/main/resources/labels_*.properties for available GUI labels. + * + * @param object + * @return label for object, base line: "Object" + */ + public static String getGUILabel(Object object) { + + if(object instanceof CollectionImeji) { + return "COLLECTION"; + } + else if(object instanceof User) { + return "user"; + } + else if(object instanceof Item) { + return "image"; + } + else if(object instanceof UserGroup) { + return "admin_userGroup"; + } + else if(object instanceof Statement) { + return "statement"; + } + else if(object instanceof Facet) { + return "facet"; + } + else { + return "object"; + } + } + } diff --git a/src/main/java/de/mpg/imeji/presentation/collection/CollectionActionMenu.java b/src/main/java/de/mpg/imeji/presentation/collection/CollectionActionMenu.java index 8109687ce..7f58d75c0 100644 --- a/src/main/java/de/mpg/imeji/presentation/collection/CollectionActionMenu.java +++ b/src/main/java/de/mpg/imeji/presentation/collection/CollectionActionMenu.java @@ -137,13 +137,14 @@ private void addProvidedDOI(String newDOI) { } catch (final ImejiException imejiException) { // restore collection.setDoi(currentDOI); - + // exception handling if (imejiException instanceof UnprocessableError) { BeanHelper.error(Imeji.RESOURCE_BUNDLE.getMessage(imejiException.getMessage(), locale)); LOGGER.error(Imeji.RESOURCE_BUNDLE.getMessage(imejiException.getMessage(), locale)); } else if (imejiException instanceof ImejiExceptionWithUserMessage) { ImejiExceptionWithUserMessage exceptionWithMessage = (ImejiExceptionWithUserMessage) imejiException; - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), locale); + String userMessage = Imeji.RESOURCE_BUNDLE.getMessage("error_doi_creation", locale) + " " + + exceptionWithMessage.getUserMessage(locale); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -172,7 +173,9 @@ private void addMPDLDoi() { BeanHelper.error(Imeji.RESOURCE_BUNDLE.getMessage(e.getMessage(), locale)); LOGGER.error(Imeji.RESOURCE_BUNDLE.getMessage(e.getMessage(), locale)); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), locale); + String userMessage = + Imeji.RESOURCE_BUNDLE.getMessage("error_doi_creation", locale) + " " + + exceptionWithMessage.getUserMessage(locale); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/collection/CreateCollectionBean.java b/src/main/java/de/mpg/imeji/presentation/collection/CreateCollectionBean.java index ed5616ee6..f15dcd6ed 100644 --- a/src/main/java/de/mpg/imeji/presentation/collection/CreateCollectionBean.java +++ b/src/main/java/de/mpg/imeji/presentation/collection/CreateCollectionBean.java @@ -129,7 +129,9 @@ public boolean createCollection() { BeanHelper.error(e, getLocale()); LOGGER.error("Error create collection", e); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = + Imeji.RESOURCE_BUNDLE.getMessage("error_collection_create", getLocale()) + " " + + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/collection/EditCollectionBean.java b/src/main/java/de/mpg/imeji/presentation/collection/EditCollectionBean.java index efb382ac3..25b0a09a7 100644 --- a/src/main/java/de/mpg/imeji/presentation/collection/EditCollectionBean.java +++ b/src/main/java/de/mpg/imeji/presentation/collection/EditCollectionBean.java @@ -85,7 +85,6 @@ public void init() { getCollection().setAdditionalInformations(additionalList); } - //Always add empty additional info at the end getCollection().getAdditionalInformations().add(new ContainerAdditionalInfo()); // init linked collections @@ -135,7 +134,8 @@ public boolean saveEditedCollection() { return true; } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error saving collection: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = Imeji.RESOURCE_BUNDLE.getMessage("error_collection_save", getLocale()) + " " + + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error("Error saving collection: " + exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -156,12 +156,6 @@ public boolean saveEditedCollection() { BeanHelper.error(Imeji.RESOURCE_BUNDLE.getMessage("error_collection_logo_uri_save", getLocale())); LOGGER.error("Error saving collection", e); return false; - } catch (final ReloadBeforeSaveException reloadBeforeSave) { - String reloadBeforeSaveMessage = - Imeji.RESOURCE_BUNDLE.getMessage("error_collection_save", getLocale()) + ": " + reloadBeforeSave.getMessage(); - BeanHelper.error(reloadBeforeSaveMessage); - LOGGER.info("Saving collection ReloadBeforeSaveException: " + reloadBeforeSave.getMessage()); - return false; } catch (final ImejiException e) { BeanHelper.error(Imeji.RESOURCE_BUNDLE.getMessage("error_collection_save", getLocale())); LOGGER.error("Error saving collection", e); diff --git a/src/main/java/de/mpg/imeji/presentation/collection/share/ShareBean.java b/src/main/java/de/mpg/imeji/presentation/collection/share/ShareBean.java index 9df11950a..08340b785 100644 --- a/src/main/java/de/mpg/imeji/presentation/collection/share/ShareBean.java +++ b/src/main/java/de/mpg/imeji/presentation/collection/share/ShareBean.java @@ -103,10 +103,10 @@ public void initShareCollection() { this.init(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error initializing page: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { - LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); + LOGGER.error("Error initializing page: " + exceptionWithMessage.getMessage(), exceptionWithMessage); } else { LOGGER.error(userMessage, exceptionWithMessage); } diff --git a/src/main/java/de/mpg/imeji/presentation/collection/subcollection/SubCollectionFormBean.java b/src/main/java/de/mpg/imeji/presentation/collection/subcollection/SubCollectionFormBean.java index c63c14b3b..ca1b06d9b 100644 --- a/src/main/java/de/mpg/imeji/presentation/collection/subcollection/SubCollectionFormBean.java +++ b/src/main/java/de/mpg/imeji/presentation/collection/subcollection/SubCollectionFormBean.java @@ -52,10 +52,10 @@ public void create(CollectionImeji parent) throws IOException { redirect(getNavigation().getCollectionUrl() + subcollection.getIdString()); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error creating Subcollection: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { - LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); + LOGGER.error("Error creating Subcollection: " + exceptionWithMessage.getMessage(), exceptionWithMessage); } else { LOGGER.error(userMessage, exceptionWithMessage); } @@ -80,10 +80,10 @@ public void createAndUpload() throws IOException { redirect(getNavigation().getCollectionUrl() + subcollection.getIdString() + "?showUpload=1"); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error creating Subcollection: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { - LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); + LOGGER.error("Error creating Subcollection: " + exceptionWithMessage.getMessage(), exceptionWithMessage); } else { LOGGER.error(userMessage, exceptionWithMessage); } diff --git a/src/main/java/de/mpg/imeji/presentation/item/browse/ItemsBean.java b/src/main/java/de/mpg/imeji/presentation/item/browse/ItemsBean.java index e26af5e74..02717865a 100644 --- a/src/main/java/de/mpg/imeji/presentation/item/browse/ItemsBean.java +++ b/src/main/java/de/mpg/imeji/presentation/item/browse/ItemsBean.java @@ -158,7 +158,7 @@ public List retrieveList(int offset, int size) { return thumbnailBeans; } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -407,7 +407,9 @@ private void withdraw(List uris) throws ImejiException { unselect(uris); BeanHelper.info(count + " " + Imeji.RESOURCE_BUNDLE.getLabel("images_withdraw", getLocale())); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = + Imeji.RESOURCE_BUNDLE.getMessage("error_withdraw_selected_items", getLocale()) + " " + + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -437,7 +439,7 @@ private void delete(List uris) { BeanHelper.info(uris.size() + " " + Imeji.RESOURCE_BUNDLE.getLabel("images_deleted", getLocale())); unselect(uris); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -694,7 +696,9 @@ private Collection findSelectedDeletableItems() { .collect(Collectors.toList()); return deletableItems; } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = + Imeji.RESOURCE_BUNDLE.getMessage("error_retrieve_selected_items", getLocale()) + " " + + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/item/details/ItemBean.java b/src/main/java/de/mpg/imeji/presentation/item/details/ItemBean.java index 7667803f8..0276eb28b 100644 --- a/src/main/java/de/mpg/imeji/presentation/item/details/ItemBean.java +++ b/src/main/java/de/mpg/imeji/presentation/item/details/ItemBean.java @@ -203,7 +203,7 @@ public void loadCollection(User user) { try { collection = new CollectionService().retrieveLazy(item.getCollection(), user); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -312,7 +312,9 @@ public void save() throws IOException { editor.updateMetadataEntries(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = + Imeji.RESOURCE_BUNDLE.getMessage("error_metadata_edit", getLocale()) + " " + + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -320,10 +322,6 @@ public void save() throws IOException { LOGGER.error(userMessage, exceptionWithMessage); } editor.updateMetadataEntries(); - } - catch (ReloadBeforeSaveException reloadBeforeSave) { - BeanHelper.error(Imeji.RESOURCE_BUNDLE.getMessage("error_metadata_edit", getLocale()) + ": " + reloadBeforeSave.getMessage()); - editor.updateMetadataEntries(); } catch (ImejiException e) { BeanHelper.error(Imeji.RESOURCE_BUNDLE.getMessage("error_metadata_edit", getLocale()) + ": " + e.getMessage()); LOGGER.error("Error saving item metadata", e); @@ -362,7 +360,8 @@ public void withdraw() { this.discardComment = null; } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = Imeji.RESOURCE_BUNDLE.getMessage("error_withdraw_image", getLocale()) + " " + + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/item/edit/EditMetadataAbstract.java b/src/main/java/de/mpg/imeji/presentation/item/edit/EditMetadataAbstract.java index 9a40cd866..cc0779083 100644 --- a/src/main/java/de/mpg/imeji/presentation/item/edit/EditMetadataAbstract.java +++ b/src/main/java/de/mpg/imeji/presentation/item/edit/EditMetadataAbstract.java @@ -53,7 +53,7 @@ public EditMetadataAbstract() { statementMenu = statementMap.keySet().stream().map(s -> new SelectItem(s)).collect(Collectors.toList()); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error retrieving statements. " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/item/edit/batch/EditItemsBatchBean.java b/src/main/java/de/mpg/imeji/presentation/item/edit/batch/EditItemsBatchBean.java index 7411577a9..6a12172a9 100644 --- a/src/main/java/de/mpg/imeji/presentation/item/edit/batch/EditItemsBatchBean.java +++ b/src/main/java/de/mpg/imeji/presentation/item/edit/batch/EditItemsBatchBean.java @@ -93,7 +93,7 @@ public void append() { BeanHelper.addMessage(Imeji.RESOURCE_BUNDLE.getMessage("success_items_save", getLocale())); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -122,7 +122,7 @@ public void fill() { BeanHelper.addMessage(Imeji.RESOURCE_BUNDLE.getMessage("success_items_save", getLocale())); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -153,7 +153,7 @@ public void overwrite() { BeanHelper.addMessage(Imeji.RESOURCE_BUNDLE.getMessage("success_items_save", getLocale())); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/item/edit/selected/EditItemsSelectedBean.java b/src/main/java/de/mpg/imeji/presentation/item/edit/selected/EditItemsSelectedBean.java index ed8d33621..a8ae18678 100644 --- a/src/main/java/de/mpg/imeji/presentation/item/edit/selected/EditItemsSelectedBean.java +++ b/src/main/java/de/mpg/imeji/presentation/item/edit/selected/EditItemsSelectedBean.java @@ -79,7 +79,7 @@ public void init() { tableSize = rows.size() > tableSize ? tableSize : rows.size(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error initialiting page: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -111,7 +111,7 @@ public void save() { goBack(); BeanHelper.addMessage(Imeji.RESOURCE_BUNDLE.getMessage("success_items_save", getLocale())); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error updating items: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -122,7 +122,7 @@ public void save() { catch (UnprocessableError e) { BeanHelper.error(e, getLocale()); } catch (ImejiException e1) { - LOGGER.error("Edit updating items", e1); + LOGGER.error("Error updating items", e1); BeanHelper.error(e1.getMessage()); } catch (IOException e) { LOGGER.error("Error redirect after save", e); diff --git a/src/main/java/de/mpg/imeji/presentation/item/license/ItemsEditLicenseBean.java b/src/main/java/de/mpg/imeji/presentation/item/license/ItemsEditLicenseBean.java index 027c9601b..561d46bda 100644 --- a/src/main/java/de/mpg/imeji/presentation/item/license/ItemsEditLicenseBean.java +++ b/src/main/java/de/mpg/imeji/presentation/item/license/ItemsEditLicenseBean.java @@ -93,7 +93,7 @@ public void save() throws ImejiException, IOException { + " " + Imeji.RESOURCE_BUNDLE.getLabel("items", getLocale())); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error saving items " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/item/move/MoveItemsBean.java b/src/main/java/de/mpg/imeji/presentation/item/move/MoveItemsBean.java index ccf23b33b..a1ae13018 100644 --- a/src/main/java/de/mpg/imeji/presentation/item/move/MoveItemsBean.java +++ b/src/main/java/de/mpg/imeji/presentation/item/move/MoveItemsBean.java @@ -206,7 +206,7 @@ private void moveItems(CollectionImeji col, List ids) { + " " + Imeji.RESOURCE_BUNDLE.getLabel("moved_error", getLocale())); } } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error moving items " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -247,18 +247,15 @@ private void moveCollection(String collectionId, CollectionImeji target) { if (collectionItemsBean != null) { collectionItemsBean.refresh(); } - } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error moving collection: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); } else { LOGGER.error(userMessage, exceptionWithMessage); } - } - - catch (ImejiException e) { + } catch (ImejiException e) { BeanHelper.error("Error moving collection: " + e.getMessage()); LOGGER.error("Error moving collection", e); } diff --git a/src/main/java/de/mpg/imeji/presentation/item/upload/UploadBean.java b/src/main/java/de/mpg/imeji/presentation/item/upload/UploadBean.java index d24ee48ce..062072a22 100644 --- a/src/main/java/de/mpg/imeji/presentation/item/upload/UploadBean.java +++ b/src/main/java/de/mpg/imeji/presentation/item/upload/UploadBean.java @@ -55,7 +55,7 @@ public void init() { } } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error initializing page: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/search/facet/CreateFacetBean.java b/src/main/java/de/mpg/imeji/presentation/search/facet/CreateFacetBean.java index 59a513f45..d7aabbd73 100644 --- a/src/main/java/de/mpg/imeji/presentation/search/facet/CreateFacetBean.java +++ b/src/main/java/de/mpg/imeji/presentation/search/facet/CreateFacetBean.java @@ -61,7 +61,7 @@ public void save() { redirect(getNavigation().getApplicationUrl() + "facets"); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error creating facet. " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/search/facet/EditFacetBean.java b/src/main/java/de/mpg/imeji/presentation/search/facet/EditFacetBean.java index 684f663dd..03a66b76d 100644 --- a/src/main/java/de/mpg/imeji/presentation/search/facet/EditFacetBean.java +++ b/src/main/java/de/mpg/imeji/presentation/search/facet/EditFacetBean.java @@ -37,7 +37,7 @@ public void init() { setObjectType(facet.getObjectType()); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Unknown facet. " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -64,10 +64,10 @@ public void save() { redirect(getNavigation().getApplicationUrl() + "facets"); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error saving facet: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error saving facet. " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { - LOGGER.error("Error saving facet: " + exceptionWithMessage.getMessage(), exceptionWithMessage); + LOGGER.error("Error saving facet. " + exceptionWithMessage.getMessage(), exceptionWithMessage); } else { LOGGER.error(userMessage, exceptionWithMessage); } diff --git a/src/main/java/de/mpg/imeji/presentation/search/facet/FacetsBean.java b/src/main/java/de/mpg/imeji/presentation/search/facet/FacetsBean.java index ad81dee85..58246eb2d 100644 --- a/src/main/java/de/mpg/imeji/presentation/search/facet/FacetsBean.java +++ b/src/main/java/de/mpg/imeji/presentation/search/facet/FacetsBean.java @@ -50,7 +50,7 @@ public void init() { setPosition(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error retrieving facets: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -90,7 +90,7 @@ public void delete() { reload(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error deleting facet: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/statement/StatementCreateBean.java b/src/main/java/de/mpg/imeji/presentation/statement/StatementCreateBean.java index c9e3108b9..d9ed63a7b 100644 --- a/src/main/java/de/mpg/imeji/presentation/statement/StatementCreateBean.java +++ b/src/main/java/de/mpg/imeji/presentation/statement/StatementCreateBean.java @@ -31,7 +31,7 @@ public void save() { service.create(statementForm.asStatement(), getSessionUser()); redirect(getNavigation().getApplicationUrl() + "statements"); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error creating statement: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/statement/StatementEditBean.java b/src/main/java/de/mpg/imeji/presentation/statement/StatementEditBean.java index fb45b763c..9406d8d5e 100644 --- a/src/main/java/de/mpg/imeji/presentation/statement/StatementEditBean.java +++ b/src/main/java/de/mpg/imeji/presentation/statement/StatementEditBean.java @@ -86,7 +86,7 @@ public void save() { redirect(getNavigation().getApplicationUrl() + "statements"); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error editing statement: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/statement/StatementsBean.java b/src/main/java/de/mpg/imeji/presentation/statement/StatementsBean.java index 523893336..e72ad914a 100644 --- a/src/main/java/de/mpg/imeji/presentation/statement/StatementsBean.java +++ b/src/main/java/de/mpg/imeji/presentation/statement/StatementsBean.java @@ -74,7 +74,7 @@ public void delete() { redirect(getNavigation().getApplicationUrl() + "statements"); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error deleting statement: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/user/UserBean.java b/src/main/java/de/mpg/imeji/presentation/user/UserBean.java index e23337afa..06bc4d3d4 100644 --- a/src/main/java/de/mpg/imeji/presentation/user/UserBean.java +++ b/src/main/java/de/mpg/imeji/presentation/user/UserBean.java @@ -69,7 +69,7 @@ private void init(String id) { this.setQuota(new QuotaUICompoment(user, getLocale())); } } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error initializing page. " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -121,19 +121,15 @@ public void generateNewApiKey() { BeanHelper.error("Error generating API Key"); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error saving API key: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error saving API key. " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); } else { LOGGER.error(userMessage, exceptionWithMessage); } - } - catch (final ReloadBeforeSaveException r) { - LOGGER.error("Error saving API key. User has changed in store. Please reload user and generate key again ", r); - BeanHelper.error("Error saving API key. User has changed in store. Please generate key one more time."); - reloadPage(); - } catch (ImejiException ie) { + reloadPage(); + } catch (ImejiException ie) { LOGGER.error("Error generating API Key ", ie); BeanHelper.error("Error generating API Key"); } @@ -216,22 +212,19 @@ public void updateUser() throws ImejiException { BeanHelper.info(Imeji.RESOURCE_BUNDLE.getMessage("success_save", getLocale())); reloadPage(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error updating user: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error updating user: " + exceptionWithMessage.getUserMessage( getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); } else { LOGGER.error(userMessage, exceptionWithMessage); } + reloadPage(); } catch (final UnprocessableError e) { BeanHelper.error(e, getLocale()); LOGGER.error("Error updating user", e); - } catch (final ReloadBeforeSaveException rbse) { - BeanHelper.error("Error updating user. User object has been changed in database. Please try again."); - LOGGER.error("Error updating user. User object has been changed in database.", rbse); - reloadPage(); - } + } } } diff --git a/src/main/java/de/mpg/imeji/presentation/user/UserCreationBean.java b/src/main/java/de/mpg/imeji/presentation/user/UserCreationBean.java index 14eaf31ba..acacab43f 100644 --- a/src/main/java/de/mpg/imeji/presentation/user/UserCreationBean.java +++ b/src/main/java/de/mpg/imeji/presentation/user/UserCreationBean.java @@ -76,7 +76,7 @@ public String create() { reloadUserPage(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error creating user: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/user/UsersBean.java b/src/main/java/de/mpg/imeji/presentation/user/UsersBean.java index ed0716361..26e0453ab 100644 --- a/src/main/java/de/mpg/imeji/presentation/user/UsersBean.java +++ b/src/main/java/de/mpg/imeji/presentation/user/UsersBean.java @@ -92,7 +92,7 @@ public void retrieveGroup() { setGroup(c.retrieve(UrlHelper.getParameterValue("group"), getSessionUser())); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error loading user group: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error loading user group: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error("Error loading user group: " + exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -130,7 +130,7 @@ public String sendPassword() { BeanHelper.info(Imeji.RESOURCE_BUNDLE.getMessage("success_change_user_password", getLocale())); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error saving user's new password: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error saving user's new password: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error("Error saving user's new password: " + exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -138,10 +138,7 @@ public String sendPassword() { LOGGER.error(userMessage, exceptionWithMessage); } } - catch (ReloadBeforeSaveException r) { - BeanHelper.error("Error saving user's new password. User has changed in store. Please reload user and try again."); - LOGGER.error("Error saving user's new password. User has changed in store. Please reload user and try again. ", r); - } catch (final Exception e) { + catch (final Exception e) { BeanHelper.error("Could not update or send new password!"); LOGGER.error("Could not update or send new password", e); } @@ -180,7 +177,7 @@ public String deleteUser() { controller.delete(controller.retrieve(email, getSessionUser())); reload(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error deleting user: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error deleting user: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -208,7 +205,7 @@ public void removeUser() { reload(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error removing user. " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error removing user. " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error("Error removing user. " + exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -216,10 +213,7 @@ public void removeUser() { LOGGER.error(userMessage, exceptionWithMessage); } } - catch (ReloadBeforeSaveException r) { - BeanHelper.error("Error removing user. Please reload and try again."); - LOGGER.error("Error removing user. Please reload and try again. ", r); - } catch (Exception e) { + catch (Exception e) { LOGGER.error("Error removing user", e); } } @@ -236,17 +230,14 @@ public void reactivateUser() { controller.update(user, getSessionUser()); reload(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error reactivating user: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error reactivating user: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); } else { LOGGER.error(userMessage, exceptionWithMessage); } - } catch (ReloadBeforeSaveException r) { - BeanHelper.error("Error reactivating user. User has changed in store. Please reload user and try again."); - LOGGER.error("Error reactivating user. User has changed in store. Please reload user and try again. ", r); - } catch (Exception e) { + } catch (Exception e) { LOGGER.error("Error reactivating user", e); } } @@ -274,7 +265,7 @@ public void confirmRegistration() { reload(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error deleting registration. " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -283,8 +274,8 @@ public void confirmRegistration() { } } catch (final Exception e) { - BeanHelper.error("Error Deleting registration"); - LOGGER.error("Error Deleting registration", e); + BeanHelper.error("Error deleting registration"); + LOGGER.error("Error deleting registration", e); } } @@ -302,7 +293,7 @@ public String addToGroup() { this.group = userGroupService.addUserToGroup(getSessionUser(), this.group, userToAdd); FacesContext.getCurrentInstance().getExternalContext().redirect(getNavigation().getApplicationUrl() + "users?group=" + group.getId()); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage =exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -326,7 +317,7 @@ public String removeFromGroup() { FacesContext.getCurrentInstance().getExternalContext().redirect(getNavigation().getApplicationUrl() + "users?group=" + group.getId()); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error removing user from group: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error removing user from group: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/user/registration/RegistrationBean.java b/src/main/java/de/mpg/imeji/presentation/user/registration/RegistrationBean.java index 698740b6f..688b42b78 100644 --- a/src/main/java/de/mpg/imeji/presentation/user/registration/RegistrationBean.java +++ b/src/main/java/de/mpg/imeji/presentation/user/registration/RegistrationBean.java @@ -72,7 +72,7 @@ private void activateUser() { redirect(getNavigation().getHomeUrl() + "/pwdreset?from=registration"); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error activating user: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error activating user: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error("Error activating user: " + exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -123,7 +123,7 @@ public void register() throws IOException { registration_success = true; } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error registering user: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error registering user: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error("Error registering user: " + exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/user/subscription/SubscriptionBean.java b/src/main/java/de/mpg/imeji/presentation/user/subscription/SubscriptionBean.java index 0e4227913..c6a95bb01 100644 --- a/src/main/java/de/mpg/imeji/presentation/user/subscription/SubscriptionBean.java +++ b/src/main/java/de/mpg/imeji/presentation/user/subscription/SubscriptionBean.java @@ -58,7 +58,7 @@ public void construct() { initUser(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -80,7 +80,7 @@ public void init() { initGroups(retrieveCollections()); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error initializing page: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -209,7 +209,7 @@ public void subscribe(User user, CollectionImeji collection) { reload(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error subscribing to collection: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error subscribing to collection: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -238,7 +238,7 @@ public void unSubscribe(User user, CollectionImeji collection) { reload(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error unsubscribing from collection " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error unsubscribing from collection " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error("Error unsubscribing from collection " + exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -300,7 +300,7 @@ public void unSubscribe(Subscription subscription) { new SubscriptionService().unSubscribe(subscription, getSessionUser()); initGroups(retrieveCollections()); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error unsubscribing from collection: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error unsubscribing from collection: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error(exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/userGroup/UserGroupBean.java b/src/main/java/de/mpg/imeji/presentation/userGroup/UserGroupBean.java index 0f5bdfde6..92d5bb97f 100644 --- a/src/main/java/de/mpg/imeji/presentation/userGroup/UserGroupBean.java +++ b/src/main/java/de/mpg/imeji/presentation/userGroup/UserGroupBean.java @@ -71,7 +71,7 @@ public void init() { } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error reading user group: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error reading user group: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error("Error reading user group: " + exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -124,7 +124,7 @@ public void removeUserFromGroup(URI removeUserURI) throws IOException { reload(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Could not update user group : " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Could not update user group : " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error("Could not update user group : " + exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -186,7 +186,7 @@ public String create() { reload(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error creating user group: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error creating user group: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error("Error creating user group: " + exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -215,7 +215,7 @@ public void save() throws IOException { c.update(userGroup, getSessionUser()); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error updating user group: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error updating user group: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error("Error updating user group: " + exceptionWithMessage.getMessage(), exceptionWithMessage); @@ -326,7 +326,7 @@ public void addUser(User user) { reload(); } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error updating user group: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error updating user group: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error("Error updating user group: " + exceptionWithMessage.getMessage(), exceptionWithMessage); diff --git a/src/main/java/de/mpg/imeji/presentation/userGroup/UserGroupsBean.java b/src/main/java/de/mpg/imeji/presentation/userGroup/UserGroupsBean.java index 93f7a1eaa..b332391c1 100644 --- a/src/main/java/de/mpg/imeji/presentation/userGroup/UserGroupsBean.java +++ b/src/main/java/de/mpg/imeji/presentation/userGroup/UserGroupsBean.java @@ -106,7 +106,7 @@ public String remove() { } } catch (final ImejiExceptionWithUserMessage exceptionWithMessage) { - String userMessage = "Error removing group: " + Imeji.RESOURCE_BUNDLE.getMessage(exceptionWithMessage.getMessageLabel(), getLocale()); + String userMessage = "Error removing group: " + exceptionWithMessage.getUserMessage(getLocale()); BeanHelper.error(userMessage); if (exceptionWithMessage.getMessage() != null) { LOGGER.error("Error removing group: " + exceptionWithMessage.getMessage(), exceptionWithMessage);