Search in sources :

Example 1 with DataItem

use of com.evolveum.midpoint.model.impl.dataModel.model.DataItem in project midpoint by Evolveum.

the class DataModelVisualizerImpl method processInboundMapping.

private void processInboundMapping(@NotNull DataModel model, @NotNull ResourceDataItem sourceItem, @NotNull MappingType mapping, @Nullable ItemPath defaultTargetItemPath) {
    LOGGER.debug("Processing inbound mapping: {} for {}", mapping, sourceItem);
    List<DataItem> sources = new ArrayList<>();
    for (VariableBindingDefinitionType sourceDecl : mapping.getSource()) {
        LOGGER.debug(" - src: {}", sourceDecl.getPath());
        DataItem explicitSourceItem = resolveSourceItem(model, sourceItem, mapping, sourceDecl, null);
        sources.add(explicitSourceItem);
    }
    if (!sources.contains(sourceItem)) {
        sources.add(sourceItem);
    }
    DataItem targetItem = null;
    VariableBindingDefinitionType targetDecl = mapping.getTarget();
    if (mapping.getTarget() != null) {
        LOGGER.debug(" - target: {}", targetDecl.getPath());
        targetItem = resolveTargetItem(model, sourceItem, mapping, targetDecl, ExpressionConstants.VAR_FOCUS);
    } else if (defaultTargetItemPath != null) {
        targetItem = resolveTargetItem(model, sourceItem, mapping, defaultTargetItemPath, ExpressionConstants.VAR_FOCUS);
    }
    model.registerMappingRelation(sources, targetItem, mapping);
}
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) ArrayList(java.util.ArrayList)

Example 2 with DataItem

use of com.evolveum.midpoint.model.impl.dataModel.model.DataItem 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 3 with DataItem

use of com.evolveum.midpoint.model.impl.dataModel.model.DataItem in project midpoint by Evolveum.

the class DataModelVisualizerImpl method processOutboundMapping.

private void processOutboundMapping(@NotNull DataModel model, @NotNull ResourceDataItem targetItem, @NotNull MappingType mapping, @Nullable ItemPath defaultSourceItemPath) {
    LOGGER.debug("Processing outbound mapping: {} for {}", mapping, targetItem);
    List<DataItem> sources = new ArrayList<>();
    for (VariableBindingDefinitionType sourceDecl : mapping.getSource()) {
        LOGGER.debug(" - src: {}", sourceDecl.getPath());
        DataItem sourceItem = resolveSourceItem(model, targetItem, mapping, sourceDecl, ExpressionConstants.VAR_FOCUS);
        sources.add(sourceItem);
    }
    if (defaultSourceItemPath != null) {
        DataItem defaultSource = resolveSourceItem(model, targetItem, mapping, defaultSourceItemPath, ExpressionConstants.VAR_FOCUS);
        if (!sources.contains(defaultSource)) {
            sources.add(defaultSource);
        }
    }
    VariableBindingDefinitionType targetDecl = mapping.getTarget();
    if (targetDecl != null) {
        LOGGER.warn(" - ignoring target (mapping is outbound): {}; using {} instead", targetDecl.getPath(), targetItem);
    }
    model.registerMappingRelation(sources, targetItem, mapping);
}
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) ArrayList(java.util.ArrayList)

Example 4 with DataItem

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

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