@Override public Collection<Attribute> attributes(AttributeFilter filter) { Collection<Attribute> filtered = new ArrayList<Attribute>(attributes().size() / 2); for (Attribute attr : attributes()) { if (filter.accepts(attr)) { filtered.add(attr); } } return filtered; }
/** * Converts {@link AttributeFilter} to {@link Fetch} based on {@link EntityMetaData}. * * @param attrFilter the {@link AttributeFilter} to convert * @param entityMeta {@link EntityMetaData} for the entity * @return {@link Fetch}, or null for 'all attributes' {@link AttributeFilter} there are no * refEntities * @throws UnknownAttributeException if the entity does not have one of the attributes mentioned * in the filter */ public static Fetch convert( AttributeFilter attrFilter, EntityMetaData entityMeta, String languageCode) { if (attrFilter == null || attrFilter.isStar()) { return createDefaultEntityFetch(entityMeta, languageCode); } Fetch fetch = new Fetch(); createFetchContentRec(attrFilter, entityMeta, fetch, languageCode); return fetch; }
private static void createFetchContentRec( AttributeFilter attrFilter, EntityMetaData entityMeta, Fetch fetch, String languageCode) { if (attrFilter.isIncludeAllAttrs()) { entityMeta .getAtomicAttributes() .forEach( attr -> fetch.field(attr.getName(), createDefaultAttributeFetch(attr, languageCode))); } if (attrFilter.isIncludeIdAttr()) { fetch.field(entityMeta.getIdAttribute().getName()); } if (attrFilter.isIncludeLabelAttr()) { fetch.field(entityMeta.getLabelAttribute(languageCode).getName()); } attrFilter.forEach( entry -> { String attrName = entry.getKey(); AttributeMetaData attr = getAttribute(entityMeta, attrName); createFetchContentRec(attrFilter, entityMeta, attr, fetch, languageCode); }); }
private static void createFetchContentRec( AttributeFilter attrFilter, EntityMetaData entityMeta, AttributeMetaData attr, Fetch fetch, String languageCode) { AttributeType attrType = attr.getDataType(); switch (attrType) { case COMPOUND: { AttributeFilter subAttrFilter = attrFilter != null ? attrFilter.getAttributeFilter(entityMeta, attr) : null; if (subAttrFilter != null && !subAttrFilter.isIncludeAllAttrs()) { // include compound attribute parts defined by filter if (subAttrFilter.isIncludeIdAttr()) { createFetchContentRec( subAttrFilter, entityMeta, entityMeta.getIdAttribute(), fetch, languageCode); } if (subAttrFilter.isIncludeLabelAttr()) { createFetchContentRec( subAttrFilter, entityMeta, entityMeta.getLabelAttribute(languageCode), fetch, languageCode); } subAttrFilter.forEach( entry -> { String attrPartName = entry.getKey(); AttributeMetaData attrPart = attr.getAttributePart(attrPartName); createFetchContentRec(subAttrFilter, entityMeta, attrPart, fetch, languageCode); }); } else { // include all compound attribute parts attr.getAttributeParts() .forEach( attrPart -> { createFetchContentRec( subAttrFilter, entityMeta, attrPart, fetch, languageCode); }); } break; } case CATEGORICAL: case CATEGORICAL_MREF: case FILE: case MREF: case XREF: { AttributeFilter subAttrFilter = attrFilter != null ? attrFilter.getAttributeFilter(entityMeta, attr) : null; Fetch subFetch; if (subAttrFilter != null) { subFetch = convert(subAttrFilter, attr.getRefEntity(), languageCode); } else { subFetch = createDefaultAttributeFetch(attr, languageCode); } fetch.field(attr.getName(), subFetch); break; } // $CASES-OMITTED$ default: fetch.field(attr.getName()); break; } }