diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java index f68f832..cea2f47 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java @@ -102,6 +102,8 @@ import org.gcube.portlets.user.workspace.client.model.SmartFolderModel; import org.gcube.portlets.user.workspace.client.model.SubTree; import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService; import org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceServiceAsync; +import org.gcube.portlets.user.workspace.client.uploader.FileUploader; +import org.gcube.portlets.user.workspace.client.uploader.UpdateServiceUploader; import org.gcube.portlets.user.workspace.client.util.RequestBuilderWorkspaceValidateItem; import org.gcube.portlets.user.workspace.client.util.WindowOpenParameter; import org.gcube.portlets.user.workspace.client.view.BasicDNDExample; @@ -117,12 +119,10 @@ import org.gcube.portlets.user.workspace.client.view.windows.DialogPublicLink; import org.gcube.portlets.user.workspace.client.view.windows.DialogShareLink; import org.gcube.portlets.user.workspace.client.view.windows.DialogText; import org.gcube.portlets.user.workspace.client.view.windows.DialogWebDavUrl; -import org.gcube.portlets.user.workspace.client.view.windows.FileUploader; import org.gcube.portlets.user.workspace.client.view.windows.InfoDisplay; import org.gcube.portlets.user.workspace.client.view.windows.InfoDisplayMessage; import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxAlert; import org.gcube.portlets.user.workspace.client.view.windows.MessageBoxConfirm; -import org.gcube.portlets.user.workspace.client.view.windows.UpdateServiceUploader; import org.gcube.portlets.user.workspace.client.view.windows.WindowImagePreview; import org.gcube.portlets.user.workspace.client.view.windows.WindowOpenUrl; import org.gcube.portlets.user.workspace.client.view.windows.accounting.WindowAccountingInfo; @@ -583,45 +583,96 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt eventBus.addHandler(PasteItemEvent.TYPE, new PasteItemEventHandler() { @Override - public void onCopyAndPaste(PasteItemEvent pasteItemEvent) { + public void onCutCopyAndPaste(PasteItemEvent pasteItemEvent) { GWT.log("PasteItemEvent is fired on : "+pasteItemEvent.getIds().size()+ "items, DestinationId: "+pasteItemEvent.getFolderDestinationId()); - doCopyAndPaste(pasteItemEvent); + doCutCopyAndPaste(pasteItemEvent); } - private void doCopyAndPaste(final PasteItemEvent pasteItemEvent) { + private void doCutCopyAndPaste(final PasteItemEvent pasteItemEvent) { - Info.display("Info", "Paste working..."); + if(pasteItemEvent.getIds()==null) + return; - rpcWorkspaceService.copyItems(pasteItemEvent.getIds(), pasteItemEvent.getFolderDestinationId(), new AsyncCallback() { + Info.display("Info", "Paste working..."); - @Override - public void onFailure(Throwable caught) { + switch(pasteItemEvent.getOperationType()){ + + case CUT: + + //TODO remove this comments +// if(pasteItemEvent.getFolderSourceId()==null || pasteItemEvent.getFolderSourceId().isEmpty()) +// return; + + rpcWorkspaceService.moveItems(pasteItemEvent.getIds(), pasteItemEvent.getFolderDestinationId(), new AsyncCallback() { - if(caught instanceof SessionExpiredException){ - GWT.log("Session expired"); - eventBus.fireEvent(new SessionExpiredEvent()); - return; + public void onFailure(Throwable caught) { + + if(caught instanceof SessionExpiredException){ + GWT.log("Session expired"); + eventBus.fireEvent(new SessionExpiredEvent()); + return; + } + + new MessageBoxAlert("Error", caught.getMessage()+"." , null); + System.out.println(caught.getMessage()); + explorerPanel.getAsycTreePanel().reloadTreeLevelAndExpandFolder(pasteItemEvent.getFolderDestinationId(), false); + explorerPanel.getAsycTreePanel().reloadTreeLevelAndExpandFolder(pasteItemEvent.getFolderSourceId(), true); } - new MessageBoxAlert("Error", caught.getMessage(), null); - - eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, true, false)); - - notifySubscriber(pasteItemEvent); - } + @Override + public void onSuccess(Boolean result) { + + if(result){ - @Override - public void onSuccess(Boolean result) { + eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, false, false)); + // explorerPanel.getAsycTreePanel().setExpandTreeLevel(event.getTargetParentFileModel(), true); //Expand level drop + } + notifySubscriber(pasteItemEvent); + } + }); + + break; + + case COPY: + + rpcWorkspaceService.copyItems(pasteItemEvent.getIds(), pasteItemEvent.getFolderDestinationId(), new AsyncCallback() { - if(result) - eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, false, false)); + @Override + public void onFailure(Throwable caught) { - notifySubscriber(pasteItemEvent); - } + if(caught instanceof SessionExpiredException){ + GWT.log("Session expired"); + eventBus.fireEvent(new SessionExpiredEvent()); + return; + } + + new MessageBoxAlert("Error", caught.getMessage(), null); + + eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, true, false)); + + notifySubscriber(pasteItemEvent); + } + + @Override + public void onSuccess(Boolean result) { + + if(result) + eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, false, false)); + + notifySubscriber(pasteItemEvent); + } + + }); + + break; + + default: + + } + - }); } }); diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/event/PasteItemEvent.java b/src/main/java/org/gcube/portlets/user/workspace/client/event/PasteItemEvent.java index de0fb5d..29947a3 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/event/PasteItemEvent.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/event/PasteItemEvent.java @@ -4,6 +4,7 @@ import java.util.List; import org.gcube.portlets.user.workspace.client.interfaces.EventsTypeEnum; import org.gcube.portlets.user.workspace.client.interfaces.GuiEventInterface; +import org.gcube.portlets.user.workspace.client.view.tree.CutCopyAndPaste.OperationType; import com.google.gwt.event.shared.GwtEvent; @@ -14,15 +15,21 @@ public class PasteItemEvent extends GwtEvent implements G private String folderDestinationId; private List ids; + + private OperationType operationType; + private String folderSourceId; //Used to move + + // public PasteItemEvent(String itemId, String folderDestinationId) { // this.itemId = itemId; // this.folderDestinationId = folderDestinationId; // } - public PasteItemEvent(List ids, String folderDestinationId) { + public PasteItemEvent(List ids, String folderDestinationId, OperationType operation) { this.ids = ids; this.folderDestinationId = folderDestinationId; + this.operationType = operation; } @Override @@ -32,7 +39,7 @@ public class PasteItemEvent extends GwtEvent implements G @Override protected void dispatch(PasteItemEventHandler handler) { - handler.onCopyAndPaste(this); + handler.onCutCopyAndPaste(this); } @@ -60,4 +67,16 @@ public class PasteItemEvent extends GwtEvent implements G this.ids = ids; } + public OperationType getOperationType() { + return operationType; + } + + public String getFolderSourceId() { + return folderSourceId; + } + + public void setFolderSourceId(String folderSourceId) { + this.folderSourceId = folderSourceId; + } + } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/event/PasteItemEventHandler.java b/src/main/java/org/gcube/portlets/user/workspace/client/event/PasteItemEventHandler.java index 950584f..a727604 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/event/PasteItemEventHandler.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/event/PasteItemEventHandler.java @@ -3,5 +3,5 @@ package org.gcube.portlets.user.workspace.client.event; import com.google.gwt.event.shared.EventHandler; public interface PasteItemEventHandler extends EventHandler { - void onCopyAndPaste(PasteItemEvent pasteItemEvent); + void onCutCopyAndPaste(PasteItemEvent pasteItemEvent); } \ No newline at end of file diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/resources/icons/cut-icon.png b/src/main/java/org/gcube/portlets/user/workspace/client/resources/icons/cut-icon.png new file mode 100644 index 0000000..8dda4d5 Binary files /dev/null and b/src/main/java/org/gcube/portlets/user/workspace/client/resources/icons/cut-icon.png differ diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java index 72f65f9..5f5ee40 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceService.java @@ -184,4 +184,12 @@ public interface GWTWorkspaceService extends RemoteService{ boolean copyItems(List idsItem, String destinationFolderId) throws Exception; + /** + * @param ids + * @param destinationId + * @return + * @throws Exception + */ + Boolean moveItems(List ids, String destinationId) throws Exception; + } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java index e6d0b33..c841f57 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/rpc/GWTWorkspaceServiceAsync.java @@ -167,4 +167,7 @@ public interface GWTWorkspaceServiceAsync { void copyItems(List idsItem, String destinationFolderId, AsyncCallback callback); + void moveItems(List ids, String destinationId, + AsyncCallback callback); + } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/FileUploader.java b/src/main/java/org/gcube/portlets/user/workspace/client/uploader/FileUploader.java similarity index 96% rename from src/main/java/org/gcube/portlets/user/workspace/client/view/windows/FileUploader.java rename to src/main/java/org/gcube/portlets/user/workspace/client/uploader/FileUploader.java index 5e1b181..3d24155 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/FileUploader.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/uploader/FileUploader.java @@ -1,7 +1,7 @@ /** * */ -package org.gcube.portlets.user.workspace.client.view.windows; +package org.gcube.portlets.user.workspace.client.uploader; import org.gcube.portlets.user.workspace.client.model.FileModel; import org.gcube.portlets.widgets.fileupload.client.view.UploadProgressDialog; diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/UpdateServiceUploader.java b/src/main/java/org/gcube/portlets/user/workspace/client/uploader/UpdateServiceUploader.java similarity index 73% rename from src/main/java/org/gcube/portlets/user/workspace/client/view/windows/UpdateServiceUploader.java rename to src/main/java/org/gcube/portlets/user/workspace/client/uploader/UpdateServiceUploader.java index 21805b0..67a89ff 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/UpdateServiceUploader.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/uploader/UpdateServiceUploader.java @@ -1,4 +1,4 @@ -package org.gcube.portlets.user.workspace.client.view.windows; +package org.gcube.portlets.user.workspace.client.uploader; import org.gcube.portlets.user.workspace.client.AppControllerExplorer; @@ -14,6 +14,7 @@ import com.google.gwt.http.client.RequestBuilder; import com.google.gwt.http.client.RequestCallback; import com.google.gwt.http.client.RequestException; import com.google.gwt.http.client.Response; +import com.google.gwt.http.client.URL; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.HTML; @@ -49,6 +50,25 @@ public class UpdateServiceUploader extends Window{ } + public static String encodeUrlDelimiters(String s) { + if (s == null) { + return null; + } + + s = s.replaceAll(";", "%2F"); + s = s.replaceAll("/", "%2F"); + s = s.replaceAll(":", "%3A"); + s = s.replaceAll("\\?", "%3F"); + s = s.replaceAll("&", "%26"); + s = s.replaceAll("\\=", "%3D"); + s = s.replaceAll("\\+", "%2B"); + s = s.replaceAll("\\$", "%24"); + s = s.replaceAll(",", "%2C"); + s = s.replaceAll("#", "%23"); + + return s; + } + public void submitForm() throws Exception{ @@ -57,7 +77,7 @@ public class UpdateServiceUploader extends Window{ String parameters = ""; - parameters+=ConstantsExplorer.UPLOAD_FORM_ELEMENT+"="+fileName+"&"; + /* parameters+=ConstantsExplorer.UPLOAD_FORM_ELEMENT+"="+fileName+"&"; if(parent.getIdentifier()!=null && !parent.getIdentifier().isEmpty()) @@ -72,18 +92,47 @@ public class UpdateServiceUploader extends Window{ parameters+=ConstantsExplorer.IS_OVERWRITE+"="+overwrite; -// String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+URL.encodeQueryString(parameters); + String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+URL.encodeQueryString(parameters); String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+parameters; + + */ - GWT.log("Encoded url request is: "+urlRequest); + String fileNameEscaped = URL.encodeQueryString(fileName); +// fileNameEscaped = encodeUrlDelimiters(fileNameEscaped); + + parameters+=ConstantsExplorer.UPLOAD_FORM_ELEMENT+"="+fileNameEscaped+"&"; - RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, urlRequest); -// requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded"); + if(parent.getIdentifier()!=null && !parent.getIdentifier().isEmpty()) + parameters+=ConstantsExplorer.ID_FOLDER+"="+parent.getIdentifier()+"&"; + else + throw new Exception("Parent Folder ID parameter is null or empty"); + + if(uploadType!=null && !uploadType.isEmpty()) + parameters+=ConstantsExplorer.UPLOAD_TYPE+"="+uploadType+"&"; + else + throw new Exception("UploadType parameter is null or empty"); + + parameters+=ConstantsExplorer.IS_OVERWRITE+"="+overwrite; + +// String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+parameters; + +// StringBuilder sb = new StringBuilder(); +// sb.append(parameters); + + + + GWT.log("Encoded parameters are: "+parameters); + + String urlRequest = ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE+"?"+parameters; + RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, ConstantsExplorer.LOCAL_UPLOAD_WORKSPACE_SERVICE); + requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded"); +// requestBuilder.setRequestData(parameters); + try { - requestBuilder.sendRequest("", new RequestCallback() { + requestBuilder.sendRequest(parameters, new RequestCallback() { @Override public void onResponseReceived(Request request, Response response) { @@ -147,7 +196,7 @@ public class UpdateServiceUploader extends Window{ }); } catch (RequestException e) { - + e.printStackTrace(); } } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/ContextMenuTree.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/ContextMenuTree.java index 889a326..80e975e 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/ContextMenuTree.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/ContextMenuTree.java @@ -32,6 +32,7 @@ import org.gcube.portlets.user.workspace.client.event.WebDavUrlEvent; import org.gcube.portlets.user.workspace.client.model.FileModel; import org.gcube.portlets.user.workspace.client.resources.Resources; import org.gcube.portlets.user.workspace.client.util.FileModelUtils; +import org.gcube.portlets.user.workspace.client.view.tree.CutCopyAndPaste.OperationType; import com.extjs.gxt.ui.client.event.MenuEvent; import com.extjs.gxt.ui.client.event.SelectionListener; @@ -332,7 +333,7 @@ public class ContextMenuTree { List ids = FileModelUtils.convertFileModelsToIds(listSelectedItems); if(ids.size()>0){ - CopyAndPaste.copy(ids); + CutCopyAndPaste.copy(ids, OperationType.COPY); eventBus.fireEvent(new CopytemEvent(ids)); } @@ -353,9 +354,9 @@ public class ContextMenuTree { FileModel parentTarget = getDirectoryOrParent(target); if(parentTarget!=null){ - eventBus.fireEvent(new PasteItemEvent(CopyAndPaste.getCopiedIdsFilesModel(), parentTarget.getIdentifier())); - CopyAndPaste.setCopiedIdsFileModels(null); - + eventBus.fireEvent(new PasteItemEvent(CutCopyAndPaste.getCopiedIdsFilesModel(), parentTarget.getIdentifier(), CutCopyAndPaste.getOperationType())); + CutCopyAndPaste.setCopiedIdsFileModels(null); + CutCopyAndPaste.setOperationType(null); } } @@ -792,7 +793,7 @@ public class ContextMenuTree { } - if(CopyAndPaste.getCopiedIdsFilesModel()!=null) + if(CutCopyAndPaste.getCopiedIdsFilesModel()!=null) contextMenu.getItemByItemId(WorkspaceOperation.PASTE.getId()).setEnabled(true); //enable paste button } diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/CopyAndPaste.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/CopyAndPaste.java deleted file mode 100644 index cec4426..0000000 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/CopyAndPaste.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.gcube.portlets.user.workspace.client.view.tree; - -import java.util.List; - - -public class CopyAndPaste { - -// private static String copiedfileModelId = null; - - private static List idsFilesModel = null; - -// public static void copy(String fileModelId){ -// copiedfileModelId = fileModelId; -// } - - public static void copy(List idsFileModel){ - idsFilesModel = idsFileModel; - } - - - public static List getCopiedIdsFilesModel() { - return idsFilesModel; - } - -// public static void setCopiedfileModelId(String copiedfileModelId) { -// CopyAndPaste.copiedfileModelId = copiedfileModelId; -// } - - -// public static String getCopiedfileModelId() { -// return copiedfileModelId; -// } - - public static void setCopiedIdsFileModels(List idsFileModel) { - CopyAndPaste.idsFilesModel = idsFileModel; - } - -} diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/CutCopyAndPaste.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/CutCopyAndPaste.java new file mode 100644 index 0000000..0ac620a --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/tree/CutCopyAndPaste.java @@ -0,0 +1,35 @@ +package org.gcube.portlets.user.workspace.client.view.tree; + +import java.util.List; + + +public class CutCopyAndPaste { + + private static List idsFilesModel = null; + + public enum OperationType {CUT, COPY}; + + private static OperationType operationType; + + public static void copy(List idsFileModel, OperationType operationType){ + CutCopyAndPaste.idsFilesModel = idsFileModel; + CutCopyAndPaste.operationType = operationType; + } + + public static List getCopiedIdsFilesModel() { + return idsFilesModel; + } + + public static void setCopiedIdsFileModels(List idsFileModel) { + CutCopyAndPaste.idsFilesModel = idsFileModel; + } + + public static OperationType getOperationType() { + return operationType; + } + + public static void setOperationType(OperationType operationType) { + CutCopyAndPaste.operationType = operationType; + } + +} diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java index fd63137..59b7022 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceServiceImpl.java @@ -484,6 +484,81 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT } + + + @Override + public Boolean moveItems(List ids, String destinationId) throws Exception { + workspaceLogger.trace("moveItems "+ids.size()+ ", destination: "+destinationId); + + if(isSessionExpired()) + throw new SessionExpiredException(); + + boolean error = false; + + try { + Workspace workspace = getWorkspace(); + + for (String itemId : ids) { + + if(itemId == null) + throw new Exception(IDENTIFIER_IS_NULL); + + workspaceLogger.trace("moveItem item: "+itemId+" destination: "+destinationId); + + WorkspaceItem sourceItem = workspace.getItem(itemId); //GET SOURCE ITEM BEFORE OF MOVE + + if(sourceItem==null){ + error = true; + break; + } + + String sourceSharedId = null; + boolean sourceItemIsShared = sourceItem.isShared(); + + if(sourceItemIsShared) + sourceSharedId = sourceItem.getIdSharedFolder(); //GET SHARED ID BEFORE OF MOVE + + + //System.out.println("moveItem item: "+itemId+" sourceItem name "+sourceItem.getName() + " shared: "+sourceItemIsShared+ " destination: "+destinationId); + + workspace.moveItem(itemId, destinationId); //move item + + WorkspaceItem folderDestinationItem = workspace.getItem(destinationId); //retrieve folder destination + + //System.out.println("sourceItem.isShared() "+sourceItemIsShared ); + //System.out.println("folderDestinationItem item: "+destinationId+" folderDestinationItem name "+folderDestinationItem.getName() + " folderDestinationItem shared: "+folderDestinationItem.isShared()); + + if(folderDestinationItem!=null){ + + try{ + checkNotifyAddItemToShare(sourceItem, sourceSharedId, folderDestinationItem); + + checkNotifyMoveItemFromShare(sourceItemIsShared, sourceItem, sourceSharedId, folderDestinationItem); + + }catch (Exception e) { + workspaceLogger.error("An error occurred in checkNotify ", e); + } + } + } + + if(error) + return Boolean.FALSE; + + return Boolean.TRUE; + + }catch (InsufficientPrivilegesException e) { + workspaceLogger.error("Error in server Item move", e); + String error1 = "An error occurred on moving item. "+e.getMessage(); + throw new Exception(error1); + + } catch (Exception e) { + workspaceLogger.error("Error in server Item move", e); + String error2 = ConstantsExplorer.SERVER_ERROR + " moving item. "+e.getMessage(); + throw new Exception(error2); + } + + } + private void checkNotifyAddItemToShare(final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem) { workspaceLogger.trace("checkNotifyAddItemToShare"); diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/LocalUploadServlet.java b/src/main/java/org/gcube/portlets/user/workspace/server/LocalUploadServlet.java index 0a24cc9..e5200ad 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/LocalUploadServlet.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/LocalUploadServlet.java @@ -44,6 +44,8 @@ import org.gcube.portlets.user.workspace.server.notifications.NotificationsUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.shared.HandlerResultMessage; +import com.google.gwt.http.client.URL; + /** * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it @@ -93,11 +95,23 @@ public class LocalUploadServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // System.out.println("GET on LocalUploadServlet"); - logger.trace("GET on LocalUploadServlet"); - String absolutePathFile = URLDecoder.decode(request.getParameter(UPLOAD_FORM_ELEMENT), UTF_8); - String destinationId = URLDecoder.decode(request.getParameter(ID_FOLDER), UTF_8); - String uploadType = URLDecoder.decode(request.getParameter(UPLOAD_TYPE), UTF_8); - boolean isOverwrite = Boolean.parseBoolean(URLDecoder.decode(request.getParameter(IS_OVERWRITE), UTF_8)); + logger.trace("GET method in LocalUploadServlet is running"); + String absolutePathFile = ""; + String destinationId = ""; + String uploadType = ""; + boolean isOverwrite = false; + try{ + absolutePathFile = request.getParameter(UPLOAD_FORM_ELEMENT); + destinationId = request.getParameter(ID_FOLDER); + uploadType = request.getParameter(UPLOAD_TYPE); + isOverwrite = Boolean.parseBoolean(request.getParameter(IS_OVERWRITE)); + + }catch (Exception e) { + logger.error("Error processing GET parameters", e); + sendError(response, "Internal error: Error during request processing"); + return; + } + uploadData(request, response, absolutePathFile, destinationId, uploadType, isOverwrite); } @@ -106,23 +120,35 @@ public class LocalUploadServlet extends HttpServlet { */ @SuppressWarnings("rawtypes") protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { -// System.out.println("POST on LocalUploadServlet"); - logger.trace("POST on LocalUploadServlet"); - String absolutePathFile = request.getParameter(UPLOAD_FORM_ELEMENT); - String destinationId = request.getParameter(ID_FOLDER); - String uploadType = request.getParameter(UPLOAD_TYPE); - boolean isOverwrite = Boolean.parseBoolean(request.getParameter(IS_OVERWRITE)); + logger.trace("POST method in LocalUploadServlet is running"); + String absolutePathFile = ""; + String destinationId = ""; + String uploadType = ""; + boolean isOverwrite = false; + try{ + + absolutePathFile = request.getParameter(UPLOAD_FORM_ELEMENT); + destinationId = request.getParameter(ID_FOLDER); + uploadType = request.getParameter(UPLOAD_TYPE); + isOverwrite = Boolean.parseBoolean(request.getParameter(IS_OVERWRITE)); + + }catch (Exception e) { + logger.error("Error processing POST parameters", e); + sendError(response, "Internal error: Error during request processing"); + return; + } uploadData(request, response, absolutePathFile, destinationId, uploadType, isOverwrite); } - private void uploadData(HttpServletRequest request, HttpServletResponse response, String absolutePathFile,String destinationId,String uploadType,boolean isOverwrite) throws ServletException, IOException{ + private void uploadData(HttpServletRequest request, HttpServletResponse response, String absolutePathFile, String destinationId,String uploadType,boolean isOverwrite) throws ServletException, IOException{ File file = null; InputStream fileUploadIS = null; try { + logger.trace("Upload servlet parameters: [uploadItem: "+absolutePathFile +", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+"]"); if(absolutePathFile==null || absolutePathFile.isEmpty()) throw new FileUploadException("Absolute path is null or empty"); @@ -133,9 +159,9 @@ public class LocalUploadServlet extends HttpServlet { if(!file.exists()) throw new FileUploadException("File dosn't exists"); - fileUploadIS = FileUtils.openInputStream(file); + fileUploadIS = FileUtils.openInputStream(file); + - logger.trace("Upload servlet parameters: [uploadItem: "+file.getAbsolutePath() +", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+"]"); } catch (Exception e) { logger.error("Error processing request in upload servlet", e); sendError(response, "Internal error: Error during request processing"); diff --git a/src/main/java/org/gcube/portlets/user/workspace/shared/FieldVerifier.java b/src/main/java/org/gcube/portlets/user/workspace/shared/FieldVerifier.java index d9cdb72..60fdb08 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/shared/FieldVerifier.java +++ b/src/main/java/org/gcube/portlets/user/workspace/shared/FieldVerifier.java @@ -1,5 +1,7 @@ package org.gcube.portlets.user.workspace.shared; +import com.google.gwt.safehtml.shared.UriUtils; + /** *

* FieldVerifier validates that the name the user enters is valid. @@ -47,4 +49,12 @@ public class FieldVerifier { } return true; } + + public static String uriUtilsEncode(String uri, boolean allowEscape){ + + if(!allowEscape) + return UriUtils.encodeAllowEscapes(uri); + + return UriUtils.encode(uri); + } }