Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Aug 7, 2019
2 parents 1e3f646 + ce56197 commit ddbad86
Show file tree
Hide file tree
Showing 18 changed files with 1,058 additions and 35 deletions.
Expand Up @@ -232,10 +232,13 @@ public D getDefinition() {
// }

public void recompute() throws SchemaException {
if (delta == null && (subItemDeltas == null || subItemDeltas.isEmpty())) {
itemNew = itemOld;
return;
}
itemNew = null;
if (delta != null) {
itemNew = delta.getItemNewMatchingPath(itemOld);
} else {
itemNew = itemOld;
}
if (subItemDeltas != null && !subItemDeltas.isEmpty()) {
if (itemNew == null) {
Expand Down Expand Up @@ -546,6 +549,7 @@ public String debugDump(int indent) {
DebugUtil.debugDumpWithLabelLn(sb, "itemOld", itemOld, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "delta", delta, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "itemNew", itemNew, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "subItemDeltas", subItemDeltas, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "definition", definition, indent + 1);
DebugUtil.debugDumpWithLabelToStringLn(sb, "resolvePath", resolvePath, indent + 1);
DebugUtil.debugDumpWithLabelToString(sb, "residualPath", residualPath, indent + 1);
Expand Down
Expand Up @@ -376,7 +376,8 @@ public String debugDump(int indent) {
}
}
dumpObject(sb, newObject, "new", indent +1);
DebugUtil.debugDumpWithLabelLn(sb, "definition", definition, indent + 1);
sb.append("\n");
DebugUtil.debugDumpWithLabel(sb, "definition", definition, indent + 1);
return sb.toString();
}

Expand Down
Expand Up @@ -740,6 +740,19 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="originDescription" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Short description of trigger origin, e.g. name of the mapping.
Used for diagnostic purposes.
</xsd:documentation>
<xsd:appinfo>
<a:operational>true</a:operational>
<a:indexed>false</a:indexed>
<a:since>4.0</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element ref="tns:extension" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>
Expand Down
Expand Up @@ -45,6 +45,8 @@
import com.evolveum.midpoint.schema.util.SchemaTestConstants;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.PasswordType;
Expand All @@ -54,6 +56,8 @@
* @author Radovan Semancik
*/
public class TestMappingDynamicSysVar extends AbstractModelCommonTest {

private static final Trace LOGGER = TraceManager.getTrace(TestMappingDynamicSysVar.class);

private static final String NS_EXTENSION = "http://midpoint.evolveum.com/xml/ns/test/extension";
private static final String PATTERN_NUMERIC = "^\\d+$";
Expand Down Expand Up @@ -615,12 +619,14 @@ public void testPathEnum() throws Exception {
OperationResult opResult = new OperationResult(TEST_NAME);

// WHEN
System.out.println("WHEN");
LOGGER.info("WHEN");
mapping.evaluate(null, opResult);

// THEN
PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = mapping.getOutputTriple();
System.out.println("Output triple");
System.out.println(outputTriple.debugDump());
System.out.println("\nOutput triple");
System.out.println(outputTriple.debugDump(1));
PrismAsserts.assertTripleNoZero(outputTriple);
PrismAsserts.assertTriplePlus(outputTriple, ActivationStatusType.DISABLED.value());
PrismAsserts.assertTripleMinus(outputTriple, ActivationStatusType.ENABLED.value());
Expand Down
Expand Up @@ -1626,7 +1626,7 @@ private boolean determineDeputyValidity(PrismObject<UserType> potentialDeputy, L
}
try {
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi =
new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainerClone(assignmentType));
new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(assignmentType));
// TODO some special mode for verification of the validity - we don't need complete calculation here!
EvaluatedAssignment<UserType> assignment = assignmentEvaluator
.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, potentialDeputy.asObjectable(),
Expand Down
Expand Up @@ -156,7 +156,7 @@ private <AH extends AssignmentHolderType> Collection<EvaluatedAssignment<AH>> ev
definition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(AssignmentHolderType.class).findContainerDefinition(AssignmentHolderType.F_ASSIGNMENT);
}
ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> assignmentIdi =
new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainerClone(assignmentType), definition);
new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(assignmentType), definition);
EvaluatedAssignment<AH> assignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, assignmentHolder, assignmentHolder.toString(), virtual, task, result);
evaluatedAssignments.add(assignment);
} catch (SchemaException | ObjectNotFoundException | ExpressionEvaluationException | PolicyViolationException | SecurityViolationException | ConfigurationException | CommunicationException e) {
Expand Down
Expand Up @@ -295,7 +295,7 @@ public AssignmentPathSegmentImpl(ObjectType source, String sourceDescription, As
private static ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> createAssignmentIdi(
AssignmentType assignment) {
try {
return new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainerClone(assignment), assignment.asPrismContainerValue().getDefinition());
return new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(assignment), assignment.asPrismContainerValue().getDefinition());
} catch (SchemaException e) {
// should not really occur!
throw new SystemException("Couldn't create assignment IDI: " + e.getMessage(), e);
Expand Down
Expand Up @@ -797,7 +797,7 @@ private static <F extends ObjectType> void checkArchetypePolicy(LensFocusContext
}
}

public static PrismContainer<AssignmentType> createAssignmentSingleValueContainerClone(@NotNull AssignmentType assignmentType) throws SchemaException {
public static PrismContainer<AssignmentType> createAssignmentSingleValueContainer(@NotNull AssignmentType assignmentType) throws SchemaException {
// Make it appear to be single-value. Therefore paths without segment IDs will work.
return assignmentType.asPrismContainerValue().asSingleValuedContainer(SchemaConstantsGenerated.C_ASSIGNMENT);
}
Expand Down
Expand Up @@ -189,6 +189,7 @@ public <V extends PrismValue, D extends ItemDefinition, T extends ObjectType, F

Map<UniformItemPath,MappingOutputStruct<V>> outputTripleMap = new HashMap<>();
XMLGregorianCalendar nextRecomputeTime = null;
String triggerOriginDescription = null;
Collection<MappingType> mappingTypes = params.getMappingTypes();
Collection<MappingImpl<V,D>> mappings = new ArrayList<>(mappingTypes.size());

Expand Down Expand Up @@ -496,6 +497,8 @@ public <V extends PrismValue, D extends ItemDefinition, T extends ObjectType, F
if (mappingNextRecomputeTime != null) {
if (nextRecomputeTime == null || nextRecomputeTime.compare(mappingNextRecomputeTime) == DatatypeConstants.GREATER) {
nextRecomputeTime = mappingNextRecomputeTime;
// TODO: maybe better description? But consider storage requirements. We do not want to store too much.
triggerOriginDescription = mapping.getIdentifier();
}
}
}
Expand All @@ -521,6 +524,7 @@ public <V extends PrismValue, D extends ItemDefinition, T extends ObjectType, F
TriggerType triggerType = triggerCVal.asContainerable();
triggerType.setTimestamp(nextRecomputeTime);
triggerType.setHandlerUri(RecomputeTriggerHandler.HANDLER_URI);
triggerType.setOriginDescription(triggerOriginDescription);

targetContext.swallowToSecondaryDelta(triggerDelta);
}
Expand Down
Expand Up @@ -485,7 +485,7 @@ private ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinit
// TODO: optimize
definition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(AssignmentHolderType.class).findContainerDefinition(AssignmentHolderType.F_ASSIGNMENT);
}
return new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainerClone(cval.asContainerable()), definition);
return new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(cval.asContainerable()), definition);
}

private ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> createAssignmentIdiAdd(
Expand Down Expand Up @@ -523,7 +523,7 @@ private ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinit
.asItemDelta();

ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> idi = new ItemDeltaItem<>(
LensUtil.createAssignmentSingleValueContainerClone(cval.asContainerable()), itemDelta, null, cval.getDefinition());
LensUtil.createAssignmentSingleValueContainer(cval.asContainerable()), itemDelta, null, cval.getDefinition());
idi.recompute();
return idi;
}
Expand All @@ -532,7 +532,8 @@ private ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinit
PrismContainerValue<AssignmentType> cval, Collection<? extends ItemDelta<?, ?>> subItemDeltas)
throws SchemaException {
ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> idi =
new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainerClone(cval.asContainerable()), cval.getDefinition());
new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(cval.asContainerable()), cval.getDefinition());
idi.setResolvePath(AssignmentHolderType.F_ASSIGNMENT);
idi.setSubItemDeltas(subItemDeltas);
idi.recompute();
return idi;
Expand Down
Expand Up @@ -170,7 +170,7 @@ public <AH extends AssignmentHolderType> void processTemplate(LensContext<AH> co
collectAutoassignMappings(context, mappings, task, result);

Map<UniformItemPath,DeltaSetTriple<? extends ItemValueWithOrigin<?,?>>> outputTripleMap = new HashMap<>();
XMLGregorianCalendar nextRecomputeTime = collectTripleFromMappings(context, mappings, phase, focusOdo, focusOdo.getNewObject(),
NextRecompute nextRecompute = collectTripleFromMappings(context, mappings, phase, focusOdo, focusOdo.getNewObject(),
outputTripleMap, iteration, iterationToken, now, task, result);

if (LOGGER.isTraceEnabled()) {
Expand All @@ -183,14 +183,14 @@ public <AH extends AssignmentHolderType> void processTemplate(LensContext<AH> co

focusContext.applyProjectionWaveSecondaryDeltas(itemDeltas);

if (nextRecomputeTime != null) {
if (nextRecompute != null) {

boolean alreadyHasTrigger = false;
PrismObject<AH> objectCurrent = focusContext.getObjectCurrent();
if (objectCurrent != null) {
for (TriggerType trigger: objectCurrent.asObjectable().getTrigger()) {
if (RecomputeTriggerHandler.HANDLER_URI.equals(trigger.getHandlerUri()) &&
nextRecomputeTime.equals(trigger.getTimestamp())) {
nextRecompute.nextRecomputeTime.equals(trigger.getTimestamp())) {
alreadyHasTrigger = true;
break;
}
Expand All @@ -204,15 +204,21 @@ public <AH extends AssignmentHolderType> void processTemplate(LensContext<AH> co
PrismContainerValue<TriggerType> triggerCVal = triggerContDef.createValue();
triggerDelta.addValueToAdd(triggerCVal);
TriggerType triggerType = triggerCVal.asContainerable();
triggerType.setTimestamp(nextRecomputeTime);
triggerType.setTimestamp(nextRecompute.nextRecomputeTime);
triggerType.setHandlerUri(RecomputeTriggerHandler.HANDLER_URI);
triggerType.setOriginDescription(nextRecompute.triggerOriginDescription);

focusContext.swallowToProjectionWaveSecondaryDelta(triggerDelta);
}
}

}

class NextRecompute {
XMLGregorianCalendar nextRecomputeTime;
String triggerOriginDescription;
}

// expects that object policy configuration is already set in focusContext
private <F extends ObjectType> ObjectTemplateType determineFocusTemplate(LensContext<F> context, OperationResult result) throws ObjectNotFoundException, SchemaException, ConfigurationException {

Expand Down Expand Up @@ -265,9 +271,8 @@ public <F extends FocusType, T extends FocusType> Collection<ItemDelta<?,?>> pro
collectAutoassignMappings(context, mappings, task, result);

Map<UniformItemPath,DeltaSetTriple<? extends ItemValueWithOrigin<?,?>>> outputTripleMap = new HashMap<>();
XMLGregorianCalendar nextRecomputeTime = collectTripleFromMappings(context, mappings, ObjectTemplateMappingEvaluationPhaseType.BEFORE_ASSIGNMENTS,
NextRecompute nextRecompute = collectTripleFromMappings(context, mappings, ObjectTemplateMappingEvaluationPhaseType.BEFORE_ASSIGNMENTS,
focusOdo, target, outputTripleMap, iteration, iterationToken, now, task, result);


if (LOGGER.isTraceEnabled()) {
LOGGER.trace("outputTripleMap before item delta computation:\n{}", DebugUtil.debugDumpMapMultiLine(outputTripleMap));
Expand Down Expand Up @@ -620,7 +625,7 @@ private ItemPath stripFocusVariableSegment(ItemPath sourcePath) {
return sourcePath;
}

private <V extends PrismValue, D extends ItemDefinition, AH extends AssignmentHolderType, T extends AssignmentHolderType> XMLGregorianCalendar collectTripleFromMappings(
private <V extends PrismValue, D extends ItemDefinition, AH extends AssignmentHolderType, T extends AssignmentHolderType> NextRecompute collectTripleFromMappings(
LensContext<AH> context, List<FocalMappingSpec> mappings, ObjectTemplateMappingEvaluationPhaseType phase,
ObjectDeltaObject<AH> focusOdo, PrismObject<T> target,
Map<UniformItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?,?>>> outputTripleMap,
Expand All @@ -630,7 +635,7 @@ private <V extends PrismValue, D extends ItemDefinition, AH extends AssignmentHo

List<FocalMappingSpec> sortedMappings = sortMappingsByDependencies(mappings);

XMLGregorianCalendar nextRecomputeTime = null;
NextRecompute nextRecompute = null;

for (FocalMappingSpec mappingSpec : sortedMappings) {
ObjectTemplateMappingEvaluationPhaseType mappingPhase = mappingSpec.getEvaluationPhase();
Expand Down Expand Up @@ -658,8 +663,10 @@ private <V extends PrismValue, D extends ItemDefinition, AH extends AssignmentHo
XMLGregorianCalendar mappingNextRecomputeTime = mapping.getNextRecomputeTime();
LOGGER.trace("Evaluation of mapping {} delayed to {}", mapping, mappingNextRecomputeTime);
if (mappingNextRecomputeTime != null) {
if (nextRecomputeTime == null || nextRecomputeTime.compare(mappingNextRecomputeTime) == DatatypeConstants.GREATER) {
nextRecomputeTime = mappingNextRecomputeTime;
if (nextRecompute == null || nextRecompute.nextRecomputeTime.compare(mappingNextRecomputeTime) == DatatypeConstants.GREATER) {
nextRecompute = new NextRecompute();
nextRecompute.nextRecomputeTime = mappingNextRecomputeTime;
nextRecompute.triggerOriginDescription = mapping.getIdentifier();
}
}
continue;
Expand Down Expand Up @@ -687,7 +694,7 @@ private <V extends PrismValue, D extends ItemDefinition, AH extends AssignmentHo
}
}

return nextRecomputeTime;
return nextRecompute;
}

private <AH extends AssignmentHolderType> ObjectDeltaObject<AH> getUpdatedFocusOdo(LensContext<AH> context, ObjectDeltaObject<AH> focusOdo,
Expand Down
Expand Up @@ -214,7 +214,9 @@ public void test120DirectExpressionReplaceDescription() throws Exception {
ObjectDeltaObject<UserType> userOdo = createUserOdo(user, userDelta);
AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);

display("Assignment old", assignmentType);
ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> assignmentIdi = createAssignmentIdi(assignmentType);
assignmentIdi.setResolvePath(UserType.F_ASSIGNMENT);
assignmentIdi.setSubItemDeltas(userDelta.getModifications());
assignmentIdi.recompute();
display("Assignment IDI", assignmentIdi);
Expand Down Expand Up @@ -277,6 +279,7 @@ public void test130DirectExpressionReplaceDescriptionFromNull() throws Exception
AssignmentEvaluator<UserType> assignmentEvaluator = createAssignmentEvaluator(userOdo);

ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> assignmentIdi = createAssignmentIdi(assignmentType);
assignmentIdi.setResolvePath(UserType.F_ASSIGNMENT);
assignmentIdi.setSubItemDeltas(userDelta.getModifications());
assignmentIdi.recompute();

Expand Down Expand Up @@ -956,6 +959,6 @@ private ObjectDeltaObject<UserType> createUserOdo(PrismObject<UserType> user, Ob
}

private ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> createAssignmentIdi(AssignmentType assignmentType) throws SchemaException {
return new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainerClone(assignmentType), getAssignmentDefinition());
return new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(assignmentType), getAssignmentDefinition());
}
}
Expand Up @@ -541,7 +541,7 @@ public void test062JackDeputyOfGuybrushDeputyOfBarbossaInLoginMode() throws Exce
.build();

ItemDeltaItem<PrismContainerValue<AssignmentType>,PrismContainerDefinition<AssignmentType>> assignmentIdi =
new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainerClone(jackGuybrushAssignment),
new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(jackGuybrushAssignment),
jackGuybrushAssignment.asPrismContainerValue().getDefinition());

// WHEN
Expand Down

0 comments on commit ddbad86

Please sign in to comment.