add files to status dialog when receive upload

Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
Michael Hirsch
2016-08-12 08:29:43 +02:00
parent 7f156f05a4
commit 630cf09162
4 changed files with 110 additions and 74 deletions

View File

@@ -7,6 +7,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.ui.artifacts.event;
/**
*
* Holds the upload file status.
@@ -14,24 +15,36 @@ package org.eclipse.hawkbit.ui.artifacts.event;
*/
public class UploadStatusEvent {
/**
* Event type definition of events during the artifact upload life-cycle
* from receiving the upload until the process end.
*/
public enum UploadStatusEventType {
UPLOAD_FAILED, UPLOAD_IN_PROGRESS, UPLOAD_STARTED, UPLOAD_FINISHED, UPLOAD_SUCCESSFUL, UPLOAD_STREAMING_FAILED, UPLOAD_STREAMING_FINISHED, ABORT_UPLOAD
RECEIVE_UPLOAD, UPLOAD_FAILED, UPLOAD_IN_PROGRESS, UPLOAD_STARTED, UPLOAD_FINISHED, UPLOAD_SUCCESSFUL, UPLOAD_STREAMING_FAILED, UPLOAD_STREAMING_FINISHED, ABORT_UPLOAD
}
private UploadStatusEventType uploadProgressEventType;
private final UploadStatusEventType uploadProgressEventType;
private UploadFileStatus uploadStatus;
public UploadStatusEvent(UploadStatusEventType eventType, UploadFileStatus entity) {
/**
* Constructor.
*
* @param eventType
* the type of the event
* @param uploadStatus
* the upload status of this event
*/
public UploadStatusEvent(final UploadStatusEventType eventType, final UploadFileStatus uploadStatus) {
this.uploadProgressEventType = eventType;
this.uploadStatus = entity;
this.uploadStatus = uploadStatus;
}
public UploadFileStatus getUploadStatus() {
return uploadStatus;
}
public void setUploadStatus(UploadFileStatus uploadStatus) {
public void setUploadStatus(final UploadFileStatus uploadStatus) {
this.uploadStatus = uploadStatus;
}

View File

@@ -71,10 +71,10 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
private transient EventBus.SessionEventBus eventBus;
private final SoftwareModule selectedSw;
private SoftwareModule selectedSwForUpload;
private ArtifactUploadState artifactUploadState;
private final ArtifactUploadState artifactUploadState;
UploadHandler(final String fileName, final long fileSize, final UploadLayout view, final long maxSize,
final Upload upload, final String mimeType, SoftwareModule selectedSw) {
final Upload upload, final String mimeType, final SoftwareModule selectedSw) {
super();
this.aborted = false;
this.fileName = fileName;
@@ -142,7 +142,11 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
try {
if (view.checkIfSoftwareModuleIsSelected() && !view.checkForDuplicate(fileName, selectedSwForUpload)) {
view.increaseNumberOfFileUploadsExpected();
return view.saveUploadedFileDetails(fileName, 0, mimeType, selectedSwForUpload);
final OutputStream saveUploadedFileDetails = view.saveUploadedFileDetails(fileName, 0, mimeType,
selectedSwForUpload);
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.RECEIVE_UPLOAD,
new UploadFileStatus(fileName, 0, -1, selectedSwForUpload)));
return saveUploadedFileDetails;
}
} catch (final ArtifactUploadFailedException e) {
LOG.error("Atifact upload failed {} ", e);
@@ -163,8 +167,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
@Override
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(), selectedSwForUpload)));
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_SUCCESSFUL,
new UploadFileStatus(event.getFilename(), 0, event.getLength(), selectedSwForUpload)));
}
/**
@@ -190,8 +194,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
@Override
public void uploadFinished(final FinishedEvent event) {
LOG.debug("Upload finished for file :{}", event.getFilename());
eventBus.publish(this,
new UploadStatusEvent(UploadStatusEventType.UPLOAD_FINISHED, new UploadFileStatus(event.getFilename())));
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FINISHED,
new UploadFileStatus(event.getFilename())));
}
/**
@@ -202,8 +206,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
@Override
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, selectedSw)));
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED,
new UploadFileStatus(fileName, 0, 0, selectedSw)));
}
/**
@@ -214,8 +218,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
@Override
public void uploadStarted(final StartedEvent event) {
uploadInterrupted = false;
selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().isPresent() ? artifactUploadState
.getSelectedBaseSoftwareModule().get() : null;
selectedSwForUpload = artifactUploadState.getSelectedBaseSoftwareModule().isPresent()
? artifactUploadState.getSelectedBaseSoftwareModule().get() : null;
if (view.isSoftwareModuleSelected()) {
// single file session
@@ -223,9 +227,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
LOG.debug("Upload started for file :{}", event.getFilename());
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_STARTED,
new UploadFileStatus(event.getFilename(), 0, 0, selectedSwForUpload)));
}
}
else {
}
} else {
failureReason = i18n.get("message.upload.failed");
upload.interruptUpload();
// actual interrupt will happen a bit late so setting the below
@@ -291,8 +294,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
interruptFileStreaming();
return;
}
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS, new UploadFileStatus(
fileName, event.getBytesReceived(), event.getContentLength(), selectedSw)));
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_IN_PROGRESS,
new UploadFileStatus(fileName, event.getBytesReceived(), event.getContentLength(), selectedSw)));
// Logging to solve sonar issue
LOG.trace("Streaming in progress for file :{}", event.getFileName());
}
@@ -332,8 +335,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
if (failureReason == null) {
failureReason = event.getReason().getMessage();
}
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.UPLOAD_FAILED, new UploadFileStatus(
fileName, failureReason, selectedSwForUpload)));
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());

View File

@@ -25,6 +25,7 @@ import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent.SoftwareModuleEventType;
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;
@@ -273,6 +274,10 @@ public class UploadLayout extends VerticalLayout {
private void processFile(final Html5File file, final SoftwareModule selectedSw) {
if (!isDirectory(file)) {
if (!checkForDuplicate(file.getFileName(), selectedSw)) {
eventBus.publish(this, new UploadStatusEvent(UploadStatusEventType.RECEIVE_UPLOAD,
new UploadFileStatus(file.getFileName(), 0, -1, selectedSw)));
artifactUploadState.getNumberOfFileUploadsExpected().incrementAndGet();
file.setStreamVariable(createStreamVariable(file, selectedSw));
}

View File

@@ -16,6 +16,7 @@ import javax.annotation.PreDestroy;
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;
@@ -135,26 +136,36 @@ public class UploadStatusInfoWindow extends Window {
@EventBusListenerMethod(scope = EventScope.SESSION)
void onEvent(final UploadStatusEvent event) {
if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_IN_PROGRESS) {
UI.getCurrent().access(
() -> updateProgress(event.getUploadStatus().getFileName(), event.getUploadStatus().getBytesRead(),
event.getUploadStatus().getContentLength(), event.getUploadStatus().getSoftwareModule()));
} else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STARTED) {
UI.getCurrent().access(() -> onStartOfUpload(event));
} else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FAILED) {
ui.access(() -> uploadFailed(event.getUploadStatus().getFileName(), event.getUploadStatus()
.getFailureReason(), event.getUploadStatus().getSoftwareModule()));
} else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_SUCCESSFUL) {
UI.getCurrent().access(
() -> uploadSucceeded(event.getUploadStatus().getFileName(), event.getUploadStatus()
.getSoftwareModule()));
} else if (event.getUploadProgressEventType() == UploadStatusEventType.UPLOAD_STREAMING_FINISHED) {
ui.access(() -> uploadSucceeded(event.getUploadStatus().getFileName(), event.getUploadStatus()
.getSoftwareModule()));
final UploadFileStatus uploadStatus = event.getUploadStatus();
switch (event.getUploadProgressEventType()) {
case UPLOAD_IN_PROGRESS:
ui.access(() -> updateProgress(uploadStatus.getFileName(), uploadStatus.getBytesRead(),
uploadStatus.getContentLength(), uploadStatus.getSoftwareModule()));
break;
case UPLOAD_STARTED:
ui.access(() -> onStartOfUpload(event));
break;
case UPLOAD_STREAMING_FAILED:
ui.access(() -> uploadFailed(uploadStatus.getFileName(), uploadStatus.getFailureReason(),
uploadStatus.getSoftwareModule()));
break;
case UPLOAD_SUCCESSFUL:
// fall through here
case UPLOAD_STREAMING_FINISHED:
ui.access(() -> uploadSucceeded(uploadStatus.getFileName(), uploadStatus.getSoftwareModule()));
break;
case RECEIVE_UPLOAD:
uploadRecevied(uploadStatus.getFileName(), uploadStatus.getSoftwareModule());
break;
case UPLOAD_FINISHED:
case ABORT_UPLOAD:
case UPLOAD_FAILED:
default:
}
}
private void onStartOfUpload(UploadStatusEvent event) {
private void onStartOfUpload(final UploadStatusEvent event) {
uploadSessionStarted();
uploadStarted(event.getUploadStatus().getFileName(), event.getUploadStatus().getSoftwareModule());
}
@@ -169,19 +180,23 @@ public class UploadStatusInfoWindow extends Window {
}
private void restoreState() {
Indexed container = grid.getContainerDataSource();
final Indexed container = grid.getContainerDataSource();
if (container.getItemIds().isEmpty()) {
container.removeAllItems();
for (UploadStatusObject statusObject : artifactUploadState.getUploadedFileStatusList()) {
Item item = container.addItem(getItemid(statusObject.getFilename(),
statusObject.getSelectedSoftwareModule()));
for (final UploadStatusObject statusObject : artifactUploadState.getUploadedFileStatusList()) {
final Item item = container
.addItem(getItemid(statusObject.getFilename(), statusObject.getSelectedSoftwareModule()));
item.getItemProperty(REASON).setValue(statusObject.getReason() != null ? statusObject.getReason() : "");
item.getItemProperty(STATUS).setValue(statusObject.getStatus());
item.getItemProperty(PROGRESS).setValue(statusObject.getProgress());
if (statusObject.getStatus() != null) {
item.getItemProperty(STATUS).setValue(statusObject.getStatus());
}
if (statusObject.getProgress() != null) {
item.getItemProperty(PROGRESS).setValue(statusObject.getProgress());
}
item.getItemProperty(FILE_NAME).setValue(statusObject.getFilename());
SoftwareModule sw = statusObject.getSelectedSoftwareModule();
item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(
HawkbitCommonUtil.getFormattedNameVersion(sw.getName(), sw.getVersion()));
final SoftwareModule sw = statusObject.getSelectedSoftwareModule();
item.getItemProperty(SPUILabelDefinitions.NAME_VERSION)
.setValue(HawkbitCommonUtil.getFormattedNameVersion(sw.getName(), sw.getVersion()));
}
if (artifactUploadState.isUploadCompleted()) {
minimizeButton.setEnabled(false);
@@ -209,7 +224,7 @@ public class UploadStatusInfoWindow extends Window {
}
private Grid createGrid() {
Grid statusGrid = new Grid(uploads);
final Grid statusGrid = new Grid(uploads);
statusGrid.addStyleName(SPUIStyleDefinitions.UPLOAD_STATUS_GRID);
statusGrid.setSelectionMode(SelectionMode.NONE);
statusGrid.setHeaderVisible(true);
@@ -219,7 +234,7 @@ public class UploadStatusInfoWindow extends Window {
}
private IndexedContainer getGridContainer() {
IndexedContainer uploadContainer = new IndexedContainer();
final IndexedContainer uploadContainer = new IndexedContainer();
uploadContainer.addContainerProperty(STATUS, String.class, "Active");
uploadContainer.addContainerProperty(FILE_NAME, String.class, null);
uploadContainer.addContainerProperty(PROGRESS, Double.class, 0D);
@@ -321,31 +336,33 @@ public class UploadStatusInfoWindow extends Window {
restoreState();
}
void uploadStarted(final String filename, final SoftwareModule softwareModule) {
private void uploadRecevied(final String filename, final SoftwareModule softwareModule) {
final Item item = uploads.addItem(getItemid(filename, softwareModule));
if (item != null) {
item.getItemProperty(FILE_NAME).setValue(filename);
item.getItemProperty(SPUILabelDefinitions.NAME_VERSION).setValue(
HawkbitCommonUtil.getFormattedNameVersion(softwareModule.getName(), softwareModule.getVersion()));
final UploadStatusObject uploadStatus = new UploadStatusObject(filename, softwareModule);
uploadStatus.setStatus("Active");
artifactUploadState.getUploadedFileStatusList().add(uploadStatus);
}
grid.scrollToEnd();
UploadStatusObject uploadStatus = new UploadStatusObject(filename, softwareModule);
uploadStatus.setStatus("Active");
artifactUploadState.getUploadedFileStatusList().add(uploadStatus);
}
void uploadStarted(final String filename, final SoftwareModule softwareModule) {
grid.scrollTo(getItemid(filename, softwareModule));
}
void updateProgress(final String filename, final long readBytes, final long contentLength,
final SoftwareModule softwareModule) {
final Item item = uploads.getItem(getItemid(filename, softwareModule));
double progress = (double) readBytes / (double) contentLength;
final double progress = (double) readBytes / (double) contentLength;
if (item != null) {
item.getItemProperty(PROGRESS).setValue(progress);
}
List<UploadStatusObject> uploadStatusObjectList = (List<UploadStatusObject>) artifactUploadState
.getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename))
.collect(Collectors.toList());
final List<UploadStatusObject> uploadStatusObjectList = artifactUploadState.getUploadedFileStatusList().stream()
.filter(e -> e.getFilename().equals(filename)).collect(Collectors.toList());
if (!uploadStatusObjectList.isEmpty()) {
UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0);
final UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0);
uploadStatusObject.setProgress(progress);
}
}
@@ -358,35 +375,33 @@ public class UploadStatusInfoWindow extends Window {
* @param softwareModule
* selected software module
*/
public void uploadSucceeded(final String filename, SoftwareModule softwareModule) {
public void uploadSucceeded(final String filename, final SoftwareModule softwareModule) {
final Item item = uploads.getItem(getItemid(filename, softwareModule));
String status = "Finished";
final String status = "Finished";
if (item != null) {
item.getItemProperty(STATUS).setValue(status);
}
List<UploadStatusObject> uploadStatusObjectList = (List<UploadStatusObject>) artifactUploadState
.getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename))
.collect(Collectors.toList());
final List<UploadStatusObject> uploadStatusObjectList = artifactUploadState.getUploadedFileStatusList().stream()
.filter(e -> e.getFilename().equals(filename)).collect(Collectors.toList());
if (!uploadStatusObjectList.isEmpty()) {
UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0);
final UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0);
uploadStatusObject.setStatus(status);
uploadStatusObject.setProgress(1d);
}
}
void uploadFailed(final String filename, final String errorReason, SoftwareModule softwareModule) {
void uploadFailed(final String filename, final String errorReason, final SoftwareModule softwareModule) {
errorOccured = true;
String status = "Failed";
final String status = "Failed";
final Item item = uploads.getItem(getItemid(filename, softwareModule));
if (item != null) {
item.getItemProperty(REASON).setValue(errorReason);
item.getItemProperty(STATUS).setValue(status);
}
List<UploadStatusObject> uploadStatusObjectList = (List<UploadStatusObject>) artifactUploadState
.getUploadedFileStatusList().stream().filter(e -> e.getFilename().equals(filename))
.collect(Collectors.toList());
final List<UploadStatusObject> uploadStatusObjectList = artifactUploadState.getUploadedFileStatusList().stream()
.filter(e -> e.getFilename().equals(filename)).collect(Collectors.toList());
if (!uploadStatusObjectList.isEmpty()) {
UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0);
final UploadStatusObject uploadStatusObject = uploadStatusObjectList.get(0);
uploadStatusObject.setStatus(status);
uploadStatusObject.setReason(errorReason);
}
@@ -428,7 +443,7 @@ public class UploadStatusInfoWindow extends Window {
return resizeBtn;
}
private void resizeWindow(ClickEvent event) {
private void resizeWindow(final ClickEvent event) {
if (event.getButton().getIcon() == FontAwesome.EXPAND) {
event.getButton().setIcon(FontAwesome.COMPRESS);
setWindowMode(WindowMode.MAXIMIZED);