Search in sources :

Example 16 with ItemPathType

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);
    }
}
Also used : QName(javax.xml.namespace.QName) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) Element(org.w3c.dom.Element)

Example 17 with ItemPathType

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;
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 18 with ItemPathType

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);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 19 with ItemPathType

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;
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType)

Example 20 with 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;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) QName(javax.xml.namespace.QName) Source(com.evolveum.midpoint.repo.common.expression.Source) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) ValueSetDefinition(com.evolveum.midpoint.repo.common.expression.ValueSetDefinition) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)55 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)36 QName (javax.xml.namespace.QName)20 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)11 ArrayList (java.util.ArrayList)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)10 ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)9 Test (org.testng.annotations.Test)9 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)7 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)7 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)6 List (java.util.List)5 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)4 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)4 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)4 MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)4 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)3