use of io.crnk.meta.model.MetaMapAttribute in project crnk-framework by crnk-project.
the class JoinRegistry method getEntityAttribute.
public E getEntityAttribute(MetaAttributePath attrPath) {
MetaAttributePath associationPath = extractAssociationPath(attrPath);
MetaAttributePath primitivePath = attrPath.subPath(associationPath.length());
@SuppressWarnings("unchecked") E from = (E) getOrCreateJoin(associationPath);
if (primitivePath.length() == 0) {
return from;
}
MetaAttributePath currentPath = associationPath;
E criteriaPath = null;
for (MetaAttribute pathElement : primitivePath) {
currentPath = currentPath.concat(pathElement);
E currentCriteriaPath = criteriaPath != null ? criteriaPath : from;
if (pathElement instanceof MetaMapAttribute) {
if (criteriaPath != null)
throw new IllegalStateException("Cannot join to map");
criteriaPath = joinMap(currentCriteriaPath, pathElement);
} else {
// we may need to downcast if attribute is defined on a subtype
MetaDataObject parent = pathElement.getParent().asDataObject();
Class<?> pathType = parent.getImplementationClass();
Class<?> currentType = backend.getJavaElementType(currentCriteriaPath);
boolean isSubType = !pathType.isAssignableFrom(currentType);
if (isSubType) {
currentCriteriaPath = backend.joinSubType(currentCriteriaPath, pathType);
}
criteriaPath = backend.getAttribute(currentCriteriaPath, pathElement);
}
}
return criteriaPath;
}
Aggregations