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