Newer
Older
result = [x for x in kwargs if x not in expected_parameters]
response = "Query Context Source Registration Subscriptions"
for key, value in kwargs.items():
match key:
case 'context':
response = f"{response} and\n Query Parameter: context set to '{value}'"
case 'limit':
response = f"{response} and\n Query Parameter: limit set to '{value}'"
case 'page':
response = f"{response} and\n Query Parameter: page set to '{value}'"
case 'accept':
response = f"{response} and\n Query Parameter: accept set to '{value}'"
# If an exact match is not confirmed, this last case will be used if provided
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
@staticmethod
def query_temporal_representation_of_entities(kwargs) -> str:
lopezaguilar
committed
# This function is a little bit special because we have a number of parameters not always defined and not always
# in the same position, so we make a different analysis to extract the values
expected_parameters = ['context', 'entity_types', 'entity_ids', 'entity_id_pattern',
'ngsild_query', 'csf', 'georel', 'geometry',
'coordinates', 'geoproperty', 'timerel', 'timeAt',
'attrs', 'limit', 'lastN', 'accept']
result = [x for x in kwargs if x not in expected_parameters]
lopezaguilar
committed
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
for key, value in kwargs.items():
match key:
case 'context':
response = f"{response} and\n Query Parameter: context set to '{value}'"
case 'entity_types':
response = f"{response} and\n Query Parameter: entity_types set to '{value}'"
case 'entity_ids':
response = f"{response} and\n Query Parameter: entity_ids set to '{value}'"
case 'entity_id_pattern':
response = f"{response} and\n Query Parameter: entity_id_pattern set to '{value}'"
case 'ngsild_query':
response = f"{response} and\n Query Parameter: ngsild_query set to '{value}'"
case 'csf':
response = f"{response} and\n Query Parameter: csf set to '{value}'"
case 'georel':
response = f"{response} and\n Query Parameter: georel set to '{value}'"
case 'geometry':
response = f"{response} and\n Query Parameter: geometry set to '{value}'"
case 'coordinates':
response = f"{response} and\n Query Parameter: coordinates set to '{value}'"
case 'geoproperty':
response = f"{response} and\n Query Parameter: geoproperty set to '{value}'"
case 'timerel':
response = f"{response} and\n Query Parameter: timerel set to '{value}'"
case 'timeAt':
response = f"{response} and\n Query Parameter: timeAt set to '{value}'"
case 'attrs':
response = f"{response} and\n Query Parameter: attrs set to '{value}'"
case 'limit':
response = f"{response} and\n Query Parameter: limit set to '{value}'"
case 'lastN':
value = re.search(pattern=r'\d+', string=value).group()
response = f"{response} and\n Query Parameter: lastN set to '{value}'"
case 'accept':
response = f"{response} and\n Query Parameter: accept set to '{value}'"
# If an exact match is not confirmed, this last case will be used if provided
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
@staticmethod
def retrieve_temporal_representation_of_entity(kwargs) -> str:
expected_parameters = ['temporal_entity_representation_id', 'attrs', 'options',
'context', 'timerel', 'timeAt',
'endTimeAt', 'lastN', 'accept']
result = [x for x in kwargs if x not in expected_parameters]
response = "Retrieve Temporal Representation of Entity"
for key, value in kwargs.items():
match key:
case 'temporal_entity_representation_id':
response = f"{response} and\n Query Parameter: id set to '{value}'"
case 'attrs':
response = f"{response} and\n Query Parameter: attrs set to '{value}'"
case 'options':
response = f"{response} and\n Query Parameter: options set to '{value}'"
case 'context':
response = f"{response} and\n Query Parameter: context set to '{value}'"
case 'timerel':
response = f"{response} and\n Query Parameter: timerel set to '{value}'"
case 'timeAt':
response = f"{response} and\n Query Parameter: timeAt set to '{value}'"
case 'endTimeAt':
response = f"{response} and\n Query Parameter: endTimeAt set to '{value}'"
case 'lastN':
value = re.search(pattern=r'\d+', string=value).group()
response = f"{response} and\n Query Parameter: lastN set to '{value}'"
case 'accept':
response = f"{response} and\n Query Parameter: accept set to '{value}'"
# If an exact match is not confirmed, this last case will be used if provided
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
@staticmethod
def retrieve_attribute(kwargs) -> str:
if 'attribute_name' in kwargs:
return f"Retrieve Attribute with attributeName set to '{kwargs['attribute_name']}'"
@staticmethod
def retrieve_entity_type(kwargs) -> str:
result = "Retrieve Entity Type"
if 'type' in kwargs:
result = f"{result}, with type set to '{kwargs['type']}'"
if 'context' in kwargs and kwargs['context'] != '':
result = f"{result}, with Header['Link'] containing '{kwargs['context']}'"
if 'type' not in kwargs or 'context' not in kwargs:
raise Exception(f"ERROR, expected type or context attributes, received '{kwargs}'")
return result
expected_parameters = ['entity_ids', 'entity_types', 'accept',
'attrs', 'context', 'geoproperty',
'options', 'limit', 'entity_id_pattern',
'georel', 'coordinates', 'geometry', 'count' , 'q']
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
result = [x for x in kwargs if x not in expected_parameters]
response = "Get Entities Request:"
for key, value in kwargs.items():
match key:
case 'entity_ids':
response = f"{response} and\n Query Parameter: entity_ids set to '{value}'"
case 'entity_types':
response = f"{response} and\n Query Parameter: entity_types set to '{value}'"
case 'accept':
response = f"{response} and\n Query Parameter: accept set to '{value}'"
case 'attrs':
response = f"{response} and\n Query Parameter: attrs set to '{value}'"
case 'context':
response = (f"{response} and\n Query Parameter: Link set to "
f"'<${value}>; rel=\"http://www.w3.org/ns/json-ld#context\";type=\"application/ld+json\"'")
case 'geoproperty':
response = f"{response} and\n Query Parameter: geoproperty set to '{value}'"
case 'options':
response = f"{response} and\n Query Parameter: options set to '{value}'"
case 'limit':
response = f"{response} and\n Query Parameter: limit set to '{value}'"
case 'entity_id_pattern':
response = f"{response} and\n Query Parameter: entity_id_pattern set to '{value}'"
case 'georel':
response = f"{response} and\n Query Parameter: georel set to '{value}'"
case 'coordinates':
response = f"{response} and\n Query Parameter: coordinates set to '{value}'"
case 'geometry':
response = f"{response} and\n Query Parameter: geometry set to '{value}'"
case 'count':
response = f"{response} and\n Query Parameter: count set to '{value}'"
case 'q':
response = f"{response} and\n Query Parameter: q set to '{value}'"
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
def query_entities_via_post(kwargs) -> str:
expected_parameters = ['entity_id', 'entity_type', 'content_type', 'accept',
'attrs', 'entity_id_pattern', 'geometry_property']
kwargs['content_type'] = 'application/json'
if 'accept' not in kwargs:
kwargs['accept'] = 'application/json'
result = [x for x in kwargs if x not in expected_parameters]
response = "Get Entities Via POST Request:"
for key, value in kwargs.items():
match key:
response = f"{response} and\n Query Parameter: entity_ids set to '{value}'"
response = f"{response} and\n Query Parameter: entity_types set to '{value}'"
case 'content_type':
response = f"{response} and\n Query Parameter: content_type set to '{value}'"
case 'accept':
response = f"{response} and\n Query Parameter: accept set to '{value}'"
case 'context':
response = f"{response} and\n Query Parameter: context set to '{value}'"
case 'attrs':
response = f"{response} and\n Query Parameter: attrs set to '{value}'"
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
response = f"{response} and\n Query Parameter: geoproperty set to '{value}'"
case 'entity_id_pattern':
response = f"{response} and\n Query Parameter: entity_id_pattern set to '{value}'"
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
def query_temporal_representation_of_entities_via_post(kwargs) -> str:
expected_parameters = ['query_file_name', 'content_type', 'context']
if 'content_type' not in kwargs:
kwargs['content_type'] = 'application/json'
result = [x for x in kwargs if x not in expected_parameters]
response = "Query Temporal Representation of Entities Via POST Request:"
for key, value in kwargs.items():
match key:
case 'query_file_name':
response = f"{response} and\n Query Parameter: query_file_name set to '{value}'"
case 'content_type':
response = f"{response} and\n Query Parameter: content_type set to '{value}'"
case 'context':
response = (f"{response} and\n Query Parameter: Link set to "
f"'<${value}>; rel=\"http://www.w3.org/ns/json-ld#context\";type=\"application/ld+json\"'")
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
@staticmethod
def retrieve_entity_by_id(kwargs) -> str:
expected_parameters = ['id', 'accept', 'context']
result = [x for x in kwargs if x not in expected_parameters]
response = 'Request Retrieve Entity by Id'
for key, value in kwargs.items():
match key:
case 'id':
response = f"{response} and\n Query Parameter: id set to '{value}'"
case 'accept':
response = f"{response} and\n Query Parameter: accept set to '{value}'"
case 'context':
response = f"{response} and\n Query Parameter: context set to '{value}'"
# If an exact match is not confirmed, this last case will be used if provided
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
@staticmethod
def delete_entity_by_id(kwargs) -> str:
if 'id' in kwargs:
return f"Delete Entity Request with id set to '{kwargs['id']}'"
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
@staticmethod
def delete_subscription(kwargs) -> str:
if 'id' in kwargs:
return f"Delete Subscription with id set to '{kwargs['id']}'"
@staticmethod
def query_subscriptions(kwargs) -> str:
expected_parameters = ['context', 'limit', 'offset', 'accept']
result = [x for x in kwargs if x not in expected_parameters]
response = 'Query Subscription Request with data:'
for key, value in kwargs.items():
match key:
case 'context':
response = f"{response} and\n Query Parameter: context set to '{value}'"
case 'limit':
response = f"{response} and\n Query Parameter: limit set to '{value}'"
case 'offset':
response = f"{response} and\n Query Parameter: offset set to '{value}'"
case 'accept':
response = f"{response} and\n Query Parameter: accept set to '{value}'"
# If an exact match is not confirmed, this last case will be used if provided
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
@staticmethod
def retrieve_context_source_registration_subscription(kwargs) -> str:
expected_parameters = ['subscription_id', 'context', 'accept']
result = [x for x in kwargs if x not in expected_parameters]
response = 'Retrieve Context Source Registration Subscription with data:'
for key, value in kwargs.items():
match key:
case 'subscription_id':
response = f"{response} and\n Query Parameter: subscription id set to '{value}'"
case 'context':
response = f"{response} and\n Query Parameter: context set to '{value}'"
case 'accept':
response = f"{response} and\n Query Parameter: accept set to '{value}'"
# If an exact match is not confirmed, this last case will be used if provided
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
@staticmethod
def delete_context_source_registration_with_return(kwargs) -> str:
if 'id' in kwargs:
return f"Delete Context Source Registration with id set to '{kwargs['id']}'"
@staticmethod
def update_context_source_registration(kwargs) -> str:
if 'context_source_registration_id' in kwargs and 'update_fragment' in kwargs:
return (f"Update Context Source Registration "
f"with CSR Id set to '{kwargs['context_source_registration_id']}' and "
f"subscription update fragment set to '{kwargs['update_fragment']}'")
else:
raise Exception(f"ERROR, expected 'context_source_registration_id' and 'update_fragment'"
f" but received: {kwargs}")
lopezaguilar
committed
@staticmethod
def update_context_source_registration_from_file(kwargs) -> str:
if 'context_source_registration_id' in kwargs and 'filename' in kwargs:
return (f"Update Context Source Registration "
f"with CSR Id set to '{kwargs['context_source_registration_id']}' and "
f"subscription update from file '{kwargs['filename']}'")
else:
raise Exception(f"ERROR, expected 'context_source_registration_id' and 'update_fragment'"
f" but received: {kwargs}")
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
@staticmethod
def update_context_source_registration_subscription(kwargs) -> str:
if 'subscription_id' in kwargs and 'subscription_update_fragment' in kwargs:
return (f"Update Context Source Registration Subscription "
f"with subscription id set to '{kwargs['subscription_id']}' and "
f"subscription update fragment set to '{kwargs['subscription_update_fragment']}'")
else:
raise Exception(f"ERROR, expected 'subscription_id' and 'subscription_update_fragment' but received: {kwargs}")
@staticmethod
def update_context_source_registration_subscription_from_file(kwargs) -> str:
if 'subscription_id' in kwargs and 'subscription_update_fragment' in kwargs:
return (f"Update Context Source Registration Subscription from file "
f"with subscription id set to '{kwargs['subscription_id']}' and "
f"subscription update fragment set to '{kwargs['subscription_update_fragment']}'")
else:
raise Exception(f"ERROR, expected 'subscription_id' and 'subscription_update_fragment' but received: {kwargs}")
@staticmethod
def retrieve_context_source_registration(kwargs) -> str:
expected_parameters = ['context_source_registration_id', 'context', 'accept']
result = [x for x in kwargs if x not in expected_parameters]
response = 'Retrieve Context Source Registration with data:'
for key, value in kwargs.items():
match key:
case 'context_source_registration_id':
response = f"{response} and\n Query Parameter: context source registration id set to '{value}'"
case 'context':
response = f"{response} and\n Query Parameter: context set to '{value}'"
case 'accept':
response = f"{response} and\n Query Parameter: accept set to '{value}'"
# If an exact match is not confirmed, this last case will be used if provided
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
@staticmethod
def query_context_source_registrations(kwargs) -> str:
expected_parameters = ['context', 'id', 'type', 'idPattern', 'attrs',
'q', 'csf', 'georel', 'geometry',
'coordinates', 'geoproperty', 'timeproperty', 'timerel',
lopezaguilar
committed
'timeAt', 'limit', 'offset', 'accept']
# kwargs = {key: kwargs.get(key, '${EMPTY}') for key in expected_parameters}
result = [x for x in kwargs if x not in expected_parameters]
response = "Retrieve Temporal Representation of Entity"
for key, value in kwargs.items():
match key:
case 'context':
response = f"{response} and\n Query Parameter: context set to '{value}'"
case 'id':
response = f"{response} and\n Query Parameter: id set to '{value}'"
case 'type':
response = f"{response} and\n Query Parameter: type set to '{value}'"
case 'attrs':
response = f"{response} and\n Query Parameter: attrs set to '{value}'"
case 'idPattern':
response = f"{response} and\n Query Parameter: idPattern set to '{value}'"
case 'q':
response = f"{response} and\n Query Parameter: q set to '{value}'"
case 'csf':
response = f"{response} and\n Query Parameter: csf set to '{value}'"
case 'georel':
response = f"{response} and\n Query Parameter: georel set to '{value}'"
case 'geometry':
response = f"{response} and\n Query Parameter: geometry set to '{value}'"
case 'coordinates':
response = f"{response} and\n Query Parameter: coordinates set to '{value}'"
case 'geoproperty':
response = f"{response} and\n Query Parameter: geoproperty set to '{value}'"
case 'timeproperty':
response = f"{response} and\n Query Parameter: timeproperty set to '{value}'"
case 'timerel':
response = f"{response} and\n Query Parameter: timerel set to '{value}'"
case 'timeAt':
response = f"{response} and\n Query Parameter: timeAt set to '{value}'"
case 'limit':
response = f"{response} and\n Query Parameter: limit set to '{value}'"
lopezaguilar
committed
case 'offset':
response = f"{response} and\n Query Parameter: offset set to '{value}'"
case 'accept':
response = f"{response} and\n Query Parameter: accept set to '{value}'"
# If an exact match is not confirmed, this last case will be used if provided
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
@staticmethod
def update_context_source_registration_with_return(kwargs) -> str:
if 'id' in kwargs and 'filename' in kwargs and 'content' in kwargs:
return (f"Update Context Source Registration with id set to '{kwargs['id']}' "
f"and registration update fragment set to '{kwargs['filename']}' "
f"and content-type set to '{kwargs['content']}'")
@staticmethod
def delete_temporal_representation_of_entity_with_returning_response(kwargs) -> str:
if 'id' in kwargs:
return f"Delete Temporal Representation Of Entity With Returning Response with id set to '{kwargs['id']}'"
@staticmethod
def retrieve_context_source_registration_subscription_2(kwargs) -> str:
if 'id' in kwargs:
return f"Retrieve Context Source Registration Subscription with id set to '{kwargs['id']}'"
else:
raise Exception(f"ERROR, expected 'id' but received: '{kwargs}'")
@staticmethod
def delete_context_source_registration_subscription(kwargs) -> str:
if 'id' in kwargs:
return f"Delete Context Source Registration Subscription with id set to '{kwargs['id']}'"
else:
raise Exception(f"ERROR, expected 'id' but received: '{kwargs}'")
@staticmethod
def create_context_source_registration_subscription(kwargs) -> str:
if 'filename' in kwargs:
return (f"Create Context Source Registration Subscription with filename set to '{kwargs['filename']}', "
f"accept set to '${{EMPTY}}', and content-type set to 'application/ld+json'")
else:
raise Exception(f"ERROR, expected 'filename' but received: '{kwargs}'")
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
@staticmethod
def append_attribute_to_temporal_entity(kwargs) -> str:
expected_parameters = ['id', 'fragment_filename', 'content_type']
result = [x for x in kwargs if x not in expected_parameters]
response = 'Append Attribute to Temporal Entity'
for key, value in kwargs.items():
match key:
case 'id':
response = f"{response} and\n Query Parameter: id set to '{value}'"
case 'fragment_filename':
response = f"{response} and\n Query Parameter: fragment_filename set to '{value}'"
case 'content_type':
response = f"{response} and\n Query Parameter: content_type set to '{value}'"
# If an exact match is not confirmed, this last case will be used if provided
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
@staticmethod
def append_entity_attributes(kwargs) -> str:
expected_parameters = ['id', 'fragment_filename', 'content_type']
result = [x for x in kwargs if x not in expected_parameters]
response = 'Append Entity Attributes'
for key, value in kwargs.items():
match key:
case 'id':
response = f"{response} and\n Query Parameter: id set to '{value}'"
case 'fragment_filename':
response = f"{response} and\n Query Parameter: fragment_filename set to '{value}'"
case 'content_type':
response = f"{response} and\n Query Parameter: content_type set to '{value}'"
# If an exact match is not confirmed, this last case will be used if provided
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
@staticmethod
def update_entity_attributes(kwargs) -> str:
expected_parameters = ['id', 'fragment_filename', 'content_type']
result = [x for x in kwargs if x not in expected_parameters]
response = 'Update Entity Attributes'
for key, value in kwargs.items():
match key:
case 'id':
response = f"{response} and\n Query Parameter: id set to '{value}'"
case 'fragment_filename':
response = f"{response} and\n Query Parameter: fragment_filename set to '{value}'"
case 'content_type':
response = f"{response} and\n Query Parameter: content_type set to '{value}'"
# If an exact match is not confirmed, this last case will be used if provided
case _:
raise Exception(f"ERROR, unexpected attribute '{result}', the attributes expected are "
f"'{expected_parameters}', but received: {kwargs}")
return response
def get_value(self, params, param_position, param_key):
data = [x for x in params if f'{param_key}=' in x]
# The name of the attribute is passed to the function in the form attribute=value
data = data.split('=')
if data[0] != param_key:
elif len(data) == 0:
# There is no attribute=something therefore we have to apply the position
try:
data = params[param_position]
# Workaround
if 'accept' in data and param_key != 'accept':
data = ''
except IndexError:
return ''
lopezaguilar
committed
return self.get_value_simple(data=data)
def get_value_simple(self, data):
return value
except KeyError:
try:
value = self.apiutils_variables[data]
try:
value = self.config_file.get_variable(variable=data)
return value
except KeyError:
try:
aux = self.template_params_value[self.name]
value = aux[data]
return value
except KeyError:
return data