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

Knowledgebase

Part 7 : List Services


Table of Contents

Step 1: Construct the List Template

  1. In mytemplates/thewebapp make the template listservices.html
  2. Enter the following into the file
    {% if the_username %}
    	Hello <b>{{ the_username }}</b>, you are logged in. Do you want to <a href="/logout/">Logout?</a><br>
    {% else %}
    	Hello, do you want to <a href="/login/">Login</a> to save queries and query secure data services?<br>
    {% endif %}
    <h1>List Services</h1>
    
    {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
    <form action="/listservices/">
    	<input type="radio" name="service" value="1">All Services<br>
    	<input type="radio" name="service" value="2">Data Services<br>
    	<input type="radio" name="service" value="3">Analytical Services<br>
    	<input type="submit" value="Submit" />
    </form>
    {% if services %}
    	{% for aservice in services %}
    		{{ aservice }}<br>
    	{% endfor %}
    {% endif %}
    
    <a href="/index/">Back to the Index</a><br>
    
  3. Save the file

Step 2: Add the List methods

  1. Open GridClient/views.py
  2. Add imports, don't worry if eclipse complains about the imports
    from gov.nih.nci.cagrid.discovery.client import DiscoveryClient
    from gov.nih.nci.cagrid.metadata import MetadataUtils
    from org.apache.axis.types.URI import MalformedURIException
    from gov.nih.nci.cagrid.metadata.exceptions import QueryInvalidException, RemoteResourcePropertyRetrievalException, ResourcePropertyRetrievalException
    
  3. Add public variables
    #make a discoveryClient with the index service url
    discClient=DiscoveryClient(props.getProperty(DEFAULT_INDEX_SERVICE_URL_PROP))
    
  4. Add the listservices method
    def listservices(request):
        if "service" in request.GET:
            try:
                services=[]
                serviceType = int(request.GET['service'])
               
                if (serviceType == 1): serviceEndpoints = discClient.getAllServices(1)
                elif (serviceType == 2): serviceEndpoints = discClient.getAllDataServices()
                else: serviceEndpoints = discClient.getAllAnalyticalServices()
                count=1
                for ase in serviceEndpoints:
                    try:
                        services.append("%i: %s" % (count,ase.getAddress()))
                        metadata = MetadataUtils.getServiceMetadata(ase)
                        description = metadata.getServiceDescription().getService().getDescription()
                        services.append("Description: %s" % description)
                        hostingCenter = metadata.getHostingResearchCenter().getResearchCenter().getDisplayName()
                        services.append("Hosting Center: %s" % hostingCenter)
                    except Exception, e:
                        services.append("metadata %s" % e)
                    services.append("")
                    count=count+1
                if(len(serviceEndpoints)==0):
                    services.append("No matching Services found")
                return render_to_response('thewebapp/listservices.html', 
                                          {'the_username':logged_in(request),
                                           'services': services,}, 
                                          context_instance=RequestContext(request))
            except (MalformedURIException,
                    RemoteResourcePropertyRetrievalException,
                    QueryInvalidException,
                    ResourcePropertyRetrievalException,
                    Exception), e:
                return render_to_response('thewebapp/listservices.html', 
                                  {'the_username':logged_in(request),
                                   'error_message':e,}, 
                                  context_instance=RequestContext(request))
        
        else:return render_to_response('thewebapp/listservices.html',
                                       {'the_username':logged_in(request),},
                                       context_instance=RequestContext(request)) 
    
  5. Save the file

Step 3: Add the List URLs

  1. Open GridClient/urls.py
  2. Add the listservices url and the listservices method in urlpatterns
    urlpatterns = patterns('',
        (r'^index/$', 'thewebapp.views.index'),
        (r'^login/$', 'thewebapp.views.login'),
        (r'^logout/$', 'thewebapp.views.logout'),
        (r'^badlogin/$', 'thewebapp.views.badlogin'),
        (r'^listservices/$','thewebapp.views.listservices'),
    )
    
  3. Save the file

Step 4: Test the List page

  1. Go to http://localhost:8000/listservices/
  2. Select Data Services and press Submit, you should see the resulting data services
Last edited by
Saba Bokhari (554 days ago)
Adaptavist Theme Builder Powered by Atlassian Confluence