added fetch groups method for catalogue
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@134323 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
9cc90eaae1
commit
93c2db193b
|
@ -89,6 +89,7 @@ import org.gcube.portlets.user.workspace.shared.WorkspaceUserQuote;
|
||||||
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingEntryType;
|
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingEntryType;
|
||||||
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
|
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
|
||||||
import org.gcube.portlets.user.workspaceapplicationhandler.ApplicationReaderFromGenericResource;
|
import org.gcube.portlets.user.workspaceapplicationhandler.ApplicationReaderFromGenericResource;
|
||||||
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.GroupBean;
|
||||||
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
|
import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean;
|
||||||
import org.gcube.vomanagement.usermanagement.GroupManager;
|
import org.gcube.vomanagement.usermanagement.GroupManager;
|
||||||
import org.gcube.vomanagement.usermanagement.UserManager;
|
import org.gcube.vomanagement.usermanagement.UserManager;
|
||||||
|
@ -101,6 +102,8 @@ import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||||
import com.liferay.portal.service.UserLocalServiceUtil;
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
|
|
||||||
|
import eu.trentorise.opendata.jackan.model.CkanGroup;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Class GWTWorkspaceServiceImpl.
|
* The Class GWTWorkspaceServiceImpl.
|
||||||
|
@ -3504,6 +3507,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
||||||
// get key per scope
|
// get key per scope
|
||||||
String keyPerScopeRole = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_PUBLISH_WORKSPACE, scopePerCurrentUrl);
|
String keyPerScopeRole = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_PUBLISH_WORKSPACE, scopePerCurrentUrl);
|
||||||
String keyPerScopeOrganizations = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scopePerCurrentUrl);
|
String keyPerScopeOrganizations = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_ORGANIZATIONS_PUBLISH_KEY, scopePerCurrentUrl);
|
||||||
|
String keyPerScopeGroups = UtilMethods.concatenateSessionKeyScope(SessionCatalogueAttributes.CKAN_GROUPS_MEMBER, scopePerCurrentUrl);
|
||||||
|
|
||||||
// check if this information was already into the ASL Session (true means the user has at least in one org
|
// check if this information was already into the ASL Session (true means the user has at least in one org
|
||||||
// the role editor), false that he is just a member so he cannot publish
|
// the role editor), false that he is just a member so he cannot publish
|
||||||
|
@ -3528,7 +3532,7 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
||||||
// 1) organizations in which he can publish (the widget will find these info in session)
|
// 1) organizations in which he can publish (the widget will find these info in session)
|
||||||
if(role){
|
if(role){
|
||||||
httpSession.setAttribute(keyPerScopeOrganizations, orgsInWhichAtLeastEditorRole);
|
httpSession.setAttribute(keyPerScopeOrganizations, orgsInWhichAtLeastEditorRole);
|
||||||
workspaceLogger.info("Set organizations in which he can publish to " + orgsInWhichAtLeastEditorRole + " into session for user " + username);
|
httpSession.setAttribute(keyPerScopeGroups, fetchUserGroups(scopePerCurrentUrl, username));
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
workspaceLogger.error("Unable to retrieve the role information for this user. Returning FALSE", e);
|
workspaceLogger.error("Unable to retrieve the role information for this user. Returning FALSE", e);
|
||||||
|
@ -3544,6 +3548,40 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
||||||
// return false
|
// return false
|
||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
workspaceLogger.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()));
|
||||||
|
}
|
||||||
|
workspaceLogger.debug("List of groups to return is " + toReturn);
|
||||||
|
|
||||||
|
}catch(Exception e){
|
||||||
|
workspaceLogger.error("Failed to preload user's groups");
|
||||||
|
}
|
||||||
|
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#markFolderAsPublicForFolderItemId(java.lang.String, boolean)
|
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#markFolderAsPublicForFolderItemId(java.lang.String, boolean)
|
||||||
|
|
Loading…
Reference in New Issue