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:
Francesco Mangiacrapa 2016-05-12 13:12:45 +00:00
parent aa74220a50
commit 2890a420d7
14 changed files with 422 additions and 395 deletions

View File

@ -243,10 +243,12 @@ public class DialogUpload extends ClosableDialog implements HasWorskpaceUploadNo
enableButtons(false);
WorkspaceUploaderItem fakeUploader = new WorkspaceUploaderItem();
fakeUploader.setClientUploadKey(clientUploadKey);
int queueIndex = UploaderMonitor.getInstance().newQueue();
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(fakeUploader, fileUpload.getFilename());
setVisible(false);
removeLoading();
// UploaderMonitor.getInstance().pollWorkspaceUploader(fakeUploader);
UploaderMonitor.getInstance().addNewUploaderToQueue(queueIndex, fakeUploader);
UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);
}
});

View File

@ -278,7 +278,7 @@ public class MultipleDilaogUpload extends DialogUpload {
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
setVisible(false);
removeLoading();
UploaderMonitor.getInstance().addNewTimerToQueue(queueIndex, workspaceUploaderItem);
UploaderMonitor.getInstance().addNewUploaderToQueue(queueIndex, workspaceUploaderItem);
// UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
}

View File

@ -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();
}
}

View File

@ -13,7 +13,6 @@ import java.util.Set;
import org.gcube.portlets.widgets.workspaceuploader.client.ClosableDialog;
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
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.CancelUploadEventHandler;
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.user.client.Timer;
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.VerticalPanel;
@ -52,7 +50,7 @@ public class UploaderMonitor {
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>();
private Map<String, TimerUpload> currentTimersRun = new HashMap<String, TimerUpload>();
/**
* Gets the single instance of UploaderMonitor.
@ -88,13 +86,13 @@ public class UploaderMonitor {
return;
final String clientKey = deleteTimerEvent.getUploader().getClientUploadKey();
final LinkedHashMap<String, WorkspaceUploaderItem> queue = getQueueFromClientUploadKey(clientKey);
final LinkedHashMap<String, WorkspaceUploaderItem> queue = getMapUploaderByClientUploadKey(clientKey);
if(queue==null){
GWT.log("onCancelUpload mapUpload is null for key: "+clientKey +", return");
return;
}
final Timer timer = getTimer(clientKey);
final TimerUpload timer = getTimer(clientKey);
GWT.log("Client abort for timer with clientKey "+clientKey);
if(timer==null || !timer.isRunning()){
@ -102,16 +100,7 @@ public class UploaderMonitor {
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 {
@ -121,7 +110,18 @@ public class UploaderMonitor {
public void onResponseReceived(Request request, Response response) {
String result = response.getText();
GWT.log("onResponseReceived "+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);
if(resultMessage==null)
return;
@ -143,23 +143,9 @@ public class UploaderMonitor {
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);
goNextUploaderAfterKey(clientKey);
deleteTimerEvent.getUploader().setUploadStatus(UPLOAD_STATUS.ABORTED);
notifyUploadAborted(deleteTimerEvent.getUploader().getFile().getParentId(), null);
@ -172,39 +158,6 @@ public class UploaderMonitor {
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
@ -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 queue from client upload key, otherwise null;
* @return the monitorPanel
*/
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;
public MonitorPanel getMonitorPanel() {
return monitorPanel;
}
/**
* 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.
*/
@ -292,140 +217,13 @@ public class UploaderMonitor {
/**
* Do polling.
* Start timer.
*
* @param workspaceUploader the workspace uploader
* @param queue the queue
* @param indexQueue the index queue
* @return the timer
*/
/*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());
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());
}
});
}
};
public void startTimer(final WorkspaceUploaderItem workspaceUploader){
TimerUpload timer = new TimerUpload(workspaceUploader);
GWT.log("Starting new timer for key: "+workspaceUploader.getClientUploadKey());
saveTimer(timer, workspaceUploader.getClientUploadKey());
timer.scheduleRepeating(2000);
@ -449,11 +247,11 @@ public class UploaderMonitor {
/**
* Save timer.
*
* @param timer the timer
* @param timerUpload the timer upload
* @param clientKey the client key
*/
private synchronized void saveTimer(Timer timer, String clientKey){
currentTimersRun.put(clientKey, timer);
private synchronized void saveTimer(TimerUpload timerUpload, String clientKey){
currentTimersRun.put(clientKey, timerUpload);
}
@ -463,7 +261,7 @@ public class UploaderMonitor {
* @param clientKey the client key
* @return the timer
*/
private Timer getTimer(String clientKey){
private TimerUpload getTimer(String clientKey){
return currentTimersRun.get(clientKey);
}
@ -473,7 +271,7 @@ public class UploaderMonitor {
* @param parentId the parent 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");
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 itemId the item id
*/
private void notifyUploadCompleted(String parentId, String itemId){
protected void notifyUploadCompleted(String parentId, String itemId){
GWT.log("notifyUploadCompleted in monitor");
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 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));
}
@ -506,7 +304,7 @@ public class UploaderMonitor {
* @param itemId the item id
* @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));
}
@ -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 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);
queue.put(workspaceUploaderItem.getClientUploadKey(), workspaceUploaderItem);
return queue;
}
@ -595,17 +396,29 @@ public class UploaderMonitor {
}
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.
*
* @param queue the queue
* @param mapUploaders the map uploaders
* @return the next uploader
*/
public WorkspaceUploaderItem getNextUploader(LinkedHashMap<String, WorkspaceUploaderItem> queue){
Iterator<String> it = queue.keySet().iterator();
protected WorkspaceUploaderItem getNextUploader(LinkedHashMap<String, WorkspaceUploaderItem> mapUploaders){
Iterator<String> it = mapUploaders.keySet().iterator();
String firstKey = it.next();
if(firstKey==null || firstKey.isEmpty()){
@ -613,31 +426,104 @@ public class UploaderMonitor {
return null;
}
return queue.get(firstKey);
return mapUploaders.get(firstKey);
}
/**
* Next uploader.
*
* @param queue the queue
* @param indexQueue the index queue
* @param mapUploaders the map uploaders
* @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){
GWT.log("nextUploader return, queue size is = 0, deleting queue");
deleteQueue(indexQueue);
int index = getQueueIndexFromClientUploadKey(clientKey);
if(mapUploaders==null || mapUploaders.keySet().size()==0){
GWT.log("nextUploader return, mapUploaders is null or size is = 0, deleting queue");
deleteQueue(index);
return;
}
WorkspaceUploaderItem workspaceUploader = getNextUploader(queue);
WorkspaceUploaderItem workspaceUploader = getNextUploader(mapUploaders);
if(workspaceUploader==null){
GWT.log("nextUploader return a null uploader, deleting queue");
deleteQueue(indexQueue);
deleteQueue(index);
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;
}
}

View File

@ -60,7 +60,7 @@ public class WorkspaceFieldsUploadManager {
int queueIndex = UploaderMonitor.getInstance().newQueue();
for (final WorkspaceUploaderItem workspaceUploaderItem : fakeUploaders) {
UploaderMonitor.getInstance().addNewUploaderToMonitorPanel(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName());
UploaderMonitor.getInstance().addNewTimerToQueue(queueIndex, workspaceUploaderItem);
UploaderMonitor.getInstance().addNewUploaderToQueue(queueIndex, workspaceUploaderItem);
// UploaderMonitor.getInstance().pollWorkspaceUploader(workspaceUploaderItem);
}
UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);

View File

@ -138,13 +138,20 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
boolean cancelUpload = Boolean.parseBoolean(request.getParameter(CANCEL_UPLOAD));
logger.debug("GET method CANCEL_UPLOAD "+cancelUpload);
if (cancelUpload) {
cancelUpload(request.getSession(), clientUploadKey);
sendMessage(response, "Upload aborted "+clientUploadKey);
boolean cancelled = cancelUpload(request.getSession(), 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
logger.debug(CANCEL_UPLOAD + " param not found");
// }else
// sendError(response, "Internal error: CANCEL_UPLOAD NOT FOUND");
return;
}
@ -383,7 +390,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
WorkspaceItem item;
try {
logger.debug("getWorkspace Item from HL");
logger.debug("getWorkspaceItem destination id: "+destinationId+" from HL");
item = wa.getItem(destinationId);
} catch (ItemNotFoundException 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 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);
AbstractUploadProgressListener listener = getCurrentListener(session, clientUploadKey);
if (listener != null && !listener.isCanceled()) {
logger.info("CancelUpload listener is "+listener.toString());
listener.setException(new UploadCanceledException());
}else
return true;
}else{
logger.info("Skipping cancel upload: listener is null or is cancel");
return false;
}
}
/**

View File

@ -15,12 +15,18 @@ import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* The server side implementation of the RPC service.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* May 12, 2016
*/
@SuppressWarnings("serial")
public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implements WorkspaceUploaderService {
public static Logger logger = LoggerFactory.getLogger(WorkspaceUploaderServiceImpl.class);
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderService#getUploadStatus(java.lang.String)
*/
@Override
public WorkspaceUploaderItem getUploadStatus(String identifier) throws Exception {
@ -41,19 +47,22 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
logger.error(exception);
throw new Exception(exception);*/
}
// getThreadIds();
String progress = "";
if(uploader.getUploadProgress()!=null && uploader.getUploadProgress().getLastEvent()!=null)
progress = uploader.getUploadProgress().getLastEvent().toString();
else
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);
return uploader;
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderService#getWorkspaceId()
*/
@Override
public String getWorkspaceId() throws Exception {
logger.trace("getWorkspaceId");
@ -67,11 +76,11 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
String error = "An error occurred getting root id";
throw new Exception(error);
}
return null;
}
/* (non-Javadoc)
* @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 {
logger.trace("get itemExistsInWorkpace by parentId: "+parentId);
try {
Workspace workspace = WsUtil.getWorkspace(getThreadLocalRequest().getSession());
WorkspaceItem wsItem = workspace.getItem(parentId); //GET PARENT
if(wsItem.getType().equals(WorkspaceItemType.FOLDER) || wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
WorkspaceItem itemFound = workspace.find(itemName, parentId);
if(itemFound==null)
return null;
return itemFound.getId();
}
else
@ -101,7 +110,7 @@ public class WorkspaceUploaderServiceImpl extends RemoteServiceServlet implement
throw new Exception(e.getMessage());
}
}
// protected void getThreadIds(){
// WorkspaceUploadServletStream.printAllThreadIds();
// }

View File

@ -121,7 +121,6 @@ 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);

View File

@ -20,26 +20,29 @@ import org.slf4j.LoggerFactory;
*
* @see UploadProgressEvent
*/
public abstract class AbstractUploadProgressListener implements
ProgressListener, Serializable {
public abstract class AbstractUploadProgressListener implements ProgressListener, Serializable {
/**
*
*
*/
private static final long serialVersionUID = 9039352626573789199L;
private static final long serialVersionUID = -7542788161740799624L;
private static final double COMPLETE_PERECENTAGE = 100d;
private int percentage = -1;
private UploadProgress uploadProgress;
private int percentageOffset = 0;
private double completePercentage = COMPLETE_PERECENTAGE;
private static Logger logger = LoggerFactory
.getLogger(AbstractUploadProgressListener.class);
private static Logger logger = LoggerFactory.getLogger(AbstractUploadProgressListener.class);
protected RuntimeException exception = null;
protected boolean exceptionTrhown = false;
protected String sessionId;
/**
* Current.
*
* @param sessionId the session id
* @return the abstract upload progress listener
*/
public static AbstractUploadProgressListener current(String sessionId) {
throw new RuntimeException(
"Implement the static method 'current' in your customized class");
@ -64,14 +67,10 @@ public abstract class AbstractUploadProgressListener implements
/**
* Instantiates a new upload progress listener.
*
* @param request
* the request
* @param uploadProgress
* the upload progress
* @param percentageOffset
* the percentage offset
* @param completePercentage
* the complete percentage
* @param session the session
* @param clientUploadKey the client upload key
* @param percentageOffset the percentage offset
* @param completePercentage the complete percentage
*/
public AbstractUploadProgressListener(HttpSession session,
String clientUploadKey, int percentageOffset,
@ -88,16 +87,9 @@ public abstract class AbstractUploadProgressListener implements
save();
}
/**
* @return the session
*/
public HttpSession getSession() {
return session;
}
/*
* (non-Javadoc)
*
*
* @see org.apache.commons.fileupload.ProgressListener#update(long, long,
* int)
*/
@ -105,6 +97,7 @@ public abstract class AbstractUploadProgressListener implements
public void update(final long bytesRead, final long totalBytes, final int items) {
if (exceptionTrhown) {
logger.warn("An exception thrown is already true. Is upload already cancelled?, returning");
return;
}
@ -112,8 +105,7 @@ public abstract class AbstractUploadProgressListener implements
// commons-fileupload's
// parser stops and the connection is closed.
if (isCanceled()) {
String eName = exception.getClass().getName()
.replaceAll("^.+\\.", "");
String eName = exception.getClass().getName().replaceAll("^.+\\.", "");
logger.info(AbstractUploadProgressListener.class.getName() + " "
+ sessionKey + " The upload has been canceled after "
+ bytesRead + " bytes received, raising an exception ("
@ -124,21 +116,16 @@ public abstract class AbstractUploadProgressListener implements
this.bytesRead = bytesRead;
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)
return;
this.percentage = percentage;
UploadProgressChangeEvent event = new UploadProgressChangeEvent();
event.setReadPercentage(percentage);
event.setReadTime(System.currentTimeMillis());
// logger.trace("Updating percentage.. "+percentage);
synchronized (this.uploadProgress) {
// logger.trace("Adding event: "+event);
this.uploadProgress.add(event);
@ -147,6 +134,8 @@ public abstract class AbstractUploadProgressListener implements
}
/**
* Gets the bytes read.
*
* @return the bytesRead
*/
public Long getBytesRead() {
@ -154,6 +143,8 @@ public abstract class AbstractUploadProgressListener implements
}
/**
* Gets the content length.
*
* @return the contentLength
*/
public Long getContentLength() {
@ -191,6 +182,7 @@ public abstract class AbstractUploadProgressListener implements
/**
* Set the exception which cancels the upload.
*
* @param e the new exception
*/
public void setException(RuntimeException e) {
logger.info("Set RuntimeException to cancel upload");
@ -199,6 +191,8 @@ public abstract class AbstractUploadProgressListener implements
}
/**
* Gets the percentage.
*
* @return the percentage
*/
public int getPercentage() {
@ -206,12 +200,24 @@ public abstract class AbstractUploadProgressListener implements
}
/**
* Gets the client upload key.
*
* @return the clientUploadKey
*/
public String getClientUploadKey() {
return clientUploadKey;
}
/**
* Gets the session.
*
* @return the session
*/
public HttpSession getSession() {
return session;
}
/**
* Gets the session key.
*
@ -254,6 +260,6 @@ public abstract class AbstractUploadProgressListener implements
builder.append("]");
return builder.toString();
}
}

View File

@ -24,6 +24,7 @@ import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* This File Upload Listener is used by Apache Commons File Upload to monitor
* 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
* until the request has finished.
*
* @author francesco-mangiacrapa
*
* @see MemoryUploadEvent
*/
public class MemoryUploadListener extends AbstractUploadProgressListener {
@ -81,7 +81,7 @@ public class MemoryUploadListener extends AbstractUploadProgressListener {
/*
* (non-Javadoc)
*
*
* @see org.gcube.portlets.widgets.workspaceuploader.server.upload.
* AbstractUploadProgressListener#remove()
*/
@ -93,7 +93,7 @@ public class MemoryUploadListener extends AbstractUploadProgressListener {
/*
* (non-Javadoc)
*
*
* @see org.gcube.portlets.widgets.workspaceuploader.server.upload.
* AbstractUploadProgressListener#save()
*/
@ -102,6 +102,9 @@ public class MemoryUploadListener extends AbstractUploadProgressListener {
logger.debug(sessionKey + " Saved " + this.toString());
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspaceuploader.server.upload.AbstractUploadProgressListener#toString()
*/
public String toString() {
return super.toString();
}

View File

@ -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;
@ -25,5 +9,9 @@ package org.gcube.portlets.widgets.workspaceuploader.server.upload;
* Sep 8, 2015
*/
public class UploadCanceledException extends RuntimeException {
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 4311434519628111824L;
}

View File

@ -37,7 +37,7 @@ import org.slf4j.LoggerFactory;
public class UploadProgressListener extends AbstractUploadProgressListener {
/**
*
*
*/
private static final long serialVersionUID = -7757392979344200978L;
@ -47,6 +47,8 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
private static final int WATCHER_INTERVAL = 2000;
private TimeoutWatchDog watcher = null;
/**
* Sets the no data timeout.
*
@ -67,12 +69,12 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
*/
public class TimeoutWatchDog extends Thread implements Serializable {
/**
*
*
*/
private static final long serialVersionUID = -6958907286385617168L;
AbstractUploadProgressListener listener;
private long lastBytesRead = 0L;
private long lastData = (new Date()).getTime();
private long lastData = new Date().getTime();
/**
* Instantiates a new timeout watch dog.
@ -93,7 +95,7 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
/*
* (non-Javadoc)
*
*
* @see java.lang.Thread#run()
*/
@Override
@ -131,7 +133,7 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
* @return true, if is frozen
*/
private boolean isFrozen() {
long now = (new Date()).getTime();
long now = new Date().getTime();
if (bytesRead > lastBytesRead) {
lastData = now;
lastBytesRead = bytesRead;
@ -154,11 +156,10 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
public static AbstractUploadProgressListener current(HttpSession session,
String clientUploadKey) {
String sessionKey = getSessionKey(session.getId(), clientUploadKey);
return (AbstractUploadProgressListener) session
.getAttribute(sessionKey);
return (AbstractUploadProgressListener) session.getAttribute(sessionKey);
}
private TimeoutWatchDog watcher = null;
/**
* Instantiates a new upload listener.
@ -180,7 +181,7 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
/*
* (non-Javadoc)
*
*
* @see gwtupload.server.AbstractUploadListener#remove()
*/
/**
@ -196,7 +197,7 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
/*
* (non-Javadoc)
*
*
* @see gwtupload.server.AbstractUploadListener#save()
*/
/**
@ -205,15 +206,14 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
public void save() {
if (getSession() != null) {
getSession().setAttribute(sessionKey, this);
logger.info("Added in session: " + toString());
logger.info("Save - Added in session: " + toString());
}
logger.debug(sessionKey + " save listener " + toString());
}
/*
* (non-Javadoc)
*
*
* @see gwtupload.server.AbstractUploadListener#update(long, long, int)
*/
@Override
@ -256,7 +256,7 @@ public class UploadProgressListener extends AbstractUploadProgressListener {
StringBuilder builder = new StringBuilder();
builder.append("UploadProgressListener [watcher=");
builder.append(watcher);
builder.append(super.toString());
builder.append(", "+super.toString());
return builder.toString();
}
}

View File

@ -1,5 +1,5 @@
/**
*
*
*/
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 String TEST_USER = "test.user";
public static String TEST_USER_FULL_NAME = "Test User";
protected static Logger logger = Logger.getLogger(WsUtil.class);
// public static boolean withoutPortal = false;
/**
* Checks if is within portal.
*
@ -55,13 +55,13 @@ public class WsUtil {
try {
UserLocalServiceUtil.getService();
return true;
}
catch (Exception ex) {
}
catch (Exception ex) {
logger.trace("Development Mode ON");
return false;
}
}
}
/**
* Gets the asl session.
*
@ -73,18 +73,18 @@ public class WsUtil {
String sessionID = httpSession.getId();
String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE);
ASLSession session;
if (user == null) {
/*USE ANOTHER ACCOUNT (OTHERWHISE BY TEST_USER) FOR RUNNING
* COMMENT THIS IN DEVELOP ENVIROMENT (UNCOMMENT IN PRODUCTION)*/
user=TEST_USER;
if (!isWithinPortal()) { //DEV MODE
user = "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("session id: "+sessionID);
logger.warn("TEST_USER: "+user);
@ -92,21 +92,21 @@ public class WsUtil {
logger.warn("USERNAME_ATTRIBUTE: "+USERNAME_ATTRIBUTE);
session = SessionManager.getInstance().getASLSession(sessionID, user);
session.setScope(TEST_SCOPE);
//MANDATORY FOR SOCIAL LIBRARY
session.setUserAvatarId(user + "Avatar");
session.setUserFullName(TEST_USER_FULL_NAME);
session.setUserEmailAddress(user + "@mail.test");
//SET HTTP SESSION ATTRIBUTE
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
return session;
}
return SessionManager.getInstance().getASLSession(sessionID, user);
}
/**
* Checks if is session expired.
*
@ -119,22 +119,22 @@ public class WsUtil {
//READING USERNAME FROM ASL SESSION
String userUsername = getAslSession(httpSession).getUsername();
boolean isTestUser = userUsername.compareTo(WsUtil.TEST_USER)==0;
//TODO UNCOMMENT THIS FOR RELEASE
logger.trace("Is "+WsUtil.TEST_USER+" test user? "+isTestUser);
if(isTestUser){
logger.error("workspace session is expired! username is: "+WsUtil.TEST_USER);
return true; //is TEST_USER, session is expired
}
logger.trace("workspace session is valid! current username is: "+userUsername);
return false;
}
/**
* Gets the workspace.
@ -146,18 +146,18 @@ public class WsUtil {
* @throws WorkspaceFolderNotFoundException the workspace folder not found exception
*/
public static Workspace getWorkspace(final HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException{
logger.trace("Get Workspace");
final ASLSession session = getAslSession(httpSession);
logger.trace("ASLSession scope: "+session.getScope() + " username: "+session.getUsername());
ScopeProvider.instance.set(session.getScope());
logger.trace("Scope provider instancied");
return HomeLibrary.getUserWorkspace(session.getUsername());
}
/**
* Gets the notification manager.
*
@ -166,9 +166,9 @@ public class WsUtil {
*/
public static NotificationsManager getNotificationManager(ASLSession session)
{
NotificationsManager notifMng = (NotificationsManager) session.getAttribute(NOTIFICATION_MANAGER);
if (notifMng == null) {
try{
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);
}
}
return notifMng;
}
/**
* Gets the notification producer.
*
@ -191,18 +191,18 @@ public class WsUtil {
*/
public static NotificationsWorkspaceUploaderProducer getNotificationProducer(ASLSession session)
{
NotificationsWorkspaceUploaderProducer notifProducer = (NotificationsWorkspaceUploaderProducer) session.getAttribute(NOTIFICATION_PRODUCER);
if (notifProducer == null) {
logger.trace("Create new Notification Producer for user: "+session.getUsername());
notifProducer = new NotificationsWorkspaceUploaderProducer(session);
session.setAttribute(NOTIFICATION_PRODUCER, notifProducer);
}
return notifProducer;
}
/**
* Put workspace uploader in session.
*
@ -212,18 +212,17 @@ public class WsUtil {
*/
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);
if(uploader.getIdentifier()==null || uploader.getIdentifier().isEmpty())
throw new Exception("Invalid uploader");
logger.debug("Adding uploader: "+uploader.getIdentifier() +" in session");
session.setAttribute(uploader.getIdentifier(), uploader);
logger.debug("Added uploader: "+uploader.getIdentifier() +" 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
{
final ASLSession session = getAslSession(httpSession);
if(uploaderIdentifier==null || uploaderIdentifier.isEmpty())
throw new Exception("Invalid uploader");
return (WorkspaceUploaderItem) session.getAttribute(uploaderIdentifier);
}
/**
* Erase workspace uploader in session.
@ -255,17 +254,17 @@ public class WsUtil {
public static boolean eraseWorkspaceUploaderInSession(final HttpSession httpSession, String uploaderIdentifier) throws Exception
{
WorkspaceUploaderItem uploader = getWorkspaceUploaderInSession(httpSession, uploaderIdentifier);
if(uploader!=null){
logger.debug("Erased uploader: "+uploader.getIdentifier() +" in session");
logger.debug("Erasing uploader: "+uploader.getIdentifier() +" in session, adding null value");
uploader = null;
putWorkspaceUploaderInSession(httpSession, uploader);
return true;
}
logger.debug("Uploader not found, skipping erase from session");
return false;
return false;
}
/**
* Gets the user id.
@ -274,10 +273,10 @@ public class WsUtil {
* @return the user id
*/
public static String getUserId(HttpSession httpSession) {
ASLSession session = getAslSession(httpSession);
return session.getUsername();
}
}

View File

@ -111,7 +111,7 @@ public class HandlerResultMessage implements Serializable{
return errorResult("result is null or empty");
int index = result.indexOf(':');
if (index>0){
if (index>=0){
statusToken = result.substring(0,index);
if (index<result.length()){
messageToken = result.substring(index+1);