added code to put list of VREs to ckan-connector

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129210 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2016-06-21 14:12:27 +00:00
parent ad19179018
commit 7107ac4892
5 changed files with 86 additions and 29 deletions

View File

@ -33,22 +33,5 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/costantino/Downloads/gwt-2.7.0/gwt-user.jar">
<attributes>
<attribute name="javadoc_location" value="file:/home/costantino/Downloads/gwt-2.7.0/doc/javadoc/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/costantino/Downloads/gwt-2.7.0/gwt-codeserver.jar">
<attributes>
<attribute name="javadoc_location" value="file:/home/costantino/Downloads/gwt-2.7.0/doc/javadoc/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/costantino/Downloads/gwt-2.7.0/gwt-dev.jar">
<attributes>
<attribute name="javadoc_location" value="file:/home/costantino/Downloads/gwt-2.7.0/doc/javadoc/"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/home/costantino/Downloads/gwt-2.7.0/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="lib" path="/home/costantino/Downloads/gwt-2.7.0/validation-api-1.0.0.GA.jar" sourcepath="/home/costantino/Downloads/gwt-2.7.0/validation-api-1.0.0.GA-sources.jar"/>
<classpathentry kind="output" path="target/gcube-ckan-datacatalog-1.0.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -4,10 +4,7 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="ckan-metadata-publisher-widget-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ckan-metadata-publisher-widget/ckan-metadata-publisher-widget">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="ckan-util-library-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ckan-util-library/ckan-util-library">
<dependent-module archiveName="workspace-sharing-widget-1.7.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/workspace-sharing-widget-TRUNK/workspace-sharing-widget-TRUNK">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="context-root" value="gcube-ckan-datacatalog"/>

View File

@ -128,7 +128,6 @@
<dependency>
<groupId>org.gcube.dvos</groupId>
<artifactId>usermanagement-core</artifactId>
<!-- <version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version> -->
<scope>provided</scope>
</dependency>

View File

@ -28,7 +28,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.liferay.portal.model.RoleModel;
/**
* The server side implementation of the RPC service.
*
@ -38,10 +37,10 @@ import com.liferay.portal.model.RoleModel;
@SuppressWarnings("serial")
public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implements GcubeCkanDataCatalogService {
private static final String LIST_OF_VRES_PARAMETER = "listOfVres";
private static final String PORT_HTTP = ":80";
private static final String PORT_HTTPS = ":443";
private static final String GCUBE_TOKEN = "gcube-token";
private static final String GCUBE_TOKEN_PARAMETER = "gcube-token";
private static final String HTTPS = "https";
private static final String HTTP = "http";
public static String CKANCONNECTORCONTEXT = "CkanConnectorContext";
@ -52,6 +51,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
private final static String TEST_USER = "francesco.mangiacrapa";
private final static String TEST_SCOPE = "/gcube/devsec/devVRE";
private final static String TEST_MAIL = "francesco.mangiacrapa@isti.cnr.it";
private final static String TEST_SEC_TOKEN = "4620e6d0-2313-4f48-9d54-eb3efd01a810";
// private final static String TEST_SEC_TOKEN = "f539884c-8697-4ac0-9bbf-2f4d595281f5";
@ -115,8 +115,6 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
}
/**
* Gets the ckan connector parameters.
*
@ -141,14 +139,33 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
String gcubeTokenParameter = null;
if(SessionUtil.isIntoPortal()){
gcubeTokenParameter = GCUBE_TOKEN+"="+getGcubeSecurityToken();
gcubeTokenParameter = GCUBE_TOKEN_PARAMETER+"="+getGcubeSecurityToken();
}else{
logger.warn("******** Using TEST_USER security token!!!");
gcubeTokenParameter = GCUBE_TOKEN+"="+TEST_SEC_TOKEN;
gcubeTokenParameter = GCUBE_TOKEN_PARAMETER+"="+TEST_SEC_TOKEN;
}
//ADDING CKAN HH (HIDE HEADER PARAMETER)
queryString = queryString.isEmpty()?"?"+ckanHideHeader:"&"+ckanHideHeader;
//ADDING GCUBE TOKEN PARAMETER
queryString+="&"+gcubeTokenParameter;
//ADDING LIST OF VRE TO WHICH USER BELONGS
ASLSession session = getASLSession(this.getThreadLocalRequest().getSession());
List<String> listVres = UserUtil.getListVreForUser(session.getUserEmailAddress());
String vres = "";
if(listVres!=null && listVres.size()>0){
for (String vre : listVres) {
vres+=vre+",";
}
vres = vres.substring(0, vres.length()-1); //remove last ","
}
logger.debug("List of VREs contains: " +vres);
if(vres.length()>0){
queryString+="&"+LIST_OF_VRES_PARAMETER+"="+vres;
}
return pathInfo+queryString;
}
@ -209,6 +226,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
httpSession.setAttribute(USERNAME_ATTRIBUTE, user);
ASLSession session = SessionManager.getInstance().getASLSession(sessionID, user);
session.setScope(TEST_SCOPE);
session.setUserEmailAddress(TEST_MAIL);
//session.setScope("/gcube/devsec/devVRE");
return session;

View File

@ -0,0 +1,60 @@
/**
*
*/
package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server;
import java.util.ArrayList;
import java.util.List;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class UserUtil.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jun 21, 2016
*/
public class UserUtil {
private static Logger logger = LoggerFactory.getLogger(UserUtil.class);
/**
* Gets the list vre for user.
* retrieve the groups to whom a given user belongs (given the user EMail)
*
* @param userEMail the user e mail
* @return the list vre for user
*/
public static List<String> getListVreForUser(String userEMail){
// Instanciate the manager
GroupManager groupManager = new LiferayGroupManager();
// Instanciate the manager
UserManager userManager = new LiferayUserManager();
GCubeUser user;
try {
user = userManager.getUserByEmail(userEMail);
// retrieve the groups to whom a given user belongs (given the user identifier)
List<GCubeGroup> listOfGroups = groupManager.listGroupsByUser(user.getUserId());
List<String> vreNames = new ArrayList<String>(listOfGroups.size());
for (GCubeGroup gCubeGroup : listOfGroups) {
vreNames.add(gCubeGroup.getGroupName());
}
return vreNames;
}catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) {
logger.error("An error occurred during get list of VREs for user: "+userEMail, e);
return null;
}
}
}