@Override public String getLocalizedMessage() { return localizedUserFriendlyMessage != null ? localizedUserFriendlyMessage : getMessage(); }
protected String getTranslatedMessage(CommonException e) { if (e.getUserFriendlyMessage() != null) { return localizationService.translate(e.getUserFriendlyMessage(), Locale.US); } else { return e.getMessage(); } }
public <T extends ObjectType> T getObjectSimple(Class<T> clazz, String oid, GetOperationOptions options, Task task, OperationResult result) throws ObjectNotFoundException { try { return getObject(clazz, oid, SelectorOptions.createCollection(options), task, result); } catch (SystemException ex) { throw ex; } catch (ObjectNotFoundException ex) { throw ex; } catch (CommonException ex) { LoggingUtils.logException(LOGGER, "Error resolving object with oid {}", ex, oid); // Add to result only a short version of the error, the details will be in subresults result.recordFatalError( "Couldn't get object with oid '" + oid + "': "+ex.getErrorTypeMessage(), ex); throw new SystemException("Error resolving object with oid '" + oid + "': "+ex.getMessage(), ex); } }
@Override public <T extends CommonException> T translate(T e) { if (e == null) { return null; } if (e.getUserFriendlyMessage() == null) { return e; } if (e.getTechnicalMessage() == null) { e.setTechnicalMessage(translate(e.getUserFriendlyMessage(), Locale.US)); } if (e.getLocalizedUserFriendlyMessage() == null) { e.setLocalizedUserFriendlyMessage(translate(e.getUserFriendlyMessage(), Locale.getDefault())); } return e; } }
@Override public String toString() { if (userFriendlyMessage == null) { return super.toString(); } else { String technicalMessage = getMessage(); String localizedUserFriendlyMessage = getLocalizedMessage(); // this one is used by super.toString String technicalMessagePart; if (technicalMessage != null && !Objects.equals(technicalMessage, localizedUserFriendlyMessage)) { technicalMessagePart = " [" + technicalMessage + "]"; } else { technicalMessagePart = ""; } // TODO consider if we really want to display short dump of userFriendlyMessage even if localized and/or english message is present return super.toString() + technicalMessagePart + " [" + userFriendlyMessage.shortDump() + "]"; } } }
public static LocalizableMessage getUserFriendlyMessage(Throwable cause) { while (cause != null) { if (cause instanceof CommonException) { LocalizableMessage userFriendlyMessage = ((CommonException)cause).getUserFriendlyMessage(); if (userFriendlyMessage != null) { return userFriendlyMessage; } } cause = cause.getCause(); } return null; }
/** * Records result from a common exception type. This automatically * determines status and also sets appropriate message. * * @param exception * common exception */ public void record(CommonException exception) { // TODO: switch to a localized message later // Exception is a fatal error in this context recordFatalError(exception.getErrorTypeMessage(), exception); }
public String getLocalizedUserFriendlyMessage() { return getLocalizedMessage(); }
protected void assertExceptionUserFriendly(CommonException e, String expectedMessage) { LocalizableMessage userFriendlyMessage = e.getUserFriendlyMessage(); assertNotNull("No user friendly exception message", userFriendlyMessage); assertEquals("Unexpected user friendly exception fallback message", expectedMessage, userFriendlyMessage.getFallbackMessage()); }
@Override public OrgType getOrgByOid(String oid, boolean preAuthorized) throws SchemaException { try { return getObject(OrgType.class, oid, preAuthorized); } catch (ObjectNotFoundException|SecurityViolationException e) { return null; } catch (CommunicationException|ConfigurationException|ExpressionEvaluationException e) { throw new SystemException("Couldn't get org: " + e.getMessage(), e); // really shouldn't occur } }
protected void assertExceptionUserFriendly(CommonException e, String expectedMessage) { LocalizableMessage userFriendlyMessage = e.getUserFriendlyMessage(); assertNotNull("No user friendly exception message", userFriendlyMessage); assertEquals("Unexpected user friendly exception fallback message", expectedMessage, userFriendlyMessage.getFallbackMessage()); }
public static <O extends ObjectType> ModelContext<O> unwrapModelContext(LensContextType lensContextType, ModelInteractionService modelInteractionService, Task opTask, OperationResult result) throws ObjectNotFoundException { if (lensContextType != null) { try { return modelInteractionService.unwrapModelContext(lensContextType, opTask, result); } catch (SchemaException | CommunicationException | ConfigurationException |ExpressionEvaluationException e) { // todo treat appropriately throw new SystemException("Couldn't access model operation context in task: " + e.getMessage(), e); } } else { return null; } } }
public Collection<ObjectDeltaOperation<? extends ObjectType>> applyDelta(ObjectDelta delta, ModelExecuteOptions options, ExecutionContext context, OperationResult result) throws ScriptExecutionException { try { return modelService.executeChanges(Collections.singleton(delta), options, context.getTask(), result); } catch (ObjectAlreadyExistsException|ObjectNotFoundException|SchemaException|ExpressionEvaluationException|CommunicationException|ConfigurationException|PolicyViolationException|SecurityViolationException e) { throw new ScriptExecutionException("Couldn't modify object: " + e.getMessage(), e); } }
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { try { return getPrincipal(username); } catch (ObjectNotFoundException e) { throw new UsernameNotFoundException(e.getMessage(), e); } catch (SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) { throw new SystemException(e.getMessage(), e); } }
private PrismObject<SystemConfigurationType> getSystemConfiguration(OperationResult result) { PrismObject<SystemConfigurationType> systemConfiguration = null; try { // TODO: use SystemObjectCache instead? systemConfiguration = repositoryService.getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, result); } catch (ObjectNotFoundException | SchemaException e) { LOGGER.warn("No system configuration: {}", e.getMessage(), e); } return systemConfiguration; }
protected RoleType getRoleSimple(String oid) { try { return getRole(oid).asObjectable(); } catch (CommonException e) { throw new SystemException("Unexpected exception while getting role " + oid + ": " + e.getMessage(), e); } }
public Collection<ObjectDeltaOperation<? extends ObjectType>> applyDelta(ObjectDelta<? extends ObjectType> delta, ModelExecuteOptions options, boolean dryRun, ExecutionContext context, OperationResult result) throws ScriptExecutionException { try { if (dryRun) { modelInteractionService.previewChanges(Collections.singleton(delta), options, context.getTask(), result); return null; } else { return modelService.executeChanges(Collections.singleton(delta), options, context.getTask(), result); } } catch (ObjectAlreadyExistsException|ObjectNotFoundException|SchemaException|ExpressionEvaluationException|CommunicationException|ConfigurationException|PolicyViolationException|SecurityViolationException e) { throw new ScriptExecutionException("Couldn't modify object: " + e.getMessage(), e); } }
private void authenticateUser(PrismObject<UserType> user, String enteredUsername, ConnectionEnvironment connEnv, ContainerRequestContext requestCtx) { try { securityContextManager.setupPreAuthenticatedSecurityContext(user); } catch (SchemaException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException e) { securityHelper.auditLoginFailure(enteredUsername, user.asObjectable(), connEnv, "Schema error: "+e.getMessage()); requestCtx.abortWith(Response.status(Status.BAD_REQUEST).build()); // return false; } LOGGER.trace("Authenticated to REST service as {}", user); }
<T extends ObjectType> List<T> searchObjects(Class<T> type, ObjectQuery query) { List<T> ret = new ArrayList<>(); Task task = taskManager.createTaskInstance(); try { List<PrismObject<T>> list = model.searchObjects(type, query, null, task, task.getResult()).getList(); for (PrismObject<T> po : list) { ret.add(po.asObjectable()); } } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) { LOGGER.error("Could not search objects of type: " + type + " with query " + query + ". Reason: " + e.getMessage()); } return ret; }
@Override public <O extends ObjectType> HookOperationMode invoke(@NotNull ModelContext<O> context, @NotNull Task task, @NotNull OperationResult result) { if (context.getState() != ModelState.FINAL) { return HookOperationMode.FOREGROUND; } LensElementContext<O> focusContext = (LensElementContext<O>) context.getFocusContext(); if (focusContext == null || !FocusType.class.isAssignableFrom(focusContext.getObjectTypeClass())) { return HookOperationMode.FOREGROUND; } List<CertificationPolicyActionType> actions = new ArrayList<>(); actions.addAll(getFocusCertificationActions(context)); actions.addAll(getAssignmentCertificationActions(context)); try { certificationManager.startAdHocCertifications(focusContext.getObjectAny(), actions, task, result); } catch (CommonException e) { throw new SystemException("Couldn't start ad-hoc campaign(s): " + e.getMessage(), e); } return HookOperationMode.FOREGROUND; }