Search in sources :

Example 36 with NameItemPathSegment

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

the class EntityDefinition method findDefinition.

@Override
public <D extends Definition> D findDefinition(ItemPath path, Class<D> type) {
    if (path == null || path.isEmpty()) {
        if (type.isAssignableFrom(EntityDefinition.class)) {
            return (D) this;
        }
    }
    NameItemPathSegment first = (NameItemPathSegment) path.first();
    ItemPath tail = path.tail();
    if (ObjectType.F_METADATA.equals(first.getName())) {
        //metadata is not an repository entity
        first = (NameItemPathSegment) tail.first();
        tail = tail.tail();
    } else if (QNameUtil.match(AssignmentType.F_CONSTRUCTION, first.getName()) && tail != null && tail.first() instanceof NameItemPathSegment && QNameUtil.match(ConstructionType.F_RESOURCE_REF, ((NameItemPathSegment) (tail.first())).getName())) {
        // ugly hack: construction/resourceRef -> resourceRef
        first = (NameItemPathSegment) tail.first();
        tail = tail.tail();
    }
    if (tail.isEmpty()) {
        return findDefinition(first.getName(), type);
    } else {
        Definition def = findDefinition(first.getName(), Definition.class);
        if (def instanceof CollectionDefinition) {
            CollectionDefinition collDef = (CollectionDefinition) def;
            def = collDef.getDefinition();
        }
        if (def instanceof EntityDefinition) {
            EntityDefinition nextEntity = (EntityDefinition) def;
            return nextEntity.findDefinition(tail, type);
        }
    }
    return null;
}
Also used : NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 37 with NameItemPathSegment

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

Example 38 with NameItemPathSegment

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

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

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

NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)69 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)61 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)46 Test (org.testng.annotations.Test)35 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)22 QName (javax.xml.namespace.QName)20 Task (com.evolveum.midpoint.task.api.Task)19 ItemPathSegment (com.evolveum.midpoint.prism.path.ItemPathSegment)15 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)14 TestTriggerTask (com.evolveum.midpoint.model.intest.TestTriggerTask)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)10 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)10 UserType (com.evolveum.midpoint.prism.foo.UserType)7 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)7 AssignmentType (com.evolveum.midpoint.prism.foo.AssignmentType)6 MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)6 RoleType (com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType)6 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)5 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)4