@Test public void testRemoveNotExistsThenOK() throws DatabaseException { String id = GUIDFactory.newGUID().toString(); Integer tenant = 0; repository.remove(id, tenant); }
@Override public void remove(String id, Integer tenant) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, id); String index = indexName; if (indexByTenant) { index = index + "_" + tenant; } DeleteRequest request = new DeleteRequest(index) .id(id) .timeout(TimeValue.timeValueMillis(VitamConfiguration.getElasticSearchTimeoutWaitRequestInMilliseconds())) .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); DeleteResponse deleteResponse; try { deleteResponse = client.delete(request, RequestOptions.DEFAULT); } catch (IOException | ElasticsearchException e) { if (e instanceof ElasticsearchException && ((ElasticsearchException) e).status() == RestStatus.NOT_FOUND) { return; } throw new DatabaseException(e); } DocWriteResponse.Result result = deleteResponse.getResult(); switch (result) { case DELETED: case NOT_FOUND: break; default: handleFailures(deleteResponse); } }
VitamElasticsearchRepository implements VitamRepository { @Override public void remove(String id, Integer tenant) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, id); String index = indexName; if (indexByTenant) { index = index + "_" + tenant; } DeleteRequest request = new DeleteRequest(index) .id(id) .timeout(TimeValue.timeValueMillis(VitamConfiguration.getElasticSearchTimeoutWaitRequestInMilliseconds())) .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); DeleteResponse deleteResponse; try { deleteResponse = client.delete(request, RequestOptions.DEFAULT); } catch (IOException | ElasticsearchException e) { if (e instanceof ElasticsearchException && ((ElasticsearchException) e).status() == RestStatus.NOT_FOUND) { return; } throw new DatabaseException(e); } DocWriteResponse.Result result = deleteResponse.getResult(); switch (result) { case DELETED: case NOT_FOUND: break; default: handleFailures(deleteResponse); } } }
VitamElasticsearchRepository implements VitamRepository { @Override public void remove(String id, Integer tenant) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, id); String index = indexName; if (indexByTenant) { index = index + "_" + tenant; } DeleteRequest request = new DeleteRequest(index) .id(id) .timeout(TimeValue.timeValueMillis(VitamConfiguration.getElasticSearchTimeoutWaitRequestInMilliseconds())) .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); DeleteResponse deleteResponse; try { deleteResponse = client.delete(request, RequestOptions.DEFAULT); } catch (IOException | ElasticsearchException e) { if (e instanceof ElasticsearchException && ((ElasticsearchException) e).status() == RestStatus.NOT_FOUND) { return; } throw new DatabaseException(e); } DocWriteResponse.Result result = deleteResponse.getResult(); switch (result) { case DELETED: case NOT_FOUND: break; default: handleFailures(deleteResponse); } } VitamElasticsearchRepository(RestHighLevelClient client, String indexName, boolean indexByTenant); }
VitamElasticsearchRepository implements VitamRepository { @Override public void remove(String id, Integer tenant) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, id); String index = indexName; if (indexByTenant) { index = index + "_" + tenant; } DeleteRequest request = new DeleteRequest(index) .id(id) .timeout(TimeValue.timeValueMillis(VitamConfiguration.getElasticSearchTimeoutWaitRequestInMilliseconds())) .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); DeleteResponse deleteResponse; try { deleteResponse = client.delete(request, RequestOptions.DEFAULT); } catch (IOException | ElasticsearchException e) { if (e instanceof ElasticsearchException && ((ElasticsearchException) e).status() == RestStatus.NOT_FOUND) { return; } throw new DatabaseException(e); } DocWriteResponse.Result result = deleteResponse.getResult(); switch (result) { case DELETED: case NOT_FOUND: break; default: handleFailures(deleteResponse); } } VitamElasticsearchRepository(RestHighLevelClient client, String indexName, boolean indexByTenant); @Override void save(Document document); @Override VitamRepositoryStatus saveOrUpdate(Document document); @Override void save(List<Document> documents); void save(ElasticsearchCollections elasticsearchCollections, List<Document> documents); @Override void saveOrUpdate(List<Document> documents); @Override void update(List<WriteModel<Document>> updates); @Override FindIterable<Document> findDocuments(Collection<String> ids, Bson projection); @Override void remove(String id, Integer tenant); @Override long remove(Bson query); @Override void removeByNameAndTenant(String name, Integer tenant); @Override long purge(Integer tenant); static long handlePurge(RestHighLevelClient client, String index, QueryBuilder qb); @Override long purge(); @Override Optional<Document> getByID(String id, Integer tenant); @Override Optional<Document> findByIdentifierAndTenant(String identifier, Integer tenant); SearchResponse search(String index, QueryBuilder qb); @Override Optional<Document> findByIdentifier(String identifier); @Override FindIterable<Document> findByFieldsDocuments(Map<String, String> fields, int mongoBatchSize,
        Integer tenant); @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); }
VitamElasticsearchRepository implements VitamRepository { @Override public void remove(String id, Integer tenant) throws DatabaseException { ParametersChecker.checkParameter(ALL_PARAMS_REQUIRED, id); String index = indexName; if (indexByTenant) { index = index + "_" + tenant; } DeleteRequest request = new DeleteRequest(index) .id(id) .timeout(TimeValue.timeValueMillis(VitamConfiguration.getElasticSearchTimeoutWaitRequestInMilliseconds())) .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); DeleteResponse deleteResponse; try { deleteResponse = client.delete(request, RequestOptions.DEFAULT); } catch (IOException | ElasticsearchException e) { if (e instanceof ElasticsearchException && ((ElasticsearchException) e).status() == RestStatus.NOT_FOUND) { return; } throw new DatabaseException(e); } DocWriteResponse.Result result = deleteResponse.getResult(); switch (result) { case DELETED: case NOT_FOUND: break; default: handleFailures(deleteResponse); } } VitamElasticsearchRepository(RestHighLevelClient client, String indexName, boolean indexByTenant); @Override void save(Document document); @Override VitamRepositoryStatus saveOrUpdate(Document document); @Override void save(List<Document> documents); void save(ElasticsearchCollections elasticsearchCollections, List<Document> documents); @Override void saveOrUpdate(List<Document> documents); @Override void update(List<WriteModel<Document>> updates); @Override FindIterable<Document> findDocuments(Collection<String> ids, Bson projection); @Override void remove(String id, Integer tenant); @Override long remove(Bson query); @Override void removeByNameAndTenant(String name, Integer tenant); @Override long purge(Integer tenant); static long handlePurge(RestHighLevelClient client, String index, QueryBuilder qb); @Override long purge(); @Override Optional<Document> getByID(String id, Integer tenant); @Override Optional<Document> findByIdentifierAndTenant(String identifier, Integer tenant); SearchResponse search(String index, QueryBuilder qb); @Override Optional<Document> findByIdentifier(String identifier); @Override FindIterable<Document> findByFieldsDocuments(Map<String, String> fields, int mongoBatchSize,
        Integer tenant); @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 IDENTIFIER; }