diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebModelServiceUtils.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebModelServiceUtils.java index 6f5b378d8ce..da7e98fffc1 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebModelServiceUtils.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebModelServiceUtils.java @@ -523,6 +523,9 @@ public static void save(Collection> deltas, Mo page.getModelService().executeChanges(deltas, options, task, result); } catch (Exception ex) { + if (ex instanceof CommonException) { + subResult.setUserFriendlyMessage(((CommonException) ex).getUserFriendlyMessage()); + } subResult.recordFatalError(ex.getMessage()); LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save object", ex); } finally { diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/login/PageSelfRegistration.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/login/PageSelfRegistration.java index a6406b260c3..42d8c649519 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/login/PageSelfRegistration.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/login/PageSelfRegistration.java @@ -355,8 +355,14 @@ public OperationResult run() { LOGGER.trace("Registration for user {} was successfull.", getUserModel().getObject()); } else { + String message; + if (result.getUserFriendlyMessage() != null) { + message = WebModelServiceUtils.translateMessage(result, this); + } else { + message = result.getMessage(); + } getSession().error( - createStringResource("PageSelfRegistration.registration.error", result.getMessage()) + createStringResource("PageSelfRegistration.registration.error", message) .getString()); // removePassword(target); updateCaptcha(target); diff --git a/model/model-common/src/main/java/com/evolveum/midpoint/model/common/expression/script/ScriptExpressionEvaluationContext.java b/model/model-common/src/main/java/com/evolveum/midpoint/model/common/expression/script/ScriptExpressionEvaluationContext.java index c7a28dd2424..4d883d3bd49 100644 --- a/model/model-common/src/main/java/com/evolveum/midpoint/model/common/expression/script/ScriptExpressionEvaluationContext.java +++ b/model/model-common/src/main/java/com/evolveum/midpoint/model/common/expression/script/ScriptExpressionEvaluationContext.java @@ -160,13 +160,15 @@ public void setResult(OperationResult result) { this.result = result; } - ScriptExpressionEvaluationContext setupThreadLocal() { + @SuppressWarnings("WeakerAccess") // Can be used e.g. from the overlay code + public ScriptExpressionEvaluationContext setupThreadLocal() { ScriptExpressionEvaluationContext oldContext = THREAD_LOCAL_CONTEXT.get(); THREAD_LOCAL_CONTEXT.set(this); return oldContext; } - void cleanupThreadLocal(ScriptExpressionEvaluationContext oldContext) { + @SuppressWarnings("WeakerAccess") // Can be used e.g. from the overlay code + public void cleanupThreadLocal(ScriptExpressionEvaluationContext oldContext) { THREAD_LOCAL_CONTEXT.set(oldContext); } diff --git a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java index 75e0152d81d..72d13a6a65a 100644 --- a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java +++ b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java @@ -316,30 +316,34 @@ public String getContentType() { mimeMessage.setContent(multipart); javax.mail.Transport t = session.getTransport("smtp"); - if (StringUtils.isNotEmpty(mailServerConfigurationType.getUsername())) { - ProtectedStringType passwordProtected = mailServerConfigurationType.getPassword(); - String password = null; - if (passwordProtected != null) { - try { - password = protector.decryptString(passwordProtected); - } catch (EncryptionException e) { - String msg = "Couldn't send mail message to " + mailMessage.getTo() + " via " + host + ", because the plaintext password value couldn't be obtained. Trying another mail server, if there is any."; - LoggingUtils.logException(LOGGER, msg, e); - resultForServer.recordFatalError(msg, e); - continue; + try { + if (StringUtils.isNotEmpty(mailServerConfigurationType.getUsername())) { + ProtectedStringType passwordProtected = mailServerConfigurationType.getPassword(); + String password = null; + if (passwordProtected != null) { + try { + password = protector.decryptString(passwordProtected); + } catch (EncryptionException e) { + String msg = "Couldn't send mail message to " + mailMessage.getTo() + " via " + host + ", because the plaintext password value couldn't be obtained. Trying another mail server, if there is any."; + LoggingUtils.logException(LOGGER, msg, e); + resultForServer.recordFatalError(msg, e); + continue; + } } + t.connect(mailServerConfigurationType.getUsername(), password); + } else { + t.connect(); } - t.connect(mailServerConfigurationType.getUsername(), password); - } else { - t.connect(); + t.sendMessage(mimeMessage, mimeMessage.getAllRecipients()); + LOGGER.info("Message sent successfully to " + mailMessage.getTo() + " via server " + host + "."); + resultForServer.recordSuccess(); + result.recordSuccess(); + long duration = System.currentTimeMillis() - start; + task.recordState("Notification mail sent successfully via " + host + ", in " + duration + " ms overall."); + task.recordNotificationOperation(NAME, true, duration); + } finally { + t.close(); } - t.sendMessage(mimeMessage, mimeMessage.getAllRecipients()); - LOGGER.info("Message sent successfully to " + mailMessage.getTo() + " via server " + host + "."); - resultForServer.recordSuccess(); - result.recordSuccess(); - long duration = System.currentTimeMillis() - start; - task.recordState("Notification mail sent successfully via " + host + ", in " + duration + " ms overall."); - task.recordNotificationOperation(NAME, true, duration); return; } catch (MessagingException e) { String msg = "Couldn't send mail message to " + mailMessage.getTo() + " via " + host + ", trying another mail server, if there is any"; diff --git a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java index 25f18f37650..94435537e6a 100644 --- a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java +++ b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java @@ -236,14 +236,16 @@ public boolean hasContentToShow(boolean watchAuxiliaryAttributes) { ObjectDelta summarizedDelta; try { summarizedDelta = getSummarizedFocusDeltas(); - if (!summarizedDelta.isModify()) { + if (summarizedDelta == null) { + return false; + } else if (summarizedDelta.isAdd() || summarizedDelta.isDelete()) { return true; - } else if (!getTextFormatter().containsVisibleModifiedItems(summarizedDelta.getModifications(), + } else if (getTextFormatter().containsVisibleModifiedItems(summarizedDelta.getModifications(), false, watchAuxiliaryAttributes)) { + return true; + } else { LOGGER.trace("No relevant attributes in modify delta (watchAux={})", watchAuxiliaryAttributes); return false; - } else { - return true; } } catch (Throwable t) { LoggingUtils.logUnexpectedException(LOGGER, "Unable to check if there's content to show; focus context = {}", t, focusContext.debugDump()); @@ -255,7 +257,9 @@ public boolean hasContentToShow(boolean watchAuxiliaryAttributes) { public String getContentAsFormattedList(boolean showAuxiliaryAttributes) { try { ObjectDelta summarizedDelta = getSummarizedFocusDeltas(); - if (summarizedDelta.isAdd()) { + if (summarizedDelta == null) { + return ""; // should not happen + } else if (summarizedDelta.isAdd()) { return getTextFormatter().formatObject(summarizedDelta.getObjectToAdd(), false, showAuxiliaryAttributes); } else if (summarizedDelta.isModify()) { ModelElementContext focusContext = modelContext.getFocusContext(); diff --git a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/data/common/enums/RTaskWaitingReason.java b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/data/common/enums/RTaskWaitingReason.java index 8207bbcac7f..c745b6bf378 100644 --- a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/data/common/enums/RTaskWaitingReason.java +++ b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/data/common/enums/RTaskWaitingReason.java @@ -18,6 +18,9 @@ public enum RTaskWaitingReason implements SchemaEnum { OTHER_TASKS(TaskWaitingReasonType.OTHER_TASKS), + // See MID-6117. + PLACEHOLDER(null), + OTHER(TaskWaitingReasonType.OTHER); private TaskWaitingReasonType reason; diff --git a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/util/RUtil.java b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/util/RUtil.java index 771af5cfbd2..555737c1eb7 100644 --- a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/util/RUtil.java +++ b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/util/RUtil.java @@ -317,8 +317,9 @@ public static T getRepoEnumValue(Object object, Class } Object[] values = type.getEnumConstants(); for (Object value : values) { + //noinspection unchecked T schemaEnum = (T) value; - if (schemaEnum.getSchemaValue().equals(object)) { + if (object.equals(schemaEnum.getSchemaValue())) { return schemaEnum; } }