Changeset 2655
- Timestamp:
- 27/06/07 22:18:24 (14 years ago)
- Location:
- TI05-delivery/ows_framework/trunk/ows_server/ows_server
- Files:
-
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
TI05-delivery/ows_framework/trunk/ows_server/ows_server/config/ndgDiscovery.config
r2654 r2655 28 28 mailserver: outbox.rl.ac.uk 29 29 metadataMaintainer: b.n.lawrence@rl.ac.uk 30 repository: glue.badc.rl.ac.uk30 repository: http://localhost:8080 31 31 32 32 33 33 [SEARCH] 34 advancedURL: %(ndgServer)s/discovery ?advanced=134 advancedURL: %(ndgServer)s/discovery 35 35 discoveryURL: %(ndgServer)s/discovery 36 36 helpURL: %(ndgServer)s/discovery?help=1 … … 74 74 #where repository is the NDG identifier .... 75 75 # 76 neodc.nerc.ac.uk: glue.badc.rl.ac.uk77 badc.nerc.ac.uk: glue.badc.rl.ac.uk76 neodc.nerc.ac.uk: %(server)s 77 badc.nerc.ac.uk: %(server)s 78 78 npm.ac.uk: wwwdev.npm.ac.uk/rsdas/projects/ndg 79 79 #grid.bodc.nerc.ac.uk: glue.badc.rl.ac.uk … … 84 84 icon_title: Links to a METADATA BROWSE view of this dataset 85 85 service_name: B 86 instance: http://SERVICEHOST/view/URI86 instance: SERVICEHOST/view/URI 87 87 88 88 [NDG_EXIST] … … 113 113 icon_alt: Catalogue 114 114 service_name: Catalogue 115 default: %(server)s /retrieve?repository=ndg115 default: %(server)s 116 116 formatDefault=DIF 117 117 icon_title: Links to the DISCOVERY RECORD for this dataset -
TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/discovery.py
r2626 r2655 1 1 from ows_server.lib.base import * 2 from paste.request import parse_querystring 3 from ows_server.lib.Date import * 4 from ows_server.templates import DiscoveryTemplate 5 from ows_server.models import ndgSearch as NS 6 from ows_server.models.DIF import DIF 7 from ows_server.templates.renderDiscoverySet import renderDiscoverySet 8 from ows_server.models.DiscoveryState import DiscoveryState 9 from ows_server.models.ndgObject import ndgObject 10 from ows_server.models.Utilities import myConfig 11 from ows_server.lib.mailer import mailHandler 12 13 # Note that this code has not been ported to kid yet, it's pretty much the old 14 # code ported into this environment ... 2 15 3 16 class DiscoveryController(BaseController): 4 17 ''' Provides the pylons controller for NDG discovery ''' 18 19 def __setup(self): 20 ''' Common setup for controller methods ''' 21 self.cf=request.environ['ndgConfig'] 22 self.inputs=dict(parse_querystring(request.environ)) 23 self.message='' 24 5 25 def index(self): 26 27 self.__setup() 6 28 # parse the query string and hand off to a discovery engine 7 c.query='' 8 c.hits='' 9 c.time='' 10 c.scope='' 11 c.start='' 12 c.end='' 13 c.stride'' 14 c.links=[] 29 if self.inputs=={}: return self.__advancedPrompt() 30 31 #the following need to be defined 32 continuations={'start':1,'howmany':10} 33 for i in continuations: 34 if i not in self.inputs: self.inputs[i]=continuations[i] 35 36 37 # the simplest query we might get is a text search, in which case 38 # the inputs should be start, howmany and searchString (although 39 # maybe not in that order. The next simplest is one with 40 # a specified textTarget, after that we need all the inputs. 41 42 if len(self.inputs)==3 and 'searchString' in self.inputs: 43 # it's a simple text search 44 self.inputs['textTarget']='All' 45 46 # the next simplest is one that includes texttarget as well ... 47 expected=['searchString','textTarget','start','howmany'] 48 self.__checkform(expected) 49 50 if self.message!='': 51 c.xml=self.message 52 return render_response('content') 53 54 if len(self.inputs)==4: 55 response=self.doText(self.inputs['searchString'],self.inputs['textTarget'], 56 self.inputs['start'],self.inputs['howmany']) 57 else: 58 #check advanced search options 59 expected=['startDateDay','startDateMon','startDateYear', 60 'endDateDay','endDateMon','endDateYear', 61 'bboxN','bboxE','bboxS','bboxW','searchString','textTarget'] 62 self.__checkform(expected) 63 if self.message!='': 64 c.xml=self.message 65 return render_response('content') 66 67 # ------------- Handle scope from radio button on form ------- 68 if 'source' in self.inputs: 69 # the WSDL expects a list, we're just providing one ... via a radio ... 70 scope=[self.inputs['source']] 71 if scope==['All']: scope=None 72 else: 73 scope=None 74 75 # ------------- Handle Location Bounding -------- 76 # default form has a global bounding box 77 bbox=[self.inputs['bboxN'],self.inputs['bboxS'],self.inputs['bboxW'],self.inputs['bboxE']] 78 self.__checkbox(bbox) 79 if self.message!='': 80 c.xml=self.message 81 return render_response('content') 82 83 # ------------- Handle Date Ranges --------------- 84 try: 85 dateRange=[(self.inputs['startDateDay'],iMonth(self.inputs['startDateMon']),self.inputs['startDateYear']), 86 (self.inputs['endDateDay'],iMonth(self.inputs['endDateMon']),self.inputs['endDateYear'])] 87 #default form has blanks, in which case we don't want to check for date range 88 if dateRange<>[("","",""),("","","")]: 89 self.__checkdates(dateRange) 90 else: dateRange=None 91 except: 92 self.message='Invalid date provided' 93 if self.message!='': 94 c.xml=self.message 95 return render_response('content') 96 97 # ------------- ok, now go do the search ----------- 98 response=self.doText(self.inputs['searchString'],self.inputs['textTarget'], 99 self.inputs['start'],self.inputs['howmany'],scope=scope,dateRange=dateRange,bbox=bbox) 100 101 return response 102 103 def doText(self,searchString,textTarget,start,howmany,scope=None,dateRange=None,bbox=None): 104 105 ''' Carry out a text search for <searchString> 106 in the <textTarget> where the accepted text target values are controlled 107 by the DiscoveryTemplate GUI, and are: All, Authors, Parameters ''' 108 109 start,howmany=int(start),int(howmany) # url arguments need conversion ... 110 111 ws=NS.ndgSearch(logger=logger) 112 documents=ws.search(searchString,start=start,howmany=howmany,target=textTarget, 113 scope=scope,dateRange=dateRange,bbox=bbox) 114 if ws.error !=None: 115 m='' 116 for i in ws.error:m+='<p>%s</p>'%i 117 c.xml=m 118 return render_response('content') 119 120 #build constraints info for report 121 constraints=self.__buildconstraints(dateRange,bbox,scope) 122 123 hits=ws.hits 124 id=ws.serverSessionID 125 126 if hits<howmany:howmany=hits 127 state=DiscoveryState(id,searchString,request.environ,hits,constraints,start,howmany) 128 129 if hits==0: 130 c.xml='<p>No records found [%s]</p>>'%state.constraints 131 return render_response('content') 15 132 16 c.repository='' 17 c.title='' 18 c.summary='' 19 c.morelink='' 20 c.spatial=[,,,] 21 c.temporal=[,] 22 23 return Response('not yet implemented') 133 try: 134 results=ws.getLabelledDocs(format='DIF') 135 difs=[] 136 errors=[] 137 for result in results: 138 obj=ndgObject(result[0]) 139 obj.setConfig(self.cf) 140 try: 141 difs.append(DIF(result[1],ndgObj=obj)) 142 except ValueError,e: 143 errors.append((result[0],str(e))) 144 if results==[]: 145 c.xml='<p> No results for "%s"!</p>'%searchString 146 return render_response('content') 147 elif difs==[]: 148 c.xml='<p>No usable results for "%s"!</p>'%searchString 149 return render_response('content') 150 else: 151 if errors<>[]: 152 c.xml='<p>Search results for "%s"'%searchString 153 dp=[] 154 for e in errors: 155 n=ndgObject(e[0]) 156 if n.repository not in dp: dp.append(n.repository) 157 if len(dp)<>1: 158 dp='[Various Data Providers]' 159 else: 160 dp='[%s]'%dp[0] 161 c.xml+=' (unfortunately %s hits matched unformattable documents from %s, an internal error has been logged):</p>'%(len(errors),dp) 162 status,message=mailHandler(['b.n.lawrence@rl.ac.uk'],'DIF errors',str(errors), 163 server=self.cf.get('DEFAULT',mailsever)) 164 if not status: 165 c.xml+='<p> Actually, not even an internal error has been logged. <br/>' 166 c.xml+='Internal sending of mail failed with error [%s]</p>'%message 167 return render_response('content') 168 c.xml='<div>%s%s</div>'%(self.oneLineSearch(),renderDiscoverySet(difs,state,self.cf)) 169 print self.oneLineSearch() 170 f=file('debug-dif.xml','w') 171 f.write(c.xml) 172 f.close() 173 return render_response('content') 174 except ValueError,e: 175 if debug: 176 raise ValueError,str(e) 177 else: 178 c.xml='<p> Error retrieving documents for %s hits is [%s]</p>'%(hits,e) 179 return render_response('content') 180 181 return 182 def __advancedPrompt(self): 183 ''' This provides the advanced search input page ''' 184 try: 185 discoveryURL=self.cf.get('SEARCH','discoveryURL') 186 advancedURL=self.cf.get('SEARCH','advancedURL') 187 oneLiner=DiscoveryTemplate.oneLiner 188 except: 189 return 'Error, invalid configuration for search interface' 190 bboxN,bboxW,bboxE,bboxS='+90.0','-180.0','+180.0','-90.0' 191 startDateDay,startDateMon,startDateYear='','','' 192 endDateDay,endDateMon,endDateYear='','','' 193 c.xml=DiscoveryTemplate.revisedAdvancedSearch%locals() 194 return render_response('content') 195 196 def __checkbox(self,bbox): 197 if float(bbox[0])>90.0 or float(bbox[1])<-90. or float(bbox[2])<-180. or float(bbox[3])>180.: 198 self.message='Invalid bounding box dimensions entered (limits 90,-90,-180,180)' 199 200 def __checkform(self,expected): 201 ''' Simply checks the inputs to make sure the elements in expected are present ''' 202 message="An incomplete NDG search form was received: " 203 for i in expected: 204 if i not in self.inputs: 205 self.message=message+i 206 self.html='<p>%s</p>'%self.message 207 208 def __checkdates(self,dateRange): 209 ''' Check input dates for sanity ''' 210 if not ValidDate(dateRange[0])*ValidDate(dateRange[1]): 211 self.message='Input dates are not valid' 212 elif JulDay(dateRange[0])>=JulDay(dateRange[1]): 213 self.message='Second date must be after first date' 214 215 def __buildconstraints(self,dateRange,bbox,scope): 216 ''' Just build a constraint string ''' 217 constraints=' (' 218 if dateRange is not None: 219 constraints+='Including %s to %s; '%('%s,%s,%s'%dateRange[0],'%s,%s,%s'%dateRange[1]) 220 if bbox is None or bbox==['+90.0','-90.0','-180.0','+180.0']: 221 constraints+='Global; ' 222 else: constraints+='Bounding Box: %s,%s,%s,%s; '%tuple(bbox) 223 if scope is not None: 224 constraints+='Restricted to %s; '%scope[0] 225 constraints=constraints[:-2]+')' 226 logger.info(constraints) 227 return constraints 228 229 def oneLineSearch(self): 230 try: 231 discoveryURL=self.cf.get('SEARCH','discoveryURL') 232 oneLiner=DiscoveryTemplate.oneLiner 233 except: 234 return 'Error, invalid configuration for search interface' 235 return DiscoveryTemplate.searchTextOneLine%locals() -
TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/retrieve.py
r2654 r2655 3 3 from ows_server.models import ndgObject, ndgRetrieve, Utilities 4 4 from paste.request import parse_querystring 5 from ows_server.models import stubB 5 from ows_server.models import stubB,DIF 6 6 from ows_server.lib import mailer 7 7 … … 74 74 elif self.uri.schema=='DIF': 75 75 r='dif' 76 c.doc=DIF.DIF(x.tree,et=1) 77 name=c.doc.name 78 print c.doc.parameters 76 79 elif self.uri.schema=='NumSim': 77 80 r='numsim' … … 97 100 r='content' 98 101 99 if 'ndgSec' in session:102 if status and 'ndgSec' in session: 100 103 #we can update the history 101 104 if 'history' not in session: -
TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/ndg/DiscoveryTemplate.py
r2615 r2655 149 149 </div>''' 150 150 151 oneLiner='''<input type="text" size="60" name="searchString"/> <input type="hidden" value="0" name="advanced"/>151 oneLiner='''<input type="text" size="60" name="searchString"/> 152 152 (Target: <select name="textTarget"> 153 153 <option value="Authors">Authors</option> … … 213 213 <tr><td align="center"><input type="submit"/></td></tr> 214 214 </tbody></table> 215 <input type="hidden" value="1" name="advanced"/>216 215 </form> 217 216 </div>''' -
TI05-delivery/ows_framework/trunk/ows_server/ows_server/models/ndgObject.py
r2654 r2655 58 58 # This NDG object may itself be a discovery record, which makes life easy, but 59 59 # it might not be, in which case we have to build up all the possible views upon it. 60 discoveryBASE='%s &uri=%s__%s__%s'%(60 discoveryBASE='%s/view/%s__%s__%s'%( 61 61 self.config.get('DISCOVERY','default'),self.repository,self.schema,self.localID) 62 62 fmt=self.config.get('DISCOVERY','formatDefault','DIF') 63 63 # We'll build the following even if it can't be used (as would be the case for 64 64 # a non data entity B record or an A record) because it's a useful template. 65 self.discoveryURL=discoveryBASE +'&format=%s&type=html'%fmt65 self.discoveryURL=discoveryBASE 66 66 # If this record is itself a discovery record, then we don't have much more to do 67 67 if self.schema in ['DIF','DC','MDIP','ISO19139']: 68 self.xmlURL=self.discoveryURL .replace('html','xml')69 self.printableURL=self.discoveryURL .replace('html','print')68 self.xmlURL=self.discoveryURL+'&format=raw' 69 self.printableURL=self.discoveryURL+'&format=xml' 70 70 self.gettable=1 71 71 self.URL=self.discoveryURL -
TI05-delivery/ows_framework/trunk/ows_server/ows_server/models/ndgRetrieve.py
r2654 r2655 4 4 from ndgSecurity import HandleSecurity 5 5 6 debug= 16 debug=0 7 7 def ndgRetrieve(uri,config,logger=0,requestor='test',format='',securityTokens=None): 8 8 … … 55 55 f=str('ows_server/examples/%s.xml'%uri.uri) 56 56 r=file(f,'r').read() 57 58 57 else: 58 r=ws.get(uri.repository,uri.schema,uri.localID,format=format,targetCollection=target) 59 59 time2=time.time()-time1 60 60 logString='Document retrieve [%s] for [%s] took [%ss]'%(uri,requestor,time2) … … 123 123 self.setup() 124 124 doc='badc.nerc.ac.uk__NDG-B0__activity_activity_cwvc' 125 doc='neodc.nerc.ac.uk__NDG-B1__NEODC_NCAVEO_LCM2000' 125 126 uri=ndgObject.ndgObject(doc) 126 127 status,xml=ndgRetrieve(uri,self.c) … … 165 166 self.assertEqual(status,0) 166 167 168 167 169 if __name__=="__main__": 170 168 171 unittest.main() -
TI05-delivery/ows_framework/trunk/ows_server/ows_server/templates/dif.kid
r2643 r2655 12 12 ?> 13 13 <div id="${id}"> 14 <p>DIF viewing not fully implemented</p><hr/> 14 <div class="metadata"> 15 <div class="headingblock"> 16 <div id="title" class="heading">$c.doc.name</div> 17 <div id="abstract">$c.doc.abstract</div> 18 </div> 19 <div py:replace="ParameterList(c.doc.parameters)"/> 20 </div> 15 21 </div> 22 <center> 23 <p>Not all information in this record may be rendered in this view. Please see the XML version for complete 24 content </p> 25 </center> 16 26 <div py:replace="footer()"/> 17 27 </div> -
TI05-delivery/ows_framework/trunk/ows_server/ows_server/templates/ndgPage.kid
r2654 r2655 61 61 </div> 62 62 63 <!-- Parameter list class, used in StubB and DIF --> 64 65 <div py:def="ParameterList(params)" class="ParameterList"> 66 <table cellspacing="0" cellpadding="3" border="0" width="100%"><tbody> 67 <tr><td class="linehead"><span class="heading0"> Parameters</span></td></tr> 68 <span py:for="item in params"> 69 <tr><td class="rowhead">$item</td></tr> 70 <?python 71 #need to make sure keyword with spaces are not split inappropriately 72 keywords=[] 73 for word in params[item]: 74 keywords.append(word.replace(' ',' ')) 75 keywords='; '.join(keywords) 76 ?> 77 <tr py:if="params[item]!=[]"><td>$keywords</td></tr> 78 </span> 79 </tbody></table> 80 </div> 81 82 63 83 <!-- Page Footer follows --> 64 84 -
TI05-delivery/ows_framework/trunk/ows_server/ows_server/templates/stubB.kid
r2654 r2655 32 32 </div> 33 33 34 <div class="ParameterList"> 35 <table cellspacing="0" cellpadding="3" border="0" width="100%"><tbody> 36 <tr><td class="linehead"><span class="heading0"> Parameters</span></td></tr> 37 <span py:for="item in c.doc.parameters"> 38 <tr><td class="rowhead">$item</td></tr> 39 <?python 40 #need to make sure keyword with spaces are not split inappropriately 41 keywords=[] 42 for word in c.doc.parameters[item]: 43 keywords.append(word.replace(' ',' ')) 44 keywords='; '.join(keywords) 45 ?> 46 <tr py:if="c.doc.parameters[item]!=[]"><td>$keywords</td></tr> 47 </span> 48 </tbody></table> 49 </div> 34 <div py:replace="ParameterList(c.doc.parameters)"/> 50 35 51 36 <div py:if="c.doc.granules!=[]" id="Granules">
Note: See TracChangeset
for help on using the changeset viewer.