Search in sources :

Example 66 with CommonException

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;
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) ArrayList(java.util.ArrayList) CommonException(com.evolveum.midpoint.util.exception.CommonException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 67 with CommonException

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;
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) ArrayList(java.util.ArrayList) CommonException(com.evolveum.midpoint.util.exception.CommonException) CertificationPolicyActionType(com.evolveum.midpoint.xml.ns._public.common.common_3.CertificationPolicyActionType) LensElementContext(com.evolveum.midpoint.model.impl.lens.LensElementContext)

Example 68 with CommonException

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);
}
Also used : SystemException(com.evolveum.midpoint.util.exception.SystemException) LocalizationUtil.createLocalizableMessageType(com.evolveum.midpoint.schema.util.LocalizationUtil.createLocalizableMessageType) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 69 with CommonException

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();
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) WorkersReconciliation(com.evolveum.midpoint.repo.common.activity.run.distribution.WorkersReconciliation) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) WorkersReconciliationOptions(com.evolveum.midpoint.repo.common.activity.run.distribution.WorkersReconciliationOptions) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with CommonException

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);
    }
}
Also used : ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) CommonException(com.evolveum.midpoint.util.exception.CommonException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

CommonException (com.evolveum.midpoint.util.exception.CommonException)71 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)44 Task (com.evolveum.midpoint.task.api.Task)33 PrismObject (com.evolveum.midpoint.prism.PrismObject)14 SystemException (com.evolveum.midpoint.util.exception.SystemException)14 ArrayList (java.util.ArrayList)12 ModelService (com.evolveum.midpoint.model.api.ModelService)11 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)8 NotNull (org.jetbrains.annotations.NotNull)7 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 ActivityRunException (com.evolveum.midpoint.repo.common.activity.run.ActivityRunException)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 RestartResponseException (org.apache.wicket.RestartResponseException)5 ModelInteractionService (com.evolveum.midpoint.model.api.ModelInteractionService)4 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)4 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)4