use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class AutoAssignMappingCollector method collectAutoassignMappings.
<AH extends AssignmentHolderType> void collectAutoassignMappings(LensContext<AH> context, List<FocalMappingEvaluationRequest<?, ?>> mappings, OperationResult result) throws SchemaException {
if (!autoassignEnabled(context.getSystemConfiguration())) {
return;
}
ObjectQuery query = prismContext.queryFor(AbstractRoleType.class).item(SchemaConstants.PATH_AUTOASSIGN_ENABLED).eq(true).build();
ResultHandler<AbstractRoleType> handler = (role, objectResult) -> {
AutoassignSpecificationType autoassign = role.asObjectable().getAutoassign();
if (autoassign == null) {
return true;
}
if (!isTrue(autoassign.isEnabled())) {
return true;
}
FocalAutoassignSpecificationType focalAutoassignSpec = autoassign.getFocus();
if (focalAutoassignSpec == null) {
return true;
}
if (!isApplicableFor(focalAutoassignSpec.getSelector(), context.getFocusContext(), objectResult)) {
return true;
}
for (AutoassignMappingType autoMapping : focalAutoassignSpec.getMapping()) {
AutoassignMappingType mapping = LensUtil.setMappingTarget(autoMapping, new ItemPathType(SchemaConstants.PATH_ASSIGNMENT));
mappings.add(new AutoassignRoleMappingEvaluationRequest(mapping, role.asObjectable()));
LOGGER.trace("Collected autoassign mapping {} from {}", mapping.getName(), role);
}
return true;
};
cacheRepositoryService.searchObjectsIterative(AbstractRoleType.class, query, handler, createReadOnlyCollection(), true, result);
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class AbstractTestObjectLifecycleApproval method createObject.
private void createObject(ObjectType object, boolean immediate, boolean approve, String assigneeOid) throws Exception {
// noinspection unchecked
ObjectDelta<RoleType> addObjectDelta = DeltaFactory.Object.createAddDelta((PrismObject<RoleType>) object.asPrismObject());
executeTest(new TestDetails() {
@Override
protected LensContext createModelContext(OperationResult result) throws Exception {
// noinspection unchecked
LensContext<RoleType> lensContext = createLensContext((Class) object.getClass());
addFocusDeltaToContext(lensContext, addObjectDelta);
return lensContext;
}
@Override
protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) throws Exception {
if (!immediate) {
// ModelContext taskModelContext = temporaryHelper.getModelContext(rootCase, opTask, result);
// ObjectDelta realDelta0 = taskModelContext.getFocusContext().getPrimaryDelta();
// assertTrue("Non-empty primary focus delta: " + realDelta0.debugDump(), realDelta0.isEmpty());
assertNoObject(object);
ExpectedTask expectedTask = new ExpectedTask(null, "Adding role \"" + object.getName().getOrig() + "\"");
ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(assigneeOid, null, expectedTask);
assertWfContextAfterClockworkRun(rootCase, subcases, workItems, null, Collections.singletonList(expectedTask), Collections.singletonList(expectedWorkItem));
}
}
@Override
protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) throws Exception {
assertNoObject(object);
}
@Override
protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) throws Exception {
if (approve) {
assertObject(object);
} else {
assertNoObject(object);
}
}
@Override
protected boolean executeImmediately() {
return immediate;
}
@Override
public List<ApprovalInstruction> getApprovalSequence() {
return singletonList(new ApprovalInstruction(null, true, USER_JUPITER_OID, "creation comment"));
}
}, 1);
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class TestObjectLifecycleApprovalGlobal method test510AddInducementsToJudge.
@Test
public void test510AddInducementsToJudge() throws Exception {
login(userAdministrator);
ObjectDelta<RoleType> judgeDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_INDUCEMENT).add(createAssignmentTo(OID1, ObjectTypes.ROLE, prismContext), createAssignmentTo(OID2, ObjectTypes.ROLE, prismContext)).item(RoleType.F_DESCRIPTION).replace("hi").asObjectDeltaCast(roleJudgeOid);
executeTest(new TestDetails() {
@Override
protected LensContext createModelContext(OperationResult result) throws Exception {
LensContext<RoleType> lensContext = createLensContext(RoleType.class);
addFocusDeltaToContext(lensContext, judgeDelta);
lensContext.setOptions(executeOptions().executeImmediatelyAfterApproval());
return lensContext;
}
@Override
protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) {
display("subtasks", subcases);
display("work items", workItems);
// todo some asserts here
}
@Override
protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) {
// nothing here
}
@Override
protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) {
// nothing here
}
@Override
protected boolean executeImmediately() {
return true;
}
@Override
public boolean strictlySequentialApprovals() {
return true;
}
@Override
public List<ApprovalInstruction> getApprovalSequence() {
List<ApprovalInstruction> instructions = new ArrayList<>();
// this is step 1 in 1st inducement part
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
// this is step 2 in 1st inducement part
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_BOB_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
// this is step 1 in 2nd inducement part
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
// this is step 2 in 2nd inducement part
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_BOB_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
// this is step 1 in main part (owner)
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_JUDGE_OWNER_OID, null, new ExpectedTask(null, "Modifying role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
// this is step 2 in main part
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Modifying role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
return instructions;
}
}, 3);
// TODO some more asserts
PrismObject<RoleType> judgeAfter = searchObjectByName(RoleType.class, "judge");
display("Judge role", judgeAfter);
assertEquals("Wrong risk level", "high", judgeAfter.asObjectable().getRiskLevel());
assertEquals("Wrong description", "hi", judgeAfter.asObjectable().getDescription());
assertInducedRoles(judgeAfter, OID1, OID2);
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class TestObjectLifecycleApprovalGlobal method test520DeleteRoleJudge.
// MID-4372
@Test
public void test520DeleteRoleJudge() throws Exception {
login(userAdministrator);
deleteObject(UserType.class, USER_JUDGE_OWNER_OID);
ObjectDelta<RoleType> deleteDelta = prismContext.deltaFactory().object().createDeleteDelta(RoleType.class, roleJudgeOid);
executeTest(new TestDetails() {
@Override
protected LensContext createModelContext(OperationResult result) throws Exception {
LensContext<RoleType> lensContext = createLensContext(RoleType.class);
addFocusDeltaToContext(lensContext, deleteDelta);
lensContext.setOptions(executeOptions().executeImmediatelyAfterApproval());
return lensContext;
}
@Override
protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) {
display("subtasks", subcases);
display("work items", workItems);
// todo some asserts here
}
@Override
protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) {
assertObjectExists(RoleType.class, roleJudgeOid);
}
@Override
protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) {
assertObjectDoesntExist(RoleType.class, roleJudgeOid);
}
@Override
protected boolean executeImmediately() {
return true;
}
@Override
public boolean strictlySequentialApprovals() {
return true;
}
@Override
public List<ApprovalInstruction> getApprovalSequence() {
List<ApprovalInstruction> instructions = new ArrayList<>();
// this is step 2 in main part (first step is owner that is skipped as the owner was already deleted)
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Deleting role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
return instructions;
}
}, 1);
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class TestObjectLifecycleApprovalGlobal method test500CreateRoleJudge.
@Test
public void test500CreateRoleJudge() throws Exception {
login(userAdministrator);
Task task = getTestTask();
OperationResult result = getTestOperationResult();
RoleType judge = new RoleType(prismContext).name("judge").riskLevel("high");
ObjectDelta<RoleType> addObjectDelta = DeltaFactory.Object.createAddDelta(judge.asPrismObject());
executeTest(new TestDetails() {
@Override
protected LensContext createModelContext(OperationResult result) throws Exception {
LensContext<RoleType> lensContext = createLensContext(RoleType.class);
addFocusDeltaToContext(lensContext, addObjectDelta);
lensContext.setOptions(executeOptions().executeImmediatelyAfterApproval());
return lensContext;
}
@Override
protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) {
display("subtasks", subcases);
display("work items", workItems);
// todo some asserts here
}
@Override
protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) throws Exception {
assertNoObject(judge);
}
@Override
protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) throws Exception {
assertObject(judge);
}
@Override
protected boolean executeImmediately() {
return true;
}
@Override
public boolean strictlySequentialApprovals() {
return true;
}
@Override
public List<ApprovalInstruction> getApprovalSequence() {
List<ApprovalInstruction> instructions = new ArrayList<>();
// this is step 2 in riskLevel part (first step is owner that is skipped)
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Setting riskLevel")), true, USER_ADMINISTRATOR_OID, null));
// this is step 3 in riskLevel part
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_PETER_OID, null, new ExpectedTask(null, "Setting riskLevel")), true, USER_ADMINISTRATOR_OID, null));
// this is step 2 in main part
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_JUPITER_OID, null, new ExpectedTask(null, "Adding role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
// this is step 3 in main part
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_ADMINISTRATOR_OID, null, new ExpectedTask(null, "Adding role \"judge\"")), true, USER_ADMINISTRATOR_OID, null));
return instructions;
}
}, 2);
// TODO some more asserts
PrismObject<RoleType> judgeAfter = searchObjectByName(RoleType.class, "judge");
roleJudgeOid = judgeAfter.getOid();
PrismReferenceValue judgeOwner = getPrismContext().itemFactory().createReferenceValue(roleJudgeOid, RoleType.COMPLEX_TYPE);
judgeOwner.setRelation(SchemaConstants.ORG_OWNER);
executeChanges(prismContext.deltaFor(UserType.class).item(UserType.F_ASSIGNMENT).add(createAssignmentTo(judgeAfter, SchemaConstants.ORG_OWNER)).asObjectDeltaCast(USER_JUDGE_OWNER_OID), null, task, result);
display("Judge role", judgeAfter);
display("Judge owner", getUser(USER_JUDGE_OWNER_OID));
assertEquals("Wrong risk level", "high", judgeAfter.asObjectable().getRiskLevel());
}
Aggregations