-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
2,114 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# IoT Data | ||
|
||
## Overview | ||
|
||
Defines IoT `data type`, `unit`, `converter` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dependencies { | ||
api(ZeroLibs.qwe_protocol) | ||
|
||
testImplementation(testFixtures(ZeroLibs.qwe_base)) | ||
} |
13 changes: 13 additions & 0 deletions
13
data/src/main/java/io/github/zero88/qwe/iot/data/IoTEntities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package io.github.zero88.qwe.iot.data; | ||
|
||
import java.util.Collection; | ||
|
||
import io.github.zero88.qwe.dto.JsonData; | ||
|
||
public interface IoTEntities<K, T extends IoTEntity<K>> extends JsonData { | ||
|
||
IoTEntities<K, T> add(T ioTEntity); | ||
|
||
Collection<T> entities(); | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
data/src/main/java/io/github/zero88/qwe/iot/data/IoTEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.github.zero88.qwe.iot.data; | ||
|
||
import io.github.zero88.qwe.dto.JsonData; | ||
import io.github.zero88.qwe.protocol.HasProtocol; | ||
|
||
import lombok.NonNull; | ||
|
||
/** | ||
* Represents for an {@code IoT virtual entity} | ||
* | ||
* @param <K> Type of entity key | ||
*/ | ||
public interface IoTEntity<K> extends IoTObject, HasProtocol, JsonData { | ||
|
||
/** | ||
* Gets entity key | ||
* | ||
* @return entity key | ||
*/ | ||
@NonNull K key(); | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
data/src/main/java/io/github/zero88/qwe/iot/data/IoTEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.github.zero88.qwe.iot.data; | ||
|
||
import io.github.zero88.qwe.dto.PlainType; | ||
|
||
public interface IoTEnum extends IoTProperty, PlainType {} |
5 changes: 5 additions & 0 deletions
5
data/src/main/java/io/github/zero88/qwe/iot/data/IoTObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.github.zero88.qwe.iot.data; | ||
|
||
import java.io.Serializable; | ||
|
||
public interface IoTObject extends Serializable {} |
5 changes: 5 additions & 0 deletions
5
data/src/main/java/io/github/zero88/qwe/iot/data/IoTProperty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package io.github.zero88.qwe.iot.data; | ||
|
||
public interface IoTProperty extends IoTObject { | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
data/src/main/java/io/github/zero88/qwe/iot/data/TimeseriesData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.github.zero88.qwe.iot.data; | ||
|
||
public interface TimeseriesData {} |
15 changes: 15 additions & 0 deletions
15
data/src/main/java/io/github/zero88/qwe/iot/data/converter/DataTypeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.github.zero88.qwe.iot.data.converter; | ||
|
||
import io.github.zero88.qwe.iot.data.unit.DataType; | ||
|
||
/** | ||
* Represents a converter between normal data type and the equivalent data type in another {@code protocol} | ||
* | ||
* @param <T> Type of Data type | ||
* @param <U> Type of specific protocol data type | ||
* @see DataType | ||
* @since 1.0.0 | ||
*/ | ||
public interface DataTypeConverter<T extends DataType, U> extends IoTConverter<T, U> { | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
data/src/main/java/io/github/zero88/qwe/iot/data/converter/IoTConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.github.zero88.qwe.iot.data.converter; | ||
|
||
import java.io.Serializable; | ||
|
||
import io.github.zero88.qwe.iot.data.IoTObject; | ||
import io.github.zero88.qwe.protocol.HasProtocol; | ||
import io.github.zero88.qwe.protocol.Protocol; | ||
|
||
import lombok.NonNull; | ||
|
||
/** | ||
* Represents a {@code converter} between two equivalent types of {@code IoT object} with different protocol | ||
* | ||
* @param <T> Type of IoT object | ||
* @param <U> Type of IoT object | ||
* @see Protocol | ||
* @see IoTObject | ||
* @since 1.0.0 | ||
*/ | ||
public interface IoTConverter<T, U> extends HasProtocol, Serializable { | ||
|
||
/** | ||
* Translate a {@code protocol} object to a {@code QWE IoT concept} | ||
* | ||
* @param object {@code protocol} object | ||
* @return The QWE IoT concept | ||
* @apiNote if cannot translate, output can be {@code null} or throw {@link IllegalArgumentException} depends on | ||
* detail implementation | ||
* @since 1.0.0 | ||
*/ | ||
T serialize(U object); | ||
|
||
/** | ||
* Translate {@code QWE IoT concept} to a {@code protocol} object | ||
* | ||
* @param concept The QWE IoT concept | ||
* @return The protocol object | ||
* @apiNote if cannot translate, output can be {@code null} or throw {@link IllegalArgumentException} depends on | ||
* detail implementation | ||
* @since 1.0.0 | ||
*/ | ||
U deserialize(T concept); | ||
|
||
/** | ||
* The {@code QWE IoT concept} type | ||
* | ||
* @return the class | ||
* @since 1.0.0 | ||
*/ | ||
@NonNull Class<T> fromType(); | ||
|
||
/** | ||
* The {@code protocol} object type | ||
* | ||
* @return the class | ||
* @since 1.0.0 | ||
*/ | ||
@NonNull Class<U> toType(); | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
data/src/main/java/io/github/zero88/qwe/iot/data/converter/IoTEntityConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.github.zero88.qwe.iot.data.converter; | ||
|
||
import io.github.zero88.qwe.iot.data.IoTEntity; | ||
|
||
/** | ||
* Represents a {@code converter} between two equivalent types of {@code IoT entity} with different protocol | ||
* | ||
* @param <T> Type of IoT entity | ||
* @param <U> Type of IoT entity | ||
* @since 1.0.0 | ||
*/ | ||
public interface IoTEntityConverter<T extends IoTEntity, U> extends IoTConverter<T, U> { | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
data/src/main/java/io/github/zero88/qwe/iot/data/converter/IoTPropertyConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package io.github.zero88.qwe.iot.data.converter; | ||
|
||
import io.github.zero88.qwe.iot.data.IoTProperty; | ||
|
||
/** | ||
* Represents a {@code converter} between two equivalent types of {@code IoT entity} with different protocol | ||
* | ||
* @param <T> Type of IoT property | ||
* @param <U> Type of IoT property or mixin from specific protocol | ||
* @see IoTProperty | ||
* @since 1.0.0 | ||
*/ | ||
public interface IoTPropertyConverter<T extends IoTProperty, U> extends IoTConverter<T, U> { | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
data/src/main/java/io/github/zero88/qwe/iot/data/entity/AbstractDevice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.github.zero88.qwe.iot.data.entity; | ||
|
||
import io.github.zero88.qwe.iot.data.enums.DeviceStatus; | ||
import io.github.zero88.qwe.iot.data.enums.DeviceType; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.experimental.Accessors; | ||
import lombok.experimental.FieldNameConstants; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Getter | ||
@SuperBuilder | ||
@FieldNameConstants | ||
@Accessors(fluent = true) | ||
public abstract class AbstractDevice<K> implements IDevice<K> { | ||
|
||
@JsonProperty("_" + Fields.key) | ||
private final K key; | ||
@NonNull | ||
@JsonProperty("_" + Fields.networkId) | ||
private final String networkId; | ||
@NonNull | ||
@JsonProperty("_" + Fields.address) | ||
private final JsonObject address; | ||
@NonNull | ||
@JsonProperty("_" + Fields.type) | ||
private final DeviceType type; | ||
@NonNull | ||
@JsonProperty("_" + Fields.name) | ||
private final String name; | ||
@NonNull | ||
@JsonProperty("_" + Fields.status) | ||
private final DeviceStatus status; | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
data/src/main/java/io/github/zero88/qwe/iot/data/entity/AbstractEntities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.github.zero88.qwe.iot.data.entity; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import io.github.zero88.qwe.iot.data.IoTEntities; | ||
import io.github.zero88.qwe.iot.data.IoTEntity; | ||
import io.vertx.core.json.JsonObject; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import lombok.NonNull; | ||
|
||
public abstract class AbstractEntities<K, T extends IoTEntity<K>> implements IoTEntities<K, T> { | ||
|
||
private final Map<K, T> data = new HashMap<>(); | ||
|
||
@Override | ||
public IoTEntities<K, T> add(T ioTEntity) { | ||
data.put(ioTEntity.key(), ioTEntity); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Collection<T> entities() { | ||
return data.values(); | ||
} | ||
|
||
@Override | ||
public JsonObject toJson(@NonNull ObjectMapper mapper) { | ||
return mapper.convertValue(data, JsonObject.class); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
data/src/main/java/io/github/zero88/qwe/iot/data/entity/AbstractPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.github.zero88.qwe.iot.data.entity; | ||
|
||
import io.github.zero88.qwe.iot.data.enums.PointType; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.experimental.Accessors; | ||
import lombok.experimental.FieldNameConstants; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Getter | ||
@SuperBuilder | ||
@FieldNameConstants | ||
@Accessors(fluent = true) | ||
public abstract class AbstractPoint<K> implements IPoint<K> { | ||
|
||
@JsonProperty("_" + Fields.key) | ||
private final K key; | ||
@NonNull | ||
@JsonProperty("_" + Fields.networkId) | ||
private final String networkId; | ||
@NonNull | ||
@JsonProperty("_" + Fields.deviceId) | ||
private final String deviceId; | ||
@NonNull | ||
@JsonProperty("_" + Fields.type) | ||
private final PointType type; | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
data/src/main/java/io/github/zero88/qwe/iot/data/entity/AbstractPointData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.github.zero88.qwe.iot.data.entity; | ||
|
||
import io.github.zero88.qwe.iot.data.property.PointPresentValue; | ||
import io.github.zero88.qwe.iot.data.property.PointPriorityArray; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.experimental.Accessors; | ||
import lombok.experimental.FieldNameConstants; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Getter | ||
@SuperBuilder | ||
@FieldNameConstants | ||
@Accessors(fluent = true) | ||
public abstract class AbstractPointData<K> implements IPointData<K> { | ||
|
||
@JsonProperty(Fields.key) | ||
private final K key; | ||
@NonNull | ||
@JsonProperty(Fields.pointId) | ||
private final String pointId; | ||
@NonNull | ||
@JsonProperty(Fields.presentValue) | ||
private final PointPresentValue presentValue; | ||
@NonNull | ||
@JsonProperty(Fields.priorityValue) | ||
private final PointPriorityArray priorityValue; | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
data/src/main/java/io/github/zero88/qwe/iot/data/entity/HasObjectType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.github.zero88.qwe.iot.data.entity; | ||
|
||
import lombok.NonNull; | ||
|
||
/** | ||
* @param <T> Type of IoT object type | ||
*/ | ||
public interface HasObjectType<T> { | ||
|
||
@NonNull T type(); | ||
|
||
} |
Oops, something went wrong.