use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class LiteralEqualsStrategy method equalsInternal.
@Override
protected boolean equalsInternal(ObjectLocator leftLocator, ObjectLocator rightLocator, Object lhs, Object rhs) {
// System.out.println("DomAwareEqualsStrategy: "+PrettyPrinter.prettyPrint(lhs)+"<=>"+PrettyPrinter.prettyPrint(rhs));
if (lhs instanceof String && rhs instanceof String) {
// this is questionable (but seems ok)
return DOMUtil.compareTextNodeValues((String) lhs, (String) rhs);
} else if (lhs instanceof Element && rhs instanceof Element) {
// this is perhaps obsolete
final Element left = (Element) lhs;
final Element right = (Element) rhs;
boolean result = DOMUtil.compareElement(left, right, true);
// System.out.println("cmp: "+PrettyPrinter.prettyPrint(left)+"<=>"+PrettyPrinter.prettyPrint(right)+": "+result);
return result;
} else if (lhs instanceof QName && rhs instanceof QName) {
QName l = (QName) lhs;
QName r = (QName) rhs;
if (!l.equals(r)) {
return false;
}
return StringUtils.equals(l.getPrefix(), r.getPrefix());
} else if (lhs instanceof ItemPathType && rhs instanceof ItemPathType) {
// ItemPathType's equals is already working literally
return ((ItemPathType) lhs).equals((ItemPathType) rhs);
} else {
return super.equalsInternal(leftLocator, rightLocator, lhs, rhs);
}
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class ObjectTypeUtil method isModificationOf.
//TODO: refactor after new schema
public static boolean isModificationOf(ItemDeltaType modification, QName elementName, ItemPathType path) {
// if (path == null && XPathHolder.isDefault(modification.getPath())) {
// return (elementName.equals(ObjectTypeUtil.getElementName(modification)));
// }
ItemPathType modificationPath = modification.getPath();
if (ItemPathUtil.isDefault(modificationPath)) {
throw new IllegalArgumentException("Path in the delta must not be null");
}
if (path == null) {
return false;
}
// XPathHolder modPath = new XPathHolder(modification.getPath());
ItemPath full = new ItemPath(path.getItemPath(), elementName);
ItemPathType fullPath = new ItemPathType(full);
return fullPath.equivalent(modificationPath);
// if (fullPath.equals(modificationPath)) {
// return (elementName.equals(getElementName(modification)));
// }
// return false;
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class PathExpressionEvaluatorFactory method createEvaluator.
/* (non-Javadoc)
* @see com.evolveum.midpoint.common.expression.ExpressionEvaluatorFactory#createEvaluator(javax.xml.bind.JAXBElement, com.evolveum.midpoint.prism.ItemDefinition, com.evolveum.midpoint.prism.PrismContext)
*/
@Override
public <V extends PrismValue, D extends ItemDefinition> ExpressionEvaluator<V, D> createEvaluator(Collection<JAXBElement<?>> evaluatorElements, D outputDefinition, String contextDescription, Task task, OperationResult result) throws SchemaException {
Validate.notNull(outputDefinition, "output definition must be specified for path expression evaluator");
if (evaluatorElements.size() > 1) {
throw new SchemaException("More than one evaluator specified in " + contextDescription);
}
JAXBElement<?> evaluatorElement = evaluatorElements.iterator().next();
Object evaluatorElementObject = evaluatorElement.getValue();
if (!(evaluatorElementObject instanceof ItemPathType)) {
throw new IllegalArgumentException("Path expression cannot handle elements of type " + evaluatorElementObject.getClass().getName() + " in " + contextDescription);
}
ItemPath path = ((ItemPathType) evaluatorElementObject).getItemPath();
return new PathExpressionEvaluator<>(path, objectResolver, outputDefinition, protector, prismContext);
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class ModelClientUtil method createItemPathType.
public static ItemPathType createItemPathType(String stringPath) {
ItemPathType itemPathType = new ItemPathType();
String pathDeclaration = "declare default namespace '" + NS_COMMON + "'; " + stringPath;
itemPathType.setValue(pathDeclaration);
return itemPathType;
}
use of com.evolveum.prism.xml.ns._public.types_3.ItemPathType in project midpoint by Evolveum.
the class Mapping method parseSource.
private <IV extends PrismValue, ID extends ItemDefinition> Source<IV, ID> parseSource(VariableBindingDefinitionType sourceType, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
ItemPathType itemPathType = sourceType.getPath();
if (itemPathType == null) {
throw new SchemaException("No path in source definition in " + getMappingContextDescription());
}
ItemPath path = itemPathType.getItemPath();
if (path.isEmpty()) {
throw new SchemaException("Empty source path in " + getMappingContextDescription());
}
QName name = sourceType.getName();
if (name == null) {
name = ItemPath.getName(path.last());
}
ItemPath resolvePath = path;
Object sourceObject = ExpressionUtil.resolvePath(path, variables, sourceContext, objectResolver, "source definition in " + getMappingContextDescription(), task, result);
Item<IV, ID> itemOld = null;
ItemDelta<IV, ID> delta = null;
Item<IV, ID> itemNew = null;
ItemPath residualPath = null;
Collection<? extends ItemDelta<?, ?>> subItemDeltas = null;
if (sourceObject != null) {
if (sourceObject instanceof ItemDeltaItem<?, ?>) {
itemOld = ((ItemDeltaItem<IV, ID>) sourceObject).getItemOld();
delta = ((ItemDeltaItem<IV, ID>) sourceObject).getDelta();
itemNew = ((ItemDeltaItem<IV, ID>) sourceObject).getItemNew();
residualPath = ((ItemDeltaItem<IV, ID>) sourceObject).getResidualPath();
resolvePath = ((ItemDeltaItem<IV, ID>) sourceObject).getResolvePath();
subItemDeltas = ((ItemDeltaItem<IV, ID>) sourceObject).getSubItemDeltas();
} else if (sourceObject instanceof Item<?, ?>) {
itemOld = (Item<IV, ID>) sourceObject;
itemNew = (Item<IV, ID>) sourceObject;
} else {
throw new IllegalStateException("Unknown resolve result " + sourceObject);
}
}
// apply domain
ValueSetDefinitionType domainSetType = sourceType.getSet();
if (domainSetType != null) {
ValueSetDefinition setDef = new ValueSetDefinition(domainSetType, name, "domain of " + name.getLocalPart() + " in " + getMappingContextDescription(), task, result);
setDef.init(expressionFactory);
try {
if (itemOld != null) {
itemOld = itemOld.clone();
itemOld.filterValues(val -> setDef.containsTunnel(val));
}
if (itemNew != null) {
itemNew = itemNew.clone();
itemNew.filterValues(val -> setDef.containsTunnel(val));
}
if (delta != null) {
delta = delta.clone();
delta.filterValues(val -> setDef.containsTunnel(val));
}
} catch (TunnelException te) {
Throwable cause = te.getCause();
if (cause instanceof SchemaException) {
throw (SchemaException) cause;
} else if (cause instanceof ExpressionEvaluationException) {
throw (ExpressionEvaluationException) cause;
} else if (cause instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) cause;
}
}
}
Source<IV, ID> source = new Source<>(itemOld, delta, itemNew, name);
source.setResidualPath(residualPath);
source.setResolvePath(resolvePath);
source.setSubItemDeltas(subItemDeltas);
return source;
}
Aggregations