Commit 7c2a146b authored by Manuel's avatar Manuel

extracted TokenManager into modules

parent 8ddff38f
from authentication.token_manager import TokenManager from security.token_manager import TokenManager
import network_constants import network_constants
from database.entities.transaction import Transaction from database.entities.transaction import Transaction
from database.repository import Repository from database.repository import Repository
...@@ -114,13 +114,9 @@ class MessageHandler: ...@@ -114,13 +114,9 @@ class MessageHandler:
return flattened return flattened
def handle_blockchain_transaction(self, transaction: Dict): def _fetch_schema_information(self, use_case: str) -> Dict:
jwt_token = TokenManager.getInstance().getToken() jwt_token = TokenManager.getInstance().getToken()
transaction_data = transaction
use_case = transaction_data["ApplicationType"]
# query schema information # query schema information
url = f'https://{network_constants.BUSINESS_LOGIC_HOSTNAME}:{network_constants.BUSINESS_LOGIC_REST_PORT}/api/use-cases/{use_case}/schema' url = f'https://{network_constants.BUSINESS_LOGIC_HOSTNAME}:{network_constants.BUSINESS_LOGIC_REST_PORT}/api/use-cases/{use_case}/schema'
...@@ -136,11 +132,22 @@ class MessageHandler: ...@@ -136,11 +132,22 @@ class MessageHandler:
print(f"RESPONSE: {response.text}") print(f"RESPONSE: {response.text}")
if response.status_code != 200: if response.status_code != 200:
raise ValueError("no schema information available")
return json.loads(response.text)
def handle_blockchain_transaction(self, transaction: Dict):
transaction_data = transaction
use_case = transaction_data["ApplicationType"]
try:
data = self._fetch_schema_information(use_case)
except ValueError as e:
print(f"{e}")
MessageHandler._repository.add_failed_transaction(transaction) MessageHandler._repository.add_failed_transaction(transaction)
return return
data = json.loads(response.text)
mappings = data["mappings"] mappings = data["mappings"]
flattened = self._flatten_transaction(transaction_data, mappings) flattened = self._flatten_transaction(transaction_data, mappings)
......
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