From 223e0f6c857a55e6392ec1fd8ef27a055030b459 Mon Sep 17 00:00:00 2001 From: AMU7KOR Date: Fri, 3 Jun 2016 10:02:50 +0530 Subject: [PATCH] Fix: Interupt upload if software moudle is not selected Signed-off-by: AMU7KOR --- .../ui/artifacts/upload/UploadHandler.java | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index 61f68f397..78a6fd9a9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -133,7 +133,6 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public OutputStream receiveUpload(final String fileName, final String mimeType) { - uploadInterrupted = false; aborted = false; failureReason = null; this.fileName = fileName; @@ -214,17 +213,23 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public void uploadStarted(final StartedEvent event) { - selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().get(); + uploadInterrupted = false; + selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().isPresent() ? artifactUploadState + .getSelectedBaseSoftwareModule().get() : null; - // single file session - if (view.isSoftwareModuleSelected() && !view.checkIfFileIsDuplicate(event.getFilename(), selectedSwForUpload)) { - LOG.debug("Upload started for file :{}", event.getFilename()); - eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, new UploadFileStatus( - event.getFilename(), 0, 0, selectedSwForUpload))); - } else { + if (view.isSoftwareModuleSelected()) { + // single file session + if (!view.checkIfFileIsDuplicate(event.getFilename(), selectedSwForUpload)) { + LOG.debug("Upload started for file :{}", event.getFilename()); + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, + new UploadFileStatus(event.getFilename(), 0, 0, selectedSwForUpload))); + } + } + else { failureReason = i18n.get("message.upload.failed"); upload.interruptUpload(); - // actual interrupt will happen a bit late so setting the below flag + // actual interrupt will happen a bit late so setting the below + // flag uploadInterrupted = true; } } @@ -319,14 +324,20 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public void uploadFailed(final FailedEvent event) { - if (failureReason == null) { - failureReason = event.getReason().getMessage(); - } - eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( - fileName, failureReason, selectedSwForUpload))); - if (!aborted) { - LOG.info("Upload failed for file :{}", event.getFilename()); - LOG.info("Upload failed for file :{}", event.getReason()); + /** + * If upload failed due to no selected software UPLOAD_FAILED event need + * not be published. + */ + if (selectedSwForUpload != null) { + if (failureReason == null) { + failureReason = event.getReason().getMessage(); + } + eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( + fileName, failureReason, selectedSwForUpload))); + if (!aborted) { + LOG.info("Upload failed for file :{}", event.getFilename()); + LOG.info("Upload failed for file :{}", event.getReason()); + } } }