first-fix
This commit is contained in:
1 parent
6d87c1edc8
commit
565d9d673a
6284 files changed
+820267
-76
No files matched your search
@@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
Copyright © 2016-2023 The Thingsboard Authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.thingsboard</groupId>
|
||||
<version>0.6.2-SNAPSHOT</version>
|
||||
<artifactId>rule-engine</artifactId>
|
||||
</parent>
|
||||
<groupId>org.thingsboard.rule-engine</groupId>
|
||||
<artifactId>rule-engine-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Thingsboard Rule Engine API</name>
|
||||
<url>https://thingsboard.io</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<main.dir>${basedir}/../..</main.dir>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.thingsboard.common</groupId>
|
||||
<artifactId>message</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.thingsboard.common</groupId>
|
||||
<artifactId>dao-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.thingsboard.common</groupId>
|
||||
<artifactId>cluster-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.thingsboard.common</groupId>
|
||||
<artifactId>util</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-tcnative-boringssl-static</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.datastax.oss</groupId>
|
||||
<artifactId>java-driver-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>javax.mail</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.awaitility</groupId>
|
||||
<artifactId>awaitility</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<configuration>
|
||||
<skip>false</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class EmptyNodeConfiguration implements NodeConfiguration<EmptyNodeConfiguration> {
|
||||
|
||||
private int version;
|
||||
|
||||
@Override
|
||||
public EmptyNodeConfiguration defaultConfiguration() {
|
||||
EmptyNodeConfiguration configuration = new EmptyNodeConfiguration();
|
||||
return configuration;
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.thingsboard.server.common.data.ApiFeature;
|
||||
import org.thingsboard.server.common.data.ApiUsageRecordState;
|
||||
import org.thingsboard.server.common.data.ApiUsageStateValue;
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
|
||||
public interface MailService {
|
||||
|
||||
void updateMailConfiguration();
|
||||
|
||||
void sendEmail(TenantId tenantId, String email, String subject, String message) throws ThingsboardException;
|
||||
|
||||
void sendTestMail(JsonNode config, String email) throws ThingsboardException;
|
||||
|
||||
void sendActivationEmail(String activationLink, String email) throws ThingsboardException;
|
||||
void sendActivationEmail(TenantId tenantId, String activationLink, String email) throws ThingsboardException;
|
||||
void sendAccountActivatedEmail(String loginLink, String email) throws ThingsboardException;
|
||||
|
||||
void sendResetPasswordEmail(String passwordResetLink, String email) throws ThingsboardException;
|
||||
|
||||
void sendResetPasswordEmailAsync(String passwordResetLink, String email);
|
||||
|
||||
void sendPasswordWasResetEmail(String loginLink, String email) throws ThingsboardException;
|
||||
|
||||
void sendAccountLockoutEmail(String lockoutEmail, String email, Integer maxFailedLoginAttempts) throws ThingsboardException;
|
||||
|
||||
void sendTwoFaVerificationEmail(String email, String verificationCode, int expirationTimeSeconds) throws ThingsboardException;
|
||||
|
||||
void send(TenantId tenantId, CustomerId customerId, TbEmail tbEmail) throws ThingsboardException;
|
||||
|
||||
void send(TenantId tenantId, CustomerId customerId, TbEmail tbEmail, JavaMailSender javaMailSender, long timeout) throws ThingsboardException;
|
||||
|
||||
void sendApiFeatureStateEmail(ApiFeature apiFeature, ApiUsageStateValue stateValue, String email, ApiUsageRecordState recordState) throws ThingsboardException;
|
||||
|
||||
void testConnection(TenantId tenantId) throws Exception;
|
||||
|
||||
boolean isConfigured(TenantId tenantId);
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
public interface NodeConfiguration<T extends NodeConfiguration> {
|
||||
|
||||
T defaultConfiguration();
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class NodeDefinition {
|
||||
|
||||
private String details;
|
||||
private String description;
|
||||
private boolean inEnabled;
|
||||
private boolean outEnabled;
|
||||
String[] relationTypes;
|
||||
boolean customRelations;
|
||||
boolean ruleChainNode;
|
||||
JsonNode defaultConfiguration;
|
||||
String[] uiResources;
|
||||
String configDirective;
|
||||
String icon;
|
||||
String iconUrl;
|
||||
String docUrl;
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import org.thingsboard.server.common.data.id.NotificationId;
|
||||
import org.thingsboard.server.common.data.id.NotificationRequestId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.id.UserId;
|
||||
import org.thingsboard.server.common.data.notification.NotificationDeliveryMethod;
|
||||
import org.thingsboard.server.common.data.notification.NotificationRequest;
|
||||
import org.thingsboard.server.common.data.notification.NotificationRequestStats;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface NotificationCenter {
|
||||
|
||||
NotificationRequest processNotificationRequest(TenantId tenantId, NotificationRequest notificationRequest, Consumer<NotificationRequestStats> callback);
|
||||
|
||||
void deleteNotificationRequest(TenantId tenantId, NotificationRequestId notificationRequestId);
|
||||
|
||||
void markNotificationAsRead(TenantId tenantId, UserId recipientId, NotificationId notificationId);
|
||||
|
||||
void markAllNotificationsAsRead(TenantId tenantId, UserId recipientId);
|
||||
|
||||
void deleteNotification(TenantId tenantId, UserId recipientId, NotificationId notificationId);
|
||||
|
||||
Set<NotificationDeliveryMethod> getAvailableDeliveryMethods(TenantId tenantId);
|
||||
|
||||
}
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.thingsboard.server.common.data.alarm.Alarm;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmApiCallResult;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmCreateOrUpdateActiveRequest;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmInfo;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmQuery;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmQueryV2;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmSearchStatus;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmSeverity;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmStatus;
|
||||
import org.thingsboard.server.common.data.alarm.AlarmUpdateRequest;
|
||||
import org.thingsboard.server.common.data.id.AlarmId;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.id.UserId;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.permission.MergedUserPermissions;
|
||||
import org.thingsboard.server.common.data.query.AlarmData;
|
||||
import org.thingsboard.server.common.data.query.AlarmDataQuery;
|
||||
import org.thingsboard.server.dao.alarm.AlarmOperationResult;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 02.04.18.
|
||||
*/
|
||||
public interface RuleEngineAlarmService {
|
||||
|
||||
/*
|
||||
* New API, since 3.5.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Designed for atomic operations over active alarms.
|
||||
* Only one active alarm may exist for the pair {originatorId, alarmType}
|
||||
*/
|
||||
AlarmApiCallResult createAlarm(AlarmCreateOrUpdateActiveRequest request);
|
||||
/**
|
||||
* Designed to update existing alarm. Accepts only part of the alarm fields.
|
||||
*/
|
||||
AlarmApiCallResult updateAlarm(AlarmUpdateRequest request);
|
||||
|
||||
AlarmApiCallResult acknowledgeAlarm(TenantId tenantId, AlarmId alarmId, long ackTs);
|
||||
|
||||
AlarmApiCallResult clearAlarm(TenantId tenantId, AlarmId alarmId, long clearTs, JsonNode details);
|
||||
|
||||
AlarmApiCallResult assignAlarm(TenantId tenantId, AlarmId alarmId, UserId assigneeId, long assignTs);
|
||||
|
||||
AlarmApiCallResult unassignAlarm(TenantId tenantId, AlarmId alarmId, long assignTs);
|
||||
|
||||
/*
|
||||
* Legacy API, before 3.5.
|
||||
*/
|
||||
@Deprecated(since = "3.5", forRemoval = true)
|
||||
Alarm createOrUpdateAlarm(Alarm alarm);
|
||||
|
||||
@Deprecated(since = "3.5", forRemoval = true)
|
||||
ListenableFuture<Boolean> ackAlarm(TenantId tenantId, AlarmId alarmId, long ackTs);
|
||||
|
||||
@Deprecated(since = "3.5", forRemoval = true)
|
||||
ListenableFuture<Boolean> clearAlarm(TenantId tenantId, AlarmId alarmId, JsonNode details, long clearTs);
|
||||
|
||||
@Deprecated(since = "3.5", forRemoval = true)
|
||||
ListenableFuture<AlarmOperationResult> clearAlarmForResult(TenantId tenantId, AlarmId alarmId, JsonNode details, long clearTs);
|
||||
|
||||
// Other API
|
||||
Boolean deleteAlarm(TenantId tenantId, AlarmId alarmId);
|
||||
|
||||
ListenableFuture<Alarm> findAlarmByIdAsync(TenantId tenantId, AlarmId alarmId);
|
||||
|
||||
Alarm findAlarmById(TenantId tenantId, AlarmId alarmId);
|
||||
|
||||
Alarm findLatestActiveByOriginatorAndType(TenantId tenantId, EntityId originator, String type);
|
||||
|
||||
ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type);
|
||||
|
||||
AlarmInfo findAlarmInfoById(TenantId tenantId, AlarmId alarmId);
|
||||
|
||||
default ListenableFuture<AlarmInfo> findAlarmInfoByIdAsync(TenantId tenantId, AlarmId alarmId) {
|
||||
return Futures.immediateFuture(findAlarmInfoById(tenantId, alarmId));
|
||||
}
|
||||
|
||||
ListenableFuture<PageData<AlarmInfo>> findAlarms(TenantId tenantId, AlarmQuery query);
|
||||
|
||||
ListenableFuture<PageData<AlarmInfo>> findCustomerAlarms(TenantId tenantId, CustomerId customerId, AlarmQuery query);
|
||||
|
||||
ListenableFuture<PageData<AlarmInfo>> findAlarmsV2(TenantId tenantId, AlarmQueryV2 query);
|
||||
|
||||
ListenableFuture<PageData<AlarmInfo>> findCustomerAlarmsV2(TenantId tenantId, CustomerId customerId, AlarmQueryV2 query);
|
||||
|
||||
AlarmSeverity findHighestAlarmSeverity(TenantId tenantId, EntityId entityId, AlarmSearchStatus alarmSearchStatus, AlarmStatus alarmStatus, String assigneeId);
|
||||
|
||||
PageData<AlarmData> findAlarmDataByQueryForEntities(TenantId tenantId, MergedUserPermissions mergedUserPermissions, AlarmDataQuery query, Collection<EntityId> orderedEntityIds);
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import org.thingsboard.server.common.data.ApiUsageState;
|
||||
import org.thingsboard.server.common.data.id.ApiUsageStateId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
|
||||
public interface RuleEngineApiUsageStateService {
|
||||
|
||||
ApiUsageState findApiUsageStateById(TenantId tenantId, ApiUsageStateId id);
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import org.thingsboard.server.common.data.asset.AssetProfile;
|
||||
import org.thingsboard.server.common.data.id.AssetId;
|
||||
import org.thingsboard.server.common.data.id.AssetProfileId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 02.04.18.
|
||||
*/
|
||||
public interface RuleEngineAssetProfileCache {
|
||||
|
||||
AssetProfile get(TenantId tenantId, AssetProfileId assetProfileId);
|
||||
|
||||
AssetProfile get(TenantId tenantId, AssetId assetId);
|
||||
|
||||
void addListener(TenantId tenantId, EntityId listenerId, Consumer<AssetProfile> profileListener, BiConsumer<AssetId, AssetProfile> assetlistener);
|
||||
|
||||
void removeListener(TenantId tenantId, EntityId listenerId);
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 02.04.18.
|
||||
*/
|
||||
public interface RuleEngineDeviceProfileCache {
|
||||
|
||||
DeviceProfile get(TenantId tenantId, DeviceProfileId deviceProfileId);
|
||||
|
||||
DeviceProfile get(TenantId tenantId, DeviceId deviceId);
|
||||
|
||||
void addListener(TenantId tenantId, EntityId listenerId, Consumer<DeviceProfile> profileListener, BiConsumer<DeviceId, DeviceProfile> devicelistener);
|
||||
|
||||
void removeListener(TenantId tenantId, EntityId listenerId);
|
||||
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 02.04.18.
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public final class RuleEngineDeviceRpcRequest {
|
||||
|
||||
private final TenantId tenantId;
|
||||
private final DeviceId deviceId;
|
||||
private final int requestId;
|
||||
private final UUID requestUUID;
|
||||
private final String originServiceId;
|
||||
private final boolean oneway;
|
||||
private final boolean persisted;
|
||||
private final String method;
|
||||
private final String body;
|
||||
private final long expirationTime;
|
||||
private final boolean restApiCall;
|
||||
private final String additionalInfo;
|
||||
private final Integer retries;
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.rpc.RpcError;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 02.04.18.
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public final class RuleEngineDeviceRpcResponse {
|
||||
|
||||
private final DeviceId deviceId;
|
||||
private final int requestId;
|
||||
private final Optional<String> response;
|
||||
private final Optional<RpcError> error;
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import org.thingsboard.server.common.data.id.RpcId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.rpc.Rpc;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 02.04.18.
|
||||
*/
|
||||
public interface RuleEngineRpcService {
|
||||
|
||||
void sendRpcReplyToDevice(String serviceId, UUID sessionId, int requestId, String body);
|
||||
|
||||
void sendRpcRequestToDevice(RuleEngineDeviceRpcRequest request, Consumer<RuleEngineDeviceRpcResponse> consumer);
|
||||
|
||||
Rpc findRpcById(TenantId tenantId, RpcId id);
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
|
||||
import org.thingsboard.server.common.data.kv.DeleteTsKvQuery;
|
||||
import org.thingsboard.server.common.data.kv.TsKvEntry;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 02.04.18.
|
||||
*/
|
||||
public interface RuleEngineTelemetryService {
|
||||
|
||||
ListenableFuture<Void> saveAndNotify(TenantId tenantId, EntityId entityId, TsKvEntry ts);
|
||||
|
||||
void saveAndNotify(TenantId tenantId, EntityId entityId, List<TsKvEntry> ts, FutureCallback<Void> callback);
|
||||
|
||||
void saveAndNotify(TenantId tenantId, CustomerId id, EntityId entityId, List<TsKvEntry> ts, long ttl, FutureCallback<Void> callback);
|
||||
|
||||
void saveWithoutLatestAndNotify(TenantId tenantId, CustomerId id, EntityId entityId, List<TsKvEntry> ts, long ttl, FutureCallback<Void> callback);
|
||||
|
||||
void saveAndNotify(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes, FutureCallback<Void> callback);
|
||||
|
||||
void saveAndNotify(TenantId tenantId, EntityId entityId, String scope, List<AttributeKvEntry> attributes, boolean notifyDevice, FutureCallback<Void> callback);
|
||||
|
||||
void saveLatestAndNotify(TenantId tenantId, EntityId entityId, List<TsKvEntry> ts, FutureCallback<Void> callback);
|
||||
|
||||
ListenableFuture<Void> saveAttrAndNotify(TenantId tenantId, EntityId entityId, String scope, String key, long value);
|
||||
|
||||
ListenableFuture<Void> saveAttrAndNotify(TenantId tenantId, EntityId entityId, String scope, String key, String value);
|
||||
|
||||
ListenableFuture<Void> saveAttrAndNotify(TenantId tenantId, EntityId entityId, String scope, String key, double value);
|
||||
|
||||
ListenableFuture<Void> saveAttrAndNotify(TenantId tenantId, EntityId entityId, String scope, String key, boolean value);
|
||||
|
||||
void saveAttrAndNotify(TenantId tenantId, EntityId entityId, String scope, String key, long value, FutureCallback<Void> callback);
|
||||
|
||||
void saveAttrAndNotify(TenantId tenantId, EntityId entityId, String scope, String key, String value, FutureCallback<Void> callback);
|
||||
|
||||
void saveAttrAndNotify(TenantId tenantId, EntityId entityId, String scope, String key, double value, FutureCallback<Void> callback);
|
||||
|
||||
void saveAttrAndNotify(TenantId tenantId, EntityId entityId, String scope, String key, boolean value, FutureCallback<Void> callback);
|
||||
|
||||
void deleteAndNotify(TenantId tenantId, EntityId entityId, String scope, List<String> keys, FutureCallback<Void> callback);
|
||||
|
||||
void deleteAndNotify(TenantId tenantId, EntityId entityId, String scope, List<String> keys, boolean notifyDevice, FutureCallback<Void> callback);
|
||||
|
||||
void deleteLatest(TenantId tenantId, EntityId entityId, List<String> keys, FutureCallback<Void> callback);
|
||||
|
||||
void deleteAllLatest(TenantId tenantId, EntityId entityId, FutureCallback<Collection<String>> callback);
|
||||
|
||||
void deleteTimeseriesAndNotify(TenantId tenantId, EntityId entityId, List<String> keys, List<DeleteTsKvQuery> deleteTsKvQueries, FutureCallback<Void> callback);
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import org.thingsboard.server.common.data.plugin.ComponentClusteringMode;
|
||||
import org.thingsboard.server.common.data.plugin.ComponentScope;
|
||||
import org.thingsboard.server.common.data.plugin.ComponentType;
|
||||
import org.thingsboard.server.common.data.rule.RuleChainType;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface RuleNode {
|
||||
|
||||
ComponentType type();
|
||||
|
||||
String name();
|
||||
|
||||
String nodeDescription();
|
||||
|
||||
String nodeDetails();
|
||||
|
||||
Class<? extends NodeConfiguration> configClazz();
|
||||
|
||||
ComponentClusteringMode clusteringMode() default ComponentClusteringMode.ENABLED;
|
||||
|
||||
boolean inEnabled() default true;
|
||||
|
||||
boolean outEnabled() default true;
|
||||
|
||||
ComponentScope scope() default ComponentScope.TENANT;
|
||||
|
||||
String[] relationTypes() default {"Success", "Failure"};
|
||||
|
||||
String[] uiResources() default {};
|
||||
|
||||
String configDirective() default "";
|
||||
|
||||
String icon() default "";
|
||||
|
||||
String iconUrl() default "";
|
||||
|
||||
String docUrl() default "";
|
||||
|
||||
boolean customRelations() default false;
|
||||
|
||||
boolean ruleChainNode() default false;
|
||||
|
||||
RuleChainType[] ruleChainTypes() default {RuleChainType.CORE, RuleChainType.EDGE};
|
||||
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import org.thingsboard.server.common.msg.TbMsg;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ScriptEngine {
|
||||
|
||||
ListenableFuture<List<TbMsg>> executeUpdateAsync(TbMsg msg);
|
||||
|
||||
ListenableFuture<TbMsg> executeGenerateAsync(TbMsg prevMsg);
|
||||
|
||||
ListenableFuture<Boolean> executeFilterAsync(TbMsg msg);
|
||||
|
||||
ListenableFuture<Set<String>> executeSwitchAsync(TbMsg msg);
|
||||
|
||||
ListenableFuture<JsonNode> executeJsonAsync(TbMsg msg);
|
||||
|
||||
ListenableFuture<String> executeToStringAsync(TbMsg msg);
|
||||
|
||||
void destroy();
|
||||
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.sms.config.TestSmsRequest;
|
||||
|
||||
public interface SmsService {
|
||||
|
||||
void updateSmsConfiguration();
|
||||
|
||||
void sendSms(TenantId tenantId, CustomerId customerId, String[] numbersTo, String message) throws ThingsboardException;;
|
||||
|
||||
void sendTestSms(TestSmsRequest testSmsRequest) throws ThingsboardException;
|
||||
|
||||
boolean isConfigured(TenantId tenantId);
|
||||
|
||||
}
|
||||
+366
@@ -0,0 +1,366 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import org.thingsboard.common.util.ListeningExecutor;
|
||||
import org.thingsboard.rule.engine.api.slack.SlackService;
|
||||
import org.thingsboard.rule.engine.api.sms.SmsSenderFactory;
|
||||
import org.thingsboard.server.cluster.TbClusterService;
|
||||
import org.thingsboard.server.common.data.Customer;
|
||||
import org.thingsboard.server.common.data.Device;
|
||||
import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.TenantProfile;
|
||||
import org.thingsboard.server.common.data.alarm.Alarm;
|
||||
import org.thingsboard.server.common.data.asset.Asset;
|
||||
import org.thingsboard.server.common.data.asset.AssetProfile;
|
||||
import org.thingsboard.server.common.data.id.AssetId;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.EdgeId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||
import org.thingsboard.server.common.data.id.RuleNodeId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
|
||||
import org.thingsboard.server.common.data.page.PageData;
|
||||
import org.thingsboard.server.common.data.page.PageLink;
|
||||
import org.thingsboard.server.common.data.rule.RuleNode;
|
||||
import org.thingsboard.server.common.data.rule.RuleNodeState;
|
||||
import org.thingsboard.server.common.data.script.ScriptLanguage;
|
||||
import org.thingsboard.server.common.msg.TbMsg;
|
||||
import org.thingsboard.server.common.msg.TbMsgMetaData;
|
||||
import org.thingsboard.server.dao.alarm.AlarmCommentService;
|
||||
import org.thingsboard.server.dao.asset.AssetProfileService;
|
||||
import org.thingsboard.server.dao.asset.AssetService;
|
||||
import org.thingsboard.server.dao.attributes.AttributesService;
|
||||
import org.thingsboard.server.dao.cassandra.CassandraCluster;
|
||||
import org.thingsboard.server.dao.customer.CustomerService;
|
||||
import org.thingsboard.server.dao.dashboard.DashboardService;
|
||||
import org.thingsboard.server.dao.device.DeviceCredentialsService;
|
||||
import org.thingsboard.server.dao.device.DeviceProfileService;
|
||||
import org.thingsboard.server.dao.device.DeviceService;
|
||||
import org.thingsboard.server.dao.edge.EdgeEventService;
|
||||
import org.thingsboard.server.dao.edge.EdgeService;
|
||||
import org.thingsboard.server.dao.entityview.EntityViewService;
|
||||
import org.thingsboard.server.dao.group.EntityGroupService;
|
||||
import org.thingsboard.server.dao.nosql.CassandraStatementTask;
|
||||
import org.thingsboard.server.dao.nosql.TbResultSetFuture;
|
||||
import org.thingsboard.server.dao.notification.NotificationRequestService;
|
||||
import org.thingsboard.server.dao.notification.NotificationRuleService;
|
||||
import org.thingsboard.server.dao.notification.NotificationTargetService;
|
||||
import org.thingsboard.server.dao.notification.NotificationTemplateService;
|
||||
import org.thingsboard.server.dao.ota.OtaPackageService;
|
||||
import org.thingsboard.server.dao.queue.QueueService;
|
||||
import org.thingsboard.server.dao.relation.RelationService;
|
||||
import org.thingsboard.server.dao.resource.ResourceService;
|
||||
import org.thingsboard.server.dao.rule.RuleChainService;
|
||||
import org.thingsboard.server.dao.scheduler.SchedulerEventService;
|
||||
import org.thingsboard.server.dao.tenant.TenantService;
|
||||
import org.thingsboard.server.dao.timeseries.TimeseriesService;
|
||||
import org.thingsboard.server.dao.user.UserService;
|
||||
import org.thingsboard.server.dao.widget.WidgetTypeService;
|
||||
import org.thingsboard.server.dao.widget.WidgetsBundleService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 13.01.18.
|
||||
*/
|
||||
public interface TbContext {
|
||||
|
||||
/*
|
||||
*
|
||||
* METHODS TO CONTROL THE MESSAGE FLOW
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Indicates that message was successfully processed by the rule node.
|
||||
* Sends message to all Rule Nodes in the Rule Chain
|
||||
* that are connected to the current Rule Node using "Success" relationType.
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
void tellSuccess(TbMsg msg);
|
||||
|
||||
/**
|
||||
* Sends message to all Rule Nodes in the Rule Chain
|
||||
* that are connected to the current Rule Node using specified relationType.
|
||||
*
|
||||
* @param msg
|
||||
* @param relationType
|
||||
*/
|
||||
void tellNext(TbMsg msg, String relationType);
|
||||
|
||||
/**
|
||||
* Sends message to all Rule Nodes in the Rule Chain
|
||||
* that are connected to the current Rule Node using one of specified relationTypes.
|
||||
*
|
||||
* @param msg
|
||||
* @param relationTypes
|
||||
*/
|
||||
void tellNext(TbMsg msg, Set<String> relationTypes);
|
||||
|
||||
/**
|
||||
* Sends message to the current Rule Node with specified delay in milliseconds.
|
||||
* Note: this message is not queued and may be lost in case of a server restart.
|
||||
*
|
||||
* @param msg
|
||||
*/
|
||||
void tellSelf(TbMsg msg, long delayMs);
|
||||
|
||||
/**
|
||||
* Notifies Rule Engine about failure to process current message.
|
||||
*
|
||||
* @param msg - message
|
||||
* @param th - exception
|
||||
*/
|
||||
void tellFailure(TbMsg msg, Throwable th);
|
||||
|
||||
/**
|
||||
* Puts new message to queue for processing by the Root Rule Chain
|
||||
*
|
||||
* @param msg - message
|
||||
*/
|
||||
void enqueue(TbMsg msg, Runnable onSuccess, Consumer<Throwable> onFailure);
|
||||
|
||||
/**
|
||||
* Sends message to the nested rule chain.
|
||||
* Fails processing of the message if the nested rule chain is not found.
|
||||
*
|
||||
* @param msg - the message
|
||||
* @param ruleChainId - the id of a nested rule chain
|
||||
*/
|
||||
void input(TbMsg msg, RuleChainId ruleChainId);
|
||||
|
||||
/**
|
||||
* Sends message to the caller rule chain.
|
||||
* Acknowledge the message if no caller rule chain is present in processing stack
|
||||
*
|
||||
* @param msg - the message
|
||||
* @param relationType - the relation type that will be used to route messages in the caller rule chain
|
||||
*/
|
||||
void output(TbMsg msg, String relationType);
|
||||
|
||||
/**
|
||||
* Puts new message to custom queue for processing
|
||||
*
|
||||
* @param msg - message
|
||||
*/
|
||||
void enqueue(TbMsg msg, String queueName, Runnable onSuccess, Consumer<Throwable> onFailure);
|
||||
|
||||
void enqueueForTellFailure(TbMsg msg, String failureMessage);
|
||||
|
||||
void enqueueForTellFailure(TbMsg tbMsg, Throwable t);
|
||||
|
||||
void enqueueForTellNext(TbMsg msg, String relationType);
|
||||
|
||||
void enqueueForTellNext(TbMsg msg, Set<String> relationTypes);
|
||||
|
||||
void enqueueForTellNext(TbMsg msg, String relationType, Runnable onSuccess, Consumer<Throwable> onFailure);
|
||||
|
||||
void enqueueForTellNext(TbMsg msg, Set<String> relationTypes, Runnable onSuccess, Consumer<Throwable> onFailure);
|
||||
|
||||
void enqueueForTellNext(TbMsg msg, String queueName, String relationType, Runnable onSuccess, Consumer<Throwable> onFailure);
|
||||
|
||||
void enqueueForTellNext(TbMsg msg, String queueName, Set<String> relationTypes, Runnable onSuccess, Consumer<Throwable> onFailure);
|
||||
|
||||
void ack(TbMsg tbMsg);
|
||||
|
||||
TbMsg newMsg(String queueName, String type, EntityId originator, TbMsgMetaData metaData, String data);
|
||||
|
||||
TbMsg newMsg(String queueName, String type, EntityId originator, CustomerId customerId, TbMsgMetaData metaData, String data);
|
||||
|
||||
TbMsg transformMsg(TbMsg origMsg, String type, EntityId originator, TbMsgMetaData metaData, String data);
|
||||
|
||||
TbMsg customerCreatedMsg(Customer customer, RuleNodeId ruleNodeId);
|
||||
|
||||
TbMsg deviceCreatedMsg(Device device, RuleNodeId ruleNodeId);
|
||||
|
||||
TbMsg assetCreatedMsg(Asset asset, RuleNodeId ruleNodeId);
|
||||
|
||||
// TODO: Does this changes the message?
|
||||
TbMsg alarmActionMsg(Alarm alarm, RuleNodeId ruleNodeId, String action);
|
||||
|
||||
TbMsg attributesUpdatedActionMsg(EntityId originator, RuleNodeId ruleNodeId, String scope, List<AttributeKvEntry> attributes);
|
||||
|
||||
TbMsg attributesDeletedActionMsg(EntityId originator, RuleNodeId ruleNodeId, String scope, List<String> keys);
|
||||
|
||||
void onEdgeEventUpdate(TenantId tenantId, EdgeId edgeId);
|
||||
|
||||
/*
|
||||
*
|
||||
* METHODS TO PROCESS THE MESSAGES
|
||||
*
|
||||
*/
|
||||
|
||||
void schedule(Runnable runnable, long delay, TimeUnit timeUnit);
|
||||
|
||||
void checkTenantEntity(EntityId entityId) throws TbNodeException;
|
||||
|
||||
boolean isLocalEntity(EntityId entityId);
|
||||
|
||||
RuleNodeId getSelfId();
|
||||
|
||||
RuleNode getSelf();
|
||||
|
||||
String getRuleChainName();
|
||||
|
||||
TenantId getTenantId();
|
||||
|
||||
AttributesService getAttributesService();
|
||||
|
||||
CustomerService getCustomerService();
|
||||
|
||||
TenantService getTenantService();
|
||||
|
||||
UserService getUserService();
|
||||
|
||||
AssetService getAssetService();
|
||||
|
||||
DeviceService getDeviceService();
|
||||
|
||||
DeviceProfileService getDeviceProfileService();
|
||||
|
||||
AssetProfileService getAssetProfileService();
|
||||
|
||||
DeviceCredentialsService getDeviceCredentialsService();
|
||||
|
||||
TbClusterService getClusterService();
|
||||
|
||||
DashboardService getDashboardService();
|
||||
|
||||
RuleEngineAlarmService getAlarmService();
|
||||
|
||||
AlarmCommentService getAlarmCommentService();
|
||||
|
||||
RuleChainService getRuleChainService();
|
||||
|
||||
RuleEngineRpcService getRpcService();
|
||||
|
||||
RuleEngineTelemetryService getTelemetryService();
|
||||
|
||||
TimeseriesService getTimeseriesService();
|
||||
|
||||
RelationService getRelationService();
|
||||
|
||||
EntityViewService getEntityViewService();
|
||||
|
||||
ResourceService getResourceService();
|
||||
EntityGroupService getEntityGroupService();
|
||||
|
||||
OtaPackageService getOtaPackageService();
|
||||
|
||||
RuleEngineDeviceProfileCache getDeviceProfileCache();
|
||||
|
||||
RuleEngineAssetProfileCache getAssetProfileCache();
|
||||
|
||||
EdgeService getEdgeService();
|
||||
|
||||
EdgeEventService getEdgeEventService();
|
||||
|
||||
QueueService getQueueService();
|
||||
|
||||
ListeningExecutor getMailExecutor();
|
||||
|
||||
ListeningExecutor getSmsExecutor();
|
||||
|
||||
ListeningExecutor getDbCallbackExecutor();
|
||||
|
||||
ListeningExecutor getExternalCallExecutor();
|
||||
|
||||
ListeningExecutor getNotificationExecutor();
|
||||
|
||||
MailService getMailService(boolean isSystem);
|
||||
|
||||
SmsService getSmsService();
|
||||
|
||||
SmsSenderFactory getSmsSenderFactory();
|
||||
|
||||
NotificationCenter getNotificationCenter();
|
||||
|
||||
NotificationTargetService getNotificationTargetService();
|
||||
|
||||
NotificationTemplateService getNotificationTemplateService();
|
||||
|
||||
NotificationRequestService getNotificationRequestService();
|
||||
|
||||
NotificationRuleService getNotificationRuleService();
|
||||
|
||||
SlackService getSlackService();
|
||||
|
||||
SchedulerEventService getSchedulerEventService();
|
||||
|
||||
boolean isExternalNodeForceAck();
|
||||
|
||||
/**
|
||||
* Creates JS Script Engine
|
||||
* @deprecated
|
||||
* <p> Use {@link #createScriptEngine} instead.
|
||||
*
|
||||
*/
|
||||
@Deprecated
|
||||
ScriptEngine createJsScriptEngine(String script, String... argNames);
|
||||
|
||||
ScriptEngine createScriptEngine(ScriptLanguage scriptLang, String script, String... argNames);
|
||||
|
||||
void logJsEvalRequest();
|
||||
|
||||
void logJsEvalResponse();
|
||||
|
||||
void logJsEvalFailure();
|
||||
|
||||
String getServiceId();
|
||||
|
||||
EventLoopGroup getSharedEventLoop();
|
||||
|
||||
CassandraCluster getCassandraCluster();
|
||||
|
||||
TbResultSetFuture submitCassandraReadTask(CassandraStatementTask task);
|
||||
|
||||
TbResultSetFuture submitCassandraWriteTask(CassandraStatementTask task);
|
||||
|
||||
PageData<RuleNodeState> findRuleNodeStates(PageLink pageLink);
|
||||
|
||||
RuleNodeState findRuleNodeStateForEntity(EntityId entityId);
|
||||
|
||||
void removeRuleNodeStateForEntity(EntityId entityId);
|
||||
|
||||
RuleNodeState saveRuleNodeState(RuleNodeState state);
|
||||
|
||||
void clearRuleNodeStates();
|
||||
|
||||
void addTenantProfileListener(Consumer<TenantProfile> listener);
|
||||
|
||||
void addDeviceProfileListeners(Consumer<DeviceProfile> listener, BiConsumer<DeviceId, DeviceProfile> deviceListener);
|
||||
|
||||
void addAssetProfileListeners(Consumer<AssetProfile> listener, BiConsumer<AssetId, AssetProfile> assetListener);
|
||||
|
||||
void removeListeners();
|
||||
|
||||
TenantProfile getTenantProfile();
|
||||
|
||||
WidgetsBundleService getWidgetBundleService();
|
||||
|
||||
WidgetTypeService getWidgetTypeService();
|
||||
|
||||
RuleEngineApiUsageStateService getRuleEngineApiUsageStateService();
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class TbEmail {
|
||||
|
||||
private final String from;
|
||||
private final String to;
|
||||
private final String cc;
|
||||
private final String bcc;
|
||||
private final String subject;
|
||||
private final String body;
|
||||
private final Map<String, String> images;
|
||||
private final boolean html;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import org.thingsboard.server.common.msg.TbMsg;
|
||||
import org.thingsboard.server.common.msg.queue.PartitionChangeMsg;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 19.01.18.
|
||||
*/
|
||||
public interface TbNode {
|
||||
|
||||
void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException;
|
||||
|
||||
void onMsg(TbContext ctx, TbMsg msg) throws ExecutionException, InterruptedException, TbNodeException;
|
||||
|
||||
default void destroy() {}
|
||||
|
||||
default void onPartitionChangeMsg(TbContext ctx, PartitionChangeMsg msg) {}
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 19.01.18.
|
||||
*/
|
||||
@Data
|
||||
public final class TbNodeConfiguration {
|
||||
|
||||
private final JsonNode data;
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.thingsboard.server.common.msg.TbActorError;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 19.01.18.
|
||||
*/
|
||||
public class TbNodeException extends Exception implements TbActorError {
|
||||
|
||||
@Getter
|
||||
private final boolean unrecoverable;
|
||||
|
||||
public TbNodeException(String message) {
|
||||
this(message, false);
|
||||
}
|
||||
|
||||
public TbNodeException(String message, boolean unrecoverable) {
|
||||
super(message);
|
||||
this.unrecoverable = unrecoverable;
|
||||
}
|
||||
|
||||
public TbNodeException(Exception e) {
|
||||
this(e, false);
|
||||
}
|
||||
|
||||
public TbNodeException(Exception e, boolean unrecoverable) {
|
||||
super(e);
|
||||
this.unrecoverable = unrecoverable;
|
||||
}
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 19.01.18.
|
||||
*/
|
||||
public final class TbNodeState {
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 19.01.18.
|
||||
*/
|
||||
public final class TbRelationTypes {
|
||||
|
||||
public static String SUCCESS = "Success";
|
||||
public static String FAILURE = "Failure";
|
||||
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.msg;
|
||||
|
||||
import org.thingsboard.server.common.data.DataConstants;
|
||||
import org.thingsboard.server.common.data.kv.AttributeKey;
|
||||
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author Andrew Shvayka
|
||||
*/
|
||||
public class DeviceAttributes {
|
||||
|
||||
private final Map<String, AttributeKvEntry> clientSideAttributesMap;
|
||||
private final Map<String, AttributeKvEntry> serverPrivateAttributesMap;
|
||||
private final Map<String, AttributeKvEntry> serverPublicAttributesMap;
|
||||
|
||||
public DeviceAttributes(List<AttributeKvEntry> clientSideAttributes, List<AttributeKvEntry> serverPrivateAttributes, List<AttributeKvEntry> serverPublicAttributes) {
|
||||
this.clientSideAttributesMap = mapAttributes(clientSideAttributes);
|
||||
this.serverPrivateAttributesMap = mapAttributes(serverPrivateAttributes);
|
||||
this.serverPublicAttributesMap = mapAttributes(serverPublicAttributes);
|
||||
}
|
||||
|
||||
private static Map<String, AttributeKvEntry> mapAttributes(List<AttributeKvEntry> attributes) {
|
||||
Map<String, AttributeKvEntry> result = new HashMap<>();
|
||||
for (AttributeKvEntry attribute : attributes) {
|
||||
result.put(attribute.getKey(), attribute);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Collection<AttributeKvEntry> getClientSideAttributes() {
|
||||
return clientSideAttributesMap.values();
|
||||
}
|
||||
|
||||
public Collection<AttributeKvEntry> getServerSideAttributes() {
|
||||
return serverPrivateAttributesMap.values();
|
||||
}
|
||||
|
||||
public Collection<AttributeKvEntry> getServerSidePublicAttributes() {
|
||||
return serverPublicAttributesMap.values();
|
||||
}
|
||||
|
||||
public Optional<AttributeKvEntry> getClientSideAttribute(String attribute) {
|
||||
return Optional.ofNullable(clientSideAttributesMap.get(attribute));
|
||||
}
|
||||
|
||||
public Optional<AttributeKvEntry> getServerPrivateAttribute(String attribute) {
|
||||
return Optional.ofNullable(serverPrivateAttributesMap.get(attribute));
|
||||
}
|
||||
|
||||
public Optional<AttributeKvEntry> getServerPublicAttribute(String attribute) {
|
||||
return Optional.ofNullable(serverPublicAttributesMap.get(attribute));
|
||||
}
|
||||
|
||||
public void remove(AttributeKey key) {
|
||||
Map<String, AttributeKvEntry> map = getMapByScope(key.getScope());
|
||||
if (map != null) {
|
||||
map.remove(key.getAttributeKey());
|
||||
}
|
||||
}
|
||||
|
||||
public void update(String scope, List<AttributeKvEntry> values) {
|
||||
Map<String, AttributeKvEntry> map = getMapByScope(scope);
|
||||
values.forEach(v -> map.put(v.getKey(), v));
|
||||
}
|
||||
|
||||
private Map<String, AttributeKvEntry> getMapByScope(String scope) {
|
||||
Map<String, AttributeKvEntry> map = null;
|
||||
if (scope.equalsIgnoreCase(DataConstants.CLIENT_SCOPE)) {
|
||||
map = clientSideAttributesMap;
|
||||
} else if (scope.equalsIgnoreCase(DataConstants.SHARED_SCOPE)) {
|
||||
map = serverPublicAttributesMap;
|
||||
} else if (scope.equalsIgnoreCase(DataConstants.SERVER_SCOPE)) {
|
||||
map = serverPrivateAttributesMap;
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DeviceAttributes{" +
|
||||
"clientSideAttributesMap=" + clientSideAttributesMap +
|
||||
", serverPrivateAttributesMap=" + serverPrivateAttributesMap +
|
||||
", serverPublicAttributesMap=" + serverPublicAttributesMap +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.msg;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.kv.AttributeKey;
|
||||
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
|
||||
import org.thingsboard.server.common.msg.MsgType;
|
||||
import org.thingsboard.server.common.msg.ToDeviceActorNotificationMsg;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Andrew Shvayka
|
||||
*/
|
||||
@ToString
|
||||
@AllArgsConstructor
|
||||
public class DeviceAttributesEventNotificationMsg implements ToDeviceActorNotificationMsg {
|
||||
|
||||
@Getter
|
||||
private final TenantId tenantId;
|
||||
@Getter
|
||||
private final DeviceId deviceId;
|
||||
@Getter
|
||||
private final Set<AttributeKey> deletedKeys;
|
||||
@Getter
|
||||
private final String scope;
|
||||
@Getter
|
||||
private final List<AttributeKvEntry> values;
|
||||
@Getter
|
||||
private final boolean deleted;
|
||||
|
||||
public static DeviceAttributesEventNotificationMsg onUpdate(TenantId tenantId, DeviceId deviceId, String scope, List<AttributeKvEntry> values) {
|
||||
return new DeviceAttributesEventNotificationMsg(tenantId, deviceId, null, scope, values, false);
|
||||
}
|
||||
|
||||
public static DeviceAttributesEventNotificationMsg onDelete(TenantId tenantId, DeviceId deviceId, String scope, List<String> keys) {
|
||||
Set<AttributeKey> keysToNotify = new HashSet<>();
|
||||
keys.forEach(key -> keysToNotify.add(new AttributeKey(scope, key)));
|
||||
return new DeviceAttributesEventNotificationMsg(tenantId, deviceId, keysToNotify, null, null, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MsgType getMsgType() {
|
||||
return MsgType.DEVICE_ATTRIBUTES_UPDATE_TO_DEVICE_ACTOR_MSG;
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.msg;
|
||||
|
||||
import lombok.Data;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.security.DeviceCredentials;
|
||||
import org.thingsboard.server.common.msg.MsgType;
|
||||
import org.thingsboard.server.common.msg.ToDeviceActorNotificationMsg;
|
||||
|
||||
/**
|
||||
* @author Andrew Shvayka
|
||||
*/
|
||||
@Data
|
||||
public class DeviceCredentialsUpdateNotificationMsg implements ToDeviceActorNotificationMsg {
|
||||
|
||||
private static final long serialVersionUID = -3956907402411126990L;
|
||||
|
||||
private final TenantId tenantId;
|
||||
private final DeviceId deviceId;
|
||||
|
||||
/**
|
||||
* LwM2M
|
||||
* @return
|
||||
*/
|
||||
private final DeviceCredentials deviceCredentials;
|
||||
|
||||
@Override
|
||||
public MsgType getMsgType() {
|
||||
return MsgType.DEVICE_CREDENTIALS_UPDATE_TO_DEVICE_ACTOR_MSG;
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.msg;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.EdgeId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.msg.MsgType;
|
||||
import org.thingsboard.server.common.msg.ToDeviceActorNotificationMsg;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class DeviceEdgeUpdateMsg implements ToDeviceActorNotificationMsg {
|
||||
|
||||
private final TenantId tenantId;
|
||||
private final DeviceId deviceId;
|
||||
private final EdgeId edgeId;
|
||||
|
||||
@Override
|
||||
public MsgType getMsgType() {
|
||||
return MsgType.DEVICE_EDGE_UPDATE_TO_DEVICE_ACTOR_MSG;
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.msg;
|
||||
|
||||
import lombok.Data;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
|
||||
/**
|
||||
* Contains basic device metadata;
|
||||
*
|
||||
* @author ashvayka
|
||||
*/
|
||||
@Data
|
||||
public final class DeviceMetaData {
|
||||
|
||||
final DeviceId deviceId;
|
||||
final String deviceName;
|
||||
final String deviceType;
|
||||
final DeviceAttributes deviceAttributes;
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.msg;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.msg.MsgType;
|
||||
import org.thingsboard.server.common.msg.ToDeviceActorNotificationMsg;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class DeviceNameOrTypeUpdateMsg implements ToDeviceActorNotificationMsg {
|
||||
|
||||
private static final long serialVersionUID = -5738949227650536685L;
|
||||
|
||||
private final TenantId tenantId;
|
||||
private final DeviceId deviceId;
|
||||
private final String deviceName;
|
||||
private final String deviceType;
|
||||
|
||||
@Override
|
||||
public MsgType getMsgType() {
|
||||
return MsgType.DEVICE_NAME_OR_TYPE_UPDATE_TO_DEVICE_ACTOR_MSG;
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.slack;
|
||||
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.notification.targets.slack.SlackConversation;
|
||||
import org.thingsboard.server.common.data.notification.targets.slack.SlackConversationType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SlackService {
|
||||
|
||||
void sendMessage(TenantId tenantId, String token, String conversationId, String message);
|
||||
|
||||
List<SlackConversation> listConversations(TenantId tenantId, String token, SlackConversationType conversationType);
|
||||
|
||||
String getToken(TenantId tenantId);
|
||||
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.sms;
|
||||
|
||||
import org.thingsboard.rule.engine.api.sms.exception.SmsException;
|
||||
|
||||
public interface SmsSender {
|
||||
|
||||
int sendSms(String numberTo, String message) throws SmsException;
|
||||
|
||||
void destroy();
|
||||
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.sms;
|
||||
|
||||
import org.thingsboard.server.common.data.sms.config.SmsProviderConfiguration;
|
||||
|
||||
public interface SmsSenderFactory {
|
||||
|
||||
SmsSender createSmsSender(SmsProviderConfiguration config);
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.sms.exception;
|
||||
|
||||
public abstract class SmsException extends RuntimeException {
|
||||
|
||||
public SmsException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public SmsException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.sms.exception;
|
||||
|
||||
public class SmsParseException extends SmsException {
|
||||
|
||||
public SmsParseException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public SmsParseException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.sms.exception;
|
||||
|
||||
public class SmsSendException extends SmsException {
|
||||
|
||||
public SmsSendException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public SmsSendException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.thingsboard.rule.engine.api.TbNodeConfiguration;
|
||||
import org.thingsboard.rule.engine.api.TbNodeException;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.msg.TbMsg;
|
||||
import org.thingsboard.server.common.msg.TbMsgMetaData;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 19.01.18.
|
||||
*/
|
||||
public class TbNodeUtils {
|
||||
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
private static final Pattern DATA_PATTERN = Pattern.compile("(\\$\\[)(.*?)(])");
|
||||
|
||||
public static <T> T convert(TbNodeConfiguration configuration, Class<T> clazz) throws TbNodeException {
|
||||
try {
|
||||
return mapper.treeToValue(configuration.getData(), clazz);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new TbNodeException(e, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> processPatterns(List<String> patterns, TbMsg tbMsg) {
|
||||
if (!CollectionUtils.isEmpty(patterns)) {
|
||||
return patterns.stream().map(p -> processPattern(p, tbMsg)).collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public static String processPattern(String pattern, TbMsg tbMsg) {
|
||||
try {
|
||||
String result = processPattern(pattern, tbMsg.getMetaData());
|
||||
JsonNode json = mapper.readTree(tbMsg.getData());
|
||||
if (json.isObject()) {
|
||||
Matcher matcher = DATA_PATTERN.matcher(result);
|
||||
while (matcher.find()) {
|
||||
String group = matcher.group(2);
|
||||
String[] keys = group.split("\\.");
|
||||
JsonNode jsonNode = json;
|
||||
for (String key : keys) {
|
||||
if (!StringUtils.isEmpty(key) && jsonNode != null) {
|
||||
jsonNode = jsonNode.get(key);
|
||||
} else {
|
||||
jsonNode = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonNode != null && jsonNode.isValueNode()) {
|
||||
result = result.replace(formatDataVarTemplate(group), jsonNode.asText());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to process pattern!", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> processPatterns(List<String> patterns, TbMsgMetaData metaData) {
|
||||
if (!CollectionUtils.isEmpty(patterns)) {
|
||||
return patterns.stream().map(p -> processPattern(p, metaData)).collect(Collectors.toList());
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public static String processPattern(String pattern, TbMsgMetaData metaData) {
|
||||
return processTemplate(pattern, metaData.values());
|
||||
}
|
||||
|
||||
public static String processTemplate(String template, Map<String, String> data) {
|
||||
String result = template;
|
||||
for (Map.Entry<String, String> kv : data.entrySet()) {
|
||||
result = processVar(result, kv.getKey(), kv.getValue());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String processVar(String pattern, String key, String val) {
|
||||
return pattern.replace(formatMetadataVarTemplate(key), val);
|
||||
}
|
||||
|
||||
static String formatDataVarTemplate(String key) {
|
||||
return "$[" + key + ']';
|
||||
}
|
||||
|
||||
static String formatMetadataVarTemplate(String key) {
|
||||
return "${" + key + '}';
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* Copyright © 2016-2023 The Thingsboard Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.thingsboard.rule.engine.api.util;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.thingsboard.common.util.JacksonUtil;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.msg.TbMsg;
|
||||
import org.thingsboard.server.common.msg.TbMsgMetaData;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TbNodeUtilsTest {
|
||||
|
||||
private static final String DATA_VARIABLE_TEMPLATE = "$[%s]";
|
||||
private static final String METADATA_VARIABLE_TEMPLATE = "${%s}";
|
||||
|
||||
@Test
|
||||
public void testSimpleReplacement() {
|
||||
String pattern = "ABC ${metadata_key} $[data_key]";
|
||||
TbMsgMetaData md = new TbMsgMetaData();
|
||||
md.putValue("metadata_key", "metadata_value");
|
||||
|
||||
ObjectNode node = JacksonUtil.newObjectNode();
|
||||
node.put("data_key", "data_value");
|
||||
|
||||
TbMsg msg = TbMsg.newMsg("CUSTOM", TenantId.SYS_TENANT_ID, md, JacksonUtil.toString(node));
|
||||
String result = TbNodeUtils.processPattern(pattern, msg);
|
||||
Assert.assertEquals("ABC metadata_value data_value", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoReplacement() {
|
||||
String pattern = "ABC ${metadata_key} $[data_key]";
|
||||
TbMsgMetaData md = new TbMsgMetaData();
|
||||
md.putValue("key", "metadata_value");
|
||||
|
||||
ObjectNode node = JacksonUtil.newObjectNode();
|
||||
node.put("key", "data_value");
|
||||
|
||||
TbMsg msg = TbMsg.newMsg("CUSTOM", TenantId.SYS_TENANT_ID, md, JacksonUtil.toString(node));
|
||||
String result = TbNodeUtils.processPattern(pattern, msg);
|
||||
Assert.assertEquals(pattern, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameKeysReplacement() {
|
||||
String pattern = "ABC ${key} $[key]";
|
||||
TbMsgMetaData md = new TbMsgMetaData();
|
||||
md.putValue("key", "metadata_value");
|
||||
|
||||
ObjectNode node = JacksonUtil.newObjectNode();
|
||||
node.put("key", "data_value");
|
||||
|
||||
TbMsg msg = TbMsg.newMsg("CUSTOM", TenantId.SYS_TENANT_ID, md, JacksonUtil.toString(node));
|
||||
String result = TbNodeUtils.processPattern(pattern, msg);
|
||||
Assert.assertEquals("ABC metadata_value data_value", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComplexObjectReplacement() {
|
||||
String pattern = "ABC ${key} $[key1.key2.key3]";
|
||||
TbMsgMetaData md = new TbMsgMetaData();
|
||||
md.putValue("key", "metadata_value");
|
||||
|
||||
ObjectNode key2Node = JacksonUtil.newObjectNode();
|
||||
key2Node.put("key3", "value3");
|
||||
|
||||
ObjectNode key1Node = JacksonUtil.newObjectNode();
|
||||
key1Node.set("key2", key2Node);
|
||||
|
||||
|
||||
ObjectNode node = JacksonUtil.newObjectNode();
|
||||
node.set("key1", key1Node);
|
||||
|
||||
TbMsg msg = TbMsg.newMsg("CUSTOM", TenantId.SYS_TENANT_ID, md, JacksonUtil.toString(node));
|
||||
String result = TbNodeUtils.processPattern(pattern, msg);
|
||||
Assert.assertEquals("ABC metadata_value value3", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArrayReplacementDoesNotWork() {
|
||||
String pattern = "ABC ${key} $[key1.key2[0].key3]";
|
||||
TbMsgMetaData md = new TbMsgMetaData();
|
||||
md.putValue("key", "metadata_value");
|
||||
|
||||
ObjectNode key2Node = JacksonUtil.newObjectNode();
|
||||
key2Node.put("key3", "value3");
|
||||
|
||||
ObjectNode key1Node = JacksonUtil.newObjectNode();
|
||||
key1Node.set("key2", key2Node);
|
||||
|
||||
|
||||
ObjectNode node = JacksonUtil.newObjectNode();
|
||||
node.set("key1", key1Node);
|
||||
|
||||
TbMsg msg = TbMsg.newMsg("CUSTOM", TenantId.SYS_TENANT_ID, md, JacksonUtil.toString(node));
|
||||
String result = TbNodeUtils.processPattern(pattern, msg);
|
||||
Assert.assertEquals("ABC metadata_value $[key1.key2[0].key3]", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenKey_whenFormatDataVarTemplate_thenReturnTheSameStringAsFormat() {
|
||||
assertThat(TbNodeUtils.formatDataVarTemplate("key"), is("$[key]"));
|
||||
assertThat(TbNodeUtils.formatDataVarTemplate("key"), is(String.format(DATA_VARIABLE_TEMPLATE, "key")));
|
||||
|
||||
assertThat(TbNodeUtils.formatDataVarTemplate(""), is("$[]"));
|
||||
assertThat(TbNodeUtils.formatDataVarTemplate(""), is(String.format(DATA_VARIABLE_TEMPLATE, "")));
|
||||
|
||||
assertThat(TbNodeUtils.formatDataVarTemplate(null), is("$[null]"));
|
||||
assertThat(TbNodeUtils.formatDataVarTemplate(null), is(String.format(DATA_VARIABLE_TEMPLATE, (String) null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenKey_whenFormatMetadataVarTemplate_thenReturnTheSameStringAsFormat() {
|
||||
assertThat(TbNodeUtils.formatMetadataVarTemplate("key"), is("${key}"));
|
||||
assertThat(TbNodeUtils.formatMetadataVarTemplate("key"), is(String.format(METADATA_VARIABLE_TEMPLATE, "key")));
|
||||
|
||||
assertThat(TbNodeUtils.formatMetadataVarTemplate(""), is("${}"));
|
||||
assertThat(TbNodeUtils.formatMetadataVarTemplate(""), is(String.format(METADATA_VARIABLE_TEMPLATE, "")));
|
||||
|
||||
assertThat(TbNodeUtils.formatMetadataVarTemplate(null), is("${null}"));
|
||||
assertThat(TbNodeUtils.formatMetadataVarTemplate(null), is(String.format(METADATA_VARIABLE_TEMPLATE, (String) null)));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user