Search in sources :

Example 16 with UniformItemPath

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

the class SchemaTransformer method selectItemsToDelete.

@NotNull
private List<ItemName> selectItemsToDelete(PrismContainerDefinition<?> containerDefinition, UniformItemPath containerPath, List<VisibilityPolicyEntry> visibilityPolicy) {
    List<ItemName> itemsToDelete = new ArrayList<>();
    for (ItemDefinition<?> subDefinition : containerDefinition.getDefinitions()) {
        UniformItemPath itemPath = containerPath.append(subDefinition.getItemName());
        if (subDefinition instanceof PrismContainerDefinition) {
            PrismContainerDefinition<?> subContainerDef = (PrismContainerDefinition<?>) subDefinition;
            UserInterfaceElementVisibilityType itemVisibility = reduceItems(subContainerDef, itemPath, visibilityPolicy);
            if (subContainerDef.isEmpty()) {
                /*
                     * Empty sub-containers are treated in this way:
                     * - "completely defined" ones (no xsd:any) are hidden, unless explicitly set
                     *    to VISIBLE i.e. if VACANT, HIDDEN, or AUTOMATIC
                     * - "open" ones (xsd:any) are dealt with just like properties: hidden if VACANT or HIDDEN
                     *
                     * Primary motivation for this behavior is the fact that we need to keep assignment/extension definition
                     * in the object. It is required for normal model operation, specifically for the construction of "magic
                     * assignment".
                     *
                     * Note that this somehow mixes presentation requirements (hiding/showing items) with the requirements of
                     * business logic. This is because the current solution is a temporary one, to be replaced by something
                     * more serious.
                     */
                if (itemVisibility == VACANT || itemVisibility == HIDDEN || itemVisibility == AUTOMATIC && subContainerDef.isCompletelyDefined()) {
                    itemsToDelete.add(subDefinition.getItemName());
                }
            }
        } else {
            UserInterfaceElementVisibilityType itemVisibility = determineVisibility(visibilityPolicy, itemPath);
            if (itemVisibility == VACANT || itemVisibility == HIDDEN) {
                itemsToDelete.add(subDefinition.getItemName());
            }
        }
    }
    return itemsToDelete;
}
Also used : ItemName(com.evolveum.midpoint.prism.path.ItemName) UniformItemPath(com.evolveum.midpoint.prism.path.UniformItemPath) UserInterfaceElementVisibilityType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserInterfaceElementVisibilityType) NotNull(org.jetbrains.annotations.NotNull)

Example 17 with UniformItemPath

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

the class QAccessCertificationCampaignMapping method caseId.

private Long caseId(SelectorOptions<GetOperationOptions> option) {
    GetOperationOptions getOp = option.getOptions();
    if (getOp == null) {
        return null;
    }
    if (!RetrieveOption.INCLUDE.equals(getOp.getRetrieve())) {
        return null;
    }
    UniformItemPath path = option.getItemPath(null);
    if (path == null || path.size() == 1) {
        return null;
    }
    if (!F_CASE.equals(path.firstName())) {
        return null;
    }
    return ItemPath.toIdOrNull(path.getSegment(1));
}
Also used : GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) UniformItemPath(com.evolveum.midpoint.prism.path.UniformItemPath)

Example 18 with UniformItemPath

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

the class EntityRegistry method init.

@PostConstruct
public void init() {
    LOGGER.debug("Starting initialization");
    metamodel = sessionFactory.getMetamodel();
    for (EntityType<?> entity : metamodel.getEntities()) {
        Class<?> javaType = entity.getJavaType();
        Ignore ignore = javaType.getAnnotation(Ignore.class);
        if (ignore != null) {
            continue;
        }
        Class<?> jaxb;
        if (RObject.class.isAssignableFrom(javaType)) {
            // noinspection unchecked,rawtypes
            jaxb = RObjectType.getType((Class<? extends RObject>) javaType).getJaxbClass();
        } else {
            JaxbType jaxbType = javaType.getAnnotation(JaxbType.class);
            if (jaxbType == null) {
                throw new IllegalStateException("Unknown jaxb type for " + javaType.getName());
            }
            jaxb = jaxbType.type();
        }
        jaxbMappings.put(jaxb, entity);
        // create override map
        Map<String, Attribute<?, ?>> overrides = new HashMap<>();
        Map<UniformItemPath, Attribute<?, ?>> pathOverrides = new HashMap<>();
        for (Attribute<?, ?> attribute : entity.getAttributes()) {
            Class<?> jType = attribute.getJavaType();
            JaxbPath[] paths = jType.getAnnotationsByType(JaxbPath.class);
            if (paths == null || paths.length == 0) {
                paths = ((Method) attribute.getJavaMember()).getAnnotationsByType(JaxbPath.class);
            }
            if (paths == null || paths.length == 0) {
                JaxbName name = ((Method) attribute.getJavaMember()).getAnnotation(JaxbName.class);
                if (name != null) {
                    overrides.put(name.localPart(), attribute);
                }
                continue;
            }
            for (JaxbPath path : paths) {
                JaxbName[] names = path.itemPath();
                if (names.length == 1) {
                    overrides.put(names[0].localPart(), attribute);
                } else {
                    UniformItemPath customPath = prismContext.emptyPath();
                    for (JaxbName name : path.itemPath()) {
                        customPath = customPath.append(new QName(name.namespace(), name.localPart()));
                    }
                    pathOverrides.put(customPath, attribute);
                }
            }
        }
        if (!overrides.isEmpty()) {
            attributeNameOverrides.put(entity, overrides);
        }
        if (!pathOverrides.isEmpty()) {
            attributeNamePathOverrides.put(entity, pathOverrides);
        }
    }
    LOGGER.debug("Initialization finished");
}
Also used : Attribute(javax.persistence.metamodel.Attribute) HashMap(java.util.HashMap) JaxbPath(com.evolveum.midpoint.repo.sql.query.definition.JaxbPath) QName(javax.xml.namespace.QName) Method(java.lang.reflect.Method) JaxbName(com.evolveum.midpoint.repo.sql.query.definition.JaxbName) UniformItemPath(com.evolveum.midpoint.prism.path.UniformItemPath) JaxbType(com.evolveum.midpoint.repo.sql.query.definition.JaxbType) PostConstruct(javax.annotation.PostConstruct)

Aggregations

UniformItemPath (com.evolveum.midpoint.prism.path.UniformItemPath)18 NotNull (org.jetbrains.annotations.NotNull)5 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 UserInterfaceElementVisibilityType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserInterfaceElementVisibilityType)2 ArrayList (java.util.ArrayList)2 Attribute (javax.persistence.metamodel.Attribute)2 MappingImpl (com.evolveum.midpoint.model.common.mapping.MappingImpl)1 DefinitionsToTransformable (com.evolveum.midpoint.model.impl.schema.transform.DefinitionsToTransformable)1 ItemName (com.evolveum.midpoint.prism.path.ItemName)1 JaxbName (com.evolveum.midpoint.repo.sql.query.definition.JaxbName)1 JaxbPath (com.evolveum.midpoint.repo.sql.query.definition.JaxbPath)1 JaxbType (com.evolveum.midpoint.repo.sql.query.definition.JaxbType)1 DefinitionProcessingOption (com.evolveum.midpoint.schema.DefinitionProcessingOption)1 GetOperationOptions.createReadOnlyCollection (com.evolveum.midpoint.schema.GetOperationOptions.createReadOnlyCollection)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ObjectSecurityConstraints (com.evolveum.midpoint.security.enforcer.api.ObjectSecurityConstraints)1 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1