Search in sources :

Example 1 with LensContextType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType in project midpoint by Evolveum.

the class TaskOperationPanel method initLayout.

protected void initLayout() {
    final LensContextType lensContextType = getLensContextType();
    LoadableModel<ModelOperationStatusDto> operationStatusModel = null;
    if (lensContextType != null) {
        operationStatusModel = new LoadableModel<ModelOperationStatusDto>() {

            @Override
            protected ModelOperationStatusDto load() {
                Task task = getPageBase().createSimpleTask(OPERATION_LOAD_SCENE_DTO);
                OperationResult result = task.getResult();
                ModelContext ctx;
                try {
                    ctx = ModelContextUtil.unwrapModelContext(lensContextType, getPageBase().getModelInteractionService(), task, result);
                } catch (ObjectNotFoundException e) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Unexpected error, cannot get real value for model context", e, e.getMessage());
                    return null;
                }
                return new ModelOperationStatusDto(ctx, getPageBase().getModelInteractionService(), task, result);
            }
        };
    }
    ModelOperationStatusPanel panel = new ModelOperationStatusPanel(ID_MODEL_OPERATION_STATUS_PANEL, operationStatusModel);
    panel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return lensContextType != null;
        }
    });
    add(panel);
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) Task(com.evolveum.midpoint.task.api.Task) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ModelOperationStatusDto(com.evolveum.midpoint.web.component.model.operationStatus.ModelOperationStatusDto) LensContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType) ModelOperationStatusPanel(com.evolveum.midpoint.web.component.model.operationStatus.ModelOperationStatusPanel)

Example 2 with LensContextType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType in project midpoint by Evolveum.

the class TestParseModelContext method testParseModelContextPrism.

@Test
public void testParseModelContextPrism() throws Exception {
    System.out.println("===[ testParseModelContextPrism ]===");
    // GIVEN
    PrismContext prismContext = PrismTestUtil.getPrismContext();
    // WHEN
    LensContextType lensContextType = prismContext.parserFor(MODEL_CONTEXT_FILE).xml().parseRealValue(LensContextType.class);
    // THEN
    System.out.println("Parsed LensContextType: " + lensContextType);
}
Also used : PrismContext(com.evolveum.midpoint.prism.PrismContext) LensContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType) Test(org.testng.annotations.Test)

Example 3 with LensContextType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType in project midpoint by Evolveum.

the class ModelOperationTaskHandler method run.

@Override
public TaskRunResult run(Task task) {
    OperationResult result = task.getResult().createSubresult(DOT_CLASS + "run");
    TaskRunResult runResult = new TaskRunResult();
    LensContextType contextType = task.getModelOperationContext();
    if (contextType == null) {
        LOGGER.trace("No model context found, skipping the model operation execution.");
        if (result.isUnknown()) {
            result.computeStatus();
        }
        runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.FINISHED);
    } else {
        LensContext context;
        try {
            context = LensContext.fromLensContextType(contextType, prismContext, provisioningService, task, result);
        } catch (SchemaException e) {
            throw new SystemException("Cannot recover model context from task " + task + " due to schema exception", e);
        } catch (ObjectNotFoundException | ConfigurationException | ExpressionEvaluationException e) {
            throw new SystemException("Cannot recover model context from task " + task, e);
        } catch (CommunicationException e) {
            // todo wait and retry
            throw new SystemException("Cannot recover model context from task " + task, e);
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Context to be executed = {}", context.debugDump());
        }
        try {
            // here we brutally remove all the projection contexts -- because if we are continuing after rejection of a role/resource assignment
            // that resulted in such projection contexts, we DO NOT want them to appear in the context any more
            context.rot();
            Iterator<LensProjectionContext> projectionIterator = context.getProjectionContextsIterator();
            while (projectionIterator.hasNext()) {
                LensProjectionContext projectionContext = projectionIterator.next();
                if (projectionContext.getPrimaryDelta() != null && !projectionContext.getPrimaryDelta().isEmpty()) {
                    // don't remove client requested actions!
                    continue;
                }
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Removing projection context {}", projectionContext.getHumanReadableName());
                }
                projectionIterator.remove();
            }
            if (task.getChannel() == null) {
                task.setChannel(context.getChannel());
            }
            clockwork.run(context, task, result);
            task.setModelOperationContext(context.toLensContextType());
            task.savePendingModifications(result);
            if (result.isUnknown()) {
                result.computeStatus();
            }
            runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.FINISHED);
        } catch (RuntimeException | CommonException e) {
            String message = "An exception occurred within model operation, in task " + task;
            LoggingUtils.logUnexpectedException(LOGGER, message, e);
            result.recordPartialError(message, e);
            // TODO: here we do not know whether the error is temporary or permanent (in the future we could discriminate on the basis of particular exception caught)
            runResult.setRunResultStatus(TaskRunResult.TaskRunResultStatus.TEMPORARY_ERROR);
        }
    }
    task.getResult().recomputeStatus();
    runResult.setOperationResult(task.getResult());
    return runResult;
}
Also used : LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) LensContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType) TaskRunResult(com.evolveum.midpoint.task.api.TaskRunResult)

Example 4 with LensContextType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType in project midpoint by Evolveum.

the class TaskOperationTabPanel method initLayout.

private void initLayout() {
    final LensContextType lensContextType = getLensContextType();
    LoadableModel<ModelOperationStatusDto> operationStatusModel = null;
    if (lensContextType != null) {
        operationStatusModel = new LoadableModel<ModelOperationStatusDto>() {

            @Override
            protected ModelOperationStatusDto load() {
                Task task = getPageBase().createSimpleTask(OPERATION_LOAD_SCENE_DTO);
                OperationResult result = task.getResult();
                ModelContext ctx;
                try {
                    ctx = ModelContextUtil.unwrapModelContext(lensContextType, getPageBase().getModelInteractionService(), task, result);
                } catch (ObjectNotFoundException e) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Unexpected error, cannot get real value for model context", e, e.getMessage());
                    return null;
                }
                return new ModelOperationStatusDto(ctx, getPageBase().getModelInteractionService(), task, result);
            }
        };
    }
    ModelOperationStatusPanel panel = new ModelOperationStatusPanel(ID_MODEL_OPERATION_STATUS_PANEL, operationStatusModel);
    panel.add(new VisibleEnableBehaviour() {

        @Override
        public boolean isVisible() {
            return lensContextType != null;
        }
    });
    add(panel);
}
Also used : ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) Task(com.evolveum.midpoint.task.api.Task) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) VisibleEnableBehaviour(com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour) ModelOperationStatusDto(com.evolveum.midpoint.web.component.model.operationStatus.ModelOperationStatusDto) LensContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType) ModelOperationStatusPanel(com.evolveum.midpoint.web.component.model.operationStatus.ModelOperationStatusPanel)

Example 5 with LensContextType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType in project midpoint by Evolveum.

the class CaseClosing method finishCaseClosing.

public void finishCaseClosing(OperationResult result) throws SchemaException, ObjectNotFoundException, ObjectAlreadyExistsException, ExpressionEvaluationException, CommunicationException, ConfigurationException {
    CaseType approvalCase = operation.getCurrentCase();
    ObjectTreeDeltas<?> approvedDeltas = prepareDeltaOut(approvalCase);
    beans.generalHelper.storeResultingDeltas(approvalCase, approvedDeltas, result);
    // note: resulting deltas are now _not_ stored in currentCase object (these are in repo only)
    // here we should execute the deltas, if appropriate!
    CaseType rootCase = beans.generalHelper.getRootCase(approvalCase, result);
    if (CaseTypeUtil.isClosed(rootCase)) {
        LOGGER.debug("Root case ({}) is already closed; not starting any execution tasks for {}", rootCase, approvalCase);
        beans.executionHelper.closeCaseInRepository(approvalCase, result);
    } else {
        LensContextType modelContextBean = rootCase.getModelContext();
        if (modelContextBean == null) {
            throw new IllegalStateException("No model context in root case " + rootCase);
        }
        if (isExecuteImmediately(modelContextBean)) {
            processImmediateExecution(approvalCase, approvedDeltas, result);
        } else {
            processDelayedExecution(approvalCase, rootCase, result);
        }
    }
}
Also used : CaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType) LensContextType(com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType)

Aggregations

LensContextType (com.evolveum.midpoint.xml.ns._public.common.common_3.LensContextType)5 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)2 Task (com.evolveum.midpoint.task.api.Task)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 ModelOperationStatusDto (com.evolveum.midpoint.web.component.model.operationStatus.ModelOperationStatusDto)2 ModelOperationStatusPanel (com.evolveum.midpoint.web.component.model.operationStatus.ModelOperationStatusPanel)2 VisibleEnableBehaviour (com.evolveum.midpoint.web.component.util.VisibleEnableBehaviour)2 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)1 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 TaskRunResult (com.evolveum.midpoint.task.api.TaskRunResult)1 CaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType)1 Test (org.testng.annotations.Test)1