Search in sources :

Example 6 with Fetch

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

the class AttributeFilterToFetchConverterTest method testConvertNestedSelfRef.

/**
 * A Fetch for attrs=~id,selfRef(*) should fetch id and selfRef(id, label, selfRef(id, label))
 */
@Test
public void testConvertNestedSelfRef() {
    AttributeFilter filter = new AttributeFilter().setIncludeIdAttr(true).add("selfRef", new AttributeFilter().setIncludeAllAttrs(true));
    Fetch fetch = AttributeFilterToFetchConverter.convert(filter, selfRefEntityType, "en");
    assertEquals(fetch, new Fetch().field("id").field("selfRef", new Fetch().field("id").field("label").field("selfRef", new Fetch().field("id").field("label"))));
}
Also used : Fetch(org.molgenis.data.Fetch) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 7 with Fetch

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

the class AttributeFilterToFetchConverterTest method createDefaultEntityFetchRefAttr.

@Test
public void createDefaultEntityFetchRefAttr() {
    Fetch fetch = new Fetch().field(REF_ID_ATTR_NAME).field(REF_LABEL_ATTR_NAME);
    assertEquals(AttributeFilterToFetchConverter.createDefaultAttributeFetch(xrefAttr, "en"), fetch);
}
Also used : Fetch(org.molgenis.data.Fetch) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 8 with Fetch

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

the class AttributeFilterToFetchConverterTest method testConvertDoubleNestedSelfRef.

/**
 * An AttributeFilter for ~id,~lbl,selfRef(*,selfRef(*)) should fetch (id, label, selfRef(id, label, selfRef(id,
 * label)))
 */
@Test
public void testConvertDoubleNestedSelfRef() {
    AttributeFilter filter = new AttributeFilter().setIncludeIdAttr(true).setIncludeLabelAttr(true).add("selfRef", new AttributeFilter().setIncludeAllAttrs(true).add("selfRef", new AttributeFilter().setIncludeAllAttrs(true)));
    Fetch fetch = AttributeFilterToFetchConverter.convert(filter, selfRefEntityType, "en");
    assertEquals(fetch, new Fetch().field("id").field("label").field("selfRef", new Fetch().field("id").field("label").field("selfRef", new Fetch().field("id").field("label").field("selfRef", new Fetch().field("id").field("label")))));
}
Also used : Fetch(org.molgenis.data.Fetch) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 9 with Fetch

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

the class UserServiceImpl method getUserGroups.

@Override
@RunAsSystem
public Iterable<Group> getUserGroups(String username) {
    Fetch fetch = new Fetch().field(GroupMemberMetaData.GROUP, new Fetch().field(GroupMetaData.ID).field(GroupMetaData.NAME).field(GroupMetaData.ACTIVE));
    Stream<GroupMember> molgenisGroupMembers = dataService.query(GROUP_MEMBER, GroupMember.class).fetch(fetch).eq(GroupMemberMetaData.USER, getUser(username)).findAll();
    // N.B. Must collect the results in a list before yielding up the RunAsSystem privileges!
    return molgenisGroupMembers.map(GroupMember::getGroup).collect(toList());
}
Also used : Fetch(org.molgenis.data.Fetch) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Example 10 with Fetch

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

the class EntityListenerRepositoryDecoratorTest method streamFetch.

@Test
public void streamFetch() {
    Fetch fetch = new Fetch();
    @SuppressWarnings("unchecked") Consumer<List<Entity>> consumer = Mockito.mock(Consumer.class);
    entityListenerRepositoryDecorator.forEachBatched(fetch, consumer, 543);
    Mockito.verify(delegateRepository, Mockito.times(1)).forEachBatched(fetch, consumer, 543);
}
Also used : Fetch(org.molgenis.data.Fetch) List(java.util.List) Test(org.testng.annotations.Test)

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