Search in sources :

Example 1 with UncheckedApiException

use of org.thingsboard.server.extensions.api.exception.UncheckedApiException in project thingsboard by thingsboard.

the class TelemetryRestMsgHandler method extractRequestAttributes.

private List<AttributeKvEntry> extractRequestAttributes(JsonNode jsonNode) {
    long ts = System.currentTimeMillis();
    List<AttributeKvEntry> attributes = new ArrayList<>();
    jsonNode.fields().forEachRemaining(entry -> {
        String key = entry.getKey();
        JsonNode value = entry.getValue();
        if (entry.getValue().isTextual()) {
            attributes.add(new BaseAttributeKvEntry(new StringDataEntry(key, value.textValue()), ts));
        } else if (entry.getValue().isBoolean()) {
            attributes.add(new BaseAttributeKvEntry(new BooleanDataEntry(key, value.booleanValue()), ts));
        } else if (entry.getValue().isDouble()) {
            attributes.add(new BaseAttributeKvEntry(new DoubleDataEntry(key, value.doubleValue()), ts));
        } else if (entry.getValue().isNumber()) {
            if (entry.getValue().isBigInteger()) {
                throw new UncheckedApiException(new InvalidParametersException("Big integer values are not supported!"));
            } else {
                attributes.add(new BaseAttributeKvEntry(new LongDataEntry(key, value.longValue()), ts));
            }
        }
    });
    return attributes;
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) InvalidParametersException(org.thingsboard.server.extensions.api.exception.InvalidParametersException) UncheckedApiException(org.thingsboard.server.extensions.api.exception.UncheckedApiException)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 InvalidParametersException (org.thingsboard.server.extensions.api.exception.InvalidParametersException)1 UncheckedApiException (org.thingsboard.server.extensions.api.exception.UncheckedApiException)1