Commit 22ef8a54 authored by Manuel's avatar Manuel

added script to add car-sharing schema+layers

parent bde0fa8b
import sys
import os
from pathlib import Path
from typing import Dict, Any
import requests
modules_path = '../../../modules/'
if os.path.exists(modules_path):
sys.path.insert(1, modules_path)
import network_constants as nc
from security.token_manager import TokenManager
def add_car_layers():
use_case = "car-sharing"
layers = [
{
"use_case": use_case,
"name": "doctype_layer",
"properties": [
"UniqueID",
"doctype",
],
"cluster_properties": [
"doctype",
]
},
{
"use_case": use_case,
"name": "brand_layer",
"properties": [
"UniqueID",
"brand",
],
"cluster_properties": [
"brand",
]
},
{
"use_case": use_case,
"name": "model_layer",
"properties": [
"UniqueID",
"model",
],
"cluster_properties": [
"model",
]
},
{
"use_case": use_case,
"name": "colour_layer",
"properties": [
"UniqueID",
"colour",
],
"cluster_properties": [
"colour",
]
},
{
"use_case": use_case,
"name": "seats_layer",
"properties": [
"UniqueID",
"seats",
],
"cluster_properties": [
"seats",
]
},
{
"use_case": use_case,
"name": "year_layer",
"properties": [
"UniqueID",
"year",
],
"cluster_properties": [
"year",
]
},
]
jwt = TokenManager.getInstance().getToken()
for layer in layers:
url = f"https://articonf1.itec.aau.at:30420/api/layers"
response = requests.post(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = layer
)
if response.status_code == 200:
print(f"Response: {response.status_code}")
else:
print(f"Response: {response.status_code}: {response.text}")
def add_car_schema():
'''
take the columns and add the mappings at the server
replace all "/"'s in the internal representation with a "_"
'''
jwt = TokenManager.getInstance().getToken()
print(f"jwt token: {jwt}")
use_case = "car-sharing"
columns = [
"doctype",
"carLicensePlate",
"brand",
"model",
"colour",
"seats",
"year",
"ownerId",
"deleted",
"state",
"observations"
]
columns = { c : c for c in columns }
columns["UniqueID"] = "carLicensePlate"
url = f"https://articonf1.itec.aau.at:30420/api/use-cases/{use_case}/schema"
response = requests.post(
url,
verify=False,
proxies = { "http":None, "https":None },
headers = { "Authorization": f"Bearer {jwt}"},
json = columns
)
if response.status_code == 200:
print(f"Response: {response.status_code}")
return True
else:
print(f"Response: {response.status_code}: {response.text}")
return False
if __name__ == "__main__":
if add_car_schema():
add_car_layers()
\ 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