Fix: Interupt upload if software moudle is not selected

Signed-off-by: AMU7KOR <Asharani.Murugesh@in.bosch.com>
This commit is contained in:
AMU7KOR
2016-06-03 10:02:50 +05:30
parent 1fe267c5c3
commit 223e0f6c85

View File

@@ -133,7 +133,6 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
*/ */
@Override @Override
public OutputStream receiveUpload(final String fileName, final String mimeType) { public OutputStream receiveUpload(final String fileName, final String mimeType) {
uploadInterrupted = false;
aborted = false; aborted = false;
failureReason = null; failureReason = null;
this.fileName = fileName; this.fileName = fileName;
@@ -214,17 +213,23 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
*/ */
@Override @Override
public void uploadStarted(final StartedEvent event) { public void uploadStarted(final StartedEvent event) {
selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().get(); uploadInterrupted = false;
selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().isPresent() ? artifactUploadState
.getSelectedBaseSoftwareModule().get() : null;
if (view.isSoftwareModuleSelected()) {
// single file session // single file session
if (view.isSoftwareModuleSelected() && !view.checkIfFileIsDuplicate(event.getFilename(), selectedSwForUpload)) { if (!view.checkIfFileIsDuplicate(event.getFilename(), selectedSwForUpload)) {
LOG.debug("Upload started for file :{}", event.getFilename()); LOG.debug("Upload started for file :{}", event.getFilename());
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, new UploadFileStatus( eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED,
event.getFilename(), 0, 0, selectedSwForUpload))); new UploadFileStatus(event.getFilename(), 0, 0, selectedSwForUpload)));
} else { }
}
else {
failureReason = i18n.get("message.upload.failed"); failureReason = i18n.get("message.upload.failed");
upload.interruptUpload(); 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; uploadInterrupted = true;
} }
} }
@@ -319,6 +324,11 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
*/ */
@Override @Override
public void uploadFailed(final FailedEvent event) { public void uploadFailed(final FailedEvent event) {
/**
* If upload failed due to no selected software UPLOAD_FAILED event need
* not be published.
*/
if (selectedSwForUpload != null) {
if (failureReason == null) { if (failureReason == null) {
failureReason = event.getReason().getMessage(); failureReason = event.getReason().getMessage();
} }
@@ -329,6 +339,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
LOG.info("Upload failed for file :{}", event.getReason()); LOG.info("Upload failed for file :{}", event.getReason());
} }
} }
}
/** /**
* to check if upload is interrupted. * to check if upload is interrupted.