Commit 49040105 authored by Herry's avatar Herry

businessLogic: fixed bugs in endpoints caused by prior refactoring

parent 7e74f79a
......@@ -41,6 +41,9 @@ class TokenManager:
json = credentials
)
if response.status_code != 200:
raise ValueError(f"Server responded with ({response.status_code}): {response.text}")
data = json.loads(response.text)
self._token = data["token"]
......
......@@ -2,6 +2,7 @@
import network_constants as netconst
from database.MongoRepositoryBase import MongoRepositoryBase
from db.entities.schema import Schema
from db.use_case_repository import UseCaseRepository
import pymongo
import json
......@@ -22,13 +23,12 @@ class SchemaRepository(MongoRepositoryBase):
return [Schema.from_serializable_dict(row) for row in list(result)]
def add(self, schema: Schema):
self.put_use_case(schema.use_case)
super().insert_entry(self._schema_collection, schema.to_serializable_dict())
def get_for_use_case(self, use_case: str) -> Schema:
result = super().get_entries(self._schema_collection, projection={'_id': False}, selection={"use_case": use_case})
self.put(use_case)
result = list(super().get_entries(self._schema_collection, projection={'_id': False}, selection={"use_case": use_case}))
result = list(result)
if len(result) > 1:
raise ValueError("No more than 1 Schema allowed per use-case!")
......@@ -38,11 +38,13 @@ class SchemaRepository(MongoRepositoryBase):
return None
def put(self, use_case: str):
schema = self.get_for_use_case(use_case)
result = list(super().get_entries(self._schema_collection, projection={'_id': False}, selection={"use_case": use_case}))
if schema == None:
if len(result) == 0:
schema = Schema(use_case, mappings={})
self.add(schema)
else:
schema = Schema.from_serializable_dict(result[0])
return schema
......
......@@ -31,7 +31,7 @@ class UseCaseRepository(MongoRepositoryBase):
collection.delete_many({"name": name})
def put(self, use_case_name: str):
use_cases = self.all_use_cases()
use_cases = self.all()
existing_use_cases = list(filter(lambda use_case: use_case.name == use_case_name, use_cases))
......
......@@ -2,6 +2,7 @@
from db.entities.layer_adapter import LayerAdapter
from db.repository import Repository
from db.schema_repository import SchemaRepository
from db.use_case_repository import UseCaseRepository
from services.layer_adapter_service import LayerAdapterService
import json
......@@ -9,6 +10,7 @@ from flask import Response, request
schema_repository = SchemaRepository()
layer_repository = Repository()
use_case_repository = UseCaseRepository()
def all():
return [layer.to_serializable_dict() for layer in layer_repository.all()]
......@@ -17,6 +19,7 @@ def get_all_for_use_case(use_case: str):
'''
get all layers assigned to the given use_case
'''
use_case_repository.put(use_case)
return [layer.to_serializable_dict() for layer in layer_repository.all_for_use_case(use_case)]
def add_complete():
......@@ -28,6 +31,7 @@ def add_complete():
if "name" not in data or "properties" not in data or "cluster_properties" not in data or "use_case" not in data:
return Response(status=400, response=f"Field missing! Fields required: (name, properties, cluster_properties)")
use_case_repository.put(data["use_case"])
layer = layer_repository.one(data["name"], data["use_case"])
if layer != None:
......@@ -55,6 +59,7 @@ def one(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository.put(use_case)
layer = layer_repository.one(name, use_case)
if layer == None:
......@@ -70,6 +75,8 @@ def add_empty(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository.put(use_case)
if layer_repository.one(name, use_case) != None:
return Response(status=400, response=f"Layer with name '{name}' already exists!")
......@@ -84,6 +91,8 @@ def add_cluster_mapping(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository.put(use_case)
layer = layer_repository.one(name, use_case)
if layer == None:
......@@ -109,6 +118,8 @@ def delete_cluster_mapping(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository.put(use_case)
layer = layer_repository.one(name, use_case)
if layer == None:
......@@ -134,6 +145,8 @@ def add_mapping_for_all(use_case: str):
@params:
use_case - Required : String-identifier for the use-case
'''
use_case_repository.put(use_case)
data = request.json
if "internal" not in data:
......@@ -166,6 +179,8 @@ def delete_mapping_for_all(use_case: str):
@params:
use_case - Required : String-identifier for the use-case
'''
use_case_repository.put(use_case)
data = request.json
if "internal" not in data:
......@@ -190,6 +205,8 @@ def delete_mapping(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository.put(use_case)
layer = layer_repository.one(name, use_case)
if layer == None:
......@@ -216,6 +233,8 @@ def add_mapping(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository.put(use_case)
layer = layer_repository.one(name, use_case)
if layer == None:
......@@ -244,6 +263,8 @@ def delete_one(name: str, use_case: str):
name - Required : unique identifier for the layer
use_case - Required : String-identifier for the use-case
'''
use_case_repository.put(use_case)
layer = layer_repository.one(name, use_case)
if layer == None:
......
#global imports
from db.entities.layer_adapter import LayerAdapter
from db.schema_repository import SchemaRepository
from db.use_case_repository import UseCaseRepository
from services.layer_adapter_service import LayerAdapterService
import json
from flask import Response, request
use_case_repository = UseCaseRepository()
schema_repository = SchemaRepository()
def all():
return [schema.to_serializable_dict() for schema in schema_repository.all()]
def get_for_use_case(use_case:str):
use_case_repository.put(use_case)
schema = schema_repository.get_for_use_case(use_case)
if schema != None:
......@@ -30,6 +33,7 @@ def delete_for_use_case(use_case:str):
return Response(status=200)
def add_mapping(use_case:str):
use_case_repository.put(use_case)
data = request.json
if "internal" not in data or "external" not in data:
......
from db.entities.layer_adapter import LayerAdapter
from db.use_case_repository import UseCaseRepository
from db.repository import Repository
from db.schema_repository import SchemaRepository
from services.layer_adapter_service import LayerAdapterService
import json
from flask import Response, request
use_case_repository = UseCaseRepository()
schema_repository = SchemaRepository()
repository = Repository()
def all():
return [adapter.to_serializable_dict() for adapter in use_case_repository.all()]
return [use_case.to_serializable_dict() for use_case in use_case_repository.all()]
def delete_all():
LayerAdapterService.delete_all()
use_case_repository.delete_all()
repository.delete_all()
schema_repository.delete_all()
return Response(status=200)
\ No newline at end of file
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