Search in sources :

Example 16 with ItemPathSegment

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

the class TestPath method assertNormalizedPath.

private void assertNormalizedPath(ItemPath normalized, Object... expected) {
    assertEquals("wrong path length", normalized.size(), expected.length);
    for (int i = 0; i < normalized.size(); i += 2) {
        ItemPathSegment nameSegment = normalized.getSegments().get(i);
        assert nameSegment instanceof NameItemPathSegment : "Expected name segment but it was " + nameSegment.getClass();
        QName name = ((NameItemPathSegment) nameSegment).getName();
        assert name != null : "name is null";
        assert name.getNamespaceURI().equals(NS) : "wrong namespace: " + name.getNamespaceURI();
        assert name.getLocalPart().equals(expected[i]) : "wrong local name, expected " + expected[i] + ", was " + name.getLocalPart();
        if (i + 1 < expected.length) {
            ItemPathSegment idSegment = normalized.getSegments().get(i + 1);
            assert idSegment instanceof IdItemPathSegment : "Expected is segment but it was " + nameSegment.getClass();
            Long id = ((IdItemPathSegment) idSegment).getId();
            assertId(id, (Long) expected[i + 1]);
        }
    }
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) QName(javax.xml.namespace.QName) IdItemPathSegment(com.evolveum.midpoint.prism.path.IdItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment)

Example 17 with ItemPathSegment

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

the class GeneralNotifier method formatPath.

private String formatPath(ItemDelta itemDelta) {
    if (itemDelta.getDefinition() != null && itemDelta.getDefinition().getDisplayName() != null) {
        return itemDelta.getDefinition().getDisplayName();
    }
    StringBuilder sb = new StringBuilder();
    for (ItemPathSegment itemPathSegment : itemDelta.getPath().getSegments()) {
        if (itemPathSegment instanceof NameItemPathSegment) {
            NameItemPathSegment nameItemPathSegment = (NameItemPathSegment) itemPathSegment;
            if (sb.length() > 0) {
                sb.append("/");
            }
            sb.append(nameItemPathSegment.getName().getLocalPart());
        }
    }
    return sb.toString();
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment)

Example 18 with ItemPathSegment

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

the class SelectorOptions method isPathInSelected.

private static boolean isPathInSelected(ItemPath path, ItemPath selected) {
    if (selected == null || path == null) {
        return false;
    }
    if (path.isEmpty()) {
        if (selected.isEmpty()) {
            return true;
        }
    } else {
        List<ItemPathSegment> pSegments = path.getSegments();
        List<ItemPathSegment> sSegments = selected.getSegments();
        for (int i = 0; i < pSegments.size(); i++) {
            if (sSegments.size() <= i) {
                return true;
            }
            NameItemPathSegment pSegment = (NameItemPathSegment) pSegments.get(i);
            NameItemPathSegment sSegment = (NameItemPathSegment) sSegments.get(i);
            if (!pSegment.equivalent(sSegment)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment)

Example 19 with ItemPathSegment

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

the class ObjectValuePolicyEvaluator method preparePassword.

private void preparePassword() {
    if (!QNameUtil.match(UserType.F_CREDENTIALS, valueItemPath.getFirstName())) {
        return;
    }
    ItemPathSegment secondPathSegment = valueItemPath.getSegments().get(1);
    if (!(secondPathSegment instanceof NameItemPathSegment)) {
        return;
    }
    credentialQName = ((NameItemPathSegment) secondPathSegment).getName();
    if (!QNameUtil.match(CredentialsType.F_PASSWORD, credentialQName)) {
        return;
    }
    credentialPolicy = SecurityUtil.getEffectivePasswordCredentialsPolicy(securityPolicy);
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment)

Example 20 with ItemPathSegment

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

the class ModelController method resolve.

// TODO clean this mess
private <O extends ObjectType> void resolve(Containerable containerable, ItemPath path, SelectorOptions<GetOperationOptions> option, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, SecurityViolationException, ConfigurationException {
    if (path == null || path.isEmpty()) {
        return;
    }
    ItemPathSegment first = path.first();
    ItemPath rest = path.rest();
    PrismContainerValue<?> containerValue = containerable.asPrismContainerValue();
    if (first instanceof NameItemPathSegment) {
        QName refName = ItemPath.getName(first);
        PrismReference reference = containerValue.findReferenceByCompositeObjectElementName(refName);
        if (reference == null) {
            // alternatively look up by reference name (e.g. linkRef)
            reference = containerValue.findReference(refName);
        }
        if (reference != null) {
            for (PrismReferenceValue refVal : reference.getValues()) {
                PrismObject<O> refObject = refVal.getObject();
                if (refObject == null) {
                    refObject = objectResolver.resolve(refVal, containerable.toString(), option.getOptions(), task, result);
                    refObject = refObject.cloneIfImmutable();
                    schemaTransformer.applySchemasAndSecurity(refObject, option.getOptions(), null, task, result);
                    refVal.setObject(refObject);
                }
                if (!rest.isEmpty()) {
                    resolve(refObject.asObjectable(), rest, option, task, result);
                }
            }
            return;
        }
    }
    if (rest.isEmpty()) {
        return;
    }
    if (first instanceof ParentPathSegment) {
        PrismContainerValue<?> parent = containerValue.getParentContainerValue();
        if (parent != null) {
            resolve(parent.asContainerable(), rest, option, task, result);
        }
    } else {
        QName nextName = ItemPath.getName(first);
        PrismContainer<?> nextContainer = containerValue.findContainer(nextName);
        if (nextContainer != null) {
            for (PrismContainerValue<?> pcv : nextContainer.getValues()) {
                resolve(pcv.asContainerable(), rest, option, task, result);
            }
        }
    }
}
Also used : ItemPathSegment(com.evolveum.midpoint.prism.path.ItemPathSegment) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ParentPathSegment(com.evolveum.midpoint.prism.path.ParentPathSegment) QName(javax.xml.namespace.QName) 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