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:
Asharani
2016-05-17 17:50:40 +05:30
parent 652f480667
commit 51db4204d2
5 changed files with 79 additions and 52 deletions

View File

@@ -10,6 +10,8 @@ package org.eclipse.hawkbit.ui.artifacts.event;
import java.io.Serializable; import java.io.Serializable;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
/** /**
* *
* Holds file and upload status details.Meta data sent with upload events. * 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 String failureReason;
private SoftwareModule softwareModule;
public UploadFileStatus(String fileName) { public UploadFileStatus(String fileName) {
this.fileName = fileName; this.fileName = fileName;
} }
@@ -37,9 +41,10 @@ public class UploadFileStatus implements Serializable {
this.bytesRead = bytesRead; this.bytesRead = bytesRead;
} }
public UploadFileStatus(String fileName, String failureReason) { public UploadFileStatus(String fileName, String failureReason,SoftwareModule selectedSw) {
this.failureReason = failureReason; this.failureReason = failureReason;
this.fileName = fileName; this.fileName = fileName;
this.softwareModule = selectedSw;
} }
public String getFileName() { public String getFileName() {
@@ -57,4 +62,8 @@ public class UploadFileStatus implements Serializable {
public String getFailureReason() { public String getFailureReason() {
return failureReason; return failureReason;
} }
public SoftwareModule getSoftwareModule() {
return softwareModule;
}
} }

View File

@@ -14,10 +14,12 @@ import java.io.OutputStream;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
import org.eclipse.hawkbit.repository.exception.ArtifactUploadFailedException; 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.UploadArtifactUIEvent;
import org.eclipse.hawkbit.ui.artifacts.event.UploadFileStatus; import org.eclipse.hawkbit.ui.artifacts.event.UploadFileStatus;
import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent; import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent;
import org.eclipse.hawkbit.ui.artifacts.event.UploadStatusEvent.UploadStatusEventType; 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.I18N;
import org.eclipse.hawkbit.ui.utils.SpringContextHelper; import org.eclipse.hawkbit.ui.utils.SpringContextHelper;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -68,9 +70,12 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
private String failureReason; private String failureReason;
private final I18N i18n; private final I18N i18n;
private transient EventBus.SessionEventBus eventBus; 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, UploadHandler(final String fileName, final long fileSize, final UploadLayout view, final long maxSize,
final long maxSize, final Upload upload, final String mimeType) { final Upload upload, final String mimeType, SoftwareModule selectedSw) {
super(); super();
this.fileName = fileName; this.fileName = fileName;
this.fileSize = fileSize; this.fileSize = fileSize;
@@ -78,8 +83,10 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
this.maxSize = maxSize; this.maxSize = maxSize;
this.upload = upload; this.upload = upload;
this.mimeType = mimeType; this.mimeType = mimeType;
this.selectedSw = selectedSw;
this.i18n = SpringContextHelper.getBean(I18N.class); this.i18n = SpringContextHelper.getBean(I18N.class);
this.eventBus = SpringContextHelper.getBean(EventBus.SessionEventBus.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() { public final OutputStream getOutputStream() {
try { try {
streamingInterrupted = false; streamingInterrupted = false;
return view.saveUploadedFileDetails(fileName, fileSize, mimeType); return view.saveUploadedFileDetails(fileName, fileSize, mimeType, selectedSw);
} catch (final ArtifactUploadFailedException e) { } catch (final ArtifactUploadFailedException e) {
LOG.error("Atifact upload failed {} ", e); LOG.error("Atifact upload failed {} ", e);
failureReason = e.getMessage(); failureReason = e.getMessage();
@@ -116,7 +123,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
try { try {
if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName)) { if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName)) {
view.increaseNumberOfFileUploadsExpected(); view.increaseNumberOfFileUploadsExpected();
return view.saveUploadedFileDetails(fileName, 0, mimeType); selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().get();
return view.saveUploadedFileDetails(fileName, 0, mimeType, selectedSwForUpload);
} }
} catch (final ArtifactUploadFailedException e) { } catch (final ArtifactUploadFailedException e) {
LOG.error("Atifact upload failed {} ", e); LOG.error("Atifact upload failed {} ", e);
@@ -217,13 +225,14 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
*/ */
@Override @Override
public void updateProgress(final long readBytes, final long contentLength) { 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 (!uploadInterrupted) {
if (readBytes > maxSize || contentLength > maxSize) { if (readBytes > maxSize || contentLength > maxSize) {
LOG.error("User tried to upload more than was allowed ({}).", maxSize); LOG.error("User tried to upload more than was allowed ({}).", maxSize);
failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize);
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus(
fileName, failureReason))); fileName, failureReason, selectedSwForUpload)));
upload.interruptUpload(); upload.interruptUpload();
uploadInterrupted = true; uploadInterrupted = true;
return; return;
@@ -245,7 +254,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
LOG.error("User tried to upload more than was allowed ({}).", maxSize); LOG.error("User tried to upload more than was allowed ({}).", maxSize);
failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize); failureReason = i18n.get("message.uploadedfile.size.exceeded", maxSize);
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus(
fileName, failureReason))); fileName, failureReason, selectedSw)));
streamingInterrupted = true; streamingInterrupted = true;
return; return;
} }
@@ -268,7 +277,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
failureReason = event.getException().getMessage(); failureReason = event.getException().getMessage();
} }
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STREAMING_FAILED, 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()); LOG.info("Streaming failed due to :{}", event.getException());
} }
@@ -284,9 +293,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
if (failureReason == null) { if (failureReason == null) {
failureReason = event.getReason().getMessage(); failureReason = event.getReason().getMessage();
} }
System.out.println("failureReason:::"+failureReason);
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus( eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus(
fileName, failureReason))); fileName, failureReason, selectedSwForUpload)));
LOG.info("Upload failed for file :{}", event.getReason()); LOG.info("Upload failed for file :{}", event.getReason());
} }

View File

@@ -181,7 +181,7 @@ public class UploadLayout extends VerticalLayout {
final Upload upload = new Upload(); final Upload upload = new Upload();
final UploadHandler uploadHandler = new UploadHandler(null, 0, this, spInfo.getMaxArtifactFileSize(), upload, final UploadHandler uploadHandler = new UploadHandler(null, 0, this, spInfo.getMaxArtifactFileSize(), upload,
null); null, null);
upload.setButtonCaption(i18n.get("upload.file")); upload.setButtonCaption(i18n.get("upload.file"));
upload.setImmediate(true); upload.setImmediate(true);
upload.setReceiver(uploadHandler); upload.setReceiver(uploadHandler);
@@ -243,15 +243,16 @@ public class UploadLayout extends VerticalLayout {
public void drop(final DragAndDropEvent event) { public void drop(final DragAndDropEvent event) {
if (validate(event)) { if (validate(event)) {
final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); 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 // reset the flag
hasDirectory = Boolean.FALSE; hasDirectory = Boolean.FALSE;
for (final Html5File file : files) { for (final Html5File file : files) {
processFile(file); processFile(file, selectedSw);
} }
if (artifactUploadState.getNumberOfFileUploadsExpected().get() > 0) { if (artifactUploadState.getNumberOfFileUploadsExpected().get() > 0) {
processBtn.setEnabled(false); processBtn.setEnabled(false);
// reset before we start
// uploadInfoWindow.uploadSessionStarted();
} else { } else {
// If the upload is not started, it signifies all // If the upload is not started, it signifies all
// dropped files as either duplicate or directory.So // 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 (!isDirectory(file)) {
if (!checkForDuplicate(file.getFileName())) { if (!checkForDuplicate(file.getFileName())) {
artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet(); artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet();
file.setStreamVariable(createStreamVariable(file)); file.setStreamVariable(createStreamVariable(file,selectedSw));
} }
} else { } else {
hasDirectory = Boolean.TRUE; 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, 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) { private boolean isDirectory(final Html5File file) {
@@ -357,29 +358,28 @@ public class UploadLayout extends VerticalLayout {
* file size * file size
* @param mimeType * @param mimeType
* the mimeType of the file * the mimeType of the file
* @param selectedSw
* @throws IOException * @throws IOException
* in case of upload errors * 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; File tempFile = null;
try { try {
tempFile = File.createTempFile("spUiArtifactUpload", null); tempFile = File.createTempFile("spUiArtifactUpload", null);
final OutputStream out = new FileOutputStream(tempFile); final OutputStream out = new FileOutputStream(tempFile);
final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get();
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); selectedSw.getName(), selectedSw.getVersion());
final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(),
selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion(), mimeType); selectedSw.getName(), selectedSw.getVersion(), mimeType);
artifactUploadState.getFileSelected().add(customFile); artifactUploadState.getFileSelected().add(customFile);
processBtn.setEnabled(false); processBtn.setEnabled(false);
if (!artifactUploadState.getBaseSwModuleList().keySet().contains(currentBaseSoftwareModuleKey)) { if (!artifactUploadState.getBaseSwModuleList().keySet().contains(currentBaseSoftwareModuleKey)) {
artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSoftwareModule); artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSw);
} }
return out; return out;
} catch (final FileNotFoundException e) { } catch (final FileNotFoundException e) {
@@ -689,30 +689,32 @@ public class UploadLayout extends VerticalLayout {
} }
private void onUploadStreamingFailure(UploadStatusEvent event) { private void onUploadStreamingFailure(UploadStatusEvent event) {
/** /**
* If upload interrupted because of duplicate file,do not remove the * If upload interrupted because of duplicate file,do not remove the
* file already in upload list * file already in upload list
**/ **/
if (getDuplicateFileNamesList().isEmpty() if (getDuplicateFileNamesList().isEmpty()
|| !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) { || !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) {
final SoftwareModule sw = getSoftwareModuleSelected(); final SoftwareModule sw = event.getUploadStatus().getSoftwareModule();
if (sw != null) {
getFileSelected().remove( getFileSelected().remove(
new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion())); 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(); // failed reason to be updated only if there is error other than
updateUploadCounts(); // duplicate file error
enableProcessBtn(); uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus()
// check if we are finished .getFailureReason());
if (isUploadComplete()) { increaseNumberOfFileUploadsFailed();
uploadInfoWindow.uploadSessionFinished(); }
setUploadStatusButtonIconToFinished(); decreaseNumberOfFileUploadsExpected();
} updateUploadCounts();
displayDuplicateValidationMessage(); enableProcessBtn();
// check if we are finished
if (isUploadComplete()) {
uploadInfoWindow.uploadSessionFinished();
setUploadStatusButtonIconToFinished();
}
displayDuplicateValidationMessage();
} }
private void onUploadSuccess(UploadStatusEvent event) { 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 * If upload interrupted because of duplicate file,do not remove the
* file already in upload list * file already in upload list
**/ **/
if (getDuplicateFileNamesList().isEmpty() || !getDuplicateFileNamesList().contains( if (getDuplicateFileNamesList().isEmpty()
event.getUploadStatus().getFileName())) { || !getDuplicateFileNamesList().contains(event.getUploadStatus().getFileName())) {
final SoftwareModule sw = getSoftwareModuleSelected(); final SoftwareModule sw = event.getUploadStatus().getSoftwareModule();
getFileSelected().remove( if (sw != null) {
new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion())); getFileSelected().remove(
new CustomFile(event.getUploadStatus().getFileName(), sw.getName(), sw.getVersion()));
}
// failed reason to be updated only if there is error other than // failed reason to be updated only if there is error other than
// duplicate file error // duplicate file error
uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus() uploadInfoWindow.uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus()

View File

@@ -173,6 +173,7 @@ public class UploadStatusInfoWindow extends Window {
} }
private void setPopupProperties() { private void setPopupProperties() {
setId(SPUIComponetIdProvider.UPLOAD_STATUS_POPUP_ID);
addStyleName(SPUIStyleDefinitions.UPLOAD_INFO); addStyleName(SPUIStyleDefinitions.UPLOAD_INFO);
setImmediate(true); setImmediate(true);
setResizable(false); setResizable(false);

View File

@@ -903,6 +903,11 @@ public final class SPUIComponetIdProvider {
*/ */
public static final String UPLOAD_STATUS_BUTTON = "artficat.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";
/** /**
* /* Private Constructor. * /* Private Constructor.