Skip to content

Commit

Permalink
Merge pull request #440 from ScorpioBroker/vocab-support
Browse files Browse the repository at this point in the history
Vocab support
  • Loading branch information
ScorpioBroker committed Sep 13, 2023
2 parents f512a97 + 5d23a84 commit 9034419
Show file tree
Hide file tree
Showing 12 changed files with 996 additions and 62 deletions.
2 changes: 1 addition & 1 deletion AllInOneRunner/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ quarkus.flyway.baseline-on-migrate=true
quarkus.flyway.connect-retries=10
quarkus.flyway.repair-at-start=true
selfhostcorecontext=http://localhost:9090/corecontext
ngsild.corecontext=https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld
ngsild.corecontext=https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.7.jsonld
quarkus.rest-client.entity-service.url=http://localhost:9090
quarkus.rest-client.atcontext-service.url=http://localhost:9090
scorpio.registry.subscription.checkinterval=30s
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,30 @@ public class Constants {
allowedScalars.put(AppConstants.ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_OBJECT);
allowedScalars.put(AppConstants.ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_OBJECT_TYPE);
allowedScalars.put(AppConstants.ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VALUE);
allowedScalars.put(AppConstants.ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VOCAB);
allowedScalars.put(AppConstants.ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_COORDINATES);
allowedScalars.put(AppConstants.ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_UNIT_CODE);
allowedScalars.put(AppConstants.ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_DATA_SET_ID);
allowedScalars.put(AppConstants.ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_SCOPE);
allowedScalars.put(AppConstants.ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_OBJECT);
allowedScalars.put(AppConstants.ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_OBJECT_TYPE);
allowedScalars.put(AppConstants.ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VALUE);
allowedScalars.put(AppConstants.ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VOCAB);
allowedScalars.put(AppConstants.ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_COORDINATES);
allowedScalars.put(AppConstants.ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_UNIT_CODE);
allowedScalars.put(AppConstants.ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_DATA_SET_ID);
allowedScalars.put(AppConstants.ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_SCOPE);
allowedScalars.put(AppConstants.ENTITY_ATTRS_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_OBJECT);
allowedScalars.put(AppConstants.ENTITY_ATTRS_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_OBJECT_TYPE);
allowedScalars.put(AppConstants.ENTITY_ATTRS_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VALUE);
allowedScalars.put(AppConstants.ENTITY_ATTRS_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VOCAB);
allowedScalars.put(AppConstants.ENTITY_ATTRS_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_COORDINATES);
allowedScalars.put(AppConstants.ENTITY_ATTRS_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_UNIT_CODE);
allowedScalars.put(AppConstants.ENTITY_ATTRS_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_DATA_SET_ID);
allowedScalars.put(AppConstants.ENTITY_ATTRS_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_SCOPE);
allowedScalars.put(AppConstants.ENTITY_RETRIEVED_PAYLOAD, NGSIConstants.NGSI_LD_HAS_OBJECT);
allowedScalars.put(AppConstants.ENTITY_RETRIEVED_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VALUE);
allowedScalars.put(AppConstants.ENTITY_RETRIEVED_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VOCAB);
allowedScalars.put(AppConstants.ENTITY_RETRIEVED_PAYLOAD, NGSIConstants.NGSI_LD_COORDINATES);
allowedScalars.put(AppConstants.ENTITY_RETRIEVED_PAYLOAD, NGSIConstants.NGSI_LD_UNIT_CODE);
allowedScalars.put(AppConstants.ENTITY_RETRIEVED_PAYLOAD, NGSIConstants.NGSI_LD_DATA_SET_ID);
Expand All @@ -110,18 +114,21 @@ public class Constants {
allowedScalars.put(AppConstants.CSOURCE_REG_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_SCOPE);
allowedScalars.put(AppConstants.TEMP_ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_OBJECT);
allowedScalars.put(AppConstants.TEMP_ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VALUE);
allowedScalars.put(AppConstants.TEMP_ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VOCAB);
allowedScalars.put(AppConstants.TEMP_ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_COORDINATES);
allowedScalars.put(AppConstants.TEMP_ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_UNIT_CODE);
allowedScalars.put(AppConstants.TEMP_ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_DATA_SET_ID);
allowedScalars.put(AppConstants.TEMP_ENTITY_CREATE_PAYLOAD, NGSIConstants.NGSI_LD_SCOPE);
allowedScalars.put(AppConstants.TEMP_ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_OBJECT);
allowedScalars.put(AppConstants.TEMP_ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VALUE);
allowedScalars.put(AppConstants.TEMP_ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VOCAB);
allowedScalars.put(AppConstants.TEMP_ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_COORDINATES);
allowedScalars.put(AppConstants.TEMP_ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_UNIT_CODE);
allowedScalars.put(AppConstants.TEMP_ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_DATA_SET_ID);
allowedScalars.put(AppConstants.TEMP_ENTITY_UPDATE_PAYLOAD, NGSIConstants.NGSI_LD_SCOPE);
allowedScalars.put(AppConstants.TEMP_ENTITY_RETRIEVED_PAYLOAD, NGSIConstants.NGSI_LD_HAS_OBJECT);
allowedScalars.put(AppConstants.TEMP_ENTITY_RETRIEVED_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VALUE);
allowedScalars.put(AppConstants.TEMP_ENTITY_RETRIEVED_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VOCAB);
allowedScalars.put(AppConstants.TEMP_ENTITY_RETRIEVED_PAYLOAD, NGSIConstants.NGSI_LD_COORDINATES);
allowedScalars.put(AppConstants.TEMP_ENTITY_RETRIEVED_PAYLOAD, NGSIConstants.NGSI_LD_UNIT_CODE);
allowedScalars.put(AppConstants.TEMP_ENTITY_RETRIEVED_PAYLOAD, NGSIConstants.NGSI_LD_DATA_SET_ID);
Expand All @@ -134,6 +141,7 @@ public class Constants {
allowedScalars.put(AppConstants.MERGE_PATCH_PAYLOAD, NGSIConstants.NGSI_LD_HAS_OBJECT);
allowedScalars.put(AppConstants.MERGE_PATCH_PAYLOAD, NGSIConstants.NGSI_LD_OBJECT_TYPE);
allowedScalars.put(AppConstants.MERGE_PATCH_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VALUE);
allowedScalars.put(AppConstants.MERGE_PATCH_PAYLOAD, NGSIConstants.NGSI_LD_HAS_VOCAB);
allowedScalars.put(AppConstants.MERGE_PATCH_PAYLOAD, NGSIConstants.NGSI_LD_COORDINATES);
allowedScalars.put(AppConstants.MERGE_PATCH_PAYLOAD, NGSIConstants.NGSI_LD_UNIT_CODE);
allowedScalars.put(AppConstants.MERGE_PATCH_PAYLOAD, NGSIConstants.NGSI_LD_DATA_SET_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ public Object expandValue(String activeProperty, Object value) throws JsonLdErro
}
// 3)
rval.put(JsonLdConsts.VALUE, value);
// 4)
// 4)
if (td != null && td.containsKey(JsonLdConsts.TYPE)) {
rval.put(JsonLdConsts.TYPE, td.get(JsonLdConsts.TYPE));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,9 @@ else if (frameExpansion && (JsonLdConsts.EXPLICIT.equals(expandedProperty)
case AppConstants.TEMP_ENTITY_RETRIEVED_PAYLOAD:
if (NGSIConstants.NGSI_LD_HAS_VALUE.equals(expandedProperty)) {
ngsiElement.setHasAtValue(true);
} else if (NGSIConstants.NGSI_LD_HAS_OBJECT.equals(expandedProperty)) {
}else if (NGSIConstants.NGSI_LD_HAS_VOCAB.equals(expandedProperty)) {
ngsiElement.setHasVocab(true);
}else if (NGSIConstants.NGSI_LD_HAS_OBJECT.equals(expandedProperty)) {
ngsiElement.setHasAtObject(true);
} else if (NGSIConstants.NGSI_LD_DATE_TIME.equals(expandedProperty)) {
ngsiElement.setDateTime(true);
Expand Down
29 changes: 25 additions & 4 deletions Commons/src/main/java/com/github/jsonldjava/core/NGSIObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class NGSIObject {
private boolean hasAtContext = false;
private boolean atContextRequired = false;



private boolean isVocabProperty = false;
private boolean hasVocab=false;

private HashSet<String> datasetIds = new HashSet<String>();
private String id;
private String expandedProperty;
Expand All @@ -56,7 +61,9 @@ class NGSIObject {
this.parent = parent;

}
public boolean isVocabProperty() {return isVocabProperty;}

public boolean isHasVocab() {return hasVocab;}
public Object getElement() {
return element;
}
Expand Down Expand Up @@ -167,6 +174,8 @@ NGSIObject addType(String type) {
this.isDateTime = true;
} else if (NGSIConstants.NGSI_LD_LANGPROPERTY.equals(type)) {
this.isLanguageProperty = true;
}else if (NGSIConstants.NGSI_LD_VocabularyProperty.equals(type)) {
this.isVocabProperty = true;
}

return this;
Expand Down Expand Up @@ -595,7 +604,7 @@ private void validateAttribute(int payloadType, String expandedProperty, String
return;
}
if (isScalar) {
if (Constants.allowedDateTimes.get(payloadType).contains(expandedProperty)) {
if (Constants.allowedDateTimes.get(payloadType).contains(expandedProperty)) {
validateDateTime(activeProperty);
return;
}
Expand All @@ -615,16 +624,19 @@ private void validateAttribute(int payloadType, String expandedProperty, String
validateArray();
} else {
if (isLdKeyWord && parent == null && !isProperty && !isRelationship && !isGeoProperty && !isDateTime
&& !isLanguageProperty) {
&& !isLanguageProperty && !isVocabProperty) {
return;
}
if (!isProperty && !isRelationship && !isGeoProperty && !isDateTime && !isLanguageProperty) {
if (!isProperty && !isRelationship && !isGeoProperty && !isDateTime && !isLanguageProperty && !isVocabProperty) {
throw new ResponseException(ErrorType.BadRequestData,
"The key " + activeProperty + " is an invalid entry.");
}
if (isProperty && !hasValue) {
throw new ResponseException(ErrorType.BadRequestData, "You can't have properties without a value");
}
if (isVocabProperty && !hasVocab) {
throw new ResponseException(ErrorType.BadRequestData, "You can't have vocabulary property without a vocab");
}
if ((isRelationship && !hasObject)) {
throw new ResponseException(ErrorType.BadRequestData, "You can't have relationships without an object");
}
Expand Down Expand Up @@ -708,6 +720,14 @@ private void handleStringGeoProperty(JsonLdApi api) throws ResponseException {
}
}

public void setVocabProperty(boolean vocabProperty) {
this.isVocabProperty = vocabProperty;
}

public void setHasVocab(boolean hasVocab) {
this.hasVocab = hasVocab;
}

private void validateMultiPolygon(Object geoValue) throws ResponseException {
if (!(geoValue instanceof List)) {
throw new ResponseException(ErrorType.BadRequestData, "Invalid multi polygon definition");
Expand Down Expand Up @@ -825,7 +845,8 @@ public void fillUpForArray(NGSIObject ngsiV) {
this.isArray = this.isArray || ngsiV.isArray;
this.isLdKeyWord = this.isLdKeyWord || ngsiV.isLdKeyWord;
this.isScalar = this.isScalar || ngsiV.isScalar;
if ((ngsiV.isRelationship || ngsiV.isProperty || ngsiV.isLanguageProperty)) {
this.isVocabProperty = this.isVocabProperty || ngsiV.isVocabProperty;
if ((ngsiV.isRelationship || ngsiV.isProperty || ngsiV.isLanguageProperty || ngsiV.isVocabProperty)) {
if (ngsiV.datasetIds.isEmpty()) {
this.datasetIds.add(NGSIConstants.DEFAULT_DATA_SET_ID);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ public interface NGSIConstants {
public final static String NGSI_LD_MANAGEMENTINTERVAL = "https://uri.etsi.org/ngsi-ld/managementInterval";
public static final String NGSI_LD_GEOREL = "https://uri.etsi.org/ngsi-ld/georel";
public static final String NGSI_LD_SHOWCHANGES = "https://uri.etsi.org/ngsi-ld/showChanges";
public final static String NGSI_LD_HAS_VOCAB = "https://uri.etsi.org/ngsi-ld/hasVocab";
public final static String NGSI_LD_VocabularyProperty = "https://uri.etsi.org/ngsi-ld/VocabularyProperty";
public final static String VOCABULARYPROPERTY = "VocabularyProperty";

// IMPORTANT! DO NOT MESS UP THIS ORDER!!! ONLY APPEND ON THE END NEW STUFF
public final static String[] NGSI_LD_PAYLOAD_KEYS = { JSON_LD_ID, JSON_LD_TYPE, JSON_LD_CONTEXT,
NGSI_LD_DEFAULT_PREFIX, NGSI_LD_HAS_VALUE, NGSI_LD_HAS_OBJECT, JSON_LD_VALUE, NGSI_LD_LOCATION,
Expand All @@ -160,14 +164,14 @@ public interface NGSIConstants {
NGSI_LD_DESCRIPTION, NGSI_LD_GEO_REL, NGSI_LD_TIME_STAMP, NGSI_LD_TIMESTAMP_START, NGSI_LD_TIMESTAMP_END,
NGSI_LD_SUBSCRIPTION_ID, NGSI_LD_NOTIFIED_AT, NGSI_LD_DATA, NGSI_LD_INTERNAL, NGSI_LD_LAST_NOTIFICATION,
NGSI_LD_LAST_FAILURE, NGSI_LD_LAST_SUCCESS, NGSI_LD_TIMES_SENT, NGSI_LD_UNIT_CODE, NGSI_LD_DATA_SET_ID,
NGSI_LD_MANAGEMENTINTERVAL };
NGSI_LD_MANAGEMENTINTERVAL,NGSI_LD_HAS_VOCAB };

public final static String[] NGSI_LD_SUBSCRIPTON_PAYLOAD_KEYS = { JSON_LD_ID, JSON_LD_TYPE, JSON_LD_CONTEXT,
NGSI_LD_ENTITIES, NGSI_LD_ID_PATTERN, NGSI_LD_GEO_QUERY, NGSI_LD_NOTIFICATION, NGSI_LD_ATTRIBUTES,
NGSI_LD_ENDPOINT, NGSI_LD_ACCEPT, NGSI_LD_URI, NGSI_LD_FORMAT, NGSI_LD_QUERY, NGSI_LD_WATCHED_ATTRIBUTES,
NGSI_LD_TIMES_SENT, NGSI_LD_THROTTLING, NGSI_LD_TIME_INTERVAL, NGSI_LD_EXPIRES, NGSI_LD_STATUS,
NGSI_LD_DESCRIPTION, NGSI_LD_IS_ACTIVE, NGSI_LD_TIMESTAMP_END, NGSI_LD_TIMESTAMP_START,
NGSI_LD_SUBSCRIPTION_NAME };
NGSI_LD_SUBSCRIPTION_NAME,NGSI_LD_HAS_VOCAB };

public final static String GEO_JSON_COORDINATES = "coordinates";
public final static String GEO_JSON_TYPE = "type";
Expand Down Expand Up @@ -269,7 +273,7 @@ public interface NGSIConstants {
public static final Integer[] VALID_QOS = { 0, 1, 2 };
public static final String COUNT_HEADER_RESULT = "NGSILD-Results-Count";
public static final Set<String> NGSI_LD_ATTR_TYPES = Sets.newHashSet(NGSI_LD_PROPERTY, NGSI_LD_RELATIONSHIP,
NGSI_LD_GEOPROPERTY, NGSI_LD_LANGPROPERTY);
NGSI_LD_GEOPROPERTY, NGSI_LD_LANGPROPERTY,NGSI_LD_VocabularyProperty);

public final static String NOTIFICATION = "Notification";

Expand All @@ -279,6 +283,7 @@ public interface NGSIConstants {
public static final String ISACTIVE_TRUE = "active";

public static final Set<String> CORE_CONTEXT_URLS = Sets.newHashSet(
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.7.jsonld",
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.6.jsonld",
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.5.jsonld",
"https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context-v1.4.jsonld",
Expand Down Expand Up @@ -378,12 +383,13 @@ public interface NGSIConstants {
public final static String TYPE = "type";
public final static String RELATIONSHIP = "Relationship";
public final static String PROPERTY = "Property";
public final static String VOCAB = "vocab";
public final static String INSTANCE_ID = "instanceId";
public final static String QUERY_PARAMETER_CONCISE_VALUE = "concise";
public final static String QUERY_PARAMETER_CONCISE = "option";
public static final String SCOPE = "scope";
public static final String PREVIOUS_VALUE = "previousValue";

public static final String PREVIOUS_VOCAB = "previousVocab";
public static final String PREVIOUS_LANGUAGE_MAP = "previousLanguageMap";
public static final String PREVIOUS_OBJECT = "previousObject";
public static final String NGSI_LD_REG_MODE = "https://uri.etsi.org/ngsi-ld/mode";
Expand Down

0 comments on commit 9034419

Please sign in to comment.