Commit 7e00615a0d017e77695e5b0385d4dcab0345bba5

Authored by viktorbasanets
1 parent 1120f0a4

Was modified BaseController abstract class: added EntityViewService

@@ -56,6 +56,7 @@ import org.thingsboard.server.dao.customer.CustomerService; @@ -56,6 +56,7 @@ import org.thingsboard.server.dao.customer.CustomerService;
56 import org.thingsboard.server.dao.dashboard.DashboardService; 56 import org.thingsboard.server.dao.dashboard.DashboardService;
57 import org.thingsboard.server.dao.device.DeviceCredentialsService; 57 import org.thingsboard.server.dao.device.DeviceCredentialsService;
58 import org.thingsboard.server.dao.device.DeviceService; 58 import org.thingsboard.server.dao.device.DeviceService;
  59 +import org.thingsboard.server.dao.entityview.EntityViewService;
59 import org.thingsboard.server.dao.exception.DataValidationException; 60 import org.thingsboard.server.dao.exception.DataValidationException;
60 import org.thingsboard.server.dao.exception.IncorrectParameterException; 61 import org.thingsboard.server.dao.exception.IncorrectParameterException;
61 import org.thingsboard.server.dao.model.ModelConstants; 62 import org.thingsboard.server.dao.model.ModelConstants;
@@ -139,6 +140,9 @@ public abstract class BaseController { @@ -139,6 +140,9 @@ public abstract class BaseController {
139 @Autowired 140 @Autowired
140 protected DeviceStateService deviceStateService; 141 protected DeviceStateService deviceStateService;
141 142
  143 + @Autowired
  144 + protected EntityViewService entityViewService;
  145 +
142 @ExceptionHandler(ThingsboardException.class) 146 @ExceptionHandler(ThingsboardException.class)
143 public void handleThingsboardException(ThingsboardException ex, HttpServletResponse response) { 147 public void handleThingsboardException(ThingsboardException ex, HttpServletResponse response) {
144 errorResponseHandler.handle(ex, response); 148 errorResponseHandler.handle(ex, response);
@@ -313,6 +317,9 @@ public abstract class BaseController { @@ -313,6 +317,9 @@ public abstract class BaseController {
313 case USER: 317 case USER:
314 checkUserId(new UserId(entityId.getId())); 318 checkUserId(new UserId(entityId.getId()));
315 return; 319 return;
  320 + case ENTITY_VIEW:
  321 + checkEntityView(entityViewService.findEntityViewById(new EntityViewId(entityId.getId())));
  322 + return;
316 default: 323 default:
317 throw new IllegalArgumentException("Unsupported entity type: " + entityId.getEntityType()); 324 throw new IllegalArgumentException("Unsupported entity type: " + entityId.getEntityType());
318 } 325 }
@@ -340,6 +347,25 @@ public abstract class BaseController { @@ -340,6 +347,25 @@ public abstract class BaseController {
340 } 347 }
341 } 348 }
342 349
  350 + protected EntityView checkEntityViewId(EntityViewId entityViewId) throws ThingsboardException {
  351 + try {
  352 + validateId(entityViewId, "Incorrect entityViewId " + entityViewId);
  353 + EntityView entityView = entityViewService.findEntityViewById(entityViewId);
  354 + checkEntityView(entityView);
  355 + return entityView;
  356 + } catch (Exception e) {
  357 + throw handleException(e, false);
  358 + }
  359 + }
  360 +
  361 + protected void checkEntityView(EntityView entityView) throws ThingsboardException {
  362 + checkNotNull(entityView);
  363 + checkTenantId(entityView.getTenantId());
  364 + if (entityView.getCustomerId() != null && !entityView.getCustomerId().getId().equals(ModelConstants.NULL_UUID)) {
  365 + checkCustomerId(entityView.getCustomerId());
  366 + }
  367 + }
  368 +
343 Asset checkAssetId(AssetId assetId) throws ThingsboardException { 369 Asset checkAssetId(AssetId assetId) throws ThingsboardException {
344 try { 370 try {
345 validateId(assetId, "Incorrect assetId " + assetId); 371 validateId(assetId, "Incorrect assetId " + assetId);