From a7f8764145b2aa0a77790f2e40ac04da96d48483 Mon Sep 17 00:00:00 2001 From: "nikolas.laskaris" Date: Wed, 9 Oct 2013 14:57:36 +0000 Subject: [PATCH] Added code to GenericResource class to support the IS communication of VRE_Information_Space_Editor (admin) portlet git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerCore@82824 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 3 +- .../framework/core/util/GenericResource.java | 112 +++++++++++++++++- .../core/util/GenericResourcesConstants.java | 18 +++ 3 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/gcube/application/framework/core/util/GenericResourcesConstants.java diff --git a/pom.xml b/pom.xml index e143923..3cbc2a4 100644 --- a/pom.xml +++ b/pom.xml @@ -186,12 +186,13 @@ xalan 2.7.1 + net.sourceforge.addressing addressing 1.1.1 - + diff --git a/src/main/java/org/gcube/application/framework/core/util/GenericResource.java b/src/main/java/org/gcube/application/framework/core/util/GenericResource.java index 275a793..502cd02 100644 --- a/src/main/java/org/gcube/application/framework/core/util/GenericResource.java +++ b/src/main/java/org/gcube/application/framework/core/util/GenericResource.java @@ -14,6 +14,7 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; @@ -36,6 +37,7 @@ import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.queries.api.SimpleQuery; import org.gcube.resources.discovery.icclient.ICClient; import org.w3c.dom.Document; +import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,6 +47,7 @@ import static org.gcube.resources.discovery.icclient.ICFactory.*; import org.gcube.common.resources.gcore.Resource; import org.gcube.common.resources.gcore.Resource.Type; import org.gcube.common.resources.gcore.Resources; +import org.gcube.common.resources.gcore.ServiceInstance; /** @@ -148,7 +151,113 @@ public class GenericResource implements GenericResourceInfoI { return (List) (CachesManager.getInstance().getGenericResourceCache().get(query).getValue()); } + /** + * retrieves from the IS all the Tree collections under the current scope + * @param onlyUserCollections if true, it returns only user tree collections, otherwise it returns all tree collections + * @return a hashmap containing the {collection id, collection resource} + */ + public HashMap getAllTreeCollections(boolean onlyUserCollections) { + // maybe should add the ScopeProvider.instance.set(session.getScope()) here and not in the constructors. + HashMap pairs = new HashMap(); + SimpleQuery query = null; + try { + query = queryFor(org.gcube.common.resources.gcore.GenericResource.class); + query.addCondition("$resource/Profile/SecondaryType eq 'DataSource'"); + if(onlyUserCollections) + query.addCondition("$resource/Profile/Body/SourceProperties/user eq 'true'"); + List results = client.submit(query); + if (results == null || results.size() == 0) + logger.debug("Couldn't find any tree collections within that scope! Will return empty list."); + else + logger.debug("# of Tree Collections found: "+ results.size()); + for (org.gcube.common.resources.gcore.GenericResource gr : results) + pairs.put(gr.id(), gr); + } catch (Exception e) { + logger.debug("Remote Exception:" + e.toString()); + } + return pairs; + } + /** + * retrieves from the IS all the OpenSearch collections under the current scope + * @param onlyUserCollections if true, it returns only user opensearch collections, otherwise it returns all opensearch collections + * @return a hashmap containing the {collection id, collection resource} + */ + public HashMap getAllOpenSearchCollections(boolean onlyUserCollections) { + // maybe should add the ScopeProvider.instance.set(session.getScope()) here and not in the constructors. + HashMap pairs = new HashMap(); + SimpleQuery query = null; + try { + query = queryFor(org.gcube.common.resources.gcore.GenericResource.class); + query.addCondition("$resource/Profile/SecondaryType eq 'GCUBECollection'"); + if(onlyUserCollections) + query.addCondition("$resource/Profile/Body/CollectionInfo/user eq 'true'"); + List results = client.submit(query); + if (results == null || results.size() == 0) + logger.debug("Couldn't find any OpenSearch collections within that scope! Will return empty list."); + else + logger.debug("# of OpenSearch Collections found: "+ results.size()); + for (org.gcube.common.resources.gcore.GenericResource gr : results) + pairs.put(gr.id(), gr); + } catch (Exception e) { + logger.debug("Remote Exception:" + e.toString()); + } + return pairs; + } + + + + /** + * + * @param collectionID The ID of the collection + * @return the cardinality of the collection stored within the IS + */ + + public String getTreeResourceCardinality(String collectionID){ + SimpleQuery query = queryFor(ServiceInstance.class); + query.addCondition("$resource/Data/*[ends-with(name(.),'ServiceName')]/text() eq 'tree-manager-service'"); + query.addCondition("$resource/Data/*[ends-with(name(.),'SourceId')]/text() eq '"+collectionID+"'"); + DiscoveryClient client = clientFor(ServiceInstance.class); + List resources = client.submit(query); +// logger.debug("Found " + resources.size() + " resources"); + + String cardinality = "0"; + if(resources.size()==0) + logger.debug("No collection '" + collectionID +"' found within scope " + ScopeProvider.instance.get()); + else if(resources.size()==1){ + NodeList nodes = resources.get(0).properties().customProperties().getChildNodes(); + for(int i=0;i retrieveGenericResourcesFromNameParts(String nameParts, String scope) throws Exception { ScopeProvider.instance.set(scope); - System.out.println("retrieveGenericResourcesFromNameParts"); + logger.debug("retrieveGenericResourcesFromNameParts"); SimpleQuery query = queryFor(GenericResource.class); //READ COMMENT BELOW !!! query.addCondition("$resource/Profile/Name eq '"+nameParts+"'"); diff --git a/src/main/java/org/gcube/application/framework/core/util/GenericResourcesConstants.java b/src/main/java/org/gcube/application/framework/core/util/GenericResourcesConstants.java new file mode 100644 index 0000000..2ccfd87 --- /dev/null +++ b/src/main/java/org/gcube/application/framework/core/util/GenericResourcesConstants.java @@ -0,0 +1,18 @@ +package org.gcube.application.framework.core.util; + + +/** + * + * @author nikolas + * + */ +public class GenericResourcesConstants { + + /** + * Generic Resource constant for IS DataSources profile name + */ + public static final String DATASOURCENAMES = "GCUBECollection"; + + + +}