Bug fixed

Signed-off-by: asharani-murugesh <asharani.murugesh@in.bosch.com>
This commit is contained in:
asharani-murugesh
2016-02-08 11:55:57 +01:00
parent 70959ec140
commit 7237e352ff
2 changed files with 421 additions and 424 deletions

View File

@@ -89,7 +89,6 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
@Override @Override
public final OutputStream getOutputStream() { public final OutputStream getOutputStream() {
try { try {
view.getDuplicateFileNamesList().clear();
return view.saveUploadedFileDetails(fileName, fileSize, mimeType); return view.saveUploadedFileDetails(fileName, fileSize, mimeType);
} catch (final ArtifactUploadFailedException e) { } catch (final ArtifactUploadFailedException e) {
LOG.error("Atifact upload failed {} ", 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) { public OutputStream receiveUpload(final String fileName, final String mimeType) {
this.fileName = fileName; this.fileName = fileName;
this.mimeType = mimeType; this.mimeType = mimeType;
view.getDuplicateFileNamesList().clear();
try { try {
if (view.validate()) { if (view.validate()) {
if (view.checkForDuplicate(fileName)) { if (view.checkForDuplicate(fileName)) {
@@ -169,7 +167,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
view.updateActionCount(); view.updateActionCount();
// display the duplicate message after streaming all files // 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()) { if (view.enableProcessBtn()) {
infoWindow.uploadSessionFinished(); infoWindow.uploadSessionFinished();
} }
view.displayValidationMessage(); view.displayDuplicateValidationMessage();
LOG.info("Streaming failed due to :{}", event.getException()); LOG.info("Streaming failed due to :{}", event.getException());
} }
@@ -318,7 +316,6 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
} }
view.updateActionCount(); view.updateActionCount();
infoWindow.uploadFailed(event.getFilename(), failureReason); infoWindow.uploadFailed(event.getFilename(), failureReason);
LOG.info("Upload failed for file :{}", event.getReason()); LOG.info("Upload failed for file :{}", event.getReason());
} }

View File

@@ -71,123 +71,123 @@ import com.vaadin.ui.VerticalLayout;
/** /**
* Upload files layout. * Upload files layout.
* *
* @author G Venkata Narayana (RBEI/BSO3) *
*/ */
@ViewScope @ViewScope
@SpringComponent @SpringComponent
public class UploadLayout extends VerticalLayout { 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 @Autowired
private UploadStatusInfoWindow uploadInfoWindow; private UploadStatusInfoWindow uploadInfoWindow;
@Autowired @Autowired
private I18N i18n; private I18N i18n;
@Autowired @Autowired
private transient UINotification uiNotification; private transient UINotification uiNotification;
@Autowired @Autowired
private transient EventBus.SessionEventBus eventBus; private transient EventBus.SessionEventBus eventBus;
@Autowired @Autowired
private ArtifactUploadState artifactUploadState; private ArtifactUploadState artifactUploadState;
@Autowired @Autowired
private transient SPInfo spInfo; 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<String> duplicateFileNamesList = new ArrayList<String>(); private final List<String> duplicateFileNamesList = new ArrayList<String>();
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; private Boolean hasDirectory = Boolean.FALSE;
/** /**
* Initialize the upload layout. * Initialize the upload layout.
*/ */
@PostConstruct @PostConstruct
void init() { void init() {
createComponents(); createComponents();
buildLayout(); buildLayout();
updateActionCount(); updateActionCount();
eventBus.subscribe(this); eventBus.subscribe(this);
ui = UI.getCurrent(); ui = UI.getCurrent();
} }
private void createComponents() { private void createComponents() {
createProcessButton(); createProcessButton();
createDiscardBtn(); createDiscardBtn();
} }
private void buildLayout() { private void buildLayout() {
final Upload upload = new Upload(); final Upload upload = new Upload();
final UploadHandler uploadHandler = new UploadHandler(null, 0, this, uploadInfoWindow, final UploadHandler uploadHandler = new UploadHandler(null, 0, this, uploadInfoWindow,
spInfo.getMaxArtifactFileSize(), upload, null); spInfo.getMaxArtifactFileSize(), upload, null);
upload.setButtonCaption(i18n.get("upload.file")); upload.setButtonCaption(i18n.get("upload.file"));
upload.setImmediate(true); upload.setImmediate(true);
upload.setReceiver(uploadHandler); upload.setReceiver(uploadHandler);
upload.addSucceededListener(uploadHandler); upload.addSucceededListener(uploadHandler);
upload.addFailedListener(uploadHandler); upload.addFailedListener(uploadHandler);
upload.addFinishedListener(uploadHandler); upload.addFinishedListener(uploadHandler);
upload.addProgressListener(uploadHandler); upload.addProgressListener(uploadHandler);
upload.addStartedListener(uploadHandler); upload.addStartedListener(uploadHandler);
upload.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); upload.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON);
fileUploadLayout = new HorizontalLayout(); fileUploadLayout = new HorizontalLayout();
fileUploadLayout.setSpacing(true); fileUploadLayout.setSpacing(true);
fileUploadLayout.addComponent(upload); fileUploadLayout.addComponent(upload);
fileUploadLayout.setComponentAlignment(upload, Alignment.MIDDLE_LEFT); fileUploadLayout.setComponentAlignment(upload, Alignment.MIDDLE_LEFT);
fileUploadLayout.addComponent(processBtn); fileUploadLayout.addComponent(processBtn);
fileUploadLayout.setComponentAlignment(processBtn, Alignment.MIDDLE_RIGHT); fileUploadLayout.setComponentAlignment(processBtn, Alignment.MIDDLE_RIGHT);
fileUploadLayout.addComponent(discardBtn); fileUploadLayout.addComponent(discardBtn);
fileUploadLayout.setComponentAlignment(discardBtn, Alignment.MIDDLE_RIGHT); fileUploadLayout.setComponentAlignment(discardBtn, Alignment.MIDDLE_RIGHT);
setMargin(false); setMargin(false);
/* create drag-drop wrapper for drop area */ /* create drag-drop wrapper for drop area */
dropAreaWrapper = new DragAndDropWrapper(createDropAreaLayout()); dropAreaWrapper = new DragAndDropWrapper(createDropAreaLayout());
dropAreaWrapper.setDropHandler(new DropAreahandler()); dropAreaWrapper.setDropHandler(new DropAreahandler());
setSizeFull(); setSizeFull();
setSpacing(true); setSpacing(true);
} }
public DragAndDropWrapper getDropAreaWrapper() { public DragAndDropWrapper getDropAreaWrapper() {
return dropAreaWrapper; 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 @Override
public AcceptCriterion getAcceptCriterion() { public AcceptCriterion getAcceptCriterion() {
return AcceptAll.get(); return AcceptAll.get();
} }
@Override @Override
public void drop(final DragAndDropEvent event) { public void drop(final DragAndDropEvent event) {
if (validate()) { if (validate()) {
((WrapperTransferable) event.getTransferable()).getDraggedComponent(); ((WrapperTransferable) event.getTransferable()).getDraggedComponent();
final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles();
if (files != null) { if (files != null) {
@@ -207,12 +207,12 @@ public class UploadLayout extends VerticalLayout {
uploadInfoWindow.uploadSessionStarted(); uploadInfoWindow.uploadSessionStarted();
} else { } else {
//If the upload is not started, it signifies all dropped files as either duplicate or directory.So display message accordingly //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) { private static boolean isDirectory(final Html5File file) {
if (Strings.isNullOrEmpty(file.getType()) && file.getFileSize() % 4096 == 0) { if (Strings.isNullOrEmpty(file.getType()) && file.getFileSize() % 4096 == 0) {
@@ -221,12 +221,10 @@ public class UploadLayout extends VerticalLayout {
return false; return false;
} }
private void displayCompositeMessage(final Boolean hasDirectory) { private void displayCompositeMessage() {
final String duplicateMessage = showDuplicateMessage(); final String duplicateMessage = getDuplicateFileValidationMessage();
final StringBuilder compositeMessage = new StringBuilder(); final StringBuilder compositeMessage = new StringBuilder();
if (null != duplicateMessage) { if (!Strings.isNullOrEmpty(duplicateMessage)) {
// in case if all selected files are duplicate ,then display
// messag
compositeMessage.append(duplicateMessage); compositeMessage.append(duplicateMessage);
} }
if (hasDirectory) { if (hasDirectory) {
@@ -240,394 +238,396 @@ public class UploadLayout extends VerticalLayout {
} }
} }
private VerticalLayout createDropAreaLayout() { private VerticalLayout createDropAreaLayout() {
dropAreaLayout = new VerticalLayout(); dropAreaLayout = new VerticalLayout();
final Label dropHereLabel = new Label("Drop files to upload"); final Label dropHereLabel = new Label("Drop files to upload");
dropHereLabel.setWidth(null); dropHereLabel.setWidth(null);
final Label dropIcon = new Label(FontAwesome.ARROW_DOWN.getHtml(), ContentMode.HTML); final Label dropIcon = new Label(FontAwesome.ARROW_DOWN.getHtml(), ContentMode.HTML);
dropIcon.addStyleName("drop-icon"); dropIcon.addStyleName("drop-icon");
dropIcon.setWidth(null); dropIcon.setWidth(null);
dropAreaLayout.addComponent(dropIcon); dropAreaLayout.addComponent(dropIcon);
dropAreaLayout.setComponentAlignment(dropIcon, Alignment.BOTTOM_CENTER); dropAreaLayout.setComponentAlignment(dropIcon, Alignment.BOTTOM_CENTER);
dropAreaLayout.addComponent(dropHereLabel); dropAreaLayout.addComponent(dropHereLabel);
dropAreaLayout.setComponentAlignment(dropHereLabel, Alignment.TOP_CENTER); dropAreaLayout.setComponentAlignment(dropHereLabel, Alignment.TOP_CENTER);
dropAreaLayout.setSizeFull(); dropAreaLayout.setSizeFull();
dropAreaLayout.setStyleName("upload-drop-area-layout-info"); dropAreaLayout.setStyleName("upload-drop-area-layout-info");
dropAreaLayout.setSpacing(false); dropAreaLayout.setSpacing(false);
return dropAreaLayout; return dropAreaLayout;
} }
private void createProcessButton() { private void createProcessButton() {
processBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON, processBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON,
SPUILabelDefinitions.PROCESS, SPUILabelDefinitions.PROCESS, null, false, null, SPUILabelDefinitions.PROCESS, SPUILabelDefinitions.PROCESS, null, false, null,
SPUIButtonStyleSmall.class); SPUIButtonStyleSmall.class);
processBtn.setIcon(FontAwesome.BELL); processBtn.setIcon(FontAwesome.BELL);
processBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); processBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON);
processBtn.addClickListener(event -> displayConfirmWindow(event)); processBtn.addClickListener(event -> displayConfirmWindow(event));
processBtn.setHtmlContentAllowed(true); processBtn.setHtmlContentAllowed(true);
if (artifactUploadState.getFileSelected().isEmpty()) { if (artifactUploadState.getFileSelected().isEmpty()) {
processBtn.setEnabled(false); processBtn.setEnabled(false);
} }
} }
private void createDiscardBtn() { private void createDiscardBtn() {
discardBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_DISCARD_BUTTON, discardBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_DISCARD_BUTTON,
SPUILabelDefinitions.DISCARD, SPUILabelDefinitions.DISCARD, null, false, null, SPUILabelDefinitions.DISCARD, SPUILabelDefinitions.DISCARD, null, false, null,
SPUIButtonStyleSmall.class); SPUIButtonStyleSmall.class);
discardBtn.setIcon(FontAwesome.TRASH_O); discardBtn.setIcon(FontAwesome.TRASH_O);
discardBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); discardBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON);
discardBtn.addClickListener(event -> discardUploadData(event)); discardBtn.addClickListener(event -> discardUploadData(event));
} }
private StreamVariable createStreamVariable(final Html5File file) { private StreamVariable createStreamVariable(final Html5File file) {
return new UploadHandler(file.getFileName(), file.getFileSize(), this, uploadInfoWindow, return new UploadHandler(file.getFileName(), file.getFileSize(), this, uploadInfoWindow,
spInfo.getMaxArtifactFileSize(), null, file.getType()); spInfo.getMaxArtifactFileSize(), null, file.getType());
} }
boolean checkForDuplicate(final String filename) { boolean checkForDuplicate(final String filename) {
final Boolean isDuplicate = checkIfFileIsDuplicate(filename); final Boolean isDuplicate = checkIfFileIsDuplicate(filename);
if (isDuplicate) { if (isDuplicate) {
getDuplicateFileNamesList().add(filename); getDuplicateFileNamesList().add(filename);
} }
return isDuplicate; return isDuplicate;
} }
@EventBusListenerMethod(scope = EventScope.SESSION) @EventBusListenerMethod(scope = EventScope.SESSION)
void toggleProcessButton(final UploadArtifactUIEvent event) { void toggleProcessButton(final UploadArtifactUIEvent event) {
if (event == UploadArtifactUIEvent.ENABLE_PROCESS_BUTTON) { if (event == UploadArtifactUIEvent.ENABLE_PROCESS_BUTTON) {
processBtn.setEnabled(true); processBtn.setEnabled(true);
} else if (event == UploadArtifactUIEvent.DISABLE_PROCESS_BUTTON) { } else if (event == UploadArtifactUIEvent.DISABLE_PROCESS_BUTTON) {
processBtn.setEnabled(false); processBtn.setEnabled(false);
} }
} }
/** /**
* Save uploaded file details. * Save uploaded file details.
* *
* @param stream * @param stream
* read from uploaded file * read from uploaded file
* @param name * @param name
* file name * file name
* @param size * @param size
* file size * file size
* @param mimeType * @param mimeType
* the mimeType of the file * the mimeType of the file
* @throws IOException * @throws IOException
* in case of upload errors * in case of upload errors
*/ */
OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType) { OutputStream saveUploadedFileDetails(final String name, final long size, final String mimeType) {
File tempFile = null; File tempFile = null;
try { try {
tempFile = File.createTempFile("spUiArtifactUpload", null); tempFile = File.createTempFile("spUiArtifactUpload", null);
final OutputStream out = new FileOutputStream(tempFile); final OutputStream out = new FileOutputStream(tempFile);
final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get();
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil final String currentBaseSoftwareModuleKey = HawkbitCommonUtil
.getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(),
selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion(), mimeType); selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion(), mimeType);
artifactUploadState.getFileSelected().add(customFile); artifactUploadState.getFileSelected().add(customFile);
processBtn.setEnabled(false); processBtn.setEnabled(false);
if (!artifactUploadState.getBaseSwModuleList().keySet().contains(currentBaseSoftwareModuleKey)) { if (!artifactUploadState.getBaseSwModuleList().keySet().contains(currentBaseSoftwareModuleKey)) {
artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSoftwareModule); artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSoftwareModule);
} }
return out; return out;
} catch (final FileNotFoundException e) { } catch (final FileNotFoundException e) {
LOG.error("Upload failed {}", e); LOG.error("Upload failed {}", e);
throw new ArtifactUploadFailedException(i18n.get("message.file.not.found")); throw new ArtifactUploadFailedException(i18n.get("message.file.not.found"));
} catch (final IOException e) { } catch (final IOException e) {
LOG.error("Upload failed {}", e); LOG.error("Upload failed {}", e);
throw new ArtifactUploadFailedException(i18n.get("message.upload.failed")); throw new ArtifactUploadFailedException(i18n.get("message.upload.failed"));
} }
} }
Boolean validate() { Boolean validate() {
if (!isSoftwareModuleSelected()) { if (!isSoftwareModuleSelected()) {
uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected")); uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected"));
return false;
}
return true;
}
SoftwareModule getSoftwareModuleSelected() { return false;
if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) { }
return artifactUploadState.getSelectedBaseSoftwareModule().get(); return true;
} }
return null;
}
Boolean isSoftwareModuleSelected() { SoftwareModule getSoftwareModuleSelected() {
if (!artifactUploadState.getSelectedBaseSwModuleId().isPresent()) { if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) {
return false; return artifactUploadState.getSelectedBaseSoftwareModule().get();
} }
return true; return null;
} }
/** Boolean isSoftwareModuleSelected() {
* Check if file selected is duplicate.i,e already selected for upload for if (!artifactUploadState.getSelectedBaseSwModuleId().isPresent()) {
* same software module. return false;
* }
* @param name return true;
* 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( * Check if file selected is duplicate.i,e already selected for upload for
customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); * same software module.
if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) { *
isDuplicate = true; * @param name
break; * file name
} * @return Boolean
} */
return isDuplicate; public Boolean checkIfFileIsDuplicate(final String name) {
} Boolean isDuplicate = false;
final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get();
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil
.getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
void decreaseNumberOfFileUploadsExpected() { for (final CustomFile customFile : artifactUploadState.getFileSelected()) {
numberOfFileUploadsExpected.decrementAndGet(); final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
} customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion());
if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) {
isDuplicate = true;
break;
}
}
return isDuplicate;
}
List<String> getDuplicateFileNamesList() { void decreaseNumberOfFileUploadsExpected() {
return duplicateFileNamesList; numberOfFileUploadsExpected.decrementAndGet();
} }
/** List<String> getDuplicateFileNamesList() {
* Update pending action count. return duplicateFileNamesList;
*/ }
void updateActionCount() {
if (!artifactUploadState.getFileSelected().isEmpty()) {
processBtn.setCaption(SPUILabelDefinitions.PROCESS + "<div class='unread'>"
+ artifactUploadState.getFileSelected().size() + "</div>");
} else {
processBtn.setCaption(SPUILabelDefinitions.PROCESS);
}
}
void displayValidationMessage() { /**
// check if streaming of all dropped files are completed * Update pending action count.
if (numberOfFilesActuallyUpload.intValue() == numberOfFileUploadsExpected.intValue()) { */
displayCompositeMessage(hasDirectory); void updateActionCount() {
} if (!artifactUploadState.getFileSelected().isEmpty()) {
} processBtn.setCaption(SPUILabelDefinitions.PROCESS + "<div class='unread'>"
+ artifactUploadState.getFileSelected().size() + "</div>");
} else {
processBtn.setCaption(SPUILabelDefinitions.PROCESS);
}
}
/** void displayDuplicateValidationMessage() {
* Show duplicate file selected message. // check if streaming of all dropped files are completed
* if (numberOfFilesActuallyUpload.intValue() == numberOfFileUploadsExpected.intValue()) {
* @return duplicate file names displayCompositeMessage();
*/ }
public String showDuplicateMessage() { }
private String getDuplicateFileValidationMessage() {
StringBuilder message = new StringBuilder();
if (!duplicateFileNamesList.isEmpty()) { if (!duplicateFileNamesList.isEmpty()) {
final String fileNames = StringUtils.collectionToCommaDelimitedString(duplicateFileNamesList); final String fileNames = StringUtils.collectionToCommaDelimitedString(duplicateFileNamesList);
if (duplicateFileNamesList.size() == 1) { if (duplicateFileNamesList.size() == 1) {
return i18n.get("message.no.duplicateFile") + fileNames; message.append(i18n.get("message.no.duplicateFile") + fileNames);
} else if (duplicateFileNamesList.size() > 1) { } else if (duplicateFileNamesList.size() > 1) {
return i18n.get("message.no.duplicateFiles"); message.append(i18n.get("message.no.duplicateFiles"));
} }
duplicateFileNamesList.clear(); duplicateFileNamesList.clear();
} }
return null; return message.toString();
} }
void increaseNumberOfFileUploadsExpected() { public void showDuplicateMessage() {
numberOfFileUploadsExpected.incrementAndGet(); uiNotification.displayValidationError(getDuplicateFileValidationMessage());
} }
void updateFileSize(final String name, final long size) { void increaseNumberOfFileUploadsExpected() {
final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); numberOfFileUploadsExpected.incrementAndGet();
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil }
.getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
for (final CustomFile customFile : artifactUploadState.getFileSelected()) { void updateFileSize(final String name, final long size) {
final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( final SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get();
customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); final String currentBaseSoftwareModuleKey = HawkbitCommonUtil
if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) { .getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
customFile.setFileSize(size);
break;
}
}
}
void increaseNumberOfFilesActuallyUpload() { for (final CustomFile customFile : artifactUploadState.getFileSelected()) {
numberOfFilesActuallyUpload.incrementAndGet(); final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
} customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion());
if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) {
customFile.setFileSize(size);
break;
}
}
}
/** void increaseNumberOfFilesActuallyUpload() {
* Enable process button once upload is completed. numberOfFilesActuallyUpload.incrementAndGet();
*/ }
boolean enableProcessBtn() {
if (numberOfFilesActuallyUpload.intValue() >= numberOfFileUploadsExpected.intValue()) {
processBtn.setEnabled(true);
numberOfFileUploadsExpected.set(0);
numberOfFilesActuallyUpload.set(0);
return true;
}
return false;
}
Set<CustomFile> getFileSelected() { /**
return artifactUploadState.getFileSelected(); * 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;
}
private void discardUploadData(final Button.ClickEvent event) { Set<CustomFile> getFileSelected() {
if (event.getButton().equals(discardBtn)) { return artifactUploadState.getFileSelected();
if (artifactUploadState.getFileSelected().isEmpty()) { }
uiNotification.displayValidationError(i18n.get("message.error.noFileSelected"));
} else { private void discardUploadData(final Button.ClickEvent event) {
clearFileList(); if (event.getButton().equals(discardBtn)) {
} if (artifactUploadState.getFileSelected().isEmpty()) {
} uiNotification.displayValidationError(i18n.get("message.error.noFileSelected"));
}
/** } else {
* Clear details. clearFileList();
*/ }
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(); * Clear details.
processBtn.setCaption(SPUILabelDefinitions.PROCESS); */
/* disable when there is no files to upload. */ void clearFileList() {
processBtn.setEnabled(false); // delete file system zombies
numberOfFileUploadsExpected.set(0); artifactUploadState.getFileSelected().forEach(customFile -> {
numberOfFilesActuallyUpload.set(0); final File file = new File(customFile.getFilePath());
duplicateFileNamesList.clear(); file.delete();
} });
private void setConfirmationPopupHeightWidth(final float newWidth, final float newHeight) { artifactUploadState.getFileSelected().clear();
if (currentUploadConfirmationwindow != null) { artifactUploadState.getBaseSwModuleList().clear();
currentUploadConfirmationwindow.getUploadArtifactDetails().setWidth(HawkbitCommonUtil processBtn.setCaption(SPUILabelDefinitions.PROCESS);
.getArtifactUploadPopupWidth(newWidth, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), /* disable when there is no files to upload. */
Unit.PIXELS); processBtn.setEnabled(false);
currentUploadConfirmationwindow.getUploadDetailsTable().setHeight(HawkbitCommonUtil numberOfFileUploadsExpected.set(0);
.getArtifactUploadPopupHeight(newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), numberOfFilesActuallyUpload.set(0);
Unit.PIXELS); duplicateFileNamesList.clear();
} }
}
/** private void setConfirmationPopupHeightWidth(final float newWidth, final float newHeight) {
* Set artifact upload result pop up size changes. if (currentUploadConfirmationwindow != null) {
* currentUploadConfirmationwindow.getUploadArtifactDetails().setWidth(HawkbitCommonUtil
* @param newWidth .getArtifactUploadPopupWidth(newWidth, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH),
* new width of result pop up Unit.PIXELS);
* @param newHeight currentUploadConfirmationwindow.getUploadDetailsTable().setHeight(HawkbitCommonUtil
* new height of result pop up .getArtifactUploadPopupHeight(newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT),
*/ Unit.PIXELS);
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)) { * Set artifact upload result pop up size changes.
if (artifactUploadState.getFileSelected().isEmpty()) { *
uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); * @param newWidth
} else { * new width of result pop up
currentUploadConfirmationwindow = new UploadConfirmationwindow(this, artifactUploadState); * @param newHeight
UI.getCurrent().addWindow(currentUploadConfirmationwindow.getUploadConfrimationWindow()); * new height of result pop up
setConfirmationPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(), */
Page.getCurrent().getBrowserWindowHeight()); 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) {
* @return if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON)) {
*/ if (artifactUploadState.getFileSelected().isEmpty()) {
I18N getI18n() { uiNotification.displayValidationError(i18n.get("message.error.noFileSelected"));
return i18n; } else {
} currentUploadConfirmationwindow = new UploadConfirmationwindow(this, artifactUploadState);
UI.getCurrent().addWindow(currentUploadConfirmationwindow.getUploadConfrimationWindow());
setConfirmationPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(),
Page.getCurrent().getBrowserWindowHeight());
}
}
}
/** /**
* @return * @return
*/ */
SPInfo getSPInfo() { I18N getI18n() {
return spInfo; return i18n;
} }
void setCurrentUploadConfirmationwindow(final UploadConfirmationwindow currentUploadConfirmationwindow) { /**
this.currentUploadConfirmationwindow = currentUploadConfirmationwindow; * @return
} */
SPInfo getSPInfo() {
return spInfo;
}
/** void setCurrentUploadConfirmationwindow(final UploadConfirmationwindow currentUploadConfirmationwindow) {
* @return this.currentUploadConfirmationwindow = currentUploadConfirmationwindow;
*/ }
VerticalLayout getDropAreaLayout() { /**
return dropAreaLayout; * @return
} */
@EventBusListenerMethod(scope = EventScope.SESSION) VerticalLayout getDropAreaLayout() {
void onEvent(final UploadArtifactUIEvent event) { return dropAreaLayout;
if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE) { }
ui.access(() -> updateActionCount());
}
}
@PreDestroy @EventBusListenerMethod(scope = EventScope.SESSION)
void destroy() { void onEvent(final UploadArtifactUIEvent event) {
/* if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE) {
* It's good manners to do this, even though vaadin-spring will ui.access(() -> updateActionCount());
* automatically unsubscribe when this UI is garbage collected. }
*/ }
eventBus.unsubscribe(this);
}
/** @PreDestroy
* set upload status and confirmation window. void destroy() {
* /*
* @param newWidth * It's good manners to do this, even though vaadin-spring will
* browser width * automatically unsubscribe when this UI is garbage collected.
* @param newHeight */
* browser height eventBus.unsubscribe(this);
*/ }
public void setUploadPopupSize(final float newWidth, final float newHeight) {
setConfirmationPopupHeightWidth(newWidth, newHeight);
setResultPopupHeightWidth(newWidth, newHeight);
}
/** /**
* @param selectedBaseSoftwareModule * set upload status and confirmation window.
*/ *
public void refreshArtifactDetailsLayout(final SoftwareModule selectedBaseSoftwareModule) { * @param newWidth
eventBus.publish(this, * browser width
new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED, selectedBaseSoftwareModule)); * @param newHeight
} * browser height
*/
public void setUploadPopupSize(final float newWidth, final float newHeight) {
setConfirmationPopupHeightWidth(newWidth, newHeight);
setResultPopupHeightWidth(newWidth, newHeight);
}
/** /**
* @return the fileUploadLayout * @param selectedBaseSoftwareModule
*/ */
public HorizontalLayout getFileUploadLayout() { public void refreshArtifactDetailsLayout(final SoftwareModule selectedBaseSoftwareModule) {
return fileUploadLayout; eventBus.publish(this,
} new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED, selectedBaseSoftwareModule));
}
public UINotification getUINotification() { /**
return uiNotification; * @return the fileUploadLayout
} */
public HorizontalLayout getFileUploadLayout() {
return fileUploadLayout;
}
public UINotification getUINotification() {
return uiNotification;
}
} }