Search in sources :

Example 1 with PersonaConstructionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.PersonaConstructionType in project midpoint by Evolveum.

the class TestProjectorPersona method test100AssignRolePersonaAdminToJack.

@Test
public void test100AssignRolePersonaAdminToJack() throws Exception {
    final String TEST_NAME = "test100AssignRolePersonaAdminToJack";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestProjectorPersona.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);
    LensContext<UserType> context = createUserLensContext();
    fillContextWithUser(context, USER_JACK_OID, result);
    ObjectDelta<UserType> focusDelta = createAssignmentFocusDelta(UserType.class, USER_JACK_OID, ROLE_PERSONA_ADMIN_OID, RoleType.COMPLEX_TYPE, null, null, null, true);
    addFocusDeltaToContext(context, focusDelta);
    display("Input context", context);
    assertFocusModificationSanity(context);
    rememberShadowFetchOperationCount();
    // WHEN
    projector.project(context, "test", task, result);
    // THEN
    display("Output context", context);
    assertShadowFetchOperationCountIncrement(0);
    assertTrue(context.getFocusContext().getPrimaryDelta().getChangeType() == ChangeType.MODIFY);
    assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "user secondary delta", ActivationStatusType.ENABLED);
    assertTrue("Unexpected projection changes", context.getProjectionContexts().isEmpty());
    DeltaSetTriple<EvaluatedAssignmentImpl<?>> evaluatedAssignmentTriple = context.getEvaluatedAssignmentTriple();
    assertNotNull("No evaluatedAssignmentTriple", evaluatedAssignmentTriple);
    assertTrue("Unexpected evaluatedAssignmentTriple zero set", evaluatedAssignmentTriple.getZeroSet().isEmpty());
    assertTrue("Unexpected evaluatedAssignmentTriple minus set", evaluatedAssignmentTriple.getMinusSet().isEmpty());
    assertNotNull("No evaluatedAssignmentTriple plus set", evaluatedAssignmentTriple.getPlusSet());
    assertEquals("Wrong size of evaluatedAssignmentTriple plus set", 1, evaluatedAssignmentTriple.getPlusSet().size());
    EvaluatedAssignmentImpl<UserType> evaluatedAssignment = (EvaluatedAssignmentImpl<UserType>) evaluatedAssignmentTriple.getPlusSet().iterator().next();
    display("evaluatedAssignment", evaluatedAssignment);
    assertNotNull("No evaluatedAssignment", evaluatedAssignment);
    DeltaSetTriple<PersonaConstruction<UserType>> personaConstructionTriple = evaluatedAssignment.getPersonaConstructionTriple();
    display("personaConstructionTriple", personaConstructionTriple);
    assertNotNull("No personaConstructionTriple", personaConstructionTriple);
    assertFalse("Empty personaConstructionTriple", personaConstructionTriple.isEmpty());
    assertTrue("Unexpected personaConstructionTriple plus set", personaConstructionTriple.getPlusSet().isEmpty());
    assertTrue("Unexpected personaConstructionTriple minus set", personaConstructionTriple.getMinusSet().isEmpty());
    assertNotNull("No personaConstructionTriple zero set", personaConstructionTriple.getZeroSet());
    assertEquals("Wrong size of personaConstructionTriple zero set", 1, personaConstructionTriple.getZeroSet().size());
    PersonaConstruction<UserType> personaConstruction = personaConstructionTriple.getZeroSet().iterator().next();
    assertNotNull("No personaConstruction", personaConstruction);
    PersonaConstructionType personaConstructionType = personaConstruction.getConstructionType();
    assertNotNull("No personaConstructionType", personaConstructionType);
    assertTrue("Wrong type: " + personaConstructionType.getTargetType(), QNameUtil.match(UserType.COMPLEX_TYPE, personaConstructionType.getTargetType()));
    PrismAsserts.assertEqualsCollectionUnordered("Wrong subtype", personaConstructionType.getTargetSubtype(), "admin");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PersonaConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.PersonaConstructionType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 2 with PersonaConstructionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.PersonaConstructionType in project midpoint by Evolveum.

the class PersonaConstruction method debugDump.

/* (non-Javadoc)
	 * @see com.evolveum.midpoint.util.DebugDumpable#debugDump(int)
	 */
@Override
public String debugDump(int indent) {
    StringBuilder sb = new StringBuilder();
    DebugUtil.debugDumpLabelLn(sb, "PersonaConstruction", indent);
    PersonaConstructionType constructionType = getConstructionType();
    if (constructionType != null) {
        DebugUtil.debugDumpWithLabelLn(sb, "targetType", constructionType.getTargetType(), indent + 1);
        DebugUtil.debugDumpWithLabelLn(sb, "subtype", constructionType.getTargetSubtype(), indent + 1);
        DebugUtil.debugDumpWithLabelToStringLn(sb, "strength", constructionType.getStrength(), indent + 1);
    }
    DebugUtil.debugDumpWithLabelLn(sb, "isValid", isValid(), indent + 1);
    sb.append("\n");
    if (getConstructionType() != null && getConstructionType().getDescription() != null) {
        sb.append("\n");
        DebugUtil.debugDumpLabel(sb, "description", indent + 1);
        sb.append(" ").append(getConstructionType().getDescription());
    }
    if (getAssignmentPath() != null) {
        sb.append("\n");
        sb.append(getAssignmentPath().debugDump(indent + 1));
    }
    return sb.toString();
}
Also used : PersonaConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.PersonaConstructionType)

Example 3 with PersonaConstructionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.PersonaConstructionType in project midpoint by Evolveum.

the class PersonaProcessor method personaAdd.

public <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 constructionType = construction.getConstructionType();
    ObjectReferenceType objectMappingRef = constructionType.getObjectMappingRef();
    ObjectTemplateType objectMappingType = objectResolver.resolve(objectMappingRef, ObjectTemplateType.class, null, "object mapping in persona construction in " + focus, task, result);
    QName targetType = constructionType.getTargetType();
    PrismObjectDefinition<T> objectDef = prismContext.getSchemaRegistry().findObjectDefinitionByType(targetType);
    PrismObject<T> target = objectDef.instantiate();
    FocusTypeUtil.setSubtype(target, constructionType.getTargetSubtype());
    // pretend ADD focusOdo. We need to push all the items through the object template
    ObjectDeltaObject<F> focusOdo = new ObjectDeltaObject<>(null, focus.createAddDelta(), focus);
    ObjectDelta<T> targetDelta = target.createAddDelta();
    String contextDesc = "object mapping " + objectMappingType + " for persona construction for " + focus;
    XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
    Collection<ItemDelta<?, ?>> itemDeltas = objectTemplateProcessor.processObjectMapping(context, objectMappingType, focusOdo, target, targetDelta, contextDesc, now, task, result);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("itemDeltas:\n{}", DebugUtil.debugDump(itemDeltas));
    }
    for (ItemDelta itemDelta : itemDeltas) {
        itemDelta.applyTo(target);
    }
    LOGGER.trace("Creating persona:\n{}", target.debugDumpLazily());
    executePersonaDelta(targetDelta, task, result);
    link(context, target.asObjectable(), result);
}
Also used : QName(javax.xml.namespace.QName) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) PersonaConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.PersonaConstructionType)

Example 4 with PersonaConstructionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.PersonaConstructionType in project midpoint by Evolveum.

the class PersonaProcessor method personaModify.

public <F extends FocusType, T extends FocusType> void personaModify(LensContext<F> context, PersonaKey key, PersonaConstruction<F> construction, PrismObject<T> existingPersona, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, PolicyViolationException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
    PrismObject<F> focus = context.getFocusContext().getObjectNew();
    LOGGER.debug("Modifying persona {} for {} using construction {}", key, focus, construction);
    PersonaConstructionType constructionType = construction.getConstructionType();
    ObjectReferenceType objectMappingRef = constructionType.getObjectMappingRef();
    ObjectTemplateType objectMappingType = objectResolver.resolve(objectMappingRef, ObjectTemplateType.class, null, "object mapping in persona construction in " + focus, task, result);
    ObjectDeltaObject<F> focusOdo = context.getFocusContext().getObjectDeltaObject();
    String contextDesc = "object mapping " + objectMappingType + " for persona construction for " + focus;
    XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();
    Collection<ItemDelta<?, ?>> itemDeltas = objectTemplateProcessor.processObjectMapping(context, objectMappingType, focusOdo, existingPersona, null, contextDesc, now, task, result);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("itemDeltas:\n{}", DebugUtil.debugDump(itemDeltas));
    }
    ObjectDelta<T> targetDelta = existingPersona.createModifyDelta();
    for (ItemDelta itemDelta : itemDeltas) {
        targetDelta.addModification(itemDelta);
    }
    executePersonaDelta(targetDelta, task, result);
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) PersonaConstructionType(com.evolveum.midpoint.xml.ns._public.common.common_3.PersonaConstructionType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Aggregations

PersonaConstructionType (com.evolveum.midpoint.xml.ns._public.common.common_3.PersonaConstructionType)4 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)2 ObjectTemplateType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 ObjectDeltaObject (com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1 QName (javax.xml.namespace.QName)1 Test (org.testng.annotations.Test)1