Search in sources :

Example 6 with ItemPathSegment

use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.

the class ExpressionUtil method resolvePath.

public static Object resolvePath(ItemPath path, ExpressionVariables variables, Object defaultContext, ObjectResolver objectResolver, String shortDesc, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
    Object root = defaultContext;
    ItemPath relativePath = path;
    ItemPathSegment first = path.first();
    String varDesc = "default context";
    if (first.isVariable()) {
        QName varName = ((NameItemPathSegment) first).getName();
        varDesc = "variable " + PrettyPrinter.prettyPrint(varName);
        relativePath = path.rest();
        if (variables.containsKey(varName)) {
            root = variables.get(varName);
        } else {
            throw new SchemaException("No variable with name " + varName + " in " + shortDesc);
        }
    }
    if (root == null) {
        return null;
    }
    if (relativePath.isEmpty()) {
        return root;
    }
    if (root instanceof ObjectReferenceType) {
        root = resolveReference((ObjectReferenceType) root, objectResolver, varDesc, shortDesc, task, result);
    }
    if (root instanceof Objectable) {
        return (((Objectable) root).asPrismObject()).find(relativePath);
    }
    if (root instanceof PrismObject<?>) {
        return ((PrismObject<?>) root).find(relativePath);
    } else if (root instanceof PrismContainer<?>) {
        return ((PrismContainer<?>) root).find(relativePath);
    } else if (root instanceof PrismContainerValue<?>) {
        return ((PrismContainerValue<?>) root).find(relativePath);
    } else if (root instanceof Item<?, ?>) {
        // Except for container (which is handled above)
        throw new SchemaException("Cannot apply path " + relativePath + " to " + root + " in " + shortDesc);
    } else if (root instanceof ObjectDeltaObject<?>) {
        return ((ObjectDeltaObject<?>) root).findIdi(relativePath);
    } else if (root instanceof ItemDeltaItem<?, ?>) {
        return ((ItemDeltaItem<?, ?>) root).findIdi(relativePath);
    } else {
        throw new IllegalArgumentException("Unexpected root " + root + " (relative path:" + relativePath + ") in " + shortDesc);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 7 with ItemPathSegment

use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.

the class CertificationCaseHelper method checkPathSanity.

private long checkPathSanity(ItemPath deltaPath, List<Long> casesAddedOrDeleted) {
    ItemPathSegment secondSegment = deltaPath.getSegments().get(1);
    if (!(secondSegment instanceof IdItemPathSegment)) {
        throw new IllegalStateException("Couldn't update cert campaign by delta with path " + deltaPath + " - should start with case[id]");
    }
    Long id = ((IdItemPathSegment) secondSegment).getId();
    if (id == null) {
        throw new IllegalStateException("Couldn't update cert campaign by delta with path " + deltaPath + " - should start with case[id]");
    }
    if (deltaPath.size() == 2) {
        // not enough
        throw new IllegalStateException("Couldn't update cert campaign by delta with path " + deltaPath + " - should start with case[id] and contain additional path");
    }
    if (casesAddedOrDeleted == null || casesAddedOrDeleted.contains(id)) {
        throw new IllegalArgumentException("Couldn't update certification case that was added/deleted in this operation. Path=" + deltaPath);
    }
    return id;
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment)

Example 8 with ItemPathSegment

use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.

the class JpaEntityDefinition method nextLinkDefinition.

@Override
public DataSearchResult<?> nextLinkDefinition(ItemPath path, ItemDefinition<?> itemDefinition, PrismContext prismContext) throws QueryException {
    if (ItemPath.isNullOrEmpty(path)) {
        // doesn't fulfill precondition
        return null;
    }
    ItemPathSegment first = path.first();
    if (first instanceof IdItemPathSegment) {
        throw new QueryException("ID item path segments are not allowed in query: " + path);
    } else if (first instanceof ObjectReferencePathSegment) {
        throw new QueryException("'@' path segment cannot be used in the context of an entity " + this);
    }
    JpaLinkDefinition<?> link = findRawLinkDefinition(path, JpaDataNodeDefinition.class, false);
    if (link == null) {
        return null;
    } else {
        link.resolveEntityPointer();
        return new DataSearchResult<>(link, path.tail(link.getItemPath().size()));
    }
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) DataSearchResult(com.evolveum.midpoint.repo.sql.query2.resolution.DataSearchResult) ObjectReferencePathSegment(com.evolveum.midpoint.prism.path.ObjectReferencePathSegment)

Example 9 with ItemPathSegment

use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.

the class WebComponentUtil method joinPath.

public static ItemPath joinPath(ItemPath path, ItemPath deltaPath) {
    List<ItemPathSegment> newPath = new ArrayList<ItemPathSegment>();
    ItemPathSegment firstDeltaSegment = deltaPath != null ? deltaPath.first() : null;
    if (path != null) {
        for (ItemPathSegment seg : path.getSegments()) {
            if (seg.equivalent(firstDeltaSegment)) {
                break;
            }
            newPath.add(seg);
        }
    }
    if (deltaPath != null) {
        newPath.addAll(deltaPath.getSegments());
    }
    return new ItemPath(newPath);
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 10 with ItemPathSegment

use of com.evolveum.midpoint.prism.path.ItemPathSegment in project midpoint by Evolveum.

the class ObjectWrapperFactory method createPropertyPath.

private ItemPath createPropertyPath(ItemPath path, QName element) {
    List<ItemPathSegment> segments = new ArrayList<>();
    segments.addAll(path.getSegments());
    segments.add(new NameItemPathSegment(element));
    return new ItemPath(segments);
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemPathSegment (com.evolveum.midpoint.prism.path.ItemPathSegment)20 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)16 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)8 QName (javax.xml.namespace.QName)8 ObjectReferencePathSegment (com.evolveum.midpoint.prism.path.ObjectReferencePathSegment)3 ParentPathSegment (com.evolveum.midpoint.prism.path.ParentPathSegment)3 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)2 Item (com.evolveum.midpoint.prism.Item)1 PrismValueDeltaSetTriple (com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 ItemDeltaItem (com.evolveum.midpoint.repo.common.expression.ItemDeltaItem)1 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)1 DataSearchResult (com.evolveum.midpoint.repo.sql.query2.resolution.DataSearchResult)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1