@Test public void should_save_atr_and_context_successfully() throws Exception { doReturn(createATR()).when(handler).getInput(0); doReturn("container").when(handler).getContainerName(); StoredInfoResult storedInfo = new StoredInfoResult(); storedInfo.setOfferIds(Collections.emptyList()); when(storageClient.storeFileFromWorkspace(anyString(), any(), anyString(), any())).thenReturn(storedInfo); ItemStatus execute = saveAtrPlugin.execute(null, handler); assertThat(execute.getGlobalStatus()).isEqualTo(OK); verify(storageClient).storeFileFromWorkspace(anyString(), any(), anyString(), any()); }
@Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { ArchiveTransferReplyType atr = (ArchiveTransferReplyType) handler.getInput(0); try (StorageClient storageClient = storageClientFactory.getClient()) { String messageIdentifier = atr.getMessageIdentifier().getValue(); ObjectDescription description = getDescription(messageIdentifier, handler.getContainerName()); StoredInfoResult storedInfo = storageClient.storeFileFromWorkspace(VitamConfiguration.getDefaultStrategy(), description.getType(), description.getObjectName(), description); handler.addOutputResult(0, atr); return buildItemStatus(PLUGIN_NAME, OK, Collections.singletonMap(messageIdentifier, BinaryEventData.from(storedInfo))); } catch (StorageAlreadyExistsClientException e) { LOGGER.warn(e); return buildItemStatus(PLUGIN_NAME, WARNING, EventDetails.of(e.getMessage(), "ATR already exists but it will continue.")); } catch (StorageNotFoundClientException | StorageServerClientException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, FATAL, EventDetails.of(e.getMessage())); } }
SaveAtrPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { ArchiveTransferReplyType atr = (ArchiveTransferReplyType) handler.getInput(0); try (StorageClient storageClient = storageClientFactory.getClient()) { String messageIdentifier = atr.getMessageIdentifier().getValue(); ObjectDescription description = getDescription(messageIdentifier, handler.getContainerName()); StoredInfoResult storedInfo = storageClient.storeFileFromWorkspace(VitamConfiguration.getDefaultStrategy(), description.getType(), description.getObjectName(), description); handler.addOutputResult(0, atr); return buildItemStatus(PLUGIN_NAME, OK, Collections.singletonMap(messageIdentifier, BinaryEventData.from(storedInfo))); } catch (StorageAlreadyExistsClientException e) { LOGGER.warn(e); return buildItemStatus(PLUGIN_NAME, WARNING, EventDetails.of(e.getMessage(), "ATR already exists but it will continue.")); } catch (StorageNotFoundClientException | StorageServerClientException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, FATAL, EventDetails.of(e.getMessage())); } } }
SaveAtrPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { ArchiveTransferReplyType atr = (ArchiveTransferReplyType) handler.getInput(0); try (StorageClient storageClient = storageClientFactory.getClient()) { String messageIdentifier = atr.getMessageIdentifier().getValue(); ObjectDescription description = getDescription(messageIdentifier, handler.getContainerName()); StoredInfoResult storedInfo = storageClient.storeFileFromWorkspace(VitamConfiguration.getDefaultStrategy(), description.getType(), description.getObjectName(), description); handler.addOutputResult(0, atr); return buildItemStatus(PLUGIN_NAME, OK, Collections.singletonMap(messageIdentifier, BinaryEventData.from(storedInfo))); } catch (StorageAlreadyExistsClientException e) { LOGGER.warn(e); return buildItemStatus(PLUGIN_NAME, WARNING, EventDetails.of(e.getMessage(), "ATR already exists but it will continue.")); } catch (StorageNotFoundClientException | StorageServerClientException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, FATAL, EventDetails.of(e.getMessage())); } } SaveAtrPlugin(); @VisibleForTesting  SaveAtrPlugin(StorageClientFactory storageClientFactory); }
SaveAtrPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { ArchiveTransferReplyType atr = (ArchiveTransferReplyType) handler.getInput(0); try (StorageClient storageClient = storageClientFactory.getClient()) { String messageIdentifier = atr.getMessageIdentifier().getValue(); ObjectDescription description = getDescription(messageIdentifier, handler.getContainerName()); StoredInfoResult storedInfo = storageClient.storeFileFromWorkspace(VitamConfiguration.getDefaultStrategy(), description.getType(), description.getObjectName(), description); handler.addOutputResult(0, atr); return buildItemStatus(PLUGIN_NAME, OK, Collections.singletonMap(messageIdentifier, BinaryEventData.from(storedInfo))); } catch (StorageAlreadyExistsClientException e) { LOGGER.warn(e); return buildItemStatus(PLUGIN_NAME, WARNING, EventDetails.of(e.getMessage(), "ATR already exists but it will continue.")); } catch (StorageNotFoundClientException | StorageServerClientException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, FATAL, EventDetails.of(e.getMessage())); } } SaveAtrPlugin(); @VisibleForTesting  SaveAtrPlugin(StorageClientFactory storageClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); }
SaveAtrPlugin extends ActionHandler { @Override public ItemStatus execute(WorkerParameters param, HandlerIO handler) throws ProcessingException { ArchiveTransferReplyType atr = (ArchiveTransferReplyType) handler.getInput(0); try (StorageClient storageClient = storageClientFactory.getClient()) { String messageIdentifier = atr.getMessageIdentifier().getValue(); ObjectDescription description = getDescription(messageIdentifier, handler.getContainerName()); StoredInfoResult storedInfo = storageClient.storeFileFromWorkspace(VitamConfiguration.getDefaultStrategy(), description.getType(), description.getObjectName(), description); handler.addOutputResult(0, atr); return buildItemStatus(PLUGIN_NAME, OK, Collections.singletonMap(messageIdentifier, BinaryEventData.from(storedInfo))); } catch (StorageAlreadyExistsClientException e) { LOGGER.warn(e); return buildItemStatus(PLUGIN_NAME, WARNING, EventDetails.of(e.getMessage(), "ATR already exists but it will continue.")); } catch (StorageNotFoundClientException | StorageServerClientException e) { LOGGER.error(e); return buildItemStatus(PLUGIN_NAME, FATAL, EventDetails.of(e.getMessage())); } } SaveAtrPlugin(); @VisibleForTesting  SaveAtrPlugin(StorageClientFactory storageClientFactory); @Override ItemStatus execute(WorkerParameters param, HandlerIO handler); static final String PLUGIN_NAME; }