@RunWithCustomExecutor @Test public void should_get_null_when_loading_and_storage_returns_file_unit_without_lfc() throws StorageServerClientException, StorageNotFoundException, FileNotFoundException { when(storageClientFactory.getClient().getContainerAsync(VitamConfiguration.getDefaultStrategy(), "100.json", DataCategory.UNIT, AccessLogUtils.getNoLogAccessLog())) .thenReturn( new FakeInboundResponse(Status.OK, PropertiesUtils.getResourceAsStream("reconstruction_unit_no_lfc.json"), MediaType.APPLICATION_OCTET_STREAM_TYPE, null)); RestoreBackupService restoreBackupService = new RestoreBackupService(storageClientFactory); MetadataBackupModel model = restoreBackupService.loadData(VitamConfiguration.getDefaultStrategy(), MetadataCollections.UNIT, "100.json", 100L); assertThat(model).isNull(); }
public MetadataBackupModel loadData(String strategy, MetadataCollections collection, String filename, long offset) throws StorageNotFoundException { LOGGER .info(String.format( "[Reconstruction]: Retrieve file {%s} from storage of {%s} Collection on {%s} Vitam strategy", filename, collection.name(), strategy)); InputStream inputStream = null; try { DataCategory type; switch (collection) { case UNIT: type = DataCategory.UNIT; break; case OBJECTGROUP: type = DataCategory.OBJECTGROUP; break; default: throw new IllegalArgumentException(String.format("ERROR: Invalid collection {%s}", collection)); } inputStream = loadData(strategy, type, filename); MetadataBackupModel metadataBackupModel = JsonHandler.getFromInputStream(inputStream, MetadataBackupModel.class); if (metadataBackupModel.getMetadatas() != null && metadataBackupModel.getLifecycle() != null) { metadataBackupModel.setOffset(offset); return metadataBackupModel; } } catch (InvalidParseOperationException e) { throw new VitamRuntimeException("ERROR: Exception has been thrown when using storage service:", e); } finally { IOUtils.closeQuietly(inputStream); } return null; }
RestoreBackupService { public MetadataBackupModel loadData(String strategy, MetadataCollections collection, String filename, long offset) throws StorageNotFoundException { LOGGER .info(String.format( "[Reconstruction]: Retrieve file {%s} from storage of {%s} Collection on {%s} Vitam strategy", filename, collection.name(), strategy)); InputStream inputStream = null; try { DataCategory type; switch (collection) { case UNIT: type = DataCategory.UNIT; break; case OBJECTGROUP: type = DataCategory.OBJECTGROUP; break; default: throw new IllegalArgumentException(String.format("ERROR: Invalid collection {%s}", collection)); } inputStream = loadData(strategy, type, filename); MetadataBackupModel metadataBackupModel = JsonHandler.getFromInputStream(inputStream, MetadataBackupModel.class); if (metadataBackupModel.getMetadatas() != null && metadataBackupModel.getLifecycle() != null) { metadataBackupModel.setOffset(offset); return metadataBackupModel; } } catch (InvalidParseOperationException e) { throw new VitamRuntimeException("ERROR: Exception has been thrown when using storage service:", e); } finally { IOUtils.closeQuietly(inputStream); } return null; } }
RestoreBackupService { public MetadataBackupModel loadData(String strategy, MetadataCollections collection, String filename, long offset) throws StorageNotFoundException { LOGGER .info(String.format( "[Reconstruction]: Retrieve file {%s} from storage of {%s} Collection on {%s} Vitam strategy", filename, collection.name(), strategy)); InputStream inputStream = null; try { DataCategory type; switch (collection) { case UNIT: type = DataCategory.UNIT; break; case OBJECTGROUP: type = DataCategory.OBJECTGROUP; break; default: throw new IllegalArgumentException(String.format("ERROR: Invalid collection {%s}", collection)); } inputStream = loadData(strategy, type, filename); MetadataBackupModel metadataBackupModel = JsonHandler.getFromInputStream(inputStream, MetadataBackupModel.class); if (metadataBackupModel.getMetadatas() != null && metadataBackupModel.getLifecycle() != null) { metadataBackupModel.setOffset(offset); return metadataBackupModel; } } catch (InvalidParseOperationException e) { throw new VitamRuntimeException("ERROR: Exception has been thrown when using storage service:", e); } finally { IOUtils.closeQuietly(inputStream); } return null; } RestoreBackupService(); @VisibleForTesting  RestoreBackupService(StorageClientFactory storageClientFactory); }
RestoreBackupService { public MetadataBackupModel loadData(String strategy, MetadataCollections collection, String filename, long offset) throws StorageNotFoundException { LOGGER .info(String.format( "[Reconstruction]: Retrieve file {%s} from storage of {%s} Collection on {%s} Vitam strategy", filename, collection.name(), strategy)); InputStream inputStream = null; try { DataCategory type; switch (collection) { case UNIT: type = DataCategory.UNIT; break; case OBJECTGROUP: type = DataCategory.OBJECTGROUP; break; default: throw new IllegalArgumentException(String.format("ERROR: Invalid collection {%s}", collection)); } inputStream = loadData(strategy, type, filename); MetadataBackupModel metadataBackupModel = JsonHandler.getFromInputStream(inputStream, MetadataBackupModel.class); if (metadataBackupModel.getMetadatas() != null && metadataBackupModel.getLifecycle() != null) { metadataBackupModel.setOffset(offset); return metadataBackupModel; } } catch (InvalidParseOperationException e) { throw new VitamRuntimeException("ERROR: Exception has been thrown when using storage service:", e); } finally { IOUtils.closeQuietly(inputStream); } return null; } RestoreBackupService(); @VisibleForTesting  RestoreBackupService(StorageClientFactory storageClientFactory); Iterator<OfferLog> getListing(String strategy, DataCategory category, Long offset, Integer limit, Order order,
        int batchSize); MetadataBackupModel loadData(String strategy, MetadataCollections collection, String filename,
        long offset); InputStream loadData(String strategy, DataCategory category, String filename); }
RestoreBackupService { public MetadataBackupModel loadData(String strategy, MetadataCollections collection, String filename, long offset) throws StorageNotFoundException { LOGGER .info(String.format( "[Reconstruction]: Retrieve file {%s} from storage of {%s} Collection on {%s} Vitam strategy", filename, collection.name(), strategy)); InputStream inputStream = null; try { DataCategory type; switch (collection) { case UNIT: type = DataCategory.UNIT; break; case OBJECTGROUP: type = DataCategory.OBJECTGROUP; break; default: throw new IllegalArgumentException(String.format("ERROR: Invalid collection {%s}", collection)); } inputStream = loadData(strategy, type, filename); MetadataBackupModel metadataBackupModel = JsonHandler.getFromInputStream(inputStream, MetadataBackupModel.class); if (metadataBackupModel.getMetadatas() != null && metadataBackupModel.getLifecycle() != null) { metadataBackupModel.setOffset(offset); return metadataBackupModel; } } catch (InvalidParseOperationException e) { throw new VitamRuntimeException("ERROR: Exception has been thrown when using storage service:", e); } finally { IOUtils.closeQuietly(inputStream); } return null; } RestoreBackupService(); @VisibleForTesting  RestoreBackupService(StorageClientFactory storageClientFactory); Iterator<OfferLog> getListing(String strategy, DataCategory category, Long offset, Integer limit, Order order,
        int batchSize); MetadataBackupModel loadData(String strategy, MetadataCollections collection, String filename,
        long offset); InputStream loadData(String strategy, DataCategory category, String filename);  }