From 74d32b1bd455b67de4e12a17bc13b0e3abdb5198 Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Wed, 30 Nov 2016 13:44:00 +0000 Subject: [PATCH] Fixed Image Preview git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@135112 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../client/AppControllerExplorer.java | 2 +- .../workspace/client/ConstantsExplorer.java | 1 + .../view/windows/WindowImagePreview.java | 74 ++++++++++++++++--- .../workspace/server/GWTWorkspaceBuilder.java | 63 ++++++++-------- .../server/GWTWorkspaceServiceImpl.java | 3 +- .../user/workspace/server/ImageServlet.java | 11 ++- 6 files changed, 104 insertions(+), 50 deletions(-) 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 de68eea..6277025 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 @@ -1493,7 +1493,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt @Override public void onSuccess(GWTWorkspaceItem item) { - + GWT.log("Image loaded: "+item.toString()); if(fileModel.getGXTFolderItemType().equals(GXTFolderItemTypeEnum.IMAGE_DOCUMENT)) new WindowImagePreview(fileModel.getName(), (GWTImageDocument) item, positionX, positionY); else diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java index 04a522d..ec36035 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java @@ -21,6 +21,7 @@ public class ConstantsExplorer { public static final String UPLOAD_WORKSPACE_SERVICE = GWT.getModuleBaseURL() + "UploadService"; public static final String LOCAL_UPLOAD_WORKSPACE_SERVICE = GWT.getModuleBaseURL() + "LocalUploadService"; public static final String DOWNLOAD_WORKSPACE_SERVICE = GWT.getModuleBaseURL() + "DownloadService"; + public static final String IMAGE_SERVLET = GWT.getModuleBaseURL() + "ImageService"; public static final String DOWNLOAD_WORKSPACE_FOLDER_SERVLET = GWT.getModuleBaseURL() + "DownloadFolderServlet"; public static final String DOWNLOAD_WORKSPACE_FOLDER_SERVICE = "downloadfolder"; public static final String DOWNLOAD_WORKSPACE_FOLDER_PROTOCOL_DO_ZIP = "ZIP"; diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/WindowImagePreview.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/WindowImagePreview.java index 24c69d1..46d915e 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/WindowImagePreview.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/WindowImagePreview.java @@ -1,30 +1,68 @@ package org.gcube.portlets.user.workspace.client.view.windows; import org.gcube.portlets.user.workspace.client.ConstantsExplorer; +import org.gcube.portlets.user.workspace.client.resources.Resources; import org.gcube.portlets.user.workspace.client.workspace.folder.item.GWTExternalImage; import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTImageDocument; import com.extjs.gxt.ui.client.widget.Window; +import com.google.gwt.core.shared.GWT; +import com.google.gwt.event.dom.client.LoadEvent; +import com.google.gwt.event.dom.client.LoadHandler; import com.google.gwt.user.client.ui.Image; + +/** + * The Class WindowImagePreview. + * + * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Nov 30, 2016 + */ public class WindowImagePreview { - + Window window = new Window(); - - + + Image loader = Resources.getIconLoading().createImage(); + + /** + * Instantiates a new window image preview. + * + * @param name the name + * @param image the image + * @param positionX the position x + * @param positionY the position y + */ public WindowImagePreview(String name, GWTImageDocument image, int positionX, int positionY) { initWindow(name, positionX, positionY); - + window.add(loader); Image img = new Image(image.getThumbnailUrl()); img.setWidth(String.valueOf(image.getThumbnailWidth())); img.setHeight(String.valueOf(image.getThumbnailHeight())); log("Thumbnail URL: "+image.getThumbnailUrl()); - window.add(new Image(image.getThumbnailUrl())); + Image loadImg = new Image(image.getThumbnailUrl()); + + loadImg.addLoadHandler(new LoadHandler() { + + @Override + public void onLoad(LoadEvent event) { + GWT.log("Image Load event fired"); + window.remove(loader); + } + }); + window.add(loadImg); window.show(); } - + + /** + * Instantiates a new window image preview. + * + * @param name the name + * @param image the image + * @param positionX the position x + * @param positionY the position y + */ public WindowImagePreview(String name, GWTExternalImage image, int positionX, int positionY){ - + initWindow(name, positionX, positionY); // System.out.println("URL.................." + image.getThumbnailUrl()); @@ -38,20 +76,32 @@ public class WindowImagePreview { img.setHeight(String.valueOf(image.getThumbnailHeight())); window.add(new Image(image.getThumbnailUrl())); window.show(); - + } + /** + * Inits the window. + * + * @param name the name + * @param positionX the position x + * @param positionY the position y + */ private void initWindow(String name, int positionX, int positionY) { window.setHeaderVisible(true); - window.setHeading(ConstantsExplorer.PREVIEWOF + " " + name); - window.setMaximizable(false); - window.setResizable(false); + window.setHeading(ConstantsExplorer.PREVIEWOF + " " + name); + window.setMaximizable(false); + window.setResizable(false); window.setAutoWidth(true); window.setAutoHeight(true); window.setPosition(positionX, positionY); } - + + /** + * Log. + * + * @param msg the msg + */ public static native void log(String msg) /*-{ console.log(msg); }-*/; diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java index 4afddbc..d7d17e6 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java @@ -91,24 +91,18 @@ import com.thoughtworks.xstream.XStream; * The Class GWTWorkspaceBuilder. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it + * Nov 30, 2016 */ public class GWTWorkspaceBuilder { - /** - * - */ protected static final String IMAGE_SERVICE_URL = "ImageService"; protected static Logger logger = Logger.getLogger(GWTWorkspaceBuilder.class); private InfoContactModel userLogged; protected static HashMap hashTestUser = null; -// private final String UNKNOWN = "unknown"; -// private final String FOLDER = "Folder"; - - /** - * Instantiates a new GWT workspace builder. - */ + * Instantiates a new GWT workspace builder. + */ public GWTWorkspaceBuilder() { } @@ -163,34 +157,29 @@ public class GWTWorkspaceBuilder { protected String toDateFormatToString(Calendar calendar){ SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM, yyyy HH:mm:ss z"); - Date resultdate = getDate(calendar); - return dateFormat.format(resultdate); } - /** * To date format. * - * @param calendar the calendar + * @param calendar + * the calendar * @return the date */ - protected Date toDateFormat(Calendar calendar){ - - SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM, yyyy HH:mm:ss z"); + protected Date toDateFormat(Calendar calendar) { + SimpleDateFormat dateFormat = + new SimpleDateFormat("dd-MM, yyyy HH:mm:ss z"); Date resultdate = getDate(calendar); - try { - resultdate = dateFormat.parse(dateFormat.format(resultdate)); - - } catch (ParseException e) { + } + catch (ParseException e) { e.printStackTrace(); resultdate = new Date(0); } - return resultdate; } @@ -233,38 +222,45 @@ public class GWTWorkspaceBuilder { * Builds the image url. * * @param id the id + * @param scope the scope * @return the string */ - protected String buildImageUrl(String id) + protected String buildImageUrl(String id, String scope) { - return buildImageServiceUrl(id, ImageRequestType.IMAGE); + return buildImageServiceUrl(id, ImageRequestType.IMAGE, scope); } + /** * Builds the thumbnail url. * * @param id the id + * @param currentGroupId the current group id read from PortalContext * @return the string */ - protected String buildThumbnailUrl(String id) + protected String buildThumbnailUrl(String id, String currentGroupId) { - return buildImageServiceUrl(id, ImageRequestType.THUMBNAIL); + return buildImageServiceUrl(id, ImageRequestType.THUMBNAIL, currentGroupId); } + /** * Builds the image service url. * * @param id the id * @param requestType the request type + * @param currentGroupId the current group id read from PortalContext * @return the string */ - protected String buildImageServiceUrl(String id, ImageRequestType requestType){ + protected String buildImageServiceUrl(String id, ImageRequestType requestType, String currentGroupId){ StringBuilder sb = new StringBuilder(); sb.append(IMAGE_SERVICE_URL); sb.append("?id="); sb.append(id); sb.append("&type="); sb.append(requestType.toString()); + sb.append("&"+ConstantsExplorer.CONTEXT_ID+"="); + sb.append(currentGroupId); sb.append("&random="); sb.append(UUID.randomUUID().toString()); return sb.toString(); @@ -276,11 +272,12 @@ public class GWTWorkspaceBuilder { * @param item the item * @param isInteralImage the is interal image * @param fullDetails the full details + * @param currentGroupId the current group id * @return the GWT workspace item * @throws InternalErrorException the internal error exception */ @SuppressWarnings("unchecked") - protected GWTWorkspaceItem buildGWTWorkspaceImage(WorkspaceItem item, boolean isInteralImage, boolean fullDetails) throws InternalErrorException + protected GWTWorkspaceItem buildGWTWorkspaceImage(WorkspaceItem item, boolean isInteralImage, boolean fullDetails, String currentGroupId) throws InternalErrorException { GWTWorkspaceItem gwtImage; @@ -306,8 +303,8 @@ public class GWTWorkspaceBuilder { toDate(image.getLastModificationTime()), GWTWorkspaceItemAction.valueOf(image.getLastAction().toString()), null, - buildImageUrl(image.getId()), - buildThumbnailUrl(image.getId()), + buildImageUrl(image.getId(), currentGroupId), + buildThumbnailUrl(image.getId(), currentGroupId), Integer.parseInt(image.getProperties().getPropertyValue(NodeProperty.IMAGE_WIDTH.toString())), Integer.parseInt(image.getProperties().getPropertyValue(NodeProperty.IMAGE_HEIGHT.toString())), Integer.parseInt(image.getProperties().getPropertyValue(NodeProperty.THUMBNAIL_WIDTH.toString())), @@ -339,8 +336,8 @@ public class GWTWorkspaceBuilder { toDate(image.getLastModificationTime()), GWTWorkspaceItemAction.valueOf(image.getLastAction().toString()), null, //parent - buildImageUrl(image.getId()), - buildThumbnailUrl(image.getId()), + buildImageUrl(image.getId(), currentGroupId), + buildThumbnailUrl(image.getId(), currentGroupId), image.getWidth(), image.getHeight(), image.getLength(), @@ -351,8 +348,8 @@ public class GWTWorkspaceBuilder { }else{ gwtImage = new GWTExternalImage( - buildImageUrl(image.getId()), - buildThumbnailUrl(image.getId()), + buildImageUrl(image.getId(), currentGroupId), + buildThumbnailUrl(image.getId(), currentGroupId), image.getWidth(), image.getHeight(), image.getLength(), 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 3d540de..c4ad1bc 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 @@ -1286,7 +1286,8 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT WorkspaceItem item = workspace.getItem(identifier); //get item from workspace workspaceLogger.trace("item name " + item.getName()); GWTWorkspaceBuilder builder = getGWTWorkspaceBuilder(); - return builder.buildGWTWorkspaceImage(item, isInteralImage, fullDetails); + PortalContextInfo context = WsUtil.getPortalContext(this.getThreadLocalRequest()); + return builder.buildGWTWorkspaceImage(item, isInteralImage, fullDetails, context.getCurrGroupId()+""); } catch (Exception e) { workspaceLogger.error("Error in server get image by id", e); diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/ImageServlet.java b/src/main/java/org/gcube/portlets/user/workspace/server/ImageServlet.java index a0408f0..15e57aa 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/ImageServlet.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/ImageServlet.java @@ -22,6 +22,8 @@ import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException; import org.gcube.common.homelibrary.home.workspace.folder.FolderItem; import org.gcube.common.homelibrary.home.workspace.folder.items.Image; +import org.gcube.common.portal.PortalContext; +import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.client.util.ImageRequestType; import org.gcube.portlets.user.workspace.server.util.WsUtil; @@ -30,7 +32,7 @@ import org.gcube.portlets.user.workspace.server.util.WsUtil; * The Class ImageServlet. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Nov 25, 2016 + * Nov 30, 2016 */ public class ImageServlet extends HttpServlet{ @@ -57,8 +59,9 @@ public class ImageServlet extends HttpServlet{ String imageId = req.getParameter("id"); String imageType = req.getParameter("type"); + String contextID = req.getParameter(ConstantsExplorer.CONTEXT_ID); - logger.trace("request image id: "+imageId+" type: "+imageType); + logger.info("request image id: "+imageId+", type: "+imageType +", "+ConstantsExplorer.CONTEXT_ID+ ": "+contextID); ImageRequestType requestType = null; @@ -70,7 +73,9 @@ public class ImageServlet extends HttpServlet{ Workspace wa = null; try { - wa = WsUtil.getWorkspace(req); + String currentScope= PortalContext.getConfiguration().getCurrentScope(contextID); + logger.info("For ContextID: "+contextID +", read scope from Portal Context: "+currentScope); + wa = WsUtil.getWorkspace(req, currentScope); } catch (Exception e) { logger.error("Error during workspace retrieving", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"Error during workspace retrieving");