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: ...@@ -32,7 +32,7 @@ paths:
/trace: /trace:
post: post:
operationId: "rest.blockchain_trace.receive" operationId: "rest.blockchain_trace.post"
tags: tags:
- "Blockchain Trace" - "Blockchain Trace"
summary: "Add a new blockchain trace to SMART" summary: "Add a new blockchain trace to SMART"
...@@ -49,6 +49,18 @@ paths: ...@@ -49,6 +49,18 @@ paths:
description: "Successful operation" description: "Successful operation"
400: 400:
description: "Invalid input" 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: definitions:
BlockchainTrace: BlockchainTrace:
......
...@@ -17,8 +17,8 @@ class MongoRepository: ...@@ -17,8 +17,8 @@ class MongoRepository:
def insert_trace(self, content: dict): def insert_trace(self, content: dict):
self._collection.insert_one(content) self._collection.insert_one(content)
def get_traces(self, selection: dict = {}): def get_traces(self, selection: dict = {}, projection: dict = {'_': 0}) -> pymongo.cursor.Cursor:
return self._collection.find(selection) return self._collection.find(selection, projection)
def close_connection(self): def close_connection(self):
self._mongo_client.close() self._mongo_client.close()
......
from db.MongoRepository import MongoRepository from db.MongoRepository import MongoRepository
from messaging.MessageSender import MessageSender
import json import json
import logging import logging
...@@ -6,9 +7,16 @@ LOGGER = logging.getLogger(__name__) ...@@ -6,9 +7,16 @@ LOGGER = logging.getLogger(__name__)
class MessageHandler: class MessageHandler:
_mongo_repo = None _mongo_repo = None
_message_sender = None
def __init__(self): def __init__(self):
self._mongo_repo = MongoRepository() 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): def handle_generic(self, body):
LOGGER.info(f"Received message: {body}") LOGGER.info(f"Received message: {body}")
...@@ -31,3 +39,7 @@ class MessageHandler: ...@@ -31,3 +39,7 @@ class MessageHandler:
def handle_blockchain_transaction(self, transaction): def handle_blockchain_transaction(self, transaction):
self._mongo_repo.insert_trace(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 flask import request, Response
from db.MongoRepository import MongoRepository
def receive(): mongo_repo = MongoRepository()
def post():
return Response(status=501) 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