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");
}
Aggregations