Skip to content

Commit

Permalink
support for archetypes personas
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Sep 17, 2021
1 parent 16fcbf7 commit f423dc3
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,30 @@ public static AssignmentType createRoleAssignment(String roleOid) {
return createTargetAssignment(roleOid, RoleType.COMPLEX_TYPE);
}

public static AssignmentType createOrgAssignment(String roleOid) {
return createTargetAssignment(roleOid, OrgType.COMPLEX_TYPE);
public static AssignmentType createOrgAssignment(String orgOid) {
return createTargetAssignment(orgOid, OrgType.COMPLEX_TYPE);
}

public static AssignmentType createArchetypeAssignment(String archetypeOid) {
return createTargetAssignment(archetypeOid, ArchetypeType.COMPLEX_TYPE);
}

public static <AH extends AssignmentHolderType> void addArchetypeAssignments(PrismObject<AH> object, List<ObjectReferenceType> archetypeRefs) {
List<AssignmentType> archetypeAssignments = archetypeRefs.stream()
.map(archetypeRef -> createTargetAssignment(archetypeRef))
.collect(Collectors.toList());
object.asObjectable().getAssignment().addAll(archetypeAssignments);
}

public static AssignmentType createTargetAssignment(String targetOid, QName type) {
AssignmentType assignmentType = new AssignmentType();
ObjectReferenceType targetRef = new ObjectReferenceType();
targetRef.setOid(targetOid);
targetRef.setType(type);
return createTargetAssignment(targetRef);
}

public static AssignmentType createTargetAssignment(ObjectReferenceType targetRef) {
AssignmentType assignmentType = new AssignmentType();
assignmentType.setTargetRef(targetRef);
return assignmentType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12297,15 +12297,19 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="targetSubtype" type="xsd:string" minOccurs="1" maxOccurs="unbounded">
<xsd:element name="targetSubtype" type="xsd:string" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Object subtype of the target persona.
Constructions with the same type and subtype configuration are
interpreted as if they describe the same persona.

DEPRECATED, use archetypeRef instead
</xsd:documentation>
<xsd:appinfo>
<a:since>3.6</a:since>
<a:deprecated/>
<a:deprecatedSince>4.4</a:deprecatedSince>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
Expand All @@ -12324,6 +12328,17 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="archetypeRef" type="c:ObjectReferenceType" minOccurs="1" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Archetype of the target persona.
</xsd:documentation>
<xsd:appinfo>
<a:objectReferenceTargetType>tns:ArchetypeType</a:objectReferenceTargetType>
<a:since>4.4</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.evolveum.midpoint.model.impl.lens.projector.focus.TemplateMappingsEvaluation;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.delta.*;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -252,7 +253,11 @@ private <F extends FocusType, T extends FocusType> void personaAdd(LensContext<F
PrismObjectDefinition<T> objectDef = prismContext.getSchemaRegistry().findObjectDefinitionByType(targetType);
PrismObject<T> target = objectDef.instantiate();

FocusTypeUtil.setSubtype(target, constructionBean.getTargetSubtype());
if (constructionBean.getArchetypeRef() != null) {
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());
Expand Down Expand Up @@ -386,11 +391,13 @@ class PersonaKey implements HumanReadableDescribable {

private final QName type;
private final List<String> subtypes;
private final List<ObjectReferenceType> archetypeRef;

private PersonaKey(PersonaConstructionType constructionType) {
super();
this.type = constructionType.getTargetType();
this.subtypes = constructionType.getTargetSubtype();
this.archetypeRef = constructionType.getArchetypeRef();
}

public QName getType() {
Expand All @@ -403,7 +410,7 @@ private List<String> getSubtypes() {

@Override
public String toHumanReadableDescription() {
return "persona "+type.getLocalPart()+"/"+subtypes+"'";
return "persona " + type.getLocalPart() + "/" + archetypeRef != null ? archetypeRef.toString() : subtypes + "'";
}

@Override
Expand All @@ -413,6 +420,7 @@ public int hashCode() {
result = prime * result + getOuterType().hashCode();
result = prime * result + ((subtypes == null) ? 0 : subtypes.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + ((archetypeRef == null) ? 0 : archetypeRef.hashCode());
return result;
}

Expand All @@ -438,12 +446,17 @@ public boolean equals(Object obj) {
return false;
} else if (!type.equals(other.type))
return false;
if (archetypeRef == null) {
if (other.archetypeRef != null)
return false;
} else if (!archetypeRef.equals(other.archetypeRef))
return false;
return true;
}

@Override
public String toString() {
return "PersonaKey(" + type + "/" + subtypes + ")";
return "PersonaKey(" + type + "/" + archetypeRef != null ? archetypeRef.toString() : subtypes + ")";
}

private PersonaProcessor getOuterType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public String debugDump(int indent) {
if (constructionBean != null) {
DebugUtil.debugDumpWithLabelLn(sb, "targetType", constructionBean.getTargetType(), indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "subtype", constructionBean.getTargetSubtype(), indent + 1);
DebugUtil.debugDumpWithLabelToStringLn(sb, "subtype", constructionBean.getArchetypeRef(), indent + 1);

This comment has been minimized.

Copy link
@mederly

mederly Sep 17, 2021

Member
  • archetypeRef instead of subtype
DebugUtil.debugDumpWithLabelToStringLn(sb, "strength", constructionBean.getStrength(), indent + 1);
}
DebugUtil.debugDumpWithLabelLn(sb, "valid", isValid(), indent + 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Copyright (c) 2010-2021 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.model.impl.lens;

import static org.testng.AssertJUnit.*;

import java.io.File;

import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;

import com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl;
import com.evolveum.midpoint.model.impl.lens.construction.PersonaConstruction;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.DeltaSetTriple;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.internals.InternalCounters;
import com.evolveum.midpoint.schema.internals.InternalMonitor;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.QNameUtil;

@ContextConfiguration(locations = { "classpath:ctx-model-test-main.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
public abstract class AbstractTestProjectorPersona extends AbstractLensTest {

@Override
public void initSystem(Task initTask, OperationResult initResult) throws Exception {
super.initSystem(initTask, initResult);
setDefaultUserTemplate(USER_TEMPLATE_OID);
addObject(getPersonaRoleFile());
InternalMonitor.reset();
}

protected abstract File getPersonaRoleFile();

protected abstract String getPersonaRoleOid();

@Test
public void test100AssignRolePersonaAdminToJack() throws Exception {
// GIVEN
Task task = getTestTask();
OperationResult result = task.getResult();
assumeAssignmentPolicy(AssignmentPolicyEnforcementType.FULL);

LensContext<UserType> context = createUserLensContext();
fillContextWithUser(context, USER_JACK_OID, result);
ObjectDelta<UserType> focusDelta = createAssignmentAssignmentHolderDelta(UserType.class, USER_JACK_OID,
getPersonaRoleOid(), RoleType.COMPLEX_TYPE, null, null, null, true);
addFocusDeltaToContext(context, focusDelta);

displayDumpable("Input context", context);

assertFocusModificationSanity(context);
rememberCounter(InternalCounters.SHADOW_FETCH_OPERATION_COUNT);

// WHEN
projector.project(context, "test", task, result);

// THEN
displayDumpable("Output context", context);
assertCounterIncrement(InternalCounters.SHADOW_FETCH_OPERATION_COUNT, 0);

assertSame(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();
displayDumpable("evaluatedAssignment", evaluatedAssignment);
assertNotNull("No evaluatedAssignment", evaluatedAssignment);
DeltaSetTriple<PersonaConstruction<UserType>> personaConstructionTriple = evaluatedAssignment.getPersonaConstructionTriple();
displayDumpable("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.getConstructionBean();
assertNotNull("No personaConstructionType", personaConstructionType);
assertTrue("Wrong type: " + personaConstructionType.getTargetType(), QNameUtil.match(UserType.COMPLEX_TYPE, personaConstructionType.getTargetType()));
assertPersonaSubtypeOrArchetype(personaConstructionType);
}

protected abstract void assertPersonaSubtypeOrArchetype(PersonaConstructionType personaConstructionType);
}

0 comments on commit f423dc3

Please sign in to comment.