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 <asharani.murugesh@in.bosch.com>
This commit is contained in:
@@ -10,6 +10,8 @@ package org.eclipse.hawkbit.ui.artifacts.event;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
|
||||
/**
|
||||
*
|
||||
* Holds file and upload status details.Meta data sent with upload events.
|
||||
@@ -27,6 +29,8 @@ public class UploadFileStatus implements Serializable {
|
||||
|
||||
private String failureReason;
|
||||
|
||||
private SoftwareModule softwareModule;
|
||||
|
||||
public UploadFileStatus(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
@@ -37,9 +41,10 @@ public class UploadFileStatus implements Serializable {
|
||||
this.bytesRead = bytesRead;
|
||||
}
|
||||
|
||||
public UploadFileStatus(String fileName, String failureReason) {
|
||||
public UploadFileStatus(String fileName, String failureReason,SoftwareModule selectedSw) {
|
||||
this.failureReason = failureReason;
|
||||
this.fileName = fileName;
|
||||
this.softwareModule = selectedSw;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
@@ -57,4 +62,8 @@ public class UploadFileStatus implements Serializable {
|
||||
public String getFailureReason() {
|
||||
return failureReason;
|
||||
}
|
||||
|
||||
public SoftwareModule getSoftwareModule() {
|
||||
return softwareModule;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,10 +14,12 @@ import java.io.OutputStream;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException;
|
||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadArtifactUIEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadFileStatus;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent;
|
||||
import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType;
|
||||
import org.eclipse.hawkbit.ui.artifacts.state.ArtifactUploadState;
|
||||
import org.eclipse.hawkbit.ui.utils.I18N;
|
||||
import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
|
||||
import org.slf4j.Logger;
|
||||
@@ -68,9 +70,12 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
||||
private String failureReason;
|
||||
private final I18N i18n;
|
||||
private transient EventBus.SessionEventBus eventBus;
|
||||
private final SoftwareModule selectedSw;
|
||||
private SoftwareModule selectedSwForUpload;
|
||||
private ArtifactUploadState artifactUploadState;
|
||||
|
||||
UploadHandler(final String fileName, final long fileSize, final UploadLayout view,
|
||||
final long maxSize, final Upload upload, final String mimeType) {
|
||||
UploadHandler(final String fileName, final long fileSize, final UploadLayout view, final long maxSize,
|
||||
final Upload upload, final String mimeType, SoftwareModule selectedSw) {
|
||||
super();
|
||||
this.fileName = fileName;
|
||||
this.fileSize = fileSize;
|
||||
@@ -78,8 +83,10 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
||||
this.maxSize = maxSize;
|
||||
this.upload = upload;
|
||||
this.mimeType = mimeType;
|
||||
this.selectedSw = selectedSw;
|
||||
this.i18n = SpringContextHelper.getBean(I18N.class);
|
||||
this.eventBus = SpringContextHelper.getBean(EventBus.SessionEventBus.class);
|
||||
this.artifactUploadState = SpringContextHelper.getBean(ArtifactUploadState.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +98,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
||||
public final OutputStream getOutputStream() {
|
||||
try {
|
||||
streamingInterrupted = false;
|
||||
return view.saveUploadedFileDetails(fileName, fileSize, mimeType);
|
||||
return view.saveUploadedFileDetails(fileName, fileSize, mimeType, selectedSw);
|
||||
} catch (final ArtifactUploadFailedException e) {
|
||||
LOG.error("Atifact upload failed {} ", e);
|
||||
failureReason = e.getMessage();
|
||||
@@ -116,7 +123,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
||||
try {
|
||||
if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName)) {
|
||||
view.increaseNumberOfFileUploadsExpected();
|
||||
return view.saveUploadedFileDetails(fileName, 0, mimeType);
|
||||
selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().get();
|
||||
return view.saveUploadedFileDetails(fileName, 0, mimeType, selectedSwForUpload);
|
||||
}
|
||||
} catch (final ArtifactUploadFailedException e) {
|
||||
LOG.error("Atifact upload failed {} ", e);
|
||||
@@ -217,13 +225,14 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
||||
*/
|
||||
@Override
|
||||
public void updateProgress(final long readBytes, final long contentLength) {
|
||||
//Update progress is called event after upload interrupted in uploadStarted method
|
||||
// Update progress is called event after upload interrupted in
|
||||
// uploadStarted method
|
||||
if (!uploadInterrupted) {
|
||||
if (readBytes > maxSize || contentLength > maxSize) {
|
||||
LOG.error("User tried to upload more than was allowed ({}).", maxSize);
|
||||
failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize);
|
||||
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus(
|
||||
fileName, failureReason)));
|
||||
fileName, failureReason, selectedSwForUpload)));
|
||||
upload.interruptUpload();
|
||||
uploadInterrupted = true;
|
||||
return;
|
||||
@@ -245,7 +254,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
||||
LOG.error("User tried to upload more than was allowed ({}).", maxSize);
|
||||
failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize);
|
||||
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus(
|
||||
fileName, failureReason)));
|
||||
fileName, failureReason, selectedSw)));
|
||||
streamingInterrupted = true;
|
||||
return;
|
||||
}
|
||||
@@ -268,7 +277,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
||||
failureReason = event.getException().getMessage();
|
||||
}
|
||||
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STREAMING_FAILED,
|
||||
new UploadFileStatus(fileName, failureReason)));
|
||||
new UploadFileStatus(fileName, failureReason, selectedSw)));
|
||||
|
||||
LOG.info("Streaming failed due to :{}", event.getException());
|
||||
}
|
||||
@@ -284,9 +293,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
||||
if (failureReason == null) {
|
||||
failureReason = event.getReason().getMessage();
|
||||
}
|
||||
System.out.println("failureReason:::"+failureReason);
|
||||
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus(
|
||||
fileName, failureReason)));
|
||||
fileName, failureReason, selectedSwForUpload)));
|
||||
LOG.info("Upload failed for file :{}", event.getReason());
|
||||
}
|
||||
|
||||
@@ -335,5 +343,5 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public class UploadLayout extends VerticalLayout {
|
||||
|
||||
final Upload upload = new Upload();
|
||||
final UploadHandler uploadHandler = new UploadHandler(null, 0, this, spInfo.getMaxArtifactFileSize(), upload,
|
||||
null);
|
||||
null, null);
|
||||
upload.setButtonCaption(i18n.get("upload.file"));
|
||||
upload.setImmediate(true);
|
||||
upload.setReceiver(uploadHandler);
|
||||
@@ -243,15 +243,16 @@ public class UploadLayout extends VerticalLayout {
|
||||
public void drop(final DragAndDropEvent event) {
|
||||
if (validate(event)) {
|
||||
final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles();
|
||||
// selected software module at the time of file drop is
|
||||
// considered for upload
|
||||
SoftwareModule selectedSw = artifactUploadState.getSelectedBaseSoftwareModule().get();
|
||||
// reset the flag
|
||||
hasDirectory = Boolean.FALSE;
|
||||
for (final Html5File file : files) {
|
||||
processFile(file);
|
||||
processFile(file, selectedSw);
|
||||
}
|
||||
if (artifactUploadState.getNumberOfFileUploadsExpected().get() > 0) {
|
||||
processBtn.setEnabled(false);
|
||||
// reset before we start
|
||||
// uploadInfoWindow.uploadSessionStarted();
|
||||
} else {
|
||||
// If the upload is not started, it signifies all
|
||||
// dropped files as either duplicate or directory.So
|
||||
@@ -261,20 +262,20 @@ public class UploadLayout extends VerticalLayout {
|
||||
}
|
||||
}
|
||||
|
||||
private void processFile(final Html5File file) {
|
||||
private void processFile(final Html5File file, SoftwareModule selectedSw) {
|
||||
if (!isDirectory(file)) {
|
||||
if (!checkForDuplicate(file.getFileName())) {
|
||||
artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet();
|
||||
file.setStreamVariable(createStreamVariable(file));
|
||||
file.setStreamVariable(createStreamVariable(file,selectedSw));
|
||||
}
|
||||
} else {
|
||||
hasDirectory = Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
private StreamVariable createStreamVariable(final Html5File file) {
|
||||
private StreamVariable createStreamVariable(final Html5File file, SoftwareModule selectedSw) {
|
||||
return new UploadHandler(file.getFileName(), file.getFileSize(), UploadLayout.this,
|
||||
spInfo.getMaxArtifactFileSize(), null, file.getType());
|
||||
spInfo.getMaxArtifactFileSize(), null, file.getType(),selectedSw);
|
||||
}
|
||||
|
||||
private boolean isDirectory(final Html5File file) {
|
||||
@@ -357,29 +358,28 @@ public class UploadLayout extends VerticalLayout {
|
||||
* file size
|
||||
* @param mimeType
|
||||
* the mimeType of the file
|
||||
* @param selectedSw
|
||||
* @throws IOException
|
||||
* in case of upload errors
|
||||
*/
|
||||
OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType) {
|
||||
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 SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get();
|
||||
|
||||
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
|
||||
selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
|
||||
selectedSw.getName(), selectedSw.getVersion());
|
||||
|
||||
final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(),
|
||||
selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion(), mimeType);
|
||||
selectedSw.getName(), selectedSw.getVersion(), mimeType);
|
||||
|
||||
artifactUploadState.getFileSelected().add(customFile);
|
||||
processBtn.setEnabled(false);
|
||||
|
||||
if (!artifactUploadState.getBaseSwModuleList().keySet().contains(currentBaseSoftwareModuleKey)) {
|
||||
artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSoftwareModule);
|
||||
artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSw);
|
||||
}
|
||||
return out;
|
||||
} catch (final FileNotFoundException e) {
|
||||
@@ -689,30 +689,32 @@ public class UploadLayout extends VerticalLayout {
|
||||
}
|
||||
|
||||
private void onUploadStreamingFailure(UploadStatusEvent event) {
|
||||
/**
|
||||
* If upload interrupted because of duplicate file,do not remove the
|
||||
* file already in upload list
|
||||
**/
|
||||
if (getDuplicateFileNamesList().isEmpty()
|
||||
|| !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) {
|
||||
final SoftwareModule sw = getSoftwareModuleSelected();
|
||||
/**
|
||||
* If upload interrupted because of duplicate file,do not remove the
|
||||
* file already in upload list
|
||||
**/
|
||||
if (getDuplicateFileNamesList().isEmpty()
|
||||
|| !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) {
|
||||
final SoftwareModule sw = event.getUploadStatus().getSoftwareModule();
|
||||
if (sw != null) {
|
||||
getFileSelected().remove(
|
||||
new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion()));
|
||||
// failed reason to be updated only if there is error other than
|
||||
// duplicate file error
|
||||
uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus()
|
||||
.getFailureReason());
|
||||
increaseNumberOfFileUploadsFailed();
|
||||
}
|
||||
decreaseNumberOfFileUploadsExpected();
|
||||
updateUploadCounts();
|
||||
enableProcessBtn();
|
||||
// check if we are finished
|
||||
if (isUploadComplete()) {
|
||||
uploadInfoWindow.uploadSessionFinished();
|
||||
setUploadStatusButtonIconToFinished();
|
||||
}
|
||||
displayDuplicateValidationMessage();
|
||||
// failed reason to be updated only if there is error other than
|
||||
// duplicate file error
|
||||
uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus()
|
||||
.getFailureReason());
|
||||
increaseNumberOfFileUploadsFailed();
|
||||
}
|
||||
decreaseNumberOfFileUploadsExpected();
|
||||
updateUploadCounts();
|
||||
enableProcessBtn();
|
||||
// check if we are finished
|
||||
if (isUploadComplete()) {
|
||||
uploadInfoWindow.uploadSessionFinished();
|
||||
setUploadStatusButtonIconToFinished();
|
||||
}
|
||||
displayDuplicateValidationMessage();
|
||||
}
|
||||
|
||||
private void onUploadSuccess(UploadStatusEvent event) {
|
||||
@@ -745,11 +747,13 @@ public class UploadLayout extends VerticalLayout {
|
||||
* If upload interrupted because of duplicate file,do not remove the
|
||||
* file already in upload list
|
||||
**/
|
||||
if (getDuplicateFileNamesList().isEmpty() || !getDuplicateFileNamesList().contains(
|
||||
event.getUploadStatus().getFileName())) {
|
||||
final SoftwareModule sw = getSoftwareModuleSelected();
|
||||
getFileSelected().remove(
|
||||
new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion()));
|
||||
if (getDuplicateFileNamesList().isEmpty()
|
||||
|| !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) {
|
||||
final SoftwareModule sw = event.getUploadStatus().getSoftwareModule();
|
||||
if (sw != null) {
|
||||
getFileSelected().remove(
|
||||
new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion()));
|
||||
}
|
||||
// failed reason to be updated only if there is error other than
|
||||
// duplicate file error
|
||||
uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus()
|
||||
|
||||
@@ -173,6 +173,7 @@ public class UploadStatusInfoWindow extends Window {
|
||||
}
|
||||
|
||||
private void setPopupProperties() {
|
||||
setId(SPUIComponetIdProvider.UPLOAD_STATUS_POPUP_ID);
|
||||
addStyleName(SPUIStyleDefinitions.UPLOAD_INFO);
|
||||
setImmediate(true);
|
||||
setResizable(false);
|
||||
|
||||
@@ -902,6 +902,11 @@ public final class SPUIComponetIdProvider {
|
||||
* Artifact upload view - upload status button id.
|
||||
*/
|
||||
public static final String UPLOAD_STATUS_BUTTON = "artficat.upload.status.button.id";
|
||||
|
||||
/**
|
||||
* Artifact uplaod view - uplod status popup id.
|
||||
*/
|
||||
public static final String UPLOAD_STATUS_POPUP_ID = "artifact.upload.status.popup.id";
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user