diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java index 96ef33e..c838c28 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/client/ui/CreateDatasetForm.java @@ -287,7 +287,7 @@ public class CreateDatasetForm extends Composite{ @Override public void onFailure(Throwable caught) { - setAlertBlock("Error while retrieving information, try to refresh the page and retry", AlertType.ERROR, true); + setAlertBlock("Error while retrieving information", AlertType.ERROR, true); } @@ -296,7 +296,7 @@ public class CreateDatasetForm extends Composite{ if(bean == null){ - setAlertBlock("Error while retrieving information, try to refresh the page and retry", AlertType.ERROR, true); + setAlertBlock("Error while retrieving information", AlertType.ERROR, true); } else{ @@ -362,7 +362,7 @@ public class CreateDatasetForm extends Composite{ // force the selection of the first one, and retrieve the list of profiles organizationsListbox.setSelectedIndex(0); - // add change handler to dinamycally retrieve the list of profiles + // add change handler to dynamically retrieve the list of profiles organizationsListbox.addChangeHandler(new ChangeHandler() { @Override @@ -383,14 +383,14 @@ public class CreateDatasetForm extends Composite{ @Override public void onFailure(Throwable caught) { - setAlertBlock("Error while retrieving profiles, try later", AlertType.ERROR, true); + setAlertBlock("Error while retrieving profiles, retry later", AlertType.ERROR, true); } @Override public void onSuccess(final List profiles) { if(profiles == null){ - setAlertBlock("Error while retrieving profiles, try later", AlertType.ERROR, true); + setAlertBlock("Error while retrieving profiles, retry later", AlertType.ERROR, true); } else{ diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java index 36a50c2..47226d2 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/CKANPublisherServicesImpl.java @@ -516,17 +516,17 @@ public class CKANPublisherServicesImpl extends RemoteServiceServlet implements C public boolean isPublisherUser(boolean isWorkspaceRequest) { String username = Utils.getCurrentUser(getThreadLocalRequest()).getUsername(); - logger.info("Checking if the user " + username + " can publish or not"); + logger.info("Checking if the user " + username + " can publish or not on the catalogue"); + if(!isWithinPortal()){ + logger.warn("OUT FROM PORTAL DETECTED RETURNING TRUE"); + return false; + } + try{ HttpSession httpSession = this.getThreadLocalRequest().getSession(); - if(!isWithinPortal()){ - logger.warn("OUT FROM PORTAL DETECTED RETURNING TRUE"); - return false; - } - // retrieve scope per current portlet url String scopePerCurrentUrl = Utils.getScopeFromClientUrl(getThreadLocalRequest()); diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GCoreEndPointReaderSocial.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GCoreEndPointReaderSocial.java new file mode 100644 index 0000000..2583fae --- /dev/null +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/GCoreEndPointReaderSocial.java @@ -0,0 +1,73 @@ +package org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils; + +import static org.gcube.resources.discovery.icclient.ICFactory.client; +import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; + +import java.util.List; + +import org.gcube.common.resources.gcore.GCoreEndpoint; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.SimpleQuery; + +import com.liferay.portal.kernel.log.Log; +import com.liferay.portal.kernel.log.LogFactoryUtil; + +/** + * Retrieves the base url of the social-networking service in the scope provided + * @author Costantino Perciante at ISTI-CNR + * (costantino.perciante@isti.cnr.it) + */ +public class GCoreEndPointReaderSocial { + + private String basePath = null; + private static final Log logger = LogFactoryUtil.getLog(GCoreEndPointReaderSocial.class); + private static final String resource = "jersey-servlet"; + private static final String serviceName = "SocialNetworking"; + private static final String serviceClass = "Portal"; + + public GCoreEndPointReaderSocial(String context){ + + if(context == null || context.isEmpty()) + throw new IllegalArgumentException("A valid context is needed to discover the service"); + + + String oldContext = ScopeProvider.instance.get(); + ScopeProvider.instance.set(context); + + try{ + + SimpleQuery query = queryFor(GCoreEndpoint.class); + query.addCondition(String.format("$resource/Profile/ServiceClass/text() eq '%s'",serviceClass)); + query.addCondition("$resource/Profile/DeploymentData/Status/text() eq 'ready'"); + query.addCondition(String.format("$resource/Profile/ServiceName/text() eq '%s'",serviceName)); + query.setResult("$resource/Profile/AccessPoint/RunningInstanceInterfaces//Endpoint[@EntryName/string() eq \""+resource+"\"]/text()"); + + DiscoveryClient client = client(); + List endpoints = client.submit(query); + if (endpoints == null || endpoints.isEmpty()) throw new Exception("Cannot retrieve the GCoreEndpoint serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+context); + + + this.basePath = endpoints.get(0); + if(basePath==null) + throw new Exception("Endpoint:"+resource+", is null for serviceName: "+serviceName +", serviceClass: " +serviceClass +", in scope: "+context); + + logger.info("found entyname "+basePath+" for ckanResource: "+resource); + + }catch(Exception e){ + logger.error("Unable to retrieve such service endpoint information!", e); + }finally{ + if(oldContext != null && !oldContext.equals(context)) + ScopeProvider.instance.set(oldContext); + } + logger.info("Found base path " + basePath + " for the service"); + } + + /** + * Get the base path of the social networking service + * @return + */ + public String getBasePath() { + return basePath; + } +} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/ServiceEndPointReaderSocial.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/ServiceEndPointReaderSocial.java deleted file mode 100644 index efc13f3..0000000 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/ServiceEndPointReaderSocial.java +++ /dev/null @@ -1,100 +0,0 @@ -package org.gcube.portlets.widgets.ckandatapublisherwidget.server.utils; - -import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; -import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; - -import java.util.Iterator; -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.resources.discovery.client.api.DiscoveryClient; -import org.gcube.resources.discovery.client.queries.api.SimpleQuery; - -import com.liferay.portal.kernel.log.Log; -import com.liferay.portal.kernel.log.LogFactoryUtil; - -/** - * Retrieves the base url of the social-networking service in the scope provided - * @author Costantino Perciante at ISTI-CNR - * (costantino.perciante@isti.cnr.it) - */ -public class ServiceEndPointReaderSocial { - - private String basePath = null; - - //private static Logger logger = LoggerFactory.getLogger(ServiceEndPointReaderSocial.class); - private static final Log logger = LogFactoryUtil.getLog(ServiceEndPointReaderSocial.class); - private final static String RUNTIME_RESOURCE_NAME = "SocialNetworking"; - private final static String CATEGORY = "Portal"; - - public ServiceEndPointReaderSocial(String context){ - - if(context == null || context.isEmpty()) - throw new IllegalArgumentException("A valid context is needed to discover the service"); - - - String oldContext = ScopeProvider.instance.get(); - ScopeProvider.instance.set(context); - - try{ - - List resources = getConfigurationFromIS(); - if (resources.size() == 0){ - logger.error("There is no Runtime Resource having name " + RUNTIME_RESOURCE_NAME +" and Category " + CATEGORY + " in this scope."); - throw new Exception("There is no Runtime Resource having name " + RUNTIME_RESOURCE_NAME +" and Category " + CATEGORY + " in this scope."); - } - else { - - for (ServiceEndpoint res : resources) { - - Iterator accessPointIterator = res.profile().accessPoints().iterator(); - - while (accessPointIterator.hasNext()) { - ServiceEndpoint.AccessPoint accessPoint = (ServiceEndpoint.AccessPoint) accessPointIterator - .next(); - - // get base path - basePath = accessPoint.address(); - - // break - break; - } - } - - } - - }catch(Exception e){ - logger.error("Unable to retrieve such service endpoint information!", e); - }finally{ - if(oldContext != null && !oldContext.equals(context)) - ScopeProvider.instance.set(oldContext); - } - logger.info("Found base path " + basePath + " for the service"); - } - - /** - * Retrieve endpoints information from IS for the Service endpoint - * @return list of endpoints - * @throws Exception - */ - private List getConfigurationFromIS() throws Exception{ - - SimpleQuery query = queryFor(ServiceEndpoint.class); - query.addCondition("$resource/Profile/Name/text() eq '"+ RUNTIME_RESOURCE_NAME +"'"); - query.addCondition("$resource/Profile/Category/text() eq '"+ CATEGORY +"'"); - DiscoveryClient client = clientFor(ServiceEndpoint.class); - List toReturn = client.submit(query); - return toReturn; - - } - - /** - * Get the base path of the social networking service - * @return - */ - public String getBasePath() { - return basePath; - } -} diff --git a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java index 8203584..097dd8b 100644 --- a/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java +++ b/src/main/java/org/gcube/portlets/widgets/ckandatapublisherwidget/server/utils/Utils.java @@ -101,7 +101,7 @@ public class Utils { } return null; } - + /** * 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 * @param currentScope the current scope @@ -140,6 +140,9 @@ public class Utils { for (GCubeGroup gCubeGroup : groups) { + if(!groupManager.isVRE(gCubeGroup.getGroupId())) + continue; + // get the name of this group String gCubeGroupName = gCubeGroup.getGroupName(); @@ -241,16 +244,11 @@ public class Utils { boolean res = catalogue.checkRoleIntoOrganization(username, gCubeGroupName, correspondentRoleToCheck); if(res && !correspondentRoleToCheck.equals(RolesCkanGroupOrOrg.MEMBER)){ // get the orgs of the user and retrieve its title and name - List ckanOrgs = catalogue.getOrganizationsByUser(username); - for (CkanOrganization ckanOrganization : ckanOrgs) { - if(ckanOrganization.getName().equals(gCubeGroupName.toLowerCase())){ - orgs.add(new OrganizationBean(ckanOrganization.getTitle(), ckanOrganization.getName())); - break; - } - } + CkanOrganization organization = catalogue.getOrganizationByName(gCubeGroupName.toLowerCase()); + orgs.add(new OrganizationBean(organization.getTitle(), organization.getName())); } - } - + }else + logger.warn("It seems there is no ckan instance into scope " + groupManager.getInfrastructureScope(groupId)); } /** @@ -410,7 +408,7 @@ public class Utils { String tokenUser = SecurityTokenProvider.instance.get(); logger.info("Current scope for writeProductPost is " + currentScope + " and token is " + tokenUser.substring(0, 10) + "***************"); - String basePath = new ServiceEndPointReaderSocial(currentScope).getBasePath(); + String basePath = new GCoreEndPointReaderSocial(currentScope).getBasePath(); if(basePath == null){