Search in sources :

Example 1 with ObjectReferencePathSegment

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

the class PrismReferenceDefinitionImpl method findItemDefinition.

@Override
public <T extends ItemDefinition> T findItemDefinition(@NotNull ItemPath path, @NotNull Class<T> clazz) {
    if (path.isEmpty() || !(path.first() instanceof ObjectReferencePathSegment)) {
        return super.findItemDefinition(path, clazz);
    } else {
        ItemPath rest = path.rest();
        PrismObjectDefinition referencedObjectDefinition = getSchemaRegistry().determineReferencedObjectDefinition(targetTypeName, rest);
        return (T) referencedObjectDefinition.findItemDefinition(rest, clazz);
    }
}
Also used : ObjectReferencePathSegment(com.evolveum.midpoint.prism.path.ObjectReferencePathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with ObjectReferencePathSegment

use of com.evolveum.midpoint.prism.path.ObjectReferencePathSegment 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 3 with ObjectReferencePathSegment

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

the class ComplexTypeDefinitionImpl method findItemDefinition.

@Override
public <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path, @NotNull Class<ID> clazz) {
    for (; ; ) {
        if (path.isEmpty()) {
            throw new IllegalArgumentException("Cannot resolve empty path on complex type definition " + this);
        }
        ItemPathSegment first = path.first();
        if (first instanceof NameItemPathSegment) {
            QName firstName = ((NameItemPathSegment) first).getName();
            return findNamedItemDefinition(firstName, path.rest(), clazz);
        } else if (first instanceof IdItemPathSegment) {
            path = path.rest();
        } else if (first instanceof ParentPathSegment) {
            ItemPath rest = path.rest();
            ComplexTypeDefinition parent = getSchemaRegistry().determineParentDefinition(this, rest);
            if (rest.isEmpty()) {
                // requires that the parent is defined as an item (container, object)
                return (ID) getSchemaRegistry().findItemDefinitionByType(parent.getTypeName());
            } else {
                return parent.findItemDefinition(rest, clazz);
            }
        } else if (first instanceof ObjectReferencePathSegment) {
            throw new IllegalStateException("Couldn't use '@' path segment in this context. CTD=" + getTypeName() + ", path=" + path);
        } else {
            throw new IllegalStateException("Unexpected path segment: " + first + " in " + path);
        }
    }
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ParentPathSegment(com.evolveum.midpoint.prism.path.ParentPathSegment) QName(javax.xml.namespace.QName) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ObjectReferencePathSegment(com.evolveum.midpoint.prism.path.ObjectReferencePathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 4 with ObjectReferencePathSegment

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

the class PrismContainerDefinitionImpl method findItemDefinition.

public <ID extends ItemDefinition> ID findItemDefinition(@NotNull ItemPath path, @NotNull Class<ID> clazz) {
    for (; ; ) {
        if (path.isEmpty()) {
            if (clazz.isAssignableFrom(PrismContainerDefinition.class)) {
                return (ID) this;
            } else {
                return null;
            }
        }
        ItemPathSegment first = path.first();
        if (first instanceof NameItemPathSegment) {
            QName firstName = ((NameItemPathSegment) first).getName();
            return findNamedItemDefinition(firstName, path.rest(), clazz);
        } else if (first instanceof IdItemPathSegment) {
            path = path.rest();
        } else if (first instanceof ParentPathSegment) {
            ItemPath rest = path.rest();
            ComplexTypeDefinition parent = getSchemaRegistry().determineParentDefinition(getComplexTypeDefinition(), rest);
            if (rest.isEmpty()) {
                // requires that the parent is defined as an item (container, object)
                return (ID) getSchemaRegistry().findItemDefinitionByType(parent.getTypeName());
            } else {
                return parent.findItemDefinition(rest, clazz);
            }
        } else if (first instanceof ObjectReferencePathSegment) {
            throw new IllegalStateException("Couldn't use '@' path segment in this context. PCD=" + getTypeName() + ", path=" + path);
        } else {
            throw new IllegalStateException("Unexpected path segment: " + first + " in " + path);
        }
    }
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ParentPathSegment(com.evolveum.midpoint.prism.path.ParentPathSegment) QName(javax.xml.namespace.QName) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ObjectReferencePathSegment(com.evolveum.midpoint.prism.path.ObjectReferencePathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ObjectReferencePathSegment (com.evolveum.midpoint.prism.path.ObjectReferencePathSegment)4 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)3 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 ItemPathSegment (com.evolveum.midpoint.prism.path.ItemPathSegment)3 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)2 ParentPathSegment (com.evolveum.midpoint.prism.path.ParentPathSegment)2 QName (javax.xml.namespace.QName)2 QueryException (com.evolveum.midpoint.repo.sql.query.QueryException)1 DataSearchResult (com.evolveum.midpoint.repo.sql.query2.resolution.DataSearchResult)1