@Test public void testCandidatesAreRetrievedFromMongo() { Collection<Candidate> candidates = mongoCandidateSupplier.getCandidates(entityInformation); assertFalse(candidates.isEmpty()); }
@Override public Collection<Candidate> getCandidates(EntityInformation<T> entityInformation) { Collection<Candidate> candidates = new HashSet<>(); MongoCollection<Document> collection = mongoDatabase.getCollection(argumentsMap.get(PARAM_COLLECTION)); Optional<Bson> buildQuery = buildQuery(entityInformation); if (buildQuery.isPresent()) { FindIterable<Document> documents = collection.find(buildQuery.get()); for (Document document : documents) { Map<String, String> map = new MongoDocumentFlattener(document).flatten(); String candidateID = document.get(argumentsMap.getOrDefault(PARAM_ID_FIELD, DEFAULT_MONGO_ID)).toString(); String candidateName = document.get(argumentsMap.get(PARAM_SEARCH_FIELD)).toString(); candidates.add(new DefaultCandidate(candidateID, candidateName, map)); } } return candidates; }
MongoCandidateSupplier implements CandidateSupplier<T> { @Override public Collection<Candidate> getCandidates(EntityInformation<T> entityInformation) { Collection<Candidate> candidates = new HashSet<>(); MongoCollection<Document> collection = mongoDatabase.getCollection(argumentsMap.get(PARAM_COLLECTION)); Optional<Bson> buildQuery = buildQuery(entityInformation); if (buildQuery.isPresent()) { FindIterable<Document> documents = collection.find(buildQuery.get()); for (Document document : documents) { Map<String, String> map = new MongoDocumentFlattener(document).flatten(); String candidateID = document.get(argumentsMap.getOrDefault(PARAM_ID_FIELD, DEFAULT_MONGO_ID)).toString(); String candidateName = document.get(argumentsMap.get(PARAM_SEARCH_FIELD)).toString(); candidates.add(new DefaultCandidate(candidateID, candidateName, map)); } } return candidates; } }
MongoCandidateSupplier implements CandidateSupplier<T> { @Override public Collection<Candidate> getCandidates(EntityInformation<T> entityInformation) { Collection<Candidate> candidates = new HashSet<>(); MongoCollection<Document> collection = mongoDatabase.getCollection(argumentsMap.get(PARAM_COLLECTION)); Optional<Bson> buildQuery = buildQuery(entityInformation); if (buildQuery.isPresent()) { FindIterable<Document> documents = collection.find(buildQuery.get()); for (Document document : documents) { Map<String, String> map = new MongoDocumentFlattener(document).flatten(); String candidateID = document.get(argumentsMap.getOrDefault(PARAM_ID_FIELD, DEFAULT_MONGO_ID)).toString(); String candidateName = document.get(argumentsMap.get(PARAM_SEARCH_FIELD)).toString(); candidates.add(new DefaultCandidate(candidateID, candidateName, map)); } } return candidates; } MongoCandidateSupplier();   MongoCandidateSupplier(Function<Map<String, String>, MongoFactory> factorySupplier); }
MongoCandidateSupplier implements CandidateSupplier<T> { @Override public Collection<Candidate> getCandidates(EntityInformation<T> entityInformation) { Collection<Candidate> candidates = new HashSet<>(); MongoCollection<Document> collection = mongoDatabase.getCollection(argumentsMap.get(PARAM_COLLECTION)); Optional<Bson> buildQuery = buildQuery(entityInformation); if (buildQuery.isPresent()) { FindIterable<Document> documents = collection.find(buildQuery.get()); for (Document document : documents) { Map<String, String> map = new MongoDocumentFlattener(document).flatten(); String candidateID = document.get(argumentsMap.getOrDefault(PARAM_ID_FIELD, DEFAULT_MONGO_ID)).toString(); String candidateName = document.get(argumentsMap.get(PARAM_SEARCH_FIELD)).toString(); candidates.add(new DefaultCandidate(candidateID, candidateName, map)); } } return candidates; } MongoCandidateSupplier();   MongoCandidateSupplier(Function<Map<String, String>, MongoFactory> factorySupplier); @Override Collection<Candidate> getCandidates(EntityInformation<T> entityInformation); @Override void configure(String[] argumentPairs); @Override void close(); }
MongoCandidateSupplier implements CandidateSupplier<T> { @Override public Collection<Candidate> getCandidates(EntityInformation<T> entityInformation) { Collection<Candidate> candidates = new HashSet<>(); MongoCollection<Document> collection = mongoDatabase.getCollection(argumentsMap.get(PARAM_COLLECTION)); Optional<Bson> buildQuery = buildQuery(entityInformation); if (buildQuery.isPresent()) { FindIterable<Document> documents = collection.find(buildQuery.get()); for (Document document : documents) { Map<String, String> map = new MongoDocumentFlattener(document).flatten(); String candidateID = document.get(argumentsMap.getOrDefault(PARAM_ID_FIELD, DEFAULT_MONGO_ID)).toString(); String candidateName = document.get(argumentsMap.get(PARAM_SEARCH_FIELD)).toString(); candidates.add(new DefaultCandidate(candidateID, candidateName, map)); } } return candidates; } MongoCandidateSupplier();   MongoCandidateSupplier(Function<Map<String, String>, MongoFactory> factorySupplier); @Override Collection<Candidate> getCandidates(EntityInformation<T> entityInformation); @Override void configure(String[] argumentPairs); @Override void close(); static final String PARAM_COLLECTION; static final String PARAM_SEARCH_FIELD; static final String PARAM_ID_FIELD; }