Commit 7ff599f7c40b15202137dcc5def2e286f0bad9cd

Authored by Igor Kulikov
1 parent 680cd1d2

Introduct AssetInfo and EntityViewInfo dtos

Showing 29 changed files with 1119 additions and 246 deletions
... ... @@ -30,6 +30,7 @@ import org.thingsboard.server.common.data.Customer;
30 30 import org.thingsboard.server.common.data.EntitySubtype;
31 31 import org.thingsboard.server.common.data.EntityType;
32 32 import org.thingsboard.server.common.data.asset.Asset;
  33 +import org.thingsboard.server.common.data.asset.AssetInfo;
33 34 import org.thingsboard.server.common.data.asset.AssetSearchQuery;
34 35 import org.thingsboard.server.common.data.audit.ActionType;
35 36 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
... ... @@ -70,6 +71,19 @@ public class AssetController extends BaseController {
70 71 }
71 72
72 73 @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
  74 + @RequestMapping(value = "/asset/info/{assetId}", method = RequestMethod.GET)
  75 + @ResponseBody
  76 + public AssetInfo getAssetInfoById(@PathVariable(ASSET_ID) String strAssetId) throws ThingsboardException {
  77 + checkParameter(ASSET_ID, strAssetId);
  78 + try {
  79 + AssetId assetId = new AssetId(toUUID(strAssetId));
  80 + return checkAssetInfoId(assetId, Operation.READ);
  81 + } catch (Exception e) {
  82 + throw handleException(e);
  83 + }
  84 + }
  85 +
  86 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
73 87 @RequestMapping(value = "/asset", method = RequestMethod.POST)
74 88 @ResponseBody
75 89 public Asset saveAsset(@RequestBody Asset asset) throws ThingsboardException {
... ... @@ -230,6 +244,29 @@ public class AssetController extends BaseController {
230 244 }
231 245
232 246 @PreAuthorize("hasAuthority('TENANT_ADMIN')")
  247 + @RequestMapping(value = "/tenant/assetInfos", params = {"pageSize", "page"}, method = RequestMethod.GET)
  248 + @ResponseBody
  249 + public PageData<AssetInfo> getTenantAssetInfos(
  250 + @RequestParam int pageSize,
  251 + @RequestParam int page,
  252 + @RequestParam(required = false) String type,
  253 + @RequestParam(required = false) String textSearch,
  254 + @RequestParam(required = false) String sortProperty,
  255 + @RequestParam(required = false) String sortOrder) throws ThingsboardException {
  256 + try {
  257 + TenantId tenantId = getCurrentUser().getTenantId();
  258 + PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
  259 + if (type != null && type.trim().length() > 0) {
  260 + return checkNotNull(assetService.findAssetInfosByTenantIdAndType(tenantId, type, pageLink));
  261 + } else {
  262 + return checkNotNull(assetService.findAssetInfosByTenantId(tenantId, pageLink));
  263 + }
  264 + } catch (Exception e) {
  265 + throw handleException(e);
  266 + }
  267 + }
  268 +
  269 + @PreAuthorize("hasAuthority('TENANT_ADMIN')")
233 270 @RequestMapping(value = "/tenant/assets", params = {"assetName"}, method = RequestMethod.GET)
234 271 @ResponseBody
235 272 public Asset getTenantAsset(
... ... @@ -270,6 +307,33 @@ public class AssetController extends BaseController {
270 307 }
271 308
272 309 @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
  310 + @RequestMapping(value = "/customer/{customerId}/assetInfos", params = {"pageSize", "page"}, method = RequestMethod.GET)
  311 + @ResponseBody
  312 + public PageData<AssetInfo> getCustomerAssetInfos(
  313 + @PathVariable("customerId") String strCustomerId,
  314 + @RequestParam int pageSize,
  315 + @RequestParam int page,
  316 + @RequestParam(required = false) String type,
  317 + @RequestParam(required = false) String textSearch,
  318 + @RequestParam(required = false) String sortProperty,
  319 + @RequestParam(required = false) String sortOrder) throws ThingsboardException {
  320 + checkParameter("customerId", strCustomerId);
  321 + try {
  322 + TenantId tenantId = getCurrentUser().getTenantId();
  323 + CustomerId customerId = new CustomerId(toUUID(strCustomerId));
  324 + checkCustomerId(customerId, Operation.READ);
  325 + PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
  326 + if (type != null && type.trim().length() > 0) {
  327 + return checkNotNull(assetService.findAssetInfosByTenantIdAndCustomerIdAndType(tenantId, customerId, type, pageLink));
  328 + } else {
  329 + return checkNotNull(assetService.findAssetInfosByTenantIdAndCustomerId(tenantId, customerId, pageLink));
  330 + }
  331 + } catch (Exception e) {
  332 + throw handleException(e);
  333 + }
  334 + }
  335 +
  336 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
273 337 @RequestMapping(value = "/assets", params = {"assetIds"}, method = RequestMethod.GET)
274 338 @ResponseBody
275 339 public List<Asset> getAssetsByIds(
... ...
... ... @@ -33,6 +33,7 @@ import org.thingsboard.server.common.data.alarm.Alarm;
33 33 import org.thingsboard.server.common.data.alarm.AlarmId;
34 34 import org.thingsboard.server.common.data.alarm.AlarmInfo;
35 35 import org.thingsboard.server.common.data.asset.Asset;
  36 +import org.thingsboard.server.common.data.asset.AssetInfo;
36 37 import org.thingsboard.server.common.data.audit.ActionType;
37 38 import org.thingsboard.server.common.data.exception.ThingsboardErrorCode;
38 39 import org.thingsboard.server.common.data.exception.ThingsboardException;
... ... @@ -396,6 +397,18 @@ public abstract class BaseController {
396 397 }
397 398 }
398 399
  400 + EntityViewInfo checkEntityViewInfoId(EntityViewId entityViewId, Operation operation) throws ThingsboardException {
  401 + try {
  402 + validateId(entityViewId, "Incorrect entityViewId " + entityViewId);
  403 + EntityViewInfo entityView = entityViewService.findEntityViewInfoById(getCurrentUser().getTenantId(), entityViewId);
  404 + checkNotNull(entityView);
  405 + accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE, operation, entityViewId, entityView);
  406 + return entityView;
  407 + } catch (Exception e) {
  408 + throw handleException(e, false);
  409 + }
  410 + }
  411 +
399 412 Asset checkAssetId(AssetId assetId, Operation operation) throws ThingsboardException {
400 413 try {
401 414 validateId(assetId, "Incorrect assetId " + assetId);
... ... @@ -408,6 +421,18 @@ public abstract class BaseController {
408 421 }
409 422 }
410 423
  424 + AssetInfo checkAssetInfoId(AssetId assetId, Operation operation) throws ThingsboardException {
  425 + try {
  426 + validateId(assetId, "Incorrect assetId " + assetId);
  427 + AssetInfo asset = assetService.findAssetInfoById(getCurrentUser().getTenantId(), assetId);
  428 + checkNotNull(asset);
  429 + accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE, operation, assetId, asset);
  430 + return asset;
  431 + } catch (Exception e) {
  432 + throw handleException(e, false);
  433 + }
  434 + }
  435 +
411 436 Alarm checkAlarmId(AlarmId alarmId, Operation operation) throws ThingsboardException {
412 437 try {
413 438 validateId(alarmId, "Incorrect alarmId " + alarmId);
... ...
... ... @@ -29,11 +29,7 @@ import org.springframework.web.bind.annotation.RequestParam;
29 29 import org.springframework.web.bind.annotation.ResponseBody;
30 30 import org.springframework.web.bind.annotation.ResponseStatus;
31 31 import org.springframework.web.bind.annotation.RestController;
32   -import org.thingsboard.server.common.data.Customer;
33   -import org.thingsboard.server.common.data.DataConstants;
34   -import org.thingsboard.server.common.data.EntitySubtype;
35   -import org.thingsboard.server.common.data.EntityType;
36   -import org.thingsboard.server.common.data.EntityView;
  32 +import org.thingsboard.server.common.data.*;
37 33 import org.thingsboard.server.common.data.audit.ActionType;
38 34 import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery;
39 35 import org.thingsboard.server.common.data.exception.ThingsboardException;
... ... @@ -83,6 +79,19 @@ public class EntityViewController extends BaseController {
83 79 }
84 80
85 81 @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
  82 + @RequestMapping(value = "/entityView/info/{entityViewId}", method = RequestMethod.GET)
  83 + @ResponseBody
  84 + public EntityViewInfo getEntityViewInfoById(@PathVariable(ENTITY_VIEW_ID) String strEntityViewId) throws ThingsboardException {
  85 + checkParameter(ENTITY_VIEW_ID, strEntityViewId);
  86 + try {
  87 + EntityViewId entityViewId = new EntityViewId(toUUID(strEntityViewId));
  88 + return checkEntityViewInfoId(entityViewId, Operation.READ);
  89 + } catch (Exception e) {
  90 + throw handleException(e);
  91 + }
  92 + }
  93 +
  94 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
86 95 @RequestMapping(value = "/entityView", method = RequestMethod.POST)
87 96 @ResponseBody
88 97 public EntityView saveEntityView(@RequestBody EntityView entityView) throws ThingsboardException {
... ... @@ -282,6 +291,33 @@ public class EntityViewController extends BaseController {
282 291 }
283 292 }
284 293
  294 + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
  295 + @RequestMapping(value = "/customer/{customerId}/entityViewInfos", params = {"pageSize", "page"}, method = RequestMethod.GET)
  296 + @ResponseBody
  297 + public PageData<EntityViewInfo> getCustomerEntityViewInfos(
  298 + @PathVariable("customerId") String strCustomerId,
  299 + @RequestParam int pageSize,
  300 + @RequestParam int page,
  301 + @RequestParam(required = false) String type,
  302 + @RequestParam(required = false) String textSearch,
  303 + @RequestParam(required = false) String sortProperty,
  304 + @RequestParam(required = false) String sortOrder) throws ThingsboardException {
  305 + checkParameter("customerId", strCustomerId);
  306 + try {
  307 + TenantId tenantId = getCurrentUser().getTenantId();
  308 + CustomerId customerId = new CustomerId(toUUID(strCustomerId));
  309 + checkCustomerId(customerId, Operation.READ);
  310 + PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
  311 + if (type != null && type.trim().length() > 0) {
  312 + return checkNotNull(entityViewService.findEntityViewInfosByTenantIdAndCustomerIdAndType(tenantId, customerId, type, pageLink));
  313 + } else {
  314 + return checkNotNull(entityViewService.findEntityViewInfosByTenantIdAndCustomerId(tenantId, customerId, pageLink));
  315 + }
  316 + } catch (Exception e) {
  317 + throw handleException(e);
  318 + }
  319 + }
  320 +
285 321 @PreAuthorize("hasAuthority('TENANT_ADMIN')")
286 322 @RequestMapping(value = "/tenant/entityViews", params = {"pageSize", "page"}, method = RequestMethod.GET)
287 323 @ResponseBody
... ... @@ -306,6 +342,29 @@ public class EntityViewController extends BaseController {
306 342 }
307 343 }
308 344
  345 + @PreAuthorize("hasAuthority('TENANT_ADMIN')")
  346 + @RequestMapping(value = "/tenant/entityViewInfos", params = {"pageSize", "page"}, method = RequestMethod.GET)
  347 + @ResponseBody
  348 + public PageData<EntityViewInfo> getTenantEntityViewInfos(
  349 + @RequestParam int pageSize,
  350 + @RequestParam int page,
  351 + @RequestParam(required = false) String type,
  352 + @RequestParam(required = false) String textSearch,
  353 + @RequestParam(required = false) String sortProperty,
  354 + @RequestParam(required = false) String sortOrder) throws ThingsboardException {
  355 + try {
  356 + TenantId tenantId = getCurrentUser().getTenantId();
  357 + PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
  358 + if (type != null && type.trim().length() > 0) {
  359 + return checkNotNull(entityViewService.findEntityViewInfosByTenantIdAndType(tenantId, type, pageLink));
  360 + } else {
  361 + return checkNotNull(entityViewService.findEntityViewInfosByTenantId(tenantId, pageLink));
  362 + }
  363 + } catch (Exception e) {
  364 + throw handleException(e);
  365 + }
  366 + }
  367 +
309 368 @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
310 369 @RequestMapping(value = "/entityViews", method = RequestMethod.POST)
311 370 @ResponseBody
... ...
... ... @@ -308,6 +308,7 @@ spring.resources.chain:
308 308 enabled: "true"
309 309
310 310 spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation: "true"
  311 +spring.jpa.properties.hibernate.order_by.default_null_ordering: "last"
311 312
312 313 # SQL DAO Configuration
313 314 spring:
... ...
... ... @@ -25,11 +25,7 @@ import org.junit.After;
25 25 import org.junit.Assert;
26 26 import org.junit.Before;
27 27 import org.junit.Test;
28   -import org.thingsboard.server.common.data.Customer;
29   -import org.thingsboard.server.common.data.Device;
30   -import org.thingsboard.server.common.data.EntityView;
31   -import org.thingsboard.server.common.data.Tenant;
32   -import org.thingsboard.server.common.data.User;
  28 +import org.thingsboard.server.common.data.*;
33 29 import org.thingsboard.server.common.data.id.CustomerId;
34 30 import org.thingsboard.server.common.data.objects.AttributesEntityView;
35 31 import org.thingsboard.server.common.data.objects.TelemetryEntityView;
... ... @@ -214,16 +210,20 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
214 210
215 211 @Test
216 212 public void testGetCustomerEntityViews() throws Exception {
217   - CustomerId customerId = doPost("/api/customer", getNewCustomer("Test customer"), Customer.class).getId();
218   - String urlTemplate = "/api/customer/" + customerId.getId().toString() + "/entityViews?";
  213 + Customer customer = doPost("/api/customer", getNewCustomer("Test customer"), Customer.class);
  214 + CustomerId customerId = customer.getId();
  215 + String urlTemplate = "/api/customer/" + customerId.getId().toString() + "/entityViewInfos?";
219 216
220   - List<EntityView> views = new ArrayList<>();
  217 + List<EntityViewInfo> views = new ArrayList<>();
221 218 for (int i = 0; i < 128; i++) {
222   - views.add(doPost("/api/customer/" + customerId.getId().toString() + "/entityView/"
223   - + getNewSavedEntityView("Test entity view " + i).getId().getId().toString(), EntityView.class));
  219 + views.add(
  220 + new EntityViewInfo(doPost("/api/customer/" + customerId.getId().toString() + "/entityView/"
  221 + + getNewSavedEntityView("Test entity view " + i).getId().getId().toString(), EntityView.class),
  222 + customer.getTitle(), customer.isPublic())
  223 + );
224 224 }
225 225
226   - List<EntityView> loadedViews = loadListOf(new PageLink(23), urlTemplate);
  226 + List<EntityViewInfo> loadedViews = loadListOfInfo(new PageLink(23), urlTemplate);
227 227
228 228 Collections.sort(views, idComparator);
229 229 Collections.sort(loadedViews, idComparator);
... ... @@ -274,11 +274,11 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
274 274 @Test
275 275 public void testGetTenantEntityViews() throws Exception {
276 276
277   - List<EntityView> views = new ArrayList<>();
  277 + List<EntityViewInfo> views = new ArrayList<>();
278 278 for (int i = 0; i < 178; i++) {
279   - views.add(getNewSavedEntityView("Test entity view" + i));
  279 + views.add(new EntityViewInfo(getNewSavedEntityView("Test entity view" + i), null, false));
280 280 }
281   - List<EntityView> loadedViews = loadListOf(new PageLink(23), "/api/tenant/entityViews?");
  281 + List<EntityViewInfo> loadedViews = loadListOfInfo(new PageLink(23), "/api/tenant/entityViewInfos?");
282 282
283 283 Collections.sort(views, idComparator);
284 284 Collections.sort(loadedViews, idComparator);
... ... @@ -530,4 +530,19 @@ public abstract class BaseEntityViewControllerTest extends AbstractControllerTes
530 530
531 531 return loadedItems;
532 532 }
  533 +
  534 + private List<EntityViewInfo> loadListOfInfo(PageLink pageLink, String urlTemplate) throws Exception {
  535 + List<EntityViewInfo> loadedItems = new ArrayList<>();
  536 + PageData<EntityViewInfo> pageData;
  537 + do {
  538 + pageData = doGetTypedWithPageLink(urlTemplate, new TypeReference<PageData<EntityViewInfo>>() {
  539 + }, pageLink);
  540 + loadedItems.addAll(pageData.getData());
  541 + if (pageData.hasNext()) {
  542 + pageLink = pageLink.nextPageLink();
  543 + }
  544 + } while (pageData.hasNext());
  545 +
  546 + return loadedItems;
  547 + }
533 548 }
... ...
... ... @@ -18,6 +18,7 @@ package org.thingsboard.server.dao.asset;
18 18 import com.google.common.util.concurrent.ListenableFuture;
19 19 import org.thingsboard.server.common.data.EntitySubtype;
20 20 import org.thingsboard.server.common.data.asset.Asset;
  21 +import org.thingsboard.server.common.data.asset.AssetInfo;
21 22 import org.thingsboard.server.common.data.asset.AssetSearchQuery;
22 23 import org.thingsboard.server.common.data.id.AssetId;
23 24 import org.thingsboard.server.common.data.id.CustomerId;
... ... @@ -30,6 +31,8 @@ import java.util.Optional;
30 31
31 32 public interface AssetService {
32 33
  34 + AssetInfo findAssetInfoById(TenantId tenantId, AssetId assetId);
  35 +
33 36 Asset findAssetById(TenantId tenantId, AssetId assetId);
34 37
35 38 ListenableFuture<Asset> findAssetByIdAsync(TenantId tenantId, AssetId assetId);
... ... @@ -46,16 +49,24 @@ public interface AssetService {
46 49
47 50 PageData<Asset> findAssetsByTenantId(TenantId tenantId, PageLink pageLink);
48 51
  52 + PageData<AssetInfo> findAssetInfosByTenantId(TenantId tenantId, PageLink pageLink);
  53 +
49 54 PageData<Asset> findAssetsByTenantIdAndType(TenantId tenantId, String type, PageLink pageLink);
50 55
  56 + PageData<AssetInfo> findAssetInfosByTenantIdAndType(TenantId tenantId, String type, PageLink pageLink);
  57 +
51 58 ListenableFuture<List<Asset>> findAssetsByTenantIdAndIdsAsync(TenantId tenantId, List<AssetId> assetIds);
52 59
53 60 void deleteAssetsByTenantId(TenantId tenantId);
54 61
55 62 PageData<Asset> findAssetsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, PageLink pageLink);
56 63
  64 + PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, PageLink pageLink);
  65 +
57 66 PageData<Asset> findAssetsByTenantIdAndCustomerIdAndType(TenantId tenantId, CustomerId customerId, String type, PageLink pageLink);
58 67
  68 + PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerIdAndType(TenantId tenantId, CustomerId customerId, String type, PageLink pageLink);
  69 +
59 70 ListenableFuture<List<Asset>> findAssetsByTenantIdCustomerIdAndIdsAsync(TenantId tenantId, CustomerId customerId, List<AssetId> assetIds);
60 71
61 72 void unassignCustomerAssets(TenantId tenantId, CustomerId customerId);
... ...
... ... @@ -18,6 +18,7 @@ package org.thingsboard.server.dao.entityview;
18 18 import com.google.common.util.concurrent.ListenableFuture;
19 19 import org.thingsboard.server.common.data.EntitySubtype;
20 20 import org.thingsboard.server.common.data.EntityView;
  21 +import org.thingsboard.server.common.data.EntityViewInfo;
21 22 import org.thingsboard.server.common.data.Tenant;
22 23 import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery;
23 24 import org.thingsboard.server.common.data.id.CustomerId;
... ... @@ -42,18 +43,28 @@ public interface EntityViewService {
42 43
43 44 void unassignCustomerEntityViews(TenantId tenantId, CustomerId customerId);
44 45
  46 + EntityViewInfo findEntityViewInfoById(TenantId tenantId, EntityViewId entityViewId);
  47 +
45 48 EntityView findEntityViewById(TenantId tenantId, EntityViewId entityViewId);
46 49
47 50 EntityView findEntityViewByTenantIdAndName(TenantId tenantId, String name);
48 51
49 52 PageData<EntityView> findEntityViewByTenantId(TenantId tenantId, PageLink pageLink);
50 53
  54 + PageData<EntityViewInfo> findEntityViewInfosByTenantId(TenantId tenantId, PageLink pageLink);
  55 +
51 56 PageData<EntityView> findEntityViewByTenantIdAndType(TenantId tenantId, PageLink pageLink, String type);
52 57
  58 + PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndType(TenantId tenantId, String type, PageLink pageLink);
  59 +
53 60 PageData<EntityView> findEntityViewsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, PageLink pageLink);
54 61
  62 + PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, PageLink pageLink);
  63 +
55 64 PageData<EntityView> findEntityViewsByTenantIdAndCustomerIdAndType(TenantId tenantId, CustomerId customerId, PageLink pageLink, String type);
56 65
  66 + PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerIdAndType(TenantId tenantId, CustomerId customerId, String type, PageLink pageLink);
  67 +
57 68 ListenableFuture<List<EntityView>> findEntityViewsByQuery(TenantId tenantId, EntityViewSearchQuery query);
58 69
59 70 ListenableFuture<EntityView> findEntityViewByIdAsync(TenantId tenantId, EntityViewId entityViewId);
... ...
  1 +/**
  2 + * Copyright © 2016-2019 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.common.data;
  17 +
  18 +import lombok.Data;
  19 +import org.thingsboard.server.common.data.id.EntityViewId;
  20 +
  21 +@Data
  22 +public class EntityViewInfo extends EntityView {
  23 +
  24 + private String customerTitle;
  25 + private boolean customerIsPublic;
  26 +
  27 + public EntityViewInfo() {
  28 + super();
  29 + }
  30 +
  31 + public EntityViewInfo(EntityViewId entityViewId) {
  32 + super(entityViewId);
  33 + }
  34 +
  35 + public EntityViewInfo(EntityView entityView, String customerTitle, boolean customerIsPublic) {
  36 + super(entityView);
  37 + this.customerTitle = customerTitle;
  38 + this.customerIsPublic = customerIsPublic;
  39 + }
  40 +}
... ...
  1 +/**
  2 + * Copyright © 2016-2019 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.common.data.asset;
  17 +
  18 +import lombok.Data;
  19 +import org.thingsboard.server.common.data.id.AssetId;
  20 +
  21 +@Data
  22 +public class AssetInfo extends Asset {
  23 +
  24 + private String customerTitle;
  25 + private boolean customerIsPublic;
  26 +
  27 + public AssetInfo() {
  28 + super();
  29 + }
  30 +
  31 + public AssetInfo(AssetId assetId) {
  32 + super(assetId);
  33 + }
  34 +
  35 + public AssetInfo(Asset asset, String customerTitle, boolean customerIsPublic) {
  36 + super(asset);
  37 + this.customerTitle = customerTitle;
  38 + this.customerIsPublic = customerIsPublic;
  39 + }
  40 +}
... ...
... ... @@ -18,6 +18,7 @@ package org.thingsboard.server.dao.asset;
18 18 import com.google.common.util.concurrent.ListenableFuture;
19 19 import org.thingsboard.server.common.data.EntitySubtype;
20 20 import org.thingsboard.server.common.data.asset.Asset;
  21 +import org.thingsboard.server.common.data.asset.AssetInfo;
21 22 import org.thingsboard.server.common.data.id.TenantId;
22 23 import org.thingsboard.server.common.data.page.PageData;
23 24 import org.thingsboard.server.common.data.page.PageLink;
... ... @@ -34,6 +35,15 @@ import java.util.UUID;
34 35 public interface AssetDao extends Dao<Asset> {
35 36
36 37 /**
  38 + * Find asset info by id.
  39 + *
  40 + * @param tenantId the tenant id
  41 + * @param assetId the asset id
  42 + * @return the asset info object
  43 + */
  44 + AssetInfo findAssetInfoById(TenantId tenantId, UUID assetId);
  45 +
  46 + /**
37 47 * Save or update asset object
38 48 *
39 49 * @param asset the asset object
... ... @@ -51,6 +61,15 @@ public interface AssetDao extends Dao<Asset> {
51 61 PageData<Asset> findAssetsByTenantId(UUID tenantId, PageLink pageLink);
52 62
53 63 /**
  64 + * Find asset infos by tenantId and page link.
  65 + *
  66 + * @param tenantId the tenantId
  67 + * @param pageLink the page link
  68 + * @return the list of asset info objects
  69 + */
  70 + PageData<AssetInfo> findAssetInfosByTenantId(UUID tenantId, PageLink pageLink);
  71 +
  72 + /**
54 73 * Find assets by tenantId, type and page link.
55 74 *
56 75 * @param tenantId the tenantId
... ... @@ -61,6 +80,16 @@ public interface AssetDao extends Dao<Asset> {
61 80 PageData<Asset> findAssetsByTenantIdAndType(UUID tenantId, String type, PageLink pageLink);
62 81
63 82 /**
  83 + * Find asset infos by tenantId, type and page link.
  84 + *
  85 + * @param tenantId the tenantId
  86 + * @param type the type
  87 + * @param pageLink the page link
  88 + * @return the list of asset info objects
  89 + */
  90 + PageData<AssetInfo> findAssetInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink);
  91 +
  92 + /**
64 93 * Find assets by tenantId and assets Ids.
65 94 *
66 95 * @param tenantId the tenantId
... ... @@ -80,6 +109,16 @@ public interface AssetDao extends Dao<Asset> {
80 109 PageData<Asset> findAssetsByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink);
81 110
82 111 /**
  112 + * Find asset infos by tenantId, customerId and page link.
  113 + *
  114 + * @param tenantId the tenantId
  115 + * @param customerId the customerId
  116 + * @param pageLink the page link
  117 + * @return the list of asset info objects
  118 + */
  119 + PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink);
  120 +
  121 + /**
83 122 * Find assets by tenantId, customerId, type and page link.
84 123 *
85 124 * @param tenantId the tenantId
... ... @@ -91,6 +130,17 @@ public interface AssetDao extends Dao<Asset> {
91 130 PageData<Asset> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink);
92 131
93 132 /**
  133 + * Find asset infos by tenantId, customerId, type and page link.
  134 + *
  135 + * @param tenantId the tenantId
  136 + * @param customerId the customerId
  137 + * @param type the type
  138 + * @param pageLink the page link
  139 + * @return the list of asset info objects
  140 + */
  141 + PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink);
  142 +
  143 + /**
94 144 * Find assets by tenantId, customerId and assets Ids.
95 145 *
96 146 * @param tenantId the tenantId
... ...
... ... @@ -33,6 +33,7 @@ import org.thingsboard.server.common.data.EntityType;
33 33 import org.thingsboard.server.common.data.EntityView;
34 34 import org.thingsboard.server.common.data.Tenant;
35 35 import org.thingsboard.server.common.data.asset.Asset;
  36 +import org.thingsboard.server.common.data.asset.AssetInfo;
36 37 import org.thingsboard.server.common.data.asset.AssetSearchQuery;
37 38 import org.thingsboard.server.common.data.id.AssetId;
38 39 import org.thingsboard.server.common.data.id.CustomerId;
... ... @@ -86,6 +87,13 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
86 87 private CacheManager cacheManager;
87 88
88 89 @Override
  90 + public AssetInfo findAssetInfoById(TenantId tenantId, AssetId assetId) {
  91 + log.trace("Executing findAssetInfoById [{}]", assetId);
  92 + validateId(assetId, INCORRECT_ASSET_ID + assetId);
  93 + return assetDao.findAssetInfoById(tenantId, assetId.getId());
  94 + }
  95 +
  96 + @Override
89 97 public Asset findAssetById(TenantId tenantId, AssetId assetId) {
90 98 log.trace("Executing findAssetById [{}]", assetId);
91 99 validateId(assetId, INCORRECT_ASSET_ID + assetId);
... ... @@ -165,6 +173,14 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
165 173 }
166 174
167 175 @Override
  176 + public PageData<AssetInfo> findAssetInfosByTenantId(TenantId tenantId, PageLink pageLink) {
  177 + log.trace("Executing findAssetInfosByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
  178 + validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
  179 + validatePageLink(pageLink);
  180 + return assetDao.findAssetInfosByTenantId(tenantId.getId(), pageLink);
  181 + }
  182 +
  183 + @Override
168 184 public PageData<Asset> findAssetsByTenantIdAndType(TenantId tenantId, String type, PageLink pageLink) {
169 185 log.trace("Executing findAssetsByTenantIdAndType, tenantId [{}], type [{}], pageLink [{}]", tenantId, type, pageLink);
170 186 validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
... ... @@ -174,6 +190,15 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
174 190 }
175 191
176 192 @Override
  193 + public PageData<AssetInfo> findAssetInfosByTenantIdAndType(TenantId tenantId, String type, PageLink pageLink) {
  194 + log.trace("Executing findAssetInfosByTenantIdAndType, tenantId [{}], type [{}], pageLink [{}]", tenantId, type, pageLink);
  195 + validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
  196 + validateString(type, "Incorrect type " + type);
  197 + validatePageLink(pageLink);
  198 + return assetDao.findAssetInfosByTenantIdAndType(tenantId.getId(), type, pageLink);
  199 + }
  200 +
  201 + @Override
177 202 public ListenableFuture<List<Asset>> findAssetsByTenantIdAndIdsAsync(TenantId tenantId, List<AssetId> assetIds) {
178 203 log.trace("Executing findAssetsByTenantIdAndIdsAsync, tenantId [{}], assetIds [{}]", tenantId, assetIds);
179 204 validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
... ... @@ -198,6 +223,15 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
198 223 }
199 224
200 225 @Override
  226 + public PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, PageLink pageLink) {
  227 + log.trace("Executing findAssetInfosByTenantIdAndCustomerId, tenantId [{}], customerId [{}], pageLink [{}]", tenantId, customerId, pageLink);
  228 + validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
  229 + validateId(customerId, INCORRECT_CUSTOMER_ID + customerId);
  230 + validatePageLink(pageLink);
  231 + return assetDao.findAssetInfosByTenantIdAndCustomerId(tenantId.getId(), customerId.getId(), pageLink);
  232 + }
  233 +
  234 + @Override
201 235 public PageData<Asset> findAssetsByTenantIdAndCustomerIdAndType(TenantId tenantId, CustomerId customerId, String type, PageLink pageLink) {
202 236 log.trace("Executing findAssetsByTenantIdAndCustomerIdAndType, tenantId [{}], customerId [{}], type [{}], pageLink [{}]", tenantId, customerId, type, pageLink);
203 237 validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
... ... @@ -208,6 +242,16 @@ public class BaseAssetService extends AbstractEntityService implements AssetServ
208 242 }
209 243
210 244 @Override
  245 + public PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerIdAndType(TenantId tenantId, CustomerId customerId, String type, PageLink pageLink) {
  246 + log.trace("Executing findAssetInfosByTenantIdAndCustomerIdAndType, tenantId [{}], customerId [{}], type [{}], pageLink [{}]", tenantId, customerId, type, pageLink);
  247 + validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
  248 + validateId(customerId, INCORRECT_CUSTOMER_ID + customerId);
  249 + validateString(type, "Incorrect type " + type);
  250 + validatePageLink(pageLink);
  251 + return assetDao.findAssetInfosByTenantIdAndCustomerIdAndType(tenantId.getId(), customerId.getId(), type, pageLink);
  252 + }
  253 +
  254 + @Override
211 255 public ListenableFuture<List<Asset>> findAssetsByTenantIdCustomerIdAndIdsAsync(TenantId tenantId, CustomerId customerId, List<AssetId> assetIds) {
212 256 log.trace("Executing findAssetsByTenantIdAndCustomerIdAndIdsAsync, tenantId [{}], customerId [{}], assetIds [{}]", tenantId, customerId, assetIds);
213 257 validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
... ...
... ... @@ -85,7 +85,7 @@ public interface DeviceDao extends Dao<Device> {
85 85 * @param tenantId the tenantId
86 86 * @param type the type
87 87 * @param pageLink the page link
88   - * @return the list of device onfo objects
  88 + * @return the list of device info objects
89 89 */
90 90 PageData<DeviceInfo> findDeviceInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink);
91 91
... ...
... ... @@ -16,9 +16,9 @@
16 16 package org.thingsboard.server.dao.entityview;
17 17
18 18 import com.google.common.util.concurrent.ListenableFuture;
19   -import org.thingsboard.server.common.data.Device;
20 19 import org.thingsboard.server.common.data.EntitySubtype;
21 20 import org.thingsboard.server.common.data.EntityView;
  21 +import org.thingsboard.server.common.data.EntityViewInfo;
22 22 import org.thingsboard.server.common.data.id.TenantId;
23 23 import org.thingsboard.server.common.data.page.PageData;
24 24 import org.thingsboard.server.common.data.page.PageLink;
... ... @@ -34,6 +34,15 @@ import java.util.UUID;
34 34 public interface EntityViewDao extends Dao<EntityView> {
35 35
36 36 /**
  37 + * Find entity view info by id.
  38 + *
  39 + * @param tenantId the tenant id
  40 + * @param assetId the asset id
  41 + * @return the entity view info object
  42 + */
  43 + EntityViewInfo findEntityViewInfoById(TenantId tenantId, UUID entityViewId);
  44 +
  45 + /**
37 46 * Save or update device object
38 47 *
39 48 * @param entityView the entity-view object
... ... @@ -51,6 +60,15 @@ public interface EntityViewDao extends Dao<EntityView> {
51 60 PageData<EntityView> findEntityViewsByTenantId(UUID tenantId, PageLink pageLink);
52 61
53 62 /**
  63 + * Find entity view infos by tenantId and page link.
  64 + *
  65 + * @param tenantId the tenantId
  66 + * @param pageLink the page link
  67 + * @return the list of entity view info objects
  68 + */
  69 + PageData<EntityViewInfo> findEntityViewInfosByTenantId(UUID tenantId, PageLink pageLink);
  70 +
  71 + /**
54 72 * Find entity views by tenantId, type and page link.
55 73 *
56 74 * @param tenantId the tenantId
... ... @@ -61,6 +79,16 @@ public interface EntityViewDao extends Dao<EntityView> {
61 79 PageData<EntityView> findEntityViewsByTenantIdAndType(UUID tenantId, String type, PageLink pageLink);
62 80
63 81 /**
  82 + * Find entity view infos by tenantId, type and page link.
  83 + *
  84 + * @param tenantId the tenantId
  85 + * @param type the type
  86 + * @param pageLink the page link
  87 + * @return the list of entity view info objects
  88 + */
  89 + PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink);
  90 +
  91 + /**
64 92 * Find entity views by tenantId and entity view name.
65 93 *
66 94 * @param tenantId the tenantId
... ... @@ -82,6 +110,16 @@ public interface EntityViewDao extends Dao<EntityView> {
82 110 PageLink pageLink);
83 111
84 112 /**
  113 + * Find entity view infos by tenantId, customerId and page link.
  114 + *
  115 + * @param tenantId the tenantId
  116 + * @param customerId the customerId
  117 + * @param pageLink the page link
  118 + * @return the list of entity view info objects
  119 + */
  120 + PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink);
  121 +
  122 + /**
85 123 * Find entity views by tenantId, customerId, type and page link.
86 124 *
87 125 * @param tenantId the tenantId
... ... @@ -95,6 +133,17 @@ public interface EntityViewDao extends Dao<EntityView> {
95 133 String type,
96 134 PageLink pageLink);
97 135
  136 + /**
  137 + * Find entity view infos by tenantId, customerId, type and page link.
  138 + *
  139 + * @param tenantId the tenantId
  140 + * @param customerId the customerId
  141 + * @param type the type
  142 + * @param pageLink the page link
  143 + * @return the list of entity view info objects
  144 + */
  145 + PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink);
  146 +
98 147 ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId);
99 148
100 149 /**
... ...
... ... @@ -28,11 +28,7 @@ import org.springframework.cache.annotation.CacheEvict;
28 28 import org.springframework.cache.annotation.Cacheable;
29 29 import org.springframework.cache.annotation.Caching;
30 30 import org.springframework.stereotype.Service;
31   -import org.thingsboard.server.common.data.Customer;
32   -import org.thingsboard.server.common.data.EntitySubtype;
33   -import org.thingsboard.server.common.data.EntityType;
34   -import org.thingsboard.server.common.data.EntityView;
35   -import org.thingsboard.server.common.data.Tenant;
  31 +import org.thingsboard.server.common.data.*;
36 32 import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery;
37 33 import org.thingsboard.server.common.data.id.CustomerId;
38 34 import org.thingsboard.server.common.data.id.EntityId;
... ... @@ -124,6 +120,13 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
124 120 customerEntityViewsUnAssigner.removeEntities(tenantId, customerId);
125 121 }
126 122
  123 + @Override
  124 + public EntityViewInfo findEntityViewInfoById(TenantId tenantId, EntityViewId entityViewId) {
  125 + log.trace("Executing findEntityViewInfoById [{}]", entityViewId);
  126 + validateId(entityViewId, INCORRECT_ENTITY_VIEW_ID + entityViewId);
  127 + return entityViewDao.findEntityViewInfoById(tenantId, entityViewId.getId());
  128 + }
  129 +
127 130 @Cacheable(cacheNames = ENTITY_VIEW_CACHE, key = "{#entityViewId}")
128 131 @Override
129 132 public EntityView findEntityViewById(TenantId tenantId, EntityViewId entityViewId) {
... ... @@ -150,6 +153,14 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
150 153 }
151 154
152 155 @Override
  156 + public PageData<EntityViewInfo> findEntityViewInfosByTenantId(TenantId tenantId, PageLink pageLink) {
  157 + log.trace("Executing findEntityViewInfosByTenantId, tenantId [{}], pageLink [{}]", tenantId, pageLink);
  158 + validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
  159 + validatePageLink(pageLink);
  160 + return entityViewDao.findEntityViewInfosByTenantId(tenantId.getId(), pageLink);
  161 + }
  162 +
  163 + @Override
153 164 public PageData<EntityView> findEntityViewByTenantIdAndType(TenantId tenantId, PageLink pageLink, String type) {
154 165 log.trace("Executing findEntityViewByTenantIdAndType, tenantId [{}], pageLink [{}], type [{}]", tenantId, pageLink, type);
155 166 validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
... ... @@ -159,6 +170,15 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
159 170 }
160 171
161 172 @Override
  173 + public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndType(TenantId tenantId, String type, PageLink pageLink) {
  174 + log.trace("Executing findEntityViewInfosByTenantIdAndType, tenantId [{}], pageLink [{}], type [{}]", tenantId, pageLink, type);
  175 + validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
  176 + validatePageLink(pageLink);
  177 + validateString(type, "Incorrect type " + type);
  178 + return entityViewDao.findEntityViewInfosByTenantIdAndType(tenantId.getId(), type, pageLink);
  179 + }
  180 +
  181 + @Override
162 182 public PageData<EntityView> findEntityViewsByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId,
163 183 PageLink pageLink) {
164 184 log.trace("Executing findEntityViewByTenantIdAndCustomerId, tenantId [{}], customerId [{}]," +
... ... @@ -171,6 +191,17 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
171 191 }
172 192
173 193 @Override
  194 + public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerId(TenantId tenantId, CustomerId customerId, PageLink pageLink) {
  195 + log.trace("Executing findEntityViewInfosByTenantIdAndCustomerId, tenantId [{}], customerId [{}]," +
  196 + " pageLink [{}]", tenantId, customerId, pageLink);
  197 + validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
  198 + validateId(customerId, INCORRECT_CUSTOMER_ID + customerId);
  199 + validatePageLink(pageLink);
  200 + return entityViewDao.findEntityViewInfosByTenantIdAndCustomerId(tenantId.getId(),
  201 + customerId.getId(), pageLink);
  202 + }
  203 +
  204 + @Override
174 205 public PageData<EntityView> findEntityViewsByTenantIdAndCustomerIdAndType(TenantId tenantId, CustomerId customerId, PageLink pageLink, String type) {
175 206 log.trace("Executing findEntityViewsByTenantIdAndCustomerIdAndType, tenantId [{}], customerId [{}]," +
176 207 " pageLink [{}], type [{}]", tenantId, customerId, pageLink, type);
... ... @@ -183,6 +214,18 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti
183 214 }
184 215
185 216 @Override
  217 + public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerIdAndType(TenantId tenantId, CustomerId customerId, String type, PageLink pageLink) {
  218 + log.trace("Executing findEntityViewInfosByTenantIdAndCustomerIdAndType, tenantId [{}], customerId [{}]," +
  219 + " pageLink [{}], type [{}]", tenantId, customerId, pageLink, type);
  220 + validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
  221 + validateId(customerId, INCORRECT_CUSTOMER_ID + customerId);
  222 + validatePageLink(pageLink);
  223 + validateString(type, "Incorrect type " + type);
  224 + return entityViewDao.findEntityViewInfosByTenantIdAndCustomerIdAndType(tenantId.getId(),
  225 + customerId.getId(), type, pageLink);
  226 + }
  227 +
  228 + @Override
186 229 public ListenableFuture<List<EntityView>> findEntityViewsByQuery(TenantId tenantId, EntityViewSearchQuery query) {
187 230 ListenableFuture<List<EntityRelation>> relations = relationService.findByQuery(tenantId, query.toEntitySearchQuery());
188 231 ListenableFuture<List<EntityView>> entityViews = Futures.transformAsync(relations, r -> {
... ...
  1 +/**
  2 + * Copyright © 2016-2019 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.model.sql;
  17 +
  18 +import com.datastax.driver.core.utils.UUIDs;
  19 +import com.fasterxml.jackson.databind.JsonNode;
  20 +import lombok.Data;
  21 +import lombok.EqualsAndHashCode;
  22 +import org.hibernate.annotations.Type;
  23 +import org.hibernate.annotations.TypeDef;
  24 +import org.thingsboard.server.common.data.UUIDConverter;
  25 +import org.thingsboard.server.common.data.asset.Asset;
  26 +import org.thingsboard.server.common.data.id.AssetId;
  27 +import org.thingsboard.server.common.data.id.CustomerId;
  28 +import org.thingsboard.server.common.data.id.TenantId;
  29 +import org.thingsboard.server.dao.model.BaseSqlEntity;
  30 +import org.thingsboard.server.dao.model.ModelConstants;
  31 +import org.thingsboard.server.dao.model.SearchTextEntity;
  32 +import org.thingsboard.server.dao.util.mapping.JsonStringType;
  33 +
  34 +import javax.persistence.Column;
  35 +import javax.persistence.Entity;
  36 +import javax.persistence.MappedSuperclass;
  37 +import javax.persistence.Table;
  38 +
  39 +import static org.thingsboard.server.dao.model.ModelConstants.ASSET_COLUMN_FAMILY_NAME;
  40 +import static org.thingsboard.server.dao.model.ModelConstants.ASSET_CUSTOMER_ID_PROPERTY;
  41 +import static org.thingsboard.server.dao.model.ModelConstants.ASSET_NAME_PROPERTY;
  42 +import static org.thingsboard.server.dao.model.ModelConstants.ASSET_TENANT_ID_PROPERTY;
  43 +import static org.thingsboard.server.dao.model.ModelConstants.ASSET_TYPE_PROPERTY;
  44 +import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY;
  45 +
  46 +@Data
  47 +@EqualsAndHashCode(callSuper = true)
  48 +@TypeDef(name = "json", typeClass = JsonStringType.class)
  49 +@MappedSuperclass
  50 +public abstract class AbstractAssetEntity<T extends Asset> extends BaseSqlEntity<T> implements SearchTextEntity<T> {
  51 +
  52 + @Column(name = ASSET_TENANT_ID_PROPERTY)
  53 + private String tenantId;
  54 +
  55 + @Column(name = ASSET_CUSTOMER_ID_PROPERTY)
  56 + private String customerId;
  57 +
  58 + @Column(name = ASSET_NAME_PROPERTY)
  59 + private String name;
  60 +
  61 + @Column(name = ASSET_TYPE_PROPERTY)
  62 + private String type;
  63 +
  64 + @Column(name = SEARCH_TEXT_PROPERTY)
  65 + private String searchText;
  66 +
  67 + @Type(type = "json")
  68 + @Column(name = ModelConstants.ASSET_ADDITIONAL_INFO_PROPERTY)
  69 + private JsonNode additionalInfo;
  70 +
  71 + public AbstractAssetEntity() {
  72 + super();
  73 + }
  74 +
  75 + public AbstractAssetEntity(Asset asset) {
  76 + if (asset.getId() != null) {
  77 + this.setId(asset.getId().getId());
  78 + }
  79 + if (asset.getTenantId() != null) {
  80 + this.tenantId = UUIDConverter.fromTimeUUID(asset.getTenantId().getId());
  81 + }
  82 + if (asset.getCustomerId() != null) {
  83 + this.customerId = UUIDConverter.fromTimeUUID(asset.getCustomerId().getId());
  84 + }
  85 + this.name = asset.getName();
  86 + this.type = asset.getType();
  87 + this.additionalInfo = asset.getAdditionalInfo();
  88 + }
  89 +
  90 + public AbstractAssetEntity(AssetEntity assetEntity) {
  91 + this.setId(assetEntity.getId());
  92 + this.tenantId = assetEntity.getTenantId();
  93 + this.customerId = assetEntity.getCustomerId();
  94 + this.type = assetEntity.getType();
  95 + this.name = assetEntity.getName();
  96 + this.searchText = assetEntity.getSearchText();
  97 + this.additionalInfo = assetEntity.getAdditionalInfo();
  98 + }
  99 +
  100 + @Override
  101 + public String getSearchTextSource() {
  102 + return name;
  103 + }
  104 +
  105 + @Override
  106 + public void setSearchText(String searchText) {
  107 + this.searchText = searchText;
  108 + }
  109 +
  110 + public String getSearchText() {
  111 + return searchText;
  112 + }
  113 +
  114 + protected Asset toAsset() {
  115 + Asset asset = new Asset(new AssetId(UUIDConverter.fromString(id)));
  116 + asset.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id)));
  117 + if (tenantId != null) {
  118 + asset.setTenantId(new TenantId(UUIDConverter.fromString(tenantId)));
  119 + }
  120 + if (customerId != null) {
  121 + asset.setCustomerId(new CustomerId(UUIDConverter.fromString(customerId)));
  122 + }
  123 + asset.setName(name);
  124 + asset.setType(type);
  125 + asset.setAdditionalInfo(additionalInfo);
  126 + return asset;
  127 + }
  128 +
  129 +}
\ No newline at end of file
... ...
  1 +/**
  2 + * Copyright © 2016-2019 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.model.sql;
  17 +
  18 +import com.datastax.driver.core.utils.UUIDs;
  19 +import com.fasterxml.jackson.databind.JsonNode;
  20 +import com.fasterxml.jackson.databind.ObjectMapper;
  21 +import lombok.Data;
  22 +import lombok.EqualsAndHashCode;
  23 +import lombok.extern.slf4j.Slf4j;
  24 +import org.hibernate.annotations.Type;
  25 +import org.hibernate.annotations.TypeDef;
  26 +import org.thingsboard.server.common.data.EntityType;
  27 +import org.thingsboard.server.common.data.EntityView;
  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;
  32 +import org.thingsboard.server.common.data.objects.TelemetryEntityView;
  33 +import org.thingsboard.server.dao.model.BaseSqlEntity;
  34 +import org.thingsboard.server.dao.model.ModelConstants;
  35 +import org.thingsboard.server.dao.model.SearchTextEntity;
  36 +import org.thingsboard.server.dao.util.mapping.JsonStringType;
  37 +
  38 +import javax.persistence.*;
  39 +import java.io.IOException;
  40 +
  41 +import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPERTY;
  42 +
  43 +/**
  44 + * Created by Victor Basanets on 8/30/2017.
  45 + */
  46 +
  47 +@Data
  48 +@EqualsAndHashCode(callSuper = true)
  49 +@TypeDef(name = "json", typeClass = JsonStringType.class)
  50 +@MappedSuperclass
  51 +@Slf4j
  52 +public abstract class AbstractEntityViewEntity<T extends EntityView> extends BaseSqlEntity<T> implements SearchTextEntity<T> {
  53 +
  54 + @Column(name = ModelConstants.ENTITY_VIEW_ENTITY_ID_PROPERTY)
  55 + private String entityId;
  56 +
  57 + @Enumerated(EnumType.STRING)
  58 + @Column(name = ENTITY_TYPE_PROPERTY)
  59 + private EntityType entityType;
  60 +
  61 + @Column(name = ModelConstants.ENTITY_VIEW_TENANT_ID_PROPERTY)
  62 + private String tenantId;
  63 +
  64 + @Column(name = ModelConstants.ENTITY_VIEW_CUSTOMER_ID_PROPERTY)
  65 + private String customerId;
  66 +
  67 + @Column(name = ModelConstants.DEVICE_TYPE_PROPERTY)
  68 + private String type;
  69 +
  70 + @Column(name = ModelConstants.ENTITY_VIEW_NAME_PROPERTY)
  71 + private String name;
  72 +
  73 + @Column(name = ModelConstants.ENTITY_VIEW_KEYS_PROPERTY)
  74 + private String keys;
  75 +
  76 + @Column(name = ModelConstants.ENTITY_VIEW_START_TS_PROPERTY)
  77 + private long startTs;
  78 +
  79 + @Column(name = ModelConstants.ENTITY_VIEW_END_TS_PROPERTY)
  80 + private long endTs;
  81 +
  82 + @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
  83 + private String searchText;
  84 +
  85 + @Type(type = "json")
  86 + @Column(name = ModelConstants.ENTITY_VIEW_ADDITIONAL_INFO_PROPERTY)
  87 + private JsonNode additionalInfo;
  88 +
  89 + private static final ObjectMapper mapper = new ObjectMapper();
  90 +
  91 + public AbstractEntityViewEntity() {
  92 + super();
  93 + }
  94 +
  95 + public AbstractEntityViewEntity(EntityView entityView) {
  96 + if (entityView.getId() != null) {
  97 + this.setId(entityView.getId().getId());
  98 + }
  99 + if (entityView.getEntityId() != null) {
  100 + this.entityId = toString(entityView.getEntityId().getId());
  101 + this.entityType = entityView.getEntityId().getEntityType();
  102 + }
  103 + if (entityView.getTenantId() != null) {
  104 + this.tenantId = toString(entityView.getTenantId().getId());
  105 + }
  106 + if (entityView.getCustomerId() != null) {
  107 + this.customerId = toString(entityView.getCustomerId().getId());
  108 + }
  109 + this.type = entityView.getType();
  110 + this.name = entityView.getName();
  111 + try {
  112 + this.keys = mapper.writeValueAsString(entityView.getKeys());
  113 + } catch (IOException e) {
  114 + log.error("Unable to serialize entity view keys!", e);
  115 + }
  116 + this.startTs = entityView.getStartTimeMs();
  117 + this.endTs = entityView.getEndTimeMs();
  118 + this.searchText = entityView.getSearchText();
  119 + this.additionalInfo = entityView.getAdditionalInfo();
  120 + }
  121 +
  122 + public AbstractEntityViewEntity(EntityViewEntity entityViewEntity) {
  123 + this.setId(entityViewEntity.getId());
  124 + this.entityId = entityViewEntity.getEntityId();
  125 + this.entityType = entityViewEntity.getEntityType();
  126 + this.tenantId = entityViewEntity.getTenantId();
  127 + this.customerId = entityViewEntity.getCustomerId();
  128 + this.type = entityViewEntity.getType();
  129 + this.name = entityViewEntity.getName();
  130 + this.keys = entityViewEntity.getKeys();
  131 + this.startTs = entityViewEntity.getStartTs();
  132 + this.endTs = entityViewEntity.getEndTs();
  133 + this.searchText = entityViewEntity.getSearchText();
  134 + this.additionalInfo = entityViewEntity.getAdditionalInfo();
  135 + }
  136 +
  137 + @Override
  138 + public String getSearchTextSource() {
  139 + return name;
  140 + }
  141 +
  142 + @Override
  143 + public void setSearchText(String searchText) {
  144 + this.searchText = searchText;
  145 + }
  146 +
  147 + protected EntityView toEntityView() {
  148 + EntityView entityView = new EntityView(new EntityViewId(getId()));
  149 + entityView.setCreatedTime(UUIDs.unixTimestamp(getId()));
  150 +
  151 + if (entityId != null) {
  152 + entityView.setEntityId(EntityIdFactory.getByTypeAndId(entityType.name(), toUUID(entityId).toString()));
  153 + }
  154 + if (tenantId != null) {
  155 + entityView.setTenantId(new TenantId(toUUID(tenantId)));
  156 + }
  157 + if (customerId != null) {
  158 + entityView.setCustomerId(new CustomerId(toUUID(customerId)));
  159 + }
  160 + entityView.setType(type);
  161 + entityView.setName(name);
  162 + try {
  163 + entityView.setKeys(mapper.readValue(keys, TelemetryEntityView.class));
  164 + } catch (IOException e) {
  165 + log.error("Unable to read entity view keys!", e);
  166 + }
  167 + entityView.setStartTimeMs(startTs);
  168 + entityView.setEndTimeMs(endTs);
  169 + entityView.setAdditionalInfo(additionalInfo);
  170 + return entityView;
  171 + }
  172 +}
... ...
... ... @@ -15,106 +15,35 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
19   -import com.fasterxml.jackson.databind.JsonNode;
20 18 import lombok.Data;
21 19 import lombok.EqualsAndHashCode;
22   -import org.hibernate.annotations.Type;
23 20 import org.hibernate.annotations.TypeDef;
24   -import org.thingsboard.server.common.data.UUIDConverter;
25 21 import org.thingsboard.server.common.data.asset.Asset;
26   -import org.thingsboard.server.common.data.id.AssetId;
27   -import org.thingsboard.server.common.data.id.CustomerId;
28   -import org.thingsboard.server.common.data.id.TenantId;
29   -import org.thingsboard.server.dao.model.BaseSqlEntity;
30   -import org.thingsboard.server.dao.model.ModelConstants;
31   -import org.thingsboard.server.dao.model.SearchTextEntity;
32 22 import org.thingsboard.server.dao.util.mapping.JsonStringType;
33 23
34   -import javax.persistence.Column;
35 24 import javax.persistence.Entity;
36 25 import javax.persistence.Table;
37 26
38 27 import static org.thingsboard.server.dao.model.ModelConstants.ASSET_COLUMN_FAMILY_NAME;
39   -import static org.thingsboard.server.dao.model.ModelConstants.ASSET_CUSTOMER_ID_PROPERTY;
40   -import static org.thingsboard.server.dao.model.ModelConstants.ASSET_NAME_PROPERTY;
41   -import static org.thingsboard.server.dao.model.ModelConstants.ASSET_TENANT_ID_PROPERTY;
42   -import static org.thingsboard.server.dao.model.ModelConstants.ASSET_TYPE_PROPERTY;
43   -import static org.thingsboard.server.dao.model.ModelConstants.SEARCH_TEXT_PROPERTY;
44 28
45 29 @Data
46 30 @EqualsAndHashCode(callSuper = true)
47 31 @Entity
48 32 @TypeDef(name = "json", typeClass = JsonStringType.class)
49 33 @Table(name = ASSET_COLUMN_FAMILY_NAME)
50   -public final class AssetEntity extends BaseSqlEntity<Asset> implements SearchTextEntity<Asset> {
51   -
52   - @Column(name = ASSET_TENANT_ID_PROPERTY)
53   - private String tenantId;
54   -
55   - @Column(name = ASSET_CUSTOMER_ID_PROPERTY)
56   - private String customerId;
57   -
58   - @Column(name = ASSET_NAME_PROPERTY)
59   - private String name;
60   -
61   - @Column(name = ASSET_TYPE_PROPERTY)
62   - private String type;
63   -
64   - @Column(name = SEARCH_TEXT_PROPERTY)
65   - private String searchText;
66   -
67   - @Type(type = "json")
68   - @Column(name = ModelConstants.ASSET_ADDITIONAL_INFO_PROPERTY)
69   - private JsonNode additionalInfo;
  34 +public final class AssetEntity extends AbstractAssetEntity<Asset> {
70 35
71 36 public AssetEntity() {
72 37 super();
73 38 }
74 39
75 40 public AssetEntity(Asset asset) {
76   - if (asset.getId() != null) {
77   - this.setId(asset.getId().getId());
78   - }
79   - if (asset.getTenantId() != null) {
80   - this.tenantId = UUIDConverter.fromTimeUUID(asset.getTenantId().getId());
81   - }
82   - if (asset.getCustomerId() != null) {
83   - this.customerId = UUIDConverter.fromTimeUUID(asset.getCustomerId().getId());
84   - }
85   - this.name = asset.getName();
86   - this.type = asset.getType();
87   - this.additionalInfo = asset.getAdditionalInfo();
88   - }
89   -
90   - @Override
91   - public String getSearchTextSource() {
92   - return name;
93   - }
94   -
95   - @Override
96   - public void setSearchText(String searchText) {
97   - this.searchText = searchText;
98   - }
99   -
100   - public String getSearchText() {
101   - return searchText;
  41 + super(asset);
102 42 }
103 43
104 44 @Override
105 45 public Asset toData() {
106   - Asset asset = new Asset(new AssetId(UUIDConverter.fromString(id)));
107   - asset.setCreatedTime(UUIDs.unixTimestamp(UUIDConverter.fromString(id)));
108   - if (tenantId != null) {
109   - asset.setTenantId(new TenantId(UUIDConverter.fromString(tenantId)));
110   - }
111   - if (customerId != null) {
112   - asset.setCustomerId(new CustomerId(UUIDConverter.fromString(customerId)));
113   - }
114   - asset.setName(name);
115   - asset.setType(type);
116   - asset.setAdditionalInfo(additionalInfo);
117   - return asset;
  46 + return super.toAsset();
118 47 }
119 48
120 49 }
\ No newline at end of file
... ...
  1 +/**
  2 + * Copyright © 2016-2019 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.model.sql;
  17 +
  18 +import com.fasterxml.jackson.databind.JsonNode;
  19 +import lombok.Data;
  20 +import lombok.EqualsAndHashCode;
  21 +import org.thingsboard.server.common.data.asset.AssetInfo;
  22 +
  23 +import java.util.HashMap;
  24 +import java.util.Map;
  25 +
  26 +@Data
  27 +@EqualsAndHashCode(callSuper = true)
  28 +public class AssetInfoEntity extends AbstractAssetEntity<AssetInfo> {
  29 +
  30 + public static final Map<String,String> assetInfoColumnMap = new HashMap<>();
  31 + static {
  32 + assetInfoColumnMap.put("customerTitle", "c.title");
  33 + }
  34 +
  35 + private String customerTitle;
  36 + private boolean customerIsPublic;
  37 +
  38 + public AssetInfoEntity() {
  39 + super();
  40 + }
  41 +
  42 + public AssetInfoEntity(AssetEntity assetEntity,
  43 + String customerTitle,
  44 + Object customerAdditionalInfo) {
  45 + super(assetEntity);
  46 + this.customerTitle = customerTitle;
  47 + if (customerAdditionalInfo != null && ((JsonNode)customerAdditionalInfo).has("isPublic")) {
  48 + this.customerIsPublic = ((JsonNode)customerAdditionalInfo).get("isPublic").asBoolean();
  49 + } else {
  50 + this.customerIsPublic = false;
  51 + }
  52 + }
  53 +
  54 + @Override
  55 + public AssetInfo toData() {
  56 + return new AssetInfo(super.toAsset(), customerTitle, customerIsPublic);
  57 + }
  58 +}
... ...
... ... @@ -15,22 +15,13 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
19   -import com.fasterxml.jackson.databind.JsonNode;
20 18 import lombok.Data;
21 19 import lombok.EqualsAndHashCode;
22   -import org.hibernate.annotations.Type;
23 20 import org.hibernate.annotations.TypeDef;
24 21 import org.thingsboard.server.common.data.Device;
25   -import org.thingsboard.server.common.data.id.CustomerId;
26   -import org.thingsboard.server.common.data.id.DeviceId;
27   -import org.thingsboard.server.common.data.id.TenantId;
28   -import org.thingsboard.server.dao.model.BaseSqlEntity;
29 22 import org.thingsboard.server.dao.model.ModelConstants;
30   -import org.thingsboard.server.dao.model.SearchTextEntity;
31 23 import org.thingsboard.server.dao.util.mapping.JsonStringType;
32 24
33   -import javax.persistence.Column;
34 25 import javax.persistence.Entity;
35 26 import javax.persistence.Table;
36 27
... ...
... ... @@ -15,34 +15,15 @@
15 15 */
16 16 package org.thingsboard.server.dao.model.sql;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
19   -import com.fasterxml.jackson.databind.JsonNode;
20   -import com.fasterxml.jackson.databind.ObjectMapper;
21 18 import lombok.Data;
22 19 import lombok.EqualsAndHashCode;
23   -import lombok.extern.slf4j.Slf4j;
24   -import org.hibernate.annotations.Type;
25 20 import org.hibernate.annotations.TypeDef;
26   -import org.thingsboard.server.common.data.EntityType;
27 21 import org.thingsboard.server.common.data.EntityView;
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;
32   -import org.thingsboard.server.common.data.objects.TelemetryEntityView;
33   -import org.thingsboard.server.dao.model.BaseSqlEntity;
34 22 import org.thingsboard.server.dao.model.ModelConstants;
35   -import org.thingsboard.server.dao.model.SearchTextEntity;
36 23 import org.thingsboard.server.dao.util.mapping.JsonStringType;
37 24
38   -import javax.persistence.Column;
39 25 import javax.persistence.Entity;
40   -import javax.persistence.EnumType;
41   -import javax.persistence.Enumerated;
42 26 import javax.persistence.Table;
43   -import java.io.IOException;
44   -
45   -import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPERTY;
46 27
47 28 /**
48 29 * Created by Victor Basanets on 8/30/2017.
... ... @@ -53,111 +34,18 @@ import static org.thingsboard.server.dao.model.ModelConstants.ENTITY_TYPE_PROPER
53 34 @Entity
54 35 @TypeDef(name = "json", typeClass = JsonStringType.class)
55 36 @Table(name = ModelConstants.ENTITY_VIEW_TABLE_FAMILY_NAME)
56   -@Slf4j
57   -public class EntityViewEntity extends BaseSqlEntity<EntityView> implements SearchTextEntity<EntityView> {
58   -
59   - @Column(name = ModelConstants.ENTITY_VIEW_ENTITY_ID_PROPERTY)
60   - private String entityId;
61   -
62   - @Enumerated(EnumType.STRING)
63   - @Column(name = ENTITY_TYPE_PROPERTY)
64   - private EntityType entityType;
65   -
66   - @Column(name = ModelConstants.ENTITY_VIEW_TENANT_ID_PROPERTY)
67   - private String tenantId;
68   -
69   - @Column(name = ModelConstants.ENTITY_VIEW_CUSTOMER_ID_PROPERTY)
70   - private String customerId;
71   -
72   - @Column(name = ModelConstants.DEVICE_TYPE_PROPERTY)
73   - private String type;
74   -
75   - @Column(name = ModelConstants.ENTITY_VIEW_NAME_PROPERTY)
76   - private String name;
77   -
78   - @Column(name = ModelConstants.ENTITY_VIEW_KEYS_PROPERTY)
79   - private String keys;
80   -
81   - @Column(name = ModelConstants.ENTITY_VIEW_START_TS_PROPERTY)
82   - private long startTs;
83   -
84   - @Column(name = ModelConstants.ENTITY_VIEW_END_TS_PROPERTY)
85   - private long endTs;
86   -
87   - @Column(name = ModelConstants.SEARCH_TEXT_PROPERTY)
88   - private String searchText;
89   -
90   - @Type(type = "json")
91   - @Column(name = ModelConstants.ENTITY_VIEW_ADDITIONAL_INFO_PROPERTY)
92   - private JsonNode additionalInfo;
93   -
94   - private static final ObjectMapper mapper = new ObjectMapper();
  37 +public class EntityViewEntity extends AbstractEntityViewEntity<EntityView> {
95 38
96 39 public EntityViewEntity() {
97 40 super();
98 41 }
99 42
100 43 public EntityViewEntity(EntityView entityView) {
101   - if (entityView.getId() != null) {
102   - this.setId(entityView.getId().getId());
103   - }
104   - if (entityView.getEntityId() != null) {
105   - this.entityId = toString(entityView.getEntityId().getId());
106   - this.entityType = entityView.getEntityId().getEntityType();
107   - }
108   - if (entityView.getTenantId() != null) {
109   - this.tenantId = toString(entityView.getTenantId().getId());
110   - }
111   - if (entityView.getCustomerId() != null) {
112   - this.customerId = toString(entityView.getCustomerId().getId());
113   - }
114   - this.type = entityView.getType();
115   - this.name = entityView.getName();
116   - try {
117   - this.keys = mapper.writeValueAsString(entityView.getKeys());
118   - } catch (IOException e) {
119   - log.error("Unable to serialize entity view keys!", e);
120   - }
121   - this.startTs = entityView.getStartTimeMs();
122   - this.endTs = entityView.getEndTimeMs();
123   - this.searchText = entityView.getSearchText();
124   - this.additionalInfo = entityView.getAdditionalInfo();
125   - }
126   -
127   - @Override
128   - public String getSearchTextSource() {
129   - return name;
130   - }
131   -
132   - @Override
133   - public void setSearchText(String searchText) {
134   - this.searchText = searchText;
  44 + super(entityView);
135 45 }
136 46
137 47 @Override
138 48 public EntityView toData() {
139   - EntityView entityView = new EntityView(new EntityViewId(getId()));
140   - entityView.setCreatedTime(UUIDs.unixTimestamp(getId()));
141   -
142   - if (entityId != null) {
143   - entityView.setEntityId(EntityIdFactory.getByTypeAndId(entityType.name(), toUUID(entityId).toString()));
144   - }
145   - if (tenantId != null) {
146   - entityView.setTenantId(new TenantId(toUUID(tenantId)));
147   - }
148   - if (customerId != null) {
149   - entityView.setCustomerId(new CustomerId(toUUID(customerId)));
150   - }
151   - entityView.setType(type);
152   - entityView.setName(name);
153   - try {
154   - entityView.setKeys(mapper.readValue(keys, TelemetryEntityView.class));
155   - } catch (IOException e) {
156   - log.error("Unable to read entity view keys!", e);
157   - }
158   - entityView.setStartTimeMs(startTs);
159   - entityView.setEndTimeMs(endTs);
160   - entityView.setAdditionalInfo(additionalInfo);
161   - return entityView;
  49 + return super.toEntityView();
162 50 }
163 51 }
... ...
  1 +/**
  2 + * Copyright © 2016-2019 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.dao.model.sql;
  17 +
  18 +import com.fasterxml.jackson.databind.JsonNode;
  19 +import lombok.Data;
  20 +import lombok.EqualsAndHashCode;
  21 +import org.thingsboard.server.common.data.EntityViewInfo;
  22 +
  23 +import java.util.HashMap;
  24 +import java.util.Map;
  25 +
  26 +@Data
  27 +@EqualsAndHashCode(callSuper = true)
  28 +public class EntityViewInfoEntity extends AbstractEntityViewEntity<EntityViewInfo> {
  29 +
  30 + public static final Map<String,String> entityViewInfoColumnMap = new HashMap<>();
  31 + static {
  32 + entityViewInfoColumnMap.put("customerTitle", "c.title");
  33 + }
  34 +
  35 + private String customerTitle;
  36 + private boolean customerIsPublic;
  37 +
  38 + public EntityViewInfoEntity() {
  39 + super();
  40 + }
  41 +
  42 + public EntityViewInfoEntity(EntityViewEntity entityViewEntity,
  43 + String customerTitle,
  44 + Object customerAdditionalInfo) {
  45 + super(entityViewEntity);
  46 + this.customerTitle = customerTitle;
  47 + if (customerAdditionalInfo != null && ((JsonNode)customerAdditionalInfo).has("isPublic")) {
  48 + this.customerIsPublic = ((JsonNode)customerAdditionalInfo).get("isPublic").asBoolean();
  49 + } else {
  50 + this.customerIsPublic = false;
  51 + }
  52 + }
  53 +
  54 + @Override
  55 + public EntityViewInfo toData() {
  56 + return new EntityViewInfo(super.toEntityView(), customerTitle, customerIsPublic);
  57 + }
  58 +}
... ...
... ... @@ -22,6 +22,7 @@ import org.springframework.data.repository.CrudRepository;
22 22 import org.springframework.data.repository.PagingAndSortingRepository;
23 23 import org.springframework.data.repository.query.Param;
24 24 import org.thingsboard.server.dao.model.sql.AssetEntity;
  25 +import org.thingsboard.server.dao.model.sql.AssetInfoEntity;
25 26 import org.thingsboard.server.dao.util.SqlDao;
26 27
27 28 import java.util.List;
... ... @@ -32,12 +33,27 @@ import java.util.List;
32 33 @SqlDao
33 34 public interface AssetRepository extends PagingAndSortingRepository<AssetEntity, String> {
34 35
  36 + @Query("SELECT new org.thingsboard.server.dao.model.sql.AssetInfoEntity(a, c.title, c.additionalInfo) " +
  37 + "FROM AssetEntity a " +
  38 + "LEFT JOIN CustomerEntity c on c.id = a.customerId " +
  39 + "WHERE a.id = :assetId")
  40 + AssetInfoEntity findAssetInfoById(@Param("assetId") String assetId);
  41 +
35 42 @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
36 43 "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))")
37 44 Page<AssetEntity> findByTenantId(@Param("tenantId") String tenantId,
38 45 @Param("textSearch") String textSearch,
39 46 Pageable pageable);
40 47
  48 + @Query("SELECT new org.thingsboard.server.dao.model.sql.AssetInfoEntity(a, c.title, c.additionalInfo) " +
  49 + "FROM AssetEntity a " +
  50 + "LEFT JOIN CustomerEntity c on c.id = a.customerId " +
  51 + "WHERE a.tenantId = :tenantId " +
  52 + "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))")
  53 + Page<AssetInfoEntity> findAssetInfosByTenantId(@Param("tenantId") String tenantId,
  54 + @Param("textSearch") String textSearch,
  55 + Pageable pageable);
  56 +
41 57 @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
42 58 "AND a.customerId = :customerId " +
43 59 "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))")
... ... @@ -46,6 +62,17 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity,
46 62 @Param("textSearch") String textSearch,
47 63 Pageable pageable);
48 64
  65 + @Query("SELECT new org.thingsboard.server.dao.model.sql.AssetInfoEntity(a, c.title, c.additionalInfo) " +
  66 + "FROM AssetEntity a " +
  67 + "LEFT JOIN CustomerEntity c on c.id = a.customerId " +
  68 + "WHERE a.tenantId = :tenantId " +
  69 + "AND a.customerId = :customerId " +
  70 + "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:searchText, '%'))")
  71 + Page<AssetInfoEntity> findAssetInfosByTenantIdAndCustomerId(@Param("tenantId") String tenantId,
  72 + @Param("customerId") String customerId,
  73 + @Param("searchText") String searchText,
  74 + Pageable pageable);
  75 +
49 76 List<AssetEntity> findByTenantIdAndIdIn(String tenantId, List<String> assetIds);
50 77
51 78 List<AssetEntity> findByTenantIdAndCustomerIdAndIdIn(String tenantId, String customerId, List<String> assetIds);
... ... @@ -60,6 +87,18 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity,
60 87 @Param("textSearch") String textSearch,
61 88 Pageable pageable);
62 89
  90 + @Query("SELECT new org.thingsboard.server.dao.model.sql.AssetInfoEntity(a, c.title, c.additionalInfo) " +
  91 + "FROM AssetEntity a " +
  92 + "LEFT JOIN CustomerEntity c on c.id = a.customerId " +
  93 + "WHERE a.tenantId = :tenantId " +
  94 + "AND a.type = :type " +
  95 + "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))")
  96 + Page<AssetInfoEntity> findAssetInfosByTenantIdAndType(@Param("tenantId") String tenantId,
  97 + @Param("type") String type,
  98 + @Param("textSearch") String textSearch,
  99 + Pageable pageable);
  100 +
  101 +
63 102 @Query("SELECT a FROM AssetEntity a WHERE a.tenantId = :tenantId " +
64 103 "AND a.customerId = :customerId AND a.type = :type " +
65 104 "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))")
... ... @@ -69,6 +108,19 @@ public interface AssetRepository extends PagingAndSortingRepository<AssetEntity,
69 108 @Param("textSearch") String textSearch,
70 109 Pageable pageable);
71 110
  111 + @Query("SELECT new org.thingsboard.server.dao.model.sql.AssetInfoEntity(a, c.title, c.additionalInfo) " +
  112 + "FROM AssetEntity a " +
  113 + "LEFT JOIN CustomerEntity c on c.id = a.customerId " +
  114 + "WHERE a.tenantId = :tenantId " +
  115 + "AND a.customerId = :customerId " +
  116 + "AND a.type = :type " +
  117 + "AND LOWER(a.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))")
  118 + Page<AssetInfoEntity> findAssetInfosByTenantIdAndCustomerIdAndType(@Param("tenantId") String tenantId,
  119 + @Param("customerId") String customerId,
  120 + @Param("type") String type,
  121 + @Param("textSearch") String textSearch,
  122 + Pageable pageable);
  123 +
72 124 @Query("SELECT DISTINCT a.type FROM AssetEntity a WHERE a.tenantId = :tenantId")
73 125 List<String> findTenantAssetTypes(@Param("tenantId") String tenantId);
74 126
... ...
... ... @@ -23,12 +23,14 @@ import org.springframework.stereotype.Component;
23 23 import org.thingsboard.server.common.data.EntitySubtype;
24 24 import org.thingsboard.server.common.data.EntityType;
25 25 import org.thingsboard.server.common.data.asset.Asset;
  26 +import org.thingsboard.server.common.data.asset.AssetInfo;
26 27 import org.thingsboard.server.common.data.id.TenantId;
27 28 import org.thingsboard.server.common.data.page.PageData;
28 29 import org.thingsboard.server.common.data.page.PageLink;
29 30 import org.thingsboard.server.dao.DaoUtil;
30 31 import org.thingsboard.server.dao.asset.AssetDao;
31 32 import org.thingsboard.server.dao.model.sql.AssetEntity;
  33 +import org.thingsboard.server.dao.model.sql.AssetInfoEntity;
32 34 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
33 35 import org.thingsboard.server.dao.util.SqlDao;
34 36
... ... @@ -64,6 +66,11 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
64 66 }
65 67
66 68 @Override
  69 + public AssetInfo findAssetInfoById(TenantId tenantId, UUID assetId) {
  70 + return DaoUtil.getData(assetRepository.findAssetInfoById(fromTimeUUID(assetId)));
  71 + }
  72 +
  73 + @Override
67 74 public PageData<Asset> findAssetsByTenantId(UUID tenantId, PageLink pageLink) {
68 75 return DaoUtil.toPageData(assetRepository
69 76 .findByTenantId(
... ... @@ -73,6 +80,15 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
73 80 }
74 81
75 82 @Override
  83 + public PageData<AssetInfo> findAssetInfosByTenantId(UUID tenantId, PageLink pageLink) {
  84 + return DaoUtil.toPageData(
  85 + assetRepository.findAssetInfosByTenantId(
  86 + fromTimeUUID(tenantId),
  87 + Objects.toString(pageLink.getTextSearch(), ""),
  88 + DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap)));
  89 + }
  90 +
  91 + @Override
76 92 public ListenableFuture<List<Asset>> findAssetsByTenantIdAndIdsAsync(UUID tenantId, List<UUID> assetIds) {
77 93 return service.submit(() ->
78 94 DaoUtil.convertDataList(assetRepository.findByTenantIdAndIdIn(fromTimeUUID(tenantId), fromTimeUUIDs(assetIds))));
... ... @@ -89,6 +105,16 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
89 105 }
90 106
91 107 @Override
  108 + public PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) {
  109 + return DaoUtil.toPageData(
  110 + assetRepository.findAssetInfosByTenantIdAndCustomerId(
  111 + fromTimeUUID(tenantId),
  112 + fromTimeUUID(customerId),
  113 + Objects.toString(pageLink.getTextSearch(), ""),
  114 + DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap)));
  115 + }
  116 +
  117 + @Override
92 118 public ListenableFuture<List<Asset>> findAssetsByTenantIdAndCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> assetIds) {
93 119 return service.submit(() ->
94 120 DaoUtil.convertDataList(assetRepository.findByTenantIdAndCustomerIdAndIdIn(fromTimeUUID(tenantId), fromTimeUUID(customerId), fromTimeUUIDs(assetIds))));
... ... @@ -111,6 +137,16 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
111 137 }
112 138
113 139 @Override
  140 + public PageData<AssetInfo> findAssetInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) {
  141 + return DaoUtil.toPageData(
  142 + assetRepository.findAssetInfosByTenantIdAndType(
  143 + fromTimeUUID(tenantId),
  144 + type,
  145 + Objects.toString(pageLink.getTextSearch(), ""),
  146 + DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap)));
  147 + }
  148 +
  149 + @Override
114 150 public PageData<Asset> findAssetsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) {
115 151 return DaoUtil.toPageData(assetRepository
116 152 .findByTenantIdAndCustomerIdAndType(
... ... @@ -122,6 +158,17 @@ public class JpaAssetDao extends JpaAbstractSearchTextDao<AssetEntity, Asset> im
122 158 }
123 159
124 160 @Override
  161 + public PageData<AssetInfo> findAssetInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) {
  162 + return DaoUtil.toPageData(
  163 + assetRepository.findAssetInfosByTenantIdAndCustomerIdAndType(
  164 + fromTimeUUID(tenantId),
  165 + fromTimeUUID(customerId),
  166 + type,
  167 + Objects.toString(pageLink.getTextSearch(), ""),
  168 + DaoUtil.toPageable(pageLink, AssetInfoEntity.assetInfoColumnMap)));
  169 + }
  170 +
  171 + @Override
125 172 public ListenableFuture<List<EntitySubtype>> findTenantAssetTypesAsync(UUID tenantId) {
126 173 return service.submit(() -> convertTenantAssetTypesToDto(tenantId, assetRepository.findTenantAssetTypes(fromTimeUUID(tenantId))));
127 174 }
... ...
... ... @@ -22,6 +22,7 @@ import org.springframework.data.repository.CrudRepository;
22 22 import org.springframework.data.repository.PagingAndSortingRepository;
23 23 import org.springframework.data.repository.query.Param;
24 24 import org.thingsboard.server.dao.model.sql.EntityViewEntity;
  25 +import org.thingsboard.server.dao.model.sql.EntityViewInfoEntity;
25 26 import org.thingsboard.server.dao.util.SqlDao;
26 27
27 28 import java.util.List;
... ... @@ -32,12 +33,27 @@ import java.util.List;
32 33 @SqlDao
33 34 public interface EntityViewRepository extends PagingAndSortingRepository<EntityViewEntity, String> {
34 35
  36 + @Query("SELECT new org.thingsboard.server.dao.model.sql.EntityViewInfoEntity(e, c.title, c.additionalInfo) " +
  37 + "FROM EntityViewEntity e " +
  38 + "LEFT JOIN CustomerEntity c on c.id = e.customerId " +
  39 + "WHERE e.id = :entityViewId")
  40 + EntityViewInfoEntity findEntityViewInfoById(@Param("entityViewId") String entityViewId);
  41 +
35 42 @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " +
36 43 "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))")
37 44 Page<EntityViewEntity> findByTenantId(@Param("tenantId") String tenantId,
38 45 @Param("textSearch") String textSearch,
39 46 Pageable pageable);
40 47
  48 + @Query("SELECT new org.thingsboard.server.dao.model.sql.EntityViewInfoEntity(e, c.title, c.additionalInfo) " +
  49 + "FROM EntityViewEntity e " +
  50 + "LEFT JOIN CustomerEntity c on c.id = e.customerId " +
  51 + "WHERE e.tenantId = :tenantId " +
  52 + "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))")
  53 + Page<EntityViewInfoEntity> findEntityViewInfosByTenantId(@Param("tenantId") String tenantId,
  54 + @Param("textSearch") String textSearch,
  55 + Pageable pageable);
  56 +
41 57 @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " +
42 58 "AND e.type = :type " +
43 59 "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))")
... ... @@ -46,6 +62,17 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV
46 62 @Param("textSearch") String textSearch,
47 63 Pageable pageable);
48 64
  65 + @Query("SELECT new org.thingsboard.server.dao.model.sql.EntityViewInfoEntity(e, c.title, c.additionalInfo) " +
  66 + "FROM EntityViewEntity e " +
  67 + "LEFT JOIN CustomerEntity c on c.id = e.customerId " +
  68 + "WHERE e.tenantId = :tenantId " +
  69 + "AND e.type = :type " +
  70 + "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))")
  71 + Page<EntityViewInfoEntity> findEntityViewInfosByTenantIdAndType(@Param("tenantId") String tenantId,
  72 + @Param("type") String type,
  73 + @Param("textSearch") String textSearch,
  74 + Pageable pageable);
  75 +
49 76 @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " +
50 77 "AND e.customerId = :customerId " +
51 78 "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:searchText, '%'))")
... ... @@ -54,6 +81,17 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV
54 81 @Param("searchText") String searchText,
55 82 Pageable pageable);
56 83
  84 + @Query("SELECT new org.thingsboard.server.dao.model.sql.EntityViewInfoEntity(e, c.title, c.additionalInfo) " +
  85 + "FROM EntityViewEntity e " +
  86 + "LEFT JOIN CustomerEntity c on c.id = e.customerId " +
  87 + "WHERE e.tenantId = :tenantId " +
  88 + "AND e.customerId = :customerId " +
  89 + "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:searchText, '%'))")
  90 + Page<EntityViewInfoEntity> findEntityViewInfosByTenantIdAndCustomerId(@Param("tenantId") String tenantId,
  91 + @Param("customerId") String customerId,
  92 + @Param("searchText") String searchText,
  93 + Pageable pageable);
  94 +
57 95 @Query("SELECT e FROM EntityViewEntity e WHERE e.tenantId = :tenantId " +
58 96 "AND e.customerId = :customerId " +
59 97 "AND e.type = :type " +
... ... @@ -64,6 +102,19 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV
64 102 @Param("searchText") String searchText,
65 103 Pageable pageable);
66 104
  105 + @Query("SELECT new org.thingsboard.server.dao.model.sql.EntityViewInfoEntity(e, c.title, c.additionalInfo) " +
  106 + "FROM EntityViewEntity e " +
  107 + "LEFT JOIN CustomerEntity c on c.id = e.customerId " +
  108 + "WHERE e.tenantId = :tenantId " +
  109 + "AND e.customerId = :customerId " +
  110 + "AND e.type = :type " +
  111 + "AND LOWER(e.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))")
  112 + Page<EntityViewInfoEntity> findEntityViewInfosByTenantIdAndCustomerIdAndType(@Param("tenantId") String tenantId,
  113 + @Param("customerId") String customerId,
  114 + @Param("type") String type,
  115 + @Param("textSearch") String textSearch,
  116 + Pageable pageable);
  117 +
67 118 EntityViewEntity findByTenantIdAndName(String tenantId, String name);
68 119
69 120 List<EntityViewEntity> findAllByTenantIdAndEntityId(String tenantId, String entityId);
... ...
... ... @@ -20,16 +20,14 @@ import org.springframework.beans.factory.annotation.Autowired;
20 20 import org.springframework.data.domain.PageRequest;
21 21 import org.springframework.data.repository.CrudRepository;
22 22 import org.springframework.stereotype.Component;
23   -import org.thingsboard.server.common.data.EntitySubtype;
24   -import org.thingsboard.server.common.data.EntityType;
25   -import org.thingsboard.server.common.data.EntityView;
26   -import org.thingsboard.server.common.data.UUIDConverter;
  23 +import org.thingsboard.server.common.data.*;
27 24 import org.thingsboard.server.common.data.id.TenantId;
28 25 import org.thingsboard.server.common.data.page.PageData;
29 26 import org.thingsboard.server.common.data.page.PageLink;
30 27 import org.thingsboard.server.dao.DaoUtil;
31 28 import org.thingsboard.server.dao.entityview.EntityViewDao;
32 29 import org.thingsboard.server.dao.model.sql.EntityViewEntity;
  30 +import org.thingsboard.server.dao.model.sql.EntityViewInfoEntity;
33 31 import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
34 32 import org.thingsboard.server.dao.util.SqlDao;
35 33
... ... @@ -65,6 +63,11 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
65 63 }
66 64
67 65 @Override
  66 + public EntityViewInfo findEntityViewInfoById(TenantId tenantId, UUID entityViewId) {
  67 + return DaoUtil.getData(entityViewRepository.findEntityViewInfoById(fromTimeUUID(entityViewId)));
  68 + }
  69 +
  70 + @Override
68 71 public PageData<EntityView> findEntityViewsByTenantId(UUID tenantId, PageLink pageLink) {
69 72 return DaoUtil.toPageData(
70 73 entityViewRepository.findByTenantId(
... ... @@ -74,6 +77,15 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
74 77 }
75 78
76 79 @Override
  80 + public PageData<EntityViewInfo> findEntityViewInfosByTenantId(UUID tenantId, PageLink pageLink) {
  81 + return DaoUtil.toPageData(
  82 + entityViewRepository.findEntityViewInfosByTenantId(
  83 + fromTimeUUID(tenantId),
  84 + Objects.toString(pageLink.getTextSearch(), ""),
  85 + DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap)));
  86 + }
  87 +
  88 + @Override
77 89 public PageData<EntityView> findEntityViewsByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) {
78 90 return DaoUtil.toPageData(
79 91 entityViewRepository.findByTenantIdAndType(
... ... @@ -84,6 +96,16 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
84 96 }
85 97
86 98 @Override
  99 + public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndType(UUID tenantId, String type, PageLink pageLink) {
  100 + return DaoUtil.toPageData(
  101 + entityViewRepository.findEntityViewInfosByTenantIdAndType(
  102 + fromTimeUUID(tenantId),
  103 + type,
  104 + Objects.toString(pageLink.getTextSearch(), ""),
  105 + DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap)));
  106 + }
  107 +
  108 + @Override
87 109 public Optional<EntityView> findEntityViewByTenantIdAndName(UUID tenantId, String name) {
88 110 return Optional.ofNullable(
89 111 DaoUtil.getData(entityViewRepository.findByTenantIdAndName(fromTimeUUID(tenantId), name)));
... ... @@ -103,6 +125,16 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
103 125 }
104 126
105 127 @Override
  128 + public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerId(UUID tenantId, UUID customerId, PageLink pageLink) {
  129 + return DaoUtil.toPageData(
  130 + entityViewRepository.findEntityViewInfosByTenantIdAndCustomerId(
  131 + fromTimeUUID(tenantId),
  132 + fromTimeUUID(customerId),
  133 + Objects.toString(pageLink.getTextSearch(), ""),
  134 + DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap)));
  135 + }
  136 +
  137 + @Override
106 138 public PageData<EntityView> findEntityViewsByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) {
107 139 return DaoUtil.toPageData(
108 140 entityViewRepository.findByTenantIdAndCustomerIdAndType(
... ... @@ -115,6 +147,17 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity,
115 147 }
116 148
117 149 @Override
  150 + public PageData<EntityViewInfo> findEntityViewInfosByTenantIdAndCustomerIdAndType(UUID tenantId, UUID customerId, String type, PageLink pageLink) {
  151 + return DaoUtil.toPageData(
  152 + entityViewRepository.findEntityViewInfosByTenantIdAndCustomerIdAndType(
  153 + fromTimeUUID(tenantId),
  154 + fromTimeUUID(customerId),
  155 + type,
  156 + Objects.toString(pageLink.getTextSearch(), ""),
  157 + DaoUtil.toPageable(pageLink, EntityViewInfoEntity.entityViewInfoColumnMap)));
  158 + }
  159 +
  160 + @Override
118 161 public ListenableFuture<List<EntityView>> findEntityViewsByTenantIdAndEntityIdAsync(UUID tenantId, UUID entityId) {
119 162 return service.submit(() -> DaoUtil.convertDataList(
120 163 entityViewRepository.findAllByTenantIdAndEntityId(UUIDConverter.fromTimeUUID(tenantId), UUIDConverter.fromTimeUUID(entityId))));
... ...
... ... @@ -24,7 +24,7 @@ import java.util.Arrays;
24 24
25 25 @RunWith(ClasspathSuite.class)
26 26 @ClassnameFilters({
27   - "org.thingsboard.server.dao.service.*DeviceServiceSqlTest"
  27 + "org.thingsboard.server.dao.service.*ServiceSqlTest"
28 28 })
29 29 public class SqlDaoServiceTestSuite {
30 30
... ...
... ... @@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.Customer;
25 25 import org.thingsboard.server.common.data.EntitySubtype;
26 26 import org.thingsboard.server.common.data.Tenant;
27 27 import org.thingsboard.server.common.data.asset.Asset;
  28 +import org.thingsboard.server.common.data.asset.AssetInfo;
28 29 import org.thingsboard.server.common.data.id.CustomerId;
29 30 import org.thingsboard.server.common.data.id.TenantId;
30 31 import org.thingsboard.server.common.data.page.PageData;
... ... @@ -252,7 +253,7 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
252 253 @Test
253 254 public void testFindAssetsByTenantIdAndName() {
254 255 String title1 = "Asset title 1";
255   - List<Asset> assetsTitle1 = new ArrayList<>();
  256 + List<AssetInfo> assetsTitle1 = new ArrayList<>();
256 257 for (int i=0;i<143;i++) {
257 258 Asset asset = new Asset();
258 259 asset.setTenantId(tenantId);
... ... @@ -261,10 +262,10 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
261 262 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
262 263 asset.setName(name);
263 264 asset.setType("default");
264   - assetsTitle1.add(assetService.saveAsset(asset));
  265 + assetsTitle1.add(new AssetInfo(assetService.saveAsset(asset), null, false));
265 266 }
266 267 String title2 = "Asset title 2";
267   - List<Asset> assetsTitle2 = new ArrayList<>();
  268 + List<AssetInfo> assetsTitle2 = new ArrayList<>();
268 269 for (int i=0;i<175;i++) {
269 270 Asset asset = new Asset();
270 271 asset.setTenantId(tenantId);
... ... @@ -273,14 +274,14 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
273 274 name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
274 275 asset.setName(name);
275 276 asset.setType("default");
276   - assetsTitle2.add(assetService.saveAsset(asset));
  277 + assetsTitle2.add(new AssetInfo(assetService.saveAsset(asset), null, false));
277 278 }
278 279
279   - List<Asset> loadedAssetsTitle1 = new ArrayList<>();
  280 + List<AssetInfo> loadedAssetsTitle1 = new ArrayList<>();
280 281 PageLink pageLink = new PageLink(15, 0, title1);
281   - PageData<Asset> pageData = null;
  282 + PageData<AssetInfo> pageData = null;
282 283 do {
283   - pageData = assetService.findAssetsByTenantId(tenantId, pageLink);
  284 + pageData = assetService.findAssetInfosByTenantId(tenantId, pageLink);
284 285 loadedAssetsTitle1.addAll(pageData.getData());
285 286 if (pageData.hasNext()) {
286 287 pageLink = pageLink.nextPageLink();
... ... @@ -292,10 +293,10 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
292 293
293 294 Assert.assertEquals(assetsTitle1, loadedAssetsTitle1);
294 295
295   - List<Asset> loadedAssetsTitle2 = new ArrayList<>();
  296 + List<AssetInfo> loadedAssetsTitle2 = new ArrayList<>();
296 297 pageLink = new PageLink(4, 0, title2);
297 298 do {
298   - pageData = assetService.findAssetsByTenantId(tenantId, pageLink);
  299 + pageData = assetService.findAssetInfosByTenantId(tenantId, pageLink);
299 300 loadedAssetsTitle2.addAll(pageData.getData());
300 301 if (pageData.hasNext()) {
301 302 pageLink = pageLink.nextPageLink();
... ... @@ -312,7 +313,7 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
312 313 }
313 314
314 315 pageLink = new PageLink(4, 0, title1);
315   - pageData = assetService.findAssetsByTenantId(tenantId, pageLink);
  316 + pageData = assetService.findAssetInfosByTenantId(tenantId, pageLink);
316 317 Assert.assertFalse(pageData.hasNext());
317 318 Assert.assertEquals(0, pageData.getData().size());
318 319
... ... @@ -321,7 +322,7 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
321 322 }
322 323
323 324 pageLink = new PageLink(4, 0, title2);
324   - pageData = assetService.findAssetsByTenantId(tenantId, pageLink);
  325 + pageData = assetService.findAssetInfosByTenantId(tenantId, pageLink);
325 326 Assert.assertFalse(pageData.hasNext());
326 327 Assert.assertEquals(0, pageData.getData().size());
327 328 }
... ... @@ -419,21 +420,21 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
419 420 customer = customerService.saveCustomer(customer);
420 421 CustomerId customerId = customer.getId();
421 422
422   - List<Asset> assets = new ArrayList<>();
  423 + List<AssetInfo> assets = new ArrayList<>();
423 424 for (int i=0;i<278;i++) {
424 425 Asset asset = new Asset();
425 426 asset.setTenantId(tenantId);
426 427 asset.setName("Asset"+i);
427 428 asset.setType("default");
428 429 asset = assetService.saveAsset(asset);
429   - assets.add(assetService.assignAssetToCustomer(tenantId, asset.getId(), customerId));
  430 + assets.add(new AssetInfo(assetService.assignAssetToCustomer(tenantId, asset.getId(), customerId), customer.getTitle(), customer.isPublic()));
430 431 }
431 432
432   - List<Asset> loadedAssets = new ArrayList<>();
  433 + List<AssetInfo> loadedAssets = new ArrayList<>();
433 434 PageLink pageLink = new PageLink(23);
434   - PageData<Asset> pageData = null;
  435 + PageData<AssetInfo> pageData = null;
435 436 do {
436   - pageData = assetService.findAssetsByTenantIdAndCustomerId(tenantId, customerId, pageLink);
  437 + pageData = assetService.findAssetInfosByTenantIdAndCustomerId(tenantId, customerId, pageLink);
437 438 loadedAssets.addAll(pageData.getData());
438 439 if (pageData.hasNext()) {
439 440 pageLink = pageLink.nextPageLink();
... ... @@ -448,7 +449,7 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
448 449 assetService.unassignCustomerAssets(tenantId, customerId);
449 450
450 451 pageLink = new PageLink(33);
451   - pageData = assetService.findAssetsByTenantIdAndCustomerId(tenantId, customerId, pageLink);
  452 + pageData = assetService.findAssetInfosByTenantIdAndCustomerId(tenantId, customerId, pageLink);
452 453 Assert.assertFalse(pageData.hasNext());
453 454 Assert.assertTrue(pageData.getData().isEmpty());
454 455
... ...
... ... @@ -4,6 +4,7 @@ sql.ts_inserts_executor_type=fixed
4 4 sql.ts_inserts_fixed_thread_pool_size=10
5 5
6 6 spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
  7 +spring.jpa.properties.hibernate.order_by.default_null_ordering=last
7 8 spring.jpa.show-sql=false
8 9 spring.jpa.hibernate.ddl-auto=none
9 10 spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
... ...
... ... @@ -4,6 +4,7 @@ sql.ts_inserts_executor_type=fixed
4 4 sql.ts_inserts_fixed_thread_pool_size=10
5 5
6 6 spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
  7 +spring.jpa.properties.hibernate.order_by.default_null_ordering=last
7 8 spring.jpa.show-sql=false
8 9 spring.jpa.hibernate.ddl-auto=validate
9 10 spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
... ...