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;
}
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));
}
}
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));
}
}
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);
}
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);
}
Aggregations