Showing
19 changed files
with
102 additions
and
270 deletions
@@ -14,10 +14,9 @@ | @@ -14,10 +14,9 @@ | ||
14 | -- limitations under the License. | 14 | -- limitations under the License. |
15 | -- | 15 | -- |
16 | 16 | ||
17 | -DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_views_by_tenant_and_name; | ||
18 | -DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_views_by_tenant_and_entity; | ||
19 | -DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_views_by_tenant_and_customer; | ||
20 | -DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity; | 17 | +DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_name; |
18 | +DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_search_text; | ||
19 | +DROP MATERIALIZED VIEW IF EXISTS thingsboard.entity_view_by_tenant_and_customer; | ||
21 | 20 | ||
22 | DROP TABLE IF EXISTS thingsboard.entity_views; | 21 | DROP TABLE IF EXISTS thingsboard.entity_views; |
23 | 22 | ||
@@ -36,7 +35,7 @@ CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( | @@ -36,7 +35,7 @@ CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( | ||
36 | PRIMARY KEY (id, entity_id, tenant_id, customer_id) | 35 | PRIMARY KEY (id, entity_id, tenant_id, customer_id) |
37 | ); | 36 | ); |
38 | 37 | ||
39 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_name AS | 38 | +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_name AS |
40 | SELECT * | 39 | SELECT * |
41 | from thingsboard.entity_views | 40 | from thingsboard.entity_views |
42 | WHERE tenant_id IS NOT NULL | 41 | WHERE tenant_id IS NOT NULL |
@@ -58,18 +57,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_sea | @@ -58,18 +57,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_sea | ||
58 | PRIMARY KEY (tenant_id, search_text, id, customer_id, entity_id) | 57 | PRIMARY KEY (tenant_id, search_text, id, customer_id, entity_id) |
59 | WITH CLUSTERING ORDER BY (search_text ASC, id DESC, customer_id DESC); | 58 | WITH CLUSTERING ORDER BY (search_text ASC, id DESC, customer_id DESC); |
60 | 59 | ||
61 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_entity AS | ||
62 | - SELECT * | ||
63 | - from thingsboard.entity_views | ||
64 | - WHERE tenant_id IS NOT NULL | ||
65 | - AND customer_id IS NOT NULL | ||
66 | - AND entity_id IS NOT NULL | ||
67 | - AND search_text IS NOT NULL | ||
68 | - AND id IS NOT NULL | ||
69 | - PRIMARY KEY (tenant_id, entity_id, search_text, id, customer_id) | ||
70 | - WITH CLUSTERING ORDER BY (entity_id ASC, search_text ASC, id DESC, customer_id DESC); | ||
71 | - | ||
72 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer AS | 60 | +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_customer AS |
73 | SELECT * | 61 | SELECT * |
74 | from thingsboard.entity_views | 62 | from thingsboard.entity_views |
75 | WHERE tenant_id IS NOT NULL | 63 | WHERE tenant_id IS NOT NULL |
@@ -79,14 +67,3 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_cu | @@ -79,14 +67,3 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_cu | ||
79 | AND id IS NOT NULL | 67 | AND id IS NOT NULL |
80 | PRIMARY KEY (tenant_id, customer_id, search_text, id, entity_id) | 68 | PRIMARY KEY (tenant_id, customer_id, search_text, id, entity_id) |
81 | WITH CLUSTERING ORDER BY (customer_id DESC, search_text ASC, id DESC); | 69 | WITH CLUSTERING ORDER BY (customer_id DESC, search_text ASC, id DESC); |
82 | - | ||
83 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity AS | ||
84 | - SELECT * | ||
85 | - from thingsboard.entity_views | ||
86 | - WHERE tenant_id IS NOT NULL | ||
87 | - AND customer_id IS NOT NULL | ||
88 | - AND entity_id IS NOT NULL | ||
89 | - AND search_text IS NOT NULL | ||
90 | - AND id IS NOT NULL | ||
91 | - PRIMARY KEY (tenant_id, customer_id, entity_id, search_text, id) | ||
92 | - WITH CLUSTERING ORDER BY (customer_id DESC, entity_id ASC, search_text ASC, id DESC); |
@@ -93,8 +93,6 @@ public class ThingsboardInstallService { | @@ -93,8 +93,6 @@ public class ThingsboardInstallService { | ||
93 | 93 | ||
94 | databaseUpgradeService.upgradeDatabase("2.0.0"); | 94 | databaseUpgradeService.upgradeDatabase("2.0.0"); |
95 | 95 | ||
96 | - dataUpdateService.updateData("2.0.0"); | ||
97 | - | ||
98 | log.info("Updating system data..."); | 96 | log.info("Updating system data..."); |
99 | 97 | ||
100 | systemDataLoaderService.deleteSystemWidgetBundle("charts"); | 98 | systemDataLoaderService.deleteSystemWidgetBundle("charts"); |
@@ -49,10 +49,6 @@ public class DefaultDataUpdateService implements DataUpdateService { | @@ -49,10 +49,6 @@ public class DefaultDataUpdateService implements DataUpdateService { | ||
49 | log.info("Updating data from version 1.4.0 to 2.0.0 ..."); | 49 | log.info("Updating data from version 1.4.0 to 2.0.0 ..."); |
50 | tenantsDefaultRuleChainUpdater.updateEntities(null); | 50 | tenantsDefaultRuleChainUpdater.updateEntities(null); |
51 | break; | 51 | break; |
52 | - case "2.0.0": | ||
53 | - log.info("Updating data from version 2.0.0 to 2.1.1 ..."); | ||
54 | - tenantsDefaultRuleChainUpdater.updateEntities(null); | ||
55 | - break; | ||
56 | default: | 52 | default: |
57 | throw new RuntimeException("Unable to update data, unsupported fromVersion: " + fromVersion); | 53 | throw new RuntimeException("Unable to update data, unsupported fromVersion: " + fromVersion); |
58 | } | 54 | } |
@@ -30,7 +30,15 @@ import org.thingsboard.server.common.data.EntityView; | @@ -30,7 +30,15 @@ import org.thingsboard.server.common.data.EntityView; | ||
30 | import org.thingsboard.server.common.data.Tenant; | 30 | import org.thingsboard.server.common.data.Tenant; |
31 | import org.thingsboard.server.common.data.asset.Asset; | 31 | import org.thingsboard.server.common.data.asset.Asset; |
32 | import org.thingsboard.server.common.data.exception.ThingsboardException; | 32 | import org.thingsboard.server.common.data.exception.ThingsboardException; |
33 | -import org.thingsboard.server.common.data.id.*; | 33 | +import org.thingsboard.server.common.data.id.AssetId; |
34 | +import org.thingsboard.server.common.data.id.CustomerId; | ||
35 | +import org.thingsboard.server.common.data.id.DeviceId; | ||
36 | +import org.thingsboard.server.common.data.id.EntityId; | ||
37 | +import org.thingsboard.server.common.data.id.EntityIdFactory; | ||
38 | +import org.thingsboard.server.common.data.id.EntityViewId; | ||
39 | +import org.thingsboard.server.common.data.id.RuleChainId; | ||
40 | +import org.thingsboard.server.common.data.id.RuleNodeId; | ||
41 | +import org.thingsboard.server.common.data.id.TenantId; | ||
34 | import org.thingsboard.server.common.data.rule.RuleChain; | 42 | import org.thingsboard.server.common.data.rule.RuleChain; |
35 | import org.thingsboard.server.common.data.rule.RuleNode; | 43 | import org.thingsboard.server.common.data.rule.RuleNode; |
36 | import org.thingsboard.server.controller.HttpValidationCallback; | 44 | import org.thingsboard.server.controller.HttpValidationCallback; |
@@ -22,7 +22,11 @@ import org.junit.After; | @@ -22,7 +22,11 @@ import org.junit.After; | ||
22 | import org.junit.Assert; | 22 | import org.junit.Assert; |
23 | import org.junit.Before; | 23 | import org.junit.Before; |
24 | import org.junit.Test; | 24 | import org.junit.Test; |
25 | -import org.thingsboard.server.common.data.*; | 25 | +import org.thingsboard.server.common.data.Customer; |
26 | +import org.thingsboard.server.common.data.Device; | ||
27 | +import org.thingsboard.server.common.data.EntityView; | ||
28 | +import org.thingsboard.server.common.data.Tenant; | ||
29 | +import org.thingsboard.server.common.data.User; | ||
26 | import org.thingsboard.server.common.data.id.CustomerId; | 30 | import org.thingsboard.server.common.data.id.CustomerId; |
27 | import org.thingsboard.server.common.data.objects.AttributesEntityView; | 31 | import org.thingsboard.server.common.data.objects.AttributesEntityView; |
28 | import org.thingsboard.server.common.data.objects.TelemetryEntityView; | 32 | import org.thingsboard.server.common.data.objects.TelemetryEntityView; |
@@ -31,7 +35,10 @@ import org.thingsboard.server.common.data.page.TextPageLink; | @@ -31,7 +35,10 @@ import org.thingsboard.server.common.data.page.TextPageLink; | ||
31 | import org.thingsboard.server.common.data.security.Authority; | 35 | import org.thingsboard.server.common.data.security.Authority; |
32 | import org.thingsboard.server.dao.model.ModelConstants; | 36 | import org.thingsboard.server.dao.model.ModelConstants; |
33 | 37 | ||
34 | -import java.util.*; | 38 | +import java.util.ArrayList; |
39 | +import java.util.Arrays; | ||
40 | +import java.util.Collections; | ||
41 | +import java.util.List; | ||
35 | 42 | ||
36 | import static org.hamcrest.Matchers.containsString; | 43 | import static org.hamcrest.Matchers.containsString; |
37 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | 44 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; |
@@ -43,7 +50,6 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | @@ -43,7 +50,6 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | ||
43 | private Tenant savedTenant; | 50 | private Tenant savedTenant; |
44 | private User tenantAdmin; | 51 | private User tenantAdmin; |
45 | private Device testDevice; | 52 | private Device testDevice; |
46 | - private TelemetryEntityView obj; | ||
47 | 53 | ||
48 | @Before | 54 | @Before |
49 | public void beforeTest() throws Exception { | 55 | public void beforeTest() throws Exception { |
@@ -67,14 +73,6 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | @@ -67,14 +73,6 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | ||
67 | device.setName("Test device"); | 73 | device.setName("Test device"); |
68 | device.setType("default"); | 74 | device.setType("default"); |
69 | testDevice = doPost("/api/device", device, Device.class); | 75 | testDevice = doPost("/api/device", device, Device.class); |
70 | - obj = new TelemetryEntityView( | ||
71 | - Arrays.asList("109L", "209L"), | ||
72 | - new AttributesEntityView( | ||
73 | - Arrays.asList("caKey1", "caKey2"), | ||
74 | - Arrays.asList("saKey1", "saKey2", "saKey3"), | ||
75 | - Arrays.asList("shKey1", "shKey2", "shKey3", "shKey4") | ||
76 | - ) | ||
77 | - ); | ||
78 | } | 76 | } |
79 | 77 | ||
80 | @After | 78 | @After |
@@ -239,14 +237,16 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | @@ -239,14 +237,16 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | ||
239 | doDelete("/api/customer/entityView/" + view.getId().getId().toString()).andExpect(status().isOk()); | 237 | doDelete("/api/customer/entityView/" + view.getId().getId().toString()).andExpect(status().isOk()); |
240 | } | 238 | } |
241 | TextPageData<EntityView> pageData = doGetTypedWithPageLink(urlTemplate, | 239 | TextPageData<EntityView> pageData = doGetTypedWithPageLink(urlTemplate, |
242 | - new TypeReference<TextPageData<EntityView>>(){}, new TextPageLink(4, name1)); | 240 | + new TypeReference<TextPageData<EntityView>>() { |
241 | + }, new TextPageLink(4, name1)); | ||
243 | Assert.assertFalse(pageData.hasNext()); | 242 | Assert.assertFalse(pageData.hasNext()); |
244 | Assert.assertEquals(0, pageData.getData().size()); | 243 | Assert.assertEquals(0, pageData.getData().size()); |
245 | 244 | ||
246 | for (EntityView view : loadedNamesOfView2) { | 245 | for (EntityView view : loadedNamesOfView2) { |
247 | doDelete("/api/customer/entityView/" + view.getId().getId().toString()).andExpect(status().isOk()); | 246 | doDelete("/api/customer/entityView/" + view.getId().getId().toString()).andExpect(status().isOk()); |
248 | } | 247 | } |
249 | - pageData = doGetTypedWithPageLink(urlTemplate, new TypeReference<TextPageData<EntityView>>(){}, | 248 | + pageData = doGetTypedWithPageLink(urlTemplate, new TypeReference<TextPageData<EntityView>>() { |
249 | + }, | ||
250 | new TextPageLink(4, name2)); | 250 | new TextPageLink(4, name2)); |
251 | Assert.assertFalse(pageData.hasNext()); | 251 | Assert.assertFalse(pageData.hasNext()); |
252 | Assert.assertEquals(0, pageData.getData().size()); | 252 | Assert.assertEquals(0, pageData.getData().size()); |
@@ -287,14 +287,16 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | @@ -287,14 +287,16 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | ||
287 | doDelete("/api/entityView/" + view.getId().getId().toString()).andExpect(status().isOk()); | 287 | doDelete("/api/entityView/" + view.getId().getId().toString()).andExpect(status().isOk()); |
288 | } | 288 | } |
289 | TextPageData<EntityView> pageData = doGetTypedWithPageLink("/api/tenant/entityViews?", | 289 | TextPageData<EntityView> pageData = doGetTypedWithPageLink("/api/tenant/entityViews?", |
290 | - new TypeReference<TextPageData<EntityView>>(){}, new TextPageLink(4, name1)); | 290 | + new TypeReference<TextPageData<EntityView>>() { |
291 | + }, new TextPageLink(4, name1)); | ||
291 | Assert.assertFalse(pageData.hasNext()); | 292 | Assert.assertFalse(pageData.hasNext()); |
292 | Assert.assertEquals(0, pageData.getData().size()); | 293 | Assert.assertEquals(0, pageData.getData().size()); |
293 | 294 | ||
294 | for (EntityView view : loadedNamesOfView2) { | 295 | for (EntityView view : loadedNamesOfView2) { |
295 | doDelete("/api/entityView/" + view.getId().getId().toString()).andExpect(status().isOk()); | 296 | doDelete("/api/entityView/" + view.getId().getId().toString()).andExpect(status().isOk()); |
296 | } | 297 | } |
297 | - pageData = doGetTypedWithPageLink("/api/tenant/entityViews?", new TypeReference<TextPageData<EntityView>>(){}, | 298 | + pageData = doGetTypedWithPageLink("/api/tenant/entityViews?", new TypeReference<TextPageData<EntityView>>() { |
299 | + }, | ||
298 | new TextPageLink(4, name2)); | 300 | new TextPageLink(4, name2)); |
299 | Assert.assertFalse(pageData.hasNext()); | 301 | Assert.assertFalse(pageData.hasNext()); |
300 | Assert.assertEquals(0, pageData.getData().size()); | 302 | Assert.assertEquals(0, pageData.getData().size()); |
@@ -305,7 +307,14 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | @@ -305,7 +307,14 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | ||
305 | view.setEntityId(testDevice.getId()); | 307 | view.setEntityId(testDevice.getId()); |
306 | view.setTenantId(savedTenant.getId()); | 308 | view.setTenantId(savedTenant.getId()); |
307 | view.setName(name); | 309 | view.setName(name); |
308 | - view.setKeys(new TelemetryEntityView(obj)); | 310 | + |
311 | + view.setKeys(new TelemetryEntityView( | ||
312 | + Arrays.asList("109L", "209L"), | ||
313 | + new AttributesEntityView( | ||
314 | + Arrays.asList("caKey1", "caKey2"), | ||
315 | + Arrays.asList("saKey1", "saKey2", "saKey3"), | ||
316 | + Arrays.asList("shKey1", "shKey2", "shKey3", "shKey4")))); | ||
317 | + | ||
309 | return doPost("/api/entityView", view, EntityView.class); | 318 | return doPost("/api/entityView", view, EntityView.class); |
310 | } | 319 | } |
311 | 320 | ||
@@ -346,7 +355,8 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | @@ -346,7 +355,8 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes | ||
346 | List<EntityView> loadedItems = new ArrayList<>(); | 355 | List<EntityView> loadedItems = new ArrayList<>(); |
347 | TextPageData<EntityView> pageData; | 356 | TextPageData<EntityView> pageData; |
348 | do { | 357 | do { |
349 | - pageData = doGetTypedWithPageLink(urlTemplate, new TypeReference<TextPageData<EntityView>>(){}, pageLink); | 358 | + pageData = doGetTypedWithPageLink(urlTemplate, new TypeReference<TextPageData<EntityView>>() { |
359 | + }, pageLink); | ||
350 | loadedItems.addAll(pageData.getData()); | 360 | loadedItems.addAll(pageData.getData()); |
351 | if (pageData.hasNext()) { | 361 | if (pageData.hasNext()) { |
352 | pageLink = pageData.getNextPageLink(); | 362 | pageLink = pageData.getNextPageLink(); |
@@ -15,7 +15,9 @@ | @@ -15,7 +15,9 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.common.data; | 16 | package org.thingsboard.server.common.data; |
17 | 17 | ||
18 | -import lombok.*; | 18 | +import lombok.AllArgsConstructor; |
19 | +import lombok.Data; | ||
20 | +import lombok.EqualsAndHashCode; | ||
19 | import org.thingsboard.server.common.data.id.CustomerId; | 21 | import org.thingsboard.server.common.data.id.CustomerId; |
20 | import org.thingsboard.server.common.data.id.EntityId; | 22 | import org.thingsboard.server.common.data.id.EntityId; |
21 | import org.thingsboard.server.common.data.id.EntityViewId; | 23 | import org.thingsboard.server.common.data.id.EntityViewId; |
@@ -32,6 +32,7 @@ import org.thingsboard.server.dao.asset.AssetService; | @@ -32,6 +32,7 @@ import org.thingsboard.server.dao.asset.AssetService; | ||
32 | import org.thingsboard.server.dao.dashboard.DashboardService; | 32 | import org.thingsboard.server.dao.dashboard.DashboardService; |
33 | import org.thingsboard.server.dao.device.DeviceService; | 33 | import org.thingsboard.server.dao.device.DeviceService; |
34 | import org.thingsboard.server.dao.entity.AbstractEntityService; | 34 | import org.thingsboard.server.dao.entity.AbstractEntityService; |
35 | +import org.thingsboard.server.dao.entityview.EntityViewService; | ||
35 | import org.thingsboard.server.dao.exception.DataValidationException; | 36 | import org.thingsboard.server.dao.exception.DataValidationException; |
36 | import org.thingsboard.server.dao.exception.IncorrectParameterException; | 37 | import org.thingsboard.server.dao.exception.IncorrectParameterException; |
37 | import org.thingsboard.server.dao.service.DataValidator; | 38 | import org.thingsboard.server.dao.service.DataValidator; |
@@ -70,6 +71,9 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom | @@ -70,6 +71,9 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom | ||
70 | private DeviceService deviceService; | 71 | private DeviceService deviceService; |
71 | 72 | ||
72 | @Autowired | 73 | @Autowired |
74 | + private EntityViewService entityViewService; | ||
75 | + | ||
76 | + @Autowired | ||
73 | private DashboardService dashboardService; | 77 | private DashboardService dashboardService; |
74 | 78 | ||
75 | @Override | 79 | @Override |
@@ -113,6 +117,7 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom | @@ -113,6 +117,7 @@ public class CustomerServiceImpl extends AbstractEntityService implements Custom | ||
113 | dashboardService.unassignCustomerDashboards(customerId); | 117 | dashboardService.unassignCustomerDashboards(customerId); |
114 | assetService.unassignCustomerAssets(customer.getTenantId(), customerId); | 118 | assetService.unassignCustomerAssets(customer.getTenantId(), customerId); |
115 | deviceService.unassignCustomerDevices(customer.getTenantId(), customerId); | 119 | deviceService.unassignCustomerDevices(customer.getTenantId(), customerId); |
120 | + entityViewService.unassignCustomerEntityViews(customer.getTenantId(), customerId); | ||
116 | userService.deleteCustomerUsers(customer.getTenantId(), customerId); | 121 | userService.deleteCustomerUsers(customer.getTenantId(), customerId); |
117 | deleteEntityRelations(customerId); | 122 | deleteEntityRelations(customerId); |
118 | customerDao.removeById(customerId.getId()); | 123 | customerDao.removeById(customerId.getId()); |
@@ -30,11 +30,23 @@ import org.thingsboard.server.dao.model.nosql.EntityViewEntity; | @@ -30,11 +30,23 @@ import org.thingsboard.server.dao.model.nosql.EntityViewEntity; | ||
30 | import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; | 30 | import org.thingsboard.server.dao.nosql.CassandraAbstractSearchTextDao; |
31 | import org.thingsboard.server.dao.util.NoSqlDao; | 31 | import org.thingsboard.server.dao.util.NoSqlDao; |
32 | 32 | ||
33 | -import java.util.*; | 33 | +import java.util.Arrays; |
34 | +import java.util.Collections; | ||
35 | +import java.util.List; | ||
36 | +import java.util.Optional; | ||
37 | +import java.util.UUID; | ||
34 | 38 | ||
35 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; | 39 | import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; |
36 | import static com.datastax.driver.core.querybuilder.QueryBuilder.select; | 40 | import static com.datastax.driver.core.querybuilder.QueryBuilder.select; |
37 | -import static org.thingsboard.server.dao.model.ModelConstants.*; | 41 | +import static org.thingsboard.server.dao.model.ModelConstants.CUSTOMER_ID_PROPERTY; |
42 | +import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_ID_COLUMN; | ||
43 | +import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_SEARCH_TEXT; | ||
44 | +import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_BY_TENANT_AND_NAME; | ||
45 | +import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME; | ||
46 | +import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_NAME_PROPERTY; | ||
47 | +import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_TABLE_FAMILY_NAME; | ||
48 | +import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_VIEW_TENANT_ID_PROPERTY; | ||
49 | +import static org.thingsboard.server.dao.model.ModelConstants.TENANT_ID_PROPERTY; | ||
38 | 50 | ||
39 | /** | 51 | /** |
40 | * Created by Victor Basanets on 9/06/2017. | 52 | * Created by Victor Basanets on 9/06/2017. |
@@ -85,19 +97,6 @@ public class CassandraEntityViewDao extends CassandraAbstractSearchTextDao<Entit | @@ -85,19 +97,6 @@ public class CassandraEntityViewDao extends CassandraAbstractSearchTextDao<Entit | ||
85 | } | 97 | } |
86 | 98 | ||
87 | @Override | 99 | @Override |
88 | - public List<EntityView> findEntityViewByTenantIdAndEntityId(UUID tenantId, UUID entityId, TextPageLink pageLink) { | ||
89 | - log.debug("Try to find entity views by tenantId [{}], entityId [{}] and pageLink [{}]", | ||
90 | - tenantId, entityId, pageLink); | ||
91 | - List<EntityViewEntity> entityViewEntities = findPageWithTextSearch( | ||
92 | - ENTITY_VIEW_BY_TENANT_AND_ENTITY_AND_SEARCH_TEXT, | ||
93 | - Arrays.asList(eq(CUSTOMER_ID_PROPERTY, entityId), eq(TENANT_ID_PROPERTY, tenantId)), | ||
94 | - pageLink); | ||
95 | - log.trace("Found entity views [{}] by tenantId [{}], entityId [{}] and pageLink [{}]", | ||
96 | - entityViewEntities, tenantId, entityId, pageLink); | ||
97 | - return DaoUtil.convertDataList(entityViewEntities); | ||
98 | - } | ||
99 | - | ||
100 | - @Override | ||
101 | public List<EntityView> findEntityViewsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { | 100 | public List<EntityView> findEntityViewsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) { |
102 | log.debug("Try to find entity views by tenantId [{}], customerId[{}] and pageLink [{}]", | 101 | log.debug("Try to find entity views by tenantId [{}], customerId[{}] and pageLink [{}]", |
103 | tenantId, customerId, pageLink); | 102 | tenantId, customerId, pageLink); |
@@ -111,26 +110,6 @@ public class CassandraEntityViewDao extends CassandraAbstractSearchTextDao<Entit | @@ -111,26 +110,6 @@ public class CassandraEntityViewDao extends CassandraAbstractSearchTextDao<Entit | ||
111 | } | 110 | } |
112 | 111 | ||
113 | @Override | 112 | @Override |
114 | - public List<EntityView> findEntityViewsByTenantIdAndCustomerIdAndEntityId(UUID tenantId, | ||
115 | - UUID customerId, | ||
116 | - UUID entityId, | ||
117 | - TextPageLink pageLink) { | ||
118 | - | ||
119 | - log.debug("Try to find entity views by tenantId [{}], customerId [{}], entityId [{}] and pageLink [{}]", | ||
120 | - tenantId, customerId, entityId, pageLink); | ||
121 | - List<EntityViewEntity> entityViewEntities = findPageWithTextSearch( | ||
122 | - ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_ENTITY_AND_SEARCH_TEXT, | ||
123 | - Arrays.asList( | ||
124 | - eq(TENANT_ID_PROPERTY, tenantId), | ||
125 | - eq(CUSTOMER_ID_PROPERTY, customerId), | ||
126 | - eq(ENTITY_ID_COLUMN, entityId)), | ||
127 | - pageLink); | ||
128 | - log.trace("Found devices [{}] by tenantId [{}], customerId [{}], entityId [{}] and pageLink [{}]", | ||
129 | - entityViewEntities, tenantId, customerId, entityId, pageLink); | ||
130 | - return DaoUtil.convertDataList(entityViewEntities); | ||
131 | - } | ||
132 | - | ||
133 | - @Override | ||
134 | public ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId) { | 113 | public ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId) { |
135 | log.debug("Try to find entity views by tenantId [{}] and entityId [{}]", tenantId, entityId); | 114 | log.debug("Try to find entity views by tenantId [{}] and entityId [{}]", tenantId, entityId); |
136 | Select.Where query = select().from(getColumnFamilyName()).where(); | 115 | Select.Where query = select().from(getColumnFamilyName()).where(); |
@@ -57,18 +57,6 @@ public interface EntityViewDao extends Dao<EntityView> { | @@ -57,18 +57,6 @@ public interface EntityViewDao extends Dao<EntityView> { | ||
57 | Optional<EntityView> findEntityViewByTenantIdAndName(UUID tenantId, String name); | 57 | Optional<EntityView> findEntityViewByTenantIdAndName(UUID tenantId, String name); |
58 | 58 | ||
59 | /** | 59 | /** |
60 | - * Find entity views by tenantId, entityId and page link. | ||
61 | - * | ||
62 | - * @param tenantId the tenantId | ||
63 | - * @param entityId the entityId | ||
64 | - * @param pageLink the page link | ||
65 | - * @return the list of entity view objects | ||
66 | - */ | ||
67 | - List<EntityView> findEntityViewByTenantIdAndEntityId(UUID tenantId, | ||
68 | - UUID entityId, | ||
69 | - TextPageLink pageLink); | ||
70 | - | ||
71 | - /** | ||
72 | * Find entity views by tenantId, customerId and page link. | 60 | * Find entity views by tenantId, customerId and page link. |
73 | * | 61 | * |
74 | * @param tenantId the tenantId | 62 | * @param tenantId the tenantId |
@@ -80,19 +68,6 @@ public interface EntityViewDao extends Dao<EntityView> { | @@ -80,19 +68,6 @@ public interface EntityViewDao extends Dao<EntityView> { | ||
80 | UUID customerId, | 68 | UUID customerId, |
81 | TextPageLink pageLink); | 69 | TextPageLink pageLink); |
82 | 70 | ||
83 | - /** | ||
84 | - * Find entity views by tenantId, customerId, entityId and page link. | ||
85 | - * | ||
86 | - * @param tenantId the tenantId | ||
87 | - * @param customerId the customerId | ||
88 | - * @param entityId the entityId | ||
89 | - * @param pageLink the page link | ||
90 | - * @return the list of entity view objects | ||
91 | - */ | ||
92 | - List<EntityView> findEntityViewsByTenantIdAndCustomerIdAndEntityId(UUID tenantId, | ||
93 | - UUID customerId, | ||
94 | - UUID entityId, | ||
95 | - TextPageLink pageLink); | ||
96 | 71 | ||
97 | ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId); | 72 | ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId); |
98 | } | 73 | } |
@@ -16,14 +16,12 @@ | @@ -16,14 +16,12 @@ | ||
16 | package org.thingsboard.server.dao.entityview; | 16 | package org.thingsboard.server.dao.entityview; |
17 | 17 | ||
18 | import com.google.common.util.concurrent.ListenableFuture; | 18 | import com.google.common.util.concurrent.ListenableFuture; |
19 | -import org.thingsboard.server.common.data.Device; | ||
20 | -import org.thingsboard.server.common.data.EntitySubtype; | ||
21 | -import org.thingsboard.server.common.data.EntityType; | ||
22 | import org.thingsboard.server.common.data.EntityView; | 19 | import org.thingsboard.server.common.data.EntityView; |
23 | -import org.thingsboard.server.common.data.Tenant; | ||
24 | -import org.thingsboard.server.common.data.device.DeviceSearchQuery; | ||
25 | import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery; | 20 | import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery; |
26 | -import org.thingsboard.server.common.data.id.*; | 21 | +import org.thingsboard.server.common.data.id.CustomerId; |
22 | +import org.thingsboard.server.common.data.id.EntityId; | ||
23 | +import org.thingsboard.server.common.data.id.EntityViewId; | ||
24 | +import org.thingsboard.server.common.data.id.TenantId; | ||
27 | import org.thingsboard.server.common.data.page.TextPageData; | 25 | import org.thingsboard.server.common.data.page.TextPageData; |
28 | import org.thingsboard.server.common.data.page.TextPageLink; | 26 | import org.thingsboard.server.common.data.page.TextPageLink; |
29 | 27 | ||
@@ -36,8 +34,6 @@ public interface EntityViewService { | @@ -36,8 +34,6 @@ public interface EntityViewService { | ||
36 | 34 | ||
37 | EntityView findEntityViewById(EntityViewId entityViewId); | 35 | EntityView findEntityViewById(EntityViewId entityViewId); |
38 | 36 | ||
39 | - EntityView findEntityViewByTenantIdAndName(TenantId tenantId, String name); | ||
40 | - | ||
41 | EntityView saveEntityView(EntityView entityView); | 37 | EntityView saveEntityView(EntityView entityView); |
42 | 38 | ||
43 | EntityView assignEntityViewToCustomer(EntityViewId entityViewId, CustomerId customerId); | 39 | EntityView assignEntityViewToCustomer(EntityViewId entityViewId, CustomerId customerId); |
@@ -48,19 +44,11 @@ public interface EntityViewService { | @@ -48,19 +44,11 @@ public interface EntityViewService { | ||
48 | 44 | ||
49 | TextPageData<EntityView> findEntityViewByTenantId(TenantId tenantId, TextPageLink pageLink); | 45 | TextPageData<EntityView> findEntityViewByTenantId(TenantId tenantId, TextPageLink pageLink); |
50 | 46 | ||
51 | - TextPageData<EntityView> findEntityViewByTenantIdAndEntityId(TenantId tenantId, EntityId entityId, | ||
52 | - TextPageLink pageLink); | ||
53 | - | ||
54 | - void deleteEntityViewByTenantId(TenantId tenantId); | 47 | + void deleteEntityViewsByTenantId(TenantId tenantId); |
55 | 48 | ||
56 | TextPageData<EntityView> findEntityViewsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, | 49 | TextPageData<EntityView> findEntityViewsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, |
57 | TextPageLink pageLink); | 50 | TextPageLink pageLink); |
58 | 51 | ||
59 | - TextPageData<EntityView> findEntityViewsByTenantIdAndCustomerIdAndEntityId(TenantId tenantId, | ||
60 | - CustomerId customerId, | ||
61 | - EntityId entityId, | ||
62 | - TextPageLink pageLink); | ||
63 | - | ||
64 | void unassignCustomerEntityViews(TenantId tenantId, CustomerId customerId); | 52 | void unassignCustomerEntityViews(TenantId tenantId, CustomerId customerId); |
65 | 53 | ||
66 | ListenableFuture<EntityView> findEntityViewByIdAsync(EntityViewId entityViewId); | 54 | ListenableFuture<EntityView> findEntityViewByIdAsync(EntityViewId entityViewId); |
@@ -96,15 +96,6 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | @@ -96,15 +96,6 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | ||
96 | return entityViewDao.findById(entityViewId.getId()); | 96 | return entityViewDao.findById(entityViewId.getId()); |
97 | } | 97 | } |
98 | 98 | ||
99 | - @Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#tenantId, #name}") | ||
100 | - @Override | ||
101 | - public EntityView findEntityViewByTenantIdAndName(TenantId tenantId, String name) { | ||
102 | - log.trace("Executing findEntityViewByTenantIdAndName [{}][{}]", tenantId, name); | ||
103 | - validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | ||
104 | - return entityViewDao.findEntityViewByTenantIdAndName(tenantId.getId(), name) | ||
105 | - .orElse(null); | ||
106 | - } | ||
107 | - | ||
108 | @CacheEvict(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityView.tenantId, #entityView.name}") | 99 | @CacheEvict(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityView.tenantId, #entityView.name}") |
109 | @Override | 100 | @Override |
110 | public EntityView saveEntityView(EntityView entityView) { | 101 | public EntityView saveEntityView(EntityView entityView) { |
@@ -187,24 +178,8 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | @@ -187,24 +178,8 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | ||
187 | } | 178 | } |
188 | 179 | ||
189 | @Override | 180 | @Override |
190 | - public TextPageData<EntityView> findEntityViewByTenantIdAndEntityId(TenantId tenantId, EntityId entityId, | ||
191 | - TextPageLink pageLink) { | ||
192 | - | ||
193 | - log.trace("Executing findEntityViewByTenantIdAndType, tenantId [{}], entityId [{}], pageLink [{}]", | ||
194 | - tenantId, entityId, pageLink); | ||
195 | - | ||
196 | - validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | ||
197 | - validateString(entityId.toString(), "Incorrect entityId " + entityId.toString()); | ||
198 | - validatePageLink(pageLink, INCORRECT_PAGE_LINK + pageLink); | ||
199 | - List<EntityView> entityViews = entityViewDao.findEntityViewByTenantIdAndEntityId(tenantId.getId(), | ||
200 | - entityId.getId(), pageLink); | ||
201 | - | ||
202 | - return new TextPageData<>(entityViews, pageLink); | ||
203 | - } | ||
204 | - | ||
205 | - @Override | ||
206 | - public void deleteEntityViewByTenantId(TenantId tenantId) { | ||
207 | - log.trace("Executing deleteEntityViewByTenantId, tenantId [{}]", tenantId); | 181 | + public void deleteEntityViewsByTenantId(TenantId tenantId) { |
182 | + log.trace("Executing deleteEntityViewsByTenantId, tenantId [{}]", tenantId); | ||
208 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | 183 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
209 | tenantEntityViewRemover.removeEntities(tenantId); | 184 | tenantEntityViewRemover.removeEntities(tenantId); |
210 | } | 185 | } |
@@ -226,25 +201,6 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | @@ -226,25 +201,6 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti | ||
226 | } | 201 | } |
227 | 202 | ||
228 | @Override | 203 | @Override |
229 | - public TextPageData<EntityView> findEntityViewsByTenantIdAndCustomerIdAndEntityId(TenantId tenantId, | ||
230 | - CustomerId customerId, | ||
231 | - EntityId entityId, | ||
232 | - TextPageLink pageLink) { | ||
233 | - | ||
234 | - log.trace("Executing findEntityViewsByTenantIdAndCustomerIdAndType, tenantId [{}], customerId [{}]," + | ||
235 | - " entityId [{}], pageLink [{}]", tenantId, customerId, entityId, pageLink); | ||
236 | - | ||
237 | - validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | ||
238 | - validateId(customerId, INCORRECT_CUSTOMER_ID + customerId); | ||
239 | - validateString(entityId.toString(), "Incorrect entityId " + entityId.toString()); | ||
240 | - validatePageLink(pageLink, INCORRECT_PAGE_LINK + pageLink); | ||
241 | - List<EntityView> entityViews = entityViewDao.findEntityViewsByTenantIdAndCustomerIdAndEntityId( | ||
242 | - tenantId.getId(), customerId.getId(), entityId.getId(), pageLink); | ||
243 | - | ||
244 | - return new TextPageData<>(entityViews, pageLink); | ||
245 | - } | ||
246 | - | ||
247 | - @Override | ||
248 | public void unassignCustomerEntityViews(TenantId tenantId, CustomerId customerId) { | 204 | public void unassignCustomerEntityViews(TenantId tenantId, CustomerId customerId) { |
249 | log.trace("Executing unassignCustomerEntityViews, tenantId [{}], customerId [{}]", tenantId, customerId); | 205 | log.trace("Executing unassignCustomerEntityViews, tenantId [{}], customerId [{}]", tenantId, customerId); |
250 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | 206 | validateId(tenantId, INCORRECT_TENANT_ID + tenantId); |
@@ -150,15 +150,13 @@ public class ModelConstants { | @@ -150,15 +150,13 @@ public class ModelConstants { | ||
150 | public static final String ENTITY_VIEW_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; | 150 | public static final String ENTITY_VIEW_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY; |
151 | public static final String ENTITY_VIEW_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; | 151 | public static final String ENTITY_VIEW_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY; |
152 | public static final String ENTITY_VIEW_NAME_PROPERTY = DEVICE_NAME_PROPERTY; | 152 | public static final String ENTITY_VIEW_NAME_PROPERTY = DEVICE_NAME_PROPERTY; |
153 | - public static final String ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_ENTITY_AND_SEARCH_TEXT = "entity_views_by_tenant_and_customer_and_entity"; | ||
154 | - public static final String ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_SEARCH_TEXT = "entity_views_by_tenant_and_customer"; | 153 | + public static final String ENTITY_VIEW_BY_TENANT_AND_CUSTOMER_AND_SEARCH_TEXT = "entity_view_by_tenant_and_customer"; |
155 | public static final String ENTITY_VIEW_KEYS_PROPERTY = "keys"; | 154 | public static final String ENTITY_VIEW_KEYS_PROPERTY = "keys"; |
156 | public static final String ENTITY_VIEW_START_TS_PROPERTY = "start_ts"; | 155 | public static final String ENTITY_VIEW_START_TS_PROPERTY = "start_ts"; |
157 | public static final String ENTITY_VIEW_END_TS_PROPERTY = "end_ts"; | 156 | public static final String ENTITY_VIEW_END_TS_PROPERTY = "end_ts"; |
158 | public static final String ENTITY_VIEW_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY; | 157 | public static final String ENTITY_VIEW_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY; |
159 | public static final String ENTITY_VIEW_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "entity_view_by_tenant_and_search_text"; | 158 | public static final String ENTITY_VIEW_BY_TENANT_AND_SEARCH_TEXT_COLUMN_FAMILY_NAME = "entity_view_by_tenant_and_search_text"; |
160 | - public static final String ENTITY_VIEW_BY_TENANT_AND_NAME = "entity_views_by_tenant_and_name"; | ||
161 | - public static final String ENTITY_VIEW_BY_TENANT_AND_ENTITY_AND_SEARCH_TEXT = "entity_view_by_tenant_and_entity"; | 159 | + public static final String ENTITY_VIEW_BY_TENANT_AND_NAME = "entity_view_by_tenant_and_name"; |
162 | 160 | ||
163 | /** | 161 | /** |
164 | * Cassandra audit log constants. | 162 | * Cassandra audit log constants. |
@@ -24,10 +24,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; | @@ -24,10 +24,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ||
24 | import lombok.Data; | 24 | import lombok.Data; |
25 | import lombok.EqualsAndHashCode; | 25 | import lombok.EqualsAndHashCode; |
26 | import lombok.ToString; | 26 | import lombok.ToString; |
27 | +import lombok.extern.slf4j.Slf4j; | ||
27 | import org.hibernate.annotations.Type; | 28 | import org.hibernate.annotations.Type; |
28 | import org.thingsboard.server.common.data.EntityType; | 29 | import org.thingsboard.server.common.data.EntityType; |
29 | import org.thingsboard.server.common.data.EntityView; | 30 | import org.thingsboard.server.common.data.EntityView; |
30 | -import org.thingsboard.server.common.data.id.*; | 31 | +import org.thingsboard.server.common.data.id.CustomerId; |
32 | +import org.thingsboard.server.common.data.id.EntityIdFactory; | ||
33 | +import org.thingsboard.server.common.data.id.EntityViewId; | ||
34 | +import org.thingsboard.server.common.data.id.TenantId; | ||
31 | import org.thingsboard.server.common.data.objects.TelemetryEntityView; | 35 | import org.thingsboard.server.common.data.objects.TelemetryEntityView; |
32 | import org.thingsboard.server.dao.model.ModelConstants; | 36 | import org.thingsboard.server.dao.model.ModelConstants; |
33 | import org.thingsboard.server.dao.model.SearchTextEntity; | 37 | import org.thingsboard.server.dao.model.SearchTextEntity; |
@@ -48,6 +52,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; | @@ -48,6 +52,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.ID_PROPERTY; | ||
48 | @Table(name = ENTITY_VIEW_TABLE_FAMILY_NAME) | 52 | @Table(name = ENTITY_VIEW_TABLE_FAMILY_NAME) |
49 | @EqualsAndHashCode | 53 | @EqualsAndHashCode |
50 | @ToString | 54 | @ToString |
55 | +@Slf4j | ||
51 | public class EntityViewEntity implements SearchTextEntity<EntityView> { | 56 | public class EntityViewEntity implements SearchTextEntity<EntityView> { |
52 | 57 | ||
53 | @PartitionKey(value = 0) | 58 | @PartitionKey(value = 0) |
@@ -112,7 +117,7 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> { | @@ -112,7 +117,7 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> { | ||
112 | try { | 117 | try { |
113 | this.keys = mapper.writeValueAsString(entityView.getKeys()); | 118 | this.keys = mapper.writeValueAsString(entityView.getKeys()); |
114 | } catch (IOException e) { | 119 | } catch (IOException e) { |
115 | - e.printStackTrace(); | 120 | + log.error("Unable to serialize entity view keys!", e); |
116 | } | 121 | } |
117 | this.startTs = entityView.getStartTimeMs(); | 122 | this.startTs = entityView.getStartTimeMs(); |
118 | this.endTs = entityView.getEndTimeMs(); | 123 | this.endTs = entityView.getEndTimeMs(); |
@@ -142,7 +147,7 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> { | @@ -142,7 +147,7 @@ public class EntityViewEntity implements SearchTextEntity<EntityView> { | ||
142 | try { | 147 | try { |
143 | entityView.setKeys(mapper.readValue(keys, TelemetryEntityView.class)); | 148 | entityView.setKeys(mapper.readValue(keys, TelemetryEntityView.class)); |
144 | } catch (IOException e) { | 149 | } catch (IOException e) { |
145 | - e.printStackTrace(); | 150 | + log.error("Unable to read entity view keys!", e); |
146 | } | 151 | } |
147 | entityView.setStartTimeMs(startTs); | 152 | entityView.setStartTimeMs(startTs); |
148 | entityView.setEndTimeMs(endTs); | 153 | entityView.setEndTimeMs(endTs); |
@@ -20,18 +20,26 @@ import com.fasterxml.jackson.databind.JsonNode; | @@ -20,18 +20,26 @@ import com.fasterxml.jackson.databind.JsonNode; | ||
20 | import com.fasterxml.jackson.databind.ObjectMapper; | 20 | import com.fasterxml.jackson.databind.ObjectMapper; |
21 | import lombok.Data; | 21 | import lombok.Data; |
22 | import lombok.EqualsAndHashCode; | 22 | import lombok.EqualsAndHashCode; |
23 | +import lombok.extern.slf4j.Slf4j; | ||
23 | import org.hibernate.annotations.Type; | 24 | import org.hibernate.annotations.Type; |
24 | import org.hibernate.annotations.TypeDef; | 25 | import org.hibernate.annotations.TypeDef; |
25 | import org.thingsboard.server.common.data.EntityType; | 26 | import org.thingsboard.server.common.data.EntityType; |
26 | import org.thingsboard.server.common.data.EntityView; | 27 | import org.thingsboard.server.common.data.EntityView; |
27 | -import org.thingsboard.server.common.data.id.*; | 28 | +import org.thingsboard.server.common.data.id.CustomerId; |
29 | +import org.thingsboard.server.common.data.id.EntityIdFactory; | ||
30 | +import org.thingsboard.server.common.data.id.EntityViewId; | ||
31 | +import org.thingsboard.server.common.data.id.TenantId; | ||
28 | import org.thingsboard.server.common.data.objects.TelemetryEntityView; | 32 | import org.thingsboard.server.common.data.objects.TelemetryEntityView; |
29 | import org.thingsboard.server.dao.model.BaseSqlEntity; | 33 | import org.thingsboard.server.dao.model.BaseSqlEntity; |
30 | import org.thingsboard.server.dao.model.ModelConstants; | 34 | import org.thingsboard.server.dao.model.ModelConstants; |
31 | import org.thingsboard.server.dao.model.SearchTextEntity; | 35 | import org.thingsboard.server.dao.model.SearchTextEntity; |
32 | import org.thingsboard.server.dao.util.mapping.JsonStringType; | 36 | import org.thingsboard.server.dao.util.mapping.JsonStringType; |
33 | 37 | ||
34 | -import javax.persistence.*; | 38 | +import javax.persistence.Column; |
39 | +import javax.persistence.Entity; | ||
40 | +import javax.persistence.EnumType; | ||
41 | +import javax.persistence.Enumerated; | ||
42 | +import javax.persistence.Table; | ||
35 | import java.io.IOException; | 43 | import java.io.IOException; |
36 | 44 | ||
37 | import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPERTY; | 45 | import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPERTY; |
@@ -45,6 +53,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPER | @@ -45,6 +53,7 @@ import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPER | ||
45 | @Entity | 53 | @Entity |
46 | @TypeDef(name = "json", typeClass = JsonStringType.class) | 54 | @TypeDef(name = "json", typeClass = JsonStringType.class) |
47 | @Table(name = ModelConstants.ENTITY_VIEW_TABLE_FAMILY_NAME) | 55 | @Table(name = ModelConstants.ENTITY_VIEW_TABLE_FAMILY_NAME) |
56 | +@Slf4j | ||
48 | public class EntityViewEntity extends BaseSqlEntity<EntityView> implements SearchTextEntity<EntityView> { | 57 | public class EntityViewEntity extends BaseSqlEntity<EntityView> implements SearchTextEntity<EntityView> { |
49 | 58 | ||
50 | @Column(name = ModelConstants.ENTITY_VIEW_ENTITY_ID_PROPERTY) | 59 | @Column(name = ModelConstants.ENTITY_VIEW_ENTITY_ID_PROPERTY) |
@@ -103,7 +112,7 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc | @@ -103,7 +112,7 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc | ||
103 | try { | 112 | try { |
104 | this.keys = mapper.writeValueAsString(entityView.getKeys()); | 113 | this.keys = mapper.writeValueAsString(entityView.getKeys()); |
105 | } catch (IOException e) { | 114 | } catch (IOException e) { |
106 | - e.printStackTrace(); | 115 | + log.error("Unable to serialize entity view keys!", e); |
107 | } | 116 | } |
108 | this.startTs = entityView.getStartTimeMs(); | 117 | this.startTs = entityView.getStartTimeMs(); |
109 | this.endTs = entityView.getEndTimeMs(); | 118 | this.endTs = entityView.getEndTimeMs(); |
@@ -139,7 +148,7 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc | @@ -139,7 +148,7 @@ public class EntityViewEntity extends BaseSqlEntity<EntityView> implements Searc | ||
139 | try { | 148 | try { |
140 | entityView.setKeys(mapper.readValue(keys, TelemetryEntityView.class)); | 149 | entityView.setKeys(mapper.readValue(keys, TelemetryEntityView.class)); |
141 | } catch (IOException e) { | 150 | } catch (IOException e) { |
142 | - e.printStackTrace(); | 151 | + log.error("Unable to read entity view keys!", e); |
143 | } | 152 | } |
144 | entityView.setStartTimeMs(startTs); | 153 | entityView.setStartTimeMs(startTs); |
145 | entityView.setEndTimeMs(endTs); | 154 | entityView.setEndTimeMs(endTs); |
@@ -41,16 +41,6 @@ public interface EntityViewRepository extends CrudRepository<EntityViewEntity, S | @@ -41,16 +41,6 @@ public interface EntityViewRepository extends CrudRepository<EntityViewEntity, S | ||
41 | Pageable pageable); | 41 | Pageable pageable); |
42 | 42 | ||
43 | @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " + | 43 | @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " + |
44 | - "AND e.entityId = :entityId " + | ||
45 | - "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + | ||
46 | - "AND e.id > :idOffset ORDER BY e.id") | ||
47 | - List<EntityViewEntity> findByTenantIdAndEntityId(@Param("tenantId") String tenantId, | ||
48 | - @Param("entityId") String entityId, | ||
49 | - @Param("textSearch") String textSearch, | ||
50 | - @Param("idOffset") String idOffset, | ||
51 | - Pageable pageable); | ||
52 | - | ||
53 | - @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " + | ||
54 | "AND e.customerId = :customerId " + | 44 | "AND e.customerId = :customerId " + |
55 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:searchText, '%')) " + | 45 | "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:searchText, '%')) " + |
56 | "AND e.id > :idOffset ORDER BY e.id") | 46 | "AND e.id > :idOffset ORDER BY e.id") |
@@ -60,25 +50,7 @@ public interface EntityViewRepository extends CrudRepository<EntityViewEntity, S | @@ -60,25 +50,7 @@ public interface EntityViewRepository extends CrudRepository<EntityViewEntity, S | ||
60 | @Param("idOffset") String idOffset, | 50 | @Param("idOffset") String idOffset, |
61 | Pageable pageable); | 51 | Pageable pageable); |
62 | 52 | ||
63 | - @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " + | ||
64 | - "AND e.customerId = :customerId " + | ||
65 | - "AND e.entityId = :entityId " + | ||
66 | - "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%')) " + | ||
67 | - "AND e.id > :idOffset ORDER BY e.id") | ||
68 | - List<EntityViewEntity> findByTenantIdAndCustomerIdAndEntityId(@Param("tenantId") String tenantId, | ||
69 | - @Param("customerId") String customerId, | ||
70 | - @Param("entityId") String entityId, | ||
71 | - @Param("textSearch") String textSearch, | ||
72 | - @Param("idOffset") String idOffset, | ||
73 | - Pageable pageable); | ||
74 | - | ||
75 | EntityViewEntity findByTenantIdAndName(String tenantId, String name); | 53 | EntityViewEntity findByTenantIdAndName(String tenantId, String name); |
76 | 54 | ||
77 | - List<EntityViewEntity> findAllByTenantIdAndCustomerIdAndIdIn(String tenantId, | ||
78 | - String customerId, | ||
79 | - List<String> entityViewsIds); | ||
80 | - | ||
81 | - List<EntityViewEntity> findAllByTenantIdAndIdIn(String tenantId, List<String> entityViewsIds); | ||
82 | - | ||
83 | List<EntityViewEntity> findAllByTenantIdAndEntityId(String tenantId, String entityId); | 55 | List<EntityViewEntity> findAllByTenantIdAndEntityId(String tenantId, String entityId); |
84 | } | 56 | } |
@@ -53,7 +53,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | @@ -53,7 +53,7 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | ||
53 | implements EntityViewDao { | 53 | implements EntityViewDao { |
54 | 54 | ||
55 | @Autowired | 55 | @Autowired |
56 | - EntityViewRepository entityViewRepository; | 56 | + private EntityViewRepository entityViewRepository; |
57 | 57 | ||
58 | @Override | 58 | @Override |
59 | protected Class<EntityViewEntity> getEntityClass() { | 59 | protected Class<EntityViewEntity> getEntityClass() { |
@@ -82,19 +82,6 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | @@ -82,19 +82,6 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | ||
82 | } | 82 | } |
83 | 83 | ||
84 | @Override | 84 | @Override |
85 | - public List<EntityView> findEntityViewByTenantIdAndEntityId(UUID tenantId, | ||
86 | - UUID entityId, | ||
87 | - TextPageLink pageLink) { | ||
88 | - return DaoUtil.convertDataList( | ||
89 | - entityViewRepository.findByTenantIdAndEntityId( | ||
90 | - fromTimeUUID(tenantId), | ||
91 | - fromTimeUUID(entityId), | ||
92 | - Objects.toString(pageLink.getTextSearch(), ""), | ||
93 | - pageLink.getIdOffset() == null ? NULL_UUID_STR : fromTimeUUID(pageLink.getIdOffset()), | ||
94 | - new PageRequest(0, pageLink.getLimit()))); | ||
95 | - } | ||
96 | - | ||
97 | - @Override | ||
98 | public List<EntityView> findEntityViewsByTenantIdAndCustomerId(UUID tenantId, | 85 | public List<EntityView> findEntityViewsByTenantIdAndCustomerId(UUID tenantId, |
99 | UUID customerId, | 86 | UUID customerId, |
100 | TextPageLink pageLink) { | 87 | TextPageLink pageLink) { |
@@ -109,22 +96,6 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | @@ -109,22 +96,6 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, | ||
109 | } | 96 | } |
110 | 97 | ||
111 | @Override | 98 | @Override |
112 | - public List<EntityView> findEntityViewsByTenantIdAndCustomerIdAndEntityId(UUID tenantId, | ||
113 | - UUID customerId, | ||
114 | - UUID entityId, | ||
115 | - TextPageLink pageLink) { | ||
116 | - return DaoUtil.convertDataList( | ||
117 | - entityViewRepository.findByTenantIdAndCustomerIdAndEntityId( | ||
118 | - fromTimeUUID(tenantId), | ||
119 | - fromTimeUUID(customerId), | ||
120 | - fromTimeUUID(entityId), | ||
121 | - Objects.toString(pageLink.getTextSearch(), ""), | ||
122 | - pageLink.getIdOffset() == null ? NULL_UUID_STR : fromTimeUUID(pageLink.getIdOffset()), | ||
123 | - new PageRequest(0, pageLink.getLimit()) | ||
124 | - )); | ||
125 | - } | ||
126 | - | ||
127 | - @Override | ||
128 | public ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId) { | 99 | public ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId) { |
129 | return service.submit(() -> DaoUtil.convertDataList( | 100 | return service.submit(() -> DaoUtil.convertDataList( |
130 | entityViewRepository.findAllByTenantIdAndEntityId(UUIDConverter.fromTimeUUID(tenantId), UUIDConverter.fromTimeUUID(entityId)))); | 101 | entityViewRepository.findAllByTenantIdAndEntityId(UUIDConverter.fromTimeUUID(tenantId), UUIDConverter.fromTimeUUID(entityId)))); |
@@ -29,6 +29,7 @@ import org.thingsboard.server.dao.customer.CustomerService; | @@ -29,6 +29,7 @@ import org.thingsboard.server.dao.customer.CustomerService; | ||
29 | import org.thingsboard.server.dao.dashboard.DashboardService; | 29 | import org.thingsboard.server.dao.dashboard.DashboardService; |
30 | import org.thingsboard.server.dao.device.DeviceService; | 30 | import org.thingsboard.server.dao.device.DeviceService; |
31 | import org.thingsboard.server.dao.entity.AbstractEntityService; | 31 | import org.thingsboard.server.dao.entity.AbstractEntityService; |
32 | +import org.thingsboard.server.dao.entityview.EntityViewService; | ||
32 | import org.thingsboard.server.dao.exception.DataValidationException; | 33 | import org.thingsboard.server.dao.exception.DataValidationException; |
33 | import org.thingsboard.server.dao.rule.RuleChainService; | 34 | import org.thingsboard.server.dao.rule.RuleChainService; |
34 | import org.thingsboard.server.dao.service.DataValidator; | 35 | import org.thingsboard.server.dao.service.DataValidator; |
@@ -64,6 +65,9 @@ public class TenantServiceImpl extends AbstractEntityService implements TenantSe | @@ -64,6 +65,9 @@ public class TenantServiceImpl extends AbstractEntityService implements TenantSe | ||
64 | private DeviceService deviceService; | 65 | private DeviceService deviceService; |
65 | 66 | ||
66 | @Autowired | 67 | @Autowired |
68 | + private EntityViewService entityViewService; | ||
69 | + | ||
70 | + @Autowired | ||
67 | private WidgetsBundleService widgetsBundleService; | 71 | private WidgetsBundleService widgetsBundleService; |
68 | 72 | ||
69 | @Autowired | 73 | @Autowired |
@@ -103,6 +107,7 @@ public class TenantServiceImpl extends AbstractEntityService implements TenantSe | @@ -103,6 +107,7 @@ public class TenantServiceImpl extends AbstractEntityService implements TenantSe | ||
103 | dashboardService.deleteDashboardsByTenantId(tenantId); | 107 | dashboardService.deleteDashboardsByTenantId(tenantId); |
104 | assetService.deleteAssetsByTenantId(tenantId); | 108 | assetService.deleteAssetsByTenantId(tenantId); |
105 | deviceService.deleteDevicesByTenantId(tenantId); | 109 | deviceService.deleteDevicesByTenantId(tenantId); |
110 | + entityViewService.deleteEntityViewsByTenantId(tenantId); | ||
106 | userService.deleteTenantAdmins(tenantId); | 111 | userService.deleteTenantAdmins(tenantId); |
107 | ruleChainService.deleteRuleChainsByTenantId(tenantId); | 112 | ruleChainService.deleteRuleChainsByTenantId(tenantId); |
108 | tenantDao.removeById(tenantId.getId()); | 113 | tenantDao.removeById(tenantId.getId()); |
@@ -674,7 +674,7 @@ CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( | @@ -674,7 +674,7 @@ CREATE TABLE IF NOT EXISTS thingsboard.entity_views ( | ||
674 | PRIMARY KEY (id, entity_id, tenant_id, customer_id) | 674 | PRIMARY KEY (id, entity_id, tenant_id, customer_id) |
675 | ); | 675 | ); |
676 | 676 | ||
677 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_name AS | 677 | +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_name AS |
678 | SELECT * | 678 | SELECT * |
679 | from thingsboard.entity_views | 679 | from thingsboard.entity_views |
680 | WHERE tenant_id IS NOT NULL | 680 | WHERE tenant_id IS NOT NULL |
@@ -696,18 +696,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_sea | @@ -696,18 +696,7 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_sea | ||
696 | PRIMARY KEY (tenant_id, search_text, id, customer_id, entity_id) | 696 | PRIMARY KEY (tenant_id, search_text, id, customer_id, entity_id) |
697 | WITH CLUSTERING ORDER BY (search_text ASC, id DESC, customer_id DESC); | 697 | WITH CLUSTERING ORDER BY (search_text ASC, id DESC, customer_id DESC); |
698 | 698 | ||
699 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_entity AS | ||
700 | - SELECT * | ||
701 | - from thingsboard.entity_views | ||
702 | - WHERE tenant_id IS NOT NULL | ||
703 | - AND customer_id IS NOT NULL | ||
704 | - AND entity_id IS NOT NULL | ||
705 | - AND search_text IS NOT NULL | ||
706 | - AND id IS NOT NULL | ||
707 | - PRIMARY KEY (tenant_id, entity_id, search_text, id, customer_id) | ||
708 | - WITH CLUSTERING ORDER BY (entity_id ASC, search_text ASC, id DESC, customer_id DESC); | ||
709 | - | ||
710 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer AS | 699 | +CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_view_by_tenant_and_customer AS |
711 | SELECT * | 700 | SELECT * |
712 | from thingsboard.entity_views | 701 | from thingsboard.entity_views |
713 | WHERE tenant_id IS NOT NULL | 702 | WHERE tenant_id IS NOT NULL |
@@ -717,14 +706,3 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_cu | @@ -717,14 +706,3 @@ CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_cu | ||
717 | AND id IS NOT NULL | 706 | AND id IS NOT NULL |
718 | PRIMARY KEY (tenant_id, customer_id, search_text, id, entity_id) | 707 | PRIMARY KEY (tenant_id, customer_id, search_text, id, entity_id) |
719 | WITH CLUSTERING ORDER BY (customer_id DESC, search_text ASC, id DESC); | 708 | WITH CLUSTERING ORDER BY (customer_id DESC, search_text ASC, id DESC); |
720 | - | ||
721 | -CREATE MATERIALIZED VIEW IF NOT EXISTS thingsboard.entity_views_by_tenant_and_customer_and_entity AS | ||
722 | - SELECT * | ||
723 | - from thingsboard.entity_views | ||
724 | - WHERE tenant_id IS NOT NULL | ||
725 | - AND customer_id IS NOT NULL | ||
726 | - AND entity_id IS NOT NULL | ||
727 | - AND search_text IS NOT NULL | ||
728 | - AND id IS NOT NULL | ||
729 | - PRIMARY KEY (tenant_id, customer_id, entity_id, search_text, id) | ||
730 | - WITH CLUSTERING ORDER BY (customer_id DESC, entity_id ASC, search_text ASC, id DESC); |
@@ -19,4 +19,4 @@ DROP TABLE IF EXISTS widget_type; | @@ -19,4 +19,4 @@ DROP TABLE IF EXISTS widget_type; | ||
19 | DROP TABLE IF EXISTS widgets_bundle; | 19 | DROP TABLE IF EXISTS widgets_bundle; |
20 | DROP TABLE IF EXISTS rule_node; | 20 | DROP TABLE IF EXISTS rule_node; |
21 | DROP TABLE IF EXISTS rule_chain; | 21 | DROP TABLE IF EXISTS rule_chain; |
22 | -DROP TABLE IF EXISTS entity_views; | ||
22 | +DROP TABLE IF EXISTS entity_views; |