Skip to content

Commit

Permalink
fixing MID-5358 (Archetype assignment in inbound combined with midpoi…
Browse files Browse the repository at this point in the history
…nt.hasArchetype in template condition does not provision the assignments correctly)
  • Loading branch information
katkav committed Jun 6, 2019
1 parent 30fe82a commit 6d1e845
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
Expand Up @@ -20,6 +20,7 @@
import com.evolveum.midpoint.schema.ObjectDeltaOperation;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ArchetypeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -67,4 +68,5 @@ public interface ModelElementContext<O extends ObjectType> extends Serializable,
Collection<EvaluatedPolicyRule> getPolicyRules();

boolean isOfType(Class<?> aClass);

}
Expand Up @@ -83,7 +83,7 @@ public <O extends AssignmentHolderType> PrismObject<ArchetypeType> determineArch
return determineArchetype(assignmentHolder, null, result);
}

private <O extends AssignmentHolderType> PrismObject<ArchetypeType> determineArchetype(PrismObject<O> assignmentHolder, String explicitArchetypeOid, OperationResult result) throws SchemaException, ConfigurationException {
public <O extends AssignmentHolderType> PrismObject<ArchetypeType> determineArchetype(PrismObject<O> assignmentHolder, String explicitArchetypeOid, OperationResult result) throws SchemaException, ConfigurationException {
String archetypeOid;
if (explicitArchetypeOid != null) {
archetypeOid = explicitArchetypeOid;
Expand Down
Expand Up @@ -1834,6 +1834,16 @@ public <O extends ObjectType> boolean hasArchetype(O object, String archetypeOid
if (!(object instanceof AssignmentHolderType)) {
return archetypeOid == null;
}

LensContext<O> lensContext = ModelExpressionThreadLocalHolder.getLensContext();
if (lensContext != null) {
LensFocusContext<O> focusContext = lensContext.getFocusContext();
ArchetypeType archetypeType = focusContext.getArchetype();
if (archetypeType != null) {
return archetypeType.getOid().equals(archetypeOid);
}
}

List<ObjectReferenceType> archetypeRefs = ((AssignmentHolderType)object).getArchetypeRef();
if (archetypeOid == null) {
return archetypeRefs.isEmpty();
Expand Down
Expand Up @@ -58,6 +58,7 @@ public class LensFocusContext<O extends ObjectType> extends LensElementContext<O
private ObjectDeltaWaves<O> secondaryDeltas = new ObjectDeltaWaves<>();

transient private ArchetypePolicyType archetypePolicyType;
transient private ArchetypeType archetype;

// extracted from the template(s)
// this is not to be serialized into XML, but let's not mark it as transient
Expand All @@ -83,6 +84,14 @@ public void setArchetypePolicyType(ArchetypePolicyType objectPolicyConfiguration
this.archetypePolicyType = objectPolicyConfigurationType;
}

public ArchetypeType getArchetype() {
return archetype;
}

public void setArchetype(ArchetypeType archetype) {
this.archetype = archetype;
}

public LifecycleStateModelType getLifecycleModel() {
if (archetypePolicyType == null) {
return null;
Expand Down
Expand Up @@ -28,6 +28,8 @@
import com.evolveum.midpoint.schema.internals.InternalsConfig;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import net.sf.ehcache.CacheOperationOutcomes.GetAllOutcome;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -462,6 +464,35 @@ private <F extends ObjectType> ArchetypePolicyType determineArchetypePolicy(Lens
return null;
}
PrismObject<F> object = context.getFocusContext().getObjectAny();
String explicitArchetypeOid = determineExplicitArchetypeOid(context);
return archetypeManager.determineArchetypePolicy(object, explicitArchetypeOid, result);
}

public <F extends AssignmentHolderType> ArchetypeType updateArchetype(LensContext<F> context, Task task, OperationResult result) throws SchemaException, ConfigurationException {
PrismObject<SystemConfigurationType> systemConfiguration = context.getSystemConfiguration();
if (systemConfiguration == null) {
return null;
}
if (context.getFocusContext() == null) {
return null;
}

PrismObject<F> object = context.getFocusContext().getObjectAny();

String explicitArchetypeOid = determineExplicitArchetypeOid(context);
PrismObject<ArchetypeType> archetype = archetypeManager.determineArchetype(object, explicitArchetypeOid, result);
ArchetypeType archetypeType = null;
if (archetype != null) {
archetypeType = archetype.asObjectable();
}

context.getFocusContext().setArchetype(archetypeType);

return archetypeType;
}

private <O extends ObjectType> String determineExplicitArchetypeOid(LensContext<O> context) {
PrismObject<O> object = context.getFocusContext().getObjectAny();
String explicitArchetypeOid = null;
// Used in cases where archetype assignment haven't had the change to be processed yet.
// E.g. in case that we are creating a new object with archetype assignment
Expand All @@ -477,7 +508,7 @@ private <F extends ObjectType> ArchetypePolicyType determineArchetypePolicy(Lens
}
}
}
return archetypeManager.determineArchetypePolicy(object, explicitArchetypeOid, result);
return explicitArchetypeOid;
}

public <F extends ObjectType> void updateArchetypePolicy(LensContext<F> context, Task task, OperationResult result) throws SchemaException, ConfigurationException {
Expand Down
Expand Up @@ -206,6 +206,7 @@ private <AH extends AssignmentHolderType> void processFocusFocus(LensContext<AH>
if (consistencyChecks) context.checkConsistence();
context.recomputeFocus();
contextLoader.updateArchetypePolicy(context, task, result);
contextLoader.updateArchetype(context, task, result);
medic.traceContext(LOGGER, activityDescription, "inbound", false, context, false);
if (consistencyChecks) context.checkConsistence();
},
Expand Down

0 comments on commit 6d1e845

Please sign in to comment.