1
0

Add entities package

This commit is contained in:
Jose
2025-03-13 14:16:50 +01:00
parent b5561dea70
commit f00c9cdac0
14 changed files with 195 additions and 6 deletions

View File

@@ -20,6 +20,13 @@
<version>4.5.13</version>
</dependency>
<!-- Vert.X Web Client -->
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-web-client</artifactId>
<version>4.5.13</version>
</dependency>
<!-- Vert.X MQTT -->
<dependency>
<groupId>io.vertx</groupId>

View File

@@ -0,0 +1,5 @@
package net.miarma.contaminus.common.entities;
public class Actuator {
}

View File

@@ -0,0 +1,5 @@
package net.miarma.contaminus.common.entities;
public class COValue {
}

View File

@@ -0,0 +1,5 @@
package net.miarma.contaminus.common.entities;
public class Device {
}

View File

@@ -0,0 +1,5 @@
package net.miarma.contaminus.common.entities;
public class GpsValue {
}

View File

@@ -0,0 +1,5 @@
package net.miarma.contaminus.common.entities;
public class Group {
}

View File

@@ -0,0 +1,5 @@
package net.miarma.contaminus.common.entities;
public class Sensor {
}

View File

@@ -0,0 +1,5 @@
package net.miarma.contaminus.common.entities;
public class WeatherValue {
}

View File

@@ -25,7 +25,7 @@ public class DatabaseVerticle extends AbstractVerticle {
private EventBus eventBus;
private Gson gson = new GsonBuilder()
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer())
.create();;
.create();
@SuppressWarnings("unused")

View File

@@ -0,0 +1,139 @@
package net.miarma.contaminus.util;
import java.util.Map;
import com.google.gson.Gson;
import io.vertx.core.Promise;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.client.HttpRequest;
import io.vertx.ext.web.client.WebClient;
public class RestClientUtil {
public WebClient client;
private Gson gson;
public RestClientUtil(WebClient client) {
gson = new Gson();
this.client = client;
}
/**
* Get request utility
*
* @param <T> Type of result enveloped in JSON response
* @param port Port
* @param host Host address
* @param resource URI where resource is provided
* @param classType Type of result enveloped in JSON response
* @param promise Promise to be executed on call finish
*/
public <T> void getRequest(Integer port, String host, String resource, Class<T> classType, Promise<T> promise) {
client.getAbs(host + ":" + port + "/" + resource).send(elem -> {
if (elem.succeeded()) {
promise.complete(gson.fromJson(elem.result().bodyAsString(), classType));
} else {
promise.fail(elem.cause());
}
});
}
/**
* Get request utility
*
* @param <T> Type of result enveloped in JSON response
* @param port Port
* @param host Host address
* @param resource URI where resource is provided
* @param classType Type of result enveloped in JSON response
* @param promise Promise to be executed on call finish
* @param params Map with key-value entries for call parameters
*/
public <T> void getRequestWithParams(Integer port, String host, String resource, Class<T> classType,
Promise<T> promise, Map<String, String> params) {
HttpRequest<Buffer> httpRequest = client.getAbs(host + ":" + port + "/" + resource);
params.forEach((key, value) -> {
httpRequest.addQueryParam(key, value);
});
httpRequest.send(elem -> {
if (elem.succeeded()) {
promise.complete(gson.fromJson(elem.result().bodyAsString(), classType));
} else {
promise.fail(elem.cause());
}
});
}
/**
* Post request utility
*
* @param <B> Type of body enveloped in JSON request
* @param <T> Type of result enveloped in JSON response
* @param port Port
* @param host Host address
* @param resource URI where resource is provided
* @param classType Type of result enveloped in JSON response
* @param promise Promise to be executed on call finish
*/
public <B, T> void postRequest(Integer port, String host, String resource, Object body, Class<T> classType,
Promise<T> promise) {
JsonObject jsonBody = new JsonObject(gson.toJson(body));
client.postAbs(host + ":" + port + "/" + resource).sendJsonObject(jsonBody, elem -> {
if (elem.succeeded()) {
Gson gson = new Gson();
promise.complete(gson.fromJson(elem.result().bodyAsString(), classType));
} else {
promise.fail(elem.cause());
}
});
}
/**
* Put request utility
*
* @param <B> Type of body enveloped in JSON request
* @param <T> Type of result enveloped in JSON response
* @param port Port
* @param host Host address
* @param resource URI where resource is provided
* @param classType Type of result enveloped in JSON response
* @param promise Promise to be executed on call finish
*/
public <B, T> void putRequest(Integer port, String host, String resource, Object body, Class<T> classType,
Promise<T> promise) {
JsonObject jsonBody = new JsonObject(gson.toJson(body));
client.putAbs(host + ":" + port + "/" + resource).sendJsonObject(jsonBody, elem -> {
if (elem.succeeded()) {
Gson gson = new Gson();
promise.complete(gson.fromJson(elem.result().bodyAsString(), classType));
} else {
promise.fail(elem.cause());
}
});
}
/**
* Delete request utility
*
* @param port Port
* @param host Host address
* @param resource URI where resource is provided
* @param promise Promise to be executed on call finish
*/
public void deleteRequest(Integer port, String host, String resource, Promise<String> promise) {
client.deleteAbs(host + ":" + port + "/" + resource).send(elem -> {
if (elem.succeeded()) {
promise.complete(elem.result().bodyAsString());
} else {
promise.fail(elem.cause());
}
});
}
}

View File

@@ -15,7 +15,7 @@
<meta name="twitter:image" content="https://contaminus.miarma.net/logo.png" />
<link rel="shortcut icon" href="/images/favicon.ico" type="image/x-icon">
<title>ContaminUS</title>
<script type="module" crossorigin src="/assets/index-ByqS16T9.js"></script>
<script type="module" crossorigin src="/assets/index-75wHSipM.js"></script>
<link rel="modulepreload" crossorigin href="/assets/react-vendors-DbHEDQBy.js">
<link rel="modulepreload" crossorigin href="/assets/leaflet-DYDK0jU3.js">
<link rel="modulepreload" crossorigin href="/assets/chartjs-C6LAl0aW.js">