Skip to content

Commit

Permalink
Some minor fixes.
Browse files Browse the repository at this point in the history
- support for legacy range specification with inbound processing
- fixes related to itemValue.parent manipulation (mainly for range evaluation)
  • Loading branch information
mederly committed Nov 22, 2017
1 parent ea90038 commit fca3c58
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 28 deletions.
Expand Up @@ -448,7 +448,7 @@ private void searchPerformed(ObjectQuery query, AjaxRequestTarget target) {
}

public void refreshTable(Class<O> newTypeClass, AjaxRequestTarget target) {
ObjectTypes newType = ObjectTypes.getObjectType(newTypeClass);
ObjectTypes newType = newTypeClass != null ? ObjectTypes.getObjectType(newTypeClass) : null;

BaseSortableDataProvider<SelectableBean<O>> provider = getDataProvider();
provider.setQuery(getQuery());
Expand Down
Expand Up @@ -896,32 +896,31 @@ protected void onSelectPerformed(AjaxRequestTarget target, FocusType focus) {
}

protected void importResourceObject(ShadowType selected, AjaxRequestTarget target) {
List<ShadowType> selectedShadow = null;
List<ShadowType> selectedShadows;
if (selected != null) {
selectedShadow = new ArrayList<>();
selectedShadow.add(selected);
selectedShadows = new ArrayList<>();
selectedShadows.add(selected);
} else {
selectedShadow = getTable().getSelectedObjects();
selectedShadows = getTable().getSelectedObjects();
}

OperationResult result = new OperationResult(OPERATION_IMPORT_OBJECT);
Task task = pageBase.createSimpleTask(OPERATION_IMPORT_OBJECT);

if (selectedShadow == null || selectedShadow.isEmpty()) {
if (selectedShadows == null || selectedShadows.isEmpty()) {
result.recordWarning("Nothing select to import");
getPageBase().showResult(result);
target.add(getPageBase().getFeedbackPanel());
return;
}

for (ShadowType shadow : selectedShadow) {
for (ShadowType shadow : selectedShadows) {
try {
getPageBase().getModelService().importFromResource(shadow.getOid(), task, result);
} catch (ObjectNotFoundException | SchemaException | SecurityViolationException
| CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
result.recordPartialError("Could not import account " + shadow, e);
LOGGER.error("Could not import account {} ", shadow, e);
continue;
}
}

Expand Down
Expand Up @@ -433,10 +433,10 @@ public boolean add(@NotNull V newValue, boolean checkUniqueness) throws SchemaEx
if (newValue.getPrismContext() == null) {
newValue.setPrismContext(prismContext);
}
newValue.setParent(this);
if (checkUniqueness && containsEquivalentValue(newValue)) {
return false;
}
newValue.setParent(this);
D definition = getDefinition();
if (definition != null) {
if (!values.isEmpty() && definition.isSingleValue()) {
Expand Down Expand Up @@ -469,6 +469,7 @@ public boolean remove(V newValue) {
// TODO or include a special test condition here; see MID-3828
if (val.representsSameValue(newValue, false) || val.equalsRealValue(newValue)) {
iterator.remove();
val.setParent(null);
changed = true;
}
}
Expand Down
Expand Up @@ -252,15 +252,15 @@ public static Class<? extends ObjectType> getObjectTypeClass(QName typeName) {

@SuppressWarnings("unchecked")
@NotNull
public static ObjectTypes getObjectType(Class<? extends ObjectType> objectType) {
public static ObjectTypes getObjectType(@NotNull Class<? extends ObjectType> objectType) {
ObjectTypes rv = getObjectTypeIfKnown(objectType);
if (rv == null) {
throw new IllegalArgumentException("Unsupported object type " + objectType);
}
return rv;
}

public static ObjectTypes getObjectTypeIfKnown(Class<?> objectType) {
public static ObjectTypes getObjectTypeIfKnown(@NotNull Class<?> objectType) {
for (ObjectTypes type : values()) {
if (type.getClassDefinition().equals(objectType)) {
return type;
Expand Down
Expand Up @@ -276,7 +276,7 @@ public Boolean isTolerant() {
}

public boolean hasTargetRange() {
return mappingType.getTarget().getSet() != null;
return mappingType.getTarget().getSet() != null || mappingType.getRange() != null;
}

public boolean isConditionMaskOld() {
Expand Down Expand Up @@ -525,18 +525,18 @@ private boolean isInRange(V value, Task task, OperationResult result) throws Exp
variables.addVariableDefinitions(this.variables); // TODO is this ok?

if (value instanceof PrismContainerValue) {
// artifically create parent for PCV in order to pass it to expression
// artificially create parent for PCV in order to pass it to expression
PrismContainer.createParentIfNeeded((PrismContainerValue) value, outputDefinition);
}
variables.addVariableDefinition(ExpressionConstants.VAR_VALUE, value);

PrismPropertyDefinition<Boolean> outputDef = new PrismPropertyDefinitionImpl<Boolean>(SchemaConstantsGenerated.C_VALUE, DOMUtil.XSD_BOOLEAN, getPrismContext(), null, false);
PrismPropertyValue<Boolean> rv = ExpressionUtil.evaluateExpression(variables, outputDef, range.getIsInSetExpression(), expressionFactory, "isInSet expression in " + contextDescription, task, result);

// but now remove the parent!
if (value.getParent() != null) {
value.setParent(null);
}
// but now remove the parent! TODO: PM: why???
// if (value.getParent() != null) {
// value.setParent(null);
// }

return rv != null && rv.getValue() != null ? rv.getValue() : Boolean.FALSE;
}
Expand Down
Expand Up @@ -125,6 +125,8 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType;
import com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType;

import static org.apache.commons.lang3.BooleanUtils.isTrue;

/**
* Processor that takes changes from accounts and synchronization deltas and updates user attributes if necessary
* (by creating secondary user object delta {@link ObjectDelta}).
Expand Down Expand Up @@ -291,7 +293,7 @@ private <F extends FocusType, V extends PrismValue, D extends ItemDefinition> vo
Collection<ItemDelta<V, D>> deltas = evaluateInboundMapping(mappingsToTarget, context, projContext, task, result);

if (deltas == null) {
LOGGER.trace("No focus delta poduces from inboud mappings");
LOGGER.trace("No focus delta produces from inbound mappings");
return;
}

Expand Down Expand Up @@ -829,28 +831,25 @@ private <F extends FocusType, V extends PrismValue,D extends ItemDefinition> Col

DeltaSetTriple<ItemValueWithOrigin<V, D>> itemValueWithOrigin = ItemValueWithOrigin.createOutputTriple(mapping);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Inbound mapping for {} returned triple:\n{}", mapping.getDefaultSource().debugDump(),
LOGGER.trace("Inbound mapping for {}\nreturned triple:\n{}", mapping.getDefaultSource().debugDump(),
itemValueWithOrigin == null ? "null" : itemValueWithOrigin.debugDump());
}
if (itemValueWithOrigin != null) {

allTriples.addAllToMinusSet(itemValueWithOrigin.getMinusSet());
allTriples.addAllToPlusSet(itemValueWithOrigin.getPlusSet());
allTriples.addAllToZeroSet(itemValueWithOrigin.getZeroSet());
}

}
AssignmentPolicyEnforcementType assignmentEnforcement = projectionCtx.getAssignmentPolicyEnforcementType();
DeltaSetTriple<ItemValueWithOrigin<V, D>> consolidatedTriples = consolidateTriples(allTriples, assignmentEnforcement);

LOGGER.trace("Consolidated triples {} \nfor mapping for item {}", consolidatedTriples.debugDump(), mappingEntry.getKey());
LOGGER.trace("Consolidated triples {} \nfor mapping for item {}", consolidatedTriples.debugDumpLazily(), mappingEntry.getKey());

Mapping<V, D> firstMapping = mappingEntry.getValue().iterator().next();
outputDeltas.add(
collectOutputDelta(mappingEntry.getKey(), firstMapping.getOutputPath(), focusNew,
consolidatedTriples,
firstMapping.isTolerant() == Boolean.TRUE ? true : false,
hasRange(mappingEntry.getValue()), projectionCtx.isDelete()));
consolidatedTriples, isTrue(firstMapping.isTolerant()),
hasRange(mappingEntry.getValue()), projectionCtx.isDelete()));
}


Expand Down Expand Up @@ -1009,7 +1008,10 @@ private <V extends PrismValue, D extends ItemDefinition> DeltaSetTriple<ItemValu
}


private <V extends PrismValue, D extends ItemDefinition, F extends FocusType> ItemDelta<V, D> collectOutputDelta(ItemDefinition outputDefinition, ItemPath outputPath, PrismObject<F> focusNew, DeltaSetTriple<ItemValueWithOrigin<V, D>> consolidatedTriples, boolean tolerant, boolean hasRange, boolean isDelete) throws SchemaException {
private <V extends PrismValue, D extends ItemDefinition, F extends FocusType> ItemDelta<V, D> collectOutputDelta(
ItemDefinition outputDefinition, ItemPath outputPath, PrismObject<F> focusNew,
DeltaSetTriple<ItemValueWithOrigin<V, D>> consolidatedTriples, boolean tolerant,
boolean hasRange, boolean isDelete) throws SchemaException {

// ItemPath outputPath = inboundMappingType.getOutputPath();
ItemDelta outputFocusItemDelta = outputDefinition.createEmptyDelta(outputPath);
Expand Down Expand Up @@ -1095,7 +1097,7 @@ private <V extends PrismValue, D extends ItemDefinition, F extends FocusType> It
}

if (isDelete) {
LOGGER.trace("Skipping comarision of user's property to produces delta. Projection is going to be deleted, clean up just attributes from this projection.");
LOGGER.trace("Skipping comparison of user's property to produces delta. Projection is going to be deleted, clean up just attributes from this projection.");
return outputFocusItemDelta;
}

Expand All @@ -1110,7 +1112,7 @@ private <V extends PrismValue, D extends ItemDefinition, F extends FocusType> It

if (hasRange) {
LOGGER.trace("Skipping merge for diff delta because mapping contains range. All plus/minus/zero set were computed during renge checking");
LOGGER.trace("Returining delta: {}", outputFocusItemDelta.debugDump());
LOGGER.trace("Returning delta: {}", outputFocusItemDelta.debugDump());
return outputFocusItemDelta;
}

Expand Down

0 comments on commit fca3c58

Please sign in to comment.