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
7e36e1f2
Commit
7e36e1f2
authored
Aug 31, 2020
by
Manuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
businessLogic: refactored repositories
parent
53aba5c1
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
615 additions
and
766 deletions
+615
-766
swagger.yml
...n-hub/business-logic-microservice/app/configs/swagger.yml
+152
-217
swagger_local.yml
...business-logic-microservice/app/configs/swagger_local.yml
+152
-195
table.py
...-hub/business-logic-microservice/app/db/entities/table.py
+12
-0
layer_repository.py
...ub/business-logic-microservice/app/db/layer_repository.py
+23
-0
repository.py
...tion-hub/business-logic-microservice/app/db/repository.py
+16
-64
schema_repository.py
...b/business-logic-microservice/app/db/schema_repository.py
+59
-0
use_case_repository.py
...business-logic-microservice/app/db/use_case_repository.py
+41
-0
layer.py
...ation-hub/business-logic-microservice/app/routes/layer.py
+81
-160
schema.py
...tion-hub/business-logic-microservice/app/routes/schema.py
+47
-0
use_case.py
...on-hub/business-logic-microservice/app/routes/use_case.py
+15
-0
layer_adapter_service.py
...-logic-microservice/app/services/layer_adapter_service.py
+17
-130
No files found.
src/participation-hub/business-logic-microservice/app/configs/swagger.yml
View file @
7e36e1f2
...
@@ -15,43 +15,37 @@ produces:
...
@@ -15,43 +15,37 @@ produces:
basePath
:
"
/api"
basePath
:
"
/api"
paths
:
paths
:
/use-cases
:
/use-cases
:
delete
:
get
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.
layer.delete_uses_cases
"
operationId
:
"
routes.
use_case.all
"
tags
:
tags
:
-
"
Use-Cases"
-
"
Use-Cases"
summary
:
"
Delete
all
use-c
ases"
summary
:
"
Retrieves
all
Use-C
ases"
description
:
"
Delete
all
use-c
ases"
description
:
"
Retrieves
all
Use-C
ases"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
delete
:
operationId
:
"
routes.use_case.delete_all"
paths
:
tags
:
/use-cases/{use_case}/schema/mapping
:
-
"
Use-Cases"
put
:
summary
:
"
Delete
all
Use-Cases"
description
:
"
Delete
all
Use-Cases"
responses
:
'
200'
:
description
:
"
Successful
Request"
/schemas
:
get
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.
layer.add_mapping_to_schema
"
operationId
:
"
routes.
schema.all
"
tags
:
tags
:
-
"
Schemas"
-
"
Schemas"
summary
:
"
Adds
an
attribute
mapping
to
the
Schema
of
the
Use-Case"
summary
:
"
Get
all
Use-Cases"
description
:
"
Adds
an
attribute
mapping
to
the
each
Layer
of
the
Use-Case"
description
:
"
Get
all
Use-Cases"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Schema
belongs
to"
required
:
true
type
:
"
string"
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
$ref
:
'
#/definitions/Mapping'
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
...
@@ -59,7 +53,7 @@ paths:
...
@@ -59,7 +53,7 @@ paths:
get
:
get
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.
layer.schema
_for_use_case"
operationId
:
"
routes.
schema.get
_for_use_case"
tags
:
tags
:
-
"
Schemas"
-
"
Schemas"
summary
:
"
Get
the
Schema
assigned
to
the
Use-Case"
summary
:
"
Get
the
Schema
assigned
to
the
Use-Case"
...
@@ -78,7 +72,7 @@ paths:
...
@@ -78,7 +72,7 @@ paths:
delete
:
delete
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.
layer.delete_schema
_for_use_case"
operationId
:
"
routes.
schema.delete
_for_use_case"
tags
:
tags
:
-
"
Schemas"
-
"
Schemas"
summary
:
"
Delete
the
Schema
assigned
to
the
Use-Case"
summary
:
"
Delete
the
Schema
assigned
to
the
Use-Case"
...
@@ -94,41 +88,71 @@ paths:
...
@@ -94,41 +88,71 @@ paths:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
404'
:
'
404'
:
description
:
"
Schema
does
not
exist"
description
:
"
Schema
does
not
exist"
/
schemas
:
/
use-cases/{use_case}/schema/mapping
:
ge
t
:
pu
t
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.
layer.all_schemas
"
operationId
:
"
routes.
schema.add_mapping
"
tags
:
tags
:
-
"
Schemas"
-
"
Schemas"
summary
:
"
Get
all
Use-Cases"
summary
:
"
Adds
an
attribute
mapping
to
the
Schema
of
the
Use-Case"
description
:
"
Get
all
Use-Cases"
description
:
"
Adds
an
attribute
mapping
to
the
each
Layer
of
the
Use-Case"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Schema
belongs
to"
required
:
true
type
:
"
string"
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
$ref
:
'
#/definitions/Mapping'
responses
:
'
200'
:
description
:
"
Successful
Request"
/layers
:
get
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layer.all"
tags
:
-
"
Layers"
summary
:
"
Retrieve
all
Layers
from
the
DB"
description
:
"
Retrieve
all
Layers
from
the
DB"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
/use-cases
:
delete
:
delete
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.layer.delete_
uses_case
s"
operationId
:
"
routes.layer.delete_
all_layer
s"
tags
:
tags
:
-
"
Use-Case
s"
-
"
Layer
s"
summary
:
"
Delete
all
Use-Cases
"
summary
:
"
Delete
all
Layers
from
the
DB
"
description
:
"
Delete
all
Use-Cases
"
description
:
"
Delete
all
Layers
from
the
DB
"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
ge
t
:
pos
t
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.layer.
use_cases
"
operationId
:
"
routes.layer.
add_complete
"
tags
:
tags
:
-
"
Use-Cases"
-
"
Layers"
summary
:
"
Retrieves
all
Use-Cases"
summary
:
"
Adds
a
complete
Layer
(including
its
properties)
to
the
DB"
description
:
"
Retrieves
all
Use-Cases"
description
:
"
Adds
a
complete
Layer
(including
its
properties)
to
the
DB"
parameters
:
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
$ref
:
'
#/definitions/Layer'
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
400'
:
description
:
"
Bad
structure
in
request
body
or
Layer
already
exists"
/use-cases/{use_case}/layers
:
/use-cases/{use_case}/layers
:
get
:
get
:
security
:
security
:
...
@@ -149,19 +173,67 @@ paths:
...
@@ -149,19 +173,67 @@ paths:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
404'
:
'
404'
:
description
:
"
Use-Case
does
not
exist"
description
:
"
Use-Case
does
not
exist"
/use-cases/{use_case}/cluster-mapping/layers/{name}
:
/use-cases/{use_case}/layers/{name}
:
get
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layer.one"
tags
:
-
"
Layers"
summary
:
"
Retrieve
one
Layer
from
the
DB"
description
:
"
Retrieve
one
Layer
from
the
DB"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
required
:
true
type
:
"
string"
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
Layer"
required
:
true
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
Request"
'
404'
:
description
:
"
Layer
does
not
exist"
post
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layer.add_empty"
tags
:
-
"
Layers"
summary
:
"
Adds
an
empty
Layer
to
the
DB"
description
:
"
Adds
an
empty
Layer
to
the
DB"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
required
:
true
type
:
"
string"
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
new
Layer"
required
:
true
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
Request"
'
400'
:
description
:
"
Layer
already
exists"
delete
:
delete
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.layer.delete_
cluster_mapping
"
operationId
:
"
routes.layer.delete_
one
"
tags
:
tags
:
-
"
Layers"
-
"
Layers"
summary
:
"
Delete
s
a
cluster-attribute
mapping
from
the
selected
layer
"
summary
:
"
Delete
one
Layer
from
the
DB
"
description
:
"
Delete
s
a
cluster-attribute
mapping
from
the
selected
layer
"
description
:
"
Delete
one
Layer
from
the
DB
"
parameters
:
parameters
:
-
name
:
"
name"
-
name
:
"
name"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
layer
(must
exist)
"
description
:
"
Name
of
the
layer
to
delete
"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
name
:
"
use_case"
-
name
:
"
use_case"
...
@@ -169,23 +241,12 @@ paths:
...
@@ -169,23 +241,12 @@ paths:
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
type
:
object
properties
:
attribute
:
type
:
string
example
:
"
end_time"
description
:
"
Internal
name
of
the
attribute"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
404'
:
'
404'
:
description
:
"
Layer
does
not
exist"
description
:
"
Layer
does
not
exist"
'
400'
:
/use-cases/{use_case}/cluster-mapping/layers/{name}
:
description
:
"
Field
in
request
is
missing
or
attribute
does
not
exist
in
the
Layer"
put
:
put
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
...
@@ -195,14 +256,14 @@ paths:
...
@@ -195,14 +256,14 @@ paths:
summary
:
"
Selects
a
property
of
the
Layer
as
cluster
property"
summary
:
"
Selects
a
property
of
the
Layer
as
cluster
property"
description
:
"
Selects
a
property
of
the
Layer
as
cluster
property"
description
:
"
Selects
a
property
of
the
Layer
as
cluster
property"
parameters
:
parameters
:
-
name
:
"
nam
e"
-
name
:
"
use_cas
e"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
layer
(must
exist)
"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to
"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
name
:
"
use_cas
e"
-
name
:
"
nam
e"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to
"
description
:
"
Name
of
the
layer
(must
exist)
"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
-
in
:
body
...
@@ -222,19 +283,23 @@ paths:
...
@@ -222,19 +283,23 @@ paths:
description
:
"
Layer
does
not
exist"
description
:
"
Layer
does
not
exist"
'
400'
:
'
400'
:
description
:
"
Field
in
request
is
missing
or
attribute
does
not
exist
in
the
Layer"
description
:
"
Field
in
request
is
missing
or
attribute
does
not
exist
in
the
Layer"
/use-cases/{use_case}/layers/use-case
:
delete
:
put
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.layer.
update_use_case_for_all
"
operationId
:
"
routes.layer.
delete_cluster_mapping
"
tags
:
tags
:
-
"
Layers"
-
"
Layers"
summary
:
"
Update
the
Use-Case
of
all
Layers
belonging
to
the
Use-Case
in
the
query
"
summary
:
"
Deletes
a
cluster-attribute
mapping
from
the
selected
layer
"
description
:
"
Update
the
Use-Case
of
all
Layers
belonging
to
the
Use-Case
in
the
query
"
description
:
"
Deletes
a
cluster-attribute
mapping
from
the
selected
layer
"
parameters
:
parameters
:
-
name
:
"
use_case"
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to"
required
:
true
type
:
"
string"
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
layer
(must
exist)"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
-
in
:
body
...
@@ -243,14 +308,17 @@ paths:
...
@@ -243,14 +308,17 @@ paths:
schema
:
schema
:
type
:
object
type
:
object
properties
:
properties
:
use_cas
e
:
attribut
e
:
type
:
string
type
:
string
example
:
"
air-bnb"
example
:
"
end_time"
description
:
"
Internal
name
of
the
attribute"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
404'
:
description
:
"
Layer
does
not
exist"
'
400'
:
'
400'
:
description
:
"
Field
in
request
is
missing"
description
:
"
Field
in
request
is
missing
or
attribute
does
not
exist
in
the
Layer
"
/use-cases/{use_case}/layers/mapping
:
/use-cases/{use_case}/layers/mapping
:
put
:
put
:
security
:
security
:
...
@@ -305,37 +373,6 @@ paths:
...
@@ -305,37 +373,6 @@ paths:
'
400'
:
'
400'
:
description
:
"
Field
in
request
is
missing"
description
:
"
Field
in
request
is
missing"
/use-cases/{use_case}/layers/{name}/mapping
:
/use-cases/{use_case}/layers/{name}/mapping
:
delete
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layer.delete_mapping"
tags
:
-
"
Layers"
summary
:
"
Deletes
an
attribute
mapping
from
the
selected
Layer"
description
:
"
Deletes
an
attribute
mapping
from
the
selected
Layer"
parameters
:
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
Layer
(must
exist)"
required
:
true
type
:
"
string"
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
required
:
true
type
:
"
string"
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
$ref
:
'
#/definitions/LayerMapping'
responses
:
'
200'
:
description
:
"
Successful
Request"
'
404'
:
description
:
"
Layer
does
not
exist"
'
400'
:
description
:
"
Field
in
request
is
missing"
put
:
put
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
...
@@ -345,14 +382,14 @@ paths:
...
@@ -345,14 +382,14 @@ paths:
summary
:
"
Adds
an
attribute
mapping
to
the
selected
Layer"
summary
:
"
Adds
an
attribute
mapping
to
the
selected
Layer"
description
:
"
Adds
an
attribute
mapping
to
the
selected
Layer"
description
:
"
Adds
an
attribute
mapping
to
the
selected
Layer"
parameters
:
parameters
:
-
name
:
"
nam
e"
-
name
:
"
use_cas
e"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Layer
(must
exist)
"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to
"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
name
:
"
use_cas
e"
-
name
:
"
nam
e"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to
"
description
:
"
Name
of
the
Layer
(must
exist)
"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
-
in
:
body
...
@@ -367,139 +404,37 @@ paths:
...
@@ -367,139 +404,37 @@ paths:
description
:
"
Layer
does
not
exist"
description
:
"
Layer
does
not
exist"
'
400'
:
'
400'
:
description
:
"
Field
in
request
is
missing"
description
:
"
Field
in
request
is
missing"
/use-cases/{use_case}/layers/{name}
:
delete
:
get
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layer.one"
tags
:
-
"
Layers"
summary
:
"
Retrieve
one
Layer
from
the
DB"
description
:
"
Retrieve
one
Layer
from
the
DB"
parameters
:
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
Layer"
required
:
true
type
:
"
string"
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
required
:
true
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
Request"
'
404'
:
description
:
"
Layer
does
not
exist"
post
:
security
:
security
:
-
JwtRegular
:
[]
-
JwtRegular
:
[]
operationId
:
"
routes.layer.
add
"
operationId
:
"
routes.layer.
delete_mapping
"
tags
:
tags
:
-
"
Layers"
-
"
Layers"
summary
:
"
Adds
an
empty
Layer
to
the
DB
"
summary
:
"
Deletes
an
attribute
mapping
from
the
selected
Layer
"
description
:
"
Adds
an
empty
Layer
to
the
DB
"
description
:
"
Deletes
an
attribute
mapping
from
the
selected
Layer
"
parameters
:
parameters
:
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
new
Layer"
required
:
true
type
:
"
string"
-
name
:
"
use_case"
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
Request"
'
400'
:
description
:
"
Layer
already
exists"
delete
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layer.delete_one"
tags
:
-
"
Layers"
summary
:
"
Delete
one
Layer
from
the
DB"
description
:
"
Delete
one
Layer
from
the
DB"
parameters
:
-
name
:
"
name"
-
name
:
"
name"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
layer
to
delete"
description
:
"
Name
of
the
Layer
(must
exist)"
required
:
true
type
:
"
string"
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
Request"
'
404'
:
description
:
"
Layer
does
not
exist"
/layers
:
get
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layer.all"
tags
:
-
"
Layers"
summary
:
"
Retrieve
all
Layers
from
the
DB"
description
:
"
Retrieve
all
Layers
from
the
DB"
responses
:
'
200'
:
description
:
"
Successful
Request"
delete
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layer.delete_all_layers"
tags
:
-
"
Layers"
summary
:
"
Delete
all
Layers
from
the
DB"
description
:
"
Delete
all
Layers
from
the
DB"
responses
:
'
200'
:
description
:
"
Successful
Request"
post
:
security
:
-
JwtRegular
:
[]
operationId
:
"
routes.layer.add_complete"
tags
:
-
"
Layers"
summary
:
"
Adds
a
complete
Layer
(including
its
properties)
to
the
DB"
description
:
"
Adds
a
complete
Layer
(including
its
properties)
to
the
DB"
parameters
:
-
in
:
body
-
in
:
body
name
:
"
Object"
name
:
"
Object"
required
:
true
required
:
true
schema
:
schema
:
$ref
:
'
#/definitions/Layer'
$ref
:
'
#/definitions/Layer
Mapping
'
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
404'
:
description
:
"
Layer
does
not
exist"
'
400'
:
'
400'
:
description
:
"
Bad
structure
in
request
body
or
Layer
already
exists"
description
:
"
Field
in
request
is
missing"
/debug
:
post
:
security
:
-
JwtRegular
:
[]
operationId
:
"
debug.echo"
tags
:
-
"
Echo"
summary
:
"
Echo
function
for
debugging
purposes"
description
:
"
Echoes
the
input
back
to
the
caller."
parameters
:
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
type
:
object
responses
:
'
200'
:
description
:
"
Successful
echo
of
request
data"
definitions
:
definitions
:
LayerMapping
:
LayerMapping
:
...
...
src/participation-hub/business-logic-microservice/app/configs/swagger_local.yml
View file @
7e36e1f2
...
@@ -12,30 +12,38 @@ produces:
...
@@ -12,30 +12,38 @@ produces:
basePath
:
"
/api"
basePath
:
"
/api"
paths
:
paths
:
/use-cases/{use_case}/schema/mapping
:
/use-cases
:
put
:
get
:
operationId
:
"
routes.layer.add_mapping_to_schema"
operationId
:
"
routes.use_case.all"
tags
:
-
"
Use-Cases"
summary
:
"
Retrieves
all
Use-Cases"
description
:
"
Retrieves
all
Use-Cases"
responses
:
'
200'
:
description
:
"
Successful
Request"
delete
:
operationId
:
"
routes.use_case.delete_all"
tags
:
-
"
Use-Cases"
summary
:
"
Delete
all
Use-Cases"
description
:
"
Delete
all
Use-Cases"
responses
:
'
200'
:
description
:
"
Successful
Request"
/schemas
:
get
:
operationId
:
"
routes.schema.all"
tags
:
tags
:
-
"
Schemas"
-
"
Schemas"
summary
:
"
Adds
an
attribute
mapping
to
the
Schema
of
the
Use-Case"
summary
:
"
Get
all
Use-Cases"
description
:
"
Adds
an
attribute
mapping
to
the
each
Layer
of
the
Use-Case"
description
:
"
Get
all
Use-Cases"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Schema
belongs
to"
required
:
true
type
:
"
string"
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
$ref
:
'
#/definitions/Mapping'
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
/use-cases/{use_case}/schema
:
/use-cases/{use_case}/schema
:
get
:
get
:
operationId
:
"
routes.
layer.schema
_for_use_case"
operationId
:
"
routes.
schema.get
_for_use_case"
tags
:
tags
:
-
"
Schemas"
-
"
Schemas"
summary
:
"
Get
the
Schema
assigned
to
the
Use-Case"
summary
:
"
Get
the
Schema
assigned
to
the
Use-Case"
...
@@ -52,7 +60,7 @@ paths:
...
@@ -52,7 +60,7 @@ paths:
'
404'
:
'
404'
:
description
:
"
Schema
does
not
exist"
description
:
"
Schema
does
not
exist"
delete
:
delete
:
operationId
:
"
routes.
layer.delete_schema
_for_use_case"
operationId
:
"
routes.
schema.delete
_for_use_case"
tags
:
tags
:
-
"
Schemas"
-
"
Schemas"
summary
:
"
Delete
the
Schema
assigned
to
the
Use-Case"
summary
:
"
Delete
the
Schema
assigned
to
the
Use-Case"
...
@@ -68,35 +76,63 @@ paths:
...
@@ -68,35 +76,63 @@ paths:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
404'
:
'
404'
:
description
:
"
Schema
does
not
exist"
description
:
"
Schema
does
not
exist"
/
schemas
:
/
use-cases/{use_case}/schema/mapping
:
ge
t
:
pu
t
:
operationId
:
"
routes.
layer.all_schemas
"
operationId
:
"
routes.
schema.add_mapping
"
tags
:
tags
:
-
"
Schemas"
-
"
Schemas"
summary
:
"
Get
all
Use-Cases"
summary
:
"
Adds
an
attribute
mapping
to
the
Schema
of
the
Use-Case"
description
:
"
Get
all
Use-Cases"
description
:
"
Adds
an
attribute
mapping
to
the
each
Layer
of
the
Use-Case"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Schema
belongs
to"
required
:
true
type
:
"
string"
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
$ref
:
'
#/definitions/Mapping'
responses
:
'
200'
:
description
:
"
Successful
Request"
/layers
:
get
:
operationId
:
"
routes.layer.all"
tags
:
-
"
Layers"
summary
:
"
Retrieve
all
Layers
from
the
DB"
description
:
"
Retrieve
all
Layers
from
the
DB"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
/use-cases
:
delete
:
delete
:
operationId
:
"
routes.layer.delete_
uses_case
s"
operationId
:
"
routes.layer.delete_
all_layer
s"
tags
:
tags
:
-
"
Use-Case
s"
-
"
Layer
s"
summary
:
"
Delete
all
Use-Cases
"
summary
:
"
Delete
all
Layers
from
the
DB
"
description
:
"
Delete
all
Use-Cases
"
description
:
"
Delete
all
Layers
from
the
DB
"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
ge
t
:
pos
t
:
operationId
:
"
routes.layer.
use_cases
"
operationId
:
"
routes.layer.
add_complete
"
tags
:
tags
:
-
"
Use-Cases"
-
"
Layers"
summary
:
"
Retrieves
all
Use-Cases"
summary
:
"
Adds
a
complete
Layer
(including
its
properties)
to
the
DB"
description
:
"
Retrieves
all
Use-Cases"
description
:
"
Adds
a
complete
Layer
(including
its
properties)
to
the
DB"
parameters
:
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
$ref
:
'
#/definitions/Layer'
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
400'
:
description
:
"
Bad
structure
in
request
body
or
Layer
already
exists"
/use-cases/{use_case}/layers
:
/use-cases/{use_case}/layers
:
get
:
get
:
operationId
:
"
routes.layer.get_all_for_use_case"
operationId
:
"
routes.layer.get_all_for_use_case"
...
@@ -115,17 +151,61 @@ paths:
...
@@ -115,17 +151,61 @@ paths:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
404'
:
'
404'
:
description
:
"
Use-Case
does
not
exist"
description
:
"
Use-Case
does
not
exist"
/use-cases/{use_case}/cluster-mapping/layers/{name}
:
/use-cases/{use_case}/layers/{name}
:
get
:
operationId
:
"
routes.layer.one"
tags
:
-
"
Layers"
summary
:
"
Retrieve
one
Layer
from
the
DB"
description
:
"
Retrieve
one
Layer
from
the
DB"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
required
:
true
type
:
"
string"
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
Layer"
required
:
true
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
Request"
'
404'
:
description
:
"
Layer
does
not
exist"
post
:
operationId
:
"
routes.layer.add_empty"
tags
:
-
"
Layers"
summary
:
"
Adds
an
empty
Layer
to
the
DB"
description
:
"
Adds
an
empty
Layer
to
the
DB"
parameters
:
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
required
:
true
type
:
"
string"
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
new
Layer"
required
:
true
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
Request"
'
400'
:
description
:
"
Layer
already
exists"
delete
:
delete
:
operationId
:
"
routes.layer.delete_
cluster_mapping
"
operationId
:
"
routes.layer.delete_
one
"
tags
:
tags
:
-
"
Layers"
-
"
Layers"
summary
:
"
Delete
s
a
cluster-attribute
mapping
from
the
selected
layer
"
summary
:
"
Delete
one
Layer
from
the
DB
"
description
:
"
Delete
s
a
cluster-attribute
mapping
from
the
selected
layer
"
description
:
"
Delete
one
Layer
from
the
DB
"
parameters
:
parameters
:
-
name
:
"
name"
-
name
:
"
name"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
layer
(must
exist)
"
description
:
"
Name
of
the
layer
to
delete
"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
name
:
"
use_case"
-
name
:
"
use_case"
...
@@ -133,23 +213,12 @@ paths:
...
@@ -133,23 +213,12 @@ paths:
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
type
:
object
properties
:
attribute
:
type
:
string
example
:
"
end_time"
description
:
"
Internal
name
of
the
attribute"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
404'
:
'
404'
:
description
:
"
Layer
does
not
exist"
description
:
"
Layer
does
not
exist"
'
400'
:
/use-cases/{use_case}/cluster-mapping/layers/{name}
:
description
:
"
Field
in
request
is
missing
or
attribute
does
not
exist
in
the
Layer"
put
:
put
:
operationId
:
"
routes.layer.add_cluster_mapping"
operationId
:
"
routes.layer.add_cluster_mapping"
tags
:
tags
:
...
@@ -157,14 +226,14 @@ paths:
...
@@ -157,14 +226,14 @@ paths:
summary
:
"
Selects
a
property
of
the
Layer
as
cluster
property"
summary
:
"
Selects
a
property
of
the
Layer
as
cluster
property"
description
:
"
Selects
a
property
of
the
Layer
as
cluster
property"
description
:
"
Selects
a
property
of
the
Layer
as
cluster
property"
parameters
:
parameters
:
-
name
:
"
nam
e"
-
name
:
"
use_cas
e"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
layer
(must
exist)
"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to
"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
name
:
"
use_cas
e"
-
name
:
"
nam
e"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to
"
description
:
"
Name
of
the
layer
(must
exist)
"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
-
in
:
body
...
@@ -184,17 +253,21 @@ paths:
...
@@ -184,17 +253,21 @@ paths:
description
:
"
Layer
does
not
exist"
description
:
"
Layer
does
not
exist"
'
400'
:
'
400'
:
description
:
"
Field
in
request
is
missing
or
attribute
does
not
exist
in
the
Layer"
description
:
"
Field
in
request
is
missing
or
attribute
does
not
exist
in
the
Layer"
/use-cases/{use_case}/layers/use-case
:
delete
:
put
:
operationId
:
"
routes.layer.delete_cluster_mapping"
operationId
:
"
routes.layer.update_use_case_for_all"
tags
:
tags
:
-
"
Layers"
-
"
Layers"
summary
:
"
Update
the
Use-Case
of
all
Layers
belonging
to
the
Use-Case
in
the
query
"
summary
:
"
Deletes
a
cluster-attribute
mapping
from
the
selected
layer
"
description
:
"
Update
the
Use-Case
of
all
Layers
belonging
to
the
Use-Case
in
the
query
"
description
:
"
Deletes
a
cluster-attribute
mapping
from
the
selected
layer
"
parameters
:
parameters
:
-
name
:
"
use_case"
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to"
required
:
true
type
:
"
string"
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
layer
(must
exist)"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
-
in
:
body
...
@@ -203,14 +276,17 @@ paths:
...
@@ -203,14 +276,17 @@ paths:
schema
:
schema
:
type
:
object
type
:
object
properties
:
properties
:
use_cas
e
:
attribut
e
:
type
:
string
type
:
string
example
:
"
air-bnb"
example
:
"
end_time"
description
:
"
Internal
name
of
the
attribute"
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
404'
:
description
:
"
Layer
does
not
exist"
'
400'
:
'
400'
:
description
:
"
Field
in
request
is
missing"
description
:
"
Field
in
request
is
missing
or
attribute
does
not
exist
in
the
Layer
"
/use-cases/{use_case}/layers/mapping
:
/use-cases/{use_case}/layers/mapping
:
put
:
put
:
operationId
:
"
routes.layer.add_mapping_for_all"
operationId
:
"
routes.layer.add_mapping_for_all"
...
@@ -261,35 +337,6 @@ paths:
...
@@ -261,35 +337,6 @@ paths:
'
400'
:
'
400'
:
description
:
"
Field
in
request
is
missing"
description
:
"
Field
in
request
is
missing"
/use-cases/{use_case}/layers/{name}/mapping
:
/use-cases/{use_case}/layers/{name}/mapping
:
delete
:
operationId
:
"
routes.layer.delete_mapping"
tags
:
-
"
Layers"
summary
:
"
Deletes
an
attribute
mapping
from
the
selected
Layer"
description
:
"
Deletes
an
attribute
mapping
from
the
selected
Layer"
parameters
:
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
Layer
(must
exist)"
required
:
true
type
:
"
string"
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
required
:
true
type
:
"
string"
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
$ref
:
'
#/definitions/LayerMapping'
responses
:
'
200'
:
description
:
"
Successful
Request"
'
404'
:
description
:
"
Layer
does
not
exist"
'
400'
:
description
:
"
Field
in
request
is
missing"
put
:
put
:
operationId
:
"
routes.layer.add_mapping"
operationId
:
"
routes.layer.add_mapping"
tags
:
tags
:
...
@@ -297,14 +344,14 @@ paths:
...
@@ -297,14 +344,14 @@ paths:
summary
:
"
Adds
an
attribute
mapping
to
the
selected
Layer"
summary
:
"
Adds
an
attribute
mapping
to
the
selected
Layer"
description
:
"
Adds
an
attribute
mapping
to
the
selected
Layer"
description
:
"
Adds
an
attribute
mapping
to
the
selected
Layer"
parameters
:
parameters
:
-
name
:
"
nam
e"
-
name
:
"
use_cas
e"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Layer
(must
exist)
"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to
"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
name
:
"
use_cas
e"
-
name
:
"
nam
e"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to
"
description
:
"
Name
of
the
Layer
(must
exist)
"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
-
in
:
body
-
in
:
body
...
@@ -319,125 +366,35 @@ paths:
...
@@ -319,125 +366,35 @@ paths:
description
:
"
Layer
does
not
exist"
description
:
"
Layer
does
not
exist"
'
400'
:
'
400'
:
description
:
"
Field
in
request
is
missing"
description
:
"
Field
in
request
is
missing"
/use-cases/{use_case}/layers/{name}
:
delete
:
get
:
operationId
:
"
routes.layer.delete_mapping"
operationId
:
"
routes.layer.one"
tags
:
-
"
Layers"
summary
:
"
Retrieve
one
Layer
from
the
DB"
description
:
"
Retrieve
one
Layer
from
the
DB"
parameters
:
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
Layer"
required
:
true
type
:
"
string"
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
required
:
true
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
Request"
'
404'
:
description
:
"
Layer
does
not
exist"
post
:
operationId
:
"
routes.layer.add"
tags
:
tags
:
-
"
Layers"
-
"
Layers"
summary
:
"
Adds
an
empty
Layer
to
the
DB
"
summary
:
"
Deletes
an
attribute
mapping
from
the
selected
Layer
"
description
:
"
Adds
an
empty
Layer
to
the
DB
"
description
:
"
Deletes
an
attribute
mapping
from
the
selected
Layer
"
parameters
:
parameters
:
-
name
:
"
name"
in
:
"
path"
description
:
"
Name
of
the
new
Layer"
required
:
true
type
:
"
string"
-
name
:
"
use_case"
-
name
:
"
use_case"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
description
:
"
Name
of
the
Use-Case
the
Layer
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
Request"
'
400'
:
description
:
"
Layer
already
exists"
delete
:
operationId
:
"
routes.layer.delete_one"
tags
:
-
"
Layers"
summary
:
"
Delete
one
Layer
from
the
DB"
description
:
"
Delete
one
Layer
from
the
DB"
parameters
:
-
name
:
"
name"
-
name
:
"
name"
in
:
"
path"
in
:
"
path"
description
:
"
Name
of
the
layer
to
delete"
description
:
"
Name
of
the
Layer
(must
exist)"
required
:
true
type
:
"
string"
-
name
:
"
use_case"
in
:
"
path"
description
:
"
Name
of
the
Use-Case
the
layer
belongs
to"
required
:
true
required
:
true
type
:
"
string"
type
:
"
string"
responses
:
'
200'
:
description
:
"
Successful
Request"
'
404'
:
description
:
"
Layer
does
not
exist"
/layers
:
get
:
operationId
:
"
routes.layer.all"
tags
:
-
"
Layers"
summary
:
"
Retrieve
all
Layers
from
the
DB"
description
:
"
Retrieve
all
Layers
from
the
DB"
responses
:
'
200'
:
description
:
"
Successful
Request"
delete
:
operationId
:
"
routes.layer.delete_all_layers"
tags
:
-
"
Layers"
summary
:
"
Delete
all
Layers
from
the
DB"
description
:
"
Delete
all
Layers
from
the
DB"
responses
:
'
200'
:
description
:
"
Successful
Request"
post
:
operationId
:
"
routes.layer.add_complete"
tags
:
-
"
Layers"
summary
:
"
Adds
a
complete
Layer
(including
its
properties)
to
the
DB"
description
:
"
Adds
a
complete
Layer
(including
its
properties)
to
the
DB"
parameters
:
-
in
:
body
-
in
:
body
name
:
"
Object"
name
:
"
Object"
required
:
true
required
:
true
schema
:
schema
:
$ref
:
'
#/definitions/Layer'
$ref
:
'
#/definitions/Layer
Mapping
'
responses
:
responses
:
'
200'
:
'
200'
:
description
:
"
Successful
Request"
description
:
"
Successful
Request"
'
404'
:
description
:
"
Layer
does
not
exist"
'
400'
:
'
400'
:
description
:
"
Bad
structure
in
request
body
or
Layer
already
exists"
description
:
"
Field
in
request
is
missing"
/debug
:
post
:
operationId
:
"
debug.echo"
tags
:
-
"
Echo"
summary
:
"
Echo
function
for
debugging
purposes"
description
:
"
Echoes
the
input
back
to
the
caller."
parameters
:
-
in
:
body
name
:
"
Object"
required
:
true
schema
:
type
:
object
responses
:
'
200'
:
description
:
"
Successful
echo
of
request
data"
definitions
:
definitions
:
LayerMapping
:
LayerMapping
:
...
...
src/participation-hub/business-logic-microservice/app/db/entities/table.py
0 → 100644
View file @
7e36e1f2
from
typing
import
Dict
class
Table
:
def
__init__
(
self
,
name
):
self
.
name
=
name
def
to_serializable_dict
(
self
)
->
Dict
:
return
{
"name"
:
self
.
name
}
@
staticmethod
def
from_serializable_dict
(
data
:
Dict
):
return
Table
(
data
[
"name"
])
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/db/layer_repository.py
0 → 100644
View file @
7e36e1f2
# global imports (dont't worry, red is normal)
import
network_constants
as
netconst
from
database.MongoRepositoryBase
import
MongoRepositoryBase
from
db.entities.table
import
Table
import
pymongo
import
json
from
typing
import
List
,
Dict
class
TableRepository
(
MongoRepositoryBase
):
'''This is a repository for MongoDb.'''
def
__init__
(
self
):
super
()
.
__init__
(
netconst
.
BUSINESS_LOGIC_DB_HOSTNAME
,
netconst
.
BUSINESS_LOGIC_DB_PORT
,
'rest-gateway-db'
)
self
.
_table_collection
=
'tables'
def
add_one
(
self
,
table
:
Table
):
super
()
.
insert_entry
(
self
.
_table_collection
,
table
.
to_serializable_dict
())
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/db/repository.py
View file @
7e36e1f2
...
@@ -3,7 +3,6 @@ import network_constants as netconst
...
@@ -3,7 +3,6 @@ import network_constants as netconst
from
database.MongoRepositoryBase
import
MongoRepositoryBase
from
database.MongoRepositoryBase
import
MongoRepositoryBase
from
db.entities.layer_adapter
import
LayerAdapter
from
db.entities.layer_adapter
import
LayerAdapter
from
db.entities.use_case
import
UseCase
from
db.entities.use_case
import
UseCase
from
db.entities.schema
import
Schema
import
pymongo
import
pymongo
import
json
import
json
...
@@ -19,72 +18,35 @@ class Repository(MongoRepositoryBase):
...
@@ -19,72 +18,35 @@ class Repository(MongoRepositoryBase):
self
.
_adapter_collection
=
'layer_adapters'
self
.
_adapter_collection
=
'layer_adapters'
self
.
_use_case_collection
=
'use_cases'
self
.
_use_case_collection
=
'use_cases'
self
.
_schema_collection
=
'schemas'
def
add_schema
(
self
,
schema
:
Schema
):
def
all
(
self
)
->
List
[
Dict
]:
self
.
put_use_case
(
schema
.
use_case
)
result
=
super
()
.
get_entries
(
self
.
_adapter_collection
,
projection
=
{
'_id'
:
False
})
super
()
.
insert_entry
(
self
.
_schema_collection
,
schema
.
to_serializable_dict
())
def
all_schemas
(
self
)
->
List
[
Schema
]:
return
[
LayerAdapter
.
from_serializable_dict
(
row
)
for
row
in
list
(
result
)]
result
=
super
()
.
get_entries
(
self
.
_schema_collection
,
projection
=
{
'_id'
:
False
})
return
[
Schema
.
from_serializable_dict
(
row
)
for
row
in
list
(
result
)]
def
schema
_for_use_case
(
self
,
use_case
:
str
)
->
List
[
Dict
]:
def
all
_for_use_case
(
self
,
use_case
:
str
)
->
List
[
Dict
]:
result
=
super
()
.
get_entries
(
self
.
_
schema
_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"use_case"
:
use_case
})
result
=
super
()
.
get_entries
(
self
.
_
adapter
_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"use_case"
:
use_case
})
result
=
list
(
result
)
return
[
LayerAdapter
.
from_serializable_dict
(
row
)
for
row
in
list
(
result
)]
if
len
(
result
)
>
1
:
raise
ValueError
(
"No more than 1 Schema allowed per use-case!"
)
def
one
(
self
,
name
:
str
,
use_case
:
str
)
->
LayerAdapter
:
result
=
list
(
super
()
.
get_entries
(
self
.
_adapter_collection
,
selection
=
{
"name"
:
name
,
"use_case"
:
use_case
}))
if
len
(
result
)
==
1
:
if
len
(
result
)
==
1
:
return
Schema
.
from_serializable_dict
(
result
[
0
])
return
LayerAdapter
.
from_serializable_dict
(
result
[
0
])
return
None
return
None
def
delete_schema_with_use_case
(
self
,
use_case
:
str
):
def
delete_all
(
self
):
collection
=
self
.
_database
[
self
.
_schema_collection
]
collection
.
delete_one
({
"use_case"
:
use_case
})
def
delete_all_schemas
(
self
):
collection
=
self
.
_database
[
self
.
_schema_collection
]
collection
.
delete_many
({})
def
update_schema
(
self
,
schema
:
Schema
):
collection
=
self
.
_database
[
self
.
_schema_collection
]
collection
.
update_one
({
"use_case"
:
schema
.
use_case
},
{
"$set"
:
schema
.
to_serializable_dict
()})
def
delete_all_use_cases_with_name
(
self
,
name
:
str
):
collection
=
self
.
_database
[
self
.
_use_case_collection
]
collection
.
delete_many
({
"name"
:
name
})
def
delete_all_layers
(
self
):
collection
=
self
.
_database
[
self
.
_adapter_collection
]
collection
=
self
.
_database
[
self
.
_adapter_collection
]
collection
.
delete_many
({})
collection
.
delete_many
({})
def
delete_all_use_cases
(
self
):
collection
=
self
.
_database
[
self
.
_use_case_collection
]
collection
.
delete_many
({})
def
all_use_cases
(
self
)
->
List
[
UseCase
]:
dicts
=
list
(
super
()
.
get_entries
(
self
.
_use_case_collection
,
projection
=
{
'_id'
:
False
}))
return
[
UseCase
.
from_serializable_dict
(
d
)
for
d
in
dicts
]
def
put_use_case
(
self
,
use_case_name
:
str
):
use_cases
=
self
.
all_use_cases
()
existing_use_cases
=
list
(
filter
(
lambda
use_case
:
use_case
.
name
==
use_case_name
,
use_cases
))
if
len
(
existing_use_cases
)
==
0
:
use_case
=
UseCase
(
use_case_name
)
super
()
.
insert_entry
(
self
.
_use_case_collection
,
use_case
.
to_serializable_dict
())
def
add
(
self
,
adapter
:
LayerAdapter
):
def
add
(
self
,
adapter
:
LayerAdapter
):
self
.
put_use_case
(
adapter
.
use_case
)
super
()
.
insert_entry
(
self
.
_adapter_collection
,
adapter
.
to_serializable_dict
())
super
()
.
insert_entry
(
self
.
_adapter_collection
,
adapter
.
to_serializable_dict
())
def
one_by_name_and_usecase
(
self
,
name
:
str
,
use_case
:
str
)
->
LayerAdapter
:
def
add_empty
(
self
,
name
:
str
,
use_case
:
str
):
return
list
(
super
()
.
get_entries
(
self
.
_adapter_collection
,
selection
=
{
"name"
:
name
,
"use_case"
:
use_case
}))
adapter
=
LayerAdapter
(
name
,
use_case
,
[],
[])
super
()
.
insert_entry
(
self
.
_adapter_collection
,
adapter
.
to_serializable_dict
())
def
update_use_case
(
self
,
adapter
:
LayerAdapter
,
use_case
:
str
):
def
update_use_case
(
self
,
adapter
:
LayerAdapter
,
use_case
:
str
):
collection
=
self
.
_database
[
self
.
_adapter_collection
]
collection
=
self
.
_database
[
self
.
_adapter_collection
]
...
@@ -97,13 +59,3 @@ class Repository(MongoRepositoryBase):
...
@@ -97,13 +59,3 @@ class Repository(MongoRepositoryBase):
def
delete_all_with_name_and_use_case
(
self
,
name
:
str
,
use_case
:
str
):
def
delete_all_with_name_and_use_case
(
self
,
name
:
str
,
use_case
:
str
):
collection
=
self
.
_database
[
self
.
_adapter_collection
]
collection
=
self
.
_database
[
self
.
_adapter_collection
]
collection
.
delete_many
({
"name"
:
name
,
"use_case"
:
use_case
})
collection
.
delete_many
({
"name"
:
name
,
"use_case"
:
use_case
})
\ No newline at end of file
def
all
(
self
)
->
List
[
Dict
]:
result
=
super
()
.
get_entries
(
self
.
_adapter_collection
,
projection
=
{
'_id'
:
False
})
return
list
(
result
)
def
all_for_use_case
(
self
,
use_case
:
str
)
->
List
[
Dict
]:
result
=
super
()
.
get_entries
(
self
.
_adapter_collection
,
projection
=
{
'_id'
:
False
},
selection
=
{
"use_case"
:
use_case
})
return
list
(
result
)
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/db/schema_repository.py
0 → 100644
View file @
7e36e1f2
# global imports (dont't worry, red is normal)
import
network_constants
as
netconst
from
database.MongoRepositoryBase
import
MongoRepositoryBase
from
db.entities.schema
import
Schema
import
pymongo
import
json
from
typing
import
List
,
Dict
class
SchemaRepository
(
MongoRepositoryBase
):
'''This is a repository for MongoDb.'''
def
__init__
(
self
):
super
()
.
__init__
(
netconst
.
BUSINESS_LOGIC_DB_HOSTNAME
,
netconst
.
BUSINESS_LOGIC_DB_PORT
,
'rest-gateway-db'
)
self
.
_schema_collection
=
'schemas'
def
all
(
self
)
->
List
[
Schema
]:
result
=
super
()
.
get_entries
(
self
.
_schema_collection
,
projection
=
{
'_id'
:
False
})
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
})
result
=
list
(
result
)
if
len
(
result
)
>
1
:
raise
ValueError
(
"No more than 1 Schema allowed per use-case!"
)
if
len
(
result
)
==
1
:
return
Schema
.
from_serializable_dict
(
result
[
0
])
return
None
def
put
(
self
,
use_case
:
str
):
schema
=
self
.
get_for_use_case
(
use_case
)
if
schema
==
None
:
schema
=
Schema
(
use_case
,
mappings
=
{})
self
.
add
(
schema
)
return
schema
def
delete_for_use_case
(
self
,
use_case
:
str
):
collection
=
self
.
_database
[
self
.
_schema_collection
]
collection
.
delete_one
({
"use_case"
:
use_case
})
def
delete_all
(
self
):
collection
=
self
.
_database
[
self
.
_schema_collection
]
collection
.
delete_many
({})
def
update
(
self
,
schema
:
Schema
):
collection
=
self
.
_database
[
self
.
_schema_collection
]
collection
.
update_one
({
"use_case"
:
schema
.
use_case
},
{
"$set"
:
schema
.
to_serializable_dict
()})
src/participation-hub/business-logic-microservice/app/db/use_case_repository.py
0 → 100644
View file @
7e36e1f2
# global imports (dont't worry, red is normal)
import
network_constants
as
netconst
from
database.MongoRepositoryBase
import
MongoRepositoryBase
from
db.entities.use_case
import
UseCase
import
pymongo
import
json
from
typing
import
List
,
Dict
class
UseCaseRepository
(
MongoRepositoryBase
):
'''This is a repository for MongoDb.'''
def
__init__
(
self
):
super
()
.
__init__
(
netconst
.
BUSINESS_LOGIC_DB_HOSTNAME
,
netconst
.
BUSINESS_LOGIC_DB_PORT
,
'rest-gateway-db'
)
self
.
_use_case_collection
=
'use_cases'
def
all
(
self
)
->
List
[
UseCase
]:
dicts
=
list
(
super
()
.
get_entries
(
self
.
_use_case_collection
,
projection
=
{
'_id'
:
False
}))
return
[
UseCase
.
from_serializable_dict
(
d
)
for
d
in
dicts
]
def
delete_all
(
self
):
collection
=
self
.
_database
[
self
.
_use_case_collection
]
collection
.
delete_many
({})
def
delete_all_with_name
(
self
,
name
:
str
):
collection
=
self
.
_database
[
self
.
_use_case_collection
]
collection
.
delete_many
({
"name"
:
name
})
def
put
(
self
,
use_case_name
:
str
):
use_cases
=
self
.
all_use_cases
()
existing_use_cases
=
list
(
filter
(
lambda
use_case
:
use_case
.
name
==
use_case_name
,
use_cases
))
if
len
(
existing_use_cases
)
==
0
:
use_case
=
UseCase
(
use_case_name
)
super
()
.
insert_entry
(
self
.
_use_case_collection
,
use_case
.
to_serializable_dict
())
src/participation-hub/business-logic-microservice/app/routes/layer.py
View file @
7e36e1f2
#global imports
#global imports
from
db.entities.layer_adapter
import
LayerAdapter
from
db.entities.layer_adapter
import
LayerAdapter
from
db.repository
import
Repository
from
db.schema_repository
import
SchemaRepository
from
services.layer_adapter_service
import
LayerAdapterService
from
services.layer_adapter_service
import
LayerAdapterService
import
json
import
json
from
flask
import
Response
,
request
from
flask
import
Response
,
request
schema_repository
=
SchemaRepository
()
def
use_cases
():
layer_repository
=
Repository
()
return
[
adapter
.
to_serializable_dict
()
for
adapter
in
LayerAdapterService
.
all_use_cases
()]
def
delete_uses_cases
():
LayerAdapterService
.
delete_all_use_cases
()
return
Response
(
status
=
200
)
def
all
():
def
all
():
return
LayerAdapterService
.
all
()
return
[
layer
.
to_serializable_dict
()
for
layer
in
layer_repository
.
all
()]
def
all_schemas
():
return
[
schema
.
to_serializable_dict
()
for
schema
in
LayerAdapterService
.
all_schemas
()]
def
schema_for_use_case
(
use_case
:
str
):
schema
=
LayerAdapterService
.
schema_for_use_case
(
use_case
)
if
schema
!=
None
:
return
Response
(
status
=
200
,
response
=
json
.
dumps
(
schema
.
to_serializable_dict
()))
return
Response
(
status
=
404
,
response
=
f
"Schema {use_case} does not exist"
)
def
add_mapping_to_schema
(
use_case
:
str
):
data
=
request
.
json
if
"internal"
not
in
data
or
"external"
not
in
data
:
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal, external)"
)
schema
=
LayerAdapterService
.
schema_for_use_case
(
use_case
)
if
schema
==
None
:
print
(
"schema not there, creating it..."
)
schema
=
LayerAdapterService
.
put_schema
(
use_case
)
schema
.
add_mapping
(
data
[
"internal"
],
data
[
"external"
])
LayerAdapterService
.
update_schema
(
schema
)
return
Response
(
status
=
200
)
def
delete_schema_for_use_case
(
use_case
:
str
):
schema
=
LayerAdapterService
.
schema_for_use_case
(
use_case
)
if
schema
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Schema {use_case} does not exist"
)
LayerAdapterService
.
delete_schema
(
use_case
)
return
Response
(
status
=
200
)
##########
# LAYERS #
##########
def
get_all_for_use_case
(
use_case
:
str
):
def
get_all_for_use_case
(
use_case
:
str
):
'''
'''
get all layers assigned to the given use_case
get all layers assigned to the given use_case
'''
'''
return
LayerAdapterService
.
all_for_use_case
(
use_case
)
return
[
layer
.
to_serializable_dict
()
for
layer
in
layer_repository
.
all_for_use_case
(
use_case
)]
def
add
(
name
:
str
,
use_case
:
str
):
'''
add an empty layer to the DB
@params:
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
if
LayerAdapterService
.
one
(
name
,
use_case
)
!=
None
:
return
Response
(
status
=
400
,
response
=
f
"Layer with name '{name}' already exists!"
)
LayerAdapterService
.
add
(
name
,
use_case
)
return
Response
(
status
=
200
)
def
add_complete
():
def
add_complete
():
'''
'''
...
@@ -87,7 +28,7 @@ def add_complete():
...
@@ -87,7 +28,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
:
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)"
)
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (name, properties, cluster_properties)"
)
layer
=
LayerAdapterService
.
one
(
data
[
"name"
],
data
[
"use_case"
])
layer
=
layer_repository
.
one
(
data
[
"name"
],
data
[
"use_case"
])
if
layer
!=
None
:
if
layer
!=
None
:
return
Response
(
status
=
400
,
response
=
f
'Layer with name "{data["name"]}" already exists!'
)
return
Response
(
status
=
400
,
response
=
f
'Layer with name "{data["name"]}" already exists!'
)
...
@@ -100,11 +41,10 @@ def add_complete():
...
@@ -100,11 +41,10 @@ def add_complete():
return
Response
(
status
=
400
)
return
Response
(
status
=
400
)
try
:
try
:
LayerAdapterService
.
check_layer
(
layer_new
)
LayerAdapterService
.
add_complete
(
layer_new
)
except
ValueError
as
e
:
except
ValueError
as
e
:
return
Response
(
status
=
400
,
response
=
f
"{e}"
)
return
Response
(
status
=
400
,
response
=
f
"{e}"
)
LayerAdapterService
.
add_complete
(
layer_new
)
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
def
one
(
name
:
str
,
use_case
:
str
):
def
one
(
name
:
str
,
use_case
:
str
):
...
@@ -115,99 +55,107 @@ def one(name: str, use_case: str):
...
@@ -115,99 +55,107 @@ def one(name: str, use_case: str):
name - Required : unique identifier for the layer
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
use_case - Required : String-identifier for the use-case
'''
'''
layer
=
LayerAdapterService
.
one
(
name
,
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
if
layer
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
return
Response
(
status
=
200
,
response
=
json
.
dumps
(
layer
.
to_serializable_dict
()))
return
Response
(
status
=
200
,
response
=
json
.
dumps
(
layer
.
to_serializable_dict
()))
def
add_
mapping_for_all
(
use_case
:
str
):
def
add_
empty
(
name
:
str
,
use_case
:
str
):
'''
'''
add a
new mapping to each layer of the use-case
add a
n empty layer to the DB
@params:
@params:
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
use_case - Required : String-identifier for the use-case
'''
'''
data
=
request
.
json
if
layer_repository
.
one
(
name
,
use_case
)
!=
None
:
return
Response
(
status
=
400
,
response
=
f
"Layer with name '{name}' already exists!"
)
if
"internal"
not
in
data
:
layer_repository
.
add_empty
(
name
,
use_case
)
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal)"
)
return
Response
(
status
=
200
)
# check if schema contains mapping
def
add_cluster_mapping
(
name
:
str
,
use_case
:
str
):
schema
=
LayerAdapterService
.
put_schema
(
use_case
)
'''
if
data
[
"internal"
]
not
in
schema
.
mappings
:
add a mapped property to the list of properties to cluster with
return
Response
(
status
=
400
,
response
=
f
'{data["internal"]} is not existent in the schema!'
)
layers
=
LayerAdapterService
.
all_for_use_case
(
use_case
)
@params:
layers
=
[
LayerAdapter
.
from_serializable_dict
(
d
)
for
d
in
layers
]
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
layer
=
layer_repository
.
one
(
name
,
use_case
)
for
layer
in
layers
:
if
layer
==
None
:
layer
.
add_mapping
(
data
[
"internal"
]
)
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
try
:
data
=
request
.
json
LayerAdapterService
.
check_layer
(
layer
)
except
ValueError
as
e
:
return
Response
(
status
=
400
,
response
=
f
"{e}"
)
LayerAdapterService
.
update
(
layer
)
if
"attribute"
not
in
data
:
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (attribute)"
)
try
:
layer
.
add_cluster_mapping
(
data
[
"attribute"
])
layer_repository
.
update
(
layer
)
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
except
:
return
Response
(
status
=
400
,
response
=
f
'{data["attribute"]} is no attribute in the layer!'
)
def
add
_mapping
(
name
:
str
,
use_case
:
str
):
def
delete_cluster
_mapping
(
name
:
str
,
use_case
:
str
):
'''
'''
add a new mapping to the layer identified by name
remove a mapped property from the list of properties to cluster with
@params:
@params:
name - Required : unique identifier for the layer
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
use_case - Required : String-identifier for the use-case
'''
'''
layer
=
LayerAdapterService
.
one
(
name
,
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
if
layer
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
data
=
request
.
json
data
=
request
.
json
if
"internal"
not
in
data
:
if
"attribute"
not
in
data
:
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal)"
)
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (attribute)"
)
# check if schema contains mapping
schema
=
LayerAdapterService
.
put_schema
(
use_case
)
if
data
[
"internal"
]
not
in
schema
.
mappings
:
return
Response
(
status
=
400
,
response
=
f
'{data["internal"]} is not existent in the schema!'
)
layer
.
add_mapping
(
data
[
"internal"
])
LayerAdapterService
.
update
(
layer
)
try
:
layer
.
delete_cluster_mapping
(
data
[
"attribute"
])
layer_repository
.
update
(
layer
)
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
except
ValueError
as
e
:
print
(
e
)
return
Response
(
status
=
400
,
response
=
f
'{data["attribute"]} is no attribute in the layer!'
)
def
update_use_case
_for_all
(
use_case
:
str
):
def
add_mapping
_for_all
(
use_case
:
str
):
'''
'''
update the use-case for each layer in the use-case
add a new mapping to each layer of the use-case
this changes the use-case of all layers, meaning the use-case used
for this request might not be usable after the request
@params:
@params:
use_case - Required : String-identifier for the use-case
use_case - Required : String-identifier for the use-case
'''
'''
data
=
request
.
json
data
=
request
.
json
if
"use_case"
not
in
data
:
if
"internal"
not
in
data
:
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (use_case)"
)
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal)"
)
# check if schema contains mapping
schema
=
schema_repository
.
put
(
use_case
)
if
data
[
"internal"
]
not
in
schema
.
mappings
:
return
Response
(
status
=
400
,
response
=
f
'{data["internal"]} is not existent in the schema!'
)
layers
=
LayerAdapterService
.
all_for_use_case
(
use_case
)
layers
=
layer_repository
.
all_for_use_case
(
use_case
)
layers
=
[
LayerAdapter
.
from_serializable_dict
(
d
)
for
d
in
layers
]
for
layer
in
layers
:
for
layer
in
layers
:
layer
.
use_case
=
data
[
"use_case"
]
layer
.
add_mapping
(
data
[
"internal"
])
try
:
try
:
LayerAdapterService
.
check_layer
(
layer
)
LayerAdapterService
.
check_layer
(
layer
)
except
ValueError
as
e
:
except
ValueError
as
e
:
return
Response
(
status
=
400
,
response
=
f
"{e}"
)
return
Response
(
status
=
400
,
response
=
f
"{e}"
)
LayerAdapterService
.
update_use_case
(
layer
,
use_case
)
layer_repository
.
update
(
layer
)
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
...
@@ -223,15 +171,14 @@ def delete_mapping_for_all(use_case: str):
...
@@ -223,15 +171,14 @@ def delete_mapping_for_all(use_case: str):
if
"internal"
not
in
data
:
if
"internal"
not
in
data
:
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal)"
)
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal)"
)
layers
=
LayerAdapterService
.
all_for_use_case
(
use_case
)
layers
=
layer_repository
.
all_for_use_case
(
use_case
)
layers
=
[
LayerAdapter
.
from_serializable_dict
(
d
)
for
d
in
layers
]
for
layer
in
layers
:
for
layer
in
layers
:
try
:
try
:
layer
.
delete_mapping
(
data
[
"internal"
])
layer
.
delete_mapping
(
data
[
"internal"
])
except
ValueError
:
except
ValueError
:
continue
continue
LayerAdapterService
.
update
(
layer
)
layer_repository
.
update
(
layer
)
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
...
@@ -243,7 +190,7 @@ def delete_mapping(name: str, use_case: str):
...
@@ -243,7 +190,7 @@ def delete_mapping(name: str, use_case: str):
name - Required : unique identifier for the layer
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
use_case - Required : String-identifier for the use-case
'''
'''
layer
=
LayerAdapterService
.
one
(
name
,
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
if
layer
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
...
@@ -255,65 +202,39 @@ def delete_mapping(name: str, use_case: str):
...
@@ -255,65 +202,39 @@ def delete_mapping(name: str, use_case: str):
try
:
try
:
layer
.
delete_mapping
(
data
[
"internal"
])
layer
.
delete_mapping
(
data
[
"internal"
])
LayerAdapterService
.
update
(
layer
)
layer_repository
.
update
(
layer
)
except
ValueError
:
except
ValueError
:
return
Response
(
status
=
400
,
response
=
f
'{data["internal"]} is not a property of the layer!'
)
return
Response
(
status
=
400
,
response
=
f
'{data["internal"]} is not a property of the layer!'
)
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
def
add_mapping
(
name
:
str
,
use_case
:
str
):
def
add_cluster_mapping
(
name
:
str
,
use_case
:
str
):
'''
'''
add a
mapped property to the list of properties to cluster with
add a
new mapping to the layer identified by name
@params:
@params:
name - Required : unique identifier for the layer
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
use_case - Required : String-identifier for the use-case
'''
'''
layer
=
LayerAdapterService
.
one
(
name
,
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
if
layer
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
data
=
request
.
json
data
=
request
.
json
if
"attribute"
not
in
data
:
if
"internal"
not
in
data
:
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (attribute)"
)
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal)"
)
try
:
layer
.
add_cluster_mapping
(
data
[
"attribute"
])
LayerAdapterService
.
update
(
layer
)
return
Response
(
status
=
200
)
except
:
return
Response
(
status
=
400
,
response
=
f
'{data["attribute"]} is no attribute in the layer!'
)
def
delete_cluster_mapping
(
name
:
str
,
use_case
:
str
):
'''
remove a mapped property from the list of properties to cluster with
@params:
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
layer
=
LayerAdapterService
.
one
(
name
,
use_case
)
if
layer
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
data
=
request
.
json
# check if schema contains mapping
schema
=
schema_repository
.
put
(
use_case
)
if
data
[
"internal"
]
not
in
schema
.
mappings
:
return
Response
(
status
=
400
,
response
=
f
'{data["internal"]} is not existent in the schema!'
)
if
"attribute"
not
in
data
:
layer
.
add_mapping
(
data
[
"internal"
])
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (attribute)"
)
layer_repository
.
update
(
layer
)
try
:
layer
.
delete_cluster_mapping
(
data
[
"attribute"
])
LayerAdapterService
.
update
(
layer
)
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
except
ValueError
as
e
:
print
(
e
)
return
Response
(
status
=
400
,
response
=
f
'{data["attribute"]} is no attribute in the layer!'
)
def
delete_one
(
name
:
str
,
use_case
:
str
):
def
delete_one
(
name
:
str
,
use_case
:
str
):
'''
'''
...
@@ -323,17 +244,17 @@ def delete_one(name: str, use_case: str):
...
@@ -323,17 +244,17 @@ def delete_one(name: str, use_case: str):
name - Required : unique identifier for the layer
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
use_case - Required : String-identifier for the use-case
'''
'''
layer
=
LayerAdapterService
.
one
(
name
,
use_case
)
layer
=
layer_repository
.
one
(
name
,
use_case
)
if
layer
==
None
:
if
layer
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
return
Response
(
status
=
404
,
response
=
f
"Layer with name '{name}' does not exist!"
)
LayerAdapterService
.
delet
e
(
layer
)
layer_repository
.
delete_all_with_name_and_use_cas
e
(
layer
)
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
def
delete_all_layers
():
def
delete_all_layers
():
'''
'''
delete all layers from the DB
delete all layers from the DB
'''
'''
LayerAdapterService
.
delete_all_layers
()
layer_repository
.
delete_all
()
return
Response
(
status
=
200
)
return
Response
(
status
=
200
)
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/routes/schema.py
0 → 100644
View file @
7e36e1f2
#global imports
from
db.entities.layer_adapter
import
LayerAdapter
from
db.schema_repository
import
SchemaRepository
from
services.layer_adapter_service
import
LayerAdapterService
import
json
from
flask
import
Response
,
request
schema_repository
=
SchemaRepository
()
def
all
():
return
[
schema
.
to_serializable_dict
()
for
schema
in
schema_repository
.
all
()]
def
get_for_use_case
(
use_case
:
str
):
schema
=
schema_repository
.
get_for_use_case
(
use_case
)
if
schema
!=
None
:
return
Response
(
status
=
200
,
response
=
json
.
dumps
(
schema
.
to_serializable_dict
()))
return
Response
(
status
=
404
,
response
=
f
"Schema {use_case} does not exist"
)
def
delete_for_use_case
(
use_case
:
str
):
schema
=
schema_repository
.
get_for_use_case
(
use_case
)
if
schema
==
None
:
return
Response
(
status
=
404
,
response
=
f
"Schema {use_case} does not exist"
)
schema_repository
.
delete_for_use_case
(
use_case
)
return
Response
(
status
=
200
)
def
add_mapping
(
use_case
:
str
):
data
=
request
.
json
if
"internal"
not
in
data
or
"external"
not
in
data
:
return
Response
(
status
=
400
,
response
=
f
"Field missing! Fields required: (internal, external)"
)
schema
=
schema_repository
.
get_for_use_case
(
use_case
)
if
schema
==
None
:
print
(
"schema not there, creating it..."
)
schema
=
schema_repository
.
put
(
use_case
)
schema
.
add_mapping
(
data
[
"internal"
],
data
[
"external"
])
schema_repository
.
update
(
schema
)
return
Response
(
status
=
200
)
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/routes/use_case.py
0 → 100644
View file @
7e36e1f2
from
db.entities.layer_adapter
import
LayerAdapter
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
()
def
all
():
return
[
adapter
.
to_serializable_dict
()
for
adapter
in
use_case_repository
.
all
()]
def
delete_all
():
LayerAdapterService
.
delete_all
()
return
Response
(
status
=
200
)
\ No newline at end of file
src/participation-hub/business-logic-microservice/app/services/layer_adapter_service.py
View file @
7e36e1f2
#global imports
#global imports
from
db.repository
import
Repository
from
db.repository
import
Repository
from
db.schema_repository
import
SchemaRepository
from
db.use_case_repository
import
UseCaseRepository
from
db.entities.layer_adapter
import
LayerAdapter
from
db.entities.layer_adapter
import
LayerAdapter
from
db.entities.schema
import
Schema
from
db.entities.schema
import
Schema
from
typing
import
List
from
typing
import
List
class
LayerAdapterService
:
class
LayerAdapterService
:
_repository
=
Repository
()
_schema_repository
=
SchemaRepository
()
_layer_repository
=
Repository
()
@
staticmethod
_use_case_repository
=
UseCaseRepository
()
def
all_schemas
()
->
List
[
Schema
]:
return
LayerAdapterService
.
_repository
.
all_schemas
()
@
staticmethod
def
schema_for_use_case
(
use_case
:
str
):
LayerAdapterService
.
_repository
.
put_use_case
(
use_case
)
return
LayerAdapterService
.
_repository
.
schema_for_use_case
(
use_case
)
@
staticmethod
def
put_schema
(
use_case
:
str
):
schema
=
LayerAdapterService
.
schema_for_use_case
(
use_case
)
if
schema
==
None
:
schema
=
Schema
(
use_case
,
mappings
=
{})
LayerAdapterService
.
_repository
.
add_schema
(
schema
)
return
schema
@
staticmethod
@
staticmethod
def
check_layer
(
layer
:
LayerAdapter
):
def
check_layer
(
layer
:
LayerAdapter
):
'''
'''
checks if the given layer has correct mappings regarding the schema of the use_case
checks if the given layer has correct mappings regarding the schema of the use_case
'''
'''
schema
=
LayerAdapterService
.
put_schema
(
layer
.
use_case
)
schema
=
LayerAdapterService
.
_schema_repository
.
put
(
layer
.
use_case
)
for
p
in
layer
.
properties
:
for
p
in
layer
.
properties
:
if
p
not
in
schema
.
mappings
:
if
p
not
in
schema
.
mappings
:
raise
ValueError
(
f
'{p} is not existent in the schema!'
)
raise
ValueError
(
f
'{p} is not existent in the schema!'
)
@
staticmethod
def
delete_schema
(
use_case
:
str
):
LayerAdapterService
.
_repository
.
delete_schema_with_use_case
(
use_case
)
@
staticmethod
def
update_schema
(
schema
:
Schema
):
LayerAdapterService
.
_repository
.
update_schema
(
schema
)
@
staticmethod
def
all_use_cases
()
->
List
[
str
]:
return
LayerAdapterService
.
_repository
.
all_use_cases
()
@
staticmethod
def
delete_all_use_cases
():
LayerAdapterService
.
_repository
.
delete_all_use_cases
()
LayerAdapterService
.
_repository
.
delete_all_schemas
()
LayerAdapterService
.
_repository
.
delete_all_layers
()
@
staticmethod
def
delete_use_case
(
name
:
str
):
LayerAdapterService
.
_repository
.
delete_all_use_cases_with_name
(
name
)
@
staticmethod
def
all
()
->
List
[
LayerAdapter
]:
'''
Return all currently defined layers
'''
return
LayerAdapterService
.
_repository
.
all
()
@
staticmethod
def
all_for_use_case
(
use_case
:
str
)
->
List
[
LayerAdapter
]:
'''
Return all currently defined layers that belong to the
given use-case
'''
return
LayerAdapterService
.
_repository
.
all_for_use_case
(
use_case
)
@
staticmethod
def
update
(
layer
:
LayerAdapter
):
'''
Overwrite the stored instance with the given one which is
identified by the layer name
@params:
layer - Required : layer object holding the current data
'''
LayerAdapterService
.
_repository
.
update
(
layer
)
@
staticmethod
def
update_use_case
(
layer
:
LayerAdapter
,
use_case
:
str
):
'''
Overwrite the stored instance with the given one which is
identified by the layer name
@params:
layer - Required : layer object holding the current data
'''
LayerAdapterService
.
_repository
.
update_use_case
(
layer
,
use_case
)
@
staticmethod
def
add
(
name
:
str
,
use_case
:
str
):
'''
Add a new layer to the DB. Attribute mapping and cluster
attributes will be empty per default
@params:
name - Required : Unique name for a layer.
use_case - Required : String-identifier for the use-case
'''
adapter_new
=
LayerAdapter
(
name
,
use_case
,
[],
[])
LayerAdapterService
.
_repository
.
add
(
adapter_new
)
@
staticmethod
@
staticmethod
def
add_complete
(
layer
:
LayerAdapter
):
def
add_complete
(
layer
:
LayerAdapter
):
'''
'''
Add a new layer to the DB. Attribute mappings and cluster
Add a new layer to the DB. Attribute mappings and cluster
attributes of the given layer
a
ttributes of the given layer are used
a
re used. Before inserting, the layer gets checked for consistency with the schema.
@params:
@params:
layer - Required : layer object holding correct data
layer - Required : layer object holding correct data
'''
'''
LayerAdapterService
.
_repository
.
add
(
layer
)
LayerAdapterService
.
check_layer
(
layer
)
LayerAdapterService
.
_layer_repository
.
add
(
layer
)
@
staticmethod
def
delete
(
layer
:
LayerAdapter
):
'''
delete all layers with the given name.
@params:
layer - Required : layer object to remove from the DB
'''
use_case
=
layer
.
use_case
LayerAdapterService
.
_repository
.
delete_all_with_name_and_use_case
(
layer
.
name
,
use_case
)
@
staticmethod
@
staticmethod
def
delete_all_layers
():
def
delete_all_use_cases
():
LayerAdapterService
.
_repository
.
delete_all_layers
()
# TODO
LayerAdapterService
.
_layer_repository
.
delete_all_use_cases
()
@
staticmethod
LayerAdapterService
.
_schema_repository
.
delete_all
()
def
one
(
name
:
str
,
use_case
:
str
)
->
LayerAdapter
:
LayerAdapterService
.
_use_case_repository
.
delete_all
()
'''
Retrieve a single layer from the DB. Returns None if no layer
was found under this name.
@params:
name - Required : Unique name for a layer
use_case - Required : String-identifier for the use-case
'''
result
=
LayerAdapterService
.
_repository
.
one_by_name_and_usecase
(
name
,
use_case
)
\ No newline at end of file
if
len
(
result
)
==
1
:
return
LayerAdapter
.
from_serializable_dict
(
result
[
0
])
else
:
return
None
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