Search in sources :

Example 6 with ResourceDataItem

use of com.evolveum.midpoint.model.impl.dataModel.model.ResourceDataItem 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)

Aggregations

ResourceDataItem (com.evolveum.midpoint.model.impl.dataModel.model.ResourceDataItem)6 AdHocDataItem (com.evolveum.midpoint.model.impl.dataModel.model.AdHocDataItem)4 DataItem (com.evolveum.midpoint.model.impl.dataModel.model.DataItem)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 QName (javax.xml.namespace.QName)3 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)2 ArrayList (java.util.ArrayList)2 NotNull (org.jetbrains.annotations.NotNull)2 ResourceSchema (com.evolveum.midpoint.schema.processor.ResourceSchema)1