Search in sources :

Example 16 with ItemDeltaItem

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

the class ActivationProcessor method getFocusExistsIdi.

private <F extends ObjectType> ItemDeltaItem<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> getFocusExistsIdi(LensFocusContext<F> lensFocusContext) throws SchemaException {
    Boolean existsOld = null;
    Boolean existsNew = null;
    if (lensFocusContext != null) {
        if (lensFocusContext.isDelete()) {
            existsOld = true;
            existsNew = false;
        } else if (lensFocusContext.isAdd()) {
            existsOld = false;
            existsNew = true;
        } else {
            existsOld = true;
            existsNew = true;
        }
    }
    PrismPropertyDefinitionImpl<Boolean> existsDef = new PrismPropertyDefinitionImpl<>(FOCUS_EXISTS_PROPERTY_NAME, DOMUtil.XSD_BOOLEAN, prismContext);
    existsDef.setMinOccurs(1);
    existsDef.setMaxOccurs(1);
    PrismProperty<Boolean> existsProp = existsDef.instantiate();
    existsProp.add(new PrismPropertyValue<Boolean>(existsNew));
    if (existsOld == existsNew) {
        return new ItemDeltaItem<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>>(existsProp);
    } else {
        PrismProperty<Boolean> existsPropOld = existsProp.clone();
        existsPropOld.setRealValue(existsOld);
        PropertyDelta<Boolean> existsDelta = existsPropOld.createDelta();
        existsDelta.setValuesToReplace(new PrismPropertyValue<Boolean>(existsNew));
        return new ItemDeltaItem<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>>(existsPropOld, existsDelta, existsProp);
    }
}
Also used : ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) MutableBoolean(org.apache.commons.lang.mutable.MutableBoolean)

Example 17 with ItemDeltaItem

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

the class AssignmentTripleEvaluator method processAssignment.

private void processAssignment(DeltaSetTriple<EvaluatedAssignmentImpl<F>> evaluatedAssignmentTriple, ObjectDelta<F> focusDelta, ContainerDelta<AssignmentType> assignmentDelta, SmartAssignmentElement assignmentElement) throws SchemaException, ExpressionEvaluationException, PolicyViolationException {
    LensFocusContext<F> focusContext = context.getFocusContext();
    PrismContainerValue<AssignmentType> assignmentCVal = assignmentElement.getAssignmentCVal();
    AssignmentType assignmentType = assignmentCVal.asContainerable();
    PrismContainerValue<AssignmentType> assignmentCValOld = assignmentCVal;
    PrismContainerValue<AssignmentType> assignmentCValNew = assignmentCVal;
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
    assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
    boolean presentInCurrent = assignmentElement.isCurrent();
    boolean presentInOld = assignmentElement.isOld();
    // This really means whether the WHOLE assignment was changed (e.g. added/delted/replaced). It tells nothing
    // about "micro-changes" inside assignment, these will be processed later.
    boolean isAssignmentChanged = assignmentElement.isChanged();
    boolean forceRecon = false;
    String assignmentPlacementDesc;
    if (isAssignmentChanged) {
        // Whole assignment added or deleted
        assignmentPlacementDesc = "delta for " + source;
    } else {
        assignmentPlacementDesc = source.toString();
        Collection<? extends ItemDelta<?, ?>> assignmentItemDeltas = getExecutionWaveAssignmentItemDeltas(focusContext, assignmentCVal.getId());
        if (assignmentItemDeltas != null && !assignmentItemDeltas.isEmpty()) {
            // Small changes inside assignment, but otherwise the assignment stays as it is (not added or deleted)
            assignmentIdi.setSubItemDeltas(assignmentItemDeltas);
            // The subItemDeltas above will handle some changes. But not other.
            // E.g. a replace of the whole construction will not be handled properly.
            // Therefore we force recon to sort it out.
            forceRecon = true;
            isAssignmentChanged = true;
            PrismContainer<AssignmentType> assContNew = focusContext.getObjectNew().findContainer(FocusType.F_ASSIGNMENT);
            assignmentCValNew = assContNew.getValue(assignmentCVal.getId());
        }
    }
    assignmentIdi.recompute();
    if (focusDelta != null && focusDelta.isDelete()) {
        // were not changed explicitly.
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Processing focus delete for: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
        }
        EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.MINUS, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
        if (evaluatedAssignment == null) {
            return;
        }
        evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
        evaluatedAssignment.setPresentInOldObject(presentInOld);
        collectToMinus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
    } else {
        if (assignmentDelta.isReplace()) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Processing replace of all assignments for: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
            }
            // ASSIGNMENT REPLACE
            // Handling assignment replace delta. This needs to be handled specially as all the "old"
            // assignments should be considered deleted - except those that are part of the new value set
            // (remain after replace). As account delete and add are costly operations (and potentially dangerous)
            // we optimize here are consider the assignments that were there before replace and still are there
            // after it as unchanged.
            boolean hadValue = presentInCurrent;
            boolean willHaveValue = assignmentDelta.isValueToReplace(assignmentCVal, true);
            if (hadValue && willHaveValue) {
                // No change
                EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.ZERO, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
                if (evaluatedAssignment == null) {
                    return;
                }
                evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
                evaluatedAssignment.setPresentInOldObject(presentInOld);
                collectToZero(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
            } else if (willHaveValue) {
                // add
                EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.PLUS, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
                if (evaluatedAssignment == null) {
                    return;
                }
                evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
                evaluatedAssignment.setPresentInOldObject(presentInOld);
                collectToPlus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
            } else if (hadValue) {
                // delete
                EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.MINUS, true, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
                if (evaluatedAssignment == null) {
                    return;
                }
                evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
                evaluatedAssignment.setPresentInOldObject(presentInOld);
                collectToMinus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
            } else if (assignmentElement.isOld()) {
                // This is OK, safe to skip. This is just an relic of earlier processing.
                return;
            } else {
                LOGGER.error("Whoops. Unexpected things happen. Assignment is neither current, old nor new (replace delta)\n{}", assignmentElement.debugDump(1));
                throw new SystemException("Whoops. Unexpected things happen. Assignment is neither current, old nor new (replace delta).");
            }
        } else {
            // Just sort assignments to sets: unchanged (zero), added (plus), removed (minus)
            if (isAssignmentChanged) {
                // There was some change
                boolean isAdd = assignmentDelta.isValueToAdd(assignmentCVal, true);
                boolean isDelete = assignmentDelta.isValueToDelete(assignmentCVal, true);
                if (isAdd & !isDelete) {
                    // Entirely new assignment is added
                    if (presentInCurrent && presentInOld) {
                        // Phantom add: adding assignment that is already there
                        if (LOGGER.isTraceEnabled()) {
                            LOGGER.trace("Processing changed assignment, phantom add: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
                        }
                        EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.ZERO, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
                        if (evaluatedAssignment == null) {
                            return;
                        }
                        evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
                        evaluatedAssignment.setPresentInOldObject(presentInOld);
                        collectToZero(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
                    } else {
                        if (LOGGER.isTraceEnabled()) {
                            LOGGER.trace("Processing changed assignment, add: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
                        }
                        EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.PLUS, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
                        if (evaluatedAssignment == null) {
                            return;
                        }
                        evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
                        evaluatedAssignment.setPresentInOldObject(presentInOld);
                        collectToPlus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
                    }
                } else if (isDelete && !isAdd) {
                    // Existing assignment is removed
                    if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace("Processing changed assignment, delete: {}", SchemaDebugUtil.prettyPrint(assignmentCVal));
                    }
                    EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.MINUS, true, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
                    if (evaluatedAssignment == null) {
                        return;
                    }
                    evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
                    evaluatedAssignment.setPresentInOldObject(presentInOld);
                    collectToMinus(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
                } else {
                    // Small change inside an assignment
                    // The only thing that we need to worry about is assignment validity change. That is a cause
                    // of provisioning/deprovisioning of the projections. So check that explicitly. Other changes are
                    // not significant, i.e. reconciliation can handle them.
                    boolean isValidOld = LensUtil.isAssignmentValid(focusContext.getObjectOld().asObjectable(), assignmentCValOld.asContainerable(), now, activationComputer);
                    boolean isValid = LensUtil.isAssignmentValid(focusContext.getObjectNew().asObjectable(), assignmentCValNew.asContainerable(), now, activationComputer);
                    if (isValid == isValidOld) {
                        // The change is not significant for assignment applicability. Recon will sort out the details.
                        if (LOGGER.isTraceEnabled()) {
                            LOGGER.trace("Processing changed assignment, minor change (add={}, delete={}, valid={}): {}", new Object[] { isAdd, isDelete, isValid, SchemaDebugUtil.prettyPrint(assignmentCVal) });
                        }
                        EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.ZERO, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
                        if (evaluatedAssignment == null) {
                            return;
                        }
                        evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
                        evaluatedAssignment.setPresentInOldObject(presentInOld);
                        collectToZero(evaluatedAssignmentTriple, evaluatedAssignment, true);
                    } else if (isValid) {
                        // Assignment became valid. We need to place it in plus set to initiate provisioning
                        if (LOGGER.isTraceEnabled()) {
                            LOGGER.trace("Processing changed assignment, assignment becomes valid (add={}, delete={}): {}", new Object[] { isAdd, isDelete, SchemaDebugUtil.prettyPrint(assignmentCVal) });
                        }
                        EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.PLUS, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
                        if (evaluatedAssignment == null) {
                            return;
                        }
                        evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
                        evaluatedAssignment.setPresentInOldObject(presentInOld);
                        collectToPlus(evaluatedAssignmentTriple, evaluatedAssignment, true);
                    } else {
                        // Assignment became invalid. We need to place is in minus set to initiate deprovisioning
                        if (LOGGER.isTraceEnabled()) {
                            LOGGER.trace("Processing changed assignment, assignment becomes invalid (add={}, delete={}): {}", new Object[] { isAdd, isDelete, SchemaDebugUtil.prettyPrint(assignmentCVal) });
                        }
                        EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.MINUS, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
                        if (evaluatedAssignment == null) {
                            return;
                        }
                        evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
                        evaluatedAssignment.setPresentInOldObject(presentInOld);
                        collectToMinus(evaluatedAssignmentTriple, evaluatedAssignment, true);
                    }
                }
            } else {
                // No change in assignment
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Processing unchanged assignment {}", new Object[] { SchemaDebugUtil.prettyPrint(assignmentCVal) });
                }
                EvaluatedAssignmentImpl<F> evaluatedAssignment = evaluateAssignment(assignmentIdi, PlusMinusZero.ZERO, false, context, source, assignmentEvaluator, assignmentPlacementDesc, task, result);
                if (evaluatedAssignment == null) {
                    return;
                }
                evaluatedAssignment.setPresentInCurrentObject(presentInCurrent);
                evaluatedAssignment.setPresentInOldObject(presentInOld);
                collectToZero(evaluatedAssignmentTriple, evaluatedAssignment, forceRecon);
            }
        }
    }
}
Also used : PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.EvaluatedAssignmentImpl) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) SystemException(com.evolveum.midpoint.util.exception.SystemException) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) PrismObject(com.evolveum.midpoint.prism.PrismObject)

Example 18 with ItemDeltaItem

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

the class TestAbstractAssignmentEvaluator method test170RoleManagerChangeCostCenter.

/**
     * jack has assigned role Manager.
     *
     * However, condition in job metarole for Manager is such that it needs "management"
     * to be present in user/costCenter in order to be active.
     */
@Test
public void test170RoleManagerChangeCostCenter() throws Exception {
    final String TEST_NAME = "test170RoleManagerChangeCostCenter";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> user = userTypeJack.asPrismObject().clone();
    AssignmentType assignmentType = getAssignmentType(ASSIGNMENT_ROLE_MANAGER_FILE);
    AssignmentType assignmentForUser = assignmentType.clone();
    assignmentForUser.asPrismContainerValue().setParent(null);
    user.asObjectable().getAssignment().add(assignmentForUser);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_JACK_OID, UserType.F_COST_CENTER, prismContext, "management");
    ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(user, userDelta, null);
    userOdo.recompute();
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
    assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
    assignmentIdi.recompute();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, TEST_NAME, task, result);
    evaluatedAssignment.evaluateConstructions(userOdo, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(evaluatedAssignment);
    display("Evaluated assignment", evaluatedAssignment.debugDump());
    assertEquals(4, evaluatedAssignment.getConstructionTriple().size());
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    // because Employee's job metarole is active even if Manager's is not
    assertConstruction(evaluatedAssignment, ZERO, "title", ZERO, "Employee");
    assertConstruction(evaluatedAssignment, ZERO, "title", PLUS);
    assertConstruction(evaluatedAssignment, ZERO, "title", MINUS);
    // because Manager's job metarole is originally not active
    assertConstruction(evaluatedAssignment, PLUS, "title", ZERO, "Manager");
    assertConstruction(evaluatedAssignment, PLUS, "title", PLUS);
    assertConstruction(evaluatedAssignment, PLUS, "title", MINUS);
    assertNoConstruction(evaluatedAssignment, MINUS, "title");
    // because Generic Metarole is active all the time
    assertConstruction(evaluatedAssignment, ZERO, "location", ZERO, "Caribbean");
    assertConstruction(evaluatedAssignment, ZERO, "location", PLUS);
    assertConstruction(evaluatedAssignment, ZERO, "location", MINUS);
    assertNoConstruction(evaluatedAssignment, PLUS, "location");
    assertNoConstruction(evaluatedAssignment, MINUS, "location");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 19 with ItemDeltaItem

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

the class TestAbstractAssignmentEvaluator method test200DisableEngineerEmployeeInducement.

/**
	 * Disable Engineer -> Employee inducement.
	 */
@Test(enabled = false)
public void test200DisableEngineerEmployeeInducement() throws Exception {
    final String TEST_NAME = "test200DisableEngineerEmployeeInducement";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    // disable Engineer->Employee inducement
    ObjectDelta disableInducementDelta = DeltaBuilder.deltaFor(RoleType.class, prismContext).item(RoleType.F_INDUCEMENT, 3, F_ACTIVATION, F_ADMINISTRATIVE_STATUS).replace(ActivationStatusType.DISABLED).asObjectDelta(ROLE_CORP_ENGINEER_OID);
    modelService.executeChanges(Collections.singletonList(disableInducementDelta), null, task, result);
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator();
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    AssignmentType assignmentType = getAssignmentType(ASSIGNMENT_ROLE_ENGINEER_FILE);
    ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(userTypeJack.asPrismObject(), null, null);
    userOdo.recompute();
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
    assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
    assignmentIdi.recompute();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, "testRoleEngineer", task, result);
    evaluatedAssignment.evaluateConstructions(userOdo, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(evaluatedAssignment);
    display("Evaluated assignment", evaluatedAssignment.debugDump());
// TODO
//		assertEquals(2, evaluatedAssignment.getConstructions().size());
//		PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
//
//		assertConstruction(evaluatedAssignment, ZERO, "title", ZERO, "Engineer");
//		assertConstruction(evaluatedAssignment, ZERO, "title", PLUS);
//		assertConstruction(evaluatedAssignment, ZERO, "title", MINUS);
//		assertNoConstruction(evaluatedAssignment, PLUS, "title");
//		assertNoConstruction(evaluatedAssignment, MINUS, "title");
//
//		assertConstruction(evaluatedAssignment, ZERO, "location", ZERO, "Caribbean");
//		assertConstruction(evaluatedAssignment, ZERO, "location", PLUS);
//		assertConstruction(evaluatedAssignment, ZERO, "location", MINUS);
//		assertNoConstruction(evaluatedAssignment, PLUS, "location");
//		assertNoConstruction(evaluatedAssignment, MINUS, "location");
//
//		assertEquals("Wrong number of admin GUI configs", 1, evaluatedAssignment.getAdminGuiConfigurations().size());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) RoleType(com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 20 with ItemDeltaItem

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

the class TestAbstractAssignmentEvaluator method test120DirectExpressionReplaceDescription.

@Test
public void test120DirectExpressionReplaceDescription() throws Exception {
    final String TEST_NAME = "test120DirectExpressionReplaceDescription";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> user = userTypeJack.asPrismObject().clone();
    AssignmentType assignmentType = unmarshallValueFromFile(ASSIGNMENT_DIRECT_EXPRESSION_FILE, AssignmentType.class);
    user.asObjectable().getAssignment().add(assignmentType.clone());
    ItemPath path = new ItemPath(new NameItemPathSegment(UserType.F_ASSIGNMENT), new IdItemPathSegment(123L), new NameItemPathSegment(AssignmentType.F_DESCRIPTION));
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationReplaceProperty(UserType.class, USER_JACK_OID, path, prismContext, "captain");
    ObjectDeltaObject<UserType> userOdo = new ObjectDeltaObject<>(user, userDelta, null);
    userOdo.recompute();
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);
    ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>();
    assignmentIdi.setItemOld(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
    assignmentIdi.setSubItemDeltas(userDelta.getModifications());
    assignmentIdi.recompute();
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, userTypeJack, "testDirect", task, result);
    evaluatedAssignment.evaluateConstructions(userOdo, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    assertNotNull(evaluatedAssignment);
    display("Evaluated assignment", evaluatedAssignment);
    assertEquals(1, evaluatedAssignment.getConstructionTriple().size());
    PrismAsserts.assertParentConsistency(user);
    Construction<UserType> construction = evaluatedAssignment.getConstructionTriple().getZeroSet().iterator().next();
    assertNotNull("No object class definition in construction", construction.getRefinedObjectClassDefinition());
    assertEquals(1, construction.getAttributeMappings().size());
    Mapping<PrismPropertyValue<String>, PrismPropertyDefinition<String>> attributeMapping = (Mapping<PrismPropertyValue<String>, PrismPropertyDefinition<String>>) construction.getAttributeMappings().iterator().next();
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = attributeMapping.getOutputTriple();
    PrismAsserts.assertTripleNoZero(outputTriple);
    PrismAsserts.assertTriplePlus(outputTriple, "The best captain the world has ever seen");
    PrismAsserts.assertTripleMinus(outputTriple, "The best pirate the world has ever seen");
    // the same using other words
    assertConstruction(evaluatedAssignment, ZERO, "title", ZERO);
    assertConstruction(evaluatedAssignment, ZERO, "title", PLUS, "The best captain the world has ever seen");
    assertConstruction(evaluatedAssignment, ZERO, "title", MINUS, "The best pirate the world has ever seen");
    assertNoConstruction(evaluatedAssignment, PLUS, "title");
    assertNoConstruction(evaluatedAssignment, MINUS, "title");
    assertEquals("Wrong number of admin GUI configs", 0, evaluatedAssignment.getAdminGuiConfigurations().size());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

ItemDeltaItem (com.evolveum.midpoint.repo.common.expression.ItemDeltaItem)25 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)16 ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)16 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)15 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)15 Task (com.evolveum.midpoint.task.api.Task)15 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)14 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)13 Test (org.testng.annotations.Test)13 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)4 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)3 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)3 PrismValueDeltaSetTriple (com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple)3 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)3 Source (com.evolveum.midpoint.repo.common.expression.Source)3