Search in sources :

Example 61 with NameItemPathSegment

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

the class AbstractSearchExpressionEvaluator method evaluatePopulateExpression.

private <IV extends PrismValue, ID extends ItemDefinition, C extends Containerable> ItemDelta<IV, ID> evaluatePopulateExpression(PopulateItemType populateItem, ExpressionVariables variables, ExpressionEvaluationContext params, PrismContainerDefinition<C> objectDefinition, String contextDescription, boolean evaluateMinus, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    ExpressionType expressionType = populateItem.getExpression();
    if (expressionType == null) {
        LOGGER.warn("No expression in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
        return null;
    }
    VariableBindingDefinitionType targetType = populateItem.getTarget();
    if (targetType == null) {
        LOGGER.warn("No target in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
        return null;
    }
    ItemPathType itemPathType = targetType.getPath();
    if (itemPathType == null) {
        throw new SchemaException("No path in target definition in " + contextDescription);
    }
    ItemPath targetPath = itemPathType.getItemPath();
    ID propOutputDefinition = ExpressionUtil.resolveDefinitionPath(targetPath, variables, objectDefinition, "target definition in " + contextDescription);
    if (propOutputDefinition == null) {
        throw new SchemaException("No target item that would conform to the path " + targetPath + " in " + contextDescription);
    }
    String expressionDesc = "expression in assignment expression in " + contextDescription;
    ExpressionFactory expressionFactory = params.getExpressionFactory();
    Expression<IV, ID> expression = expressionFactory.makeExpression(expressionType, propOutputDefinition, expressionDesc, task, result);
    ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, expressionDesc, task, result);
    context.setExpressionFactory(expressionFactory);
    context.setStringPolicyResolver(params.getStringPolicyResolver());
    context.setDefaultTargetContext(params.getDefaultTargetContext());
    context.setSkipEvaluationMinus(true);
    context.setSkipEvaluationPlus(false);
    PrismValueDeltaSetTriple<IV> outputTriple = expression.evaluate(context);
    LOGGER.trace("output triple: {}", outputTriple.debugDump());
    Collection<IV> pvalues = outputTriple.getNonNegativeValues();
    // Maybe not really clean but it works. TODO: refactor later
    NameItemPathSegment first = (NameItemPathSegment) targetPath.first();
    if (first.isVariable()) {
        targetPath = targetPath.rest();
    }
    ItemDelta<IV, ID> itemDelta = propOutputDefinition.createEmptyDelta(targetPath);
    itemDelta.addValuesToAdd(PrismValue.cloneCollection(pvalues));
    LOGGER.trace("Item delta:\n{}", itemDelta.debugDump());
    return itemDelta;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) VariableBindingDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 62 with NameItemPathSegment

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

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

the class DataModelVisualizerImpl method resolveSourceItem.

// for outbound (but sometimes also inbound) mappings
@NotNull
private DataItem resolveSourceItem(@NotNull DataModel model, @NotNull ResourceDataItem currentItem, @NotNull MappingType mapping, @NotNull ItemPath path, @Nullable QName defaultVariable) {
    if (!(path.first() instanceof NameItemPathSegment)) {
        LOGGER.warn("Probably incorrect path ({}) - does not start with a name - skipping", path);
        return createAdHocDataItem(model, path);
    }
    QName varName;
    ItemPath itemPath;
    NameItemPathSegment firstNameSegment = (NameItemPathSegment) path.first();
    if (firstNameSegment.isVariable()) {
        varName = firstNameSegment.getName();
        itemPath = path.tail();
    } else {
        if (defaultVariable == null) {
            LOGGER.warn("No default variable for mapping source");
            return createAdHocDataItem(model, path);
        }
        varName = defaultVariable;
        itemPath = path;
    }
    if (QNameUtil.match(ExpressionConstants.VAR_ACCOUNT, varName)) {
        return resolveResourceItem(model, currentItem, itemPath);
    } else if (QNameUtil.match(ExpressionConstants.VAR_USER, varName)) {
        return model.resolveRepositoryItem(UserType.class, itemPath);
    } else if (QNameUtil.match(ExpressionConstants.VAR_ACTOR, varName)) {
        // TODO
        return model.resolveRepositoryItem(UserType.class, itemPath);
    } else if (QNameUtil.match(ExpressionConstants.VAR_FOCUS, varName)) {
        Class<? extends ObjectType> guessedClass = guessFocusClass(currentItem.getResourceOid(), currentItem.getKind(), currentItem.getIntent());
        DataItem item = model.resolveRepositoryItem(guessedClass, itemPath);
        if (item != null) {
            return item;
        }
        // TODO guess e.g. by item existence in schema
        LOGGER.warn("Couldn't resolve {} in $focus", path);
    } else if (QNameUtil.match(ExpressionConstants.VAR_INPUT, varName)) {
        return currentItem;
    } else {
        LOGGER.warn("Unsupported variable {} in {}", varName, path);
    }
    return createAdHocDataItem(model, path);
}
Also used : AdHocDataItem(com.evolveum.midpoint.model.impl.dataModel.model.AdHocDataItem) ResourceDataItem(com.evolveum.midpoint.model.impl.dataModel.model.ResourceDataItem) DataItem(com.evolveum.midpoint.model.impl.dataModel.model.DataItem) QName(javax.xml.namespace.QName) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) NotNull(org.jetbrains.annotations.NotNull)

Example 64 with NameItemPathSegment

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

the class DataModelVisualizerImpl method resolveTargetItem.

// currently for inbounds only
@NotNull
private DataItem resolveTargetItem(@NotNull DataModel model, @NotNull ResourceDataItem currentItem, @NotNull MappingType mapping, @NotNull ItemPath path, @Nullable QName defaultVariable) {
    if (!(path.first() instanceof NameItemPathSegment)) {
        LOGGER.warn("Probably incorrect path ({}) - does not start with a name - skipping", path);
        return createAdHocDataItem(model, path);
    }
    QName varName;
    ItemPath itemPath;
    NameItemPathSegment firstNameSegment = (NameItemPathSegment) path.first();
    if (firstNameSegment.isVariable()) {
        varName = firstNameSegment.getName();
        itemPath = path.tail();
    } else {
        if (defaultVariable == null) {
            LOGGER.warn("No default variable for mapping target");
            return createAdHocDataItem(model, path);
        }
        varName = defaultVariable;
        itemPath = path;
    }
    if (QNameUtil.match(ExpressionConstants.VAR_ACCOUNT, varName)) {
        // does make sense?
        return resolveResourceItem(model, currentItem, itemPath);
    } else if (QNameUtil.match(ExpressionConstants.VAR_USER, varName)) {
        return model.resolveRepositoryItem(UserType.class, itemPath);
    } else if (QNameUtil.match(ExpressionConstants.VAR_ACTOR, varName)) {
        // TODO
        return model.resolveRepositoryItem(UserType.class, itemPath);
    } else if (QNameUtil.match(ExpressionConstants.VAR_FOCUS, varName)) {
        Class<? extends ObjectType> guessedClass = guessFocusClass(currentItem.getResourceOid(), currentItem.getKind(), currentItem.getIntent());
        DataItem item = model.resolveRepositoryItem(guessedClass, itemPath);
        if (item != null) {
            return item;
        }
        // TODO guess e.g. by item existence in schema
        LOGGER.warn("Couldn't resolve {} in $focus", path);
    } else if (QNameUtil.match(ExpressionConstants.VAR_INPUT, varName)) {
        // does make sense?
        return currentItem;
    } else {
        LOGGER.warn("Unsupported variable {} in {}", varName, path);
    }
    return createAdHocDataItem(model, path);
}
Also used : AdHocDataItem(com.evolveum.midpoint.model.impl.dataModel.model.AdHocDataItem) ResourceDataItem(com.evolveum.midpoint.model.impl.dataModel.model.ResourceDataItem) DataItem(com.evolveum.midpoint.model.impl.dataModel.model.DataItem) QName(javax.xml.namespace.QName) NameItemPathSegment(com.evolveum.midpoint.prism.path.NameItemPathSegment) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) NotNull(org.jetbrains.annotations.NotNull)

Example 65 with NameItemPathSegment

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

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