updated pom version at 1.1.0
updated distro files

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@122155 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-01-08 11:32:48 +00:00
parent 91deff581b
commit 05e4751a71
9 changed files with 257 additions and 103 deletions

View File

@ -16,7 +16,7 @@ Authors
Version and Release Date
------------------------
v. 1.0.1 December 2015
v. 1.1.0 January 2016
Description

View File

@ -1,4 +1,8 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets-widgets.workspace-uploader.1-1-0"
date="2016-01-08">
<Change>Bug Fixed #1333</Change>
</Changeset>
<Changeset component="org.gcube.portlets-widgets.workspace-uploader.1-0-1"
date="2015-12-16">
<Change>Bug Fixed - https://support.d4science.org/issues/1824</Change>

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>workspace-uploader</artifactId>
<packaging>jar</packaging>
<version>1.0.1-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<name>Workspace Uploader Widget</name>
<scm>
<connection>scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/${project.artifactId}</connection>

View File

@ -17,6 +17,7 @@ public class ConstantsWorkspaceUploader {
public static final String WORKSPACE_UPLOADER_SERVICE = GWT.getModuleBaseURL() + "workspaceUploaderService";
public static final String WORKSPACE_UPLOADER_WS_UTIL = GWT.getModuleBaseURL() + "workspaceUploaderWsUtil";
public static final String SERVER_ERROR = "Sorry, an error has occurred on the server when";
public static final String TRY_AGAIN = "Try again";
@ -34,4 +35,8 @@ public class ConstantsWorkspaceUploader {
public static final String MY_UPLOADS = "My Uploads";
public static final int LIMIT_UPLOADS = 50;
public static final String FOLDER_PARENT_ID = "FOLDER_PARENT_ID";
public static final String ITEM_NAME = "ITEM_NAME";
}

View File

@ -36,9 +36,7 @@ public class WorkspaceUploader implements EntryPoint {
.setWindow(ScriptInjector.TOP_WINDOW)
.inject();
}
// ScriptInjector.fromUrl("http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js")
// .setWindow(ScriptInjector.TOP_WINDOW)
// .inject();
@ -69,18 +67,6 @@ public class WorkspaceUploader implements EntryPoint {
}
});
// buttonUploader.addClickHandler(new ClickHandler() {
//
// @Override
// public void onClick(ClickEvent event) {
// DialogUpload uploader = new DialogUpload(headerTitle, parentId, UPLOAD_TYPE.File);
// uploader.center();
// }
// });
buttonDirect.addClickHandler(new ClickHandler() {
@Override
@ -107,19 +93,6 @@ public class WorkspaceUploader implements EntryPoint {
});
RootPanel.get("workspace-uploader").add(dnd);
// Scheduler.get().scheduleDeferred(new ScheduledCommand() {
//
// @Override
// public void execute() {
// dnd.initFileReader();
//
// }
// });
// RootPanel.get("workspace-uploader").add(buttonUploader);
RootPanel.get("workspace-uploader").add(buttonDirect);
}

View File

@ -36,6 +36,10 @@ public class MultipleDNDUpload extends LayoutPanel implements
// private String jsonKeys;
private String servlet = ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM;
private String service = ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVICE;
private String workspaceUtil = ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_WS_UTIL;
private String folder_parent_id = ConstantsWorkspaceUploader.FOLDER_PARENT_ID;
private String item_name = ConstantsWorkspaceUploader.ITEM_NAME;
public static final String FILE_DELEMITER = ";";
private Widget onlyChild;
@ -303,6 +307,20 @@ public class MultipleDNDUpload extends LayoutPanel implements
String fileDelimiter) /*-{
console.log("initW3CFileReader");
function makeSyncAjaxCall(url, params, msgText, conType){
var xhReq = new XMLHttpRequest();
xhReq.open(conType, url+"?"+params, false);
if (conType == "POST")
xhReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhReq.send(msgText);
if(xhReq.status==200){
console.log(xhReq.responseText);
return xhReq.responseText;
}else
return null;
}
function generateUUID() {
var d = new Date().getTime();
@ -511,75 +529,76 @@ public class MultipleDNDUpload extends LayoutPanel implements
var file = files[i];
var filesSelected = files[i].name + fileDelimiter;
if (!isFolder(file)) {
console.log("filesSelected: " + filesSelected);
// var files = filese
// var files = filesSelected.split(fileDelimiter);
console.log("files: " + files);
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::createJsonKeyForFiles(Ljava/lang/String;)(uploadUUID);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::updateJsonKeys(Ljava/lang/String;)(uploadUUID);
var jsonKeysMap = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::jsonKeys;
console.log("jsonKeysMap: " + jsonKeysMap);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::setCurrentJsonKeValue(Ljava/lang/String;)(uploadUUID);
var keyVal = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::currentJsonKey;
console.log("keyVal: " + keyVal);
var xhr = new XMLHttpRequest();
// var upload = xhr.upload;
// upload.fileIndex = i;
// upload.fileObj = file;
// upload.downloadStartTime = new Date().getTime();
// upload.currentStart = upload.downloadStartTime;
// upload.currentProgress = 0;
// upload.startData = 0;
// console.log("upload: " + upload.toString());
// add listeners
// upload.addEventListener("progress", progress, false);
// upload.addEventListener("load", load, false);
xhr.open(opts.type, opts.url, true);
// var boundary = "AJAX--------------" + (new Date).getTime();
// var contentType = "multipart/form-data; boundary=" + boundary;
// xhr.setRequestHeader("Content-Type", contentType);
// Use native function(Chrome 5+ ,Safari 5+ and Firefox 4+), for dealing
// with multipart/form-data and boundray generation
var formdata = new FormData(); // see
// https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Using_FormData_objects
// 'file' can be any string which you would like to associte with
// uploaded file even for example file.type eg:
// formdata.append(file.type, file);
// formdata.append(file.fileName, file);
formdata.append("isOverwrite", "false");
// $wnd.exportCreateJsonKeyForFiles();
//
// $wnd.exportAddNewSubmitToMonitor();
formdata.append("client_upload_keys", keyVal);
formdata.append("uploadType", uploadType);
formdata.append("idFolder", idfolder);
formdata.append('uploadFormElement', file);
xhr.send(formdata);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::addNewSubmitToMonitor(Ljava/lang/String;)(uploadUUID);
// reader.readAsText(file);
console.log("filesSelected: " + filesSelected);
console.log("files: " + files);
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::createJsonKeyForFiles(Ljava/lang/String;)(uploadUUID);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::updateJsonKeys(Ljava/lang/String;)(uploadUUID);
var jsonKeysMap = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::jsonKeys;
console.log("jsonKeysMap: " + jsonKeysMap);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::setCurrentJsonKeValue(Ljava/lang/String;)(uploadUUID);
var keyVal = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::currentJsonKey;
console.log("keyVal: " + keyVal);
var xhr = new XMLHttpRequest();
// var upload = xhr.upload;
// upload.fileIndex = i;
// upload.fileObj = file;
// upload.downloadStartTime = new Date().getTime();
// upload.currentStart = upload.downloadStartTime;
// upload.currentProgress = 0;
// upload.startData = 0;
// console.log("upload: " + upload.toString());
// add listeners
// upload.addEventListener("progress", progress, false);
// upload.addEventListener("load", load, false);
xhr.open(opts.type, opts.url, true);
// var boundary = "AJAX--------------" + (new Date).getTime();
// var contentType = "multipart/form-data; boundary=" + boundary;
// xhr.setRequestHeader("Content-Type", contentType);
// Use native function(Chrome 5+ ,Safari 5+ and Firefox 4+), for dealing
// with multipart/form-data and boundray generation
var formdata = new FormData();
formdata.append("client_upload_keys", keyVal);
formdata.append("uploadType", uploadType);
formdata.append("idFolder", idfolder);
//OVERWRITE??
var overwrite = false;
if(files.length == 1){
console.log("one drag, overwrite?");
var wsUtil = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::workspaceUtil;
var folder_parent_id = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::folder_parent_id;
var item_name = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::item_name;
console.log("item_name: " + item_name);
var params = folder_parent_id+"="+idfolder+"&"+item_name+"="+files[i].name
console.log("params: " + params);
var response = makeSyncAjaxCall(wsUtil, params, "", "GET");
console.log("response: " + response);
if(response!=null && response!=undefined){
console.log("overwrite confirm?");
if($wnd.confirm(files[i].name+" exists in folder. Overwrite?")){
overwrite = true;
console.log("overwrite confirmed!");
}else{
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::reset()();
return;
}
}
}
formdata.append("isOverwrite", overwrite);
//*********uploadFormElement MUST BE THE LAST!!!
formdata.append('uploadFormElement', file);
xhr.send(formdata);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::addNewSubmitToMonitor(Ljava/lang/String;)(uploadUUID);
// reader.readAsText(file);
}else{
numFolder++;
}
@ -608,8 +627,13 @@ public class MultipleDNDUpload extends LayoutPanel implements
$wnd.$('#drop_target')[0].innerHTML = 'Your browser does not support the HTML5 FileReader.';
}
}-*/;
/**
* Test.
*
* @param parentIdentifier the parent identifier
* @param name the name
*/
public static native void test(String parentIdentifier, String name)/*-{
var servlet = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::service;

View File

@ -212,7 +212,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
removeListenersIfDone(session, listClientUploadKeys);
for (String clientUploadKey : listClientUploadKeys) {
String fileName = mapKeys.get(clientUploadKey);
WorkspaceUploaderItem workspaceUploader = createNewWorkspaceUploader(clientUploadKey,destinationId,mapKeys.get(clientUploadKey));
WorkspaceUploaderItem workspaceUploader = createNewWorkspaceUploader(clientUploadKey,destinationId,mapKeys.get(clientUploadKey),isOverwrite);
logger.debug("created "+workspaceUploader);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.WAIT, "Uploading "+fileName+" at 0%", request.getSession());
}
@ -544,13 +544,14 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @param fileName the file name
* @return the workspace uploader item
*/
private WorkspaceUploaderItem createNewWorkspaceUploader(String clientUploadKey, String folderParentId, String fileName){
private WorkspaceUploaderItem createNewWorkspaceUploader(String clientUploadKey, String folderParentId, String fileName, boolean isOverwrite){
//CLIENT UPLOAD IS THE KEY
WorkspaceUploaderItem workspaceUploader = new WorkspaceUploaderItem(clientUploadKey);
workspaceUploader.setClientUploadKey(clientUploadKey);
//Create File
WorkspaceUploadFile wsUploadFile = new WorkspaceUploadFile(folderParentId, null, fileName);
workspaceUploader.setFile(wsUploadFile);
workspaceUploader.setIsOverwrite(isOverwrite);
return workspaceUploader;
}

View File

@ -0,0 +1,137 @@
package org.gcube.portlets.widgets.workspaceuploader.server;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.gcube.common.homelibary.model.items.type.WorkspaceItemType;
import org.gcube.common.homelibrary.home.workspace.Workspace;
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
import org.gcube.portlets.widgets.workspaceuploader.server.util.WsUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The server side implementation of the RPC service.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jan 7, 2016
*/
@SuppressWarnings("serial")
public class WorkspaceUploaderWsUtil extends HttpServlet {
public static Logger logger = LoggerFactory.getLogger(WorkspaceUploaderWsUtil.class);
/* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String folderParentId = req.getParameter(ConstantsWorkspaceUploader.FOLDER_PARENT_ID);
String itemName = req.getParameter(ConstantsWorkspaceUploader.ITEM_NAME);
logger.debug("folderParentId: "+folderParentId);
logger.debug("itemName: "+itemName);
try {
String itemId = itemExistsInWorkpaceFolder(req, folderParentId, itemName);
sendOKMessage(resp, itemId);
}
catch (Exception e) {
logger.error("An error occurred during item exists check",e);
sendError(resp, "An error occurred during item exists check");
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#itemExistsInWorkpaceFolder(java.lang.String, java.lang.String)
*/
//@Override
/**
* Item exists in workpace folder.
*
* @param req the req
* @param parentId the parent id
* @param itemName the item name
* @return the string
* @throws Exception the exception
*/
public String itemExistsInWorkpaceFolder(HttpServletRequest req, String parentId, String itemName) throws Exception {
logger.trace("get itemExistsInWorkpace for name: "+itemName+", by parentId: "+parentId);
try {
HttpSession session = req.getSession();
Workspace workspace = WsUtil.getWorkspace(session);
WorkspaceItem wsItem = workspace.getItem(parentId); //GET PARENT
if(wsItem.getType().equals(WorkspaceItemType.FOLDER) || wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
WorkspaceItem itemFound = workspace.find(itemName, parentId);
if(itemFound==null){
logger.trace("item: "+itemName+", not exists in parentId: "+parentId);
return null;
}
logger.trace("item: "+itemName+", exists in parentId: "+parentId +", returning id:" +itemFound.getId());
return itemFound.getId();
}
else
throw new Exception("Invalid Folder parent");
} catch (Exception e) {
String error = "Sorry an error occurred when searching item id, please refresh and try again";
logger.error(error, e);
throw new Exception(e.getMessage());
}
}
/**
* Send error.
*
* @param response the response
* @param message the message
* @throws IOException Signals that an I/O exception has occurred.
*/
protected void sendError(HttpServletResponse response, String message) throws IOException{
try {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.getWriter().write(message);
//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
// response.flushBuffer();
} catch (IOException e){
logger.warn("IOException class name: "+e.getClass().getSimpleName());
if (e.getClass().getSimpleName().equals("ClientAbortException"))
logger.warn("Skipping ClientAbortException: "+e.getMessage());
else
throw e; //Sending Exceptions
}
}
/**
* Send message.
*
* @param response the response
* @param message the message
* @throws IOException Signals that an I/O exception has occurred.
*/
protected void sendOKMessage(HttpServletResponse response, String message) throws IOException{
try {
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write(message);
//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
// response.flushBuffer();
} catch (IOException e){
logger.warn("IOException class name: "+e.getClass().getSimpleName());
if (e.getClass().getSimpleName().equals("ClientAbortException"))
logger.warn("Skipping ClientAbortException: "+e.getMessage());
else
throw e; //Sending Exceptions
}
}
}

View File

@ -17,13 +17,18 @@
<servlet-class>org.gcube.portlets.widgets.workspaceuploader.server.WorkspaceUploadServlet</servlet-class>
</servlet>
<!-- Servlets -->
<servlet>
<servlet-name>workspaceUploadServletStream</servlet-name>
<servlet-class>org.gcube.portlets.widgets.workspaceuploader.server.WorkspaceUploadServletStream</servlet-class>
</servlet>
<!-- Servlets -->
<servlet>
<servlet-name>workspaceUploaderWsUtil</servlet-name>
<servlet-class>org.gcube.portlets.widgets.workspaceuploader.server.WorkspaceUploaderWsUtil</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>workspaceUploaderService</servlet-name>
<url-pattern>/workspaceuploader/workspaceUploaderService</url-pattern>
@ -39,6 +44,11 @@
<url-pattern>/workspaceuploader/workspaceUploadServletStream</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>workspaceUploaderWsUtil</servlet-name>
<url-pattern>/workspaceuploader/workspaceUploaderWsUtil</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>workspaceuploader.html</welcome-file>