Merge pull request #53 from bsinno/Artifiact_upload_directory_upload
👍 merged
This commit is contained in:
@@ -108,8 +108,10 @@ 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;
|
||||||
|
//reset has directory flag before upload
|
||||||
|
view.setHasDirectory(false);
|
||||||
try {
|
try {
|
||||||
if (view.validate()) {
|
if (view.checkIfSoftwareModuleIsSelected()) {
|
||||||
if (view.checkForDuplicate(fileName)) {
|
if (view.checkForDuplicate(fileName)) {
|
||||||
view.showDuplicateMessage();
|
view.showDuplicateMessage();
|
||||||
} else {
|
} else {
|
||||||
@@ -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.displayDuplicateValidationMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -292,7 +294,7 @@ public class UploadHandler implements StreamVariable, Receiver, SucceededListene
|
|||||||
if (view.enableProcessBtn()) {
|
if (view.enableProcessBtn()) {
|
||||||
infoWindow.uploadSessionFinished();
|
infoWindow.uploadSessionFinished();
|
||||||
}
|
}
|
||||||
view.displayDuplicateMessageAfterStreamingAll();
|
view.displayDuplicateValidationMessage();
|
||||||
|
|
||||||
LOG.info("Streaming failed due to :{}", event.getException());
|
LOG.info("Streaming failed due to :{}", event.getException());
|
||||||
}
|
}
|
||||||
@@ -316,7 +318,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());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -116,6 +117,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.
|
||||||
*/
|
*/
|
||||||
@@ -182,27 +185,60 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drop(final DragAndDropEvent event) {
|
public void drop(final DragAndDropEvent event) {
|
||||||
if (validate()) {
|
if (validate(event)) {
|
||||||
|
|
||||||
final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles();
|
final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles();
|
||||||
if (files != null) {
|
// reset the flag
|
||||||
for (final Html5File file : files) {
|
hasDirectory = Boolean.FALSE;
|
||||||
if (!checkForDuplicate(file.getFileName())) {
|
for (final Html5File file : files) {
|
||||||
numberOfFileUploadsExpected.incrementAndGet();
|
processFile(file);
|
||||||
file.setStreamVariable(createStreamVariable(file));
|
}
|
||||||
}
|
if (numberOfFileUploadsExpected.get() > 0) {
|
||||||
}
|
processBtn.setEnabled(false);
|
||||||
if (numberOfFileUploadsExpected.get() > 0) {
|
// reset before we start
|
||||||
processBtn.setEnabled(false);
|
uploadInfoWindow.uploadSessionStarted();
|
||||||
// reset before we start
|
} else {
|
||||||
uploadInfoWindow.uploadSessionStarted();
|
// If the upload is not started, it signifies all
|
||||||
}
|
// dropped files as either duplicate or directory.So
|
||||||
// in case if all selected files are duplicate ,then display
|
// display message accordingly
|
||||||
// message
|
displayCompositeMessage();
|
||||||
displayDuplicateMessageAfterStreamingAll();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
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("<br>");
|
||||||
|
}
|
||||||
|
compositeMessage.append(i18n.get("message.no.directory.upload"));
|
||||||
|
}
|
||||||
|
if (!compositeMessage.toString().isEmpty()) {
|
||||||
|
uiNotification.displayValidationError(compositeMessage.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private VerticalLayout createDropAreaLayout() {
|
private VerticalLayout createDropAreaLayout() {
|
||||||
@@ -313,10 +349,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()) {
|
if (!isSoftwareModuleSelected()) {
|
||||||
uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected"));
|
uiNotification.displayValidationError(i18n.get("message.error.noSwModuleSelected"));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -381,27 +440,30 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayDuplicateMessageAfterStreamingAll() {
|
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()) {
|
||||||
showDuplicateMessage();
|
displayCompositeMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private String getDuplicateFileValidationMessage() {
|
||||||
* Show duplicate file selected message.
|
StringBuilder message = new StringBuilder();
|
||||||
*/
|
|
||||||
public void 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);
|
message.append(i18n.get("message.no.duplicateFile") + fileNames);
|
||||||
|
|
||||||
} else if (duplicateFileNamesList.size() > 1) {
|
} else if (duplicateFileNamesList.size() > 1) {
|
||||||
uiNotification.displayValidationError(i18n.get("message.no.duplicateFiles"));
|
message.append(i18n.get("message.no.duplicateFiles"));
|
||||||
}
|
}
|
||||||
duplicateFileNamesList.clear();
|
duplicateFileNamesList.clear();
|
||||||
}
|
}
|
||||||
|
return message.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showDuplicateMessage() {
|
||||||
|
uiNotification.displayValidationError(getDuplicateFileValidationMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
void increaseNumberOfFileUploadsExpected() {
|
void increaseNumberOfFileUploadsExpected() {
|
||||||
@@ -593,4 +655,8 @@ public class UploadLayout extends VerticalLayout {
|
|||||||
return uiNotification;
|
return uiNotification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setHasDirectory(Boolean hasDirectory) {
|
||||||
|
this.hasDirectory = hasDirectory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ soft.module.os =OS
|
|||||||
message.error.noFileSelected = No file selected for upload
|
message.error.noFileSelected = No file selected for upload
|
||||||
message.error.noProvidedName = Please provide custom file name
|
message.error.noProvidedName = Please provide custom file name
|
||||||
message.error.noSwModuleSelected = Please select a software module
|
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.no.duplicateFile = Duplicate file selected :
|
||||||
message.delete.artifact = Are you sure that you want to delete artifact {0} ?
|
message.delete.artifact = Are you sure that you want to delete artifact {0} ?
|
||||||
message.duplicate.filename = Duplicate file name
|
message.duplicate.filename = Duplicate file name
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ soft.module.os =OS
|
|||||||
message.error.noFileSelected = No file selected for upload
|
message.error.noFileSelected = No file selected for upload
|
||||||
message.error.noProvidedName = Please provide custom file name
|
message.error.noProvidedName = Please provide custom file name
|
||||||
message.error.noSwModuleSelected = Please select a software module
|
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.no.duplicateFile = Duplicate file selected :
|
||||||
message.delete.artifact = Are you sure that you want to delete artifact {0} ?
|
message.delete.artifact = Are you sure that you want to delete artifact {0} ?
|
||||||
message.duplicate.filename = Duplicate file name
|
message.duplicate.filename = Duplicate file name
|
||||||
|
|||||||
@@ -305,7 +305,7 @@ soft.module.os =OS
|
|||||||
message.error.noFileSelected = No file selected for upload
|
message.error.noFileSelected = No file selected for upload
|
||||||
message.error.noProvidedName = Please provide custom file name
|
message.error.noProvidedName = Please provide custom file name
|
||||||
message.error.noSwModuleSelected = Please select a software module
|
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.no.duplicateFile = Duplicate file selected :
|
||||||
message.delete.artifact = Are you sure that you want to delete artifact {0} ?
|
message.delete.artifact = Are you sure that you want to delete artifact {0} ?
|
||||||
message.duplicate.filename = Duplicate file name
|
message.duplicate.filename = Duplicate file name
|
||||||
|
|||||||
Reference in New Issue
Block a user