@Test public void reindexCollectionUnknownTest() { IndexParameters parameters = new IndexParameters(); parameters.setCollectionName("fakeName"); List<Integer> tenants = new ArrayList<>(); tenants.add(0); parameters.setTenants(tenants); logbookOperationsImpl = new LogbookOperationsImpl(mongoDbAccess, workspaceClientFactory, storageClientFactory, IndexationHelper.getInstance()); IndexationResult result = logbookOperationsImpl.reindex(parameters); assertNull(result.getIndexOK()); assertNotNull(result.getIndexKO()); assertEquals(1, result.getIndexKO().size()); assertEquals("fakeName_0_*", result.getIndexKO().get(0).getIndexName()); assertEquals("Try to reindex a non operation logbook collection 'fakeName' with operation logbook module", result .getIndexKO().get(0).getMessage()); assertEquals((Integer) 0, result.getIndexKO().get(0).getTenant()); }
@Override public IndexationResult reindex(IndexParameters indexParameters) { LogbookCollections collection; try { collection = LogbookCollections.valueOf(indexParameters.getCollectionName().toUpperCase()); } catch (IllegalArgumentException exc) { String message = String.format("Try to reindex a non operation logbook collection '%s' with operation " + "logbook module", indexParameters .getCollectionName()); LOGGER.error(message); return indexationHelper.getFullKOResult(indexParameters, message); } if (!LogbookCollections.OPERATION.equals(collection)) { String message = String.format("Try to reindex a non operation logbook collection '%s' with operation " + "logbook module", indexParameters .getCollectionName()); LOGGER.error(message); return indexationHelper.getFullKOResult(indexParameters, message); } else { MongoCollection<Document> mongoCollection = collection.getCollection(); try (InputStream mappingStream = ElasticsearchCollections .valueOf(indexParameters.getCollectionName().toUpperCase()) .getMappingAsInputStream()) { return indexationHelper.reindex(mongoCollection, collection.getName(), collection.getEsClient(), indexParameters.getTenants(), mappingStream); } catch (IOException exc) { LOGGER.error("Cannot get '{}' elastic search mapping for tenants {}", collection.name(), indexParameters.getTenants().stream().map(Object::toString).collect(Collectors.joining(", "))); return indexationHelper.getFullKOResult(indexParameters, exc.getMessage()); } } }
LogbookOperationsImpl implements LogbookOperations { @Override public IndexationResult reindex(IndexParameters indexParameters) { LogbookCollections collection; try { collection = LogbookCollections.valueOf(indexParameters.getCollectionName().toUpperCase()); } catch (IllegalArgumentException exc) { String message = String.format("Try to reindex a non operation logbook collection '%s' with operation " + "logbook module", indexParameters .getCollectionName()); LOGGER.error(message); return indexationHelper.getFullKOResult(indexParameters, message); } if (!LogbookCollections.OPERATION.equals(collection)) { String message = String.format("Try to reindex a non operation logbook collection '%s' with operation " + "logbook module", indexParameters .getCollectionName()); LOGGER.error(message); return indexationHelper.getFullKOResult(indexParameters, message); } else { MongoCollection<Document> mongoCollection = collection.getCollection(); try (InputStream mappingStream = ElasticsearchCollections .valueOf(indexParameters.getCollectionName().toUpperCase()) .getMappingAsInputStream()) { return indexationHelper.reindex(mongoCollection, collection.getName(), collection.getEsClient(), indexParameters.getTenants(), mappingStream); } catch (IOException exc) { LOGGER.error("Cannot get '{}' elastic search mapping for tenants {}", collection.name(), indexParameters.getTenants().stream().map(Object::toString).collect(Collectors.joining(", "))); return indexationHelper.getFullKOResult(indexParameters, exc.getMessage()); } } } }
LogbookOperationsImpl implements LogbookOperations { @Override public IndexationResult reindex(IndexParameters indexParameters) { LogbookCollections collection; try { collection = LogbookCollections.valueOf(indexParameters.getCollectionName().toUpperCase()); } catch (IllegalArgumentException exc) { String message = String.format("Try to reindex a non operation logbook collection '%s' with operation " + "logbook module", indexParameters .getCollectionName()); LOGGER.error(message); return indexationHelper.getFullKOResult(indexParameters, message); } if (!LogbookCollections.OPERATION.equals(collection)) { String message = String.format("Try to reindex a non operation logbook collection '%s' with operation " + "logbook module", indexParameters .getCollectionName()); LOGGER.error(message); return indexationHelper.getFullKOResult(indexParameters, message); } else { MongoCollection<Document> mongoCollection = collection.getCollection(); try (InputStream mappingStream = ElasticsearchCollections .valueOf(indexParameters.getCollectionName().toUpperCase()) .getMappingAsInputStream()) { return indexationHelper.reindex(mongoCollection, collection.getName(), collection.getEsClient(), indexParameters.getTenants(), mappingStream); } catch (IOException exc) { LOGGER.error("Cannot get '{}' elastic search mapping for tenants {}", collection.name(), indexParameters.getTenants().stream().map(Object::toString).collect(Collectors.joining(", "))); return indexationHelper.getFullKOResult(indexParameters, exc.getMessage()); } } } LogbookOperationsImpl(LogbookDbAccess mongoDbAccess); @VisibleForTesting  LogbookOperationsImpl(LogbookDbAccess mongoDbAccess, WorkspaceClientFactory workspaceClientFactory,
        StorageClientFactory storageClientFactory, IndexationHelper indexationHelper); }
LogbookOperationsImpl implements LogbookOperations { @Override public IndexationResult reindex(IndexParameters indexParameters) { LogbookCollections collection; try { collection = LogbookCollections.valueOf(indexParameters.getCollectionName().toUpperCase()); } catch (IllegalArgumentException exc) { String message = String.format("Try to reindex a non operation logbook collection '%s' with operation " + "logbook module", indexParameters .getCollectionName()); LOGGER.error(message); return indexationHelper.getFullKOResult(indexParameters, message); } if (!LogbookCollections.OPERATION.equals(collection)) { String message = String.format("Try to reindex a non operation logbook collection '%s' with operation " + "logbook module", indexParameters .getCollectionName()); LOGGER.error(message); return indexationHelper.getFullKOResult(indexParameters, message); } else { MongoCollection<Document> mongoCollection = collection.getCollection(); try (InputStream mappingStream = ElasticsearchCollections .valueOf(indexParameters.getCollectionName().toUpperCase()) .getMappingAsInputStream()) { return indexationHelper.reindex(mongoCollection, collection.getName(), collection.getEsClient(), indexParameters.getTenants(), mappingStream); } catch (IOException exc) { LOGGER.error("Cannot get '{}' elastic search mapping for tenants {}", collection.name(), indexParameters.getTenants().stream().map(Object::toString).collect(Collectors.joining(", "))); return indexationHelper.getFullKOResult(indexParameters, exc.getMessage()); } } } LogbookOperationsImpl(LogbookDbAccess mongoDbAccess); @VisibleForTesting  LogbookOperationsImpl(LogbookDbAccess mongoDbAccess, WorkspaceClientFactory workspaceClientFactory,
        StorageClientFactory storageClientFactory, IndexationHelper indexationHelper); @Override void create(LogbookOperationParameters parameters); @Override void update(LogbookOperationParameters parameters); @Override List<LogbookOperation> select(JsonNode select); @Override RequestResponse<LogbookOperation> selectOperations(JsonNode select); @Override RequestResponse<LogbookOperation> selectOperations(JsonNode select, boolean sliced); @Override List<LogbookOperation> select(JsonNode select, boolean sliced); @Override LogbookOperation getById(String idProcess); @Override final void createBulkLogbookOperation(final LogbookOperationParameters[] operationArray); @Override final void updateBulkLogbookOperation(final LogbookOperationParameters[] operationArray); @Override MongoCursor<LogbookOperation> selectOperationsByLastPersistenceDateInterval(LocalDateTime startDate,
        LocalDateTime endDate); @Override LogbookOperation findFirstTraceabilityOperationOKAfterDate(final LocalDateTime date); @Override LogbookOperation findLastTraceabilityOperationOK(); @Override IndexationResult reindex(IndexParameters indexParameters); @Override void switchIndex(String alias, String newIndexName); }
LogbookOperationsImpl implements LogbookOperations { @Override public IndexationResult reindex(IndexParameters indexParameters) { LogbookCollections collection; try { collection = LogbookCollections.valueOf(indexParameters.getCollectionName().toUpperCase()); } catch (IllegalArgumentException exc) { String message = String.format("Try to reindex a non operation logbook collection '%s' with operation " + "logbook module", indexParameters .getCollectionName()); LOGGER.error(message); return indexationHelper.getFullKOResult(indexParameters, message); } if (!LogbookCollections.OPERATION.equals(collection)) { String message = String.format("Try to reindex a non operation logbook collection '%s' with operation " + "logbook module", indexParameters .getCollectionName()); LOGGER.error(message); return indexationHelper.getFullKOResult(indexParameters, message); } else { MongoCollection<Document> mongoCollection = collection.getCollection(); try (InputStream mappingStream = ElasticsearchCollections .valueOf(indexParameters.getCollectionName().toUpperCase()) .getMappingAsInputStream()) { return indexationHelper.reindex(mongoCollection, collection.getName(), collection.getEsClient(), indexParameters.getTenants(), mappingStream); } catch (IOException exc) { LOGGER.error("Cannot get '{}' elastic search mapping for tenants {}", collection.name(), indexParameters.getTenants().stream().map(Object::toString).collect(Collectors.joining(", "))); return indexationHelper.getFullKOResult(indexParameters, exc.getMessage()); } } } LogbookOperationsImpl(LogbookDbAccess mongoDbAccess); @VisibleForTesting  LogbookOperationsImpl(LogbookDbAccess mongoDbAccess, WorkspaceClientFactory workspaceClientFactory,
        StorageClientFactory storageClientFactory, IndexationHelper indexationHelper); @Override void create(LogbookOperationParameters parameters); @Override void update(LogbookOperationParameters parameters); @Override List<LogbookOperation> select(JsonNode select); @Override RequestResponse<LogbookOperation> selectOperations(JsonNode select); @Override RequestResponse<LogbookOperation> selectOperations(JsonNode select, boolean sliced); @Override List<LogbookOperation> select(JsonNode select, boolean sliced); @Override LogbookOperation getById(String idProcess); @Override final void createBulkLogbookOperation(final LogbookOperationParameters[] operationArray); @Override final void updateBulkLogbookOperation(final LogbookOperationParameters[] operationArray); @Override MongoCursor<LogbookOperation> selectOperationsByLastPersistenceDateInterval(LocalDateTime startDate,
        LocalDateTime endDate); @Override LogbookOperation findFirstTraceabilityOperationOKAfterDate(final LocalDateTime date); @Override LogbookOperation findLastTraceabilityOperationOK(); @Override IndexationResult reindex(IndexParameters indexParameters); @Override void switchIndex(String alias, String newIndexName);  }