Search in sources :

Example 6 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class TestAbstractAssignmentEvaluator method test140RoleVisitor.

/*

    Explanation for roles structure (copied from role-corp-generic-metarole.xml)

        user-assignable roles:

          roles of unspecified type
          - Visitor
          - Customer

          roles of type: job
          - Contractor
          - Employee
            - Engineer (induces Employee)
            - Manager (induces Employee)

        metaroles:

          - Generic Metarole:                                   assigned to Visitor and Customer                            [ induces ri:location attribute - from user/locality ]
            - Job Metarole (induces Generic Metarole):          assigned to Contractor, Employee, Engineer, Manager         [ induces ri:title attribute - from role/name ]

     */
@Test
public void test140RoleVisitor() throws Exception {
    final String TEST_NAME = "test140RoleVisitor";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator();
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    AssignmentType assignmentType = getAssignmentType(ASSIGNMENT_ROLE_VISITOR_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, 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(1, evaluatedAssignment.getConstructionTriple().size());
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    assertConstruction(evaluatedAssignment, ZERO, "title", ZERO);
    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", 0, evaluatedAssignment.getAdminGuiConfigurations().size());
}
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 7 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class TestAbstractAssignmentEvaluator method test160AddRoleEngineer.

@Test
public void test160AddRoleEngineer() throws Exception {
    final String TEST_NAME = "test160AddRoleEngineer";
    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_ENGINEER_FILE);
    AssignmentType assignmentForUser = assignmentType.clone();
    assignmentForUser.asPrismContainerValue().setParent(null);
    ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddContainer(UserType.class, USER_JACK_OID, UserType.F_ASSIGNMENT, prismContext, assignmentForUser.asPrismContainerValue());
    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("Wrong number of constructions", 4, evaluatedAssignment.getConstructionTriple().size());
    PrismAsserts.assertParentConsistency(userTypeJack.asPrismObject());
    /*
         *  Here we observe an important thing about AssignmentEvaluator/AssignmentProcessor.
         *  The evaluator does not consider whether the assignment as such is being added or deleted or stays present.
         *  In all these cases all the constructions go into the ZERO set of constructions.
         *
         *  However, it considers changes in data that are used by assignments - either in conditions or in mappings.
         *  Changes of data used in mappings are demonstrated by testDirectExpressionReplaceDescription
         *  and testDirectExpressionReplaceDescriptionFromNull. Changes of data used in conditions are demonstrated by
         *  a couple of tests below.
         *
         *  Changes in assignment presence (add/delete) are reflected into plus/minus sets by AssignmentProcessor.
         */
    assertConstruction(evaluatedAssignment, ZERO, "title", ZERO, "Employee", "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) 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 8 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class TestAbstractAssignmentEvaluator method test300DisableRoleEmployee.

/**
	 * Jack is an Engineer which induces Employee. But role Employee is not valid anymore.
     */
@Test
public void test300DisableRoleEmployee() throws Exception {
    final String TEST_NAME = "test300DisableRoleEmployee";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestAssignmentEvaluator.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    // disable role Employee
    ObjectDelta disableEmployeeDelta = DeltaBuilder.deltaFor(RoleType.class, prismContext).item(ACTIVATION_ADMINISTRATIVE_STATUS_PATH).replace(ActivationStatusType.DISABLED).asObjectDelta(ROLE_CORP_EMPLOYEE_OID);
    modelService.executeChanges(Collections.<ObjectDelta<? extends ObjectType>>singletonList(disableEmployeeDelta), 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());
    assertEquals(2, evaluatedAssignment.getConstructionTriple().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 9 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class DynamicFieldGroupPanel method createItemWrapper.

private ItemWrapper createItemWrapper(AbstractFormItemType formField, ObjectWrapper objectWrapper) {
    ItemPathType itemPathType = GuiImplUtil.getPathType(formField);
    if (itemPathType == null) {
        getSession().error("Bad form item definition. It has to contain reference to the real attribute");
        LOGGER.error("Bad form item definition. It has to contain reference to the real attribute");
        throw new RestartResponseException(getPageBase());
    }
    ItemPath path = itemPathType.getItemPath();
    ItemDefinition itemDef = objectWrapper.getObject().getDefinition().findItemDefinition(path);
    ItemWrapper itemWrapper = null;
    if (itemDef instanceof PrismContainerDefinition) {
        itemWrapper = objectWrapper.findContainerWrapper(path);
    } else {
        itemWrapper = objectWrapper.findPropertyWrapper(path);
    }
    if (itemWrapper == null) {
        getSession().error("Bad form item definition. No attribute with path: " + path + " was found");
        LOGGER.error("Bad form item definition. No attribute with path: " + path + " was found");
        throw new RestartResponseException(getPageBase());
    }
    applyFormDefinition(itemWrapper, formField);
    return itemWrapper;
}
Also used : RestartResponseException(org.apache.wicket.RestartResponseException) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 10 with PrismContainerDefinition

use of com.evolveum.midpoint.prism.PrismContainerDefinition in project midpoint by Evolveum.

the class PageUser method saveDelegationToUser.

private void saveDelegationToUser(UserType user, List<AssignmentEditorDto> assignmentEditorDtos) {
    OperationResult result = new OperationResult(OPERATION_SAVE);
    ObjectDelta<UserType> delta;
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    try {
        delta = user.asPrismObject().createModifyDelta();
        deltas.add(delta);
        PrismContainerDefinition def = user.asPrismObject().getDefinition().findContainerDefinition(UserType.F_ASSIGNMENT);
        handleAssignmentDeltas(delta, assignmentEditorDtos, def, true);
        getModelService().executeChanges(deltas, null, createSimpleTask(OPERATION_SAVE), result);
        result.recordSuccess();
    } catch (Exception e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Could not save assignments ", e);
        error("Could not save assignments. Reason: " + e);
    } finally {
        result.recomputeStatus();
    }
    showResult(result);
}
Also used : PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Aggregations

PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)41 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)23 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)18 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)17 Task (com.evolveum.midpoint.task.api.Task)16 Test (org.testng.annotations.Test)16 ItemDeltaItem (com.evolveum.midpoint.repo.common.expression.ItemDeltaItem)15 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)14 ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)13 QName (javax.xml.namespace.QName)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 ArrayList (java.util.ArrayList)8 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)6 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)5 AjaxButton (com.evolveum.midpoint.web.component.AjaxButton)5 List (java.util.List)5 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)4 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)4 DropDownChoicePanel (com.evolveum.midpoint.web.component.input.DropDownChoicePanel)4