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:
@@ -35,10 +35,11 @@ public class UploadFileStatus implements Serializable {
|
|||||||
this.fileName = fileName;
|
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.fileName = fileName;
|
||||||
this.contentLength = contentLength;
|
this.contentLength = contentLength;
|
||||||
this.bytesRead = bytesRead;
|
this.bytesRead = bytesRead;
|
||||||
|
this.softwareModule = softwareModule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UploadFileStatus(String fileName, String failureReason,SoftwareModule selectedSw) {
|
public UploadFileStatus(String fileName, String failureReason,SoftwareModule selectedSw) {
|
||||||
|
|||||||
@@ -121,9 +121,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
|||||||
// reset has directory flag before upload
|
// reset has directory flag before upload
|
||||||
view.setHasDirectory(false);
|
view.setHasDirectory(false);
|
||||||
try {
|
try {
|
||||||
if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName)) {
|
if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName, selectedSwForUpload)) {
|
||||||
view.increaseNumberOfFileUploadsExpected();
|
view.increaseNumberOfFileUploadsExpected();
|
||||||
selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().get();
|
|
||||||
return view.saveUploadedFileDetails(fileName, 0, mimeType, selectedSwForUpload);
|
return view.saveUploadedFileDetails(fileName, 0, mimeType, selectedSwForUpload);
|
||||||
}
|
}
|
||||||
} catch (final ArtifactUploadFailedException e) {
|
} catch (final ArtifactUploadFailedException e) {
|
||||||
@@ -146,7 +145,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
|||||||
public void uploadSucceeded(final SucceededEvent event) {
|
public void uploadSucceeded(final SucceededEvent event) {
|
||||||
LOG.debug("Streaming finished for file :{}", event.getFilename());
|
LOG.debug("Streaming finished for file :{}", event.getFilename());
|
||||||
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_SUCCESSFUL, new UploadFileStatus(
|
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) {
|
public void streamingFinished(final StreamingEndEvent event) {
|
||||||
LOG.debug("Streaming finished for file :{}", event.getFileName());
|
LOG.debug("Streaming finished for file :{}", event.getFileName());
|
||||||
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STREAMING_FINISHED,
|
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) {
|
public void streamingStarted(final StreamingStartEvent event) {
|
||||||
LOG.debug("Streaming started for file :{}", fileName);
|
LOG.debug("Streaming started for file :{}", fileName);
|
||||||
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED, new UploadFileStatus(
|
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
|
@Override
|
||||||
public void uploadStarted(final StartedEvent event) {
|
public void uploadStarted(final StartedEvent event) {
|
||||||
|
selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().get();
|
||||||
|
|
||||||
// single file session
|
// 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());
|
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, new UploadFileStatus(
|
||||||
event.getFilename(), 0, 0)));
|
event.getFilename(), 0, 0, selectedSwForUpload)));
|
||||||
} else {
|
} else {
|
||||||
failureReason = i18n.get("message.upload.failed");
|
failureReason = i18n.get("message.upload.failed");
|
||||||
upload.interruptUpload();
|
upload.interruptUpload();
|
||||||
@@ -238,7 +239,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS,
|
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);
|
LOG.info("Update progress - {} : {}", fileName, (double) readBytes / (double) contentLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,7 +260,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, new UploadFileStatus(
|
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
|
// Logging to solve sonar issue
|
||||||
LOG.trace("Streaming in progress for file :{}", event.getFileName());
|
LOG.trace("Streaming in progress for file :{}", event.getFileName());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
|
|
||||||
private Button uploadStatusButton;
|
private Button uploadStatusButton;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the upload layout.
|
* Initialize the upload layout.
|
||||||
*/
|
*/
|
||||||
@@ -139,8 +138,7 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
ui.access(() -> showUploadStatusButton());
|
ui.access(() -> showUploadStatusButton());
|
||||||
} else if (event == UploadArtifactUIEvent.MAXIMIZED_STATUS_POPUP) {
|
} else if (event == UploadArtifactUIEvent.MAXIMIZED_STATUS_POPUP) {
|
||||||
ui.access(() -> maximizeStatusPopup());
|
ui.access(() -> maximizeStatusPopup());
|
||||||
}
|
} else if (event == UploadArtifactUIEvent.ARTIFACT_RESULT_POPUP_CLOSED) {
|
||||||
else if(event == UploadArtifactUIEvent.ARTIFACT_RESULT_POPUP_CLOSED){
|
|
||||||
ui.access(() -> closeUploadStatusPopup());
|
ui.access(() -> closeUploadStatusPopup());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -264,9 +262,9 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
|
|
||||||
private void processFile(final Html5File file, SoftwareModule selectedSw) {
|
private void processFile(final Html5File file, SoftwareModule selectedSw) {
|
||||||
if (!isDirectory(file)) {
|
if (!isDirectory(file)) {
|
||||||
if (!checkForDuplicate(file.getFileName())) {
|
if (!checkForDuplicate(file.getFileName(), selectedSw)) {
|
||||||
artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet();
|
artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet();
|
||||||
file.setStreamVariable(createStreamVariable(file,selectedSw));
|
file.setStreamVariable(createStreamVariable(file, selectedSw));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
hasDirectory = Boolean.TRUE;
|
hasDirectory = Boolean.TRUE;
|
||||||
@@ -275,7 +273,7 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
|
|
||||||
private StreamVariable createStreamVariable(final Html5File file, SoftwareModule selectedSw) {
|
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(),selectedSw);
|
spInfo.getMaxArtifactFileSize(), null, file.getType(), selectedSw);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDirectory(final Html5File file) {
|
private boolean isDirectory(final Html5File file) {
|
||||||
@@ -339,8 +337,8 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
discardBtn.addClickListener(event -> discardUploadData(event));
|
discardBtn.addClickListener(event -> discardUploadData(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean checkForDuplicate(final String filename) {
|
boolean checkForDuplicate(final String filename, final SoftwareModule selectedSw) {
|
||||||
final Boolean isDuplicate = checkIfFileIsDuplicate(filename);
|
final Boolean isDuplicate = checkIfFileIsDuplicate(filename, selectedSw);
|
||||||
if (isDuplicate) {
|
if (isDuplicate) {
|
||||||
getDuplicateFileNamesList().add(filename);
|
getDuplicateFileNamesList().add(filename);
|
||||||
}
|
}
|
||||||
@@ -362,18 +360,19 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
* @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, SoftwareModule selectedSw) {
|
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 String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
|
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(selectedSw.getName(),
|
||||||
selectedSw.getName(), selectedSw.getVersion());
|
selectedSw.getVersion());
|
||||||
|
|
||||||
final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(),
|
final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), selectedSw.getName(),
|
||||||
selectedSw.getName(), selectedSw.getVersion(), mimeType);
|
selectedSw.getVersion(), mimeType);
|
||||||
|
|
||||||
artifactUploadState.getFileSelected().add(customFile);
|
artifactUploadState.getFileSelected().add(customFile);
|
||||||
processBtn.setEnabled(false);
|
processBtn.setEnabled(false);
|
||||||
@@ -424,13 +423,6 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SoftwareModule getSoftwareModuleSelected() {
|
|
||||||
if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) {
|
|
||||||
return artifactUploadState.getSelectedBaseSoftwareModule().get();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
Boolean isSoftwareModuleSelected() {
|
Boolean isSoftwareModuleSelected() {
|
||||||
if (!artifactUploadState.getSelectedBaseSwModuleId().isPresent()) {
|
if (!artifactUploadState.getSelectedBaseSwModuleId().isPresent()) {
|
||||||
return false;
|
return false;
|
||||||
@@ -446,9 +438,8 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
* file name
|
* file name
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
*/
|
*/
|
||||||
public Boolean checkIfFileIsDuplicate(final String name) {
|
public Boolean checkIfFileIsDuplicate(final String name, final SoftwareModule selectedSoftwareModule) {
|
||||||
Boolean isDuplicate = false;
|
Boolean isDuplicate = false;
|
||||||
final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get();
|
|
||||||
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
|
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
|
||||||
selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
|
selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
|
||||||
|
|
||||||
@@ -514,8 +505,7 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet();
|
artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateFileSize(final String name, final long size) {
|
void updateFileSize(final String name, final long size, SoftwareModule selectedSoftwareModule) {
|
||||||
final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get();
|
|
||||||
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
|
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
|
||||||
selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
|
selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
|
||||||
|
|
||||||
@@ -718,7 +708,8 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onUploadSuccess(UploadStatusEvent event) {
|
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
|
// recorded that we now one more uploaded
|
||||||
increaseNumberOfFilesActuallyUpload();
|
increaseNumberOfFilesActuallyUpload();
|
||||||
}
|
}
|
||||||
@@ -735,7 +726,6 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
duplicateFileNamesList.clear();
|
duplicateFileNamesList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean isUploadComplete() {
|
private boolean isUploadComplete() {
|
||||||
int uploadedCount = artifactUploadState.getNumberOfFilesActuallyUpload().intValue();
|
int uploadedCount = artifactUploadState.getNumberOfFilesActuallyUpload().intValue();
|
||||||
int expectedUploadsCount = artifactUploadState.getNumberOfFileUploadsExpected().intValue();
|
int expectedUploadsCount = artifactUploadState.getNumberOfFileUploadsExpected().intValue();
|
||||||
@@ -869,7 +859,6 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
uploadStatusButton.setIcon(null);
|
uploadStatusButton.setIcon(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void updateUploadCounts() {
|
protected void updateUploadCounts() {
|
||||||
updateActionCount();
|
updateActionCount();
|
||||||
updateStatusButtonCount();
|
updateStatusButtonCount();
|
||||||
|
|||||||
Reference in New Issue
Block a user