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;
// single file session if (view.isSoftwareModuleSelected()) {
if (view.isSoftwareModuleSelected() && !view.checkIfFileIsDuplicate(event.getFilename(), selectedSwForUpload)) { // single file session
LOG.debug("Upload started for file :{}", event.getFilename()); if (!view.checkIfFileIsDuplicate(event.getFilename(), selectedSwForUpload)) {
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, new UploadFileStatus( LOG.debug("Upload started for file :{}", event.getFilename());
event.getFilename(), 0, 0, selectedSwForUpload))); eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED,
} else { new UploadFileStatus(event.getFilename(), 0, 0, selectedSwForUpload)));
}
}
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,14 +324,20 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
*/ */
@Override @Override
public void uploadFailed(final FailedEvent event) { public void uploadFailed(final FailedEvent event) {
if (failureReason == null) { /**
failureReason = event.getReason().getMessage(); * If upload failed due to no selected software UPLOAD_FAILED event need
} * not be published.
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( */
fileName, failureReason, selectedSwForUpload))); if (selectedSwForUpload != null) {
if (!aborted) { if (failureReason == null) {
LOG.info("Upload failed for file :{}", event.getFilename()); failureReason = event.getReason().getMessage();
LOG.info("Upload failed for file :{}", event.getReason()); }
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());
}
} }
} }