Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
SMART
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UNI-KLU
SMART
Commits
f42805b4
Commit
f42805b4
authored
Sep 24, 2020
by
Manuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TraceRetrieval] changed MessageHandler to work with tables
parent
313cea69
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
119 additions
and
13 deletions
+119
-13
add_car.py
...e/app/_add_use_case_scripts/car-sharing/tables/add_car.py
+1
-1
add_debug_schema.py
...rvice/app/_add_use_case_scripts/debug/add_debug_schema.py
+37
-0
add_pizza_table.py
...app/_add_use_case_scripts/debug/tables/add_pizza_table.py
+37
-0
transaction.py
...trieval-microservice/app/database/entities/transaction.py
+4
-2
MessageHandler.py
...ce-retrieval-microservice/app/messaging/MessageHandler.py
+27
-8
test_by.py
...-hub-in/trace-retrieval-microservice/app/tests/test_by.py
+13
-2
No files found.
src/participation-hub/business-logic-microservice/app/_add_use_case_scripts/car-sharing/tables/add_car.py
View file @
f42805b4
...
...
@@ -15,7 +15,7 @@
# },
# {
# "use_case": use_case,
# "name": "brand_layer",
# "name": "brand_layer",
a
# "properties": [
# "UniqueID",
# "brand",
...
...
src/participation-hub/business-logic-microservice/app/_add_use_case_scripts/debug/add_debug_schema.py
0 → 100644
View file @
f42805b4
import
sys
import
os
from
pathlib
import
Path
from
typing
import
Dict
,
Any
import
requests
modules_path
=
'../../../modules/'
if
os
.
path
.
exists
(
modules_path
):
sys
.
path
.
insert
(
1
,
modules_path
)
import
network_constants
as
nc
from
security.token_manager
import
TokenManager
import
tables.add_pizza_table
as
pizza
def
add_use_case
(
use_case
:
str
):
jwt
=
TokenManager
.
getInstance
()
.
getToken
()
url
=
f
"https://articonf1.itec.aau.at:30420/api/use-cases"
response
=
requests
.
post
(
url
,
verify
=
False
,
proxies
=
{
"http"
:
None
,
"https"
:
None
},
headers
=
{
"Authorization"
:
f
"Bearer {jwt}"
},
json
=
{
"name"
:
use_case
}
)
print
(
url
+
": "
+
str
(
response
.
status_code
))
if
__name__
==
"__main__"
:
use_case
=
"debug"
# disable ssl warnings :)
requests
.
packages
.
urllib3
.
disable_warnings
()
add_use_case
(
use_case
)
pizza
.
main
(
use_case
)
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/_add_use_case_scripts/debug/tables/add_pizza_table.py
0 → 100644
View file @
f42805b4
import
network_constants
as
nc
from
security.token_manager
import
TokenManager
import
requests
def
add_table
(
use_case
:
str
,
table_name
:
str
):
jwt
=
TokenManager
.
getInstance
()
.
getToken
()
columns
=
{
"name"
:
"name"
,
"dough"
:
"dough//type"
,
"cheese"
:
"dough//cheese"
,
"sauce"
:
"sauces[0]//name"
,
"sugar"
:
"sauces[0]//sugarcontent"
,
"UniqueID"
:
"name+dough//type"
}
url
=
f
"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/tables"
table
=
{
"name"
:
table_name
,
"mappings"
:
columns
}
response
=
requests
.
post
(
url
,
verify
=
False
,
proxies
=
{
"http"
:
None
,
"https"
:
None
},
headers
=
{
"Authorization"
:
f
"Bearer {jwt}"
},
json
=
table
)
print
(
url
+
": "
+
str
(
response
.
status_code
))
def
main
(
use_case
:
str
):
print
(
"PIZZA"
)
add_table
(
use_case
,
"pizza"
)
\ No newline at end of file
src/transaction-hub-in/trace-retrieval-microservice/app/database/entities/transaction.py
View file @
f42805b4
from
typing
import
Dict
class
Transaction
:
def
__init__
(
self
,
use_case
:
str
,
properties
:
Dict
):
def
__init__
(
self
,
use_case
:
str
,
table
:
str
,
properties
:
Dict
):
self
.
use_case
=
use_case
self
.
properties
=
properties
self
.
table
=
table
def
to_serializable_dict
(
self
):
return
{
"use_case"
:
self
.
use_case
,
"table"
:
self
.
table
,
"id"
:
self
.
properties
[
"UniqueID"
],
"properties"
:
self
.
properties
}
...
...
@@ -17,4 +19,4 @@ class Transaction:
@
staticmethod
def
from_serializable_dict
(
data
:
Dict
):
return
Transaction
(
data
[
"use_case"
],
data
[
"properties"
])
\ No newline at end of file
return
Transaction
(
data
[
"use_case"
],
data
[
"table"
],
data
[
"properties"
])
\ No newline at end of file
src/transaction-hub-in/trace-retrieval-microservice/app/messaging/MessageHandler.py
View file @
f42805b4
...
...
@@ -124,9 +124,8 @@ class MessageHandler:
'''
jwt_token
=
TokenManager
.
getInstance
()
.
getToken
()
# query schema information
url
=
f
'https://{network_constants.BUSINESS_LOGIC_HOSTNAME}:{network_constants.BUSINESS_LOGIC_REST_PORT}/api/use-cases/{use_case}/schema'
# query tables for use-case
url
=
f
'https://{network_constants.BUSINESS_LOGIC_HOSTNAME}:{network_constants.BUSINESS_LOGIC_REST_PORT}/api/use-cases/{use_case}/tables'
response
=
requests
.
get
(
url
,
verify
=
False
,
...
...
@@ -135,9 +134,10 @@ class MessageHandler:
)
if
response
.
status_code
!=
200
:
raise
ValueError
(
"
no schema information available
"
)
raise
ValueError
(
"
Error while retrieving schema information
"
)
return
json
.
loads
(
response
.
text
)
tables
=
json
.
loads
(
response
.
text
)
return
tables
def
handle_blockchain_transaction
(
self
,
transaction_message
:
Dict
):
'''
...
...
@@ -148,22 +148,41 @@ class MessageHandler:
transaction_message - Required: data of the transaction. Has to contain the key 'ApplicationType' which stores the use-case.
'''
# check if there is a use-case in the message
if
"ApplicationType"
not
in
transaction_message
.
keys
():
LOGGER
.
error
(
"Transaction has no ApplicationType, storing it under use-case 'unknown'."
)
transaction_message
[
"ApplicationType"
]
=
"unknown"
self
.
_mongo_repo
.
add_failed_transaction
(
transaction_message
)
return
# check if there is a doctype in the message
if
"docType"
not
in
transaction_message
.
keys
():
LOGGER
.
error
(
"Transaction has no docType, ignoring it."
)
return
use_case
=
transaction_message
[
"ApplicationType"
]
docType
=
transaction_message
[
"docType"
]
try
:
data
=
self
.
_fetch_schema_information
(
use_case
)
tables
=
self
.
_fetch_schema_information
(
use_case
)
except
ValueError
as
e
:
print
(
f
"{e}"
)
self
.
_mongo_repo
.
add_failed_transaction
(
transaction_message
)
return
mappings
=
data
[
"mappings"
]
target_table
=
None
# find correct table
for
table
in
tables
:
if
table
[
"name"
]
==
docType
:
target_table
=
table
break
# abort if table does not exist.
if
target_table
==
None
:
LOGGER
.
error
(
f
"There is no table '{docType}', ignoring the message."
)
return
mappings
=
table
[
"mappings"
]
try
:
flattened
=
self
.
_flatten_transaction
(
transaction_message
,
mappings
)
except
KeyError
as
e
:
...
...
@@ -171,7 +190,7 @@ class MessageHandler:
self
.
_mongo_repo
.
add_failed_transaction
(
transaction_message
)
return
transaction
=
Transaction
(
use_case
,
flattened
)
transaction
=
Transaction
(
use_case
,
target_table
[
"name"
],
flattened
)
try
:
self
.
_mongo_repo
.
add_transaction
(
transaction
)
except
ValueError
as
e
:
...
...
src/transaction-hub-in/trace-retrieval-microservice/app/tests/test_by.py
View file @
f42805b4
...
...
@@ -3,6 +3,7 @@ import manage_sys_paths
import
json
from
messaging.MessageHandler
import
MessageHandler
from
database.entities.transaction
import
Transaction
class
DummyMongoRepo
:
'''Dummy class to be used for testing the MessageHandler'''
...
...
@@ -10,6 +11,10 @@ class DummyMongoRepo:
def
insert_trace
(
self
,
trace
):
self
.
last_trace
=
trace
def
add_transaction
(
self
,
transaction
:
Transaction
):
print
(
str
(
transaction
.
to_serializable_dict
()))
from
messaging.DummyMessageManager
import
DummyMessageManager
as
DummyMessageSender
class
Test_MessageHandler
(
unittest
.
TestCase
):
...
...
@@ -50,6 +55,7 @@ class Test_MessageHandler(unittest.TestCase):
'content'
:
{
"ApplicationType"
:
"debug"
,
"docType"
:
"pizza"
,
"name"
:
"Margherita"
,
"dough"
:
{
"type"
:
"wheat"
,
...
...
@@ -57,10 +63,12 @@ class Test_MessageHandler(unittest.TestCase):
},
"sauces"
:
[
{
"name"
:
"tomato"
"name"
:
"tomato"
,
"sugarcontent"
:
0.0
,
},
{
"name"
:
"caramel"
"name"
:
"caramel"
,
"sugarcontent"
:
1.0
,
}
]
}
...
...
@@ -76,6 +84,9 @@ class Test_MessageHandler(unittest.TestCase):
print
(
"STARTING THE TEST..."
)
msg
=
self
.
_get_pizza_message
()
print
(
f
"msg: {msg}"
)
_
=
self
.
handler
.
handle_blockchain_transaction
(
json
.
loads
(
msg
)[
"content"
])
if
__name__
==
'__main__'
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment