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
19cfc8fe
Commit
19cfc8fe
authored
Sep 02, 2020
by
Manuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
traceRetrieval: cleanup
parent
3414bdc1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
106 deletions
+26
-106
swagger_local.yml
...race-retrieval-microservice/app/configs/swagger_local.yml
+3
-65
MongoRepository.py
...ce-retrieval-microservice/app/database/MongoRepository.py
+0
-17
MessageHandler.py
...ce-retrieval-microservice/app/messaging/MessageHandler.py
+23
-14
blockchain_trace.py
...ace-retrieval-microservice/app/routes/blockchain_trace.py
+0
-10
No files found.
src/transaction-hub-in/trace-retrieval-microservice/app/configs/swagger_local.yml
View file @
19cfc8fe
...
...
@@ -23,7 +23,7 @@ paths:
responses
:
'
200'
:
description
:
"
Successful
Request"
/
transactions-failed/use_case/{use_case}
:
/
use_cases/{use_case}/transactions-failed
:
delete
:
operationId
:
"
routes.transactions.delete_all_failed_for_use_case"
tags
:
...
...
@@ -52,7 +52,7 @@ paths:
responses
:
'
200'
:
description
:
"
Successful
Request"
/
transactions/use_case/{use_case}
:
/
use_cases/{use_case}/transactions
:
get
:
operationId
:
"
routes.transactions.all_for_use_case"
tags
:
...
...
@@ -84,65 +84,3 @@ paths:
responses
:
'
200'
:
description
:
"
Successful
echo
of
request
data"
\ No newline at end of file
/trace
:
post
:
operationId
:
"
routes.blockchain_trace.post"
tags
:
-
"
Blockchain
Trace"
summary
:
"
Add
a
new
blockchain
trace
to
SMART"
description
:
"
Receives
a
new
blockchain
trace
to
store
in
SMART."
parameters
:
-
in
:
body
name
:
"
BlockchainTrace"
description
:
"
The
trace
to
be
added"
required
:
true
schema
:
$ref
:
"
#/definitions/BlockchainTrace"
responses
:
'
201'
:
description
:
"
Successful
operation"
'
400'
:
description
:
"
Invalid
input"
get
:
operationId
:
"
routes.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
:
type
:
"
object"
properties
:
TransactionId
:
type
:
string
format
:
uuid
Timestamp
:
type
:
"
string"
format
:
"
date-time"
ApplicationType
:
type
:
"
string"
TransactionFrom
:
type
:
"
string"
format
:
"
uuid"
TransactionTo
:
type
:
"
string"
format
:
"
uuid"
TransferredAsset
:
type
:
"
string"
ResourceIds
:
type
:
"
string"
ResourceMd5
:
type
:
"
string"
ResourceState
:
type
:
"
string"
Metadata
:
type
:
"
string"
\ No newline at end of file
src/transaction-hub-in/trace-retrieval-microservice/app/database/MongoRepository.py
deleted
100644 → 0
View file @
3414bdc1
import
pymongo
import
network_constants
as
netconst
from
database.MongoRepositoryBase
import
MongoRepositoryBase
class
MongoRepository
(
MongoRepositoryBase
):
def
__init__
(
self
):
super
()
.
__init__
(
netconst
.
TRACE_RETRIEVAL_DB_HOSTNAME
,
netconst
.
TRACE_RETRIEVAL_DB_PORT
,
'traceRetrievalDB'
)
self
.
_collection_name
=
'traces'
def
insert_trace
(
self
,
content
:
dict
):
super
()
.
insert_entry
(
self
.
_collection_name
,
content
)
def
get_traces
(
self
,
selection
:
dict
=
{},
projection
:
dict
=
{
'_'
:
0
})
->
pymongo
.
cursor
.
Cursor
:
return
super
()
.
get_entries
(
self
.
_collection_name
,
selection
,
projection
)
src/transaction-hub-in/trace-retrieval-microservice/app/messaging/MessageHandler.py
View file @
19cfc8fe
...
...
@@ -85,9 +85,12 @@ class MessageHandler:
def
_flatten_transaction
(
self
,
transaction
:
Dict
,
mappings
:
Dict
):
'''
takes the (possibly nested) dictionary and resolves the given paths
returns a map which is no longer nested with the keys of the
mappings parameter
Resolves all paths in [mappings] with the data from [transaction] and creates
a non-nested flattened element.
@params
transaction - Required: dictionary, that is arbitrarily deep nested
mappings - Required: contains string->path mappings, describing how the flattened object is built
'''
flattened
=
{}
...
...
@@ -115,13 +118,17 @@ class MessageHandler:
return
flattened
def
_fetch_schema_information
(
self
,
use_case
:
str
)
->
Dict
:
'''
Fetches the schema of the use-case from the business-logic microservice per REST.
@params
use_case - Required: string identifier for the use-case
'''
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'
print
(
f
"CALLING: {url}"
)
response
=
requests
.
get
(
url
,
verify
=
False
,
...
...
@@ -129,27 +136,31 @@ class MessageHandler:
headers
=
{
"Authorization"
:
f
"Bearer {jwt_token}"
}
)
print
(
f
"RESPONSE: {response.text}"
)
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
def
handle_blockchain_transaction
(
self
,
transaction_message
:
Dict
):
'''
Proccesses a blockchain transaction. The schema gets fetched from the business-logic microservice and a flattened
version then is created out of it.
@params
transaction_message - Required: data of the transaction. Has to contain the key 'ApplicationType' which stores the use-case.
'''
use_case
=
transaction_
data
[
"ApplicationType"
]
use_case
=
transaction_
message
[
"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
_message
)
return
mappings
=
data
[
"mappings"
]
flattened
=
self
.
_flatten_transaction
(
transaction_
data
,
mappings
)
flattened
=
self
.
_flatten_transaction
(
transaction_
message
,
mappings
)
transaction
=
Transaction
(
use_case
,
flattened
)
MessageHandler
.
_repository
.
add_transaction
(
transaction
)
...
...
@@ -161,7 +172,5 @@ class MessageHandler:
msg_string
=
json
.
dumps
(
msg
)
print
(
"OUT: "
+
msg_string
)
# inform semantic linking microservice
self
.
_message_sender
.
send_message
(
'datahub'
,
'semantic-linking'
,
msg_string
)
\ No newline at end of file
src/transaction-hub-in/trace-retrieval-microservice/app/routes/blockchain_trace.py
deleted
100644 → 0
View file @
3414bdc1
from
flask
import
request
,
Response
from
database.MongoRepository
import
MongoRepository
mongo_repo
=
MongoRepository
()
def
post
():
return
Response
(
response
=
'Use the RESTful Gateway instead'
,
status
=
405
)
def
get
():
return
list
(
mongo_repo
.
get_traces
(
projection
=
{
'_id'
:
0
}))
\ No newline at end of file
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