def _delete_id_pair_meta(self, id1, id2, metadata): mapclient = self._mapclient pubreq = PublishRequest( mapclient.get_session_id(), str( PublishDeleteOperation(id1=str( Identity(name=id1, type="other", other_type="extended")), id2=str( Identity(name=id2, type="other", other_type="extended")), filter=metadata))) result = mapclient.call('publish', pubreq)
def _publish_id_pair_meta(self, id1, id2, metadata): mapclient = self._mapclient pubreq = PublishRequest(mapclient.get_session_id(), str(PublishUpdateOperation( id1=str(Identity(name=id1, type="other", other_type="extended")), id2=str(Identity(name=id2, type="other", other_type="extended")), metadata=metadata, lifetime='forever'))) result = mapclient.call('publish', pubreq)
def update(cls, id1_name, id2_name=None, metadatas=None): """Create or update identity with link and metadata provided.""" if metadatas is None or not metadatas: return id1_str = unicode(Identity(name=id1_name, type="other", other_type="extended")) if id1_name not in cls._graph: cls._graph[id1_name] = {'ident': id1_str, 'links': {}} if id2_name is None: property_items = '' for metadata in metadatas: metadata_name = metadata._Metadata__name meta_string = unicode(metadata) link_key = metadata_name link_info = {'meta': meta_string} cls._graph[id1_name]['links'][link_key] = link_info property_items += meta_string[10:-11] if property_items: items = ('<resultItem>%s<metadata>%s</metadata></resultItem>' % (id1_str, property_items)) else: id2_str = unicode(Identity(name=id2_name, type="other", other_type="extended")) if id2_name not in cls._graph: cls._graph[id2_name] = {'ident': id2_str, 'links': {}} items = '' for metadata in metadatas: metadata_name = metadata._Metadata__name meta_string = unicode(metadata) link_key = '%s %s' % (metadata_name, id2_name) link_info = {'meta': meta_string, 'other': id2_str} cls._graph[id1_name]['links'][link_key] = link_info items += "<resultItem>%s%s%s</resultItem>" % (id1_str, id2_str, meta_string) link_key = '%s %s' % (metadata_name, id1_name) link_info = {'meta': meta_string, 'other': id1_str} cls._graph[id2_name]['links'][link_key] = link_info for queue in cls._subscribe_list: if queue is not None: queue.put((2, time(), 'updateResult', items))
def _build_request(self, id1_name, id2_name, meta_list, delete=False): request = '' id1 = unicode( Identity(name=id1_name, type="other", other_type="extended")) if id2_name != 'self': id2 = unicode( Identity(name=id2_name, type="other", other_type="extended")) else: id2 = None for m in meta_list: if delete: filter = unicode(m) if m else None op = PublishDeleteOperation(id1=id1, id2=id2, filter=filter) else: op = PublishUpdateOperation(id1=id1, id2=id2, metadata=unicode(m), lifetime='forever') request += unicode(op) return request
def _delete_id_self_meta(self, self_imid, meta_name): mapclient = self._mapclient pubreq = PublishRequest(mapclient.get_session_id(), str(PublishDeleteOperation( id1=str(Identity( name=self_imid, type="other", other_type="extended")), filter=meta_name))) result = mapclient.call('publish', pubreq)
def search(self): if self._args.search_metas: search_metas = ' or '.join(self._args.search_metas.split(',')) else: search_metas = None if self._args.result_metas: result_metas = ' or '.join(self._args.result_metas.split(',')) else: result_metas = None start_id = str( Identity(name=self._args.search_identifier, type='other', other_type='extended')) soap_result = self._search(start_id, search_metas, result_metas) self.soap_doc = et.fromstring(soap_result) self.result_items = self.soap_doc.xpath( '/a:Envelope/a:Body/b:response/searchResult/resultItem', namespaces={ 'a': 'http://www.w3.org/2003/05/soap-envelope', 'b': 'http://www.trustedcomputinggroup.org/2010/IFMAP/2' })