Compare commits

...

12 Commits

11 changed files with 740 additions and 482 deletions

View File

@ -3,11 +3,16 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v2.1.0-SNAPSHOT] - 2022-05-03
## [v2.1.1] - 2024-07-29
- [#27898] Updated `uploadFile` and `uploadArchive` methods. They include the `fileSize` parameter
- [#27934] Updated the data structure to handle asynchronous uploading of multiple files
## [v2.1.0] - 2022-05-03
#### Enhancements
- [#23225] pdated the method to read the members of (VRE or Simple) shared folders
- [#23225] Updated the method to read the members of (VRE or Simple) shared folders
## [v2.0.6] - 2020-07-15

64
pom.xml
View File

@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.1.0</version>
<version>1.2.0</version>
<relativePath />
</parent>
@ -12,7 +13,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>workspace-uploader</artifactId>
<packaging>jar</packaging>
<version>2.1.0-SNAPSHOT</version>
<version>2.1.1</version>
<name>Workspace Uploader Widget</name>
<description>Workspace Uploader Widget allows your application to upload file/s in the gCube Workspace</description>
<scm>
@ -30,6 +31,7 @@
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven-portal-bom>4.0.0</maven-portal-bom>
</properties>
<dependencyManagement>
@ -37,26 +39,40 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>3.6.3</version>
<version>${maven-portal-bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Profiles required for managing SHUB vesion via maven-portal-bom -->
<profiles>
<!-- PROD profile -->
<profile>
<id>localRun</id>
<dependencies>
<dependency>
<groupId>xerces</groupId>
<artifactId>xerces</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
<id>workspace-release-profile</id>
<activation>
<property>
<name>Release</name>
</property>
</activation>
<properties>
<maven-portal-bom>4.0.0</maven-portal-bom>
</properties>
</profile>
<!-- DEV profile -->
<profile>
<id>workspace-snapshot-profile</id>
<activation>
<property>
<name>!Release</name>
</property>
</activation>
<properties>
<maven-portal-bom>4.0.0-SNAPSHOT</maven-portal-bom>
</properties>
</profile>
</profiles>
<dependencies>
<!-- Google Web Toolkit (GWT) -->
@ -143,6 +159,11 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>
<!-- Logger -->
<dependency>
<groupId>org.slf4j</groupId>
@ -154,13 +175,24 @@
<artifactId>slf4j-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.social-networking</groupId>
<artifactId>social-service-client</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.gcube.portal</groupId> -->
<!-- <artifactId>social-networking-library</artifactId> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslsocial</artifactId>

View File

@ -32,6 +32,8 @@ public class ConstantsWorkspaceUploader {
public static final String UPLOAD_FORM_ELEMENT = "uploadFormElement";
public static final String CLIENT_UPLOAD_KEYS = "client_upload_keys";
public static final String CLIENT_UPLOAD_FILEOBJ_FILENAME = "filename";
public static final String CLIENT_UPLOAD_FILEOBJ_FILESIZE= "filesize";
public static final String CANCEL_UPLOAD = "cancel_upload";
public static final String JSON_CLIENT_KEYS = "ClientKeys";

View File

@ -15,11 +15,15 @@ import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem.UPLOAD_STATUS;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent;
import com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler;
@ -43,16 +47,12 @@ public class MultipleDilaogUpload extends DialogUpload {
private String idFolder;
private UPLOAD_TYPE type;
/**
* Instantiates a new multiple dilaog upload stream.
*
* @param headerTitle
* the header title
* @param parentId
* the parent id
* @param uploadType
* the upload type
* @param headerTitle the header title
* @param parentId the parent id
* @param uploadType the upload type
*/
public MultipleDilaogUpload(String headerTitle, String parentId, UPLOAD_TYPE uploadType) {
super(headerTitle, parentId, uploadType);
@ -65,7 +65,9 @@ public class MultipleDilaogUpload extends DialogUpload {
this.addHandlers();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.google.gwt.user.client.ui.DialogBox#show()
*/
@Override
@ -73,7 +75,9 @@ public class MultipleDilaogUpload extends DialogUpload {
super.show();
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see com.google.gwt.user.client.ui.PopupPanel#center()
*/
@Override
@ -88,36 +92,45 @@ public class MultipleDilaogUpload extends DialogUpload {
* @param parentId the parent id
* @return the list
*/
public void generateFakeUploaders(String filesSelected, String parentId) {
public void generateFakeUploaders(JSONArray filesSelected, String parentId) {
if(filesSelected==null || filesSelected.isEmpty())
if (filesSelected == null || filesSelected.size() == 0)
return;
String[] files = filesSelected.split(FILE_DELEMITER);
// String[] files = filesSelected.split(FILE_DELEMITER);
// NORMALIZE FILE NAMES
for (int i = 0; i < files.length; i++) {
String normalizedFileName = files[i];
for (int i = 0; i < filesSelected.size(); i++) {
JSONObject fileObject = (JSONObject) filesSelected.get(i);
GWT.log("checking filename for: " + fileObject.getJavaScriptObject().toString());
String normalizedFileName = fileObject.get("filename").isString().stringValue();
if (normalizedFileName.contains("\\")) {
files[i] = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\") + 1); // remove C:\fakepath if exists
String sanitizedValue = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\") + 1); // remove
// C:\fakepath
// if exists
JSONValue jsonValue = JSONParser.parseStrict(sanitizedValue);
fileObject.put("filename", jsonValue);
filesSelected.set(i, fileObject);
}
}
GWT.log("generating fake uploaders on: "+Arrays.asList(files.toString()));
fakeUploaders = new ArrayList<WorkspaceUploaderItem>(files.length);
for (int i = 0; i < files.length; i++) {
fakeUploaders = new ArrayList<WorkspaceUploaderItem>(filesSelected.size());
for (int i = 0; i < filesSelected.size(); i++) {
JSONObject fileObject = (JSONObject) filesSelected.get(i);
WorkspaceUploaderItem fakeItem = new WorkspaceUploaderItem();
fakeItem.setClientUploadKey(GenerateUUID.get());
fakeItem.setUploadStatus(UPLOAD_STATUS.WAIT);
WorkspaceUploadFile fakeFile = new WorkspaceUploadFile();
fakeFile.setFileName(files[i]);
String fileName = fileObject.get("filename").isString().stringValue();
Long fileSize = (long) fileObject.get("size").isNumber().doubleValue();
fakeFile.setFileName(fileName);
fakeFile.setFileSize(fileSize);
fakeFile.setParentId(parentId);
fakeItem.setFile(fakeFile);
fakeUploaders.add(fakeItem);
}
GWT.log("fakeUploaders generated: " + fakeUploaders.toString());
// return fakeUploaders;
}
/*
@ -141,13 +154,11 @@ public class MultipleDilaogUpload extends DialogUpload {
if (result == null) {
removeLoading();
new DialogResult(null, "Error during upload",
"An error occurred during file upload.").center();
new DialogResult(null, "Error during upload", "An error occurred during file upload.").center();
return;
}
String strippedResult = new HTML(result).getText();
final HandlerResultMessage resultMessage = HandlerResultMessage
.parseResult(strippedResult);
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
switch (resultMessage.getStatus()) {
case ERROR:
@ -193,24 +204,26 @@ public class MultipleDilaogUpload extends DialogUpload {
@Override
public void onChange(ChangeEvent event) {
GWT.log("browse return...");
if (fileUpload.getFilename() == null
|| fileUpload.getFilename().isEmpty()) {
if (fileUpload.getFilename() == null || fileUpload.getFilename().isEmpty()) {
GWT.log("No file specified ");
MultipleDilaogUpload.this.hide();
return;
}
String[] files = null;
GWT.log("Current Uploader has id: " + fileUploadID);
String filesSelected = getFilesSelected(fileUploadID, FILE_DELEMITER);
GWT.log("getFilesSelected: " + filesSelected);
files = filesSelected.split(FILE_DELEMITER);
JavaScriptObject filesSelected = getFilesSelected(fileUploadID);
if(isLimitExceeded(files.length))
JSONArray jsonArray = new JSONArray(filesSelected);
if(jsonArray!=null)
GWT.log("sono array");
GWT.log("getFilesSelected: " + jsonArray);
if (isLimitExceeded(jsonArray.size()))
return;
// GENERATE NEW UPLOADERS
generateFakeUploaders(filesSelected, parentIdentifier);
generateFakeUploaders(jsonArray, parentIdentifier);
GWT.log(fakeUploaders.toString());
createJsonKeyForFiles();
GWT.log(jsonKeys);
@ -223,55 +236,13 @@ public class MultipleDilaogUpload extends DialogUpload {
// ADD TO FORM PANEL
// initJsonClientKeys();
jsonClientKeys.setValue(jsonKeys);
// // CASE 1 FILE
// if (files.length == 1) {
//
// // recall: Some browser would write in
// // fileUploadField.getValue() C:\fakepath\$fileName
// final String label = files[0];
// WorkspaceUploaderServiceAsync.Util.getInstance()
// .itemExistsInWorkpaceFolder(parentIdentifier,
// label, new AsyncCallback<String>() {
//
// @Override
// public void onSuccess(
// final String itemId) {
// GWT.log("itemExistsInWorkpaceFolder: "
// + itemId);
// if (itemId != null) {
// removeItemAndSubmitForm(itemId);
// updateItemSubmitForm(itemId);
//// if (Window.confirm(label+ " exists in folder. If you continue, a new version will be created")) {
//// removeItemAndSubmitForm(itemId);
//// updateItemSubmitForm(itemId);
//// }
// } else
// submitForm(); // ITEM does NOT
// // EXIST SO
// // SUBMIT FORM;
// }
//
// @Override
// public void onFailure(Throwable caught) {
// GWT.log("Sorry an error occurred on the server "
// + caught.getLocalizedMessage()
// + ". Please try again later");
// Window.alert(caught.getMessage());
// }
//
// });
// } else
submitForm();
}
});
}
/**
* Checks if is limit exceeded.
*
@ -281,9 +252,7 @@ public class MultipleDilaogUpload extends DialogUpload {
public boolean isLimitExceeded(int numbOfFiles) {
if (numbOfFiles > ConstantsWorkspaceUploader.LIMIT_UPLOADS) {
Window.alert("Multiple upload limit is "
+ ConstantsWorkspaceUploader.LIMIT_UPLOADS
+ " files");
Window.alert("Multiple upload limit is " + ConstantsWorkspaceUploader.LIMIT_UPLOADS + " files");
MultipleDilaogUpload.this.hide();
return true;
}
@ -298,7 +267,8 @@ public class MultipleDilaogUpload extends DialogUpload {
GWT.log("addNewSubmitToMonitor...");
int queueIndex = UploaderMonitor.getInstance().newQueue();
for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem,
workspaceUploaderItem.getFile().getFileName());
setVisible(false);
removeLoading();
UploaderMonitor.getInstance().addNewUploaderToQueue(queueIndex, workspaceUploaderItem);
@ -308,7 +278,6 @@ public class MultipleDilaogUpload extends DialogUpload {
UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);
}
/**
* Creates the json key for files.
*
@ -325,7 +294,11 @@ public class MultipleDilaogUpload extends DialogUpload {
for (int i = 0; i < fakeUploaders.size(); i++) {
WorkspaceUploaderItem file = fakeUploaders.get(i);
JSONObject obj = new JSONObject();
obj.put(file.getClientUploadKey(), new JSONString(file.getFile().getFileName()));
JSONObject fileObject = new JSONObject();
//Feature #27934
fileObject.put(ConstantsWorkspaceUploader.CLIENT_UPLOAD_FILEOBJ_FILENAME, new JSONString(file.getFile().getFileName()));
fileObject.put(ConstantsWorkspaceUploader.CLIENT_UPLOAD_FILEOBJ_FILESIZE, new JSONNumber(file.getFile().getFileSize()));
obj.put(file.getClientUploadKey(), fileObject);
jsonArray.set(i, obj);
}
@ -394,22 +367,24 @@ public class MultipleDilaogUpload extends DialogUpload {
/**
* Gets the files selected.
*
* @param tagId
* the tag id
* @param fileDelimiter
* the file delimiter
* @param tagId the tag id
* @param fileDelimiter the file delimiter
* @return the files selected
*/
public static native String getFilesSelected(final String tagId, final String fileDelimiter) /*-{
public static native JavaScriptObject getFilesSelected(final String tagId) /*-{
var count = $wnd.$("#" + tagId)[0].files.length;
console.log(count);
var out = "";
console.log("number of files: "+count);
var outputs = [];
for (i = 0; i < count; i++) {
var file = $wnd.$("#" + tagId)[0].files[i];
//out += file.name + fileDelimiter + file.size + fileDelimiter;
out += file.name + fileDelimiter;
var the_file = { "filename": file.name, "size": file.size };
//var jsonString = JSON.stringify(the_file);
//console.log("the file is: "+jsonString);
outputs.push(the_file);
}
return out;
console.log("returning outputs: "+outputs);
return outputs;
}-*/;
}

View File

@ -14,15 +14,17 @@ import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem
import com.google.gwt.core.client.GWT;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Window;
/**
* The Class WorkspaceFieldsUpload.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Oct 20, 2015
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Oct 20, 2015
*/
public class WorkspaceFieldsUploadManager {
@ -31,7 +33,6 @@ public class WorkspaceFieldsUploadManager {
public static final String FILE_DELEMITER = ";";
private List<WorkspaceUploaderItem> fakeUploaders = new ArrayList<WorkspaceUploaderItem>();
public WorkspaceFieldsUploadManager() {
}
@ -44,9 +45,7 @@ public class WorkspaceFieldsUploadManager {
public boolean isLimitExceeded(int numbOfFiles) {
if (numbOfFiles > ConstantsWorkspaceUploader.LIMIT_UPLOADS) {
Window.alert("Multiple upload limit is "
+ ConstantsWorkspaceUploader.LIMIT_UPLOADS
+ " files");
Window.alert("Multiple upload limit is " + ConstantsWorkspaceUploader.LIMIT_UPLOADS + " files");
return true;
}
@ -60,14 +59,14 @@ public class WorkspaceFieldsUploadManager {
GWT.log("addNewSubmitToMonitor...");
int queueIndex = UploaderMonitor.getInstance().newQueue();
for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem,
workspaceUploaderItem.getFile().getFileName());
UploaderMonitor.getInstance().addNewUploaderToQueue(queueIndex, workspaceUploaderItem);
// UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
}
UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);
}
/**
* Creates the json key for files.
*
@ -84,7 +83,15 @@ public class WorkspaceFieldsUploadManager {
for (int i = 0; i < fakeUploaders.size(); i++) {
WorkspaceUploaderItem file = fakeUploaders.get(i);
JSONObject obj = new JSONObject();
obj.put(file.getClientUploadKey(), new JSONString(file.getFile().getFileName()));
JSONObject fileObject = new JSONObject();
// Feature #27934
fileObject.put(ConstantsWorkspaceUploader.CLIENT_UPLOAD_FILEOBJ_FILENAME,
new JSONString(file.getFile().getFileName()));
fileObject.put(ConstantsWorkspaceUploader.CLIENT_UPLOAD_FILEOBJ_FILESIZE,
new JSONNumber(file.getFile().getFileSize()));
obj.put(file.getClientUploadKey(), fileObject);
// obj.put(file.getClientUploadKey(), new
// JSONString(file.getFile().getFileName()));
jsonArray.set(i, obj);
}
@ -103,32 +110,37 @@ public class WorkspaceFieldsUploadManager {
* @param parentId the parent id
* @return the list
*/
public void generateFakeUploaders(String filesSelected, String parentId) {
public void generateFakeUploaders(JSONArray filesSelected, String parentId) {
if(filesSelected==null || filesSelected.isEmpty())
if (filesSelected == null || filesSelected.size() == 0)
return;
String[] files = filesSelected.split(FILE_DELEMITER);
// NORMALIZE FILE NAMES
for (int i = 0; i < files.length; i++) {
String normalizedFileName = files[i];
for (int i = 0; i < filesSelected.size(); i++) {
JSONObject fileObject = (JSONObject) filesSelected.get(i);
GWT.log("checking filename for: " + fileObject.getJavaScriptObject().toString());
String normalizedFileName = fileObject.get("filename").isString().stringValue();
if (normalizedFileName.contains("\\")) {
files[i] = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\") + 1); // remove
// C:\fakepath\
// if
// exists
String sanitizedValue = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\") + 1); // remove
// C:\fakepath
// if exists
JSONValue jsonValue = JSONParser.parseStrict(sanitizedValue);
fileObject.put("filename", jsonValue);
filesSelected.set(i, fileObject);
}
}
GWT.log("generating fake uploaders on: "+Arrays.asList(files).toString());
fakeUploaders = new ArrayList<WorkspaceUploaderItem>(files.length);
for (int i = 0; i < files.length; i++) {
fakeUploaders = new ArrayList<WorkspaceUploaderItem>(filesSelected.size());
for (int i = 0; i < filesSelected.size(); i++) {
JSONObject fileObject = (JSONObject) filesSelected.get(i);
WorkspaceUploaderItem fakeItem = new WorkspaceUploaderItem();
fakeItem.setClientUploadKey(GenerateUUID.get());
fakeItem.setUploadStatus(UPLOAD_STATUS.WAIT);
WorkspaceUploadFile fakeFile = new WorkspaceUploadFile();
fakeFile.setFileName(files[i]);
String fileName = fileObject.get("filename").isString().stringValue();
Long fileSize = (long) fileObject.get("size").isNumber().doubleValue();
fakeFile.setFileName(fileName);
fakeFile.setFileSize(fileSize);
fakeFile.setParentId(parentId);
fakeItem.setFile(fakeFile);
fakeUploaders.add(fakeItem);
@ -137,7 +149,6 @@ public class WorkspaceFieldsUploadManager {
GWT.log("fakeUploaders generated: " + fakeUploaders.toString());
}
/**
* @return the jsonKeys
*/

View File

@ -14,7 +14,9 @@ import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderList
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.WorkspaceFieldsUploadManager;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HTML;
@ -252,9 +254,10 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
* @param uploadUUID
* the upload uuid
*/
private void generateFakeUploaders(String filesSelected, String parentId, String uploadUUID) {
private void generateFakeUploaders(JavaScriptObject filesSelected, String parentId, String uploadUUID) {
WorkspaceFieldsUploadManager field = getFieldsUploadManager(uploadUUID);
field.generateFakeUploaders(filesSelected, parentId);
JSONArray jsonArray = new JSONArray(filesSelected);
field.generateFakeUploaders(jsonArray, parentId);
}
@ -607,14 +610,15 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
console.log("# of file/s: " + files.length);
var filesSelected = "";
var arrayFileSelected = [];
for (i = 0; i < files.length; i++) {
filesSelected += files[i].name + fileDelimiter;
var file = files[i];
var the_file = { "filename": file.name, "size": file.size };
arrayFileSelected.push(the_file);
}
console.log("filesSelected: " + filesSelected);
console.log("Object arrayFileSelected: " + arrayFileSelected);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::generateFakeUploaders(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)(filesSelected,idfolder,uploadUUID);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::generateFakeUploaders(Lcom/google/gwt/core/client/JavaScriptObject;Ljava/lang/String;Ljava/lang/String;)(arrayFileSelected,idfolder,uploadUUID);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::createJsonKeyForFiles(Ljava/lang/String;)(uploadUUID);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::updateJsonKeys(Ljava/lang/String;)(uploadUUID);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::setCurrentJsonKeValue(Ljava/lang/String;)(uploadUUID);
@ -657,10 +661,9 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
var numFolder = 0;
for (var i = 0; i < files.length; i++) {
var file = files[i];
var fileSelected = files[i].name + fileDelimiter;
if (!isFolder(file)) {
console.log("fileSelected: " + fileSelected);
console.log("files: " + files);
console.log("fileSelected: " + file.name);
//console.log("files: " + files);
formdata.append("isOverwrite", true);
formdata.append('uploadFormElement', file);
}else{
@ -668,6 +671,7 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
}
}
xhr.send(formdata);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::addNewSubmitToMonitor(Ljava/lang/String;)(uploadUUID);
@ -686,6 +690,8 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::showAlert(Ljava/lang/String;)(msg);
}
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::reset()();
});
// Tells the browser that we *can* drop on this target
// addEventHandler(drop, 'dragover', cancel);

View File

@ -34,6 +34,7 @@ import org.apache.commons.fileupload.util.Streams;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.Validate;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.common.portal.PortalContext;
import org.gcube.common.storagehub.model.items.FolderItem;
import org.gcube.common.storagehub.model.items.Item;
@ -49,6 +50,7 @@ import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUpl
import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploader;
import org.gcube.portlets.widgets.workspaceuploader.server.notification.NotificationsWorkspaceUploaderProducer;
import org.gcube.portlets.widgets.workspaceuploader.server.upload.AbstractUploadProgressListener;
import org.gcube.portlets.widgets.workspaceuploader.server.upload.UploadItemProperties;
import org.gcube.portlets.widgets.workspaceuploader.server.upload.MemoryUploadListener;
import org.gcube.portlets.widgets.workspaceuploader.server.upload.UploadCanceledException;
import org.gcube.portlets.widgets.workspaceuploader.server.upload.UploadProgressInputStream;
@ -67,12 +69,10 @@ import org.json.JSONTokener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class WorkspaceUploadServletStream.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 10, 2016
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it May 10, 2016
*/
public class WorkspaceUploadServletStream extends HttpServlet implements Servlet {
@ -85,7 +85,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
public static final String VRE_ID_ATTR_NAME = "gcube-vreid";
public static final String CURR_GROUP_ID = ConstantsWorkspaceUploader.CURR_GROUP_ID;
//public static final String CURR_USER_ID = ConstantsWorkspaceUploader.CURR_USER_ID;
// public static final String CURR_USER_ID =
// ConstantsWorkspaceUploader.CURR_USER_ID;
public static final String UPLOAD_TYPE = ConstantsWorkspaceUploader.UPLOAD_TYPE;
@ -105,7 +106,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
public static final String ARCHIVE = "Archive";
public static final Map<String, String> SUPPORTED_UNPACKING_ARCHIVE = new HashMap<String, String>() {{
public static final Map<String, String> SUPPORTED_UNPACKING_ARCHIVE = new HashMap<String, String>() {
{
put("zip", "application/zip"); // .zip
put("7z", "application/x-7z-compressed"); // .7z
put("tar", "application/x-tar"); // tar
@ -113,12 +115,18 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
put("jar", "application/x-java-archive");
put("gtar", "application/x-gtar");
put("x-zip", "application/x-zip-compressed");
}};
}
};
public static Logger logger = LoggerFactory.getLogger(WorkspaceUploadServletStream.class);
private static boolean appEngine = false;
/**
* Inits the.
*
* @throws ServletException the servlet exception
*/
/*
* (non-Javadoc)
*
@ -163,9 +171,9 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
// }catch (Exception e) {
// logger.warn("An error occurred during removing cancelled upload from session ");
// }
}
else
sendWarnMessage(response, "Upload aborted for id: "+clientUploadKey +" has skipped, already aborted or completed?");
} else
sendWarnMessage(response,
"Upload aborted for id: " + clientUploadKey + " has skipped, already aborted or completed?");
} else
logger.debug(CANCEL_UPLOAD + " param not found");
return;
@ -177,7 +185,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
logger.info("POST on UploadServlet");
boolean requestIsNull = request == null;
logger.trace("[1] HttpServletRequest is: null? "+requestIsNull+", URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
logger.trace("[1] HttpServletRequest is: null? " + requestIsNull + ", URI: " + request.getRequestURI()
+ ", ServerName: " + request.getServerName());
if (!ServletFileUpload.isMultipartContent(request)) {
logger.error("ERROR: multipart request not found");
@ -192,7 +201,6 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
logger.info("UPLOAD-SERVLET session: " + session);
logger.debug("UPLOAD-SERVLET (" + session.getId() + ") new upload request received.");
if (WsUtil.isSessionExpired(request)) {
logger.error("SESSION_EXPIRED: session is expired");
sendSessionExpired(response, "SESSION_EXPIRED: session is expired");
@ -210,9 +218,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
/**
* An iterator to instances of <code>FileItemStream</code>
* parsed from the request, in the order that they were
*transmitted.
* An iterator to instances of <code>FileItemStream</code> parsed from the
* request, in the order that they were transmitted.
*/
FileItemIterator fileItemIterator = servletFileUpload.getItemIterator(request);
@ -244,21 +251,28 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
if (item.isFormField() && CLIENT_UPLOAD_KEYS.equals(item.getFieldName())) {
String jsonClientUploadKey = Streams.asString(item.openStream());
logger.debug("CLIENT_UPLOAD_KEY OK " + jsonClientUploadKey);
LinkedHashMap<String, String> mapKeys = parseJSONClientUploadKeys(jsonClientUploadKey);
listClientUploadKeys = new ArrayList<String>(mapKeys.keySet());
LinkedHashMap<String, UploadItemProperties> theMapOfUploadingFiles = parseJSONClientMapUploadPropertyFiles(
jsonClientUploadKey);
listClientUploadKeys = new ArrayList<String>(theMapOfUploadingFiles.keySet());
removeListenersIfDone(session, listClientUploadKeys);
for (String clientUploadKey : listClientUploadKeys) {
String fileName = mapKeys.get(clientUploadKey);
WorkspaceUploaderItem workspaceUploader = createNewWorkspaceUploader(clientUploadKey,destinationId,mapKeys.get(clientUploadKey),isOverwrite);
UploadItemProperties uip = theMapOfUploadingFiles.get(clientUploadKey);
String filename = uip.getFilename();
Long filesize = uip.getFilesize();
WorkspaceUploaderItem workspaceUploader = createNewWorkspaceUploader(clientUploadKey,
destinationId, filename, filesize, isOverwrite);
logger.debug("created " + workspaceUploader);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.WAIT, "Uploading "+fileName+" at 0%", request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.WAIT,
"Uploading " + filename + " at 0%", request.getSession());
}
}
if (item.isFormField() && CURR_GROUP_ID.equals(item.getFieldName())) {
scopeGroupId = Streams.asString(item.openStream());
logger.debug("currentGroupId passed as parameter = " + scopeGroupId);
logger.debug("currentGroupId into PortalContext scope= " + PortalContext.getConfiguration().getCurrentScope(scopeGroupId));
logger.debug("currentGroupId into PortalContext scope= "
+ PortalContext.getConfiguration().getCurrentScope(scopeGroupId));
}
// if (item.isFormField() && CURR_USER_ID.equals(item.getFieldName())){
@ -272,7 +286,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
uploadItem = item;
logger.debug("UPLOAD_FORM_ELEMENT OK " + uploadItem.getName() + " scopeGroupId=" + scopeGroupId);
// break;
uploadData(user, scopeGroupId, request, response, uploadItem, destinationId, uploadType, listClientUploadKeys.get(uploadItemsCnt), isOverwrite);
uploadData(user, scopeGroupId, request, response, uploadItem, destinationId, uploadType,
listClientUploadKeys.get(uploadItemsCnt), isOverwrite);
uploadItemsCnt++;
}
}
@ -288,6 +303,14 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
}
}
/**
* Coy stream to file.
*
* @param in the in
* @param fileExtension the file extension
* @return the file
* @throws IOException Signals that an I/O exception has occurred.
*/
public File coyStreamToFile(InputStream in, String fileExtension) throws IOException {
File tempFile = File.createTempFile(UUID.randomUUID().toString(), fileExtension);
tempFile.deleteOnExit();
@ -296,27 +319,6 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
return tempFile;
}
// public static InputStream clone(final InputStream inputStream) {
// try {
// inputStream.mark(0);
// ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// byte[] buffer = new byte[1024];
// int readLength = 0;
// while ((readLength = inputStream.read(buffer)) != -1) {
// outputStream.write(buffer, 0, readLength);
// }
// inputStream.reset();
// outputStream.flush();
// return new ByteArrayInputStream(outputStream.toByteArray());
// }
// catch (Exception ex) {
// ex.printStackTrace();
// }
// return null;
// }
/**
* Removes the listener if done.
*
@ -348,7 +350,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @throws FileUploadException the file upload exception
*/
@SuppressWarnings("rawtypes")
private static LinkedHashMap<String, String> parseJSONClientUploadKeys(final String jsonClientUploadKeys) throws FileUploadException{
private static LinkedHashMap<String, String> parseJSONClientUploadKeys(final String jsonClientUploadKeys)
throws FileUploadException {
JSONTokener tokener = new JSONTokener(jsonClientUploadKeys);
JSONObject root;
LinkedHashMap<String, String> keyFiles = null;
@ -376,6 +379,54 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
return keyFiles;
}
/**
* Parses the JSON client map upload property files.
*
* @param jsonClientUploadKeys the json client upload keys
* @return the linked hash map
* @throws FileUploadException the file upload exception
*/
@SuppressWarnings("rawtypes")
private static LinkedHashMap<String, UploadItemProperties> parseJSONClientMapUploadPropertyFiles(
final String jsonClientUploadKeys) throws FileUploadException {
JSONTokener tokener = new JSONTokener(jsonClientUploadKeys);
JSONObject root;
LinkedHashMap<String, UploadItemProperties> keyFiles = null;
ObjectMapper objectMapper = new ObjectMapper();
try {
root = new JSONObject(tokener);
JSONArray jsonArray = root.getJSONArray(JSON_CLIENT_KEYS);
keyFiles = new LinkedHashMap<String, UploadItemProperties>(jsonArray.length());
logger.debug("jsonArray :" + jsonArray.toString());
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
logger.debug("object :" + object);
String key = (String) object.keys().next();
JSONObject value = object.getJSONObject(key);
String valueToString = value.toString();
logger.debug("cast object to string for mapping upload properties:" + valueToString);
UploadItemProperties uploadRequest;
try {
uploadRequest = objectMapper.readValue(valueToString, UploadItemProperties.class);
logger.debug("key :" + key + ", value: " + uploadRequest);
keyFiles.put(key, uploadRequest);
} catch (IOException e) {
String theError = "Serialization issue on: " + key;
logger.error(theError, e);
throw new JSONException(theError);
}
}
} catch (JSONException e) {
logger.error("An error occurred during parsing file names: " + keyFiles, e);
throw new FileUploadException("An error occurred during parsing file names");
}
logger.debug("keyFiles: " + keyFiles);
return keyFiles;
}
/**
* Upload data.
@ -392,10 +443,14 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @throws ServletException the servlet exception
* @throws IOException Signals that an I/O exception has occurred.
*/
private void uploadData(GCubeUser user, String scopeGroupId, HttpServletRequest request, final HttpServletResponse response, final FileItemStream uploadItem, String destinationId,String uploadType,String clientUploadKey, boolean isOverwrite) throws ServletException, IOException{
private void uploadData(GCubeUser user, String scopeGroupId, HttpServletRequest request,
final HttpServletResponse response, final FileItemStream uploadItem, String destinationId,
String uploadType, String clientUploadKey, boolean isOverwrite) throws ServletException, IOException {
String fileName = uploadItem.getName();
logger.info("Upload servlet parameters: [fileName: "+fileName+ ", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+", clientUploadKey: "+clientUploadKey+"]");
logger.info("Upload servlet parameters: [fileName: " + fileName + ", destinationId: " + destinationId
+ ", uploadType: " + uploadType + ", isOverwrite: " + isOverwrite + ", clientUploadKey: "
+ clientUploadKey + "]");
if (uploadType == null || uploadType.isEmpty()) {
logger.error("Error processing request in upload servlet for: " + fileName + ". No upload type found");
@ -404,7 +459,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
}
if (clientUploadKey == null || clientUploadKey.isEmpty()) {
logger.error("Error processing request in upload servlet for: "+fileName+". No client upload key found");
logger.error(
"Error processing request in upload servlet for: " + fileName + ". No client upload key found");
sendError(response, "Internal error: No client upload key found");
return;
}
@ -421,8 +477,11 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
workspaceUploader.setIsOverwrite(isOverwrite); // SET IS OVERWRITE
} catch (Exception e) {
logger.error("Error during workspace uploader retrieving", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". Error processing request in upload servlet", request.getSession());
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error processing request in upload servlet");
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED,
"An error occurred during upload: " + fileName + ". Error processing request in upload servlet",
request.getSession());
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Error processing request in upload servlet");
return;
}
@ -436,14 +495,18 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
storageHubWrapper = WsUtil.getStorageHubWrapper(request, scopeGroupId, user);
} catch (Exception e) {
logger.error("Error during workspace retrieving", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". Error processing request in upload servlet", request.getSession());
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error processing request in upload servlet");
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED,
"An error occurred during upload: " + fileName + ". Error processing request in upload servlet",
request.getSession());
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Error processing request in upload servlet");
return;
}
if (storageHubWrapper == null) {
logger.error("Now workspace found in session");
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". No workspace in session", request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED,
"An error occurred during upload: " + fileName + ". No workspace in session", request.getSession());
sendError(response, "Internal error: No workspace retrieved");
return;
}
@ -456,19 +519,24 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
destinationItem = workspace.getItem(destinationId);
} catch (ItemNotFoundException | InternalErrorException e) {
logger.error("Error, no destination folder found", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". No destination folder found", request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED,
"An error occurred during upload: " + fileName + ". No destination folder found",
request.getSession());
sendError(response, "Internal error: No destination folder found");
return;
} catch (Exception e) {
logger.error("Error, no destination folder found", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName, request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED,
"An error occurred during upload: " + fileName, request.getSession());
sendError(response, "Internal error: No destination folder found");
return;
}
if (!destinationItem.isFolder()) {
logger.error("Error processing request in upload servlet: The destination is not a folder");
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". The destination is not a folder", request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED,
"An error occurred during upload: " + fileName + ". The destination is not a folder",
request.getSession());
sendError(response, "Internal error: Wrong destination item. The destination is not a folder");
return;
}
@ -483,7 +551,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
String notAuthorizedError = "The user cannot write in the folder with id: " + destinationFolder.getId();
String folderName = destinationFolder.getName();
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
workspaceUploader.setStatusDescription("You have not permission to upload in the folder: "+folderName);
workspaceUploader
.setStatusDescription("You have not permission to upload in the folder: " + folderName);
logger.info(notAuthorizedError);
try {
WsUtil.putWorkspaceUploaderInSession(request.getSession(), workspaceUploader);
@ -512,20 +581,39 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
itemName = baseName + extension;
logger.debug("purged item name is: " + itemName);
//SIZE
Long size = getContentLength(request);
logger.debug("size: " + size + " bytes");
// HttpServletRequest size
long requestContentLenght = getContentLength(request);
logger.info("HttpServletRequest " + FileUploadBase.CONTENT_LENGTH + "/size is: " + requestContentLenght);
Long fileSize = workspaceUploader.getFile().getFileSize();
/*
* FileItemHeaders itemHeaders = uploadItem.getHeaders(); if (itemHeaders !=
* null) { Iterator<String> headerNames =
* uploadItem.getHeaders().getHeaderNames(); while(headerNames.hasNext()) {
* String headerName = headerNames.next(); logger.info("headerName: "+headerName
* +" value: "+itemHeaders.getHeader(headerName)); }
*
* String contentLength = itemHeaders.getHeader(FileUploadBase.CONTENT_LENGTH);
* if (contentLength != null) { try { fileSize = Long.parseLong(contentLength);
* } catch (Exception e) { logger.warn("Error on getting fileSize", e); } } }
*/
logger.info("File size is: " + fileSize);
if (fileSize == null)
fileSize = requestContentLenght;
// CONFIRM DESTINATION FOLDER
workspaceUploader.getFile().setParentId(destinationFolder.getId());
// Instancing the progress listener
final AbstractUploadProgressListener uploadProgressListener = createNewListener(request.getSession(), clientUploadKey);
final UploadProgressInputStream inputStream = new UploadProgressInputStream(uploadItem.openStream(), size);
final AbstractUploadProgressListener uploadProgressListener = createNewListener(request.getSession(),
clientUploadKey);
final UploadProgressInputStream inputStream = new UploadProgressInputStream(uploadItem.openStream(),
requestContentLenght);
inputStream.addListener(uploadProgressListener);
workspaceUploader.setUploadProgress(uploadProgressListener.getUploadProgress());
// Commented this. FIXING ISSUE #19232
// try {
// //USING isOverwrite to check if the file already exists
@ -542,7 +630,6 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
String contentType = uploadItem.getContentType();
logger.debug("Stream content type: " + contentType);
if (uploadType.compareTo(ARCHIVE) == 0) {
// UPLOAD ARCHIVE
@ -551,7 +638,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
for (String archive_extension : SUPPORTED_UNPACKING_ARCHIVE.keySet()) {
// is content-type supported?
if(SUPPORTED_UNPACKING_ARCHIVE.get(archive_extension).compareTo(uploadItem.getContentType())==0){
if (SUPPORTED_UNPACKING_ARCHIVE.get(archive_extension)
.compareTo(uploadItem.getContentType()) == 0) {
isSupportedArchive = true;
break;
}
@ -560,22 +648,26 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
if (isSupportedArchive) { // Uploading Archive OK
logger.debug("Supported archive " + uploadItem.getContentType() + " for unpacking");
//USING the baseName instead of itemName in oder to avoid adding extension as suffix
workspaceUploader = WorkspaceUploaderMng.uploadArchive(storageHubWrapper, user, scopeGroupId, workspaceUploader, request, baseName, inputStream, destinationFolder, size);
// USING the baseName instead of itemName in oder to avoid adding extension as
// suffix
workspaceUploader = WorkspaceUploaderMng.uploadArchive(storageHubWrapper, user, scopeGroupId,
workspaceUploader, request, baseName, inputStream, destinationFolder, fileSize);
if (workspaceUploader == null)
throw new Exception("Error when creating uploader, it is null!");
/*
* Incident #10095. Commented OK as response
* in order to avoid downloading of .dms file by Safari
* from MAC
* Incident #10095. Commented OK as response in order to avoid downloading of
* .dms file by Safari from MAC
*/
// sendMessage(response, workspaceUploader.getIdentifier());
} else {
logger.warn("Unsuppoterd archive for unpacking: " + uploadItem.getContentType());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.ABORTED, "Unpacking not supported for: "+uploadItem.getContentType()+" Supported archive are: "+SUPPORTED_UNPACKING_ARCHIVE.keySet().toString(), request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.ABORTED,
"Unpacking not supported for: " + uploadItem.getContentType() + " Supported archive are: "
+ SUPPORTED_UNPACKING_ARCHIVE.keySet().toString(),
request.getSession());
sendError(response, "Internal error: Unpacking not supported for " + uploadItem.getContentType());
return;
}
@ -584,44 +676,50 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
// UPLOAD FILE. IT IS DEFAULT CASE
logger.debug("Uploding file....");
workspaceUploader = WorkspaceUploaderMng.uploadFile(storageHubWrapper, user, scopeGroupId, request, workspaceUploader, request.getSession(), itemName, inputStream, destinationFolder, contentType, isOverwrite, size);
workspaceUploader = WorkspaceUploaderMng.uploadFile(storageHubWrapper, user, scopeGroupId, request,
workspaceUploader, request.getSession(), itemName, inputStream, destinationFolder, contentType,
isOverwrite, fileSize);
if (workspaceUploader == null)
throw new Exception("Error when creating uploader, it is null!");
/*
* Incident #10095. Commented OK as response
* in order to avoid downloading of .dms file by Safari
* from MAC
* Incident #10095. Commented OK as response in order to avoid downloading of
* .dms file by Safari from MAC
*/
// sendMessage(response, workspaceUploader.getIdentifier());
}
} catch (InsufficientPrivilegesException e) {
logger.error("Error creating elements", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "Uploading error. Insufficient privileges", request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED,
"Uploading error. Insufficient privileges", request.getSession());
sendError(response, "Internal error: Insufficient privileges");
return;
} catch (InternalErrorException e) {
logger.error("Error creating elements", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "Uploading error:"+e.getMessage(), request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "Uploading error:" + e.getMessage(),
request.getSession());
sendError(response, "Internal error: " + e.getMessage());
return;
} catch (ItemAlreadyExistException e) {
logger.error("Error creating elements", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "Uploading error. An item with that name already exists", request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED,
"Uploading error. An item with that name already exists", request.getSession());
sendError(response, "Internal error: An item with that name already exists");
return;
} catch (IOException e) {
logger.error("Error creating elements, is it cancel?", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "Uploading error", request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "Uploading error",
request.getSession());
sendError(response, "Internal error: An item with that name already exists");
return;
// sendError(response, "Internal error: An item with that name already exists");
// return;
} catch (Exception e) {
logger.error("Error creating elements", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "Uploading error. "+e.getMessage(), request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "Uploading error. " + e.getMessage(),
request.getSession());
// sendError(response, "Internal error: An error occurred on uploading the file, try again later");
// return;
} finally {
@ -629,7 +727,6 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
}
}
/**
* Save workspace uploader status.
*
@ -639,7 +736,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @param session the session
* @return the workspace uploader item
*/
private synchronized WorkspaceUploaderItem saveWorkspaceUploaderStatus(WorkspaceUploaderItem workspaceUploader, UPLOAD_STATUS status, String description, HttpSession session){
private synchronized WorkspaceUploaderItem saveWorkspaceUploaderStatus(WorkspaceUploaderItem workspaceUploader,
UPLOAD_STATUS status, String description, HttpSession session) {
workspaceUploader.setUploadStatus(status);
workspaceUploader.setStatusDescription(description);
try {
@ -650,22 +748,25 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
return workspaceUploader;
}
/**
* Creates the new workspace uploader.
*
* @param clientUploadKey the client upload key
* @param folderParentId the folder parent id
* @param fileName the file name
* @param filesize
* @param isOverwrite the is overwrite
* @return the workspace uploader item
*/
private WorkspaceUploaderItem createNewWorkspaceUploader(String clientUploadKey, String folderParentId, String fileName, boolean isOverwrite){
private WorkspaceUploaderItem createNewWorkspaceUploader(String clientUploadKey, String folderParentId,
String fileName, Long filesize, boolean isOverwrite) {
// CLIENT UPLOAD IS THE KEY
WorkspaceUploaderItem workspaceUploader = new WorkspaceUploaderItem(clientUploadKey);
workspaceUploader.setClientUploadKey(clientUploadKey);
// Create File
WorkspaceUploadFile wsUploadFile = new WorkspaceUploadFile(folderParentId, null, fileName, null);
wsUploadFile.setFileSize(filesize);
workspaceUploader.setFile(wsUploadFile);
workspaceUploader.setIsOverwrite(isOverwrite);
return workspaceUploader;
@ -689,13 +790,16 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @return the workspace uploader item
* @throws Exception the exception
*/
public static void saveWorkspaceUploaderInSession(WorkspaceUploaderItem workspaceUploader, HttpSession httpSession) throws Exception {
public static void saveWorkspaceUploaderInSession(WorkspaceUploaderItem workspaceUploader, HttpSession httpSession)
throws Exception {
if (workspaceUploader != null) {
try {
WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
} catch (Exception e) {
logger.error("Error during WorkspaceUploaderItem save in session workspace uploader: "+workspaceUploader,e);
logger.error(
"Error during WorkspaceUploaderItem save in session workspace uploader: " + workspaceUploader,
e);
throw new Exception("An error occurred in the upload. Try again");
}
} else
@ -713,6 +817,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
logger.debug("Start time: " + startTime);
return startTime;
}
// TEST TIME
/**
* Prints the elapsed time.
@ -725,7 +830,6 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
logger.debug("Elapsed Time: " + time);
}
/**
* Notify upload in shared folder.
*
@ -734,14 +838,17 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @param scopeGroupId the scope group id
* @param request the request
* @param httpSession the http session
* @param workspace the workspace
* @param itemId the item id
* @param destinationFolderId the destination folder id
* @param isOverwrite the is overwrite
*/
public static void notifyUploadInSharedFolder(final StorageHubWrapper storageWrapper, final GCubeUser currUser, final String scopeGroupId, final HttpServletRequest request, final HttpSession httpSession, final String itemId, final String destinationFolderId, final boolean isOverwrite){
logger.trace("[2] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
final NotificationsWorkspaceUploaderProducer np = new NotificationsWorkspaceUploaderProducer(scopeGroupId, httpSession,request);
public static void notifyUploadInSharedFolder(final StorageHubWrapper storageWrapper, final GCubeUser currUser,
final String scopeGroupId, final HttpServletRequest request, final HttpSession httpSession,
final String itemId, final String destinationFolderId, final boolean isOverwrite) {
logger.trace("[2] HttpServletRequest is: URI: " + request.getRequestURI() + ", ServerName: "
+ request.getServerName());
final NotificationsWorkspaceUploaderProducer np = new NotificationsWorkspaceUploaderProducer(scopeGroupId,
httpSession, request);
new Thread() {
public void run() {
// Item sourceItem;
@ -753,7 +860,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
} catch (Exception e) {
// silent
}
Item folderDestinationItem = storageWrapper.getStorageHubClientService().getItem(destinationFolderId);
Item folderDestinationItem = storageWrapper.getStorageHubClientService()
.getItem(destinationFolderId);
FolderItem folderDestination = null;
if (folderDestinationItem instanceof FolderItem) {
folderDestination = (FolderItem) folderDestinationItem;
@ -761,8 +869,10 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
Validate.notNull(folderDestination, "The folder destionation is null");
logger.trace("[3] HttpServletRequest is: URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(storageWrapper, request, currUser, scopeGroupId, np, httpSession, sourceItem, sourceSharedId, folderDestination);
logger.trace("[3] HttpServletRequest is: URI: " + request.getRequestURI() + ", ServerName: "
+ request.getServerName());
NotificationsWorkspaceUploader.checkSendNotifyChangedItemToShare(storageWrapper, request, currUser,
scopeGroupId, np, httpSession, sourceItem, sourceSharedId, folderDestination);
} catch (Exception e) {
logger.error("Error in notifyUploadInSharedFolder", e);
@ -785,7 +895,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
HandlerResultMessage resultMessage = HandlerResultMessage.errorResult(message);
response.getWriter().write(resultMessage.toString());
// 5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// When a response is closed, the container must immediately flush all remaining
// content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e) {
logger.warn("IOException class name: " + e.getClass().getSimpleName());
@ -796,7 +907,6 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
}
}
/**
* Send session expired.
*
@ -810,7 +920,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
HandlerResultMessage resultMessage = HandlerResultMessage.sessionExpiredResult(message);
response.getWriter().write(resultMessage.toString());
// 5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// When a response is closed, the container must immediately flush all remaining
// content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e) {
logger.warn("IOException class name: " + e.getClass().getSimpleName());
@ -835,7 +946,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
HandlerResultMessage resultMessage = HandlerResultMessage.okResult(message);
response.getWriter().write(resultMessage.toString());
// 5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// When a response is closed, the container must immediately flush all remaining
// content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e) {
logger.warn("IOException class name: " + e.getClass().getSimpleName());
@ -859,7 +971,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
HandlerResultMessage resultMessage = HandlerResultMessage.warnResult(message);
response.getWriter().write(resultMessage.toString());
// 5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// When a response is closed, the container must immediately flush all remaining
// content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e) {
logger.warn("IOException class name: " + e.getClass().getSimpleName());
@ -906,8 +1019,8 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
}
/**
* Just a method to detect whether the web container is running with
* appengine restrictions.
* Just a method to detect whether the web container is running with appengine
* restrictions.
*
* @return true if the case of the application is running in appengine
*/
@ -930,7 +1043,6 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
}
}
/**
* Gets the content length.
*
@ -940,8 +1052,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
private long getContentLength(HttpServletRequest request) {
long size = -1;
try {
size = Long.parseLong(request
.getHeader(FileUploadBase.CONTENT_LENGTH));
size = Long.parseLong(request.getHeader(FileUploadBase.CONTENT_LENGTH));
} catch (NumberFormatException e) {
}
return size;

View File

@ -3,7 +3,6 @@
*/
package org.gcube.portlets.widgets.workspaceuploader.server.notification;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

View File

@ -0,0 +1,105 @@
package org.gcube.portlets.widgets.workspaceuploader.server.upload;
import java.io.Serializable;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
/**
* The Class UploadItemProperties.
*
* contains properties sent from client for any file uploaded
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Aug 1, 2024
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class UploadItemProperties implements Serializable {
/**
*
*/
private static final long serialVersionUID = -7226677146789586756L;
@JsonProperty(ConstantsWorkspaceUploader.CLIENT_UPLOAD_FILEOBJ_FILENAME)
private String filename;
@JsonProperty(ConstantsWorkspaceUploader.CLIENT_UPLOAD_FILEOBJ_FILESIZE)
private Long filesize;
/**
* Instantiates a new upload item properties.
*/
public UploadItemProperties() {
}
/**
* Instantiates a new upload item properties.
*
* @param filename the filename
* @param filesize the filesize
*/
public UploadItemProperties(String filename, Long filesize) {
super();
this.filename = filename;
this.filesize = filesize;
}
/**
* Gets the filename.
*
* @return the filename
*/
@JsonProperty(ConstantsWorkspaceUploader.CLIENT_UPLOAD_FILEOBJ_FILENAME)
public String getFilename() {
return filename;
}
/**
* Gets the filesize.
*
* @return the filesize
*/
@JsonProperty(ConstantsWorkspaceUploader.CLIENT_UPLOAD_FILEOBJ_FILESIZE)
public Long getFilesize() {
return filesize;
}
/**
* Sets the filename.
*
* @param filename the new filename
*/
public void setFilename(String filename) {
this.filename = filename;
}
/**
* Sets the filesize.
*
* @param filesize the new filesize
*/
public void setFilesize(Long filesize) {
this.filesize = filesize;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("UploadItemProperties [filename=");
builder.append(filename);
builder.append(", filesize=");
builder.append(filesize);
builder.append("]");
return builder.toString();
}
}

View File

@ -77,7 +77,8 @@ public class WorkspaceUploaderMng {
Long startTime = WorkspaceUploadServletStream.printStartTime();
//UPLOAD
createdItem = storageWrapper.getWorkspace().uploadFile(destinationFolder.getId(), uploadFile, itemName, "");
logger.info("calling upload file - [itemName: "+itemName+", totalBytes: "+totalBytes+"]");
createdItem = storageWrapper.getWorkspace().uploadFile(destinationFolder.getId(), uploadFile, itemName, "", totalBytes);
if(createdItem!=null){
WorkspaceUploadServletStream.printElapsedTime(startTime);
@ -199,13 +200,13 @@ public class WorkspaceUploaderMng {
*/
private static WorkspaceUploaderItem createWorkspaceUploaderArchive(StorageHubWrapper storageWrapper, final GCubeUser currUser, final String scopeGroupId, final WorkspaceUploaderItem workspaceUploader, final HttpServletRequest request, final InputStream uploadArchive, final String itemName, final WorkspaceFolder destinationFolder, final long totalBytes) throws InternalErrorException, IOException{
HttpSession httpSession = request.getSession();
logger.info("calling upload archive - [itemName: "+itemName+"]");
logger.info("calling upload archive - [itemName: "+itemName+", totalBytes: "+totalBytes+"]");
WorkspaceItem createdItem = null;
try {
workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS);
workspaceUploader.setStatusDescription("Uploading "+itemName);
createdItem = storageWrapper.getWorkspace().uploadArchive(destinationFolder.getId(), uploadArchive, itemName);
createdItem = storageWrapper.getWorkspace().uploadArchive(destinationFolder.getId(), uploadArchive, itemName, totalBytes);
if(createdItem!=null){
logger.debug("StorageHub"+createdItem.getName() + " with id: "+createdItem.getId() + " uploaded correctly in "+destinationFolder.getPath());

View File

@ -22,6 +22,7 @@ public class WorkspaceUploadFile implements Serializable{
private String fileName;
private String itemId;
private String versionName;
private Long fileSize;
/**
* Instantiates a new workspace upload file.
@ -129,6 +130,20 @@ public class WorkspaceUploadFile implements Serializable{
this.fileName = fileName;
}
public Long getFileSize() {
return fileSize;
}
public void setFileSize(Long fileSize) {
this.fileSize = fileSize;
}
/*
* (non-Javadoc)
*
@ -145,12 +160,8 @@ public class WorkspaceUploadFile implements Serializable{
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("WorkspaceUploadFile [parentId=");
builder.append(parentId);
@ -160,10 +171,10 @@ public class WorkspaceUploadFile implements Serializable{
builder.append(itemId);
builder.append(", versionName=");
builder.append(versionName);
builder.append(", fileSize=");
builder.append(fileSize);
builder.append("]");
return builder.toString();
}
}