diff --git a/src/main/java/de/app/fivegla/api/enums/SmartModelEntityType.java b/src/main/java/de/app/fivegla/api/enums/SmartModelEntityType.java new file mode 100644 index 00000000..3b3ebb98 --- /dev/null +++ b/src/main/java/de/app/fivegla/api/enums/SmartModelEntityType.java @@ -0,0 +1,12 @@ +package de.app.fivegla.api.enums; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum SmartModelEntityType { + DEVICE_MEASUREMENT("DeviceMeasurement"); + + private final String key; +} diff --git a/src/main/java/de/app/fivegla/integration/fiware/model/AgriCrop.java b/src/main/java/de/app/fivegla/integration/fiware/model/AgriCrop.java index ddaccf02..caca979f 100644 --- a/src/main/java/de/app/fivegla/integration/fiware/model/AgriCrop.java +++ b/src/main/java/de/app/fivegla/integration/fiware/model/AgriCrop.java @@ -5,6 +5,7 @@ import de.app.fivegla.integration.fiware.model.api.Validatable; import de.app.fivegla.integration.fiware.model.internal.Attribute; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.StringUtils; import java.util.List; @@ -35,6 +36,11 @@ public String asJson() { return json; } + @Override + public String asSmartModelJson() { + throw new NotImplementedException("Smart model JSON is not supported for AgriCrop."); + } + @Override public void validate() { if (StringUtils.isBlank(id)) { @@ -54,4 +60,9 @@ public String getId() { public String getType() { return type; } + + @Override + public boolean shouldCreateSmartModelEntity() { + return false; + } } diff --git a/src/main/java/de/app/fivegla/integration/fiware/model/CameraImage.java b/src/main/java/de/app/fivegla/integration/fiware/model/CameraImage.java index b35a1a41..932a18dc 100644 --- a/src/main/java/de/app/fivegla/integration/fiware/model/CameraImage.java +++ b/src/main/java/de/app/fivegla/integration/fiware/model/CameraImage.java @@ -4,6 +4,7 @@ import de.app.fivegla.integration.fiware.model.api.Validatable; import de.app.fivegla.integration.fiware.model.internal.Attribute; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.StringUtils; /** @@ -43,6 +44,11 @@ public String asJson() { return json; } + @Override + public String asSmartModelJson() { + throw new NotImplementedException("Smart model JSON is not supported for CameraImage."); + } + @Override public void validate() { if (StringUtils.isBlank(id)) { @@ -62,4 +68,9 @@ public String getId() { public String getType() { return type; } + + @Override + public boolean shouldCreateSmartModelEntity() { + return false; + } } diff --git a/src/main/java/de/app/fivegla/integration/fiware/model/DeviceMeasurement.java b/src/main/java/de/app/fivegla/integration/fiware/model/DeviceMeasurement.java index a81af1e9..1c7ebb12 100644 --- a/src/main/java/de/app/fivegla/integration/fiware/model/DeviceMeasurement.java +++ b/src/main/java/de/app/fivegla/integration/fiware/model/DeviceMeasurement.java @@ -1,5 +1,6 @@ package de.app.fivegla.integration.fiware.model; +import de.app.fivegla.api.enums.SmartModelEntityType; import de.app.fivegla.integration.fiware.model.api.FiwareEntity; import de.app.fivegla.integration.fiware.model.api.Validatable; import de.app.fivegla.integration.fiware.model.internal.Attribute; @@ -39,6 +40,23 @@ public String asJson() { return json; } + @Override + public String asSmartModelJson() { + validate(); + var json = "{" + + " \"id\":\"" + id.trim() + "\"," + + " \"type\":\"" + SmartModelEntityType.DEVICE_MEASUREMENT.getKey() + "\"," + + " \"customGroup\":" + group.asJson().trim() + "," + + " \"name\":" + name.asJson().trim() + "," + + " \"controlledProperty\":" + controlledProperty.asJson().trim() + "," + + " \"externalDataReference\":" + externalDataReference.asJson().trim() + "," + + " \"dateCreated\":" + dateCreated.asJson().trim() + "," + + " \"location\":" + locationAsJson(latitude, longitude).trim() + + "}"; + log.debug("{} as JSON: {}", this.getClass().getSimpleName(), json); + return json; + } + @Override public void validate() { if (StringUtils.isBlank(id)) { @@ -58,4 +76,9 @@ public String getId() { public String getType() { return type; } + + @Override + public boolean shouldCreateSmartModelEntity() { + return true; + } } diff --git a/src/main/java/de/app/fivegla/integration/fiware/model/DevicePosition.java b/src/main/java/de/app/fivegla/integration/fiware/model/DevicePosition.java index f317a93b..face54e0 100644 --- a/src/main/java/de/app/fivegla/integration/fiware/model/DevicePosition.java +++ b/src/main/java/de/app/fivegla/integration/fiware/model/DevicePosition.java @@ -4,6 +4,7 @@ import de.app.fivegla.integration.fiware.model.api.Validatable; import de.app.fivegla.integration.fiware.model.internal.Attribute; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.StringUtils; /** @@ -37,6 +38,11 @@ public String asJson() { return json; } + @Override + public String asSmartModelJson() { + throw new NotImplementedException("Smart model JSON is not supported for DevicePosition."); + } + @Override public void validate() { if (StringUtils.isBlank(id)) { @@ -56,4 +62,9 @@ public String getId() { public String getType() { return type; } + + @Override + public boolean shouldCreateSmartModelEntity() { + return false; + } } diff --git a/src/main/java/de/app/fivegla/integration/fiware/model/ManualPrecipitationEvent.java b/src/main/java/de/app/fivegla/integration/fiware/model/ManualPrecipitationEvent.java index 2e0e61b8..e4e3eaa6 100644 --- a/src/main/java/de/app/fivegla/integration/fiware/model/ManualPrecipitationEvent.java +++ b/src/main/java/de/app/fivegla/integration/fiware/model/ManualPrecipitationEvent.java @@ -5,6 +5,7 @@ import de.app.fivegla.integration.fiware.model.internal.Attribute; import de.app.fivegla.integration.fiware.model.internal.NumberAttribute; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.StringUtils; @Slf4j @@ -37,6 +38,11 @@ public String asJson() { return json; } + @Override + public String asSmartModelJson() { + throw new NotImplementedException("Smart model JSON is not supported for ManualPrecipitationEvent."); + } + @Override public void validate() { if (StringUtils.isBlank(id)) { @@ -56,4 +62,9 @@ public String getId() { public String getType() { return type; } + + @Override + public boolean shouldCreateSmartModelEntity() { + return false; + } } \ No newline at end of file diff --git a/src/main/java/de/app/fivegla/integration/fiware/model/ManualWeatherDataEvent.java b/src/main/java/de/app/fivegla/integration/fiware/model/ManualWeatherDataEvent.java index 0f9d1f74..56f05363 100644 --- a/src/main/java/de/app/fivegla/integration/fiware/model/ManualWeatherDataEvent.java +++ b/src/main/java/de/app/fivegla/integration/fiware/model/ManualWeatherDataEvent.java @@ -5,6 +5,7 @@ import de.app.fivegla.integration.fiware.model.internal.Attribute; import de.app.fivegla.integration.fiware.model.internal.NumberAttribute; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.StringUtils; @Slf4j @@ -51,6 +52,11 @@ public String asJson() { return json; } + @Override + public String asSmartModelJson() { + throw new NotImplementedException("Smart model JSON is not supported for ManualWeatherDataEvent."); + } + @Override public void validate() { if (StringUtils.isBlank(id)) { @@ -70,4 +76,9 @@ public String getId() { public String getType() { return type; } + + @Override + public boolean shouldCreateSmartModelEntity() { + return false; + } } \ No newline at end of file diff --git a/src/main/java/de/app/fivegla/integration/fiware/model/StationaryCameraImage.java b/src/main/java/de/app/fivegla/integration/fiware/model/StationaryCameraImage.java index 88c7df66..eb93fe39 100644 --- a/src/main/java/de/app/fivegla/integration/fiware/model/StationaryCameraImage.java +++ b/src/main/java/de/app/fivegla/integration/fiware/model/StationaryCameraImage.java @@ -41,6 +41,11 @@ public String asJson() { return json; } + @Override + public String asSmartModelJson() { + throw new UnsupportedOperationException("Smart model JSON is not supported for StationaryCameraImage."); + } + @Override public void validate() { if (StringUtils.isBlank(id)) { @@ -60,4 +65,9 @@ public String getId() { public String getType() { return type; } + + @Override + public boolean shouldCreateSmartModelEntity() { + return false; + } } diff --git a/src/main/java/de/app/fivegla/integration/fiware/model/WeatherData.java b/src/main/java/de/app/fivegla/integration/fiware/model/WeatherData.java index b3fe193f..b7c06ca7 100644 --- a/src/main/java/de/app/fivegla/integration/fiware/model/WeatherData.java +++ b/src/main/java/de/app/fivegla/integration/fiware/model/WeatherData.java @@ -5,6 +5,7 @@ import de.app.fivegla.integration.fiware.model.internal.Attribute; import de.app.fivegla.integration.fiware.model.internal.NumberAttribute; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.NotImplementedException; import org.apache.commons.lang3.StringUtils; @Slf4j @@ -55,6 +56,11 @@ public String asJson() { return json; } + @Override + public String asSmartModelJson() { + throw new NotImplementedException("Smart model JSON is not supported for WeatherData."); + } + @Override public void validate() { if (StringUtils.isBlank(id)) { @@ -74,4 +80,9 @@ public String getId() { public String getType() { return type; } + + @Override + public boolean shouldCreateSmartModelEntity() { + return false; + } } \ No newline at end of file diff --git a/src/main/java/de/app/fivegla/integration/fiware/model/api/FiwareEntity.java b/src/main/java/de/app/fivegla/integration/fiware/model/api/FiwareEntity.java index d4b29086..eb248d09 100644 --- a/src/main/java/de/app/fivegla/integration/fiware/model/api/FiwareEntity.java +++ b/src/main/java/de/app/fivegla/integration/fiware/model/api/FiwareEntity.java @@ -18,6 +18,13 @@ public interface FiwareEntity { */ String asJson(); + /** + * Converts the FiwareEntity object to JSON format for a smart model. + * + * @return The FiwareEntity object in JSON format for a smart model. + */ + String asSmartModelJson(); + /** * Returns the JSON representation of the location coordinates. * @@ -72,4 +79,11 @@ default String coordinatesAsJson(List coordinates) { * @return The type of the FiwareEntity object. */ String getType(); + + /** + * Returns whether a smart model entity should be created. + * + * @return true if a smart model entity should be created, false otherwise + */ + boolean shouldCreateSmartModelEntity(); } diff --git a/src/main/java/de/app/fivegla/integration/fiware/request/UpdateOrCreateFiwareEntitiesRequest.java b/src/main/java/de/app/fivegla/integration/fiware/request/UpdateOrCreateFiwareEntitiesRequest.java index 7715e12d..6a0eeab8 100644 --- a/src/main/java/de/app/fivegla/integration/fiware/request/UpdateOrCreateFiwareEntitiesRequest.java +++ b/src/main/java/de/app/fivegla/integration/fiware/request/UpdateOrCreateFiwareEntitiesRequest.java @@ -28,7 +28,11 @@ public class UpdateOrCreateFiwareEntitiesRequest { private List entities; public String asJson() { - return "{\"actionType\":\"" + actionType + "\",\"entities\":[" + entitiesAsJson() + "]}"; + return "{\"actionType\":\"" + actionType + "\",\"entities\":[" + entitiesAsJson() + "," + entitiesAsSmartModelJson() + "]}"; + } + + private String entitiesAsSmartModelJson() { + return entities.stream().filter(FiwareEntity::shouldCreateSmartModelEntity).map(FiwareEntity::asSmartModelJson).collect(Collectors.joining(",")); } private String entitiesAsJson() {