Ignore:
Timestamp:
11/10/06 14:06:59 (13 years ago)
Author:
lawrence
Message:

Test code that works with the latest Matt discovery wsdl

Location:
TI01-discovery/trunk/python/ws2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TI01-discovery/trunk/python/ws2/Discovery.wsdl

    r1563 r1574  
    33<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:tns1="urn:DiscoveryServiceAPI" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:DiscoveryServiceAPI"> 
    44        <wsdl:types> 
    5                 <xsd:schema targetNamespace="urn:DiscoveryServiceAPI" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:DiscoveryServiceAPI"> 
     5                <xsd:schema targetNamespace="urn:DiscoveryServiceAPI" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:DiscoveryServiceAPI" elementFormDefault="qualified" attributeFormDefault="unqualified"> 
    66                        <!-- Request types --> 
    77                        <xs:element name="doFullTextSearch" type="tns:FullTextSearchType"/> 
     
    2828                                        <xs:element name="status" type="xs:boolean"/> 
    2929                                        <xs:element name="statusMessage" type="xs:string"/> 
    30                                         <xs:element name="document" type="xs:anyType"/> 
     30                                        <xs:element name="document" type="xs:string" minOccurs="0"/> 
    3131                                </xs:sequence> 
    3232                        </xs:complexType> 
     
    3535                                        <xs:element name="status" type="xs:boolean"/> 
    3636                                        <xs:element name="statusMessage" type="xs:string"/> 
    37                                         <xs:element name="resultId" type="xs:int"/> 
    38                                         <xs:element name="hits" type="xs:int"/> 
    39                                         <xs:element name="documents" type="tns:DocumentsType"/> 
     37                                        <xs:element name="resultId" type="xs:int" minOccurs="0"/> 
     38                                        <xs:element name="hits" type="xs:int" minOccurs="0"/> 
     39                                        <xs:element name="documents" type="tns:DocumentsType" minOccurs="0"/> 
    4040                                </xs:sequence> 
    4141                        </xs:complexType> 
     
    9898        <wsdl:service name="DiscoveryService"> 
    9999                <wsdl:port name="Discovery" binding="tns1:DiscoverySoapBinding"> 
    100                         <wsdlsoap:address location="http://sstdwmjp.neodc.rl.ac.uk:8080/axis2/services/DiscoveryService"/> 
     100                        <wsdlsoap:address location="http://sstdwmjp.neodc.rl.ac.uk:8080/axis2/services/DiscoveryService2"/> 
    101101                </wsdl:port> 
    102102        </wsdl:service> 
  • TI01-discovery/trunk/python/ws2/DiscoveryService_services.py

    r1563 r1574  
    1313# Locator 
    1414class DiscoveryServiceLocator: 
    15     Discovery_address = "http://sstdwmjp.neodc.rl.ac.uk:8080/axis2/services/DiscoveryService" 
     15    Discovery_address = "http://sstdwmjp.neodc.rl.ac.uk:8080/axis2/services/DiscoveryService2" 
    1616    def getDiscoveryAddress(self): 
    1717        return DiscoveryServiceLocator.Discovery_address 
     
    3737        # no output wsaction 
    3838        response = self.binding.Receive(doFullTextSearchResponse.typecode) 
     39        if isinstance(response, doFullTextSearchResponse.typecode.pyclass) is False: 
     40            raise TypeError, "%s incorrect response type" % (response.__class__) 
    3941        return response 
    4042 
     
    4850        # no output wsaction 
    4951        response = self.binding.Receive(doPresentResponse.typecode) 
     52        if isinstance(response, doPresentResponse.typecode.pyclass) is False: 
     53            raise TypeError, "%s incorrect response type" % (response.__class__) 
    5054        return response 
    5155 
  • TI01-discovery/trunk/python/ws2/DiscoveryService_services_types.py

    r1563 r1574  
    88import ZSI.TCcompound 
    99from ZSI.TC import ElementDeclaration,TypeDefinition 
    10 from ZSI.TC import _get_type_definition as GTD, _get_global_element_declaration as GED 
    1110from ZSI.generate.pyclass import pyclass_type 
    1211 
     
    2423        def __init__(self, pname, ofwhat=(), attributes=None, extend=False, restrict=False, **kw): 
    2524            ns = ns0.FullTextSearchType_Def.schema 
    26             TClist = [ZSI.TC.String(pname="term", aname="_term", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded")), ZSI.TCnumbers.Iint(pname="start", aname="_start", minOccurs=0, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded")), ZSI.TCnumbers.Iint(pname="howMany", aname="_howMany", minOccurs=0, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded")), GTD("urn:DiscoveryServiceAPI","orderByType",lazy=False)(pname="orderBy", aname="_orderBy", minOccurs=0, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded"))] 
     25            TClist = [ZSI.TC.String(pname=(ns,"term"), aname="_term", minOccurs=1, maxOccurs=1, nillable=False, encoded=kw.get("encoded")), ZSI.TCnumbers.Iint(pname=(ns,"start"), aname="_start", minOccurs=0, maxOccurs=1, nillable=False, encoded=kw.get("encoded")), ZSI.TCnumbers.Iint(pname=(ns,"howMany"), aname="_howMany", minOccurs=0, maxOccurs=1, nillable=False, encoded=kw.get("encoded")), ns0.orderByType_Def(pname=(ns,"orderBy"), aname="_orderBy", minOccurs=0, maxOccurs=1, nillable=False, encoded=kw.get("encoded"))] 
    2726            self.attribute_typecode_dict = attributes or {} 
    2827            if extend: TClist += ofwhat 
     
    4746        def __init__(self, pname, ofwhat=(), attributes=None, extend=False, restrict=False, **kw): 
    4847            ns = ns0.PresentType_Def.schema 
    49             TClist = [ZSI.TC.String(pname="document", aname="_document", minOccurs=0, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded"))] 
     48            TClist = [ZSI.TC.String(pname=(ns,"document"), aname="_document", minOccurs=0, maxOccurs=1, nillable=False, encoded=kw.get("encoded"))] 
    5049            self.attribute_typecode_dict = attributes or {} 
    5150            if extend: TClist += ofwhat 
     
    6766        def __init__(self, pname, ofwhat=(), attributes=None, extend=False, restrict=False, **kw): 
    6867            ns = ns0.PresentReturnType_Def.schema 
    69             TClist = [ZSI.TC.Boolean(pname="status", aname="_status", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded")), ZSI.TC.String(pname="statusMessage", aname="_statusMessage", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded")), ZSI.TC.AnyType(pname="document", aname="_document", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded"))] 
     68            TClist = [ZSI.TC.Boolean(pname=(ns,"status"), aname="_status", minOccurs=1, maxOccurs=1, nillable=False, encoded=kw.get("encoded")), ZSI.TC.String(pname=(ns,"statusMessage"), aname="_statusMessage", minOccurs=1, maxOccurs=1, nillable=False, encoded=kw.get("encoded")), ZSI.TC.String(pname=(ns,"document"), aname="_document", minOccurs=0, maxOccurs=1, nillable=False, encoded=kw.get("encoded"))] 
    7069            self.attribute_typecode_dict = attributes or {} 
    7170            if extend: TClist += ofwhat 
     
    8988        def __init__(self, pname, ofwhat=(), attributes=None, extend=False, restrict=False, **kw): 
    9089            ns = ns0.SearchReturnType_Def.schema 
    91             TClist = [ZSI.TC.Boolean(pname="status", aname="_status", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded")), ZSI.TC.String(pname="statusMessage", aname="_statusMessage", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded")), ZSI.TCnumbers.Iint(pname="resultId", aname="_resultId", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded")), ZSI.TCnumbers.Iint(pname="hits", aname="_hits", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded")), GTD("urn:DiscoveryServiceAPI","DocumentsType",lazy=False)(pname="documents", aname="_documents", minOccurs=1, maxOccurs=1, nillable=False, typed=False, encoded=kw.get("encoded"))] 
     90            TClist = [ZSI.TC.Boolean(pname=(ns,"status"), aname="_status", minOccurs=1, maxOccurs=1, nillable=False, encoded=kw.get("encoded")), ZSI.TC.String(pname=(ns,"statusMessage"), aname="_statusMessage", minOccurs=1, maxOccurs=1, nillable=False, encoded=kw.get("encoded")), ZSI.TCnumbers.Iint(pname=(ns,"resultId"), aname="_resultId", minOccurs=0, maxOccurs=1, nillable=False, encoded=kw.get("encoded")), ZSI.TCnumbers.Iint(pname=(ns,"hits"), aname="_hits", minOccurs=0, maxOccurs=1, nillable=False, encoded=kw.get("encoded")), ns0.DocumentsType_Def(pname=(ns,"documents"), aname="_documents", minOccurs=0, maxOccurs=1, nillable=False, encoded=kw.get("encoded"))] 
    9291            self.attribute_typecode_dict = attributes or {} 
    9392            if extend: TClist += ofwhat 
     
    113112        def __init__(self, pname, ofwhat=(), attributes=None, extend=False, restrict=False, **kw): 
    114113            ns = ns0.DocumentsType_Def.schema 
    115             TClist = [ZSI.TC.String(pname="document", aname="_document", minOccurs=1, maxOccurs="unbounded", nillable=False, typed=False, encoded=kw.get("encoded"))] 
     114            TClist = [ZSI.TC.String(pname=(ns,"document"), aname="_document", minOccurs=1, maxOccurs="unbounded", nillable=False, encoded=kw.get("encoded"))] 
    116115            self.attribute_typecode_dict = attributes or {} 
    117116            if extend: TClist += ofwhat 
  • TI01-discovery/trunk/python/ws2/test_discovery.py

    r1563 r1574  
     1# these imports are autogenerated by wsdl2py ... 
    12from DiscoveryService_services_types import * 
    23from DiscoveryService_services import * 
    34 
     5#normal imports 
     6import sys 
     7try: #python 2.5 
     8    import xml.etree.ElementTree as ET 
     9except: 
     10    import ElementTree as ET 
     11     
     12from ETxmlView import loadET,et2text 
    413 
    5 #get an instance of the discovery service 
    6 loc=DiscoveryServiceLocator() 
    7 service=loc.getDiscovery() 
     14class ndgSearch: 
     15    ''' Proivdes a client to the NDG discovery services methods exposed by the Discovery.wsdl ''' 
     16     
     17    def __init__(self): 
     18        '''get an instance of the service''' 
     19        #how do we get a different backend provider? 
     20        loc=DiscoveryServiceLocator() 
     21        self.server=loc.getDiscovery()#tracefile=sys.stdout) 
     22        self.documents=None 
     23        self.hits=None 
     24        self.serverSessionID=None 
     25     
     26    def search(self,term,start=1,howmany=30): 
     27        ''' Get a list of documents for a specific term using a free text search''' 
     28         
     29        #create a request object 
     30        request=doFullTextSearchRequest() 
     31        request._term=term 
     32        request._start=start 
     33        request._howmany=howmany 
     34         
     35        #do the search 
     36        response=self.server.doFullTextSearch(request) 
     37        if response._status: 
     38            self.serverSessionID=response._resultId 
     39            self.hits=response._hits 
     40            self.documents=response._documents._document 
     41        self.status=[response._statusMessage,] 
     42        return self.documents 
    843 
    9 #create a request object 
    10 request=doFullTextSearchRequest() 
    11 request._term='temperature' 
    12  
    13 response=service.doFullTextSearch(request) 
    14 print response._statusMessage 
    15 print response._resultId 
    16 print response._hits 
    17 for i in response._documents._document: print i 
    18  
    19  
     44    def getDoc(self,document): 
     45        ''' Return a document from the backend database ''' 
     46         
     47        #create a request object 
     48        request=doPresentRequest() 
     49        request._document=document 
     50        searchResult=self.server.doPresent(request) 
     51        if searchResult._status: 
     52            result=searchResult._document 
     53        else: 
     54            result=searchResult._statusMessage 
     55        return result 
     56                    
     57    def getAllDocs(self):             
     58        ''' Parse the list of documents, get them, and load them into a list of tuple strings (name,content) ''' 
     59        # we keep the name to make it easy to get the actual document out to avoid xpath issues ... 
     60         
     61        docs=[] 
     62        self.status=[] 
     63         
     64        #create a request object 
     65        request=doPresentRequest() 
     66        for doc in self.documents: 
     67            request._document=doc 
     68            result=self.server.doPresent(request) 
     69            if result._status: 
     70                docs.append((doc,result._document)) 
     71            else: 
     72                self.status.append((doc,result._statusMessage)) 
     73                 
     74        self.docs=docs 
     75        return self.docs 
     76             
     77             
     78    def __xmlerror(self,docmessage): 
     79        print docmessage 
     80        return ET.fromstring('<Error><Document>%s</Document><Message>%s</Message></Error>'%docmessage) 
     81             
     82    def getDocElement(self,document): 
     83        ''' Takes a document path (maybe from a previous call to ndgSearch) and extracts that document 
     84        into an ElementTree instance ''' 
     85        #we stick it straight into element tree because we need to use et to get the actual document 
     86        #we want, not the envelope xml elements  
     87         
     88        doc=self.getDoc(document) 
     89        path=document.rstrip('.xml') 
     90        try: 
     91            r=loadET(doc) 
     92            #return r.find(path) 
     93            return r 
     94        except: 
     95            return self.__xmlerror((path,doc)) 
     96             
     97    def getAllDocsAsElements(self): 
     98        ''' Get all the documents and load them into a list of ET instances ''' 
     99        result=[] 
     100        docs=self.getAllDocs() 
     101        for doc in docs:  
     102            try: 
     103                r=loadET(doc[1]) 
     104                path=doc[0].rstrip('.xml') 
     105                result.append(r)#result.append(r.find(path)) 
     106            except: 
     107                result.append(self.__xmlerror((path,doc[1]))) 
     108        return result 
     109             
     110if __name__=="__main__": 
     111     
     112    s=ndgSearch() 
     113    docs=s.search('temperature') 
     114    print s.status 
     115    for i in docs: print i 
     116     
     117    #docs=s.getAllDocs() 
     118    #print docs[0] 
     119    #print s.status 
     120     
     121    doc=s.documents[1] 
     122    r=s.getDocElement(doc) 
     123    print et2text(r) 
Note: See TracChangeset for help on using the changeset viewer.