use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class TestObjectLifecycleApprovalGlobal method test610DeleteInducementsFromCaptain.
@Test
public void test610DeleteInducementsFromCaptain() throws Exception {
login(userAdministrator);
PrismObject<RoleType> captainBefore = getRole(roleCaptainOid);
ObjectDelta<RoleType> captainDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_INDUCEMENT).delete(cloneCollectionMembers(captainBefore.findContainer(RoleType.F_INDUCEMENT).getValues())).asObjectDeltaCast(roleCaptainOid);
executeTest(new TestDetails() {
@Override
protected LensContext createModelContext(OperationResult result) throws Exception {
LensContext<RoleType> lensContext = createLensContext(RoleType.class);
addFocusDeltaToContext(lensContext, captainDelta);
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;
}
@SuppressWarnings("Duplicates")
@Override
public List<ApprovalInstruction> getApprovalSequence() {
List<ApprovalInstruction> instructions = new ArrayList<>();
// this is step 1 in 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 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 inducement part (2nd)
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 inducement part (2nd)
instructions.add(new ApprovalInstruction(new ExpectedWorkItem(USER_BOB_OID, null, new ExpectedTask(null, "Changing inducement")), true, USER_ADMINISTRATOR_OID, null));
return instructions;
}
}, 2);
// TODO some more asserts
PrismObject<RoleType> captainAfter = getRole(roleCaptainOid);
display("Captain role", captainAfter);
assertEquals("Wrong risk level", "high", captainAfter.asObjectable().getRiskLevel());
assertInducements(captainAfter, 0);
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class TestObjectLifecycleAdvanced method test020ActivateIncompleteRole.
@Test
public void test020ActivateIncompleteRole() throws Exception {
login(userAdministrator);
Task task = getTestTask();
OperationResult result = getTestOperationResult();
@SuppressWarnings({ "raw" }) ObjectDelta<RoleType> activateRoleDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_LIFECYCLE_STATE).replace(SchemaConstants.LIFECYCLE_ACTIVE).asObjectDelta(roleEmployeeOid);
RecordingProgressListener recordingListener = new RecordingProgressListener();
try {
modelService.executeChanges(Collections.singleton(activateRoleDelta), null, task, Collections.singleton(recordingListener), result);
fail("unexpected success");
} catch (PolicyViolationException e) {
System.out.println("Got expected exception: " + e.getMessage());
}
// noinspection unchecked
LensContext<RoleType> context = (LensContext<RoleType>) recordingListener.getModelContext();
System.out.println(context.dumpFocusPolicyRules(0));
EvaluatedPolicyRule incompleteActivationRule = context.getFocusContext().getObjectPolicyRules().stream().filter(rule -> "disallow-incomplete-role-activation".equals(rule.getName())).findFirst().orElseThrow(() -> new AssertionError("rule not found"));
// objectState + or
assertEquals("Wrong # of triggers in incompleteActivationRule", 2, incompleteActivationRule.getTriggers().size());
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class TestObjectLifecycleAdvanced method test045ActivateCompleteRole.
@Test
public void test045ActivateCompleteRole() throws Exception {
login(userAdministrator);
ObjectDelta<RoleType> activateRoleDelta = prismContext.deltaFor(RoleType.class).item(RoleType.F_LIFECYCLE_STATE).replace(SchemaConstants.LIFECYCLE_ACTIVE).item(RoleType.F_DESCRIPTION).replace("hi").asObjectDelta(roleEmployeeOid);
executeTest(new TestDetails() {
@Override
protected LensContext createModelContext(OperationResult result) throws Exception {
LensContext<RoleType> lensContext = createLensContext(RoleType.class);
addFocusDeltaToContext(lensContext, activateRoleDelta);
return lensContext;
}
@Override
protected void afterFirstClockworkRun(CaseType rootCase, CaseType case0, List<CaseType> subcases, List<CaseWorkItemType> workItems, Task opTask, OperationResult result) throws Exception {
ExpectedTask expectedTask = new ExpectedTask(null, "Matching state: after operation (\"active lifecycleState\")");
ExpectedWorkItem expectedWorkItem = new ExpectedWorkItem(userEmployeeOwnerOid, null, expectedTask);
assertWfContextAfterClockworkRun(rootCase, subcases, workItems, null, Collections.singletonList(expectedTask), Collections.singletonList(expectedWorkItem));
ApprovalContextType wfc = subcases.get(0).getApprovalContext();
assertEquals("Wrong # of attached policy rules entries", 1, wfc.getPolicyRules().getEntry().size());
SchemaAttachedPolicyRuleType attachedRule = wfc.getPolicyRules().getEntry().get(0);
assertEquals(1, attachedRule.getStageMin().intValue());
assertEquals(1, attachedRule.getStageMax().intValue());
assertEquals("Wrong # of attached triggers", 1, attachedRule.getRule().getTrigger().size());
EvaluatedPolicyRuleTriggerType trigger = attachedRule.getRule().getTrigger().get(0);
assertEquals("Wrong constraintKind in trigger", PolicyConstraintKindType.TRANSITION, trigger.getConstraintKind());
CaseWorkItemType workItem = subcases.get(0).getWorkItem().get(0);
assertEquals("Wrong # of additional information", 0, workItem.getAdditionalInformation().size());
}
@Override
protected void afterCase0Finishes(CaseType rootCase, Task opTask, OperationResult result) {
// assertNoObject(employee);
}
@Override
protected void afterRootCaseFinishes(CaseType rootCase, List<CaseType> subcases, Task opTask, OperationResult result) {
// assertObject(employee);
}
@Override
protected boolean executeImmediately() {
return false;
}
@Override
protected Boolean decideOnApproval(CaseWorkItemType caseWorkItem) throws Exception {
login(getUser(userEmployeeOwnerOid));
return true;
}
}, 1);
}
use of com.evolveum.midpoint.model.impl.lens.LensContext in project midpoint by Evolveum.
the class BasePrimaryChangeAspect method resolveReferenceFromFilter.
private <O extends ObjectType, F extends ObjectType> List<ObjectReferenceType> resolveReferenceFromFilter(Class<O> clazz, SearchFilterType filter, String sourceDescription, LensContext<F> lensContext, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment.ExpressionEnvironmentBuilder<F, PrismValue, ItemDefinition<?>>().lensContext(lensContext).currentResult(result).currentTask(task).build());
try {
PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(result);
VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(getFocusObjectable(lensContext), null, null, systemConfiguration.asObjectable(), prismContext);
ObjectFilter origFilter = prismContext.getQueryConverter().parseFilter(filter, clazz);
ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(origFilter, variables, MiscSchemaUtil.getExpressionProfile(), mappingFactory.getExpressionFactory(), prismContext, " evaluating approverRef filter expression ", task, result);
if (evaluatedFilter == null) {
throw new SchemaException("Filter could not be evaluated in approverRef in " + sourceDescription + "; original filter = " + origFilter);
}
SearchResultList<PrismObject<O>> targets = repositoryService.searchObjects(clazz, prismContext.queryFactory().createQuery(evaluatedFilter), null, result);
return targets.stream().map(object -> ObjectTypeUtil.createObjectRef(object, prismContext)).collect(Collectors.toList());
} finally {
ModelExpressionThreadLocalHolder.popExpressionEnvironment();
}
}
Aggregations