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
This commit is contained in:
Francesco Mangiacrapa 2016-09-13 13:25:23 +00:00
parent 7619df4ca8
commit 8337e7b912
6 changed files with 78 additions and 111 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/workspace-explorer-app-0.0.1-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/workspace-explorer-app-0.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/workspace-explorer-app-0.0.1-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/workspace-explorer-app-0.1.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -33,5 +33,5 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/workspace-explorer-app-0.0.1-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/workspace-explorer-app-0.1.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

37
pom.xml
View File

@ -9,7 +9,7 @@
</parent>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>workspace-explorer-app</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<description>
@ -70,17 +70,16 @@
<scope>compile</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>com.google.gwt</groupId> -->
<!-- <artifactId>gwt-servlet</artifactId> -->
<!-- <version>${gwtVersion}</version> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>com.google.gwt</groupId> -->
<!-- <artifactId>gwt-servlet</artifactId> -->
<!-- <version>${gwtVersion}</version> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<dependency>
<groupId>com.github.gwtbootstrap</groupId>
<artifactId>gwt-bootstrap</artifactId>
<version>2.3.2.0</version>
<scope>compile</scope>
</dependency>
@ -113,36 +112,33 @@
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>compile</scope>
</dependency>
<!-- END FWS -->
<dependency>
<groupId>org.gcube.applicationsupportlayer</groupId>
<artifactId>aslcore</artifactId>
<version>[4.0.0-SNAPSHOT, 5.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.gcube.applicationsupportlayer</groupId> -->
<!-- <artifactId>aslcore</artifactId> -->
<!-- <scope>provided</scope> -->
<!-- </dependency> -->
<!-- HOME LIBRARY -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-model</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-jcr</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<version>[2.5.0-SNAPSHOT,3.5.0-SNAPSHOT)</version>
<scope>provided</scope>
<exclusions>
<exclusion>
@ -154,8 +150,7 @@
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
<!-- <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> -->
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<version>[2.5.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
<exclusions>
<exclusion>
@ -198,7 +193,7 @@
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>

View File

@ -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);

View File

@ -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();
}
}

View File

@ -6,6 +6,11 @@
<welcome-file-list>
<welcome-file>WorkspaceExplorerApp.html</welcome-file>
</welcome-file-list>
<context-param>
<description>scope for using HL</description>
<param-name>scope</param-name>
<param-value>/d4science.research-infrastructures.eu</param-value>
</context-param>
<servlet>
<servlet-name>workspaceExplorerAppServlet</servlet-name>
<servlet-class>org.gcube.portlets.user.workspaceexplorerapp.server.WorkspaceExplorerAppServiceImpl</servlet-class>
@ -22,9 +27,9 @@
<servlet-name>DownloadServlet</servlet-name>
<url-pattern>/workspaceexplorerapp/DownloadServlet</url-pattern>
</servlet-mapping>
<display-name>workspace-explorer-app</display-name>
<welcome-file-list>
<welcome-file>WorkspaceExplorerApp.html</welcome-file>
</welcome-file-list>