Search in sources :

Example 1 with AttributesKVMsg

use of org.thingsboard.server.common.msg.kv.AttributesKVMsg in project thingsboard by thingsboard.

the class JsonCoapAdaptor method convertGetAttributesResponse.

private Response convertGetAttributesResponse(GetAttributesResponse msg) {
    if (msg.isSuccess()) {
        Optional<AttributesKVMsg> payload = msg.getData();
        if (!payload.isPresent() || (payload.get().getClientAttributes().isEmpty() && payload.get().getSharedAttributes().isEmpty())) {
            return new Response(ResponseCode.NOT_FOUND);
        } else {
            Response response = new Response(ResponseCode.CONTENT);
            JsonObject result = JsonConverter.toJson(payload.get(), false);
            response.setPayload(result.toString());
            return response;
        }
    } else {
        return convertError(msg.getError());
    }
}
Also used : Response(org.eclipse.californium.core.coap.Response) JsonObject(com.google.gson.JsonObject) AttributesKVMsg(org.thingsboard.server.common.msg.kv.AttributesKVMsg)

Example 2 with AttributesKVMsg

use of org.thingsboard.server.common.msg.kv.AttributesKVMsg in project thingsboard by thingsboard.

the class GatewayDeviceSessionCtx method createMqttPublishMsg.

private MqttMessage createMqttPublishMsg(String topic, GetAttributesResponse response) {
    JsonObject result = new JsonObject();
    result.addProperty("id", response.getRequestId());
    result.addProperty(DEVICE_PROPERTY, device.getName());
    Optional<AttributesKVMsg> responseData = response.getData();
    if (responseData.isPresent()) {
        AttributesKVMsg msg = responseData.get();
        if (msg.getClientAttributes() != null) {
            addValues(result, msg.getClientAttributes());
        }
        if (msg.getSharedAttributes() != null) {
            addValues(result, msg.getSharedAttributes());
        }
    }
    return createMqttPublishMsg(topic, result);
}
Also used : JsonObject(com.google.gson.JsonObject) AttributesKVMsg(org.thingsboard.server.common.msg.kv.AttributesKVMsg)

Aggregations

JsonObject (com.google.gson.JsonObject)2 AttributesKVMsg (org.thingsboard.server.common.msg.kv.AttributesKVMsg)2 Response (org.eclipse.californium.core.coap.Response)1