Search in sources :

Example 11 with ItemPathSegment

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

the class ModificationDto method getItemName.

private static String getItemName(ItemDelta delta) {
    if (delta.getDefinition() != null) {
        if (delta.getDefinition().getDisplayName() != null) {
            return delta.getDefinition().getDisplayName();
        }
        if (delta.getDefinition().getName() != null) {
            return delta.getDefinition().getName().getLocalPart();
        }
    }
    ItemPath path = delta.getPath();
    for (int i = path.getSegments().size() - 1; i >= 0; i--) {
        if (path.getSegments().get(i) instanceof NameItemPathSegment) {
            String retval = ((NameItemPathSegment) path.getSegments().get(i)).getName().getLocalPart();
            i++;
            while (i < path.getSegments().size()) {
                ItemPathSegment itemPathSegment = path.getSegments().get(i);
                if (itemPathSegment instanceof IdItemPathSegment) {
                    // should always be the case
                    retval += "[" + ((IdItemPathSegment) itemPathSegment).getId() + "]";
                }
            }
            return retval;
        }
    }
    // this means there's some problem there
    return delta.toString();
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 12 with ItemPathSegment

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

use of com.evolveum.midpoint.prism.path.ItemPathSegment 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)

Example 14 with ItemPathSegment

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

the class ShadowUtil method getAttributeName.

public static QName getAttributeName(ItemPath attributePath, String message) throws SchemaException {
    if (attributePath == null || attributePath.isEmpty()) {
        return null;
    }
    ItemPathSegment firstPathSegment = attributePath.first();
    if (!(firstPathSegment instanceof NameItemPathSegment)) {
        throw new SchemaException(message + ": first path segment is not a name segment");
    }
    if (!QNameUtil.match(ShadowType.F_ATTRIBUTES, ((NameItemPathSegment) firstPathSegment).getName())) {
        throw new SchemaException(message + ": first path segment is not " + ShadowType.F_ATTRIBUTES);
    }
    if (attributePath.size() < 1) {
        throw new SchemaException(message + ": path too short (" + attributePath.size() + " segments)");
    }
    if (attributePath.size() > 2) {
        throw new SchemaException(message + ": path too long (" + attributePath.size() + " segments)");
    }
    ItemPathSegment secondPathSegment = attributePath.getSegments().get(1);
    if (!(secondPathSegment instanceof NameItemPathSegment)) {
        throw new SchemaException(message + ": second path segment is not a name segment");
    }
    return ((NameItemPathSegment) secondPathSegment).getName();
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment)

Example 15 with ItemPathSegment

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

the class TextFormatter method getItemPathLabel.

private String getItemPathLabel(ItemPath path, Definition deltaDefinition, PrismObjectDefinition objectDefinition) {
    NameItemPathSegment lastNamedSegment = path.lastNamed();
    StringBuilder sb = new StringBuilder();
    for (ItemPathSegment segment : path.getSegments()) {
        if (segment instanceof NameItemPathSegment) {
            if (sb.length() > 0) {
                sb.append("/");
            }
            Definition itemDefinition;
            if (objectDefinition == null) {
                if (segment == lastNamedSegment) {
                    // definition for last segment is the definition taken from delta
                    // this may be null but we don't care
                    itemDefinition = deltaDefinition;
                } else {
                    // definitions for previous segments are unknown
                    itemDefinition = null;
                }
            } else {
                // todo we could make this iterative (resolving definitions while walking down the path); but this is definitely simpler to implement and debug :)
                itemDefinition = objectDefinition.findItemDefinition(path.allUpToIncluding(segment));
            }
            if (itemDefinition != null && itemDefinition.getDisplayName() != null) {
                sb.append(resolve(itemDefinition.getDisplayName()));
            } else {
                sb.append(((NameItemPathSegment) segment).getName().getLocalPart());
            }
        } else if (segment instanceof IdItemPathSegment) {
            sb.append("[").append(((IdItemPathSegment) segment).getId()).append("]");
        }
    }
    return sb.toString();
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment)

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