From a774412055645759be25942342402c61f3ceb076 Mon Sep 17 00:00:00 2001 From: Asharani Date: Wed, 18 May 2016 11:14:51 +0530 Subject: [PATCH] Bug fix : During upload the files when changing the selection of the software module the upload also changes to the new selected software module Signed-off-by: Asharani --- .../ui/artifacts/event/UploadFileStatus.java | 3 +- .../ui/artifacts/upload/UploadHandler.java | 19 ++++---- .../ui/artifacts/upload/UploadLayout.java | 45 +++++++------------ 3 files changed, 29 insertions(+), 38 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java index f594fad8b..81b096c3e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/event/UploadFileStatus.java @@ -35,10 +35,11 @@ public class UploadFileStatus implements Serializable { this.fileName = fileName; } - public UploadFileStatus(String fileName, long bytesRead, long contentLength) { + public UploadFileStatus(String fileName, long bytesRead, long contentLength,SoftwareModule softwareModule) { this.fileName = fileName; this.contentLength = contentLength; this.bytesRead = bytesRead; + this.softwareModule = softwareModule; } public UploadFileStatus(String fileName, String failureReason,SoftwareModule selectedSw) { 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 277e56967..848fa2da5 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 @@ -121,9 +121,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene // reset has directory flag before upload view.setHasDirectory(false); try { - if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName)) { + if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName, selectedSwForUpload)) { view.increaseNumberOfFileUploadsExpected(); - selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().get(); return view.saveUploadedFileDetails(fileName, 0, mimeType, selectedSwForUpload); } } catch (final ArtifactUploadFailedException e) { @@ -146,7 +145,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public void uploadSucceeded(final SucceededEvent event) { LOG.debug("Streaming finished for file :{}", event.getFilename()); eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_SUCCESSFUL, new UploadFileStatus( - event.getFilename(), 0, event.getLength()))); + event.getFilename(), 0, event.getLength(), selectedSwForUpload))); } /** @@ -160,7 +159,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public void streamingFinished(final StreamingEndEvent event) { LOG.debug("Streaming finished for file :{}", event.getFileName()); eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STREAMING_FINISHED, - new UploadFileStatus(event.getFileName(), 0, event.getContentLength()))); + new UploadFileStatus(event.getFileName(), 0, event.getContentLength(), selectedSw))); } /** @@ -185,7 +184,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public void streamingStarted(final StreamingStartEvent event) { LOG.debug("Streaming started for file :{}", fileName); eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, new UploadFileStatus( - fileName, 0, 0))); + fileName, 0, 0, selectedSw))); } /** @@ -195,11 +194,13 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene */ @Override public void uploadStarted(final StartedEvent event) { + selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().get(); + // single file session - if (view.isSoftwareModuleSelected() && !view.checkIfFileIsDuplicate(event.getFilename())) { + 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))); + event.getFilename(), 0, 0, selectedSwForUpload))); } else { failureReason = i18n.get("message.upload.failed"); upload.interruptUpload(); @@ -238,7 +239,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene return; } eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, - new UploadFileStatus(fileName, readBytes, contentLength))); + new UploadFileStatus(fileName, readBytes, contentLength, selectedSwForUpload))); LOG.info("Update progress - {} : {}", fileName, (double) readBytes / (double) contentLength); } } @@ -259,7 +260,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene return; } eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, new UploadFileStatus( - fileName, event.getBytesReceived(), event.getContentLength()))); + fileName, event.getBytesReceived(), event.getContentLength(), selectedSw))); // Logging to solve sonar issue LOG.trace("Streaming in progress for file :{}", event.getFileName()); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index fedee30b9..cbf766da8 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -118,7 +118,6 @@ public class UploadLayout extends VerticalLayout { private Button uploadStatusButton; - /** * Initialize the upload layout. */ @@ -139,8 +138,7 @@ public class UploadLayout extends VerticalLayout { ui.access(() -> showUploadStatusButton()); } else if (event == UploadArtifactUIEvent.MAXIMIZED_STATUS_POPUP) { ui.access(() -> maximizeStatusPopup()); - } - else if(event == UploadArtifactUIEvent.ARTIFACT_RESULT_POPUP_CLOSED){ + } else if (event == UploadArtifactUIEvent.ARTIFACT_RESULT_POPUP_CLOSED) { ui.access(() -> closeUploadStatusPopup()); } } @@ -264,9 +262,9 @@ public class UploadLayout extends VerticalLayout { private void processFile(final Html5File file, SoftwareModule selectedSw) { if (!isDirectory(file)) { - if (!checkForDuplicate(file.getFileName())) { + if (!checkForDuplicate(file.getFileName(), selectedSw)) { artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet(); - file.setStreamVariable(createStreamVariable(file,selectedSw)); + file.setStreamVariable(createStreamVariable(file, selectedSw)); } } else { hasDirectory = Boolean.TRUE; @@ -275,7 +273,7 @@ public class UploadLayout extends VerticalLayout { private StreamVariable createStreamVariable(final Html5File file, SoftwareModule selectedSw) { return new UploadHandler(file.getFileName(), file.getFileSize(), UploadLayout.this, - spInfo.getMaxArtifactFileSize(), null, file.getType(),selectedSw); + spInfo.getMaxArtifactFileSize(), null, file.getType(), selectedSw); } private boolean isDirectory(final Html5File file) { @@ -339,8 +337,8 @@ public class UploadLayout extends VerticalLayout { discardBtn.addClickListener(event -> discardUploadData(event)); } - boolean checkForDuplicate(final String filename) { - final Boolean isDuplicate = checkIfFileIsDuplicate(filename); + boolean checkForDuplicate(final String filename, final SoftwareModule selectedSw) { + final Boolean isDuplicate = checkIfFileIsDuplicate(filename, selectedSw); if (isDuplicate) { getDuplicateFileNamesList().add(filename); } @@ -358,22 +356,23 @@ public class UploadLayout extends VerticalLayout { * file size * @param mimeType * the mimeType of the file - * @param selectedSw + * @param selectedSw * @throws IOException * in case of upload errors */ - OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType, SoftwareModule selectedSw) { + OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType, + SoftwareModule selectedSw) { File tempFile = null; try { tempFile = File.createTempFile("spUiArtifactUpload", null); final OutputStream out = new FileOutputStream(tempFile); - final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( - selectedSw.getName(), selectedSw.getVersion()); + final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(selectedSw.getName(), + selectedSw.getVersion()); - final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), - selectedSw.getName(), selectedSw.getVersion(), mimeType); + final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), selectedSw.getName(), + selectedSw.getVersion(), mimeType); artifactUploadState.getFileSelected().add(customFile); processBtn.setEnabled(false); @@ -424,13 +423,6 @@ public class UploadLayout extends VerticalLayout { return true; } - SoftwareModule getSoftwareModuleSelected() { - if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) { - return artifactUploadState.getSelectedBaseSoftwareModule().get(); - } - return null; - } - Boolean isSoftwareModuleSelected() { if (!artifactUploadState.getSelectedBaseSwModuleId().isPresent()) { return false; @@ -446,9 +438,8 @@ public class UploadLayout extends VerticalLayout { * file name * @return Boolean */ - public Boolean checkIfFileIsDuplicate(final String name) { + public Boolean checkIfFileIsDuplicate(final String name, final SoftwareModule selectedSoftwareModule) { Boolean isDuplicate = false; - final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); @@ -514,8 +505,7 @@ public class UploadLayout extends VerticalLayout { artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet(); } - void updateFileSize(final String name, final long size) { - final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); + void updateFileSize(final String name, final long size, SoftwareModule selectedSoftwareModule) { final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); @@ -718,7 +708,8 @@ public class UploadLayout extends VerticalLayout { } private void onUploadSuccess(UploadStatusEvent event) { - updateFileSize(event.getUploadStatus().getFileName(), event.getUploadStatus().getContentLength()); + updateFileSize(event.getUploadStatus().getFileName(), event.getUploadStatus().getContentLength(), event + .getUploadStatus().getSoftwareModule()); // recorded that we now one more uploaded increaseNumberOfFilesActuallyUpload(); } @@ -735,7 +726,6 @@ public class UploadLayout extends VerticalLayout { duplicateFileNamesList.clear(); } - private boolean isUploadComplete() { int uploadedCount = artifactUploadState.getNumberOfFilesActuallyUpload().intValue(); int expectedUploadsCount = artifactUploadState.getNumberOfFileUploadsExpected().intValue(); @@ -869,7 +859,6 @@ public class UploadLayout extends VerticalLayout { uploadStatusButton.setIcon(null); } - protected void updateUploadCounts() { updateActionCount(); updateStatusButtonCount();