@RunWithCustomExecutor @Test public void should_return_request_offset_when_metadata_null() throws Exception { when(offsetRepository.findOffsetBy(10, STRATEGY_UNIT, MetadataCollections.UNIT.getName())).thenReturn(100L); MetadataBackupModel metadataBackupModel100 = getUnitMetadataBackupModel("100", 100L); metadataBackupModel100.setUnit(null); when(restoreBackupService.getListing(STRATEGY_UNIT, DataCategory.UNIT, 100l, requestItem.getLimit(), Order.ASC, VitamConfiguration.getRestoreBulkSize())) .thenReturn(IteratorUtils.arrayIterator(getOfferLog(100), getOfferLog(101))); when(restoreBackupService.loadData(STRATEGY_UNIT, MetadataCollections.UNIT, "100", 100L)) .thenReturn(metadataBackupModel100); when(restoreBackupService.loadData(STRATEGY_UNIT, MetadataCollections.UNIT, "101", 101L)) .thenReturn(getUnitMetadataBackupModel("101", 101L)); when(storageClient.getStorageStrategies()).thenReturn(getStorageStrategies()); ReconstructionService reconstructionService = new ReconstructionService(vitamRepositoryProvider, restoreBackupService, logbookLifecycleClientFactory, storageClientFactory, offsetRepository); ReconstructionResponseItem realResponseItem = reconstructionService.reconstruct(requestItem); assertThat(realResponseItem).isNotNull(); assertThat(realResponseItem.getCollection()).isEqualTo(MetadataCollections.UNIT.name()); assertThat(realResponseItem.getTenant()).isEqualTo(10); assertThat(realResponseItem.getStatus()).isEqualTo(StatusCode.KO); }
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);  }