Search in sources :

Example 1 with JaxbPath

use of com.evolveum.midpoint.repo.sql.query.definition.JaxbPath 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)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 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 PostConstruct (javax.annotation.PostConstruct)1 Attribute (javax.persistence.metamodel.Attribute)1 QName (javax.xml.namespace.QName)1