@Test public void findByDomain() throws TechnicalException { AccessPolicy accessPolicy = new AccessPolicy(); accessPolicy.setName("accessPolicyName"); accessPolicy.setDomain(DOMAIN_ID); repository.create(accessPolicy).blockingGet(); TestObserver<Page<AccessPolicy>> testObserver = repository.findByDomain(DOMAIN_ID, 0, 10).test(); testObserver.awaitTerminalEvent(); testObserver.assertComplete(); testObserver.assertNoErrors(); testObserver.assertValue(p -> p.getTotalCount() == 1); }
@Override public Single<Page<AccessPolicy>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(accessPoliciesCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<List<AccessPolicy>> accessPoliciesOperation = Observable.fromPublisher(accessPoliciesCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).toList(); return Single.zip(countOperation, accessPoliciesOperation, (count, accessPolicies) -> new Page<>(accessPolicies, page, count)); }
MongoAccessPolicyRepository extends AbstractManagementMongoRepository implements AccessPolicyRepository { @Override public Single<Page<AccessPolicy>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(accessPoliciesCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<List<AccessPolicy>> accessPoliciesOperation = Observable.fromPublisher(accessPoliciesCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).toList(); return Single.zip(countOperation, accessPoliciesOperation, (count, accessPolicies) -> new Page<>(accessPolicies, page, count)); } }
MongoAccessPolicyRepository extends AbstractManagementMongoRepository implements AccessPolicyRepository { @Override public Single<Page<AccessPolicy>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(accessPoliciesCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<List<AccessPolicy>> accessPoliciesOperation = Observable.fromPublisher(accessPoliciesCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).toList(); return Single.zip(countOperation, accessPoliciesOperation, (count, accessPolicies) -> new Page<>(accessPolicies, page, count)); }  }
MongoAccessPolicyRepository extends AbstractManagementMongoRepository implements AccessPolicyRepository { @Override public Single<Page<AccessPolicy>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(accessPoliciesCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<List<AccessPolicy>> accessPoliciesOperation = Observable.fromPublisher(accessPoliciesCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).toList(); return Single.zip(countOperation, accessPoliciesOperation, (count, accessPolicies) -> new Page<>(accessPolicies, page, count)); }  @PostConstruct void init(); @Override Single<Page<AccessPolicy>> findByDomain(String domain, int page, int size); @Override Single<List<AccessPolicy>> findByDomainAndResource(String domain, String resource); @Override Single<List<AccessPolicy>> findByResources(List<String> resources); @Override Single<Long> countByResource(String resource); @Override Maybe<AccessPolicy> findById(String id); @Override Single<AccessPolicy> create(AccessPolicy item); @Override Single<AccessPolicy> update(AccessPolicy item); @Override Completable delete(String id); }
MongoAccessPolicyRepository extends AbstractManagementMongoRepository implements AccessPolicyRepository { @Override public Single<Page<AccessPolicy>> findByDomain(String domain, int page, int size) { Single<Long> countOperation = Observable.fromPublisher(accessPoliciesCollection.countDocuments(eq(FIELD_DOMAIN, domain))).first(0l); Single<List<AccessPolicy>> accessPoliciesOperation = Observable.fromPublisher(accessPoliciesCollection.find(eq(FIELD_DOMAIN, domain)).sort(new BasicDBObject(FIELD_UPDATED_AT, -1)).skip(size * page).limit(size)).map(this::convert).toList(); return Single.zip(countOperation, accessPoliciesOperation, (count, accessPolicies) -> new Page<>(accessPolicies, page, count)); }  @PostConstruct void init(); @Override Single<Page<AccessPolicy>> findByDomain(String domain, int page, int size); @Override Single<List<AccessPolicy>> findByDomainAndResource(String domain, String resource); @Override Single<List<AccessPolicy>> findByResources(List<String> resources); @Override Single<Long> countByResource(String resource); @Override Maybe<AccessPolicy> findById(String id); @Override Single<AccessPolicy> create(AccessPolicy item); @Override Single<AccessPolicy> update(AccessPolicy item); @Override Completable delete(String id); static final String COLLECTION_NAME; }