Skip to content

Commit

Permalink
Proper handling of object template defined in archetype (MID-3151)
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed May 17, 2019
1 parent 04dd755 commit 85bcfdf
Show file tree
Hide file tree
Showing 9 changed files with 362 additions and 53 deletions.
Expand Up @@ -80,28 +80,42 @@ public <O extends AssignmentHolderType> ObjectReferenceType determineArchetypeRe
}

public <O extends AssignmentHolderType> PrismObject<ArchetypeType> determineArchetype(PrismObject<O> assignmentHolder, OperationResult result) throws SchemaException, ConfigurationException {
ObjectReferenceType archetypeRef = determineArchetypeRef(assignmentHolder, result);
if (archetypeRef == null) {
return null;
return determineArchetype(assignmentHolder, null, result);
}

private <O extends AssignmentHolderType> PrismObject<ArchetypeType> determineArchetype(PrismObject<O> assignmentHolder, String explicitArchetypeOid, OperationResult result) throws SchemaException, ConfigurationException {
String archetypeOid;
if (explicitArchetypeOid != null) {
archetypeOid = explicitArchetypeOid;
} else {
ObjectReferenceType archetypeRef = determineArchetypeRef(assignmentHolder, result);
if (archetypeRef == null) {
return null;
}
archetypeOid = archetypeRef.getOid();
}

PrismObject<ArchetypeType> archetype;
try {
archetype = systemObjectCache.getArchetype(archetypeRef.getOid(), result);
archetype = systemObjectCache.getArchetype(archetypeOid, result);
} catch (ObjectNotFoundException e) {
LOGGER.warn("Archetype {} for object {} cannot be found", archetypeRef.getOid(), assignmentHolder);
LOGGER.warn("Archetype {} for object {} cannot be found", archetypeOid, assignmentHolder);
return null;
}
return archetype;
}

public <O extends ObjectType> ArchetypePolicyType determineArchetypePolicy(PrismObject<O> object, OperationResult result) throws SchemaException, ConfigurationException {
return determineArchetypePolicy(object, null, result);
}

public <O extends ObjectType> ArchetypePolicyType determineArchetypePolicy(PrismObject<O> object, String explicitArchetypeOid, OperationResult result) throws SchemaException, ConfigurationException {
if (object == null) {
return null;
}
ArchetypePolicyType archetypePolicy = null;
if (object.canRepresent(AssignmentHolderType.class)) {
PrismObject<ArchetypeType> archetype = determineArchetype((PrismObject<? extends AssignmentHolderType>) object, result);
PrismObject<ArchetypeType> archetype = determineArchetype((PrismObject<? extends AssignmentHolderType>) object, explicitArchetypeOid, result);
if (archetype != null) {
archetypePolicy = archetype.asObjectable().getArchetypePolicy();
}
Expand Down
Expand Up @@ -38,6 +38,7 @@
import com.evolveum.midpoint.schema.util.FocusTypeUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand Down Expand Up @@ -299,29 +300,7 @@ public void cleanup() {
// secondaryDeltas.remove(getWave());
// }
}


@Override
public void recompute() throws SchemaException, ConfigurationException {
super.recompute();
updateObjectPolicy();
}

private void updateObjectPolicy() throws ConfigurationException {
PrismObject<SystemConfigurationType> systemConfiguration = getLensContext().getSystemConfiguration();
if (systemConfiguration == null) {
return;
}
PrismObject<O> object = getObjectAny();
ObjectPolicyConfigurationType policyConfigurationType = ArchetypeManager.determineObjectPolicyConfiguration(object, systemConfiguration.asObjectable());
if (policyConfigurationType != getArchetypePolicyType()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Changed policy configuration because of changed subtypes {}:\n{}",
FocusTypeUtil.determineSubTypes(object), policyConfigurationType==null?null:policyConfigurationType.asPrismContainerValue().debugDump(1));
}
setArchetypePolicyType(policyConfigurationType);
}
}


@Override
public void normalize() {
Expand Down
Expand Up @@ -427,14 +427,13 @@ private <F extends ObjectType> void loadFromSystemConfig(LensContext<F> context,
SystemConfigurationType systemConfigurationType = systemConfiguration.asObjectable();

if (context.getFocusContext() != null) {
PrismObject<F> object = context.getFocusContext().getObjectAny();
if (context.getFocusContext().getArchetypePolicyType() == null) {
ArchetypePolicyType policyConfigurationType = archetypeManager.determineArchetypePolicy(object, result);
ArchetypePolicyType archetypePolicy = determineArchetypePolicy(context, task, result);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Selected policy configuration from subtypes {}:\n{}",
FocusTypeUtil.determineSubTypes(object), policyConfigurationType==null?null:policyConfigurationType.asPrismContainerValue().debugDump(1));
LOGGER.trace("Selected archetype policy:\n{}",
archetypePolicy==null?null:archetypePolicy.asPrismContainerValue().debugDump(1));
}
context.getFocusContext().setArchetypePolicyType(policyConfigurationType);
context.getFocusContext().setArchetypePolicyType(archetypePolicy);
}
}

Expand All @@ -454,6 +453,46 @@ private <F extends ObjectType> void loadFromSystemConfig(LensContext<F> context,
loadSecurityPolicy(context, task, result);
}

private <F extends ObjectType> ArchetypePolicyType determineArchetypePolicy(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 = 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
if (object.canRepresent(AssignmentHolderType.class)) {
AssignmentHolderType assignmentHolderType = (AssignmentHolderType)object.asObjectable();
List<ObjectReferenceType> archetypeRefs = assignmentHolderType.getArchetypeRef();
if (archetypeRefs.isEmpty()) {
for (AssignmentType assignment : assignmentHolderType.getAssignment()) {
ObjectReferenceType targetRef = assignment.getTargetRef();
if (targetRef != null && QNameUtil.match(ArchetypeType.COMPLEX_TYPE, targetRef.getType())) {
explicitArchetypeOid = targetRef.getOid();
}
}
}
}
return archetypeManager.determineArchetypePolicy(object, explicitArchetypeOid, result);
}

public <F extends ObjectType> void updateArchetypePolicy(LensContext<F> context, Task task, OperationResult result) throws SchemaException, ConfigurationException {
if (context.getFocusContext() == null) {
return;
}
ArchetypePolicyType newArchetypePolicy = determineArchetypePolicy(context, task, result);
if (newArchetypePolicy != context.getFocusContext().getArchetypePolicyType()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Changed policy configuration because of changed subtypes:\n{}",
newArchetypePolicy==null?null:newArchetypePolicy.asPrismContainerValue().debugDump(1));
}
context.getFocusContext().setArchetypePolicyType(newArchetypePolicy);
}
}

// expects that object policy configuration is already set in focusContext
private <F extends ObjectType> PrismObject<ObjectTemplateType> determineFocusTemplate(LensContext<F> context, OperationResult result) throws ObjectNotFoundException, SchemaException, ConfigurationException {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -49,6 +49,7 @@
import com.evolveum.midpoint.model.impl.lens.LensFocusContext;
import com.evolveum.midpoint.model.impl.lens.LensUtil;
import com.evolveum.midpoint.model.impl.lens.OperationalDataManager;
import com.evolveum.midpoint.model.impl.lens.projector.ContextLoader;
import com.evolveum.midpoint.model.impl.lens.projector.MappingEvaluator;
import com.evolveum.midpoint.model.impl.lens.projector.credentials.CredentialsProcessor;
import com.evolveum.midpoint.prism.path.UniformItemPath;
Expand Down Expand Up @@ -85,16 +86,12 @@ public class AssignmentHolderProcessor {
private PrismContainerDefinition<ActivationType> activationDefinition;
private PrismPropertyDefinition<Integer> failedLoginsDefinition;

@Autowired private ContextLoader contextLoader;
@Autowired private InboundProcessor inboundProcessor;
@Autowired private AssignmentProcessor assignmentProcessor;
@Autowired private ObjectTemplateProcessor objectTemplateProcessor;
@Autowired private PrismContext prismContext;
@Autowired private CredentialsProcessor credentialsProcessor;
@Autowired private ModelObjectResolver modelObjectResolver;
@Autowired private ActivationComputer activationComputer;
@Autowired private ExpressionFactory expressionFactory;
@Autowired private MappingEvaluator mappingHelper;
@Autowired private OperationalDataManager metadataManager;
@Autowired private PolicyRuleProcessor policyRuleProcessor;
@Autowired private FocusLifecycleProcessor focusLifecycleProcessor;
@Autowired private ClockworkMedic medic;
Expand Down Expand Up @@ -206,6 +203,7 @@ private <AH extends AssignmentHolderType> void processFocusFocus(LensContext<AH>
inboundProcessor.processInbound(context, now, task, result);
if (consistencyChecks) context.checkConsistence();
context.recomputeFocus();
contextLoader.updateArchetypePolicy(context, task, result);
medic.traceContext(LOGGER, activityDescription, "inbound", false, context, false);
if (consistencyChecks) context.checkConsistence();
},
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2018 Evolveum
* Copyright (c) 2010-2019 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,6 +35,7 @@
import com.evolveum.midpoint.model.impl.lens.LensFocusContext;
import com.evolveum.midpoint.model.impl.lens.LensUtil;
import com.evolveum.midpoint.model.impl.lens.OperationalDataManager;
import com.evolveum.midpoint.model.impl.lens.projector.ContextLoader;
import com.evolveum.midpoint.model.impl.lens.projector.MappingEvaluator;
import com.evolveum.midpoint.model.impl.lens.projector.credentials.CredentialsProcessor;
import com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleEnforcer;
Expand Down Expand Up @@ -101,20 +102,9 @@ public class FocusProcessor {
private PrismContainerDefinition<ActivationType> activationDefinition;
private PrismPropertyDefinition<Integer> failedLoginsDefinition;

@Autowired private InboundProcessor inboundProcessor;
@Autowired private AssignmentProcessor assignmentProcessor;
@Autowired private ObjectTemplateProcessor objectTemplateProcessor;
@Autowired private PrismContext prismContext;
@Autowired private CredentialsProcessor credentialsProcessor;
@Autowired private ModelObjectResolver modelObjectResolver;
@Autowired private ActivationComputer activationComputer;
@Autowired private ExpressionFactory expressionFactory;
@Autowired private MappingEvaluator mappingHelper;
@Autowired private OperationalDataManager metadataManager;
@Autowired private PolicyRuleProcessor policyRuleProcessor;
@Autowired private FocusLifecycleProcessor focusLifecycleProcessor;
@Autowired private ClockworkMedic medic;
@Autowired private PolicyRuleEnforcer policyRuleEnforcer;


public <AH extends AssignmentHolderType, F extends FocusType> void processActivationBeforeAssignments(LensContext<AH> context, XMLGregorianCalendar now,
Expand Down

0 comments on commit 85bcfdf

Please sign in to comment.