@Test public void should_add_result_with_stored_info() throws Exception { OutputPreservation output = new OutputPreservation(); output.setStatus(PreservationStatus.OK); output.setAction(ActionTypePreservation.GENERATE); output.setOutputName("outputName"); OutputExtra outputExtra = new OutputExtra(output, "binaryGUID", Optional.of(42L), Optional.of("42424242424242424242"), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty()); List<OutputExtra> outputExtras = Arrays.asList(outputExtra); List<WorkflowBatchResult> workflowBatchResults = Collections.singletonList(WorkflowBatchResult.of("", "", "", "", outputExtras, "", "other_binary_strategy")); File file = tmpGriffinFolder.newFolder(OUTPUT_FILES); Files.createFile(file.toPath().resolve(output.getOutputName())); WorkflowBatchResults batchResults = new WorkflowBatchResults(tmpGriffinFolder.getRoot().toPath(), workflowBatchResults); handler.addOutputResult(0, batchResults); StoredInfoResult storedInfo = new StoredInfoResult(); storedInfo.setId("id"); storedInfo.setDigest("42424242424242424242"); storedInfo.setDigestType("SHA"); storedInfo.setOfferIds(Collections.singletonList("offer.42.consul")); given(backupService.backup(any(), eq(DataCategory.OBJECT), anyString(), eq("other_binary_strategy"))).willReturn(storedInfo); storageBinaryPlugin.executeList(null, handler); assertThat(((WorkflowBatchResults) handler.getInput(0)).getWorkflowBatchResults()) .extracting(w -> w.getOutputExtras().get(0).getStoredInfo()) .extracting(Optional::get) .extracting(StoredInfoResult::getDigest) .containsOnly("42424242424242424242"); }
@Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { logger.info("Starting PRESERVATION_STORAGE_BINARY."); handler.setCurrentObjectId(WorkflowBatchResults.NAME); WorkflowBatchResults results = (WorkflowBatchResults) handler.getInput(0); Path outputFiles = results.getBatchDirectory().resolve(OUTPUT_FILES); List<ItemStatus> itemStatuses = new ArrayList<>(); List<WorkflowBatchResult> workflowBatchResults = new ArrayList<>(); for (WorkflowBatchResult workflowBatchResult : results.getWorkflowBatchResults()) { List<OutputExtra> outputExtras = workflowBatchResult.getOutputExtras() .stream() .filter(OutputExtra::isOkAndGenerated) .map(a -> getOutputExtra(outputFiles, a, workflowBatchResult.getSourceStrategy())) .collect(Collectors.toList()); if (outputExtras.isEmpty()) { workflowBatchResults.add(workflowBatchResult); ItemStatus itemStatus = new ItemStatus(ITEM_ID); itemStatus.disableLfc(); itemStatuses.add(itemStatus); continue; } itemStatuses.add(getItemStatus(outputExtras)); Stream<OutputExtra> otherActions = workflowBatchResult.getOutputExtras() .stream() .filter(o -> !o.isOkAndGenerated()); List<OutputExtra> previousAndNewExtras = Stream.concat(otherActions, outputExtras.stream().filter(outputExtra -> !outputExtra.isInError())) .collect(Collectors.toList()); workflowBatchResults.add(WorkflowBatchResult.of(workflowBatchResult, previousAndNewExtras)); } handler.addOutputResult(0, new WorkflowBatchResults(results.getBatchDirectory(), workflowBatchResults)); return itemStatuses; }
PreservationStorageBinaryPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { logger.info("Starting PRESERVATION_STORAGE_BINARY."); handler.setCurrentObjectId(WorkflowBatchResults.NAME); WorkflowBatchResults results = (WorkflowBatchResults) handler.getInput(0); Path outputFiles = results.getBatchDirectory().resolve(OUTPUT_FILES); List<ItemStatus> itemStatuses = new ArrayList<>(); List<WorkflowBatchResult> workflowBatchResults = new ArrayList<>(); for (WorkflowBatchResult workflowBatchResult : results.getWorkflowBatchResults()) { List<OutputExtra> outputExtras = workflowBatchResult.getOutputExtras() .stream() .filter(OutputExtra::isOkAndGenerated) .map(a -> getOutputExtra(outputFiles, a, workflowBatchResult.getSourceStrategy())) .collect(Collectors.toList()); if (outputExtras.isEmpty()) { workflowBatchResults.add(workflowBatchResult); ItemStatus itemStatus = new ItemStatus(ITEM_ID); itemStatus.disableLfc(); itemStatuses.add(itemStatus); continue; } itemStatuses.add(getItemStatus(outputExtras)); Stream<OutputExtra> otherActions = workflowBatchResult.getOutputExtras() .stream() .filter(o -> !o.isOkAndGenerated()); List<OutputExtra> previousAndNewExtras = Stream.concat(otherActions, outputExtras.stream().filter(outputExtra -> !outputExtra.isInError())) .collect(Collectors.toList()); workflowBatchResults.add(WorkflowBatchResult.of(workflowBatchResult, previousAndNewExtras)); } handler.addOutputResult(0, new WorkflowBatchResults(results.getBatchDirectory(), workflowBatchResults)); return itemStatuses; } }
PreservationStorageBinaryPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { logger.info("Starting PRESERVATION_STORAGE_BINARY."); handler.setCurrentObjectId(WorkflowBatchResults.NAME); WorkflowBatchResults results = (WorkflowBatchResults) handler.getInput(0); Path outputFiles = results.getBatchDirectory().resolve(OUTPUT_FILES); List<ItemStatus> itemStatuses = new ArrayList<>(); List<WorkflowBatchResult> workflowBatchResults = new ArrayList<>(); for (WorkflowBatchResult workflowBatchResult : results.getWorkflowBatchResults()) { List<OutputExtra> outputExtras = workflowBatchResult.getOutputExtras() .stream() .filter(OutputExtra::isOkAndGenerated) .map(a -> getOutputExtra(outputFiles, a, workflowBatchResult.getSourceStrategy())) .collect(Collectors.toList()); if (outputExtras.isEmpty()) { workflowBatchResults.add(workflowBatchResult); ItemStatus itemStatus = new ItemStatus(ITEM_ID); itemStatus.disableLfc(); itemStatuses.add(itemStatus); continue; } itemStatuses.add(getItemStatus(outputExtras)); Stream<OutputExtra> otherActions = workflowBatchResult.getOutputExtras() .stream() .filter(o -> !o.isOkAndGenerated()); List<OutputExtra> previousAndNewExtras = Stream.concat(otherActions, outputExtras.stream().filter(outputExtra -> !outputExtra.isInError())) .collect(Collectors.toList()); workflowBatchResults.add(WorkflowBatchResult.of(workflowBatchResult, previousAndNewExtras)); } handler.addOutputResult(0, new WorkflowBatchResults(results.getBatchDirectory(), workflowBatchResults)); return itemStatuses; } PreservationStorageBinaryPlugin(); @VisibleForTesting private  PreservationStorageBinaryPlugin(BackupService backupService); }
PreservationStorageBinaryPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { logger.info("Starting PRESERVATION_STORAGE_BINARY."); handler.setCurrentObjectId(WorkflowBatchResults.NAME); WorkflowBatchResults results = (WorkflowBatchResults) handler.getInput(0); Path outputFiles = results.getBatchDirectory().resolve(OUTPUT_FILES); List<ItemStatus> itemStatuses = new ArrayList<>(); List<WorkflowBatchResult> workflowBatchResults = new ArrayList<>(); for (WorkflowBatchResult workflowBatchResult : results.getWorkflowBatchResults()) { List<OutputExtra> outputExtras = workflowBatchResult.getOutputExtras() .stream() .filter(OutputExtra::isOkAndGenerated) .map(a -> getOutputExtra(outputFiles, a, workflowBatchResult.getSourceStrategy())) .collect(Collectors.toList()); if (outputExtras.isEmpty()) { workflowBatchResults.add(workflowBatchResult); ItemStatus itemStatus = new ItemStatus(ITEM_ID); itemStatus.disableLfc(); itemStatuses.add(itemStatus); continue; } itemStatuses.add(getItemStatus(outputExtras)); Stream<OutputExtra> otherActions = workflowBatchResult.getOutputExtras() .stream() .filter(o -> !o.isOkAndGenerated()); List<OutputExtra> previousAndNewExtras = Stream.concat(otherActions, outputExtras.stream().filter(outputExtra -> !outputExtra.isInError())) .collect(Collectors.toList()); workflowBatchResults.add(WorkflowBatchResult.of(workflowBatchResult, previousAndNewExtras)); } handler.addOutputResult(0, new WorkflowBatchResults(results.getBatchDirectory(), workflowBatchResults)); return itemStatuses; } PreservationStorageBinaryPlugin(); @VisibleForTesting private  PreservationStorageBinaryPlugin(BackupService backupService); @Override List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler); }
PreservationStorageBinaryPlugin extends ActionHandler { @Override public List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler) throws ProcessingException { logger.info("Starting PRESERVATION_STORAGE_BINARY."); handler.setCurrentObjectId(WorkflowBatchResults.NAME); WorkflowBatchResults results = (WorkflowBatchResults) handler.getInput(0); Path outputFiles = results.getBatchDirectory().resolve(OUTPUT_FILES); List<ItemStatus> itemStatuses = new ArrayList<>(); List<WorkflowBatchResult> workflowBatchResults = new ArrayList<>(); for (WorkflowBatchResult workflowBatchResult : results.getWorkflowBatchResults()) { List<OutputExtra> outputExtras = workflowBatchResult.getOutputExtras() .stream() .filter(OutputExtra::isOkAndGenerated) .map(a -> getOutputExtra(outputFiles, a, workflowBatchResult.getSourceStrategy())) .collect(Collectors.toList()); if (outputExtras.isEmpty()) { workflowBatchResults.add(workflowBatchResult); ItemStatus itemStatus = new ItemStatus(ITEM_ID); itemStatus.disableLfc(); itemStatuses.add(itemStatus); continue; } itemStatuses.add(getItemStatus(outputExtras)); Stream<OutputExtra> otherActions = workflowBatchResult.getOutputExtras() .stream() .filter(o -> !o.isOkAndGenerated()); List<OutputExtra> previousAndNewExtras = Stream.concat(otherActions, outputExtras.stream().filter(outputExtra -> !outputExtra.isInError())) .collect(Collectors.toList()); workflowBatchResults.add(WorkflowBatchResult.of(workflowBatchResult, previousAndNewExtras)); } handler.addOutputResult(0, new WorkflowBatchResults(results.getBatchDirectory(), workflowBatchResults)); return itemStatuses; } PreservationStorageBinaryPlugin(); @VisibleForTesting private  PreservationStorageBinaryPlugin(BackupService backupService); @Override List<ItemStatus> executeList(WorkerParameters workerParameters, HandlerIO handler); static final String ITEM_ID; }