use of com.evolveum.midpoint.prism.Visitor in project midpoint by Evolveum.
the class PrismValueDeltaSetTriple method checkConsistence.
public void checkConsistence() {
Visitor visitor = visitable -> {
if (visitable instanceof PrismValue) {
if (((PrismValue) visitable).isEmpty()) {
throw new IllegalStateException("Empty value " + visitable + " in triple " + PrismValueDeltaSetTriple.this);
}
}
};
accept(visitor);
Processor<V> processor = pval -> {
if (pval.getParent() != null) {
throw new IllegalStateException("Value " + pval + " in triple " + PrismValueDeltaSetTriple.this + " has parent, looks like it was not cloned properly");
}
};
foreach(processor);
}
use of com.evolveum.midpoint.prism.Visitor in project midpoint by Evolveum.
the class ObjectMerger method computeDefaultDeltas.
private <O extends ObjectType> void computeDefaultDeltas(final ObjectDelta<O> leftObjectDelta, final PrismObject<O> objectLeft, final PrismObject<O> objectRight, final List<ItemPath> processedPaths, MergeConfigurationType mergeConfiguration, final String mergeConfigurationName, final Task task, final OperationResult result) throws SchemaException, ConfigurationException, ExpressionEvaluationException, ObjectNotFoundException {
final ItemMergeConfigurationType defaultItemMergeConfig = mergeConfiguration.getDefault();
if (defaultItemMergeConfig != null) {
try {
Visitor visitor = new Visitor() {
@Override
public void visit(Visitable visitable) {
if (!(visitable instanceof Item)) {
return;
}
Item item = (Item) visitable;
ItemPath itemPath = item.getPath();
if (itemPath == null || itemPath.isEmpty()) {
return;
}
if (SchemaConstants.PATH_LINK_REF.equivalent(itemPath)) {
// Skip. There is a special processing for this.
return;
}
boolean found = false;
for (ItemPath processedPath : processedPaths) {
// Need to check for super-paths here.
// E.g. if we have already processed metadata, we do not want to process
// metadata/modifyTimestamp
CompareResult compareResult = processedPath.compareComplex(itemPath);
if (compareResult == CompareResult.EQUIVALENT || compareResult == CompareResult.SUBPATH) {
found = true;
break;
}
}
if (found) {
return;
}
processedPaths.add(itemPath);
if (item instanceof PrismContainer<?>) {
if (item.getDefinition().isSingleValue()) {
// we will handle every individual property there.
return;
} else {
// TODO: we may need special handling for multi-value containers
// such as assignment
}
}
ItemDelta itemDelta;
try {
itemDelta = mergeItem(objectLeft, objectRight, mergeConfigurationName, defaultItemMergeConfig, itemPath, task, result);
} catch (SchemaException | ConfigurationException | ExpressionEvaluationException | ObjectNotFoundException e) {
throw new TunnelException(e);
}
LOGGER.trace("Item {} delta (default): {}", itemPath, itemDelta);
if (itemDelta != null && !itemDelta.isEmpty()) {
leftObjectDelta.addModification(itemDelta);
}
}
};
objectLeft.accept(visitor);
objectRight.accept(visitor);
} catch (TunnelException te) {
if (te.getCause() instanceof SchemaException) {
throw (SchemaException) te.getCause();
} else if (te.getCause() instanceof ConfigurationException) {
throw (ConfigurationException) te.getCause();
} else if (te.getCause() instanceof ExpressionEvaluationException) {
throw (ExpressionEvaluationException) te.getCause();
} else if (te.getCause() instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) te.getCause();
} else {
throw new SystemException("Unexpected exception: " + te, te);
}
}
}
}
use of com.evolveum.midpoint.prism.Visitor in project midpoint by Evolveum.
the class ModelController method removeOperationalItems.
// TODO write in cleaner way
private <T extends ObjectType> void removeOperationalItems(PrismObject<T> object) {
if (object == null) {
return;
}
final List<ItemPath> operationalItems = new ArrayList<>();
object.accept(new Visitor() {
@Override
public void visit(Visitable visitable) {
if (visitable instanceof Item) {
Item item = ((Item) visitable);
if (item.getDefinition() != null && item.getDefinition().isOperational()) {
operationalItems.add(item.getPath());
// it would be nice if we could stop visiting children here but that's not possible now
}
}
}
});
LOGGER.trace("Operational items: {}", operationalItems);
removeIgnoredItems(object, operationalItems);
}
Aggregations