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 56 import org.thingsboard.server.dao.dashboard.DashboardService;
57 57 import org.thingsboard.server.dao.device.DeviceCredentialsService;
58 58 import org.thingsboard.server.dao.device.DeviceService;
  59 +import org.thingsboard.server.dao.entityview.EntityViewService;
59 60 import org.thingsboard.server.dao.exception.DataValidationException;
60 61 import org.thingsboard.server.dao.exception.IncorrectParameterException;
61 62 import org.thingsboard.server.dao.model.ModelConstants;
... ... @@ -139,6 +140,9 @@ public abstract class BaseController {
139 140 @Autowired
140 141 protected DeviceStateService deviceStateService;
141 142
  143 + @Autowired
  144 + protected EntityViewService entityViewService;
  145 +
142 146 @ExceptionHandler(ThingsboardException.class)
143 147 public void handleThingsboardException(ThingsboardException ex, HttpServletResponse response) {
144 148 errorResponseHandler.handle(ex, response);
... ... @@ -313,6 +317,9 @@ public abstract class BaseController {
313 317 case USER:
314 318 checkUserId(new UserId(entityId.getId()));
315 319 return;
  320 + case ENTITY_VIEW:
  321 + checkEntityView(entityViewService.findEntityViewById(new EntityViewId(entityId.getId())));
  322 + return;
316 323 default:
317 324 throw new IllegalArgumentException("Unsupported entity type: " + entityId.getEntityType());
318 325 }
... ... @@ -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 369 Asset checkAssetId(AssetId assetId) throws ThingsboardException {
344 370 try {
345 371 validateId(assetId, "Incorrect assetId " + assetId);
... ...