use of com.evolveum.midpoint.prism.util.ObjectDeltaObject in project midpoint by Evolveum.
the class TestAssignmentProcessor2 method test062JackDeputyOfGuybrushDeputyOfBarbossaInLoginMode.
// goes through assignmentEvaluator in order to employ login mode
// MID-4176
@Test(enabled = FIRST_PART)
public void test062JackDeputyOfGuybrushDeputyOfBarbossaInLoginMode() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = getTestOperationResult();
PrismObject<UserType> jack = getUser(USER_JACK_OID);
AssignmentType jackGuybrushAssignment = new AssignmentType(prismContext).targetRef(USER_GUYBRUSH_OID, UserType.COMPLEX_TYPE, SchemaConstants.ORG_DEPUTY);
jackGuybrushAssignment.beginLimitTargetContent().allowTransitive(true);
jack.asObjectable().getAssignment().add(jackGuybrushAssignment);
LensContext<UserType> context = new LensContextPlaceholder<>(jack);
AssignmentEvaluator<UserType> assignmentEvaluator = new AssignmentEvaluator.Builder<UserType>().referenceResolver(referenceResolver).focusOdo(new ObjectDeltaObject<>(jack, null, jack, jack.getDefinition())).lensContext(context).channel(context.getChannel()).modelBeans(modelBeans).objectResolver(objectResolver).systemObjectCache(systemObjectCache).relationRegistry(relationRegistry).prismContext(prismContext).mappingFactory(mappingFactory).mappingEvaluator(mappingEvaluator).contextLoader(contextLoader).activationComputer(activationComputer).now(clock.currentTimeXMLGregorianCalendar()).systemConfiguration(context.getSystemConfiguration()).loginMode(true).build();
// noinspection unchecked,rawtypes
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(jackGuybrushAssignment), jackGuybrushAssignment.asPrismContainerValue().getDefinition());
// WHEN
when();
EvaluatedAssignmentImpl<UserType> evaluatedAssignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, jack.asObjectable(), jack.toString(), AssignmentOrigin.createInObject(), task, result);
// THEN
then();
displayDumpable("Output context", context);
displayDumpable("Evaluated assignment", evaluatedAssignment);
assertSuccess("Assignment evaluator failed (result)", result);
assertEquals("Wrong evaluatedAssignment.isValid", true, evaluatedAssignment.isValid());
assertTargets(evaluatedAssignment, true, "R1 R2 O3 R4 R5 R6", null, null, null, null, null);
assertTargets(evaluatedAssignment, false, "guybrush barbossa MR1 MR2 MR3 MR4 MMR1", null, null, null, null, null);
assertMembershipRef(evaluatedAssignment, "");
assertOrgRef(evaluatedAssignment, "O3");
assertDelegation(evaluatedAssignment, "guybrush barbossa R1 R2 O3 R4 R5 R6");
PrismReferenceValue guybrushRef = evaluatedAssignment.getDelegationRefVals().stream().filter(v -> USER_GUYBRUSH_OID.equals(v.getOid())).findFirst().orElseThrow(() -> new AssertionError("No guybrush ref in delegation ref vals"));
assertEquals("Wrong relation for guybrush delegation", SchemaConstants.ORG_DEPUTY, guybrushRef.getRelation());
// the following entities are not evaluated in login mode
assertConstructions(evaluatedAssignment, (String) null, null, null, null, null, null);
assertFocusMappings(evaluatedAssignment, (String) null);
assertFocusPolicyRules(evaluatedAssignment, (String) null);
assertTargetPolicyRules(evaluatedAssignment, (String) null, null);
assertAuthorizations(evaluatedAssignment, "R1 R2 O3 R4 R5 R6");
assertGuiConfig(evaluatedAssignment, "R1 R2 O3 R4 R5 R6");
assertSerializable(context);
}
use of com.evolveum.midpoint.prism.util.ObjectDeltaObject in project midpoint by Evolveum.
the class PersonaProcessor method personaAdd.
private <F extends FocusType, T extends FocusType> void personaAdd(LensContext<F> context, PersonaKey key, PersonaConstruction<F> construction, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, PolicyViolationException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
PrismObject<F> focus = context.getFocusContext().getObjectNew();
LOGGER.debug("Adding persona {} for {} using construction {}", key, focus, construction);
PersonaConstructionType constructionBean = construction.getConstructionBean();
ObjectReferenceType templateRef = constructionBean.getObjectMappingRef();
ObjectTemplateType template = objectResolver.resolve(templateRef, ObjectTemplateType.class, null, "object template in persona construction in " + focus, task, result);
QName targetType = constructionBean.getTargetType();
PrismObjectDefinition<T> objectDef = prismContext.getSchemaRegistry().findObjectDefinitionByType(targetType);
PrismObject<T> target = objectDef.instantiate();
if (!constructionBean.getArchetypeRef().isEmpty()) {
FocusTypeUtil.addArchetypeAssignments(target, constructionBean.getArchetypeRef());
} else {
FocusTypeUtil.setSubtype(target, constructionBean.getTargetSubtype());
}
// pretend ADD focusOdo. We need to push all the items through the object template
ObjectDeltaObject<F> focusOdoAbsolute = new ObjectDeltaObject<>(null, focus.createAddDelta(), focus, context.getFocusContext().getObjectDefinition());
ObjectDelta<T> targetDelta = target.createAddDelta();
String contextDesc = "persona construction for " + focus;
XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
Collection<ItemDelta<?, ?>> itemDeltas = processPersonaTemplate(context, template, focusOdoAbsolute, target, targetDelta, contextDesc, now, task, result);
LOGGER.trace("itemDeltas:\n{}", DebugUtil.debugDumpLazily(itemDeltas));
for (ItemDelta itemDelta : itemDeltas) {
itemDelta.applyTo(target);
}
LOGGER.trace("Creating persona:\n{}", target.debugDumpLazily(1));
String targetOid = executePersonaDelta(targetDelta, focus.getOid(), task, result);
target.setOid(targetOid);
link(context, target.asObjectable(), result);
}
Aggregations