Search in sources :

Example 61 with LensProjectionContext

use of com.evolveum.midpoint.model.impl.lens.LensProjectionContext 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 62 with LensProjectionContext

use of com.evolveum.midpoint.model.impl.lens.LensProjectionContext in project midpoint by Evolveum.

the class MidpointFunctionsImpl method getResourceDelta.

@Override
public ObjectDeltaType getResourceDelta(ModelContext context, String resourceOid) throws SchemaException {
    List<ObjectDelta<ShadowType>> deltas = new ArrayList<>();
    for (Object modelProjectionContextObject : context.getProjectionContexts()) {
        LensProjectionContext lensProjectionContext = (LensProjectionContext) modelProjectionContextObject;
        if (lensProjectionContext.getResourceShadowDiscriminator() != null && resourceOid.equals(lensProjectionContext.getResourceShadowDiscriminator().getResourceOid())) {
            // union of primary and secondary deltas
            deltas.add(lensProjectionContext.getDelta());
        }
    }
    ObjectDelta<ShadowType> sum = ObjectDelta.summarize(deltas);
    return DeltaConvertor.toObjectDeltaType(sum);
}
Also used : LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 63 with LensProjectionContext

use of com.evolveum.midpoint.model.impl.lens.LensProjectionContext in project midpoint by Evolveum.

the class MidpointFunctionsImpl method hasLinkedAccount.

public <F extends ObjectType> boolean hasLinkedAccount(String resourceOid) {
    LensContext<F> ctx = ModelExpressionThreadLocalHolder.getLensContext();
    if (ctx == null) {
        throw new IllegalStateException("No lens context");
    }
    LensFocusContext<F> focusContext = ctx.getFocusContext();
    if (focusContext == null) {
        throw new IllegalStateException("No focus in lens context");
    }
    ScriptExpressionEvaluationContext scriptContext = ScriptExpressionEvaluationContext.getThreadLocal();
    ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(resourceOid, ShadowKindType.ACCOUNT, null);
    LensProjectionContext projectionContext = ctx.findProjectionContext(rat);
    if (projectionContext == null) {
        // but check if it is not among list of deleted contexts
        if (scriptContext == null || scriptContext.isEvaluateNew()) {
            return false;
        }
        // evaluating old state
        for (ResourceShadowDiscriminator deletedOne : ctx.getHistoricResourceObjects()) {
            if (resourceOid.equals(deletedOne.getResourceOid()) && deletedOne.getKind() == ShadowKindType.ACCOUNT && deletedOne.getIntent() == null || "default".equals(deletedOne.getIntent())) {
                // TODO implement this seriously
                // TODO remove
                LOGGER.trace("Found deleted one: {}", deletedOne);
                return true;
            }
        }
        return false;
    }
    if (projectionContext.isThombstone()) {
        return false;
    }
    SynchronizationPolicyDecision synchronizationPolicyDecision = projectionContext.getSynchronizationPolicyDecision();
    SynchronizationIntent synchronizationIntent = projectionContext.getSynchronizationIntent();
    if (scriptContext == null) {
        if (synchronizationPolicyDecision == null) {
            if (synchronizationIntent == SynchronizationIntent.DELETE || synchronizationIntent == SynchronizationIntent.UNLINK) {
                return false;
            } else {
                return true;
            }
        } else {
            if (synchronizationPolicyDecision == SynchronizationPolicyDecision.DELETE || synchronizationPolicyDecision == SynchronizationPolicyDecision.UNLINK) {
                return false;
            } else {
                return true;
            }
        }
    } else if (scriptContext.isEvaluateNew()) {
        // Evaluating new state
        if (focusContext.isDelete()) {
            return false;
        }
        if (synchronizationPolicyDecision == null) {
            if (synchronizationIntent == SynchronizationIntent.DELETE || synchronizationIntent == SynchronizationIntent.UNLINK) {
                return false;
            } else {
                return true;
            }
        } else {
            if (synchronizationPolicyDecision == SynchronizationPolicyDecision.DELETE || synchronizationPolicyDecision == SynchronizationPolicyDecision.UNLINK) {
                return false;
            } else {
                return true;
            }
        }
    } else {
        // Evaluating old state
        if (focusContext.isAdd()) {
            return false;
        }
        if (synchronizationPolicyDecision == null) {
            if (synchronizationIntent == SynchronizationIntent.ADD) {
                return false;
            } else {
                return true;
            }
        } else {
            if (synchronizationPolicyDecision == SynchronizationPolicyDecision.ADD) {
                return false;
            } else {
                return true;
            }
        }
    }
}
Also used : ScriptExpressionEvaluationContext(com.evolveum.midpoint.model.common.expression.script.ScriptExpressionEvaluationContext) SynchronizationIntent(com.evolveum.midpoint.model.impl.lens.SynchronizationIntent) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) SynchronizationPolicyDecision(com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision)

Example 64 with LensProjectionContext

use of com.evolveum.midpoint.model.impl.lens.LensProjectionContext in project midpoint by Evolveum.

the class ShadowConstraintsChecker method check.

public void check(Task task, OperationResult result) throws SchemaException, ObjectAlreadyExistsException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    RefinedObjectClassDefinition projOcDef = projectionContext.getCompositeObjectClassDefinition();
    PrismObject<ShadowType> projectionNew = projectionContext.getObjectNew();
    if (projectionNew == null) {
        // This must be delete
        LOGGER.trace("No new object in projection context. Current shadow satisfy constraints");
        satisfiesConstraints = true;
        return;
    }
    PrismContainer<?> attributesContainer = projectionNew.findContainer(ShadowType.F_ATTRIBUTES);
    if (attributesContainer == null) {
        // No attributes no constraint violations
        LOGGER.trace("Current shadow does not contain attributes, skipping checking uniqueness.");
        satisfiesConstraints = true;
        return;
    }
    ConstraintViolationConfirmer confirmer = new ConstraintViolationConfirmer() {

        @Override
        public boolean confirmViolation(String oid) {
            boolean violation = true;
            LensProjectionContext foundContext = context.findProjectionContextByOid(oid);
            if (foundContext != null) {
                if (foundContext.getResourceShadowDiscriminator() != null) {
                    if (foundContext.getResourceShadowDiscriminator().isThombstone()) {
                        violation = false;
                    }
                    LOGGER.trace("Comparing with account in other context resulted to violation confirmation of {}", violation);
                }
            }
            return violation;
        }
    };
    constraintsCheckingResult = provisioningService.checkConstraints(projOcDef, projectionNew, projectionContext.getResource(), projectionContext.getOid(), projectionContext.getResourceShadowDiscriminator(), confirmer, task, result);
    if (constraintsCheckingResult.isSatisfiesConstraints()) {
        satisfiesConstraints = true;
        return;
    }
    for (QName checkedAttributeName : constraintsCheckingResult.getCheckedAttributes()) {
        if (constraintsCheckingResult.getConflictingAttributes().contains(checkedAttributeName)) {
            if (isInDelta(checkedAttributeName, projectionContext.getPrimaryDelta())) {
                throw new ObjectAlreadyExistsException("Attribute " + checkedAttributeName + " conflicts with existing object (and it is present in primary " + "account delta therefore no iteration is performed)");
            }
        }
    }
    if (projectionContext.getResourceShadowDiscriminator() != null && projectionContext.getResourceShadowDiscriminator().isThombstone()) {
        satisfiesConstraints = true;
    } else {
        satisfiesConstraints = false;
    }
}
Also used : RefinedObjectClassDefinition(com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition) ConstraintViolationConfirmer(com.evolveum.midpoint.provisioning.api.ConstraintViolationConfirmer) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 65 with LensProjectionContext

use of com.evolveum.midpoint.model.impl.lens.LensProjectionContext in project midpoint by Evolveum.

the class TestProjectorRoleEntitlement method assertAssignEntitlementToPirate.

private void assertAssignEntitlementToPirate(LensContext<RoleType> context) {
    display("Output context", context);
    assertTrue(context.getFocusContext().getPrimaryDelta().getChangeType() == ChangeType.MODIFY);
    assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "focus secondary delta", ActivationStatusType.ENABLED);
    assertFalse("No projection changes", context.getProjectionContexts().isEmpty());
    Collection<LensProjectionContext> projectionContexts = context.getProjectionContexts();
    assertEquals(1, projectionContexts.size());
    LensProjectionContext projContext = projectionContexts.iterator().next();
    assertNull("Projection primary delta sneaked in", projContext.getPrimaryDelta());
    ObjectDelta<ShadowType> projSecondaryDelta = projContext.getSecondaryDelta();
    assertEquals("Wrong decision", SynchronizationPolicyDecision.ADD, projContext.getSynchronizationPolicyDecision());
    assertEquals(ChangeType.MODIFY, projSecondaryDelta.getChangeType());
    PrismAsserts.assertPropertyReplace(projSecondaryDelta, getIcfsNameAttributePath(), "Pirate");
    PrismAsserts.assertPropertyReplace(projSecondaryDelta, getDummyResourceController().getAttributePath(DummyResourceContoller.DUMMY_GROUP_ATTRIBUTE_DESCRIPTION), "Bloody pirates");
    PrismAsserts.assertOrigin(projSecondaryDelta, OriginType.OUTBOUND);
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext)

Aggregations

LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)71 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)28 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)24 Task (com.evolveum.midpoint.task.api.Task)19 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)18 Test (org.testng.annotations.Test)17 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)15 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)14 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)12 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)11 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)10 MockLensDebugListener (com.evolveum.midpoint.model.impl.util.mock.MockLensDebugListener)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)8 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)7 SynchronizationPolicyDecision (com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision)5 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)5 PrismReference (com.evolveum.midpoint.prism.PrismReference)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)5