intial commit
Signed-off-by: asharani-murugesh <asharani.murugesh@in.bosch.com>
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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,7 +71,7 @@ import com.vaadin.ui.VerticalLayout;
|
||||
/**
|
||||
* Upload files layout.
|
||||
*
|
||||
*
|
||||
* @author G Venkata Narayana (RBEI/BSO3)
|
||||
*/
|
||||
@ViewScope
|
||||
@SpringComponent
|
||||
@@ -118,6 +119,8 @@ public class UploadLayout extends VerticalLayout {
|
||||
|
||||
private DragAndDropWrapper dropAreaWrapper;
|
||||
|
||||
private Boolean hasDirectory = Boolean.FALSE;
|
||||
|
||||
/**
|
||||
* Initialize the upload layout.
|
||||
*/
|
||||
@@ -185,25 +188,55 @@ 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));
|
||||
}
|
||||
} 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
|
||||
// message
|
||||
displayDuplicateMessageAfterStreamingAll();
|
||||
// messag
|
||||
compositeMessage.append(duplicateMessage);
|
||||
}
|
||||
if (hasDirectory) {
|
||||
if (compositeMessage.length() > 0) {
|
||||
compositeMessage.append("<br>");
|
||||
}
|
||||
compositeMessage.append(i18n.get("message.no.directory.upload"));
|
||||
}
|
||||
if (!compositeMessage.toString().isEmpty()) {
|
||||
uiNotification.displayValidationError(compositeMessage.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,7 +351,6 @@ public class UploadLayout extends VerticalLayout {
|
||||
Boolean validate() {
|
||||
if (!isSoftwareModuleSelected()) {
|
||||
uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected"));
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -383,27 +415,30 @@ public class UploadLayout extends VerticalLayout {
|
||||
}
|
||||
}
|
||||
|
||||
void displayDuplicateMessageAfterStreamingAll() {
|
||||
void displayValidationMessage() {
|
||||
// check if streaming of all dropped files are completed
|
||||
if (numberOfFilesActuallyUpload.intValue() == numberOfFileUploadsExpected.intValue()) {
|
||||
showDuplicateMessage();
|
||||
displayCompositeMessage(hasDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show duplicate file selected message.
|
||||
*
|
||||
* @return duplicate file names
|
||||
*/
|
||||
public void showDuplicateMessage() {
|
||||
public String showDuplicateMessage() {
|
||||
if (!duplicateFileNamesList.isEmpty()) {
|
||||
final String fileNames = StringUtils.collectionToCommaDelimitedString(duplicateFileNamesList);
|
||||
if (duplicateFileNamesList.size() == 1) {
|
||||
uiNotification.displayValidationError(i18n.get("message.no.duplicateFile") + fileNames);
|
||||
return i18n.get("message.no.duplicateFile") + fileNames;
|
||||
|
||||
} else if (duplicateFileNamesList.size() > 1) {
|
||||
uiNotification.displayValidationError(i18n.get("message.no.duplicateFiles"));
|
||||
return i18n.get("message.no.duplicateFiles");
|
||||
}
|
||||
duplicateFileNamesList.clear();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void increaseNumberOfFileUploadsExpected() {
|
||||
|
||||
Reference in New Issue
Block a user