@Test public void testGetByIDNotExistsOK() throws DatabaseException { Optional<Document> response = repository.getByID(GUIDFactory.newGUID().toString(), 0); assertThat(response).isEmpty(); }
@Override public Optional<Document> getByID(String id, Integer tenant) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, id); try { FindIterable<Document> result = collection.find(new BasicDBObject(ID, id)); if (result.iterator().hasNext()) { return Optional.of(result.first()); } else { return Optional.empty(); } } catch (Exception e) { LOGGER.error(String.format("DatabaseException while getting document by id : %s", id), e); throw new DatabaseException(String.format("DatabaseException while getting document by id : %s", id), e); } }
VitamMongoRepository implements VitamRepository { @Override public Optional<Document> getByID(String id, Integer tenant) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, id); try { FindIterable<Document> result = collection.find(new BasicDBObject(ID, id)); if (result.iterator().hasNext()) { return Optional.of(result.first()); } else { return Optional.empty(); } } catch (Exception e) { LOGGER.error(String.format("DatabaseException while getting document by id : %s", id), e); throw new DatabaseException(String.format("DatabaseException while getting document by id : %s", id), e); } } }
VitamMongoRepository implements VitamRepository { @Override public Optional<Document> getByID(String id, Integer tenant) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, id); try { FindIterable<Document> result = collection.find(new BasicDBObject(ID, id)); if (result.iterator().hasNext()) { return Optional.of(result.first()); } else { return Optional.empty(); } } catch (Exception e) { LOGGER.error(String.format("DatabaseException while getting document by id : %s", id), e); throw new DatabaseException(String.format("DatabaseException while getting document by id : %s", id), e); } } VitamMongoRepository(MongoCollection<Document> collection); }
VitamMongoRepository implements VitamRepository { @Override public Optional<Document> getByID(String id, Integer tenant) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, id); try { FindIterable<Document> result = collection.find(new BasicDBObject(ID, id)); if (result.iterator().hasNext()) { return Optional.of(result.first()); } else { return Optional.empty(); } } catch (Exception e) { LOGGER.error(String.format("DatabaseException while getting document by id : %s", id), e); throw new DatabaseException(String.format("DatabaseException while getting document by id : %s", id), e); } } VitamMongoRepository(MongoCollection<Document> collection); @Override void save(Document document); @Override VitamRepositoryStatus saveOrUpdate(Document document); @Override void save(List<Document> documents); @Override void saveOrUpdate(List<Document> documents); @Override void update(List<WriteModel<Document>> queries); @Override void remove(String id, Integer tenant); @Override long remove(Bson query); @Override void removeByNameAndTenant(String name, Integer tenant); @Override long purge(Integer tenant); @Override long purge(); @Override Optional<Document> getByID(String id, Integer tenant); @Override Optional<Document> findByIdentifierAndTenant(String identifier, Integer tenant); @Override Optional<Document> findByIdentifier(String identifier); @Override FindIterable<Document> findByFieldsDocuments(Map<String, String> fields, int mongoBatchSize,
        Integer tenant); @Override FindIterable<Document> findDocuments(Collection<String> ids, Bson projection); @Override FindIterable<Document> findDocuments(int mongoBatchSize, Integer tenant); @Override FindIterable<Document> findDocuments(int mongoBatchSize); @Override FindIterable<Document> findDocuments(Bson query, int mongoBatchSize); @Override void delete(List<String> ids, int tenant); }
VitamMongoRepository implements VitamRepository { @Override public Optional<Document> getByID(String id, Integer tenant) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, id); try { FindIterable<Document> result = collection.find(new BasicDBObject(ID, id)); if (result.iterator().hasNext()) { return Optional.of(result.first()); } else { return Optional.empty(); } } catch (Exception e) { LOGGER.error(String.format("DatabaseException while getting document by id : %s", id), e); throw new DatabaseException(String.format("DatabaseException while getting document by id : %s", id), e); } } VitamMongoRepository(MongoCollection<Document> collection); @Override void save(Document document); @Override VitamRepositoryStatus saveOrUpdate(Document document); @Override void save(List<Document> documents); @Override void saveOrUpdate(List<Document> documents); @Override void update(List<WriteModel<Document>> queries); @Override void remove(String id, Integer tenant); @Override long remove(Bson query); @Override void removeByNameAndTenant(String name, Integer tenant); @Override long purge(Integer tenant); @Override long purge(); @Override Optional<Document> getByID(String id, Integer tenant); @Override Optional<Document> findByIdentifierAndTenant(String identifier, Integer tenant); @Override Optional<Document> findByIdentifier(String identifier); @Override FindIterable<Document> findByFieldsDocuments(Map<String, String> fields, int mongoBatchSize,
        Integer tenant); @Override FindIterable<Document> findDocuments(Collection<String> ids, Bson projection); @Override FindIterable<Document> findDocuments(int mongoBatchSize, Integer tenant); @Override FindIterable<Document> findDocuments(int mongoBatchSize); @Override FindIterable<Document> findDocuments(Bson query, int mongoBatchSize); @Override void delete(List<String> ids, int tenant); static final String NAME; }