# HG changeset patch # User dwinter # Date 1338389625 -7200 # Node ID e6c3334e9611a4dfd26789d7fa18f32c3f71843e # Parent 0ed5ecf366932370a3ebce9344c28281e6b2a770 new function: getSingleRelationFromEntity diff -r 0ed5ecf36693 -r e6c3334e9611 JSONClient.py --- a/JSONClient.py Sun Oct 23 21:33:26 2011 +0200 +++ b/JSONClient.py Wed May 30 16:53:45 2012 +0200 @@ -8,7 +8,10 @@ import os.path import logging +from BTrees.OOBTree import OOBTree + class JSONClient(SimpleItem): + meta_type="JSONClient" manage_options=SimpleItem.manage_options+( @@ -32,13 +35,14 @@ def changeJSONClientConfig(self,url,RESPONSE=None): + """cahnge the JSON config""" self.url=url if RESPONSE is not None: RESPONSE.redirect('manage_main') def getEntityLink(self,entId): - return "http://neruda.mpiwg-berlin.mpg.de:8080/om4-ismi/browse/entityDetails.iface?eid="+str(entId) + return "https://openmind-ismi-dev.mpiwg-berlin.mpg.de/om4-ismi/browse/entityDetails.iface?eid="+str(entId) def json(self,method,params={},cache=True): """json aufruf""" @@ -46,7 +50,7 @@ paramString=urllib.urlencode(params) callUrl = self.url%(method,paramString) - + logging.debug(callUrl) if (cache is True) and (self._v_jsonCache.get(callUrl,None)!=None): return self._v_jsonCache.get(callUrl) else: @@ -68,9 +72,18 @@ return attrsHash def getOV(self,entId): + if (entId)<0: #-1 falls keine Entity gefunden wurde + return"" obj=self.json("getEntity", {'entId':entId}) return obj.get('entity').get('ownValue') + def getSingleRelationFromEntity(self,jsonHash,type="srcRelations",relName=None,idType="sourceId"): + ret = self.getRelationFromEntity(jsonHash,type,relName,maxNum=1) + if len(ret)==0: + return -1 + else: + return ret[0].get(idType) + def getRelationFromEntity(self,jsonHash,type="srcRelations",relName=None,maxNum=30): hash=jsonHash.get("entity") logging.debug(type) @@ -213,6 +226,43 @@ for entry in history: ret.append("""%s"""%entry) return "-->".join(ret) + + def filter(self,list,filterValue,letter,cache=True,cacheName=None): + """filters a list of jsonObjects, gives only elements where the filterValue, begins with letter.""" + + if cache and cacheName and (self._v_jsonCache.get(cacheName,None)!=None): + hash = self._v_jsonCache.get(cacheName).get(filterValue,None) + if hash is not None: + return hash.get(letter,[]) + + + caches = self._v_jsonCache.get(cacheName,None) + if caches is None: + caches= OOBTree() + + hash=caches.get(filterValue,None) + if hash is None: + hash=OOBTree() + + + for object in list: + sortValue = object.get(filterValue).lower() + if len(sortValue)>0: + val = sortValue[0] + if val=="[" and len(sortValue)>1: + val = sortValue[1] + else: + val="" + + valList=hash.get(val,[]) + valList.append(object) + hash.update({val:valList}) + + caches.update({filterValue:hash}) + + self._v_jsonCache.update({cacheName:caches}) + + return hash.get(letter,[]), hash.keys() def manage_addJSONClient(self,id,url,RESPONSE=None): """add a json client""" diff -r 0ed5ecf36693 -r e6c3334e9611 zpt/changeJSONClientForm.zpt --- a/zpt/changeJSONClientForm.zpt Sun Oct 23 21:33:26 2011 +0200 +++ b/zpt/changeJSONClientForm.zpt Wed May 30 16:53:45 2012 +0200 @@ -1,6 +1,6 @@