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
1aa36851
Commit
1aa36851
authored
Oct 07, 2019
by
Alexander Lercher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extracted database access logic
parent
48c4791d
Pipeline
#11
failed with stages
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
9 deletions
+31
-9
MongoRepositoryBase.py
modules/database/MongoRepositoryBase.py
+8
-7
MongoRepository.py
...ce-retrieval-microservice/app/database/MongoRepository.py
+21
-0
main.py
transaction-hub-in/trace-retrieval-microservice/app/main.py
+1
-1
blockchain_trace.py
...trace-retrieval-microservice/app/rest/blockchain_trace.py
+1
-1
No files found.
transaction-hub-in/trace-retrieval-microservice/app/db/MongoRepository
.py
→
modules/database/MongoRepositoryBase
.py
View file @
1aa36851
import
pymongo
import
pymongo
import
network_constants
as
netconst
import
network_constants
as
netconst
class
MongoRepository
:
class
MongoRepositoryBase
:
'''Base class to connect to, insert and read from a single MongoDB collection'''
# TODO extract to docker env var
# TODO extract to docker env var
_username
=
'root'
_username
=
'root'
_password
=
'root'
_password
=
'root'
...
@@ -9,18 +10,18 @@ class MongoRepository:
...
@@ -9,18 +10,18 @@ class MongoRepository:
_collection
:
pymongo
.
collection
.
Collection
=
None
_collection
:
pymongo
.
collection
.
Collection
=
None
_mongo_client
:
pymongo
.
MongoClient
=
None
_mongo_client
:
pymongo
.
MongoClient
=
None
def
__init__
(
self
,
username
=
_username
,
password
=
_password
):
def
__init__
(
self
,
database_name
,
collection_name
,
username
=
_username
,
password
=
_password
):
self
.
_mongo_client
=
pymongo
.
MongoClient
(
f
"mongodb://{username}:{password}@{netconst.MONGO_DB_HOSTNAME}:{netconst.MONGO_DB_PORT}/"
)
self
.
_mongo_client
=
pymongo
.
MongoClient
(
f
"mongodb://{username}:{password}@{netconst.MONGO_DB_HOSTNAME}:{netconst.MONGO_DB_PORT}/"
)
database
=
self
.
_mongo_client
[
'traceRetrievalDB'
]
database
=
self
.
_mongo_client
[
database_name
]
self
.
_collection
=
database
[
'traces'
]
self
.
_collection
=
database
[
collection_name
]
def
insert_
trace
(
self
,
content
:
dict
):
def
insert_
entry
(
self
,
content
:
dict
):
self
.
_collection
.
insert_one
(
content
)
self
.
_collection
.
insert_one
(
content
)
def
get_
trac
es
(
self
,
selection
:
dict
=
{},
projection
:
dict
=
{
'_'
:
0
})
->
pymongo
.
cursor
.
Cursor
:
def
get_
entri
es
(
self
,
selection
:
dict
=
{},
projection
:
dict
=
{
'_'
:
0
})
->
pymongo
.
cursor
.
Cursor
:
return
self
.
_collection
.
find
(
selection
,
projection
)
return
self
.
_collection
.
find
(
selection
,
projection
)
def
close_connection
(
self
):
def
close_connection
(
self
):
self
.
_mongo_client
.
close
()
self
.
_mongo_client
.
close
()
self
.
_collection
=
None
self
.
_mongo_client
=
None
self
.
_mongo_client
=
None
self
.
_collection
=
None
transaction-hub-in/trace-retrieval-microservice/app/database/MongoRepository.py
0 → 100644
View file @
1aa36851
import
pymongo
import
network_constants
as
netconst
from
database.MongoRepositoryBase
import
MongoRepositoryBase
class
MongoRepository
(
MongoRepositoryBase
):
# TODO extract to docker env var
_username
=
'root'
_password
=
'root'
_collection
:
pymongo
.
collection
.
Collection
=
None
_mongo_client
:
pymongo
.
MongoClient
=
None
def
__init__
(
self
,
username
=
_username
,
password
=
_password
):
super
()
.
__init__
(
'traceRetrievalDB'
,
'traces'
)
def
insert_trace
(
self
,
content
:
dict
):
super
()
.
insert_entry
(
content
)
def
get_traces
(
self
,
selection
:
dict
=
{},
projection
:
dict
=
{
'_'
:
0
})
->
pymongo
.
cursor
.
Cursor
:
return
super
()
.
get_entries
(
selection
,
projection
)
transaction-hub-in/trace-retrieval-microservice/app/main.py
View file @
1aa36851
...
@@ -14,7 +14,7 @@ LOGGER = logging.getLogger(__name__)
...
@@ -14,7 +14,7 @@ LOGGER = logging.getLogger(__name__)
#############################
#############################
import
connexion
import
connexion
from
d
b
.MongoRepository
import
MongoRepository
from
d
atabase
.MongoRepository
import
MongoRepository
from
messaging.MessageHandler
import
MessageHandler
from
messaging.MessageHandler
import
MessageHandler
from
messaging.ReconnectingMessageManager
import
ReconnectingMessageManager
from
messaging.ReconnectingMessageManager
import
ReconnectingMessageManager
...
...
transaction-hub-in/trace-retrieval-microservice/app/rest/blockchain_trace.py
View file @
1aa36851
from
flask
import
request
,
Response
from
flask
import
request
,
Response
from
d
b
.MongoRepository
import
MongoRepository
from
d
atabase
.MongoRepository
import
MongoRepository
mongo_repo
=
MongoRepository
()
mongo_repo
=
MongoRepository
()
...
...
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