Changeset 8466 for mauRepo/HPFos
- Timestamp:
- 12/07/12 16:03:48 (9 years ago)
- Location:
- mauRepo/HPFos/trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
mauRepo/HPFos/trunk/resources/requirements.txt
r8450 r8466 7 7 # --extra-index-url http://ciprod1.cems.rl.ac.uk/pip 8 8 # to your pip install 9 ceda-markup==0.0. 410 ceda-moles-model==0.1. 49 ceda-markup==0.0.6 10 ceda-moles-model==0.1.5 11 11 12 12 #This package should be available in the machine where CedaManager will be deployed -
mauRepo/HPFos/trunk/src/HPFos/moles3epb.py
r8431 r8466 41 41 from sqlalchemy import Table, Column, ForeignKey, Integer, String 42 42 from sqlalchemy.orm import mapper 43 from ea_model.moles3_4.utilities.mo_responsiblepartyinfo import MO_ResponsiblePartyInfo44 from sqlalchemy.orm.collections import InstrumentedList45 43 from ceda_guid import CedaGUID 46 44 from sqlalchemy.orm.util import identity_key … … 115 113 if isinstance(class_type, type(CEDA_ObservationCollection)) or isinstance(class_type, type(CEDA_Observation)): 116 114 return self._session.query(class_type).all() 117 return None 118 119 def getUnifyObservationCollectionGE(self, collection): 120 """ 121 Returns the union of the collections.member'a GeographicExtension(s) 122 @param collection: an CEDA_ObservationColleciton instance 123 """ 124 bboxes = [] 125 for member in collection.member: 126 for ge in member.geographicExtent: 127 bboxes.append(self.getGeograpicExtentGeometry(ge)) 128 129 return unifyGeometries(bboxes, self) 115 return None 130 116 131 117 def getObservationCollections(self, bbox = None): … … 136 122 """ 137 123 138 collections = self._session.query(CEDA_ObservationCollection) .all()124 collections = self._session.query(CEDA_ObservationCollection) 139 125 if bbox == None: 140 return collections 126 return collections.all() 141 127 142 128 res = [] 143 129 for collection in collections: 144 collection_geometry = self.getUnifyObservationCollectionGE(collection) 145 if collection_geometry and intersectGeometries([collection_geometry, bbox], self): 146 res.append(collection) 130 if len(collection.geographicExtent) > 0: 131 collection_geometry = getGeograpicExtentGeometry(collection.geographicExtent[0]) 132 if collection_geometry is not None \ 133 and intersectGeometries([collection_geometry, bbox], self): 134 res.append(self.searchSelectiveLoad(CEDA_ObservationCollection, \ 135 collection.id, ['geographicExtent.*'])) 147 136 return res 148 149 def searchEager(self, clazz, inst_id): 150 return EPB.searchEager(clazz, inst_id, self._session) 151 152 def persistInstance(self, instance): 153 """ 154 Adds a new migration object. 155 @param migrationObj: the migration object to add 156 @param session: an SQLAlchemy Session object. If not None the session IS NOT closed at the exit, 157 If None (default) a new Session is created from the underlying EPB and closed at the exit. 158 @return an updated, session independent, object instance reflecting the new persisted object 159 """ 160 EPB.persistInstance(instance, self._session) 161 162 163 def updateCedaObject(self, ceda_object, cols_to_update): 164 """ 165 Update and eventually commit a CEDA Object in MOLES3 db. 166 NOTE: only the returned instance will reflect the update! 167 @param ceda_object: the CEDA object to persist 168 @param dict: a dictionary containing the columns to update for the given ceda_object 169 @param session: the external session to use. If None a new session will be open to add and commit the object and then closed at the exit. The object is committed 170 @return: the given instance with the updated attributes. 171 """ 172 coll = None 173 try: 174 coll = self._session.merge(ceda_object) 175 except Exception as e: 176 print e 177 if coll != None: 178 for k,v in cols_to_update.items(): 179 if hasattr(coll, k): 180 val = None 181 try: 182 val = self._session.merge(v) 183 except Exception: 184 val = v 185 coll_k = getattr(coll, k) 186 if type(coll_k) == list or type(coll_k) == InstrumentedList: 187 if type(val) == list or type(val) == InstrumentedList: 188 coll_k.extend(val) 189 else: 190 if val in coll_k: 191 break 192 coll_k.append(val) 193 else: 194 setattr(coll, k, val) 195 EPB.persistInstance(coll, self._session) 137 138 def retrieveGUIDFromInstance(self, instance): 139 """ 140 Returns the CedaGUID object associated with the given instance. 141 @param instance: an instance of CEDA_Observation os CEDA_ObservationCollection 142 """ 143 if instance is None: 144 return None 145 if type(instance) == CEDA_ObservationCollection: 146 return self._session.query(CedaGUID).filter(CedaGUID.ceda_observationcollection==instance.id).first() 147 elif type(instance) == CEDA_Observation: 148 return self._session.query(CedaGUID).filter(CedaGUID.ceda_observation==instance.id).first() 196 149 197 150 def getInstanceFromGUID(self, guid): … … 208 161 return self.search(CEDA_ObservationCollection, ceda_guid.ceda_observationcollection) 209 162 return None 210 211 def retrieveGUIDFromInstance(self, instance): 212 """ 213 Returns the CedaGUID object associated with the given instance. 214 @param instance: an instance of CEDA_Observation os CEDA_ObservationCollection 215 """ 216 if instance is None: 217 return None 218 if type(instance) == CEDA_ObservationCollection: 219 return self._session.query(CedaGUID).filter(CedaGUID.ceda_observationcollection==instance.id).first() 220 elif type(instance) == CEDA_Observation: 221 return self._session.query(CedaGUID).filter(CedaGUID.ceda_observation==instance.id).first() 163 222 164 223 165 def getObservationFromObservationCollection(self, obs_coll_id): … … 228 170 """ 229 171 return self._session.query(CEDA_ObservationCollection, CEDA_Observation).filter(CEDA_ObservationCollection.id==obs_coll_id).all() 230 231 172 232 173 def extractObservationByTitleKeywords(self, keywords): … … 247 188 q = q.params(terms=keywords) 248 189 return q 249 250 251 def extractCollectionIdentifierByTitle(self, i_title):252 """253 Searches for an MD_Identifier from a CEDA_ObservationCollection contains a specific title (observation.identifier.code)254 @param i_title: the CEDA_ObservationCollection.identifier.title value to search for255 @return: a tuple containing a CEDA_ObservationCollection and the CEDA_ObservationCollection.idenfitier element having the title256 """257 return self._session.query(CEDA_ObservationCollection, MD_Identifier). \258 join(MO_ObservationCollection).join(MO_ObservationCollection.identifier). \259 join(MD_Identifier.authority).filter(CI_Citation.title.like('%' + i_title + '%'))260 261 def extractObservationsForProject(self, project):262 """263 Searches for the CEDA_Observation associated with a CEDA_Project264 @param project: a CEDA_Project instance265 @return: a tuple containing the associated CEDA_Observation266 """267 return self._session.query(CEDA_Observation). \268 join(CEDA_Observation, MO_Observation.inSupportOf).filter(CEDA_Project.id == project.id)269 270 def extractProjectObservationCollections(self, project):271 """272 Searches for the Observation_Collections associated with a CEDA_Project273 @param project: a CEDA_Project instance274 @return: a tuple containing the associated CEDA_ObservationCollection275 """276 mo_obs = self._session.query(MO_Observation).join(CEDA_Project).filter(CEDA_Project.id == project.id).subquery()277 obsers = self._session.query(CEDA_Observation).join(mo_obs, CEDA_Observation.id == mo_obs.c.id).one()278 #print "obsers: " + str(intSession.query(CEDA_Observation).join(mo_obs, CEDA_Observation.id == mo_obs.c.id).count())279 280 cos = self._session.query(CEDA_ObservationCollection).all()281 co = self._session.query(MO_ObservationCollection).join(MO_ObservationCollection.member).filter(MO_ObservationCollection.member.contains(obsers))282 283 observations = self._session.query(MO_ObservationCollection).join(CEDA_Observation). \284 filter(obsers.any(CEDA_Observation.id==obsers.c.id))285 print "observation:" + str(observations.count())286 return observations287 190 288 191 def search(self, clazz, inst_key): … … 360 263 return EPB.executeNative(sqlNative, self._session) 361 264 362 def getGeograpicExtentGeometry( self,ge):265 def getGeograpicExtentGeometry(ge): 363 266 ''' 364 267 Creates the appropriate postgis geometry from a EX_GeographicExtent -
mauRepo/HPFos/trunk/src/HPFos/osImpl/hpfos_conf.py
r8383 r8466 32 32 ''' 33 33 from myimpl import MyOSQuery, MyOSAtomResponse 34 from ceda_markup.opensearch.os_request import OpenSearch Request34 from ceda_markup.opensearch.os_request import OpenSearchDescription 35 35 from ceda_markup.opensearch.os_engine import OSEngine 36 36 37 37 def setUp(): 38 38 query = MyOSQuery() 39 #htmlResponse = MyOSHTMLResponse()40 39 atomResponse = MyOSAtomResponse() 41 40 os_short_name = "Web Search" 42 41 os_description = "A default description" 43 os = OpenSearch Request(query, [atomResponse],os_short_name, os_description)44 return OSEngine( os)42 os = OpenSearchDescription(os_short_name, os_description) 43 return OSEngine(query, [atomResponse], os) -
mauRepo/HPFos/trunk/src/HPFos/osImpl/myimpl.py
r8450 r8466 31 31 @author: Maurizio Nagni 32 32 ''' 33 from xml.etree.ElementTree import tostring, ElementTree34 33 from xml.dom import minidom 35 34 from datetime import datetime 36 35 from libs.postgisutil import create_st_setSRID 37 #from ceda_markup.atom.atom import Atom 38 from ceda_markup.opensearch.os_response import OpenSearchResponse 39 from ceda_markup.atom.link import Link 40 from ceda_markup.opensearch.os_engine import get_mimetype 41 from ceda_markup.template.atom import OSAtomResponse 42 #from ceda_markup.atom.info import Title, Info, Content 43 #from ceda_markup.atom.entry import Entry 44 #from ceda_markup.dc.dc import Date 45 #from ceda_markup.gml.gml import PosList, LinearRing, Exterior, Polygon 46 #from ceda_markup.georss.georss import Where 47 from ceda_markup.template.html import OSHTMLResponse 48 from ceda_markup.opensearch.osquery import OSQuery, URL_INDEX_OFFSET_DEFAULT,\ 49 URL_PAGE_OFFSET_DEFAULT 36 from ceda_markup.opensearch.osquery import OSQuery 50 37 from ceda_markup.opensearch.osParam import OSParam 51 from ceda_markup.atom.atom import create Atom, createID, createUpdated,\52 createPublished, create Link, ATOM_LINK_REL_SEARCH38 from ceda_markup.atom.atom import createID, createUpdated,\ 39 createPublished, createAtomDocument, createEntry 53 40 from ceda_markup.atom.info import createTitle, HTML_TYPE, createContent 54 from ceda_markup.atom.entry import createEntry55 41 from ceda_markup.dc.dc import createDate 56 42 from ceda_markup.gml.gml import createPosList, createLinearRing, createExterior,\ 57 43 createPolygon 58 44 from ceda_markup.georss.georss import createWhere 59 45 from ceda_markup.atom.link import REL_SEARCH, REL_SELF, REL_FIRST, REL_NEXT,\ 46 REL_LAST, REL_ALTERNATE 47 from ceda_markup.opensearch.os_response import createOpenSearchRespose 48 from ceda_markup.opensearch import filterResults, COUNT_DEFAULT,\ 49 START_INDEX_DEFAULT, START_PAGE_DEFAULT, createAutodiscoveryLink,\ 50 generateAutodiscoveryPath 51 from ceda_markup.opensearch.template.osresponse import Result 52 from xml.etree.ElementTree import tostring 53 from ceda_markup.opensearch.template.atom import OSAtomResponse 54 from ceda_markup.opensearch.template.html import OSHTMLResponse 55 from ea_model.ceda_metadatamodel.ceda_observationcollection.ceda_observationcollection import CEDA_ObservationCollection 56 from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation 57 from ea_model.ceda_metadatamodel.ceda_result.ceda_result import CEDA_Result 58 59 GUID = 'guid' 60 60 COLLECTION = 'collection' 61 61 OBSERVATION = 'observation' 62 62 RESULT = 'result' 63 BBOX = 'box' 63 BBOX = 'bbox' 64 DUMMY_GUID = 'dummy_guid' 64 65 65 66 CEDA_TITLE = 'ceda_title' 66 67 67 def calculateStep(**kwargs): 68 step = 10 69 if kwargs['params_values'].has_key('count'): 70 step = int(kwargs['params_values']['count']) 71 if step == 0: 72 step = 10 73 return step 68 74 69 75 70 class MyOSAtomResponse(OSAtomResponse): … … 85 80 Constructor 86 81 ''' 87 82 83 def _get_tot_results(self, results): 84 if results is None: 85 return 0 86 87 if isinstance(results, list): 88 return len(results) 89 90 return 1 91 92 def digestSearchResults(self, results, context): 93 count, startIndex, startPage = self._importCountAndPage(context) 94 95 filtered = None 96 tot_results = 0 97 98 if type(results) == CEDA_ObservationCollection: 99 filtered = filterResults(results.member, count, startIndex, startPage) 100 tot_results = self._get_tot_results(results.member) 101 elif type(results) == CEDA_Observation: 102 #to be done 103 filtered = filterResults(results.result, count, startIndex, startPage) 104 tot_results = self._get_tot_results(results.result) 105 else: 106 filtered = filterResults(results, count, startIndex, startPage) 107 tot_results = self._get_tot_results(results) 108 109 subresults = [] 110 for result in filtered: 111 item = None 112 if type(result) != CEDA_Result: 113 result_guid = context['moles3EPB'].retrieveGUIDFromInstance(result) 114 ititle = self._extractTitle(result) 115 item = Subresult(result_guid.id, ititle, result.description, datetime.now().isoformat()) 116 else: 117 item = Subresult(DUMMY_GUID, 'dummy_resultTitle', 'dummy_resultDescription', datetime.now().isoformat()) 118 subresults.append(item) 119 120 return Result(count, startIndex, startPage, tot_results, subresult = subresults) 88 121 89 def generateResponse(self, result, queries, osHostURL, **kwargs): 90 """ 91 @param result: a Result instance 92 @param queries: 93 @param osHostURL: 94 @param kwargs: 95 """ 96 id = "" 97 ospath = self.generateLinkHref(osHostURL, result.id, self.extension, rel = None) 122 def generateResponse(self, results, queries, osHostURL, context): 123 ospath = generateAutodiscoveryPath(osHostURL, None, self.extension, rel = None) 98 124 99 125 #Generates the ATOM document 100 atomID = createID(ospath + "atom") 101 atomTitle = createTitle(result.title) 102 atomUpdate = createUpdated(result.updated) 103 atomdoc = createAtom() 104 atomdoc.append(atomID) 105 atomdoc.append(atomTitle) 106 atomdoc.append(atomUpdate) 107 108 #configuration level 109 step = calculateStep(**kwargs) 110 root = ElementTree(atomdoc).getroot() 126 atomdoc = createAtomDocument(ospath + "atom", results.title, results.updated) 111 127 112 128 #Generate feed's links 113 self.generateFeedLinks(root, ospath, None, result.totalResult, step) 114 129 self.generateFeedLinks(atomdoc, ospath, None, results.totalResult, results.count) 115 130 116 131 #Inserts the OpenSearchResponse elements 117 osdoc = OpenSearchResponse(root) 118 os_totalResults = str(result.totalResult) 119 os_startIndex = str(0) 120 os_itemsPerPage = str(step) 121 osdoc.createDocument(totalResults = os_totalResults, startIndex = os_startIndex, itemsPerPage = os_itemsPerPage) 122 for query in queries: 123 root.append(query) 124 125 self.generateEntries(root, result.subresult, ospath) 132 createOpenSearchRespose(atomdoc, results.totalResult, results.startIndex, results.count, queries) 133 self.generateEntries(atomdoc, results.subresult, ospath) 126 134 127 135 reparsed = minidom.parseString(tostring(atomdoc)) … … 129 137 130 138 def generateFeedLinks(self, atomroot, path, linkid = None, total_results = None, step = 0): 131 self.appendAtomLink(atomroot, path, linkid, startIndex = None, rel = Link.REL_SEARCH) 132 self.appendAtomLink(atomroot, path, linkid, 0, Link.REL_SELF) 133 self.appendAtomLink(atomroot, path, linkid, 0, Link.REL_FIRST) 139 atomroot.append(createAutodiscoveryLink(atomroot, path, self.extension, \ 140 linkid, startIndex = None, rel = REL_SEARCH)) 141 atomroot.append(createAutodiscoveryLink(atomroot, path, self.extension, \ 142 linkid, startIndex = 0, rel = REL_SELF)) 143 atomroot.append(createAutodiscoveryLink(atomroot, path, self.extension, \ 144 linkid, startIndex = 0, rel = REL_FIRST)) 134 145 135 146 if total_results > 2*step: 136 self.appendAtomLink(atomroot, path, linkid, step, Link.REL_NEXT) 137 self.appendAtomLink(atomroot, path, linkid, total_results - (total_results % step), Link.REL_LAST) 147 atomroot.append(createAutodiscoveryLink(atomroot, path, self.extension, \ 148 linkid, step, rel = REL_NEXT)) 149 atomroot.append(createAutodiscoveryLink(atomroot, path, self.extension, \ 150 linkid, total_results - (total_results % step), rel = REL_LAST)) 138 151 else: 139 152 if total_results > step: 140 self.appendAtomLink(atomroot, path, linkid, step, Link.REL_NEXT) 141 self.appendAtomLink(atomroot, path, linkid, step, Link.REL_LAST) 153 atomroot.append(createAutodiscoveryLink(atomroot, path, self.extension, \ 154 linkid, step, rel = REL_NEXT)) 155 atomroot.append(createAutodiscoveryLink(atomroot, path, self.extension, \ 156 linkid, step, rel = REL_LAST)) 142 157 else: 143 self.appendAtomLink(atomroot, path, linkid, 0, Link.REL_NEXT) 144 self.appendAtomLink(atomroot, path, linkid, 0, Link.REL_LAST) 145 146 def generateEntryLinks(self, atomroot, path, linkid = None): 147 self.appendAtomLink(atomroot, path, linkid, startIndex = None, rel = Link.REL_ALTERNATE) 148 self.appendAtomLink(atomroot, path, linkid, startIndex = None, rel = Link.REL_SEARCH) 149 150 def appendAtomLink(self, atomroot, path, linkid = None, startIndex = 0, rel = Link.REL_SELF): 151 href = self.generateLinkHref(path, linkid, startIndex, rel) 152 itype = get_mimetype(self.extension) 153 if rel == ATOM_LINK_REL_SEARCH: 154 itype = get_mimetype('opensearchdescription') 155 link = createLink(href, rel = rel, itype = itype) 156 atomroot.append(link) 157 158 def generateLinkHref(self, path, linkid, startIndex = None, rel = Link.REL_SELF): 159 """ 160 @param path: the host URL 161 @param linkid: the search id 162 @param startIndex: the starting index 163 @param rel: a Link type identificator. If None returns a generic ID 164 """ 165 if rel == None: 166 if linkid: 167 return "%s/search/%s/" % (path, linkid) 168 else: 169 return "%s/search/" % (path) 170 171 if rel == Link.REL_SEARCH: 172 if linkid: 173 return "%s%s/description" % (path, linkid) 174 else: 175 return "%sdescription" % (path) 176 177 if rel == Link.REL_ALTERNATE: 178 if linkid: 179 return "%s%s/%s" % (path, linkid, self.extension) 180 else: 181 return "%s%s" % (path, self.extension) 182 183 if linkid: 184 return "%s%s/%s/?startIndex=%d" % (path, linkid, self.extension, startIndex) 185 else: 186 return "%s%s/?startIndex=%d" % (path, self.extension, startIndex) 158 atomroot.append(createAutodiscoveryLink(atomroot, path, self.extension, \ 159 linkid, 0, rel = REL_NEXT)) 160 atomroot.append(createAutodiscoveryLink(atomroot, path, self.extension, \ 161 linkid, step, rel = REL_LAST)) 162 163 def generateEntryLinks(self, entry, atomroot, path, linkid = None): 164 entry.append(createAutodiscoveryLink(atomroot, path, self.extension, linkid, None, rel = REL_ALTERNATE)) 165 entry.append(createAutodiscoveryLink(atomroot, path, self.extension, linkid, None, rel = REL_SEARCH)) 187 166 188 167 def generateEntries(self, atomroot, subresults, path): … … 191 170 for subresult in subresults: 192 171 #Here could loop over results 193 #ititle = Title(Info.HTML_TYPE, subresult.title)194 #icontent = Content(Info.HTML_TYPE, subresult.description)195 172 atomID = createID(path + subresult.id + '/' + self.extension, root = atomroot) 196 173 ititle = createTitle(root = atomroot, body = subresult.title, itype = HTML_TYPE) … … 200 177 entry = createEntry(atomID, ititle, atomUpdated, 201 178 published=atomPublished, 202 content=atomContent )179 content=atomContent, root = atomroot) 203 180 #xmlentry = entry.buildElement() 204 181 … … 213 190 where = createWhere(root = atomroot, body = polygon) 214 191 entry.append(where) 215 self.generateEntryLinks(entry, path, subresult.id) 216 192 self.generateEntryLinks(entry, atomroot, path, subresult.id) 217 193 entries.append(entry) 218 194 219 195 for entry in entries: 220 196 atomroot.append(entry) 197 198 def _importCountAndPage(self, context): 199 count = COUNT_DEFAULT 200 startIndex = START_INDEX_DEFAULT 201 startPage = START_PAGE_DEFAULT 202 203 try: 204 count = int(context['count']) 205 except: 206 pass 207 208 try: 209 startIndex = int(context['startIndex']) 210 except: 211 pass 212 213 try: 214 startPage = int(context['startPage']) 215 except: 216 pass 217 218 return count, startIndex, startPage 219 220 def _extractTitle(self, cedaObj): 221 if hasattr(cedaObj, 'identifier'): 222 for ident in cedaObj.identifier: 223 if ident.authority.title == CEDA_TITLE: 224 return ident.code 221 225 222 226 class MyOSHTMLResponse(OSHTMLResponse): … … 254 258 params = [param_1, param_2, param_3, param_4, param_5, param_6, param_7, param_8] 255 259 super(MyOSQuery, self).__init__(params) 256 257 258 def _filterResults(self, results, **kwargs): 259 step = calculateStep(**kwargs) 260 261 startIndex = self.indexOffset 262 if kwargs['params_values'].has_key('startIndex'): 263 if int(kwargs['params_values']['startIndex']) > 0 and int(kwargs['params_values']['startIndex']) -1 < len(results): 264 startIndex = int(kwargs['params_values']['startIndex']) 265 266 startPage = self.pageOffset 267 if kwargs['params_values'].has_key('startPage'): 268 if int(kwargs['params_values']['startPage']) * step < len(results): 269 startPage = int(kwargs['params_values']['startPage']) 270 271 firstResult = startIndex 272 lastResult = firstResult + step 273 274 if startPage > 1 and (firstResult + (startPage - 1)*step) <= len(results): 275 firstResult = firstResult + (startPage - 1)*step 276 if firstResult + step <= len(results): 277 lastResult = firstResult + step 278 else: 279 lastResult = len(results) 280 281 return results[firstResult - 1:lastResult - 1] 282 283 def _packResult(self, results, **kwargs): 284 filtered = self._filterResults(results, **kwargs) 285 286 subresults = [] 287 for result in filtered: 288 result_guid = kwargs['moles3EPB'].retrieveGUIDFromInstance(result) 289 ititle = self._extractTitle(result) 290 item = Subresult(result_guid.id, ititle, result.description, datetime.now().isoformat()) 291 subresults.append(item) 292 293 return Result(len(results), subresult = subresults) 294 295 def _extractTitle(self, cedaObj): 296 if hasattr(cedaObj, 'identifier'): 297 for ident in cedaObj.identifier: 298 if ident.authority.title == CEDA_TITLE: 299 return ident.code 300 301 def doSearch(self, **kwargs): 260 261 def doSearch(self, context): 302 262 ibbox = None 303 if kwargs['params_values'] and kwargs['params_values'].has_key(BBOX):304 coords = kwargs['params_values'][BBOX].split(',')263 if context is not None and context.has_key(BBOX) and context[BBOX] is not None: 264 coords = context[BBOX].split(',') 305 265 try: 306 266 if len(coords) == 4: 307 267 ibbox = create_st_setSRID(int(coords[0]),int(coords[1]),int(coords[2]),int(coords[3])) 308 except Exception as e:268 except: 309 269 pass 310 270 311 if kwargs['params_values'] and kwargs['params_values'].has_key(COLLECTION) and kwargs['params_values'].has_key(OBSERVATION): 312 return self.searchObservation(**kwargs) 313 314 if kwargs['params_values'] and kwargs['params_values'].has_key(COLLECTION): 315 return self.searchCollection(**kwargs) 316 317 results = kwargs['moles3EPB'].getObservationCollections(bbox = ibbox) 318 319 return self._packResult(results, **kwargs) 320 321 def searchCollection(self, **kwargs): 322 obs_coll = kwargs['moles3EPB'].getInstanceFromGUID(kwargs['params_values'][COLLECTION]) 323 if obs_coll: 324 obs_coll = kwargs['moles3EPB'].searchSelectiveLoadByInstance(obs_coll, 'member') 325 326 return self._packResult(obs_coll.member, id = kwargs['params_values'][COLLECTION], **kwargs) 327 328 def searchObservation(self, **kwargs): 329 observation = kwargs['moles3EPB'].getInstanceFromGUID(kwargs['params_values'][OBSERVATION]) 330 if observation: 331 observation = kwargs['moles3EPB'].searchSelectiveLoadByInstance(observation, 'result') 332 return None 333 334 class Result(object): 335 def __init__(self, totalResults, iid = None, title = "Discovery feed for Search Services", updated = datetime.now().isoformat(), subresult = []): 336 ''' 337 Constructor 338 @param id: a unique identifier, eventually an URI 339 @param title: an atom.Entry instance 340 @param updated: the last time the record was updated 341 @param subresult: a Subresults array 342 ''' 343 self.totalResult = totalResults 344 self.id = iid 345 self.title = title 346 self.updated = updated 347 self.subresult = subresult 271 if not context.has_key(GUID) or context[GUID] is None: 272 return context['moles3EPB'].getObservationCollections(bbox = ibbox) 273 274 obj = context['moles3EPB'].getInstanceFromGUID(context[GUID]) 275 if obj is None: 276 return None 277 if type(obj) == CEDA_ObservationCollection: 278 return context['moles3EPB'].searchSelectiveLoadByInstance(obj, 'member') #need to add bbox & phenomTime 279 elif type(obj) == CEDA_Observation: 280 return context['moles3EPB'].searchSelectiveLoadByInstance(obj, 'result') #need to add bbox & phenomTime 348 281 349 282 -
mauRepo/HPFos/trunk/src/HPFos/settings.py
r8406 r8466 167 167 os_engine = setUp() 168 168 #MOLES3_DB_CONNECTION = 'postgresql://user:pws@host:port/dbName' 169 #MOLES3_DB_CONNECTION = 'PG_MOLES3_DB_CONNECTION' 170 #MOLES3_DB_CONNECTION = 'postgresql://badc:rotyn217m@neptune.badc.rl.ac.uk:5432/Moles3' 171 MOLES3_DB_CONNECTION = 'postgresql://badc:rotyn217m@neptune.badc.rl.ac.uk:5432/Moles3_dev1' 169 MOLES3_DB_CONNECTION = 'PG_MOLES3_DB_CONNECTION' 172 170 from ea_model.sqlTables import doTables as doMoles 173 171 MOLES3_DB_SCRIPT = doMoles 172 173 # Local modifications to settings are imported from settings_local.py 174 from settings_local import * -
mauRepo/HPFos/trunk/src/HPFos/testepb.py
r8353 r8466 15 15 from sqlalchemy.orm import mapper 16 16 from ea_model.moles3_4.utilities.mo_responsiblepartyinfo import MO_ResponsiblePartyInfo 17 from ea_model.moles3_4.utilities.mo_rolevalue import MO_RoleValue18 17 from sqlalchemy.orm.collections import InstrumentedList 19 18 from ceda_guid import CedaGUID -
mauRepo/HPFos/trunk/src/HPFos/view/view.py
r8406 r8466 31 31 @author: Maurizio Nagni 32 32 ''' 33 from HPFos.settings import os_engine 34 from HPFos.osImpl.myimpl import COLLECTION, OBSERVATION, RESULT, GUID,\ 35 DUMMY_GUID 36 from django.utils.safestring import mark_safe 33 37 from django.shortcuts import render_to_response 34 38 from django.core.context_processors import csrf 35 from django.utils.safestring import mark_safe 36 from HPFos.settings import os_engine 37 from HPFos.osImpl.myimpl import COLLECTION, OBSERVATION, RESULT 39 from ea_model.ceda_metadatamodel.ceda_observationcollection.ceda_observationcollection import CEDA_ObservationCollection 40 from ea_model.ceda_metadatamodel.ceda_observation.ceda_observation import CEDA_Observation 38 41 39 42 hostURL = 'http://localhost:8000' … … 51 54 return 'http://%s/HPFos' % (request.get_host()) 52 55 53 54 55 56 56 def getHome(request): 57 57 context = {} … … 65 65 context = {} 66 66 context['response'] = mark_safe(response) 67 return _dispatchResponse(request, 'responseTemplate', context) 67 return _dispatchResponse(request, 'responseTemplate', context) 68 68 69 def _doSearch(request, iformat, collection_guid = None, observation_guid = None, result_guid = None):69 def _doSearch(request, iformat, guid = None, result_guid = None): 70 70 hostURL = _buildHostURL(request) 71 #params = {'q': ['ice', 'snow']}72 params = request.GET.copy()73 if collection_guid:74 params[COLLECTION] = collection_guid75 if observation_guid:76 params[OBSERVATION] = observation_guid77 if result_guid:78 params[RESULT] = result_guid71 context = os_engine.createQueryDictionary() 72 if request.GET is not None: 73 for param in request.GET.iteritems(): 74 context[param[0]] = param[1] 75 76 context[GUID] = guid 77 if guid == DUMMY_GUID: 78 context[GUID] = None 79 79 80 response = os_engine.doSearch(hostURL, iformat, params_values = params, moles3EPB = request.moles3EPB, \ 81 startIndex = 1, startPage = 2, count = 0) 80 context['moles3EPB'] = request.moles3EPB 81 82 response = os_engine.doSearch(hostURL, iformat, context) 83 82 84 context = {} 83 85 context['response'] = mark_safe(response) … … 87 89 return _doSearch(request, iformat) 88 90 89 def doSearchL1(request, collection_guid, iformat): 90 return _doSearch(request, iformat, collection_guid) 91 92 def doSearchL2(request, collection_guid, observation_guid, iformat): 93 return _doSearch(request, iformat, collection_guid, observation_guid) 94 95 def doSearchL3(request, collection_guid, observation_guid, result_guid, iformat): 96 return _doSearch(request, iformat, collection_guid, observation_guid, result_guid) 91 def doSearchL1(request, guid, iformat): 92 return _doSearch(request, iformat, guid) 97 93 98 94 def _buildDescriptionOsPath(hostURL, collection_guid = None, observation_guid = None, result_guid = None): -
mauRepo/HPFos/trunk/src/tests/moles3epbtests.py
r8406 r8466 36 36 from logging import StreamHandler 37 37 from tests.testconfig import getMoles3EPB, closeEPB 38 from ea_model.ceda_metadatamodel.ceda_observationcollection.ceda_observationcollection import CEDA_ObservationCollection39 38 40 39 class Moles3EPBTest(TestCase): … … 52 51 self.extractCollections() 53 52 54 def extractCollections(self):55 for collection in self.moles3epb.getObjectsByGE(CEDA_ObservationCollection):56 union = self.moles3epb.getUnifyObservationCollectionGE(collection)57 if union:58 print "Collection:%d - Union: %s" % (collection.id, union)59 '''60 self.logging.info('Tries to retrieve them')61 obs_collections = self.moles3epb.getObjectsByGE(CEDA_ObservationCollection)62 if obs_collections:63 print len(obs_collections)64 '''65 #self.assertTrue(hasattr(observationCollection, 'id'), "Cannot create ObservationCollection")66 #self.assertNotEqual(res, None, "Cannot retrieve the stored instance")67 68 53 if __name__ == "__main__": 69 54 #import sys;sys.argv = ['', 'Test.testName']
Note: See TracChangeset
for help on using the changeset viewer.