Commit 0652b32f authored by Alexander Lercher's avatar Alexander Lercher

Trace Retrieval: new traces: inform semantic-linking; expose rest get

parent 07074316
......@@ -32,7 +32,7 @@ paths:
/trace:
post:
operationId: "rest.blockchain_trace.receive"
operationId: "rest.blockchain_trace.post"
tags:
- "Blockchain Trace"
summary: "Add a new blockchain trace to SMART"
......@@ -49,6 +49,18 @@ paths:
description: "Successful operation"
400:
description: "Invalid input"
get:
operationId: "rest.blockchain_trace.get"
tags:
- "Blockchain Trace"
summary: "Get blockchain traces"
description: "Returns all blockchain traces in the database"
parameters: []
responses:
200:
description: "Successful operation"
schema:
$ref: "#/definitions/BlockchainTrace"
definitions:
BlockchainTrace:
......
......@@ -17,8 +17,8 @@ class MongoRepository:
def insert_trace(self, content: dict):
self._collection.insert_one(content)
def get_traces(self, selection: dict = {}):
return self._collection.find(selection)
def get_traces(self, selection: dict = {}, projection: dict = {'_': 0}) -> pymongo.cursor.Cursor:
return self._collection.find(selection, projection)
def close_connection(self):
self._mongo_client.close()
......
from db.MongoRepository import MongoRepository
from messaging.MessageSender import MessageSender
import json
import logging
......@@ -6,9 +7,16 @@ LOGGER = logging.getLogger(__name__)
class MessageHandler:
_mongo_repo = None
_message_sender = None
def __init__(self):
self._mongo_repo = MongoRepository()
self._init_message_sender()
def _init_message_sender(self):
self._message_sender = MessageSender()
self._message_sender.connect()
self._message_sender.create_exchange('inhub', 'direct')
def handle_generic(self, body):
LOGGER.info(f"Received message: {body}")
......@@ -31,3 +39,7 @@ class MessageHandler:
def handle_blockchain_transaction(self, transaction):
self._mongo_repo.insert_trace(transaction)
# inform semantic linking microservice
msg = {'type': 'new-traces-available'}
self._message_sender.send('datahub', json.dumps(msg), 'semantic-linking')
from flask import request, Response
from db.MongoRepository import MongoRepository
def receive():
mongo_repo = MongoRepository()
def post():
return Response(status=501)
def get():
return list(mongo_repo.get_traces(projection={'_id': 0}))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment