Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
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']
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
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 _:
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}'"
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
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
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
@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']}'"
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
@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
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
@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}")
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
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
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
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
@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', 'attrs',
'q', 'csf', 'georel', 'geometry',
'coordinates', 'geoproperty', 'timeproperty', 'timerel',
'timeAt', 'limit', 'page', '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 '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 '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}'"
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 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}'")
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
@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
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
@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