use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class ObjectCreator method execute.
public List<O> execute(OperationResult result) throws CommonException {
List<O> objects = new ArrayList<>(objectCount);
long start = System.currentTimeMillis();
for (int i = 0; i < objectCount; i++) {
O object;
try {
object = type.getDeclaredConstructor(PrismContext.class).newInstance(PrismContext.get());
} catch (Exception e) {
throw new SystemException(e);
}
object.setName(PolyStringType.fromOrig(createName(i)));
if (customizer != null) {
customizer.customize(object, i);
}
realCreator.create(object, result);
objects.add(object);
}
long duration = System.currentTimeMillis() - start;
System.out.printf("Created %d objects in %d milliseconds (%,.1f ms per object)\n", objectCount, duration, (float) duration / (float) objectCount);
return objects;
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class CertificationHook method invoke.
@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;
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class PolicyRuleBasedAspect method processNameFromApprovalActions.
// corresponds with ConstraintEvaluationHelper.createVariablesMap
private LocalizableMessage processNameFromApprovalActions(ApprovalSchemaBuilder.Result schemaBuilderResult, @Nullable EvaluatedAssignment<?> evaluatedAssignment, ModelInvocationContext<?> ctx, OperationResult result) {
if (schemaBuilderResult.approvalDisplayName == null) {
return null;
}
VariablesMap variables = new VariablesMap();
ObjectType focusType = ctx.getFocusObjectNewOrOld();
variables.put(ExpressionConstants.VAR_OBJECT, focusType, focusType.asPrismObject().getDefinition());
variables.put(ExpressionConstants.VAR_OBJECT_DISPLAY_INFORMATION, createLocalizableMessageType(createDisplayInformation(asPrismObject(focusType), false)), LocalizableMessageType.class);
if (evaluatedAssignment != null) {
variables.put(ExpressionConstants.VAR_TARGET, evaluatedAssignment.getTarget(), evaluatedAssignment.getTarget().getDefinition());
variables.put(ExpressionConstants.VAR_TARGET_DISPLAY_INFORMATION, createLocalizableMessageType(createDisplayInformation(evaluatedAssignment.getTarget(), false)), LocalizableMessageType.class);
variables.put(ExpressionConstants.VAR_EVALUATED_ASSIGNMENT, evaluatedAssignment, EvaluatedAssignment.class);
// Wrong ... but this will get reworked in 4.0 anyway.
variables.put(ExpressionConstants.VAR_ASSIGNMENT, evaluatedAssignment.getAssignment(), AssignmentType.class);
} else {
// Wrong ... but this will get reworked in 4.0 anyway.
variables.put(ExpressionConstants.VAR_TARGET, null, ObjectType.class);
variables.put(ExpressionConstants.VAR_TARGET_DISPLAY_INFORMATION, null, LocalizableMessageType.class);
variables.put(ExpressionConstants.VAR_EVALUATED_ASSIGNMENT, null, EvaluatedAssignment.class);
// Wrong ... but this will get reworked in 4.0 anyway.
variables.put(ExpressionConstants.VAR_ASSIGNMENT, null, AssignmentType.class);
}
LocalizableMessageType localizableMessageType;
try {
localizableMessageType = modelInteractionService.createLocalizableMessageType(schemaBuilderResult.approvalDisplayName, variables, ctx.task, result);
} catch (CommonException | RuntimeException e) {
throw new SystemException("Couldn't create localizable message for approval display name: " + e.getMessage(), e);
}
return LocalizationUtil.toLocalizableMessage(localizableMessageType);
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class TaskActivityManager method reconcileWorkersForActivity.
/**
* Note: common exceptions are not propagated - these are reflected only in the operation result
*/
@NotNull
private WorkersReconciliationResultType reconcileWorkersForActivity(@NotNull Task rootTask, @NotNull TaskType coordinatorTaskBean, @NotNull ActivityPath path, OperationResult parentResult) {
OperationResult result = parentResult.subresult(OP_RECONCILE_WORKERS_FOR_ACTIVITY).addArbitraryObjectAsParam("rootTask", rootTask).addParam("coordinatorTask", coordinatorTaskBean).addArbitraryObjectAsParam("path", path).build();
try {
Task coordinatorTask = taskManager.createTaskInstance(coordinatorTaskBean.asPrismObject(), result);
WorkersReconciliationOptions options = new WorkersReconciliationOptions();
// TODO
options.setDontCloseWorkersWhenWorkDone(true);
return new WorkersReconciliation(rootTask, coordinatorTask, path, options, beans).execute(result);
} catch (CommonException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't reconcile workers for activity path '{}' in {}/{}", e, path, coordinatorTaskBean, rootTask);
result.recordFatalError(e);
return new WorkersReconciliationResultType(prismContext).status(OperationResultStatusType.FATAL_ERROR);
} catch (Throwable t) {
result.recordFatalError(t);
throw t;
} finally {
result.computeStatusIfUnknown();
}
}
use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.
the class TaskActivityManager method purgeState.
private void purgeState(TaskType task, ActivityPath activityPath, ActivityStateType activityState, OperationResult result) {
try {
TaskActivityStateType taskActivityState = task.getActivityState();
ItemPath stateItemPath = ActivityStateUtil.getStateItemPath(taskActivityState, activityPath);
List<ItemDelta<?, ?>> itemDeltas = PrismContext.get().deltaFor(TaskType.class).item(stateItemPath.append(ActivityStateType.F_RESULT_STATUS)).replace().item(stateItemPath.append(ActivityStateType.F_PROGRESS)).replace().item(stateItemPath.append(ActivityStateType.F_STATISTICS)).replace().item(stateItemPath.append(ActivityStateType.F_BUCKETING)).replace().item(stateItemPath.append(ActivityStateType.F_COUNTERS)).replace().asItemDeltas();
if (!(activityState.getWorkState() instanceof DelegationWorkStateType)) {
itemDeltas.addAll(PrismContext.get().deltaFor(TaskType.class).item(stateItemPath.append(ActivityStateType.F_REALIZATION_STATE)).replace().item(stateItemPath.append(ActivityStateType.F_WORK_STATE)).replace().asItemDeltas());
}
plainRepositoryService.modifyObject(TaskType.class, task.getOid(), itemDeltas, result);
LOGGER.info("Purged activity state for '{}' in {}", activityPath, task);
} catch (CommonException e) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete state for activity path '{}' in {}", e, activityPath, task);
}
}
Aggregations