@Test public void testFindByReferenceAndMember() { Membership membership = new Membership(); membership.setRoleId("role#1"); membership.setReferenceType(ReferenceType.ORGANIZATION); membership.setReferenceId(ORGANIZATION_ID); membership.setMemberType(MemberType.USER); membership.setMemberId("user#1"); Membership createdMembership = membershipRepository.create(membership).blockingGet(); TestObserver<Membership> obs = membershipRepository.findByReferenceAndMember(ReferenceType.ORGANIZATION, ORGANIZATION_ID, membership.getMemberType(), membership.getMemberId()).test(); obs.awaitTerminalEvent(); obs.assertComplete(); obs.assertValue(m -> m.getId().equals(createdMembership.getId())); }
@Override public Maybe<Membership> findByReferenceAndMember(ReferenceType referenceType, String referenceId, MemberType memberType, String memberId) { return Observable.fromPublisher(membershipsCollection.find( and(eq(FIELD_REFERENCE_TYPE, referenceType.name()), eq(FIELD_REFERENCE_ID, referenceId), eq(FIELD_MEMBER_TYPE, memberType.name()), eq(FIELD_MEMBER_ID, memberId))).first()) .firstElement().map(this::convert); }
MongoMembershipRepository extends AbstractManagementMongoRepository implements MembershipRepository { @Override public Maybe<Membership> findByReferenceAndMember(ReferenceType referenceType, String referenceId, MemberType memberType, String memberId) { return Observable.fromPublisher(membershipsCollection.find( and(eq(FIELD_REFERENCE_TYPE, referenceType.name()), eq(FIELD_REFERENCE_ID, referenceId), eq(FIELD_MEMBER_TYPE, memberType.name()), eq(FIELD_MEMBER_ID, memberId))).first()) .firstElement().map(this::convert); } }
MongoMembershipRepository extends AbstractManagementMongoRepository implements MembershipRepository { @Override public Maybe<Membership> findByReferenceAndMember(ReferenceType referenceType, String referenceId, MemberType memberType, String memberId) { return Observable.fromPublisher(membershipsCollection.find( and(eq(FIELD_REFERENCE_TYPE, referenceType.name()), eq(FIELD_REFERENCE_ID, referenceId), eq(FIELD_MEMBER_TYPE, memberType.name()), eq(FIELD_MEMBER_ID, memberId))).first()) .firstElement().map(this::convert); }  }
MongoMembershipRepository extends AbstractManagementMongoRepository implements MembershipRepository { @Override public Maybe<Membership> findByReferenceAndMember(ReferenceType referenceType, String referenceId, MemberType memberType, String memberId) { return Observable.fromPublisher(membershipsCollection.find( and(eq(FIELD_REFERENCE_TYPE, referenceType.name()), eq(FIELD_REFERENCE_ID, referenceId), eq(FIELD_MEMBER_TYPE, memberType.name()), eq(FIELD_MEMBER_ID, memberId))).first()) .firstElement().map(this::convert); }  @PostConstruct void init(); @Override Single<List<Membership>> findByReference(String referenceId, ReferenceType referenceType); @Override Flowable<Membership> findByCriteria(ReferenceType referenceType, String referenceId, MembershipCriteria criteria); @Override Maybe<Membership> findByReferenceAndMember(ReferenceType referenceType, String referenceId, MemberType memberType, String memberId); @Override Maybe<Membership> findById(String id); @Override Single<Membership> create(Membership item); @Override Single<Membership> update(Membership item); @Override Completable delete(String id); }
MongoMembershipRepository extends AbstractManagementMongoRepository implements MembershipRepository { @Override public Maybe<Membership> findByReferenceAndMember(ReferenceType referenceType, String referenceId, MemberType memberType, String memberId) { return Observable.fromPublisher(membershipsCollection.find( and(eq(FIELD_REFERENCE_TYPE, referenceType.name()), eq(FIELD_REFERENCE_ID, referenceId), eq(FIELD_MEMBER_TYPE, memberType.name()), eq(FIELD_MEMBER_ID, memberId))).first()) .firstElement().map(this::convert); }  @PostConstruct void init(); @Override Single<List<Membership>> findByReference(String referenceId, ReferenceType referenceType); @Override Flowable<Membership> findByCriteria(ReferenceType referenceType, String referenceId, MembershipCriteria criteria); @Override Maybe<Membership> findByReferenceAndMember(ReferenceType referenceType, String referenceId, MemberType memberType, String memberId); @Override Maybe<Membership> findById(String id); @Override Single<Membership> create(Membership item); @Override Single<Membership> update(Membership item); @Override Completable delete(String id); static final String FIELD_MEMBER_TYPE; static final String FIELD_ROLE; }