From 70959ec1408a12623e9f152899b7e0fc4a42d308 Mon Sep 17 00:00:00 2001 From: asharani-murugesh Date: Mon, 8 Feb 2016 10:47:42 +0100 Subject: [PATCH 01/10] intial commit Signed-off-by: asharani-murugesh --- .../ui/artifacts/upload/UploadHandler.java | 6 +- .../ui/artifacts/upload/UploadLayout.java | 1053 +++++++++-------- 2 files changed, 548 insertions(+), 511 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index 834246c63..ed4e22ba0 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -89,6 +89,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public final OutputStream getOutputStream() { try { + view.getDuplicateFileNamesList().clear(); return view.saveUploadedFileDetails(fileName, fileSize, mimeType); } catch (final ArtifactUploadFailedException e) { LOG.error("Atifact upload failed {} ", e); @@ -108,6 +109,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public OutputStream receiveUpload(final String fileName, final String mimeType) { this.fileName = fileName; this.mimeType = mimeType; + view.getDuplicateFileNamesList().clear(); try { if (view.validate()) { if (view.checkForDuplicate(fileName)) { @@ -167,7 +169,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene view.updateActionCount(); // display the duplicate message after streaming all files - view.displayDuplicateMessageAfterStreamingAll(); + view.displayValidationMessage(); } /** @@ -292,7 +294,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene if (view.enableProcessBtn()) { infoWindow.uploadSessionFinished(); } - view.displayDuplicateMessageAfterStreamingAll(); + view.displayValidationMessage(); LOG.info("Streaming failed due to :{}", event.getException()); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index e570c84c4..b944006ff 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -46,6 +46,7 @@ import org.vaadin.spring.events.EventBus; import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.annotation.EventBusListenerMethod; +import com.google.common.base.Strings; import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.DropHandler; import com.vaadin.event.dd.acceptcriteria.AcceptAll; @@ -70,529 +71,563 @@ import com.vaadin.ui.VerticalLayout; /** * Upload files layout. * - * + * @author G Venkata Narayana (RBEI/BSO3) */ @ViewScope @SpringComponent public class UploadLayout extends VerticalLayout { - private static final long serialVersionUID = -566164756606779220L; + private static final long serialVersionUID = -566164756606779220L; - private static final Logger LOG = LoggerFactory.getLogger(UploadLayout.class); + private static final Logger LOG = LoggerFactory.getLogger(UploadLayout.class); - @Autowired - private UploadStatusInfoWindow uploadInfoWindow; + @Autowired + private UploadStatusInfoWindow uploadInfoWindow; - @Autowired - private I18N i18n; + @Autowired + private I18N i18n; - @Autowired - private transient UINotification uiNotification; + @Autowired + private transient UINotification uiNotification; - @Autowired - private transient EventBus.SessionEventBus eventBus; + @Autowired + private transient EventBus.SessionEventBus eventBus; - @Autowired - private ArtifactUploadState artifactUploadState; + @Autowired + private ArtifactUploadState artifactUploadState; - @Autowired - private transient SPInfo spInfo; + @Autowired + private transient SPInfo spInfo; - private final AtomicInteger numberOfFileUploadsExpected = new AtomicInteger(); + private final AtomicInteger numberOfFileUploadsExpected = new AtomicInteger(); - private final AtomicInteger numberOfFilesActuallyUpload = new AtomicInteger(); + private final AtomicInteger numberOfFilesActuallyUpload = new AtomicInteger(); - private final List duplicateFileNamesList = new ArrayList(); - - private Button processBtn; - - private Button discardBtn; - - private UploadConfirmationwindow currentUploadConfirmationwindow; - - private VerticalLayout dropAreaLayout; - - private UI ui; - - private HorizontalLayout fileUploadLayout; - - private DragAndDropWrapper dropAreaWrapper; - - /** - * Initialize the upload layout. - */ - @PostConstruct - void init() { - createComponents(); - buildLayout(); - updateActionCount(); - eventBus.subscribe(this); - ui = UI.getCurrent(); - } - - private void createComponents() { - - createProcessButton(); - createDiscardBtn(); - } - - private void buildLayout() { - - final Upload upload = new Upload(); - final UploadHandler uploadHandler = new UploadHandler(null, 0, this, uploadInfoWindow, - spInfo.getMaxArtifactFileSize(), upload, null); - upload.setButtonCaption(i18n.get("upload.file")); - upload.setImmediate(true); - upload.setReceiver(uploadHandler); - upload.addSucceededListener(uploadHandler); - upload.addFailedListener(uploadHandler); - upload.addFinishedListener(uploadHandler); - upload.addProgressListener(uploadHandler); - upload.addStartedListener(uploadHandler); - upload.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); - - fileUploadLayout = new HorizontalLayout(); - fileUploadLayout.setSpacing(true); - fileUploadLayout.addComponent(upload); - fileUploadLayout.setComponentAlignment(upload, Alignment.MIDDLE_LEFT); - fileUploadLayout.addComponent(processBtn); - fileUploadLayout.setComponentAlignment(processBtn, Alignment.MIDDLE_RIGHT); - fileUploadLayout.addComponent(discardBtn); - fileUploadLayout.setComponentAlignment(discardBtn, Alignment.MIDDLE_RIGHT); - setMargin(false); - - /* create drag-drop wrapper for drop area */ - dropAreaWrapper = new DragAndDropWrapper(createDropAreaLayout()); - dropAreaWrapper.setDropHandler(new DropAreahandler()); - setSizeFull(); - setSpacing(true); - - } - - public DragAndDropWrapper getDropAreaWrapper() { - return dropAreaWrapper; - } - - private class DropAreahandler implements DropHandler { - - private static final long serialVersionUID = 1L; - - @Override - public AcceptCriterion getAcceptCriterion() { - return AcceptAll.get(); - } - - @Override - public void drop(final DragAndDropEvent event) { - if (validate()) { - - final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); - if (files != null) { - for (final Html5File file : files) { - if (!checkForDuplicate(file.getFileName())) { - numberOfFileUploadsExpected.incrementAndGet(); - file.setStreamVariable(createStreamVariable(file)); - } - } - if (numberOfFileUploadsExpected.get() > 0) { - processBtn.setEnabled(false); - // reset before we start - uploadInfoWindow.uploadSessionStarted(); - } - // in case if all selected files are duplicate ,then display - // message - displayDuplicateMessageAfterStreamingAll(); - } - } - } - } - - private VerticalLayout createDropAreaLayout() { - dropAreaLayout = new VerticalLayout(); - final Label dropHereLabel = new Label("Drop files to upload"); - dropHereLabel.setWidth(null); - - final Label dropIcon = new Label(FontAwesome.ARROW_DOWN.getHtml(), ContentMode.HTML); - dropIcon.addStyleName("drop-icon"); - dropIcon.setWidth(null); - - dropAreaLayout.addComponent(dropIcon); - dropAreaLayout.setComponentAlignment(dropIcon, Alignment.BOTTOM_CENTER); - dropAreaLayout.addComponent(dropHereLabel); - dropAreaLayout.setComponentAlignment(dropHereLabel, Alignment.TOP_CENTER); - dropAreaLayout.setSizeFull(); - dropAreaLayout.setStyleName("upload-drop-area-layout-info"); - dropAreaLayout.setSpacing(false); - return dropAreaLayout; - } - - private void createProcessButton() { - processBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON, - SPUILabelDefinitions.PROCESS, SPUILabelDefinitions.PROCESS, null, false, null, - SPUIButtonStyleSmall.class); - processBtn.setIcon(FontAwesome.BELL); - processBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); - processBtn.addClickListener(event -> displayConfirmWindow(event)); - processBtn.setHtmlContentAllowed(true); - if (artifactUploadState.getFileSelected().isEmpty()) { - processBtn.setEnabled(false); - } - } - - private void createDiscardBtn() { - discardBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_DISCARD_BUTTON, - SPUILabelDefinitions.DISCARD, SPUILabelDefinitions.DISCARD, null, false, null, - SPUIButtonStyleSmall.class); - discardBtn.setIcon(FontAwesome.TRASH_O); - discardBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); - discardBtn.addClickListener(event -> discardUploadData(event)); - } - - private StreamVariable createStreamVariable(final Html5File file) { - return new UploadHandler(file.getFileName(), file.getFileSize(), this, uploadInfoWindow, - spInfo.getMaxArtifactFileSize(), null, file.getType()); - } - - boolean checkForDuplicate(final String filename) { - final Boolean isDuplicate = checkIfFileIsDuplicate(filename); - if (isDuplicate) { - getDuplicateFileNamesList().add(filename); - } - return isDuplicate; - } - - @EventBusListenerMethod(scope = EventScope.SESSION) - void toggleProcessButton(final UploadArtifactUIEvent event) { - if (event == UploadArtifactUIEvent.ENABLE_PROCESS_BUTTON) { - processBtn.setEnabled(true); - } else if (event == UploadArtifactUIEvent.DISABLE_PROCESS_BUTTON) { - processBtn.setEnabled(false); - } - } - - /** - * Save uploaded file details. - * - * @param stream - * read from uploaded file - * @param name - * file name - * @param size - * file size - * @param mimeType - * the mimeType of the file - * @throws IOException - * in case of upload errors - */ - OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType) { - 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()); - - final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), - selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion(), mimeType); - - artifactUploadState.getFileSelected().add(customFile); - processBtn.setEnabled(false); - - if (!artifactUploadState.getBaseSwModuleList().keySet().contains(currentBaseSoftwareModuleKey)) { - artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSoftwareModule); - } - return out; - } catch (final FileNotFoundException e) { - LOG.error("Upload failed {}", e); - throw new ArtifactUploadFailedException(i18n.get("message.file.not.found")); - } catch (final IOException e) { - LOG.error("Upload failed {}", e); - throw new ArtifactUploadFailedException(i18n.get("message.upload.failed")); - } - } - - Boolean validate() { - if (!isSoftwareModuleSelected()) { - uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected")); - - return false; - } - return true; - } - - SoftwareModule getSoftwareModuleSelected() { - if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) { - return artifactUploadState.getSelectedBaseSoftwareModule().get(); - } - return null; - } - - Boolean isSoftwareModuleSelected() { - if (!artifactUploadState.getSelectedBaseSwModuleId().isPresent()) { - return false; - } - return true; - } - - /** - * Check if file selected is duplicate.i,e already selected for upload for - * same software module. - * - * @param name - * file name - * @return Boolean - */ - public Boolean checkIfFileIsDuplicate(final String name) { - Boolean isDuplicate = false; - final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); - final String currentBaseSoftwareModuleKey = HawkbitCommonUtil - .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); - - for (final CustomFile customFile : artifactUploadState.getFileSelected()) { - final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( - customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); - if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) { - isDuplicate = true; - break; - } - } - return isDuplicate; - } - - void decreaseNumberOfFileUploadsExpected() { - numberOfFileUploadsExpected.decrementAndGet(); - } - - List getDuplicateFileNamesList() { - return duplicateFileNamesList; - } - - /** - * Update pending action count. - */ - void updateActionCount() { - if (!artifactUploadState.getFileSelected().isEmpty()) { - processBtn.setCaption(SPUILabelDefinitions.PROCESS + "
" - + artifactUploadState.getFileSelected().size() + "
"); - } else { - processBtn.setCaption(SPUILabelDefinitions.PROCESS); - } - } - - void displayDuplicateMessageAfterStreamingAll() { - // check if streaming of all dropped files are completed - if (numberOfFilesActuallyUpload.intValue() == numberOfFileUploadsExpected.intValue()) { - showDuplicateMessage(); - } - } - - /** - * Show duplicate file selected message. - */ - public void showDuplicateMessage() { - if (!duplicateFileNamesList.isEmpty()) { - final String fileNames = StringUtils.collectionToCommaDelimitedString(duplicateFileNamesList); - if (duplicateFileNamesList.size() == 1) { - uiNotification.displayValidationError(i18n.get("message.no.duplicateFile") + fileNames); - - } else if (duplicateFileNamesList.size() > 1) { - uiNotification.displayValidationError(i18n.get("message.no.duplicateFiles")); - } - duplicateFileNamesList.clear(); - } - } - - void increaseNumberOfFileUploadsExpected() { - numberOfFileUploadsExpected.incrementAndGet(); - } - - void updateFileSize(final String name, final long size) { - final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); - final String currentBaseSoftwareModuleKey = HawkbitCommonUtil - .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); - - for (final CustomFile customFile : artifactUploadState.getFileSelected()) { - final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( - customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); - if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) { - customFile.setFileSize(size); - break; - } - } - } - - void increaseNumberOfFilesActuallyUpload() { - numberOfFilesActuallyUpload.incrementAndGet(); - } - - /** - * Enable process button once upload is completed. - */ - boolean enableProcessBtn() { - if (numberOfFilesActuallyUpload.intValue() >= numberOfFileUploadsExpected.intValue()) { - processBtn.setEnabled(true); - numberOfFileUploadsExpected.set(0); - numberOfFilesActuallyUpload.set(0); - return true; - } - return false; - } - - Set getFileSelected() { - return artifactUploadState.getFileSelected(); - } - - private void discardUploadData(final Button.ClickEvent event) { - if (event.getButton().equals(discardBtn)) { - if (artifactUploadState.getFileSelected().isEmpty()) { - uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); - - } else { - clearFileList(); - } - } - } - - /** - * Clear details. - */ - void clearFileList() { - // delete file system zombies - artifactUploadState.getFileSelected().forEach(customFile -> { - final File file = new File(customFile.getFilePath()); - file.delete(); - }); - - artifactUploadState.getFileSelected().clear(); - artifactUploadState.getBaseSwModuleList().clear(); - processBtn.setCaption(SPUILabelDefinitions.PROCESS); - /* disable when there is no files to upload. */ - processBtn.setEnabled(false); - numberOfFileUploadsExpected.set(0); - numberOfFilesActuallyUpload.set(0); - duplicateFileNamesList.clear(); - } - - private void setConfirmationPopupHeightWidth(final float newWidth, final float newHeight) { - if (currentUploadConfirmationwindow != null) { - currentUploadConfirmationwindow.getUploadArtifactDetails().setWidth(HawkbitCommonUtil - .getArtifactUploadPopupWidth(newWidth, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), - Unit.PIXELS); - currentUploadConfirmationwindow.getUploadDetailsTable().setHeight(HawkbitCommonUtil - .getArtifactUploadPopupHeight(newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), - Unit.PIXELS); - } - } - - /** - * Set artifact upload result pop up size changes. - * - * @param newWidth - * new width of result pop up - * @param newHeight - * new height of result pop up - */ - void setResultPopupHeightWidth(final float newWidth, final float newHeight) { - if (currentUploadConfirmationwindow != null - && currentUploadConfirmationwindow.getCurrentUploadResultWindow() != null) { - final UploadResultWindow uploadResultWindow = currentUploadConfirmationwindow - .getCurrentUploadResultWindow(); - uploadResultWindow.getUploadResultsWindow().setWidth(HawkbitCommonUtil.getArtifactUploadPopupWidth(newWidth, - SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), Unit.PIXELS); - uploadResultWindow.getUploadResultTable().setHeight(HawkbitCommonUtil.getArtifactUploadPopupHeight( - newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), Unit.PIXELS); - } - } - - private void displayConfirmWindow(final Button.ClickEvent event) { - if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON)) { - if (artifactUploadState.getFileSelected().isEmpty()) { - uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); - } else { - currentUploadConfirmationwindow = new UploadConfirmationwindow(this, artifactUploadState); - UI.getCurrent().addWindow(currentUploadConfirmationwindow.getUploadConfrimationWindow()); - setConfirmationPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(), - Page.getCurrent().getBrowserWindowHeight()); - } - } - } - - /** - * @return - */ - I18N getI18n() { - return i18n; - } - - /** - * @return - */ - SPInfo getSPInfo() { - return spInfo; - } - - void setCurrentUploadConfirmationwindow(final UploadConfirmationwindow currentUploadConfirmationwindow) { - this.currentUploadConfirmationwindow = currentUploadConfirmationwindow; - } - - /** - * @return - */ - - VerticalLayout getDropAreaLayout() { - return dropAreaLayout; - } - - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final UploadArtifactUIEvent event) { - if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE) { - ui.access(() -> updateActionCount()); - } - } - - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); - } - - /** - * set upload status and confirmation window. - * - * @param newWidth - * browser width - * @param newHeight - * browser height - */ - public void setUploadPopupSize(final float newWidth, final float newHeight) { - setConfirmationPopupHeightWidth(newWidth, newHeight); - setResultPopupHeightWidth(newWidth, newHeight); - } - - /** - * @param selectedBaseSoftwareModule - */ - public void refreshArtifactDetailsLayout(final SoftwareModule selectedBaseSoftwareModule) { - eventBus.publish(this, - new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED, selectedBaseSoftwareModule)); - } - - /** - * @return the fileUploadLayout - */ - public HorizontalLayout getFileUploadLayout() { - return fileUploadLayout; - } - - public UINotification getUINotification() { - return uiNotification; - } + private final List duplicateFileNamesList = new ArrayList(); + + private Button processBtn; + + private Button discardBtn; + + private UploadConfirmationwindow currentUploadConfirmationwindow; + + private VerticalLayout dropAreaLayout; + + private UI ui; + + private HorizontalLayout fileUploadLayout; + + private DragAndDropWrapper dropAreaWrapper; + + private Boolean hasDirectory = Boolean.FALSE; + + /** + * Initialize the upload layout. + */ + @PostConstruct + void init() { + createComponents(); + buildLayout(); + updateActionCount(); + eventBus.subscribe(this); + ui = UI.getCurrent(); + } + + private void createComponents() { + + createProcessButton(); + createDiscardBtn(); + } + + private void buildLayout() { + + final Upload upload = new Upload(); + final UploadHandler uploadHandler = new UploadHandler(null, 0, this, uploadInfoWindow, + spInfo.getMaxArtifactFileSize(), upload, null); + upload.setButtonCaption(i18n.get("upload.file")); + upload.setImmediate(true); + upload.setReceiver(uploadHandler); + upload.addSucceededListener(uploadHandler); + upload.addFailedListener(uploadHandler); + upload.addFinishedListener(uploadHandler); + upload.addProgressListener(uploadHandler); + upload.addStartedListener(uploadHandler); + upload.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); + + fileUploadLayout = new HorizontalLayout(); + fileUploadLayout.setSpacing(true); + fileUploadLayout.addComponent(upload); + fileUploadLayout.setComponentAlignment(upload, Alignment.MIDDLE_LEFT); + fileUploadLayout.addComponent(processBtn); + fileUploadLayout.setComponentAlignment(processBtn, Alignment.MIDDLE_RIGHT); + fileUploadLayout.addComponent(discardBtn); + fileUploadLayout.setComponentAlignment(discardBtn, Alignment.MIDDLE_RIGHT); + setMargin(false); + + /* create drag-drop wrapper for drop area */ + dropAreaWrapper = new DragAndDropWrapper(createDropAreaLayout()); + dropAreaWrapper.setDropHandler(new DropAreahandler()); + setSizeFull(); + setSpacing(true); + + } + + public DragAndDropWrapper getDropAreaWrapper() { + return dropAreaWrapper; + } + + private class DropAreahandler implements DropHandler { + + private static final long serialVersionUID = 1L; + + @Override + public AcceptCriterion getAcceptCriterion() { + return AcceptAll.get(); + } + + @Override + public void drop(final DragAndDropEvent event) { + if (validate()) { + ((WrapperTransferable) event.getTransferable()).getDraggedComponent(); + final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); + if (files != null) { + for (final Html5File file : files) { + if (!isDirectory(file)) { + if (!checkForDuplicate(file.getFileName())) { + numberOfFileUploadsExpected.incrementAndGet(); + file.setStreamVariable(createStreamVariable(file)); + } + } else { + hasDirectory = Boolean.TRUE; + } + } + if (numberOfFileUploadsExpected.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 display message accordingly + displayCompositeMessage(hasDirectory); + } + } + } + } + } + + private static boolean isDirectory(final Html5File file) { + if (Strings.isNullOrEmpty(file.getType()) && file.getFileSize() % 4096 == 0) { + return true; + } + return false; + } + + private void displayCompositeMessage(final Boolean hasDirectory) { + final String duplicateMessage = showDuplicateMessage(); + final StringBuilder compositeMessage = new StringBuilder(); + if (null != duplicateMessage) { + // in case if all selected files are duplicate ,then display + // messag + compositeMessage.append(duplicateMessage); + } + if (hasDirectory) { + if (compositeMessage.length() > 0) { + compositeMessage.append("
"); + } + compositeMessage.append(i18n.get("message.no.directory.upload")); + } + if (!compositeMessage.toString().isEmpty()) { + uiNotification.displayValidationError(compositeMessage.toString()); + } + } + + private VerticalLayout createDropAreaLayout() { + dropAreaLayout = new VerticalLayout(); + final Label dropHereLabel = new Label("Drop files to upload"); + dropHereLabel.setWidth(null); + + final Label dropIcon = new Label(FontAwesome.ARROW_DOWN.getHtml(), ContentMode.HTML); + dropIcon.addStyleName("drop-icon"); + dropIcon.setWidth(null); + + dropAreaLayout.addComponent(dropIcon); + dropAreaLayout.setComponentAlignment(dropIcon, Alignment.BOTTOM_CENTER); + dropAreaLayout.addComponent(dropHereLabel); + dropAreaLayout.setComponentAlignment(dropHereLabel, Alignment.TOP_CENTER); + dropAreaLayout.setSizeFull(); + dropAreaLayout.setStyleName("upload-drop-area-layout-info"); + dropAreaLayout.setSpacing(false); + return dropAreaLayout; + } + + private void createProcessButton() { + processBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON, + SPUILabelDefinitions.PROCESS, SPUILabelDefinitions.PROCESS, null, false, null, + SPUIButtonStyleSmall.class); + processBtn.setIcon(FontAwesome.BELL); + processBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); + processBtn.addClickListener(event -> displayConfirmWindow(event)); + processBtn.setHtmlContentAllowed(true); + if (artifactUploadState.getFileSelected().isEmpty()) { + processBtn.setEnabled(false); + } + } + + private void createDiscardBtn() { + discardBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_DISCARD_BUTTON, + SPUILabelDefinitions.DISCARD, SPUILabelDefinitions.DISCARD, null, false, null, + SPUIButtonStyleSmall.class); + discardBtn.setIcon(FontAwesome.TRASH_O); + discardBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); + discardBtn.addClickListener(event -> discardUploadData(event)); + } + + private StreamVariable createStreamVariable(final Html5File file) { + return new UploadHandler(file.getFileName(), file.getFileSize(), this, uploadInfoWindow, + spInfo.getMaxArtifactFileSize(), null, file.getType()); + } + + boolean checkForDuplicate(final String filename) { + final Boolean isDuplicate = checkIfFileIsDuplicate(filename); + if (isDuplicate) { + getDuplicateFileNamesList().add(filename); + } + return isDuplicate; + } + + @EventBusListenerMethod(scope = EventScope.SESSION) + void toggleProcessButton(final UploadArtifactUIEvent event) { + if (event == UploadArtifactUIEvent.ENABLE_PROCESS_BUTTON) { + processBtn.setEnabled(true); + } else if (event == UploadArtifactUIEvent.DISABLE_PROCESS_BUTTON) { + processBtn.setEnabled(false); + } + } + + /** + * Save uploaded file details. + * + * @param stream + * read from uploaded file + * @param name + * file name + * @param size + * file size + * @param mimeType + * the mimeType of the file + * @throws IOException + * in case of upload errors + */ + OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType) { + 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()); + + final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), + selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion(), mimeType); + + artifactUploadState.getFileSelected().add(customFile); + processBtn.setEnabled(false); + + if (!artifactUploadState.getBaseSwModuleList().keySet().contains(currentBaseSoftwareModuleKey)) { + artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSoftwareModule); + } + return out; + } catch (final FileNotFoundException e) { + LOG.error("Upload failed {}", e); + throw new ArtifactUploadFailedException(i18n.get("message.file.not.found")); + } catch (final IOException e) { + LOG.error("Upload failed {}", e); + throw new ArtifactUploadFailedException(i18n.get("message.upload.failed")); + } + } + + Boolean validate() { + if (!isSoftwareModuleSelected()) { + uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected")); + return false; + } + return true; + } + + SoftwareModule getSoftwareModuleSelected() { + if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) { + return artifactUploadState.getSelectedBaseSoftwareModule().get(); + } + return null; + } + + Boolean isSoftwareModuleSelected() { + if (!artifactUploadState.getSelectedBaseSwModuleId().isPresent()) { + return false; + } + return true; + } + + /** + * Check if file selected is duplicate.i,e already selected for upload for + * same software module. + * + * @param name + * file name + * @return Boolean + */ + public Boolean checkIfFileIsDuplicate(final String name) { + Boolean isDuplicate = false; + final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); + final String currentBaseSoftwareModuleKey = HawkbitCommonUtil + .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); + + for (final CustomFile customFile : artifactUploadState.getFileSelected()) { + final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( + customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); + if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) { + isDuplicate = true; + break; + } + } + return isDuplicate; + } + + void decreaseNumberOfFileUploadsExpected() { + numberOfFileUploadsExpected.decrementAndGet(); + } + + List getDuplicateFileNamesList() { + return duplicateFileNamesList; + } + + /** + * Update pending action count. + */ + void updateActionCount() { + if (!artifactUploadState.getFileSelected().isEmpty()) { + processBtn.setCaption(SPUILabelDefinitions.PROCESS + "
" + + artifactUploadState.getFileSelected().size() + "
"); + } else { + processBtn.setCaption(SPUILabelDefinitions.PROCESS); + } + } + + void displayValidationMessage() { + // check if streaming of all dropped files are completed + if (numberOfFilesActuallyUpload.intValue() == numberOfFileUploadsExpected.intValue()) { + displayCompositeMessage(hasDirectory); + } + } + + /** + * Show duplicate file selected message. + * + * @return duplicate file names + */ + public String showDuplicateMessage() { + if (!duplicateFileNamesList.isEmpty()) { + final String fileNames = StringUtils.collectionToCommaDelimitedString(duplicateFileNamesList); + if (duplicateFileNamesList.size() == 1) { + return i18n.get("message.no.duplicateFile") + fileNames; + + } else if (duplicateFileNamesList.size() > 1) { + return i18n.get("message.no.duplicateFiles"); + } + duplicateFileNamesList.clear(); + } + return null; + } + + void increaseNumberOfFileUploadsExpected() { + numberOfFileUploadsExpected.incrementAndGet(); + } + + void updateFileSize(final String name, final long size) { + final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); + final String currentBaseSoftwareModuleKey = HawkbitCommonUtil + .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); + + for (final CustomFile customFile : artifactUploadState.getFileSelected()) { + final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( + customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); + if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) { + customFile.setFileSize(size); + break; + } + } + } + + void increaseNumberOfFilesActuallyUpload() { + numberOfFilesActuallyUpload.incrementAndGet(); + } + + /** + * Enable process button once upload is completed. + */ + boolean enableProcessBtn() { + if (numberOfFilesActuallyUpload.intValue() >= numberOfFileUploadsExpected.intValue()) { + processBtn.setEnabled(true); + numberOfFileUploadsExpected.set(0); + numberOfFilesActuallyUpload.set(0); + return true; + } + return false; + } + + Set getFileSelected() { + return artifactUploadState.getFileSelected(); + } + + private void discardUploadData(final Button.ClickEvent event) { + if (event.getButton().equals(discardBtn)) { + if (artifactUploadState.getFileSelected().isEmpty()) { + uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); + + } else { + clearFileList(); + } + } + } + + /** + * Clear details. + */ + void clearFileList() { + // delete file system zombies + artifactUploadState.getFileSelected().forEach(customFile -> { + final File file = new File(customFile.getFilePath()); + file.delete(); + }); + + artifactUploadState.getFileSelected().clear(); + artifactUploadState.getBaseSwModuleList().clear(); + processBtn.setCaption(SPUILabelDefinitions.PROCESS); + /* disable when there is no files to upload. */ + processBtn.setEnabled(false); + numberOfFileUploadsExpected.set(0); + numberOfFilesActuallyUpload.set(0); + duplicateFileNamesList.clear(); + } + + private void setConfirmationPopupHeightWidth(final float newWidth, final float newHeight) { + if (currentUploadConfirmationwindow != null) { + currentUploadConfirmationwindow.getUploadArtifactDetails().setWidth(HawkbitCommonUtil + .getArtifactUploadPopupWidth(newWidth, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), + Unit.PIXELS); + currentUploadConfirmationwindow.getUploadDetailsTable().setHeight(HawkbitCommonUtil + .getArtifactUploadPopupHeight(newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), + Unit.PIXELS); + } + } + + /** + * Set artifact upload result pop up size changes. + * + * @param newWidth + * new width of result pop up + * @param newHeight + * new height of result pop up + */ + void setResultPopupHeightWidth(final float newWidth, final float newHeight) { + if (currentUploadConfirmationwindow != null + && currentUploadConfirmationwindow.getCurrentUploadResultWindow() != null) { + final UploadResultWindow uploadResultWindow = currentUploadConfirmationwindow + .getCurrentUploadResultWindow(); + uploadResultWindow.getUploadResultsWindow().setWidth(HawkbitCommonUtil.getArtifactUploadPopupWidth(newWidth, + SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), Unit.PIXELS); + uploadResultWindow.getUploadResultTable().setHeight(HawkbitCommonUtil.getArtifactUploadPopupHeight( + newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), Unit.PIXELS); + } + } + + private void displayConfirmWindow(final Button.ClickEvent event) { + if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON)) { + if (artifactUploadState.getFileSelected().isEmpty()) { + uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); + } else { + currentUploadConfirmationwindow = new UploadConfirmationwindow(this, artifactUploadState); + UI.getCurrent().addWindow(currentUploadConfirmationwindow.getUploadConfrimationWindow()); + setConfirmationPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(), + Page.getCurrent().getBrowserWindowHeight()); + } + } + } + + /** + * @return + */ + I18N getI18n() { + return i18n; + } + + /** + * @return + */ + SPInfo getSPInfo() { + return spInfo; + } + + void setCurrentUploadConfirmationwindow(final UploadConfirmationwindow currentUploadConfirmationwindow) { + this.currentUploadConfirmationwindow = currentUploadConfirmationwindow; + } + + /** + * @return + */ + + VerticalLayout getDropAreaLayout() { + return dropAreaLayout; + } + + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final UploadArtifactUIEvent event) { + if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE) { + ui.access(() -> updateActionCount()); + } + } + + @PreDestroy + void destroy() { + /* + * It's good manners to do this, even though vaadin-spring will + * automatically unsubscribe when this UI is garbage collected. + */ + eventBus.unsubscribe(this); + } + + /** + * set upload status and confirmation window. + * + * @param newWidth + * browser width + * @param newHeight + * browser height + */ + public void setUploadPopupSize(final float newWidth, final float newHeight) { + setConfirmationPopupHeightWidth(newWidth, newHeight); + setResultPopupHeightWidth(newWidth, newHeight); + } + + /** + * @param selectedBaseSoftwareModule + */ + public void refreshArtifactDetailsLayout(final SoftwareModule selectedBaseSoftwareModule) { + eventBus.publish(this, + new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED, selectedBaseSoftwareModule)); + } + + /** + * @return the fileUploadLayout + */ + public HorizontalLayout getFileUploadLayout() { + return fileUploadLayout; + } + + public UINotification getUINotification() { + return uiNotification; + } } From 7237e352ff7800b2b7da8063fc1a2e7b5d686c52 Mon Sep 17 00:00:00 2001 From: asharani-murugesh Date: Mon, 8 Feb 2016 11:55:57 +0100 Subject: [PATCH 02/10] Bug fixed Signed-off-by: asharani-murugesh --- .../ui/artifacts/upload/UploadHandler.java | 7 +- .../ui/artifacts/upload/UploadLayout.java | 838 +++++++++--------- 2 files changed, 421 insertions(+), 424 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index ed4e22ba0..3d7ce0886 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -89,7 +89,6 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene @Override public final OutputStream getOutputStream() { try { - view.getDuplicateFileNamesList().clear(); return view.saveUploadedFileDetails(fileName, fileSize, mimeType); } catch (final ArtifactUploadFailedException e) { LOG.error("Atifact upload failed {} ", e); @@ -109,7 +108,6 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public OutputStream receiveUpload(final String fileName, final String mimeType) { this.fileName = fileName; this.mimeType = mimeType; - view.getDuplicateFileNamesList().clear(); try { if (view.validate()) { if (view.checkForDuplicate(fileName)) { @@ -169,7 +167,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene view.updateActionCount(); // display the duplicate message after streaming all files - view.displayValidationMessage(); + view.displayDuplicateValidationMessage(); } /** @@ -294,7 +292,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene if (view.enableProcessBtn()) { infoWindow.uploadSessionFinished(); } - view.displayValidationMessage(); + view.displayDuplicateValidationMessage(); LOG.info("Streaming failed due to :{}", event.getException()); } @@ -318,7 +316,6 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene } view.updateActionCount(); infoWindow.uploadFailed(event.getFilename(), failureReason); - LOG.info("Upload failed for file :{}", event.getReason()); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index b944006ff..0f9bcd5cc 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -71,123 +71,123 @@ import com.vaadin.ui.VerticalLayout; /** * Upload files layout. * - * @author G Venkata Narayana (RBEI/BSO3) + * */ @ViewScope @SpringComponent public class UploadLayout extends VerticalLayout { - private static final long serialVersionUID = -566164756606779220L; + private static final long serialVersionUID = -566164756606779220L; - private static final Logger LOG = LoggerFactory.getLogger(UploadLayout.class); + private static final Logger LOG = LoggerFactory.getLogger(UploadLayout.class); - @Autowired - private UploadStatusInfoWindow uploadInfoWindow; + @Autowired + private UploadStatusInfoWindow uploadInfoWindow; - @Autowired - private I18N i18n; + @Autowired + private I18N i18n; - @Autowired - private transient UINotification uiNotification; + @Autowired + private transient UINotification uiNotification; - @Autowired - private transient EventBus.SessionEventBus eventBus; + @Autowired + private transient EventBus.SessionEventBus eventBus; - @Autowired - private ArtifactUploadState artifactUploadState; + @Autowired + private ArtifactUploadState artifactUploadState; - @Autowired - private transient SPInfo spInfo; + @Autowired + private transient SPInfo spInfo; - private final AtomicInteger numberOfFileUploadsExpected = new AtomicInteger(); + private final AtomicInteger numberOfFileUploadsExpected = new AtomicInteger(); - private final AtomicInteger numberOfFilesActuallyUpload = new AtomicInteger(); + private final AtomicInteger numberOfFilesActuallyUpload = new AtomicInteger(); - private final List duplicateFileNamesList = new ArrayList(); + private final List duplicateFileNamesList = new ArrayList(); - private Button processBtn; + private Button processBtn; - private Button discardBtn; + private Button discardBtn; - private UploadConfirmationwindow currentUploadConfirmationwindow; + private UploadConfirmationwindow currentUploadConfirmationwindow; - private VerticalLayout dropAreaLayout; + private VerticalLayout dropAreaLayout; - private UI ui; + private UI ui; - private HorizontalLayout fileUploadLayout; + private HorizontalLayout fileUploadLayout; - private DragAndDropWrapper dropAreaWrapper; + private DragAndDropWrapper dropAreaWrapper; private Boolean hasDirectory = Boolean.FALSE; - /** - * Initialize the upload layout. - */ - @PostConstruct - void init() { - createComponents(); - buildLayout(); - updateActionCount(); - eventBus.subscribe(this); - ui = UI.getCurrent(); - } + /** + * Initialize the upload layout. + */ + @PostConstruct + void init() { + createComponents(); + buildLayout(); + updateActionCount(); + eventBus.subscribe(this); + ui = UI.getCurrent(); + } - private void createComponents() { + private void createComponents() { - createProcessButton(); - createDiscardBtn(); - } + createProcessButton(); + createDiscardBtn(); + } - private void buildLayout() { + private void buildLayout() { - final Upload upload = new Upload(); - final UploadHandler uploadHandler = new UploadHandler(null, 0, this, uploadInfoWindow, - spInfo.getMaxArtifactFileSize(), upload, null); - upload.setButtonCaption(i18n.get("upload.file")); - upload.setImmediate(true); - upload.setReceiver(uploadHandler); - upload.addSucceededListener(uploadHandler); - upload.addFailedListener(uploadHandler); - upload.addFinishedListener(uploadHandler); - upload.addProgressListener(uploadHandler); - upload.addStartedListener(uploadHandler); - upload.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); + final Upload upload = new Upload(); + final UploadHandler uploadHandler = new UploadHandler(null, 0, this, uploadInfoWindow, + spInfo.getMaxArtifactFileSize(), upload, null); + upload.setButtonCaption(i18n.get("upload.file")); + upload.setImmediate(true); + upload.setReceiver(uploadHandler); + upload.addSucceededListener(uploadHandler); + upload.addFailedListener(uploadHandler); + upload.addFinishedListener(uploadHandler); + upload.addProgressListener(uploadHandler); + upload.addStartedListener(uploadHandler); + upload.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); - fileUploadLayout = new HorizontalLayout(); - fileUploadLayout.setSpacing(true); - fileUploadLayout.addComponent(upload); - fileUploadLayout.setComponentAlignment(upload, Alignment.MIDDLE_LEFT); - fileUploadLayout.addComponent(processBtn); - fileUploadLayout.setComponentAlignment(processBtn, Alignment.MIDDLE_RIGHT); - fileUploadLayout.addComponent(discardBtn); - fileUploadLayout.setComponentAlignment(discardBtn, Alignment.MIDDLE_RIGHT); - setMargin(false); + fileUploadLayout = new HorizontalLayout(); + fileUploadLayout.setSpacing(true); + fileUploadLayout.addComponent(upload); + fileUploadLayout.setComponentAlignment(upload, Alignment.MIDDLE_LEFT); + fileUploadLayout.addComponent(processBtn); + fileUploadLayout.setComponentAlignment(processBtn, Alignment.MIDDLE_RIGHT); + fileUploadLayout.addComponent(discardBtn); + fileUploadLayout.setComponentAlignment(discardBtn, Alignment.MIDDLE_RIGHT); + setMargin(false); - /* create drag-drop wrapper for drop area */ - dropAreaWrapper = new DragAndDropWrapper(createDropAreaLayout()); - dropAreaWrapper.setDropHandler(new DropAreahandler()); - setSizeFull(); - setSpacing(true); + /* create drag-drop wrapper for drop area */ + dropAreaWrapper = new DragAndDropWrapper(createDropAreaLayout()); + dropAreaWrapper.setDropHandler(new DropAreahandler()); + setSizeFull(); + setSpacing(true); - } + } - public DragAndDropWrapper getDropAreaWrapper() { - return dropAreaWrapper; - } + public DragAndDropWrapper getDropAreaWrapper() { + return dropAreaWrapper; + } - private class DropAreahandler implements DropHandler { + private class DropAreahandler implements DropHandler { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - @Override - public AcceptCriterion getAcceptCriterion() { - return AcceptAll.get(); - } + @Override + public AcceptCriterion getAcceptCriterion() { + return AcceptAll.get(); + } - @Override - public void drop(final DragAndDropEvent event) { - if (validate()) { + @Override + public void drop(final DragAndDropEvent event) { + if (validate()) { ((WrapperTransferable) event.getTransferable()).getDraggedComponent(); final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); if (files != null) { @@ -207,12 +207,12 @@ public class UploadLayout extends VerticalLayout { uploadInfoWindow.uploadSessionStarted(); } else { //If the upload is not started, it signifies all dropped files as either duplicate or directory.So display message accordingly - displayCompositeMessage(hasDirectory); + displayCompositeMessage(); } } } - } - } + } + } private static boolean isDirectory(final Html5File file) { if (Strings.isNullOrEmpty(file.getType()) && file.getFileSize() % 4096 == 0) { @@ -221,12 +221,10 @@ public class UploadLayout extends VerticalLayout { return false; } - private void displayCompositeMessage(final Boolean hasDirectory) { - final String duplicateMessage = showDuplicateMessage(); + private void displayCompositeMessage() { + final String duplicateMessage = getDuplicateFileValidationMessage(); final StringBuilder compositeMessage = new StringBuilder(); - if (null != duplicateMessage) { - // in case if all selected files are duplicate ,then display - // messag + if (!Strings.isNullOrEmpty(duplicateMessage)) { compositeMessage.append(duplicateMessage); } if (hasDirectory) { @@ -239,395 +237,397 @@ public class UploadLayout extends VerticalLayout { uiNotification.displayValidationError(compositeMessage.toString()); } } + + private VerticalLayout createDropAreaLayout() { + dropAreaLayout = new VerticalLayout(); + final Label dropHereLabel = new Label("Drop files to upload"); + dropHereLabel.setWidth(null); - private VerticalLayout createDropAreaLayout() { - dropAreaLayout = new VerticalLayout(); - final Label dropHereLabel = new Label("Drop files to upload"); - dropHereLabel.setWidth(null); + final Label dropIcon = new Label(FontAwesome.ARROW_DOWN.getHtml(), ContentMode.HTML); + dropIcon.addStyleName("drop-icon"); + dropIcon.setWidth(null); - final Label dropIcon = new Label(FontAwesome.ARROW_DOWN.getHtml(), ContentMode.HTML); - dropIcon.addStyleName("drop-icon"); - dropIcon.setWidth(null); + dropAreaLayout.addComponent(dropIcon); + dropAreaLayout.setComponentAlignment(dropIcon, Alignment.BOTTOM_CENTER); + dropAreaLayout.addComponent(dropHereLabel); + dropAreaLayout.setComponentAlignment(dropHereLabel, Alignment.TOP_CENTER); + dropAreaLayout.setSizeFull(); + dropAreaLayout.setStyleName("upload-drop-area-layout-info"); + dropAreaLayout.setSpacing(false); + return dropAreaLayout; + } - dropAreaLayout.addComponent(dropIcon); - dropAreaLayout.setComponentAlignment(dropIcon, Alignment.BOTTOM_CENTER); - dropAreaLayout.addComponent(dropHereLabel); - dropAreaLayout.setComponentAlignment(dropHereLabel, Alignment.TOP_CENTER); - dropAreaLayout.setSizeFull(); - dropAreaLayout.setStyleName("upload-drop-area-layout-info"); - dropAreaLayout.setSpacing(false); - return dropAreaLayout; - } + private void createProcessButton() { + processBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON, + SPUILabelDefinitions.PROCESS, SPUILabelDefinitions.PROCESS, null, false, null, + SPUIButtonStyleSmall.class); + processBtn.setIcon(FontAwesome.BELL); + processBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); + processBtn.addClickListener(event -> displayConfirmWindow(event)); + processBtn.setHtmlContentAllowed(true); + if (artifactUploadState.getFileSelected().isEmpty()) { + processBtn.setEnabled(false); + } + } - private void createProcessButton() { - processBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON, - SPUILabelDefinitions.PROCESS, SPUILabelDefinitions.PROCESS, null, false, null, - SPUIButtonStyleSmall.class); - processBtn.setIcon(FontAwesome.BELL); - processBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); - processBtn.addClickListener(event -> displayConfirmWindow(event)); - processBtn.setHtmlContentAllowed(true); - if (artifactUploadState.getFileSelected().isEmpty()) { - processBtn.setEnabled(false); - } - } + private void createDiscardBtn() { + discardBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_DISCARD_BUTTON, + SPUILabelDefinitions.DISCARD, SPUILabelDefinitions.DISCARD, null, false, null, + SPUIButtonStyleSmall.class); + discardBtn.setIcon(FontAwesome.TRASH_O); + discardBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); + discardBtn.addClickListener(event -> discardUploadData(event)); + } - private void createDiscardBtn() { - discardBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_DISCARD_BUTTON, - SPUILabelDefinitions.DISCARD, SPUILabelDefinitions.DISCARD, null, false, null, - SPUIButtonStyleSmall.class); - discardBtn.setIcon(FontAwesome.TRASH_O); - discardBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); - discardBtn.addClickListener(event -> discardUploadData(event)); - } + private StreamVariable createStreamVariable(final Html5File file) { + return new UploadHandler(file.getFileName(), file.getFileSize(), this, uploadInfoWindow, + spInfo.getMaxArtifactFileSize(), null, file.getType()); + } - private StreamVariable createStreamVariable(final Html5File file) { - return new UploadHandler(file.getFileName(), file.getFileSize(), this, uploadInfoWindow, - spInfo.getMaxArtifactFileSize(), null, file.getType()); - } + boolean checkForDuplicate(final String filename) { + final Boolean isDuplicate = checkIfFileIsDuplicate(filename); + if (isDuplicate) { + getDuplicateFileNamesList().add(filename); + } + return isDuplicate; + } - boolean checkForDuplicate(final String filename) { - final Boolean isDuplicate = checkIfFileIsDuplicate(filename); - if (isDuplicate) { - getDuplicateFileNamesList().add(filename); - } - return isDuplicate; - } + @EventBusListenerMethod(scope = EventScope.SESSION) + void toggleProcessButton(final UploadArtifactUIEvent event) { + if (event == UploadArtifactUIEvent.ENABLE_PROCESS_BUTTON) { + processBtn.setEnabled(true); + } else if (event == UploadArtifactUIEvent.DISABLE_PROCESS_BUTTON) { + processBtn.setEnabled(false); + } + } - @EventBusListenerMethod(scope = EventScope.SESSION) - void toggleProcessButton(final UploadArtifactUIEvent event) { - if (event == UploadArtifactUIEvent.ENABLE_PROCESS_BUTTON) { - processBtn.setEnabled(true); - } else if (event == UploadArtifactUIEvent.DISABLE_PROCESS_BUTTON) { - processBtn.setEnabled(false); - } - } + /** + * Save uploaded file details. + * + * @param stream + * read from uploaded file + * @param name + * file name + * @param size + * file size + * @param mimeType + * the mimeType of the file + * @throws IOException + * in case of upload errors + */ + OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType) { + File tempFile = null; + try { + tempFile = File.createTempFile("spUiArtifactUpload", null); - /** - * Save uploaded file details. - * - * @param stream - * read from uploaded file - * @param name - * file name - * @param size - * file size - * @param mimeType - * the mimeType of the file - * @throws IOException - * in case of upload errors - */ - OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType) { - File tempFile = null; - try { - tempFile = File.createTempFile("spUiArtifactUpload", null); + final OutputStream out = new FileOutputStream(tempFile); - final OutputStream out = new FileOutputStream(tempFile); + final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); - final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); + final String currentBaseSoftwareModuleKey = HawkbitCommonUtil + .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); - final String currentBaseSoftwareModuleKey = HawkbitCommonUtil - .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); + final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), + selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion(), mimeType); - final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), - selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion(), mimeType); + artifactUploadState.getFileSelected().add(customFile); + processBtn.setEnabled(false); - artifactUploadState.getFileSelected().add(customFile); - processBtn.setEnabled(false); + if (!artifactUploadState.getBaseSwModuleList().keySet().contains(currentBaseSoftwareModuleKey)) { + artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSoftwareModule); + } + return out; + } catch (final FileNotFoundException e) { + LOG.error("Upload failed {}", e); + throw new ArtifactUploadFailedException(i18n.get("message.file.not.found")); + } catch (final IOException e) { + LOG.error("Upload failed {}", e); + throw new ArtifactUploadFailedException(i18n.get("message.upload.failed")); + } + } - if (!artifactUploadState.getBaseSwModuleList().keySet().contains(currentBaseSoftwareModuleKey)) { - artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSoftwareModule); - } - return out; - } catch (final FileNotFoundException e) { - LOG.error("Upload failed {}", e); - throw new ArtifactUploadFailedException(i18n.get("message.file.not.found")); - } catch (final IOException e) { - LOG.error("Upload failed {}", e); - throw new ArtifactUploadFailedException(i18n.get("message.upload.failed")); - } - } + Boolean validate() { + if (!isSoftwareModuleSelected()) { + uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected")); - Boolean validate() { - if (!isSoftwareModuleSelected()) { - uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected")); - return false; - } - return true; - } + return false; + } + return true; + } - SoftwareModule getSoftwareModuleSelected() { - if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) { - return artifactUploadState.getSelectedBaseSoftwareModule().get(); - } - return null; - } + SoftwareModule getSoftwareModuleSelected() { + if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) { + return artifactUploadState.getSelectedBaseSoftwareModule().get(); + } + return null; + } - Boolean isSoftwareModuleSelected() { - if (!artifactUploadState.getSelectedBaseSwModuleId().isPresent()) { - return false; - } - return true; - } + Boolean isSoftwareModuleSelected() { + if (!artifactUploadState.getSelectedBaseSwModuleId().isPresent()) { + return false; + } + return true; + } - /** - * Check if file selected is duplicate.i,e already selected for upload for - * same software module. - * - * @param name - * file name - * @return Boolean - */ - public Boolean checkIfFileIsDuplicate(final String name) { - Boolean isDuplicate = false; - final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); - final String currentBaseSoftwareModuleKey = HawkbitCommonUtil - .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); + /** + * Check if file selected is duplicate.i,e already selected for upload for + * same software module. + * + * @param name + * file name + * @return Boolean + */ + public Boolean checkIfFileIsDuplicate(final String name) { + Boolean isDuplicate = false; + final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); + final String currentBaseSoftwareModuleKey = HawkbitCommonUtil + .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); - for (final CustomFile customFile : artifactUploadState.getFileSelected()) { - final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( - customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); - if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) { - isDuplicate = true; - break; - } - } - return isDuplicate; - } + for (final CustomFile customFile : artifactUploadState.getFileSelected()) { + final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( + customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); + if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) { + isDuplicate = true; + break; + } + } + return isDuplicate; + } - void decreaseNumberOfFileUploadsExpected() { - numberOfFileUploadsExpected.decrementAndGet(); - } + void decreaseNumberOfFileUploadsExpected() { + numberOfFileUploadsExpected.decrementAndGet(); + } - List getDuplicateFileNamesList() { - return duplicateFileNamesList; - } + List getDuplicateFileNamesList() { + return duplicateFileNamesList; + } - /** - * Update pending action count. - */ - void updateActionCount() { - if (!artifactUploadState.getFileSelected().isEmpty()) { - processBtn.setCaption(SPUILabelDefinitions.PROCESS + "
" - + artifactUploadState.getFileSelected().size() + "
"); - } else { - processBtn.setCaption(SPUILabelDefinitions.PROCESS); - } - } + /** + * Update pending action count. + */ + void updateActionCount() { + if (!artifactUploadState.getFileSelected().isEmpty()) { + processBtn.setCaption(SPUILabelDefinitions.PROCESS + "
" + + artifactUploadState.getFileSelected().size() + "
"); + } else { + processBtn.setCaption(SPUILabelDefinitions.PROCESS); + } + } - void displayValidationMessage() { - // check if streaming of all dropped files are completed - if (numberOfFilesActuallyUpload.intValue() == numberOfFileUploadsExpected.intValue()) { - displayCompositeMessage(hasDirectory); - } - } + void displayDuplicateValidationMessage() { + // check if streaming of all dropped files are completed + if (numberOfFilesActuallyUpload.intValue() == numberOfFileUploadsExpected.intValue()) { + displayCompositeMessage(); + } + } + - /** - * Show duplicate file selected message. - * - * @return duplicate file names - */ - public String showDuplicateMessage() { + private String getDuplicateFileValidationMessage() { + StringBuilder message = new StringBuilder(); if (!duplicateFileNamesList.isEmpty()) { final String fileNames = StringUtils.collectionToCommaDelimitedString(duplicateFileNamesList); if (duplicateFileNamesList.size() == 1) { - return i18n.get("message.no.duplicateFile") + fileNames; + message.append(i18n.get("message.no.duplicateFile") + fileNames); } else if (duplicateFileNamesList.size() > 1) { - return i18n.get("message.no.duplicateFiles"); + message.append(i18n.get("message.no.duplicateFiles")); } duplicateFileNamesList.clear(); } - return null; + return message.toString(); } - void increaseNumberOfFileUploadsExpected() { - numberOfFileUploadsExpected.incrementAndGet(); + public void showDuplicateMessage() { + uiNotification.displayValidationError(getDuplicateFileValidationMessage()); } + + void increaseNumberOfFileUploadsExpected() { + numberOfFileUploadsExpected.incrementAndGet(); + } - void updateFileSize(final String name, final long size) { - final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); - final String currentBaseSoftwareModuleKey = HawkbitCommonUtil - .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); + void updateFileSize(final String name, final long size) { + final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); + final String currentBaseSoftwareModuleKey = HawkbitCommonUtil + .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); - for (final CustomFile customFile : artifactUploadState.getFileSelected()) { - final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( - customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); - if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) { - customFile.setFileSize(size); - break; - } - } - } + for (final CustomFile customFile : artifactUploadState.getFileSelected()) { + final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( + customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); + if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) { + customFile.setFileSize(size); + break; + } + } + } - void increaseNumberOfFilesActuallyUpload() { - numberOfFilesActuallyUpload.incrementAndGet(); - } + void increaseNumberOfFilesActuallyUpload() { + numberOfFilesActuallyUpload.incrementAndGet(); + } - /** - * Enable process button once upload is completed. - */ - boolean enableProcessBtn() { - if (numberOfFilesActuallyUpload.intValue() >= numberOfFileUploadsExpected.intValue()) { - processBtn.setEnabled(true); - numberOfFileUploadsExpected.set(0); - numberOfFilesActuallyUpload.set(0); - return true; - } - return false; - } + /** + * Enable process button once upload is completed. + */ + boolean enableProcessBtn() { + if (numberOfFilesActuallyUpload.intValue() >= numberOfFileUploadsExpected.intValue()) { + processBtn.setEnabled(true); + numberOfFileUploadsExpected.set(0); + numberOfFilesActuallyUpload.set(0); + return true; + } + return false; + } - Set getFileSelected() { - return artifactUploadState.getFileSelected(); - } + Set getFileSelected() { + return artifactUploadState.getFileSelected(); + } - private void discardUploadData(final Button.ClickEvent event) { - if (event.getButton().equals(discardBtn)) { - if (artifactUploadState.getFileSelected().isEmpty()) { - uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); + private void discardUploadData(final Button.ClickEvent event) { + if (event.getButton().equals(discardBtn)) { + if (artifactUploadState.getFileSelected().isEmpty()) { + uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); - } else { - clearFileList(); - } - } - } + } else { + clearFileList(); + } + } + } - /** - * Clear details. - */ - void clearFileList() { - // delete file system zombies - artifactUploadState.getFileSelected().forEach(customFile -> { - final File file = new File(customFile.getFilePath()); - file.delete(); - }); + /** + * Clear details. + */ + void clearFileList() { + // delete file system zombies + artifactUploadState.getFileSelected().forEach(customFile -> { + final File file = new File(customFile.getFilePath()); + file.delete(); + }); - artifactUploadState.getFileSelected().clear(); - artifactUploadState.getBaseSwModuleList().clear(); - processBtn.setCaption(SPUILabelDefinitions.PROCESS); - /* disable when there is no files to upload. */ - processBtn.setEnabled(false); - numberOfFileUploadsExpected.set(0); - numberOfFilesActuallyUpload.set(0); - duplicateFileNamesList.clear(); - } + artifactUploadState.getFileSelected().clear(); + artifactUploadState.getBaseSwModuleList().clear(); + processBtn.setCaption(SPUILabelDefinitions.PROCESS); + /* disable when there is no files to upload. */ + processBtn.setEnabled(false); + numberOfFileUploadsExpected.set(0); + numberOfFilesActuallyUpload.set(0); + duplicateFileNamesList.clear(); + } - private void setConfirmationPopupHeightWidth(final float newWidth, final float newHeight) { - if (currentUploadConfirmationwindow != null) { - currentUploadConfirmationwindow.getUploadArtifactDetails().setWidth(HawkbitCommonUtil - .getArtifactUploadPopupWidth(newWidth, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), - Unit.PIXELS); - currentUploadConfirmationwindow.getUploadDetailsTable().setHeight(HawkbitCommonUtil - .getArtifactUploadPopupHeight(newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), - Unit.PIXELS); - } - } + private void setConfirmationPopupHeightWidth(final float newWidth, final float newHeight) { + if (currentUploadConfirmationwindow != null) { + currentUploadConfirmationwindow.getUploadArtifactDetails().setWidth(HawkbitCommonUtil + .getArtifactUploadPopupWidth(newWidth, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), + Unit.PIXELS); + currentUploadConfirmationwindow.getUploadDetailsTable().setHeight(HawkbitCommonUtil + .getArtifactUploadPopupHeight(newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), + Unit.PIXELS); + } + } - /** - * Set artifact upload result pop up size changes. - * - * @param newWidth - * new width of result pop up - * @param newHeight - * new height of result pop up - */ - void setResultPopupHeightWidth(final float newWidth, final float newHeight) { - if (currentUploadConfirmationwindow != null - && currentUploadConfirmationwindow.getCurrentUploadResultWindow() != null) { - final UploadResultWindow uploadResultWindow = currentUploadConfirmationwindow - .getCurrentUploadResultWindow(); - uploadResultWindow.getUploadResultsWindow().setWidth(HawkbitCommonUtil.getArtifactUploadPopupWidth(newWidth, - SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), Unit.PIXELS); - uploadResultWindow.getUploadResultTable().setHeight(HawkbitCommonUtil.getArtifactUploadPopupHeight( - newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), Unit.PIXELS); - } - } + /** + * Set artifact upload result pop up size changes. + * + * @param newWidth + * new width of result pop up + * @param newHeight + * new height of result pop up + */ + void setResultPopupHeightWidth(final float newWidth, final float newHeight) { + if (currentUploadConfirmationwindow != null + && currentUploadConfirmationwindow.getCurrentUploadResultWindow() != null) { + final UploadResultWindow uploadResultWindow = currentUploadConfirmationwindow + .getCurrentUploadResultWindow(); + uploadResultWindow.getUploadResultsWindow().setWidth(HawkbitCommonUtil.getArtifactUploadPopupWidth(newWidth, + SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), Unit.PIXELS); + uploadResultWindow.getUploadResultTable().setHeight(HawkbitCommonUtil.getArtifactUploadPopupHeight( + newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), Unit.PIXELS); + } + } - private void displayConfirmWindow(final Button.ClickEvent event) { - if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON)) { - if (artifactUploadState.getFileSelected().isEmpty()) { - uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); - } else { - currentUploadConfirmationwindow = new UploadConfirmationwindow(this, artifactUploadState); - UI.getCurrent().addWindow(currentUploadConfirmationwindow.getUploadConfrimationWindow()); - setConfirmationPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(), - Page.getCurrent().getBrowserWindowHeight()); - } - } - } + private void displayConfirmWindow(final Button.ClickEvent event) { + if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON)) { + if (artifactUploadState.getFileSelected().isEmpty()) { + uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); + } else { + currentUploadConfirmationwindow = new UploadConfirmationwindow(this, artifactUploadState); + UI.getCurrent().addWindow(currentUploadConfirmationwindow.getUploadConfrimationWindow()); + setConfirmationPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(), + Page.getCurrent().getBrowserWindowHeight()); + } + } + } - /** - * @return - */ - I18N getI18n() { - return i18n; - } + /** + * @return + */ + I18N getI18n() { + return i18n; + } - /** - * @return - */ - SPInfo getSPInfo() { - return spInfo; - } + /** + * @return + */ + SPInfo getSPInfo() { + return spInfo; + } - void setCurrentUploadConfirmationwindow(final UploadConfirmationwindow currentUploadConfirmationwindow) { - this.currentUploadConfirmationwindow = currentUploadConfirmationwindow; - } + void setCurrentUploadConfirmationwindow(final UploadConfirmationwindow currentUploadConfirmationwindow) { + this.currentUploadConfirmationwindow = currentUploadConfirmationwindow; + } - /** - * @return - */ + /** + * @return + */ - VerticalLayout getDropAreaLayout() { - return dropAreaLayout; - } + VerticalLayout getDropAreaLayout() { + return dropAreaLayout; + } - @EventBusListenerMethod(scope = EventScope.SESSION) - void onEvent(final UploadArtifactUIEvent event) { - if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE) { - ui.access(() -> updateActionCount()); - } - } + @EventBusListenerMethod(scope = EventScope.SESSION) + void onEvent(final UploadArtifactUIEvent event) { + if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE) { + ui.access(() -> updateActionCount()); + } + } - @PreDestroy - void destroy() { - /* - * It's good manners to do this, even though vaadin-spring will - * automatically unsubscribe when this UI is garbage collected. - */ - eventBus.unsubscribe(this); - } + @PreDestroy + void destroy() { + /* + * It's good manners to do this, even though vaadin-spring will + * automatically unsubscribe when this UI is garbage collected. + */ + eventBus.unsubscribe(this); + } - /** - * set upload status and confirmation window. - * - * @param newWidth - * browser width - * @param newHeight - * browser height - */ - public void setUploadPopupSize(final float newWidth, final float newHeight) { - setConfirmationPopupHeightWidth(newWidth, newHeight); - setResultPopupHeightWidth(newWidth, newHeight); - } + /** + * set upload status and confirmation window. + * + * @param newWidth + * browser width + * @param newHeight + * browser height + */ + public void setUploadPopupSize(final float newWidth, final float newHeight) { + setConfirmationPopupHeightWidth(newWidth, newHeight); + setResultPopupHeightWidth(newWidth, newHeight); + } - /** - * @param selectedBaseSoftwareModule - */ - public void refreshArtifactDetailsLayout(final SoftwareModule selectedBaseSoftwareModule) { - eventBus.publish(this, - new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED, selectedBaseSoftwareModule)); - } + /** + * @param selectedBaseSoftwareModule + */ + public void refreshArtifactDetailsLayout(final SoftwareModule selectedBaseSoftwareModule) { + eventBus.publish(this, + new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED, selectedBaseSoftwareModule)); + } - /** - * @return the fileUploadLayout - */ - public HorizontalLayout getFileUploadLayout() { - return fileUploadLayout; - } + /** + * @return the fileUploadLayout + */ + public HorizontalLayout getFileUploadLayout() { + return fileUploadLayout; + } - public UINotification getUINotification() { - return uiNotification; - } + public UINotification getUINotification() { + return uiNotification; + } } From d3035ccebe7969b34a1552f516078ee1d6e9afb3 Mon Sep 17 00:00:00 2001 From: asharani-murugesh Date: Mon, 8 Feb 2016 13:20:50 +0100 Subject: [PATCH 03/10] modified error message Signed-off-by: asharani-murugesh --- .../org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java | 1 + hawkbit-ui/src/main/resources/messages.properties | 2 +- hawkbit-ui/src/main/resources/messages_de.properties | 2 +- hawkbit-ui/src/main/resources/messages_en.properties | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 0f9bcd5cc..1737d0495 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -196,6 +196,7 @@ public class UploadLayout extends VerticalLayout { if (!checkForDuplicate(file.getFileName())) { numberOfFileUploadsExpected.incrementAndGet(); file.setStreamVariable(createStreamVariable(file)); + hasDirectory = Boolean.FALSE; } } else { hasDirectory = Boolean.TRUE; diff --git a/hawkbit-ui/src/main/resources/messages.properties b/hawkbit-ui/src/main/resources/messages.properties index 8e785c3db..168920f52 100644 --- a/hawkbit-ui/src/main/resources/messages.properties +++ b/hawkbit-ui/src/main/resources/messages.properties @@ -308,7 +308,7 @@ soft.module.os =OS message.error.noFileSelected = No file selected for upload message.error.noProvidedName = Please provide custom file name message.error.noSwModuleSelected = Please select a software module -message.no.duplicateFiles = duplicate files selected +message.no.duplicateFiles = Duplicate files selected message.no.duplicateFile = Duplicate file selected : message.delete.artifact = Are you sure that you want to delete artifact {0} ? message.duplicate.filename = Duplicate file name diff --git a/hawkbit-ui/src/main/resources/messages_de.properties b/hawkbit-ui/src/main/resources/messages_de.properties index 94a0df4cf..62088946a 100644 --- a/hawkbit-ui/src/main/resources/messages_de.properties +++ b/hawkbit-ui/src/main/resources/messages_de.properties @@ -305,7 +305,7 @@ soft.module.os =OS message.error.noFileSelected = No file selected for upload message.error.noProvidedName = Please provide custom file name message.error.noSwModuleSelected = Please select a software module -message.no.duplicateFiles = duplicate files selected +message.no.duplicateFiles = Duplicate files selected message.no.duplicateFile = Duplicate file selected : message.delete.artifact = Are you sure that you want to delete artifact {0} ? message.duplicate.filename = Duplicate file name diff --git a/hawkbit-ui/src/main/resources/messages_en.properties b/hawkbit-ui/src/main/resources/messages_en.properties index d31ca2af3..075347f12 100644 --- a/hawkbit-ui/src/main/resources/messages_en.properties +++ b/hawkbit-ui/src/main/resources/messages_en.properties @@ -299,7 +299,7 @@ soft.module.os =OS message.error.noFileSelected = No file selected for upload message.error.noProvidedName = Please provide custom file name message.error.noSwModuleSelected = Please select a software module -message.no.duplicateFiles = duplicate files selected +message.no.duplicateFiles = Duplicate files selected message.no.duplicateFile = Duplicate file selected : message.delete.artifact = Are you sure that you want to delete artifact {0} ? message.duplicate.filename = Duplicate file name From 1252bfe53dcdec535d917128ed1fe5582d5bc82f Mon Sep 17 00:00:00 2001 From: asharani-murugesh Date: Tue, 16 Feb 2016 09:29:17 +0100 Subject: [PATCH 04/10] Formatted Signed-off-by: asharani-murugesh --- .../ui/artifacts/upload/UploadLayout.java | 135 +++++++++--------- 1 file changed, 68 insertions(+), 67 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 1737d0495..2e8c6a51e 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -119,7 +119,7 @@ public class UploadLayout extends VerticalLayout { private DragAndDropWrapper dropAreaWrapper; - private Boolean hasDirectory = Boolean.FALSE; + private Boolean hasDirectory = Boolean.FALSE; /** * Initialize the upload layout. @@ -187,58 +187,60 @@ public class UploadLayout extends VerticalLayout { @Override public void drop(final DragAndDropEvent event) { - if (validate()) { - ((WrapperTransferable) event.getTransferable()).getDraggedComponent(); - final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); - if (files != null) { - for (final Html5File file : files) { - if (!isDirectory(file)) { - if (!checkForDuplicate(file.getFileName())) { - numberOfFileUploadsExpected.incrementAndGet(); - file.setStreamVariable(createStreamVariable(file)); - hasDirectory = Boolean.FALSE; - } - } else { - hasDirectory = Boolean.TRUE; - } - } - if (numberOfFileUploadsExpected.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 display message accordingly - displayCompositeMessage(); - } - } - } + if (validate()) { + ((WrapperTransferable) event.getTransferable()).getDraggedComponent(); + final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); + if (files != null) { + for (final Html5File file : files) { + if (!isDirectory(file)) { + if (!checkForDuplicate(file.getFileName())) { + numberOfFileUploadsExpected.incrementAndGet(); + file.setStreamVariable(createStreamVariable(file)); + hasDirectory = Boolean.FALSE; + } + } else { + hasDirectory = Boolean.TRUE; + } + } + if (numberOfFileUploadsExpected.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 + // display message accordingly + displayCompositeMessage(); + } + } + } } } - private static boolean isDirectory(final Html5File file) { - if (Strings.isNullOrEmpty(file.getType()) && file.getFileSize() % 4096 == 0) { - return true; - } - return false; - } + private static boolean isDirectory(final Html5File file) { + if (Strings.isNullOrEmpty(file.getType()) && file.getFileSize() % 4096 == 0) { + return true; + } + return false; + } + + private void displayCompositeMessage() { + final String duplicateMessage = getDuplicateFileValidationMessage(); + final StringBuilder compositeMessage = new StringBuilder(); + if (!Strings.isNullOrEmpty(duplicateMessage)) { + compositeMessage.append(duplicateMessage); + } + if (hasDirectory) { + if (compositeMessage.length() > 0) { + compositeMessage.append("
"); + } + compositeMessage.append(i18n.get("message.no.directory.upload")); + } + if (!compositeMessage.toString().isEmpty()) { + uiNotification.displayValidationError(compositeMessage.toString()); + } + } - private void displayCompositeMessage() { - final String duplicateMessage = getDuplicateFileValidationMessage(); - final StringBuilder compositeMessage = new StringBuilder(); - if (!Strings.isNullOrEmpty(duplicateMessage)) { - compositeMessage.append(duplicateMessage); - } - if (hasDirectory) { - if (compositeMessage.length() > 0) { - compositeMessage.append("
"); - } - compositeMessage.append(i18n.get("message.no.directory.upload")); - } - if (!compositeMessage.toString().isEmpty()) { - uiNotification.displayValidationError(compositeMessage.toString()); - } - } - private VerticalLayout createDropAreaLayout() { dropAreaLayout = new VerticalLayout(); final Label dropHereLabel = new Label("Drop files to upload"); @@ -421,27 +423,26 @@ public class UploadLayout extends VerticalLayout { displayCompositeMessage(); } } - - private String getDuplicateFileValidationMessage() { - StringBuilder message = new StringBuilder(); - if (!duplicateFileNamesList.isEmpty()) { - final String fileNames = StringUtils.collectionToCommaDelimitedString(duplicateFileNamesList); - if (duplicateFileNamesList.size() == 1) { - message.append(i18n.get("message.no.duplicateFile") + fileNames); + private String getDuplicateFileValidationMessage() { + StringBuilder message = new StringBuilder(); + if (!duplicateFileNamesList.isEmpty()) { + final String fileNames = StringUtils.collectionToCommaDelimitedString(duplicateFileNamesList); + if (duplicateFileNamesList.size() == 1) { + message.append(i18n.get("message.no.duplicateFile") + fileNames); - } else if (duplicateFileNamesList.size() > 1) { - message.append(i18n.get("message.no.duplicateFiles")); - } - duplicateFileNamesList.clear(); - } - return message.toString(); - } + } else if (duplicateFileNamesList.size() > 1) { + message.append(i18n.get("message.no.duplicateFiles")); + } + duplicateFileNamesList.clear(); + } + return message.toString(); + } + + public void showDuplicateMessage() { + uiNotification.displayValidationError(getDuplicateFileValidationMessage()); + } - public void showDuplicateMessage() { - uiNotification.displayValidationError(getDuplicateFileValidationMessage()); - } - void increaseNumberOfFileUploadsExpected() { numberOfFileUploadsExpected.incrementAndGet(); } From f969d6f4c2f06e564abf1cae66e775c493209f99 Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 25 Feb 2016 14:38:25 +0100 Subject: [PATCH 05/10] clean code refactorings - add description to assertions in unit tests - make inner classes static - remove out-commented code Signed-off-by: Michael Hirsch --- .../AmqpMessageDispatcherServiceTest.java | 43 ++++++++++------ .../event/AbstractPropertyChangeEvent.java | 2 +- .../repository/ArtifactManagementTest.java | 8 +-- .../repository/SoftwareManagementTest.java | 50 +++++++++---------- .../repository/rsql/RSQLActionFieldsTest.java | 2 +- .../repository/rsql/RSQLUtilityTest.java | 16 +++--- .../rest/resource/SoftwareModuleResource.java | 46 ----------------- .../resource/model/ExceptionInfoTest.java | 13 +++-- ...ExcludePathAwareShallowETagFilterTest.java | 3 +- .../org/eclipse/hawkbit/util/IpUtilTest.java | 38 ++++++++------ 10 files changed, 99 insertions(+), 122 deletions(-) diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java index 348e8dea4..4d313dd2c 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpMessageDispatcherServiceTest.java @@ -91,7 +91,8 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent); final Message sendMessage = createArgumentCapture(targetAssignDistributionSetEvent.getTargetAdress().getHost()); final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage); - assertTrue(downloadAndUpdateRequest.getSoftwareModules().isEmpty()); + assertTrue("No softwaremmodule should be contained in the request", + downloadAndUpdateRequest.getSoftwareModules().isEmpty()); } @Test @@ -104,17 +105,22 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent); final Message sendMessage = createArgumentCapture(targetAssignDistributionSetEvent.getTargetAdress().getHost()); final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage); - assertEquals(3, downloadAndUpdateRequest.getSoftwareModules().size()); + assertEquals("Expecting a size of 3 software modules in the reuqest", 3, + downloadAndUpdateRequest.getSoftwareModules().size()); for (final org.eclipse.hawkbit.dmf.json.model.SoftwareModule softwareModule : downloadAndUpdateRequest .getSoftwareModules()) { - assertTrue(softwareModule.getArtifacts().isEmpty()); + assertTrue("Artifact list for softwaremodule should be empty", softwareModule.getArtifacts().isEmpty()); for (final SoftwareModule softwareModule2 : dsA.getModules()) { - assertNotNull(softwareModule.getModuleId()); + assertNotNull("Sofware module ID should be set", softwareModule.getModuleId()); if (!softwareModule.getModuleId().equals(softwareModule2.getId())) { continue; } - assertEquals(softwareModule.getModuleType(), softwareModule2.getType().getKey()); - assertEquals(softwareModule.getModuleVersion(), softwareModule2.getVersion()); + assertEquals( + "Software module type in event should be the same as the softwaremodule in the distribution set", + softwareModule.getModuleType(), softwareModule2.getType().getKey()); + assertEquals( + "Software module version in event should be the same as the softwaremodule in the distribution set", + softwareModule.getModuleVersion(), softwareModule2.getVersion()); } } } @@ -138,13 +144,14 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit amqpMessageDispatcherService.targetAssignDistributionSet(targetAssignDistributionSetEvent); final Message sendMessage = createArgumentCapture(targetAssignDistributionSetEvent.getTargetAdress().getHost()); final DownloadAndUpdateRequest downloadAndUpdateRequest = assertDownloadAndInstallMessage(sendMessage); - assertEquals(3, downloadAndUpdateRequest.getSoftwareModules().size()); + assertEquals("DownloadAndUpdateRequest event should contains 3 software modules", 3, + downloadAndUpdateRequest.getSoftwareModules().size()); for (final org.eclipse.hawkbit.dmf.json.model.SoftwareModule softwareModule : downloadAndUpdateRequest .getSoftwareModules()) { if (!softwareModule.getModuleId().equals(module.getId())) { continue; } - assertFalse(softwareModule.getArtifacts().isEmpty()); + assertFalse("The software module artifacts should not be empty", softwareModule.getArtifacts().isEmpty()); } } @@ -164,8 +171,8 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit private void assertCancelMessage(final Message sendMessage) { assertEventMessage(sendMessage); final Long actionId = convertMessage(sendMessage, Long.class); - assertEquals(actionId, Long.valueOf(1)); - assertEquals(EventTopic.CANCEL_DOWNLOAD, + assertEquals("Action ID should be 1", actionId, Long.valueOf(1)); + assertEquals("The topc in the message should be a CANCEL_DOWNLOAD value", EventTopic.CANCEL_DOWNLOAD, sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TOPIC)); } @@ -174,8 +181,9 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit assertEventMessage(sendMessage); final DownloadAndUpdateRequest downloadAndUpdateRequest = convertMessage(sendMessage, DownloadAndUpdateRequest.class); - assertEquals(downloadAndUpdateRequest.getActionId(), Long.valueOf(1)); - assertEquals(EventTopic.DOWNLOAD_AND_INSTALL, + assertEquals("The action ID of the downloadAndUpdateRequest event shuold be 1", + downloadAndUpdateRequest.getActionId(), Long.valueOf(1)); + assertEquals("The topic of the event shuold contain DOWNLOAD_AND_INSTALL", EventTopic.DOWNLOAD_AND_INSTALL, sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TOPIC)); return downloadAndUpdateRequest; @@ -185,11 +193,14 @@ public class AmqpMessageDispatcherServiceTest extends AbstractIntegrationTestWit * @param sendMessage */ private void assertEventMessage(final Message sendMessage) { - assertNotNull(sendMessage); + assertNotNull("The message should not be null", sendMessage); - assertEquals(CONTROLLER_ID, sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.THING_ID)); - assertEquals(MessageType.EVENT, sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TYPE)); - assertEquals(MessageProperties.CONTENT_TYPE_JSON, sendMessage.getMessageProperties().getContentType()); + assertEquals("The value of the message header THING_ID should be " + CONTROLLER_ID, CONTROLLER_ID, + sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.THING_ID)); + assertEquals("The value of the message header TYPE should be EVENT", MessageType.EVENT, + sendMessage.getMessageProperties().getHeaders().get(MessageHeaderKey.TYPE)); + assertEquals("The content type message should be " + MessageProperties.CONTENT_TYPE_JSON, + MessageProperties.CONTENT_TYPE_JSON, sendMessage.getMessageProperties().getContentType()); } protected Message createArgumentCapture(final String exchange) { diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java index 8a596eeb5..86251e675 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java @@ -47,7 +47,7 @@ public class AbstractPropertyChangeEvent extends AbstractB * Carries old value and new value of a property . * */ - public class Values { + public static class Values { private final Object oldValue; private final Object newValue; diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java index 5585aab95..2929110dd 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/ArtifactManagementTest.java @@ -150,14 +150,14 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { ExternalArtifact result = artifactManagement.createExternalArtifact(provider, null, sm.getId()); - assertNotNull(result); + assertNotNull("The result of an external artifact should not be null", result); assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(1); assertThat(result.getSoftwareModule().getId()).isEqualTo(sm.getId()); assertThat(result.getUrl()).isEqualTo("https://fhghdfjgh/{version}/"); assertThat(result.getExternalArtifactProvider()).isEqualTo(provider); result = artifactManagement.createExternalArtifact(provider, "/test", sm2.getId()); - assertNotNull(result); + assertNotNull("The newly created external artifact should not be null", result); assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(2); assertThat(result.getUrl()).isEqualTo("https://fhghdfjgh/test"); assertThat(result.getExternalArtifactProvider()).isEqualTo(provider); @@ -176,7 +176,7 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { "https://fhghdfjgh", "/{version}/"); final ExternalArtifact result = artifactManagement.createExternalArtifact(provider, null, sm.getId()); - assertNotNull(result); + assertNotNull("The newly created external artifact should not be null", result); assertThat(externalArtifactRepository.findAll()).contains(result).hasSize(1); artifactManagement.deleteExternalArtifact(result.getId()); @@ -348,7 +348,7 @@ public class ArtifactManagementTest extends AbstractIntegrationTestWithMongoDB { final LocalArtifact result = artifactManagement.createLocalArtifact(new ByteArrayInputStream(random), sm.getId(), "file1", false); - assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(random), + assertTrue("The stored binary matches the given binary", IOUtils.contentEquals(new ByteArrayInputStream(random), artifactManagement.loadLocalArtifactBinary(result).getFileInputStream())); } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java index dc9a654c7..49776e392 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SoftwareManagementTest.java @@ -159,10 +159,10 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { public void hardDeleteOfNotAssignedArtifact() { // [STEP1]: Create SoftwareModuleX with Artifacts - SoftwareModule unassignedModule = createSoftwareModuleWithArtifacts(osType, "moduleX", "3.0.2", 2); - Iterator artifactsIt = unassignedModule.getArtifacts().iterator(); - Artifact artifact1 = artifactsIt.next(); - Artifact artifact2 = artifactsIt.next(); + final SoftwareModule unassignedModule = createSoftwareModuleWithArtifacts(osType, "moduleX", "3.0.2", 2); + final Iterator artifactsIt = unassignedModule.getArtifacts().iterator(); + final Artifact artifact1 = artifactsIt.next(); + final Artifact artifact2 = artifactsIt.next(); // [STEP2]: Delete unassigned SoftwareModule softwareManagement.deleteSoftwareModule(unassignedModule); @@ -185,7 +185,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { public void softDeleteOfAssignedArtifact() { // Init DistributionSet - DistributionSet disSet = distributionSetManagement + final DistributionSet disSet = distributionSetManagement .createDistributionSet(new DistributionSet("ds1", "v1.0", "test ds", standardDsType, null)); // [STEP1]: Create SoftwareModuleX with ArtifactX @@ -200,14 +200,14 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { // [VERIFY EXPECTED RESULT]: // verify: assignedModule is marked as deleted assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId()); - assertTrue(assignedModule.isDeleted()); + assertTrue("The module should be flagged as deleted", assignedModule.isDeleted()); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); assertThat(softwareModuleRepository.findAll()).hasSize(1); // verify: binary data is deleted - Iterator artifactsIt = assignedModule.getArtifacts().iterator(); - Artifact artifact1 = artifactsIt.next(); - Artifact artifact2 = artifactsIt.next(); + final Iterator artifactsIt = assignedModule.getArtifacts().iterator(); + final Artifact artifact1 = artifactsIt.next(); + final Artifact artifact2 = artifactsIt.next(); assertArtfiactNull(artifact1, artifact2); // verify: artifact meta data is still available @@ -221,7 +221,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { // Init target and DistributionSet final Target target = targetManagement.createTarget(new Target("test123")); - DistributionSet disSet = distributionSetManagement + final DistributionSet disSet = distributionSetManagement .createDistributionSet(new DistributionSet("ds1", "v1.0", "test ds", standardDsType, null)); // [STEP1]: Create SoftwareModuleX and include the new ArtifactX @@ -242,14 +242,14 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { // [VERIFY EXPECTED RESULT]: // verify: assignedModule is marked as deleted assignedModule = softwareManagement.findSoftwareModuleById(assignedModule.getId()); - assertTrue(assignedModule.isDeleted()); + assertTrue("The found module should be flagged deleted", assignedModule.isDeleted()); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); assertThat(softwareModuleRepository.findAll()).hasSize(1); // verify: binary data is deleted - Iterator artifactsIt = assignedModule.getArtifacts().iterator(); - Artifact artifact1 = artifactsIt.next(); - Artifact artifact2 = artifactsIt.next(); + final Iterator artifactsIt = assignedModule.getArtifacts().iterator(); + final Artifact artifact1 = artifactsIt.next(); + final Artifact artifact2 = artifactsIt.next(); assertArtfiactNull(artifact1, artifact2); // verify: artifact meta data is still available @@ -265,7 +265,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { assertThat(operations.find(new Query())).hasSize(0); // Init artifact binary data, target and DistributionSets - byte[] source = RandomUtils.nextBytes(1024); + final byte[] source = RandomUtils.nextBytes(1024); // [STEP1]: Create SoftwareModuleX and add a new ArtifactX SoftwareModule moduleX = createSoftwareModuleWithArtifacts(osType, "modulex", "v1.0", 0); @@ -273,7 +273,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { // [STEP2]: Create newArtifactX and add it to SoftwareModuleX artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false); moduleX = softwareManagement.findSoftwareModuleWithDetails(moduleX.getId()); - Artifact artifactX = moduleX.getArtifacts().iterator().next(); + final Artifact artifactX = moduleX.getArtifacts().iterator().next(); // [STEP3]: Create SoftwareModuleY and add the same ArtifactX SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0); @@ -281,7 +281,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { // [STEP4]: Assign the same ArtifactX to SoftwareModuleY artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false); moduleY = softwareManagement.findSoftwareModuleWithDetails(moduleY.getId()); - Artifact artifactY = moduleY.getArtifacts().iterator().next(); + final Artifact artifactY = moduleY.getArtifacts().iterator().next(); // verify: that only one entry was created in mongoDB assertThat(operations.find(new Query())).hasSize(1); @@ -325,14 +325,14 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleX.getId(), "artifactx", false); moduleX = softwareManagement.findSoftwareModuleWithDetails(moduleX.getId()); - Artifact artifactX = moduleX.getArtifacts().iterator().next(); + final Artifact artifactX = moduleX.getArtifacts().iterator().next(); // [STEP2]: Create SoftwareModuleY and add the same ArtifactX SoftwareModule moduleY = createSoftwareModuleWithArtifacts(osType, "moduley", "v1.0", 0); artifactManagement.createLocalArtifact(new ByteArrayInputStream(source), moduleY.getId(), "artifactx", false); moduleY = softwareManagement.findSoftwareModuleWithDetails(moduleY.getId()); - Artifact artifactY = moduleY.getArtifacts().iterator().next(); + final Artifact artifactY = moduleY.getArtifacts().iterator().next(); // verify: that only one entry was created in mongoDB assertThat(operations.find(new Query())).hasSize(1); @@ -358,8 +358,8 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { // verify: SoftwareModuleX and SofwtareModule are marked as deleted assertThat(moduleX).isNotNull(); assertThat(moduleY).isNotNull(); - assertTrue(moduleX.isDeleted()); - assertTrue(moduleY.isDeleted()); + assertTrue("The module should be flagged deleted", moduleX.isDeleted()); + assertTrue("The module should be flagged deleted", moduleY.isDeleted()); assertThat(softwareManagement.findSoftwareModulesAll(pageReq)).hasSize(0); assertThat(softwareModuleRepository.findAll()).hasSize(2); @@ -370,10 +370,10 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { assertThat(artifactRepository.findOne(artifactY.getId())).isNotNull(); } - private SoftwareModule createSoftwareModuleWithArtifacts(SoftwareModuleType type, String name, String version, - int numberArtifacts) { + private SoftwareModule createSoftwareModuleWithArtifacts(final SoftwareModuleType type, final String name, + final String version, final int numberArtifacts) { - long countSoftwareModule = softwareModuleRepository.count(); + final long countSoftwareModule = softwareModuleRepository.count(); // create SoftwareModule SoftwareModule softwareModule = softwareManagement @@ -388,7 +388,7 @@ public class SoftwareManagementTest extends AbstractIntegrationTestWithMongoDB { softwareModule = softwareManagement.findSoftwareModuleWithDetails(softwareModule.getId()); assertThat(softwareModuleRepository.findAll()).hasSize((int) countSoftwareModule + 1); - List artifacts = softwareModule.getArtifacts(); + final List artifacts = softwareModule.getArtifacts(); assertThat(artifacts).hasSize(numberArtifacts); if (numberArtifacts != 0) { diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLActionFieldsTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLActionFieldsTest.java index 71cf511ae..139b0a88d 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLActionFieldsTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLActionFieldsTest.java @@ -72,7 +72,7 @@ public class RSQLActionFieldsTest extends AbstractIntegrationTest { try { assertRSQLQuery(ActionFields.STATUS.name() + "==true", 5); - fail(); + fail("Missing expected RSQLParameterUnsupportedFieldException because status cannot be compared with 'true'"); } catch (final RSQLParameterUnsupportedFieldException e) { } } diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLUtilityTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLUtilityTest.java index 3b923d167..bcfade8d5 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLUtilityTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/rsql/RSQLUtilityTest.java @@ -63,7 +63,7 @@ public class RSQLUtilityTest { try { RSQLUtility.parse(wrongRSQL, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); - fail(); + fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax"); } catch (final RSQLParameterSyntaxException e) { } } @@ -75,7 +75,7 @@ public class RSQLUtilityTest { try { RSQLUtility.parse(wrongRSQL, SoftwareModuleFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); - fail(); + fail("Missing an expected RSQLParameterUnsupportedFieldException because of unknown RSQL field"); } catch (final RSQLParameterUnsupportedFieldException e) { } @@ -87,7 +87,7 @@ public class RSQLUtilityTest { try { RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); - fail(); + fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax"); } catch (final RSQLParameterUnsupportedFieldException e) { } @@ -95,7 +95,7 @@ public class RSQLUtilityTest { try { RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); - fail(); + fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax"); } catch (final RSQLParameterUnsupportedFieldException e) { } @@ -103,7 +103,7 @@ public class RSQLUtilityTest { try { RSQLUtility.parse(wrongRSQL, DistributionSetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); - fail(); + fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax"); } catch (final RSQLParameterUnsupportedFieldException e) { } @@ -115,7 +115,7 @@ public class RSQLUtilityTest { try { RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); - fail(); + fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax"); } catch (final RSQLParameterUnsupportedFieldException e) { } @@ -123,7 +123,7 @@ public class RSQLUtilityTest { try { RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); - fail(); + fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax"); } catch (final RSQLParameterUnsupportedFieldException e) { } @@ -131,7 +131,7 @@ public class RSQLUtilityTest { try { RSQLUtility.parse(wrongRSQL, TargetFields.class).toPredicate(baseSoftwareModuleRootMock, criteriaQueryMock, criteriaBuilderMock); - fail(); + fail("Missing expected RSQLParameterSyntaxException because of wrong RSQL syntax"); } catch (final RSQLParameterUnsupportedFieldException e) { } } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java index 9ce1a2975..dfbac1a6f 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SoftwareModuleResource.java @@ -99,52 +99,6 @@ public class SoftwareModuleResource implements SoftwareModuleRestAPI { return new ResponseEntity<>(SoftwareModuleMapper.artifactsToResponse(module.getArtifacts()), HttpStatus.OK); } - /** - * Handles the GET request for downloading an artifact. - * - * @param softwareModuleId - * of the parent SoftwareModule - * @param artifactId - * of the related LocalArtifact - * @param servletResponse - * of the servlet - * @param request - * of the client - * - * @return responseEntity with status ok if successful - */ - // @RequestMapping(method = RequestMethod.GET, value = - // RestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING - // + "/{softwareModuleId}/artifacts/{artifactId}/download") - // @ResponseBody - // public ResponseEntity downloadArtifact(@PathVariable final Long - // softwareModuleId, - // @PathVariable final Long artifactId, final HttpServletResponse - // servletResponse, - // final HttpServletRequest request) { - // final SoftwareModule module = - // findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId); - // - // if (null == module || !module.getLocalArtifact(artifactId).isPresent()) { - // return new ResponseEntity<>(HttpStatus.NOT_FOUND); - // } - // - // final LocalArtifact artifact = module.getLocalArtifact(artifactId).get(); - // final DbArtifact file = - // artifactManagement.loadLocalArtifactBinary(artifact); - // - // final String ifMatch = request.getHeader("If-Match"); - // if (ifMatch != null && - // !RestResourceConversionHelper.matchesHttpHeader(ifMatch, - // artifact.getSha1Hash())) { - // return new ResponseEntity<>(HttpStatus.PRECONDITION_FAILED); - // } - // - // return RestResourceConversionHelper.writeFileResponse(artifact, - // servletResponse, request, file); - // - // } - @Override public ResponseEntity getArtifact(@PathVariable final Long softwareModuleId, @PathVariable final Long artifactId) { diff --git a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/ExceptionInfoTest.java b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/ExceptionInfoTest.java index e9601d693..ab5012d73 100644 --- a/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/ExceptionInfoTest.java +++ b/hawkbit-rest-resource/src/test/java/org/eclipse/hawkbit/rest/resource/model/ExceptionInfoTest.java @@ -32,10 +32,15 @@ public class ExceptionInfoTest { underTest.setMessage(knownMessage); underTest.setParameters(knownParameters); - assertThat(underTest.getErrorCode()).isEqualTo(knownErrorCode); - assertThat(underTest.getExceptionClass()).isEqualTo(knownExceptionClass); - assertThat(underTest.getMessage()).isEqualTo(knownMessage); - assertThat(underTest.getParameters()).isEqualTo(knownParameters); + assertThat(underTest.getErrorCode()).as("The error code should match with the known error code in the test") + .isEqualTo(knownErrorCode); + assertThat(underTest.getExceptionClass()) + .as("The exception class should match with the known error code in the test") + .isEqualTo(knownExceptionClass); + assertThat(underTest.getMessage()).as("The message should match with the known error code in the test") + .isEqualTo(knownMessage); + assertThat(underTest.getParameters()).as("The parameters should match with the known error code in the test") + .isEqualTo(knownParameters); } } diff --git a/hawkbit-security-core/src/test/java/org/eclipse/hawkbit/ExcludePathAwareShallowETagFilterTest.java b/hawkbit-security-core/src/test/java/org/eclipse/hawkbit/ExcludePathAwareShallowETagFilterTest.java index ce663fbfb..d3dc066f1 100644 --- a/hawkbit-security-core/src/test/java/org/eclipse/hawkbit/ExcludePathAwareShallowETagFilterTest.java +++ b/hawkbit-security-core/src/test/java/org/eclipse/hawkbit/ExcludePathAwareShallowETagFilterTest.java @@ -56,7 +56,8 @@ public class ExcludePathAwareShallowETagFilterTest { filterUnderTest.doFilterInternal(servletRequestMock, servletResponseMock, filterChainMock); // verify no eTag header is set and response has not been changed - assertThat(servletResponseMock.getHeader("ETag")).isNull(); + assertThat(servletResponseMock.getHeader("ETag")) + .as("ETag header should not be set during downloading, too expensive").isNull(); // the servlet response must be the same mock! verify(filterChainMock, times(1)).doFilter(servletRequestMock, servletResponseMock); } diff --git a/hawkbit-security-core/src/test/java/org/eclipse/hawkbit/util/IpUtilTest.java b/hawkbit-security-core/src/test/java/org/eclipse/hawkbit/util/IpUtilTest.java index e1e809ab8..d56c59252 100644 --- a/hawkbit-security-core/src/test/java/org/eclipse/hawkbit/util/IpUtilTest.java +++ b/hawkbit-security-core/src/test/java/org/eclipse/hawkbit/util/IpUtilTest.java @@ -53,7 +53,8 @@ public class IpUtilTest { final URI remoteAddr = IpUtil.getClientIpFromRequest(requestMock, "bumlux"); // verify - assertThat(remoteAddr).isEqualTo(knownRemoteClientIP); + assertThat(remoteAddr).as("The remote address should be as the known client IP address") + .isEqualTo(knownRemoteClientIP); verify(requestMock, times(1)).getHeader("bumlux"); verify(requestMock, times(1)).getRemoteAddr(); } @@ -71,7 +72,8 @@ public class IpUtilTest { final URI remoteAddr = IpUtil.getClientIpFromRequest(requestMock, "X-Forwarded-For"); // verify - assertThat(remoteAddr).isEqualTo(knownRemoteClientIP); + assertThat(remoteAddr).as("The remote address should be as the known client IP address") + .isEqualTo(knownRemoteClientIP); verify(requestMock, times(1)).getHeader(HttpHeaders.X_FORWARDED_FOR); verify(requestMock, times(0)).getRemoteAddr(); } @@ -94,10 +96,10 @@ public class IpUtilTest { } private void assertHttpUri(final String host, final URI httpUri) { - assertTrue(IpUtil.isHttpUri(httpUri)); - assertFalse(IpUtil.isAmqpUri(httpUri)); - assertEquals(host, httpUri.getHost()); - assertEquals("http", httpUri.getScheme()); + assertTrue("The given URI has an http scheme", IpUtil.isHttpUri(httpUri)); + assertFalse("The given URI is not an AMQP scheme", IpUtil.isAmqpUri(httpUri)); + assertEquals("The URI hosts matches the given host", host, httpUri.getHost()); + assertEquals("The given URI scheme is http", "http", httpUri.getScheme()); } @Test @@ -117,22 +119,26 @@ public class IpUtilTest { } private void assertAmqpUri(final String host, final URI httpUri) { - assertTrue(IpUtil.isAmqpUri(httpUri)); - assertFalse(IpUtil.isHttpUri(httpUri)); - assertEquals(host, httpUri.getHost()); - assertEquals("amqp", httpUri.getScheme()); + assertTrue("The given URI is an AMQP scheme", IpUtil.isAmqpUri(httpUri)); + assertFalse("The given URI is not an HTTP scheme", IpUtil.isHttpUri(httpUri)); + assertEquals("The given host matches the URI host", host, httpUri.getHost()); + assertEquals("The given URI has an AMQP scheme", "amqp", httpUri.getScheme()); } - @Test(expected = IllegalArgumentException.class) + @Test @Description("Tests create invalid uri") public void testCreateInvalidUri() { final String host = "10.99.99.1"; final URI testUri = IpUtil.createUri("test", host); - assertFalse(IpUtil.isAmqpUri(testUri)); - assertFalse(IpUtil.isHttpUri(testUri)); - assertEquals(host, testUri.getHost()); - IpUtil.createUri(":/", host); - fail(); + assertFalse("The given URI is not an AMQP address", IpUtil.isAmqpUri(testUri)); + assertFalse("The given URI is not an HTTP address", IpUtil.isHttpUri(testUri)); + assertEquals("The given host matches the URI host", host, testUri.getHost()); + try { + IpUtil.createUri(":/", host); + fail("Missing expected IllegalArgumentException due invalid URI"); + } catch (final IllegalArgumentException e) { + // expected + } } } From 62d96a4ac67abca2d21ea715618fe9bde124febc Mon Sep 17 00:00:00 2001 From: Michael Hirsch Date: Thu, 25 Feb 2016 14:51:45 +0100 Subject: [PATCH 06/10] remove static modifier from inner class Signed-off-by: Michael Hirsch --- .../hawkbit/eventbus/event/AbstractPropertyChangeEvent.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java index 86251e675..8a596eeb5 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/eventbus/event/AbstractPropertyChangeEvent.java @@ -47,7 +47,7 @@ public class AbstractPropertyChangeEvent extends AbstractB * Carries old value and new value of a property . * */ - public static class Values { + public class Values { private final Object oldValue; private final Object newValue; From 0b5c0673b1601ed838d668a4a45608bb9aa3a3ed Mon Sep 17 00:00:00 2001 From: asharani-murugesh Date: Thu, 25 Feb 2016 17:43:28 +0100 Subject: [PATCH 07/10] fix Signed-off-by: asharani-murugesh --- .../org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 2e8c6a51e..665fbcb6f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -191,12 +191,13 @@ public class UploadLayout extends VerticalLayout { ((WrapperTransferable) event.getTransferable()).getDraggedComponent(); final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); if (files != null) { + //reset the flag + hasDirectory = Boolean.FALSE; for (final Html5File file : files) { if (!isDirectory(file)) { if (!checkForDuplicate(file.getFileName())) { numberOfFileUploadsExpected.incrementAndGet(); file.setStreamVariable(createStreamVariable(file)); - hasDirectory = Boolean.FALSE; } } else { hasDirectory = Boolean.TRUE; From b8ed510e8a5bb5dba93156779092867610f811ce Mon Sep 17 00:00:00 2001 From: asharani-murugesh Date: Thu, 25 Feb 2016 17:54:50 +0100 Subject: [PATCH 08/10] reset the has directory flag Signed-off-by: asharani-murugesh --- .../eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java | 2 ++ .../org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index 3d7ce0886..cac4ef2f9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -108,6 +108,8 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene public OutputStream receiveUpload(final String fileName, final String mimeType) { this.fileName = fileName; this.mimeType = mimeType; + //reset has directory flag before upload + view.setHasDirectory(false); try { if (view.validate()) { if (view.checkForDuplicate(fileName)) { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 665fbcb6f..c254a8b18 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -633,4 +633,8 @@ public class UploadLayout extends VerticalLayout { return uiNotification; } + + public void setHasDirectory(Boolean hasDirectory) { + this.hasDirectory = hasDirectory; + } } From 92811f1a22c516684a774e1feec23eebee05ad6b Mon Sep 17 00:00:00 2001 From: asharani-murugesh Date: Fri, 26 Feb 2016 08:47:21 +0100 Subject: [PATCH 09/10] review comment addressed Signed-off-by: asharani-murugesh --- .../ui/artifacts/upload/UploadLayout.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index c254a8b18..9a7969f05 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -59,6 +59,7 @@ import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; +import com.vaadin.ui.Component; import com.vaadin.ui.DragAndDropWrapper; import com.vaadin.ui.DragAndDropWrapper.WrapperTransferable; import com.vaadin.ui.HorizontalLayout; @@ -187,21 +188,13 @@ public class UploadLayout extends VerticalLayout { @Override public void drop(final DragAndDropEvent event) { - if (validate()) { - ((WrapperTransferable) event.getTransferable()).getDraggedComponent(); + if (event.getTransferable() instanceof WrapperTransferable && validate()) { final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); if (files != null) { - //reset the flag + // reset the flag hasDirectory = Boolean.FALSE; for (final Html5File file : files) { - if (!isDirectory(file)) { - if (!checkForDuplicate(file.getFileName())) { - numberOfFileUploadsExpected.incrementAndGet(); - file.setStreamVariable(createStreamVariable(file)); - } - } else { - hasDirectory = Boolean.TRUE; - } + processFile(file); } if (numberOfFileUploadsExpected.get() > 0) { processBtn.setEnabled(false); @@ -216,6 +209,17 @@ public class UploadLayout extends VerticalLayout { } } } + + private void processFile(final Html5File file) { + if (!isDirectory(file)) { + if (!checkForDuplicate(file.getFileName())) { + numberOfFileUploadsExpected.incrementAndGet(); + file.setStreamVariable(createStreamVariable(file)); + } + } else { + hasDirectory = Boolean.TRUE; + } + } } private static boolean isDirectory(final Html5File file) { From 80366b03be121fa4b3fc539256c15578ffa2bb9f Mon Sep 17 00:00:00 2001 From: asharani-murugesh Date: Sat, 27 Feb 2016 09:24:18 +0100 Subject: [PATCH 10/10] Review comments addresses Signed-off-by: asharani-murugesh --- .../ui/artifacts/upload/UploadHandler.java | 2 +- .../ui/artifacts/upload/UploadLayout.java | 60 ++++++++++++------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java index cac4ef2f9..8c1feeb33 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadHandler.java @@ -111,7 +111,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene //reset has directory flag before upload view.setHasDirectory(false); try { - if (view.validate()) { + if (view.checkIfSoftwareModuleIsSelected()) { if (view.checkForDuplicate(fileName)) { view.showDuplicateMessage(); } else { diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java index 9a7969f05..994a9786f 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/artifacts/upload/UploadLayout.java @@ -59,7 +59,6 @@ import com.vaadin.spring.annotation.SpringComponent; import com.vaadin.spring.annotation.ViewScope; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; -import com.vaadin.ui.Component; import com.vaadin.ui.DragAndDropWrapper; import com.vaadin.ui.DragAndDropWrapper.WrapperTransferable; import com.vaadin.ui.HorizontalLayout; @@ -188,24 +187,22 @@ public class UploadLayout extends VerticalLayout { @Override public void drop(final DragAndDropEvent event) { - if (event.getTransferable() instanceof WrapperTransferable && validate()) { + if (validate(event)) { final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); - if (files != null) { - // reset the flag - hasDirectory = Boolean.FALSE; - for (final Html5File file : files) { - processFile(file); - } - if (numberOfFileUploadsExpected.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 - // display message accordingly - displayCompositeMessage(); - } + // reset the flag + hasDirectory = Boolean.FALSE; + for (final Html5File file : files) { + processFile(file); + } + if (numberOfFileUploadsExpected.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 + // display message accordingly + displayCompositeMessage(); } } } @@ -354,10 +351,33 @@ public class UploadLayout extends VerticalLayout { } } - Boolean validate() { + Boolean validate(DragAndDropEvent event) { + // check if drop is valid.If valid ,check if software module is + // selected. + if(!isFilesDropped(event)){ + uiNotification.displayValidationError(i18n.get("message.action.not.allowed")); + return false; + } + return checkIfSoftwareModuleIsSelected(); + } + + private boolean isFilesDropped(DragAndDropEvent event) { + if (event.getTransferable() instanceof WrapperTransferable) { + final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); + // other components can also be wrapped in WrapperTransferable , so + // additional check on files + if (files == null) { + return false; + } + return true; + } else { + return false; + } + } + + Boolean checkIfSoftwareModuleIsSelected() { if (!isSoftwareModuleSelected()) { uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected")); - return false; } return true;