From 8337e7b912cf0bc090e8c94998dee485ea2f1b6a Mon Sep 17 00:00:00 2001 From: Francesco Mangiacrapa Date: Tue, 13 Sep 2016 13:25:23 +0000 Subject: [PATCH] Updated in order to use the method: Workspace ws = HomeLibrary.getHomeManagerFactory().getHomeManager().getGuestLogin().getWorkspace(); see: #3782 git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/workspace-explorer-app@131325 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 6 +- .settings/org.eclipse.m2e.core.prefs | 4 ++ pom.xml | 37 +++++----- .../WorkspaceExplorerAppServiceImpl.java | 67 +++++++++---------- .../workspaceexplorerapp/server/WsUtil.java | 66 +++++------------- src/main/webapp/WEB-INF/web.xml | 9 ++- 6 files changed, 78 insertions(+), 111 deletions(-) create mode 100644 .settings/org.eclipse.m2e.core.prefs diff --git a/.classpath b/.classpath index 3f26f3c..ee0fbef 100644 --- a/.classpath +++ b/.classpath @@ -1,12 +1,12 @@ - + - + @@ -33,5 +33,5 @@ - + diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/pom.xml b/pom.xml index 6ab2b7a..b2beea7 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ org.gcube.portlets.user workspace-explorer-app - 0.1.0-SNAPSHOT + 1.0.0-SNAPSHOT war @@ -70,17 +70,16 @@ compile - - - - - - + + + + + + com.github.gwtbootstrap gwt-bootstrap - 2.3.2.0 compile @@ -113,36 +112,33 @@ org.gcube.resources.discovery ic-client - [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) provided org.gcube.core common-scope-maps - [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) compile - - org.gcube.applicationsupportlayer - aslcore - [4.0.0-SNAPSHOT, 5.0.0-SNAPSHOT) - provided - + + + + + org.gcube.common home-library-model - [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) provided org.gcube.common home-library-jcr - [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) + [2.5.0-SNAPSHOT,3.5.0-SNAPSHOT) provided @@ -154,8 +150,7 @@ org.gcube.common home-library - - [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) + [2.5.0-SNAPSHOT,3.0.0-SNAPSHOT) provided @@ -198,7 +193,7 @@ 4.7 test - + javax.validation validation-api diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WorkspaceExplorerAppServiceImpl.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WorkspaceExplorerAppServiceImpl.java index cd52bd5..3a82f2c 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WorkspaceExplorerAppServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WorkspaceExplorerAppServiceImpl.java @@ -6,9 +6,7 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; -import org.gcube.application.framework.core.session.ASLSession; import org.gcube.common.homelibary.model.items.type.WorkspaceItemType; -import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.workspace.Workspace; import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder; import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; @@ -140,37 +138,37 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem @Override public Item getItemByCategory(ItemCategory category) throws WorkspaceNavigatorServiceException{ logger.trace("GetItemByCategory category: "+category); - try { - Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); - Item item = null; - - switch(category){ - case HOME:{ - WorkspaceItem root = workspace.getRoot(); - ASLSession session = WsUtil.getASLSession(this.getThreadLocalRequest().getSession()); -// String fullName = UserUtil.getUserFullName(session.getUsername()); - String fullName = session.getUsername(); - if(fullName.indexOf(" ")>0){ - fullName = fullName.substring(0, fullName.indexOf(" ")); - }else if(fullName.indexOf(".")>0){ - fullName = fullName.substring(0, fullName.indexOf(".")); - } - item = new Item(null, root.getId(), fullName+"'s", ItemType.FOLDER, root.getPath(), root.getOwner().getPortalLogin(), null, true, true); - break; - } - case VRE_FOLDER:{ - WorkspaceItem folder = workspace.getMySpecialFolders(); - item = new Item(null, folder.getId(), WorkspaceExplorerAppConstants.VRE_FOLDERS_LABEL, ItemType.FOLDER, folder.getPath(), folder.getOwner().getPortalLogin(), null, true, false); - //SET SPECIAL FOLDER /Workspace/MySpecialFolders - item.setSpecialFolder(true); - break; - } - } - return item; - } catch (Exception e) { - logger.error("Error during get item by category", e); - throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get item by category"); - } + return null; //TODO +// try { +// Workspace workspace = WsUtil.getWorkspace(); +// Item item = null; +// +// switch(category){ +// case HOME:{ +// WorkspaceItem root = workspace.getRoot(); +//// String fullName = UserUtil.getUserFullName(session.getUsername()); +// String fullName = session.getUsername(); +// if(fullName.indexOf(" ")>0){ +// fullName = fullName.substring(0, fullName.indexOf(" ")); +// }else if(fullName.indexOf(".")>0){ +// fullName = fullName.substring(0, fullName.indexOf(".")); +// } +// item = new Item(null, root.getId(), fullName+"'s", ItemType.FOLDER, root.getPath(), root.getOwner().getPortalLogin(), null, true, true); +// break; +// } +// case VRE_FOLDER:{ +// WorkspaceItem folder = workspace.getMySpecialFolders(); +// item = new Item(null, folder.getId(), WorkspaceExplorerAppConstants.VRE_FOLDERS_LABEL, ItemType.FOLDER, folder.getPath(), folder.getOwner().getPortalLogin(), null, true, false); +// //SET SPECIAL FOLDER /Workspace/MySpecialFolders +// item.setSpecialFolder(true); +// break; +// } +// } +// return item; +// } catch (Exception e) { +// logger.error("Error during get item by category", e); +// throw new WorkspaceNavigatorServiceException("Sorry, an error occurred when performing get item by category"); +// } } /** @@ -228,8 +226,7 @@ public class WorkspaceExplorerAppServiceImpl extends RemoteServiceServlet implem public boolean checkName(String name) throws WorkspaceNavigatorServiceException { logger.trace("checkName name: "+name); try { - ASLSession session = WsUtil.getASLSession(this.getThreadLocalRequest().getSession()); - Workspace workspace = HomeLibrary.getUserWorkspace(session.getUsername()); + Workspace workspace = WsUtil.getWorkspace(this.getThreadLocalRequest().getSession()); return workspace.isValidName(name); } catch (Exception e) { logger.error("Error during folder retrieving", e); diff --git a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WsUtil.java b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WsUtil.java index b154e9a..da43746 100644 --- a/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WsUtil.java +++ b/src/main/java/org/gcube/portlets/user/workspaceexplorerapp/server/WsUtil.java @@ -5,11 +5,10 @@ package org.gcube.portlets.user.workspaceexplorerapp.server; import javax.servlet.http.HttpSession; -import org.gcube.application.framework.core.session.ASLSession; -import org.gcube.application.framework.core.session.SessionManager; import org.gcube.common.homelibrary.home.HomeLibrary; import org.gcube.common.homelibrary.home.exceptions.HomeNotFoundException; import org.gcube.common.homelibrary.home.exceptions.InternalErrorException; +import org.gcube.common.homelibrary.home.exceptions.UserNotFoundException; import org.gcube.common.homelibrary.home.workspace.Workspace; import org.gcube.common.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException; import org.gcube.common.scope.api.ScopeProvider; @@ -21,49 +20,12 @@ import org.slf4j.LoggerFactory; * The Class WsUtil. * * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * Mar 7, 2016 + * Sep 13, 2016 */ public class WsUtil { - public static final String USERNAME_ATTRIBUTE = "username"; - public static final String TEST_USER = "francesco.mangiacrapa"; - public static final String TEST_SCOPE = "/gcube/devsec/devVRE"; - public static final Logger logger = LoggerFactory.getLogger(WsUtil.class); - - /** - * Gets the ASL session. - * - * @param httpSession the http session - * @return the ASL session - */ - public static ASLSession getASLSession(HttpSession httpSession) { - String sessionID = httpSession.getId(); - String user = (String) httpSession.getAttribute(USERNAME_ATTRIBUTE); - - //TODO we check for the older attribute name - if (user == null) { - user = (String) httpSession.getAttribute("user"); - } - - if (user == null) { - - logger.error("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND"); - - //for test only -// user = "test.user"; - user = TEST_USER; - httpSession.setAttribute(USERNAME_ATTRIBUTE, user); - ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user); - session.setScope(TEST_SCOPE); - - return session; - } - else { - logger.trace("user found in session "+user); - } - return SessionManager.getInstance().getASLSession(sessionID, user); - } + private static final String SCOPE = "scope"; /** * Gets the workspace. @@ -73,17 +35,21 @@ public class WsUtil { * @throws InternalErrorException the internal error exception * @throws HomeNotFoundException the home not found exception * @throws WorkspaceFolderNotFoundException the workspace folder not found exception + * @throws UserNotFoundException */ - public static Workspace getWorkspace(HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException { - ASLSession session = getASLSession(httpSession); - logger.trace("Scope : "+session.getScope() + " username: "+session.getUsername()); - String scope = session.getScope(); - if(scope==null) - scope= WsUtil.TEST_SCOPE; - System.out.println("Scope : "+scope + " username: "+session.getUsername()); + public static Workspace getWorkspace(HttpSession httpSession) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException, UserNotFoundException { +// ASLSession session = getASLSession(httpSession); + + String scope = (String) httpSession.getAttribute(SCOPE); + + if(scope==null){ + logger.info(SCOPE + "read from context is: "+scope); + scope = httpSession.getServletContext().getInitParameter(SCOPE); + } + //GET CONTEXT + logger.info("Setting scope: "+scope); ScopeProvider.instance.set(scope); - Workspace workspace = HomeLibrary.getUserWorkspace(session.getUsername()); - return workspace; + return HomeLibrary.getHomeManagerFactory().getHomeManager().getGuestLogin().getWorkspace(); } } diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 74c8c9c..49d721e 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -6,6 +6,11 @@ WorkspaceExplorerApp.html + + scope for using HL + scope + /d4science.research-infrastructures.eu + workspaceExplorerAppServlet org.gcube.portlets.user.workspaceexplorerapp.server.WorkspaceExplorerAppServiceImpl @@ -22,9 +27,9 @@ DownloadServlet /workspaceexplorerapp/DownloadServlet - + workspace-explorer-app - + WorkspaceExplorerApp.html