def paths(self, source, dest): types = self.__eco.agora.fountain.types if dest not in types: raise NotFoundError('{}'.format(dest)) if source not in types: raise NotFoundError('{}'.format(source)) try: return self.__eco.agora.fountain.get_paths( dest, force_seed=[ ('<{}-uri>'.format(source.lower()).replace(':', '-'), source) ]) except Exception as e: raise GatewayError(e.message)
def delete_resource(self, uri): try: self.__eco.delete_resource(uri) except AttributeError: raise NotFoundError(uri) except Exception as e: raise GatewayError(e.message)
def get_resource(self, uri): try: return self.__eco.get_resource(uri) except AttributeError: raise NotFoundError(uri) except Exception as e: raise GatewayError(e.message)
def get_type(self, ty): try: return self.__eco.agora.fountain.get_type(ty) except TypeError: raise NotFoundError(ty) except Exception as e: raise GatewayError(e.message)
def get_property(self, pr): try: return self.__eco.agora.fountain.get_property(pr) except TypeError: raise NotFoundError(pr) except Exception as e: raise GatewayError(e.message)
def forget_extension(self, name): if name not in self.__eco.extensions: raise NotFoundError(name) try: self.__eco.delete_extension(name) except Exception as e: raise GatewayError(e.message)
def add_description(self, id, types): try: return self.__eco.add_description(id, types) except TypeError as e: raise NotFoundError(e.message) except AttributeError as e: raise ConflictError(e.message) except Exception as e: raise GatewayError(e.message)
def add_resource(self, uri, types): try: return self.__eco.add_resource(uri, types) except TypeError as e: raise NotFoundError(e.message) except AttributeError as e: raise ConflictError(e.message) except Exception as e: raise GatewayError(e.message)
def get_extension(self, eid): if eid in self.__eco.extensions: try: return self.__eco.get_extension(eid) except GatewayError as e: raise e except Exception as e: raise GatewayError(e.message) raise NotFoundError('{}?'.format(eid))
def add_mapping(eco_gw, id, amid, predicate, key, jsonpath=None, root=False, transformed_by=None): try: td = eco_gw.get_description(id) except AttributeError: raise NotFoundError(id) transform_td = None if transformed_by: try: transform_td = eco_gw.get_description(transformed_by) except AttributeError: raise NotFoundError(transformed_by) target_am = [ am for am in td.access_mappings if str(am.id) == amid or am.endpoint.href.toPython() == amid ] if not target_am: raise NotFoundError(amid) target_am = target_am.pop() m = Mapping( key=key, predicate=URIRef(extend_uri(predicate, eco_gw.agora.fountain.prefixes)), root=root, path=jsonpath, transform=ResourceTransform(transform_td) if transform_td else None) target_am.mappings.add(m) g = td.to_graph(th_nodes={}) eco_gw.learn_descriptions(g) return m
def delete_description(self, id): try: td = self.__eco.get_description(id) except AttributeError: td = None if td is None: raise NotFoundError('Unknown description: {}'.format(id)) try: self.__eco.delete_description(id) except Exception as e: raise GatewayError(e.message)
def add_access_mapping(eco_gw, td_id, link): # type: (EcoGateway, basestring, basestring) -> AccessMapping td = eco_gw.get_description(td_id) if not td: raise NotFoundError(td_id) endpoint_hrefs = map(lambda e: u'{}'.format(e.href), td.endpoints) if link in endpoint_hrefs: raise ConflictError('Link already mapped') e = Endpoint(href=link) am = AccessMapping(e) td.add_access_mapping(am) g = td.to_graph(th_nodes={}) eco_gw.learn_descriptions(g) return am