class FragmentRequest(DeliveryRequest): def __init__(self): super(FragmentRequest, self).__init__() self.__pattern_graph = CGraph() self.__pattern_graph.bind('curator', CURATOR) try: prefixes = agora_client.prefixes for p in prefixes: self.__pattern_graph.bind(p, prefixes[p]) except Exception, e: raise EnvironmentError(e.message)
def build_reply(template, reply_to, comment=None): reply_graph = CGraph() root_node = None for (s, p, o) in template: reply_graph.add((s, p, o)) if p == RDF.type: root_node = s reply_graph.add((root_node, CURATOR.responseTo, Literal(reply_to, datatype=TYPES.UUID))) reply_graph.set((root_node, CURATOR.submittedOn, Literal(datetime.now()))) reply_graph.set((root_node, CURATOR.messageId, Literal(str(uuid.uuid4()), datatype=TYPES.UUID))) if comment is not None: reply_graph.set((root_node, RDFS.comment, Literal(comment, datatype=XSD.string))) for (prefix, ns) in template.namespaces(): reply_graph.bind(prefix, ns) return reply_graph
class Request(object): def __init__(self): from sdh.curator.actions.core import CURATOR, AMQP self._graph = CGraph() self._graph.bind('curator', CURATOR) self._graph.bind('amqp', AMQP) self._request_node = None self._fields = {} def parse(self, message): log.debug('Parsing message...') try: self._graph.parse(StringIO.StringIO(message), format='turtle') except Exception, e: raise SyntaxError(e.message) self._extract_content()
def _build_reply_templates(): accepted = CGraph() failure = CGraph() response_node = BNode() curator_node = BNode() accepted.add((response_node, RDF.type, CURATOR.Accepted)) accepted.add((curator_node, RDF.type, FOAF.Agent)) accepted.add((response_node, CURATOR.responseNumber, Literal("0", datatype=XSD.unsignedLong))) accepted.add((response_node, CURATOR.submittedBy, curator_node)) accepted.add((response_node, CURATOR.submittedBy, curator_node)) accepted.add( (curator_node, CURATOR.agentId, CURATOR_UUID)) accepted.bind('types', TYPES) accepted.bind('curator', CURATOR) accepted.bind('foaf', FOAF) for triple in accepted: failure.add(triple) failure.set((response_node, RDF.type, CURATOR.Failure)) for (prefix, ns) in accepted.namespaces(): failure.bind(prefix, ns) return accepted, failure