Changeset 1150


Ignore:
Timestamp:
09/06/06 21:30:36 (13 years ago)
Author:
lawrence
Message:

A step on the way to refactoring the servicebinding to
allow flexible icons, and configurable binding between
service descriptions in metadata and actual service
implementations ...

Location:
TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/ServiceBinding.py

    r938 r1150  
     1# 
     2# There are (at least) two classes of service map issues which NDG needs to support. 
     3# Firstly, one can expect that given a specific NDG record, there is a native 
     4# service for that record ... eg. for an A record, the native service is the  
     5# data extractor, but there may be others ... at some point we need to be 
     6# able to find those out (this is a processing affordance issue, and something 
     7# that we want to use registries for) ... anyway, meanwhile, we have these "native" 
     8# service types. 
     9# Secondly, in D  we have related URL's, which are essentially mappings to  
     10# services which may exist on the dataset described by that D-catalogue record. 
     11# This is a special case of the generic case described above ... 
     12# 
     13# This module provides classes to support these activities. 
     14 
     15from Utilities import wrapGetText, myConfig 
     16from htmlUtilities import hyperlink,image 
     17 
     18class ServiceMap(myConfig): 
     19    ''' This should itself eventually be a service that can be looked up, or maybe 
     20    even use the dns ''' 
     21    def __init__(self,serviceFile='cgi/serviceMap.config'): 
     22        myConfig.__init__(self,serviceFile) 
     23        self.icon,self.iconalt=None,'NoIcon' 
     24    def do(self,serviceType,dataProvider): 
     25        '''  Return an actual endpoint for a given service from the data provider, e.g. 
     26        for ndg_a_service,badc.nerc.ac.uk get http://superglue.badc.rl.ac.uk/cgi-bin/browse.py ''' 
     27        r=self.get(serviceType,dataProvider) 
     28        if r is None: 
     29            # we assume this isn't an NDG service and just return the URL 
     30            if dataProvider[0:4]!='http': 
     31                return 'http://%s'%dataProvider 
     32            else: return dataProvider 
     33        else: 
     34            # this is a service type known to ndg, so we have constructed an endpoint 
     35            self.icon=self.get(serviceType,'icon') 
     36            print 'Icon',self.icon 
     37            self.iconalt=self.get(serviceType,'icon_alt') 
     38            return r 
     39         
    140class Service: 
     41    ''' This simple class simply holds the service information known in a DIF '''  
    242    def __init__(self): 
     43        self.type='dif_related_url' 
    344        self.name='' 
    445        self.url='' 
     
    647 
    748class ServiceBinding (Service): 
    8         ''' Handles all service binding issues ''' 
    9         #very temporary code 
    10         def __init__(self,s,e,n='URL'): 
    11                 Service.__init__(self) 
    12                 if s=='A': 
    13                         service='ANotYetConfigured' 
    14                         host='' 
    15                 elif s=='B': 
    16                         service='cgi/browse.py' 
    17                         host='' #bodge 
    18                 else: 
    19                         service='ServiceNotKnown' 
    20                         host='' 
    21                 try: 
    22                         repID=e.find('repositoryIdentifier').text 
    23                         localID=e.find('localIdentifier').text 
    24                         self.url='%s/%s?uri=%s/%s'%(host,service,repID,localID) 
    25                 except: 
    26                         self.url='No link' 
    27                 self.name=n 
     49        ''' Given a specific NDG id, we can go from the scheme identifier to the  
     50        native service which one expects to be able to operate upon it, for example, 
     51        an NDG-A type identifier should expect the NDG-A-Service running at the 
     52        specific repository ''' 
     53        def __init__(self,n='',nativeID=None): 
     54            Service.__init__(self) 
     55            # regrettably we used different things in our ID's than we did in 
     56            # our difs : 
     57            self.mapping={'NDG-A0':'NDG_A_Service','NDG-B0':'NDG_B_Service'} 
     58            self.serviceMap=ServiceMap() 
     59            self.name=n 
     60            if nativeID is not None: self.native(nativeID)  
     61        def native(self,elem): 
     62            ''' Given an ndg id, get the native service ''' 
     63            #e.g. 
     64            #<dataModelID> 
     65            #    <schemeIdentifier>NDG-A0</schemeIdentifier> 
     66            #    <repositoryIdentifier>badc.nerc.ac.uk</repositoryIdentifier> 
     67            #    <localIdentifier>acsoe_badc_eae96_macehead_mcf_1</localIdentifier> 
     68            #</dataModelID> 
     69            if elem is None:return 'No valid URL' 
     70            s=wrapGetText(elem,'schemeIdentifier') 
     71            r=wrapGetText(elem,'repositoryIdentifier') 
     72            l=wrapGetText(elem,'localIdentifier') 
     73            if s in self.mapping: s=self.mapping[s] 
     74            b=self.serviceMap.do(s,r) 
     75            self.url='%s?uri=%s'%(b,l) 
     76            return self 
     77        def related(self,elem,idelem): 
     78            ''' Given a DIF related URL, get a service binding ''' 
     79            # e.g: 
     80            #<Related_URL> 
     81            #<URL_Content_Type>NDG_B_Service</URL_Content_Type> 
     82            #<URL>badc.nerc.ac.uk</URL> 
     83            #</Related_URL> 
     84            #<Related_URL> 
     85            #<URL>http://badc.nerc.ac.uk/browse/badc/CDs/spade9293</URL> 
     86            #</Related_URL> 
     87            self.description=wrapGetText(elem,'Description') 
     88            ctype=wrapGetText(elem,'URL_Content_Type') 
     89            if ctype!='': 
     90                b=self.serviceMap.do(ctype,wrapGetText(elem,'URL')) 
     91                l=wrapGetText(idelem,'localIdentifier') 
     92                self.url='%s?uri=%s'%(b,l) 
     93            else: 
     94                self.url=wrapGetText(elem,'URL') 
     95            return self 
     96        def __str__(self): 
     97            ''' return string only html link ''' 
     98            return hyperlink(self.name,self.url) 
     99        def icon(self): 
     100            ''' return icon html link ''' 
     101            return hyperlink(image(self.serviceMap.icon,self.serviceMap.iconalt),self.url) 
    28102                 
    29103if __name__=="__main__": 
     
    34108                <localIdentifier>acsoe_badc_eae96_macehead_mcf_1</localIdentifier> 
    35109            </dataModelID>''' 
    36         e=ET.fromstring(s) 
    37         print e.tag 
    38         binding=ServiceBinding('A',e) 
    39         print binding.url 
     110        idelem=ET.fromstring(s) 
     111        n=ServiceBinding('macehead',nativeID=idelem) 
     112        maceheadServices=[n] 
     113        s='''<dummy><Related_URL> 
     114        <URL_Content_Type>NDG_B_Service</URL_Content_Type> 
     115        <URL>badc.nerc.ac.uk</URL> 
     116        </Related_URL> 
     117        <Related_URL> 
     118        <URL>http://badc.nerc.ac.uk/browse/badc/CDs/spade9293</URL> 
     119        </Related_URL> 
     120        <Related_URL> 
     121        <URL_Content_Type>NDG_A_Service</URL_Content_Type> 
     122        <URL>glue.badc.rl.ac.uk/somelongpath</URL> 
     123        <Description> dummy dx example </Description> 
     124        </Related_URL></dummy> 
     125        ''' 
     126        stuff=ET.fromstring(s) 
     127        for x in stuff.findall('Related_URL'): 
     128            n=ServiceBinding('macehead') 
     129            maceheadServices.append(n.related(x,idelem)) 
     130        for i in maceheadServices:  
     131            print str(i) 
     132            print i.icon() 
  • TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/Utilities.py

    r1140 r1150  
    2424        def log(self,string): 
    2525            ''' Log some debug information ''' 
     26            if self.logfile is None: return 
    2627            if string is not None: 
    2728                self.logfile.write('%s\n'%string) 
  • TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/browseCGI.py

    r1143 r1150  
    124124                self.request=Request(self.env) 
    125125                self.requestURL=self.request.URL 
    126                 self.selector=selector(self.requestURL,config.get('layout','selectI')) 
     126                self.selector=selector(self.requestURL,'select',config.get('layout','selectI')) 
    127127                 
    128128 
  • TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/htmlUtilities.py

    r1103 r1150  
    44class selector: 
    55    ''' Provides a selection icon to add a dataset to a selector box ''' 
    6     def __init__(self,baseURL,icon): 
     6    def __init__(self,baseURL,arg,icon): 
    77        self.baseURL=baseURL 
     8        self.argument=arg 
    89        self.icon=icon 
    910    def target(self,id): 
    10         url='%s&select=%s'%(self.baseURL,id) 
    11         return hyperlink(image(self.icon,'select'),url) 
     11        url='%s&%s=%s'%(self.baseURL,self.argument,id) 
     12        return hyperlink(image(self.icon,self.argument),url) 
    1213 
    1314def span(x,id): 
  • TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/stubB.py

    r976 r1150  
    1818                self.elem=elem 
    1919                self.constraints=AccessControl(elem.find('accessControlPolicy')) 
    20                 self.binding=ServiceBinding('A',elem.find('dataModelID')) 
     20                self.binding=ServiceBinding('granule',nativeID=elem.find('dataModelID')) 
    2121                self.Aurl=self.binding.url 
    2222                 
     
    146146                                        for subitem in subitems: 
    147147                                                name=wrapGetText(subitem,'name') 
    148                                                 binding=ServiceBinding('B',subitem.find('dgMetadataID')) 
     148                                                binding=ServiceBinding(name,nativeID=subitem.find('dgMetadataID')) 
    149149                                                aa.append([name,binding.url]) 
    150150                                        deployment[1].append([self.labels[item],aa]) 
Note: See TracChangeset for help on using the changeset viewer.