Commit 4d9ebc89 authored by Manuel's avatar Manuel

businessLogic: restructured layer system and added schema information

parent 28641988
......@@ -10,3 +10,5 @@ src/modules/certificate/articonf1.key
src/modules/certificate/articonf1.crt
src/modules/certificate/articonf1-chain.crt
src/modules/security/regular_user_credentials.json
......@@ -20,7 +20,7 @@ paths:
/use-cases:
delete:
security:
- JwtAdmin: []
- JwtRegular: []
operationId: "routes.layer.delete_uses_cases"
tags:
- "Use-Cases"
......@@ -29,14 +29,103 @@ paths:
responses:
'200':
description: "Successful Request"
paths:
/use-cases/{use_case}/schema/mapping:
put:
security:
- JwtRegular: []
operationId: "routes.layer.add_mapping_to_schema"
tags:
- "Schemas"
summary: "Adds an attribute mapping to the Schema of the Use-Case"
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"
/use-cases/{use_case}/schema:
get:
security:
- JwtRegular: []
operationId: "routes.layer.schema_for_use_case"
tags:
- "Schemas"
summary: "Get the Schema assigned to the Use-Case"
description: "Get the Schema assigned to the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Schema does not exist"
delete:
security:
- JwtRegular: []
operationId: "routes.layer.delete_schema_for_use_case"
tags:
- "Schemas"
summary: "Delete the Schema assigned to the Use-Case"
description: "Delete the Schema assigned to the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Schema does not exist"
/schemas:
get:
security:
- JwtRegular: []
operationId: "routes.layer.all_schemas"
tags:
- "Schemas"
summary: "Get all Use-Cases"
description: "Get all Use-Cases"
responses:
'200':
description: "Successful Request"
/use-cases:
delete:
security:
- JwtRegular: []
operationId: "routes.layer.delete_uses_cases"
tags:
- "Use-Cases"
summary: "Delete all Use-Cases"
description: "Delete all Use-Cases"
responses:
'200':
description: "Successful Request"
get:
security:
- JwtRegular: []
operationId: "routes.layer.use_cases"
tags:
- "Use-Cases"
summary: "Retrieves all use-cases"
description: "Retrieves all use-cases"
summary: "Retrieves all Use-Cases"
description: "Retrieves all Use-Cases"
responses:
'200':
description: "Successful Request"
......@@ -47,8 +136,8 @@ paths:
operationId: "routes.layer.get_all_for_use_case"
tags:
- "Layers"
summary: "Retrieves all layers belonging to the given use-case"
description: "Retrieves all layers belonging to the given use-case"
summary: "Retrieves all layers belonging to the given Use-Case"
description: "Retrieves all layers belonging to the given Use-Case"
parameters:
- name: "use_case"
in: "path"
......@@ -103,8 +192,8 @@ paths:
operationId: "routes.layer.add_cluster_mapping"
tags:
- "Layers"
summary: "Adds a cluster-attribute mapping to the selected layer"
description: "Adds a cluster-attribute mapping to the selected layer"
summary: "Selects a property of the Layer as cluster property"
description: "Selects a property of the Layer as cluster property"
parameters:
- name: "name"
in: "path"
......@@ -140,12 +229,12 @@ paths:
operationId: "routes.layer.update_use_case_for_all"
tags:
- "Layers"
summary: "Update the use-case of all layers belonging to the use-case in the query"
description: "Update the use-case of all layers belonging to the use-case in the query"
summary: "Update the Use-Case of all Layers belonging to the Use-Case in the query"
description: "Update the Use-Case of all Layers belonging to the Use-Case in the query"
parameters:
- name: "use_case"
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"
- in: body
......@@ -169,26 +258,19 @@ paths:
operationId: "routes.layer.add_mapping_for_all"
tags:
- "Layers"
summary: "Adds an attribute mapping to the each layer of the use-case"
description: "Adds an attribute mapping to the each layer of the use-case"
summary: "Adds an attribute mapping to the each Layer of the Use-Case"
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 layer belongs to"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
external:
type: string
example: "arrival_unix_timestamp_utc"
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
......@@ -200,39 +282,12 @@ paths:
operationId: "routes.layer.delete_mapping_for_all"
tags:
- "Layers"
summary: "Deletes an attribute mapping for all layers of the use-case"
description: "Deletes an attribute mapping for all layers of the use-case"
parameters:
- 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:
type: object
properties:
internal:
type: string
example: "end_time"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
/use-cases/{use_case}/layers/mapping:
put:
operationId: "routes.layer.add_mapping_for_all"
tags:
- "Layers"
summary: "Adds an attribute mapping to the each layer of the use-case"
description: "Adds an attribute mapping to the each layer of the use-case"
summary: "Deletes an attribute mapping for all Layers of the Use-Case"
description: "Deletes an attribute mapping for all Layers of the Use-Case"
parameters:
- name: "use_case"
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"
- in: body
......@@ -244,42 +299,11 @@ paths:
internal:
type: string
example: "end_time"
external:
type: string
example: "arrival_unix_timestamp_utc"
responses:
'200':
description: "Successful Request"
'400':
description: "Field in request is missing"
delete:
operationId: "routes.layer.delete_mapping_for_all"
tags:
- "Layers"
summary: "Deletes an attribute mapping for all layers of the use-case"
description: "Deletes an attribute mapping for all layers of the use-case"
parameters:
- 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:
type: object
properties:
internal:
type: string
example: "end_time"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
'400':
description: "Field in request is missing"
/use-cases/{use_case}/layers/{name}/mapping:
delete:
security:
......@@ -287,28 +311,24 @@ paths:
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"
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)"
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"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
......@@ -322,31 +342,24 @@ paths:
operationId: "routes.layer.add_mapping"
tags:
- "Layers"
summary: "Adds an attribute mapping to the selected layer"
description: "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"
parameters:
- name: "name"
in: "path"
description: "Name of the layer (must exist)"
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"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
external:
type: string
example: "arrival_unix_timestamp_utc"
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
......@@ -355,23 +368,23 @@ paths:
'400':
description: "Field in request is missing"
/use-cases/{use_case}/layers/{name}:
delete:
get:
security:
- JwtRegular: []
operationId: "routes.layer.delete_one"
operationId: "routes.layer.one"
tags:
- "Layers"
summary: "Delete one LayerAdapter from the DB"
description: "Delete one LayerAdapter from the DB"
summary: "Retrieve one Layer from the DB"
description: "Retrieve one Layer from the DB"
parameters:
- name: "name"
in: "path"
description: "Name of the layer to delete"
description: "Name of the Layer"
required: true
type: "string"
- name: "use_case"
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"
responses:
......@@ -379,42 +392,42 @@ paths:
description: "Successful Request"
'404':
description: "Layer does not exist"
get:
post:
security:
- JwtRegular: []
operationId: "routes.layer.one"
operationId: "routes.layer.add"
tags:
- "Layers"
summary: "Retrieve one LayerAdapter from the DB"
description: "Retrieve one LayerAdapter from the DB"
summary: "Adds an empty Layer to the DB"
description: "Adds an empty Layer to the DB"
parameters:
- name: "name"
in: "path"
description: "Name of the layer"
description: "Name of the new Layer"
required: true
type: "string"
- name: "use_case"
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"
responses:
'200':
description: "Successful Request"
'404':
description: "Layer does not exist"
post:
'400':
description: "Layer already exists"
delete:
security:
- JwtRegular: []
operationId: "routes.layer.add"
operationId: "routes.layer.delete_one"
tags:
- "Layers"
summary: "Adds a new layer to the DB"
description: "Adds a new layer to the DB"
summary: "Delete one Layer from the DB"
description: "Delete one Layer from the DB"
parameters:
- name: "name"
in: "path"
description: "Name of the new layer"
description: "Name of the layer to delete"
required: true
type: "string"
- name: "use_case"
......@@ -425,40 +438,50 @@ paths:
responses:
'200':
description: "Successful Request"
'400':
description: "Layer already exists"
'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"
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
name: "Object"
required: true
schema:
$ref: '#/definitions/LayerAdapter'
$ref: '#/definitions/Layer'
responses:
'200':
description: "Successful Request"
'400':
description: "Bad structure in request body or layer already exists"
get:
security:
- JwtRegular: []
operationId: "routes.layer.all"
tags:
- "Layers"
summary: "Retrieve all LayerAdapters from the DB"
description: "Retrieve all LayerAdapters from the DB"
responses:
'200':
description: "Successful Request"
description: "Bad structure in request body or Layer already exists"
/debug:
post:
security:
......@@ -479,7 +502,27 @@ paths:
description: "Successful echo of request data"
definitions:
LayerAdapter:
LayerMapping:
type: "object"
required:
- internal
properties:
internal:
type: string
example: "end_time"
Mapping:
type: "object"
required:
- internal
- external
properties:
internal:
type: string
example: "end_time"
external:
type: string
example: "arrival_unix_timestamp_utc"
Layer:
type: "object"
required:
- name
......@@ -499,9 +542,7 @@ definitions:
type: string
example: "internal_property_1"
properties:
type: object
additionalProperties:
type: array
items:
type: string
example:
"internal_property_1": "external_property_1"
"internal_property_2": "external_property_2"
\ No newline at end of file
example: "internal_property_1"
\ No newline at end of file
......@@ -12,13 +12,79 @@ produces:
basePath: "/api"
paths:
/use-cases/{use_case}/schema/mapping:
put:
operationId: "routes.layer.add_mapping_to_schema"
tags:
- "Schemas"
summary: "Adds an attribute mapping to the Schema of the Use-Case"
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"
/use-cases/{use_case}/schema:
get:
operationId: "routes.layer.schema_for_use_case"
tags:
- "Schemas"
summary: "Get the Schema assigned to the Use-Case"
description: "Get the Schema assigned to the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Schema does not exist"
delete:
operationId: "routes.layer.delete_schema_for_use_case"
tags:
- "Schemas"
summary: "Delete the Schema assigned to the Use-Case"
description: "Delete the Schema assigned to the Use-Case"
parameters:
- name: "use_case"
in: "path"
description: "Name of the Use-Case the Schema belongs to"
required: true
type: "string"
responses:
'200':
description: "Successful Request"
'404':
description: "Schema does not exist"
/schemas:
get:
operationId: "routes.layer.all_schemas"
tags:
- "Schemas"
summary: "Get all Use-Cases"
description: "Get all Use-Cases"
responses:
'200':
description: "Successful Request"
/use-cases:
delete:
operationId: "routes.layer.delete_uses_cases"
tags:
- "Use-Cases"
summary: "Delete all use-cases"
description: "Delete all use-cases"
summary: "Delete all Use-Cases"
description: "Delete all Use-Cases"
responses:
'200':
description: "Successful Request"
......@@ -26,8 +92,8 @@ paths:
operationId: "routes.layer.use_cases"
tags:
- "Use-Cases"
summary: "Retrieves all use-cases"
description: "Retrieves all use-cases"
summary: "Retrieves all Use-Cases"
description: "Retrieves all Use-Cases"
responses:
'200':
description: "Successful Request"
......@@ -36,8 +102,8 @@ paths:
operationId: "routes.layer.get_all_for_use_case"
tags:
- "Layers"
summary: "Retrieves all layers belonging to the given use-case"
description: "Retrieves all layers belonging to the given use-case"
summary: "Retrieves all layers belonging to the given Use-Case"
description: "Retrieves all layers belonging to the given Use-Case"
parameters:
- name: "use_case"
in: "path"
......@@ -88,8 +154,8 @@ paths:
operationId: "routes.layer.add_cluster_mapping"
tags:
- "Layers"
summary: "Adds a cluster-attribute mapping to the selected layer"
description: "Adds a cluster-attribute mapping to the selected layer"
summary: "Selects a property of the Layer as cluster property"
description: "Selects a property of the Layer as cluster property"
parameters:
- name: "name"
in: "path"
......@@ -123,12 +189,12 @@ paths:
operationId: "routes.layer.update_use_case_for_all"
tags:
- "Layers"
summary: "Update the use-case of all layers belonging to the use-case in the query"
description: "Update the use-case of all layers belonging to the use-case in the query"
summary: "Update the Use-Case of all Layers belonging to the Use-Case in the query"
description: "Update the Use-Case of all Layers belonging to the Use-Case in the query"
parameters:
- name: "use_case"
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"
- in: body
......@@ -150,26 +216,19 @@ paths:
operationId: "routes.layer.add_mapping_for_all"
tags:
- "Layers"
summary: "Adds an attribute mapping to the each layer of the use-case"
description: "Adds an attribute mapping to the each layer of the use-case"
summary: "Adds an attribute mapping to the each Layer of the Use-Case"
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 layer belongs to"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
external:
type: string
example: "arrival_unix_timestamp_utc"
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
......@@ -179,12 +238,12 @@ paths:
operationId: "routes.layer.delete_mapping_for_all"
tags:
- "Layers"
summary: "Deletes an attribute mapping for all layers of the use-case"
description: "Deletes an attribute mapping for all layers of the use-case"
summary: "Deletes an attribute mapping for all Layers of the Use-Case"
description: "Deletes an attribute mapping for all Layers of the Use-Case"
parameters:
- name: "use_case"
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"
- in: body
......@@ -206,28 +265,24 @@ paths:
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"
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)"
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"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
......@@ -239,31 +294,24 @@ paths:
operationId: "routes.layer.add_mapping"
tags:
- "Layers"
summary: "Adds an attribute mapping to the selected layer"
description: "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"
parameters:
- name: "name"
in: "path"
description: "Name of the layer (must exist)"
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"
description: "Name of the Use-Case the Layer belongs to"
required: true
type: "string"
- in: body
name: "Object"
required: true
schema:
type: object
properties:
internal:
type: string
example: "end_time"
external:
type: string
example: "arrival_unix_timestamp_utc"
$ref: '#/definitions/LayerMapping'
responses:
'200':
description: "Successful Request"
......@@ -276,17 +324,17 @@ paths:
operationId: "routes.layer.one"
tags:
- "Layers"
summary: "Retrieve one LayerAdapter from the DB"
description: "Retrieve one LayerAdapter from the DB"
summary: "Retrieve one Layer from the DB"
description: "Retrieve one Layer from the DB"
parameters:
- name: "name"
in: "path"
description: "Name of the layer"
description: "Name of the Layer"
required: true
type: "string"
- name: "use_case"
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"
responses:
......@@ -298,17 +346,17 @@ paths:
operationId: "routes.layer.add"
tags:
- "Layers"
summary: "Adds a new layer to the DB"
description: "Adds a new layer to the DB"
summary: "Adds an empty Layer to the DB"
description: "Adds an empty Layer to the DB"
parameters:
- name: "name"
in: "path"
description: "Name of the new layer"
description: "Name of the new Layer"
required: true
type: "string"
- name: "use_case"
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"
responses:
......@@ -320,8 +368,8 @@ paths:
operationId: "routes.layer.delete_one"
tags:
- "Layers"
summary: "Delete one LayerAdapter from the DB"
description: "Delete one LayerAdapter from the DB"
summary: "Delete one Layer from the DB"
description: "Delete one Layer from the DB"
parameters:
- name: "name"
in: "path"
......@@ -339,33 +387,41 @@ paths:
'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"
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
name: "Object"
required: true
schema:
$ref: '#/definitions/LayerAdapter'
$ref: '#/definitions/Layer'
responses:
'200':
description: "Successful Request"
'400':
description: "Bad structure in request body or layer already exists"
get:
operationId: "routes.layer.all"
tags:
- "Layers"
summary: "Retrieve all LayerAdapters from the DB"
description: "Retrieve all LayerAdapters from the DB"
responses:
'200':
description: "Successful Request"
description: "Bad structure in request body or Layer already exists"
/debug:
post:
operationId: "debug.echo"
......@@ -384,7 +440,27 @@ paths:
description: "Successful echo of request data"
definitions:
LayerAdapter:
LayerMapping:
type: "object"
required:
- internal
properties:
internal:
type: string
example: "end_time"
Mapping:
type: "object"
required:
- internal
- external
properties:
internal:
type: string
example: "end_time"
external:
type: string
example: "arrival_unix_timestamp_utc"
Layer:
type: "object"
required:
- name
......@@ -404,9 +480,7 @@ definitions:
type: string
example: "internal_property_1"
properties:
type: object
additionalProperties:
type: array
items:
type: string
example:
"internal_property_1": "external_property_1"
"internal_property_2": "external_property_2"
\ No newline at end of file
example: "internal_property_1"
\ No newline at end of file
......@@ -7,14 +7,14 @@ class LayerAdapter:
attributes from the dataset correspond to each one
'''
def __init__(self, name: str, use_case: str, properties: Dict[str, str], cluster_properties: List[str]):
def __init__(self, name: str, use_case: str, properties: List[str], cluster_properties: List[str]):
'''
Creates a new instance of LayerAdapter
@params:
name - Required : unique identifier for the layer
properties - Required : maps InternalPropertyName->DatasetPropertyName
cluster_properties - Required : subset of the keys of properties, marks properties to cluster with
properties - Required : list of mappings from the Schema
cluster_properties - Required : subset of properties to indicate what properties are used for clustering
use_case - Required : identifier for the use-case this layer belongs to
'''
self.name = name
......@@ -22,12 +22,12 @@ class LayerAdapter:
self.use_case = use_case
for prop in cluster_properties:
if prop not in properties.keys():
if prop not in properties:
raise ValueError(f"{prop} is no property in the layer!")
self.cluster_properties = cluster_properties
def add_mapping(self, internal: str, external: str):
def add_mapping(self, internal: str):
'''
Add a new mapping to the layer. This mapping consists of an internal representation.
......@@ -35,23 +35,24 @@ class LayerAdapter:
internal - Required: string identifier used internally, f.e. "startTime"
external - Required: string identifier the column has in the external dataset f.e. "arrivalTimeOfCustomer"
'''
self.properties[internal] = external
if internal not in self.properties:
self.properties.append(internal)
def delete_mapping(self, internal: str):
'''
Removes a mapping from the layer. Raises a ValueError if the mapping identified by the internal representation
Removes a proprety from the layer. Raises a ValueError if the property identified by the internal representation
does not exist.
@params:
internal - Required: string identifier used internally, f.e. "startTime"
'''
if internal not in self.properties.keys():
if internal not in self.properties:
raise ValueError(f"Attribute {internal} is not an internal attribute!")
if internal in self.cluster_properties:
self.delete_cluster_mapping(internal)
del self.properties[internal]
self.properties.remove(internal)
def add_cluster_mapping(self, attribute:str):
'''
......@@ -61,7 +62,7 @@ class LayerAdapter:
@params:
attribute - Required: string identifier used internally, f.e. "startTime"
'''
if attribute not in self.properties.keys():
if attribute not in self.properties:
raise ValueError(f"Attribute {attribute} is not an internal attribute!")
if attribute not in self.cluster_properties:
......@@ -70,12 +71,12 @@ class LayerAdapter:
def delete_cluster_mapping(self, attribute:str):
'''
Removes an attribute from the set of cluster-attributes. Raises a ValueError if either the attribute does not exist
as an internal representation or if the attribute exists, but was not added as a cluster-attribute yet
as an internal representation
@params:
attribute - Required: string identifier used internally, f.e. "startTime"
'''
if attribute not in self.properties.keys():
if attribute not in self.properties:
raise ValueError(f"Attribute {attribute} is not an internal attribute!")
self.cluster_properties.remove(attribute)
......
from typing import Dict
class Schema:
def __init__(self, use_case:str, mappings:Dict[str, str]):
self.use_case = use_case
self.mappings = mappings
def add_mapping(self, internal:str, external:str):
if internal not in self.mappings.keys():
self.mappings[internal] = external
def to_serializable_dict(self) -> Dict:
return {
"use_case": self.use_case,
"mappings": self.mappings
}
@staticmethod
def from_serializable_dict(serializable_dict: Dict):
return Schema(
serializable_dict["use_case"],
serializable_dict["mappings"]
)
\ No newline at end of file
......@@ -3,6 +3,7 @@ import network_constants as netconst
from database.MongoRepositoryBase import MongoRepositoryBase
from db.entities.layer_adapter import LayerAdapter
from db.entities.use_case import UseCase
from db.entities.schema import Schema
import pymongo
import json
......@@ -18,6 +19,39 @@ class Repository(MongoRepositoryBase):
self._adapter_collection = 'layer_adapters'
self._use_case_collection = 'use_cases'
self._schema_collection = 'schemas'
def add_schema(self, schema: Schema):
self.put_use_case(schema.use_case)
super().insert_entry(self._schema_collection, schema.to_serializable_dict())
def all_schemas(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 schema_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 = 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 delete_schema_with_use_case(self, use_case: str):
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]
......
......@@ -16,7 +16,52 @@ def delete_uses_cases():
def all():
return LayerAdapterService.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):
'''
get all layers assigned to the given use_case
'''
return LayerAdapterService.all_for_use_case(use_case)
def add(name: str, use_case: str):
......@@ -47,14 +92,20 @@ def add_complete():
if layer != None:
return Response(status=400, response=f'Layer with name "{data["name"]}" already exists!')
# check if schema contains mapping
try:
layer_new = LayerAdapter.from_serializable_dict(data)
LayerAdapterService.add_complete(layer_new)
return Response(status=200)
except BaseException as e:
print(f"Exception: {e}")
return Response(status=400)
try:
LayerAdapterService.check_layer(layer_new)
except ValueError as e:
return Response(status = 400, response=f"{e}")
LayerAdapterService.add_complete(layer_new)
return Response(status=200)
def one(name: str, use_case: str):
'''
......@@ -80,14 +131,25 @@ def add_mapping_for_all(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)")
if "internal" not in data:
return Response(status=400, response=f"Field missing! Fields required: (internal)")
# 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!')
layers = LayerAdapterService.all_for_use_case(use_case)
layers = [LayerAdapter.from_serializable_dict(d) for d in layers]
for layer in layers:
layer.add_mapping(data["internal"], data["external"])
layer.add_mapping(data["internal"])
try:
LayerAdapterService.check_layer(layer)
except ValueError as e:
return Response(status = 400, response=f"{e}")
LayerAdapterService.update(layer)
return Response(status=200)
......@@ -107,10 +169,15 @@ def add_mapping(name: str, 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)")
if "internal" not in data:
return Response(status=400, response=f"Field missing! Fields required: (internal)")
layer.add_mapping(data["internal"], data["external"])
# 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)
return Response(status=200)
......@@ -134,6 +201,12 @@ def update_use_case_for_all(use_case: str):
for layer in layers:
layer.use_case = data["use_case"]
try:
LayerAdapterService.check_layer(layer)
except ValueError as e:
return Response(status = 400, response=f"{e}")
LayerAdapterService.update_use_case(layer, use_case)
return Response(status=200)
......@@ -164,7 +237,7 @@ def delete_mapping_for_all(use_case: str):
def delete_mapping(name: str, use_case: str):
'''
delete a mapping from the layer identified by name
delete a mapping from the layer identified by the internal representation
@params:
name - Required : unique identifier for the layer
......@@ -257,3 +330,10 @@ def delete_one(name: str, use_case: str):
LayerAdapterService.delete(layer)
return Response(status=200)
def delete_all_layers():
'''
delete all layers from the DB
'''
LayerAdapterService.delete_all_layers()
return Response(status=200)
\ No newline at end of file
#global imports
from db.repository import Repository
from db.entities.layer_adapter import LayerAdapter
from db.entities.schema import Schema
from typing import List
......@@ -9,6 +10,44 @@ class LayerAdapterService:
_repository = Repository()
@staticmethod
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
def check_layer(layer: LayerAdapter):
'''
checks if the given layer has correct mappings regarding the schema of the use_case
'''
schema = LayerAdapterService.put_schema(layer.use_case)
for p in layer.properties:
if p not in schema.mappings:
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()
......@@ -16,6 +55,7 @@ class LayerAdapterService:
@staticmethod
def delete_all_use_cases():
LayerAdapterService._repository.delete_all_use_cases()
LayerAdapterService._repository.delete_all_schemas()
LayerAdapterService._repository.delete_all_layers()
@staticmethod
......@@ -69,7 +109,7 @@ class LayerAdapterService:
name - Required : Unique name for a layer.
use_case - Required : String-identifier for the use-case
'''
adapter_new = LayerAdapter(name, use_case, {}, [])
adapter_new = LayerAdapter(name, use_case, [], [])
LayerAdapterService._repository.add(adapter_new)
......@@ -95,10 +135,9 @@ class LayerAdapterService:
use_case = layer.use_case
LayerAdapterService._repository.delete_all_with_name_and_use_case(layer.name, use_case)
# remove use-case if it is not needed
layers_in_use_case = LayerAdapterService.all_for_use_case(use_case)
if len(layers_in_use_case) == 0:
LayerAdapterService.delete_use_case(use_case)
@staticmethod
def delete_all_layers():
LayerAdapterService._repository.delete_all_layers()
@staticmethod
def one(name: str, use_case: str) -> LayerAdapter:
......
# global import, red is normal don't worry
import network_constants
import os
import json
import requests
class TokenManager:
_instance = None
@staticmethod
def getInstance():
''' Static access method. '''
if TokenManager._instance == None:
TokenManager._instance = TokenManager()
return TokenManager._instance
def __init__(self):
self._token = None
def getToken(self) -> str:
if self._token == None:
try:
credentials_path = '../../../modules/security/'
except KeyError:
credentials_path = '/srv/articonf/'
print("Looking for credentials at ... "+str(credentials_path))
with open(f'{credentials_path}regular_user_credentials.json') as file:
credentials = json.loads(file.read())
url = f'https://{network_constants.REST_GATEWAY_HOSTNAME}:{network_constants.REST_GATEWAY_REST_PORT}/api/tokens'
response = requests.post(
url,
verify = False,
proxies = { "http":None, "https":None },
json = credentials
)
data = json.loads(response.text)
self._token = data["token"]
return self._token
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment