Search in sources :

Example 1 with ObjectResolver

use of com.evolveum.midpoint.repo.common.ObjectResolver in project midpoint by Evolveum.

the class PreviewChangesTabPanel method initModels.

private void initModels() {
    final List<ObjectDelta<? extends ObjectType>> primaryDeltas = new ArrayList<>();
    final List<ObjectDelta<? extends ObjectType>> secondaryDeltas = new ArrayList<>();
    final List<? extends Scene> primaryScenes;
    final List<? extends Scene> secondaryScenes;
    ModelContext<O> modelContext = getModelObject();
    try {
        if (modelContext != null) {
            if (modelContext.getFocusContext() != null) {
                addIgnoreNull(primaryDeltas, CloneUtil.clone(modelContext.getFocusContext().getPrimaryDelta()));
                ObjectDelta<O> summarySecondaryDelta = CloneUtil.clone(modelContext.getFocusContext().getSummarySecondaryDelta());
                if (summarySecondaryDelta != null && !summarySecondaryDelta.getModifications().isEmpty()) {
                    secondaryDeltas.add(summarySecondaryDelta);
                }
            }
            for (ModelProjectionContext projCtx : modelContext.getProjectionContexts()) {
                ObjectDelta<ShadowType> primaryDelta = CloneUtil.clone(projCtx.getPrimaryDelta());
                addIgnoreNull(primaryDeltas, primaryDelta);
                if (!isEquivalentWithoutOperationAttr(primaryDelta, CloneUtil.clone(projCtx.getExecutableDelta()))) {
                    addIgnoreNull(secondaryDeltas, CloneUtil.clone(projCtx.getExecutableDelta()));
                }
            }
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Primary deltas:\n{}", DebugUtil.debugDump(primaryDeltas));
            LOGGER.trace("Secondary deltas:\n{}", DebugUtil.debugDump(secondaryDeltas));
        }
        Task task = getPageBase().createSimpleTask("visualize");
        primaryScenes = getPageBase().getModelInteractionService().visualizeDeltas(primaryDeltas, task, task.getResult());
        secondaryScenes = getPageBase().getModelInteractionService().visualizeDeltas(secondaryDeltas, task, task.getResult());
    } catch (SchemaException | ExpressionEvaluationException e) {
        // TODO
        throw new SystemException(e);
    }
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Creating context DTO for primary deltas:\n{}", DebugUtil.debugDump(primaryScenes));
        LOGGER.trace("Creating context DTO for secondary deltas:\n{}", DebugUtil.debugDump(secondaryScenes));
    }
    final WrapperScene primaryScene = new WrapperScene(primaryScenes, primaryScenes.size() != 1 ? "PagePreviewChanges.primaryChangesMore" : "PagePreviewChanges.primaryChangesOne", primaryScenes.size());
    final WrapperScene secondaryScene = new WrapperScene(secondaryScenes, secondaryScenes.size() != 1 ? "PagePreviewChanges.secondaryChangesMore" : "PagePreviewChanges.secondaryChangesOne", secondaryScenes.size());
    final SceneDto primarySceneDto = new SceneDto(primaryScene);
    final SceneDto secondarySceneDto = new SceneDto(secondaryScene);
    primaryDeltasModel = (IModel<SceneDto>) () -> primarySceneDto;
    secondaryDeltasModel = (IModel<SceneDto>) () -> secondarySceneDto;
    PolicyRuleEnforcerPreviewOutputType enforcements = modelContext != null ? modelContext.getPolicyRuleEnforcerPreviewOutput() : null;
    List<EvaluatedTriggerGroupDto> triggerGroups = enforcements != null ? Collections.singletonList(EvaluatedTriggerGroupDto.initializeFromRules(enforcements.getRule(), false, null)) : Collections.emptyList();
    policyViolationsModel = Model.ofList(triggerGroups);
    List<ApprovalSchemaExecutionInformationType> approvalsExecutionList = modelContext != null ? modelContext.getHookPreviewResults(ApprovalSchemaExecutionInformationType.class) : Collections.emptyList();
    List<ApprovalProcessExecutionInformationDto> approvals = new ArrayList<>();
    if (!approvalsExecutionList.isEmpty()) {
        // TODO
        Task opTask = getPageBase().createSimpleTask(PagePreviewChanges.class + ".createApprovals");
        OperationResult result = opTask.getResult();
        ObjectResolver modelObjectResolver = getPageBase().getModelObjectResolver();
        try {
            for (ApprovalSchemaExecutionInformationType execution : approvalsExecutionList) {
                approvals.add(ApprovalProcessExecutionInformationDto.createFrom(execution, modelObjectResolver, true, opTask, // TODO reuse session
                result));
            }
            result.computeStatus();
        } catch (Throwable t) {
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare approval information", t);
            result.recordFatalError(createStringResource("PreviewChangesTabPanel.message.prepareApproval.fatalError", t.getMessage()).getString(), t);
        }
        if (WebComponentUtil.showResultInPage(result)) {
            getPageBase().showResult(result);
        }
    }
    approvalsModel = Model.ofList(approvals);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ArrayList(java.util.ArrayList) ObjectResolver(com.evolveum.midpoint.repo.common.ObjectResolver) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ApprovalProcessExecutionInformationDto(com.evolveum.midpoint.web.page.admin.workflow.dto.ApprovalProcessExecutionInformationDto) SystemException(com.evolveum.midpoint.util.exception.SystemException) ApprovalSchemaExecutionInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalSchemaExecutionInformationType) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) PolicyRuleEnforcerPreviewOutputType(com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleEnforcerPreviewOutputType) EvaluatedTriggerGroupDto(com.evolveum.midpoint.web.page.admin.workflow.dto.EvaluatedTriggerGroupDto)

Example 2 with ObjectResolver

use of com.evolveum.midpoint.repo.common.ObjectResolver in project midpoint by Evolveum.

the class MappingTestEvaluator method init.

private void init(boolean withMetadata) throws SchemaException, SAXException, IOException {
    this.withMetadata = withMetadata;
    PrettyPrinter.setDefaultNamespacePrefix(MidPointConstants.NS_MIDPOINT_PUBLIC_PREFIX);
    PrismTestUtil.resetPrismContext(MidPointPrismContextFactory.FACTORY);
    prismContext = PrismTestUtil.createInitializedPrismContext();
    ObjectResolver resolver = new DirectoryFileObjectResolver(MidPointTestConstants.OBJECTS_DIR);
    protector = ExpressionTestUtil.createInitializedProtector(prismContext);
    Clock clock = new Clock();
    ExpressionFactory expressionFactory = ExpressionTestUtil.createInitializedExpressionFactory(resolver, protector, prismContext, clock, null, null);
    // We need only selected beans for the mapping factory
    ModelCommonBeans beans = new ModelCommonBeans();
    beans.expressionFactory = expressionFactory;
    beans.objectResolver = resolver;
    beans.prismContext = prismContext;
    beans.protector = protector;
    if (withMetadata) {
        BuiltinMetadataMappingsRegistry builtinMetadataMappingsRegistry = new BuiltinMetadataMappingsRegistry();
        ProvenanceBuiltinMapping provenanceBuiltinMapping = new ProvenanceBuiltinMapping(prismContext, builtinMetadataMappingsRegistry);
        provenanceBuiltinMapping.register();
        beans.metadataMappingEvaluator = new MetadataMappingEvaluator(mappingFactory, prismContext, builtinMetadataMappingsRegistry);
    }
    mappingFactory = new MappingFactory();
    mappingFactory.setBeans(beans);
    mappingFactory.setProfiling(true);
}
Also used : BuiltinMetadataMappingsRegistry(com.evolveum.midpoint.model.common.mapping.metadata.builtin.BuiltinMetadataMappingsRegistry) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) MetadataMappingEvaluator(com.evolveum.midpoint.model.common.mapping.metadata.MetadataMappingEvaluator) ModelCommonBeans(com.evolveum.midpoint.model.common.ModelCommonBeans) DirectoryFileObjectResolver(com.evolveum.midpoint.repo.common.DirectoryFileObjectResolver) ObjectResolver(com.evolveum.midpoint.repo.common.ObjectResolver) DirectoryFileObjectResolver(com.evolveum.midpoint.repo.common.DirectoryFileObjectResolver) ProvenanceBuiltinMapping(com.evolveum.midpoint.model.common.mapping.metadata.builtin.ProvenanceBuiltinMapping) Clock(com.evolveum.midpoint.common.Clock)

Example 3 with ObjectResolver

use of com.evolveum.midpoint.repo.common.ObjectResolver in project midpoint by Evolveum.

the class TestExpressionUtil method resolvePath.

private <T> T resolvePath(String path, VariablesMap variables, String exprShortDesc) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    OperationResult result = createOperationResult();
    ItemPath itemPath = toItemPath(path);
    // WHEN
    ObjectResolver objectResolver = new DirectoryFileObjectResolver(MidPointTestConstants.OBJECTS_DIR);
    Object resolved = ExpressionUtil.resolvePathGetValue(itemPath, variables, false, null, objectResolver, PrismTestUtil.getPrismContext(), exprShortDesc, new NullTaskImpl(), result);
    // THEN
    IntegrationTestTools.display("Resolved", resolved);
    // noinspection unchecked
    return (T) resolved;
}
Also used : DirectoryFileObjectResolver(com.evolveum.midpoint.repo.common.DirectoryFileObjectResolver) ObjectResolver(com.evolveum.midpoint.repo.common.ObjectResolver) DirectoryFileObjectResolver(com.evolveum.midpoint.repo.common.DirectoryFileObjectResolver) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDeltaObject(com.evolveum.midpoint.prism.util.ObjectDeltaObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) UniformItemPath(com.evolveum.midpoint.prism.path.UniformItemPath) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) NullTaskImpl(com.evolveum.midpoint.task.api.test.NullTaskImpl)

Example 4 with ObjectResolver

use of com.evolveum.midpoint.repo.common.ObjectResolver in project midpoint by Evolveum.

the class PreviewChangesTabPanel method initModels.

private void initModels() {
    final List<ObjectDelta<? extends ObjectType>> primaryDeltas = new ArrayList<>();
    final List<ObjectDelta<? extends ObjectType>> secondaryDeltas = new ArrayList<>();
    final List<? extends Scene> primaryScenes;
    final List<? extends Scene> secondaryScenes;
    ModelContext<O> modelContext = getModelObject();
    try {
        if (modelContext != null) {
            if (modelContext.getFocusContext() != null) {
                addIgnoreNull(primaryDeltas, CloneUtil.clone(modelContext.getFocusContext().getPrimaryDelta()));
                ObjectDelta<O> summarySecondaryDelta = CloneUtil.clone(modelContext.getFocusContext().getSummarySecondaryDelta());
                if (summarySecondaryDelta != null && !summarySecondaryDelta.getModifications().isEmpty()) {
                    secondaryDeltas.add(summarySecondaryDelta);
                }
            }
            for (ModelProjectionContext projCtx : modelContext.getProjectionContexts()) {
                ObjectDelta<ShadowType> primaryDelta = CloneUtil.clone(projCtx.getPrimaryDelta());
                addIgnoreNull(primaryDeltas, primaryDelta);
                if (!isEquivalentWithoutOperationAttr(primaryDelta, CloneUtil.clone(projCtx.getExecutableDelta()))) {
                    addIgnoreNull(secondaryDeltas, CloneUtil.clone(projCtx.getExecutableDelta()));
                }
            }
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Primary deltas:\n{}", DebugUtil.debugDump(primaryDeltas));
            LOGGER.trace("Secondary deltas:\n{}", DebugUtil.debugDump(secondaryDeltas));
        }
        Task task = getPageBase().createSimpleTask("visualize");
        primaryScenes = getPageBase().getModelInteractionService().visualizeDeltas(primaryDeltas, task, task.getResult());
        secondaryScenes = getPageBase().getModelInteractionService().visualizeDeltas(secondaryDeltas, task, task.getResult());
    } catch (SchemaException | ExpressionEvaluationException e) {
        // TODO
        throw new SystemException(e);
    }
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Creating context DTO for primary deltas:\n{}", DebugUtil.debugDump(primaryScenes));
        LOGGER.trace("Creating context DTO for secondary deltas:\n{}", DebugUtil.debugDump(secondaryScenes));
    }
    final WrapperScene primaryScene = new WrapperScene(primaryScenes, primaryScenes.size() != 1 ? "PagePreviewChanges.primaryChangesMore" : "PagePreviewChanges.primaryChangesOne", primaryScenes.size());
    final WrapperScene secondaryScene = new WrapperScene(secondaryScenes, secondaryScenes.size() != 1 ? "PagePreviewChanges.secondaryChangesMore" : "PagePreviewChanges.secondaryChangesOne", secondaryScenes.size());
    final SceneDto primarySceneDto = new SceneDto(primaryScene);
    final SceneDto secondarySceneDto = new SceneDto(secondaryScene);
    primaryDeltasModel = (IModel<SceneDto>) () -> primarySceneDto;
    secondaryDeltasModel = (IModel<SceneDto>) () -> secondarySceneDto;
    PolicyRuleEnforcerPreviewOutputType enforcements = modelContext != null ? modelContext.getPolicyRuleEnforcerPreviewOutput() : null;
    List<EvaluatedTriggerGroupDto> triggerGroups = enforcements != null ? Collections.singletonList(EvaluatedTriggerGroupDto.initializeFromRules(enforcements.getRule(), false, null)) : Collections.emptyList();
    policyViolationsModel = Model.ofList(triggerGroups);
    List<ApprovalSchemaExecutionInformationType> approvalsExecutionList = modelContext != null ? modelContext.getHookPreviewResults(ApprovalSchemaExecutionInformationType.class) : Collections.emptyList();
    List<ApprovalProcessExecutionInformationDto> approvals = new ArrayList<>();
    if (!approvalsExecutionList.isEmpty()) {
        // TODO
        Task opTask = getPageBase().createSimpleTask(PageFocusPreviewChanges.class + ".createApprovals");
        OperationResult result = opTask.getResult();
        ObjectResolver modelObjectResolver = getPageBase().getModelObjectResolver();
        try {
            for (ApprovalSchemaExecutionInformationType execution : approvalsExecutionList) {
                approvals.add(ApprovalProcessExecutionInformationDto.createFrom(execution, modelObjectResolver, true, opTask, // TODO reuse session
                result));
            }
            result.computeStatus();
        } catch (Throwable t) {
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't prepare approval information", t);
            result.recordFatalError(createStringResource("PreviewChangesTabPanel.message.prepareApproval.fatalError", t.getMessage()).getString(), t);
        }
        if (WebComponentUtil.showResultInPage(result)) {
            getPageBase().showResult(result);
        }
    }
    approvalsModel = Model.ofList(approvals);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) WrapperScene(com.evolveum.midpoint.web.component.prism.show.WrapperScene) ArrayList(java.util.ArrayList) ObjectResolver(com.evolveum.midpoint.repo.common.ObjectResolver) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ApprovalProcessExecutionInformationDto(com.evolveum.midpoint.web.page.admin.workflow.dto.ApprovalProcessExecutionInformationDto) SystemException(com.evolveum.midpoint.util.exception.SystemException) ApprovalSchemaExecutionInformationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalSchemaExecutionInformationType) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) PageFocusPreviewChanges(com.evolveum.midpoint.gui.impl.page.admin.focus.PageFocusPreviewChanges) SceneDto(com.evolveum.midpoint.web.component.prism.show.SceneDto) PolicyRuleEnforcerPreviewOutputType(com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleEnforcerPreviewOutputType) EvaluatedTriggerGroupDto(com.evolveum.midpoint.web.page.admin.workflow.dto.EvaluatedTriggerGroupDto)

Example 5 with ObjectResolver

use of com.evolveum.midpoint.repo.common.ObjectResolver in project midpoint by Evolveum.

the class ApprovalProcessExecutionInformationDto method createFrom.

@NotNull
public static ApprovalProcessExecutionInformationDto createFrom(ApprovalSchemaExecutionInformationType info, ObjectResolver resolver, boolean wholeProcess, Task opTask, OperationResult result) {
    int currentStageNumber = info.getCurrentStageNumber() != null ? info.getCurrentStageNumber() : 0;
    int numberOfStages = info.getStage().size();
    ObjectResolver.Session session = resolver.openResolutionSession(null);
    String processName = ApprovalContextUtil.getProcessName(info);
    String targetName = ApprovalContextUtil.getTargetName(info);
    CaseType aCase = ApprovalContextUtil.getCase(info);
    boolean running = aCase != null && !SchemaConstants.CASE_STATE_CLOSED.equals(aCase.getState());
    EvaluatedTriggerGroupDto triggers = EvaluatedTriggerGroupDto.initializeFromRules(ApprovalContextUtil.getAllRules(info.getPolicyRules()), false, new EvaluatedTriggerGroupDto.UniquenessFilter());
    ApprovalProcessExecutionInformationDto rv = new ApprovalProcessExecutionInformationDto(wholeProcess, currentStageNumber, numberOfStages, processName, targetName, triggers, running);
    int startingStageNumber = wholeProcess ? 1 : currentStageNumber;
    boolean reachable = true;
    for (int i = startingStageNumber; i <= numberOfStages; i++) {
        ApprovalStageExecutionInformationDto stage = ApprovalStageExecutionInformationDto.createFrom(info, i, resolver, session, opTask, result);
        stage.setReachable(reachable);
        rv.stages.add(stage);
        if (stage.getOutcome() == ApprovalLevelOutcomeType.REJECT) {
            // for following stages
            reachable = false;
        }
    }
    return rv;
}
Also used : CaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.CaseType) ObjectResolver(com.evolveum.midpoint.repo.common.ObjectResolver) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ObjectResolver (com.evolveum.midpoint.repo.common.ObjectResolver)8 DirectoryFileObjectResolver (com.evolveum.midpoint.repo.common.DirectoryFileObjectResolver)5 Clock (com.evolveum.midpoint.common.Clock)4 ArrayList (java.util.ArrayList)4 Protector (com.evolveum.midpoint.prism.crypto.Protector)3 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 BeforeClass (org.testng.annotations.BeforeClass)3 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)2 FunctionLibrary (com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 Task (com.evolveum.midpoint.task.api.Task)2 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 ApprovalProcessExecutionInformationDto (com.evolveum.midpoint.web.page.admin.workflow.dto.ApprovalProcessExecutionInformationDto)2 EvaluatedTriggerGroupDto (com.evolveum.midpoint.web.page.admin.workflow.dto.EvaluatedTriggerGroupDto)2 ApprovalSchemaExecutionInformationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalSchemaExecutionInformationType)2 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)2 PolicyRuleEnforcerPreviewOutputType (com.evolveum.midpoint.xml.ns._public.common.common_3.PolicyRuleEnforcerPreviewOutputType)2 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)2