This feature allows to download the artifact from the Artifact details table Review points are handled Signed-off-by: usb1cob <Anbazhakan.Subramaniam@in.bosch.com>
This commit is contained in:
committed by
GitHub
parent
793227e501
commit
6df1e934ee
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.ui.artifacts.details;
|
package org.eclipse.hawkbit.ui.artifacts.details;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -16,8 +17,10 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import org.eclipse.hawkbit.artifact.repository.model.AbstractDbArtifact;
|
||||||
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
import org.eclipse.hawkbit.repository.ArtifactManagement;
|
||||||
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
import org.eclipse.hawkbit.repository.SoftwareModuleManagement;
|
||||||
|
import org.eclipse.hawkbit.repository.model.Artifact;
|
||||||
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
import org.eclipse.hawkbit.repository.model.SoftwareModule;
|
||||||
import org.eclipse.hawkbit.ui.artifacts.event.ArtifactDetailsEvent;
|
import org.eclipse.hawkbit.ui.artifacts.event.ArtifactDetailsEvent;
|
||||||
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
|
import org.eclipse.hawkbit.ui.artifacts.event.SoftwareModuleEvent;
|
||||||
@@ -46,7 +49,10 @@ import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
|||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.vaadin.data.Container;
|
import com.vaadin.data.Container;
|
||||||
|
import com.vaadin.server.ErrorHandler;
|
||||||
|
import com.vaadin.server.FileDownloader;
|
||||||
import com.vaadin.server.FontAwesome;
|
import com.vaadin.server.FontAwesome;
|
||||||
|
import com.vaadin.server.StreamResource;
|
||||||
import com.vaadin.ui.Alignment;
|
import com.vaadin.ui.Alignment;
|
||||||
import com.vaadin.ui.Button;
|
import com.vaadin.ui.Button;
|
||||||
import com.vaadin.ui.HorizontalLayout;
|
import com.vaadin.ui.HorizontalLayout;
|
||||||
@@ -290,19 +296,71 @@ public class ArtifactDetailsLayout extends VerticalLayout {
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Button generateCell(final Table source, final Object itemId, final Object columnId) {
|
public HorizontalLayout generateCell(final Table source, final Object itemId, final Object columnId) {
|
||||||
final String fileName = (String) table.getContainerDataSource().getItem(itemId)
|
HorizontalLayout actioncellLayout = new HorizontalLayout();
|
||||||
.getItemProperty(PROVIDED_FILE_NAME).getValue();
|
actioncellLayout.addComponent(getArtifactDeleteButton(table, itemId));
|
||||||
final Button deleteIcon = SPUIComponentProvider.getButton(
|
actioncellLayout.addComponent(getArtifactDownloadButton(table, itemId));
|
||||||
fileName + "-" + UIComponentIdProvider.UPLOAD_FILE_DELETE_ICON, "",
|
actioncellLayout.setImmediate(true);
|
||||||
i18n.getMessage(UIMessageIdProvider.CAPTION_DISCARD), ValoTheme.BUTTON_TINY + " " + "blueicon",
|
return actioncellLayout;
|
||||||
true, FontAwesome.TRASH_O, SPUIButtonStyleNoBorder.class);
|
}
|
||||||
deleteIcon.setData(itemId);
|
});
|
||||||
deleteIcon.addClickListener(event -> confirmAndDeleteArtifact((Long) itemId, fileName));
|
}
|
||||||
return deleteIcon;
|
|
||||||
|
private Button getArtifactDeleteButton(final Table table, final Object itemId) {
|
||||||
|
final String fileName = (String) table.getContainerDataSource().getItem(itemId)
|
||||||
|
.getItemProperty(PROVIDED_FILE_NAME).getValue();
|
||||||
|
final Button deleteIcon = SPUIComponentProvider.getButton(
|
||||||
|
fileName + "-" + UIComponentIdProvider.UPLOAD_FILE_DELETE_ICON, "",
|
||||||
|
i18n.getMessage(UIMessageIdProvider.CAPTION_DISCARD), ValoTheme.BUTTON_TINY + " " + "blueicon",
|
||||||
|
true, FontAwesome.TRASH_O, SPUIButtonStyleNoBorder.class);
|
||||||
|
deleteIcon.setData(itemId);
|
||||||
|
deleteIcon.addClickListener(event -> confirmAndDeleteArtifact((Long) itemId, fileName));
|
||||||
|
return deleteIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Button getArtifactDownloadButton(final Table table, final Object itemId) {
|
||||||
|
final String fileName = (String) table.getContainerDataSource().getItem(itemId)
|
||||||
|
.getItemProperty(PROVIDED_FILE_NAME).getValue();
|
||||||
|
final Button downloadIcon = SPUIComponentProvider.getButton(
|
||||||
|
fileName + "-" + UIComponentIdProvider.ARTIFACT_FILE_DOWNLOAD_ICON, "",
|
||||||
|
i18n.getMessage(UIMessageIdProvider.TOOLTIP_ARTIFACT_DOWNLOAD), ValoTheme.BUTTON_TINY + " " + "blueicon",
|
||||||
|
true, FontAwesome.DOWNLOAD, SPUIButtonStyleNoBorder.class);
|
||||||
|
downloadIcon.setData(itemId);
|
||||||
|
FileDownloader fileDownloader = new FileDownloader(createStreamResource((Long) itemId));
|
||||||
|
fileDownloader.extend(downloadIcon);
|
||||||
|
fileDownloader.setErrorHandler(new ErrorHandler() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error handler for file downloader
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 4030230501114422570L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void error(com.vaadin.server.ErrorEvent event) {
|
||||||
|
uINotification.displayValidationError(i18n.getMessage(UIMessageIdProvider.ARTIFACT_DOWNLOAD_FAILURE_MSG));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return downloadIcon;
|
||||||
|
}
|
||||||
|
|
||||||
|
private StreamResource createStreamResource(final Long id) {
|
||||||
|
|
||||||
|
Optional<Artifact> artifact = this.artifactManagement.get(id);
|
||||||
|
if (artifact.isPresent()) {
|
||||||
|
Optional<AbstractDbArtifact> file = artifactManagement.loadArtifactBinary(artifact.get().getSha1Hash());
|
||||||
|
return new StreamResource(new StreamResource.StreamSource() {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getStream() {
|
||||||
|
if (file.isPresent()) {
|
||||||
|
return file.get().getFileInputStream();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}, artifact.get().getFilename());
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void confirmAndDeleteArtifact(final Long id, final String fileName) {
|
private void confirmAndDeleteArtifact(final Long id, final String fileName) {
|
||||||
|
|||||||
@@ -387,6 +387,11 @@ public final class UIComponentIdProvider {
|
|||||||
*/
|
*/
|
||||||
public static final String UPLOAD_SOFTWARE_MODULE_TABLE = "upload.swModule.table";
|
public static final String UPLOAD_SOFTWARE_MODULE_TABLE = "upload.swModule.table";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Artifact - file download button id
|
||||||
|
*/
|
||||||
|
public static final String ARTIFACT_FILE_DOWNLOAD_ICON = "artifact.file.download.button";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload result popup close button.
|
* Upload result popup close button.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ package org.eclipse.hawkbit.ui.utils;
|
|||||||
*/
|
*/
|
||||||
public final class UIMessageIdProvider {
|
public final class UIMessageIdProvider {
|
||||||
|
|
||||||
|
public static final String TOOLTIP_ARTIFACT_DOWNLOAD = "tooltip.artifact.download";
|
||||||
|
|
||||||
|
public static final String ARTIFACT_DOWNLOAD_FAILURE_MSG = "message.artifact.download.failure";
|
||||||
|
|
||||||
public static final String BUTTON_CANCEL = "button.cancel";
|
public static final String BUTTON_CANCEL = "button.cancel";
|
||||||
|
|
||||||
public static final String BUTTON_OK = "button.ok";
|
public static final String BUTTON_OK = "button.ok";
|
||||||
|
|||||||
@@ -304,6 +304,7 @@ tooltip.next.maintenance.window = next on {0}
|
|||||||
tooltip.target.attributes.update.request = Request attributes update
|
tooltip.target.attributes.update.request = Request attributes update
|
||||||
tooltip.target.attributes.update.requested = Update already requested
|
tooltip.target.attributes.update.requested = Update already requested
|
||||||
tooltip.documentation.link=Documentation
|
tooltip.documentation.link=Documentation
|
||||||
|
tooltip.artifact.download=Download Artifact
|
||||||
|
|
||||||
#rollout action
|
#rollout action
|
||||||
tooltip.rollout.run = Run
|
tooltip.rollout.run = Run
|
||||||
@@ -472,7 +473,7 @@ message.upload.fileSizeQuota = Maximum artifact size ({0}) exceeded
|
|||||||
message.upload.storageQuota = Storage quota exceeded, {0} left
|
message.upload.storageQuota = Storage quota exceeded, {0} left
|
||||||
message.uploadedfile.illegalFilename = Filename contains illegal characters
|
message.uploadedfile.illegalFilename = Filename contains illegal characters
|
||||||
message.artifact.deleted = Artifact with file {0} deleted successfully
|
message.artifact.deleted = Artifact with file {0} deleted successfully
|
||||||
|
message.artifact.download.failure = Artifact Download Failed
|
||||||
|
|
||||||
artifact.upload.popup.caption = Upload status
|
artifact.upload.popup.caption = Upload status
|
||||||
artifact.upload.status.caption = Status
|
artifact.upload.status.caption = Status
|
||||||
|
|||||||
Reference in New Issue
Block a user