Fixed issue on upload archive
Added listener controller git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-uploader@119406 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
c6a54dd79d
commit
bf3e09f5cd
|
@ -0,0 +1,152 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.widgets.workspaceuploader.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.events.NotifyUploadEvent;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.events.NotifyUploadEventHandler;
|
||||
|
||||
import com.google.gwt.core.shared.GWT;
|
||||
import com.google.gwt.event.shared.HandlerManager;
|
||||
|
||||
|
||||
/**
|
||||
* The Class WorkspaceExplorerListenerController.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Oct 5, 2015
|
||||
*/
|
||||
public class WorkspaceExplorerListenerController {
|
||||
|
||||
private static HandlerManager controllerEventBus = null;
|
||||
|
||||
private List<WorskpaceUploadNotificationListener> listenersUpload = new ArrayList<WorskpaceUploadNotificationListener>();
|
||||
|
||||
/**
|
||||
* Instantiates a new workspace explorer listener controller.
|
||||
*/
|
||||
public WorkspaceExplorerListenerController(){
|
||||
controllerEventBus = new HandlerManager(null);
|
||||
bindEvents();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind events.
|
||||
*/
|
||||
private void bindEvents() {
|
||||
controllerEventBus.addHandler(NotifyUploadEvent.TYPE, new NotifyUploadEventHandler() {
|
||||
|
||||
@Override
|
||||
public void onNotifyUpload(NotifyUploadEvent notifyUploadEvent) {
|
||||
|
||||
if(notifyUploadEvent.getEvent()==null)
|
||||
return;
|
||||
|
||||
switch(notifyUploadEvent.getEvent()){
|
||||
|
||||
case COMPLETED:
|
||||
GWT.log("NotifyUploadEvent Completed");
|
||||
notifyUploadCompleted(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId());
|
||||
break;
|
||||
case ABORTED:
|
||||
GWT.log("NotifyUploadEvent Aborted");
|
||||
notifyUploadAborted(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId());
|
||||
break;
|
||||
case FAILED:
|
||||
GWT.log("NotifyUploadEvent FAILED");
|
||||
notifyUploadError(notifyUploadEvent.getParentId(), notifyUploadEvent.getItemId(), notifyUploadEvent.getException());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the event bus.
|
||||
*
|
||||
* @return the event bus
|
||||
*/
|
||||
public static HandlerManager getEventBus(){
|
||||
return controllerEventBus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the workspace upload listener.
|
||||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
public void addWorkspaceUploadListener(WorskpaceUploadNotificationListener handler) {
|
||||
this.listenersUpload.add(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the workspace upload listener.
|
||||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
public void removeWorkspaceUploadListener(WorskpaceUploadNotificationListener handler) {
|
||||
try {
|
||||
this.listenersUpload.remove(handler);
|
||||
} catch (Exception e) {
|
||||
// SILENT
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset listeners.
|
||||
*/
|
||||
public void resetListeners(){
|
||||
this.listenersUpload.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify upload completed.
|
||||
*
|
||||
* @param parentId the parent id
|
||||
* @param itemId the item id
|
||||
*/
|
||||
private void notifyUploadCompleted(String parentId, String itemId){
|
||||
listnersSize();
|
||||
for (WorskpaceUploadNotificationListener listener : listenersUpload) {
|
||||
listener.onUploadCompleted(parentId, itemId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify upload aborted.
|
||||
*
|
||||
* @param parentId the parent id
|
||||
* @param itemId the item id
|
||||
*/
|
||||
private void notifyUploadAborted(String parentId, String itemId){
|
||||
for (WorskpaceUploadNotificationListener listener : listenersUpload) {
|
||||
listener.onUploadAborted(parentId, itemId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify upload error.
|
||||
*
|
||||
* @param parentId the parent id
|
||||
* @param itemId the item id
|
||||
* @param t the t
|
||||
*/
|
||||
private void notifyUploadError(String parentId, String itemId, Throwable t){
|
||||
for (WorskpaceUploadNotificationListener listener : listenersUpload) {
|
||||
listener.onError(parentId, itemId, t);
|
||||
}
|
||||
}
|
||||
|
||||
private int listnersSize(){
|
||||
GWT.log("listenersUpload.size() "+listenersUpload.size());
|
||||
return listenersUpload.size();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
package org.gcube.portlets.widgets.workspaceuploader.client.events;
|
||||
|
||||
import com.google.gwt.event.shared.GwtEvent;
|
||||
|
||||
|
||||
/**
|
||||
* The Class NotifyUploadEvent.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Oct 5, 2015
|
||||
*/
|
||||
public class NotifyUploadEvent extends GwtEvent<NotifyUploadEventHandler> {
|
||||
public static Type<NotifyUploadEventHandler> TYPE = new Type<NotifyUploadEventHandler>();
|
||||
|
||||
/**
|
||||
* The Enum UPLOAD_EVENT_TYPE.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Oct 5, 2015
|
||||
*/
|
||||
public static enum UPLOAD_EVENT_TYPE {
|
||||
COMPLETED, FAILED, ABORTED
|
||||
}
|
||||
|
||||
private UPLOAD_EVENT_TYPE event;
|
||||
private String parentId;
|
||||
private String itemId;
|
||||
private Throwable exception;
|
||||
|
||||
|
||||
/**
|
||||
* @return the exception
|
||||
*/
|
||||
public Throwable getException() {
|
||||
return exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param exception the exception to set
|
||||
*/
|
||||
public void setException(Throwable exception) {
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the event
|
||||
*/
|
||||
public UPLOAD_EVENT_TYPE getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param event the event to set
|
||||
*/
|
||||
public void setEvent(UPLOAD_EVENT_TYPE event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new notify upload event.
|
||||
*/
|
||||
public NotifyUploadEvent(UPLOAD_EVENT_TYPE event, String parentId, String itemId) {
|
||||
this.parentId = parentId;
|
||||
this.itemId = itemId;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new notify upload event.
|
||||
*/
|
||||
public NotifyUploadEvent(UPLOAD_EVENT_TYPE event, String parentId, String itemId, Throwable e) {
|
||||
this.parentId = parentId;
|
||||
this.itemId = itemId;
|
||||
this.event = event;
|
||||
this.exception = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the parentId
|
||||
*/
|
||||
public String getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the itemId
|
||||
*/
|
||||
public String getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parentId the parentId to set
|
||||
*/
|
||||
public void setParentId(String parentId) {
|
||||
this.parentId = parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemId the itemId to set
|
||||
*/
|
||||
public void setItemId(String itemId) {
|
||||
this.itemId = itemId;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
|
||||
*/
|
||||
@Override
|
||||
public Type<NotifyUploadEventHandler> getAssociatedType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared
|
||||
* .EventHandler)
|
||||
*/
|
||||
@Override
|
||||
protected void dispatch(NotifyUploadEventHandler handler) {
|
||||
handler.onNotifyUpload(this);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package org.gcube.portlets.widgets.workspaceuploader.client.events;
|
||||
|
||||
import com.google.gwt.event.shared.EventHandler;
|
||||
|
||||
|
||||
/**
|
||||
* The Interface NotifyUploadEventHandler.
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Oct 5, 2015
|
||||
*/
|
||||
public interface NotifyUploadEventHandler extends EventHandler {
|
||||
|
||||
|
||||
/**
|
||||
* On notify upload.
|
||||
*
|
||||
* @param notifyUploadEvent the notify upload event
|
||||
*/
|
||||
void onNotifyUpload(NotifyUploadEvent notifyUploadEvent);
|
||||
}
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||
import org.gcube.portlets.widgets.workspaceuploader.client.ClosableDialog;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.DialogResult;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceExplorerListenerController;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderServiceAsync;
|
||||
|
@ -43,18 +44,14 @@ import com.google.gwt.user.client.ui.VerticalPanel;
|
|||
*/
|
||||
public class DialogUploadStream extends ClosableDialog implements HasWorskpaceUploadNotificationListener{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private DialogUploadStream INSTANCE = this;
|
||||
// private boolean isStatusCompleted = false;
|
||||
protected Button btnUpload = new Button("Upload");
|
||||
// protected Button btnCancel = new Button("Cancel");
|
||||
private Hidden hiddenOverwrite = new Hidden(ConstantsWorkspaceUploader.IS_OVERWRITE,"false");
|
||||
protected final FormPanel formPanel = new FormPanel();
|
||||
protected FileUpload fileUpload;
|
||||
protected Hidden jsonClientKeys;
|
||||
protected List<WorkspaceUploaderItem> fakeUploaders = new ArrayList<WorkspaceUploaderItem>();
|
||||
protected WorkspaceExplorerListenerController controller = new WorkspaceExplorerListenerController();
|
||||
|
||||
/**
|
||||
* The Enum UPLOAD_TYPE.
|
||||
|
@ -363,7 +360,7 @@ public class DialogUploadStream extends ClosableDialog implements HasWorskpaceUp
|
|||
*/
|
||||
@Override
|
||||
public void addWorkspaceUploadNotificationListener(WorskpaceUploadNotificationListener handler) {
|
||||
UploaderMonitor.getInstance().addWorkspaceUploadListener(handler);
|
||||
controller.addWorkspaceUploadListener(handler);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -371,7 +368,7 @@ public class DialogUploadStream extends ClosableDialog implements HasWorskpaceUp
|
|||
*/
|
||||
@Override
|
||||
public void removeWorkspaceUploadNotificationListener(WorskpaceUploadNotificationListener handler) {
|
||||
UploaderMonitor.getInstance().removeWorkspaceUploadListener(handler);
|
||||
controller.removeWorkspaceUploadListener(handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,17 +3,17 @@
|
|||
*/
|
||||
package org.gcube.portlets.widgets.workspaceuploader.client.uploader;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.ClosableDialog;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.ConstantsWorkspaceUploader;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceExplorerListenerController;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploaderServiceAsync;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.events.CancelUploadEvent;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.events.CancelUploadEventHandler;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.events.NotifyUploadEvent;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.events.NotifyUploadEvent.UPLOAD_EVENT_TYPE;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.client.resource.WorkspaceUploaderResources;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.shared.HandlerResultMessage;
|
||||
import org.gcube.portlets.widgets.workspaceuploader.shared.WorkspaceUploaderItem;
|
||||
|
@ -41,11 +41,11 @@ import com.google.gwt.user.client.ui.HorizontalPanel;
|
|||
public class UploaderMonitor {
|
||||
|
||||
private static UploaderMonitor instance;
|
||||
private final static HandlerManager eventBus = new HandlerManager(null);
|
||||
private MonitorPanel monitorPanel = new MonitorPanel(eventBus);
|
||||
private final static HandlerManager monitorEventBus = new HandlerManager(null);
|
||||
private MonitorPanel monitorPanel = new MonitorPanel(monitorEventBus);
|
||||
private static Map<String, Timer> mapTimer = new HashMap<String, Timer>();
|
||||
private ClosableDialog dialogUploadMonitor = new ClosableDialog(monitorPanel, false, ConstantsWorkspaceUploader.MY_UPLOADS);
|
||||
private List<WorskpaceUploadNotificationListener> listenersUpload = new ArrayList<WorskpaceUploadNotificationListener>();
|
||||
|
||||
/**
|
||||
* Gets the single instance of UploaderMonitor.
|
||||
*
|
||||
|
@ -67,7 +67,7 @@ public class UploaderMonitor {
|
|||
*/
|
||||
private void bindEvents() {
|
||||
|
||||
eventBus.addHandler(CancelUploadEvent.TYPE, new CancelUploadEventHandler() {
|
||||
monitorEventBus.addHandler(CancelUploadEvent.TYPE, new CancelUploadEventHandler() {
|
||||
|
||||
@Override
|
||||
public void onCancelUpload(final CancelUploadEvent deleteTimerEvent) {
|
||||
|
@ -175,11 +175,13 @@ public class UploaderMonitor {
|
|||
Timer tmn = mapTimer.get(workspaceUploader.getClientUploadKey());
|
||||
if(tmn!=null && tmn.isRunning()){
|
||||
if(result.getUploadStatus().equals(UPLOAD_STATUS.COMPLETED)){
|
||||
GWT.log("Upload Completed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||
mapTimer.remove(tmn);
|
||||
notifyUploadCompleted(result.getFile().getParentId(), result.getFile().getItemId());
|
||||
// new DialogResult(null, "Upload Completed!!", result.getStatusDescription()).center();
|
||||
cancel();
|
||||
}else if(result.getUploadStatus().equals(UPLOAD_STATUS.FAILED)){
|
||||
GWT.log("Upload Failed "+result.getFile().getItemId() +" name: "+result.getFile().getFileName());
|
||||
mapTimer.remove(tmn);
|
||||
notifyUploadError(result.getFile().getParentId(), null, null);
|
||||
// new DialogResult(null, "Upload Failed!!", result.getStatusDescription()).center();
|
||||
|
@ -216,9 +218,11 @@ public class UploaderMonitor {
|
|||
* @param itemId the item id
|
||||
*/
|
||||
private void notifyUploadCompleted(String parentId, String itemId){
|
||||
for (WorskpaceUploadNotificationListener listener : listenersUpload) {
|
||||
listener.onUploadCompleted(parentId, itemId);
|
||||
}
|
||||
GWT.log("notifyUploadCompleted in monitor");
|
||||
WorkspaceExplorerListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.COMPLETED, parentId, itemId));
|
||||
// for (WorskpaceUploadNotificationListener listener : listenersUpload) {
|
||||
// listener.onUploadCompleted(parentId, itemId);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -228,9 +232,7 @@ public class UploaderMonitor {
|
|||
* @param itemId the item id
|
||||
*/
|
||||
private void notifyUploadAborted(String parentId, String itemId){
|
||||
for (WorskpaceUploadNotificationListener listener : listenersUpload) {
|
||||
listener.onUploadAborted(parentId, itemId);
|
||||
}
|
||||
WorkspaceExplorerListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.ABORTED, parentId, itemId));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -241,32 +243,6 @@ public class UploaderMonitor {
|
|||
* @param t the t
|
||||
*/
|
||||
private void notifyUploadError(String parentId, String itemId, Throwable t){
|
||||
for (WorskpaceUploadNotificationListener listener : listenersUpload) {
|
||||
listener.onError(parentId, itemId, t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the workspace upload listener.
|
||||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
public void addWorkspaceUploadListener(WorskpaceUploadNotificationListener handler) {
|
||||
this.listenersUpload.add(handler);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the workspace upload listener.
|
||||
*
|
||||
* @param handler the handler
|
||||
*/
|
||||
public void removeWorkspaceUploadListener(WorskpaceUploadNotificationListener handler) {
|
||||
try {
|
||||
this.listenersUpload.remove(handler);
|
||||
} catch (Exception e) {
|
||||
// SILENT
|
||||
}
|
||||
WorkspaceExplorerListenerController.getEventBus().fireEvent(new NotifyUploadEvent(UPLOAD_EVENT_TYPE.FAILED, parentId, itemId, t));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -405,7 +405,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
Long size = getContentLength(request);
|
||||
logger.debug("size: " + size + " bytes");
|
||||
|
||||
String contentType = null; //It's set into HL
|
||||
|
||||
|
||||
/*
|
||||
String contentType = uploadItem.getContentType();
|
||||
|
@ -435,9 +435,11 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
|
||||
saveWorkspaceUploaderInSession(workspaceUploader, request.getSession());
|
||||
|
||||
String contentType = null; //It's set into HL
|
||||
|
||||
if(uploadType.compareTo(FILE)==0) {//IS FILE UPLOAD
|
||||
|
||||
boolean isZipFile = MimeTypeUtil.isZipContentType(contentType);
|
||||
boolean isZipFile = MimeTypeUtil.isZipContentType(uploadItem.getContentType()); //UNZIP??
|
||||
|
||||
if(isZipFile && (extension.compareToIgnoreCase(D4ST)==0)){ //Create REPORT TEMPLATE
|
||||
|
||||
|
@ -463,7 +465,7 @@ public class WorkspaceUploadServletStream extends HttpServlet implements Servlet
|
|||
|
||||
}else {//IS ARCHIVE UPLOAD
|
||||
|
||||
if (MimeTypeUtil.isZipContentType(contentType)){
|
||||
if (MimeTypeUtil.isZipContentType(uploadItem.getContentType())){ //UNZIP??
|
||||
logger.debug("Unziping content");
|
||||
workspaceUploader = WorkspaceUploaderMng.uploadArchive(workspaceUploader, request.getSession(), itemName, inputStream, destinationFolder, size);
|
||||
|
||||
|
|
Loading…
Reference in New Issue