Search in sources :

Example 36 with Fetch

use of org.molgenis.data.Fetch in project molgenis by molgenis.

the class AttributeFilterToFetchConverter method createDefaultAttributeFetch.

/**
 * Create default fetch for the given attribute. For attributes referencing entities the id and label value are
 * fetched. Additionally for file entities the URL is fetched. For other attributes the default fetch is null;
 *
 * @return default attribute fetch or null
 */
public static Fetch createDefaultAttributeFetch(Attribute attr, String languageCode) {
    Fetch fetch;
    if (isReferenceType(attr)) {
        fetch = new Fetch();
        EntityType refEntityType = attr.getRefEntity();
        String idAttrName = refEntityType.getIdAttribute().getName();
        fetch.field(idAttrName);
        String labelAttrName = refEntityType.getLabelAttribute(languageCode).getName();
        if (!labelAttrName.equals(idAttrName)) {
            fetch.field(labelAttrName);
        }
        if (attr.getDataType() == FILE) {
            fetch.field(FileMetaMetaData.URL);
        }
    } else {
        fetch = null;
    }
    return fetch;
}
Also used : Fetch(org.molgenis.data.Fetch) EntityType(org.molgenis.data.meta.model.EntityType)

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