Newer
Older
expected_parameters = ['entity_ids', 'entity_types', 'accept',
'attrs', 'context', 'geoproperty',
'options', 'limit', 'entity_id_pattern',
'georel', 'coordinates', 'geometry']
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
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}")
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
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
return response
def query_entities_via_post(kwargs) -> str:
expected_parameters = ['entity_ids', 'entity_types', 'content_type',
'attrs', 'entity_id_pattern', 'geoproperty']
if 'content_type' not in kwargs:
kwargs['content_type'] = 'application/ld+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:
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 'content_type':
response = f"{response} and\n Query Parameter: content_type set to '{value}'"
case 'attrs':
response = f"{response} and\n Query Parameter: attrs set to '{value}'"
case 'geoproperty':
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
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
@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_returning_response(kwargs) -> str:
if 'id' in kwargs:
return f"Delete Entity Request with id set to '{kwargs['id']}'"
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
1147
1148
@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
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
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
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
1233
1234
1235
1236
1237
1238
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
@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_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}'")
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
@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
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
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
@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