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) {
@@ -239,395 +237,397 @@ public class UploadLayout extends VerticalLayout {
uiNotification.displayValidationError(compositeMessage.toString()); 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() { final Label dropIcon = new Label(FontAwesome.ARROW_DOWN.getHtml(), ContentMode.HTML);
dropAreaLayout = new VerticalLayout(); dropIcon.addStyleName("drop-icon");
final Label dropHereLabel = new Label("Drop files to upload"); dropIcon.setWidth(null);
dropHereLabel.setWidth(null);
final Label dropIcon = new Label(FontAwesome.ARROW_DOWN.getHtml(), ContentMode.HTML); dropAreaLayout.addComponent(dropIcon);
dropIcon.addStyleName("drop-icon"); dropAreaLayout.setComponentAlignment(dropIcon, Alignment.BOTTOM_CENTER);
dropIcon.setWidth(null); 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); private void createProcessButton() {
dropAreaLayout.setComponentAlignment(dropIcon, Alignment.BOTTOM_CENTER); processBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON,
dropAreaLayout.addComponent(dropHereLabel); SPUILabelDefinitions.PROCESS, SPUILabelDefinitions.PROCESS, null, false, null,
dropAreaLayout.setComponentAlignment(dropHereLabel, Alignment.TOP_CENTER); SPUIButtonStyleSmall.class);
dropAreaLayout.setSizeFull(); processBtn.setIcon(FontAwesome.BELL);
dropAreaLayout.setStyleName("upload-drop-area-layout-info"); processBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON);
dropAreaLayout.setSpacing(false); processBtn.addClickListener(event -> displayConfirmWindow(event));
return dropAreaLayout; processBtn.setHtmlContentAllowed(true);
} if (artifactUploadState.getFileSelected().isEmpty()) {
processBtn.setEnabled(false);
}
}
private void createProcessButton() { private void createDiscardBtn() {
processBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON, discardBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_DISCARD_BUTTON,
SPUILabelDefinitions.PROCESS, SPUILabelDefinitions.PROCESS, null, false, null, SPUILabelDefinitions.DISCARD, SPUILabelDefinitions.DISCARD, null, false, null,
SPUIButtonStyleSmall.class); SPUIButtonStyleSmall.class);
processBtn.setIcon(FontAwesome.BELL); discardBtn.setIcon(FontAwesome.TRASH_O);
processBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON); discardBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON);
processBtn.addClickListener(event -> displayConfirmWindow(event)); discardBtn.addClickListener(event -> discardUploadData(event));
processBtn.setHtmlContentAllowed(true); }
if (artifactUploadState.getFileSelected().isEmpty()) {
processBtn.setEnabled(false);
}
}
private void createDiscardBtn() { private StreamVariable createStreamVariable(final Html5File file) {
discardBtn = SPUIComponentProvider.getButton(SPUIComponetIdProvider.UPLOAD_DISCARD_BUTTON, return new UploadHandler(file.getFileName(), file.getFileSize(), this, uploadInfoWindow,
SPUILabelDefinitions.DISCARD, SPUILabelDefinitions.DISCARD, null, false, null, spInfo.getMaxArtifactFileSize(), null, file.getType());
SPUIButtonStyleSmall.class); }
discardBtn.setIcon(FontAwesome.TRASH_O);
discardBtn.addStyleName(SPUIStyleDefinitions.ACTION_BUTTON);
discardBtn.addClickListener(event -> discardUploadData(event));
}
private StreamVariable createStreamVariable(final Html5File file) { boolean checkForDuplicate(final String filename) {
return new UploadHandler(file.getFileName(), file.getFileSize(), this, uploadInfoWindow, final Boolean isDuplicate = checkIfFileIsDuplicate(filename);
spInfo.getMaxArtifactFileSize(), null, file.getType()); if (isDuplicate) {
} getDuplicateFileNamesList().add(filename);
}
return isDuplicate;
}
boolean checkForDuplicate(final String filename) { @EventBusListenerMethod(scope = EventScope.SESSION)
final Boolean isDuplicate = checkIfFileIsDuplicate(filename); void toggleProcessButton(final UploadArtifactUIEvent event) {
if (isDuplicate) { if (event == UploadArtifactUIEvent.ENABLE_PROCESS_BUTTON) {
getDuplicateFileNamesList().add(filename); processBtn.setEnabled(true);
} } else if (event == UploadArtifactUIEvent.DISABLE_PROCESS_BUTTON) {
return isDuplicate; processBtn.setEnabled(false);
} }
}
@EventBusListenerMethod(scope = EventScope.SESSION) /**
void toggleProcessButton(final UploadArtifactUIEvent event) { * Save uploaded file details.
if (event == UploadArtifactUIEvent.ENABLE_PROCESS_BUTTON) { *
processBtn.setEnabled(true); * @param stream
} else if (event == UploadArtifactUIEvent.DISABLE_PROCESS_BUTTON) { * read from uploaded file
processBtn.setEnabled(false); * @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);
* 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 SoftwareModule selectedSoftwareModule = artifactUploadState.getSelectedBaseSoftwareModule().get(); final String currentBaseSoftwareModuleKey = HawkbitCommonUtil
.getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion());
final String currentBaseSoftwareModuleKey = HawkbitCommonUtil final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(),
.getFormattedNameVersion(selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion()); selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion(), mimeType);
final CustomFile customFile = new CustomFile(name, size, tempFile.getAbsolutePath(), artifactUploadState.getFileSelected().add(customFile);
selectedSoftwareModule.getName(), selectedSoftwareModule.getVersion(), mimeType); processBtn.setEnabled(false);
artifactUploadState.getFileSelected().add(customFile); if (!artifactUploadState.getBaseSwModuleList().keySet().contains(currentBaseSoftwareModuleKey)) {
processBtn.setEnabled(false); 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)) { Boolean validate() {
artifactUploadState.getBaseSwModuleList().put(currentBaseSoftwareModuleKey, selectedSoftwareModule); if (!isSoftwareModuleSelected()) {
} uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected"));
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() { return false;
if (!isSoftwareModuleSelected()) { }
uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected")); return true;
return false; }
}
return true;
}
SoftwareModule getSoftwareModuleSelected() { SoftwareModule getSoftwareModuleSelected() {
if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) { if (artifactUploadState.getSelectedBaseSoftwareModule().isPresent()) {
return artifactUploadState.getSelectedBaseSoftwareModule().get(); return artifactUploadState.getSelectedBaseSoftwareModule().get();
} }
return null; return null;
} }
Boolean isSoftwareModuleSelected() { Boolean isSoftwareModuleSelected() {
if (!artifactUploadState.getSelectedBaseSwModuleId().isPresent()) { if (!artifactUploadState.getSelectedBaseSwModuleId().isPresent()) {
return false; return false;
} }
return true; return true;
} }
/** /**
* Check if file selected is duplicate.i,e already selected for upload for * Check if file selected is duplicate.i,e already selected for upload for
* same software module. * same software module.
* *
* @param name * @param name
* file name * file name
* @return Boolean * @return Boolean
*/ */
public Boolean checkIfFileIsDuplicate(final String name) { public Boolean checkIfFileIsDuplicate(final String name) {
Boolean isDuplicate = false; Boolean isDuplicate = false;
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());
for (final CustomFile customFile : artifactUploadState.getFileSelected()) { for (final CustomFile customFile : artifactUploadState.getFileSelected()) {
final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion());
if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) { if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) {
isDuplicate = true; isDuplicate = true;
break; break;
} }
} }
return isDuplicate; return isDuplicate;
} }
void decreaseNumberOfFileUploadsExpected() { void decreaseNumberOfFileUploadsExpected() {
numberOfFileUploadsExpected.decrementAndGet(); numberOfFileUploadsExpected.decrementAndGet();
} }
List<String> getDuplicateFileNamesList() { List<String> getDuplicateFileNamesList() {
return duplicateFileNamesList; return duplicateFileNamesList;
} }
/** /**
* Update pending action count. * Update pending action count.
*/ */
void updateActionCount() { void updateActionCount() {
if (!artifactUploadState.getFileSelected().isEmpty()) { if (!artifactUploadState.getFileSelected().isEmpty()) {
processBtn.setCaption(SPUILabelDefinitions.PROCESS + "<div class='unread'>" processBtn.setCaption(SPUILabelDefinitions.PROCESS + "<div class='unread'>"
+ artifactUploadState.getFileSelected().size() + "</div>"); + artifactUploadState.getFileSelected().size() + "</div>");
} else { } else {
processBtn.setCaption(SPUILabelDefinitions.PROCESS); processBtn.setCaption(SPUILabelDefinitions.PROCESS);
} }
} }
void displayValidationMessage() { void displayDuplicateValidationMessage() {
// check if streaming of all dropped files are completed // check if streaming of all dropped files are completed
if (numberOfFilesActuallyUpload.intValue() == numberOfFileUploadsExpected.intValue()) { if (numberOfFilesActuallyUpload.intValue() == numberOfFileUploadsExpected.intValue()) {
displayCompositeMessage(hasDirectory); displayCompositeMessage();
} }
} }
/** private String getDuplicateFileValidationMessage() {
* Show duplicate file selected message. StringBuilder message = new StringBuilder();
*
* @return duplicate file names
*/
public String showDuplicateMessage() {
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 increaseNumberOfFileUploadsExpected() {
numberOfFileUploadsExpected.incrementAndGet();
}
void updateFileSize(final String name, final long size) { void updateFileSize(final String name, final long size) {
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());
for (final CustomFile customFile : artifactUploadState.getFileSelected()) { for (final CustomFile customFile : artifactUploadState.getFileSelected()) {
final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion( final String fileSoftwareModuleKey = HawkbitCommonUtil.getFormattedNameVersion(
customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion()); customFile.getBaseSoftwareModuleName(), customFile.getBaseSoftwareModuleVersion());
if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) { if (customFile.getFileName().equals(name) && currentBaseSoftwareModuleKey.equals(fileSoftwareModuleKey)) {
customFile.setFileSize(size); customFile.setFileSize(size);
break; break;
} }
} }
} }
void increaseNumberOfFilesActuallyUpload() { void increaseNumberOfFilesActuallyUpload() {
numberOfFilesActuallyUpload.incrementAndGet(); numberOfFilesActuallyUpload.incrementAndGet();
} }
/** /**
* Enable process button once upload is completed. * Enable process button once upload is completed.
*/ */
boolean enableProcessBtn() { boolean enableProcessBtn() {
if (numberOfFilesActuallyUpload.intValue() >= numberOfFileUploadsExpected.intValue()) { if (numberOfFilesActuallyUpload.intValue() >= numberOfFileUploadsExpected.intValue()) {
processBtn.setEnabled(true); processBtn.setEnabled(true);
numberOfFileUploadsExpected.set(0); numberOfFileUploadsExpected.set(0);
numberOfFilesActuallyUpload.set(0); numberOfFilesActuallyUpload.set(0);
return true; return true;
} }
return false; return false;
} }
Set<CustomFile> getFileSelected() { Set<CustomFile> getFileSelected() {
return artifactUploadState.getFileSelected(); return artifactUploadState.getFileSelected();
} }
private void discardUploadData(final Button.ClickEvent event) { private void discardUploadData(final Button.ClickEvent event) {
if (event.getButton().equals(discardBtn)) { if (event.getButton().equals(discardBtn)) {
if (artifactUploadState.getFileSelected().isEmpty()) { if (artifactUploadState.getFileSelected().isEmpty()) {
uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); uiNotification.displayValidationError(i18n.get("message.error.noFileSelected"));
} else { } else {
clearFileList(); clearFileList();
} }
} }
} }
/** /**
* Clear details. * Clear details.
*/ */
void clearFileList() { void clearFileList() {
// delete file system zombies // delete file system zombies
artifactUploadState.getFileSelected().forEach(customFile -> { artifactUploadState.getFileSelected().forEach(customFile -> {
final File file = new File(customFile.getFilePath()); final File file = new File(customFile.getFilePath());
file.delete(); file.delete();
}); });
artifactUploadState.getFileSelected().clear(); artifactUploadState.getFileSelected().clear();
artifactUploadState.getBaseSwModuleList().clear(); artifactUploadState.getBaseSwModuleList().clear();
processBtn.setCaption(SPUILabelDefinitions.PROCESS); processBtn.setCaption(SPUILabelDefinitions.PROCESS);
/* disable when there is no files to upload. */ /* disable when there is no files to upload. */
processBtn.setEnabled(false); processBtn.setEnabled(false);
numberOfFileUploadsExpected.set(0); numberOfFileUploadsExpected.set(0);
numberOfFilesActuallyUpload.set(0); numberOfFilesActuallyUpload.set(0);
duplicateFileNamesList.clear(); duplicateFileNamesList.clear();
} }
private void setConfirmationPopupHeightWidth(final float newWidth, final float newHeight) { private void setConfirmationPopupHeightWidth(final float newWidth, final float newHeight) {
if (currentUploadConfirmationwindow != null) { if (currentUploadConfirmationwindow != null) {
currentUploadConfirmationwindow.getUploadArtifactDetails().setWidth(HawkbitCommonUtil currentUploadConfirmationwindow.getUploadArtifactDetails().setWidth(HawkbitCommonUtil
.getArtifactUploadPopupWidth(newWidth, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), .getArtifactUploadPopupWidth(newWidth, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH),
Unit.PIXELS); Unit.PIXELS);
currentUploadConfirmationwindow.getUploadDetailsTable().setHeight(HawkbitCommonUtil currentUploadConfirmationwindow.getUploadDetailsTable().setHeight(HawkbitCommonUtil
.getArtifactUploadPopupHeight(newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), .getArtifactUploadPopupHeight(newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT),
Unit.PIXELS); Unit.PIXELS);
} }
} }
/** /**
* Set artifact upload result pop up size changes. * Set artifact upload result pop up size changes.
* *
* @param newWidth * @param newWidth
* new width of result pop up * new width of result pop up
* @param newHeight * @param newHeight
* new height of result pop up * new height of result pop up
*/ */
void setResultPopupHeightWidth(final float newWidth, final float newHeight) { void setResultPopupHeightWidth(final float newWidth, final float newHeight) {
if (currentUploadConfirmationwindow != null if (currentUploadConfirmationwindow != null
&& currentUploadConfirmationwindow.getCurrentUploadResultWindow() != null) { && currentUploadConfirmationwindow.getCurrentUploadResultWindow() != null) {
final UploadResultWindow uploadResultWindow = currentUploadConfirmationwindow final UploadResultWindow uploadResultWindow = currentUploadConfirmationwindow
.getCurrentUploadResultWindow(); .getCurrentUploadResultWindow();
uploadResultWindow.getUploadResultsWindow().setWidth(HawkbitCommonUtil.getArtifactUploadPopupWidth(newWidth, uploadResultWindow.getUploadResultsWindow().setWidth(HawkbitCommonUtil.getArtifactUploadPopupWidth(newWidth,
SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), Unit.PIXELS); SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_WIDTH), Unit.PIXELS);
uploadResultWindow.getUploadResultTable().setHeight(HawkbitCommonUtil.getArtifactUploadPopupHeight( uploadResultWindow.getUploadResultTable().setHeight(HawkbitCommonUtil.getArtifactUploadPopupHeight(
newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), Unit.PIXELS); newHeight, SPUIDefinitions.MIN_UPLOAD_CONFIRMATION_POPUP_HEIGHT), Unit.PIXELS);
} }
} }
private void displayConfirmWindow(final Button.ClickEvent event) { private void displayConfirmWindow(final Button.ClickEvent event) {
if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON)) { if (event.getComponent().getId().equals(SPUIComponetIdProvider.UPLOAD_PROCESS_BUTTON)) {
if (artifactUploadState.getFileSelected().isEmpty()) { if (artifactUploadState.getFileSelected().isEmpty()) {
uiNotification.displayValidationError(i18n.get("message.error.noFileSelected")); uiNotification.displayValidationError(i18n.get("message.error.noFileSelected"));
} else { } else {
currentUploadConfirmationwindow = new UploadConfirmationwindow(this, artifactUploadState); currentUploadConfirmationwindow = new UploadConfirmationwindow(this, artifactUploadState);
UI.getCurrent().addWindow(currentUploadConfirmationwindow.getUploadConfrimationWindow()); UI.getCurrent().addWindow(currentUploadConfirmationwindow.getUploadConfrimationWindow());
setConfirmationPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(), setConfirmationPopupHeightWidth(Page.getCurrent().getBrowserWindowWidth(),
Page.getCurrent().getBrowserWindowHeight()); Page.getCurrent().getBrowserWindowHeight());
} }
} }
} }
/** /**
* @return * @return
*/ */
I18N getI18n() { I18N getI18n() {
return i18n; return i18n;
} }
/** /**
* @return * @return
*/ */
SPInfo getSPInfo() { SPInfo getSPInfo() {
return spInfo; return spInfo;
} }
void setCurrentUploadConfirmationwindow(final UploadConfirmationwindow currentUploadConfirmationwindow) { void setCurrentUploadConfirmationwindow(final UploadConfirmationwindow currentUploadConfirmationwindow) {
this.currentUploadConfirmationwindow = currentUploadConfirmationwindow; this.currentUploadConfirmationwindow = currentUploadConfirmationwindow;
} }
/** /**
* @return * @return
*/ */
VerticalLayout getDropAreaLayout() { VerticalLayout getDropAreaLayout() {
return dropAreaLayout; return dropAreaLayout;
} }
@EventBusListenerMethod(scope = EventScope.SESSION) @EventBusListenerMethod(scope = EventScope.SESSION)
void onEvent(final UploadArtifactUIEvent event) { void onEvent(final UploadArtifactUIEvent event) {
if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE) { if (event == UploadArtifactUIEvent.DELETED_ALL_SOFWARE) {
ui.access(() -> updateActionCount()); ui.access(() -> updateActionCount());
} }
} }
@PreDestroy @PreDestroy
void destroy() { void destroy() {
/* /*
* It's good manners to do this, even though vaadin-spring will * It's good manners to do this, even though vaadin-spring will
* automatically unsubscribe when this UI is garbage collected. * automatically unsubscribe when this UI is garbage collected.
*/ */
eventBus.unsubscribe(this); eventBus.unsubscribe(this);
} }
/** /**
* set upload status and confirmation window. * set upload status and confirmation window.
* *
* @param newWidth * @param newWidth
* browser width * browser width
* @param newHeight * @param newHeight
* browser height * browser height
*/ */
public void setUploadPopupSize(final float newWidth, final float newHeight) { public void setUploadPopupSize(final float newWidth, final float newHeight) {
setConfirmationPopupHeightWidth(newWidth, newHeight); setConfirmationPopupHeightWidth(newWidth, newHeight);
setResultPopupHeightWidth(newWidth, newHeight); setResultPopupHeightWidth(newWidth, newHeight);
} }
/** /**
* @param selectedBaseSoftwareModule * @param selectedBaseSoftwareModule
*/ */
public void refreshArtifactDetailsLayout(final SoftwareModule selectedBaseSoftwareModule) { public void refreshArtifactDetailsLayout(final SoftwareModule selectedBaseSoftwareModule) {
eventBus.publish(this, eventBus.publish(this,
new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED, selectedBaseSoftwareModule)); new SoftwareModuleEvent(SoftwareModuleEventType.ARTIFACTS_CHANGED, selectedBaseSoftwareModule));
} }
/** /**
* @return the fileUploadLayout * @return the fileUploadLayout
*/ */
public HorizontalLayout getFileUploadLayout() { public HorizontalLayout getFileUploadLayout() {
return fileUploadLayout; return fileUploadLayout;
} }
public UINotification getUINotification() { public UINotification getUINotification() {
return uiNotification; return uiNotification;
} }
} }