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
49040105
Commit
49040105
authored
Sep 06, 2020
by
Herry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
businessLogic: fixed bugs in endpoints caused by prior refactoring
parent
7e74f79a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
48 additions
and
9 deletions
+48
-9
token_manager.py
src/modules/security/token_manager.py
+3
-0
schema_repository.py
...b/business-logic-microservice/app/db/schema_repository.py
+8
-6
use_case_repository.py
...business-logic-microservice/app/db/use_case_repository.py
+1
-1
layer.py
...ation-hub/business-logic-microservice/app/routes/layer.py
+21
-0
schema.py
...tion-hub/business-logic-microservice/app/routes/schema.py
+4
-0
use_case.py
...on-hub/business-logic-microservice/app/routes/use_case.py
+11
-2
No files found.
src/modules/security/token_manager.py
View file @
49040105
...
...
@@ -41,6 +41,9 @@ class TokenManager:
json
=
credentials
)
if
response
.
status_code
!=
200
:
raise
ValueError
(
f
"Server responded with ({response.status_code}): {response.text}"
)
data
=
json
.
loads
(
response
.
text
)
self
.
_token
=
data
[
"token"
]
...
...
src/participation-hub/business-logic-microservice/app/db/schema_repository.py
View file @
49040105
...
...
@@ -2,6 +2,7 @@
import
network_constants
as
netconst
from
database.MongoRepositoryBase
import
MongoRepositoryBase
from
db.entities.schema
import
Schema
from
db.use_case_repository
import
UseCaseRepository
import
pymongo
import
json
...
...
@@ -22,13 +23,12 @@ class SchemaRepository(MongoRepositoryBase):
return
[
Schema
.
from_serializable_dict
(
row
)
for
row
in
list
(
result
)]
def
add
(
self
,
schema
:
Schema
):
self
.
put_use_case
(
schema
.
use_case
)
super
()
.
insert_entry
(
self
.
_schema_collection
,
schema
.
to_serializable_dict
())
def
get_for_use_case
(
self
,
use_case
:
str
)
->
Schema
:
result
=
super
()
.
get_entries
(
self
.
_schema_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"use_case"
:
use_case
})
self
.
put
(
use_case
)
result
=
list
(
super
()
.
get_entries
(
self
.
_schema_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"use_case"
:
use_case
}))
result
=
list
(
result
)
if
len
(
result
)
>
1
:
raise
ValueError
(
"No more than 1 Schema allowed per use-case!"
)
...
...
@@ -38,12 +38,14 @@ class SchemaRepository(MongoRepositoryBase):
return
None
def
put
(
self
,
use_case
:
str
):
schema
=
self
.
get_for_use_case
(
use_case
)
result
=
list
(
super
()
.
get_entries
(
self
.
_schema_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"use_case"
:
use_case
})
)
if
schema
==
None
:
if
len
(
result
)
==
0
:
schema
=
Schema
(
use_case
,
mappings
=
{})
self
.
add
(
schema
)
else
:
schema
=
Schema
.
from_serializable_dict
(
result
[
0
])
return
schema
def
delete_for_use_case
(
self
,
use_case
:
str
):
...
...
src/participation-hub/business-logic-microservice/app/db/use_case_repository.py
View file @
49040105
...
...
@@ -31,7 +31,7 @@ class UseCaseRepository(MongoRepositoryBase):
collection
.
delete_many
({
"name"
:
name
})
def
put
(
self
,
use_case_name
:
str
):
use_cases
=
self
.
all
_use_cases
()
use_cases
=
self
.
all
()
existing_use_cases
=
list
(
filter
(
lambda
use_case
:
use_case
.
name
==
use_case_name
,
use_cases
))
...
...
src/participation-hub/business-logic-microservice/app/routes/layer.py
View file @
49040105
...
...
@@ -2,6 +2,7 @@
from
db.entities.layer_adapter
import
LayerAdapter
from
db.repository
import
Repository
from
db.schema_repository
import
SchemaRepository
from
db.use_case_repository
import
UseCaseRepository
from
services.layer_adapter_service
import
LayerAdapterService
import
json
...
...
@@ -9,6 +10,7 @@ from flask import Response, request
schema_repository
=
SchemaRepository
()
layer_repository
=
Repository
()
use_case_repository
=
UseCaseRepository
()
def
all
():
return
[
layer
.
to_serializable_dict
()
for
layer
in
layer_repository
.
all
()]
...
...
@@ -17,6 +19,7 @@ def get_all_for_use_case(use_case: str):
'''
get all layers assigned to the given use_case
'''
use_case_repository
.
put
(
use_case
)
return
[
layer
.
to_serializable_dict
()
for
layer
in
layer_repository
.
all_for_use_case
(
use_case
)]
def
add_complete
():
...
...
@@ -28,6 +31,7 @@ def add_complete():
if
"name"
not
in
data
or
"properties"
not
in
data
or
"cluster_properties"
not
in
data
or
"use_case"
not
in
data
:
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (name, properties, cluster_properties)"
)
use_case_repository
.
put
(
data
[
"use_case"
])
layer
=
layer_repository
.
one
(
data
[
"name"
],
data
[
"use_case"
])
if
layer
!=
None
:
...
...
@@ -55,6 +59,7 @@ def one(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository
.
put
(
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
...
...
@@ -70,6 +75,8 @@ def add_empty(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository
.
put
(
use_case
)
if
layer_repository
.
one
(
name
,
use_case
)
!=
None
:
return
Response
(
status
=
400
,
response
=
f
"Layer with name '{name}' already exists!"
)
...
...
@@ -84,6 +91,8 @@ def add_cluster_mapping(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository
.
put
(
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
...
...
@@ -109,6 +118,8 @@ def delete_cluster_mapping(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository
.
put
(
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
...
...
@@ -134,6 +145,8 @@ def add_mapping_for_all(use_case: str):
@params:
use_case - Required : String-identifier for the use-case
'''
use_case_repository
.
put
(
use_case
)
data
=
request
.
json
if
"internal"
not
in
data
:
...
...
@@ -166,6 +179,8 @@ def delete_mapping_for_all(use_case: str):
@params:
use_case - Required : String-identifier for the use-case
'''
use_case_repository
.
put
(
use_case
)
data
=
request
.
json
if
"internal"
not
in
data
:
...
...
@@ -190,6 +205,8 @@ def delete_mapping(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository
.
put
(
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
...
...
@@ -216,6 +233,8 @@ def add_mapping(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository
.
put
(
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
...
...
@@ -244,6 +263,8 @@ def delete_one(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository
.
put
(
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
...
...
src/participation-hub/business-logic-microservice/app/routes/schema.py
View file @
49040105
#global imports
from
db.entities.layer_adapter
import
LayerAdapter
from
db.schema_repository
import
SchemaRepository
from
db.use_case_repository
import
UseCaseRepository
from
services.layer_adapter_service
import
LayerAdapterService
import
json
from
flask
import
Response
,
request
use_case_repository
=
UseCaseRepository
()
schema_repository
=
SchemaRepository
()
def
all
():
return
[
schema
.
to_serializable_dict
()
for
schema
in
schema_repository
.
all
()]
def
get_for_use_case
(
use_case
:
str
):
use_case_repository
.
put
(
use_case
)
schema
=
schema_repository
.
get_for_use_case
(
use_case
)
if
schema
!=
None
:
...
...
@@ -30,6 +33,7 @@ def delete_for_use_case(use_case:str):
return
Response
(
status
=
200
)
def
add_mapping
(
use_case
:
str
):
use_case_repository
.
put
(
use_case
)
data
=
request
.
json
if
"internal"
not
in
data
or
"external"
not
in
data
:
...
...
src/participation-hub/business-logic-microservice/app/routes/use_case.py
View file @
49040105
from
db.entities.layer_adapter
import
LayerAdapter
from
db.use_case_repository
import
UseCaseRepository
from
db.repository
import
Repository
from
db.schema_repository
import
SchemaRepository
from
services.layer_adapter_service
import
LayerAdapterService
import
json
from
flask
import
Response
,
request
use_case_repository
=
UseCaseRepository
()
schema_repository
=
SchemaRepository
()
repository
=
Repository
()
def
all
():
return
[
adapter
.
to_serializable_dict
()
for
adapter
in
use_case_repository
.
all
()]
return
[
use_case
.
to_serializable_dict
()
for
use_case
in
use_case_repository
.
all
()]
def
delete_all
():
LayerAdapterService
.
delete_all
()
use_case_repository
.
delete_all
()
repository
.
delete_all
()
schema_repository
.
delete_all
()
return
Response
(
status
=
200
)
\ 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