Search in sources :

Example 1 with ResourceDataItem

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

the class DataModelVisualizerImpl method createDataItems.

private void createDataItems(DataModel model, List<PrismObject<ResourceType>> resources) throws SchemaException {
    LOGGER.debug("createDataItems starting");
    for (PrismObject<ResourceType> resource : resources) {
        final ResourceSchema resourceSchema = RefinedResourceSchemaImpl.getResourceSchema(resource, prismContext);
        if (resourceSchema == null) {
            LOGGER.debug("Resource schema is null, skipping the resource.");
            continue;
        }
        RefinedResourceSchema refinedResourceSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
        if (refinedResourceSchema == null) {
            // actually shouldn't be null if resource schema exists
            LOGGER.debug("Refined resource schema is null, skipping the resource.");
            continue;
        }
        model.registerResource(resource);
        List<? extends RefinedObjectClassDefinition> refinedDefinitions = refinedResourceSchema.getRefinedDefinitions();
        for (RefinedObjectClassDefinition refinedDefinition : refinedDefinitions) {
            LOGGER.debug("Processing refined definition {} in {}", refinedDefinition, resource);
            Collection<? extends RefinedAttributeDefinition<?>> attributeDefinitions = refinedDefinition.getAttributeDefinitions();
            //Collection<? extends ResourceAttributeDefinition> rawAttributeDefinitions = refinedDefinition.getObjectClassDefinition().getAttributeDefinitions();
            final ShadowKindType kind = def(refinedDefinition.getKind());
            final String intent = def(refinedDefinition.getIntent());
            for (RefinedAttributeDefinition<?> attributeDefinition : attributeDefinitions) {
                if (attributeDefinition.isIgnored()) {
                    continue;
                }
                LOGGER.debug("Registering refined attribute definition for {}", attributeDefinition.getName());
                ResourceDataItem attrItem = new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, attributeDefinition.getName());
                attrItem.setRefinedAttributeDefinition(attributeDefinition);
                // TODO check the name
                model.registerDataItem(attrItem);
            }
            // TODO check attributes not mentioned in schema handling
            Collection<RefinedAssociationDefinition> associationDefinitions = refinedDefinition.getAssociationDefinitions();
            for (RefinedAssociationDefinition associationDefinition : associationDefinitions) {
                if (associationDefinition.isIgnored()) {
                    continue;
                }
                LOGGER.debug("Registering refined association definition for {}", associationDefinition.getName());
                ResourceDataItem assocItem = new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, associationDefinition.getName());
                model.registerDataItem(assocItem);
            }
            model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS)));
            model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS)));
            model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_FROM)));
            model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ActivationType.F_VALID_TO)));
            model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_ACTIVATION, ACTIVATION_EXISTENCE)));
            model.registerDataItem(new ResourceDataItem(model, resource.getOid(), kind, intent, refinedResourceSchema, refinedDefinition, new ItemPath(ShadowType.F_CREDENTIALS, CredentialsType.F_PASSWORD)));
        }
    }
    //		createRepoDataItems(UserType.class);
    //		createRepoDataItems(RoleType.class);
    //		createRepoDataItems(OrgType.class);
    //		createRepoDataItems(ServiceType.class);
    LOGGER.debug("createDataItems finished");
}
Also used : ResourceSchema(com.evolveum.midpoint.schema.processor.ResourceSchema) ResourceDataItem(com.evolveum.midpoint.model.impl.dataModel.model.ResourceDataItem) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with ResourceDataItem

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

the class DataModelVisualizerImpl method processResourceMappings.

private void processResourceMappings(DataModel model, List<PrismObject<ResourceType>> resources) throws SchemaException {
    for (PrismObject<ResourceType> resource : resources) {
        LOGGER.debug("Processing {}", ObjectTypeUtil.toShortString(resource));
        RefinedResourceSchema refinedResourceSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
        if (refinedResourceSchema == null) {
            LOGGER.debug("Refined resource schema is null, skipping the resource.");
            continue;
        }
        List<? extends RefinedObjectClassDefinition> refinedDefinitions = refinedResourceSchema.getRefinedDefinitions();
        for (RefinedObjectClassDefinition refinedDefinition : refinedDefinitions) {
            LOGGER.debug("Processing refined definition {}", refinedDefinition);
            Collection<? extends RefinedAttributeDefinition<?>> attributeDefinitions = refinedDefinition.getAttributeDefinitions();
            final ShadowKindType kind = def(refinedDefinition.getKind());
            final String intent = def(refinedDefinition.getIntent());
            for (RefinedAttributeDefinition<?> attributeDefinition : attributeDefinitions) {
                if (attributeDefinition.isIgnored()) {
                    continue;
                }
                LOGGER.debug("Processing refined attribute definition for {}", attributeDefinition.getName());
                ResourceDataItem attrItem = model.findResourceItem(resource.getOid(), kind, intent, getObjectClassName(refinedDefinition), new ItemPath(attributeDefinition.getName()));
                if (attributeDefinition.getOutboundMappingType() != null) {
                    processOutboundMapping(model, attrItem, attributeDefinition.getOutboundMappingType(), null);
                }
                processInboundMappings(model, attrItem, attributeDefinition.getInboundMappingTypes());
            }
            Collection<RefinedAssociationDefinition> associationDefinitions = refinedDefinition.getAssociationDefinitions();
            for (RefinedAssociationDefinition associationDefinition : associationDefinitions) {
                if (associationDefinition.isIgnored()) {
                    continue;
                }
                LOGGER.debug("Processing refined association definition for {}", associationDefinition.getName());
                ResourceDataItem assocItem = model.findResourceItem(resource.getOid(), kind, intent, getObjectClassName(refinedDefinition), new ItemPath(associationDefinition.getName()));
                if (associationDefinition.getOutboundMappingType() != null) {
                    processOutboundMapping(model, assocItem, associationDefinition.getOutboundMappingType(), null);
                }
            //					if (associationDefinition.getAssociationTarget() != null) {
            //						RefinedObjectClassDefinition target = associationDefinition.getAssociationTarget();
            //						boolean objectToSubject = associationDefinition.getResourceObjectAssociationType().getDirection() == ResourceObjectAssociationDirectionType.OBJECT_TO_SUBJECT;
            //						associationDefinition.getResourceObjectAssociationType().getAssociationAttribute()
            //					}
            }
            ResourceActivationDefinitionType actMapping = refinedDefinition.getActivationSchemaHandling();
            if (actMapping != null) {
                QName objectClassName = getObjectClassName(refinedDefinition);
                processBidirectionalMapping(model, resource.getOid(), kind, intent, objectClassName, new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS), actMapping.getAdministrativeStatus());
                processBidirectionalMapping(model, resource.getOid(), kind, intent, objectClassName, new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_FROM), actMapping.getValidFrom());
                processBidirectionalMapping(model, resource.getOid(), kind, intent, objectClassName, new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_VALID_TO), actMapping.getValidTo());
                processBidirectionalMapping(model, resource.getOid(), kind, intent, objectClassName, new ItemPath(FocusType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS), actMapping.getLockoutStatus());
                processBidirectionalMapping(model, resource.getOid(), kind, intent, objectClassName, new ItemPath(FocusType.F_ACTIVATION, ACTIVATION_EXISTENCE), actMapping.getExistence());
            }
            ResourcePasswordDefinitionType pwdDef = refinedDefinition.getPasswordDefinition();
            if (pwdDef != null) {
                final ItemPath pwdPath = new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD);
                ResourceDataItem resourceDataItem = model.findResourceItem(resource.getOid(), kind, intent, getObjectClassName(refinedDefinition), pwdPath);
                if (resourceDataItem == null) {
                    throw new IllegalStateException("No resource item for " + resource.getOid() + ":" + kind + ":" + intent + ":" + pwdPath);
                }
                if (pwdDef.getOutbound() != null) {
                    for (MappingType outbound : pwdDef.getOutbound()) {
                        processOutboundMapping(model, resourceDataItem, outbound, pwdPath);
                    }
                }
                for (MappingType inbound : pwdDef.getInbound()) {
                    processInboundMapping(model, resourceDataItem, inbound, pwdPath);
                }
            }
        }
    }
}
Also used : QName(javax.xml.namespace.QName) ResourceDataItem(com.evolveum.midpoint.model.impl.dataModel.model.ResourceDataItem) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 3 with ResourceDataItem

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

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

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

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