@SuppressWarnings("unchecked") @Test void testFindAll() { String entityTypeId = "MyEntityType"; Selection filter = Selection.FULL_SELECTION; Selection expand = Selection.EMPTY_SELECTION; EntityType entityType = mock(EntityType.class); Repository<Entity> repository = mock(Repository.class); when(repository.getEntityType()).thenReturn(entityType); Entity entity1 = mock(Entity.class); Entity entity2 = mock(Entity.class); Sort sort = Sort.create("field", Direction.ASC); Fetch fetch = new Fetch().field("id", new Fetch().field("refAttr")); Query q = Query.builder().setOperator(Operator.MATCHES).setValue("value").build(); org.molgenis.data.Query<Entity> findAllQuery = mock(org.molgenis.data.Query.class); org.molgenis.data.Sort dataSort = mock(org.molgenis.data.Sort.class); org.molgenis.data.Query<Entity> findQuery = new QueryImpl<>(findAllQuery); findQuery.fetch(fetch); findQuery.offset(10); findQuery.pageSize(10); findQuery.sort(dataSort); org.molgenis.data.Query<Entity> countQuery = new QueryImpl<>(findAllQuery); countQuery.offset(0); countQuery.pageSize(Integer.MAX_VALUE); when(repository.findAll(findQuery)).thenReturn(Stream.of(entity1, entity2)); when(repository.count(countQuery)).thenReturn(100L); when(queryMapper.map(q, repository)).thenReturn(findAllQuery).thenReturn(countQuery); when(sortMapper.map(sort, entityType)).thenReturn(dataSort); when(metaDataService.getRepository(entityTypeId)).thenReturn(Optional.of(repository)); Entities actual = dataServiceV3Impl.findAll(entityTypeId, q, filter, expand, sort, 10, 1); assertEquals( actual, Entities.builder().setEntities(asList(entity1, entity2)).setTotal(100).build()); }
@Transactional(readOnly = true) @Override public Entities findAll( String entityTypeId, @Nullable @CheckForNull Query query, Selection filter, Selection expand, Sort sort, int size, int number) { Repository<Entity> repository = getRepository(entityTypeId, OperationType.READ); org.molgenis.data.Query<Entity> findQuery = query != null ? queryMapper.map(query, repository) : new QueryImpl<>(repository); return getEntities(filter, expand, sort, size, number, repository, findQuery); }
DataServiceV3Impl implements DataServiceV3 { @Transactional(readOnly = true) @Override public Entities findAll( String entityTypeId, @Nullable @CheckForNull Query query, Selection filter, Selection expand, Sort sort, int size, int number) { Repository<Entity> repository = getRepository(entityTypeId, OperationType.READ); org.molgenis.data.Query<Entity> findQuery = query != null ? queryMapper.map(query, repository) : new QueryImpl<>(repository); return getEntities(filter, expand, sort, size, number, repository, findQuery); } }
DataServiceV3Impl implements DataServiceV3 { @Transactional(readOnly = true) @Override public Entities findAll( String entityTypeId, @Nullable @CheckForNull Query query, Selection filter, Selection expand, Sort sort, int size, int number) { Repository<Entity> repository = getRepository(entityTypeId, OperationType.READ); org.molgenis.data.Query<Entity> findQuery = query != null ? queryMapper.map(query, repository) : new QueryImpl<>(repository); return getEntities(filter, expand, sort, size, number, repository, findQuery); } DataServiceV3Impl(
      MetaDataService metaDataService,
      EntityManagerV3 entityManagerV3,
      QueryMapper queryMapper,
      SortMapper sortMapper,
      FetchMapper fetchMapper,
      EntityValidator entityValidator); }
DataServiceV3Impl implements DataServiceV3 { @Transactional(readOnly = true) @Override public Entities findAll( String entityTypeId, @Nullable @CheckForNull Query query, Selection filter, Selection expand, Sort sort, int size, int number) { Repository<Entity> repository = getRepository(entityTypeId, OperationType.READ); org.molgenis.data.Query<Entity> findQuery = query != null ? queryMapper.map(query, repository) : new QueryImpl<>(repository); return getEntities(filter, expand, sort, size, number, repository, findQuery); } DataServiceV3Impl(
      MetaDataService metaDataService,
      EntityManagerV3 entityManagerV3,
      QueryMapper queryMapper,
      SortMapper sortMapper,
      FetchMapper fetchMapper,
      EntityValidator entityValidator); @Transactional @Override Entity create(String entityTypeId, Map<String, Object> requestValues); @Transactional(readOnly = true) @Override Entity find(String entityTypeId, String entityId, Selection filter, Selection expand); @Transactional(readOnly = true) @Override Entities findSubresources(
      String entityTypeId,
      String entityId,
      String attributeName,
      @Nullable @CheckForNull Query query,
      Selection filter,
      Selection expand,
      Sort sort,
      int size,
      int number); @Transactional(readOnly = true) @Override Entities findAll(
      String entityTypeId,
      @Nullable @CheckForNull Query query,
      Selection filter,
      Selection expand,
      Sort sort,
      int size,
      int number); @Transactional @Override void update(String entityTypeId, String entityId, Map<String, Object> requestValues); @Transactional @Override void updatePartial(
      String entityTypeId, String entityId, Map<String, Object> requestValues); @Transactional @Override void delete(String entityTypeId, String entityId); @Transactional @Override void deleteAll(String entityTypeId, @Nullable @CheckForNull Query query); }
DataServiceV3Impl implements DataServiceV3 { @Transactional(readOnly = true) @Override public Entities findAll( String entityTypeId, @Nullable @CheckForNull Query query, Selection filter, Selection expand, Sort sort, int size, int number) { Repository<Entity> repository = getRepository(entityTypeId, OperationType.READ); org.molgenis.data.Query<Entity> findQuery = query != null ? queryMapper.map(query, repository) : new QueryImpl<>(repository); return getEntities(filter, expand, sort, size, number, repository, findQuery); } DataServiceV3Impl(
      MetaDataService metaDataService,
      EntityManagerV3 entityManagerV3,
      QueryMapper queryMapper,
      SortMapper sortMapper,
      FetchMapper fetchMapper,
      EntityValidator entityValidator); @Transactional @Override Entity create(String entityTypeId, Map<String, Object> requestValues); @Transactional(readOnly = true) @Override Entity find(String entityTypeId, String entityId, Selection filter, Selection expand); @Transactional(readOnly = true) @Override Entities findSubresources(
      String entityTypeId,
      String entityId,
      String attributeName,
      @Nullable @CheckForNull Query query,
      Selection filter,
      Selection expand,
      Sort sort,
      int size,
      int number); @Transactional(readOnly = true) @Override Entities findAll(
      String entityTypeId,
      @Nullable @CheckForNull Query query,
      Selection filter,
      Selection expand,
      Sort sort,
      int size,
      int number); @Transactional @Override void update(String entityTypeId, String entityId, Map<String, Object> requestValues); @Transactional @Override void updatePartial(
      String entityTypeId, String entityId, Map<String, Object> requestValues); @Transactional @Override void delete(String entityTypeId, String entityId); @Transactional @Override void deleteAll(String entityTypeId, @Nullable @CheckForNull Query query);  }