Access Keys:
Skip to content (Access Key - 0)

Knowledgebase


Part Six: Data Service Querying


Table of Contents

Introduction


Your client has made it possible for users to discover data service that expose the data in which they are interested. The obvious next step is to add the ability for users to query data services in order to obtain the available data. Your user will want to obtain the data in order perform analyses.

We will experiment with two types of Data Service clients. The first is a generic client that handles all returned query results as XML. The second is a client that is specifically associated with a particular data service. This type of client includes the Jars from the Data Service to enable the processing of query result sets as Java objects.

We will perform a query against the BootCamp Data Service that we discovered in the previous section.

Desired Client Functionality

Submit a Query to a Data Service

  1. Open a web browser and visit http://portal.training.cagrid.org/web/guest/tools/service-discovery
  2. Click the Search tab in the Discovery portlet.
  3. Enter the search term 2322246, select caDSR Public ID (CDE) as the Search field and click the Search button.
  4. In the query results click the Query... link for the BootCampDataSvc.
  5. In the Data Service Query Portlet you will see the list of classes that are exposed for querying.
  6. Click the gov.nih.nci.training.BootCamp.domain.Protein class name.
  7. The default Query Builder option is to return the number of entries in the selected class.
  8. Click the Edit Query Modifiers tab.
  9. Click the Selected Attributes option and highlight all 4 attributes, then click the Update button.
  10. Click the Export XML button to see how the query appears in CQL.
  11. Click the Submit Query button
  12. You will see that your query is listed as running. When the status changes to Complete.
  13. Click the Operations drop down box and click View Results.
  14. You will be presented with the query results and an option to save the the results to XML or CSV file.

Creating Client Functionality

Now, we will implement the data service query in our client applications. The service invocation will be performed using the caGrid Data Service Client against both secure and non-secure services.

Jar Files:
Jar dependencies Purpose
caGrid-CQL-cql.1.0-1.3 CQLQuery
caGrid-data-common-1.3.jar
caGrid-data-stubs-1.3.jar
caGrid-data-utils-1.3.jar
Provides the DataServiceClient,
CQLQueryProcessor and
CQLQueryResultsIterator.
cog-jglobus.jar Globus Jar used to supply the classes to manage the GlobusCredential.
wsrf_core.jar Globus Jar that defines serialization exceptions that we might encounter.

Step 1: Querying data services and receiving result sets in XML.

Update Ivy Dependencies

  1. Update ivy.xml with dependencies by adding the following entries within the <dependencies> section.
    <!-- Data Service Dependencies-->
    <dependency rev="${repository.version}" org="caGrid" name="cql" conf="default->cql,schemas"/>
    <dependency rev="${repository.version}" org="caGrid" name="data" conf="default->common,stubs,utils"/>
    
  2. Save the ivy.xml file.
  3. From the command line run ant all to retrieve the new jars.

Import Jars into the Project

  1. Right-click on the caGridClient project in the Eclipse Package Explorer.
  2. Select the Properties entry at the bottom of the list.
  3. Select Java Build Path, then Libraries.
  4. Select the lib entry and click the Edit button.
  5. Click User Libraries
  6. Click Add Jars
  7. Navigate to the newly added jars in caGridClient/lib and add them to the lib user library.
  8. In the Preferences dialog, click OK.
  9. In the Add Library dialog, click Finish.

Import Required Globus Jars

  1. To add the Globus Jars to the project properties, right-click on the caGridClient project in the Eclipse Package Explorer.
  2. Select the Properties entry at the bottom of the list.
  3. Select Java Build Path, then Libraries.
  4. Select the Add External Jars... entry.
  5. Navigate to the Globus ws-core-4.0.3/lib directory that was installed by the caGrid installer.
  6. Select the Globus Jars files, listed above, and then click Open.
  7. Click OK to close the Properties dialog.

Create the DataServiceActions Class

  1. Right-click org.cagrid.client and select New->Class
  2. Set the class name as DataServiceActions and click Finish.
  3. Add imports
    import gov.nih.nci.cagrid.cqlquery.CQLQuery;
    import gov.nih.nci.cagrid.cqlquery.Object;
    import gov.nih.nci.cagrid.cqlresultset.CQLQueryResults;
    import gov.nih.nci.cagrid.data.client.DataServiceClient;
    import gov.nih.nci.cagrid.data.utilities.CQLQueryResultsIterator;
    
    import java.rmi.RemoteException;
    
    import org.apache.axis.message.addressing.EndpointReferenceType;
    import org.apache.axis.types.URI.MalformedURIException;
    import org.globus.gsi.GlobusCredential;
    
  4. Create invokeNonSecureService method.
    public static CQLQueryResults invokeNonSecureService (EndpointReferenceType epr, String objectName)
    {
    	System.out.println ("Querying: " + objectName);
    
    	try
    	{
    		DataServiceClient client = new DataServiceClient(epr);
    		CQLQuery query = new CQLQuery();
    		Object target = new Object();
    		target.setName(objectName);
    		query.setTarget(target);
    
    		// execute the query
    		CQLQueryResults results = client.query(query);
    		CQLQueryResultsIterator iter = new  CQLQueryResultsIterator (results, true);
    
    		// here we can cast the returned object to a String because we're
    		// working with XML
    		while (iter.hasNext())
    		{
    			String singleResult = (String) iter.next();
    			System.out.println(singleResult.toString());
    		}
    
    		return results;
    	}
    	catch (MalformedURIException e)
    	{
    		// TODO Display appropriate client error
    		e.printStackTrace();
    	}
    	catch (RemoteException e)
    	{
    		// TODO Display appropriate client error
    		e.printStackTrace();
    	}
    	catch (Exception e)
    	{
    		// TODO Display appropriate client error
    		e.printStackTrace();
    	}
    
    	return null;
    }
    
  5. Create invokeSecureService method. Notice that for secure services you will be providing your Grid Credential.
    public static CQLQueryResults invokeSecureService (EndpointReferenceType epr, GlobusCredential cred, String objectName)
    {
    	try
    	{
            	System.out.println ("Querying: " + objectName);
    
    		DataServiceClient client = new DataServiceClient(epr, cred);
    		CQLQuery query = new CQLQuery();
    		Object target = new Object();
    		target.setName(objectName);
    		query.setTarget(target);
    
    		// execute the query
    		CQLQueryResults results = client.query(query);
    		CQLQueryResultsIterator iter = new CQLQueryResultsIterator (results, true);
    
    		// here we can cast the returned object to a String because we're
    		// working with XML
    		while (iter.hasNext())
    		{
    			String singleResult = (String) iter.next();
    			System.out.println(singleResult.toString());
    		}
    
    		return results;
    
    	}
    	catch (MalformedURIException e) {e.printStackTrace();}
    	catch (RemoteException e) {e.printStackTrace();}
    	catch (Exception e) {e.printStackTrace();}
    
    	return null;
    }
    
  6. Save the file.

Update the GridClient Class

  1. Open GridClient.java for editing.
  2. Add imports.
    import gov.nih.nci.cagrid.metadata.dataservice.DomainModel;
    import gov.nih.nci.cagrid.metadata.dataservice.UMLClass;
    
  3. Add displayDomainObjectNames methods to allow selection of an object type to query against.
    private int  displayDomainObjectNames (EndpointReferenceType epr)
    {
    	DomainModel domainModel;
    	UMLClass[] umlClassCollection = null;
    	try
    	{
    		domainModel = MetadataUtils.getDomainModel(epr);
    		umlClassCollection = domainModel.getExposedUMLClassCollection().getUMLClass();
    
    		for (int i=0; i < umlClassCollection.length; i++)
    		{
    		    String objectName = umlClassCollection[i].getPackageName()+"."+umlClassCollection[i].getClassName();
    			System.out.println("    " + i + ": " + objectName);
    		}
    
    		return umlClassCollection.length-1;
    	}
    	catch (Exception e)
    	{
    		System.out.println("ERROR: " + e.getClass().getName() + ": " + e.toString());
    	}
    
    	return 0;
    }
    
  4. Add queryDataService method.
    private void queryDataService()
    {
    	// get data service list
    	String indexServiceUrl = props.getProperty(DEFAULT_INDEX_SERVICE_URL_PROP);
    	EndpointReferenceType[] eprs = null;
    
    	try
    	{
    		DiscoveryActions discActions = new DiscoveryActions(indexServiceUrl);
    
    		// search for services
    		eprs = discActions.getDataServices();
    
    		if (null != eprs && eprs.length > 0)
    		{
    			System.out.println ("Available Data Services:");
    			for (int i=0; i < eprs.length; i++)
    			{
    				System.out.println("    " + i + ": " + eprs[i].getAddress().toString());
    			}
    		}
    		else {System.out.println("No matching Services found");}
    	}
    	catch (Exception e)
    	{
    		// TODO: Display appropriate client error
    		System.out.println(e.getClass().getName() + ": " + e.toString());
    	}
    
    	// get service number for query
    	int last = eprs.length -1;
    	String message = "Select Service";
    	int serviceNumber = UserInteraction.getIntegerFromUser(message, 0, last);
    
    
    	// select the endpoint
    	EndpointReferenceType serviceEndpoint = eprs[serviceNumber];
    
    	int objectCount = displayDomainObjectNames(serviceEndpoint);
    
    	if (objectCount > 0)
    	{
    		// select an object to query
    		message = "Select a object to query: [0.." + objectCount + "]:";
    		System.out.println(message);
    		int objectNumber = UserInteraction.getIntegerFromUser(message, 0, objectCount);
    
    		// create object name
    		String objectName = null;
    		try
    		{
    			DomainModel domainModel = MetadataUtils.getDomainModel(serviceEndpoint);
    			UMLClass[] umlClassCollection = domainModel.getExposedUMLClassCollection().getUMLClass();
    			objectName = umlClassCollection[objectNumber].getPackageName()+"."+umlClassCollection[objectNumber].getClassName();
    		}
    		catch (Exception e1) {e1.printStackTrace();}
    
    		if (serviceEndpoint.getAddress().getScheme().compareTo("http") == 0)
    		{
    			DataServiceActions.invokeNonSecureService( serviceEndpoint, objectName);
    		}
    		else
    		{
    			GlobusCredential cred;
    			try
    			{
    				cred = ProxyUtil.loadProxy (props.getProperty (DEFAULT_PROXY_FILENAME));
    				DataServiceActions.invokeSecureService( serviceEndpoint, cred, objectName);
    			}
    			catch (Exception e) {e.printStackTrace();}
    		}
    	}
    }
    
  5. In Main, add call to queryDataServices where we are evaluating the user input 6.
    client.queryDataService();
    
  6. Save the file.

Build the Application

  1. Build the project
    > cd GRID_CLIENT_HOME  
    > ant all
    
  2. Fix all compilation errors

Step 2: Test the Client with domain model object based queries.


The Ant build file includes a target for running the client. It will create a classpath from the jars included by Ivy.

  1. Open a command prompt.
  2. Change directory to your caGridClient location
  3. Type ant run. This will build and execute the project
  4. When prompted, type 6 to query a data service.
  5. You are presented with a list of available data services.
    ...
    [java]     4: https://tutorials.training.cagrid.org:8443/wsrf/services/cagrid/BootCampDataSvc       
    [java]     5: http://sbdev1000.semanticbits.com:18030/wsrf/services/cagrid/CaaersDataService       
    [java]     6: http://caarraygrid.c2b2.columbia.edu:80/wsrf/services/cagrid/CaArraySvc       
    [java]     7: https://140.254.126.55:8443/wsrf/services/cagrid/CaTissueSuite       
    [java] Select Service [0..7]:
    
  6. When prompted, type the number associated with the BootCampDataSvc.
  7. You are presented with a list of objects from the services domain model.
    [java]     0: gov.nih.nci.training.BootCamp.domain.Organism        
    [java]     1: gov.nih.nci.training.BootCamp.domain.BindingSite       
    [java]     2: gov.nih.nci.training.BootCamp.domain.OrganismName       
    [java]     3: gov.nih.nci.training.BootCamp.domain.Gene       
    ...       
    [java] Select a object to query: [0..8]:
    
  8. When prompted, select the number associated with the Gene object.
  9. You will be presented with the instances of that object type. NOTE: you may receive and error when querying other services. Some data services use additional security measures.
    [java] Querying: gov.nih.nci.training.BootCamp.domain.Gene       
    [java] <ns2:Gene entrezGeneId="449497" name="BRCA1" id="1" xmlns:ns2="gme://caCORE.caCORE/3.2/gov.nih.nci.training.BootCamp.domain"/>       
    [java] <ns3:Gene name="BRCA1" id="2" xmlns:ns3="gme://caCORE.caCORE/3.2/gov.nih.nci.training.BootCamp.domain"/>
    
  10. When prompted, type 10 to close the client.

Step 3: Querying a data service with file-based CQL request and results.

Next, we will obtain a CQL query from that has been stored in an XML file. We will use the XML Utils from caGrid to deserialize the XML into a CQLQuery object then submit the request to the BootCampDataSvc. The results will be returned and serialized to an output file.

Update the DataServiceActions Class

  1. Open DataServiceActions.java for editing.
  2. Create invokeNonSecureService method to query with CQLQuery input parameter.
    public static CQLQueryResults invokeNonSecureService (EndpointReferenceType epr, CQLQuery query)
    {
    	System.out.println ("Querying non-secure with CQL query");
    
    	try
    	{
    		DataServiceClient client = new DataServiceClient(epr);
    
    		// execute the query
    		CQLQueryResults results = client.query(query);
    
    		return results;
    	}
    	catch (MalformedURIException e)
    	{
    		// TODO Display appropriate client error
    		e.printStackTrace();
    	}
    	catch (RemoteException e)
    	{
    		// TODO Display appropriate client error
    		e.printStackTrace();
    	}
    	catch (Exception e)
    	{
    		// TODO Display appropriate client error
    		e.printStackTrace();
    	}
    
    	return null;
    }
    
  3. Add the invokeSecureService method to query with CQLQuery input parameter.
    public static CQLQueryResults invokeSecureService (EndpointReferenceType epr, GlobusCredential cred, CQLQuery query)
    {
    	try
    	{
             	System.out.println ("Querying with CQL query");
    
    		DataServiceClient client = new DataServiceClient(epr, cred);
    
    		// execute the query
    		CQLQueryResults results = client.query(query);
    
    		return results;
    	}
    	catch (MalformedURIException e) {e.printStackTrace();}
    	catch (RemoteException e) {e.printStackTrace();}
    	catch (Exception e) {e.printStackTrace();}
    
    	return null;
    }
    
  4. Save the File

Update the GridClient Class

  1. Open GridClient.java for editing.
  2. Add import statements
    import gov.nih.nci.cagrid.common.Utils;
    import gov.nih.nci.cagrid.cqlquery.CQLQuery;
    import gov.nih.nci.cagrid.cqlresultset.CQLQueryResults;
    import gov.nih.nci.cagrid.data.DataServiceConstants;
    import java.io.File;
    import java.io.FileReader;
    import java.io.FileNotFoundException;
    
  3. Add new constants to support the user decision of which type of data service query to perform
    private static final int QUERY_AGAINST_OBJECT = 1;
    private static final int QUERY_FROM_FILE = 2;
    
  4. Replace the queryDataService method with the following:
    private void queryDataService()
    {
    	// get data service list
    	String indexServiceUrl = props.getProperty(DEFAULT_INDEX_SERVICE_URL_PROP);
    	EndpointReferenceType[] eprs = null;
    	try
    	{
    		DiscoveryActions discActions = new DiscoveryActions(indexServiceUrl);
    
    		// search for services
    		eprs = discActions.getDataServices();
    
    		if (null != eprs && eprs.length > 0)
    		{
    			System.out.println ("Available Data Services:");
    			for (int i=0; i < eprs.length; i++)
    			{
    				System.out.println("    " + i + ": " + eprs[i].getAddress().toString());
    			}
    		}
    		else {System.out.println("No matching Services found");}
    	}
    	catch (Exception e)
    	{
    		// TODO: Display appropriate client error
    		System.out.println(e.getClass().getName() + ": " + e.toString());
    	}
    
    	// get service number for query
    	int last = eprs.length -1;
    	String message = "Select Service";
    	int serviceNumber = UserInteraction.getIntegerFromUser(message, 0, last);
    
    	// select the endpoint
    	EndpointReferenceType serviceEndpoint = eprs[serviceNumber];
    
    	// ask user for query against object or query from file
    	System.out.println("1 : Select query object from list" );
    	System.out.println("2 : Read CQL query from file");
    	message = "Select Query Type";
    	int queryType = UserInteraction.getIntegerFromUser(message, 1, 2);
    
    	if (queryType == QUERY_AGAINST_OBJECT)
    	{
    		int objectCount = displayDomainObjectNames(serviceEndpoint);
    		if (objectCount > 0)
    		{
    			// select an object to query
    			message = "Select a object to query";
    			int objectNumber = UserInteraction.getIntegerFromUser(message, 0, objectCount);
    
    			// create object name
    			String objectName = null;
    			try
    			{
    				DomainModel domainModel = MetadataUtils.getDomainModel(serviceEndpoint);
    				UMLClass[] umlClassCollection = domainModel.getExposedUMLClassCollection().getUMLClass();
    				objectName = umlClassCollection[objectNumber].getPackageName()+"."+umlClassCollection[objectNumber].getClassName();
    			}
    			catch (Exception e1) {e1.printStackTrace();}
    
    			if ( serviceEndpoint.getAddress().getScheme().compareTo("http") == 0)
          			{
    				DataServiceActions.invokeNonSecureService( serviceEndpoint, objectName);
    			}
    			else
    			{
    				GlobusCredential cred;
    				try
    				{
    					cred = ProxyUtil.loadProxy(props.getProperty(DEFAULT_PROXY_FILENAME));
    					DataServiceActions.invokeSecureService( serviceEndpoint, cred, objectName);
    				}
    				catch (Exception e)
    				{
    					//TODO: Display appropriate client error
    					e.printStackTrace();
    				}
    			}
    		}
    	}
    
    	if (queryType == QUERY_FROM_FILE)
    	{
    
    		message = "Provide CQL Filename";
    		String filename = UserInteraction.getStringFromUser(message);
    
    		// verify file existence
    		File queryFile = new File(filename);
    		if (!queryFile.exists())
    		{
    			System.out.println ("File does not exist: " + queryFile);
    			return;
    		}
    
    		try
    		{
    			// deserialize the query
    			CQLQuery query = (CQLQuery) Utils.deserializeObject(new FileReader (queryFile), CQLQuery.class);
    
    			CQLQueryResults queryResults = null;
    
    			if (serviceEndpoint.getAddress().getScheme().compareTo("http") == 0)
    			{
    				queryResults = DataServiceActions.invokeNonSecureService( serviceEndpoint, query);
    			}
    			else
    			{
    				GlobusCredential cred;
    				try
    				{
    					cred = ProxyUtil.loadProxy(props.getProperty(DEFAULT_PROXY_FILENAME));
    					queryResults = DataServiceActions.invokeSecureService( serviceEndpoint, cred, query);
    				}
    				catch (Exception e) {e.printStackTrace();}
    			}
    
    			// write the result to a local file
    			Utils.serializeDocument("queryResults.xml", queryResults, DataServiceConstants.CQL_RESULT_COLLECTION_QNAME);
    
    			System.out.println ("Query results written to queryResults.xml");
    
    		}
    		catch (FileNotFoundException e) {e.printStackTrace();}
    		catch (Exception e) {e.printStackTrace();}
    	}
    }
    
  5. Save the File.

Create the Boot Camp CQL Query File

  1. Right-click caGridClient and select New ->File
  2. Type bootcampQuery.xml as the filename and click finish.
  3. Open the file and past the following contents. This is the CQL query that will be used to obtain all Protein entries that are associated with organisms having the commonName of "Mouse"
    <ns1:CQLQuery xmlns:ns1="http://CQL.caBIG/1/gov.nih.nci.cagrid.CQLQuery">
    	<ns1:Target name="gov.nih.nci.training.BootCamp.domain.Protein">
    		<ns1:Association roleName="organismCollection" name="gov.nih.nci.training.BootCamp.domain.Organism">
    			<ns1:Attribute name="commonName" value="Mouse" predicate="EQUAL_TO"/>
    		</ns1:Association>
    	</ns1:Target>
    </ns1:CQLQuery>
    
  4. Save the File.

Build the Application

  1. Build the project
    > cd GRID_CLIENT_HOME  
    > ant all
    
  2. Fix ant compile errors.

Step 4: Test the Client with file based queries.

The Ant build file includes a target for running the client. It will create a classpath from the jars included by Ivy.

  1. Open a command prompt.
  2. Change directory to your caGridClient location
  3. Type ant run. This will build and execute the project
  4. When prompted, type 6 to query a data service.
  5. When prompted, type the number associated with the BootCampDataSvc data service.
  6. When prompted, type 2 to select querying from a file.
    [java] 1 : Select query object from list 
    [java] 2 : Read CQL query from file 
    [java] Select Query Type [1..2] :
    
  7. You will be prompted for a filename. Type 'bootcampQuery.xml',
    [java] Provide CQL Filename:
    
  8. At this point the client will read the query, submit the query to the data service and write the results to a file named 'queryResults.xml' in your caGridClient directory.
    [java] Querying with CQL query 
    [java] Query results written to queryResults.xml
    
  9. When prompted, type the '10' to close the client.
  10. Now, view the contents of the file:
    <ns1:CQLQueryResultCollection targetClassname="gov.nih.nci.training.BootCamp.domain.Protein" xsi:type="ns1:CQLQueryResults" xmlns:ns1="http://CQL.caBIG/1/gov.nih.nci.cagrid.CQLResultSet" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <ns1:ObjectResult xsi:type="ns1:CQLObjectResult">
      <ns2:Protein uniprotkbPrimaryAccession="4" uniprotkbEntryName="BRCA1_MOUSE" type="full sequence" id="P48754" xmlns:ns2="gme://caCORE.caCORE/3.2/gov.nih.nci.training.BootCamp.domain"/>
     </ns1:ObjectResult>
     <ns1:ObjectResult xsi:type="ns1:CQLObjectResult">
      <ns3:Protein uniprotkbPrimaryAccession="12" uniprotkbEntryName="BRCA2_MOUSE" type="full sequence" id="P97929" xmlns:ns3="gme://caCORE.caCORE/3.2/gov.nih.nci.training.BootCamp.domain"/>
     </ns1:ObjectResult>
    </ns1:CQLQueryResultCollection>
    

Step 5: Querying a local data service

Update the GridClient Class

  1. Update queryDataService method
    Replace
    // get data service list
    String indexServiceUrl = props.getProperty(DEFAULT_INDEX_SERVICE_URL_PROP);
    EndpointReferenceType[] eprs = null;
    try
    {
    	DiscoveryActions discActions = new DiscoveryActions(indexServiceUrl);
    	// search for services
    	eprs = discActions.getDataServices();
    	if (null != eprs && eprs.length > 0)
    	{
    		System.out.println ("Available Data Services:");
    		for (int i=0; i < eprs.length; i++)
    		{
    			System.out.println("    " + i + ": " + eprs[i].getAddress().toString());
    		}
    	}
    	else {System.out.println("No matching Services found");}
    }
    catch (Exception e)
    {
    	// TODO: Display appropriate client error
    	System.out.println(e.getClass().getName() + ": " + e.toString());
    }
    
    // get service number for query
    int last = eprs.length -1;
    String message = "Select Service";
    int serviceNumber = UserInteraction.getIntegerFromUser(message, 0, last);
    
    // select the endpoint
    EndpointReferenceType serviceEndpoint = eprs[serviceNumber];
    

    With

    String ask="Would you like to query a local Data Service? press 1 for yes, press 0 for no";
    int answer=UserInteraction.getIntegerFromUser(ask, 0, 1);
    EndpointReferenceType serviceEndpoint =new EndpointReferenceType();
    if (answer==1)
    {
    	Scanner keyboard=new Scanner(System.in);
    	System.out.println("What is the URL of the service?");
     	ask=keyboard.nextLine();
    	serviceEndpoint= new EndpointReferenceType(new URI(ask));
    }
    else
    {
    	String indexServiceUrl = props.getProperty(DEFAULT_INDEX_SERVICE_URL_PROP);
    	EndpointReferenceType[] eprs = null;
        	// get data service list
    	try 
    	{
        		DiscoveryActions discActions = new DiscoveryActions(indexServiceUrl);
    	
        		// search for services
        		eprs = discActions.getDataServices();
    	
        		if (null != eprs && eprs.length > 0) 
        		{
        			System.out.println ("Available Data Services:");
        			for (int i=0; i < eprs.length; i++) 
        			{System.out.println("    " + i + ": " + eprs[i].getAddress().toString());}
        		}
    		else {System.out.println("No matching Services found");}
    	} 
    	catch (Exception e) {System.out.println(e.getClass().getName() + ": " + e.toString());}
    	
    	// get service number for query
    	int last = eprs.length -1;
    	String message = "Select Service";
    	int serviceNumber = UserInteraction.getIntegerFromUser(message, 0, last);
    	
    	// select the endpoint
    	serviceEndpoint = eprs[serviceNumber];
    }
    
  2. Save the File.

Build the Application

  1. Build the project
    > cd GRID_CLIENT_HOME  
    > ant all
    
  2. Fix ant compile errors.

Step 6: Test the Client with a local service

  1. Open a command prompt.
  2. Change directory to your caGridClient location
  3. Type ant run. This will build and execute the project
  4. When prompted, type 6 to query a data service.
    [java] --------------------------
    [java] 1 : Sync with Trust Fabric
    [java] 2 : Register Grid Account
    [java] 3 : Login to Grid
    [java] 4 : Search for Services
    [java] 5 : List All Services
    [java] 6 : Query a Data Service
    [java] 7 : Invoke Bootcamp Services
    [java] 8 : Get Grouper Groups for User
    [java] 9 : Invoke COPPA PO Service
    [java] 10: Quit
    [java] Select client action:  [1..10] :
    6
    [java]
    [java] Would you like to query a local Data Service? press 1 for yes, press 0 for no [0..1] :
    1
    [java] What is the URL of the service?
    
  5. Give the URL of the local data service
    https://localhost:8443/wsrf/services/cagrid/Sdk42Example 
    [java] 1 : Select query object from list
    [java] 2 : Read CQL query from file[java] Select Query Type [1..2] :
    
  6. Select the query type, in this example we use the object list option.
    1
    [java]     0: gov.nih.nci.cacoresdk.domain.inheritance.abstrakt.PrivateTeacher
    [java]     1: gov.nih.nci.cacoresdk.domain.inheritance.abstrakt.Pupil
    [java]     2: gov.nih.nci.cacoresdk.domain.inheritance.abstrakt.Teacher
    [java]     3: gov.nih.nci.cacoresdk.domain.inheritance.childwithassociation.Credit
    [java]     4: gov.nih.nci.cacoresdk.domain.inheritance.childwithassociation.Payment
    [java]     5: gov.nih.nci.cacoresdk.domain.inheritance.childwithassociation.Cash
    [java]     6: gov.nih.nci.cacoresdk.domain.inheritance.childwithassociation.Bank...
    
  7. Choose a query object
    88
    [java] Querying: gov.nih.nci.cacoresdk.domain.other.levelassociation.Card
    [java] <Card image="My Ace" Name="Ace" id="1" xmlns="gme://caCORE.caCORE/3.2/gov.nih.nci.cacoresdk.domain.other.levelassociation"/>
    [java] <Card Name="Two" id="2" xmlns="gme://caCORE.caCORE/3.2/gov.nih.nci.cacoresdk.domain.other.levelassociation"/>
    [java] <Card Name="Three" id="3" xmlns="gme://caCORE.caCORE/3.2/gov.nih.nci.cacoresdk.domain.other.levelassociation"/>
    [java] <Card Name="Four" id="4" xmlns="gme://caCORE.caCORE/3.2/gov.nih.nci.cacoresdk.domain.other.levelassociation"/>
    [java] <Card Name="Five" id="5" xmlns="gme://caCORE.caCORE/3.2/gov.nih.nci.cacoresdk.domain.other.levelassociation"/>
    [java] <Card Name="Six" id="6" xmlns="gme://caCORE.caCORE/3.2/gov.nih.nci.cacoresdk.domain.other.levelassociation"/>...
    

    Conclusion


    In this section we implemented code that allows us to retrieve data from local, secure and non-secure Grid Data Services. We utilized the CQL queries from files and direct queries based on discovered types from the Data Service domain models. You should now experiment with more complex queries in order to get familiar with the capabilities of the CQL language.

References


Last edited by
Saba Bokhari (365 days ago) , ...
Adaptavist Theme Builder Powered by Atlassian Confluence