@Test public void testFindByDomain() throws TechnicalException { Resource resource1 = new Resource().setResourceScopes(Arrays.asList("a","b","c")).setDomain(DOMAIN_ID).setClientId(CLIENT_ID).setUserId(USER_ID); Resource resource2 = new Resource().setResourceScopes(Arrays.asList("d","e","f")).setDomain(DOMAIN_ID).setClientId(CLIENT_ID).setUserId(USER_ID); repository.create(resource1).blockingGet(); repository.create(resource2).blockingGet(); TestObserver<Page<Resource>> testObserver = repository.findByDomain(DOMAIN_ID, 0, Integer.MAX_VALUE).test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete(); testObserver.assertNoErrors(); testObserver.assertValue(resources -> resources.getData().size() == 2); }
@Override public Single<Page<Resource>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(resourceCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<Set<Resource>> resourceSetOperation = Observable.fromPublisher(resourceCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).collect(HashSet::new, Set::add); return Single.zip(countOperation, resourceSetOperation, (count, resourceSet) -> new Page<>(resourceSet, page, count)); }
MongoResourceRepository extends AbstractManagementMongoRepository implements ResourceRepository { @Override public Single<Page<Resource>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(resourceCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<Set<Resource>> resourceSetOperation = Observable.fromPublisher(resourceCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).collect(HashSet::new, Set::add); return Single.zip(countOperation, resourceSetOperation, (count, resourceSet) -> new Page<>(resourceSet, page, count)); } }
MongoResourceRepository extends AbstractManagementMongoRepository implements ResourceRepository { @Override public Single<Page<Resource>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(resourceCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<Set<Resource>> resourceSetOperation = Observable.fromPublisher(resourceCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).collect(HashSet::new, Set::add); return Single.zip(countOperation, resourceSetOperation, (count, resourceSet) -> new Page<>(resourceSet, page, count)); }  }
MongoResourceRepository extends AbstractManagementMongoRepository implements ResourceRepository { @Override public Single<Page<Resource>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(resourceCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<Set<Resource>> resourceSetOperation = Observable.fromPublisher(resourceCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).collect(HashSet::new, Set::add); return Single.zip(countOperation, resourceSetOperation, (count, resourceSet) -> new Page<>(resourceSet, page, count)); }  @PostConstruct void init(); @Override Single<Page<Resource>> findByDomainAndClient(String domain, String client, int page, int size); @Override Maybe<Resource> findById(String id); @Override Single<Resource> create(Resource item); @Override Single<Resource> update(Resource item); @Override Completable delete(String id); @Override Single<List<Resource>> findByDomainAndClientAndUser(String domain, String client, String user); @Override Single<Page<Resource>> findByDomain(String domain, int page, int size); @Override Single<List<Resource>> findByResources(List<String> resources); @Override Single<List<Resource>> findByDomainAndClientAndResources(String domain, String client, List<String> resources); @Override Maybe<Resource> findByDomainAndClientAndUserAndResource(String domain, String client, String user, String resource); }
MongoResourceRepository extends AbstractManagementMongoRepository implements ResourceRepository { @Override public Single<Page<Resource>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(resourceCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<Set<Resource>> resourceSetOperation = Observable.fromPublisher(resourceCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).collect(HashSet::new, Set::add); return Single.zip(countOperation, resourceSetOperation, (count, resourceSet) -> new Page<>(resourceSet, page, count)); }  @PostConstruct void init(); @Override Single<Page<Resource>> findByDomainAndClient(String domain, String client, int page, int size); @Override Maybe<Resource> findById(String id); @Override Single<Resource> create(Resource item); @Override Single<Resource> update(Resource item); @Override Completable delete(String id); @Override Single<List<Resource>> findByDomainAndClientAndUser(String domain, String client, String user); @Override Single<Page<Resource>> findByDomain(String domain, int page, int size); @Override Single<List<Resource>> findByResources(List<String> resources); @Override Single<List<Resource>> findByDomainAndClientAndResources(String domain, String client, List<String> resources); @Override Maybe<Resource> findByDomainAndClientAndUserAndResource(String domain, String client, String user, String resource); static final String COLLECTION_NAME; }