Skip to content

Commit

Permalink
Do minor tracing-related improvements
Browse files Browse the repository at this point in the history
1) Added some auxiliary trace information.
2) Added some experimental data manipulation methods in prism.
3) Fixed PCV.keepPaths method.
4) Fixed serialization of target names in bean-embedded references.
5) Serializing target names in traces.
  • Loading branch information
mederly committed Mar 25, 2020
1 parent 920490e commit 1ff58a4
Show file tree
Hide file tree
Showing 15 changed files with 2,010 additions and 1,684 deletions.
Expand Up @@ -11,6 +11,7 @@
import com.evolveum.midpoint.prism.equivalence.ParameterizedEquivalenceStrategy;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.midpoint.util.exception.SchemaException;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -299,6 +300,12 @@ static boolean isEmpty(ObjectDelta delta) {

boolean isRedundant(PrismObject<O> object, boolean assumeMissingItems) throws SchemaException;

@Experimental
void removeOperationalItems();

@Experimental
void removeEstimatedOldValues();

class FactorOutResultMulti<T extends Objectable> {
public final ObjectDelta<T> remainder;
public final List<ObjectDelta<T>> offsprings = new ArrayList<>();
Expand Down
Expand Up @@ -52,11 +52,11 @@ public static boolean containsSubpath(Collection<? extends ItemPath> paths, Item
/**
* Returns true if the collection contains a superpath of or equivalent path to the given path.
* I.e. having collection = { A/B, A/C }
* then the method for this collection and 'path' returns:
* - path = A/B -&gt; true
* - path = A -&gt; true
* - path = A/B/C -&gt; false
* - path = X -&gt; false
* then the method for this collection and 'pathToBeFound' returns:
* - pathToBeFound = A/B -&gt; true
* - pathToBeFound = A -&gt; true
* - pathToBeFound = A/B/C -&gt; false
* - pathToBeFound = X -&gt; false
*/
public static boolean containsSuperpathOrEquivalent(Collection<? extends ItemPath> paths, ItemPath pathToBeFound) {
for (ItemPath path : paths) {
Expand Down
Expand Up @@ -1672,7 +1672,9 @@ public void keepPaths(List<? extends ItemPath> keep) throws SchemaException {
for (QName itemName : itemNames) {
Item<?, ?> item = findItemByQName(itemName);
ItemPath itemPath = item.getPath().removeIds();
if (!ItemPathCollectionsUtil.containsSuperpathOrEquivalent(keep, itemPath)) {
if (!ItemPathCollectionsUtil.containsSuperpathOrEquivalent(keep, itemPath)
&& !ItemPathCollectionsUtil.containsSubpathOrEquivalent(keep, itemPath)) {
System.out.println("Removing " + itemPath + " because not in " + keep);
removeItem(ItemName.fromQName(itemName), Item.class);
} else {
if (item instanceof PrismContainer) {
Expand Down
Expand Up @@ -15,6 +15,7 @@
import com.evolveum.midpoint.prism.path.ItemPathCollectionsUtil;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
Expand Down Expand Up @@ -1405,4 +1406,47 @@ public boolean isRedundant(PrismObject<O> object, boolean assumeMissingItems) th
throw new AssertionError("Unknown change type: " + changeType);
}
}

@Experimental // todo review and write some tests
@Override
public void removeOperationalItems() {
switch (changeType) {
case ADD:
objectToAdd.getValue().removeOperationalItems();
return;
case MODIFY:
Iterator<? extends ItemDelta<?, ?>> iterator = modifications.iterator();
while (iterator.hasNext()) {
ItemDelta<?, ?> itemDelta = iterator.next();
ItemDefinition<?> definition = itemDelta.getDefinition();
if (definition != null && definition.isOperational()) {
iterator.remove();
} else {
emptyIfNull(itemDelta.getValuesToAdd()).forEach(this::removeOperationalItems);
emptyIfNull(itemDelta.getValuesToDelete()).forEach(this::removeOperationalItems);
emptyIfNull(itemDelta.getValuesToReplace()).forEach(this::removeOperationalItems);
emptyIfNull(itemDelta.getEstimatedOldValues()).forEach(this::removeOperationalItems);
}
}
return;
case DELETE:
// nothing to do here
}
}

private void removeOperationalItems(PrismValue value) {
if (value instanceof PrismContainerValue) {
((PrismContainerValue<?>) value).removeOperationalItems();
}
}

@Experimental // todo review and write some tests
@Override
public void removeEstimatedOldValues() {
if (changeType == ChangeType.MODIFY) {
for (ItemDelta<?, ?> modification : modifications) {
modification.setEstimatedOldValues(null);
}
}
}
}
Expand Up @@ -212,7 +212,7 @@ private XNodeImpl marshalItemValue(@NotNull PrismValue itemValue, @Nullable Item
xnode = serializeReferenceValue((PrismReferenceValue)itemValue, (PrismReferenceDefinition) definition, ctx);
} else if (itemValue instanceof PrismPropertyValue<?>) {
warnIfItemsToSkip(itemValue, itemsToSkip);
xnode = serializePropertyValue((PrismPropertyValue<?>)itemValue, (PrismPropertyDefinition) definition, typeName);
xnode = serializePropertyValue((PrismPropertyValue<?>)itemValue, (PrismPropertyDefinition) definition, typeName, ctx);
} else if (itemValue instanceof PrismContainerValue<?>) {
xnode = marshalContainerValue((PrismContainerValue<?>)itemValue, (PrismContainerDefinition) definition, ctx, itemsToSkip);
} else {
Expand Down Expand Up @@ -453,7 +453,8 @@ private QName createReferenceQName(QName qname, String namespace) {

//region Serializing properties - specific functionality
@NotNull
private <T> XNodeImpl serializePropertyValue(@NotNull PrismPropertyValue<T> value, PrismPropertyDefinition<T> definition, QName typeNameIfNoDefinition) throws SchemaException {
private <T> XNodeImpl serializePropertyValue(@NotNull PrismPropertyValue<T> value, PrismPropertyDefinition<T> definition,
QName typeNameIfNoDefinition, SerializationContext ctx) throws SchemaException {
@Nullable QName typeName = definition != null ? definition.getTypeName() : typeNameIfNoDefinition;
ExpressionWrapper expression = value.getExpression();
if (expression != null) {
Expand All @@ -467,7 +468,7 @@ private <T> XNodeImpl serializePropertyValue(@NotNull PrismPropertyValue<T> valu
} else if (realValue instanceof PolyStringType) { // should not occur ...
return beanMarshaller.marshalPolyString(((PolyStringType) realValue).toPolyString());
} else if (beanMarshaller.canProcess(typeName)) {
XNodeImpl xnode = beanMarshaller.marshall(realValue);
XNodeImpl xnode = beanMarshaller.marshall(realValue, ctx);
if (xnode == null) {
// Marshaling attempt may process the expression in raw element
expression = value.getExpression();
Expand Down

0 comments on commit 1ff58a4

Please sign in to comment.