Search in sources :

Example 6 with TbNodeException

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);
    }
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) TbNodeException(org.thingsboard.rule.engine.api.TbNodeException) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) ExecutionException(java.util.concurrent.ExecutionException) TbNodeException(org.thingsboard.rule.engine.api.TbNodeException)

Example 7 with TbNodeException

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);
    }
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) TbNodeException(org.thingsboard.rule.engine.api.TbNodeException) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) TbNodeException(org.thingsboard.rule.engine.api.TbNodeException)

Example 8 with TbNodeException

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);
    }
}
Also used : TbNodeException(org.thingsboard.rule.engine.api.TbNodeException) IOException(java.io.IOException) TbNodeException(org.thingsboard.rule.engine.api.TbNodeException)

Example 9 with TbNodeException

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;
}
Also used : TbNodeException(org.thingsboard.rule.engine.api.TbNodeException) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) JsonParser(com.google.gson.JsonParser)

Example 10 with TbNodeException

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);
    }
}
Also used : TbNodeException(org.thingsboard.rule.engine.api.TbNodeException) TbNodeConfiguration(org.thingsboard.rule.engine.api.TbNodeConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

TbNodeException (org.thingsboard.rule.engine.api.TbNodeException)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 TbNodeConfiguration (org.thingsboard.rule.engine.api.TbNodeConfiguration)4 AWSCredentials (com.amazonaws.auth.AWSCredentials)2 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)2 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)2 IOException (java.io.IOException)2 SSLException (javax.net.ssl.SSLException)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)1 Properties (java.util.Properties)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 TimeoutException (org.apache.kafka.common.errors.TimeoutException)1 CertPemCredentials (org.thingsboard.rule.engine.credentials.CertPemCredentials)1 ClientCredentials (org.thingsboard.rule.engine.credentials.ClientCredentials)1 TbMqttNodeConfiguration (org.thingsboard.rule.engine.mqtt.TbMqttNodeConfiguration)1 EntityType (org.thingsboard.server.common.data.EntityType)1