use of org.molgenis.data.Fetch in project molgenis by molgenis.
the class AttributeFilterToFetchConverterTest method convertNoAttrFilter.
@Test
public void convertNoAttrFilter() {
Fetch fetch = new Fetch().field(ID_ATTR_NAME).field(LABEL_ATTR_NAME).field(COMPOUND_PART_FILE_ATTR_NAME, new Fetch().field(FileMetaMetaData.ID).field(FileMetaMetaData.FILENAME).field(FileMetaMetaData.URL)).field(XREF_ATTR_NAME, new Fetch().field(REF_ID_ATTR_NAME).field(REF_LABEL_ATTR_NAME)).field(COMPOUND_PART_COMPOUND_PART_ATTR_NAME).field(COMPOUND_PART_COMPOUND_PART_ATTR2_NAME);
assertEquals(AttributeFilterToFetchConverter.convert(null, entityType, "en"), fetch);
}
use of org.molgenis.data.Fetch in project molgenis by molgenis.
the class AttributeFilterToFetchConverterTest method convertAttrFilterIncludeAll.
@Test
public void convertAttrFilterIncludeAll() {
AttributeFilter attrFilter = new AttributeFilter().setIncludeAllAttrs(true);
assertEquals(AttributeFilterToFetchConverter.convert(attrFilter, entityType, "en"), new Fetch().field("attrId").field("attrLabel").field("attrCompoundPartFile", new Fetch().field("id").field("filename").field("url")).field("attrCompoundPartCompoundPart").field("attr2CompoundPartCompoundPart").field("xrefAttr", new Fetch().field("refAttrId").field("refAttrLabel")));
}
use of org.molgenis.data.Fetch in project molgenis by molgenis.
the class AttributeFilterToFetchConverterTest method convertAttrFilterCompoundAttrPart.
@Test
public void convertAttrFilterCompoundAttrPart() {
AttributeFilter attrFilter = new AttributeFilter().add(COMPOUND_ATTR_NAME, new AttributeFilter().add(COMPOUND_PART_COMPOUND_ATTR_NAME));
assertEquals(AttributeFilterToFetchConverter.convert(attrFilter, entityType, "en"), new Fetch().field(COMPOUND_PART_COMPOUND_PART_ATTR_NAME).field(COMPOUND_PART_COMPOUND_PART_ATTR2_NAME));
}
use of org.molgenis.data.Fetch in project molgenis by molgenis.
the class AttributeFilterToFetchConverter method convert.
/**
* Converts {@link AttributeFilter} to {@link Fetch} based on {@link EntityType}.
*
* @param attrFilter the {@link AttributeFilter} to convert
* @param entityType {@link EntityType} 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, EntityType entityType, String languageCode) {
if (attrFilter == null || attrFilter.isStar()) {
return createDefaultEntityFetch(entityType, languageCode);
}
Fetch fetch = new Fetch();
createFetchContentRec(attrFilter, entityType, fetch, languageCode);
return fetch;
}
use of org.molgenis.data.Fetch in project molgenis by molgenis.
the class AttributeFilterToFetchConverter method createDefaultEntityFetch.
/**
* Create default entity fetch that fetches all attributes.
*
* @return default entity fetch or null
*/
public static Fetch createDefaultEntityFetch(EntityType entityType, String languageCode) {
boolean hasRefAttr = false;
Fetch fetch = new Fetch();
for (Attribute attr : entityType.getAtomicAttributes()) {
Fetch subFetch = createDefaultAttributeFetch(attr, languageCode);
if (subFetch != null) {
hasRefAttr = true;
}
fetch.field(attr.getName(), subFetch);
}
return hasRefAttr ? fetch : null;
}
Aggregations