@RunWithCustomExecutor @Test public void should_return_new_offset_when_item_got_graph_is_ok() throws Exception { VitamConfiguration.setAdminTenant(1); when(offsetRepository.findOffsetBy(1, VitamConfiguration.getDefaultStrategy(), DataCategory.OBJECTGROUP_GRAPH.name())).thenReturn(100L); requestItem.setCollection(DataCategory.OBJECTGROUP_GRAPH.name()); when(restoreBackupService.getListing(VitamConfiguration.getDefaultStrategy(), DataCategory.OBJECTGROUP_GRAPH, 100l, requestItem.getLimit(), Order.ASC, VitamConfiguration.getRestoreBulkSize())) .thenReturn(IteratorUtils.arrayIterator(getOfferLog("1970-01-01-00-00-00-000_2018-04-20-17-00-01-444", 100), getOfferLog("2018-04-20-17-00-01-444_2018-05-20-17-00-01-445", 101))); when(restoreBackupService .loadData(VitamConfiguration.getDefaultStrategy(), DataCategory.OBJECTGROUP_GRAPH, "1970-01-01-00-00-00-000_2018-04-20-17-00-01-444")) .thenReturn(new FakeInputStream(1, false)); when(restoreBackupService .loadData(VitamConfiguration.getDefaultStrategy(), DataCategory.OBJECTGROUP_GRAPH, "2018-04-20-17-00-01-444_2018-05-20-17-00-01-445")) .thenReturn(new FakeInputStream(1, true)); when(storageClient.getStorageStrategies()).thenReturn(getStorageStrategies()); ReconstructionService reconstructionService = new ReconstructionService(vitamRepositoryProvider, restoreBackupService, logbookLifecycleClientFactory, storageClientFactory, offsetRepository); FindIterable findIterable = mock(FindIterable.class); final MongoCursor<String> iterator = mock(MongoCursor.class); final Bson projection = include(getComputedGraphObjectGroupFields()); when(mongoRepository.findDocuments(anyList(), eq(projection))).thenReturn(findIterable); when(findIterable.iterator()).thenReturn(iterator); when(iterator.hasNext()).thenReturn(Boolean.FALSE); ReconstructionResponseItem realResponseItem = reconstructionService.reconstruct(requestItem); assertThat(realResponseItem).isNotNull(); assertThat(realResponseItem.getCollection()).isEqualTo(DataCategory.OBJECTGROUP_GRAPH.name()); verify(offsetRepository).createOrUpdateOffset(1, VitamConfiguration.getDefaultStrategy(), DataCategory.OBJECTGROUP_GRAPH.name(), 101L); assertThat(realResponseItem.getTenant()).isEqualTo(1); assertThat(realResponseItem.getStatus()).isEqualTo(StatusCode.OK); }
public ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem) { ParametersChecker.checkParameter(RECONSTRUCTION_ITEM_MANDATORY_MSG, reconstructionItem); ParametersChecker.checkParameter(RECONSTRUCTION_COLLECTION_MANDATORY_MSG, reconstructionItem.getCollection()); ParametersChecker.checkParameter(RECONSTRUCTION_TENANT_MANDATORY_MSG, reconstructionItem.getTenant()); if (reconstructionItem.getLimit() < 0) { throw new IllegalArgumentException(RECONSTRUCTION_LIMIT_POSITIVE_MSG); } LOGGER .info(String.format( "[Reconstruction]: Reconstruction of {%s} Collection on {%s} Vitam tenant", reconstructionItem.getCollection(), reconstructionItem.getTenant())); switch (DataCategory.valueOf(reconstructionItem.getCollection().toUpperCase())) { case UNIT_GRAPH: case OBJECTGROUP_GRAPH: return reconstructGraphFromZipStream(reconstructionItem.getCollection(), reconstructionItem.getLimit()); case UNIT: case OBJECTGROUP: return reconstructCollection(MetadataCollections.getFromValue(reconstructionItem.getCollection()), reconstructionItem.getTenant(), reconstructionItem.getLimit()); default: return new ReconstructionResponseItem(reconstructionItem, StatusCode.KO); } }
ReconstructionService { public ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem) { ParametersChecker.checkParameter(RECONSTRUCTION_ITEM_MANDATORY_MSG, reconstructionItem); ParametersChecker.checkParameter(RECONSTRUCTION_COLLECTION_MANDATORY_MSG, reconstructionItem.getCollection()); ParametersChecker.checkParameter(RECONSTRUCTION_TENANT_MANDATORY_MSG, reconstructionItem.getTenant()); if (reconstructionItem.getLimit() < 0) { throw new IllegalArgumentException(RECONSTRUCTION_LIMIT_POSITIVE_MSG); } LOGGER .info(String.format( "[Reconstruction]: Reconstruction of {%s} Collection on {%s} Vitam tenant", reconstructionItem.getCollection(), reconstructionItem.getTenant())); switch (DataCategory.valueOf(reconstructionItem.getCollection().toUpperCase())) { case UNIT_GRAPH: case OBJECTGROUP_GRAPH: return reconstructGraphFromZipStream(reconstructionItem.getCollection(), reconstructionItem.getLimit()); case UNIT: case OBJECTGROUP: return reconstructCollection(MetadataCollections.getFromValue(reconstructionItem.getCollection()), reconstructionItem.getTenant(), reconstructionItem.getLimit()); default: return new ReconstructionResponseItem(reconstructionItem, StatusCode.KO); } } }
ReconstructionService { public ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem) { ParametersChecker.checkParameter(RECONSTRUCTION_ITEM_MANDATORY_MSG, reconstructionItem); ParametersChecker.checkParameter(RECONSTRUCTION_COLLECTION_MANDATORY_MSG, reconstructionItem.getCollection()); ParametersChecker.checkParameter(RECONSTRUCTION_TENANT_MANDATORY_MSG, reconstructionItem.getTenant()); if (reconstructionItem.getLimit() < 0) { throw new IllegalArgumentException(RECONSTRUCTION_LIMIT_POSITIVE_MSG); } LOGGER .info(String.format( "[Reconstruction]: Reconstruction of {%s} Collection on {%s} Vitam tenant", reconstructionItem.getCollection(), reconstructionItem.getTenant())); switch (DataCategory.valueOf(reconstructionItem.getCollection().toUpperCase())) { case UNIT_GRAPH: case OBJECTGROUP_GRAPH: return reconstructGraphFromZipStream(reconstructionItem.getCollection(), reconstructionItem.getLimit()); case UNIT: case OBJECTGROUP: return reconstructCollection(MetadataCollections.getFromValue(reconstructionItem.getCollection()), reconstructionItem.getTenant(), reconstructionItem.getLimit()); default: return new ReconstructionResponseItem(reconstructionItem, StatusCode.KO); } } ReconstructionService(VitamRepositoryProvider vitamRepositoryProvider,
        OffsetRepository offsetRepository); @VisibleForTesting  ReconstructionService(VitamRepositoryProvider vitamRepositoryProvider,
        RestoreBackupService recoverBackupService, LogbookLifeCyclesClientFactory logbookLifecycleClientFactory,
        StorageClientFactory storageClientFactory, OffsetRepository offsetRepository); }
ReconstructionService { public ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem) { ParametersChecker.checkParameter(RECONSTRUCTION_ITEM_MANDATORY_MSG, reconstructionItem); ParametersChecker.checkParameter(RECONSTRUCTION_COLLECTION_MANDATORY_MSG, reconstructionItem.getCollection()); ParametersChecker.checkParameter(RECONSTRUCTION_TENANT_MANDATORY_MSG, reconstructionItem.getTenant()); if (reconstructionItem.getLimit() < 0) { throw new IllegalArgumentException(RECONSTRUCTION_LIMIT_POSITIVE_MSG); } LOGGER .info(String.format( "[Reconstruction]: Reconstruction of {%s} Collection on {%s} Vitam tenant", reconstructionItem.getCollection(), reconstructionItem.getTenant())); switch (DataCategory.valueOf(reconstructionItem.getCollection().toUpperCase())) { case UNIT_GRAPH: case OBJECTGROUP_GRAPH: return reconstructGraphFromZipStream(reconstructionItem.getCollection(), reconstructionItem.getLimit()); case UNIT: case OBJECTGROUP: return reconstructCollection(MetadataCollections.getFromValue(reconstructionItem.getCollection()), reconstructionItem.getTenant(), reconstructionItem.getLimit()); default: return new ReconstructionResponseItem(reconstructionItem, StatusCode.KO); } } ReconstructionService(VitamRepositoryProvider vitamRepositoryProvider,
        OffsetRepository offsetRepository); @VisibleForTesting  ReconstructionService(VitamRepositoryProvider vitamRepositoryProvider,
        RestoreBackupService recoverBackupService, LogbookLifeCyclesClientFactory logbookLifecycleClientFactory,
        StorageClientFactory storageClientFactory, OffsetRepository offsetRepository); ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem); void purgeReconstructedDocumentsWithGraphOnlyData(MetadataCollections metaDaCollection); }
ReconstructionService { public ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem) { ParametersChecker.checkParameter(RECONSTRUCTION_ITEM_MANDATORY_MSG, reconstructionItem); ParametersChecker.checkParameter(RECONSTRUCTION_COLLECTION_MANDATORY_MSG, reconstructionItem.getCollection()); ParametersChecker.checkParameter(RECONSTRUCTION_TENANT_MANDATORY_MSG, reconstructionItem.getTenant()); if (reconstructionItem.getLimit() < 0) { throw new IllegalArgumentException(RECONSTRUCTION_LIMIT_POSITIVE_MSG); } LOGGER .info(String.format( "[Reconstruction]: Reconstruction of {%s} Collection on {%s} Vitam tenant", reconstructionItem.getCollection(), reconstructionItem.getTenant())); switch (DataCategory.valueOf(reconstructionItem.getCollection().toUpperCase())) { case UNIT_GRAPH: case OBJECTGROUP_GRAPH: return reconstructGraphFromZipStream(reconstructionItem.getCollection(), reconstructionItem.getLimit()); case UNIT: case OBJECTGROUP: return reconstructCollection(MetadataCollections.getFromValue(reconstructionItem.getCollection()), reconstructionItem.getTenant(), reconstructionItem.getLimit()); default: return new ReconstructionResponseItem(reconstructionItem, StatusCode.KO); } } ReconstructionService(VitamRepositoryProvider vitamRepositoryProvider,
        OffsetRepository offsetRepository); @VisibleForTesting  ReconstructionService(VitamRepositoryProvider vitamRepositoryProvider,
        RestoreBackupService recoverBackupService, LogbookLifeCyclesClientFactory logbookLifecycleClientFactory,
        StorageClientFactory storageClientFactory, OffsetRepository offsetRepository); ReconstructionResponseItem reconstruct(ReconstructionRequestItem reconstructionItem); void purgeReconstructedDocumentsWithGraphOnlyData(MetadataCollections metaDaCollection);  }