use of com.evolveum.midpoint.task.api.Task 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.task.api.Task 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.task.api.Task 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.task.api.Task in project midpoint by Evolveum.
the class RoleMemberPanel method removeMembersPerformed.
@Override
protected void removeMembersPerformed(QueryScope scope, AjaxRequestTarget target) {
Task operationalTask = getPageBase().createSimpleTask(getTaskName("Remove", scope));
ObjectDelta delta = prepareDelta(FocusType.COMPLEX_TYPE, null, MemberOperation.REMOVE, operationalTask.getResult());
executeMemberOperation(operationalTask, FocusType.COMPLEX_TYPE, getActionQuery(scope), delta, TaskCategory.EXECUTE_CHANGES, target);
}
use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.
the class PageTaskAdd method savePerformed.
private void savePerformed(AjaxRequestTarget target) {
LOGGER.debug("Saving new task.");
OperationResult result = new OperationResult(OPERATION_SAVE_TASK);
TaskAddDto dto = model.getObject();
Task operationTask = createSimpleTask(OPERATION_SAVE_TASK);
try {
TaskType task = createTask(dto);
getPrismContext().adopt(task);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Adding new task.");
}
getModelService().executeChanges(prepareChangesToExecute(task), null, operationTask, result);
result.recomputeStatus();
setResponsePage(PageTasks.class);
} catch (Exception ex) {
result.recomputeStatus();
result.recordFatalError("Unable to save task.", ex);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't add new task", ex);
}
showResult(result);
target.add(getFeedbackPanel());
}
Aggregations