3962: Workspace Uploader improvements: use a sequential get status instead of parallel during (multiple-)uploads

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

Updated pom version at 1.2.0
Starting sequential system to upload instead of parallel

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@128558 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-05-11 08:25:22 +00:00
parent 852cb584be
commit aa74220a50
15 changed files with 821 additions and 515 deletions

View File

@ -29,5 +29,6 @@
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/francesco-mangiacrapa/libraries/asm-5.0.3/lib/asm-5.0.3.jar"/>
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@ -1,5 +1,5 @@
eclipse.preferences.version=1
jarsExcludedFromWebInfLib=
lastWarOutDir=/home/francesco-mangiacrapa/wseclipseluna/workspace-uploader-TRUNK/target/workspace-uploader-1.0.0-SNAPSHOT
warSrcDir=
warSrcDir=src/main/webapp
warSrcDirIsOutput=false

View File

@ -1,4 +1,8 @@
<ReleaseNotes>
<Changeset component="org.gcube.portlets-widgets.workspace-uploader.1-2-0"
date="2016-05-09">
<Change>[Feature #3962] Sequential upload status</Change>
</Changeset>
<Changeset component="org.gcube.portlets-widgets.workspace-uploader.1-1-0"
date="2016-01-08">
<Change>Bug Fixed #1333</Change>

15
pom.xml
View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.widgets</groupId>
<artifactId>workspace-uploader</artifactId>
<packaging>jar</packaging>
<version>1.1.1-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<name>Workspace Uploader Widget</name>
<description>Workspace Uploader Widget allows your application to upload file/s in the gCube Workspace</description>
<scm>
@ -37,7 +37,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>maven-portal-bom</artifactId>
<version>LATEST</version>
<version>2.6.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -60,11 +60,11 @@
<dependencies>
<!-- UNCOMMENT THIS TO RUN IN DEVO MODE -->
<!-- <dependency> -->
<!-- <groupId>xerces</groupId> -->
<!-- <artifactId>xerces</artifactId> -->
<!-- <version>2.4.0</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>xerces</groupId> -->
<!-- <artifactId>xerces</artifactId> -->
<!-- <version>2.4.0</version> -->
<!-- </dependency> -->
<!-- Google Web Toolkit (GWT) -->
<dependency>
@ -179,7 +179,6 @@
<dependency>
<groupId>org.gcube.portal</groupId>
<artifactId>social-networking-library</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -6,11 +6,12 @@ import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem
import com.google.gwt.event.shared.GwtEvent;
/**
* The Class CancelUploadEvent.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 7, 2015
* May 10, 2016
*/
public class CancelUploadEvent extends GwtEvent<CancelUploadEventHandler> {
public static Type<CancelUploadEventHandler> TYPE = new Type<CancelUploadEventHandler>();
@ -18,16 +19,12 @@ public class CancelUploadEvent extends GwtEvent<CancelUploadEventHandler> {
private String fileName;
private WorkspaceUploaderItem uploader;
/**
* @return the hp
*/
public UploaderProgressView getProgessView() {
return uploaderProgressView;
}
/**
* Instantiates a new cancel upload event.
*
* @param uploader the uploader
* @param uploaderProgressView the uploader progress view
* @param fileName the file name
*/
public CancelUploadEvent(WorkspaceUploaderItem uploader, UploaderProgressView uploaderProgressView, String fileName) {
this.uploader = uploader;
@ -36,6 +33,8 @@ public class CancelUploadEvent extends GwtEvent<CancelUploadEventHandler> {
}
/**
* Gets the uploader.
*
* @return the uploader
*/
public WorkspaceUploaderItem getUploader() {
@ -59,7 +58,19 @@ public class CancelUploadEvent extends GwtEvent<CancelUploadEventHandler> {
}
/**
* @return
* Gets the progess view.
*
* @return the progess view
*/
public UploaderProgressView getProgessView() {
return uploaderProgressView;
}
/**
* Gets the file name.
*
* @return the file name
*/
public String getFileName() {
return fileName;

View File

@ -44,15 +44,15 @@ import com.google.gwt.user.client.ui.VerticalPanel;
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 24, 2015
*/
public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNotificationListener{
public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNotificationListener{
private Hidden hiddenOverwrite = new Hidden(ConstantsWorkspaceUploader.IS_OVERWRITE,"false");
protected final FormPanel formPanel = new FormPanel();
protected final FormPanel formPanel = new FormPanel();
protected FileUpload fileUpload;
protected Hidden jsonClientKeys;
protected List<WorkspaceUploaderItem> fakeUploaders = new ArrayList<WorkspaceUploaderItem>();
protected WorkspaceUploaderListenerController controller = new WorkspaceUploaderListenerController();
/**
* The Enum UPLOAD_TYPE.
*
@ -81,31 +81,31 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
super(false, true, headerTitle);
setWidth("400px");
fileUpload = new FileUpload();
//ONLY IN CASE OF FILE MULTIPLE UPLOAD IS AVAILABLE
if(uploadType.equals(UPLOAD_TYPE.File))
fileUpload.getElement().setAttribute("multiple", "multiple");
this.parentIdentifier = parentId;
this.uploadType = uploadType;
this.addStyleName("fileInputUploader");
formPanel.setAction(ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM);
formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
formPanel.setMethod(FormPanel.METHOD_POST);
formPanel.setAction(ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM);
formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
formPanel.setMethod(FormPanel.METHOD_POST);
formPanel.setWidth("auto");
// Create a panel to hold all of the form widgets.
panel = new VerticalPanel();
formPanel.setWidget(panel);
setModal(false);
fileUpload.setName(ConstantsWorkspaceUploader.UPLOAD_FORM_ELEMENT);
// Add hidden parameters
panel.add(new Hidden(ConstantsWorkspaceUploader.ID_FOLDER,parentId));
panel.add(new Hidden(ConstantsWorkspaceUploader.UPLOAD_TYPE,uploadType.toString()));
panel.add(hiddenOverwrite);
initJsonClientKeys();
panel.add(jsonClientKeys);
panel.add(fileUpload);
@ -116,10 +116,10 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
hp.getElement().getStyle().setMarginTop(5, Unit.PX);
hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
hp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
anchorMyUploads = new Anchor(ConstantsWorkspaceUploader.MY_UPLOADS);
anchorMyUploads.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
UploaderMonitor.getInstance().showMonitor();
@ -127,12 +127,12 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
});
hp.add(anchorMyUploads);
panel.add(hp);
hpBottom = new HorizontalPanel();
hpBottom.setWidth("100%");
// hpBottom.getElement().getStyle().setMarginTop(5, Unit.PX);
hpBottom.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
if(uploadType.equals(UPLOAD_TYPE.File)){
HTML msg = new HTML("<p>To select multiple files, press and hold down the Ctrl key, and then</p><p style='margin:-3px 0;'>click each item that you want to select</p>");
msg.getElement().getStyle().setFontSize(10, Unit.PX);
@ -143,10 +143,10 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
hp2.getElement().getStyle().setMarginTop(5, Unit.PX);
// hp2.getElement().getStyle().setWidth(100, Unit.PCT);
hp2.addStyleName("align-right-close");
Button bClose = new Button("Close");
bClose.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
DialogUpload.this.hide();
@ -155,11 +155,11 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
hp2.add(bClose);
hpBottom.add(hp2);
panel.add(hpBottom);
panel.add(hpBottom);
add(formPanel);
}
/**
* @return the panel
*/
@ -170,7 +170,7 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
protected void initJsonClientKeys(){
jsonClientKeys = new Hidden(ConstantsWorkspaceUploader.CLIENT_UPLOAD_KEYS,"");
}
/**
* Bind events.
*/
@ -183,17 +183,17 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
* Adds the handlers.
*/
protected void addHandlers() {
// handle the post
// handle the post
formPanel.addSubmitCompleteHandler(new SubmitCompleteHandler() {
@Override
public void onSubmitComplete(SubmitCompleteEvent event) {
GWT.log("onSubmitComplete");
GWT.log("onSubmitComplete");
hide();
// isStatusCompleted = true;
String result = event.getResults();
if (result == null) {
removeLoading();
new DialogResult(null, "Error during upload", "An error occurred during file upload.").center();
@ -203,63 +203,64 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
switch (resultMessage.getStatus()) {
case ERROR:
case ERROR:
removeLoading();
GWT.log("Error during upload "+resultMessage.getMessage());
GWT.log("Error during upload "+resultMessage.getMessage());
break;
case UNKNOWN:
case UNKNOWN:
removeLoading();
GWT.log("Error during upload "+resultMessage.getMessage());
GWT.log("Error during upload "+resultMessage.getMessage());
break;
case WARN: {
GWT.log("Upload completed with warnings "+resultMessage.getMessage());
GWT.log("Upload completed with warnings "+resultMessage.getMessage());
removeLoading();
break;
}
case OK: {
// removeLoading();
// UploaderMonitor.getInstance().pollWorkspaceUploaderId(resultMessage.getMessage());
/*Timer t = new Timer() {
public void run() {
GWT.log("Upload started with id: "+resultMessage.getMessage());
GWT.log("Upload started with id: "+resultMessage.getMessage());
UploaderMonitor.getInstance().pollWorkspaceUploaderId(resultMessage.getMessage());
}
};
t.schedule(250);*/
}
}
}
}
});
//TODO NEVER USED, WE ARE USING MULTIPLE DIALOG UPLOAD
formPanel.addSubmitHandler(new SubmitHandler() {
@Override
public void onSubmit(SubmitEvent event) {
GWT.log("SubmitEvent");
GWT.log("SubmitEvent");
addLoading();
enableButtons(false);
WorkspaceUploaderItem fakeUploader = new WorkspaceUploaderItem();
fakeUploader.setClientUploadKey(clientUploadKey);
UploaderMonitor.getInstance().addNewSubmit(fakeUploader, fileUpload.getFilename());
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(fakeUploader, fileUpload.getFilename());
setVisible(false);
removeLoading();
UploaderMonitor.getInstance().pollWorkspaceUploader(fakeUploader);
// UploaderMonitor.getInstance().pollWorkspaceUploader(fakeUploader);
}
});
fileUpload.addChangeHandler(new ChangeHandler() {
@Override
public void onChange(ChangeEvent event) {
GWT.log("btnSubmit click");
if (fileUpload.getFilename()==null || !(fileUpload.getFilename().length()>2)) {
GWT.log("No file specified ");
return;
}
GWT.log("btnSubmit click");
if (fileUpload.getFilename()==null || !(fileUpload.getFilename().length()>2)) {
GWT.log("No file specified ");
return;
}
GWT.log("fileUpload.getFilename() "+fileUpload.getFilename());
/*
* TODO: recall: Some browser would write in fileUploadField.getValue() C:\fakepath\$fileName
@ -301,7 +302,7 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
protected void addLoading(){
panel.add(LOADING);
}
/**
* Removes the loading.
*/
@ -309,10 +310,10 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
try{
panel.remove(LOADING);
}catch(Exception e){
}
}
/**
* Enable buttons.
*
@ -328,7 +329,7 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
* Submit form.
*/
public void submitForm(){
formPanel.submit();
formPanel.submit();
}
@ -359,7 +360,7 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
});*/
}
/**
* Update item submit form.
*
@ -385,5 +386,5 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
public void removeWorkspaceUploadNotificationListener(WorskpaceUploadNotificationListener handler) {
controller.removeWorkspaceUploadListener(handler);
}
}
}

View File

@ -1,5 +1,5 @@
/**
*
*
*/
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
@ -35,19 +35,19 @@ import com.google.gwt.user.client.ui.VerticalPanel;
* Sep 24, 2015
*/
public class MonitorPanel extends ScrollPanel{
private VerticalPanel vpListUpload = new VerticalPanel();
private VerticalPanel mainPanel = new VerticalPanel();
private Map<String, WorkspaceUploaderItem> mapUploading = new HashMap<String, WorkspaceUploaderItem>();
private Map<String, UploaderProgressView> mapPanels = new HashMap<String, UploaderProgressView>();
private HandlerManager eventBus;
private HorizontalPanel hpNoUploads = new HorizontalPanel();
private HTML labelNumbUpload = new HTML("Uploaded 0 of 0");
private HorizontalPanel hpBottomPanel = new HorizontalPanel();
private HorizontalPanel hpCloseMonitor = new HorizontalPanel();
static {
ProgressBarCssAndImages.INSTANCE.css().ensureInjected();
}
@ -67,10 +67,10 @@ public class MonitorPanel extends ScrollPanel{
hpBottomPanel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
hpBottomPanel.setWidth("100%");
hpBottomPanel.add(labelNumbUpload);
// mainPanel.add(hpNumbUpload);
// mainPanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
//LIST OF UPLOADS
vpListUpload.getElement().getStyle().setMargin(5, Unit.PX);
// setHeight("500px");
@ -80,61 +80,61 @@ public class MonitorPanel extends ScrollPanel{
scroll.setHeight("200px");
// scroll.getElement().getStyle().setBorderStyle(BorderStyle.SOLID);
// scroll.getElement().getStyle().setBorderWidth(1.0, Unit.PX);
mainPanel.add(scroll);
//CLOSE MONITOR
// hpCloseMonitor.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
// hpCloseMonitor.setVerticalAlignment(HasVerticalAlignment.ALIGN_BOTTOM);
Button bClose = new Button("Close");
bClose.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
eventBus.fireEvent(new HideMonitorEvent());
}
});
// hpNumbUpload.add(bClose);
hpCloseMonitor.add(bClose);
hpCloseMonitor.addStyleName("align-right-close");
hpBottomPanel.add(hpCloseMonitor);
hpBottomPanel.getElement().getStyle().setMarginTop(5.0, Unit.PX);
mainPanel.setWidth("100%");
mainPanel.add(hpBottomPanel);
add(mainPanel);
// RootPanel.get("workspace-uploader").add(verticalPanel);
}
private void updateNumberUpload(){
int numCompleted = 0;
for (String uploadKey : mapUploading.keySet()) {
WorkspaceUploaderItem uploader = mapUploading.get(uploadKey);
if(uploader.getUploadStatus().equals(UPLOAD_STATUS.COMPLETED))
numCompleted++;
}
}
labelNumbUpload.setHTML("Uploaded "+numCompleted +" of "+mapUploading.size());
}
private void initPanelNoUploads(){
hpNoUploads = new HorizontalPanel();
hpNoUploads.addStyleName("noUploads");
hpNoUploads.add(new HTML("No Uploads"));
}
private void removeNoUploads(){
try{
vpListUpload.remove(hpNoUploads);
}catch(Exception e){
}
}
/**
* Update workspace uploder.
*
@ -142,18 +142,23 @@ public class MonitorPanel extends ScrollPanel{
*/
public void updateWorkspaceUploder(WorkspaceUploaderItem uploader){
if(uploader==null){
GWT.log("Skipping update progress view, uploader is null");
return;
}
mapUploading.put(uploader.getClientUploadKey(), uploader);
if(mapPanels.get(uploader.getClientUploadKey())!=null){
UploaderProgressView upv = mapPanels.get(uploader.getClientUploadKey());
upv.update(uploader);
}else{
GWT.log("Skip update, uploader: "+uploader.getClientUploadKey() +" "+uploader.getFile().toString()+", not found!");
GWT.log("Skipping update progress view, uploader: "+uploader.getClientUploadKey() +" "+uploader.getFile().toString()+", not found!");
}
updateNumberUpload();
}
/**
* New workspace uploder.
*
@ -169,7 +174,7 @@ public class MonitorPanel extends ScrollPanel{
upvPanel.addStyleName("upladerMargin");
// vpListUpload.insert(upvPanel, 0);
vpListUpload.add(upvPanel);
updateNumberUpload();
}
@ -177,7 +182,7 @@ public class MonitorPanel extends ScrollPanel{
* Adds the close handler.
*/
private void addCloseHandler(){
Window.addWindowClosingHandler(new Window.ClosingHandler() {
@Override
public void onWindowClosing(ClosingEvent event) {
@ -185,11 +190,11 @@ public class MonitorPanel extends ScrollPanel{
String msg = "";
for (String uploadKey : mapUploading.keySet()) {
WorkspaceUploaderItem uploader = mapUploading.get(uploadKey);
GWT.log("Closing uploder status: "+uploader.getFile().getFileName() +" status: "+uploader.getUploadStatus());
GWT.log("Closing uploader status: "+uploader.getFile().getFileName() +" status: "+uploader.getUploadStatus());
if(uploader.getUploadStatus().equals(UPLOAD_STATUS.WAIT) || uploader.getUploadStatus().equals(UPLOAD_STATUS.IN_PROGRESS))
msg+=uploader.getFile().getFileName()+";";
}
if(msg!=null && !msg.isEmpty()){
event.setMessage("Abort upload? "+msg);
}
@ -200,7 +205,7 @@ public class MonitorPanel extends ScrollPanel{
@Override
public void onClose(CloseEvent<Window> event) {
// Window.alert("bye bye Closed");
}
}
});
}

View File

@ -1,5 +1,5 @@
/**
*
*
*/
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
@ -40,7 +40,7 @@ public class MultipleDilaogUpload extends DialogUpload {
private MultipleDNDUpload dnd;
public MultipleDilaogUpload instance = this;
private String jsonKeys;
private String idFolder;
private UPLOAD_TYPE type;
private String servlet = ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM;
@ -57,16 +57,13 @@ public class MultipleDilaogUpload extends DialogUpload {
*/
public MultipleDilaogUpload(String headerTitle, String parentId, UPLOAD_TYPE uploadType) {
super(headerTitle, parentId, uploadType);
this.type =uploadType;
this.idFolder = parentId;
fileUploadID = GenerateUUID.get(10, 16); // is tagID
fileUpload.getElement().setId(fileUploadID);
this.addHandlers();
// exportGenerateFakeUploaders();
// exportCreateJsonKeyForFiles();
// exportAddNewSubmitToMonitor();
}
/**
@ -77,23 +74,20 @@ public class MultipleDilaogUpload extends DialogUpload {
* @return the list
*/
public void generateFakeUploaders(String filesSelected, String parentId) {
if(filesSelected==null || filesSelected.isEmpty())
return;
String[] files = filesSelected.split(FILE_DELEMITER);
// NORMALIZE FILE NAMES
for (int i = 0; i < files.length; i++) {
String normalizedFileName = files[i];
if (normalizedFileName.contains("\\")) {
files[i] = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\") + 1); // remove
// C:\fakepath\
// if
// exists
files[i] = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\") + 1); // remove C:\fakepath if exists
}
}
GWT.log("generating fake uploaders on: "+files.toString());
fakeUploaders = new ArrayList<WorkspaceUploaderItem>(files.length);
for (int i = 0; i < files.length; i++) {
@ -106,14 +100,14 @@ public class MultipleDilaogUpload extends DialogUpload {
fakeItem.setFile(fakeFile);
fakeUploaders.add(fakeItem);
}
GWT.log("fakeUploaders generated: "+fakeUploaders.toString());
// return fakeUploaders;
}
/*
* (non-Javadoc)
*
*
* @see org.gcube.portlets.widgets.workspaceuploader.client.uploader.
* DialogUploadStream#addHandlers()
*/
@ -156,19 +150,6 @@ public class MultipleDilaogUpload extends DialogUpload {
break;
}
case OK: {
// removeLoading();
// UploaderMonitor.getInstance().pollWorkspaceUploaderId(resultMessage.getMessage());
/*
* Timer t = new Timer() { public void run() {
* GWT.log("Upload started with id: "
* +resultMessage.getMessage());
* UploaderMonitor.getInstance(
* ).pollWorkspaceUploaderId(resultMessage.getMessage()); }
* };
*
* t.schedule(250);
*/
}
}
}
@ -202,19 +183,9 @@ public class MultipleDilaogUpload extends DialogUpload {
// GWT.log("getFilesSelected: " + filesSelected);
files = filesSelected.split(FILE_DELEMITER);
if(isLimitExceeded(files.length))
return;
// if (files.length > ConstantsWorkspaceUploader.LIMIT_UPLOADS) {
// Window.alert("Multiple upload limit is "
// + ConstantsWorkspaceUploader.LIMIT_UPLOADS
// + " files");
// MultipleDilaogUpload.this.hide();
// return;
// }
// GENERATE NEW UPLOADERS
generateFakeUploaders(filesSelected, parentIdentifier);
@ -275,9 +246,9 @@ public class MultipleDilaogUpload extends DialogUpload {
}
});
}
/**
* Checks if is limit exceeded.
*
@ -285,7 +256,7 @@ public class MultipleDilaogUpload extends DialogUpload {
* @return true, if is limit exceeded
*/
public boolean isLimitExceeded(int numbOfFiles){
if (numbOfFiles > ConstantsWorkspaceUploader.LIMIT_UPLOADS) {
Window.alert("Multiple upload limit is "
+ ConstantsWorkspaceUploader.LIMIT_UPLOADS
@ -293,24 +264,28 @@ public class MultipleDilaogUpload extends DialogUpload {
MultipleDilaogUpload.this.hide();
return true;
}
return false;
}
}
/**
* Adds the new submit to monitor.
*/
public void addNewSubmitToMonitor(){
GWT.log("addNewSubmitToMonitor...");
int queueIndex = UploaderMonitor.getInstance().newQueue();
for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
UploaderMonitor.getInstance().addNewSubmit(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
setVisible(false);
removeLoading();
UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
UploaderMonitor.getInstance().addNewTimerToQueue(queueIndex, workspaceUploaderItem);
// UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
}
UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);
}
/**
* Creates the json key for files.
*
@ -323,14 +298,14 @@ public class MultipleDilaogUpload extends DialogUpload {
JSONArray jsonArray = new JSONArray();
productObj.put(ConstantsWorkspaceUploader.JSON_CLIENT_KEYS, jsonArray);
// GWT.log("Creating json keys on fakeUploaders: "+fakeUploaders.toString());
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()));
jsonArray.set(i, obj);
}
jsonKeys = productObj.toString();
GWT.log("updated jsonKeys: "+jsonKeys);
} catch (Exception e) {
@ -339,64 +314,12 @@ public class MultipleDilaogUpload extends DialogUpload {
}
}
// /**
// * Export generate fake uploaders.
// */
// public native void exportGenerateFakeUploaders() /*-{
// var that = this;
// $wnd.add = $entry(function(files,parentId) {
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::generateFakeUploaders([Ljava/lang/String;Ljava/lang/String;)(files,parentId);
// });
// }-*/;
//
// /**
// * Export create json key for files.
// */
// public native void exportCreateJsonKeyForFiles() /*-{
// var that = this;
// $wnd.add = $entry(function() {
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::createJsonKeyForFiles()();
// });
// }-*/;
//
// /**
// * Export create json key for files.
// */
// public native void exportAddNewSubmitToMonitor() /*-{
// var that = this;
// $wnd.add = $entry(function() {
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::addNewSubmitToMonitor()();
// });
// }-*/;
/**
* Submit form.
*/
@Override
public void submitForm() {
formPanel.submit();
// for (final WorkspaceUploaderItem workspaceUploaderItem :
// fakeUploaders) {
//
// UploaderMonitor.getInstance().addNewSubmit(workspaceUploaderItem,
// workspaceUploaderItem.getFile().getFileName());
// setVisible(false);
// removeLoading();
// //
// UploaderMonitor.getInstance().pollWorkspaceUploaderId(workspaceUploaderItem.getClientUploadKey());
//
// //WAITING 0.1 SEC TO FIRST UPDATES
// /*new Timer() {
//
// @Override
// public void run() {
// removeLoading();
// UploaderMonitor.getInstance().pollWorkspaceUploaderId(workspaceUploaderItem.getClientUploadKey());
//
// }
// }.schedule(100);*/
// }
}
/**
@ -426,7 +349,7 @@ public class MultipleDilaogUpload extends DialogUpload {
}
}-*/;
/**
* Gets the parent id.
*
@ -444,22 +367,7 @@ public class MultipleDilaogUpload extends DialogUpload {
public UPLOAD_TYPE getUploadType() {
return uploadType;
}
// public native void exportParentId() /*-{
// var that = this;
// $wnd.add = $entry(function() {
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::getParentId();
// });
// }-*/;
//
// public native void exportUploadType() /*-{
// var that = this;
// $wnd.add = $entry(function() {
// that.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::getUploadType();
// });
// }-*/;
/**
* Gets the files selected.
*
@ -482,15 +390,15 @@ public class MultipleDilaogUpload extends DialogUpload {
}
return out;
}-*/;
/**
* Inits the file reader.
*/
public void initFileReader() {
initW3CFileReader(instance, MultipleDilaogUpload.FILE_DELEMITER);
}
/**
* Gets the files selected.
*
@ -531,7 +439,7 @@ public class MultipleDilaogUpload extends DialogUpload {
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 = {
@ -539,10 +447,10 @@ public class MultipleDilaogUpload extends DialogUpload {
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);
@ -555,17 +463,17 @@ public class MultipleDilaogUpload extends DialogUpload {
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);
@ -575,14 +483,14 @@ public class MultipleDilaogUpload extends DialogUpload {
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
@ -606,7 +514,7 @@ public class MultipleDilaogUpload extends DialogUpload {
formdata.append("isOverwrite", "false");
// $wnd.exportCreateJsonKeyForFiles();
//
//
// $wnd.exportAddNewSubmitToMonitor();
formdata.append("client_upload_keys", jsonKeys);
@ -615,7 +523,9 @@ public class MultipleDilaogUpload extends DialogUpload {
formdata.append('uploadFormElement', file);
xhr.send(formdata);
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.MultipleDilaogUpload::addNewSubmitToMonitor()();
// reader.readAsText(file);
}
return false;

View File

@ -1,10 +1,14 @@
/**
*
*
*/
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import org.gcube.portlets.widgets.workspaceuploader.client.ClosableDialog;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
@ -41,13 +45,15 @@ import com.google.gwt.user.client.ui.VerticalPanel;
* Sep 7, 2015
*/
public class UploaderMonitor {
private static UploaderMonitor instance;
private final static HandlerManager monitorEventBus = new HandlerManager(null);
private MonitorPanel monitorPanel = new MonitorPanel(monitorEventBus);
private static Map<String, Timer> mapTimer = new HashMap<String, Timer>();
private static ArrayList<LinkedHashMap<String, WorkspaceUploaderItem>> queueUploads = new ArrayList<LinkedHashMap<String,WorkspaceUploaderItem>>();
private ClosableDialog dialogUploadMonitor = new ClosableDialog(monitorPanel, false, ConstantsWorkspaceUploader.MY_UPLOADS);
private Map<String, Timer> currentTimersRun = new HashMap<String, Timer>();
/**
* Gets the single instance of UploaderMonitor.
*
@ -59,7 +65,10 @@ public class UploaderMonitor {
}
return instance;
}
/**
* Instantiates a new uploader monitor.
*/
private UploaderMonitor(){
dialogUploadMonitor.setWidth("400px");
bindEvents();
@ -69,43 +78,63 @@ public class UploaderMonitor {
* Bind events.
*/
private void bindEvents() {
monitorEventBus.addHandler(CancelUploadEvent.TYPE, new CancelUploadEventHandler() {
@Override
public void onCancelUpload(final CancelUploadEvent deleteTimerEvent) {
if(deleteTimerEvent.getUploader()==null)
return;
String clientKey = deleteTimerEvent.getUploader().getClientUploadKey();
Timer timer = mapTimer.get(clientKey);
GWT.log("Delete timer "+timer);
if(timer!=null && timer.isRunning()){
timer.cancel();
mapTimer.put(clientKey, null);
final String clientKey = deleteTimerEvent.getUploader().getClientUploadKey();
final LinkedHashMap<String, WorkspaceUploaderItem> queue = getQueueFromClientUploadKey(clientKey);
if(queue==null){
GWT.log("onCancelUpload mapUpload is null for key: "+clientKey +", return");
return;
}
RequestBuilder request = new RequestBuilder(RequestBuilder.GET,
ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM+"?"+ConstantsWorkspaceUploader.CLIENT_UPLOAD_KEYS+"="+clientKey+"&"+ConstantsWorkspaceUploader.CANCEL_UPLOAD+"=true");
final Timer timer = getTimer(clientKey);
GWT.log("Client abort for timer with clientKey "+clientKey);
if(timer==null || !timer.isRunning()){
GWT.log("Timer abort skipping, timer for clientKey "+clientKey+" is null or not running");
return;
}
//CANCELLING TIMER
timer.cancel();
// queue.put(clientKey, null);
/*if(timer!=null && timer.isRunning()){
timer.cancel();
// mapUpload.put(clientKey, null);
GWT.log("Aborted WorkspaceUploaderItem for key: "+clientKey);
// removeTimer(clientKey);
}*/
RequestBuilder request = new RequestBuilder(RequestBuilder.GET, ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM+"?"+ConstantsWorkspaceUploader.CLIENT_UPLOAD_KEYS+"="+clientKey+"&"+ConstantsWorkspaceUploader.CANCEL_UPLOAD+"=true");
try {
request.sendRequest(null, new RequestCallback() {
@SuppressWarnings("incomplete-switch")
@Override
public void onResponseReceived(Request request, Response response) {
String strippedResult = new HTML(response.getText()).getText();
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(strippedResult);
switch (resultMessage.getStatus()) {
case ERROR: {
GWT.log("ERROR: Error during stop upload "+resultMessage.getMessage());
Window.alert("Sorry, An error occurred during upload abort!");
String result = response.getText();
GWT.log("onResponseReceived "+result);
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(result);
GWT.log("Cancel Upload Stream result: "+resultMessage);
if(resultMessage==null)
return;
}
case OK: {
switch(resultMessage.getStatus()){
case ERROR:{
GWT.log("ERROR: Error during stop upload "+resultMessage.getMessage());
Window.alert("Sorry, An error occurred during upload abort! "+resultMessage.getMessage());
break;
}
case OK:{
UploaderProgressView upv = deleteTimerEvent.getProgessView();
VerticalPanel vp = upv.getPanel();
VerticalPanel vp = upv!=null?upv.getPanel():null;
if(vp!=null){
vp.clear();
HTML html = new HTML();
@ -113,36 +142,132 @@ public class UploaderMonitor {
String text = "<div><img src='"+WorkspaceUploaderResources.getImageCancelRed().getUrl()+"'>";
text+="<span style='margin-left:5px; vertical-align: top;'>Upload "+deleteTimerEvent.getFileName()+ " aborted</span></div>";
html.setHTML(text);
//UPDATING STATUS AS ABORTED IN ORDER TO STOP THE TIMER
// WorkspaceUploaderItem workspaceUploader = mapUpload.get(clientKey);
// workspaceUploader.setUploadStatus(UPLOAD_STATUS.ABORTED);
// mapUpload.put(clientKey, workspaceUploader);
//UPDATING STATUS AS ABORTED IN ORDER TO STOP THE TIMER
GWT.log("Upload Aborted is OK");
timer.cancel();
// queue.remove(clientKey);
removeTimer(clientKey);
// int indexQueue = getQueueIndexFromClientUploadKey(clientKey);
// nextUploader(queue, indexQueue);
// queue.remove(clientKey);
// timer.cancel();
// removeTimer(clientKey);
// int indexQueue = getQueueIndexFromClientUploadKey(clientKey);
// nextUploader(queue, indexQueue);
deleteTimerEvent.getUploader().setUploadStatus(UPLOAD_STATUS.ABORTED);
notifyUploadAborted(deleteTimerEvent.getUploader().getFile().getParentId(), null);
}
break;
break;
}
}
case UNKNOWN:
case WARN:{
GWT.log("UNKNOWN/WARN CASE: Error during stop upload "+resultMessage.getMessage());
break;
}
}
// switch (resultMessage.getStatus()) {
// case ERROR: {
// GWT.log("ERROR: Error during stop upload "+resultMessage.getMessage());
// Window.alert("Sorry, An error occurred during upload abort! "+resultMessage.getMessage());
// break;
// }
// case OK: {
// UploaderProgressView upv = deleteTimerEvent.getProgessView();
// VerticalPanel vp = upv!=null?upv.getPanel():null;
// if(vp!=null){
// vp.clear();
// HTML html = new HTML();
// vp.add(html);
// String text = "<div><img src='"+WorkspaceUploaderResources.getImageCancelRed().getUrl()+"'>";
// text+="<span style='margin-left:5px; vertical-align: top;'>Upload "+deleteTimerEvent.getFileName()+ " aborted</span></div>";
// html.setHTML(text);
//UPDATING STATUS AS ABORTED IN ORDER TO STOP THE TIMER
// WorkspaceUploaderItem workspaceUploader = mapUpload.get(clientKey);
// workspaceUploader.setUploadStatus(UPLOAD_STATUS.ABORTED);
// mapUpload.put(clientKey, workspaceUploader);
// deleteTimerEvent.getUploader().setUploadStatus(UPLOAD_STATUS.ABORTED);
// notifyUploadAborted(deleteTimerEvent.getUploader().getFile().getParentId(), null);
// }
// break;
// }
// default:{
// GWT.log("UNKNOWN CASE: Error during stop upload "+resultMessage.getMessage());
// break;
// }
// }
}
@Override
public void onError(Request request, Throwable exception) {
GWT.log("ERROR: Error during stop upload "+exception.getMessage());
GWT.log("ERROR: Error during stop upload "+exception.getMessage());
}
});
} catch (RequestException e) {
GWT.log("RequestException: Error during stop upload "+e.getMessage());
GWT.log("RequestException: Error during stop upload "+e.getMessage());
}
}
});
monitorEventBus.addHandler(HideMonitorEvent.TYPE, new HideMonitorEventHandler() {
@Override
public void onHideMonitor(HideMonitorEvent hideMonitorEvent) {
dialogUploadMonitor.hide();
}
});
}
/**
* Gets the queue from client upload key.
*
* @param clientKey the client key
* @return the queue from client upload key, otherwise null;
*/
public LinkedHashMap<String, WorkspaceUploaderItem> getQueueFromClientUploadKey(String clientKey){
for (LinkedHashMap<String, WorkspaceUploaderItem> queue : queueUploads) {
if(queue!=null){
WorkspaceUploaderItem tm = queue.get(clientKey);
if(tm != null)
return queue;
}
}
return null;
}
/**
* Gets the queue index from client upload key.
*
* @param clientKey the client key
* @return the queue index from client upload key, otherwise -1;
*/
public int getQueueIndexFromClientUploadKey(String clientKey){
int index = -1;
for (LinkedHashMap<String, WorkspaceUploaderItem> queue : queueUploads) {
if(queue!=null){
index++;
WorkspaceUploaderItem tm = queue.get(clientKey);
if(tm != null)
return index;
}
}
return index;
}
/**
* Show monitor.
*/
@ -152,67 +277,69 @@ public class UploaderMonitor {
}
/**
* Adds the new submit.
* Adds the new uploader to monitor panel.
*
* @param uploader the uploader
* @param fileName the file name
*/
public void addNewSubmit(WorkspaceUploaderItem uploader, String fileName){
public void addNewUploaderToMonitorPanel(WorkspaceUploaderItem uploader, String fileName){
if(!dialogUploadMonitor.isShowing())
dialogUploadMonitor.center();
monitorPanel.newWorkspaceUploder(uploader, fileName);
}
/**
* Poll workspace uploader.
* Do polling.
*
* @param workspaceUploader the workspace uploader item
* @param workspaceUploader the workspace uploader
* @param queue the queue
* @param indexQueue the index queue
* @return the timer
*/
public void pollWorkspaceUploader(final WorkspaceUploaderItem workspaceUploader){
/*private void doPolling(final WorkspaceUploaderItem workspaceUploader){
Timer timer = new Timer() {
@Override
public void run() {
WorkspaceUploaderServiceAsync.Util.getInstance().getUploadStatus(workspaceUploader.getClientUploadKey(), new AsyncCallback<WorkspaceUploaderItem>() {
@Override
public void onSuccess(WorkspaceUploaderItem result) {
// GWT.log("onSuccess: "+result.toString());
// GWT.log("onSuccess: "+result.toString());
synchronized(this){
Timer tmn = mapTimer.get(workspaceUploader.getClientUploadKey());
Timer tmn = queueTimers.get(workspaceUploader.getClientUploadKey());
if(tmn!=null && tmn.isRunning()){
if(result.getUploadStatus().equals(UPLOAD_STATUS.COMPLETED)){
GWT.log("Upload Completed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
mapTimer.remove(tmn);
queueTimers.remove(tmn);
if(!result.getIsOverwrite())
notifyUploadCompleted(result.getFile().getParentId(), result.getFile().getItemId());
else
notifyOverwriteCompleted(result.getFile().getParentId(), result.getFile().getItemId());
cancel();
}else if(result.getUploadStatus().equals(UPLOAD_STATUS.FAILED)){
GWT.log("Upload Failed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
mapTimer.remove(tmn);
queueTimers.remove(tmn);
notifyUploadError(result.getFile().getParentId(), null, null);
// new DialogResult(null, "Upload Failed!!", result.getStatusDescription()).center();
// new DialogResult(null, "Upload Failed!!", result.getStatusDescription()).center();
cancel();
}
monitorPanel.updateWorkspaceUploder(result);
// GWT.log(result.toString());
// GWT.log(result.toString());
}else{
GWT.log("Timer is null or already closed or completed");
cancel();
}
}
}
@Override
public void onFailure(Throwable caught) {
GWT.log("onFailure: "+caught.getMessage());
@ -220,13 +347,126 @@ public class UploaderMonitor {
cancel();
}
});
}
};
mapTimer.put(workspaceUploader.getClientUploadKey(), timer);
queueTimers.put(workspaceUploader.getClientUploadKey(), timer);
timer.scheduleRepeating(2000);
}*/
public void startTimer(final WorkspaceUploaderItem workspaceUploader, final LinkedHashMap<String, WorkspaceUploaderItem> queue, final int indexQueue){
final Timer timer = new Timer() {
@Override
public void run() {
WorkspaceUploaderServiceAsync.Util.getInstance().getUploadStatus(workspaceUploader.getClientUploadKey(), new AsyncCallback<WorkspaceUploaderItem>() {
@Override
public void onSuccess(WorkspaceUploaderItem result) {
// GWT.log("onSuccess: "+result.toString());
synchronized(this){
// Timer tmn = queue.get(workspaceUploader.getClientUploadKey());
if(isRunning()){
if(result.getUploadStatus()==null){
GWT.log("Upload status is null for: "+workspaceUploader.getClientUploadKey());
return;
}
if(result.getUploadStatus().equals(UPLOAD_STATUS.COMPLETED)){
GWT.log("Upload Completed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
queue.remove(workspaceUploader.getClientUploadKey());
if(!result.getIsOverwrite())
notifyUploadCompleted(result.getFile().getParentId(), result.getFile().getItemId());
else
notifyOverwriteCompleted(result.getFile().getParentId(), result.getFile().getItemId());
cancel();
removeTimer(workspaceUploader.getClientUploadKey());
nextUploader(queue, indexQueue);
}else if(result.getUploadStatus().equals(UPLOAD_STATUS.FAILED)){
GWT.log("Upload Failed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
queue.remove(workspaceUploader.getClientUploadKey());
notifyUploadError(result.getFile().getParentId(), null, null);
// new DialogResult(null, "Upload Failed!!", result.getStatusDescription()).center();
cancel();
removeTimer(workspaceUploader.getClientUploadKey());
nextUploader(queue, indexQueue);
}
// }else if(result.getUploadStatus().equals(UPLOAD_STATUS.ABORTED)){
// GWT.log("Upload Aborted "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
// cancel();
// removeTimer(workspaceUploader.getClientUploadKey());
// nextUploader(queue, indexQueue);
// }
monitorPanel.updateWorkspaceUploder(result);
// GWT.log(result.toString());
}else{
GWT.log("Timer is null or already closed or completed");
cancel();
removeTimer(workspaceUploader.getClientUploadKey());
nextUploader(queue, indexQueue);
}
}
}
@Override
public void onFailure(Throwable caught) {
GWT.log("onFailure: "+caught.getMessage());
cancel();
notifyUploadError(workspaceUploader.getFile().getParentId(), null, caught);
removeTimer(workspaceUploader.getClientUploadKey());
}
});
}
};
GWT.log("Starting new timer for key: "+workspaceUploader.getClientUploadKey());
saveTimer(timer, workspaceUploader.getClientUploadKey());
timer.scheduleRepeating(2000);
}
/**
* Removes the timer.
*
* @param clientKey the client key
*/
private synchronized void removeTimer(String clientKey){
Timer timer = currentTimersRun.get(clientKey);
if(timer!=null){
currentTimersRun.remove(clientKey);
GWT.log("Remove timer for key: "+clientKey+", performed correctly");
}else
GWT.log("Remove timer for key: "+clientKey+", skypped, already removed?");
}
/**
* Save timer.
*
* @param timer the timer
* @param clientKey the client key
*/
private synchronized void saveTimer(Timer timer, String clientKey){
currentTimersRun.put(clientKey, timer);
}
/**
* Gets the timer.
*
* @param clientKey the client key
* @return the timer
*/
private Timer getTimer(String clientKey){
return currentTimersRun.get(clientKey);
}
/**
* Notify upload completed.
*
@ -237,7 +477,7 @@ public class UploaderMonitor {
GWT.log("notifyOverwriteCompleted in monitor");
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.OVERWRITE_COMPLETED, parentId, itemId));
}
/**
* Notify upload completed.
*
@ -248,7 +488,7 @@ public class UploaderMonitor {
GWT.log("notifyUploadCompleted in monitor");
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.UPLOAD_COMPLETED, parentId, itemId));
}
/**
* Notify upload aborted.
*
@ -258,7 +498,7 @@ public class UploaderMonitor {
private void notifyUploadAborted(String parentId, String itemId){
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.ABORTED, parentId, itemId));
}
/**
* Notify upload error.
*
@ -269,4 +509,135 @@ public class UploaderMonitor {
private void notifyUploadError(String parentId, String itemId, Throwable t){
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.FAILED, parentId, itemId, t));
}
/**
* New queue.
*
* @return the int
*/
public synchronized int newQueue() {
int freeIndex = -1;
GWT.log("Current queue upload size is: "+queueUploads.size());
for(int i = 0; i < queueUploads.size(); i++){
if(queueUploads.get(i) == null){
freeIndex = i;
break;
}
}
GWT.log("Index for new queue uploads is: "+freeIndex);
if(freeIndex>=0 && freeIndex<queueUploads.size()){
GWT.log("Using set index: "+freeIndex);
queueUploads.set(freeIndex, new LinkedHashMap<String,WorkspaceUploaderItem>());
}else{
freeIndex= queueUploads.size();
GWT.log("Using add index: "+freeIndex);
queueUploads.add(freeIndex, new LinkedHashMap<String,WorkspaceUploaderItem>());
}
GWT.log("Returning new queue index: "+freeIndex);
return freeIndex;
}
/**
* Delete queue.
*
* @param index the index
*/
public synchronized void deleteQueue(int index) {
if(index<0){
GWT.log("Delete queue at invalid index: "+index +", skipping delete");
return;
}
if(queueUploads.get(index)!=null){
queueUploads.set(index, null);
GWT.log("Deleted queue at index: "+index);
}else
GWT.log("Queue at index: "+index +", not found, already deleted?, skipping");
}
/**
* Adds the new timer to queue.
*
* @param indexQueue the index queue
* @param workspaceUploaderItem the workspace uploader item
*/
public void addNewTimerToQueue(int indexQueue, WorkspaceUploaderItem workspaceUploaderItem) {
LinkedHashMap<String, WorkspaceUploaderItem> queue = queueUploads.get(indexQueue);
queue.put(workspaceUploaderItem.getClientUploadKey(), workspaceUploaderItem);
}
/**
* Do start polling queue.
*
* @param index the index
*/
public synchronized void doStartPollingQueue(int index) {
LinkedHashMap<String, WorkspaceUploaderItem> queue = queueUploads.get(index);
if(queue.size()<0){
GWT.log("doStartPollingQueue return, queue size is < 0");
return;
}
Set<String> keys = queue.keySet();
if(keys.size()==0){
GWT.log("no keys for queue index: "+index+", return");
return;
}
WorkspaceUploaderItem workspaceUploader = getNextUploader(queue);
startTimer(workspaceUploader, queue, index);
}
/**
* Gets the next uploader.
*
* @param queue the queue
* @return the next uploader
*/
public WorkspaceUploaderItem getNextUploader(LinkedHashMap<String, WorkspaceUploaderItem> queue){
Iterator<String> it = queue.keySet().iterator();
String firstKey = it.next();
if(firstKey==null || firstKey.isEmpty()){
GWT.log("getNextUploader return empty or null key, returning null");
return null;
}
return queue.get(firstKey);
}
/**
* Next uploader.
*
* @param queue the queue
* @param indexQueue the index queue
*/
public synchronized void nextUploader(LinkedHashMap<String, WorkspaceUploaderItem> queue, int indexQueue){
if(queue.keySet().size()==0){
GWT.log("nextUploader return, queue size is = 0, deleting queue");
deleteQueue(indexQueue);
return;
}
WorkspaceUploaderItem workspaceUploader = getNextUploader(queue);
if(workspaceUploader==null){
GWT.log("nextUploader return a null uploader, deleting queue");
deleteQueue(indexQueue);
return;
}
startTimer(workspaceUploader, queue, indexQueue);
}
}

View File

@ -1,5 +1,5 @@
/**
*
*
*/
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
@ -28,7 +28,7 @@ import com.google.gwt.user.client.ui.VerticalPanel;
* Oct 12, 2015
*/
public class UploaderProgressView {
private VerticalPanel vp = new VerticalPanel();
private static final int MAX_CHARS = 50;
private HorizontalPanel hp = new HorizontalPanel();
@ -38,7 +38,7 @@ public class UploaderProgressView {
private HandlerManager eventBus;
private boolean cancel = false;
private Image cancelImg = null;
/**
* Instantiates a new uploader progress view.
*
@ -53,27 +53,27 @@ public class UploaderProgressView {
cancelImg.addStyleName("cancel-upload");
hpBar.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
String text = "<div><img src='"+WorkspaceUploaderResources.getImageLoading().getUrl()+"'>";
String msg = StringUtil.ellipsize("Uploading "+fileName, MAX_CHARS, 0);
text+="<span style='margin-left:5px; vertical-align: top;'>"+msg+"</span>";
text+="</div>";
html.setHTML(text);
html.setTitle("Uploading "+fileName);
hp.add(html);
bar.update(0);
setVisibleBar(false);
setVisibleCancel(false);
vp.add(hp);
hpBar.add(cancelImg);
hpBar.add(bar);
vp.add(hpBar);
// vp.add(bar);
}
/**
* @param b
*/
@ -84,7 +84,7 @@ public class UploaderProgressView {
public void setVisibleBar(boolean bool){
bar.setVisible(bool);
}
/**
* Update.
*
@ -92,80 +92,84 @@ public class UploaderProgressView {
*/
public void update(WorkspaceUploaderItem uploader){
String text;
switch(uploader.getUploadStatus()){
case COMPLETED:
setVisibleBar(true);
text = "<div><img src='"+WorkspaceUploaderResources.getImageCompleted().getUrl()+"'>";
text+="<span style='margin-left:5px; vertical-align: top;'>"+StringUtil.ellipsize(uploader.getFile().getFileName()+" uploaded successfully!", MAX_CHARS, 0)+"</span></div>";
// GWT.log(text);
html.setHTML(text);
html.setTitle(uploader.getStatusDescription());
bar.update(uploader.getUploadProgress().getLastEvent().getReadPercentage());
try{
hpBar.clear();
}catch (Exception e) {}
break;
case FAILED:
setVisibleBar(true);
text = "<div><img src='"+WorkspaceUploaderResources.getImageFailed().getUrl()+"'>";
text+="<span style='margin-left:5px; vertical-align: top;'>"+StringUtil.ellipsize(uploader.getStatusDescription(), MAX_CHARS, 0)+"</span></div>";
// GWT.log(text);
html.setHTML(text);
html.setTitle(uploader.getStatusDescription());
// bar.update(uploader.getUploadProgress().getLastEvent().getReadPercentage());
try{
hpBar.clear();
}catch (Exception e) {}
break;
case IN_PROGRESS:
setVisibleBar(true);
// text = "<div><img src='"+WorkspaceUploaderResources.getImageUpload().getUrl()+"'>";
text = "<div><img src='"+WorkspaceUploaderResources.getImageLoading().getUrl()+"'>";
String msg = StringUtil.ellipsize(uploader.getFile().getFileName(), MAX_CHARS, 0);
text+="<span style='margin-left:5px; vertical-align: top;'>"+msg+"</span>";
text+="</div>";
// GWT.log(text);
html.setHTML(text);
html.setTitle(uploader.getStatusDescription());
if(uploader.getUploadProgress().getLastEvent().getReadPercentage()!=100 && !cancel){
cancel = true;
handleCancelUpload(uploader);
setVisibleCancel(true);
}else if(uploader.getUploadProgress().getLastEvent().getReadPercentage()==100 && cancel){
try{
setVisibleCancel(false);
// hp.remove(cancelImg);
}catch (Exception e) {}
}
bar.update(uploader.getUploadProgress().getLastEvent().getReadPercentage());
break;
case WAIT:
setVisibleBar(false);
text = "<div><img src='"+WorkspaceUploaderResources.getImageLoading().getUrl()+"'>";
String descr = "";
if(uploader.getFile()!=null && uploader.getFile().getFileName()!=null)
descr = uploader.getFile().getFileName();
else
descr = uploader.getStatusDescription();
text+="<span style='margin-left:5px; vertical-align: top;'>"+StringUtil.ellipsize(descr, MAX_CHARS, 0)+"</span></div>";
text+="</div>";
// GWT.log(text);
html.setHTML(text);
if(uploader.getUploadProgress()!=null && uploader.getUploadProgress().getLastEvent()!=null)
try{
switch(uploader.getUploadStatus()){
case COMPLETED:
setVisibleBar(true);
text = "<div><img src='"+WorkspaceUploaderResources.getImageCompleted().getUrl()+"'>";
text+="<span style='margin-left:5px; vertical-align: top;'>"+StringUtil.ellipsize(uploader.getFile().getFileName()+" uploaded successfully!", MAX_CHARS, 0)+"</span></div>";
// GWT.log(text);
html.setHTML(text);
html.setTitle(uploader.getStatusDescription());
bar.update(uploader.getUploadProgress().getLastEvent().getReadPercentage());
else
bar.update(0);
break;
default:
break;
try{
hpBar.clear();
}catch (Exception e) {}
break;
case FAILED:
setVisibleBar(true);
text = "<div><img src='"+WorkspaceUploaderResources.getImageFailed().getUrl()+"'>";
text+="<span style='margin-left:5px; vertical-align: top;'>"+StringUtil.ellipsize(uploader.getStatusDescription(), MAX_CHARS, 0)+"</span></div>";
// GWT.log(text);
html.setHTML(text);
html.setTitle(uploader.getStatusDescription());
// bar.update(uploader.getUploadProgress().getLastEvent().getReadPercentage());
try{
hpBar.clear();
}catch (Exception e) {}
break;
case IN_PROGRESS:
setVisibleBar(true);
// text = "<div><img src='"+WorkspaceUploaderResources.getImageUpload().getUrl()+"'>";
text = "<div><img src='"+WorkspaceUploaderResources.getImageLoading().getUrl()+"'>";
String msg = StringUtil.ellipsize(uploader.getFile().getFileName(), MAX_CHARS, 0);
text+="<span style='margin-left:5px; vertical-align: top;'>"+msg+"</span>";
text+="</div>";
// GWT.log(text);
html.setHTML(text);
html.setTitle(uploader.getStatusDescription());
if(uploader.getUploadProgress().getLastEvent().getReadPercentage()!=100 && !cancel){
cancel = true;
handleCancelUpload(uploader);
setVisibleCancel(true);
}else if(uploader.getUploadProgress().getLastEvent().getReadPercentage()==100 && cancel){
try{
setVisibleCancel(false);
// hp.remove(cancelImg);
}catch (Exception e) {}
}
bar.update(uploader.getUploadProgress().getLastEvent().getReadPercentage());
break;
case WAIT:
setVisibleBar(false);
text = "<div><img src='"+WorkspaceUploaderResources.getImageLoading().getUrl()+"'>";
String descr = "";
if(uploader.getFile()!=null && uploader.getFile().getFileName()!=null)
descr = uploader.getFile().getFileName();
else
descr = uploader.getStatusDescription();
text+="<span style='margin-left:5px; vertical-align: top;'>"+StringUtil.ellipsize(descr, MAX_CHARS, 0)+"</span></div>";
text+="</div>";
// GWT.log(text);
html.setHTML(text);
if(uploader.getUploadProgress()!=null && uploader.getUploadProgress().getLastEvent()!=null)
bar.update(uploader.getUploadProgress().getLastEvent().getReadPercentage());
else
bar.update(0);
break;
default:
break;
}
}catch(Exception e) {
GWT.log("error during update");
}
}
/**
* Handle cancel upload.
*
@ -175,7 +179,7 @@ public class UploaderProgressView {
private Image handleCancelUpload(final WorkspaceUploaderItem uploader){
cancelImg.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
GWT.log("Click cancel");
@ -194,7 +198,7 @@ public class UploaderProgressView {
});
return cancelImg;
}
/**
* Gets the panel.

View File

@ -1,5 +1,5 @@
/**
*
*
*/
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
@ -24,13 +24,13 @@ import com.google.gwt.user.client.Window;
* Oct 20, 2015
*/
public class WorkspaceFieldsUploadManager {
//FORM FIELD TO UPLOAD INTO WORKSPACE
private String jsonKeys;
public static final String FILE_DELEMITER = ";";
private List<WorkspaceUploaderItem> fakeUploaders = new ArrayList<WorkspaceUploaderItem>();
public WorkspaceFieldsUploadManager() {
}
@ -41,29 +41,32 @@ public class WorkspaceFieldsUploadManager {
* @return true, if is limit exceeded
*/
public boolean isLimitExceeded(int numbOfFiles){
if (numbOfFiles > ConstantsWorkspaceUploader.LIMIT_UPLOADS) {
Window.alert("Multiple upload limit is "
+ ConstantsWorkspaceUploader.LIMIT_UPLOADS
+ " files");
return true;
}
return false;
}
}
/**
* Adds the new submit to monitor.
*/
public void addNewSubmitToMonitor(){
GWT.log("addNewSubmitToMonitor...");
int queueIndex = UploaderMonitor.getInstance().newQueue();
for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
UploaderMonitor.getInstance().addNewSubmit(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
UploaderMonitor.getInstance().addNewTimerToQueue(queueIndex, workspaceUploaderItem);
// UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
}
UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);
}
/**
* Creates the json key for files.
*
@ -76,14 +79,14 @@ public class WorkspaceFieldsUploadManager {
JSONArray jsonArray = new JSONArray();
productObj.put(ConstantsWorkspaceUploader.JSON_CLIENT_KEYS, jsonArray);
// GWT.log("Creating json keys on fakeUploaders: "+fakeUploaders.toString());
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()));
jsonArray.set(i, obj);
}
jsonKeys = productObj.toString();
GWT.log("updated jsonKeys: "+jsonKeys);
} catch (Exception e) {
@ -91,7 +94,7 @@ public class WorkspaceFieldsUploadManager {
jsonKeys = null;
}
}
/**
* Generate new upload client keys.
*
@ -100,12 +103,12 @@ public class WorkspaceFieldsUploadManager {
* @return the list
*/
public void generateFakeUploaders(String filesSelected, String parentId) {
if(filesSelected==null || filesSelected.isEmpty())
return;
String[] files = filesSelected.split(FILE_DELEMITER);
// NORMALIZE FILE NAMES
for (int i = 0; i < files.length; i++) {
String normalizedFileName = files[i];
@ -116,7 +119,7 @@ public class WorkspaceFieldsUploadManager {
// exists
}
}
GWT.log("generating fake uploaders on: "+files.toString());
fakeUploaders = new ArrayList<WorkspaceUploaderItem>(files.length);
for (int i = 0; i < files.length; i++) {
@ -129,10 +132,10 @@ public class WorkspaceFieldsUploadManager {
fakeItem.setFile(fakeFile);
fakeUploaders.add(fakeItem);
}
GWT.log("fakeUploaders generated: "+fakeUploaders.toString());
}
/**
* @return the jsonKeys

View File

@ -1,5 +1,5 @@
/**
*
*
*/
package org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop;
@ -37,10 +37,10 @@ public class MultipleDNDUpload extends LayoutPanel implements
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;
@ -64,14 +64,14 @@ public class MultipleDNDUpload extends LayoutPanel implements
// ScriptInjector.fromUrl("workspaceuploader/dndhtmlfileupload.js")
// .setWindow(ScriptInjector.TOP_WINDOW).inject();
}
/* (non-Javadoc)
* @see com.google.gwt.user.client.ui.LayoutPanel#onAttach()
*/
@Override
protected void onAttach() {
super.onAttach();
if(onlyChild!=null){
onlyChild.getElement().setId("drop_target_only_child");
}
@ -129,7 +129,7 @@ public class MultipleDNDUpload extends LayoutPanel implements
/*
* (non-Javadoc)
*
*
* @see com.google.gwt.user.client.ui.Widget#onLoad()
*/
@Override
@ -161,7 +161,7 @@ public class MultipleDNDUpload extends LayoutPanel implements
Window.alert("Multiple upload limit is "
+ ConstantsWorkspaceUploader.LIMIT_UPLOADS + " files");
return isLimitExceeded = true;
}
return isLimitExceeded = false;
@ -307,19 +307,26 @@ 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');
function isFileOverwrite(url, params, msgText){
var xhReq = new XMLHttpRequest();
xhReq.open("GET", url+"?"+params, false); //SYNCRONUS CALL
xhReq.send(msgText);
if(xhReq.status==200){
console.log(xhReq.responseText);
return xhReq.responseText;
}else
if(xhReq.readyState==4 && xhReq.status==200) {
var content = xhReq.responseText;
console.log("responseText:" +content);
if(content!=undefined && content=='null'){
console.log("isFileOverwrite response ok, responseText is null, returning null");
return null;
}else{
console.log("isFileOverwrite response ok, responseText "+content);
return content;
}
}else if(xhReq.readyState==4 && xhReq.status!=200){
console.log("isFileOverwrite error on status, returning null");
return null;
}
}
function generateUUID() {
@ -335,16 +342,6 @@ public class MultipleDNDUpload extends LayoutPanel implements
//DROP CHECK IF CONTAINS FILES
function containsFiles(items) {
// if (dataTransfer.types) {
// for (var i = 0; i < dataTransfer.types.length; i++) {
// console.log("dataTransfer.types[i] "+dataTransfer.types[i]);
// if (dataTransfer.types[i] != "Files") {
// return false;
// }
// }
// }
// return true;
if (items) {
for (i = 0; i < items.length; i++) {
@ -374,7 +371,7 @@ public class MultipleDNDUpload extends LayoutPanel implements
console.log("before load");
var drop = $wnd.$('#drop_target')[0];
$wnd.$('#drop_target_outer')[0].style.display = "none";
console.log("drop is " + drop);
function cancel(e) {
@ -425,7 +422,7 @@ public class MultipleDNDUpload extends LayoutPanel implements
$wnd.$('#drop_target_inner')[0].className = "";
// $wnd.$('#drop_target_only_child')[0].style.display = "none";
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::setVisibleOnlyChild(Z)(false);
e.preventDefault();
if (containsFiles(e)) {
console.log("The drag event contains files");
@ -456,7 +453,7 @@ public class MultipleDNDUpload extends LayoutPanel implements
e = e || window.event; // get window.event if e argument missing (in IE)
if (e.preventDefault) {
e.preventDefault();
} //
} //
console.log('dragover');
drop.className = "over-true";
$wnd.$('#drop_target_outer')[0].style.display = "";
@ -523,19 +520,19 @@ public class MultipleDNDUpload extends LayoutPanel implements
}
console.log("# of file/s: " + files.length);
var numFolder = 0;
for (var i = 0; i < files.length; i++) {
var file = files[i];
var filesSelected = files[i].name + fileDelimiter;
if (!isFolder(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);
@ -543,27 +540,27 @@ public class MultipleDNDUpload extends LayoutPanel implements
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);
@ -578,8 +575,8 @@ public class MultipleDNDUpload extends LayoutPanel implements
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);
var response = isFileOverwrite(wsUtil, params, "");
console.log("response overwrite: " + response);
if(response!=null && response!=undefined){
console.log("overwrite confirm?");
if($wnd.confirm(files[i].name+" exists in folder. Overwrite?")){
@ -588,22 +585,22 @@ public class MultipleDNDUpload extends LayoutPanel implements
}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++;
}
}
if(numFolder>0){
var msg;
if(numFolder==files.length){
@ -611,7 +608,7 @@ public class MultipleDNDUpload extends LayoutPanel implements
instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::showAlert(Ljava/lang/String;)(msg);
return;
}
var msg = "Ignored ";
msg += numFolder > 1? numFolder+" folders": numFolder+" folder";
msg+= " during upload";
@ -636,7 +633,7 @@ public class MultipleDNDUpload extends LayoutPanel implements
*/
public static native void test(String parentIdentifier, String name)/*-{
var servlet = instance.@org.gcube.portlets.widgets.workspaceuploader.client.uploader.dragdrop.MultipleDNDUpload::service;
var jqxhr = $.get("itemExistsInWorkpaceFolder?", function() {
alert( "success" );
})
@ -658,7 +655,7 @@ public class MultipleDNDUpload extends LayoutPanel implements
/*
* (non-Javadoc)
*
*
* @see org.gcube.portlets.widgets.workspaceuploader.client.
* WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#
* addWorkspaceUploadNotificationListener
@ -673,7 +670,7 @@ public class MultipleDNDUpload extends LayoutPanel implements
/*
* (non-Javadoc)
*
*
* @see org.gcube.portlets.widgets.workspaceuploader.client.
* WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#
* removeWorkspaceUploadNotificationListener

View File

@ -65,11 +65,12 @@ import org.json.JSONTokener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class WorkspaceUploadServletStream.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jan 21, 2014
* May 10, 2016
*/
public class WorkspaceUploadServletStream extends HttpServlet implements Servlet{
@ -138,7 +139,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
logger.debug("GET method CANCEL_UPLOAD "+cancelUpload);
if (cancelUpload) {
cancelUpload(request.getSession(), clientUploadKey);
sendMessage(response, "Upload abort: "+request.getParameter(CANCEL_UPLOAD));
sendMessage(response, "Upload aborted "+clientUploadKey);
}else
logger.debug(CANCEL_UPLOAD + " param not found");
// }else
@ -544,6 +545,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
* @param clientUploadKey the client upload key
* @param folderParentId the folder parent id
* @param fileName the file name
* @param isOverwrite the is overwrite
* @return the workspace uploader item
*/
private WorkspaceUploaderItem createNewWorkspaceUploader(String clientUploadKey, String folderParentId, String fileName, boolean isOverwrite){
@ -837,6 +839,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
protected void sendMessage(HttpServletResponse response, String message) throws IOException{
try {
response.setStatus(HttpServletResponse.SC_ACCEPTED);
message = message.replaceAll(":", "");
HandlerResultMessage resultMessage = HandlerResultMessage.okResult(message);
response.getWriter().write(resultMessage.toString());
//5.6 Closure of Response Object:
@ -964,21 +967,4 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
}else
logger.warn("Listener "+clientUploadKey+ "is null");
}
/**
* The main method.
*
* @param args the arguments
*/
/*
public static void main(String[] args) {
try {
parseJSONClientUploadKeys("{\"ClientKeys\":[{\"3D6CAAEFF9241F6\":\"bookmarks.xml\"}, {\"69E9907A78AD20B\":\"WFS\"}]}");
} catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}*/
}

View File

@ -45,7 +45,7 @@ public class WorkspaceUploaderWsUtil extends HttpServlet {
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)
*/
@ -65,14 +65,14 @@ public class WorkspaceUploaderWsUtil extends HttpServlet {
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);
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();
}
@ -85,7 +85,7 @@ public class WorkspaceUploaderWsUtil extends HttpServlet {
throw new Exception(e.getMessage());
}
}
/**
* Send error.
@ -109,7 +109,7 @@ public class WorkspaceUploaderWsUtil extends HttpServlet {
throw e; //Sending Exceptions
}
}
/**
* Send message.
@ -121,6 +121,9 @@ public class WorkspaceUploaderWsUtil extends HttpServlet {
protected void sendOKMessage(HttpServletResponse response, String message) throws IOException{
try {
response.setStatus(HttpServletResponse.SC_OK);
response.setContentType("text/xml");
if(message==null)
message="null";
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
@ -133,5 +136,5 @@ public class WorkspaceUploaderWsUtil extends HttpServlet {
throw e; //Sending Exceptions
}
}
}

View File

@ -1,5 +1,5 @@
/**
*
*
*/
package org.gcube.portlets.widgets.workspaceuploader.shared;
@ -10,15 +10,18 @@ import java.io.Serializable;
* The Class HandlerResultMessage.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Aug 3, 2015
* May 10, 2016
*/
public class HandlerResultMessage implements Serializable{
protected Status status;
protected String message;
/**
*
*
*/
private static final long serialVersionUID = -4607236625671465107L;
private static final long serialVersionUID = -7652344136772252755L;
/**
* The Enum Status.
@ -32,20 +35,37 @@ public class HandlerResultMessage implements Serializable{
*/
ERROR,
/**
* If no error occurs.
* If no error occurs.
*/
OK,
/**
* If there was some problems.
*/
WARN,
/**
* If the result is unknown.
*/
UNKNOWN;
}
/**
* TO SERIALIZATION
*/
public HandlerResultMessage() {
}
/**
* Create a new result message.
* @param status the status.
* @param message the message.
*/
public HandlerResultMessage(Status status, String message) {
this.status = status;
this.message = message;
}
/**
* Error result.
*
@ -55,7 +75,7 @@ public class HandlerResultMessage implements Serializable{
public static HandlerResultMessage errorResult(String message){
return new HandlerResultMessage(Status.ERROR, message);
}
/**
* Ok result.
*
@ -65,7 +85,7 @@ public class HandlerResultMessage implements Serializable{
public static HandlerResultMessage okResult(String message){
return new HandlerResultMessage(Status.OK, message);
}
/**
* Warn result.
*
@ -75,18 +95,21 @@ public class HandlerResultMessage implements Serializable{
public static HandlerResultMessage warnResult(String message){
return new HandlerResultMessage(Status.WARN, message);
}
/**
* Parses the result.
*
* expected status:message (e.g. OK:Upload aborted)
* @param result the result
* @return the handler result message
*/
public static HandlerResultMessage parseResult(String result){
//expected 200:Upload complete
//expected status:message
String statusToken = null;
String messageToken = null;
if(result==null || result.isEmpty())
return errorResult("result is null or empty");
int index = result.indexOf(':');
if (index>0){
statusToken = result.substring(0,index);
@ -94,30 +117,20 @@ public class HandlerResultMessage implements Serializable{
messageToken = result.substring(index+1);
}
}
Status status = Status.UNKNOWN;
if (statusToken!=null){
status = Status.valueOf(statusToken);
try{
status = Status.valueOf(statusToken);
}catch (Exception e) {
status = Status.UNKNOWN;
}
}
String message = (messageToken!=null)?messageToken:"";
String message = messageToken!=null?messageToken:"";
return new HandlerResultMessage(status, message);
}
protected Status status;
protected String message;
/**
* Create a new result message.
* @param status the status.
* @param message the message.
*/
public HandlerResultMessage(Status status, String message) {
this.status = status;
this.message = message;
}
/**
@ -149,6 +162,4 @@ public class HandlerResultMessage implements Serializable{
builder.append(message);
return builder.toString();
}
}