Commit 3acc11bc authored by Manuel's avatar Manuel

roleStage: use-cases now get fetched from the server

parent b56119fa
......@@ -55,22 +55,45 @@ def _fetch_nodes(use_case: str, layer: Layer) -> List[Dict]:
return nodes
def fetch_nodes_from_semantic_linking(use_case: str):
# prune DB
repository = Repository()
repository.delete_all_layers()
repository.delete_all_nodes()
def _fetch_use_cases() -> List[str]:
# fetch use-cases
jwt = TokenManager.getInstance().getToken()
url = f'https://{network_constants.BUSINESS_LOGIC_HOSTNAME}:{network_constants.BUSINESS_LOGIC_REST_PORT}/api/use-cases'
response = requests.get(
url,
verify = False,
proxies = { "http":None, "https":None },
headers = {"Authorization": f"Bearer {jwt}"}
)
if response.status_code != 200:
raise ConnectionError(f"Could not fetch data from the server, statuscode: {response.status_code}!")
data = json.loads(response.text)
return [row["name"] for row in data]
def fetch_nodes_from_semantic_linking():
use_cases = _fetch_use_cases()
for use_case in use_cases:
# prune DB
repository = Repository()
repository.delete_all_layers()
repository.delete_all_nodes()
layers = _fetch_layers(use_case)
layers = _fetch_layers(use_case)
for layer in layers:
# check if layer already exists in DB, add it if not
reference_layer = repository.get_layer_for_use_case(layer.layer_name, use_case)
if reference_layer == None:
repository.add_layer(layer)
for layer in layers:
# check if layer already exists in DB, add it if not
reference_layer = repository.get_layer_for_use_case(layer.layer_name, use_case)
if reference_layer == None:
repository.add_layer(layer)
nodes = repository.get_layer_nodes(layer.layer_name)
nodes = _fetch_nodes(use_case, layer)
nodes = repository.get_layer_nodes(layer.layer_name)
nodes = _fetch_nodes(use_case, layer)
for node in nodes:
repository.add_layer_node(node)
\ No newline at end of file
for node in nodes:
repository.add_layer_node(node)
\ No newline at end of file
......@@ -10,4 +10,4 @@ import processing.fetching.fetching as f
if __name__ == "__main__":
# TODO read use_case from somewhere
f.fetch_nodes_from_semantic_linking("smart-energy")
\ No newline at end of file
f.fetch_nodes_from_semantic_linking()
\ 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