Commit dcad5eb6 authored by Robin Knapp's avatar Robin Knapp

wip: ld migration

parent 55ed426b
......@@ -23,6 +23,10 @@
"nav": "type==type&value=value",
"type": "Property"
},
"initTick": {
"nav": "type==type&value=value",
"type": "Property"
},
"height": {
"nav": "type==type&value=value",
"type": "Property"
......@@ -57,19 +61,23 @@
},
"truckLocation": {
"nav": "type==type&value=value",
"type": "Property"
"type": "GeoProperty"
},
"version": {
"nav": "type==type&value=value",
"type": "Property"
},
"taxon": {
"nav": "type==type&value=value",
"type": "Property"
},
"width": {
"nav": "type==type&value=value",
"type": "Property"
},
"refDevice" : {
"nav": "type==type&value=object",
"ldType": "Relationship"
"nav": "type==type&value=value",
"type": "Relationship"
},
"flowerType": {
"nav": "type==type&value=value",
......
......@@ -233,7 +233,8 @@ class Connector(object):
try:
bp_key = current_app.config["URL_RESOURCES"]["URL_NAME_CONVENTIONS"]["BLUEPRINTS"]
bp_key = bp_key.format(modelname=model_type, modeltype=model_version) # '{modeltype}_{modelname}_BLUEPRINTS_URL'
bp_key = bp_key.format(modelname=model_type,
modeltype=model_version) # '{modeltype}_{modelname}_BLUEPRINTS_URL'
url = current_app.config["URL_RESOURCES"][bp_key]
current_app.logger.warning(f'<<{__name__}>> load blueprint from {url}')
return self.load_json_from_url(url=url)
......@@ -359,7 +360,7 @@ class Converter(object):
func='Converter.convert_ld_to_kv')
# single validation for @context attribute, delete afterwards if successful
FiwareElement(structuredvalue=ld_model["@context"])
FiwareElement(structuredvalue=str(ld_model["@context"]))
ld_model.pop('@context')
# iterate model and check attributes with blueprints & add attributes to kv-model
......@@ -377,8 +378,16 @@ class Converter(object):
, func='Converter.convert_ld_to_kv', module=__name__)
elif '=' in cmd:
kv_model_attr, ld_model_attr = cmd.split('=') # value, value/object
kv_model[ld_model_key] = ld_model_value[ld_model_attr]
kv_model_attr, ld_model_attr = cmd.split('=') # value, value
# the actual value may be hidden in `value: { ..., @value: <actual value>}`
if ld_model_value.get(ld_model_attr):
value = ld_model_value[ld_model_attr]
if isinstance(value, dict):
if value.get('@value'):
value = value['@value']
kv_model[ld_model_key] = value
else:
current_app.logger.debug(f"Error in {cmd}. Does not contain a comparison or assignment")
......@@ -386,7 +395,8 @@ class Converter(object):
, func='Converter.convert_v2_to_kv', module=__name__)
except KeyError:
raise ValidationException(extern=f'Attributes are not compliant with model. Caused by attribute' \
f' "{ld_model_key}"', func='Converter.convert_v2_to_kv', module=__name__)
f' "{ld_model_key}"', func='Converter.convert_ld_to_kv', module=__name__)
i = 1
return kv_model
......
......@@ -136,13 +136,14 @@ class StructuredValue(Validator):
"""
try:
res = ast.literal_eval(value)
if not isinstance(res, dict) and not isinstance(res, list):
raise ValueError("Structured Value needs to be in form of key-value-pairs or as listed values")
if isinstance(res, list):
if isinstance(res, dict):
return
elif isinstance(res, list):
for v in res:
if not (isinstance(v, str) or isinstance(v, int) or isinstance(v, float)):
raise ValueError(f'Value "{v}" is not of fiware-type Text or Number')
else:
raise ValueError("Structured Value needs to be in form of key-value-pairs or as listed values")
except (SyntaxError, ValueError):
raise ValueError("Structured Value needs to be in form of key-value-pairs")
......@@ -329,7 +330,14 @@ class Location(Validator):
value = transform_geo_json(geo_json=value)
coord_type = value['type']
coords = value['value']
# coordinates might be named 'value' in case of V2 and KV but might be named 'coordinates' in case of LD
if value.get('value'):
coords = value['value']
elif value.get('coordinates'):
coords = value['coordinates']
else:
raise KeyError('Model does not match to fiware `Location`-specifications')
if coord_type.lower() == 'geo:point': # "2,3" or [2, 3]
check_point_geom(point=coords)
......
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