diff --git a/application/src/main/data/upgrade/1.5.0/schema_update.cql b/application/src/main/data/upgrade/1.5.0/schema_update.cql index 9481fc0501..0a3f42bd21 100644 --- a/application/src/main/data/upgrade/1.5.0/schema_update.cql +++ b/application/src/main/data/upgrade/1.5.0/schema_update.cql @@ -94,5 +94,3 @@ CREATE TABLE IF NOT EXISTS thingsboard.rule_node ( PRIMARY KEY (id) ); -ALTER TABLE thingsboard.device ADD last_connect bigint; -ALTER TABLE thingsboard.device ADD last_update bigint; \ No newline at end of file diff --git a/application/src/main/data/upgrade/1.5.0/schema_update.sql b/application/src/main/data/upgrade/1.5.0/schema_update.sql index ef5f6db682..c3c5ade4d7 100644 --- a/application/src/main/data/upgrade/1.5.0/schema_update.sql +++ b/application/src/main/data/upgrade/1.5.0/schema_update.sql @@ -35,7 +35,4 @@ CREATE TABLE IF NOT EXISTS rule_node ( name varchar(255), debug_mode boolean, search_text varchar(255) -); - -ALTER TABLE device ADD COLUMN IF NOT EXISTS last_connect BIGINT; -ALTER TABLE device ADD COLUMN IF NOT EXISTS last_update BIGINT; \ No newline at end of file +); \ No newline at end of file diff --git a/application/src/main/java/org/thingsboard/server/controller/BaseController.java b/application/src/main/java/org/thingsboard/server/controller/BaseController.java index a35e5dcc3c..f24c77a376 100644 --- a/application/src/main/java/org/thingsboard/server/controller/BaseController.java +++ b/application/src/main/java/org/thingsboard/server/controller/BaseController.java @@ -45,7 +45,6 @@ import org.thingsboard.server.dao.audit.AuditLogService; 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.DeviceOfflineService; import org.thingsboard.server.dao.device.DeviceService; import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.IncorrectParameterException; @@ -135,9 +134,6 @@ public abstract class BaseController { @Autowired protected AuditLogService auditLogService; - @Autowired - protected DeviceOfflineService offlineService; - @Autowired protected DeviceStateService deviceStateService; diff --git a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java index 5322b2c017..e1023caebf 100644 --- a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java +++ b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java @@ -25,9 +25,6 @@ import org.thingsboard.server.common.data.EntitySubtype; import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.audit.ActionType; import org.thingsboard.server.common.data.device.DeviceSearchQuery; -import org.thingsboard.server.common.data.device.DeviceStatusQuery; -import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; -import org.thingsboard.server.common.data.exception.ThingsboardException; import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.common.data.id.TenantId; @@ -37,6 +34,8 @@ import org.thingsboard.server.common.data.security.Authority; import org.thingsboard.server.common.data.security.DeviceCredentials; import org.thingsboard.server.dao.exception.IncorrectParameterException; import org.thingsboard.server.dao.model.ModelConstants; +import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; +import org.thingsboard.server.common.data.exception.ThingsboardException; import org.thingsboard.server.service.security.model.SecurityUser; import java.util.ArrayList; @@ -70,7 +69,7 @@ public class DeviceController extends BaseController { device.setTenantId(getCurrentUser().getTenantId()); if (getCurrentUser().getAuthority() == Authority.CUSTOMER_USER) { if (device.getId() == null || device.getId().isNullUid() || - device.getCustomerId() == null || device.getCustomerId().isNullUid()) { + device.getCustomerId() == null || device.getCustomerId().isNullUid()) { throw new ThingsboardException("You don't have permission to perform this operation!", ThingsboardErrorCode.PERMISSION_DENIED); } else { @@ -374,32 +373,4 @@ public class DeviceController extends BaseController { throw handleException(e); } } - - @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/device/offline", method = RequestMethod.GET) - @ResponseBody - public List getOfflineDevices(@RequestParam("contactType") DeviceStatusQuery.ContactType contactType, - @RequestParam("threshold") long threshold) throws ThingsboardException { - try { - TenantId tenantId = getCurrentUser().getTenantId(); - ListenableFuture> offlineDevices = offlineService.findOfflineDevices(tenantId.getId(), contactType, threshold); - return checkNotNull(offlineDevices.get()); - } catch (Exception e) { - throw handleException(e); - } - } - - @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") - @RequestMapping(value = "/device/online", method = RequestMethod.GET) - @ResponseBody - public List getOnlineDevices(@RequestParam("contactType") DeviceStatusQuery.ContactType contactType, - @RequestParam("threshold") long threshold) throws ThingsboardException { - try { - TenantId tenantId = getCurrentUser().getTenantId(); - ListenableFuture> offlineDevices = offlineService.findOnlineDevices(tenantId.getId(), contactType, threshold); - return checkNotNull(offlineDevices.get()); - } catch (Exception e) { - throw handleException(e); - } - } } diff --git a/application/src/main/java/org/thingsboard/server/service/component/AnnotationComponentDiscoveryService.java b/application/src/main/java/org/thingsboard/server/service/component/AnnotationComponentDiscoveryService.java index 9377756b86..ee4ec2424d 100644 --- a/application/src/main/java/org/thingsboard/server/service/component/AnnotationComponentDiscoveryService.java +++ b/application/src/main/java/org/thingsboard/server/service/component/AnnotationComponentDiscoveryService.java @@ -118,6 +118,7 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe case FILTER: case TRANSFORMATION: case ACTION: + case EXTERNAL: RuleNode ruleNodeAnnotation = clazz.getAnnotation(RuleNode.class); scannedComponent.setName(ruleNodeAnnotation.name()); scannedComponent.setScope(ruleNodeAnnotation.scope()); @@ -194,6 +195,8 @@ public class AnnotationComponentDiscoveryService implements ComponentDiscoverySe nodeDefinition.setDefaultConfiguration(mapper.valueToTree(defaultConfiguration)); nodeDefinition.setUiResources(nodeAnnotation.uiResources()); nodeDefinition.setConfigDirective(nodeAnnotation.configDirective()); + nodeDefinition.setIcon(nodeAnnotation.icon()); + nodeDefinition.setIconUrl(nodeAnnotation.iconUrl()); return nodeDefinition; } diff --git a/application/src/main/java/org/thingsboard/server/service/state/DefaultDeviceStateService.java b/application/src/main/java/org/thingsboard/server/service/state/DefaultDeviceStateService.java index 7d5586d873..45b969669c 100644 --- a/application/src/main/java/org/thingsboard/server/service/state/DefaultDeviceStateService.java +++ b/application/src/main/java/org/thingsboard/server/service/state/DefaultDeviceStateService.java @@ -262,7 +262,7 @@ public class DefaultDeviceStateService implements DeviceStateService { state.setInactivityTimeout(inactivityTimeout); boolean oldActive = state.isActive(); state.setActive(ts < state.getLastActivityTime() + state.getInactivityTimeout()); - if (!oldActive && state.isActive()) { + if (!oldActive && state.isActive() || oldActive && !state.isActive()) { saveAttribute(deviceId, ACTIVITY_STATE, state.isActive()); } } @@ -333,10 +333,6 @@ public class DefaultDeviceStateService implements DeviceStateService { }); } - private long getLastPersistTime(List attributes) { - return attributes.stream().map(AttributeKvEntry::getLastUpdateTs).max(Long::compare).orElse(0L); - } - private long getAttributeValue(List attributes, String attributeName, long defaultValue) { for (AttributeKvEntry attribute : attributes) { if (attribute.getKey().equals(attributeName)) { diff --git a/application/src/test/java/org/thingsboard/server/system/BaseDeviceOfflineTest.java b/application/src/test/java/org/thingsboard/server/system/BaseDeviceOfflineTest.java deleted file mode 100644 index 5a09a68b43..0000000000 --- a/application/src/test/java/org/thingsboard/server/system/BaseDeviceOfflineTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/** - * Copyright © 2016-2018 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.system; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.google.common.collect.ImmutableMap; -import org.junit.Before; -import org.junit.Test; -import org.thingsboard.server.common.data.Device; -import org.thingsboard.server.common.data.security.DeviceCredentials; -import org.thingsboard.server.controller.AbstractControllerTest; - -import java.util.List; -import java.util.UUID; -import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertEquals; - -public class BaseDeviceOfflineTest extends AbstractControllerTest { - - private Device deviceA; - private Device deviceB; - private DeviceCredentials credA; - private DeviceCredentials credB; - - @Before - public void before() throws Exception { - loginTenantAdmin(); - deviceA = createDevice("DevA", "VMS"); - credA = getCredentials(deviceA.getUuidId()); - deviceB = createDevice("DevB", "SOLAR"); - credB = getCredentials(deviceB.getUuidId()); - } - - @Test - public void offlineDevicesCanBeFoundByLastConnectField() throws Exception { - makeDeviceContact(credA); - Thread.sleep(1000); - makeDeviceContact(credB); - Thread.sleep(100); - List devices = doGetTyped("/api/device/offline?contactType=CONNECT&threshold=700", new TypeReference>() { - }); - - assertEquals(devices.toString(),1, devices.size()); - assertEquals("DevA", devices.get(0).getName()); - } - - @Test - public void offlineDevicesCanBeFoundByLastUpdateField() throws Exception { - makeDeviceUpdate(credA); - Thread.sleep(1000); - makeDeviceUpdate(credB); - makeDeviceContact(credA); - Thread.sleep(100); - List devices = doGetTyped("/api/device/offline?contactType=UPLOAD&threshold=700", new TypeReference>() { - }); - - assertEquals(devices.toString(),1, devices.size()); - assertEquals("DevA", devices.get(0).getName()); - } - - @Test - public void onlineDevicesCanBeFoundByLastConnectField() throws Exception { - makeDeviceContact(credB); - Thread.sleep(1000); - makeDeviceContact(credA); - Thread.sleep(100); - List devices = doGetTyped("/api/device/online?contactType=CONNECT&threshold=700", new TypeReference>() { - }); - - assertEquals(devices.toString(),1, devices.size()); - assertEquals("DevA", devices.get(0).getName()); - } - - @Test - public void onlineDevicesCanBeFoundByLastUpdateField() throws Exception { - makeDeviceUpdate(credB); - Thread.sleep(1000); - makeDeviceUpdate(credA); - makeDeviceContact(credB); - Thread.sleep(100); - List devices = doGetTyped("/api/device/online?contactType=UPLOAD&threshold=700", new TypeReference>() { - }); - - assertEquals(devices.toString(),1, devices.size()); - assertEquals("DevA", devices.get(0).getName()); - } - - private Device createDevice(String name, String type) throws Exception { - Device device = new Device(); - device.setName(name); - device.setType(type); - long currentTime = System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(10); - device.setLastConnectTs(currentTime); - device.setLastUpdateTs(currentTime); - return doPost("/api/device", device, Device.class); - } - - private DeviceCredentials getCredentials(UUID deviceId) throws Exception { - return doGet("/api/device/" + deviceId.toString() + "/credentials", DeviceCredentials.class); - } - - private void makeDeviceUpdate(DeviceCredentials credentials) throws Exception { - doPost("/api/v1/" + credentials.getCredentialsId() + "/attributes", ImmutableMap.of("keyA", "valueA"), new String[]{}); - } - - private void makeDeviceContact(DeviceCredentials credentials) throws Exception { - doGet("/api/v1/" + credentials.getCredentialsId() + "/attributes?clientKeys=keyA,keyB,keyC"); - } -} diff --git a/application/src/test/java/org/thingsboard/server/system/BaseHttpDeviceApiTest.java b/application/src/test/java/org/thingsboard/server/system/BaseHttpDeviceApiTest.java index c3e87c27ff..4fa61621bc 100644 --- a/application/src/test/java/org/thingsboard/server/system/BaseHttpDeviceApiTest.java +++ b/application/src/test/java/org/thingsboard/server/system/BaseHttpDeviceApiTest.java @@ -15,7 +15,6 @@ */ package org.thingsboard.server.system; -import com.google.common.collect.ImmutableMap; import org.junit.Before; import org.junit.Test; import org.springframework.test.web.servlet.ResultActions; @@ -29,9 +28,6 @@ import java.util.Map; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -52,9 +48,6 @@ public abstract class BaseHttpDeviceApiTest extends AbstractControllerTest { device = new Device(); device.setName("My device"); device.setType("default"); - long currentTime = System.currentTimeMillis(); - device.setLastConnectTs(currentTime); - device.setLastUpdateTs(currentTime); device = doPost("/api/device", device, Device.class); deviceCredentials = @@ -74,34 +67,6 @@ public abstract class BaseHttpDeviceApiTest extends AbstractControllerTest { doGetAsync("/api/v1/" + deviceCredentials.getCredentialsId() + "/attributes?clientKeys=keyA,keyB,keyC").andExpect(status().isOk()); } - @Test - public void deviceLastContactAndUpdateFieldsAreUpdated() throws Exception { - Device actualDevice = doGet("/api/device/" + this.device.getId(), Device.class); - Long initConnectTs = actualDevice.getLastConnectTs(); - Long initUpdateTs = actualDevice.getLastUpdateTs(); - assertNotNull(initConnectTs); - assertNotNull(initUpdateTs); - Thread.sleep(50); - - doPost("/api/v1/" + deviceCredentials.getCredentialsId() + "/attributes", ImmutableMap.of("keyA", "valueA"), new String[]{}); - actualDevice = doGet("/api/device/" + this.device.getId(), Device.class); - Long postConnectTs = actualDevice.getLastConnectTs(); - Long postUpdateTs = actualDevice.getLastUpdateTs(); - System.out.println(postConnectTs + " - " + postUpdateTs + " -> " + (postConnectTs - initConnectTs) + " : " + (postUpdateTs - initUpdateTs)); - assertTrue(postConnectTs > initConnectTs); - assertEquals(postConnectTs, postUpdateTs); - Thread.sleep(50); - - doGet("/api/v1/" + deviceCredentials.getCredentialsId() + "/attributes?clientKeys=keyA,keyB,keyC"); - Thread.sleep(50); - actualDevice = doGet("/api/device/" + this.device.getId(), Device.class); - Long getConnectTs = actualDevice.getLastConnectTs(); - Long getUpdateTs = actualDevice.getLastUpdateTs(); - assertTrue(getConnectTs > postConnectTs); - assertEquals(getUpdateTs, postUpdateTs); - - } - protected ResultActions doGetAsync(String urlTemplate, Object... urlVariables) throws Exception { MockHttpServletRequestBuilder getRequest; getRequest = get(urlTemplate, urlVariables); diff --git a/application/src/test/java/org/thingsboard/server/system/nosql/DeviceOfflineNoSqlTest.java b/application/src/test/java/org/thingsboard/server/system/nosql/DeviceOfflineNoSqlTest.java deleted file mode 100644 index f25ec279a4..0000000000 --- a/application/src/test/java/org/thingsboard/server/system/nosql/DeviceOfflineNoSqlTest.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright © 2016-2018 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.system.nosql; - -import org.thingsboard.server.dao.service.DaoNoSqlTest; -import org.thingsboard.server.system.BaseDeviceOfflineTest; - -@DaoNoSqlTest -public class DeviceOfflineNoSqlTest extends BaseDeviceOfflineTest { -} diff --git a/application/src/test/java/org/thingsboard/server/system/sql/DeviceOfflineSqlTest.java b/application/src/test/java/org/thingsboard/server/system/sql/DeviceOfflineSqlTest.java deleted file mode 100644 index a9617bcdb4..0000000000 --- a/application/src/test/java/org/thingsboard/server/system/sql/DeviceOfflineSqlTest.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright © 2016-2018 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.system.sql; - -import org.thingsboard.server.dao.service.DaoSqlTest; -import org.thingsboard.server.system.BaseDeviceOfflineTest; - -@DaoSqlTest -public class DeviceOfflineSqlTest extends BaseDeviceOfflineTest { -} diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/Device.java b/common/data/src/main/java/org/thingsboard/server/common/data/Device.java index 6d257fc905..95662c1292 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/Device.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/Device.java @@ -31,8 +31,6 @@ public class Device extends SearchTextBasedWithAdditionalInfo implemen private CustomerId customerId; private String name; private String type; - private Long lastConnectTs; - private Long lastUpdateTs; public Device() { super(); @@ -83,22 +81,6 @@ public class Device extends SearchTextBasedWithAdditionalInfo implemen this.type = type; } - public Long getLastConnectTs() { - return lastConnectTs; - } - - public void setLastConnectTs(Long lastConnectTs) { - this.lastConnectTs = lastConnectTs; - } - - public Long getLastUpdateTs() { - return lastUpdateTs; - } - - public void setLastUpdateTs(Long lastUpdateTs) { - this.lastUpdateTs = lastUpdateTs; - } - @Override public String getSearchText() { return getName(); @@ -119,10 +101,6 @@ public class Device extends SearchTextBasedWithAdditionalInfo implemen builder.append(getAdditionalInfo()); builder.append(", createdTime="); builder.append(createdTime); - builder.append(", lastUpdateTs="); - builder.append(lastUpdateTs); - builder.append(", lastConnectTs="); - builder.append(lastConnectTs); builder.append(", id="); builder.append(id); builder.append("]"); diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/device/DeviceStatusQuery.java b/common/data/src/main/java/org/thingsboard/server/common/data/device/DeviceStatusQuery.java deleted file mode 100644 index 0d0dad1117..0000000000 --- a/common/data/src/main/java/org/thingsboard/server/common/data/device/DeviceStatusQuery.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright © 2016-2018 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.common.data.device; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.ToString; - -@Data -@AllArgsConstructor -@ToString -public class DeviceStatusQuery { - - private Status status; - private ContactType contactType; - private long threshold; - - - public enum Status { - ONLINE, OFFLINE - } - - public enum ContactType { - CONNECT, UPLOAD - } - -} diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/plugin/ComponentType.java b/common/data/src/main/java/org/thingsboard/server/common/data/plugin/ComponentType.java index a1030640cb..e6958e64f8 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/plugin/ComponentType.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/plugin/ComponentType.java @@ -20,6 +20,6 @@ package org.thingsboard.server.common.data.plugin; */ public enum ComponentType { - ENRICHMENT, FILTER, TRANSFORMATION, ACTION, OLD_ACTION, PLUGIN + ENRICHMENT, FILTER, TRANSFORMATION, ACTION, EXTERNAL, OLD_ACTION, PLUGIN } diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/CassandraDeviceDao.java b/dao/src/main/java/org/thingsboard/server/dao/device/CassandraDeviceDao.java index 0246da54ec..641c464cec 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/device/CassandraDeviceDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/device/CassandraDeviceDao.java @@ -15,9 +15,9 @@ */ package org.thingsboard.server.dao.device; -import com.datastax.driver.core.*; -import com.datastax.driver.core.querybuilder.Clause; -import com.datastax.driver.core.querybuilder.QueryBuilder; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.ResultSetFuture; +import com.datastax.driver.core.Statement; import com.datastax.driver.core.querybuilder.Select; import com.datastax.driver.mapping.Result; import com.google.common.base.Function; @@ -28,11 +28,9 @@ import org.springframework.stereotype.Component; import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.EntitySubtype; import org.thingsboard.server.common.data.EntityType; -import org.thingsboard.server.common.data.device.DeviceStatusQuery; import org.thingsboard.server.common.data.page.TextPageLink; import org.thingsboard.server.dao.DaoUtil; import org.thingsboard.server.dao.model.EntitySubtypeEntity; -import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.nosql.DeviceEntity; import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; import org.thingsboard.server.dao.util.NoSqlDao; @@ -159,7 +157,7 @@ public class CassandraDeviceDao extends CassandraAbstractSearchTextDao entitySubtypes = new ArrayList<>(); result.all().forEach((entitySubtypeEntity) -> - entitySubtypes.add(entitySubtypeEntity.toEntitySubtype()) + entitySubtypes.add(entitySubtypeEntity.toEntitySubtype()) ); return entitySubtypes; } else { @@ -169,68 +167,4 @@ public class CassandraDeviceDao extends CassandraAbstractSearchTextDao> findDevicesByTenantIdAndStatus(UUID tenantId, DeviceStatusQuery statusQuery) { - log.debug("Try to find [{}] devices by tenantId [{}]", statusQuery.getStatus(), tenantId); - - Select select = select().from(DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME).allowFiltering(); - Select.Where query = select.where(); - query.and(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)); - Clause clause = statusClause(statusQuery); - query.and(clause); - return findListByStatementAsync(query); - } - - @Override - public ListenableFuture> findDevicesByTenantIdTypeAndStatus(UUID tenantId, String type, DeviceStatusQuery statusQuery) { - log.debug("Try to find [{}] devices by tenantId [{}] and type [{}]", statusQuery.getStatus(), tenantId, type); - - Select select = select().from(DEVICE_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME).allowFiltering(); - Select.Where query = select.where() - .and(eq(DEVICE_TENANT_ID_PROPERTY, tenantId)) - .and(eq(DEVICE_TYPE_PROPERTY, type)); - - query.and(statusClause(statusQuery)); - return findListByStatementAsync(query); - } - - - @Override - public void saveDeviceStatus(Device device) { - PreparedStatement statement = prepare("insert into " + - "device (id, tenant_id, customer_id, type, last_connect, last_update) values (?, ?, ?, ?, ?, ?)"); - BoundStatement boundStatement = statement.bind(device.getUuidId(), device.getTenantId().getId(), device.getCustomerId().getId(), - device.getType(), device.getLastConnectTs(), device.getLastUpdateTs()); - ResultSetFuture resultSetFuture = executeAsyncWrite(boundStatement); - Futures.withFallback(resultSetFuture, t -> { - log.error("Can't update device status for [{}]", device, t); - throw new IllegalArgumentException("Can't update device status for {" + device + "}", t); - }); - } - - private String getStatusProperty(DeviceStatusQuery statusQuery) { - switch (statusQuery.getContactType()) { - case UPLOAD: - return DEVICE_LAST_UPDATE_PROPERTY; - case CONNECT: - return DEVICE_LAST_CONNECT_PROPERTY; - } - return null; - } - - private Clause statusClause(DeviceStatusQuery statusQuery) { - long minTime = System.currentTimeMillis() - statusQuery.getThreshold(); - String statusProperty = getStatusProperty(statusQuery); - if (statusProperty != null) { - switch (statusQuery.getStatus()) { - case ONLINE: - return gt(statusProperty, minTime); - case OFFLINE: - return lt(statusProperty, minTime); - } - } - log.error("Could not build status query from [{}]", statusQuery); - throw new IllegalStateException("Could not build status query for device []"); - } - } diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java index 2b9e5224e0..dbc098e575 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java @@ -18,7 +18,6 @@ package org.thingsboard.server.dao.device; import com.google.common.util.concurrent.ListenableFuture; import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.EntitySubtype; -import org.thingsboard.server.common.data.device.DeviceStatusQuery; import org.thingsboard.server.common.data.page.TextPageLink; import org.thingsboard.server.dao.Dao; @@ -28,6 +27,7 @@ import java.util.UUID; /** * The Interface DeviceDao. + * */ public interface DeviceDao extends Dao { @@ -52,7 +52,7 @@ public interface DeviceDao extends Dao { * Find devices by tenantId, type and page link. * * @param tenantId the tenantId - * @param type the type + * @param type the type * @param pageLink the page link * @return the list of device objects */ @@ -61,7 +61,7 @@ public interface DeviceDao extends Dao { /** * Find devices by tenantId and devices Ids. * - * @param tenantId the tenantId + * @param tenantId the tenantId * @param deviceIds the device Ids * @return the list of device objects */ @@ -70,9 +70,9 @@ public interface DeviceDao extends Dao { /** * Find devices by tenantId, customerId and page link. * - * @param tenantId the tenantId + * @param tenantId the tenantId * @param customerId the customerId - * @param pageLink the page link + * @param pageLink the page link * @return the list of device objects */ List findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink); @@ -80,10 +80,10 @@ public interface DeviceDao extends Dao { /** * Find devices by tenantId, customerId, type and page link. * - * @param tenantId the tenantId + * @param tenantId the tenantId * @param customerId the customerId - * @param type the type - * @param pageLink the page link + * @param type the type + * @param pageLink the page link * @return the list of device objects */ List findDevicesByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, TextPageLink pageLink); @@ -92,9 +92,9 @@ public interface DeviceDao extends Dao { /** * Find devices by tenantId, customerId and devices Ids. * - * @param tenantId the tenantId + * @param tenantId the tenantId * @param customerId the customerId - * @param deviceIds the device Ids + * @param deviceIds the device Ids * @return the list of device objects */ ListenableFuture> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List deviceIds); @@ -103,7 +103,7 @@ public interface DeviceDao extends Dao { * Find devices by tenantId and device name. * * @param tenantId the tenantId - * @param name the device name + * @param name the device name * @return the optional device object */ Optional findDeviceByTenantIdAndName(UUID tenantId, String name); @@ -114,31 +114,4 @@ public interface DeviceDao extends Dao { * @return the list of tenant device type objects */ ListenableFuture> findTenantDeviceTypesAsync(UUID tenantId); - - /** - * Find devices by tenantId, statusQuery and page link. - * - * @param tenantId the tenantId - * @param statusQuery the page link - * @return the list of device objects - */ - ListenableFuture> findDevicesByTenantIdAndStatus(UUID tenantId, DeviceStatusQuery statusQuery); - - /** - * Find devices by tenantId, type, statusQuery and page link. - * - * @param tenantId the tenantId - * @param type the type - * @param statusQuery the page link - * @return the list of device objects - */ - ListenableFuture> findDevicesByTenantIdTypeAndStatus(UUID tenantId, String type, DeviceStatusQuery statusQuery); - - - /** - * Update device last contact and update timestamp async - * - * @param device the device object - */ - void saveDeviceStatus(Device device); } diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceOfflineService.java b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceOfflineService.java deleted file mode 100644 index 3bf3662eab..0000000000 --- a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceOfflineService.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright © 2016-2018 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.dao.device; - -import com.google.common.util.concurrent.ListenableFuture; -import org.thingsboard.server.common.data.Device; -import org.thingsboard.server.common.data.device.DeviceStatusQuery; - -import java.util.List; -import java.util.UUID; - -public interface DeviceOfflineService { - - void online(Device device, boolean isUpdate); - - void offline(Device device); - - ListenableFuture> findOfflineDevices(UUID tenantId, DeviceStatusQuery.ContactType contactType, long offlineThreshold); - - ListenableFuture> findOnlineDevices(UUID tenantId, DeviceStatusQuery.ContactType contactType, long offlineThreshold); -} diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceOfflineServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceOfflineServiceImpl.java deleted file mode 100644 index f4d8e61d98..0000000000 --- a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceOfflineServiceImpl.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright © 2016-2018 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.dao.device; - -import com.google.common.util.concurrent.ListenableFuture; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.thingsboard.server.common.data.Device; -import org.thingsboard.server.common.data.device.DeviceStatusQuery; - -import java.util.List; -import java.util.UUID; - -import static org.thingsboard.server.common.data.device.DeviceStatusQuery.Status.OFFLINE; -import static org.thingsboard.server.common.data.device.DeviceStatusQuery.Status.ONLINE; - -@Service -public class DeviceOfflineServiceImpl implements DeviceOfflineService { - - @Autowired - private DeviceDao deviceDao; - - @Override - public void online(Device device, boolean isUpdate) { - long current = System.currentTimeMillis(); - device.setLastConnectTs(current); - if(isUpdate) { - device.setLastUpdateTs(current); - } - deviceDao.saveDeviceStatus(device); - } - - @Override - public void offline(Device device) { - online(device, false); - } - - @Override - public ListenableFuture> findOfflineDevices(UUID tenantId, DeviceStatusQuery.ContactType contactType, long offlineThreshold) { - DeviceStatusQuery statusQuery = new DeviceStatusQuery(OFFLINE, contactType, offlineThreshold); - return deviceDao.findDevicesByTenantIdAndStatus(tenantId, statusQuery); - } - - @Override - public ListenableFuture> findOnlineDevices(UUID tenantId, DeviceStatusQuery.ContactType contactType, long offlineThreshold) { - DeviceStatusQuery statusQuery = new DeviceStatusQuery(ONLINE, contactType, offlineThreshold); - return deviceDao.findDevicesByTenantIdAndStatus(tenantId, statusQuery); - } -} diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java b/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java index 37b9158213..aff6381b05 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java +++ b/dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java @@ -133,8 +133,6 @@ public class ModelConstants { public static final String DEVICE_NAME_PROPERTY = "name"; public static final String DEVICE_TYPE_PROPERTY = "type"; public static final String DEVICE_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY; - public static final String DEVICE_LAST_CONNECT_PROPERTY = "last_connect"; - public static final String DEVICE_LAST_UPDATE_PROPERTY = "last_update"; public static final String DEVICE_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "device_by_tenant_and_search_text"; public static final String DEVICE_BY_TENANT_BY_TYPE_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "device_by_tenant_by_type_and_search_text"; diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/nosql/DeviceEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/nosql/DeviceEntity.java index 7458e56a2e..ef0c5fe159 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/model/nosql/DeviceEntity.java +++ b/dao/src/main/java/org/thingsboard/server/dao/model/nosql/DeviceEntity.java @@ -63,12 +63,6 @@ public final class DeviceEntity implements SearchTextEntity { @Column(name = DEVICE_ADDITIONAL_INFO_PROPERTY, codec = JsonCodec.class) private JsonNode additionalInfo; - @Column(name = DEVICE_LAST_CONNECT_PROPERTY) - private Long lastConnectTs; - - @Column(name = DEVICE_LAST_UPDATE_PROPERTY) - private Long lastUpdateTs; - public DeviceEntity() { super(); } @@ -86,8 +80,6 @@ public final class DeviceEntity implements SearchTextEntity { this.name = device.getName(); this.type = device.getType(); this.additionalInfo = device.getAdditionalInfo(); - this.lastConnectTs = device.getLastConnectTs(); - this.lastUpdateTs = device.getLastUpdateTs(); } public UUID getId() { @@ -137,23 +129,7 @@ public final class DeviceEntity implements SearchTextEntity { public void setAdditionalInfo(JsonNode additionalInfo) { this.additionalInfo = additionalInfo; } - - public Long getLastConnectTs() { - return lastConnectTs; - } - - public void setLastConnectTs(Long lastConnectTs) { - this.lastConnectTs = lastConnectTs; - } - - public Long getLastUpdateTs() { - return lastUpdateTs; - } - - public void setLastUpdateTs(Long lastUpdateTs) { - this.lastUpdateTs = lastUpdateTs; - } - + @Override public String getSearchTextSource() { return getName(); @@ -181,8 +157,6 @@ public final class DeviceEntity implements SearchTextEntity { device.setName(name); device.setType(type); device.setAdditionalInfo(additionalInfo); - device.setLastConnectTs(lastConnectTs); - device.setLastUpdateTs(lastUpdateTs); return device; } diff --git a/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceEntity.java b/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceEntity.java index e831c6e5ff..7aaf0ae155 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceEntity.java +++ b/dao/src/main/java/org/thingsboard/server/dao/model/sql/DeviceEntity.java @@ -34,9 +34,6 @@ import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_LAST_CONNECT_PROPERTY; -import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_LAST_UPDATE_PROPERTY; - @Data @EqualsAndHashCode(callSuper = true) @Entity @@ -63,12 +60,6 @@ public final class DeviceEntity extends BaseSqlEntity implements SearchT @Column(name = ModelConstants.DEVICE_ADDITIONAL_INFO_PROPERTY) private JsonNode additionalInfo; - @Column(name = DEVICE_LAST_CONNECT_PROPERTY) - private Long lastConnectTs; - - @Column(name = DEVICE_LAST_UPDATE_PROPERTY) - private Long lastUpdateTs; - public DeviceEntity() { super(); } @@ -86,8 +77,6 @@ public final class DeviceEntity extends BaseSqlEntity implements SearchT this.name = device.getName(); this.type = device.getType(); this.additionalInfo = device.getAdditionalInfo(); - this.lastConnectTs = device.getLastConnectTs(); - this.lastUpdateTs = device.getLastUpdateTs(); } @Override @@ -113,8 +102,6 @@ public final class DeviceEntity extends BaseSqlEntity implements SearchT device.setName(name); device.setType(type); device.setAdditionalInfo(additionalInfo); - device.setLastConnectTs(lastConnectTs); - device.setLastUpdateTs(lastUpdateTs); return device; } } \ No newline at end of file diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java b/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java index a48805b8be..3bab1c522e 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java @@ -79,28 +79,4 @@ public interface DeviceRepository extends CrudRepository { List findDevicesByTenantIdAndCustomerIdAndIdIn(String tenantId, String customerId, List deviceIds); List findDevicesByTenantIdAndIdIn(String tenantId, List deviceIds); - - @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId AND d.lastConnectTs > :time") - List findConnectOnlineByTenantId(@Param("tenantId") String tenantId, @Param("time") long time); - - @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId AND d.lastConnectTs < :time") - List findConnectOfflineByTenantId(@Param("tenantId") String tenantId, @Param("time") long time); - - @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId AND d.lastUpdateTs > :time") - List findUpdateOnlineByTenantId(@Param("tenantId") String tenantId, @Param("time") long time); - - @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId AND d.lastUpdateTs < :time") - List findUpdateOfflineByTenantId(@Param("tenantId") String tenantId, @Param("time") long time); - - @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId AND d.lastConnectTs > :time AND d.type = :type") - List findConnectOnlineByTenantIdAndType(@Param("tenantId") String tenantId, @Param("time") long time, @Param("type") String type); - - @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId AND d.lastConnectTs < :time AND d.type = :type") - List findConnectOfflineByTenantIdAndType(@Param("tenantId") String tenantId, @Param("time") long time, @Param("type") String type); - - @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId AND d.lastUpdateTs > :time AND d.type = :type") - List findUpdateOnlineByTenantIdAndType(@Param("tenantId") String tenantId, @Param("time") long time, @Param("type") String type); - - @Query("SELECT d FROM DeviceEntity d WHERE d.tenantId = :tenantId AND d.lastUpdateTs < :time AND d.type = :type") - List findUpdateOfflineByTenantIdAndType(@Param("tenantId") String tenantId, @Param("time") long time, @Param("type") String type); } diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java b/dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java index baba65952d..4f3cd7d6fb 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java @@ -15,9 +15,7 @@ */ package org.thingsboard.server.dao.sql.device; -import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.repository.CrudRepository; @@ -26,7 +24,6 @@ import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.EntitySubtype; import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.UUIDConverter; -import org.thingsboard.server.common.data.device.DeviceStatusQuery; import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.page.TextPageLink; import org.thingsboard.server.dao.DaoUtil; @@ -46,7 +43,6 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID_STR; */ @Component @SqlDao -@Slf4j public class JpaDeviceDao extends JpaAbstractSearchTextDao implements DeviceDao { @Autowired @@ -128,73 +124,6 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao return service.submit(() -> convertTenantDeviceTypesToDto(tenantId, deviceRepository.findTenantDeviceTypes(fromTimeUUID(tenantId)))); } - @Override - public ListenableFuture> findDevicesByTenantIdAndStatus(UUID tenantId, DeviceStatusQuery statusQuery) { - String strTenantId = fromTimeUUID(tenantId); - long minTime = System.currentTimeMillis() - statusQuery.getThreshold(); - switch (statusQuery.getStatus()) { - case OFFLINE: { - switch (statusQuery.getContactType()) { - case UPLOAD: - return service.submit(() -> DaoUtil.convertDataList(deviceRepository.findUpdateOfflineByTenantId(strTenantId, minTime))); - case CONNECT: - return service.submit(() -> DaoUtil.convertDataList(deviceRepository.findConnectOfflineByTenantId(strTenantId, minTime))); - } - break; - } - case ONLINE: { - switch (statusQuery.getContactType()) { - case UPLOAD: - return service.submit(() -> DaoUtil.convertDataList(deviceRepository.findUpdateOnlineByTenantId(strTenantId, minTime))); - case CONNECT: - return service.submit(() -> DaoUtil.convertDataList(deviceRepository.findConnectOnlineByTenantId(strTenantId, minTime))); - } - break; - } - } - - log.error("Could not build status query from [{}]", statusQuery); - throw new IllegalStateException("Could not build status query for device []"); - } - - @Override - public ListenableFuture> findDevicesByTenantIdTypeAndStatus(UUID tenantId, String type, DeviceStatusQuery statusQuery) { - String strTenantId = fromTimeUUID(tenantId); - long minTime = System.currentTimeMillis() - statusQuery.getThreshold(); - switch (statusQuery.getStatus()) { - case OFFLINE: { - switch (statusQuery.getContactType()) { - case UPLOAD: - return service.submit(() -> DaoUtil.convertDataList(deviceRepository.findUpdateOfflineByTenantIdAndType(strTenantId, minTime, type))); - case CONNECT: - return service.submit(() -> DaoUtil.convertDataList(deviceRepository.findConnectOfflineByTenantIdAndType(strTenantId, minTime, type))); - } - break; - } - case ONLINE: { - switch (statusQuery.getContactType()) { - case UPLOAD: - return service.submit(() -> DaoUtil.convertDataList(deviceRepository.findUpdateOnlineByTenantIdAndType(strTenantId, minTime, type))); - case CONNECT: - return service.submit(() -> DaoUtil.convertDataList(deviceRepository.findConnectOnlineByTenantIdAndType(strTenantId, minTime, type))); - } - break; - } - } - - log.error("Could not build status query from [{}]", statusQuery); - throw new IllegalStateException("Could not build status query for device []"); - } - - @Override - public void saveDeviceStatus(Device device) { - ListenableFuture future = service.submit(() -> save(device)); - Futures.withFallback(future, t -> { - log.error("Can't update device status for [{}]", device, t); - throw new IllegalArgumentException("Can't update device status for {" + device + "}", t); - }); - } - private List convertTenantDeviceTypesToDto(UUID tenantId, List types) { List list = Collections.emptyList(); if (types != null && !types.isEmpty()) { diff --git a/dao/src/main/resources/cassandra/schema.cql b/dao/src/main/resources/cassandra/schema.cql index 24b2117c98..91505878ff 100644 --- a/dao/src/main/resources/cassandra/schema.cql +++ b/dao/src/main/resources/cassandra/schema.cql @@ -159,8 +159,6 @@ CREATE TABLE IF NOT EXISTS thingsboard.device ( type text, search_text text, additional_info text, - last_connect bigint, - last_update bigint, PRIMARY KEY (id, tenant_id, customer_id, type) ); diff --git a/dao/src/main/resources/sql/schema.sql b/dao/src/main/resources/sql/schema.sql index f2458e1613..5876fbb562 100644 --- a/dao/src/main/resources/sql/schema.sql +++ b/dao/src/main/resources/sql/schema.sql @@ -118,9 +118,7 @@ CREATE TABLE IF NOT EXISTS device ( type varchar(255), name varchar(255), search_text varchar(255), - tenant_id varchar(31), - last_connect bigint, - last_update bigint + tenant_id varchar(31) ); CREATE TABLE IF NOT EXISTS device_credentials ( diff --git a/rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/NodeDefinition.java b/rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/NodeDefinition.java index 18b2b941ad..aeaf3f1a20 100644 --- a/rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/NodeDefinition.java +++ b/rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/NodeDefinition.java @@ -31,5 +31,7 @@ public class NodeDefinition { JsonNode defaultConfiguration; String[] uiResources; String configDirective; + String icon; + String iconUrl; } diff --git a/rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/RuleNode.java b/rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/RuleNode.java index eea92ed00a..cfb67d33eb 100644 --- a/rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/RuleNode.java +++ b/rule-engine/rule-engine-api/src/main/java/org/thingsboard/rule/engine/api/RuleNode.java @@ -49,6 +49,10 @@ public @interface RuleNode { String configDirective() default ""; + String icon() default ""; + + String iconUrl() default ""; + boolean customRelations() default false; } diff --git a/rule-engine/rule-engine-components/pom.xml b/rule-engine/rule-engine-components/pom.xml index a38df289d3..3352f5acec 100644 --- a/rule-engine/rule-engine-components/pom.xml +++ b/rule-engine/rule-engine-components/pom.xml @@ -72,16 +72,6 @@ com.google.guava guava - - org.apache.velocity - velocity - provided - - - org.apache.velocity - velocity-tools - provided - org.springframework spring-web diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbAlarmNode.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbAlarmNode.java index 566a125bd8..e1112971f5 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbAlarmNode.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbAlarmNode.java @@ -47,7 +47,9 @@ import static org.thingsboard.rule.engine.DonAsynchron.withCallback; "Message payload can be accessed via msg property. For example 'temperature = ' + msg.temperature ;" + "Message metadata can be accessed via metadata property. For example 'name = ' + metadata.customerName;", uiResources = {"static/rulenode/rulenode-core-config.js"}, - configDirective = "tbActionNodeAlarmConfig") + configDirective = "tbActionNodeAlarmConfig", + icon = "notifications_active" +) public class TbAlarmNode implements TbNode { diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbLogNode.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbLogNode.java index 9e114b0c01..b6f53dba9c 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbLogNode.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/action/TbLogNode.java @@ -34,7 +34,9 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; "Message payload can be accessed via msg property. For example 'temperature = ' + msg.temperature ;" + "Message metadata can be accessed via metadata property. For example 'name = ' + metadata.customerName;", uiResources = {"static/rulenode/rulenode-core-config.js"}, - configDirective = "tbActionNodeLogConfig") + configDirective = "tbActionNodeLogConfig", + icon = "menu" +) public class TbLogNode implements TbNode { diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/aws/sns/TbSnsNode.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/aws/sns/TbSnsNode.java index 428621cf67..22db39474c 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/aws/sns/TbSnsNode.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/aws/sns/TbSnsNode.java @@ -38,13 +38,14 @@ import static org.thingsboard.rule.engine.DonAsynchron.withCallback; @Slf4j @RuleNode( - type = ComponentType.ACTION, + type = ComponentType.EXTERNAL, name = "aws sns", configClazz = TbSnsNodeConfiguration.class, nodeDescription = "Publish messages to AWS SNS", nodeDetails = "Expects messages with any message type. Will publish message to AWS SNS topic.", uiResources = {"static/rulenode/rulenode-core-config.js"}, - configDirective = "tbActionNodeSnsConfig" + configDirective = "tbActionNodeSnsConfig", + iconUrl = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjQ4IiBoZWlnaHQ9IjQ4Ij48cGF0aCBkPSJNMTMuMjMgMTAuNTZWMTBjLTEuOTQgMC0zLjk5LjM5LTMuOTkgMi42NyAwIDEuMTYuNjEgMS45NSAxLjYzIDEuOTUuNzYgMCAxLjQzLS40NyAxLjg2LTEuMjIuNTItLjkzLjUtMS44LjUtMi44NG0yLjcgNi41M2MtLjE4LjE2LS40My4xNy0uNjMuMDYtLjg5LS43NC0xLjA1LTEuMDgtMS41NC0xLjc5LTEuNDcgMS41LTIuNTEgMS45NS00LjQyIDEuOTUtMi4yNSAwLTQuMDEtMS4zOS00LjAxLTQuMTcgMC0yLjE4IDEuMTctMy42NCAyLjg2LTQuMzggMS40Ni0uNjQgMy40OS0uNzYgNS4wNC0uOTNWNy41YzAtLjY2LjA1LTEuNDEtLjMzLTEuOTYtLjMyLS40OS0uOTUtLjctMS41LS43LTEuMDIgMC0xLjkzLjUzLTIuMTUgMS42MS0uMDUuMjQtLjI1LjQ4LS40Ny40OWwtMi42LS4yOGMtLjIyLS4wNS0uNDYtLjIyLS40LS41Ni42LTMuMTUgMy40NS00LjEgNi00LjEgMS4zIDAgMyAuMzUgNC4wMyAxLjMzQzE3LjExIDQuNTUgMTcgNi4xOCAxNyA3Ljk1djQuMTdjMCAxLjI1LjUgMS44MSAxIDIuNDguMTcuMjUuMjEuNTQgMCAuNzFsLTIuMDYgMS43OGgtLjAxIj48L3BhdGg+PHBhdGggZD0iTTIwLjE2IDE5LjU0QzE4IDIxLjE0IDE0LjgyIDIyIDEyLjEgMjJjLTMuODEgMC03LjI1LTEuNDEtOS44NS0zLjc2LS4yLS4xOC0uMDItLjQzLjI1LS4yOSAyLjc4IDEuNjMgNi4yNSAyLjYxIDkuODMgMi42MSAyLjQxIDAgNS4wNy0uNSA3LjUxLTEuNTMuMzctLjE2LjY2LjI0LjMyLjUxIj48L3BhdGg+PHBhdGggZD0iTTIxLjA3IDE4LjVjLS4yOC0uMzYtMS44NS0uMTctMi41Ny0uMDgtLjE5LjAyLS4yMi0uMTYtLjAzLS4zIDEuMjQtLjg4IDMuMjktLjYyIDMuNTMtLjMzLjI0LjMtLjA3IDIuMzUtMS4yNCAzLjMyLS4xOC4xNi0uMzUuMDctLjI2LS4xMS4yNi0uNjcuODUtMi4xNC41Ny0yLjV6Ij48L3BhdGg+PC9zdmc+" ) public class TbSnsNode implements TbNode { diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/aws/sqs/TbSqsNode.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/aws/sqs/TbSqsNode.java index f5172c7cc3..c4ac13e834 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/aws/sqs/TbSqsNode.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/aws/sqs/TbSqsNode.java @@ -41,13 +41,14 @@ import static org.thingsboard.rule.engine.DonAsynchron.withCallback; @Slf4j @RuleNode( - type = ComponentType.ACTION, + type = ComponentType.EXTERNAL, name = "aws sqs", configClazz = TbSqsNodeConfiguration.class, nodeDescription = "Publish messages to AWS SQS", nodeDetails = "Expects messages with any message type. Will publish message to AWS SQS queue.", uiResources = {"static/rulenode/rulenode-core-config.js"}, - configDirective = "tbActionNodeSqsConfig" + configDirective = "tbActionNodeSqsConfig", + iconUrl = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgd2lkdGg9IjQ4IiBoZWlnaHQ9IjQ4Ij48cGF0aCBkPSJNMTMuMjMgMTAuNTZWMTBjLTEuOTQgMC0zLjk5LjM5LTMuOTkgMi42NyAwIDEuMTYuNjEgMS45NSAxLjYzIDEuOTUuNzYgMCAxLjQzLS40NyAxLjg2LTEuMjIuNTItLjkzLjUtMS44LjUtMi44NG0yLjcgNi41M2MtLjE4LjE2LS40My4xNy0uNjMuMDYtLjg5LS43NC0xLjA1LTEuMDgtMS41NC0xLjc5LTEuNDcgMS41LTIuNTEgMS45NS00LjQyIDEuOTUtMi4yNSAwLTQuMDEtMS4zOS00LjAxLTQuMTcgMC0yLjE4IDEuMTctMy42NCAyLjg2LTQuMzggMS40Ni0uNjQgMy40OS0uNzYgNS4wNC0uOTNWNy41YzAtLjY2LjA1LTEuNDEtLjMzLTEuOTYtLjMyLS40OS0uOTUtLjctMS41LS43LTEuMDIgMC0xLjkzLjUzLTIuMTUgMS42MS0uMDUuMjQtLjI1LjQ4LS40Ny40OWwtMi42LS4yOGMtLjIyLS4wNS0uNDYtLjIyLS40LS41Ni42LTMuMTUgMy40NS00LjEgNi00LjEgMS4zIDAgMyAuMzUgNC4wMyAxLjMzQzE3LjExIDQuNTUgMTcgNi4xOCAxNyA3Ljk1djQuMTdjMCAxLjI1LjUgMS44MSAxIDIuNDguMTcuMjUuMjEuNTQgMCAuNzFsLTIuMDYgMS43OGgtLjAxIj48L3BhdGg+PHBhdGggZD0iTTIwLjE2IDE5LjU0QzE4IDIxLjE0IDE0LjgyIDIyIDEyLjEgMjJjLTMuODEgMC03LjI1LTEuNDEtOS44NS0zLjc2LS4yLS4xOC0uMDItLjQzLjI1LS4yOSAyLjc4IDEuNjMgNi4yNSAyLjYxIDkuODMgMi42MSAyLjQxIDAgNS4wNy0uNSA3LjUxLTEuNTMuMzctLjE2LjY2LjI0LjMyLjUxIj48L3BhdGg+PHBhdGggZD0iTTIxLjA3IDE4LjVjLS4yOC0uMzYtMS44NS0uMTctMi41Ny0uMDgtLjE5LjAyLS4yMi0uMTYtLjAzLS4zIDEuMjQtLjg4IDMuMjktLjYyIDMuNTMtLjMzLjI0LjMtLjA3IDIuMzUtMS4yNCAzLjMyLS4xOC4xNi0uMzUuMDctLjI2LS4xMS4yNi0uNjcuODUtMi4xNC41Ny0yLjV6Ij48L3BhdGg+PC9zdmc+" ) public class TbSqsNode implements TbNode { diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/debug/TbMsgGeneratorNode.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/debug/TbMsgGeneratorNode.java index 40ea3b84d6..f8bdc0394c 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/debug/TbMsgGeneratorNode.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/debug/TbMsgGeneratorNode.java @@ -41,7 +41,8 @@ import static org.thingsboard.rule.engine.api.TbRelationTypes.SUCCESS; nodeDetails = "Generates messages with configurable period. ", inEnabled = false, uiResources = {"static/rulenode/rulenode-core-config.js", "static/rulenode/rulenode-core-config.css"}, - configDirective = "tbActionNodeGeneratorConfig" + configDirective = "tbActionNodeGeneratorConfig", + icon = "repeat" ) public class TbMsgGeneratorNode implements TbNode { diff --git a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/filter/TbMsgTypeFilterNodeConfiguration.java b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/filter/TbMsgTypeFilterNodeConfiguration.java index ae88aa8b07..100d876667 100644 --- a/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/filter/TbMsgTypeFilterNodeConfiguration.java +++ b/rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/filter/TbMsgTypeFilterNodeConfiguration.java @@ -17,6 +17,7 @@ package org.thingsboard.rule.engine.filter; import lombok.Data; import org.thingsboard.rule.engine.api.NodeConfiguration; +import org.thingsboard.server.common.msg.session.SessionMsgType; import java.util.Arrays; import java.util.Collections; @@ -33,7 +34,10 @@ public class TbMsgTypeFilterNodeConfiguration implements NodeConfiguration fromTemplate; - private Optional