Search in sources :

Example 81 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class RepositoryTemplateLoader method findTemplateSource.

@Override
public Object findTemplateSource(String name) throws IOException {
    FreemarkerTemplate template = dataService.findOne(FREEMARKER_TEMPLATE, new QueryImpl<FreemarkerTemplate>().eq("Name", name), FreemarkerTemplate.class);
    if (template == null) {
        return null;
    }
    TemplateSource templateSource = new TemplateSource(template);
    LOG.debug("Created " + templateSource);
    return templateSource;
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) FreemarkerTemplate(org.molgenis.core.ui.data.system.core.FreemarkerTemplate)

Example 82 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class InMemoryRepositoryTest method findAllAsStream.

@Test
public void findAllAsStream() throws IOException {
    String idAttrName = "id";
    EntityType entityType = mock(EntityType.class);
    Attribute idAttr = when(mock(Attribute.class).getName()).thenReturn(idAttrName).getMock();
    when(entityType.getIdAttribute()).thenReturn(idAttr);
    try (InMemoryRepository inMemoryRepository = new InMemoryRepository(entityType)) {
        Object id0 = 0;
        Entity entity0 = when(mock(Entity.class).get(idAttrName)).thenReturn(id0).getMock();
        Object id1 = 1;
        Entity entity1 = when(mock(Entity.class).get(idAttrName)).thenReturn(id1).getMock();
        inMemoryRepository.add(entity0);
        inMemoryRepository.add(entity1);
        List<Entity> entities = inMemoryRepository.findAll(new QueryImpl<>()).collect(Collectors.toList());
        assertEquals(Lists.newArrayList(entities), Arrays.asList(entity0, entity1));
    }
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test)

Example 83 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class InMemoryRepositoryTest method findAllAsStreamSingleEqualsQuery.

@Test
public void findAllAsStreamSingleEqualsQuery() throws IOException {
    String idAttrName = "id";
    EntityType entityType = mock(EntityType.class);
    Attribute idAttr = when(mock(Attribute.class).getName()).thenReturn(idAttrName).getMock();
    when(entityType.getIdAttribute()).thenReturn(idAttr);
    try (InMemoryRepository inMemoryRepository = new InMemoryRepository(entityType)) {
        Object id0 = 0;
        Entity entity0 = when(mock(Entity.class).get("attr")).thenReturn("a").getMock();
        when(entity0.get("id")).thenReturn(id0);
        Object id1 = 1;
        Entity entity1 = when(mock(Entity.class).get("attr")).thenReturn("a").getMock();
        when(entity1.get("id")).thenReturn(id1);
        Object id2 = 2;
        Entity entity2 = when(mock(Entity.class).get("attr")).thenReturn("b").getMock();
        when(entity2.get("id")).thenReturn(id2);
        inMemoryRepository.add(entity0);
        inMemoryRepository.add(entity1);
        inMemoryRepository.add(entity2);
        System.out.println(entity0.get(idAttrName));
        List<Entity> entities = inMemoryRepository.findAll(new QueryImpl<>().eq("attr", "a")).filter(Objects::nonNull).collect(Collectors.toList());
        assertEquals(Lists.newArrayList(entities), Arrays.asList(entity0, entity1));
    }
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Entity(org.molgenis.data.Entity) QueryImpl(org.molgenis.data.support.QueryImpl) Attribute(org.molgenis.data.meta.model.Attribute) Test(org.testng.annotations.Test)

Example 84 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class OneClickImporterNamingServiceTest method testGetLabelWithPostFixWhenFiveDuplicate.

@Test
public void testGetLabelWithPostFixWhenFiveDuplicate() {
    EntityType e1 = Mockito.mock(EntityType.class);
    when(e1.getLabel()).thenReturn("label");
    EntityType e2 = Mockito.mock(EntityType.class);
    when(e2.getLabel()).thenReturn("label (1)");
    EntityType e3 = Mockito.mock(EntityType.class);
    when(e3.getLabel()).thenReturn("label (2)");
    EntityType e4 = Mockito.mock(EntityType.class);
    when(e4.getLabel()).thenReturn("label (3)");
    EntityType e5 = Mockito.mock(EntityType.class);
    when(e5.getLabel()).thenReturn("label (4)");
    String label = "label";
    when(dataService.findAll(ENTITY_TYPE_META_DATA, new QueryImpl<EntityType>().like(LABEL, label), EntityType.class)).thenReturn(Stream.of(e1, e2, e3, e4, e5));
    oneClickImporterNamingService = new OneClickImporterNamingServiceImpl(dataService);
    String actual = oneClickImporterNamingService.getLabelWithPostFix(label);
    String expected = "label (5)";
    assertEquals(actual, expected);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) QueryImpl(org.molgenis.data.support.QueryImpl) OneClickImporterNamingServiceImpl(org.molgenis.oneclickimporter.service.impl.OneClickImporterNamingServiceImpl) Test(org.testng.annotations.Test)

Example 85 with QueryImpl

use of org.molgenis.data.support.QueryImpl in project molgenis by molgenis.

the class OneClickImporterNamingServiceTest method testGetLabelWithPostFixDuplicateInNoOrder.

@Test
public void testGetLabelWithPostFixDuplicateInNoOrder() {
    EntityType e1 = Mockito.mock(EntityType.class);
    when(e1.getLabel()).thenReturn("label");
    EntityType e2 = Mockito.mock(EntityType.class);
    when(e2.getLabel()).thenReturn("label (1)");
    EntityType e3 = Mockito.mock(EntityType.class);
    when(e3.getLabel()).thenReturn("label (3)");
    String label = "label";
    when(dataService.findAll(ENTITY_TYPE_META_DATA, new QueryImpl<EntityType>().like(LABEL, label), EntityType.class)).thenReturn(Stream.of(e1, e2, e3));
    oneClickImporterNamingService = new OneClickImporterNamingServiceImpl(dataService);
    String actual = oneClickImporterNamingService.getLabelWithPostFix(label);
    String expected = "label (2)";
    assertEquals(actual, expected);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) QueryImpl(org.molgenis.data.support.QueryImpl) OneClickImporterNamingServiceImpl(org.molgenis.oneclickimporter.service.impl.OneClickImporterNamingServiceImpl) Test(org.testng.annotations.Test)

Aggregations

QueryImpl (org.molgenis.data.support.QueryImpl)98 Test (org.testng.annotations.Test)70 DynamicEntity (org.molgenis.data.support.DynamicEntity)37 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)36 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)36 EntityType (org.molgenis.data.meta.model.EntityType)28 Attribute (org.molgenis.data.meta.model.Attribute)25 Entity (org.molgenis.data.Entity)15 WithMockUser (org.springframework.security.test.context.support.WithMockUser)8 Stream (java.util.stream.Stream)7 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)7 AggregateQueryImpl (org.molgenis.data.support.AggregateQueryImpl)7 Objects.requireNonNull (java.util.Objects.requireNonNull)6 QueryRule (org.molgenis.data.QueryRule)6 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)6 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)6 BeforeMethod (org.testng.annotations.BeforeMethod)6 Instant (java.time.Instant)5 LocalDate (java.time.LocalDate)5 Operator (org.molgenis.data.QueryRule.Operator)5