Search in sources :

Example 21 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class PageAttorneySelection method getAttorneySelectionQuery.

private ObjectQuery getAttorneySelectionQuery() {
    ModelInteractionService service = getModelInteractionService();
    Task task = createSimpleTask(OPERATION_GET_DONOR_FILTER);
    try {
        ObjectQuery query = PageAttorneySelection.this.getPrismContext().queryFactory().createQuery();
        // todo target authorization action
        ObjectFilter filter = service.getDonorFilter(UserType.class, null, null, task, task.getResult());
        query.addFilter(filter);
        return query;
    } catch (CommonException ex) {
        LOGGER.error("Couldn't get donor filter, reason: {}", ex.getMessage());
        LOGGER.debug("Couldn't get donor filter", ex);
        PageError error = new PageError(ex);
        throw new RestartResponseException(error);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ModelInteractionService(com.evolveum.midpoint.model.api.ModelInteractionService) RestartResponseException(org.apache.wicket.RestartResponseException) PageError(com.evolveum.midpoint.web.page.error.PageError) CommonException(com.evolveum.midpoint.util.exception.CommonException) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 22 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class ActivityBasedTaskRun method run.

@NotNull
@Override
public TaskRunResult run(OperationResult result) throws TaskException {
    try {
        activityTree = ActivityTree.create(getRootTask(), getBeans());
        localRootPath = ActivityStateUtil.getLocalRootPath(runningTask.getWorkState());
        localRootActivity = activityTree.getActivity(localRootPath);
        localRootActivity.setLocalRoot(true);
    } catch (CommonException e) {
        throw new TaskException("Couldn't initialize activity tree", FATAL_ERROR, PERMANENT_ERROR, e);
    }
    if (localRootActivity.isSkipped()) {
        LOGGER.trace("Local root activity is skipped, exiting");
        return TaskRunResult.createNotApplicableTaskRunResult();
    }
    logStart();
    try {
        if (isRootRun()) {
            setupTaskArchetypeIfNeeded(result);
            updateStateOnRootRunStart(result);
        }
        AbstractActivityRun<?, ?, ?> localRootRun = localRootActivity.createRun(this, result);
        ActivityRunResult runResult = localRootRun.run(result);
        if (isRootRun()) {
            updateStateOnRootRunEnd(runResult, result);
        }
        logEnd(localRootRun, runResult);
        return runResult.createTaskRunResult();
    } catch (ActivityRunException e) {
        // These should be only really unexpected ones. So we won't bother with e.g. updating the tree state.
        logException(e);
        throw e.toTaskException();
    } catch (Throwable t) {
        logException(t);
        throw t;
    }
}
Also used : TaskException(com.evolveum.midpoint.task.api.TaskException) ActivityRunException(com.evolveum.midpoint.repo.common.activity.run.ActivityRunException) ActivityRunResult(com.evolveum.midpoint.repo.common.activity.run.ActivityRunResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) NotNull(org.jetbrains.annotations.NotNull)

Example 23 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class ActivityTreePurger method purge.

/**
 * Purges state (including task-level stats) from current task and its subtasks. Deletes subtasks if possible.
 *
 * * Pre: task is an execution root
 * * Post: task is refreshed
 */
public void purge(OperationResult result) throws ActivityRunException {
    try {
        boolean canDeleteRoot = purgeInTasksRecursively(ActivityPath.empty(), taskRun.getRunningTask(), result);
        if (canDeleteRoot) {
            taskRun.getRunningTask().restartCollectingStatisticsFromZero();
            taskRun.getRunningTask().updateAndStoreStatisticsIntoRepository(true, result);
        }
    } catch (CommonException e) {
        throw new ActivityRunException("Couldn't purge activity tree state", FATAL_ERROR, PERMANENT_ERROR, e);
    }
}
Also used : ActivityRunException(com.evolveum.midpoint.repo.common.activity.run.ActivityRunException) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 24 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class AbstractActivityRun method updateAndCloseActivityState.

/**
 * Updates the activity state with the result of the run.
 * Stores also the live values of progress/statistics into the current task.
 */
private void updateAndCloseActivityState(ActivityRunResult runResult, OperationResult result) throws ActivityRunException {
    activityState.updateProgressAndStatisticsNoCommit();
    completeRunResult(runResult);
    OperationResultStatus currentResultStatus = runResult.getOperationResultStatus();
    if (runResult.isFinished()) {
        // Note the asymmetry: "in progress" (IN_PROGRESS_LOCAL, IN_PROGRESS_DISTRIBUTED, IN_PROGRESS_DELEGATED)
        // states, along with the timestamp, are written in subclasses. The "complete" state, along with the timestamp,
        // is written here.
        activityState.markComplete(currentResultStatus, endTimestamp);
    } else if (currentResultStatus != null && currentResultStatus != activityState.getResultStatus()) {
        activityState.setResultStatus(currentResultStatus);
    }
    try {
        getRunningTask().updateAndStoreStatisticsIntoRepository(true, // Contains implicit task flush
        result);
    } catch (CommonException e) {
        throw new ActivityRunException("Couldn't update task when updating and closing activity state", FATAL_ERROR, PERMANENT_ERROR, e);
    }
    activityState.close();
}
Also used : OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 25 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class TaskActivityManager method deleteState.

private void deleteState(TaskType task, ActivityPath activityPath, OperationResult result) {
    try {
        TaskActivityStateType taskActivityState = task.getActivityState();
        ItemPath stateItemPath = ActivityStateUtil.getStateItemPath(taskActivityState, activityPath);
        List<ItemDelta<?, ?>> itemDeltas;
        if (activityPath.equals(ActivityStateUtil.getLocalRootPath(taskActivityState))) {
            // This is the [local] root activity. Delete everything!
            itemDeltas = PrismContext.get().deltaFor(TaskType.class).item(TaskType.F_ACTIVITY_STATE).replace().asItemDeltas();
        } else {
            Long id = ItemPath.toId(stateItemPath.last());
            assert id != null;
            itemDeltas = PrismContext.get().deltaFor(TaskType.class).item(stateItemPath.allExceptLast()).delete(new ActivityStateType().id(id)).asItemDeltas();
        }
        plainRepositoryService.modifyObject(TaskType.class, task.getOid(), itemDeltas, result);
        LOGGER.info("Deleted 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