Search in sources :

Example 61 with CommonException

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

the class DummyItsm method tryToFail.

private void tryToFail() throws CommonException {
    if (failureClass == null) {
        return;
    }
    CommonException exception;
    try {
        Constructor<? extends CommonException> constructor = failureClass.getConstructor(String.class);
        exception = constructor.newInstance("Simulated error: " + failureClass.getSimpleName());
    } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        throw new RuntimeException("Failed to fail: " + e.getMessage(), e);
    }
    throw exception;
}
Also used : CommonException(com.evolveum.midpoint.util.exception.CommonException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 62 with CommonException

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

the class PolicyRuleScriptExecutor method executeScriptsFromCollectedRules.

private <O extends ObjectType> void executeScriptsFromCollectedRules(List<EvaluatedPolicyRuleImpl> rules, LensContext<O> context, Task task, OperationResult parentResult) {
    // Must not be minor because of background OID information.
    OperationResult result = parentResult.createSubresult(OP_EXECUTE_SCRIPTS_FROM_RULES);
    try (RunAsRunner runAsRunner = runAsRunnerFactory.runner()) {
        for (EvaluatedPolicyRuleImpl rule : rules) {
            List<ScriptExecutionPolicyActionType> enabledActions = rule.getEnabledActions(ScriptExecutionPolicyActionType.class);
            LOGGER.trace("Rule {} has {} enabled script execution actions", rule, enabledActions.size());
            for (ScriptExecutionPolicyActionType action : enabledActions) {
                ActionContext actx = new ActionContext(action, rule, context, task, this);
                try {
                    // We should consider ordering actions to be executed by runAsRef to avoid unnecessary context switches.
                    runAsRunner.runAs(() -> executeScriptingAction(actx, result), actx.action.getRunAsRef(), result);
                } catch (CommonException e) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Couldn't execute scripting action - continuing with others (if present)", e);
                }
            }
        }
    } catch (Throwable t) {
        result.recordFatalError(t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
        // as we are used to. So this hack is definitely the lesser evil for now.
        if (result.getStatus() == OperationResultStatus.FATAL_ERROR) {
            result.setStatus(OperationResultStatus.PARTIAL_ERROR);
        }
    }
}
Also used : ScriptExecutionPolicyActionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptExecutionPolicyActionType) EvaluatedPolicyRuleImpl(com.evolveum.midpoint.model.impl.lens.EvaluatedPolicyRuleImpl) RunAsRunner(com.evolveum.midpoint.model.impl.security.RunAsRunner) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 63 with CommonException

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

the class ActivityBasedTaskRun method setupTaskArchetypeIfNeeded.

private void setupTaskArchetypeIfNeeded(OperationResult result) throws ActivityRunException {
    if (activityBasedTaskHandler.isAvoidAutoAssigningArchetypes()) {
        return;
    }
    try {
        RunningTask task = getRunningTask();
        String defaultArchetypeOid = activityTree.getRootActivity().getHandler().getDefaultArchetypeOid();
        if (defaultArchetypeOid != null) {
            task.addArchetypeInformationIfMissing(defaultArchetypeOid);
            task.flushPendingModifications(result);
        }
    } catch (CommonException e) {
        throw new ActivityRunException("Couldn't setup the task archetype", FATAL_ERROR, PERMANENT_ERROR, e);
    }
}
Also used : ActivityRunException(com.evolveum.midpoint.repo.common.activity.run.ActivityRunException) RunningTask(com.evolveum.midpoint.task.api.RunningTask) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 64 with CommonException

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

the class InitializableMixin method initialize.

/**
 * Initializes given object.
 *
 * - Precondition: lifecycle state is CREATED.
 * - Postcondition (unless exception is thrown): lifecycle state is INITIALIZED or INITIALIZATION_FAILED.
 */
default void initialize(Task task, OperationResult result) {
    InitializationState state = getInitializationState();
    getLogger().trace("Item before initialization (state: {}):\n{}", state, debugDumpLazily());
    try {
        state.moveFromCreatedToInitializing();
        try {
            initializeInternal(task, result);
        } catch (NotApplicableException e) {
            state.recordNotApplicable();
            result.recordNotApplicable();
        }
        state.moveFromInitializingToInitialized();
        checkConsistence();
    } catch (CommonException | EncryptionException | RuntimeException e) {
        // TODO change to debug
        getLogger().warn("Got an exception during initialization of {}", this, e);
        getInitializationState().recordInitializationFailed(e);
        result.recordFatalError(e);
    }
    state.checkAfterInitialization();
    getLogger().trace("Item after initialization (state: {}):\n{}", state, debugDumpLazily());
}
Also used : InitializationState(com.evolveum.midpoint.provisioning.util.InitializationState) NotApplicableException(com.evolveum.midpoint.provisioning.impl.shadows.sync.NotApplicableException) EncryptionException(com.evolveum.midpoint.prism.crypto.EncryptionException) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 65 with CommonException

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

the class ClassicDashboardReportExportActivityRun method iterateOverItemsInBucket.

@Override
public void iterateOverItemsInBucket(OperationResult result) throws CommonException {
    // Issue the search to audit or model/repository
    // And use the following handler to handle the results
    List<DashboardWidgetType> widgets = support.getDashboard().getWidget();
    AtomicInteger widgetSequence = new AtomicInteger(1);
    for (DashboardWidgetType widget : widgets) {
        ExportDashboardReportLine<Containerable> widgetLine = new ExportDashboardReportLine<>(widgetSequence.getAndIncrement(), widget);
        ItemProcessingRequest<ExportDashboardReportLine<Containerable>> widgetRequest = new ExportDashboardReportLineProcessingRequest(widgetLine, this);
        coordinator.submit(widgetRequest, result);
        if (support.isWidgetTableVisible()) {
            AtomicInteger sequence = new AtomicInteger(1);
            Handler<Containerable> handler = record -> {
                ExportDashboardReportLine<Containerable> line = new ExportDashboardReportLine<>(sequence.getAndIncrement(), record, widget.getIdentifier());
                ItemProcessingRequest<ExportDashboardReportLine<Containerable>> request = new ExportDashboardReportLineProcessingRequest(line, this);
                coordinator.submit(request, result);
                return true;
            };
            DashboardWidgetHolder holder = mapOfWidgetsController.get(widget.getIdentifier());
            ContainerableReportDataSource searchSpecificationHolder = holder.getSearchSpecificationHolder();
            searchSpecificationHolder.run(handler, result);
        }
    }
}
Also used : ItemProcessingRequest(com.evolveum.midpoint.repo.common.activity.run.processing.ItemProcessingRequest) ActivityRunException(com.evolveum.midpoint.repo.common.activity.run.ActivityRunException) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) com.evolveum.midpoint.repo.common.activity.run(com.evolveum.midpoint.repo.common.activity.run) RunningTask(com.evolveum.midpoint.task.api.RunningTask) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) com.evolveum.midpoint.report.impl.controller(com.evolveum.midpoint.report.impl.controller) ReportServiceImpl(com.evolveum.midpoint.report.impl.ReportServiceImpl) CommonException(com.evolveum.midpoint.util.exception.CommonException) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Handler(com.evolveum.midpoint.util.Handler) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Containerable(com.evolveum.midpoint.prism.Containerable) DashboardWidgetHolder(com.evolveum.midpoint.report.impl.activity.ExportDashboardActivitySupport.DashboardWidgetHolder) NotNull(org.jetbrains.annotations.NotNull) ReportUtils(com.evolveum.midpoint.report.impl.ReportUtils) DashboardWidgetHolder(com.evolveum.midpoint.report.impl.activity.ExportDashboardActivitySupport.DashboardWidgetHolder) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ItemProcessingRequest(com.evolveum.midpoint.repo.common.activity.run.processing.ItemProcessingRequest) Containerable(com.evolveum.midpoint.prism.Containerable)

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