4055: Workspace Uploder enhancement: work with multiple-instances of DnD Workspace Uploader in the DOM

Task-Url: https://support.d4science.org/issues/4055

ProgressListener and WorkspaceUploader removed after last read from client

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@128685 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-05-19 13:38:24 +00:00
parent c6bf3b0660
commit efea5d3c8f
10 changed files with 399 additions and 294 deletions

View File

@ -1,112 +1,112 @@
package org.gcube.portlets.widgets.workspaceuploader.client;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload;
import org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.ScriptInjector;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class WorkspaceUploader implements EntryPoint {
String headerTitle = "Upload in your Workspace";
String parentId;
private Button buttonUploader;
private Button buttonDirect;
public void onModuleLoad() {
boolean jQueryLoaded = isjQueryLoaded();
GWT.log("jQueryLoaded: "+jQueryLoaded);
GWT.log("Injected : http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js");
if (!jQueryLoaded) {
ScriptInjector.fromUrl("http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js")
.setWindow(ScriptInjector.TOP_WINDOW)
.inject();
}
//package org.gcube.portlets.widgets.workspaceuploader.client;
//
//import org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE;
//import org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload;
//import org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload;
//
//import com.google.gwt.core.client.EntryPoint;
//import com.google.gwt.core.client.ScriptInjector;
//import com.google.gwt.core.shared.GWT;
//import com.google.gwt.event.dom.client.ClickEvent;
//import com.google.gwt.event.dom.client.ClickHandler;
//import com.google.gwt.user.client.Window;
//import com.google.gwt.user.client.rpc.AsyncCallback;
//import com.google.gwt.user.client.ui.Button;
//import com.google.gwt.user.client.ui.RootPanel;
//
///**
// * Entry point classes define <code>onModuleLoad()</code>.
// */
//public class WorkspaceUploader implements EntryPoint {
//
// String headerTitle = "Upload in your Workspace";
// String parentId;
// private Button buttonUploader;
// private Button buttonDirect;
//
// public void onModuleLoad() {
//
// boolean jQueryLoaded = isjQueryLoaded();
// GWT.log("jQueryLoaded: "+jQueryLoaded);
//
// GWT.log("Injected : http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js");
//
// if (!jQueryLoaded) {
// ScriptInjector.fromUrl("http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js")
// .setWindow(ScriptInjector.TOP_WINDOW)
// .inject();
buttonUploader = new Button("Upload in your Workspace");
buttonDirect = new Button("Upload (Stream) in your Workspace");
enableUpload(false);
WorkspaceUploaderServiceAsync.Util.getInstance().getWorkspaceId(
new AsyncCallback<String>() {
@Override
public void onSuccess(String result) {
if (result != null) {
parentId = result;
enableUpload(true);
} else {
Window.alert("An error occurred on recovering workspace, try again later");
enableUpload(true);
}
}
@Override
public void onFailure(Throwable caught) {
Window.alert("An error occurred on recovering workspace, try again later");
enableUpload(true);
}
});
buttonDirect.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
MultipleDilaogUpload uploadStream = new MultipleDilaogUpload(headerTitle, parentId, org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE.File);
uploadStream.initFileReader();
uploadStream.center();
}
});
final MultipleDNDUpload dnd = new MultipleDNDUpload();
buttonDirect.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// }
//
//// ScriptInjector.fromUrl("http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js")
//// .setWindow(ScriptInjector.TOP_WINDOW)
//// .inject();
//
// buttonUploader = new Button("Upload in your Workspace");
// buttonDirect = new Button("Upload (Stream) in your Workspace");
// enableUpload(false);
//
// WorkspaceUploaderServiceAsync.Util.getInstance().getWorkspaceId(
// new AsyncCallback<String>() {
//
// @Override
// public void onSuccess(String result) {
//
// if (result != null) {
// parentId = result;
// enableUpload(true);
// } else {
// Window.alert("An error occurred on recovering workspace, try again later");
// enableUpload(true);
// }
// }
//
// @Override
// public void onFailure(Throwable caught) {
// Window.alert("An error occurred on recovering workspace, try again later");
// enableUpload(true);
// }
// });
//
// buttonDirect.addClickHandler(new ClickHandler() {
//
// @Override
// public void onClick(ClickEvent event) {
// MultipleDilaogUpload uploadStream = new MultipleDilaogUpload(headerTitle, parentId, org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE.File);
// uploadStream.initFileReader();
// uploadStream.center();
dnd.setParameters(parentId, UPLOAD_TYPE.File);
}
});
RootPanel.get("workspace-uploader").add(dnd);
RootPanel.get("workspace-uploader").add(buttonDirect);
}
private void enableUpload(boolean bool){
buttonUploader.setEnabled(bool);
buttonDirect.setEnabled(bool);
}
/**
* Checks if is j query loaded.
*
* @return true, if is j query loaded
*/
private native boolean isjQueryLoaded() /*-{
return (typeof $wnd['jQuery'] !== 'undefined');
}-*/;
}
//
// }
// });
//
// final MultipleDNDUpload dnd = new MultipleDNDUpload();
//
// buttonDirect.addClickHandler(new ClickHandler() {
//
// @Override
// public void onClick(ClickEvent event) {
//// MultipleDilaogUpload uploadStream = new MultipleDilaogUpload(headerTitle, parentId, org.gcube.portlets.widgets.workspaceuploader.client.uploader.DialogUpload.UPLOAD_TYPE.File);
//// uploadStream.initFileReader();
//// uploadStream.center();
// dnd.setParameters(parentId, UPLOAD_TYPE.File);
//
// }
// });
//
// RootPanel.get("workspace-uploader").add(dnd);
// RootPanel.get("workspace-uploader").add(buttonDirect);
// }
//
// private void enableUpload(boolean bool){
// buttonUploader.setEnabled(bool);
// buttonDirect.setEnabled(bool);
// }
//
// /**
// * Checks if is j query loaded.
// *
// * @return true, if is j query loaded
// */
// private native boolean isjQueryLoaded() /*-{
// return (typeof $wnd['jQuery'] !== 'undefined');
// }-*/;
//}

View File

@ -66,6 +66,22 @@ public class MultipleDilaogUpload extends DialogUpload {
this.addHandlers();
}
/* (non-Javadoc)
* @see com.google.gwt.user.client.ui.DialogBox#show()
*/
@Override
public void show() {
super.show();
}
/* (non-Javadoc)
* @see com.google.gwt.user.client.ui.PopupPanel#center()
*/
@Override
public void center() {
super.center();
}
/**
* Generate new upload client keys.
*
@ -377,8 +393,7 @@ public class MultipleDilaogUpload extends DialogUpload {
* the file delimiter
* @return the files selected
*/
public static native String getFilesSelected(final String tagId,
final String fileDelimiter) /*-{
public static native String getFilesSelected(final String tagId, final String fileDelimiter) /*-{
var count = $wnd.$("#" + tagId)[0].files.length;
console.log(count);
var out = "";
@ -392,150 +407,150 @@ public class MultipleDilaogUpload extends DialogUpload {
}-*/;
/**
* Inits the file reader.
*/
public void initFileReader() {
initW3CFileReader(instance, MultipleDilaogUpload.FILE_DELEMITER);
}
/**
* Gets the files selected.
*
* @param instance the instance
* @param fileDelimiter the file delimiter
* @return the files selected
*/
public static native String initW3CFileReader(MultipleDilaogUpload instance, String fileDelimiter) /*-{
console.log("initW3CFileReader");
if (window.FileReader) {
console.log("before load");
var drop = $wnd.$('#drop_target')[0];
console.log("drop is " + drop);
function cancel(e) {
if (e.preventDefault) {
e.preventDefault();
}
return false;
}
function addEventHandler(obj, evt, handler) {
if (obj.addEventListener) {
// W3C method
obj.addEventListener(evt, handler, false);
} else if (obj.attachEvent) {
// IE method.
obj.attachEvent('on' + evt, handler);
} else {
// Old school method.
obj['on' + evt] = handler;
}
}
addEventHandler(drop, 'drop', function(e) {
e = e || window.event; // get window.event if e argument missing (in IE)
if (e.preventDefault) {
e.preventDefault();
} // stops the browser from redirecting off to the image.
var servlet = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::servlet;
var opts = {
url : servlet,
type : "POST",
processData : false
};
var idfolder = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::idFolder;
console.log("idfolder: " + idfolder);
var uploadType = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::type;
console.log("uploadType: " + uploadType);
var dt = e.dataTransfer;
var files = dt.files;
var filesSelected = "";
for (i = 0; i < files.length; i++) {
filesSelected += files[i].name + fileDelimiter;
}
console.log("filesSelected: " + filesSelected);
// var files = filese
// var files = filesSelected.split(fileDelimiter);
console.log("files: " + files);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::isLimitExceeded(I)(files.length);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::generateFakeUploaders(Ljava/lang/String;Ljava/lang/String;)(filesSelected,idfolder);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::createJsonKeyForFiles()();
var jsonKeys = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::jsonKeys;
console.log("jsonKeys: " + jsonKeys);
for (var i = 0; i < files.length; i++) {
var file = files[i];
// var reader = new FileReader();
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", jsonKeys);
formdata.append("uploadType", uploadType);
formdata.append("idFolder", idfolder);
formdata.append('uploadFormElement', file);
xhr.send(formdata);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::addNewSubmitToMonitor()();
// reader.readAsText(file);
}
return false;
})
// Tells the browser that we *can* drop on this target
addEventHandler(drop, 'dragover', cancel);
addEventHandler(drop, 'dragenter', cancel);
} else {
$wnd.$('#drop_target')[0].innerHTML = 'Your browser does not support the HTML5 FileReader.';
}
}-*/;
// /**
// * Inits the file reader.
// */
// public void initFileReader() {
// initW3CFileReader(instance, MultipleDilaogUpload.FILE_DELEMITER);
// }
//
// /**
// * Gets the files selected.
// *
// * @param instance the instance
// * @param fileDelimiter the file delimiter
// * @return the files selected
// */
// public static native String initW3CFileReader(MultipleDilaogUpload instance, String fileDelimiter) /*-{
// console.log("initW3CFileReader");
//
// if (window.FileReader) {
// console.log("before load");
// var drop = $wnd.$('#drop_target')[0];
// console.log("drop is " + drop);
//
// function cancel(e) {
// if (e.preventDefault) {
// e.preventDefault();
// }
// return false;
// }
//
// function addEventHandler(obj, evt, handler) {
// if (obj.addEventListener) {
// // W3C method
// obj.addEventListener(evt, handler, false);
// } else if (obj.attachEvent) {
// // IE method.
// obj.attachEvent('on' + evt, handler);
// } else {
// // Old school method.
// obj['on' + evt] = handler;
// }
// }
//
// addEventHandler(drop, 'drop', function(e) {
// e = e || window.event; // get window.event if e argument missing (in IE)
// if (e.preventDefault) {
// e.preventDefault();
// } // stops the browser from redirecting off to the image.
//
// var servlet = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::servlet;
//
// var opts = {
// url : servlet,
// type : "POST",
// processData : false
// };
//
// var idfolder = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::idFolder;
// console.log("idfolder: " + idfolder);
//
// var uploadType = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::type;
// console.log("uploadType: " + uploadType);
//
// var dt = e.dataTransfer;
// var files = dt.files;
//
// var filesSelected = "";
//
// for (i = 0; i < files.length; i++) {
// filesSelected += files[i].name + fileDelimiter;
// }
// console.log("filesSelected: " + filesSelected);
//
//// var files = filese
//// var files = filesSelected.split(fileDelimiter);
// console.log("files: " + files);
//
// instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::isLimitExceeded(I)(files.length);
//
// instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::generateFakeUploaders(Ljava/lang/String;Ljava/lang/String;)(filesSelected,idfolder);
//
// instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::createJsonKeyForFiles()();
//
// var jsonKeys = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::jsonKeys;
// console.log("jsonKeys: " + jsonKeys);
//
// for (var i = 0; i < files.length; i++) {
// var file = files[i];
//// var reader = new FileReader();
//
// 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", jsonKeys);
// formdata.append("uploadType", uploadType);
// formdata.append("idFolder", idfolder);
// formdata.append('uploadFormElement', file);
//
// xhr.send(formdata);
//
// instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::addNewSubmitToMonitor()();
//
//// reader.readAsText(file);
// }
// return false;
// })
//
// // Tells the browser that we *can* drop on this target
// addEventHandler(drop, 'dragover', cancel);
// addEventHandler(drop, 'dragenter', cancel);
// } else {
// $wnd.$('#drop_target')[0].innerHTML = 'Your browser does not support the HTML5 FileReader.';
// }
// }-*/;
}

View File

@ -4,6 +4,7 @@
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
@ -120,7 +121,7 @@ public class WorkspaceFieldsUploadManager {
}
}
GWT.log("generating fake uploaders on: "+files.toString());
GWT.log("generating fake uploaders on: "+Arrays.asList(files).toString());
fakeUploaders = new ArrayList<WorkspaceUploaderItem>(files.length);
for (int i = 0; i < files.length; i++) {
WorkspaceUploaderItem fakeItem = new WorkspaceUploaderItem();

View File

@ -161,13 +161,14 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
initW3CFileReader(this, FILE_DELEMITER);
}
/**
* Inits the workspace fields.
* New workspace fields manager for uuid.
*
* @param uploadUUID
* the upload uuid
* @param uploadUUID the upload uuid
*/
private void initWorkspaceFields(String uploadUUID) {
private void newWorkspaceFieldsManagerForUUID(String uploadUUID) {
fields.put(uploadUUID, new WorkspaceFieldsUploadManager());
}
@ -206,7 +207,7 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
* the upload uuid
*/
private void addNewSubmitToMonitor(String uploadUUID) {
WorkspaceFieldsUploadManager field = getField(uploadUUID);
WorkspaceFieldsUploadManager field = getFieldsUploadManager(uploadUUID);
field.addNewSubmitToMonitor();
}
@ -217,7 +218,7 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
* the upload uuid
*/
private void createJsonKeyForFiles(String uploadUUID) {
WorkspaceFieldsUploadManager field = getField(uploadUUID);
WorkspaceFieldsUploadManager field = getFieldsUploadManager(uploadUUID);
field.createJsonKeyForFiles();
}
@ -231,20 +232,19 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
* @param uploadUUID
* the upload uuid
*/
private void generateFakeUploaders(String filesSelected, String parentId,
String uploadUUID) {
WorkspaceFieldsUploadManager field = getField(uploadUUID);
private void generateFakeUploaders(String filesSelected, String parentId, String uploadUUID) {
WorkspaceFieldsUploadManager field = getFieldsUploadManager(uploadUUID);
field.generateFakeUploaders(filesSelected, parentId);
}
/**
* Gets the fields.
* Gets the field upload manager.
*
* @param uploadUUID
* the upload uuid
* @return the fields
* @param uploadUUID the upload uuid
* @return the field upload manager
*/
private WorkspaceFieldsUploadManager getField(String uploadUUID) {
private WorkspaceFieldsUploadManager getFieldsUploadManager(String uploadUUID) {
return fields.get(uploadUUID);
}
@ -255,7 +255,7 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
* the upload uuid
*/
private void updateJsonKeys(String uploadUUID) {
WorkspaceFieldsUploadManager field = getField(uploadUUID);
WorkspaceFieldsUploadManager field = getFieldsUploadManager(uploadUUID);
jsonKeys.put(uploadUUID, field.getJsonKeys());
// this.jsonKeys = field.getJsonKeys();
}
@ -533,7 +533,7 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
var uploadUUID = generateUUID();
console.log("uploadKey: " + uploadUUID);
//NEW WORKSPACE FIELDS
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::initWorkspaceFields(Ljava/lang/String;)(uploadUUID);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::newWorkspaceFieldsManagerForUUID(Ljava/lang/String;)(uploadUUID);
var servlet = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::servlet;
@ -584,12 +584,12 @@ public class MultipleDNDUpload extends LayoutPanel implements HasWorskpaceUpload
var numFolder = 0;
for (var i = 0; i < files.length; i++) {
var file = files[i];
var filesSelected = files[i].name + fileDelimiter;
var fileSelected = files[i].name + fileDelimiter;
if (!isFolder(file)) {
console.log("filesSelected: " + filesSelected);
console.log("fileSelected: " + fileSelected);
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::generateFakeUploaders(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)(fileSelected,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);

View File

@ -741,7 +741,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
}finally{
try {
// StreamUtils.deleteTempFile(file);
WsUtil.eraseWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier());
WsUtil.setErasableWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier());
} catch (Exception e2) {
// TODO: handle exception
}
@ -803,7 +803,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
}finally{
try {
// StreamUtils.deleteTempFile(fileInputStream);
WsUtil.eraseWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier());
WsUtil.setErasableWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier());
} catch (Exception e2) {
// TODO: handle exception
}

View File

@ -1,5 +1,7 @@
package org.gcube.portlets.widgets.workspaceuploader.server;
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;
@ -37,6 +39,7 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
}
logger.trace("Get UploadStatus for id: "+identifier);
WorkspaceUploaderItem uploader = WsUtil.getWorkspaceUploaderInSession(getThreadLocalRequest().getSession(), identifier);
logger.trace("Uploader status for id: "+identifier +" returns "+uploader);
if (uploader == null) {
WorkspaceUploaderItem waitingUpload = new WorkspaceUploaderItem(identifier, null, UPLOAD_STATUS.WAIT, "Upload waiting..", new UploadProgress());
@ -56,10 +59,42 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
progress = "upload progress is null or last event is null";
logger.info("returning uploader: "+uploader.getClientUploadKey() +" status: "+uploader.getUploadStatus() +", file: "+uploader.getFile().toString() +", progress: "+progress);
checkUploaderErasable(getThreadLocalRequest().getSession(), uploader);
return uploader;
}
/**
* Check uploader erasable.
*
* @param httpSession the http session
* @param uploader the uploader
*/
private void checkUploaderErasable(final HttpSession httpSession, final WorkspaceUploaderItem uploader){
logger.trace("Checking Uploader erasable...");
if(uploader==null){
logger.error("Uploader is null, returning..");
return;
}
new Thread(){
@Override
public void run() {
try {
logger.trace("Uploader: "+uploader.getClientUploadKey() +"is erasable?");
WsUtil.eraseWorkspaceUploaderInSession(httpSession, uploader);
}
catch (Exception e) {
logger.warn("Error during checkUploaderErasable: ", e);
}
}
}.start();
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderService#getWorkspaceId()
*/

View File

@ -175,6 +175,9 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
public void remove() {
logger.debug(sessionKey + " removing: " + toString());
if (getSession() != null) {
// logger.debug(sessionKey + " skipping remove. A TODO must be realized");
// /*TODO REMOVE SESSION KEY FROM SESSION MUST BE MANAGED IN ANOTHER WAY IN ORDER TO AVOID THAT
// * IT'S REMOVED FROM SESSION BEFORE THAT POLLING RETRIEVES STATUS, USE A FLAG REMOVED?*/
getSession().removeAttribute(sessionKey);
logger.info("Removed from session: " + toString());
}

View File

@ -128,7 +128,7 @@ public class WorkspaceUploaderMng {
}finally{
try {
// StreamUtils.deleteTempFile(uploadFile);
WsUtil.eraseWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier());
WsUtil.setErasableWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier());
} catch (Exception e2) {
}
}
@ -187,7 +187,7 @@ public class WorkspaceUploaderMng {
}finally{
try {
// StreamUtils.deleteTempFile(uploadFile);
WsUtil.eraseWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier());
WsUtil.setErasableWorkspaceUploaderInSession(httpSession, workspaceUploader.getIdentifier());
} catch (Exception e2) {
// TODO: handle exception
}

View File

@ -38,7 +38,7 @@ public class WsUtil {
public static final String NOTIFICATION_PORTLET_CLASS_ID = "org.gcube.portlets.user.workspace.server.GWTWorkspaceServiceImpl";
//IN DEV
public static final String TEST_SCOPE = "/gcube/devsec";
public static String TEST_USER = "test.user";
public static String TEST_USER = "francesco.mangiacrapa";
public static String TEST_USER_FULL_NAME = "Test User";
@ -222,6 +222,27 @@ public class WsUtil {
logger.debug("Added uploader: "+uploader.getIdentifier() +" in session");
}
/**
* Erase workspace uploader in session.
*
* @param httpSession the http session
* @param uploader the uploader
* @throws Exception the exception
*/
public static void eraseWorkspaceUploaderInSession(final HttpSession httpSession, WorkspaceUploaderItem uploader) throws Exception
{
logger.trace("Erase WorkspaceUploader workspace uploader in session: "+uploader.getIdentifier() + ", erasable? "+uploader.isErasable());
final ASLSession session = getAslSession(httpSession);
if(uploader==null || uploader.getIdentifier()==null || uploader.getIdentifier().isEmpty())
throw new Exception("Invalid uploader");
if(uploader.isErasable()){
session.setAttribute(uploader.getIdentifier(), null);
logger.info("Erased uploader: "+uploader.getIdentifier() +" with null value");
}
}
/**
* Gets the workspace uploader in session.
@ -244,20 +265,23 @@ public class WsUtil {
/**
* Erase workspace uploader in session.
* Sets the erasable workspace uploader in session.
*
* @param httpSession the http session
* @param uploaderIdentifier the uploader identifier
* @return true, if successful
* @throws Exception the exception
*/
public static boolean eraseWorkspaceUploaderInSession(final HttpSession httpSession, String uploaderIdentifier) throws Exception
public static boolean setErasableWorkspaceUploaderInSession(final HttpSession httpSession, String uploaderIdentifier) throws Exception
{
WorkspaceUploaderItem uploader = getWorkspaceUploaderInSession(httpSession, uploaderIdentifier);
if(uploader!=null){
logger.debug("Erasing uploader: "+uploader.getIdentifier() +" in session, adding null value");
uploader = null;
/*TODO REMOVE SESSION KEY FROM SESSION MUST BE MANAGED IN ANOTHER WAY IN ORDER TO AVOID THATH IT'S REMOVED FROM SESSION BEFORE THAT
* POLLING RETRIEVES STATUS, USE A FLAG REMOVED?*/
logger.debug("Set erasable uploader: "+uploader.getIdentifier() +" in session");
// uploader = null;
uploader.setErasable(true);
putWorkspaceUploaderInSession(httpSession, uploader);
return true;
}

View File

@ -1,5 +1,5 @@
/**
*
*
*/
package org.gcube.portlets.widgets.workspaceuploader.shared;
@ -12,9 +12,9 @@ import java.io.Serializable;
* Aug 3, 2015
*/
public class WorkspaceUploaderItem implements Serializable{
/**
*
*
*/
private static final long serialVersionUID = -7657531873615480050L;
@ -26,16 +26,16 @@ public class WorkspaceUploaderItem implements Serializable{
* Aug 6, 2015
*/
public static enum UPLOAD_STATUS{
WAIT("WAIT", "wait"),
IN_PROGRESS("IN_PROGRESS", "in progress"),
FAILED("FAILED", "failed"),
ABORTED("ABORTED", "aborted"),
COMPLETED("COMPLETED", "completed");
protected String id;
protected String label;
/**
* Instantiates a new upload status.
*
@ -47,7 +47,7 @@ public class WorkspaceUploaderItem implements Serializable{
this.label = label;
}
}
private String identifier;
private WorkspaceUploadFile file;
private UPLOAD_STATUS uploadStatus;
@ -56,6 +56,7 @@ public class WorkspaceUploaderItem implements Serializable{
private UploadProgress uploadProgress;
private Boolean isOverwrite;
// private Long threadId;
private boolean erasable;
/**
* Instantiates a new workspace uploader item.
@ -158,7 +159,7 @@ public class WorkspaceUploaderItem implements Serializable{
public void setUploadStatus(UPLOAD_STATUS uploadStatus) {
this.uploadStatus = uploadStatus;
}
/**
* Gets the client upload key.
@ -178,7 +179,7 @@ public class WorkspaceUploaderItem implements Serializable{
public void setClientUploadKey(String clientUploadKey) {
this.clientUploadKey = clientUploadKey;
}
/**
* Gets the upload progress.
*
@ -211,11 +212,32 @@ public class WorkspaceUploaderItem implements Serializable{
this.isOverwrite = isOverwrite;
}
/**
* Sets the erasable.
*
* @param b the new erasable
*/
public void setErasable(boolean b) {
this.erasable = b;
}
/**
* Checks if is erasable.
*
* @return the erasable
*/
public boolean isErasable() {
return erasable;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("WorkspaceUploaderItem [identifier=");
builder.append(identifier);
@ -227,11 +249,16 @@ public class WorkspaceUploaderItem implements Serializable{
builder.append(statusDescription);
builder.append(", clientUploadKey=");
builder.append(clientUploadKey);
builder.append(", uploadProgress=");
builder.append(uploadProgress);
// builder.append(", uploadProgress=");
// builder.append(uploadProgress);
builder.append(", isOverwrite=");
builder.append(isOverwrite);
builder.append(", erasable=");
builder.append(erasable);
builder.append("]");
return builder.toString();
}
}