3962: Workspace Uploader improvements: use a sequential get status instead of parallel during (multiple-)uploads
Task-Url: https://support.d4science.org/issues/3962 Fixed problem on cancel during multiple-uploads git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@128570 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
aa74220a50
commit
2890a420d7
|
@ -243,10 +243,12 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
|
||||||
enableButtons(false);
|
enableButtons(false);
|
||||||
WorkspaceUploaderItem fakeUploader = new WorkspaceUploaderItem();
|
WorkspaceUploaderItem fakeUploader = new WorkspaceUploaderItem();
|
||||||
fakeUploader.setClientUploadKey(clientUploadKey);
|
fakeUploader.setClientUploadKey(clientUploadKey);
|
||||||
|
int queueIndex = UploaderMonitor.getInstance().newQueue();
|
||||||
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(fakeUploader, fileUpload.getFilename());
|
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(fakeUploader, fileUpload.getFilename());
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
removeLoading();
|
removeLoading();
|
||||||
// UploaderMonitor.getInstance().pollWorkspaceUploader(fakeUploader);
|
UploaderMonitor.getInstance().addNewUploaderToQueue(queueIndex, fakeUploader);
|
||||||
|
UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -278,7 +278,7 @@ public class MultipleDilaogUpload extends DialogUpload {
|
||||||
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
|
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
removeLoading();
|
removeLoading();
|
||||||
UploaderMonitor.getInstance().addNewTimerToQueue(queueIndex, workspaceUploaderItem);
|
UploaderMonitor.getInstance().addNewUploaderToQueue(queueIndex, workspaceUploaderItem);
|
||||||
// UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
|
// UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,124 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
|
||||||
|
|
||||||
|
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderServiceAsync;
|
||||||
|
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
|
||||||
|
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem.UPLOAD_STATUS;
|
||||||
|
|
||||||
|
import com.google.gwt.core.shared.GWT;
|
||||||
|
import com.google.gwt.user.client.Timer;
|
||||||
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Class TimerUpload.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* May 11, 2016
|
||||||
|
*/
|
||||||
|
public class TimerUpload extends Timer{
|
||||||
|
|
||||||
|
/** The workspace uploader. */
|
||||||
|
private WorkspaceUploaderItem workspaceUploader;
|
||||||
|
private UploaderMonitor monitor;
|
||||||
|
private TimerUpload INSTANCE = this;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiates a new timer upload.
|
||||||
|
*
|
||||||
|
* @param workspaceUploader the workspace uploader
|
||||||
|
* @param queue the queue
|
||||||
|
* @param indexQueue the index queue
|
||||||
|
*/
|
||||||
|
public TimerUpload(WorkspaceUploaderItem workspaceUploader) {
|
||||||
|
this.workspaceUploader = workspaceUploader;
|
||||||
|
this.monitor = UploaderMonitor.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see com.google.gwt.user.client.Timer#run()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
WorkspaceUploaderServiceAsync.Util.getInstance().getUploadStatus(workspaceUploader.getClientUploadKey(), new AsyncCallback<WorkspaceUploaderItem>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(WorkspaceUploaderItem result) {
|
||||||
|
try{
|
||||||
|
synchronized(this){
|
||||||
|
// Timer tmn = queue.get(workspaceUploader.getClientUploadKey());
|
||||||
|
if(INSTANCE!=null && INSTANCE.isRunning()){
|
||||||
|
if(result==null || result.getUploadStatus()==null){
|
||||||
|
GWT.log("Upload or status its 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());
|
||||||
|
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
|
||||||
|
|
||||||
|
if(!result.getIsOverwrite())
|
||||||
|
monitor.notifyUploadCompleted(result.getFile().getParentId(), result.getFile().getItemId());
|
||||||
|
else
|
||||||
|
monitor.notifyOverwriteCompleted(result.getFile().getParentId(), result.getFile().getItemId());
|
||||||
|
|
||||||
|
cancel();
|
||||||
|
monitor.goNextUploaderAfterKey(workspaceUploader.getClientUploadKey());
|
||||||
|
}else if(result.getUploadStatus().equals(UPLOAD_STATUS.FAILED)){
|
||||||
|
GWT.log("Upload Failed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||||
|
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
|
||||||
|
// queue.remove(workspaceUploader.getClientUploadKey());
|
||||||
|
monitor.notifyUploadError(result.getFile().getParentId(), null, null);
|
||||||
|
// new DialogResult(null, "Upload Failed!!", result.getStatusDescription()).center();
|
||||||
|
|
||||||
|
cancel();
|
||||||
|
monitor.goNextUploaderAfterKey(workspaceUploader.getClientUploadKey());
|
||||||
|
}else if(result.getUploadStatus().equals(UPLOAD_STATUS.ABORTED)){
|
||||||
|
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
|
||||||
|
GWT.log("Upload Aborted "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||||
|
cancel();
|
||||||
|
monitor.goNextUploaderAfterKey(workspaceUploader.getClientUploadKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
monitor.getMonitorPanel().updateWorkspaceUploder(result);
|
||||||
|
// GWT.log(result.toString());
|
||||||
|
}else{
|
||||||
|
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
|
||||||
|
GWT.log("Timer is null or already closed or completed");
|
||||||
|
cancel();
|
||||||
|
monitor.goNextUploaderAfterKey(workspaceUploader.getClientUploadKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch(Exception e){
|
||||||
|
GWT.log("getUploadStatus exception "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable caught) {
|
||||||
|
GWT.log("onFailure: "+caught.getMessage());
|
||||||
|
cancel();
|
||||||
|
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
|
||||||
|
monitor.goNextUploaderAfterKey(workspaceUploader.getClientUploadKey());
|
||||||
|
monitor.notifyUploadError(workspaceUploader.getFile().getParentId(), null, caught);
|
||||||
|
// removeTimer(workspaceUploader.getClientUploadKey());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see com.google.gwt.user.client.Timer#cancel()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void cancel() {
|
||||||
|
GWT.log("Cancelling timer for "+workspaceUploader);
|
||||||
|
super.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -13,7 +13,6 @@ import java.util.Set;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.client.ClosableDialog;
|
import org.gcube.portlets.widgets.workspaceuploader.client.ClosableDialog;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderListenerController;
|
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderListenerController;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderServiceAsync;
|
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.client.events.CancelUploadEvent;
|
import org.gcube.portlets.widgets.workspaceuploader.client.events.CancelUploadEvent;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.client.events.CancelUploadEventHandler;
|
import org.gcube.portlets.widgets.workspaceuploader.client.events.CancelUploadEventHandler;
|
||||||
import org.gcube.portlets.widgets.workspaceuploader.client.events.HideMonitorEvent;
|
import org.gcube.portlets.widgets.workspaceuploader.client.events.HideMonitorEvent;
|
||||||
|
@ -34,7 +33,6 @@ import com.google.gwt.http.client.RequestException;
|
||||||
import com.google.gwt.http.client.Response;
|
import com.google.gwt.http.client.Response;
|
||||||
import com.google.gwt.user.client.Timer;
|
import com.google.gwt.user.client.Timer;
|
||||||
import com.google.gwt.user.client.Window;
|
import com.google.gwt.user.client.Window;
|
||||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
||||||
import com.google.gwt.user.client.ui.HTML;
|
import com.google.gwt.user.client.ui.HTML;
|
||||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
|
|
||||||
|
@ -52,7 +50,7 @@ public class UploaderMonitor {
|
||||||
private static ArrayList<LinkedHashMap<String, WorkspaceUploaderItem>> queueUploads = new ArrayList<LinkedHashMap<String,WorkspaceUploaderItem>>();
|
private static ArrayList<LinkedHashMap<String, WorkspaceUploaderItem>> queueUploads = new ArrayList<LinkedHashMap<String,WorkspaceUploaderItem>>();
|
||||||
|
|
||||||
private ClosableDialog dialogUploadMonitor = new ClosableDialog(monitorPanel, false, ConstantsWorkspaceUploader.MY_UPLOADS);
|
private ClosableDialog dialogUploadMonitor = new ClosableDialog(monitorPanel, false, ConstantsWorkspaceUploader.MY_UPLOADS);
|
||||||
private Map<String, Timer> currentTimersRun = new HashMap<String, Timer>();
|
private Map<String, TimerUpload> currentTimersRun = new HashMap<String, TimerUpload>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the single instance of UploaderMonitor.
|
* Gets the single instance of UploaderMonitor.
|
||||||
|
@ -88,13 +86,13 @@ public class UploaderMonitor {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final String clientKey = deleteTimerEvent.getUploader().getClientUploadKey();
|
final String clientKey = deleteTimerEvent.getUploader().getClientUploadKey();
|
||||||
final LinkedHashMap<String, WorkspaceUploaderItem> queue = getQueueFromClientUploadKey(clientKey);
|
final LinkedHashMap<String, WorkspaceUploaderItem> queue = getMapUploaderByClientUploadKey(clientKey);
|
||||||
if(queue==null){
|
if(queue==null){
|
||||||
GWT.log("onCancelUpload mapUpload is null for key: "+clientKey +", return");
|
GWT.log("onCancelUpload mapUpload is null for key: "+clientKey +", return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Timer timer = getTimer(clientKey);
|
final TimerUpload timer = getTimer(clientKey);
|
||||||
GWT.log("Client abort for timer with clientKey "+clientKey);
|
GWT.log("Client abort for timer with clientKey "+clientKey);
|
||||||
|
|
||||||
if(timer==null || !timer.isRunning()){
|
if(timer==null || !timer.isRunning()){
|
||||||
|
@ -102,16 +100,7 @@ public class UploaderMonitor {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//CANCELLING TIMER
|
|
||||||
timer.cancel();
|
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");
|
RequestBuilder request = new RequestBuilder(RequestBuilder.GET, ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM+"?"+ConstantsWorkspaceUploader.CLIENT_UPLOAD_KEYS+"="+clientKey+"&"+ConstantsWorkspaceUploader.CANCEL_UPLOAD+"=true");
|
||||||
try {
|
try {
|
||||||
|
@ -121,7 +110,18 @@ public class UploaderMonitor {
|
||||||
public void onResponseReceived(Request request, Response response) {
|
public void onResponseReceived(Request request, Response response) {
|
||||||
String result = response.getText();
|
String result = response.getText();
|
||||||
GWT.log("onResponseReceived "+result);
|
GWT.log("onResponseReceived "+result);
|
||||||
|
|
||||||
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(result);
|
final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(result);
|
||||||
|
// timer.cancel();
|
||||||
|
// int indexQueue = getQueueIndexFromClientUploadKey(clientKey);
|
||||||
|
// goNextUploaderFromKey(clientKey, queue, indexQueue);
|
||||||
|
// deleteTimerEvent.getUploader().setUploadStatus(UPLOAD_STATUS.ABORTED);
|
||||||
|
// notifyUploadAborted(deleteTimerEvent.getUploader().getFile().getParentId(), null);
|
||||||
|
|
||||||
|
// if(timer!=null)
|
||||||
|
// timer.cancel();
|
||||||
|
// goNextUploaderAfterKey(clientKey);
|
||||||
|
|
||||||
GWT.log("Cancel Upload Stream result: "+resultMessage);
|
GWT.log("Cancel Upload Stream result: "+resultMessage);
|
||||||
if(resultMessage==null)
|
if(resultMessage==null)
|
||||||
return;
|
return;
|
||||||
|
@ -143,23 +143,9 @@ public class UploaderMonitor {
|
||||||
text+="<span style='margin-left:5px; vertical-align: top;'>Upload "+deleteTimerEvent.getFileName()+ " aborted</span></div>";
|
text+="<span style='margin-left:5px; vertical-align: top;'>Upload "+deleteTimerEvent.getFileName()+ " aborted</span></div>";
|
||||||
html.setHTML(text);
|
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
|
//UPDATING STATUS AS ABORTED IN ORDER TO STOP THE TIMER
|
||||||
GWT.log("Upload Aborted is OK");
|
GWT.log("Upload Aborted is OK");
|
||||||
timer.cancel();
|
goNextUploaderAfterKey(clientKey);
|
||||||
// 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);
|
deleteTimerEvent.getUploader().setUploadStatus(UPLOAD_STATUS.ABORTED);
|
||||||
notifyUploadAborted(deleteTimerEvent.getUploader().getFile().getParentId(), null);
|
notifyUploadAborted(deleteTimerEvent.getUploader().getFile().getParentId(), null);
|
||||||
|
@ -172,39 +158,6 @@ public class UploaderMonitor {
|
||||||
break;
|
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
|
@Override
|
||||||
|
@ -229,45 +182,17 @@ public class UploaderMonitor {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the queue from client upload key.
|
* Gets the monitor panel.
|
||||||
*
|
*
|
||||||
* @param clientKey the client key
|
* @return the monitorPanel
|
||||||
* @return the queue from client upload key, otherwise null;
|
|
||||||
*/
|
*/
|
||||||
public LinkedHashMap<String, WorkspaceUploaderItem> getQueueFromClientUploadKey(String clientKey){
|
public MonitorPanel getMonitorPanel() {
|
||||||
for (LinkedHashMap<String, WorkspaceUploaderItem> queue : queueUploads) {
|
|
||||||
if(queue!=null){
|
return monitorPanel;
|
||||||
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.
|
* Show monitor.
|
||||||
*/
|
*/
|
||||||
|
@ -292,140 +217,13 @@ public class UploaderMonitor {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do polling.
|
* Start timer.
|
||||||
*
|
*
|
||||||
* @param workspaceUploader the workspace uploader
|
* @param workspaceUploader the workspace uploader
|
||||||
* @param queue the queue
|
|
||||||
* @param indexQueue the index queue
|
|
||||||
* @return the timer
|
|
||||||
*/
|
*/
|
||||||
/*private void doPolling(final WorkspaceUploaderItem workspaceUploader){
|
public void startTimer(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());
|
|
||||||
synchronized(this){
|
|
||||||
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());
|
|
||||||
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());
|
|
||||||
queueTimers.remove(tmn);
|
|
||||||
notifyUploadError(result.getFile().getParentId(), null, null);
|
|
||||||
// new DialogResult(null, "Upload Failed!!", result.getStatusDescription()).center();
|
|
||||||
cancel();
|
|
||||||
}
|
|
||||||
monitorPanel.updateWorkspaceUploder(result);
|
|
||||||
// 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());
|
|
||||||
notifyUploadError(workspaceUploader.getFile().getParentId(), null, caught);
|
|
||||||
cancel();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
TimerUpload timer = new TimerUpload(workspaceUploader);
|
||||||
GWT.log("Starting new timer for key: "+workspaceUploader.getClientUploadKey());
|
GWT.log("Starting new timer for key: "+workspaceUploader.getClientUploadKey());
|
||||||
saveTimer(timer, workspaceUploader.getClientUploadKey());
|
saveTimer(timer, workspaceUploader.getClientUploadKey());
|
||||||
timer.scheduleRepeating(2000);
|
timer.scheduleRepeating(2000);
|
||||||
|
@ -449,11 +247,11 @@ public class UploaderMonitor {
|
||||||
/**
|
/**
|
||||||
* Save timer.
|
* Save timer.
|
||||||
*
|
*
|
||||||
* @param timer the timer
|
* @param timerUpload the timer upload
|
||||||
* @param clientKey the client key
|
* @param clientKey the client key
|
||||||
*/
|
*/
|
||||||
private synchronized void saveTimer(Timer timer, String clientKey){
|
private synchronized void saveTimer(TimerUpload timerUpload, String clientKey){
|
||||||
currentTimersRun.put(clientKey, timer);
|
currentTimersRun.put(clientKey, timerUpload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -463,7 +261,7 @@ public class UploaderMonitor {
|
||||||
* @param clientKey the client key
|
* @param clientKey the client key
|
||||||
* @return the timer
|
* @return the timer
|
||||||
*/
|
*/
|
||||||
private Timer getTimer(String clientKey){
|
private TimerUpload getTimer(String clientKey){
|
||||||
return currentTimersRun.get(clientKey);
|
return currentTimersRun.get(clientKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,7 +271,7 @@ public class UploaderMonitor {
|
||||||
* @param parentId the parent id
|
* @param parentId the parent id
|
||||||
* @param itemId the item id
|
* @param itemId the item id
|
||||||
*/
|
*/
|
||||||
private void notifyOverwriteCompleted(String parentId, String itemId){
|
protected void notifyOverwriteCompleted(String parentId, String itemId){
|
||||||
GWT.log("notifyOverwriteCompleted in monitor");
|
GWT.log("notifyOverwriteCompleted in monitor");
|
||||||
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.OVERWRITE_COMPLETED, parentId, itemId));
|
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.OVERWRITE_COMPLETED, parentId, itemId));
|
||||||
}
|
}
|
||||||
|
@ -484,7 +282,7 @@ public class UploaderMonitor {
|
||||||
* @param parentId the parent id
|
* @param parentId the parent id
|
||||||
* @param itemId the item id
|
* @param itemId the item id
|
||||||
*/
|
*/
|
||||||
private void notifyUploadCompleted(String parentId, String itemId){
|
protected void notifyUploadCompleted(String parentId, String itemId){
|
||||||
GWT.log("notifyUploadCompleted in monitor");
|
GWT.log("notifyUploadCompleted in monitor");
|
||||||
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.UPLOAD_COMPLETED, parentId, itemId));
|
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.UPLOAD_COMPLETED, parentId, itemId));
|
||||||
}
|
}
|
||||||
|
@ -495,7 +293,7 @@ public class UploaderMonitor {
|
||||||
* @param parentId the parent id
|
* @param parentId the parent id
|
||||||
* @param itemId the item id
|
* @param itemId the item id
|
||||||
*/
|
*/
|
||||||
private void notifyUploadAborted(String parentId, String itemId){
|
protected void notifyUploadAborted(String parentId, String itemId){
|
||||||
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.ABORTED, parentId, itemId));
|
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.ABORTED, parentId, itemId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,7 +304,7 @@ public class UploaderMonitor {
|
||||||
* @param itemId the item id
|
* @param itemId the item id
|
||||||
* @param t the t
|
* @param t the t
|
||||||
*/
|
*/
|
||||||
private void notifyUploadError(String parentId, String itemId, Throwable t){
|
protected void notifyUploadError(String parentId, String itemId, Throwable t){
|
||||||
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.FAILED, parentId, itemId, t));
|
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.FAILED, parentId, itemId, t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,15 +360,18 @@ public class UploaderMonitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the new timer to queue.
|
* Adds the new uploader to queue.
|
||||||
*
|
*
|
||||||
* @param indexQueue the index queue
|
* @param indexQueue the index queue
|
||||||
* @param workspaceUploaderItem the workspace uploader item
|
* @param workspaceUploaderItem the workspace uploader item
|
||||||
|
* @return the linked hash map
|
||||||
*/
|
*/
|
||||||
public void addNewTimerToQueue(int indexQueue, WorkspaceUploaderItem workspaceUploaderItem) {
|
public LinkedHashMap<String, WorkspaceUploaderItem> addNewUploaderToQueue(int indexQueue, WorkspaceUploaderItem workspaceUploaderItem) {
|
||||||
LinkedHashMap<String, WorkspaceUploaderItem> queue = queueUploads.get(indexQueue);
|
LinkedHashMap<String, WorkspaceUploaderItem> queue = queueUploads.get(indexQueue);
|
||||||
queue.put(workspaceUploaderItem.getClientUploadKey(), workspaceUploaderItem);
|
queue.put(workspaceUploaderItem.getClientUploadKey(), workspaceUploaderItem);
|
||||||
|
return queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -595,17 +396,29 @@ public class UploaderMonitor {
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkspaceUploaderItem workspaceUploader = getNextUploader(queue);
|
WorkspaceUploaderItem workspaceUploader = getNextUploader(queue);
|
||||||
startTimer(workspaceUploader, queue, index);
|
startTimer(workspaceUploader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Go next uploader after key.
|
||||||
|
*
|
||||||
|
* @param clientKey the client key
|
||||||
|
*/
|
||||||
|
protected void goNextUploaderAfterKey(String clientKey){
|
||||||
|
removeTimer(clientKey);
|
||||||
|
LinkedHashMap<String, WorkspaceUploaderItem> mapUploader = deleteUploaderByClientKey(clientKey);
|
||||||
|
nextUploader(mapUploader, clientKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the next uploader.
|
* Gets the next uploader.
|
||||||
*
|
*
|
||||||
* @param queue the queue
|
* @param mapUploaders the map uploaders
|
||||||
* @return the next uploader
|
* @return the next uploader
|
||||||
*/
|
*/
|
||||||
public WorkspaceUploaderItem getNextUploader(LinkedHashMap<String, WorkspaceUploaderItem> queue){
|
protected WorkspaceUploaderItem getNextUploader(LinkedHashMap<String, WorkspaceUploaderItem> mapUploaders){
|
||||||
Iterator<String> it = queue.keySet().iterator();
|
Iterator<String> it = mapUploaders.keySet().iterator();
|
||||||
String firstKey = it.next();
|
String firstKey = it.next();
|
||||||
|
|
||||||
if(firstKey==null || firstKey.isEmpty()){
|
if(firstKey==null || firstKey.isEmpty()){
|
||||||
|
@ -613,31 +426,104 @@ public class UploaderMonitor {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return queue.get(firstKey);
|
return mapUploaders.get(firstKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Next uploader.
|
* Next uploader.
|
||||||
*
|
*
|
||||||
* @param queue the queue
|
* @param mapUploaders the map uploaders
|
||||||
* @param indexQueue the index queue
|
* @param clientKey the client key
|
||||||
*/
|
*/
|
||||||
public synchronized void nextUploader(LinkedHashMap<String, WorkspaceUploaderItem> queue, int indexQueue){
|
protected synchronized void nextUploader(LinkedHashMap<String, WorkspaceUploaderItem> mapUploaders, String clientKey){
|
||||||
|
|
||||||
if(queue.keySet().size()==0){
|
int index = getQueueIndexFromClientUploadKey(clientKey);
|
||||||
GWT.log("nextUploader return, queue size is = 0, deleting queue");
|
|
||||||
deleteQueue(indexQueue);
|
if(mapUploaders==null || mapUploaders.keySet().size()==0){
|
||||||
|
GWT.log("nextUploader return, mapUploaders is null or size is = 0, deleting queue");
|
||||||
|
deleteQueue(index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
WorkspaceUploaderItem workspaceUploader = getNextUploader(queue);
|
WorkspaceUploaderItem workspaceUploader = getNextUploader(mapUploaders);
|
||||||
|
|
||||||
if(workspaceUploader==null){
|
if(workspaceUploader==null){
|
||||||
GWT.log("nextUploader return a null uploader, deleting queue");
|
GWT.log("nextUploader return a null uploader, deleting queue");
|
||||||
deleteQueue(indexQueue);
|
deleteQueue(index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
startTimer(workspaceUploader, queue, indexQueue);
|
startTimer(workspaceUploader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the map uploader by client upload key.
|
||||||
|
*
|
||||||
|
* @param clientKey the client key
|
||||||
|
* @return the map uploader by client upload key
|
||||||
|
*/
|
||||||
|
protected LinkedHashMap<String, WorkspaceUploaderItem> getMapUploaderByClientUploadKey(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 uploader by client upload key.
|
||||||
|
*
|
||||||
|
* @param clientKey the client key
|
||||||
|
* @return the uploader by client upload key
|
||||||
|
*/
|
||||||
|
protected WorkspaceUploaderItem getUploaderByClientUploadKey(String clientKey){
|
||||||
|
LinkedHashMap<String, WorkspaceUploaderItem> map = getMapUploaderByClientUploadKey(clientKey);
|
||||||
|
if(map!=null)
|
||||||
|
return map.get(clientKey);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete uploader by client key.
|
||||||
|
*
|
||||||
|
* @param clientKey the client key
|
||||||
|
* @return the linked hash map
|
||||||
|
*/
|
||||||
|
protected LinkedHashMap<String, WorkspaceUploaderItem> deleteUploaderByClientKey(String clientKey){
|
||||||
|
GWT.log("deleteUploaderByClientKey by key: "+clientKey);
|
||||||
|
LinkedHashMap<String, WorkspaceUploaderItem> map = getMapUploaderByClientUploadKey(clientKey);
|
||||||
|
if(map!=null){
|
||||||
|
GWT.log("Deleted uploader with key: "+clientKey);
|
||||||
|
map.remove(clientKey);
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
else
|
||||||
|
index = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class WorkspaceFieldsUploadManager {
|
||||||
int queueIndex = UploaderMonitor.getInstance().newQueue();
|
int queueIndex = UploaderMonitor.getInstance().newQueue();
|
||||||
for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
|
for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
|
||||||
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
|
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
|
||||||
UploaderMonitor.getInstance().addNewTimerToQueue(queueIndex, workspaceUploaderItem);
|
UploaderMonitor.getInstance().addNewUploaderToQueue(queueIndex, workspaceUploaderItem);
|
||||||
// UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
|
// UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
|
||||||
}
|
}
|
||||||
UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);
|
UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);
|
||||||
|
|
|
@ -138,13 +138,20 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
boolean cancelUpload = Boolean.parseBoolean(request.getParameter(CANCEL_UPLOAD));
|
boolean cancelUpload = Boolean.parseBoolean(request.getParameter(CANCEL_UPLOAD));
|
||||||
logger.debug("GET method CANCEL_UPLOAD "+cancelUpload);
|
logger.debug("GET method CANCEL_UPLOAD "+cancelUpload);
|
||||||
if (cancelUpload) {
|
if (cancelUpload) {
|
||||||
cancelUpload(request.getSession(), clientUploadKey);
|
boolean cancelled = cancelUpload(request.getSession(), clientUploadKey);
|
||||||
sendMessage(response, "Upload aborted "+clientUploadKey);
|
if(cancelled){
|
||||||
|
sendMessage(response, "Upload aborted "+clientUploadKey);
|
||||||
|
// try {
|
||||||
|
//// removeCurrentListener(request.getSession(), clientUploadKey);
|
||||||
|
// WsUtil.eraseWorkspaceUploaderInSession(request.getSession(), clientUploadKey);
|
||||||
|
// }catch (Exception e) {
|
||||||
|
// logger.warn("An error occurred during removing cancelled upload from session ");
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sendWarnMessage(response, "Upload aborted for id: "+clientUploadKey +" has skipped, already aborted or completed?");
|
||||||
}else
|
}else
|
||||||
logger.debug(CANCEL_UPLOAD + " param not found");
|
logger.debug(CANCEL_UPLOAD + " param not found");
|
||||||
// }else
|
|
||||||
// sendError(response, "Internal error: CANCEL_UPLOAD NOT FOUND");
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +390,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
|
|
||||||
WorkspaceItem item;
|
WorkspaceItem item;
|
||||||
try {
|
try {
|
||||||
logger.debug("getWorkspace Item from HL");
|
logger.debug("getWorkspaceItem destination id: "+destinationId+" from HL");
|
||||||
item = wa.getItem(destinationId);
|
item = wa.getItem(destinationId);
|
||||||
} catch (ItemNotFoundException e) {
|
} catch (ItemNotFoundException e) {
|
||||||
logger.error("Error, no destination folder found", e);
|
logger.error("Error, no destination folder found", e);
|
||||||
|
@ -883,15 +890,19 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
||||||
*
|
*
|
||||||
* @param session the session
|
* @param session the session
|
||||||
* @param clientUploadKey the client upload key
|
* @param clientUploadKey the client upload key
|
||||||
|
* @return true, if successful
|
||||||
*/
|
*/
|
||||||
public void cancelUpload(HttpSession session, String clientUploadKey) {
|
public boolean cancelUpload(HttpSession session, String clientUploadKey) {
|
||||||
logger.debug("UPLOAD-SERVLET (" + session.getId()+ ") cancelling Upload: "+clientUploadKey);
|
logger.debug("UPLOAD-SERVLET (" + session.getId()+ ") cancelling Upload: "+clientUploadKey);
|
||||||
AbstractUploadProgressListener listener = getCurrentListener(session, clientUploadKey);
|
AbstractUploadProgressListener listener = getCurrentListener(session, clientUploadKey);
|
||||||
if (listener != null && !listener.isCanceled()) {
|
if (listener != null && !listener.isCanceled()) {
|
||||||
logger.info("CancelUpload listener is "+listener.toString());
|
logger.info("CancelUpload listener is "+listener.toString());
|
||||||
listener.setException(new UploadCanceledException());
|
listener.setException(new UploadCanceledException());
|
||||||
}else
|
return true;
|
||||||
|
}else{
|
||||||
logger.info("Skipping cancel upload: listener is null or is cancel");
|
logger.info("Skipping cancel upload: listener is null or is cancel");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,12 +15,18 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The server side implementation of the RPC service.
|
* The server side implementation of the RPC service.
|
||||||
|
*
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* May 12, 2016
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implements WorkspaceUploaderService {
|
public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implements WorkspaceUploaderService {
|
||||||
|
|
||||||
public static Logger logger = LoggerFactory.getLogger(WorkspaceUploaderServiceImpl.class);
|
public static Logger logger = LoggerFactory.getLogger(WorkspaceUploaderServiceImpl.class);
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderService#getUploadStatus(java.lang.String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public WorkspaceUploaderItem getUploadStatus(String identifier) throws Exception {
|
public WorkspaceUploaderItem getUploadStatus(String identifier) throws Exception {
|
||||||
|
|
||||||
|
@ -41,19 +47,22 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
|
||||||
logger.error(exception);
|
logger.error(exception);
|
||||||
throw new Exception(exception);*/
|
throw new Exception(exception);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// getThreadIds();
|
// getThreadIds();
|
||||||
String progress = "";
|
String progress = "";
|
||||||
if(uploader.getUploadProgress()!=null && uploader.getUploadProgress().getLastEvent()!=null)
|
if(uploader.getUploadProgress()!=null && uploader.getUploadProgress().getLastEvent()!=null)
|
||||||
progress = uploader.getUploadProgress().getLastEvent().toString();
|
progress = uploader.getUploadProgress().getLastEvent().toString();
|
||||||
else
|
else
|
||||||
progress = "upload progress is null or last event is null";
|
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);
|
logger.info("returning uploader: "+uploader.getClientUploadKey() +" status: "+uploader.getUploadStatus() +", file: "+uploader.getFile().toString() +", progress: "+progress);
|
||||||
return uploader;
|
return uploader;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderService#getWorkspaceId()
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getWorkspaceId() throws Exception {
|
public String getWorkspaceId() throws Exception {
|
||||||
logger.trace("getWorkspaceId");
|
logger.trace("getWorkspaceId");
|
||||||
|
@ -67,11 +76,11 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
|
||||||
String error = "An error occurred getting root id";
|
String error = "An error occurred getting root id";
|
||||||
throw new Exception(error);
|
throw new Exception(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#itemExistsInWorkpaceFolder(java.lang.String, java.lang.String)
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#itemExistsInWorkpaceFolder(java.lang.String, java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
@ -79,17 +88,17 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
|
||||||
public String itemExistsInWorkpaceFolder(String parentId, String itemName) throws Exception {
|
public String itemExistsInWorkpaceFolder(String parentId, String itemName) throws Exception {
|
||||||
logger.trace("get itemExistsInWorkpace by parentId: "+parentId);
|
logger.trace("get itemExistsInWorkpace by parentId: "+parentId);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Workspace workspace = WsUtil.getWorkspace(getThreadLocalRequest().getSession());
|
Workspace workspace = WsUtil.getWorkspace(getThreadLocalRequest().getSession());
|
||||||
WorkspaceItem wsItem = workspace.getItem(parentId); //GET PARENT
|
WorkspaceItem wsItem = workspace.getItem(parentId); //GET PARENT
|
||||||
|
|
||||||
if(wsItem.getType().equals(WorkspaceItemType.FOLDER) || wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
|
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)
|
if(itemFound==null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return itemFound.getId();
|
return itemFound.getId();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -101,7 +110,7 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
|
||||||
throw new Exception(e.getMessage());
|
throw new Exception(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// protected void getThreadIds(){
|
// protected void getThreadIds(){
|
||||||
// WorkspaceUploadServletStream.printAllThreadIds();
|
// WorkspaceUploadServletStream.printAllThreadIds();
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -121,7 +121,6 @@ public class WorkspaceUploaderWsUtil extends HttpServlet {
|
||||||
protected void sendOKMessage(HttpServletResponse response, String message) throws IOException{
|
protected void sendOKMessage(HttpServletResponse response, String message) throws IOException{
|
||||||
try {
|
try {
|
||||||
response.setStatus(HttpServletResponse.SC_OK);
|
response.setStatus(HttpServletResponse.SC_OK);
|
||||||
response.setContentType("text/xml");
|
|
||||||
if(message==null)
|
if(message==null)
|
||||||
message="null";
|
message="null";
|
||||||
response.getWriter().write(message);
|
response.getWriter().write(message);
|
||||||
|
|
|
@ -20,26 +20,29 @@ import org.slf4j.LoggerFactory;
|
||||||
*
|
*
|
||||||
* @see UploadProgressEvent
|
* @see UploadProgressEvent
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractUploadProgressListener implements
|
public abstract class AbstractUploadProgressListener implements ProgressListener, Serializable {
|
||||||
ProgressListener, Serializable {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 9039352626573789199L;
|
private static final long serialVersionUID = -7542788161740799624L;
|
||||||
|
|
||||||
private static final double COMPLETE_PERECENTAGE = 100d;
|
private static final double COMPLETE_PERECENTAGE = 100d;
|
||||||
private int percentage = -1;
|
private int percentage = -1;
|
||||||
|
|
||||||
private UploadProgress uploadProgress;
|
private UploadProgress uploadProgress;
|
||||||
private int percentageOffset = 0;
|
private int percentageOffset = 0;
|
||||||
private double completePercentage = COMPLETE_PERECENTAGE;
|
private double completePercentage = COMPLETE_PERECENTAGE;
|
||||||
private static Logger logger = LoggerFactory
|
private static Logger logger = LoggerFactory.getLogger(AbstractUploadProgressListener.class);
|
||||||
.getLogger(AbstractUploadProgressListener.class);
|
|
||||||
protected RuntimeException exception = null;
|
protected RuntimeException exception = null;
|
||||||
protected boolean exceptionTrhown = false;
|
protected boolean exceptionTrhown = false;
|
||||||
protected String sessionId;
|
protected String sessionId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current.
|
||||||
|
*
|
||||||
|
* @param sessionId the session id
|
||||||
|
* @return the abstract upload progress listener
|
||||||
|
*/
|
||||||
public static AbstractUploadProgressListener current(String sessionId) {
|
public static AbstractUploadProgressListener current(String sessionId) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"Implement the static method 'current' in your customized class");
|
"Implement the static method 'current' in your customized class");
|
||||||
|
@ -64,14 +67,10 @@ public abstract class AbstractUploadProgressListener implements
|
||||||
/**
|
/**
|
||||||
* Instantiates a new upload progress listener.
|
* Instantiates a new upload progress listener.
|
||||||
*
|
*
|
||||||
* @param request
|
* @param session the session
|
||||||
* the request
|
* @param clientUploadKey the client upload key
|
||||||
* @param uploadProgress
|
* @param percentageOffset the percentage offset
|
||||||
* the upload progress
|
* @param completePercentage the complete percentage
|
||||||
* @param percentageOffset
|
|
||||||
* the percentage offset
|
|
||||||
* @param completePercentage
|
|
||||||
* the complete percentage
|
|
||||||
*/
|
*/
|
||||||
public AbstractUploadProgressListener(HttpSession session,
|
public AbstractUploadProgressListener(HttpSession session,
|
||||||
String clientUploadKey, int percentageOffset,
|
String clientUploadKey, int percentageOffset,
|
||||||
|
@ -88,16 +87,9 @@ public abstract class AbstractUploadProgressListener implements
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return the session
|
|
||||||
*/
|
|
||||||
public HttpSession getSession() {
|
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see org.apache.commons.fileupload.ProgressListener#update(long, long,
|
* @see org.apache.commons.fileupload.ProgressListener#update(long, long,
|
||||||
* int)
|
* int)
|
||||||
*/
|
*/
|
||||||
|
@ -105,6 +97,7 @@ public abstract class AbstractUploadProgressListener implements
|
||||||
public void update(final long bytesRead, final long totalBytes, final int items) {
|
public void update(final long bytesRead, final long totalBytes, final int items) {
|
||||||
|
|
||||||
if (exceptionTrhown) {
|
if (exceptionTrhown) {
|
||||||
|
logger.warn("An exception thrown is already true. Is upload already cancelled?, returning");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,8 +105,7 @@ public abstract class AbstractUploadProgressListener implements
|
||||||
// commons-fileupload's
|
// commons-fileupload's
|
||||||
// parser stops and the connection is closed.
|
// parser stops and the connection is closed.
|
||||||
if (isCanceled()) {
|
if (isCanceled()) {
|
||||||
String eName = exception.getClass().getName()
|
String eName = exception.getClass().getName().replaceAll("^.+\\.", "");
|
||||||
.replaceAll("^.+\\.", "");
|
|
||||||
logger.info(AbstractUploadProgressListener.class.getName() + " "
|
logger.info(AbstractUploadProgressListener.class.getName() + " "
|
||||||
+ sessionKey + " The upload has been canceled after "
|
+ sessionKey + " The upload has been canceled after "
|
||||||
+ bytesRead + " bytes received, raising an exception ("
|
+ bytesRead + " bytes received, raising an exception ("
|
||||||
|
@ -124,21 +116,16 @@ public abstract class AbstractUploadProgressListener implements
|
||||||
|
|
||||||
this.bytesRead = bytesRead;
|
this.bytesRead = bytesRead;
|
||||||
this.contentLength = totalBytes;
|
this.contentLength = totalBytes;
|
||||||
|
int percentage = percentageOffset+ (int) Math.floor((double) bytesRead / (double) totalBytes* completePercentage);
|
||||||
int percentage = percentageOffset
|
|
||||||
+ ((int) Math.floor(((double) bytesRead / (double) totalBytes)
|
|
||||||
* completePercentage));
|
|
||||||
|
|
||||||
if (this.percentage == percentage)
|
if (this.percentage == percentage)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.percentage = percentage;
|
this.percentage = percentage;
|
||||||
|
|
||||||
UploadProgressChangeEvent event = new UploadProgressChangeEvent();
|
UploadProgressChangeEvent event = new UploadProgressChangeEvent();
|
||||||
event.setReadPercentage(percentage);
|
event.setReadPercentage(percentage);
|
||||||
event.setReadTime(System.currentTimeMillis());
|
event.setReadTime(System.currentTimeMillis());
|
||||||
// logger.trace("Updating percentage.. "+percentage);
|
// logger.trace("Updating percentage.. "+percentage);
|
||||||
|
|
||||||
synchronized (this.uploadProgress) {
|
synchronized (this.uploadProgress) {
|
||||||
// logger.trace("Adding event: "+event);
|
// logger.trace("Adding event: "+event);
|
||||||
this.uploadProgress.add(event);
|
this.uploadProgress.add(event);
|
||||||
|
@ -147,6 +134,8 @@ public abstract class AbstractUploadProgressListener implements
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the bytes read.
|
||||||
|
*
|
||||||
* @return the bytesRead
|
* @return the bytesRead
|
||||||
*/
|
*/
|
||||||
public Long getBytesRead() {
|
public Long getBytesRead() {
|
||||||
|
@ -154,6 +143,8 @@ public abstract class AbstractUploadProgressListener implements
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the content length.
|
||||||
|
*
|
||||||
* @return the contentLength
|
* @return the contentLength
|
||||||
*/
|
*/
|
||||||
public Long getContentLength() {
|
public Long getContentLength() {
|
||||||
|
@ -191,6 +182,7 @@ public abstract class AbstractUploadProgressListener implements
|
||||||
/**
|
/**
|
||||||
* Set the exception which cancels the upload.
|
* Set the exception which cancels the upload.
|
||||||
*
|
*
|
||||||
|
* @param e the new exception
|
||||||
*/
|
*/
|
||||||
public void setException(RuntimeException e) {
|
public void setException(RuntimeException e) {
|
||||||
logger.info("Set RuntimeException to cancel upload");
|
logger.info("Set RuntimeException to cancel upload");
|
||||||
|
@ -199,6 +191,8 @@ public abstract class AbstractUploadProgressListener implements
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the percentage.
|
||||||
|
*
|
||||||
* @return the percentage
|
* @return the percentage
|
||||||
*/
|
*/
|
||||||
public int getPercentage() {
|
public int getPercentage() {
|
||||||
|
@ -206,12 +200,24 @@ public abstract class AbstractUploadProgressListener implements
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets the client upload key.
|
||||||
|
*
|
||||||
* @return the clientUploadKey
|
* @return the clientUploadKey
|
||||||
*/
|
*/
|
||||||
public String getClientUploadKey() {
|
public String getClientUploadKey() {
|
||||||
return clientUploadKey;
|
return clientUploadKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the session.
|
||||||
|
*
|
||||||
|
* @return the session
|
||||||
|
*/
|
||||||
|
public HttpSession getSession() {
|
||||||
|
return session;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the session key.
|
* Gets the session key.
|
||||||
*
|
*
|
||||||
|
@ -254,6 +260,6 @@ public abstract class AbstractUploadProgressListener implements
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import javax.servlet.http.HttpSession;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This File Upload Listener is used by Apache Commons File Upload to monitor
|
* This File Upload Listener is used by Apache Commons File Upload to monitor
|
||||||
* the progress of the uploaded file.
|
* the progress of the uploaded file.
|
||||||
|
@ -34,8 +35,7 @@ import org.slf4j.LoggerFactory;
|
||||||
* It is thought to be used in systems where session objects are not updated
|
* It is thought to be used in systems where session objects are not updated
|
||||||
* until the request has finished.
|
* until the request has finished.
|
||||||
*
|
*
|
||||||
* @author francesco-mangiacrapa
|
* @see MemoryUploadEvent
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class MemoryUploadListener extends AbstractUploadProgressListener {
|
public class MemoryUploadListener extends AbstractUploadProgressListener {
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public class MemoryUploadListener extends AbstractUploadProgressListener {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see org.gcube.portlets.widgets.workspaceuploader.server.upload.
|
* @see org.gcube.portlets.widgets.workspaceuploader.server.upload.
|
||||||
* AbstractUploadProgressListener#remove()
|
* AbstractUploadProgressListener#remove()
|
||||||
*/
|
*/
|
||||||
|
@ -93,7 +93,7 @@ public class MemoryUploadListener extends AbstractUploadProgressListener {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see org.gcube.portlets.widgets.workspaceuploader.server.upload.
|
* @see org.gcube.portlets.widgets.workspaceuploader.server.upload.
|
||||||
* AbstractUploadProgressListener#save()
|
* AbstractUploadProgressListener#save()
|
||||||
*/
|
*/
|
||||||
|
@ -102,6 +102,9 @@ public class MemoryUploadListener extends AbstractUploadProgressListener {
|
||||||
logger.debug(sessionKey + " Saved " + this.toString());
|
logger.debug(sessionKey + " Saved " + this.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.gcube.portlets.widgets.workspaceuploader.server.upload.AbstractUploadProgressListener#toString()
|
||||||
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString();
|
return super.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,3 @@
|
||||||
/*
|
|
||||||
* Copyright 2010 Manuel Carrasco Moñino. (manolo at apache/org)
|
|
||||||
* http://code.google.com/p/gwtupload
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package org.gcube.portlets.widgets.workspaceuploader.server.upload;
|
package org.gcube.portlets.widgets.workspaceuploader.server.upload;
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,5 +9,9 @@ package org.gcube.portlets.widgets.workspaceuploader.server.upload;
|
||||||
* Sep 8, 2015
|
* Sep 8, 2015
|
||||||
*/
|
*/
|
||||||
public class UploadCanceledException extends RuntimeException {
|
public class UploadCanceledException extends RuntimeException {
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 4311434519628111824L;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
|
||||||
public class UploadProgressListener extends AbstractUploadProgressListener {
|
public class UploadProgressListener extends AbstractUploadProgressListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -7757392979344200978L;
|
private static final long serialVersionUID = -7757392979344200978L;
|
||||||
|
|
||||||
|
@ -47,6 +47,8 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
|
||||||
|
|
||||||
private static final int WATCHER_INTERVAL = 2000;
|
private static final int WATCHER_INTERVAL = 2000;
|
||||||
|
|
||||||
|
private TimeoutWatchDog watcher = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the no data timeout.
|
* Sets the no data timeout.
|
||||||
*
|
*
|
||||||
|
@ -67,12 +69,12 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
|
||||||
*/
|
*/
|
||||||
public class TimeoutWatchDog extends Thread implements Serializable {
|
public class TimeoutWatchDog extends Thread implements Serializable {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -6958907286385617168L;
|
private static final long serialVersionUID = -6958907286385617168L;
|
||||||
AbstractUploadProgressListener listener;
|
AbstractUploadProgressListener listener;
|
||||||
private long lastBytesRead = 0L;
|
private long lastBytesRead = 0L;
|
||||||
private long lastData = (new Date()).getTime();
|
private long lastData = new Date().getTime();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new timeout watch dog.
|
* Instantiates a new timeout watch dog.
|
||||||
|
@ -93,7 +95,7 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see java.lang.Thread#run()
|
* @see java.lang.Thread#run()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -131,7 +133,7 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
|
||||||
* @return true, if is frozen
|
* @return true, if is frozen
|
||||||
*/
|
*/
|
||||||
private boolean isFrozen() {
|
private boolean isFrozen() {
|
||||||
long now = (new Date()).getTime();
|
long now = new Date().getTime();
|
||||||
if (bytesRead > lastBytesRead) {
|
if (bytesRead > lastBytesRead) {
|
||||||
lastData = now;
|
lastData = now;
|
||||||
lastBytesRead = bytesRead;
|
lastBytesRead = bytesRead;
|
||||||
|
@ -154,11 +156,10 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
|
||||||
public static AbstractUploadProgressListener current(HttpSession session,
|
public static AbstractUploadProgressListener current(HttpSession session,
|
||||||
String clientUploadKey) {
|
String clientUploadKey) {
|
||||||
String sessionKey = getSessionKey(session.getId(), clientUploadKey);
|
String sessionKey = getSessionKey(session.getId(), clientUploadKey);
|
||||||
return (AbstractUploadProgressListener) session
|
return (AbstractUploadProgressListener) session.getAttribute(sessionKey);
|
||||||
.getAttribute(sessionKey);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private TimeoutWatchDog watcher = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new upload listener.
|
* Instantiates a new upload listener.
|
||||||
|
@ -180,7 +181,7 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see gwtupload.server.AbstractUploadListener#remove()
|
* @see gwtupload.server.AbstractUploadListener#remove()
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
@ -196,7 +197,7 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see gwtupload.server.AbstractUploadListener#save()
|
* @see gwtupload.server.AbstractUploadListener#save()
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
|
@ -205,15 +206,14 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
|
||||||
public void save() {
|
public void save() {
|
||||||
if (getSession() != null) {
|
if (getSession() != null) {
|
||||||
getSession().setAttribute(sessionKey, this);
|
getSession().setAttribute(sessionKey, this);
|
||||||
logger.info("Added in session: " + toString());
|
logger.info("Save - Added in session: " + toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(sessionKey + " save listener " + toString());
|
logger.debug(sessionKey + " save listener " + toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
*
|
*
|
||||||
* @see gwtupload.server.AbstractUploadListener#update(long, long, int)
|
* @see gwtupload.server.AbstractUploadListener#update(long, long, int)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -256,7 +256,7 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("UploadProgressListener [watcher=");
|
builder.append("UploadProgressListener [watcher=");
|
||||||
builder.append(watcher);
|
builder.append(watcher);
|
||||||
builder.append(super.toString());
|
builder.append(", "+super.toString());
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.gcube.portlets.widgets.workspaceuploader.server.util;
|
package org.gcube.portlets.widgets.workspaceuploader.server.util;
|
||||||
|
|
||||||
|
@ -40,12 +40,12 @@ public class WsUtil {
|
||||||
public static final String TEST_SCOPE = "/gcube/devsec";
|
public static final String TEST_SCOPE = "/gcube/devsec";
|
||||||
public static String TEST_USER = "test.user";
|
public static String TEST_USER = "test.user";
|
||||||
public static String TEST_USER_FULL_NAME = "Test User";
|
public static String TEST_USER_FULL_NAME = "Test User";
|
||||||
|
|
||||||
|
|
||||||
protected static Logger logger = Logger.getLogger(WsUtil.class);
|
protected static Logger logger = Logger.getLogger(WsUtil.class);
|
||||||
|
|
||||||
// public static boolean withoutPortal = false;
|
// public static boolean withoutPortal = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if is within portal.
|
* Checks if is within portal.
|
||||||
*
|
*
|
||||||
|
@ -55,13 +55,13 @@ public class WsUtil {
|
||||||
try {
|
try {
|
||||||
UserLocalServiceUtil.getService();
|
UserLocalServiceUtil.getService();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
logger.trace("Development Mode ON");
|
logger.trace("Development Mode ON");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the asl session.
|
* Gets the asl session.
|
||||||
*
|
*
|
||||||
|
@ -73,18 +73,18 @@ public class WsUtil {
|
||||||
String sessionID = httpSession.getId();
|
String sessionID = httpSession.getId();
|
||||||
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
|
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
|
||||||
ASLSession session;
|
ASLSession session;
|
||||||
|
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
|
|
||||||
/*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING
|
/*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING
|
||||||
* COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/
|
* COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/
|
||||||
user=TEST_USER;
|
user=TEST_USER;
|
||||||
|
|
||||||
if (!isWithinPortal()) { //DEV MODE
|
if (!isWithinPortal()) { //DEV MODE
|
||||||
user = "francesco.mangiacrapa";
|
user = "francesco.mangiacrapa";
|
||||||
TEST_USER_FULL_NAME = "Francesco Mangiacrapa";
|
TEST_USER_FULL_NAME = "Francesco Mangiacrapa";
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
|
logger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
|
||||||
logger.warn("session id: "+sessionID);
|
logger.warn("session id: "+sessionID);
|
||||||
logger.warn("TEST_USER: "+user);
|
logger.warn("TEST_USER: "+user);
|
||||||
|
@ -92,21 +92,21 @@ public class WsUtil {
|
||||||
logger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE);
|
logger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE);
|
||||||
session = SessionManager.getInstance().getASLSession(sessionID, user);
|
session = SessionManager.getInstance().getASLSession(sessionID, user);
|
||||||
session.setScope(TEST_SCOPE);
|
session.setScope(TEST_SCOPE);
|
||||||
|
|
||||||
//MANDATORY FOR SOCIAL LIBRARY
|
//MANDATORY FOR SOCIAL LIBRARY
|
||||||
session.setUserAvatarId(user + "Avatar");
|
session.setUserAvatarId(user + "Avatar");
|
||||||
session.setUserFullName(TEST_USER_FULL_NAME);
|
session.setUserFullName(TEST_USER_FULL_NAME);
|
||||||
session.setUserEmailAddress(user + "@mail.test");
|
session.setUserEmailAddress(user + "@mail.test");
|
||||||
|
|
||||||
//SET HTTP SESSION ATTRIBUTE
|
//SET HTTP SESSION ATTRIBUTE
|
||||||
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
|
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
|
||||||
return session;
|
return session;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SessionManager.getInstance().getASLSession(sessionID, user);
|
return SessionManager.getInstance().getASLSession(sessionID, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if is session expired.
|
* Checks if is session expired.
|
||||||
*
|
*
|
||||||
|
@ -119,22 +119,22 @@ public class WsUtil {
|
||||||
//READING USERNAME FROM ASL SESSION
|
//READING USERNAME FROM ASL SESSION
|
||||||
String userUsername = getAslSession(httpSession).getUsername();
|
String userUsername = getAslSession(httpSession).getUsername();
|
||||||
boolean isTestUser = userUsername.compareTo(WsUtil.TEST_USER)==0;
|
boolean isTestUser = userUsername.compareTo(WsUtil.TEST_USER)==0;
|
||||||
|
|
||||||
//TODO UNCOMMENT THIS FOR RELEASE
|
//TODO UNCOMMENT THIS FOR RELEASE
|
||||||
logger.trace("Is "+WsUtil.TEST_USER+" test user? "+isTestUser);
|
logger.trace("Is "+WsUtil.TEST_USER+" test user? "+isTestUser);
|
||||||
|
|
||||||
if(isTestUser){
|
if(isTestUser){
|
||||||
logger.error("workspace session is expired! username is: "+WsUtil.TEST_USER);
|
logger.error("workspace session is expired! username is: "+WsUtil.TEST_USER);
|
||||||
return true; //is TEST_USER, session is expired
|
return true; //is TEST_USER, session is expired
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.trace("workspace session is valid! current username is: "+userUsername);
|
logger.trace("workspace session is valid! current username is: "+userUsername);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the workspace.
|
* Gets the workspace.
|
||||||
|
@ -146,18 +146,18 @@ public class WsUtil {
|
||||||
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
|
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
|
||||||
*/
|
*/
|
||||||
public static Workspace getWorkspace(final HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException{
|
public static Workspace getWorkspace(final HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException{
|
||||||
|
|
||||||
logger.trace("Get Workspace");
|
logger.trace("Get Workspace");
|
||||||
final ASLSession session = getAslSession(httpSession);
|
final ASLSession session = getAslSession(httpSession);
|
||||||
logger.trace("ASLSession scope: "+session.getScope() + " username: "+session.getUsername());
|
logger.trace("ASLSession scope: "+session.getScope() + " username: "+session.getUsername());
|
||||||
|
|
||||||
ScopeProvider.instance.set(session.getScope());
|
ScopeProvider.instance.set(session.getScope());
|
||||||
logger.trace("Scope provider instancied");
|
logger.trace("Scope provider instancied");
|
||||||
|
|
||||||
return HomeLibrary.getUserWorkspace(session.getUsername());
|
return HomeLibrary.getUserWorkspace(session.getUsername());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the notification manager.
|
* Gets the notification manager.
|
||||||
*
|
*
|
||||||
|
@ -166,9 +166,9 @@ public class WsUtil {
|
||||||
*/
|
*/
|
||||||
public static NotificationsManager getNotificationManager(ASLSession session)
|
public static NotificationsManager getNotificationManager(ASLSession session)
|
||||||
{
|
{
|
||||||
|
|
||||||
NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER);
|
NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER);
|
||||||
|
|
||||||
if (notifMng == null) {
|
if (notifMng == null) {
|
||||||
try{
|
try{
|
||||||
logger.trace("Create new NotificationsManager for user: "+session.getUsername());
|
logger.trace("Create new NotificationsManager for user: "+session.getUsername());
|
||||||
|
@ -179,10 +179,10 @@ public class WsUtil {
|
||||||
logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e);
|
logger.error("An error occurred instancing ApplicationNotificationsManager for user: "+session.getUsername(),e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return notifMng;
|
return notifMng;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the notification producer.
|
* Gets the notification producer.
|
||||||
*
|
*
|
||||||
|
@ -191,18 +191,18 @@ public class WsUtil {
|
||||||
*/
|
*/
|
||||||
public static NotificationsWorkspaceUploaderProducer getNotificationProducer(ASLSession session)
|
public static NotificationsWorkspaceUploaderProducer getNotificationProducer(ASLSession session)
|
||||||
{
|
{
|
||||||
|
|
||||||
NotificationsWorkspaceUploaderProducer notifProducer = (NotificationsWorkspaceUploaderProducer) session.getAttribute(NOTIFICATION_PRODUCER);
|
NotificationsWorkspaceUploaderProducer notifProducer = (NotificationsWorkspaceUploaderProducer) session.getAttribute(NOTIFICATION_PRODUCER);
|
||||||
|
|
||||||
if (notifProducer == null) {
|
if (notifProducer == null) {
|
||||||
logger.trace("Create new Notification Producer for user: "+session.getUsername());
|
logger.trace("Create new Notification Producer for user: "+session.getUsername());
|
||||||
notifProducer = new NotificationsWorkspaceUploaderProducer(session);
|
notifProducer = new NotificationsWorkspaceUploaderProducer(session);
|
||||||
session.setAttribute(NOTIFICATION_PRODUCER, notifProducer);
|
session.setAttribute(NOTIFICATION_PRODUCER, notifProducer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return notifProducer;
|
return notifProducer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Put workspace uploader in session.
|
* Put workspace uploader in session.
|
||||||
*
|
*
|
||||||
|
@ -212,18 +212,17 @@ public class WsUtil {
|
||||||
*/
|
*/
|
||||||
public static void putWorkspaceUploaderInSession(final HttpSession httpSession, WorkspaceUploaderItem uploader) throws Exception
|
public static void putWorkspaceUploaderInSession(final HttpSession httpSession, WorkspaceUploaderItem uploader) throws Exception
|
||||||
{
|
{
|
||||||
logger.trace("Get Workspace");
|
logger.trace("Put workspace uploader in session: "+uploader);
|
||||||
final ASLSession session = getAslSession(httpSession);
|
final ASLSession session = getAslSession(httpSession);
|
||||||
|
|
||||||
if(uploader.getIdentifier()==null || uploader.getIdentifier().isEmpty())
|
if(uploader.getIdentifier()==null || uploader.getIdentifier().isEmpty())
|
||||||
throw new Exception("Invalid uploader");
|
throw new Exception("Invalid uploader");
|
||||||
|
|
||||||
logger.debug("Adding uploader: "+uploader.getIdentifier() +" in session");
|
|
||||||
session.setAttribute(uploader.getIdentifier(), uploader);
|
session.setAttribute(uploader.getIdentifier(), uploader);
|
||||||
|
logger.debug("Added uploader: "+uploader.getIdentifier() +" in session");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the workspace uploader in session.
|
* Gets the workspace uploader in session.
|
||||||
*
|
*
|
||||||
|
@ -235,14 +234,14 @@ public class WsUtil {
|
||||||
public static WorkspaceUploaderItem getWorkspaceUploaderInSession(final HttpSession httpSession, String uploaderIdentifier) throws Exception
|
public static WorkspaceUploaderItem getWorkspaceUploaderInSession(final HttpSession httpSession, String uploaderIdentifier) throws Exception
|
||||||
{
|
{
|
||||||
final ASLSession session = getAslSession(httpSession);
|
final ASLSession session = getAslSession(httpSession);
|
||||||
|
|
||||||
if(uploaderIdentifier==null || uploaderIdentifier.isEmpty())
|
if(uploaderIdentifier==null || uploaderIdentifier.isEmpty())
|
||||||
throw new Exception("Invalid uploader");
|
throw new Exception("Invalid uploader");
|
||||||
|
|
||||||
return (WorkspaceUploaderItem) session.getAttribute(uploaderIdentifier);
|
return (WorkspaceUploaderItem) session.getAttribute(uploaderIdentifier);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Erase workspace uploader in session.
|
* Erase workspace uploader in session.
|
||||||
|
@ -255,17 +254,17 @@ public class WsUtil {
|
||||||
public static boolean eraseWorkspaceUploaderInSession(final HttpSession httpSession, String uploaderIdentifier) throws Exception
|
public static boolean eraseWorkspaceUploaderInSession(final HttpSession httpSession, String uploaderIdentifier) throws Exception
|
||||||
{
|
{
|
||||||
WorkspaceUploaderItem uploader = getWorkspaceUploaderInSession(httpSession, uploaderIdentifier);
|
WorkspaceUploaderItem uploader = getWorkspaceUploaderInSession(httpSession, uploaderIdentifier);
|
||||||
|
|
||||||
if(uploader!=null){
|
if(uploader!=null){
|
||||||
logger.debug("Erased uploader: "+uploader.getIdentifier() +" in session");
|
logger.debug("Erasing uploader: "+uploader.getIdentifier() +" in session, adding null value");
|
||||||
uploader = null;
|
uploader = null;
|
||||||
putWorkspaceUploaderInSession(httpSession, uploader);
|
putWorkspaceUploaderInSession(httpSession, uploader);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
logger.debug("Uploader not found, skipping erase from session");
|
logger.debug("Uploader not found, skipping erase from session");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the user id.
|
* Gets the user id.
|
||||||
|
@ -274,10 +273,10 @@ public class WsUtil {
|
||||||
* @return the user id
|
* @return the user id
|
||||||
*/
|
*/
|
||||||
public static String getUserId(HttpSession httpSession) {
|
public static String getUserId(HttpSession httpSession) {
|
||||||
|
|
||||||
ASLSession session = getAslSession(httpSession);
|
ASLSession session = getAslSession(httpSession);
|
||||||
|
|
||||||
return session.getUsername();
|
return session.getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class HandlerResultMessage implements Serializable{
|
||||||
return errorResult("result is null or empty");
|
return errorResult("result is null or empty");
|
||||||
|
|
||||||
int index = result.indexOf(':');
|
int index = result.indexOf(':');
|
||||||
if (index>0){
|
if (index>=0){
|
||||||
statusToken = result.substring(0,index);
|
statusToken = result.substring(0,index);
|
||||||
if (index<result.length()){
|
if (index<result.length()){
|
||||||
messageToken = result.substring(index+1);
|
messageToken = result.substring(index+1);
|
||||||
|
|
Loading…
Reference in New Issue