Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Oct 2, 2023
2 parents 23c53d0 + fc00737 commit bad7602
Show file tree
Hide file tree
Showing 11 changed files with 968 additions and 584 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
String mappingName = mappingBean.getName();

if (!mappingBuilder.isApplicableToChannel(params.getContext().getChannel())) {
LOGGER.trace("Mapping {} not applicable to channel, skipping {}", mappingName, params.getContext().getChannel());
LOGGER.trace("Mapping {} not applicable to channel {}, skipping", mappingName, params.getContext().getChannel());
continue;
}
if (!task.canSee(mappingBean)) {
Expand Down Expand Up @@ -130,9 +130,9 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
boolean timeConstraintValid = mapping.isTimeConstraintValid();

if (params.getEvaluateCurrent() == MappingTimeEval.CURRENT && !timeConstraintValid) {
LOGGER.trace("Mapping {} is non-current, but evaluating current mappings, skipping {}", mappingName, params.getContext().getChannel());
LOGGER.trace("Mapping {} is non-current, but evaluating current mappings, skipping", mappingName);
} else if (params.getEvaluateCurrent() == MappingTimeEval.FUTURE && timeConstraintValid) {
LOGGER.trace("Mapping {} is current, but evaluating non-current mappings, skipping {}", mappingName, params.getContext().getChannel());
LOGGER.trace("Mapping {} is current, but evaluating non-current mappings, skipping", mappingName);
} else {
mappings.add(mapping);
}
Expand All @@ -142,11 +142,14 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
PrismObject<T> aPrioriTargetObject = params.getAPrioriTargetObject();

LOGGER.trace("Going to process {} mappings for {}", mappings.size(), mappingDesc);
LOGGER.trace("Target context: {}", targetContext);

for (MappingImpl<V, D> mapping : mappings) {

LOGGER.trace("Evaluating mapping: {}", mapping.getContextDescription());

if (mapping.getStrength() == MappingStrengthType.WEAK) {
// Evaluate weak mappings in a second run.
LOGGER.trace("-> weak mapping, will be evaluated in the second run");
continue;
}

Expand All @@ -159,6 +162,7 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
ItemDelta<?, ?> aPrioriItemDelta = params.getAPrioriTargetDelta().findItemDelta(mappingOutputPathUniform);
if (mapping.getStrength() != MappingStrengthType.STRONG) {
if (aPrioriItemDelta != null && !aPrioriItemDelta.isEmpty()) {
LOGGER.trace("-> a-priori delta for non-strong mapping, ignoring the mapping");
continue;
}
}
Expand All @@ -167,8 +171,7 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
mappingEvaluator.evaluateMapping(mapping, params.getContext(), task, result);

PrismValueDeltaSetTriple<V> mappingOutputTriple = mapping.getOutputTriple();
LOGGER.trace("Output triple of mapping {}\n{}", mapping.getContextDescription(),
mappingOutputTriple == null ? null : mappingOutputTriple.debugDumpLazily(1));
LOGGER.trace("Output triple:\n{}", mappingOutputTriple == null ? null : mappingOutputTriple.debugDumpLazily(1));

if (isMeaningful(mappingOutputTriple)) {

Expand All @@ -181,12 +184,14 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
if (mapping.getStrength() == MappingStrengthType.STRONG) {
mappingOutputStruct.setStrongMappingWasUsed(true);

if (!hasFullTargetObject && params.getTargetLoader() != null && aPrioriTargetObject != null && aPrioriTargetObject.getOid() != null) {
if (!params.getTargetLoader().isLoaded()) {
aPrioriTargetObject = params.getTargetLoader().load("strong mapping", task, result);
LOGGER.trace("Loaded object because of strong mapping: {}", aPrioriTargetObject);
hasFullTargetObject = true;
}
if (!hasFullTargetObject
&& params.getTargetLoader() != null
&& aPrioriTargetObject != null
&& aPrioriTargetObject.getOid() != null
&& !params.getTargetLoader().isLoaded()) {
aPrioriTargetObject = params.getTargetLoader().load("strong mapping", task, result);
LOGGER.trace("Loaded object because of strong mapping: {}", aPrioriTargetObject);
hasFullTargetObject = true;
}
}

Expand All @@ -196,12 +201,14 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(

// TODO should we really load the resource object also if we are pushing the changes?
// (but it looks like we have to!)
if (!hasFullTargetObject && params.getTargetLoader() != null && aPrioriTargetObject != null && aPrioriTargetObject.getOid() != null) {
if (!params.getTargetLoader().isLoaded()) {
aPrioriTargetObject = params.getTargetLoader().load("pushing changes", task, result);
LOGGER.trace("Loaded object because of pushing changes: {}", aPrioriTargetObject);
hasFullTargetObject = true;
}
if (!hasFullTargetObject
&& params.getTargetLoader() != null
&& aPrioriTargetObject != null
&& aPrioriTargetObject.getOid() != null
&& !params.getTargetLoader().isLoaded()) {
aPrioriTargetObject = params.getTargetLoader().load("pushing changes", task, result);
LOGGER.trace("Loaded object because of pushing changes: {}", aPrioriTargetObject);
hasFullTargetObject = true;
}
}

Expand All @@ -213,7 +220,7 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
}

} else {
LOGGER.trace("Output triple of mapping {} is NOT meaningful", mapping.getContextDescription());
LOGGER.trace("Output triple of mapping is NOT meaningful, ignoring it");
}

}
Expand All @@ -226,6 +233,8 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
continue;
}

LOGGER.trace("Evaluating weak mapping: {}", mapping.getContextDescription());

UniformItemPath mappingOutputPath = prismContext.toUniformPathKeepNull(mapping.getOutputPath());
if (params.isFixTarget() && mappingOutputPath != null && defaultTargetItemPath != null && !mappingOutputPath.equivalent(defaultTargetItemPath)) {
throw new ExpressionEvaluationException("Target cannot be overridden in " + mappingDesc);
Expand All @@ -248,6 +257,7 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
// values. Also we may need the output of the weak mapping to correctly process
// non-tolerant values (to avoid removing the value that weak mapping produces).
// MID-3847
LOGGER.trace("Previous mapping(s) produced zero/positive output, skipping weak mapping");
continue;
}

Expand All @@ -268,12 +278,14 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
// But the mapping may not be activated (e.g. condition is false). And in that
// case we really do not want to trigger object loading.
// This is all not right. See MID-3847
if (!hasFullTargetObject && params.getTargetLoader() != null && aPrioriTargetObject != null && aPrioriTargetObject.getOid() != null) {
if (!params.getTargetLoader().isLoaded()) {
aPrioriTargetObject = params.getTargetLoader().load("weak mapping", task, result);
LOGGER.trace("Loaded object because of weak mapping: {}", aPrioriTargetObject);
hasFullTargetObject = true;
}
if (!hasFullTargetObject
&& params.getTargetLoader() != null
&& aPrioriTargetObject != null
&& aPrioriTargetObject.getOid() != null
&& !params.getTargetLoader().isLoaded()) {
aPrioriTargetObject = params.getTargetLoader().load("weak mapping", task, result);
LOGGER.trace("Loaded object because of weak mapping: {}", aPrioriTargetObject);
hasFullTargetObject = true;
}
if (aPrioriTargetObject != null && mappingOutputPath != null) {
aPrioriTargetItem = aPrioriTargetObject.findItem(mappingOutputPath);
Expand All @@ -293,9 +305,13 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
}
}

LOGGER.trace("Mapping(s) are evaluated, going to process output triple(s)");

MappingOutputProcessor<V> processor = params.getProcessor();
for (Map.Entry<UniformItemPath, MappingOutputStruct<V>> outputTripleMapEntry : outputTripleMap.entrySet()) {
UniformItemPath mappingOutputPath = outputTripleMapEntry.getKey();
LOGGER.trace("Processing output triple for path '{}'", mappingOutputPath);

MappingOutputStruct<V> mappingOutputStruct = outputTripleMapEntry.getValue();
PrismValueDeltaSetTriple<V> outputTriple = mappingOutputStruct.getOutputTriple();

Expand All @@ -310,7 +326,7 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
if (defaultProcessing) {

if (outputTriple == null) {
LOGGER.trace("{} expression resulted in null triple for {}, skipping", mappingDesc, targetContext);
LOGGER.trace("Expression resulted in null triple, skipping");
continue;
}

Expand Down Expand Up @@ -344,9 +360,10 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(

Collection<V> nonNegativeValues = outputTriple.getNonNegativeValues();
if (nonNegativeValues.isEmpty()) {
LOGGER.trace("{} resulted in null or empty value for {}, skipping", mappingDesc, targetContext);
LOGGER.trace("The output is null or empty for ADD operation, skipping");
continue;
}
LOGGER.trace("Setting up the REPLACE delta because of ADD operation; values: {}", nonNegativeValues);
targetItemDelta.setValuesToReplace(PrismValueCollectionsUtil.cloneCollection(nonNegativeValues));

} else {
Expand All @@ -366,8 +383,9 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
valuesToReplace = outputTriple.getPlusSet();
}

LOGGER.trace("{}: hasFullTargetObject={}, isStrongMappingWasUsed={}, pushingChange={}, valuesToReplace={}",
mappingDesc, hasFullTargetObject, mappingOutputStruct.isStrongMappingWasUsed(),
LOGGER.trace(
"Computed new values when hasFullTargetObject={}, isStrongMappingWasUsed={}, pushingChange={}: {}",
hasFullTargetObject, mappingOutputStruct.isStrongMappingWasUsed(),
mappingOutputStruct.isPushChanges(), valuesToReplace);

if (!valuesToReplace.isEmpty()) {
Expand All @@ -378,30 +396,37 @@ Map<UniformItemPath, MappingOutputStruct<V>> evaluateMappingsToTriples(
if (hasFullTargetObject && targetContext.isFresh() && aPrioriTargetItem != null) {
Collection<V> valuesPresent = aPrioriTargetItem.getValues();
if (PrismValueCollectionsUtil.equalsRealValues(valuesPresent, valuesToReplace)) {
LOGGER.trace("{} resulted in existing values for {}, skipping creation of a delta", mappingDesc, targetContext);
LOGGER.trace("Computed values are equivalent to existing ones, skipping creation of a delta");
continue;
} else {
LOGGER.trace("Will create a delta, because computed values are NOT equivalent to existing ones, "
+ "which are: {}", valuesPresent);
}
} else {
LOGGER.trace("Not checking with the existing values because of no fresh full target object");
}

targetItemDelta.setValuesToReplace(PrismValueCollectionsUtil.cloneCollection(valuesToReplace));

applyEstimatedOldValueInReplaceCaseIfCredentials(params, targetItemDelta, outputTriple);

} else if (outputTriple.hasMinusSet()) {
LOGGER.trace("{} resulted in null or empty value for {} and there is a minus set, resetting it (replace with empty)", mappingDesc, targetContext);
LOGGER.trace("The output is null or empty and there is a minus set, clearing the target property");
targetItemDelta.setValueToReplace();

applyEstimatedOldValueInReplaceCaseIfCredentials(params, targetItemDelta, outputTriple);

} else {
LOGGER.trace("{} resulted in null or empty value for {}, skipping", mappingDesc, targetContext);
LOGGER.trace("The output is null or empty, skipping creation of a delta");
// implicit "continue" (the delta is empty here)
}
}

if (targetItemDelta.isEmpty()) {
continue;
}

LOGGER.trace("{} adding new delta for {}: {}", mappingDesc, targetContext, targetItemDelta);
LOGGER.trace("Adding new delta: {}", targetItemDelta);
targetContext.swallowToSecondaryDelta(targetItemDelta);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import com.evolveum.midpoint.model.impl.lens.LensProjectionContext;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.ConfigurationException;
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.*;

import org.jetbrains.annotations.Nullable;

import javax.xml.datatype.XMLGregorianCalendar;
import java.util.List;

Expand All @@ -37,25 +38,24 @@ public DelayedDeleteEvaluator(ResourceActivationDefinitionType activationDefinit
}

@Override
public void init() {
super.init();
public void initialize() {
super.initialize();
timeEvaluation = new TimeConstraintEvaluation(
ItemPath.create(FocusType.F_ACTIVATION, ActivationType.F_DISABLE_TIMESTAMP),
getActivationDefinitionBean().getDelayedDelete().getDeleteAfter());
}

public <F extends FocusType> boolean defineExistence(
final LensContext<F> context, final LensProjectionContext projCtx) {
public <F extends FocusType> boolean defineExistence(LensContext<F> context, LensProjectionContext projCtx) {
return false;
}

@Override
public <F extends FocusType> XMLGregorianCalendar defineTimeForTriggerOfExistence(
public <F extends FocusType> XMLGregorianCalendar getNextRecomputeTimeForExistence(
LensContext<F> context, LensProjectionContext projCtx, XMLGregorianCalendar now)
throws SchemaException, ConfigurationException {
checkInitialization();
initializeIfNeeded();

if (timeEvaluation.isTimeConstraintValid() == null) {
if (!timeEvaluation.isTimeValidityEstablished()) {
timeEvaluation.evaluateFrom(projCtx.getObjectDeltaObject(), now);
}

Expand All @@ -71,38 +71,24 @@ public <F extends FocusType> XMLGregorianCalendar defineTimeForTriggerOfExistenc
}

@Override
public <F extends FocusType> boolean isConfigured(Task task) {
if (getActivationDefinitionBean().getDelayedDelete() == null) {
LOGGER.trace(
"DelayedDeleteEvaluator: non-exist configuration for delayedDelete in: {}, skipping",
getActivationDefinitionBean());
return false;
}

DelayedDeleteActivationMappingType delayedDelete = getActivationDefinitionBean().getDelayedDelete();
if (!task.canSee(delayedDelete.getLifecycleState())) {
LOGGER.trace("DelayedDeleteEvaluator: not applicable to the execution mode, skipping");
return false;
}
return true;
@Nullable AbstractPredefinedActivationMappingType getConfiguration() {
return getActivationDefinitionBean().getDelayedDelete();
}

@Override
public <F extends FocusType> boolean isApplicable(
LensContext<F> context, LensProjectionContext projCtx, XMLGregorianCalendar now)
throws SchemaException, ConfigurationException {
checkInitialization();
initializeIfNeeded();

timeEvaluation.evaluateFrom(projCtx.getObjectDeltaObject(), now);
if (!timeEvaluation.isTimeConstraintValid()) {
LOGGER.trace("DelayedDeleteEvaluator: time constraint isn't valid, skipping");
LOGGER.trace("Time constraint isn't valid -> not applicable");
return false;
}

if (!isConditionSatisfied(projCtx)) {
LOGGER.trace(
"DelayedDeleteEvaluator: activation status isn't disabled "
+ "or disable reason isn't mapped or deprovision, skipping");
LOGGER.trace("Activation status isn't 'disabled' or disable reason isn't 'deprovision' -> not applicable");
return false;
}

Expand All @@ -129,4 +115,9 @@ private boolean isConditionSatisfied(LensProjectionContext projCtx) throws Schem

return true;
}

@Override
Trace getLogger() {
return LOGGER;
}
}

0 comments on commit bad7602

Please sign in to comment.