DeviceInfo for Edge support
This commit is contained in:
parent
9e589c8044
commit
7a385e34d1
@ -680,7 +680,7 @@ public class DeviceController extends BaseController {
|
|||||||
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/edge/{edgeId}/devices", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
@RequestMapping(value = "/edge/{edgeId}/devices", params = {"pageSize", "page"}, method = RequestMethod.GET)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public PageData<Device> getEdgeDevices(
|
public PageData<DeviceInfo> getEdgeDevices(
|
||||||
@ApiParam(value = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
@ApiParam(value = EDGE_ID_PARAM_DESCRIPTION, required = true)
|
||||||
@PathVariable(EDGE_ID) String strEdgeId,
|
@PathVariable(EDGE_ID) String strEdgeId,
|
||||||
@ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
|
@ApiParam(value = PAGE_SIZE_DESCRIPTION, required = true)
|
||||||
@ -704,25 +704,13 @@ public class DeviceController extends BaseController {
|
|||||||
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
|
EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
|
||||||
checkEdgeId(edgeId, Operation.READ);
|
checkEdgeId(edgeId, Operation.READ);
|
||||||
TimePageLink pageLink = createTimePageLink(pageSize, page, textSearch, sortProperty, sortOrder, startTime, endTime);
|
TimePageLink pageLink = createTimePageLink(pageSize, page, textSearch, sortProperty, sortOrder, startTime, endTime);
|
||||||
PageData<Device> nonFilteredResult;
|
DeviceInfoFilter.DeviceInfoFilterBuilder filter = DeviceInfoFilter.builder();
|
||||||
|
filter.tenantId(tenantId);
|
||||||
|
filter.edgeId(edgeId);
|
||||||
if (type != null && type.trim().length() > 0) {
|
if (type != null && type.trim().length() > 0) {
|
||||||
nonFilteredResult = deviceService.findDevicesByTenantIdAndEdgeIdAndType(tenantId, edgeId, type, pageLink);
|
filter.type(type);
|
||||||
} else {
|
|
||||||
nonFilteredResult = deviceService.findDevicesByTenantIdAndEdgeId(tenantId, edgeId, pageLink);
|
|
||||||
}
|
}
|
||||||
List<Device> filteredDevices = nonFilteredResult.getData().stream().filter(device -> {
|
return checkNotNull(deviceService.findDeviceInfosByFilter(filter.build(), pageLink));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Count devices by device profile (countByDeviceProfileAndEmptyOtaPackage)",
|
@ApiOperation(value = "Count devices by device profile (countByDeviceProfileAndEmptyOtaPackage)",
|
||||||
|
|||||||
@ -38,6 +38,7 @@ import org.thingsboard.common.util.JacksonUtil;
|
|||||||
import org.thingsboard.common.util.ThingsBoardExecutors;
|
import org.thingsboard.common.util.ThingsBoardExecutors;
|
||||||
import org.thingsboard.server.common.data.Customer;
|
import org.thingsboard.server.common.data.Customer;
|
||||||
import org.thingsboard.server.common.data.Device;
|
import org.thingsboard.server.common.data.Device;
|
||||||
|
import org.thingsboard.server.common.data.DeviceInfo;
|
||||||
import org.thingsboard.server.common.data.DeviceProfile;
|
import org.thingsboard.server.common.data.DeviceProfile;
|
||||||
import org.thingsboard.server.common.data.EntitySubtype;
|
import org.thingsboard.server.common.data.EntitySubtype;
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.EntityType;
|
||||||
@ -1287,8 +1288,8 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
|
|||||||
savedDevice.getId().getId().toString(), savedEdge.getId().getId().toString(), savedEdge.getName());
|
savedDevice.getId().getId().toString(), savedEdge.getId().getId().toString(), savedEdge.getName());
|
||||||
testNotificationUpdateGatewayNever();
|
testNotificationUpdateGatewayNever();
|
||||||
|
|
||||||
pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId() + "/devices?",
|
PageData<DeviceInfo> pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId() + "/devices?",
|
||||||
PAGE_DATA_DEVICE_TYPE_REF, new PageLink(100));
|
new TypeReference<>() {}, new PageLink(100));
|
||||||
|
|
||||||
Assert.assertEquals(1, pageData.getData().size());
|
Assert.assertEquals(1, pageData.getData().size());
|
||||||
|
|
||||||
@ -1303,7 +1304,7 @@ public abstract class BaseDeviceControllerTest extends AbstractControllerTest {
|
|||||||
testNotificationUpdateGatewayNever();
|
testNotificationUpdateGatewayNever();
|
||||||
|
|
||||||
pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId() + "/devices?",
|
pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId() + "/devices?",
|
||||||
PAGE_DATA_DEVICE_TYPE_REF, new PageLink(100));
|
new TypeReference<>() {}, new PageLink(100));
|
||||||
|
|
||||||
Assert.assertEquals(0, pageData.getData().size());
|
Assert.assertEquals(0, pageData.getData().size());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import lombok.Builder;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.thingsboard.server.common.data.id.CustomerId;
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||||
|
import org.thingsboard.server.common.data.id.EdgeId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@ -27,6 +28,7 @@ public class DeviceInfoFilter {
|
|||||||
|
|
||||||
private TenantId tenantId;
|
private TenantId tenantId;
|
||||||
private CustomerId customerId;
|
private CustomerId customerId;
|
||||||
|
private EdgeId edgeId;
|
||||||
private String type;
|
private String type;
|
||||||
private DeviceProfileId deviceProfileId;
|
private DeviceProfileId deviceProfileId;
|
||||||
private Boolean active;
|
private Boolean active;
|
||||||
|
|||||||
@ -119,6 +119,7 @@ public interface DeviceRepository extends JpaRepository<DeviceEntity, UUID>, Exp
|
|||||||
@Query("SELECT d FROM DeviceInfoEntity d " +
|
@Query("SELECT d FROM DeviceInfoEntity d " +
|
||||||
"WHERE d.tenantId = :tenantId " +
|
"WHERE d.tenantId = :tenantId " +
|
||||||
"AND (:customerId IS NULL OR d.customerId = uuid(:customerId)) " +
|
"AND (:customerId IS NULL OR d.customerId = uuid(:customerId)) " +
|
||||||
|
"AND (:edgeId IS NULL OR d.id IN (SELECT re.toId FROM RelationEntity re WHERE re.toType = 'DEVICE' AND re.relationTypeGroup = 'EDGE' AND re.relationType = 'Contains' AND re.fromType = 'EDGE' AND re.fromId = uuid(:edgeId))) " +
|
||||||
"AND ((:deviceType) IS NULL OR d.type = :deviceType) " +
|
"AND ((:deviceType) IS NULL OR d.type = :deviceType) " +
|
||||||
"AND (:deviceProfileId IS NULL OR d.deviceProfileId = uuid(:deviceProfileId)) " +
|
"AND (:deviceProfileId IS NULL OR d.deviceProfileId = uuid(:deviceProfileId)) " +
|
||||||
"AND ((:filterByActive) IS FALSE OR d.active = :deviceActive) " +
|
"AND ((:filterByActive) IS FALSE OR d.active = :deviceActive) " +
|
||||||
@ -128,6 +129,7 @@ public interface DeviceRepository extends JpaRepository<DeviceEntity, UUID>, Exp
|
|||||||
"OR LOWER(d.customerTitle) LIKE LOWER(CONCAT('%', :textSearch, '%')))")
|
"OR LOWER(d.customerTitle) LIKE LOWER(CONCAT('%', :textSearch, '%')))")
|
||||||
Page<DeviceInfoEntity> findDeviceInfosByFilter(@Param("tenantId") UUID tenantId,
|
Page<DeviceInfoEntity> findDeviceInfosByFilter(@Param("tenantId") UUID tenantId,
|
||||||
@Param("customerId") String customerId,
|
@Param("customerId") String customerId,
|
||||||
|
@Param("edgeId") String edgeId,
|
||||||
@Param("deviceType") String type,
|
@Param("deviceType") String type,
|
||||||
@Param("deviceProfileId") String deviceProfileId,
|
@Param("deviceProfileId") String deviceProfileId,
|
||||||
@Param("filterByActive") boolean filterByActive,
|
@Param("filterByActive") boolean filterByActive,
|
||||||
|
|||||||
@ -115,6 +115,7 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device>
|
|||||||
deviceRepository.findDeviceInfosByFilter(
|
deviceRepository.findDeviceInfosByFilter(
|
||||||
filter.getTenantId().getId(),
|
filter.getTenantId().getId(),
|
||||||
DaoUtil.getStringId(filter.getCustomerId()),
|
DaoUtil.getStringId(filter.getCustomerId()),
|
||||||
|
DaoUtil.getStringId(filter.getEdgeId()),
|
||||||
filter.getType(),
|
filter.getType(),
|
||||||
DaoUtil.getStringId(filter.getDeviceProfileId()),
|
DaoUtil.getStringId(filter.getDeviceProfileId()),
|
||||||
filter.getActive() != null,
|
filter.getActive() != null,
|
||||||
|
|||||||
@ -881,6 +881,9 @@ FROM device d
|
|||||||
LEFT JOIN customer c ON c.id = d.customer_id
|
LEFT JOIN customer c ON c.id = d.customer_id
|
||||||
LEFT JOIN ts_kv_latest dt ON dt.entity_id = d.id and dt.key = (select key_id from ts_kv_dictionary where key = 'active');
|
LEFT JOIN ts_kv_latest dt ON dt.entity_id = d.id and dt.key = (select key_id from ts_kv_dictionary where key = 'active');
|
||||||
|
|
||||||
|
DROP VIEW IF EXISTS device_info_view CASCADE;
|
||||||
|
CREATE OR REPLACE VIEW device_info_view AS SELECT * FROM device_info_active_attribute_view;
|
||||||
|
|
||||||
DROP VIEW IF EXISTS alarm_info CASCADE;
|
DROP VIEW IF EXISTS alarm_info CASCADE;
|
||||||
CREATE VIEW alarm_info AS
|
CREATE VIEW alarm_info AS
|
||||||
SELECT a.*,
|
SELECT a.*,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user