Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/user-search
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Aug 24, 2015
2 parents 7913d5a + 245d11c commit ac8f55d
Show file tree
Hide file tree
Showing 18 changed files with 517 additions and 277 deletions.
36 changes: 25 additions & 11 deletions config/initial-objects/090-report-audit.xml

Large diffs are not rendered by default.

33 changes: 21 additions & 12 deletions config/initial-objects/100-report-reconciliation.xml

Large diffs are not rendered by default.

27 changes: 21 additions & 6 deletions config/initial-objects/110-report-user-list.xml

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Expand Up @@ -434,6 +434,10 @@ public void resetValuesToAdd() {
valuesToAdd = null;
}

public void resetValuesToDelete() {
valuesToDelete = null;
}

public void setValuesToReplace(Collection<V> newValues) {
if (valuesToAdd != null) {
throw new IllegalStateException("Delta " + this
Expand Down Expand Up @@ -1564,5 +1568,13 @@ public static void mergeAll(Collection<? extends ItemDelta> modifications, Colle
merge(modifications, deltaToMerge);
}
}

public void addToReplaceDelta() {
if (isReplace()) {
throw new IllegalStateException("Delta is a REPLACE delta, not an ADD one");
}
valuesToReplace = valuesToAdd;
valuesToAdd = null;
}

}
Expand Up @@ -7,6 +7,8 @@
import com.evolveum.midpoint.prism.path.NameItemPathSegment;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;

import java.util.Map;

public class ItemPathUtil {

private ItemPathUtil(){
Expand Down Expand Up @@ -49,4 +51,27 @@ public static QName getOnlySegmentQName(ItemPath path) {
}
}

public static <T> T putToMap(Map<ItemPath, T> map, ItemPath itemPath, T value) {
for (ItemPath key : map.keySet()) {
if (key.equivalent(itemPath)) {
return map.put(key, value);
}
}
return map.put(itemPath, value);
}

public static <T> void putAllToMap(Map<ItemPath, T> target, Map<ItemPath, T> source) {
for (Map.Entry<ItemPath, T> entry : source.entrySet()) {
putToMap(target, entry.getKey(), entry.getValue());
}
}

public static <T> T getFromMap(Map<ItemPath, T> map, ItemPath itemPath) {
for (Map.Entry<ItemPath, T> entry : map.entrySet()) {
if (entry.getKey().equivalent(itemPath)) {
return entry.getValue();
}
}
return null;
}
}
Expand Up @@ -1258,6 +1258,7 @@ public void cleanupResult() {
*/
public void cleanupResult(Throwable e) {
if (status == OperationResultStatus.UNKNOWN) {
LOGGER.error("Attempt to cleanup result of operation " + operation + " that is still UNKNOWN:\n{}", this.debugDump());
throw new IllegalStateException("Attempt to cleanup result of operation "+operation+" that is still UNKNOWN");
}
if (subresults == null) {
Expand All @@ -1268,6 +1269,7 @@ public void cleanupResult(Throwable e) {
OperationResult subresult = iterator.next();
if (subresult.getStatus() == OperationResultStatus.UNKNOWN) {
String message = "Subresult "+subresult.getOperation()+" of operation "+operation+" is still UNKNOWN during cleanup";
LOGGER.error("{}:\n{}", message, this.debugDump());
if (e == null) {
throw new IllegalStateException(message);
} else {
Expand Down
225 changes: 117 additions & 108 deletions infra/schema/src/main/resources/xml/ns/public/common/common-3.xsd

Large diffs are not rendered by default.

Expand Up @@ -542,7 +542,7 @@ private <F extends FocusType> void processAssignmentsProjectionsWithFocus(LensCo
collectFocusTripleFromMappings(evaluatedAssignmentTriple.getMinusSet(), focusOutputTripleMap, PlusMinusZero.MINUS);
collectFocusTripleFromMappings(evaluatedAssignmentTriple.getZeroSet(), focusOutputTripleMap, PlusMinusZero.ZERO);
ObjectDeltaObject<F> focusOdo = focusContext.getObjectDeltaObject();
Collection<ItemDelta<?,?>> focusDeltas = objectTemplateProcessor.computeItemDeltas(focusOutputTripleMap,
Collection<ItemDelta<?,?>> focusDeltas = objectTemplateProcessor.computeItemDeltas(focusOutputTripleMap, null,
focusOdo, focusContext.getObjectDefinition(), "focus mappings in assignments of "+focusContext.getHumanReadableName());
LOGGER.trace("Computed focus deltas: {}", focusDeltas);
focusContext.applyProjectionWaveSecondaryDeltas(focusDeltas);
Expand Down
Expand Up @@ -25,6 +25,7 @@
import javax.xml.datatype.DatatypeConstants;
import javax.xml.datatype.XMLGregorianCalendar;

import com.evolveum.midpoint.prism.util.ItemPathUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -134,11 +135,13 @@ public <F extends FocusType> void processTemplate(LensContext<F> context, Object
new Object[]{objectTemplate, focusContext.getObjectNew(), iteration, iterationToken, phase});

Map<ItemPath,DeltaSetTriple<? extends ItemValueWithOrigin<?,?>>> outputTripleMap = new HashMap<>();


Map<ItemPath,ObjectTemplateItemDefinitionType> itemDefinitionsMap = collectItemDefinitionsFromTemplate(objectTemplate, objectTemplate.toString(), task, result);

XMLGregorianCalendar nextRecomputeTime = collectTripleFromTemplate(context, objectTemplate, phase, focusOdo, outputTripleMap,
iteration, iterationToken, now, objectTemplate.toString(), task, result);
Collection<ItemDelta<?,?>> itemDeltas = computeItemDeltas(outputTripleMap, focusOdo, focusDefinition, "object template "+objectTemplate+ " for focus "+focusOdo.getAnyObject());

Collection<ItemDelta<?,?>> itemDeltas = computeItemDeltas(outputTripleMap, itemDefinitionsMap, focusOdo, focusDefinition, "object template "+objectTemplate+ " for focus "+focusOdo.getAnyObject());

focusContext.applyProjectionWaveSecondaryDeltas(itemDeltas);

Expand Down Expand Up @@ -172,7 +175,38 @@ public <F extends FocusType> void processTemplate(LensContext<F> context, Object

}

private Map<ItemPath, ObjectTemplateItemDefinitionType> collectItemDefinitionsFromTemplate(ObjectTemplateType objectTemplateType, String contextDesc, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
Map<ItemPath, ObjectTemplateItemDefinitionType> definitions = new HashMap<>();
// Process includes (TODO refactor as a generic method)
for (ObjectReferenceType includeRef: objectTemplateType.getIncludeRef()) {
PrismObject<ObjectTemplateType> includeObject = includeRef.asReferenceValue().getObject();
if (includeObject == null) {
ObjectTemplateType includeObjectType = modelObjectResolver.resolve(includeRef, ObjectTemplateType.class,
null, "include reference in "+objectTemplateType + " in " + contextDesc, result);
includeObject = includeObjectType.asPrismObject();
// Store resolved object for future use (e.g. next waves).
includeRef.asReferenceValue().setObject(includeObject);
}
LOGGER.trace("Including template {}", includeObject);
ObjectTemplateType includeObjectType = includeObject.asObjectable();
Map<ItemPath, ObjectTemplateItemDefinitionType> includedDefinitions = collectItemDefinitionsFromTemplate(includeObjectType, "include "+includeObject+" in "+objectTemplateType + " in " + contextDesc, task, result);
if (includedDefinitions != null) {
ItemPathUtil.putAllToMap(definitions, includedDefinitions);
}
}

// Process own definitions
for (ObjectTemplateItemDefinitionType def : objectTemplateType.getItem()) {
if (def.getRef() == null) {
throw new IllegalStateException("Item definition with null ref in " + contextDesc);
}
ItemPathUtil.putToMap(definitions, def.getRef().getItemPath(), def); // TODO check for incompatible overrides
}
return definitions;
}

<F extends FocusType> Collection<ItemDelta<?,?>> computeItemDeltas(Map<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?,?>>> outputTripleMap,
Map<ItemPath,ObjectTemplateItemDefinitionType> itemDefinitionsMap, // may be null
ObjectDeltaObject<F> focusOdo, PrismObjectDefinition<F> focusDefinition, String contextDesc) throws ExpressionEvaluationException, PolicyViolationException, SchemaException {
Collection<ItemDelta<?,?>> itemDeltas = new ArrayList<>();
for (Entry<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?,?>>> entry: outputTripleMap.entrySet()) {
Expand All @@ -181,13 +215,34 @@ <F extends FocusType> Collection<ItemDelta<?,?>> computeItemDeltas(Map<ItemPath,
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Computed triple for {}:\n{}", itemPath, outputTriple.debugDump());
}
ItemDelta apropriItemDelta = null;
// boolean addUnchangedValues = focusContext.isAdd();
// We need to add unchanged values otherwise the unconditional mappings will not be applied
boolean addUnchangedValues = true;
ObjectTemplateItemDefinitionType itemDefinition = null;
if (itemDefinitionsMap != null) {
itemDefinition = ItemPathUtil.getFromMap(itemDefinitionsMap, itemPath);
}
boolean isNonTolerant = itemDefinition != null && Boolean.FALSE.equals(itemDefinition.isTolerant());

ItemDelta aprioriItemDelta = null;
boolean addUnchangedValues = true; // We need to add unchanged values otherwise the unconditional mappings will not be applied
boolean filterExistingValues = !isNonTolerant; // if non-tolerant, we want to gather ZERO & PLUS sets
ItemDelta<?,?> itemDelta = LensUtil.consolidateTripleToDelta(itemPath, (DeltaSetTriple)outputTriple,
focusDefinition.findItemDefinition(itemPath), apropriItemDelta, focusOdo.getNewObject(), null, null,
addUnchangedValues, true, false, contextDesc, true);
focusDefinition.findItemDefinition(itemPath), aprioriItemDelta, focusOdo.getNewObject(), null, null,
addUnchangedValues, filterExistingValues, false, contextDesc, true);

if (isNonTolerant) {
if (itemDelta.isDelete()) {
LOGGER.trace("Non-tolerant item with values to DELETE => removing them");
itemDelta.resetValuesToDelete(); // these are useless now - we move everything to REPLACE
}
if (itemDelta.isAdd()) {
itemDelta.addToReplaceDelta();
LOGGER.trace("Non-tolerant item with resulting ADD delta => converted ADD to REPLACE values");
} else if (itemDelta.isReplace()) {
LOGGER.trace("Non-tolerant item with resulting REPLACE delta => doing nothing");
} else {
itemDelta.setValuesToReplace();
LOGGER.trace("Non-tolerant item => converting resulting empty delta to 'delete all values' delta");
}
}

itemDelta.simplify();
itemDelta.validate(contextDesc);
Expand Down Expand Up @@ -221,7 +276,7 @@ private <F extends FocusType> XMLGregorianCalendar collectTripleFromTemplate(Len
LOGGER.trace("Including template {}", includeObject);
ObjectTemplateType includeObjectType = includeObject.asObjectable();
XMLGregorianCalendar includeNextRecomputeTime = collectTripleFromTemplate(context, includeObjectType, phase, userOdo,
outputTripleMap, iteration, iterationToken,
outputTripleMap, iteration, iterationToken,
now, "include "+includeObject+" in "+objectTemplateType + " in " + contextDesc, task, result);
if (includeNextRecomputeTime != null) {
if (nextRecomputeTime == null || nextRecomputeTime.compare(includeNextRecomputeTime) == DatatypeConstants.GREATER) {
Expand Down
Expand Up @@ -530,12 +530,12 @@ private void decideIfTolerate(LensProjectionContext accCtx,

for (PrismPropertyValue<Object> isPValue : arePValues){
if (matchPattern(attributeDefinition.getTolerantValuePattern(), isPValue, valueMatcher)){
LOGGER.trace("Value {} of the attribute {} match with toletant value pattern. Value will be NOT DELETED." , new Object[]{isPValue, attributeDefinition});
LOGGER.trace("Value {} of the attribute {} match with tolerant value pattern. Value will be NOT DELETED." , new Object[]{isPValue, attributeDefinition});
continue;
}

if (matchPattern(attributeDefinition.getIntolerantValuePattern(), isPValue, valueMatcher)){
LOGGER.trace("Value {} of the attribute {} match with intoletant value pattern. Value will be DELETED." , new Object[]{isPValue, attributeDefinition});
LOGGER.trace("Value {} of the attribute {} match with intolerant value pattern. Value will be DELETED." , new Object[]{isPValue, attributeDefinition});
recordDelta(valueMatcher, accCtx, attributeDefinition, ModificationType.DELETE,
isPValue.getValue(), null);
continue;
Expand Down

0 comments on commit ac8f55d

Please sign in to comment.