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());
}
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());
}
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());
}
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;
}
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);
}
Aggregations