Added monitoring upload client-side
This commit is contained in:
parent
15f4c01ec5
commit
b3fcfc021f
|
@ -19,6 +19,16 @@ public class ConstantsMPFormBuilder {
|
|||
public static final String JSON_CLIENT_KEYS = "ClientKeys";
|
||||
|
||||
public static final int LIMIT_UPLOADS = 50;
|
||||
|
||||
/**
|
||||
* Log.
|
||||
*
|
||||
* @param txt the txt
|
||||
*/
|
||||
public static native void jslog(String txt) /*-{
|
||||
console.log(txt)
|
||||
}-*/;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.mpformbuilder.client;
|
|||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.WorkspaceUploaderItem;
|
||||
|
||||
import com.google.gwt.user.client.rpc.RemoteService;
|
||||
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
||||
|
@ -16,4 +17,6 @@ public interface MetadataProfileFormBuilderService extends RemoteService {
|
|||
List<MetaDataProfileBean> getProfilesInTheScope(String scope, String genericResourceSecondaryType) throws Exception;
|
||||
|
||||
MetaDataProfileBean getProfileForMetadata(String metadata) throws Exception;
|
||||
|
||||
WorkspaceUploaderItem getUploadStatus(String clientUploadKey) throws Exception;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.gcube.portlets.widgets.mpformbuilder.client;
|
|||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.WorkspaceUploaderItem;
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
@ -37,4 +38,6 @@ public interface MetadataProfileFormBuilderServiceAsync {
|
|||
// Utility class should not be instantiated
|
||||
}
|
||||
}
|
||||
|
||||
void getUploadStatus(String clientUploadKey, AsyncCallback<WorkspaceUploaderItem> asyncCallback);
|
||||
}
|
||||
|
|
|
@ -47,11 +47,12 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
|
|||
* Sep 11, 2015
|
||||
*/
|
||||
private HTML UPLOADING = new HTML("Uploading...");
|
||||
protected VerticalPanel panel;
|
||||
protected VerticalPanel verticalMainPanel;
|
||||
// private MonitorPanel monitorPanel;
|
||||
protected String clientUploadKey;
|
||||
//protected String clientUploadKey;
|
||||
|
||||
private String purgedUploadingFileName;
|
||||
private UploaderProgressView upv;
|
||||
|
||||
/**
|
||||
* Instantiates a new dialog upload stream.
|
||||
|
@ -70,18 +71,18 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
|
|||
setWidth("auto");
|
||||
|
||||
// Create a panel to hold all of the form widgets.
|
||||
panel = new VerticalPanel();
|
||||
setWidget(panel);
|
||||
verticalMainPanel = new VerticalPanel();
|
||||
setWidget(verticalMainPanel);
|
||||
|
||||
fileUpload.setName(ConstantsMPFormBuilder.UPLOAD_FORM_ELEMENT);
|
||||
|
||||
// Add hidden parameters
|
||||
panel.add(new Hidden(ConstantsMPFormBuilder.CURR_GROUP_ID, GCubeClientContext.getCurrentContextId()));
|
||||
panel.add(new Hidden(ConstantsMPFormBuilder.UPLOAD_TYPE, ConstantsMPFormBuilder.THE_UPLOAD_TYPE.File.name()));
|
||||
verticalMainPanel.add(new Hidden(ConstantsMPFormBuilder.CURR_GROUP_ID, GCubeClientContext.getCurrentContextId()));
|
||||
verticalMainPanel.add(new Hidden(ConstantsMPFormBuilder.UPLOAD_TYPE, ConstantsMPFormBuilder.THE_UPLOAD_TYPE.File.name()));
|
||||
|
||||
initJsonClientKeys();
|
||||
panel.add(jsonClientKeys);
|
||||
panel.add(fileUpload);
|
||||
verticalMainPanel.add(jsonClientKeys);
|
||||
verticalMainPanel.add(fileUpload);
|
||||
|
||||
HorizontalPanel hp = new HorizontalPanel();
|
||||
// hp.getElement().setId("hpID");
|
||||
|
@ -89,14 +90,14 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
|
|||
hp.getElement().getStyle().setMarginTop(5, Unit.PX);
|
||||
hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
|
||||
hp.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
|
||||
panel.add(hp);
|
||||
verticalMainPanel.add(hp);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the panel
|
||||
*/
|
||||
public VerticalPanel getPanel() {
|
||||
return panel;
|
||||
return verticalMainPanel;
|
||||
}
|
||||
|
||||
protected void initJsonClientKeys(){
|
||||
|
@ -177,30 +178,12 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
|
|||
@Override
|
||||
public void onSubmit(SubmitEvent event) {
|
||||
GWT.log("SubmitEvent");
|
||||
addLoading();
|
||||
enableButtons(false);
|
||||
WorkspaceUploaderItem fakeUploader = new WorkspaceUploaderItem();
|
||||
fakeUploader.setClientUploadKey(clientUploadKey);
|
||||
// mapUploading.put(clientUploadKey, fakeUploader);
|
||||
// UploaderProgressView upv = new UploaderProgressView(fakeUploader, purgedUploadingFileName, null);
|
||||
// //mapPanels.put(uploader.getClientUploadKey(), upv);
|
||||
// VerticalPanel upvPanel = upv.getPanel();
|
||||
// upvPanel.addStyleName("upladerMargin");
|
||||
//// vpListUpload.insert(upvPanel, 0);
|
||||
// //vpListUpload.add(upvPanel);
|
||||
//
|
||||
// //updateNumberUpload();
|
||||
// removeLoading();
|
||||
// UploaderMonitor.getInstance().addNewUploaderToQueue(queueIndex, fakeUploader);
|
||||
// UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);
|
||||
|
||||
onSubmitAction();
|
||||
}
|
||||
});
|
||||
|
||||
fileUpload.addChangeHandler(new ChangeHandler() {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onChange(ChangeEvent event) {
|
||||
|
||||
|
@ -224,12 +207,31 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void onSubmitAction() {
|
||||
GWT.log("SubmitEvent");
|
||||
try {
|
||||
if(upv!=null)
|
||||
verticalMainPanel.remove(upv.getPanel());
|
||||
}catch (Exception e) {
|
||||
// TODO: handle exception
|
||||
}
|
||||
addLoading();
|
||||
enableButtons(false);
|
||||
//Only the first, just to manage single uploading
|
||||
WorkspaceUploaderItem workspaceUploaderItem = fakeUploaders.get(0);
|
||||
upv = new UploaderProgressView(workspaceUploaderItem, workspaceUploaderItem.getFile().getFileName(), null);
|
||||
verticalMainPanel.add(upv.getPanel());
|
||||
removeLoading();
|
||||
SingleUploadMonitor.getInstance().doStartPollingQueue(workspaceUploaderItem, upv);
|
||||
fakeUploaders.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the loading.
|
||||
*/
|
||||
protected void addLoading(){
|
||||
panel.add(UPLOADING);
|
||||
verticalMainPanel.add(UPLOADING);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -237,7 +239,7 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
|
|||
*/
|
||||
protected void removeLoading(){
|
||||
try{
|
||||
panel.remove(UPLOADING);
|
||||
verticalMainPanel.remove(UPLOADING);
|
||||
}catch(Exception e){
|
||||
|
||||
}
|
||||
|
|
|
@ -148,7 +148,7 @@ public class MultipleDilaogUpload extends DialogUpload {
|
|||
GWT.log("SubmitEvent");
|
||||
addLoading();
|
||||
enableButtons(false);
|
||||
addNewSubmitToMonitor();
|
||||
onSubmitAction();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -156,7 +156,7 @@ public class MultipleDilaogUpload extends DialogUpload {
|
|||
|
||||
@Override
|
||||
public void onChange(ChangeEvent event) {
|
||||
GWT.log("browse return...");
|
||||
GWT.log("file upload change handler, browse return...");
|
||||
if (fileUpload.getFilename() == null || fileUpload.getFilename().isEmpty()) {
|
||||
GWT.log("No file specified ");
|
||||
//MultipleDilaogUpload.this.hide();
|
||||
|
@ -186,47 +186,7 @@ public class MultipleDilaogUpload extends DialogUpload {
|
|||
// ADD TO FORM PANEL
|
||||
// initJsonClientKeys();
|
||||
jsonClientKeys.setValue(jsonKeys);
|
||||
|
||||
// // CASE 1 FILE
|
||||
// if (files.length == 1) {
|
||||
//
|
||||
// // recall: Some browser would write in
|
||||
// // fileUploadField.getValue() C:\fakepath\$fileName
|
||||
// final String label = files[0];
|
||||
// WorkspaceUploaderServiceAsync.Util.getInstance()
|
||||
// .itemExistsInWorkpaceFolder(parentIdentifier,
|
||||
// label, new AsyncCallback<String>() {
|
||||
//
|
||||
// @Override
|
||||
// public void onSuccess(
|
||||
// final String itemId) {
|
||||
// GWT.log("itemExistsInWorkpaceFolder: "
|
||||
// + itemId);
|
||||
// if (itemId != null) {
|
||||
// removeItemAndSubmitForm(itemId);
|
||||
// updateItemSubmitForm(itemId);
|
||||
//// if (Window.confirm(label+ " exists in folder. If you continue, a new version will be created")) {
|
||||
//// removeItemAndSubmitForm(itemId);
|
||||
//// updateItemSubmitForm(itemId);
|
||||
//// }
|
||||
// } else
|
||||
// submitForm(); // ITEM does NOT
|
||||
// // EXIST SO
|
||||
// // SUBMIT FORM;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onFailure(Throwable caught) {
|
||||
// GWT.log("Sorry an error occurred on the server "
|
||||
// + caught.getLocalizedMessage()
|
||||
// + ". Please try again later");
|
||||
// Window.alert(caught.getMessage());
|
||||
// }
|
||||
//
|
||||
// });
|
||||
// } else
|
||||
submitForm();
|
||||
|
||||
submitForm();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -348,7 +308,7 @@ public class MultipleDilaogUpload extends DialogUpload {
|
|||
*/
|
||||
public static native String getFilesSelected(final String tagId, final String fileDelimiter) /*-{
|
||||
var count = $wnd.$("#" + tagId)[0].files.length;
|
||||
console.log(count);
|
||||
//console.log(count);
|
||||
var out = "";
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.events.NotifyUploadEvent;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.events.NotifyUploadEvent.UPLOAD_EVENT_TYPE;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.WorkspaceUploaderItem;
|
||||
|
||||
import com.google.gwt.core.shared.GWT;
|
||||
import com.google.gwt.event.shared.HandlerManager;
|
||||
import com.google.gwt.user.client.Timer;
|
||||
|
||||
public class SingleUploadMonitor {
|
||||
|
||||
private static SingleUploadMonitor instance;
|
||||
|
||||
private final static HandlerManager monitorEventBus = new HandlerManager(null);
|
||||
private Map<String, TimerUpload> currentTimersRun = new HashMap<String, TimerUpload>();
|
||||
|
||||
/**
|
||||
* Gets the single instance of UploaderMonitor.
|
||||
*
|
||||
* @return single instance of UploaderMonitor
|
||||
*/
|
||||
public static synchronized SingleUploadMonitor getInstance() {
|
||||
if (instance == null){
|
||||
instance = new SingleUploadMonitor();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Do start polling queue.
|
||||
*
|
||||
* @param index the index
|
||||
* @param workspaceUploader
|
||||
* @param upv
|
||||
*/
|
||||
public synchronized void doStartPollingQueue(WorkspaceUploaderItem workspaceUploader, UploaderProgressView upv) {
|
||||
TimerUpload timer = new TimerUpload(workspaceUploader, upv);
|
||||
startTimer(workspaceUploader, timer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start timer.
|
||||
*
|
||||
* @param workspaceUploader the workspace uploader
|
||||
*/
|
||||
public void startTimer(final WorkspaceUploaderItem workspaceUploader, TimerUpload timer){
|
||||
GWT.log("Starting new timer for key: "+workspaceUploader.getClientUploadKey());
|
||||
saveTimer(timer, workspaceUploader.getClientUploadKey());
|
||||
timer.scheduleRepeating(2000);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes the timer.
|
||||
*
|
||||
* @param clientKey the client key
|
||||
*/
|
||||
public synchronized void removeTimer(String clientKey){
|
||||
Timer timer = currentTimersRun.get(clientKey);
|
||||
if(timer!=null){
|
||||
currentTimersRun.remove(clientKey);
|
||||
GWT.log("Remove timer for key: "+clientKey+", performed correctly");
|
||||
}else
|
||||
GWT.log("Remove timer for key: "+clientKey+", skypped, already removed?");
|
||||
}
|
||||
|
||||
/**
|
||||
* Save timer.
|
||||
*
|
||||
* @param timerUpload the timer upload
|
||||
* @param clientKey the client key
|
||||
*/
|
||||
private synchronized void saveTimer(TimerUpload timerUpload, String clientKey){
|
||||
currentTimersRun.put(clientKey, timerUpload);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the timer.
|
||||
*
|
||||
* @param clientKey the client key
|
||||
* @return the timer
|
||||
*/
|
||||
private TimerUpload getTimer(String clientKey){
|
||||
return currentTimersRun.get(clientKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify upload completed.
|
||||
*
|
||||
* @param parentId the parent id
|
||||
* @param itemId the item id
|
||||
*/
|
||||
protected void notifyOverwriteCompleted(String parentId, String itemId){
|
||||
GWT.log("notifyOverwriteCompleted in monitor");
|
||||
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.OVERWRITE_COMPLETED, parentId, itemId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify upload completed.
|
||||
*
|
||||
* @param parentId the parent id
|
||||
* @param itemId the item id
|
||||
*/
|
||||
protected void notifyUploadCompleted(String parentId, String itemId){
|
||||
GWT.log("notifyUploadCompleted in monitor");
|
||||
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.UPLOAD_COMPLETED, parentId, itemId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify upload aborted.
|
||||
*
|
||||
* @param parentId the parent id
|
||||
* @param itemId the item id
|
||||
*/
|
||||
protected void notifyUploadAborted(String parentId, String itemId){
|
||||
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.ABORTED, parentId, itemId));
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify upload error.
|
||||
*
|
||||
* @param parentId the parent id
|
||||
* @param itemId the item id
|
||||
* @param t the t
|
||||
*/
|
||||
protected void notifyUploadError(String parentId, String itemId, String error, Throwable t){
|
||||
WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.FAILED, parentId, itemId, error, t));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,138 +1,137 @@
|
|||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload;
|
||||
//
|
||||
//import org.gcube.portlets.widgets.mpformbuilder.shared.upload.WorkspaceUploaderItem;
|
||||
//import org.gcube.portlets.widgets.mpformbuilder.shared.upload.WorkspaceUploaderItem.UPLOAD_STATUS;
|
||||
//import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
||||
//import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderServiceAsync;
|
||||
//
|
||||
//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(final 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());
|
||||
//
|
||||
// ConstantsWorkspaceUploader.jslog("Upload Completed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||
//
|
||||
// Timer timer = new Timer() {
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// ConstantsWorkspaceUploader.jslog("Upload Completed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||
// if(!result.getIsOverwrite())
|
||||
// monitor.notifyUploadCompleted(result.getFile().getParentId(), result.getFile().getItemId());
|
||||
// else
|
||||
// monitor.notifyOverwriteCompleted(result.getFile().getParentId(), result.getFile().getItemId());
|
||||
// }
|
||||
// };
|
||||
// //THIS IS A DELAY TO WAIT REPOSITORY SYNCHRONIZATION
|
||||
// timer.schedule(1000);
|
||||
//
|
||||
// cancel();
|
||||
// monitor.goNextUploaderAfterKey(workspaceUploader.getClientUploadKey());
|
||||
// }else if(result.getUploadStatus().equals(UPLOAD_STATUS.FAILED)){
|
||||
// //GWT.log("Upload Failed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||
// GWT.log("Upload Failed Upload Key: "+result.getClientUploadKey() +" status description: "+result.getStatusDescription());
|
||||
// // monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
|
||||
// // queue.remove(workspaceUploader.getClientUploadKey());
|
||||
// monitor.notifyUploadError(result.getFile().getParentId(), null, result.getStatusDescription(), 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 Upload Key: "+result.getClientUploadKey() +" status description: "+result.getStatusDescription());
|
||||
// cancel();
|
||||
// monitor.notifyUploadAborted(result.getFile().getParentId(), null);
|
||||
// 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, 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();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload;
|
||||
|
||||
import org.gcube.portlets.widgets.mpformbuilder.client.ConstantsMPFormBuilder;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderServiceAsync;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.WorkspaceUploaderItem;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.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 TimerUpload INSTANCE = this;
|
||||
private UploaderProgressView upv;
|
||||
|
||||
/**
|
||||
* Instantiates a new timer upload.
|
||||
*
|
||||
* @param workspaceUploader the workspace uploader
|
||||
* @param upv
|
||||
* @param queue the queue
|
||||
* @param indexQueue the index queue
|
||||
*/
|
||||
public TimerUpload(WorkspaceUploaderItem workspaceUploader, UploaderProgressView upv) {
|
||||
this.workspaceUploader = workspaceUploader;
|
||||
this.upv = upv;
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.google.gwt.user.client.Timer#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
final SingleUploadMonitor monitor = SingleUploadMonitor.getInstance();
|
||||
|
||||
MetadataProfileFormBuilderServiceAsync.Util.getInstance().getUploadStatus(workspaceUploader.getClientUploadKey(), new AsyncCallback<WorkspaceUploaderItem>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(final 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().getFileName() +" name: "+result.getFile().getFileName());
|
||||
// queue.remove(workspaceUploader.getClientUploadKey());
|
||||
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
|
||||
|
||||
ConstantsMPFormBuilder.jslog("Upload Completed for file: "+result.getFile().getFileName());
|
||||
|
||||
Timer timer = new Timer() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ConstantsMPFormBuilder.jslog("Upload Completed "+result.getFile().getFileName());
|
||||
monitor.notifyUploadCompleted(result.getFile().getFileName(), result.getFile().getFileName());
|
||||
}
|
||||
};
|
||||
//THIS IS A DELAY TO WAIT REPOSITORY SYNCHRONIZATION
|
||||
timer.schedule(1000);
|
||||
|
||||
cancel();
|
||||
}else if(result.getUploadStatus().equals(UPLOAD_STATUS.FAILED)){
|
||||
//GWT.log("Upload Failed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||
GWT.log("Upload Failed Upload Key: "+result.getClientUploadKey() +" status description: "+result.getStatusDescription());
|
||||
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
|
||||
// queue.remove(workspaceUploader.getClientUploadKey());
|
||||
monitor.notifyUploadError(result.getFile().getFileName(), null, result.getStatusDescription(), null);
|
||||
// new DialogResult(null, "Upload Failed!!", result.getStatusDescription()).center();
|
||||
|
||||
cancel();
|
||||
}else if(result.getUploadStatus().equals(UPLOAD_STATUS.ABORTED)){
|
||||
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
|
||||
GWT.log("Upload Aborted Upload Key: "+result.getClientUploadKey() +" status description: "+result.getStatusDescription());
|
||||
cancel();
|
||||
monitor.notifyUploadAborted(result.getFile().getFileName(), null);
|
||||
}
|
||||
|
||||
//is running
|
||||
upv.update(result);
|
||||
|
||||
// GWT.log(result.toString());
|
||||
}else{
|
||||
// monitor.deleteUploaderByClientKey(workspaceUploader.getClientUploadKey());
|
||||
GWT.log("Timer is null or already closed or completed");
|
||||
cancel();
|
||||
monitor.removeTimer(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.notifyUploadError(workspaceUploader.getFile().getFileName(), null, 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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,453 +0,0 @@
|
|||
///**
|
||||
// *
|
||||
// */
|
||||
//package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Iterator;
|
||||
//import java.util.LinkedHashMap;
|
||||
//import java.util.Map;
|
||||
//import java.util.Set;
|
||||
//
|
||||
//import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.events.NotifyUploadEvent;
|
||||
//import org.gcube.portlets.widgets.mpformbuilder.client.ui.upload.events.NotifyUploadEvent.UPLOAD_EVENT_TYPE;
|
||||
//import org.gcube.portlets.widgets.mpformbuilder.shared.upload.WorkspaceUploaderItem;
|
||||
//
|
||||
//import com.google.gwt.core.shared.GWT;
|
||||
//import com.google.gwt.event.shared.HandlerManager;
|
||||
//import com.google.gwt.user.client.Timer;
|
||||
//
|
||||
///**
|
||||
// * The Class UploaderMonitor.
|
||||
// *
|
||||
// * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
// * Sep 7, 2015
|
||||
// */
|
||||
//public class UploaderMonitor {
|
||||
//
|
||||
// private static UploaderMonitor instance;
|
||||
// private final static HandlerManager monitorEventBus = new HandlerManager(null);
|
||||
// private static ArrayList<LinkedHashMap<String, WorkspaceUploaderItem>> queueUploads = new ArrayList<LinkedHashMap<String,WorkspaceUploaderItem>>();
|
||||
// private Map<String, TimerUpload> currentTimersRun = new HashMap<String, TimerUpload>();
|
||||
//
|
||||
// /**
|
||||
// * Gets the single instance of UploaderMonitor.
|
||||
// *
|
||||
// * @return single instance of UploaderMonitor
|
||||
// */
|
||||
// public static synchronized UploaderMonitor getInstance() {
|
||||
// if (instance == null){
|
||||
// instance = new UploaderMonitor();
|
||||
// }
|
||||
// return instance;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Bind events.
|
||||
// */
|
||||
// private void bindEvents() {
|
||||
//
|
||||
// /*monitorEventBus.addHandler(CancelUploadEvent.TYPE, new CancelUploadEventHandler() {
|
||||
//
|
||||
// @Override
|
||||
// public void onCancelUpload(final CancelUploadEvent deleteTimerEvent) {
|
||||
//
|
||||
// if(deleteTimerEvent.getUploader()==null)
|
||||
// return;
|
||||
//
|
||||
// final String clientKey = deleteTimerEvent.getUploader().getClientUploadKey();
|
||||
// final LinkedHashMap<String, WorkspaceUploaderItem> queue = getMapUploaderByClientUploadKey(clientKey);
|
||||
// if(queue==null){
|
||||
// GWT.log("onCancelUpload mapUpload is null for key: "+clientKey +", return");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// final TimerUpload timer = getTimer(clientKey);
|
||||
// GWT.log("Client abort for timer with clientKey "+clientKey);
|
||||
//
|
||||
// if(timer==null || !timer.isRunning()){
|
||||
// GWT.log("Timer abort skipping, timer for clientKey "+clientKey+" is null or not running");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// timer.cancel();
|
||||
//
|
||||
// RequestBuilder request = new RequestBuilder(RequestBuilder.GET, ConstantsWorkspaceUploader.WORKSPACE_UPLOADER_SERVLET_STREAM__MODIFIED+"?"+ConstantsWorkspaceUploader.CLIENT_UPLOAD_KEYS+"="+clientKey+"&"+ConstantsWorkspaceUploader.CANCEL_UPLOAD+"=true");
|
||||
// try {
|
||||
// request.sendRequest(null, new RequestCallback() {
|
||||
//
|
||||
// @Override
|
||||
// public void onResponseReceived(Request request, Response response) {
|
||||
// String result = response.getText();
|
||||
// GWT.log("onResponseReceived "+result);
|
||||
//
|
||||
// final HandlerResultMessage resultMessage = HandlerResultMessage.parseResult(result);
|
||||
// GWT.log("Cancel Upload Stream result: "+resultMessage);
|
||||
// if(resultMessage==null)
|
||||
// return;
|
||||
//
|
||||
// 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());
|
||||
// goNextUploaderAfterKey(clientKey);
|
||||
// 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
|
||||
// GWT.log("Upload Aborted is OK");
|
||||
// goNextUploaderAfterKey(clientKey);
|
||||
//
|
||||
// deleteTimerEvent.getUploader().setUploadStatus(UPLOAD_STATUS.ABORTED);
|
||||
// notifyUploadAborted(deleteTimerEvent.getUploader().getFile().getParentId(), null);
|
||||
// }
|
||||
// break;
|
||||
// }
|
||||
// case UNKNOWN:
|
||||
// case WARN:{
|
||||
// GWT.log("UNKNOWN/WARN CASE: Error during stop upload "+resultMessage.getMessage());
|
||||
// goNextUploaderAfterKey(clientKey);
|
||||
// break;
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(Request request, Throwable exception) {
|
||||
// GWT.log("ERROR: Error during stop upload "+exception.getMessage());
|
||||
// goNextUploaderAfterKey(clientKey);
|
||||
//
|
||||
// }
|
||||
// });
|
||||
// } catch (RequestException e) {
|
||||
// GWT.log("RequestException: Error during stop upload "+e.getMessage());
|
||||
// goNextUploaderAfterKey(clientKey);
|
||||
// }
|
||||
// }
|
||||
// });*/
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Start timer.
|
||||
// *
|
||||
// * @param workspaceUploader the workspace uploader
|
||||
// */
|
||||
// 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);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Removes the timer.
|
||||
// *
|
||||
// * @param clientKey the client key
|
||||
// */
|
||||
// private synchronized void removeTimer(String clientKey){
|
||||
// Timer timer = currentTimersRun.get(clientKey);
|
||||
// if(timer!=null){
|
||||
// currentTimersRun.remove(clientKey);
|
||||
// GWT.log("Remove timer for key: "+clientKey+", performed correctly");
|
||||
// }else
|
||||
// GWT.log("Remove timer for key: "+clientKey+", skypped, already removed?");
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Save timer.
|
||||
// *
|
||||
// * @param timerUpload the timer upload
|
||||
// * @param clientKey the client key
|
||||
// */
|
||||
// private synchronized void saveTimer(TimerUpload timerUpload, String clientKey){
|
||||
// currentTimersRun.put(clientKey, timerUpload);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Gets the timer.
|
||||
// *
|
||||
// * @param clientKey the client key
|
||||
// * @return the timer
|
||||
// */
|
||||
// private TimerUpload getTimer(String clientKey){
|
||||
// return currentTimersRun.get(clientKey);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Notify upload completed.
|
||||
// *
|
||||
// * @param parentId the parent id
|
||||
// * @param itemId the item id
|
||||
// */
|
||||
// protected void notifyOverwriteCompleted(String parentId, String itemId){
|
||||
// GWT.log("notifyOverwriteCompleted in monitor");
|
||||
// WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.OVERWRITE_COMPLETED, parentId, itemId));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Notify upload completed.
|
||||
// *
|
||||
// * @param parentId the parent id
|
||||
// * @param itemId the item id
|
||||
// */
|
||||
// protected void notifyUploadCompleted(String parentId, String itemId){
|
||||
// GWT.log("notifyUploadCompleted in monitor");
|
||||
// WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.UPLOAD_COMPLETED, parentId, itemId));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Notify upload aborted.
|
||||
// *
|
||||
// * @param parentId the parent id
|
||||
// * @param itemId the item id
|
||||
// */
|
||||
// protected void notifyUploadAborted(String parentId, String itemId){
|
||||
// WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.ABORTED, parentId, itemId));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Notify upload error.
|
||||
// *
|
||||
// * @param parentId the parent id
|
||||
// * @param itemId the item id
|
||||
// * @param t the t
|
||||
// */
|
||||
// protected void notifyUploadError(String parentId, String itemId, String error, Throwable t){
|
||||
// WorkspaceUploaderListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.FAILED, parentId, itemId, error, t));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * New queue.
|
||||
// *
|
||||
// * @return the int
|
||||
// */
|
||||
// public synchronized int newQueue() {
|
||||
//
|
||||
// int freeIndex = -1;
|
||||
// GWT.log("Current queue upload size is: "+queueUploads.size());
|
||||
// for(int i = 0; i < queueUploads.size(); i++){
|
||||
// if(queueUploads.get(i) == null){
|
||||
// freeIndex = i;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// GWT.log("Index for new queue uploads is: "+freeIndex);
|
||||
//
|
||||
// if(freeIndex>=0 && freeIndex<queueUploads.size()){
|
||||
// GWT.log("Using set index: "+freeIndex);
|
||||
// queueUploads.set(freeIndex, new LinkedHashMap<String,WorkspaceUploaderItem>());
|
||||
// }else{
|
||||
// freeIndex= queueUploads.size();
|
||||
// GWT.log("Using add index: "+freeIndex);
|
||||
// queueUploads.add(freeIndex, new LinkedHashMap<String,WorkspaceUploaderItem>());
|
||||
// }
|
||||
// GWT.log("Returning new queue index: "+freeIndex);
|
||||
// return freeIndex;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Delete queue.
|
||||
// *
|
||||
// * @param index the index
|
||||
// */
|
||||
// public synchronized void deleteQueue(int index) {
|
||||
//
|
||||
// if(index<0){
|
||||
// GWT.log("Delete queue at invalid index: "+index +", skipping delete");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// if(queueUploads.get(index)!=null){
|
||||
// queueUploads.set(index, null);
|
||||
// GWT.log("Deleted queue at index: "+index);
|
||||
// }else
|
||||
// GWT.log("Queue at index: "+index +", not found, already deleted?, skipping");
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Adds the new uploader to queue.
|
||||
// *
|
||||
// * @param indexQueue the index queue
|
||||
// * @param workspaceUploaderItem the workspace uploader item
|
||||
// * @return the linked hash map
|
||||
// */
|
||||
// public LinkedHashMap<String, WorkspaceUploaderItem> addNewUploaderToQueue(int indexQueue, WorkspaceUploaderItem workspaceUploaderItem) {
|
||||
// LinkedHashMap<String, WorkspaceUploaderItem> queue = queueUploads.get(indexQueue);
|
||||
// queue.put(workspaceUploaderItem.getClientUploadKey(), workspaceUploaderItem);
|
||||
// return queue;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Do start polling queue.
|
||||
// *
|
||||
// * @param index the index
|
||||
// */
|
||||
// public synchronized void doStartPollingQueue(int index) {
|
||||
// LinkedHashMap<String, WorkspaceUploaderItem> queue = queueUploads.get(index);
|
||||
//
|
||||
// if(queue.size()<0){
|
||||
// GWT.log("doStartPollingQueue return, queue size is < 0");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// Set<String> keys = queue.keySet();
|
||||
//
|
||||
// if(keys.size()==0){
|
||||
// GWT.log("no keys for queue index: "+index+", return");
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// WorkspaceUploaderItem workspaceUploader = getNextUploader(queue);
|
||||
// startTimer(workspaceUploader);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 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 mapUploaders the map uploaders
|
||||
// * @return the next uploader
|
||||
// */
|
||||
// protected WorkspaceUploaderItem getNextUploader(LinkedHashMap<String, WorkspaceUploaderItem> mapUploaders){
|
||||
// Iterator<String> it = mapUploaders.keySet().iterator();
|
||||
// String firstKey = it.next();
|
||||
//
|
||||
// if(firstKey==null || firstKey.isEmpty()){
|
||||
// GWT.log("getNextUploader return empty or null key, returning null");
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// return mapUploaders.get(firstKey);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Next uploader.
|
||||
// *
|
||||
// * @param mapUploaders the map uploaders
|
||||
// * @param clientKey the client key
|
||||
// */
|
||||
// protected synchronized void nextUploader(LinkedHashMap<String, WorkspaceUploaderItem> mapUploaders, String clientKey){
|
||||
//
|
||||
// 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(mapUploaders);
|
||||
//
|
||||
// if(workspaceUploader==null){
|
||||
// GWT.log("nextUploader return a null uploader, deleting queue");
|
||||
// deleteQueue(index);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// 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;
|
||||
// }
|
||||
//
|
||||
//}
|
|
@ -62,10 +62,10 @@ public class UploaderProgressView {
|
|||
setVisibleCancel(false);
|
||||
vp.add(hp);
|
||||
|
||||
hpBar.add(cancelImg);
|
||||
hpBar.add(bar);
|
||||
vp.add(hpBar);
|
||||
// vp.add(bar);
|
||||
//TODO DISPLAY PROGRESS BAR...
|
||||
//hpBar.add(cancelImg);
|
||||
//hpBar.add(bar);
|
||||
//vp.add(hpBar);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,16 +91,16 @@ public class UploaderProgressView {
|
|||
case COMPLETED:
|
||||
setVisibleBar(true);
|
||||
text = "<div><img src='"+Images.ICONS.completed().getURL()+"'>";
|
||||
String msgClt = StringUtil.ellipsize(uploader.getFile().getFileName()+" uploaded successfully!", MAX_CHARS, 0);
|
||||
String msgClt = uploader.getFile().getFileName()+" uploaded successfully!";
|
||||
|
||||
text+="<span style='margin-left:5px; vertical-align: top;'>"+msgClt+"</span></div>";
|
||||
// GWT.log(text);
|
||||
html.setHTML(text);
|
||||
html.setTitle(uploader.getStatusDescription());
|
||||
bar.update(uploader.getUploadProgress().getLastEvent().getReadPercentage());
|
||||
try{
|
||||
hpBar.clear();
|
||||
}catch (Exception e) {}
|
||||
// try{
|
||||
// hpBar.clear();
|
||||
// }catch (Exception e) {}
|
||||
break;
|
||||
case FAILED:
|
||||
setVisibleBar(true);
|
||||
|
|
|
@ -5,9 +5,16 @@ import java.io.InputStream;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.client.MetadataProfileFormBuilderService;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.server.util.WsUtil;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.UploadProgress;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.WorkspaceUploaderItem;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.WorkspaceUploaderItem.UPLOAD_STATUS;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -71,4 +78,71 @@ public class MetadataProfileFormBuilderServiceImpl extends RemoteServiceServlet
|
|||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderService#getUploadStatus(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public WorkspaceUploaderItem getUploadStatus(String identifier) throws Exception {
|
||||
LOG.debug("Called getUploadStatus for id: "+identifier);
|
||||
|
||||
if (identifier == null || identifier.isEmpty()) {
|
||||
String exception = "Invalid upload identifier, it is null or empty";
|
||||
LOG.error(exception);
|
||||
throw new Exception(exception);
|
||||
}
|
||||
|
||||
WorkspaceUploaderItem uploader = WsUtil.getWorkspaceUploaderInSession(getThreadLocalRequest(), identifier);
|
||||
|
||||
if (uploader == null) {
|
||||
WorkspaceUploaderItem waitingUpload = new WorkspaceUploaderItem(identifier, null, UPLOAD_STATUS.WAIT, "Upload waiting..", new UploadProgress());
|
||||
waitingUpload.setClientUploadKey(identifier);
|
||||
return waitingUpload;
|
||||
}
|
||||
|
||||
// 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";
|
||||
|
||||
LOG.debug("returning uploader: "+uploader.getClientUploadKey() +" status: "+uploader.getUploadStatus() +", file: "+uploader.getFile().toString() +", progress: "+progress);
|
||||
|
||||
checkUploaderErasable(this.getThreadLocalRequest(), uploader);
|
||||
return uploader;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check uploader erasable.
|
||||
*
|
||||
* @param httpRequest the http request
|
||||
* @param uploader the uploader
|
||||
*/
|
||||
private void checkUploaderErasable(final HttpServletRequest httpRequest, final WorkspaceUploaderItem uploader){
|
||||
LOG.debug("Called check Uploader erasable...");
|
||||
|
||||
if(uploader==null){
|
||||
LOG.error("Uploader is null, returning..");
|
||||
return;
|
||||
}
|
||||
|
||||
final HttpSession session = httpRequest.getSession();
|
||||
|
||||
new Thread(){
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
LOG.debug("Uploader: "+uploader.getClientUploadKey() +", is erasable? "+uploader.isErasable());
|
||||
WsUtil.eraseWorkspaceUploaderInSession(session, uploader);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.warn("Error during checkUploaderErasable: ", e);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -433,7 +433,7 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
|
|||
// sendError(response, "Internal error: An error occurred on uploading the file, try again later");
|
||||
// return;
|
||||
}finally{
|
||||
removeCurrentListener(request.getSession(), clientUploadKey);
|
||||
//removeCurrentListener(request.getSession(), clientUploadKey);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,14 +5,15 @@ package org.gcube.portlets.widgets.mpformbuilder.shared.upload;
|
|||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.google.gwt.user.client.rpc.IsSerializable;
|
||||
|
||||
public class WorkspaceUploaderItem implements Serializable{
|
||||
|
||||
public class WorkspaceUploaderItem implements Serializable, IsSerializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3635794780284917733L;
|
||||
private static final long serialVersionUID = 2858520729654840274L;
|
||||
|
||||
/**
|
||||
* The Enum UPLOAD_STATUS.
|
||||
|
@ -49,7 +50,6 @@ public class WorkspaceUploaderItem implements Serializable{
|
|||
private String statusDescription;
|
||||
private String clientUploadKey;
|
||||
private UploadProgress uploadProgress;
|
||||
private Boolean isOverwrite;
|
||||
// private Long threadId;
|
||||
private Boolean erasable;
|
||||
|
||||
|
@ -193,20 +193,6 @@ public class WorkspaceUploaderItem implements Serializable{
|
|||
this.uploadProgress = uploadProgress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the isOverwrite
|
||||
*/
|
||||
public Boolean getIsOverwrite() {
|
||||
return isOverwrite;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isOverwrite the isOverwrite to set
|
||||
*/
|
||||
public void setIsOverwrite(Boolean isOverwrite) {
|
||||
this.isOverwrite = isOverwrite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the erasable.
|
||||
*
|
||||
|
@ -249,8 +235,6 @@ public class WorkspaceUploaderItem implements Serializable{
|
|||
builder.append(clientUploadKey);
|
||||
// builder.append(", uploadProgress=");
|
||||
// builder.append(uploadProgress);
|
||||
builder.append(", isOverwrite=");
|
||||
builder.append(isOverwrite);
|
||||
builder.append(", erasable=");
|
||||
builder.append(erasable);
|
||||
builder.append("]");
|
||||
|
|
Loading…
Reference in New Issue