
----
{cagridroundpanel}
{pre:class=cagridheaderfont}Table of Contents{pre}
{toc:outline=false|exclude=Part 7 : List Services|style=bullets}
{cagridroundpanel}
h3. Step 1: Construct the List Template
# In *mytemplates/thewebapp* make the template listservices.html
# Enter the following into the file
{code:html}
{% 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>
{code}
# Save the file
h3. Step 2: Add the List methods
# Open *GridClient/views.py*
# Add imports, don't worry if eclipse complains about the imports
{code}
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
{code}
# Add public variables
{code}
#make a discoveryClient with the index service url
discClient=DiscoveryClient(props.getProperty(DEFAULT_INDEX_SERVICE_URL_PROP))
{code}
# Add the listservices method
{code}
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))
{code}
# Save the file
h3. Step 3: Add the List URLs
# Open *GridClient/urls.py*
# Add the listservices url and the listservices method in urlpatterns
{code}
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'),
)
{code}
# Save the file
h3. Step 4: Test the List page
# Go to http://localhost:8000/listservices/
{gallery:include=Screen shot 2011-11-10 at 10.17.58 AM.png}
# Select Data Services and press Submit, you should see the resulting data services
{gallery:include=Screen shot 2011-11-10 at 10.18.28 AM.png}
{scrollbar}