Search in sources :

Example 6 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbHttpClient method processException.

private TbMsg processException(TbContext ctx, TbMsg origMsg, Throwable e) {
    TbMsgMetaData metaData = origMsg.getMetaData();
    metaData.putValue(ERROR, e.getClass() + ": " + e.getMessage());
    if (e instanceof HttpClientErrorException) {
        HttpClientErrorException httpClientErrorException = (HttpClientErrorException) e;
        metaData.putValue(STATUS, httpClientErrorException.getStatusText());
        metaData.putValue(STATUS_CODE, httpClientErrorException.getRawStatusCode() + "");
        metaData.putValue(ERROR_BODY, httpClientErrorException.getResponseBodyAsString());
    }
    return ctx.transformMsg(origMsg, origMsg.getType(), origMsg.getOriginator(), metaData, origMsg.getData());
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData)

Example 7 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbHttpClient method processResponse.

private TbMsg processResponse(TbContext ctx, TbMsg origMsg, ResponseEntity<String> response) {
    TbMsgMetaData metaData = origMsg.getMetaData();
    metaData.putValue(STATUS, response.getStatusCode().name());
    metaData.putValue(STATUS_CODE, response.getStatusCode().value() + "");
    metaData.putValue(STATUS_REASON, response.getStatusCode().getReasonPhrase());
    response.getHeaders().toSingleValueMap().forEach(metaData::putValue);
    String body = response.getBody() == null ? "{}" : response.getBody();
    return ctx.transformMsg(origMsg, origMsg.getType(), origMsg.getOriginator(), metaData, body);
}
Also used : TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData)

Example 8 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbHttpClient method processFailureResponse.

private TbMsg processFailureResponse(TbContext ctx, TbMsg origMsg, ResponseEntity<String> response) {
    TbMsgMetaData metaData = origMsg.getMetaData();
    metaData.putValue(STATUS, response.getStatusCode().name());
    metaData.putValue(STATUS_CODE, response.getStatusCode().value() + "");
    metaData.putValue(STATUS_REASON, response.getStatusCode().getReasonPhrase());
    metaData.putValue(ERROR_BODY, response.getBody());
    return ctx.transformMsg(origMsg, origMsg.getType(), origMsg.getOriginator(), metaData, origMsg.getData());
}
Also used : TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData)

Example 9 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class AlarmState method pushMsg.

public void pushMsg(TbContext ctx, TbMsg msg, TbAlarmResult alarmResult, AlarmRuleState ruleState) {
    JsonNode jsonNodes = JacksonUtil.valueToTree(alarmResult.getAlarm());
    String data = jsonNodes.toString();
    TbMsgMetaData metaData = lastMsgMetaData != null ? lastMsgMetaData.copy() : new TbMsgMetaData();
    String relationType;
    if (alarmResult.isCreated()) {
        relationType = "Alarm Created";
        metaData.putValue(DataConstants.IS_NEW_ALARM, Boolean.TRUE.toString());
    } else if (alarmResult.isUpdated()) {
        relationType = "Alarm Updated";
        metaData.putValue(DataConstants.IS_EXISTING_ALARM, Boolean.TRUE.toString());
    } else if (alarmResult.isSeverityUpdated()) {
        relationType = "Alarm Severity Updated";
        metaData.putValue(DataConstants.IS_EXISTING_ALARM, Boolean.TRUE.toString());
        metaData.putValue(DataConstants.IS_SEVERITY_UPDATED_ALARM, Boolean.TRUE.toString());
    } else {
        relationType = "Alarm Cleared";
        metaData.putValue(DataConstants.IS_CLEARED_ALARM, Boolean.TRUE.toString());
    }
    setAlarmConditionMetadata(ruleState, metaData);
    TbMsg newMsg = ctx.newMsg(lastMsgQueueName != null ? lastMsgQueueName : ServiceQueue.MAIN, "ALARM", originator, msg != null ? msg.getCustomerId() : null, metaData, data);
    ctx.enqueueForTellNext(newMsg, relationType);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) TbMsg(org.thingsboard.server.common.msg.TbMsg)

Example 10 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class DeviceProvisionServiceImpl method createTbMsgMetaData.

private TbMsgMetaData createTbMsgMetaData(Device device) {
    TbMsgMetaData metaData = new TbMsgMetaData();
    metaData.putValue("tenantId", device.getTenantId().toString());
    return metaData;
}
Also used : TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData)

Aggregations

TbMsgMetaData (org.thingsboard.server.common.msg.TbMsgMetaData)89 TbMsg (org.thingsboard.server.common.msg.TbMsg)56 Test (org.junit.Test)49 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)26 Device (org.thingsboard.server.common.data.Device)17 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)17 List (java.util.List)16 DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)16 DeviceId (org.thingsboard.server.common.data.id.DeviceId)15 EntityId (org.thingsboard.server.common.data.id.EntityId)15 AlarmCondition (org.thingsboard.server.common.data.device.profile.AlarmCondition)14 AlarmConditionFilter (org.thingsboard.server.common.data.device.profile.AlarmConditionFilter)14 AlarmConditionFilterKey (org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)14 AlarmRule (org.thingsboard.server.common.data.device.profile.AlarmRule)14 DeviceProfileAlarm (org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm)14 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)14 NumericFilterPredicate (org.thingsboard.server.common.data.query.NumericFilterPredicate)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)13 DynamicValue (org.thingsboard.server.common.data.query.DynamicValue)13 AttributeKvCompositeKey (org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey)13