Skip to content

Commit

Permalink
Add QWE IoT data project
Browse files Browse the repository at this point in the history
  • Loading branch information
zero88 committed Feb 8, 2021
1 parent 8b8df12 commit da6f299
Show file tree
Hide file tree
Showing 49 changed files with 2,114 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ subprojects {
project.ext.set("description", findProperty("description") ?: "A Vertx framework for microservice: ${project.name}")

afterEvaluate {
if (setOf("iot", "connectors", "bacnet").contains(project.name)) {
if (setOf("service").contains(project.name)) {
project.tasks.forEach { it.enabled = false }
} else {
println("- Project Name: ${project.ext.get("baseName")}")
Expand Down
5 changes: 5 additions & 0 deletions data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# IoT Data

## Overview

Defines IoT `data type`, `unit`, `converter`
5 changes: 5 additions & 0 deletions data/build.gradle.kts
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 data/src/main/java/io/github/zero88/qwe/iot/data/IoTEntities.java
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 data/src/main/java/io/github/zero88/qwe/iot/data/IoTEntity.java
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 data/src/main/java/io/github/zero88/qwe/iot/data/IoTEnum.java
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 {}
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 {}
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 {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package io.github.zero88.qwe.iot.data;

public interface TimeseriesData {}
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> {

}
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();

}
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> {

}
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> {

}
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;

}
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);
}

}
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;

}
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;

}
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();

}
Loading

0 comments on commit da6f299

Please sign in to comment.