Search in sources :

Example 1 with MetaMapAttribute

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;
}
Also used : MetaMapAttribute(io.crnk.meta.model.MetaMapAttribute) MetaDataObject(io.crnk.meta.model.MetaDataObject) MetaAttribute(io.crnk.meta.model.MetaAttribute) MetaAttributePath(io.crnk.meta.model.MetaAttributePath)

Aggregations

MetaAttribute (io.crnk.meta.model.MetaAttribute)1 MetaAttributePath (io.crnk.meta.model.MetaAttributePath)1 MetaDataObject (io.crnk.meta.model.MetaDataObject)1 MetaMapAttribute (io.crnk.meta.model.MetaMapAttribute)1