added the upload servlet
This commit is contained in:
parent
dde2d039d9
commit
15f4c01ec5
|
@ -1,30 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-module deploy-name="metadata-profile-form-builder-widget-0.1.0-SNAPSHOT">
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
|
||||
|
||||
|
||||
|
||||
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/resources"/>
|
||||
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/test/java"/>
|
||||
|
||||
|
||||
|
||||
|
||||
<property name="context-root" value="metadata-profile-form-builder-widget"/>
|
||||
|
||||
|
||||
|
||||
|
||||
<property name="java-output-path" value="/metadata-profile-form-builder-widget/target/classes"/>
|
||||
|
||||
|
||||
|
||||
|
||||
</wb-module>
|
||||
|
||||
|
||||
|
||||
|
||||
</project-modules>
|
||||
|
|
|
@ -4,12 +4,13 @@ import com.google.gwt.core.client.GWT;
|
|||
|
||||
public class ConstantsMPFormBuilder {
|
||||
|
||||
public static final String WORKSPACE_UPLOADER_SERVLET_STREAM__MODIFIED = GWT.getModuleBaseURL() + "mpformbuilderUploadServlet";
|
||||
public static final String WORKSPACE_UPLOADER_SERVLET_STREAM__MODIFIED = GWT.getModuleBaseURL() + "metadataProfileFormBuilderUploadServlet";
|
||||
public static final String CURR_GROUP_ID = "currGroupId";
|
||||
|
||||
//public static final String CURR_USER_ID = "currUserId";
|
||||
public static final String IS_OVERWRITE = "isOverwrite";
|
||||
public static final String UPLOAD_TYPE = "uploadType";
|
||||
public static enum THE_UPLOAD_TYPE {File, Archive};
|
||||
public static final String ID_FOLDER = "idFolder";
|
||||
public static final String UPLOAD_FORM_ELEMENT = "uploadFormElement";
|
||||
|
||||
|
|
|
@ -1,21 +1,31 @@
|
|||
package org.gcube.portlets.widgets.mpformbuilder.client.ui.icons;
|
||||
|
||||
|
||||
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.resources.client.ClientBundle;
|
||||
import com.google.gwt.resources.client.ImageResource;
|
||||
|
||||
public interface Images extends ClientBundle {
|
||||
|
||||
|
||||
public static final Images ICONS = GWT.create(Images.class);
|
||||
|
||||
|
||||
@Source("file.png")
|
||||
ImageResource fileIcon();
|
||||
|
||||
|
||||
@Source("folder.png")
|
||||
ImageResource folderIcon();
|
||||
|
||||
|
||||
@Source("loading.gif")
|
||||
ImageResource loading();
|
||||
|
||||
@Source("completed.gif")
|
||||
ImageResource completed();
|
||||
|
||||
@Source("delete.gif")
|
||||
ImageResource delete();
|
||||
|
||||
@Source("failed.png")
|
||||
ImageResource failed();
|
||||
|
||||
@Source("abort.png")
|
||||
ImageResource aborted();
|
||||
}
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 319 B |
Binary file not shown.
After Width: | Height: | Size: 541 B |
Binary file not shown.
After Width: | Height: | Size: 120 B |
Binary file not shown.
After Width: | Height: | Size: 655 B |
|
@ -46,10 +46,12 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
|
|||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Sep 11, 2015
|
||||
*/
|
||||
private HTML LOADING = new HTML("Upload starting...");
|
||||
private HTML UPLOADING = new HTML("Uploading...");
|
||||
protected VerticalPanel panel;
|
||||
// private MonitorPanel monitorPanel;
|
||||
protected String clientUploadKey;
|
||||
|
||||
private String purgedUploadingFileName;
|
||||
|
||||
/**
|
||||
* Instantiates a new dialog upload stream.
|
||||
|
@ -75,6 +77,7 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
|
|||
|
||||
// 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()));
|
||||
|
||||
initJsonClientKeys();
|
||||
panel.add(jsonClientKeys);
|
||||
|
@ -174,22 +177,30 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
|
|||
@Override
|
||||
public void onSubmit(SubmitEvent event) {
|
||||
GWT.log("SubmitEvent");
|
||||
/*addLoading();
|
||||
addLoading();
|
||||
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().addNewUploaderToQueue(queueIndex, fakeUploader);
|
||||
UploaderMonitor.getInstance().doStartPollingQueue(queueIndex);
|
||||
*/
|
||||
// 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);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
fileUpload.addChangeHandler(new ChangeHandler() {
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onChange(ChangeEvent event) {
|
||||
|
||||
|
@ -208,7 +219,7 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
|
|||
normalizedFileName = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\")+1); //remove C:\fakepath\ if exists
|
||||
}
|
||||
|
||||
final String label = normalizedFileName;
|
||||
purgedUploadingFileName = normalizedFileName;
|
||||
submitForm();
|
||||
}
|
||||
});
|
||||
|
@ -218,7 +229,7 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
|
|||
* Adds the loading.
|
||||
*/
|
||||
protected void addLoading(){
|
||||
panel.add(LOADING);
|
||||
panel.add(UPLOADING);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -226,7 +237,7 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
|
|||
*/
|
||||
protected void removeLoading(){
|
||||
try{
|
||||
panel.remove(LOADING);
|
||||
panel.remove(UPLOADING);
|
||||
}catch(Exception e){
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,138 @@
|
|||
///**
|
||||
// *
|
||||
// */
|
||||
//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();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
//}
|
|
@ -0,0 +1,453 @@
|
|||
///**
|
||||
// *
|
||||
// */
|
||||
//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;
|
||||
// }
|
||||
//
|
||||
//}
|
|
@ -0,0 +1,230 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload;
|
||||
|
||||
import org.gcube.portlets.widgets.mpformbuilder.client.ui.icons.Images;
|
||||
import org.gcube.portlets.widgets.mpformbuilder.client.ui.utils.StringUtil;
|
||||
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.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.HasVerticalAlignment;
|
||||
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||
import com.google.gwt.user.client.ui.Image;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
|
||||
|
||||
/**
|
||||
* The Class UploaderProgressView.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Oct 12, 2015
|
||||
*/
|
||||
public class UploaderProgressView {
|
||||
|
||||
private VerticalPanel vp = new VerticalPanel();
|
||||
private static final int MAX_CHARS = 50;
|
||||
private HorizontalPanel hp = new HorizontalPanel();
|
||||
private HorizontalPanel hpBar = new HorizontalPanel();
|
||||
private HTML html = new HTML();
|
||||
private ProgressBar bar = new ProgressBar();
|
||||
private HandlerManager eventBus;
|
||||
private boolean cancel = false;
|
||||
private Image cancelImg = new Image(Images.ICONS.delete());
|
||||
|
||||
/**
|
||||
* Instantiates a new uploader progress view.
|
||||
*
|
||||
* @param uploader the uploader
|
||||
* @param fileName the file name
|
||||
* @param eventBus the event bus
|
||||
*/
|
||||
public UploaderProgressView(WorkspaceUploaderItem uploader, final String fileName, HandlerManager eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
cancelImg.setTitle("Cancel upload");
|
||||
cancelImg.addStyleName("cancel-upload");
|
||||
hpBar.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
|
||||
hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
|
||||
|
||||
String text = "<div><img src='"+Images.ICONS.loading().getURL()+"'>";
|
||||
String msg = StringUtil.ellipsize("Uploading "+fileName, MAX_CHARS, 0);
|
||||
text+="<span style='margin-left:5px; vertical-align: top;'>"+msg+"</span>";
|
||||
text+="</div>";
|
||||
|
||||
html.setHTML(text);
|
||||
html.setTitle("Uploading "+fileName);
|
||||
hp.add(html);
|
||||
|
||||
bar.update(0);
|
||||
setVisibleBar(false);
|
||||
setVisibleCancel(false);
|
||||
vp.add(hp);
|
||||
|
||||
hpBar.add(cancelImg);
|
||||
hpBar.add(bar);
|
||||
vp.add(hpBar);
|
||||
// vp.add(bar);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
*/
|
||||
private void setVisibleCancel(boolean b) {
|
||||
cancelImg.setVisible(b);
|
||||
}
|
||||
|
||||
public void setVisibleBar(boolean bool){
|
||||
bar.setVisible(bool);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update.
|
||||
*
|
||||
* @param uploader the uploader
|
||||
*/
|
||||
public void update(WorkspaceUploaderItem uploader){
|
||||
String text;
|
||||
try{
|
||||
switch(uploader.getUploadStatus()){
|
||||
case COMPLETED:
|
||||
setVisibleBar(true);
|
||||
text = "<div><img src='"+Images.ICONS.completed().getURL()+"'>";
|
||||
String msgClt = StringUtil.ellipsize(uploader.getFile().getFileName()+" uploaded successfully!", MAX_CHARS, 0);
|
||||
|
||||
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) {}
|
||||
break;
|
||||
case FAILED:
|
||||
setVisibleBar(true);
|
||||
text = "<div><img src='"+Images.ICONS.failed().getURL()+"'>";
|
||||
text+="<span style='margin-left:5px; vertical-align: top;'>"+StringUtil.ellipsize(uploader.getStatusDescription(), MAX_CHARS, 0)+"</span></div>";
|
||||
// GWT.log(text);
|
||||
html.setHTML(text);
|
||||
html.setTitle(uploader.getStatusDescription());
|
||||
// bar.update(uploader.getUploadProgress().getLastEvent().getReadPercentage());
|
||||
try{
|
||||
hpBar.clear();
|
||||
}catch (Exception e) {}
|
||||
break;
|
||||
case ABORTED:
|
||||
setVisibleBar(true);
|
||||
text = "<div><img src='"+Images.ICONS.aborted().getURL()+"'>";
|
||||
text+="<span style='margin-left:5px; vertical-align: top;'>"+StringUtil.ellipsize(uploader.getStatusDescription(), MAX_CHARS, 0)+"</span></div>";
|
||||
// GWT.log(text);
|
||||
html.setHTML(text);
|
||||
html.setTitle(uploader.getStatusDescription());
|
||||
// bar.update(uploader.getUploadProgress().getLastEvent().getReadPercentage());
|
||||
try{
|
||||
hpBar.clear();
|
||||
}catch (Exception e) {}
|
||||
break;
|
||||
case IN_PROGRESS:
|
||||
setVisibleBar(true);
|
||||
// text = "<div><img src='"+WorkspaceUploaderResources.getImageUpload().getUrl()+"'>";
|
||||
text = "<div><img src='"+Images.ICONS.loading().getURL()+"'>";
|
||||
|
||||
String msg = "";
|
||||
if(uploader.getUploadProgress().getLastEvent().getReadPercentage()<100){
|
||||
msg = StringUtil.ellipsize(uploader.getFile().getFileName(), MAX_CHARS, 0);
|
||||
}else{ //is 100%
|
||||
String message = "Finalising the upload of "+ uploader.getFile().getFileName();
|
||||
msg = StringUtil.ellipsize(message, MAX_CHARS, 0);
|
||||
}
|
||||
|
||||
text+="<span style='margin-left:5px; vertical-align: top;'>"+msg+"</span>";
|
||||
text+="</div>";
|
||||
// GWT.log(text);
|
||||
html.setHTML(text);
|
||||
html.setTitle(uploader.getStatusDescription());
|
||||
|
||||
//TODO CANCEL OPERATION MUST BE ENHANCED IN ORDER TO CANCELL ALL UPLOADS
|
||||
/*
|
||||
if(uploader.getUploadProgress().getLastEvent().getReadPercentage()!=100 && !cancel){
|
||||
cancel = true;
|
||||
handleCancelUpload(uploader);
|
||||
setVisibleCancel(true);
|
||||
}else if(uploader.getUploadProgress().getLastEvent().getReadPercentage()==100 && cancel){
|
||||
try{
|
||||
setVisibleCancel(false);
|
||||
// hp.remove(cancelImg);
|
||||
}catch (Exception e) {}
|
||||
}*/
|
||||
|
||||
bar.update(uploader.getUploadProgress().getLastEvent().getReadPercentage());
|
||||
break;
|
||||
case WAIT:
|
||||
setVisibleBar(false);
|
||||
text = "<div><img src='"+Images.ICONS.loading().getURL()+"'>";
|
||||
String descr = "";
|
||||
if(uploader.getFile()!=null && uploader.getFile().getFileName()!=null)
|
||||
descr = uploader.getFile().getFileName();
|
||||
else
|
||||
descr = uploader.getStatusDescription();
|
||||
|
||||
text+="<span style='margin-left:5px; vertical-align: top;'>"+StringUtil.ellipsize(descr, MAX_CHARS, 0)+"</span></div>";
|
||||
text+="</div>";
|
||||
// GWT.log(text);
|
||||
html.setHTML(text);
|
||||
|
||||
if(uploader.getUploadProgress()!=null && uploader.getUploadProgress().getLastEvent()!=null)
|
||||
bar.update(uploader.getUploadProgress().getLastEvent().getReadPercentage());
|
||||
else
|
||||
bar.update(0);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}catch(Exception e) {
|
||||
GWT.log("error during update");
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Handle cancel upload.
|
||||
// *
|
||||
// * @param uploader the uploader
|
||||
// * @return the image
|
||||
// */
|
||||
// private Image handleCancelUpload(final WorkspaceUploaderItem uploader){
|
||||
//
|
||||
// cancelImg.addClickHandler(new ClickHandler() {
|
||||
//
|
||||
// @Override
|
||||
// public void onClick(ClickEvent event) {
|
||||
// GWT.log("Click cancel");
|
||||
// String fileName = uploader.getFile()!=null? uploader.getFile().getFileName(): "";
|
||||
// if(Window.confirm("Confirm cancel uploading "+fileName+"?")){
|
||||
// hp.clear();
|
||||
// HTML html = new HTML();
|
||||
// hp.add(html);
|
||||
// String text = "<div><img src='"+Images.ICONS.delete().getURL()+"'>";
|
||||
// String msg = StringUtil.ellipsize("Aborting upload: "+fileName, MAX_CHARS, 0);
|
||||
// text+="<span style='margin-left:5px; vertical-align: top;'>"+msg+"</span></div>";
|
||||
// html.setHTML(text);
|
||||
// eventBus.fireEvent(new CancelUploadEvent(uploader, UploaderProgressView.this, fileName));
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// return cancelImg;
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Gets the panel.
|
||||
*
|
||||
* @return the panel
|
||||
*/
|
||||
public VerticalPanel getPanel() {
|
||||
return vp;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.widgets.mpformbuilder.client.ui.utils;
|
||||
|
||||
import com.google.gwt.core.shared.GWT;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Sep 9, 2015
|
||||
*/
|
||||
public class StringUtil {
|
||||
|
||||
/**
|
||||
* Puts ellipses in input strings that are longer than than maxCharacters. Shorter strings or
|
||||
* null is returned unchanged.
|
||||
* @param input the input string that may be subjected to shortening
|
||||
* @param maxCharacters the maximum characters that are acceptable for the unshortended string. Must be at least 3, otherwise a string with ellipses is too long already.
|
||||
* @param the number of characters that should appear after the ellipsis (0 or larger)
|
||||
*/
|
||||
public static String ellipsize(String input, int maxCharacters, int charactersAfterEllipsis) {
|
||||
|
||||
try{
|
||||
if(maxCharacters < 3) {
|
||||
throw new IllegalArgumentException("maxCharacters must be at least 3 because the ellipsis already take up 3 characters");
|
||||
}
|
||||
if(maxCharacters - 3 < charactersAfterEllipsis) {
|
||||
throw new IllegalArgumentException("charactersAfterEllipsis must be less than maxCharacters-3");
|
||||
}
|
||||
if (input == null || input.length() < maxCharacters) {
|
||||
return input;
|
||||
}
|
||||
return input.substring(0, maxCharacters - 3 - charactersAfterEllipsis) + "..." + input.substring(input.length() - charactersAfterEllipsis);
|
||||
}catch(Exception e){
|
||||
GWT.log(e.getMessage());
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -10,7 +10,6 @@ import java.io.InputStream;
|
|||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.Servlet;
|
||||
|
@ -90,8 +89,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
|
|||
/** The Constant CANCEL_UPLOAD. */
|
||||
public static final String CANCEL_UPLOAD = ConstantsMPFormBuilder.CANCEL_UPLOAD;
|
||||
|
||||
/** The Constant FILE. */
|
||||
public static final String FILE = "File";
|
||||
/** The Constant UPLOAD_TYPE. */
|
||||
public static final String UPLOAD_TYPE = ConstantsMPFormBuilder.UPLOAD_TYPE;
|
||||
|
||||
/** The logger. */
|
||||
public static Logger logger = LoggerFactory.getLogger(MetadataProfileFormBuilderUploadServlet.class);
|
||||
|
@ -178,17 +177,18 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
|
|||
logger.debug("UPLOAD-SERVLET (" + session.getId() + ") new upload request received.");
|
||||
|
||||
|
||||
|
||||
if(WsUtil.isSessionExpired(request)){
|
||||
logger.error("SESSION_EXPIRED: session is expired");
|
||||
sendSessionExpired(response, "SESSION_EXPIRED: session is expired");
|
||||
return;
|
||||
}
|
||||
|
||||
String destinationId = null;
|
||||
String uploadType = null;
|
||||
// String clientUploadKey = null;
|
||||
FileItemStream uploadItem = null;
|
||||
ArrayList<String> listClientUploadKeys = null;
|
||||
|
||||
GCubeUser user = PortalContext.getConfiguration().getCurrentUser(request);
|
||||
FileItemFactory factory = new DiskFileItemFactory();
|
||||
ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
|
||||
|
@ -206,10 +206,10 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
|
|||
while (fileItemIterator.hasNext()) {
|
||||
FileItemStream item = fileItemIterator.next();
|
||||
|
||||
// if (item.isFormField() && UPLOAD_TYPE.equals(item.getFieldName())){
|
||||
// uploadType = Streams.asString(item.openStream());
|
||||
// logger.debug("UPLOAD_TYPE OK " +uploadType);
|
||||
// }
|
||||
if (item.isFormField() && UPLOAD_TYPE.equals(item.getFieldName())){
|
||||
uploadType = Streams.asString(item.openStream());
|
||||
logger.debug("UPLOAD_TYPE OK " +uploadType);
|
||||
}
|
||||
|
||||
// if (item.isFormField() && IS_OVERWRITE.equals(item.getFieldName())){
|
||||
// try{
|
||||
|
@ -251,7 +251,7 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
|
|||
uploadItem = item;
|
||||
logger.debug("UPLOAD_FORM_ELEMENT OK "+uploadItem.getName() + " scopeGroupId="+scopeGroupId);
|
||||
// break;
|
||||
uploadData(user, scopeGroupId, request, response, uploadItem, destinationId, uploadType, listClientUploadKeys.get(uploadItemsCnt));
|
||||
uploadData(user, scopeGroupId, request, response, uploadItem, uploadType, listClientUploadKeys.get(uploadItemsCnt));
|
||||
uploadItemsCnt++;
|
||||
}
|
||||
}
|
||||
|
@ -336,16 +336,15 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
|
|||
* @param request the request
|
||||
* @param response the response
|
||||
* @param uploadItem the upload item
|
||||
* @param destinationId the destination id
|
||||
* @param uploadType the upload type
|
||||
* @param clientUploadKey the client upload key
|
||||
* @throws ServletException the servlet exception
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
private void uploadData(GCubeUser user, String scopeGroupId, HttpServletRequest request, final HttpServletResponse response, final FileItemStream uploadItem, String destinationId,String uploadType,String clientUploadKey) throws ServletException, IOException{
|
||||
private void uploadData(GCubeUser user, String scopeGroupId, HttpServletRequest request, final HttpServletResponse response, final FileItemStream uploadItem, String uploadType,String clientUploadKey) throws ServletException, IOException{
|
||||
|
||||
String fileName = uploadItem.getName();
|
||||
logger.info("Upload servlet parameters: [fileName: "+fileName+ ", destinationId: "+destinationId +", uploadType: "+uploadType+", clientUploadKey: "+clientUploadKey+"]");
|
||||
logger.info("Upload servlet parameters: [fileName: "+fileName+ ", uploadType: "+uploadType+", clientUploadKey: "+clientUploadKey+"]");
|
||||
|
||||
if (uploadType == null || uploadType.isEmpty()) {
|
||||
logger.error("Error processing request in upload servlet for: "+fileName+". No upload type found");
|
||||
|
@ -405,15 +404,22 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
|
|||
String contentType = uploadItem.getContentType();
|
||||
logger.debug("Stream content type: "+contentType);
|
||||
|
||||
|
||||
//UPLOAD FILE. IT IS DEFAULT CASE
|
||||
logger.debug("Uploding file in the temp system TEMP");
|
||||
workspaceUploader = createStreamToTempFile(workspaceUploader, inputStream, user.getUsername(), clientUploadKey, fileName, extension);
|
||||
logger.debug("Uploding file in the TEMP system folder...");
|
||||
workspaceUploader = createStreamToTempFile(request, workspaceUploader, inputStream, user.getUsername(), clientUploadKey, fileName, extension);
|
||||
|
||||
saveWorkspaceUploaderInSession(workspaceUploader, request.getSession());
|
||||
|
||||
if(workspaceUploader==null)
|
||||
throw new Exception("Error when creating uploader, it is null!");
|
||||
|
||||
/*
|
||||
* Incident #10095. Commented OK as response
|
||||
* in order to avoid downloading of .dms file by Safari
|
||||
* from MAC
|
||||
*/
|
||||
//sendMessage(response, workspaceUploader.getIdentifier());
|
||||
|
||||
} catch (IOException e){
|
||||
logger.error("Error creating elements, is it cancel?", e);
|
||||
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "Uploading error", request.getSession());
|
||||
|
@ -469,17 +475,6 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
|
|||
workspaceUploader.setFile(wsUploadFile);
|
||||
return workspaceUploader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the random.
|
||||
*
|
||||
* @return the random
|
||||
*/
|
||||
private static int getRandom(){
|
||||
Random randomGenerator = new Random();
|
||||
return randomGenerator.nextInt(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save workspace uploader in session.
|
||||
|
@ -505,6 +500,7 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
|
|||
|
||||
/**
|
||||
* Creates the stream to temp file.
|
||||
* @param request
|
||||
*
|
||||
* @param workspaceUploader the workspace uploader
|
||||
* @param in the in
|
||||
|
@ -515,11 +511,16 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
|
|||
* @return the workspace uploader item
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public WorkspaceUploaderItem createStreamToTempFile(WorkspaceUploaderItem workspaceUploader, InputStream in, String username, String clientUploadKey, String fileName, String fileExtension) throws IOException{
|
||||
public WorkspaceUploaderItem createStreamToTempFile(HttpServletRequest request, WorkspaceUploaderItem workspaceUploader, InputStream in, String username, String clientUploadKey, String fileName, String fileExtension) throws IOException{
|
||||
|
||||
if(fileExtension==null)
|
||||
if (fileExtension == null)
|
||||
fileExtension = "";
|
||||
if (username == null)
|
||||
username = "";
|
||||
try {
|
||||
workspaceUploader.setStatusDescription("Uploading...");
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.IN_PROGRESS);
|
||||
saveWorkspaceUploaderInSession(workspaceUploader, request.getSession());
|
||||
String uniqueFileName = String.format("%s_%s_%s",username,fileName,clientUploadKey);
|
||||
File tempFile = File.createTempFile(uniqueFileName, fileExtension);
|
||||
//tempFile.deleteOnExit();
|
||||
|
@ -528,9 +529,17 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
|
|||
workspaceUploader.getFile().setTempSystemPath(tempFile.getAbsolutePath());
|
||||
workspaceUploader.setStatusDescription("File uploaded correclty");
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.COMPLETED);
|
||||
saveWorkspaceUploaderInSession(workspaceUploader, request.getSession());
|
||||
}catch (Exception e) {
|
||||
workspaceUploader.setStatusDescription("Error on uploading: "+fileName+". "+e.getMessage());
|
||||
workspaceUploader.setUploadStatus(UPLOAD_STATUS.FAILED);
|
||||
}finally {
|
||||
try {
|
||||
// StreamUtils.deleteTempFile(uploadFile);
|
||||
WsUtil.setErasableWorkspaceUploaderInSession(request, workspaceUploader.getIdentifier());
|
||||
} catch (Exception e2) {
|
||||
logger.error("Error during setErasableWorkspaceUploaderInSession session update: ",e2);
|
||||
}
|
||||
}
|
||||
return workspaceUploader;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<!-- -->
|
||||
<!-- Any title is fine -->
|
||||
<!-- -->
|
||||
<title>"Metadata Profile Form Builder Web Application</title>
|
||||
<title>Metadata Profile Form Builder Web Application</title>
|
||||
|
||||
<!-- -->
|
||||
<!-- This script loads your compiled module. -->
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
<!-- Servlets -->
|
||||
<servlet>
|
||||
<servlet-name>mpformbuilderUploadServlet</servlet-name>
|
||||
<servlet-name>metadataProfileFormBuilderUploadServlet</servlet-name>
|
||||
<servlet-class>org.gcube.portlets.widgets.mpformbuilder.server.MetadataProfileFormBuilderUploadServlet</servlet-class>
|
||||
</servlet>
|
||||
|
||||
|
@ -25,8 +25,8 @@
|
|||
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>mpformbuilderUploadServlet</servlet-name>
|
||||
<url-pattern>/MetadataProfileFormBuilder/mpformbuilderUploadServlet</url-pattern>
|
||||
<servlet-name>metadataProfileFormBuilderUploadServlet</servlet-name>
|
||||
<url-pattern>/MetadataProfileFormBuilder/metadataProfileFormBuilderUploadServlet</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue