Browse Source

Merge remote-tracking branch 'upstream/master'

pull/197/head
Volodymyr Babak 9 years ago
parent
commit
467c85bf9f
  1. 1
      .mvn/jvm.config
  2. 6
      application/src/main/java/org/thingsboard/server/ThingsboardInstallApplication.java
  3. 4
      application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java
  4. 27
      application/src/main/java/org/thingsboard/server/actors/rule/RuleProcessingContext.java
  5. 2
      application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseSchemaService.java
  6. 1
      application/src/test/java/org/thingsboard/server/controller/AbstractControllerTest.java
  7. 2
      application/src/test/java/org/thingsboard/server/controller/BaseAdminControllerTest.java
  8. 2
      application/src/test/java/org/thingsboard/server/controller/BaseAssetControllerTest.java
  9. 2
      application/src/test/java/org/thingsboard/server/controller/BaseAuthControllerTest.java
  10. 2
      application/src/test/java/org/thingsboard/server/controller/BaseComponentDescriptorControllerTest.java
  11. 2
      application/src/test/java/org/thingsboard/server/controller/BaseCustomerControllerTest.java
  12. 2
      application/src/test/java/org/thingsboard/server/controller/BaseDashboardControllerTest.java
  13. 2
      application/src/test/java/org/thingsboard/server/controller/BaseDeviceControllerTest.java
  14. 6
      application/src/test/java/org/thingsboard/server/controller/BasePluginControllerTest.java
  15. 2
      application/src/test/java/org/thingsboard/server/controller/BaseRuleControllerTest.java
  16. 4
      application/src/test/java/org/thingsboard/server/controller/BaseTenantControllerTest.java
  17. 2
      application/src/test/java/org/thingsboard/server/controller/BaseUserControllerTest.java
  18. 2
      application/src/test/java/org/thingsboard/server/controller/BaseWidgetTypeControllerTest.java
  19. 2
      application/src/test/java/org/thingsboard/server/controller/BaseWidgetsBundleControllerTest.java
  20. 4
      application/src/test/java/org/thingsboard/server/controller/ControllerNoSqlTestSuite.java
  21. 36
      application/src/test/java/org/thingsboard/server/controller/ControllerSqlTestSuite.java
  22. 26
      application/src/test/java/org/thingsboard/server/controller/nosql/AdminControllerNoSqlTest.java
  23. 27
      application/src/test/java/org/thingsboard/server/controller/nosql/AssetControllerNoSqlTest.java
  24. 26
      application/src/test/java/org/thingsboard/server/controller/nosql/AuthControllerNoSqlTest.java
  25. 26
      application/src/test/java/org/thingsboard/server/controller/nosql/ComponentDescriptorControllerNoSqlTest.java
  26. 26
      application/src/test/java/org/thingsboard/server/controller/nosql/CustomerControllerNoSqlTest.java
  27. 26
      application/src/test/java/org/thingsboard/server/controller/nosql/DashboardControllerNoSqlTest.java
  28. 26
      application/src/test/java/org/thingsboard/server/controller/nosql/DeviceControllerNoSqlTest.java
  29. 26
      application/src/test/java/org/thingsboard/server/controller/nosql/PluginControllerNoSqlTest.java
  30. 26
      application/src/test/java/org/thingsboard/server/controller/nosql/RuleControllerNoSqlTest.java
  31. 26
      application/src/test/java/org/thingsboard/server/controller/nosql/TenantControllerNoSqlTest.java
  32. 26
      application/src/test/java/org/thingsboard/server/controller/nosql/UserControllerNoSqlTest.java
  33. 26
      application/src/test/java/org/thingsboard/server/controller/nosql/WidgetTypeControllerNoSqlTest.java
  34. 26
      application/src/test/java/org/thingsboard/server/controller/nosql/WidgetsBundleControllerNoSqlTest.java
  35. 26
      application/src/test/java/org/thingsboard/server/controller/sql/AdminControllerSqlTest.java
  36. 26
      application/src/test/java/org/thingsboard/server/controller/sql/AssetControllerSqlTest.java
  37. 26
      application/src/test/java/org/thingsboard/server/controller/sql/AuthControllerSqlTest.java
  38. 26
      application/src/test/java/org/thingsboard/server/controller/sql/ComponentDescriptorControllerSqlTest.java
  39. 26
      application/src/test/java/org/thingsboard/server/controller/sql/CustomerControllerSqlTest.java
  40. 26
      application/src/test/java/org/thingsboard/server/controller/sql/DashboardControllerSqlTest.java
  41. 26
      application/src/test/java/org/thingsboard/server/controller/sql/DeviceControllerSqlTest.java
  42. 26
      application/src/test/java/org/thingsboard/server/controller/sql/PluginControllerSqlTest.java
  43. 26
      application/src/test/java/org/thingsboard/server/controller/sql/RuleControllerSqlTest.java
  44. 26
      application/src/test/java/org/thingsboard/server/controller/sql/TenantControllerSqlTest.java
  45. 26
      application/src/test/java/org/thingsboard/server/controller/sql/UserControllerSqlTest.java
  46. 26
      application/src/test/java/org/thingsboard/server/controller/sql/WidgetTypeControllerSqlTest.java
  47. 26
      application/src/test/java/org/thingsboard/server/controller/sql/WidgetsBundleControllerSqlTest.java
  48. 3
      application/src/test/java/org/thingsboard/server/system/SystemSqlTestSuite.java
  49. 1
      common/data/src/main/java/org/thingsboard/server/common/data/relation/EntityRelation.java
  50. 3
      dao/src/main/java/org/thingsboard/server/dao/alarm/AlarmService.java
  51. 29
      dao/src/main/java/org/thingsboard/server/dao/alarm/BaseAlarmService.java
  52. 6
      dao/src/test/java/org/thingsboard/server/dao/CustomSqlUnit.java
  53. 4
      dao/src/test/resources/sql-test.properties
  54. 10
      extensions-api/src/main/java/org/thingsboard/server/extensions/api/rules/RuleContext.java
  55. 2
      extensions-api/src/main/java/org/thingsboard/server/extensions/api/rules/RuleProcessor.java
  56. 14
      extensions-core/src/main/java/org/thingsboard/server/extensions/core/filter/BasicJsFilter.java
  57. 42
      extensions-core/src/main/java/org/thingsboard/server/extensions/core/filter/DeviceAttributesFilter.java
  58. 12
      extensions-core/src/main/java/org/thingsboard/server/extensions/core/filter/DeviceTelemetryFilter.java
  59. 72
      extensions-core/src/main/java/org/thingsboard/server/extensions/core/filter/NashornJsEvaluator.java
  60. 2
      extensions-core/src/main/java/org/thingsboard/server/extensions/core/processor/AlarmDeduplicationProcessor.java
  61. 213
      extensions-core/src/main/java/org/thingsboard/server/extensions/core/processor/AlarmProcessor.java
  62. 38
      extensions-core/src/main/java/org/thingsboard/server/extensions/core/processor/AlarmProcessorConfiguration.java
  63. 8
      extensions-core/src/main/java/org/thingsboard/server/extensions/core/utils/VelocityUtils.java
  64. 113
      extensions-core/src/main/resources/AlarmProcessorDescriptor.json

1
.mvn/jvm.config

@ -1 +0,0 @@
-Xmx4096m -Xms1024m

6
application/src/main/java/org/thingsboard/server/ThingsboardInstallApplication.java

@ -17,16 +17,14 @@
package org.thingsboard.server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.thingsboard.server.install.ThingsboardInstallService;
import java.util.Arrays;
@EnableAutoConfiguration
@SpringBootApplication
@SpringBootConfiguration
@ComponentScan({"org.thingsboard.server.install",
"org.thingsboard.server.service.component",
"org.thingsboard.server.service.install",

4
application/src/main/java/org/thingsboard/server/actors/ActorSystemContext.java

@ -37,6 +37,7 @@ import org.thingsboard.server.common.data.plugin.ComponentLifecycleEvent;
import org.thingsboard.server.common.msg.cluster.ServerAddress;
import org.thingsboard.server.common.transport.auth.DeviceAuthService;
import org.thingsboard.server.controller.plugin.PluginWebSocketMsgEndpoint;
import org.thingsboard.server.dao.alarm.AlarmService;
import org.thingsboard.server.dao.asset.AssetService;
import org.thingsboard.server.dao.attributes.AttributesService;
import org.thingsboard.server.dao.customer.CustomerService;
@ -105,6 +106,9 @@ public class ActorSystemContext {
@Autowired
@Getter private EventService eventService;
@Autowired
@Getter private AlarmService alarmService;
@Autowired
@Getter @Setter private PluginWebSocketMsgEndpoint wsMsgEndpoint;

27
application/src/main/java/org/thingsboard/server/actors/rule/RuleProcessingContext.java

@ -15,22 +15,27 @@
*/
package org.thingsboard.server.actors.rule;
import com.google.common.util.concurrent.ListenableFuture;
import org.thingsboard.server.actors.ActorSystemContext;
import org.thingsboard.server.common.data.Event;
import org.thingsboard.server.common.data.alarm.Alarm;
import org.thingsboard.server.common.data.alarm.AlarmId;
import org.thingsboard.server.common.data.id.*;
import org.thingsboard.server.dao.alarm.AlarmService;
import org.thingsboard.server.dao.event.EventService;
import org.thingsboard.server.dao.timeseries.TimeseriesService;
import org.thingsboard.server.extensions.api.device.DeviceAttributes;
import org.thingsboard.server.common.msg.device.ToDeviceActorMsg;
import org.thingsboard.server.extensions.api.device.DeviceMetaData;
import org.thingsboard.server.extensions.api.rules.RuleContext;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
public class RuleProcessingContext implements RuleContext {
private final TimeseriesService tsService;
private final EventService eventService;
private final AlarmService alarmService;
private final RuleId ruleId;
private TenantId tenantId;
private CustomerId customerId;
@ -40,6 +45,7 @@ public class RuleProcessingContext implements RuleContext {
RuleProcessingContext(ActorSystemContext systemContext, RuleId ruleId) {
this.tsService = systemContext.getTsService();
this.eventService = systemContext.getEventService();
this.alarmService = systemContext.getAlarmService();
this.ruleId = ruleId;
}
@ -77,6 +83,25 @@ public class RuleProcessingContext implements RuleContext {
return eventService.findEvent(tenantId, deviceId, eventType, eventUid);
}
@Override
public Alarm createOrUpdateAlarm(Alarm alarm) {
alarm.setTenantId(tenantId);
return alarmService.createOrUpdateAlarm(alarm);
}
public Optional<Alarm> findLatestAlarm(EntityId originator, String alarmType) {
try {
return Optional.ofNullable(alarmService.findLatestByOriginatorAndType(tenantId, originator, alarmType).get());
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException("Failed to lookup alarm!", e);
}
}
@Override
public ListenableFuture<Boolean> clearAlarm(AlarmId alarmId, long clearTs) {
return alarmService.clearAlarm(alarmId, clearTs);
}
private void checkEvent(Event event) {
if (event.getTenantId() == null) {
event.setTenantId(tenantId);

2
application/src/main/java/org/thingsboard/server/service/install/SqlDatabaseSchemaService.java

@ -20,10 +20,12 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;
import org.thingsboard.server.dao.util.SqlDao;
@Service
@Profile("install")
@Slf4j
@SqlDao
public class SqlDatabaseSchemaService implements DatabaseSchemaService {
@Value("${install.data_dir}")

1
application/src/test/java/org/thingsboard/server/controller/AbstractControllerTest.java

@ -80,7 +80,6 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC
@ActiveProfiles("test")
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = AbstractControllerTest.class, loader = SpringBootContextLoader.class)
@TestPropertySource(locations = {"classpath:cassandra-test.properties", "classpath:application-test.properties", "classpath:nosql-test.properties"})
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@Configuration
@ComponentScan({"org.thingsboard.server"})

2
application/src/test/java/org/thingsboard/server/controller/AdminControllerTest.java → application/src/test/java/org/thingsboard/server/controller/BaseAdminControllerTest.java

@ -29,7 +29,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
public class AdminControllerTest extends AbstractControllerTest {
public abstract class BaseAdminControllerTest extends AbstractControllerTest {
@Test
public void testFindAdminSettingsByKey() throws Exception {

2
application/src/test/java/org/thingsboard/server/controller/AssetControllerTest.java → application/src/test/java/org/thingsboard/server/controller/BaseAssetControllerTest.java

@ -40,7 +40,7 @@ import org.junit.Test;
import com.datastax.driver.core.utils.UUIDs;
import com.fasterxml.jackson.core.type.TypeReference;
public class AssetControllerTest extends AbstractControllerTest {
public abstract class BaseAssetControllerTest extends AbstractControllerTest {
private IdComparator<Asset> idComparator = new IdComparator<>();

2
application/src/test/java/org/thingsboard/server/controller/AuthControllerTest.java → application/src/test/java/org/thingsboard/server/controller/BaseAuthControllerTest.java

@ -22,7 +22,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import org.thingsboard.server.common.data.security.Authority;
import org.junit.Test;
public class AuthControllerTest extends AbstractControllerTest {
public abstract class BaseAuthControllerTest extends AbstractControllerTest {
@Test
public void testGetUser() throws Exception {

2
application/src/test/java/org/thingsboard/server/controller/ComponentDescriptorControllerTest.java → application/src/test/java/org/thingsboard/server/controller/BaseComponentDescriptorControllerTest.java

@ -33,7 +33,7 @@ import java.util.List;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class ComponentDescriptorControllerTest extends AbstractControllerTest {
public abstract class BaseComponentDescriptorControllerTest extends AbstractControllerTest {
private static final int AMOUNT_OF_DEFAULT_PLUGINS_DESCRIPTORS = 5;
private Tenant savedTenant;

2
application/src/test/java/org/thingsboard/server/controller/CustomerControllerTest.java → application/src/test/java/org/thingsboard/server/controller/BaseCustomerControllerTest.java

@ -35,7 +35,7 @@ import org.junit.Test;
import com.fasterxml.jackson.core.type.TypeReference;
public class CustomerControllerTest extends AbstractControllerTest {
public abstract class BaseCustomerControllerTest extends AbstractControllerTest {
private IdComparator<Customer> idComparator = new IdComparator<>();

2
application/src/test/java/org/thingsboard/server/controller/DashboardControllerTest.java → application/src/test/java/org/thingsboard/server/controller/BaseDashboardControllerTest.java

@ -38,7 +38,7 @@ import org.junit.Test;
import com.fasterxml.jackson.core.type.TypeReference;
public class DashboardControllerTest extends AbstractControllerTest {
public abstract class BaseDashboardControllerTest extends AbstractControllerTest {
private IdComparator<DashboardInfo> idComparator = new IdComparator<>();

2
application/src/test/java/org/thingsboard/server/controller/DeviceControllerTest.java → application/src/test/java/org/thingsboard/server/controller/BaseDeviceControllerTest.java

@ -42,7 +42,7 @@ import org.junit.Test;
import com.fasterxml.jackson.core.type.TypeReference;
public class DeviceControllerTest extends AbstractControllerTest {
public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
private IdComparator<Device> idComparator = new IdComparator<>();

6
application/src/test/java/org/thingsboard/server/controller/PluginControllerTest.java → application/src/test/java/org/thingsboard/server/controller/BasePluginControllerTest.java

@ -37,7 +37,7 @@ import java.util.stream.Collectors;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class PluginControllerTest extends AbstractControllerTest {
public abstract class BasePluginControllerTest extends AbstractControllerTest {
private IdComparator<PluginMetaData> idComparator = new IdComparator<>();
@ -130,7 +130,7 @@ public class PluginControllerTest extends AbstractControllerTest {
doPost("/api/plugin/" + savedPlugin.getId().getId().toString() + "/activate").andExpect(status().isOk());
RuleMetaData rule = RuleControllerTest.createRuleMetaData(savedPlugin);
RuleMetaData rule = BaseRuleControllerTest.createRuleMetaData(savedPlugin);
RuleMetaData savedRule = doPost("/api/rule", rule, RuleMetaData.class);
doPost("/api/rule/" + savedRule.getId().getId().toString() + "/activate").andExpect(status().isOk());
@ -151,7 +151,7 @@ public class PluginControllerTest extends AbstractControllerTest {
PluginMetaData savedPlugin = doPost("/api/plugin", plugin, PluginMetaData.class);
RuleMetaData rule = RuleControllerTest.createRuleMetaData(savedPlugin);
RuleMetaData rule = BaseRuleControllerTest.createRuleMetaData(savedPlugin);
RuleMetaData savedRule = doPost("/api/rule", rule, RuleMetaData.class);
doDelete("/api/plugin/" + savedPlugin.getId().getId()).andExpect(status().isBadRequest());

2
application/src/test/java/org/thingsboard/server/controller/RuleControllerTest.java → application/src/test/java/org/thingsboard/server/controller/BaseRuleControllerTest.java

@ -38,7 +38,7 @@ import java.util.stream.Collectors;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class RuleControllerTest extends AbstractControllerTest {
public abstract class BaseRuleControllerTest extends AbstractControllerTest {
private IdComparator<RuleMetaData> idComparator = new IdComparator<>();

4
application/src/test/java/org/thingsboard/server/controller/TenantControllerTest.java → application/src/test/java/org/thingsboard/server/controller/BaseTenantControllerTest.java

@ -31,7 +31,7 @@ import org.junit.Test;
import com.fasterxml.jackson.core.type.TypeReference;
public class TenantControllerTest extends AbstractControllerTest {
public abstract class BaseTenantControllerTest extends AbstractControllerTest {
private IdComparator<Tenant> idComparator = new IdComparator<>();
@ -107,7 +107,7 @@ public class TenantControllerTest extends AbstractControllerTest {
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(1, pageData.getData().size());
tenants.addAll(pageData.getData());
for (int i=0;i<56;i++) {
Tenant tenant = new Tenant();
tenant.setTitle("Tenant"+i);

2
application/src/test/java/org/thingsboard/server/controller/UserControllerTest.java → application/src/test/java/org/thingsboard/server/controller/BaseUserControllerTest.java

@ -39,7 +39,7 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
public class UserControllerTest extends AbstractControllerTest {
public abstract class BaseUserControllerTest extends AbstractControllerTest {
private IdComparator<User> idComparator = new IdComparator<>();

2
application/src/test/java/org/thingsboard/server/controller/WidgetTypeControllerTest.java → application/src/test/java/org/thingsboard/server/controller/BaseWidgetTypeControllerTest.java

@ -35,7 +35,7 @@ import java.util.List;
import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class WidgetTypeControllerTest extends AbstractControllerTest {
public abstract class BaseWidgetTypeControllerTest extends AbstractControllerTest {
private IdComparator<WidgetType> idComparator = new IdComparator<>();

2
application/src/test/java/org/thingsboard/server/controller/WidgetsBundleControllerTest.java → application/src/test/java/org/thingsboard/server/controller/BaseWidgetsBundleControllerTest.java

@ -34,7 +34,7 @@ import java.util.List;
import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
public class WidgetsBundleControllerTest extends AbstractControllerTest {
public abstract class BaseWidgetsBundleControllerTest extends AbstractControllerTest {
private IdComparator<WidgetsBundle> idComparator = new IdComparator<>();

4
application/src/test/java/org/thingsboard/server/controller/ControllerTestSuite.java → application/src/test/java/org/thingsboard/server/controller/ControllerNoSqlTestSuite.java

@ -25,8 +25,8 @@ import java.util.Arrays;
@RunWith(ClasspathSuite.class)
@ClasspathSuite.ClassnameFilters({
"org.thingsboard.server.controller.*Test"})
public class ControllerTestSuite {
"org.thingsboard.server.controller.nosql.*Test"})
public class ControllerNoSqlTestSuite {
@ClassRule
public static CustomCassandraCQLUnit cassandraUnit =

36
application/src/test/java/org/thingsboard/server/controller/ControllerSqlTestSuite.java

@ -0,0 +1,36 @@
/**
* Copyright © 2016-2017 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.server.controller;
import org.junit.ClassRule;
import org.junit.extensions.cpsuite.ClasspathSuite;
import org.junit.runner.RunWith;
import org.thingsboard.server.dao.CustomSqlUnit;
import java.util.Arrays;
@RunWith(ClasspathSuite.class)
@ClasspathSuite.ClassnameFilters({
"org.thingsboard.server.controller.sql.*SqlTest",
})
public class ControllerSqlTestSuite {
@ClassRule
public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
Arrays.asList("sql/schema.sql", "sql/system-data.sql"),
"sql/drop-all-tables.sql",
"sql-test.properties");
}

26
application/src/test/java/org/thingsboard/server/controller/nosql/AdminControllerNoSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.nosql;
import org.thingsboard.server.controller.BaseAdminControllerTest;
import org.thingsboard.server.dao.service.DaoNoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoNoSqlTest
public class AdminControllerNoSqlTest extends BaseAdminControllerTest {
}

27
application/src/test/java/org/thingsboard/server/controller/nosql/AssetControllerNoSqlTest.java

@ -0,0 +1,27 @@
/**
* Copyright © 2016-2017 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.server.controller.nosql;
import org.thingsboard.server.controller.BaseAssetControllerTest;
import org.thingsboard.server.dao.service.DaoNoSqlTest;
import org.thingsboard.server.dao.util.NoSqlDao;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoNoSqlTest
public class AssetControllerNoSqlTest extends BaseAssetControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/nosql/AuthControllerNoSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.nosql;
import org.thingsboard.server.controller.BaseAuthControllerTest;
import org.thingsboard.server.dao.service.DaoNoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoNoSqlTest
public class AuthControllerNoSqlTest extends BaseAuthControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/nosql/ComponentDescriptorControllerNoSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.nosql;
import org.thingsboard.server.controller.BaseComponentDescriptorControllerTest;
import org.thingsboard.server.dao.service.DaoNoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoNoSqlTest
public class ComponentDescriptorControllerNoSqlTest extends BaseComponentDescriptorControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/nosql/CustomerControllerNoSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.nosql;
import org.thingsboard.server.controller.BaseCustomerControllerTest;
import org.thingsboard.server.dao.service.DaoNoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoNoSqlTest
public class CustomerControllerNoSqlTest extends BaseCustomerControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/nosql/DashboardControllerNoSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.nosql;
import org.thingsboard.server.controller.BaseDashboardControllerTest;
import org.thingsboard.server.dao.service.DaoNoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoNoSqlTest
public class DashboardControllerNoSqlTest extends BaseDashboardControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/nosql/DeviceControllerNoSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.nosql;
import org.thingsboard.server.controller.BaseDeviceControllerTest;
import org.thingsboard.server.dao.service.DaoNoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoNoSqlTest
public class DeviceControllerNoSqlTest extends BaseDeviceControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/nosql/PluginControllerNoSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.nosql;
import org.thingsboard.server.controller.BasePluginControllerTest;
import org.thingsboard.server.dao.service.DaoNoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoNoSqlTest
public class PluginControllerNoSqlTest extends BasePluginControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/nosql/RuleControllerNoSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.nosql;
import org.thingsboard.server.controller.BaseRuleControllerTest;
import org.thingsboard.server.dao.service.DaoNoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoNoSqlTest
public class RuleControllerNoSqlTest extends BaseRuleControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/nosql/TenantControllerNoSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.nosql;
import org.thingsboard.server.controller.BaseTenantControllerTest;
import org.thingsboard.server.dao.service.DaoNoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoNoSqlTest
public class TenantControllerNoSqlTest extends BaseTenantControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/nosql/UserControllerNoSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.nosql;
import org.thingsboard.server.controller.BaseUserControllerTest;
import org.thingsboard.server.dao.service.DaoNoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoNoSqlTest
public class UserControllerNoSqlTest extends BaseUserControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/nosql/WidgetTypeControllerNoSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.nosql;
import org.thingsboard.server.controller.BaseWidgetTypeControllerTest;
import org.thingsboard.server.dao.service.DaoNoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoNoSqlTest
public class WidgetTypeControllerNoSqlTest extends BaseWidgetTypeControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/nosql/WidgetsBundleControllerNoSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.nosql;
import org.thingsboard.server.controller.BaseWidgetsBundleControllerTest;
import org.thingsboard.server.dao.service.DaoNoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoNoSqlTest
public class WidgetsBundleControllerNoSqlTest extends BaseWidgetsBundleControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/sql/AdminControllerSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.sql;
import org.thingsboard.server.controller.BaseAdminControllerTest;
import org.thingsboard.server.dao.service.DaoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoSqlTest
public class AdminControllerSqlTest extends BaseAdminControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/sql/AssetControllerSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.sql;
import org.thingsboard.server.controller.BaseAssetControllerTest;
import org.thingsboard.server.dao.service.DaoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoSqlTest
public class AssetControllerSqlTest extends BaseAssetControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/sql/AuthControllerSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.sql;
import org.thingsboard.server.controller.BaseAuthControllerTest;
import org.thingsboard.server.dao.service.DaoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoSqlTest
public class AuthControllerSqlTest extends BaseAuthControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/sql/ComponentDescriptorControllerSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.sql;
import org.thingsboard.server.controller.BaseComponentDescriptorControllerTest;
import org.thingsboard.server.dao.service.DaoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoSqlTest
public class ComponentDescriptorControllerSqlTest extends BaseComponentDescriptorControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/sql/CustomerControllerSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.sql;
import org.thingsboard.server.controller.BaseCustomerControllerTest;
import org.thingsboard.server.dao.service.DaoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoSqlTest
public class CustomerControllerSqlTest extends BaseCustomerControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/sql/DashboardControllerSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.sql;
import org.thingsboard.server.controller.BaseDashboardControllerTest;
import org.thingsboard.server.dao.service.DaoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoSqlTest
public class DashboardControllerSqlTest extends BaseDashboardControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/sql/DeviceControllerSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.sql;
import org.thingsboard.server.controller.BaseDeviceControllerTest;
import org.thingsboard.server.dao.service.DaoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoSqlTest
public class DeviceControllerSqlTest extends BaseDeviceControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/sql/PluginControllerSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.sql;
import org.thingsboard.server.controller.BasePluginControllerTest;
import org.thingsboard.server.dao.service.DaoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoSqlTest
public class PluginControllerSqlTest extends BasePluginControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/sql/RuleControllerSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.sql;
import org.thingsboard.server.controller.BaseRuleControllerTest;
import org.thingsboard.server.dao.service.DaoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoSqlTest
public class RuleControllerSqlTest extends BaseRuleControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/sql/TenantControllerSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.sql;
import org.thingsboard.server.controller.BaseTenantControllerTest;
import org.thingsboard.server.dao.service.DaoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoSqlTest
public class TenantControllerSqlTest extends BaseTenantControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/sql/UserControllerSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.sql;
import org.thingsboard.server.controller.BaseUserControllerTest;
import org.thingsboard.server.dao.service.DaoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoSqlTest
public class UserControllerSqlTest extends BaseUserControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/sql/WidgetTypeControllerSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.sql;
import org.thingsboard.server.controller.BaseWidgetTypeControllerTest;
import org.thingsboard.server.dao.service.DaoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoSqlTest
public class WidgetTypeControllerSqlTest extends BaseWidgetTypeControllerTest {
}

26
application/src/test/java/org/thingsboard/server/controller/sql/WidgetsBundleControllerSqlTest.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2017 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.server.controller.sql;
import org.thingsboard.server.controller.BaseWidgetsBundleControllerTest;
import org.thingsboard.server.dao.service.DaoSqlTest;
/**
* Created by Valerii Sosliuk on 6/28/2017.
*/
@DaoSqlTest
public class WidgetsBundleControllerSqlTest extends BaseWidgetsBundleControllerTest {
}

3
application/src/test/java/org/thingsboard/server/system/SystemSqlTestSuite.java

@ -33,8 +33,7 @@ public class SystemSqlTestSuite {
public static CustomSqlUnit sqlUnit = new CustomSqlUnit(
Arrays.asList("sql/schema.sql", "sql/system-data.sql"),
"sql/drop-all-tables.sql",
"sql-test.properties"
);
"sql-test.properties");
}

1
common/data/src/main/java/org/thingsboard/server/common/data/relation/EntityRelation.java

@ -110,7 +110,6 @@ public class EntityRelation {
if (to != null ? !to.equals(that.to) : that.to != null) return false;
if (type != null ? !type.equals(that.type) : that.type != null) return false;
return typeGroup == that.typeGroup;
}
@Override

3
dao/src/main/java/org/thingsboard/server/dao/alarm/AlarmService.java

@ -18,6 +18,7 @@ package org.thingsboard.server.dao.alarm;
import com.google.common.util.concurrent.ListenableFuture;
import org.thingsboard.server.common.data.alarm.*;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.TimePageData;
/**
@ -40,4 +41,6 @@ public interface AlarmService {
AlarmSeverity findHighestAlarmSeverity(EntityId entityId, AlarmSearchStatus alarmSearchStatus,
AlarmStatus alarmStatus);
ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type);
}

29
dao/src/main/java/org/thingsboard/server/dao/alarm/BaseAlarmService.java

@ -27,6 +27,7 @@ import org.springframework.util.StringUtils;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.alarm.*;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.TimePageData;
import org.thingsboard.server.common.data.page.TimePageLink;
import org.thingsboard.server.common.data.relation.EntityRelation;
@ -111,6 +112,10 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
}
}
public ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type) {
return alarmDao.findLatestByOriginatorAndType(tenantId, originator, type);
}
private Alarm createAlarm(Alarm alarm) throws InterruptedException, ExecutionException {
log.debug("New Alarm : {}", alarm);
Alarm saved = alarmDao.save(alarm);
@ -204,15 +209,15 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
validateId(alarmId, "Incorrect alarmId " + alarmId);
return Futures.transform(alarmDao.findAlarmByIdAsync(alarmId.getId()),
(AsyncFunction<Alarm, AlarmInfo>) alarm1 -> {
AlarmInfo alarmInfo = new AlarmInfo(alarm1);
return Futures.transform(
entityService.fetchEntityNameAsync(alarmInfo.getOriginator()), (Function<String, AlarmInfo>)
originatorName -> {
alarmInfo.setOriginatorName(originatorName);
return alarmInfo;
}
);
});
AlarmInfo alarmInfo = new AlarmInfo(alarm1);
return Futures.transform(
entityService.fetchEntityNameAsync(alarmInfo.getOriginator()), (Function<String, AlarmInfo>)
originatorName -> {
alarmInfo.setOriginatorName(originatorName);
return alarmInfo;
}
);
});
}
@Override
@ -234,7 +239,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
));
}
return Futures.successfulAsList(alarmFutures);
});
});
}
return Futures.transform(alarms, new Function<List<AlarmInfo>, TimePageData<AlarmInfo>>() {
@Nullable
@ -247,7 +252,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
@Override
public AlarmSeverity findHighestAlarmSeverity(EntityId entityId, AlarmSearchStatus alarmSearchStatus,
AlarmStatus alarmStatus) {
AlarmStatus alarmStatus) {
TimePageLink nextPageLink = new TimePageLink(100);
boolean hasNext = true;
AlarmSeverity highestSeverity = null;
@ -321,7 +326,7 @@ public class BaseAlarmService extends AbstractEntityService implements AlarmServ
List<EntityId> parentEntities = relationService.findByQuery(query).get().stream().map(r -> r.getFrom()).collect(Collectors.toList());
for (EntityId parentId : parentEntities) {
updateAlarmRelation(parentId, alarm.getId(), oldStatus, newStatus);
}
}
updateAlarmRelation(alarm.getOriginator(), alarm.getId(), oldStatus, newStatus);
} catch (ExecutionException | InterruptedException e) {
log.warn("[{}] Failed to update relations. Old status: [{}], New status: [{}]", alarm.getId(), oldStatus, newStatus);

6
dao/src/test/java/org/thingsboard/server/dao/CustomSqlUnit.java

@ -58,6 +58,8 @@ public class CustomSqlUnit extends ExternalResource {
@Override
public void before() {
cleanUpDb();
Connection conn = null;
try {
conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
@ -81,6 +83,10 @@ public class CustomSqlUnit extends ExternalResource {
@Override
public void after() {
cleanUpDb();
}
private void cleanUpDb() {
Connection conn = null;
try {
conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);

4
dao/src/test/resources/sql-test.properties

@ -1,4 +1,4 @@
database.type=sql
database.type=sql
spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=validate
@ -6,5 +6,5 @@ spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.url=jdbc:hsqldb:mem:testDb;sql.enforce_size=false
spring.datasource.url=jdbc:hsqldb:file:/tmp/testDb;sql.enforce_size=false
spring.datasource.driverClassName=org.hsqldb.jdbc.JDBCDriver

10
extensions-api/src/main/java/org/thingsboard/server/extensions/api/rules/RuleContext.java

@ -15,9 +15,12 @@
*/
package org.thingsboard.server.extensions.api.rules;
import com.google.common.util.concurrent.ListenableFuture;
import org.thingsboard.server.common.data.Event;
import org.thingsboard.server.common.data.alarm.Alarm;
import org.thingsboard.server.common.data.alarm.AlarmId;
import org.thingsboard.server.common.data.id.EntityId;
import org.thingsboard.server.common.data.id.RuleId;
import org.thingsboard.server.extensions.api.device.DeviceAttributes;
import org.thingsboard.server.extensions.api.device.DeviceMetaData;
import java.util.Optional;
@ -34,4 +37,9 @@ public interface RuleContext {
Optional<Event> findEvent(String eventType, String eventUid);
Optional<Alarm> findLatestAlarm(EntityId originator, String alarmType);
Alarm createOrUpdateAlarm(Alarm alarm);
ListenableFuture<Boolean> clearAlarm(AlarmId id, long clearTs);
}

2
extensions-api/src/main/java/org/thingsboard/server/extensions/api/rules/RuleProcessor.java

@ -18,6 +18,8 @@ package org.thingsboard.server.extensions.api.rules;
import org.thingsboard.server.common.msg.device.ToDeviceActorMsg;
import org.thingsboard.server.extensions.api.component.ConfigurableComponent;
import javax.script.ScriptException;
/**
* @author Andrew Shvayka
*/

14
extensions-core/src/main/java/org/thingsboard/server/extensions/core/filter/BasicJsFilter.java

@ -75,18 +75,4 @@ public abstract class BasicJsFilter implements RuleFilter<JsFilterConfiguration>
}
}
protected static Object getValue(KvEntry attr) {
switch (attr.getDataType()) {
case STRING:
return attr.getStrValue().get();
case LONG:
return attr.getLongValue().get();
case DOUBLE:
return attr.getDoubleValue().get();
case BOOLEAN:
return attr.getBooleanValue().get();
}
return null;
}
}

42
extensions-core/src/main/java/org/thingsboard/server/extensions/core/filter/DeviceAttributesFilter.java

@ -16,9 +16,6 @@
package org.thingsboard.server.extensions.core.filter;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
import org.thingsboard.server.common.msg.core.UpdateAttributesRequest;
import org.thingsboard.server.common.msg.device.ToDeviceActorMsg;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
@ -28,10 +25,6 @@ import org.thingsboard.server.extensions.api.rules.RuleContext;
import javax.script.Bindings;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
/**
* @author Andrew Shvayka
@ -40,25 +33,18 @@ import java.util.Map;
@Slf4j
public class DeviceAttributesFilter extends BasicJsFilter {
public static final String CLIENT_SIDE = "cs";
public static final String SERVER_SIDE = "ss";
public static final String SHARED = "shared";
@Override
protected boolean doFilter(RuleContext ctx, ToDeviceActorMsg msg) throws ScriptException {
return evaluator.execute(toBindings(ctx.getDeviceMetaData().getDeviceAttributes(), msg != null ? msg.getPayload() : null));
}
private Bindings toBindings(DeviceAttributes attributes, FromDeviceMsg msg) {
Bindings bindings = new SimpleBindings();
convertListEntries(bindings, CLIENT_SIDE, attributes.getClientSideAttributes());
convertListEntries(bindings, SERVER_SIDE, attributes.getServerSideAttributes());
convertListEntries(bindings, SHARED, attributes.getServerSidePublicAttributes());
Bindings bindings = NashornJsEvaluator.getAttributeBindings(attributes);
if (msg != null) {
switch (msg.getMsgType()) {
case POST_ATTRIBUTES_REQUEST:
updateBindings(bindings, (UpdateAttributesRequest) msg);
bindings = NashornJsEvaluator.updateBindings(bindings, (UpdateAttributesRequest) msg);
break;
}
}
@ -66,28 +52,4 @@ public class DeviceAttributesFilter extends BasicJsFilter {
return bindings;
}
private void updateBindings(Bindings bindings, UpdateAttributesRequest msg) {
Map<String, Object> attrMap = (Map<String, Object>) bindings.get(CLIENT_SIDE);
for (AttributeKvEntry attr : msg.getAttributes()) {
if (!CLIENT_SIDE.equalsIgnoreCase(attr.getKey()) && !SERVER_SIDE.equalsIgnoreCase(attr.getKey())
&& !SHARED.equalsIgnoreCase(attr.getKey())) {
bindings.put(attr.getKey(), getValue(attr));
}
attrMap.put(attr.getKey(), getValue(attr));
}
bindings.put(CLIENT_SIDE, attrMap);
}
public static Bindings convertListEntries(Bindings bindings, String attributesVarName, Collection<AttributeKvEntry> attributes) {
Map<String, Object> attrMap = new HashMap<>();
for (AttributeKvEntry attr : attributes) {
if (!CLIENT_SIDE.equalsIgnoreCase(attr.getKey()) && !SERVER_SIDE.equalsIgnoreCase(attr.getKey())
&& !SHARED.equalsIgnoreCase(attr.getKey())) {
bindings.put(attr.getKey(), getValue(attr));
}
attrMap.put(attr.getKey(), getValue(attr));
}
bindings.put(attributesVarName, attrMap);
return bindings;
}
}

12
extensions-core/src/main/java/org/thingsboard/server/extensions/core/filter/DeviceTelemetryFilter.java

@ -23,9 +23,7 @@ import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.extensions.api.component.Filter;
import org.thingsboard.server.extensions.api.rules.RuleContext;
import javax.script.Bindings;
import javax.script.ScriptException;
import javax.script.SimpleBindings;
import java.util.List;
/**
@ -41,7 +39,7 @@ public class DeviceTelemetryFilter extends BasicJsFilter {
if (deviceMsg instanceof TelemetryUploadRequest) {
TelemetryUploadRequest telemetryMsg = (TelemetryUploadRequest) deviceMsg;
for (List<KvEntry> entries : telemetryMsg.getData().values()) {
if (evaluator.execute(toBindings(entries))) {
if (evaluator.execute(NashornJsEvaluator.toBindings(entries))) {
return true;
}
}
@ -49,12 +47,4 @@ public class DeviceTelemetryFilter extends BasicJsFilter {
return false;
}
private Bindings toBindings(List<KvEntry> entries) {
Bindings bindings = new SimpleBindings();
for (KvEntry entry : entries) {
bindings.put(entry.getKey(), getValue(entry));
}
return bindings;
}
}

72
extensions-core/src/main/java/org/thingsboard/server/extensions/core/filter/NashornJsEvaluator.java

@ -17,10 +17,16 @@ package org.thingsboard.server.extensions.core.filter;
import jdk.nashorn.api.scripting.NashornScriptEngineFactory;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.thingsboard.server.common.data.kv.AttributeKvEntry;
import org.thingsboard.server.common.data.kv.KvEntry;
import org.thingsboard.server.common.msg.core.UpdateAttributesRequest;
import org.thingsboard.server.extensions.api.device.DeviceAttributes;
import javax.script.*;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Andrew Shvayka
@ -28,6 +34,9 @@ import javax.script.*;
@Slf4j
public class NashornJsEvaluator {
public static final String CLIENT_SIDE = "cs";
public static final String SERVER_SIDE = "ss";
public static final String SHARED = "shared";
private static NashornScriptEngineFactory factory = new NashornScriptEngineFactory();
private CompiledScript engine;
@ -47,6 +56,65 @@ public class NashornJsEvaluator {
}
}
public static Bindings convertListEntries(Bindings bindings, String attributesVarName, Collection<AttributeKvEntry> attributes) {
Map<String, Object> attrMap = new HashMap<>();
for (AttributeKvEntry attr : attributes) {
if (!CLIENT_SIDE.equalsIgnoreCase(attr.getKey()) && !SERVER_SIDE.equalsIgnoreCase(attr.getKey())
&& !SHARED.equalsIgnoreCase(attr.getKey())) {
bindings.put(attr.getKey(), getValue(attr));
}
attrMap.put(attr.getKey(), getValue(attr));
}
bindings.put(attributesVarName, attrMap);
return bindings;
}
public static Bindings updateBindings(Bindings bindings, UpdateAttributesRequest msg) {
Map<String, Object> attrMap = (Map<String, Object>) bindings.get(CLIENT_SIDE);
for (AttributeKvEntry attr : msg.getAttributes()) {
if (!CLIENT_SIDE.equalsIgnoreCase(attr.getKey()) && !SERVER_SIDE.equalsIgnoreCase(attr.getKey())
&& !SHARED.equalsIgnoreCase(attr.getKey())) {
bindings.put(attr.getKey(), getValue(attr));
}
attrMap.put(attr.getKey(), getValue(attr));
}
bindings.put(CLIENT_SIDE, attrMap);
return bindings;
}
protected static Object getValue(KvEntry attr) {
switch (attr.getDataType()) {
case STRING:
return attr.getStrValue().get();
case LONG:
return attr.getLongValue().get();
case DOUBLE:
return attr.getDoubleValue().get();
case BOOLEAN:
return attr.getBooleanValue().get();
}
return null;
}
public static Bindings toBindings(List<KvEntry> entries) {
return toBindings(new SimpleBindings(), entries);
}
public static Bindings toBindings(Bindings bindings, List<KvEntry> entries) {
for (KvEntry entry : entries) {
bindings.put(entry.getKey(), getValue(entry));
}
return bindings;
}
public static Bindings getAttributeBindings(DeviceAttributes attributes) {
Bindings bindings = new SimpleBindings();
convertListEntries(bindings, CLIENT_SIDE, attributes.getClientSideAttributes());
convertListEntries(bindings, SERVER_SIDE, attributes.getServerSideAttributes());
convertListEntries(bindings, SHARED, attributes.getServerSidePublicAttributes());
return bindings;
}
public Boolean execute(Bindings bindings) throws ScriptException {
Object eval = engine.eval(bindings);
if (eval instanceof Boolean) {

2
extensions-core/src/main/java/org/thingsboard/server/extensions/core/processor/AlarmDeduplicationProcessor.java

@ -32,7 +32,7 @@ import java.util.Optional;
/**
* @author Andrew Shvayka
*/
@Processor(name = "Alarm Deduplication Processor", descriptor = "AlarmDeduplicationProcessorDescriptor.json",
@Processor(name = "(Deprecated) Alarm Deduplication Processor", descriptor = "AlarmDeduplicationProcessorDescriptor.json",
configuration = AlarmDeduplicationProcessorConfiguration.class)
@Slf4j
public class AlarmDeduplicationProcessor extends SimpleRuleLifecycleComponent

213
extensions-core/src/main/java/org/thingsboard/server/extensions/core/processor/AlarmProcessor.java

@ -0,0 +1,213 @@
/**
* Copyright © 2016-2017 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.server.extensions.core.processor;
import java.util.Optional;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.runtime.parser.ParseException;
import org.thingsboard.server.common.data.alarm.Alarm;
import org.thingsboard.server.common.data.alarm.AlarmSeverity;
import org.thingsboard.server.common.data.alarm.AlarmStatus;
import org.thingsboard.server.common.data.kv.KvEntry;
import org.thingsboard.server.common.msg.core.TelemetryUploadRequest;
import org.thingsboard.server.common.msg.core.UpdateAttributesRequest;
import org.thingsboard.server.common.msg.device.ToDeviceActorMsg;
import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.extensions.api.component.Processor;
import org.thingsboard.server.extensions.api.rules.*;
import org.thingsboard.server.extensions.core.filter.NashornJsEvaluator;
import org.thingsboard.server.extensions.core.utils.VelocityUtils;
import javax.script.Bindings;
import javax.script.ScriptException;
import java.io.IOException;
import java.util.List;
/**
* @author Andrew Shvayka
*/
@Processor(name = "Alarm Processor", descriptor = "AlarmProcessorDescriptor.json",
configuration = AlarmProcessorConfiguration.class)
@Slf4j
public class AlarmProcessor implements RuleProcessor<AlarmProcessorConfiguration> {
static final String IS_NEW_ALARM = "isNewAlarm";
static final String IS_EXISTING_ALARM = "isExistingAlarm";
static final String IS_CLEARED_ALARM = "isClearedAlarm";
protected NashornJsEvaluator newAlarmEvaluator;
protected NashornJsEvaluator clearAlarmEvaluator;
private ObjectMapper mapper = new ObjectMapper();
private AlarmProcessorConfiguration configuration;
private AlarmStatus status;
private AlarmSeverity severity;
private Template alarmTypeTemplate;
private Template alarmDetailsTemplate;
@Override
public void init(AlarmProcessorConfiguration configuration) {
this.configuration = configuration;
try {
this.alarmTypeTemplate = VelocityUtils.create(configuration.getAlarmTypeTemplate(), "Alarm Type Template");
this.alarmDetailsTemplate = VelocityUtils.create(configuration.getAlarmDetailsTemplate(), "Alarm Details Template");
this.status = AlarmStatus.valueOf(configuration.getAlarmStatus());
this.severity = AlarmSeverity.valueOf(configuration.getAlarmSeverity());
initEvaluators();
} catch (Exception e) {
log.error("Failed to create templates based on provided configuration!", e);
throw new RuntimeException("Failed to create templates based on provided configuration!", e);
}
}
@Override
public void resume() {
initEvaluators();
log.debug("Resume method was called, but no impl provided!");
}
@Override
public void suspend() {
destroyEvaluators();
log.debug("Suspend method was called, but no impl provided!");
}
@Override
public void stop() {
destroyEvaluators();
log.debug("Stop method was called, but no impl provided!");
}
@Override
public RuleProcessingMetaData process(RuleContext ctx, ToDeviceActorMsg wrapper) throws RuleException {
RuleProcessingMetaData md = new RuleProcessingMetaData();
FromDeviceMsg msg = wrapper.getPayload();
Bindings bindings = buildBindings(ctx, msg);
boolean isActiveAlarm;
boolean isClearedAlarm;
try {
isActiveAlarm = newAlarmEvaluator.execute(bindings);
isClearedAlarm = clearAlarmEvaluator.execute(bindings);
} catch (ScriptException e) {
log.debug("[{}] Failed to evaluate alarm expressions!", ctx.getRuleId(), e);
throw new RuleException("Failed to evaluate alarm expressions!", e);
}
if (!isActiveAlarm && !isClearedAlarm) {
log.debug("[{}] Incoming message do not trigger alarm", ctx.getRuleId());
return md;
}
Alarm existing = null;
if (isActiveAlarm) {
Alarm alarm = buildAlarm(ctx, msg);
existing = ctx.createOrUpdateAlarm(alarm);
if (existing.getStartTs() == alarm.getStartTs()) {
log.debug("[{}][{}] New Active Alarm detected");
md.put(IS_NEW_ALARM, Boolean.TRUE);
} else {
log.debug("[{}][{}] Existing Active Alarm detected");
md.put(IS_EXISTING_ALARM, Boolean.TRUE);
}
} else if (isClearedAlarm) {
VelocityContext context = VelocityUtils.createContext(ctx.getDeviceMetaData(), msg);
String alarmType = VelocityUtils.merge(alarmTypeTemplate, context);
Optional<Alarm> alarm = ctx.findLatestAlarm(ctx.getDeviceMetaData().getDeviceId(), alarmType);
if (alarm.isPresent()) {
ctx.clearAlarm(alarm.get().getId(), System.currentTimeMillis());
log.debug("[{}][{}] Existing Active Alarm cleared");
md.put(IS_CLEARED_ALARM, Boolean.TRUE);
existing = alarm.get();
}
}
//TODO: handle cleared alarms
if (existing != null) {
md.put("alarmId", existing.getId().getId());
md.put("alarmType", existing.getType());
md.put("alarmSeverity", existing.getSeverity());
try {
md.put("alarmDetails", mapper.writeValueAsString(existing.getDetails()));
} catch (JsonProcessingException e) {
throw new RuleException("Failed to serialize alarm details", e);
}
}
return md;
}
private Alarm buildAlarm(RuleContext ctx, FromDeviceMsg msg) throws RuleException {
VelocityContext context = VelocityUtils.createContext(ctx.getDeviceMetaData(), msg);
String alarmType = VelocityUtils.merge(alarmTypeTemplate, context);
String alarmDetails = VelocityUtils.merge(alarmDetailsTemplate, context);
Alarm alarm = new Alarm();
alarm.setOriginator(ctx.getDeviceMetaData().getDeviceId());
alarm.setType(alarmType);
alarm.setStatus(status);
alarm.setSeverity(severity);
alarm.setPropagate(configuration.isAlarmPropagateFlag());
try {
alarm.setDetails(mapper.readTree(alarmDetails));
} catch (IOException e) {
log.debug("[{}] Failed to parse alarm details {} as json string after evaluation.", ctx.getRuleId(), e);
throw new RuleException("Failed to parse alarm details as json string after evaluation!", e);
}
return alarm;
}
private Bindings buildBindings(RuleContext ctx, FromDeviceMsg msg) {
Bindings bindings = NashornJsEvaluator.getAttributeBindings(ctx.getDeviceMetaData().getDeviceAttributes());
if (msg != null) {
switch (msg.getMsgType()) {
case POST_ATTRIBUTES_REQUEST:
bindings = NashornJsEvaluator.updateBindings(bindings, (UpdateAttributesRequest) msg);
break;
case POST_TELEMETRY_REQUEST:
TelemetryUploadRequest telemetryMsg = (TelemetryUploadRequest) msg;
for (List<KvEntry> entries : telemetryMsg.getData().values()) {
bindings = NashornJsEvaluator.toBindings(bindings, entries);
}
}
}
return bindings;
}
private void initEvaluators() {
newAlarmEvaluator = new NashornJsEvaluator(configuration.getNewAlarmExpression());
clearAlarmEvaluator = new NashornJsEvaluator(configuration.getClearAlarmExpression());
}
private void destroyEvaluators() {
if (newAlarmEvaluator != null) {
newAlarmEvaluator.destroy();
}
if (clearAlarmEvaluator != null) {
clearAlarmEvaluator.destroy();
}
}
}

38
extensions-core/src/main/java/org/thingsboard/server/extensions/core/processor/AlarmProcessorConfiguration.java

@ -0,0 +1,38 @@
/**
* Copyright © 2016-2017 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.server.extensions.core.processor;
import lombok.Data;
import java.util.List;
/**
* @author Andrew Shvayka
*/
@Data
public class AlarmProcessorConfiguration {
private String newAlarmExpression;
private String clearAlarmExpression;
private String alarmTypeTemplate;
private String alarmSeverity;
private String alarmStatus;
private boolean alarmPropagateFlag;
private String alarmDetailsTemplate;
}

8
extensions-core/src/main/java/org/thingsboard/server/extensions/core/utils/VelocityUtils.java

@ -29,7 +29,7 @@ import org.thingsboard.server.common.msg.session.FromDeviceMsg;
import org.thingsboard.server.extensions.api.device.DeviceAttributes;
import org.thingsboard.server.extensions.api.device.DeviceMetaData;
import org.thingsboard.server.extensions.api.rules.RuleProcessingMetaData;
import org.thingsboard.server.extensions.core.filter.DeviceAttributesFilter;
import org.thingsboard.server.extensions.core.filter.NashornJsEvaluator;
import java.io.StringReader;
import java.io.StringWriter;
@ -70,9 +70,9 @@ public class VelocityUtils {
context.put("date", new DateTool());
DeviceAttributes deviceAttributes = deviceMetaData.getDeviceAttributes();
pushAttributes(context, deviceAttributes.getClientSideAttributes(), DeviceAttributesFilter.CLIENT_SIDE);
pushAttributes(context, deviceAttributes.getServerSideAttributes(), DeviceAttributesFilter.SERVER_SIDE);
pushAttributes(context, deviceAttributes.getServerSidePublicAttributes(), DeviceAttributesFilter.SHARED);
pushAttributes(context, deviceAttributes.getClientSideAttributes(), NashornJsEvaluator.CLIENT_SIDE);
pushAttributes(context, deviceAttributes.getServerSideAttributes(), NashornJsEvaluator.SERVER_SIDE);
pushAttributes(context, deviceAttributes.getServerSidePublicAttributes(), NashornJsEvaluator.SHARED);
switch (payload.getMsgType()) {
case POST_TELEMETRY_REQUEST:

113
extensions-core/src/main/resources/AlarmProcessorDescriptor.json

@ -0,0 +1,113 @@
{
"schema": {
"title": "Alarm Configuration",
"type": "object",
"properties": {
"newAlarmExpression": {
"title": "Alarm trigger expression",
"type": "string",
"default": ""
},
"clearAlarmExpression": {
"title": "Alarm clear expression",
"type": "string",
"default": ""
},
"alarmTypeTemplate": {
"title": "Alarm type",
"type": "string"
},
"alarmSeverity": {
"title": "Severity",
"type": "string"
},
"alarmStatus": {
"title": "Status",
"type": "string"
},
"alarmPropagateFlag": {
"title": "Propagate Alarm",
"type": "boolean"
},
"alarmDetailsTemplate": {
"title": "Alarm details",
"type": "string"
}
},
"required": [
"newAlarmExpression",
"clearAlarmExpression",
"alarmSeverity",
"alarmStatus",
"alarmTypeTemplate",
"alarmDetailsTemplate"
]
},
"form": [
{
"key": "newAlarmExpression",
"type": "javascript"
},
{
"key": "clearAlarmExpression",
"type": "javascript"
},
{
"key": "alarmSeverity",
"type": "rc-select",
"multiple": false,
"items": [
{
"value": "CRITICAL",
"label": "Critical"
},
{
"value": "MAJOR",
"label": "Major"
},
{
"value": "MINOR",
"label": "Minor"
},
{
"value": "WARNING",
"label": "Warning"
},
{
"value": "INDETERMINATE",
"label": "Indeterminate"
}
]
},
{
"key": "alarmStatus",
"type": "rc-select",
"multiple": false,
"items": [
{
"value": "ACTIVE_UNACK",
"label": "Active Unacknowledged"
},
{
"value": "ACTIVE_ACK",
"label": "Active Acknowledged"
},
{
"value": "CLEARED_UNACK",
"label": "Cleared Unacknowledged"
},
{
"value": "CLEARED_ACK",
"label": "Cleared Acknowledged"
}
]
},
"alarmTypeTemplate",
"alarmPropagateFlag",
{
"key": "alarmDetailsTemplate",
"type": "textarea",
"rows": 5
}
]
}
Loading…
Cancel
Save