Difference between revisions of "ExistClient"

From Gcube Wiki
Jump to: navigation, search
(Usage Examples)
(Usage Examples)
Line 62: Line 62:
  
 
<pre>
 
<pre>
 +
 +
GCUBERIQuery RIquery = client.getQuery(GCUBERIQuery.class);
 +
RIquery.addAtomicConditions(new AtomicCondition("//Endpoint@EntryName","gcube/annotationmanagement/abe/factory"),new AtomicCondition("//ServiceName","ABE"));
 +
for (GCUBERunningInstance instance : client.execute(RIquery,GCUBEScope.getScope("/gcube/devsec")))
 +
logger.debug(instance.getServiceName()+"("+instance.getID()+")");
 +
 +
 +
GCUBEGHNQuery GHNquery = client.getQuery(GCUBEGHNQuery.class);
 +
for (GCUBEHostingNode node : client.execute(GHNquery,GCUBEScope.getScope("/gcube/devsec"))) l
 +
logger.debug(node.getID()+"("+node.getNodeDescription().getName()+")");
 +
 
</pre>
 
</pre>
  
Line 68: Line 79:
  
 
<pre>
 
<pre>
 +
 +
WSResourceQuery wsquery = client.getQuery(WSResourceQuery.class);
 +
wsquery.addAtomicConditions(new AtomicCondition("//ServiceClass","Samples"));
 +
for (RPDocument d : client.execute(wsquery,GCUBEScope.getScope("/gcube/devsec")))
 +
logger.(d.getEndpoint()+":+d.getVO()+":"d.evaluate("//MyRP").get(0));
 +
 
</pre>
 
</pre>
  
Line 78: Line 95:
 
List<XMLResult> result =client.execute(query, scope);
 
List<XMLResult> result =client.execute(query, scope);
 
for (String resultItem :result ) {
 
for (String resultItem :result ) {
System.out.println(resultItem.evaluate("an XPath ... "));  
+
logger.debug(resultItem.evaluate("an XPath ... "));  
System.out.println(resultItem.toString());
+
logger.debug(resultItem.toString());
 
}
 
}
  
Line 103: Line 120:
 
for (XMLResult result : client.execute(query,scope)) logger.debug(result.evaluate("//Description")); //displays a singleton list
 
for (XMLResult result : client.execute(query,scope)) logger.debug(result.evaluate("//Description")); //displays a singleton list
  
</pre>
 
 
You can use a predefined ISQuery Object as well:
 
 
<pre>
 
 
GCUBEWSResourceEPRFromRPValuesAndNamespaceQuery query = client.getQuery(GCUBEWSResourceEPRFromRPValuesAndNamespaceQuery.class);
 
GCUBEWSProperty property = new GCUBEWSProperty("IndexTypeName","index_type_string_string");
 
 
GCUBEWSProperty property2 = new GCUBEWSProperty("IndexID","999ba610-e9fb-11dc-b51b-84732c1e88f2");
 
 
ArrayList <GCUBEWSProperty> properties = new ArrayList();
 
properties.add(property);
 
properties.add(property2);
 
query.setPropertiesValuesAndNamespace(properties, "http://gcube-system.org/namespaces/index/ForwardIndexManagementService");
 
 
List<EndpointReferenceType> result = client.execute(query, scope);
 
 
for (EndpointReferenceType resultItem :result ) {
 
System.out.println(resultItem.toString());
 
 
}
 
 
</pre>
 
</pre>

Revision as of 17:57, 23 May 2008

Introduction

The ExistClient is a Java library that implements the ISClient interface provided by the gCoreFramework. This library allow the developer to execute queries on the Information System.


Implementation Overview

The ExistClient implements all the query defined in the ISClient Interface:


Queries over GCUBEResource:

  • GCUBECollectionQuery
  • GCUBECSInstanceQuery
  • GCUBECSQuery
  • GCUBEExternalRIQuery
  • GCUBEGenericResourceQuery
  • GCUBEGHNQuery
  • GCUBEMCollectionQuery
  • GCUBERIQuery
  • GCUBEServiceQuery
  • GCUBETPQuery
  • GCUBEVREQuery

This queries returns a List of specialized GCUBEResource.


Queries over GCUBEWSResource:

  • WSResourceQuery

This query returns a List of RPDocument. The RPDocument object allows developer to retrieve the informations on WSResourceProperties or to exceute XPath .


The ExistClient also offers the possibility to execute custom queries: GCUBEGenericQuery. GCUBEGenericQuery allows the developer to set the query expression to execute and to use a predefined set of queries which he should set some parameters on listed below:

  • GCUBEResourceQuery
  • GCUBEWSResourceQuery
  • RIEndpoint
  • RIOnGHN
  • RISpecificData
  • GHNIDFromHostName
  • InternalCollections
  • UserCollectionIDsFromSchemaURI
  • MCollectionIDForCollection
  • MCollectionFormatsForCollection
  • MCollectionIDFromCollectionIDAndRole
  • MCollectionIDFromFormatLanguage
  • MCollectionIDFromFormatLanguage
  • MCollectionIDFromName
  • MCollectionIDFromSchemaURI


This kind of queries returns a List of XMLResult. The XMLResult object allows the developer to explore the contained document with XPaths.

Usage Examples

Query over GCUBEResource examples:


GCUBERIQuery RIquery = client.getQuery(GCUBERIQuery.class);
RIquery.addAtomicConditions(new AtomicCondition("//Endpoint@EntryName","gcube/annotationmanagement/abe/factory"),new AtomicCondition("//ServiceName","ABE"));
for (GCUBERunningInstance instance : client.execute(RIquery,GCUBEScope.getScope("/gcube/devsec")))
logger.debug(instance.getServiceName()+"("+instance.getID()+")");


GCUBEGHNQuery GHNquery = client.getQuery(GCUBEGHNQuery.class);
for (GCUBEHostingNode node : client.execute(GHNquery,GCUBEScope.getScope("/gcube/devsec"))) l
logger.debug(node.getID()+"("+node.getNodeDescription().getName()+")");


Query over WSResource examples:


WSResourceQuery wsquery = client.getQuery(WSResourceQuery.class);
wsquery.addAtomicConditions(new AtomicCondition("//ServiceClass","Samples"));
for (RPDocument d : client.execute(wsquery,GCUBEScope.getScope("/gcube/devsec"))) 
logger.(d.getEndpoint()+":+d.getVO()+":"d.evaluate("//MyRP").get(0));

GCUBEGenericQuery example:


GCUBEGenericQuery query = client.getQuery(GCUBEGenericQuery.class);
query.setExpression("for $Profile in collection(\"/db/Profiles\")//Document/Data/child::*[local-name()='Profile']/Resource return $Profile/UniqueID");
List<XMLResult> result =client.execute(query, scope);
for (String resultItem :result ) {
logger.debug(resultItem.evaluate("an XPath ... ")); 
logger.debug(resultItem.toString());
}

Predefined generic query examples:


GCUBEGenericQuery query = client.getQuery("GCUBEResourceQuery");
for (XMLResult result : client.execute(query,scope)) logger.debug(result.evaluate("/ID/text()"));//displays a singleton list
//a bit of customisation goes a long way whilst keeping the previous abstractions
query.addParameters(new QueryParameter("RESULT","$result/Type"));
for (XMLResult result : client.execute(query, scope)) logger.debug(result.evaluate("/Type/text()"));

//specialise to GCUBE Running Instances (NB. queries can be composed incrementally, possibly by different objects in different methods)
query.addParameters(new QueryParameter("TYPE",GCUBERunningInstance.TYPE)); 
for (XMLResult result : client.execute(query,scope)) logger.debug(result.evaluate("/Type/text()"));
//introduce a filter (NB. parameters can be added in batches) 
query.addParameters(new QueryParameter("TYPE",GCUBERunningInstance.TYPE), //ovverride previous setting
     new QueryParameter("FILTER","$result/Profile/ServiceClass/string() eq 'Annotation'"),
     new QueryParameter ("RESULT", "$result/Profile/Description")); //any Xquery condition on $result would do
for (XMLResult result : client.execute(query,scope)) logger.debug(result.evaluate("//Description")); //displays a singleton list