put in session groups of the user
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@134319 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
f4eea2427a
commit
99db1074b2
|
@ -22,6 +22,7 @@ import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCat
|
|||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgRole;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint;
|
||||
import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.GroupBean;
|
||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
|
||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||
|
@ -30,6 +31,7 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
|
||||
import eu.trentorise.opendata.jackan.model.CkanGroup;
|
||||
import eu.trentorise.opendata.jackan.model.CkanOrganization;
|
||||
/**
|
||||
* The server side implementation of the RPC service.
|
||||
|
@ -253,9 +255,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
|
||||
// check if session expired
|
||||
if(username.equals(TEST_USER)){
|
||||
|
||||
logger.warn("Session expired, returning " + toReturn);
|
||||
|
||||
}else{
|
||||
|
||||
// get the scope
|
||||
|
@ -264,6 +264,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
// get key per scope
|
||||
String keyPerScopeRole = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_HIGHEST_ROLE, scopePerCurrentUrl);
|
||||
String keyPerScopeOrganizations = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scopePerCurrentUrl);
|
||||
String keyPerScopeGroups = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scopePerCurrentUrl);
|
||||
|
||||
// check into session
|
||||
if(httpSession.getAttribute(keyPerScopeRole) != null){
|
||||
|
@ -287,9 +288,10 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
|
||||
// if he is an admin/editor preload:
|
||||
// 1) organizations in which he can publish (the widget will find these info in session)
|
||||
// 2) the list of groups
|
||||
if(toReturn.equals(CkanRole.ADMIN) || toReturn.equals(CkanRole.EDITOR)){
|
||||
httpSession.setAttribute(keyPerScopeOrganizations, orgsInWhichAtLeastEditorRole);
|
||||
logger.info("Set organizations in which he can publish to " + orgsInWhichAtLeastEditorRole + " into session for user " + username);
|
||||
httpSession.setAttribute(keyPerScopeGroups, fetchUserGroups(scopePerCurrentUrl, username));
|
||||
}
|
||||
}catch(Exception e){
|
||||
logger.error("Error while retreving roles... returning " + toReturn, e);
|
||||
|
@ -302,6 +304,40 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem
|
|||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the list of ckan groups for which the user is member
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
private List<GroupBean> fetchUserGroups(String context, String username) {
|
||||
|
||||
List<GroupBean> toReturn = null;
|
||||
logger.info("Preloading user's groups");
|
||||
|
||||
try{
|
||||
DataCatalogue catalogue = getCatalogue(context);
|
||||
List<CkanGroup> ckanGroups = catalogue.getGroups();
|
||||
String apiKey = catalogue.getApiKeyFromUsername(username);
|
||||
toReturn = new ArrayList<GroupBean>();
|
||||
|
||||
// Members/Admin of the group
|
||||
for (CkanGroup ckanGroup : ckanGroups) {
|
||||
String role = catalogue.getRoleOfUserInGroup(username, ckanGroup.getName(), apiKey);
|
||||
|
||||
if(role == null)
|
||||
continue;
|
||||
|
||||
toReturn.add(new GroupBean(ckanGroup.getTitle(), ckanGroup.getName()));
|
||||
}
|
||||
logger.debug("List of groups to return is " + toReturn);
|
||||
|
||||
}catch(Exception e){
|
||||
logger.error("Failed to preload user's groups");
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String logoutURIFromCkan() {
|
||||
HttpSession httpSession = this.getThreadLocalRequest().getSession();
|
||||
|
|
Loading…
Reference in New Issue