From e63504470161d63d02888c92e8beeac1901d985b Mon Sep 17 00:00:00 2001 From: Ken Zangelin Date: Tue, 7 Jan 2025 17:22:12 +0100 Subject: [PATCH] VocabularyProperty => VocabProperty --- CHANGES_NEXT_RELEASE | 3 +- .../orionld/dbModel/dbModelToApiAttribute.cpp | 14 ++-- .../dbModel/dbModelToApiSubAttribute.cpp | 3 +- .../orionld/payloadCheck/pCheckAttribute.cpp | 42 +++++++----- src/lib/orionld/troe/pgAttributeBuild.cpp | 2 +- .../orionld/types/OrionldAttributeType.cpp | 3 +- ...ch_registration_all_individual_fields.test | 6 +- ...ch_registration_all_individual_fields.test | 6 +- .../0000_ngsild/ngsild_vocab-property.test | 68 ++++++++++--------- 9 files changed, 84 insertions(+), 63 deletions(-) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 4f689531bc..d2ff26ad6a 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -3,8 +3,9 @@ #1707: Support for local=true in the type discovery endpoints (GET /ngsi-ld/v1/types[/{typeName}] #XXXX: Support for local=true in the ATTRIBUTE discovery endpoints (GET /ngsi-ld/v1/attributes}] #1708: Reloaded hosted contexts were not persisted in mongo, only the context cache + #XXXX: Using "VocabProperty" and not "VocabularyProperty" (old name still accepted as input) ## New Features: - * Support for ... + * ## Notes diff --git a/src/lib/orionld/dbModel/dbModelToApiAttribute.cpp b/src/lib/orionld/dbModel/dbModelToApiAttribute.cpp index 0c88f392e3..a0373046cf 100644 --- a/src/lib/orionld/dbModel/dbModelToApiAttribute.cpp +++ b/src/lib/orionld/dbModel/dbModelToApiAttribute.cpp @@ -114,9 +114,10 @@ void dbModelToApiAttribute(KjNode* dbAttrP, bool sysAttrs, bool eqsForDots) if (strcmp(typeP->value.s, "Relationship") == 0) valueP->name = (char*) "object"; else if (strcmp(typeP->value.s, "LanguageProperty") == 0) valueP->name = (char*) "languageMap"; else if (strcmp(typeP->value.s, "JsonProperty") == 0) valueP->name = (char*) "json"; - else if (strcmp(typeP->value.s, "VocabularyProperty") == 0) + else if ((strcmp(typeP->value.s, "VocabularyProperty") == 0) || (strcmp(typeP->value.s, "VocabProperty") == 0)) { - valueP->name = (char*) "vocab"; + typeP->value.s = (char*) "VocabProperty"; + valueP->name = (char*) "vocab"; if (valueP->type == KjString) valueP->value.s = orionldContextItemAliasLookup(orionldState.contextP, valueP->value.s, NULL, NULL); @@ -354,7 +355,10 @@ KjNode* dbModelToApiAttribute2(KjNode* dbAttrP, KjNode* datasetP, bool sysAttrs, // And call dbModelToApiSubAttribute2 with Concise // bool conciseAsKeyValues = false; - KjNode* attrTypeNodeP = NULL; + KjNode* attrTypeNodeP = kjLookup(dbAttrP, "type"); + + if ((attrTypeNodeP != NULL) && (strcmp(attrTypeNodeP->value.s, "VocabularyProperty") == 0)) + attrTypeNodeP->value.s = (char*) "VocabProperty"; if ((renderFormat == RF_CONCISE) && (sysAttrs == false)) { @@ -377,7 +381,7 @@ KjNode* dbModelToApiAttribute2(KjNode* dbAttrP, KjNode* datasetP, bool sysAttrs, dbModelToApiLangPropertySimplified(dbAttrP, lang); attrP = dbAttrP; } - else if (strcmp(attrTypeNodeP->value.s, "VocabularyProperty") == 0) + else if (strcmp(attrTypeNodeP->value.s, "VocabProperty") == 0) { KjNode* valueP = kjLookup(dbAttrP, "value"); @@ -392,6 +396,8 @@ KjNode* dbModelToApiAttribute2(KjNode* dbAttrP, KjNode* datasetP, bool sysAttrs, } } + attrTypeNodeP->value.s = (char*) "VocabProperty"; + // Remove everything except the value, and change its name to "vocab" dbAttrP->value.firstChildP = valueP; dbAttrP->lastChild = valueP; diff --git a/src/lib/orionld/dbModel/dbModelToApiSubAttribute.cpp b/src/lib/orionld/dbModel/dbModelToApiSubAttribute.cpp index 6a9042ee6e..f64f44cb28 100644 --- a/src/lib/orionld/dbModel/dbModelToApiSubAttribute.cpp +++ b/src/lib/orionld/dbModel/dbModelToApiSubAttribute.cpp @@ -84,7 +84,8 @@ void dbModelToApiSubAttribute(KjNode* dbSubAttrP) { if (strcmp(typeP->value.s, "Relationship") == 0) valueP->name = (char*) "object"; else if (strcmp(typeP->value.s, "LanguageProperty") == 0) valueP->name = (char*) "languageMap"; - else if (strcmp(typeP->value.s, "VocabularyProperty") == 0) valueP->name = (char*) "vocab"; + else if (strcmp(typeP->value.s, "VocabularyProperty") == 0) { valueP->name = (char*) "vocab"; typeP->value.s = (char*) "VocabProperty"; } + else if (strcmp(typeP->value.s, "VocabProperty") == 0) valueP->name = (char*) "vocab"; else if (strcmp(typeP->value.s, "JsonProperty") == 0) valueP->name = (char*) "json"; } } diff --git a/src/lib/orionld/payloadCheck/pCheckAttribute.cpp b/src/lib/orionld/payloadCheck/pCheckAttribute.cpp index 8c0c451c5a..f67e00b530 100644 --- a/src/lib/orionld/payloadCheck/pCheckAttribute.cpp +++ b/src/lib/orionld/payloadCheck/pCheckAttribute.cpp @@ -70,7 +70,7 @@ static const char* attrTypeChangeTitle(OrionldAttributeType oldType, OrionldAttr if (oldType == Relationship) return "Attempt to transform a Relationship into a Property"; if (oldType == GeoProperty) return "Attempt to transform a GeoProperty into a Property"; if (oldType == LanguageProperty) return "Attempt to transform a LanguageProperty into a Property"; - if (oldType == VocabularyProperty) return "Attempt to transform a VocabularyProperty into a Property"; + if (oldType == VocabularyProperty) return "Attempt to transform a VocabProperty into a Property"; if (oldType == JsonProperty) return "Attempt to transform a JsonProperty into a Property"; } else if (newType == Relationship) @@ -78,7 +78,7 @@ static const char* attrTypeChangeTitle(OrionldAttributeType oldType, OrionldAttr if (oldType == Property) return "Attempt to transform a Property into a Relationship"; if (oldType == GeoProperty) return "Attempt to transform a GeoProperty into a Relationship"; if (oldType == LanguageProperty) return "Attempt to transform a LanguageProperty into a Relationship"; - if (oldType == VocabularyProperty) return "Attempt to transform a VocabularyProperty into a Relationship"; + if (oldType == VocabularyProperty) return "Attempt to transform a VocabProperty into a Relationship"; if (oldType == JsonProperty) return "Attempt to transform a JsonProperty into a Relationship"; } else if (newType == GeoProperty) @@ -86,7 +86,7 @@ static const char* attrTypeChangeTitle(OrionldAttributeType oldType, OrionldAttr if (oldType == Property) return "Attempt to transform a Property into a GeoProperty"; if (oldType == Relationship) return "Attempt to transform a Relationship into a GeoProperty"; if (oldType == LanguageProperty) return "Attempt to transform a LanguageProperty into a GeoProperty"; - if (oldType == VocabularyProperty) return "Attempt to transform a VocabularyProperty into a GeoProperty"; + if (oldType == VocabularyProperty) return "Attempt to transform a VocabProperty into a GeoProperty"; if (oldType == JsonProperty) return "Attempt to transform a JsonProperty into a GeoProperty"; } else if (newType == LanguageProperty) @@ -94,16 +94,16 @@ static const char* attrTypeChangeTitle(OrionldAttributeType oldType, OrionldAttr if (oldType == Property) return "Attempt to transform a Property into a LanguageProperty"; if (oldType == Relationship) return "Attempt to transform a Relationship into a LanguageProperty"; if (oldType == GeoProperty) return "Attempt to transform a GeoProperty into a LanguageProperty"; - if (oldType == VocabularyProperty) return "Attempt to transform a VocabularyProperty into a LanguageProperty"; + if (oldType == VocabularyProperty) return "Attempt to transform a VocabProperty into a LanguageProperty"; if (oldType == JsonProperty) return "Attempt to transform a JsonProperty into a LanguageProperty"; } else if (newType == VocabularyProperty) { - if (oldType == Property) return "Attempt to transform a Property into a VocabularyProperty"; - if (oldType == Relationship) return "Attempt to transform a Relationship into a VocabularyProperty"; - if (oldType == GeoProperty) return "Attempt to transform a GeoProperty into a VocabularyProperty"; - if (oldType == LanguageProperty) return "Attempt to transform a LanguageProperty into a VocabularyProperty"; - if (oldType == JsonProperty) return "Attempt to transform a JsonProperty into a VocabularyProperty"; + if (oldType == Property) return "Attempt to transform a Property into a VocabProperty"; + if (oldType == Relationship) return "Attempt to transform a Relationship into a VocabProperty"; + if (oldType == GeoProperty) return "Attempt to transform a GeoProperty into a VocabProperty"; + if (oldType == LanguageProperty) return "Attempt to transform a LanguageProperty into a VocabProperty"; + if (oldType == JsonProperty) return "Attempt to transform a JsonProperty into a VocabProperty"; } else if (newType == JsonProperty) { @@ -111,7 +111,7 @@ static const char* attrTypeChangeTitle(OrionldAttributeType oldType, OrionldAttr if (oldType == Relationship) return "Attempt to transform a Relationship into a JsonProperty"; if (oldType == GeoProperty) return "Attempt to transform a GeoProperty into a JsonProperty"; if (oldType == LanguageProperty) return "Attempt to transform a LanguageProperty into a JsonProperty"; - if (oldType == VocabularyProperty) return "Attempt to transform a VocabularyProperty into a JsonProperty"; + if (oldType == VocabularyProperty) return "Attempt to transform a VocabProperty into a JsonProperty"; } return "Attribute type inconsistency"; @@ -547,27 +547,27 @@ bool valueAndTypeCheck(KjNode* attrP, OrionldAttributeType attributeType, bool a { if (valueP != NULL) { - orionldError(OrionldBadRequestData, "Forbidden field for a VocabularyProperty: value", attrP->name, 400); + orionldError(OrionldBadRequestData, "Forbidden field for a VocabProperty: value", attrP->name, 400); return false; } else if (objectP != NULL) { - orionldError(OrionldBadRequestData, "Forbidden field for a VocabularyProperty: object", attrP->name, 400); + orionldError(OrionldBadRequestData, "Forbidden field for a VocabProperty: object", attrP->name, 400); return false; } else if (languageMapP != NULL) { - orionldError(OrionldBadRequestData, "Forbidden field for a VocabularyProperty: languageMap", attrP->name, 400); + orionldError(OrionldBadRequestData, "Forbidden field for a VocabProperty: languageMap", attrP->name, 400); return false; } else if (jsonP != NULL) { - orionldError(OrionldBadRequestData, "Forbidden field for a VocabularyProperty: json", attrP->name, 400); + orionldError(OrionldBadRequestData, "Forbidden field for a VocabProperty: json", attrP->name, 400); return false; } else if ((vocabP == NULL) && (attributeExisted == false)) // Attribute is new but the value is missing { - orionldError(OrionldBadRequestData, "Missing /vocab/ field for VocabularyProperty at creation time", attrP->name, 400); + orionldError(OrionldBadRequestData, "Missing /vocab/ field for VocabProperty at creation time", attrP->name, 400); return false; } @@ -737,7 +737,7 @@ static bool pCheckVocabulary(KjNode* vocabP, const char* attrName) { if (wordP->type != KjString) { - orionldError(OrionldBadRequestData, "Invalid VocabularyProperty vocab array item - not a string", attrName, 400); + orionldError(OrionldBadRequestData, "Invalid VocabProperty vocab array item - not a string", attrName, 400); return false; } @@ -746,7 +746,7 @@ static bool pCheckVocabulary(KjNode* vocabP, const char* attrName) } else { - orionldError(OrionldBadRequestData, "Invalid VocabularyProperty vocab - not a string nor an array", attrName, 400); + orionldError(OrionldBadRequestData, "Invalid VocabProperty vocab - not a string nor an array", attrName, 400); return false; } @@ -898,8 +898,10 @@ bool deletionWithTypePresent(KjNode* attrP, KjNode* typeP) return true; } } - else if (strcmp(typeP->value.s, "VocabularyProperty") == 0) + else if ((strcmp(typeP->value.s, "VocabularyProperty") == 0) || (strcmp(typeP->value.s, "VocabProperty") == 0)) { + typeP->value.s = (char*) "VocabProperty"; + valueP = kjLookup(attrP, "vocab"); if ((valueP != NULL) && (valueP->type == KjString) && (strcmp(valueP->value.s, "urn:ngsi-ld:null") == 0)) { @@ -1091,6 +1093,10 @@ static bool pCheckAttributeObject bool geoJsonValue = false; attributeType = orionldAttributeType(typeP->value.s); + + if (strcmp(typeP->value.s, "VocabularyProperty") == 0) + typeP->value.s = (char*) "VocabProperty"; + if (attributeType == NoAttributeType) { if (isGeoJsonValue(attrP)) diff --git a/src/lib/orionld/troe/pgAttributeBuild.cpp b/src/lib/orionld/troe/pgAttributeBuild.cpp index 8c21f43002..cd9c69a47b 100644 --- a/src/lib/orionld/troe/pgAttributeBuild.cpp +++ b/src/lib/orionld/troe/pgAttributeBuild.cpp @@ -162,7 +162,7 @@ bool pgAttributeBuild skip = (char*) "RelationshipArray"; } else if (strcmp(nodeP->name, "languageMap") == 0) skip = (char*) "LanguageProperty"; - else if (strcmp(nodeP->name, "vocab") == 0) skip = (char*) "VocabularyProperty"; + else if (strcmp(nodeP->name, "vocab") == 0) skip = (char*) "VocabProperty"; else if (strcmp(nodeP->name, "createdAt") == 0) {} // skip = (char*) "BuiltinTimestamp"; else if (strcmp(nodeP->name, "modifiedAt") == 0) {} // skip = (char*) "BuiltinTimestamp"; else if (strcmp(nodeP->name, "https://uri.etsi.org/ngsi-ld/createdAt") == 0) {} // Skipping diff --git a/src/lib/orionld/types/OrionldAttributeType.cpp b/src/lib/orionld/types/OrionldAttributeType.cpp index cb6f9f2811..bab7e79b4a 100644 --- a/src/lib/orionld/types/OrionldAttributeType.cpp +++ b/src/lib/orionld/types/OrionldAttributeType.cpp @@ -43,7 +43,7 @@ const char* orionldAttributeTypeName(OrionldAttributeType attributeType) case Relationship: return "Relationship"; case GeoProperty: return "GeoProperty"; case LanguageProperty: return "LanguageProperty"; - case VocabularyProperty: return "VocabularyProperty"; + case VocabularyProperty: return "VocabProperty"; case JsonProperty: return "JsonProperty"; } @@ -62,6 +62,7 @@ OrionldAttributeType orionldAttributeType(const char* typeString) else if (strcmp(typeString, "Relationship") == 0) return Relationship; else if (strcmp(typeString, "GeoProperty") == 0) return GeoProperty; else if (strcmp(typeString, "LanguageProperty") == 0) return LanguageProperty; + else if (strcmp(typeString, "VocabProperty") == 0) return VocabularyProperty; else if (strcmp(typeString, "VocabularyProperty") == 0) return VocabularyProperty; else if (strcmp(typeString, "JsonProperty") == 0) return JsonProperty; diff --git a/test/functionalTest/cases/0000_ngsild/ngsild_new_patch_registration_all_individual_fields.test b/test/functionalTest/cases/0000_ngsild/ngsild_new_patch_registration_all_individual_fields.test index 259397e874..e5a3f912f6 100644 --- a/test/functionalTest/cases/0000_ngsild/ngsild_new_patch_registration_all_individual_fields.test +++ b/test/functionalTest/cases/0000_ngsild/ngsild_new_patch_registration_all_individual_fields.test @@ -410,7 +410,7 @@ payload='{ "type": "Point", "coordinates": [ 31.0, 32.77 ] }, - "expiresAt": "2024-12-31T10:00:19.975Z", + "expiresAt": "2029-12-31T10:00:19.975Z", "endpoint": "http://my.other.csource.org:1099", "P1": [ 1, 2, 3, 4 ] }' @@ -1685,7 +1685,7 @@ Link: