use of org.thingsboard.rule.engine.api.TbNodeException in project thingsboard by thingsboard.
the class TbSnsNode method init.
@Override
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
this.config = TbNodeUtils.convert(configuration, TbSnsNodeConfiguration.class);
AWSCredentials awsCredentials = new BasicAWSCredentials(this.config.getAccessKeyId(), this.config.getSecretAccessKey());
AWSStaticCredentialsProvider credProvider = new AWSStaticCredentialsProvider(awsCredentials);
try {
this.snsClient = AmazonSNSClient.builder().withCredentials(credProvider).withRegion(this.config.getRegion()).build();
} catch (Exception e) {
throw new TbNodeException(e);
}
}
use of org.thingsboard.rule.engine.api.TbNodeException in project thingsboard by thingsboard.
the class TbSqsNode method init.
@Override
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
this.config = TbNodeUtils.convert(configuration, TbSqsNodeConfiguration.class);
AWSCredentials awsCredentials = new BasicAWSCredentials(this.config.getAccessKeyId(), this.config.getSecretAccessKey());
AWSStaticCredentialsProvider credProvider = new AWSStaticCredentialsProvider(awsCredentials);
try {
this.sqsClient = AmazonSQSClientBuilder.standard().withCredentials(credProvider).withRegion(this.config.getRegion()).build();
} catch (Exception e) {
throw new TbNodeException(e);
}
}
use of org.thingsboard.rule.engine.api.TbNodeException in project thingsboard by thingsboard.
the class TbPubSubNode method init.
@Override
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
try {
this.config = TbNodeUtils.convert(configuration, TbPubSubNodeConfiguration.class);
this.pubSubClient = initPubSubClient();
} catch (Exception e) {
throw new TbNodeException(e);
}
}
use of org.thingsboard.rule.engine.api.TbNodeException in project thingsboard by thingsboard.
the class AbstractGeofencingNode method checkMatches.
protected boolean checkMatches(TbMsg msg) throws TbNodeException {
JsonElement msgDataElement = new JsonParser().parse(msg.getData());
if (!msgDataElement.isJsonObject()) {
throw new TbNodeException("Incoming Message is not a valid JSON object");
}
JsonObject msgDataObj = msgDataElement.getAsJsonObject();
double latitude = getValueFromMessageByName(msg, msgDataObj, config.getLatitudeKeyName());
double longitude = getValueFromMessageByName(msg, msgDataObj, config.getLongitudeKeyName());
List<Perimeter> perimeters = getPerimeters(msg, msgDataObj);
boolean matches = false;
for (Perimeter perimeter : perimeters) {
if (checkMatches(perimeter, latitude, longitude)) {
matches = true;
break;
}
}
return matches;
}
use of org.thingsboard.rule.engine.api.TbNodeException in project thingsboard by thingsboard.
the class TbMsgToEmailNodeTest method initWithScript.
private void initWithScript() {
try {
TbMsgToEmailNodeConfiguration config = new TbMsgToEmailNodeConfiguration();
config.setFromTemplate("test@mail.org");
config.setToTemplate("${userEmail}");
config.setSubjectTemplate("Hi ${username} there");
config.setBodyTemplate("${name} is to high. Current ${passed} and ${count}");
config.setMailBodyType("false");
ObjectMapper mapper = new ObjectMapper();
TbNodeConfiguration nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(config));
emailNode = new TbMsgToEmailNode();
emailNode.init(ctx, nodeConfiguration);
} catch (TbNodeException ex) {
throw new IllegalStateException(ex);
}
}
Aggregations