Search in sources :

Example 21 with IdItemPathSegment

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

the class PrismContainer method removeItem.

public <IV extends PrismValue, ID extends ItemDefinition, I extends Item<IV, ID>> void removeItem(ItemPath path, Class<I> itemType) {
    IdItemPathSegment idSegment = ItemPath.getFirstIdSegment(path);
    PrismContainerValue<C> cval = findValue(idSegment);
    if (cval == null) {
        return;
    }
    cval.removeItem(ItemPath.pathRestStartingWithName(path.rest()), itemType);
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment)

Example 22 with IdItemPathSegment

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

the class PrismContainer method findCreateItem.

<IV extends PrismValue, ID extends ItemDefinition, I extends Item<IV, ID>> I findCreateItem(ItemPath itemPath, Class<I> type, ID itemDefinition, boolean create) throws SchemaException {
    if (itemPath == null || itemPath.isEmpty()) {
        throw new IllegalArgumentException("Empty path specified");
    }
    IdItemPathSegment idSegment = ItemPath.getFirstIdSegment(itemPath);
    PrismContainerValue<C> cval = findValue(idSegment);
    if (cval == null) {
        return null;
    }
    // descent to the correct value
    ItemPath rest = ItemPath.pathRestStartingWithName(itemPath);
    return cval.findCreateItem(rest, type, itemDefinition, create);
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 23 with IdItemPathSegment

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

the class PrismContainer method accept.

@Override
public void accept(Visitor visitor, ItemPath path, boolean recursive) {
    if (path == null || path.isEmpty()) {
        // We are at the end of path, continue with regular visits all the way to the bottom
        if (recursive) {
            accept(visitor);
        } else {
            visitor.visit(this);
        }
    } else {
        IdItemPathSegment idSegment = ItemPath.getFirstIdSegment(path);
        ItemPath rest = ItemPath.pathRestStartingWithName(path);
        if (idSegment == null || idSegment.isWildcard()) {
            // visit all values
            for (PrismContainerValue<C> cval : getValues()) {
                cval.accept(visitor, rest, recursive);
            }
        } else {
            PrismContainerValue<C> cval = findValue(idSegment);
            if (cval != null) {
                cval.accept(visitor, rest, recursive);
            }
        }
    }
}
Also used : IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 24 with IdItemPathSegment

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

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

IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)35 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)30 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)27 Test (org.testng.annotations.Test)17 QName (javax.xml.namespace.QName)8 UserType (com.evolveum.midpoint.prism.foo.UserType)6 ItemPathSegment (com.evolveum.midpoint.prism.path.ItemPathSegment)6 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)5 AssignmentType (com.evolveum.midpoint.prism.foo.AssignmentType)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)3 ObjectReferencePathSegment (com.evolveum.midpoint.prism.path.ObjectReferencePathSegment)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)2 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)2 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)2