diff --git a/.classpath b/.classpath index e123609..fd5f814 100644 --- a/.classpath +++ b/.classpath @@ -22,16 +22,16 @@ - - - - - + + + + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 443e085..b257af7 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,6 +1,6 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 5fe3680..21deca5 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,6 +4,9 @@ + + uses + diff --git a/pom.xml b/pom.xml index 1a34862..bf4c068 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ distro 1.7 - 1.7 + 1.8 ${project.build.directory}/${project.build.finalName} UTF-8 UTF-8 @@ -215,7 +215,7 @@ 2.3.2 1.7 - 1.7 + 1.8 diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/GCubeCkanDataCatalog.gwt.xml b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/GCubeCkanDataCatalog.gwt.xml index dc53d94..51fcee3 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/GCubeCkanDataCatalog.gwt.xml +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/GCubeCkanDataCatalog.gwt.xml @@ -21,7 +21,8 @@ - + diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/GcubeCkanDataCatalogService.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/GcubeCkanDataCatalogService.java index 2d366fd..6f86b5a 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/GcubeCkanDataCatalogService.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/GcubeCkanDataCatalogService.java @@ -2,9 +2,9 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client; import java.util.List; +import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint; -import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.ManageProductBean; import com.google.gwt.user.client.rpc.RemoteService; @@ -26,12 +26,11 @@ public interface GcubeCkanDataCatalogService extends RemoteService { * * @param pathInfoParameters the path info parameters * @param queryStringParameters the query string parameters - * @param currentUrl the current url * @return the c kan connector * @throws Exception the exception */ CkanConnectorAccessPoint getCKanConnector( - String pathInfoParameters, String queryStringParameters, String currentUrl) throws Exception; + String pathInfoParameters, String queryStringParameters) throws Exception; /** * Get the current role in CKAN for this user. @@ -39,7 +38,7 @@ public interface GcubeCkanDataCatalogService extends RemoteService { * @return the my role * @throws Exception the exception */ - CkanRole getMyRole() throws Exception; + RolesCkanGroupOrOrg getMyRole() throws Exception; /** * Retrieve the list of organizations to whom the user belongs and their urls. diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/GcubeCkanDataCatalogServiceAsync.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/GcubeCkanDataCatalogServiceAsync.java index 2b62b4c..14e61bd 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/GcubeCkanDataCatalogServiceAsync.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/GcubeCkanDataCatalogServiceAsync.java @@ -5,9 +5,9 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client; import java.util.List; +import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint; -import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.ManageProductBean; import com.google.gwt.user.client.rpc.AsyncCallback; @@ -28,19 +28,18 @@ public interface GcubeCkanDataCatalogServiceAsync { * @param callback the callback * @return the my role */ - void getMyRole(AsyncCallback callback); + void getMyRole(AsyncCallback callback); /** * Gets the c kan connector. * * @param pathInfoParameters the path info parameters * @param queryStringParameters the query string parameters - * @param currentUrl the current url * @param callback the callback * @return the c kan connector */ void getCKanConnector( - String pathInfoParameters, String queryStringParameters, String currentUrl, + String pathInfoParameters, String queryStringParameters, AsyncCallback callback); /** diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java index d92c20d..668a6c7 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/client/view/GCubeCkanDataCatalogPanel.java @@ -8,11 +8,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GCubeCkanDataCatalog; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.resource.CkanPortletResources; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint; -import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole; import com.google.gwt.core.client.GWT; import com.google.gwt.event.logical.shared.ResizeEvent; @@ -85,10 +85,9 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate { String pathParameter = paramsMap.get(GCubeCkanDataCatalog.GET_PATH_PARAMETER); //Window.Location.getParameter(GCubeCkanDataCatalog.GET_PATH_PARAMETER); String queryParameter = paramsMap.get(GCubeCkanDataCatalog.GET_QUERY_PARAMETER);// Window.Location.getParameter(GCubeCkanDataCatalog.GET_QUERY_PARAMETER); - String currentPortletUrl = Window.Location.getHref().split("\\?")[0];// ignore get parameters GCubeCkanDataCatalog.service.getCKanConnector( - pathParameter, queryParameter, currentPortletUrl, + pathParameter, queryParameter, new AsyncCallback() { @Override @@ -131,7 +130,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate { }); // MANAGE CKAN MANAGEMENT PANEL ACCORDING TO MY ROLE - GCubeCkanDataCatalog.service.getMyRole(new AsyncCallback() { + GCubeCkanDataCatalog.service.getMyRole(new AsyncCallback() { @Override public void onFailure(Throwable caught) { @@ -139,7 +138,7 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate { } @Override - public void onSuccess(CkanRole result) { + public void onSuccess(RolesCkanGroupOrOrg result) { switch (result) { case ADMIN: showEditInsertButtons(true); @@ -155,44 +154,38 @@ public class GCubeCkanDataCatalogPanel extends BaseViewTemplate { break; } - // retrieve organizations - GCubeCkanDataCatalog.service.getCkanOrganizationsNamesAndUrlsForUser(new AsyncCallback>() { - - @Override - public void onSuccess(List result) { - - ckanOrganizationsPanel.setOrganizations(result); - } - - @Override - public void onFailure(Throwable caught) { - - // an error message will be displayed - ckanOrganizationsPanel.setOrganizations(null); - - } - }); - - // retrieve groups - GCubeCkanDataCatalog.service.getCkanGroupsNamesAndUrlsForUser(new AsyncCallback>() { - - @Override - public void onSuccess(List result) { - - ckanGroupsPanel.setGroups(result); - - } - - @Override - public void onFailure(Throwable caught) { - - ckanGroupsPanel.setGroups(null); - - } - }); - } }); + + // retrieve organizations + GCubeCkanDataCatalog.service.getCkanOrganizationsNamesAndUrlsForUser(new AsyncCallback>() { + + @Override + public void onSuccess(List result) { + ckanOrganizationsPanel.setOrganizations(result); + } + + @Override + public void onFailure(Throwable caught) { + // an error message will be displayed + ckanOrganizationsPanel.setOrganizations(null); + } + }); + + // retrieve groups + GCubeCkanDataCatalog.service.getCkanGroupsNamesAndUrlsForUser(new AsyncCallback>() { + + @Override + public void onSuccess(List result) { + ckanGroupsPanel.setGroups(result); + } + + @Override + public void onFailure(Throwable caught) { + ckanGroupsPanel.setGroups(null); + } + }); + } } diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java index 9d6aa28..b322798 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java @@ -12,20 +12,20 @@ import org.apache.commons.codec.binary.Base64; import org.gcube.common.authorization.client.exceptions.ObjectNotFound; import org.gcube.common.authorization.library.provider.UserInfo; import org.gcube.common.portal.PortalContext; -import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue; -import org.gcube.datacatalogue.ckanutillibrary.DataCatalogueFactory; -import org.gcube.datacatalogue.ckanutillibrary.utils.SessionCatalogueAttributes; -import org.gcube.datacatalogue.ckanutillibrary.utils.UtilMethods; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.GroupBean; -import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; +import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue; +import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogueFactory; +import org.gcube.datacatalogue.ckanutillibrary.server.utils.SessionCatalogueAttributes; +import org.gcube.datacatalogue.ckanutillibrary.server.utils.UtilMethods; +import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server.manage.GRSFNotificationService; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.BeanUserInOrgGroupRole; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint; -import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.GRSFStatus; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.ManageProductBean; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.ex.NoGRSFRecordException; +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; import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; @@ -67,7 +67,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem * @return */ public DataCatalogue getCatalogue(String discoverScope){ - String currentScope = SessionUtil.getCurrentContext(getThreadLocalRequest(), false); + String currentScope = SessionUtil.getCurrentContext(getThreadLocalRequest(), false); DataCatalogue instance = null; try{ String scopeInWhichDiscover = discoverScope != null && !discoverScope.isEmpty() ? discoverScope : currentScope; @@ -83,8 +83,8 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem * @see org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService#getCKanConnector(java.lang.String, java.lang.String) */ @Override - public CkanConnectorAccessPoint getCKanConnector(String pathInfoParameter, String queryStringParameters, String currentPortletUrl) throws Exception { - logger.info("getCKanConnector [pathInfo: "+pathInfoParameter + ", query: "+queryStringParameters+"], current url is " + currentPortletUrl); + public CkanConnectorAccessPoint getCKanConnector(String pathInfoParameter, String queryStringParameters) throws Exception { + logger.info("getCKanConnector [pathInfo: "+pathInfoParameter + ", query: "+queryStringParameters+"]"); try{ // just get the current scope and set it into ScopeProvider... @@ -167,8 +167,8 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem } // retrieve the list of VREs to whom the user belongs - List listVres = UserUtil.getListVreForUser(SessionUtil.getCurrentUser(getThreadLocalRequest()).getEmail()); - ckan.addListOfVREs(listVres); + Map roleForVre = UserUtil.getVreRoleForUser(SessionUtil.getCurrentUser(getThreadLocalRequest()).getEmail(), scopePerCurrentUrl); + ckan.addListOfVREs(roleForVre); return ckan; } @@ -201,14 +201,14 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem * @see org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService#getMyRole() */ @Override - public CkanRole getMyRole(){ + public RolesCkanGroupOrOrg getMyRole(){ // base role as default value - CkanRole toReturn = CkanRole.MEMBER; + RolesCkanGroupOrOrg toReturn = RolesCkanGroupOrOrg.MEMBER; if(!SessionUtil.isIntoPortal()){ - logger.warn("OUT FROM PORTAL DETECTED RETURNING ROLE: "+CkanRole.ADMIN); - toReturn = CkanRole.ADMIN; + logger.warn("OUT FROM PORTAL DETECTED RETURNING ROLE: "+RolesCkanGroupOrOrg.ADMIN); + toReturn = RolesCkanGroupOrOrg.ADMIN; }else{ HttpSession httpSession = this.getThreadLocalRequest().getSession(); @@ -225,7 +225,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem // check into session if(httpSession.getAttribute(keyPerScopeRole) != null){ - toReturn = (CkanRole)httpSession.getAttribute(keyPerScopeRole); + toReturn = (RolesCkanGroupOrOrg)httpSession.getAttribute(keyPerScopeRole); logger.info("Found user role into session " + toReturn + " and it is going to be returned for user " + username); }else{ @@ -245,7 +245,7 @@ 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)){ + if(!toReturn.equals(RolesCkanGroupOrOrg.MEMBER)){ httpSession.setAttribute(keyPerScopeOrganizations, orgsInWhichAtLeastEditorRole); httpSession.setAttribute(keyPerScopeGroups, fetchUserGroups(scopePerCurrentUrl, username)); } @@ -414,7 +414,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem if(!SessionUtil.isIntoPortal()){ logger.warn("You are not into the portal"); - BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole("testVRE", "/organization/devvre", CkanRole.ADMIN); + BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole("testVRE", "/organization/devvre", RolesCkanGroupOrOrg.ADMIN); toReturn.add(org); }else{ @@ -437,7 +437,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem String apiKey = catalogue.getApiKeyFromUsername(username); for (CkanOrganization ckanOrganization : organizations) { String role = catalogue.getRoleOfUserInOrganization(username, ckanOrganization.getName(), apiKey); - BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName(), CkanRole.valueOf(role.toUpperCase())); + BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanOrganization.getTitle(), "/organization/" + ckanOrganization.getName(), RolesCkanGroupOrOrg.valueOf(role.toUpperCase())); toReturn.add(org); } logger.debug("List of organizations to return for user " + username + " is " + toReturn); @@ -457,7 +457,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem if(!SessionUtil.isIntoPortal()){ logger.warn("You are not into the portal"); - BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole("testGroup", "/group/testgroup", CkanRole.MEMBER); + BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole("testGroup", "/group/testgroup", RolesCkanGroupOrOrg.MEMBER); toReturn.add(org); }else{ @@ -480,7 +480,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem String apiKey = catalogue.getApiKeyFromUsername(username); for (CkanGroup ckanGroup : groups) { String role = catalogue.getRoleOfUserInGroup(username, ckanGroup.getName(), apiKey); - BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanGroup.getTitle(), "/group/" + ckanGroup.getName(), CkanRole.valueOf(role.toUpperCase())); + BeanUserInOrgGroupRole org = new BeanUserInOrgGroupRole(ckanGroup.getTitle(), "/group/" + ckanGroup.getName(), RolesCkanGroupOrOrg.valueOf(role.toUpperCase())); toReturn.add(org); } logger.debug("List of groups to return for user " + username + " is " + toReturn); diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/SessionUtil.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/SessionUtil.java index 55228c0..d39f63a 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/SessionUtil.java @@ -8,7 +8,7 @@ import javax.servlet.http.HttpSession; import org.gcube.common.portal.PortalContext; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.datacatalogue.ckanutillibrary.ApplicationProfileScopePerUrlReader; +import org.gcube.datacatalogue.ckanutillibrary.server.ApplicationProfileScopePerUrlReader; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanConnectorAccessPoint; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; @@ -16,8 +16,6 @@ import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemExcep import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.model.GCubeGroup; import org.gcube.vomanagement.usermanagement.model.GCubeUser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/UserUtil.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/UserUtil.java index b2295cc..0aa1e44 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/UserUtil.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/UserUtil.java @@ -3,13 +3,14 @@ */ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server; -import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; -import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue; -import org.gcube.datacatalogue.ckanutillibrary.models.RolesCkanGroupOrOrg; +import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue; +import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; import org.gcube.portlets.widgets.ckandatapublisherwidget.shared.OrganizationBean; -import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.CkanRole; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.RoleManager; import org.gcube.vomanagement.usermanagement.UserManager; @@ -40,73 +41,76 @@ public class UserUtil { //private static Logger logger = LoggerFactory.getLogger(UserUtil.class); private static final Log logger = LogFactoryUtil.getLog(UserUtil.class); - private static final String SOBIGDATA_VO_CONTEXT = "/d4science.research-infrastructures.eu/SoBigData"; /** - * Gets the list vre for user. + * Gets the list vre for user and the role the user has in them. * 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 getListVreForUser(String userEMail){ + public static Map getVreRoleForUser(String userEMail, String context){ - // Instanciate the manager GroupManager groupManager = new LiferayGroupManager(); - // Instanciate the manager UserManager userManager = new LiferayUserManager(); + RoleManager roleManager = new LiferayRoleManager(); + Map mapRoleByGroup = new HashMap(); GCubeUser user; try { user = userManager.getUserByEmail(userEMail); - // retrieve the groups to whom a given user belongs (given the user identifier) List listOfGroups = groupManager.listGroupsByUser(user.getUserId()); - logger.info("List of VREs for "+userEMail+ " is/are: "+listOfGroups.size()); - List vreNames = new ArrayList(listOfGroups.size()); - boolean containsSoBigDataVRE = false; - for (GCubeGroup gCubeGroup : listOfGroups) { - vreNames.add(gCubeGroup.getGroupName()); + // filter according the current context: if it is a VO/VRE, we send all the VRES under the VO. If it is the root vo, we send all user's vres. + long groupIdContext = groupManager.getGroupIdFromInfrastructureScope(context); + GCubeGroup groupContext = groupManager.getGroup(groupIdContext); + Iterator iterator = listOfGroups.iterator(); + if(groupManager.isVRE(groupIdContext)){ - // in case of sobigdata vres (under the SoBigData VO) we need to let users access all the sobigdata organizations in ckan - // The VO scope is "/d4science.research-infrastructures.eu/SoBigData" - // This code will work only if all the sobigdata organizations are on the same ckan, of course - if(!containsSoBigDataVRE) - if(gCubeGroup.getParentGroupId() != -1 && SOBIGDATA_VO_CONTEXT.equals(groupManager.getInfrastructureScope(gCubeGroup.getParentGroupId()))) - containsSoBigDataVRE = true; + long parentId = groupContext.getParentGroupId(); + + while (iterator.hasNext()) { + GCubeGroup gCubeGroup = (GCubeGroup) iterator.next(); + if(gCubeGroup.getParentGroupId() != parentId) + iterator.remove(); + + } + + }else if(groupManager.isVO(groupIdContext)){ + + // get the list of vres + while (iterator.hasNext()) { + GCubeGroup gCubeGroup = (GCubeGroup) iterator.next(); + if(groupIdContext != gCubeGroup.getParentGroupId()) + iterator.remove(); + } + + + }else{ + + // only the vres + while (iterator.hasNext()) { + GCubeGroup gCubeGroup = (GCubeGroup) iterator.next(); + if(!groupManager.isVRE(gCubeGroup.getGroupId())) + iterator.remove(); + } } - // check if we need to add also sobigdata vres - if(containsSoBigDataVRE) - addSoBigDataVREs(groupManager, vreNames); + // retrieve the role + for (GCubeGroup vre: listOfGroups) { - logger.debug("Returning VRE names: "+vreNames); - return vreNames; + mapRoleByGroup.put(vre.getGroupName().toLowerCase(), + RolesCkanGroupOrOrg.convertToCkanCapacity(getLiferayHighestRoleInOrg(roleManager.listRolesByUserAndGroup(user.getUserId(), vre.getGroupId())))); + + } + + logger.debug("Returning Map : " + mapRoleByGroup); + return mapRoleByGroup; }catch (UserManagementSystemException | UserRetrievalFault | GroupRetrievalFault e) { logger.error("An error occurred during get list of VREs for user: "+userEMail, e); return null; } } - /** - * Fetch (if needed) the groups' names of the vres under sobigdata - * @param groupManager - * @param vreNames - */ - private static void addSoBigDataVREs(GroupManager groupManager, List vreNames){ - - try{ - // fetch all sobigdata contexts - GCubeGroup sobigdataVO = groupManager.getGroup(groupManager.getGroupIdFromInfrastructureScope(SOBIGDATA_VO_CONTEXT)); - List children = sobigdataVO.getChildren(); - - for (GCubeGroup gcubeSobigDataChild : children) { - vreNames.add(gcubeSobigDataChild.getGroupName()); - } - }catch(Exception e){ - logger.error("Unable to retrieve SoBigData vres", e); - } - } /** * Retrieve the highest ckan role the user has and also retrieve the list of organizations (scopes) in which the user has the ckan-admin or ckan-editor role @@ -117,10 +121,10 @@ public class UserUtil { * @param orgsInWhichAdminRole * @param ckanUtils ckanUtils */ - public static CkanRole getHighestRole(String currentScope, String username, String groupName, GcubeCkanDataCatalogServiceImpl gcubeCkanDataCatalogServiceImpl, List orgsInWhichAtLeastEditorRole){ + public static RolesCkanGroupOrOrg getHighestRole(String currentScope, String username, String groupName, GcubeCkanDataCatalogServiceImpl gcubeCkanDataCatalogServiceImpl, List orgsInWhichAtLeastEditorRole){ // base role as default value - CkanRole toReturn = CkanRole.MEMBER; + RolesCkanGroupOrOrg toReturn = RolesCkanGroupOrOrg.MEMBER; try{ @@ -159,12 +163,12 @@ public class UserUtil { checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(), correspondentRoleToCheck, groupManager, gcubeCkanDataCatalogServiceImpl, orgsInWhichAtLeastEditorRole); - if(toReturn.equals(CkanRole.ADMIN)) + if(toReturn.equals(RolesCkanGroupOrOrg.ADMIN)) continue; - else if(toReturn.equals(CkanRole.EDITOR) && correspondentRoleToCheck.equals(RolesCkanGroupOrOrg.ADMIN)) - toReturn = CkanRole.ADMIN; + else if(toReturn.equals(RolesCkanGroupOrOrg.EDITOR) && correspondentRoleToCheck.equals(RolesCkanGroupOrOrg.ADMIN)) + toReturn = RolesCkanGroupOrOrg.ADMIN; else // it was MEMBER - toReturn = mapRolesCkanGroupOrOrgToCkanRole(correspondentRoleToCheck); + toReturn = correspondentRoleToCheck; } @@ -189,12 +193,12 @@ public class UserUtil { checkIfRoleIsSetInCkanInstance(username, gCubeGroupName, gCubeGroup.getGroupId(), correspondentRoleToCheck, groupManager, gcubeCkanDataCatalogServiceImpl, orgsInWhichAtLeastEditorRole); - if(toReturn.equals(CkanRole.ADMIN)) + if(toReturn.equals(RolesCkanGroupOrOrg.ADMIN)) continue; - else if(toReturn.equals(CkanRole.EDITOR) && correspondentRoleToCheck.equals(RolesCkanGroupOrOrg.ADMIN)) - toReturn = CkanRole.ADMIN; + else if(toReturn.equals(RolesCkanGroupOrOrg.EDITOR) && correspondentRoleToCheck.equals(RolesCkanGroupOrOrg.ADMIN)) + toReturn = RolesCkanGroupOrOrg.ADMIN; else - toReturn = mapRolesCkanGroupOrOrgToCkanRole(correspondentRoleToCheck); + toReturn = correspondentRoleToCheck; } }else if(groupManager.isVRE(currentGroupId)){ @@ -209,12 +213,12 @@ public class UserUtil { checkIfRoleIsSetInCkanInstance(username, groupName, currentGroupId, correspondentRoleToCheck, groupManager, gcubeCkanDataCatalogServiceImpl, orgsInWhichAtLeastEditorRole); - toReturn = mapRolesCkanGroupOrOrgToCkanRole(correspondentRoleToCheck); + toReturn = correspondentRoleToCheck; } }catch(Exception e){ logger.error("Unable to retrieve the role information for this user. Returning member role", e); - return CkanRole.MEMBER; + return RolesCkanGroupOrOrg.MEMBER; } // return the role @@ -281,21 +285,4 @@ public class UserUtil { } return RolesCkanGroupOrOrg.MEMBER; } - - /** - * Return the correspondent CkanRole - * @param correspondentRoleToCheck - * @return - */ - private static CkanRole mapRolesCkanGroupOrOrgToCkanRole( - RolesCkanGroupOrOrg correspondentRoleToCheck) { - switch(correspondentRoleToCheck){ - - case ADMIN: return CkanRole.ADMIN; - case EDITOR: return CkanRole.EDITOR; - case MEMBER: return CkanRole.MEMBER; - default:return null; - - } - } } diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/manage/GRSFNotificationService.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/manage/GRSFNotificationService.java index ba5d969..1ccd9a8 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/manage/GRSFNotificationService.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/manage/GRSFNotificationService.java @@ -11,8 +11,7 @@ import java.util.List; import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; import org.gcube.common.scope.api.ScopeProvider; -import org.gcube.datacatalogue.ckanutillibrary.DataCatalogue; -import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server.SessionUtil; +import org.gcube.datacatalogue.ckanutillibrary.server.DataCatalogue; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared.ManageProductBean; import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.api.SimpleQuery; @@ -20,8 +19,6 @@ import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/shared/BeanUserInOrgGroupRole.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/shared/BeanUserInOrgGroupRole.java index 0799562..5a08345 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/shared/BeanUserInOrgGroupRole.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/shared/BeanUserInOrgGroupRole.java @@ -2,6 +2,8 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared; import java.io.Serializable; +import org.gcube.datacatalogue.ckanutillibrary.shared.RolesCkanGroupOrOrg; + /** * A bean that contains the tuple: *
    @@ -17,7 +19,7 @@ public class BeanUserInOrgGroupRole implements Serializable { private static final long serialVersionUID = 9022496195659804838L; private String name; private String url; - private CkanRole role; + private RolesCkanGroupOrOrg role; public BeanUserInOrgGroupRole() { super(); @@ -28,7 +30,7 @@ public class BeanUserInOrgGroupRole implements Serializable { * @param orgUrl * @param role */ - public BeanUserInOrgGroupRole(String name, String url, CkanRole role) { + public BeanUserInOrgGroupRole(String name, String url, RolesCkanGroupOrOrg role) { super(); this.name = name; this.url = url; @@ -51,11 +53,11 @@ public class BeanUserInOrgGroupRole implements Serializable { this.url = url; } - public CkanRole getRole() { + public RolesCkanGroupOrOrg getRole() { return role; } - public void setRole(CkanRole role) { + public void setRole(RolesCkanGroupOrOrg role) { this.role = role; } diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/shared/CkanConnectorAccessPoint.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/shared/CkanConnectorAccessPoint.java index b8fa2f7..3aac10c 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/shared/CkanConnectorAccessPoint.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/shared/CkanConnectorAccessPoint.java @@ -4,7 +4,9 @@ package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared; import java.io.Serializable; -import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; import org.gcube.portlets.gcubeckan.gcubeckandatacatalog.server.GcubeCkanDataCatalogServiceImpl; @@ -30,7 +32,7 @@ public class CkanConnectorAccessPoint implements Serializable{ private String pathInfoParameter; private String queryStringParameters; private String gcubeTokenValue; - private List listOfVRes; + private Map mapVresRoles; private String serverviceContext; /** @@ -94,14 +96,15 @@ public class CkanConnectorAccessPoint implements Serializable{ * * @param listVREs the list vr es */ - public void addListOfVREs(List listVREs){ - this.listOfVRes = listVREs; + public void addListOfVREs(Map listVREs){ + this.mapVresRoles = listVREs; String vres = ""; if(listVREs!=null && listVREs.size()>0){ - for (String vre : listVREs) { - vres+=vre+","; + Set> set = listVREs.entrySet(); + for (Entry entry : set) { + vres += entry.getKey().toLowerCase() + "|" + entry.getValue() + ","; } - vres = vres.substring(0, vres.length()-1).toLowerCase(); //remove last "," and to lower case. A CKAN Organization ID must be lower case + vres = vres.substring(0, vres.length()-1); //remove last "," and to lower case. A CKAN Organization ID must be lower case } if(vres.length()>0){ @@ -182,9 +185,9 @@ public class CkanConnectorAccessPoint implements Serializable{ * * @return the listOfVRes */ - public List getListOfVRes() { + public Map getListOfVRes() { - return listOfVRes; + return mapVresRoles; } /** @@ -250,7 +253,7 @@ public class CkanConnectorAccessPoint implements Serializable{ builder.append(", gcubeTokenValue="); builder.append(gcubeTokenValue); builder.append(", listOfVRes="); - builder.append(listOfVRes); + builder.append(mapVresRoles); builder.append(", context="); builder.append(serverviceContext); builder.append("]"); diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/shared/CkanRole.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/shared/CkanRole.java deleted file mode 100644 index ead2d4b..0000000 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/shared/CkanRole.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * - */ -package org.gcube.portlets.gcubeckan.gcubeckandatacatalog.shared; - - -/** - * The Ckan role list - * @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it - * @author Costantino Perciante costantino.perciante@isti.cnr.it - * Jun 9, 2016 - */ -public enum CkanRole { - MEMBER, - EDITOR, - ADMIN -}