Search in sources :

Example 11 with ObjectDeltaObject

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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) PrismContainerValue(com.evolveum.midpoint.prism.PrismContainerValue) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDeltaObject(com.evolveum.midpoint.prism.util.ObjectDeltaObject) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) PrismContainerDefinition(com.evolveum.midpoint.prism.PrismContainerDefinition) Test(org.testng.annotations.Test)

Example 12 with ObjectDeltaObject

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);
}
Also used : QName(javax.xml.namespace.QName) ObjectDeltaObject(com.evolveum.midpoint.prism.util.ObjectDeltaObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar)

Aggregations

ObjectDeltaObject (com.evolveum.midpoint.prism.util.ObjectDeltaObject)12 ItemDeltaItem (com.evolveum.midpoint.prism.util.ItemDeltaItem)6 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 SynchronizationPolicyDecision (com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision)2 AssignmentEvaluator (com.evolveum.midpoint.model.impl.lens.assignments.AssignmentEvaluator)2 ContextLoader (com.evolveum.midpoint.model.impl.lens.projector.ContextLoader)2 ProjectorProcessor (com.evolveum.midpoint.model.impl.lens.projector.ProjectorProcessor)2 com.evolveum.midpoint.model.impl.lens.projector.mappings (com.evolveum.midpoint.model.impl.lens.projector.mappings)2 ProcessorExecution (com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorExecution)2 ProcessorMethod (com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod)2 ModelImplUtils (com.evolveum.midpoint.model.impl.util.ModelImplUtils)2 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)2 com.evolveum.midpoint.prism.delta (com.evolveum.midpoint.prism.delta)2 ConfigurableValuePolicySupplier (com.evolveum.midpoint.repo.common.expression.ConfigurableValuePolicySupplier)2 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)2 Task (com.evolveum.midpoint.task.api.Task)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 ActivationComputer (com.evolveum.midpoint.common.ActivationComputer)1 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)1