intial commit

Signed-off-by: asharani-murugesh <asharani.murugesh@in.bosch.com>
This commit is contained in:
asharani-murugesh
2016-02-08 10:47:42 +01:00
parent be45209598
commit 70959ec140
2 changed files with 548 additions and 511 deletions

View File

@@ -89,6 +89,7 @@ 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);
@@ -108,6 +109,7 @@ 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)) {
@@ -167,7 +169,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.displayDuplicateMessageAfterStreamingAll(); view.displayValidationMessage();
} }
/** /**
@@ -292,7 +294,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
if (view.enableProcessBtn()) { if (view.enableProcessBtn()) {
infoWindow.uploadSessionFinished(); infoWindow.uploadSessionFinished();
} }
view.displayDuplicateMessageAfterStreamingAll(); view.displayValidationMessage();
LOG.info("Streaming failed due to :{}", event.getException()); LOG.info("Streaming failed due to :{}", event.getException());
} }

View File

@@ -46,6 +46,7 @@ import org.vaadin.spring.events.EventBus;
import org.vaadin.spring.events.EventScope; import org.vaadin.spring.events.EventScope;
import org.vaadin.spring.events.annotation.EventBusListenerMethod; import org.vaadin.spring.events.annotation.EventBusListenerMethod;
import com.google.common.base.Strings;
import com.vaadin.event.dd.DragAndDropEvent; import com.vaadin.event.dd.DragAndDropEvent;
import com.vaadin.event.dd.DropHandler; import com.vaadin.event.dd.DropHandler;
import com.vaadin.event.dd.acceptcriteria.AcceptAll; import com.vaadin.event.dd.acceptcriteria.AcceptAll;
@@ -70,7 +71,7 @@ import com.vaadin.ui.VerticalLayout;
/** /**
* Upload files layout. * Upload files layout.
* *
* * @author G Venkata Narayana (RBEI/BSO3)
*/ */
@ViewScope @ViewScope
@SpringComponent @SpringComponent
@@ -118,6 +119,8 @@ public class UploadLayout extends VerticalLayout {
private DragAndDropWrapper dropAreaWrapper; private DragAndDropWrapper dropAreaWrapper;
private Boolean hasDirectory = Boolean.FALSE;
/** /**
* Initialize the upload layout. * Initialize the upload layout.
*/ */
@@ -185,25 +188,55 @@ public class UploadLayout extends VerticalLayout {
@Override @Override
public void drop(final DragAndDropEvent event) { public void drop(final DragAndDropEvent event) {
if (validate()) { if (validate()) {
((WrapperTransferable) event.getTransferable()).getDraggedComponent();
final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles();
if (files != null) { if (files != null) {
for (final Html5File file : files) { for (final Html5File file : files) {
if (!isDirectory(file)) {
if (!checkForDuplicate(file.getFileName())) { if (!checkForDuplicate(file.getFileName())) {
numberOfFileUploadsExpected.incrementAndGet(); numberOfFileUploadsExpected.incrementAndGet();
file.setStreamVariable(createStreamVariable(file)); file.setStreamVariable(createStreamVariable(file));
} }
} else {
hasDirectory = Boolean.TRUE;
}
} }
if (numberOfFileUploadsExpected.get() > 0) { if (numberOfFileUploadsExpected.get() > 0) {
processBtn.setEnabled(false); processBtn.setEnabled(false);
// reset before we start // reset before we start
uploadInfoWindow.uploadSessionStarted(); 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 // in case if all selected files are duplicate ,then display
// message // messag
displayDuplicateMessageAfterStreamingAll(); 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() { Boolean validate() {
if (!isSoftwareModuleSelected()) { if (!isSoftwareModuleSelected()) {
uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected")); uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected"));
return false; return false;
} }
return true; return true;
@@ -383,27 +415,30 @@ public class UploadLayout extends VerticalLayout {
} }
} }
void displayDuplicateMessageAfterStreamingAll() { void displayValidationMessage() {
// 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()) {
showDuplicateMessage(); displayCompositeMessage(hasDirectory);
} }
} }
/** /**
* Show duplicate file selected message. * Show duplicate file selected message.
*
* @return duplicate file names
*/ */
public void showDuplicateMessage() { 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) {
uiNotification.displayValidationError(i18n.get("message.no.duplicateFile") + fileNames); return i18n.get("message.no.duplicateFile") + fileNames;
} else if (duplicateFileNamesList.size() > 1) { } else if (duplicateFileNamesList.size() > 1) {
uiNotification.displayValidationError(i18n.get("message.no.duplicateFiles")); return i18n.get("message.no.duplicateFiles");
} }
duplicateFileNamesList.clear(); duplicateFileNamesList.clear();
} }
return null;
} }
void increaseNumberOfFileUploadsExpected() { void increaseNumberOfFileUploadsExpected() {