Search in sources :

Example 31 with Fetch

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);
}
Also used : Fetch(org.molgenis.data.Fetch) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 32 with 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")));
}
Also used : Fetch(org.molgenis.data.Fetch) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 33 with Fetch

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));
}
Also used : Fetch(org.molgenis.data.Fetch) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 34 with Fetch

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;
}
Also used : Fetch(org.molgenis.data.Fetch)

Example 35 with 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;
}
Also used : Fetch(org.molgenis.data.Fetch) Attribute(org.molgenis.data.meta.model.Attribute)

Aggregations

Fetch (org.molgenis.data.Fetch)36 Test (org.testng.annotations.Test)28 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)12 EntityType (org.molgenis.data.meta.model.EntityType)10 Entity (org.molgenis.data.Entity)9 Attribute (org.molgenis.data.meta.model.Attribute)7 List (java.util.List)3 Query (org.molgenis.data.Query)3 TransactionDefinition (org.springframework.transaction.TransactionDefinition)3 ConstraintViolation (org.molgenis.data.validation.ConstraintViolation)2 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)2 Stopwatch (com.google.common.base.Stopwatch)1 Stopwatch.createStarted (com.google.common.base.Stopwatch.createStarted)1 CacheLoader (com.google.common.cache.CacheLoader)1 com.google.common.collect (com.google.common.collect)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 String.format (java.lang.String.format)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1