Browse Source

Merge remote-tracking branch 'origin/develop/2.6-edge' into develop/3.3-edge

pull/3811/head
Volodymyr Babak 6 years ago
parent
commit
eb24519772
  1. 20
      application/src/main/java/org/thingsboard/server/controller/AssetController.java
  2. 18
      application/src/main/java/org/thingsboard/server/controller/DashboardController.java
  3. 23
      application/src/main/java/org/thingsboard/server/controller/DeviceController.java
  4. 23
      application/src/main/java/org/thingsboard/server/controller/EntityViewController.java
  5. 2
      common/dao-api/src/main/java/org/thingsboard/server/dao/device/DeviceService.java
  6. 11
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java
  7. 11
      dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java
  8. 11
      dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java
  9. 12
      dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java
  10. 8
      ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts
  11. 8
      ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts
  12. 10
      ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts
  13. 8
      ui-ngx/src/app/modules/home/pages/edge/edge.component.html
  14. 28
      ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts
  15. 8
      ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts

20
application/src/main/java/org/thingsboard/server/controller/AssetController.java

@ -488,7 +488,7 @@ public class AssetController extends BaseController {
}
}
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/edge/{edgeId}/assets", params = {"pageSize", "page"}, method = RequestMethod.GET)
@ResponseBody
public PageData<Asset> getEdgeAssets(
@ -507,11 +507,25 @@ public class AssetController extends BaseController {
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
checkEdgeId(edgeId, Operation.READ);
TimePageLink pageLink = createTimePageLink(pageSize, page, textSearch, sortProperty, sortOrder, startTime, endTime);
PageData<Asset> nonFilteredResult;
if (type != null && type.trim().length() > 0) {
return checkNotNull(assetService.findAssetsByTenantIdAndEdgeIdAndType(tenantId, edgeId, type, pageLink));
nonFilteredResult = assetService.findAssetsByTenantIdAndEdgeIdAndType(tenantId, edgeId, type, pageLink);
} else {
return checkNotNull(assetService.findAssetsByTenantIdAndEdgeId(tenantId, edgeId, pageLink));
nonFilteredResult = assetService.findAssetsByTenantIdAndEdgeId(tenantId, edgeId, pageLink);
}
List<Asset> filteredAssets = nonFilteredResult.getData().stream().filter(asset -> {
try {
accessControlService.checkPermission(getCurrentUser(), Resource.ASSET, Operation.READ, asset.getId(), asset);
return true;
} catch (ThingsboardException e) {
return false;
}
}).collect(Collectors.toList());
PageData<Asset> filteredResult = new PageData<>(filteredAssets,
nonFilteredResult.getTotalPages(),
nonFilteredResult.getTotalElements(),
nonFilteredResult.hasNext());
return checkNotNull(filteredResult);
} catch (Exception e) {
throw handleException(e);
}

18
application/src/main/java/org/thingsboard/server/controller/DashboardController.java

@ -49,6 +49,7 @@ import org.thingsboard.server.service.security.permission.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@RestController
@TbCoreComponent
@ -555,7 +556,7 @@ public class DashboardController extends BaseController {
}
}
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/edge/{edgeId}/dashboards", params = {"pageSize", "page"}, method = RequestMethod.GET)
@ResponseBody
public PageData<DashboardInfo> getEdgeDashboards(
@ -573,7 +574,20 @@ public class DashboardController extends BaseController {
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
checkEdgeId(edgeId, Operation.READ);
TimePageLink pageLink = createTimePageLink(pageSize, page, textSearch, sortProperty, sortOrder, startTime, endTime);
return checkNotNull(dashboardService.findDashboardsByTenantIdAndEdgeId(tenantId, edgeId, pageLink));
PageData<DashboardInfo> nonFilteredResult = dashboardService.findDashboardsByTenantIdAndEdgeId(tenantId, edgeId, pageLink);
List<DashboardInfo> filteredDashboards = nonFilteredResult.getData().stream().filter(dashboardInfo -> {
try {
accessControlService.checkPermission(getCurrentUser(), Resource.DASHBOARD, Operation.READ, dashboardInfo.getId(), dashboardInfo);
return true;
} catch (ThingsboardException e) {
return false;
}
}).collect(Collectors.toList());
PageData<DashboardInfo> filteredResult = new PageData<>(filteredDashboards,
nonFilteredResult.getTotalPages(),
nonFilteredResult.getTotalElements(),
nonFilteredResult.hasNext());
return checkNotNull(filteredResult);
} catch (Exception e) {
throw handleException(e);
}

23
application/src/main/java/org/thingsboard/server/controller/DeviceController.java

@ -711,13 +711,14 @@ public class DeviceController extends BaseController {
}
}
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/edge/{edgeId}/devices", params = {"pageSize", "page"}, method = RequestMethod.GET)
@ResponseBody
public PageData<Device> getEdgeDevices(
@PathVariable(EDGE_ID) String strEdgeId,
@RequestParam int pageSize,
@RequestParam int page,
@RequestParam(required = false) String type,
@RequestParam(required = false) String textSearch,
@RequestParam(required = false) String sortProperty,
@RequestParam(required = false) String sortOrder,
@ -729,7 +730,25 @@ public class DeviceController extends BaseController {
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
checkEdgeId(edgeId, Operation.READ);
TimePageLink pageLink = createTimePageLink(pageSize, page, textSearch, sortProperty, sortOrder, startTime, endTime);
return checkNotNull(deviceService.findDevicesByTenantIdAndEdgeId(tenantId, edgeId, pageLink));
PageData<Device> nonFilteredResult;
if (type != null && type.trim().length() > 0) {
nonFilteredResult = deviceService.findDevicesByTenantIdAndEdgeIdAndType(tenantId, edgeId, type, pageLink);
} else {
nonFilteredResult = deviceService.findDevicesByTenantIdAndEdgeId(tenantId, edgeId, pageLink);
}
List<Device> filteredDevices = nonFilteredResult.getData().stream().filter(device -> {
try {
accessControlService.checkPermission(getCurrentUser(), Resource.DEVICE, Operation.READ, device.getId(), device);
return true;
} catch (ThingsboardException e) {
return false;
}
}).collect(Collectors.toList());
PageData<Device> filteredResult = new PageData<>(filteredDevices,
nonFilteredResult.getTotalPages(),
nonFilteredResult.getTotalElements(),
nonFilteredResult.hasNext());
return checkNotNull(filteredResult);
} catch (Exception e) {
throw handleException(e);
}

23
application/src/main/java/org/thingsboard/server/controller/EntityViewController.java

@ -38,6 +38,7 @@ import org.thingsboard.server.common.data.EntitySubtype;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.EntityView;
import org.thingsboard.server.common.data.EntityViewInfo;
import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.audit.ActionType;
import org.thingsboard.server.common.data.edge.Edge;
import org.thingsboard.server.common.data.edge.EdgeEventActionType;
@ -258,7 +259,7 @@ public class EntityViewController extends BaseController {
private ListenableFuture<List<Void>> copyLatestFromEntityToEntityView(EntityView entityView, SecurityUser user) {
EntityViewId entityId = entityView.getId();
List<String> keys = entityView.getKeys() != null && entityView.getKeys().getTimeseries() != null ?
entityView.getKeys().getTimeseries() : Collections.emptyList();
entityView.getKeys().getTimeseries() : Collections.emptyList();
long startTs = entityView.getStartTimeMs();
long endTs = entityView.getEndTimeMs() == 0 ? Long.MAX_VALUE : entityView.getEndTimeMs();
ListenableFuture<List<String>> keysFuture;
@ -673,7 +674,7 @@ public class EntityViewController extends BaseController {
}
}
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/edge/{edgeId}/entityViews", params = {"pageSize", "page"}, method = RequestMethod.GET)
@ResponseBody
public PageData<EntityView> getEdgeEntityViews(
@ -692,11 +693,25 @@ public class EntityViewController extends BaseController {
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
checkEdgeId(edgeId, Operation.READ);
TimePageLink pageLink = createTimePageLink(pageSize, page, textSearch, sortProperty, sortOrder, startTime, endTime);
PageData<EntityView> nonFilteredResult;
if (type != null && type.trim().length() > 0) {
return checkNotNull(entityViewService.findEntityViewsByTenantIdAndEdgeIdAndType(tenantId, edgeId, type, pageLink));
nonFilteredResult = entityViewService.findEntityViewsByTenantIdAndEdgeIdAndType(tenantId, edgeId, type, pageLink);
} else {
return checkNotNull(entityViewService.findEntityViewsByTenantIdAndEdgeId(tenantId, edgeId, pageLink));
nonFilteredResult = entityViewService.findEntityViewsByTenantIdAndEdgeId(tenantId, edgeId, pageLink);
}
List<EntityView> filteredEntityViews = nonFilteredResult.getData().stream().filter(entityView -> {
try {
accessControlService.checkPermission(getCurrentUser(), Resource.ENTITY_VIEW, Operation.READ, entityView.getId(), entityView);
return true;
} catch (ThingsboardException e) {
return false;
}
}).collect(Collectors.toList());
PageData<EntityView> filteredResult = new PageData<>(filteredEntityViews,
nonFilteredResult.getTotalPages(),
nonFilteredResult.getTotalElements(),
nonFilteredResult.hasNext());
return checkNotNull(filteredResult);
} catch (Exception e) {
throw handleException(e);
}

2
common/dao-api/src/main/java/org/thingsboard/server/dao/device/DeviceService.java

@ -94,4 +94,6 @@ public interface DeviceService {
Device unassignDeviceFromEdge(TenantId tenantId, DeviceId deviceId, EdgeId edgeId);
PageData<Device> findDevicesByTenantIdAndEdgeId(TenantId tenantId, EdgeId edgeId, TimePageLink pageLink);
PageData<Device> findDevicesByTenantIdAndEdgeIdAndType(TenantId tenantId, EdgeId edgeId, String type, TimePageLink pageLink);
}

11
dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java

@ -227,4 +227,15 @@ public interface DeviceDao extends Dao<Device>, TenantEntityDao {
* @return the list of device objects
*/
PageData<Device> findDevicesByTenantIdAndEdgeId(UUID tenantId, UUID edgeId, TimePageLink pageLink);
/**
* Find devices by tenantId, edgeId, type and page link.
*
* @param tenantId the tenantId
* @param edgeId the edgeId
* @param type the type
* @param pageLink the page link
* @return the list of device objects
*/
PageData<Device> findDevicesByTenantIdAndEdgeIdAndType(UUID tenantId, UUID edgeId, String type, TimePageLink pageLink);
}

11
dao/src/main/java/org/thingsboard/server/dao/device/DeviceServiceImpl.java

@ -40,6 +40,7 @@ import org.thingsboard.server.common.data.EntitySubtype;
import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.EntityView;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.device.DeviceSearchQuery;
import org.thingsboard.server.common.data.device.credentials.BasicMqttCredentials;
import org.thingsboard.server.common.data.device.data.DefaultDeviceConfiguration;
@ -571,6 +572,16 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe
return deviceDao.findDevicesByTenantIdAndEdgeId(tenantId.getId(), edgeId.getId(), pageLink);
}
@Override
public PageData<Device> findDevicesByTenantIdAndEdgeIdAndType(TenantId tenantId, EdgeId edgeId, String type, TimePageLink pageLink) {
log.trace("Executing findDevicesByTenantIdAndEdgeIdAndType, tenantId [{}], edgeId [{}], type [{}] pageLink [{}]", tenantId, edgeId, type, pageLink);
validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
validateId(edgeId, INCORRECT_EDGE_ID + edgeId);
validateString(type, "Incorrect type " + type);
validatePageLink(pageLink);
return deviceDao.findDevicesByTenantIdAndEdgeIdAndType(tenantId.getId(), edgeId.getId(), type, pageLink);
}
private DataValidator<Device> deviceValidator =
new DataValidator<Device>() {

11
dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java

@ -178,5 +178,16 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit
@Param("searchText") String searchText,
Pageable pageable);
@Query("SELECT d FROM DeviceEntity d, RelationEntity re WHERE d.tenantId = :tenantId " +
"AND d.id = re.toId AND re.toType = 'DEVICE' AND re.relationTypeGroup = 'EDGE' " +
"AND re.relationType = 'Contains' AND re.fromId = :edgeId AND re.fromType = 'EDGE' " +
"AND d.type = :type " +
"AND LOWER(d.searchText) LIKE LOWER(CONCAT(:searchText, '%'))")
Page<DeviceEntity> findByTenantIdAndEdgeIdAndType(@Param("tenantId") UUID tenantId,
@Param("edgeId") UUID edgeId,
@Param("type") String type,
@Param("searchText") String searchText,
Pageable pageable);
Long countByTenantId(UUID tenantId);
}

12
dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java

@ -248,4 +248,16 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
Objects.toString(pageLink.getTextSearch(), ""),
DaoUtil.toPageable(pageLink)));
}
@Override
public PageData<Device> findDevicesByTenantIdAndEdgeIdAndType(UUID tenantId, UUID edgeId, String type, TimePageLink pageLink) {
log.debug("Try to find devices by tenantId [{}], edgeId [{}], type [{}] and pageLink [{}]", tenantId, edgeId, type, pageLink);
return DaoUtil.toPageData(deviceRepository
.findByTenantIdAndEdgeIdAndType(
tenantId,
edgeId,
type,
Objects.toString(pageLink.getTextSearch(), ""),
DaoUtil.toPageable(pageLink)));
}
}

8
ui-ngx/src/app/modules/home/pages/asset/assets-table-config.resolver.ts

@ -121,7 +121,11 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
return this.store.pipe(select(selectAuthUser), take(1)).pipe(
tap((authUser) => {
if (authUser.authority === Authority.CUSTOMER_USER) {
this.config.componentsData.assetScope = 'customer_user';
if (route.data.assetsType === 'edge') {
this.config.componentsData.assetScope = 'edge_customer_user';
} else {
this.config.componentsData.assetScope = 'customer_user';
}
this.customerId = authUser.customerId;
}
}),
@ -179,7 +183,7 @@ export class AssetsTableConfigResolver implements Resolve<EntityTableConfig<Asse
this.config.entitiesFetchFunction = pageLink =>
this.assetService.getTenantAssetInfos(pageLink, this.config.componentsData.assetType);
this.config.deleteEntity = id => this.assetService.deleteAsset(id.id);
} else if (assetScope === 'edge') {
} else if (assetScope === 'edge' || assetScope === 'edge_customer_user') {
this.config.entitiesFetchFunction = pageLink =>
this.assetService.getEdgeAssets(this.config.componentsData.edgeId, pageLink, this.config.componentsData.assetType);
} else {

8
ui-ngx/src/app/modules/home/pages/dashboard/dashboards-table-config.resolver.ts

@ -116,7 +116,11 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
return this.store.pipe(select(selectAuthUser), take(1)).pipe(
tap((authUser) => {
if (authUser.authority === Authority.CUSTOMER_USER) {
this.config.componentsData.dashboardScope = 'customer_user';
if (route.data.dashboardsType === 'edge') {
this.config.componentsData.dashboardScope = 'edge_customer_user';
} else {
this.config.componentsData.dashboardScope = 'customer_user';
}
this.config.componentsData.customerId = authUser.customerId;
}
}),
@ -176,7 +180,7 @@ export class DashboardsTableConfigResolver implements Resolve<EntityTableConfig<
this.config.entitiesFetchFunction = pageLink =>
this.dashboardService.getTenantDashboards(pageLink);
this.config.deleteEntity = id => this.dashboardService.deleteDashboard(id.id);
} else if (dashboardScope === 'edge') {
} else if (dashboardScope === 'edge' || dashboardScope === 'edge_customer_user') {
this.config.entitiesFetchFunction = pageLink =>
this.dashboardService.getEdgeDashboards(this.config.componentsData.edgeId, pageLink, this.config.componentsData.dashboardsType);
} else {

10
ui-ngx/src/app/modules/home/pages/device/devices-table-config.resolver.ts

@ -131,7 +131,11 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
return this.store.pipe(select(selectAuthUser), take(1)).pipe(
tap((authUser) => {
if (authUser.authority === Authority.CUSTOMER_USER) {
this.config.componentsData.deviceScope = 'customer_user';
if (route.data.devicesType === 'edge') {
this.config.componentsData.deviceScope = 'edge_customer_user';
} else {
this.config.componentsData.deviceScope = 'customer_user';
}
this.customerId = authUser.customerId;
}
}),
@ -197,7 +201,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
this.config.componentsData.deviceProfileId !== null ?
this.config.componentsData.deviceProfileId.id : '');
this.config.deleteEntity = id => this.deviceService.deleteDevice(id.id);
} else if (deviceScope === 'edge') {
} else if (deviceScope === 'edge' || deviceScope === 'edge_customer_user') {
this.config.entitiesFetchFunction = pageLink =>
this.deviceService.getEdgeDevices(this.config.componentsData.edgeId, pageLink, this.config.componentsData.edgeType);
} else {
@ -267,7 +271,7 @@ export class DevicesTableConfigResolver implements Resolve<EntityTableConfig<Dev
}
);
}
if (deviceScope === 'customer_user') {
if (deviceScope === 'customer_user' || deviceScope === 'edge_customer_user') {
actions.push(
{
name: this.translate.instant('device.view-credentials'),

8
ui-ngx/src/app/modules/home/pages/edge/edge.component.html

@ -44,25 +44,25 @@
<button mat-raised-button color="primary"
[disabled]="(isLoading$ | async)"
(click)="onEntityAction($event, 'openEdgeAssets')"
[fxShow]="!isEdit && edgeScope === 'tenant'">
[fxShow]="!isEdit && (edgeScope === 'tenant' || edgeScope === 'customer_user')">
{{'edge.manage-edge-assets' | translate }}
</button>
<button mat-raised-button color="primary"
[disabled]="(isLoading$ | async)"
(click)="onEntityAction($event, 'openEdgeDevices')"
[fxShow]="!isEdit && edgeScope === 'tenant'">
[fxShow]="!isEdit && (edgeScope === 'tenant' || edgeScope === 'customer_user')">
{{'edge.manage-edge-devices' | translate }}
</button>
<button mat-raised-button color="primary"
[disabled]="(isLoading$ | async)"
(click)="onEntityAction($event, 'openEdgeEntityViews')"
[fxShow]="!isEdit && edgeScope === 'tenant'">
[fxShow]="!isEdit && (edgeScope === 'tenant' || edgeScope === 'customer_user')">
{{'edge.manage-edge-entity-views' | translate }}
</button>
<button mat-raised-button color="primary"
[disabled]="(isLoading$ | async)"
(click)="onEntityAction($event, 'openEdgeDashboards')"
[fxShow]="!isEdit && edgeScope === 'tenant'">
[fxShow]="!isEdit && (edgeScope === 'tenant' || edgeScope === 'customer_user')">
{{'edge.manage-edge-dashboards' | translate }}
</button>
<button mat-raised-button color="primary"

28
ui-ngx/src/app/modules/home/pages/edge/edges-table-config.resolver.ts

@ -254,6 +254,34 @@ export class EdgesTableConfigResolver implements Resolve<EntityTableConfig<EdgeI
},
);
}
if (edgeScope === 'customer_user') {
actions.push(
{
name: this.translate.instant('edge.manage-edge-assets'),
icon: 'domain',
isEnabled: (entity) => true,
onAction: ($event, entity) => this.openEdgeAssets($event, entity)
},
{
name: this.translate.instant('edge.manage-edge-devices'),
icon: 'devices_other',
isEnabled: (entity) => true,
onAction: ($event, entity) => this.openEdgeDevices($event, entity)
},
{
name: this.translate.instant('edge.manage-edge-entity-views'),
icon: 'view_quilt',
isEnabled: (entity) => true,
onAction: ($event, entity) => this.openEdgeEntityViews($event, entity)
},
{
name: this.translate.instant('edge.manage-edge-dashboards'),
icon: 'dashboard',
isEnabled: (entity) => true,
onAction: ($event, entity) => this.openEdgeDashboards($event, entity)
}
);
}
return actions;
}

8
ui-ngx/src/app/modules/home/pages/entity-view/entity-views-table-config.resolver.ts

@ -121,7 +121,11 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
return this.store.pipe(select(selectAuthUser), take(1)).pipe(
tap((authUser) => {
if (authUser.authority === Authority.CUSTOMER_USER) {
this.config.componentsData.entityViewScope = 'customer_user';
if (route.data.entityViewsType === 'edge') {
this.config.componentsData.entityViewScope = 'edge_customer_user';
} else {
this.config.componentsData.entityViewScope = 'customer_user';
}
this.customerId = authUser.customerId;
}
}),
@ -179,7 +183,7 @@ export class EntityViewsTableConfigResolver implements Resolve<EntityTableConfig
this.config.entitiesFetchFunction = pageLink =>
this.entityViewService.getTenantEntityViewInfos(pageLink, this.config.componentsData.entityViewType);
this.config.deleteEntity = id => this.entityViewService.deleteEntityView(id.id);
} else if (entityViewScope === 'edge') {
} else if (entityViewScope === 'edge' || entityViewScope === 'edge_customer_user') {
this.config.entitiesFetchFunction = pageLink =>
this.entityViewService.getEdgeEntityViews(this.config.componentsData.edgeId, pageLink, this.config.componentsData.entityViewType);
} else {

Loading…
Cancel
Save