Commit c19cf2372e4d8e861f272b1f25d9a9390c5c0d9e
1 parent
3ffa7e35
Added findEntityViewByTenantIdAndEdgeIdAndType and findDevicesByTenantIdAndEdgeIdAndDeviceProfileId
Showing
12 changed files
with
176 additions
and
3 deletions
... | ... | @@ -701,6 +701,8 @@ public class DeviceController extends BaseController { |
701 | 701 | @PathVariable(EDGE_ID) String strEdgeId, |
702 | 702 | @RequestParam int pageSize, |
703 | 703 | @RequestParam int page, |
704 | + @RequestParam(required = false) String type, | |
705 | + @RequestParam(required = false) String deviceProfileId, | |
704 | 706 | @RequestParam(required = false) String textSearch, |
705 | 707 | @RequestParam(required = false) String sortProperty, |
706 | 708 | @RequestParam(required = false) String sortOrder, |
... | ... | @@ -712,7 +714,15 @@ public class DeviceController extends BaseController { |
712 | 714 | EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); |
713 | 715 | checkEdgeId(edgeId, Operation.READ); |
714 | 716 | TimePageLink pageLink = createTimePageLink(pageSize, page, textSearch, sortProperty, sortOrder, startTime, endTime); |
715 | - return checkNotNull(deviceService.findDevicesByTenantIdAndEdgeId(tenantId, edgeId, pageLink)); | |
717 | + if (type != null && type.trim().length() > 0) { | |
718 | + return checkNotNull(deviceService.findDevicesByTenantIdAndEdgeIdAndType(tenantId, edgeId, type, pageLink)); | |
719 | + } | |
720 | + else if (deviceProfileId != null && deviceProfileId.length() > 0) { | |
721 | + DeviceProfileId profileId = new DeviceProfileId(toUUID(deviceProfileId)); | |
722 | + return checkNotNull(deviceService.findDevicesByTenantIdAndEdgeIdAndDeviceProfileId(tenantId, edgeId, profileId, pageLink)); | |
723 | + } else { | |
724 | + return checkNotNull(deviceService.findDevicesByTenantIdAndEdgeId(tenantId, edgeId, pageLink)); | |
725 | + } | |
716 | 726 | } catch (Exception e) { |
717 | 727 | throw handleException(e); |
718 | 728 | } | ... | ... |
... | ... | @@ -677,6 +677,7 @@ public class EntityViewController extends BaseController { |
677 | 677 | @PathVariable(EDGE_ID) String strEdgeId, |
678 | 678 | @RequestParam int pageSize, |
679 | 679 | @RequestParam int page, |
680 | + @RequestParam(required = false) String type, | |
680 | 681 | @RequestParam(required = false) String textSearch, |
681 | 682 | @RequestParam(required = false) String sortProperty, |
682 | 683 | @RequestParam(required = false) String sortOrder, |
... | ... | @@ -688,7 +689,11 @@ public class EntityViewController extends BaseController { |
688 | 689 | EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); |
689 | 690 | checkEdgeId(edgeId, Operation.READ); |
690 | 691 | TimePageLink pageLink = createTimePageLink(pageSize, page, textSearch, sortProperty, sortOrder, startTime, endTime); |
691 | - return checkNotNull(entityViewService.findEntityViewsByTenantIdAndEdgeId(tenantId, edgeId, pageLink)); | |
692 | + if (type != null && type.trim().length() > 0) { | |
693 | + return checkNotNull(entityViewService.findEntityViewsByTenantIdAndEdgeIdAndType(tenantId, edgeId, type, pageLink)); | |
694 | + } else { | |
695 | + return checkNotNull(entityViewService.findEntityViewsByTenantIdAndEdgeId(tenantId, edgeId, pageLink)); | |
696 | + } | |
692 | 697 | } catch (Exception e) { |
693 | 698 | throw handleException(e); |
694 | 699 | } | ... | ... |
... | ... | @@ -90,4 +90,9 @@ public interface DeviceService { |
90 | 90 | Device unassignDeviceFromEdge(TenantId tenantId, DeviceId deviceId, EdgeId edgeId); |
91 | 91 | |
92 | 92 | PageData<Device> findDevicesByTenantIdAndEdgeId(TenantId tenantId, EdgeId edgeId, TimePageLink pageLink); |
93 | + | |
94 | + PageData<Device> findDevicesByTenantIdAndEdgeIdAndType(TenantId tenantId, EdgeId edgeId, String type, TimePageLink pageLink); | |
95 | + | |
96 | + PageData<Device> findDevicesByTenantIdAndEdgeIdAndDeviceProfileId(TenantId tenantId, EdgeId edgeId, DeviceProfileId deviceProfileId, TimePageLink pageLink); | |
97 | + | |
93 | 98 | } | ... | ... |
... | ... | @@ -83,4 +83,6 @@ public interface EntityViewService { |
83 | 83 | EntityView unassignEntityViewFromEdge(TenantId tenantId, EntityViewId entityViewId, EdgeId edgeId); |
84 | 84 | |
85 | 85 | PageData<EntityView> findEntityViewsByTenantIdAndEdgeId(TenantId tenantId, EdgeId edgeId, TimePageLink pageLink); |
86 | + | |
87 | + PageData<EntityView> findEntityViewsByTenantIdAndEdgeIdAndType(TenantId tenantId, EdgeId edgeId, String type, TimePageLink pageLink); | |
86 | 88 | } | ... | ... |
... | ... | @@ -226,4 +226,27 @@ public interface DeviceDao extends Dao<Device> { |
226 | 226 | * @return the list of device objects |
227 | 227 | */ |
228 | 228 | PageData<Device> findDevicesByTenantIdAndEdgeId(UUID tenantId, UUID edgeId, TimePageLink pageLink); |
229 | + | |
230 | + /** | |
231 | + * Find devices by tenantId, edgeId, type and page link. | |
232 | + * | |
233 | + * @param tenantId the tenantId | |
234 | + * @param edgeId the edgeId | |
235 | + * @param type the type | |
236 | + * @param pageLink the page link | |
237 | + * @return the list of device objects | |
238 | + */ | |
239 | + PageData<Device> findDevicesByTenantIdAndEdgeIdAndType(UUID tenantId, UUID edgeId, String type, TimePageLink pageLink); | |
240 | + | |
241 | + /** | |
242 | + * Find devices by tenantId, edgeId, type, deviceProfileId and page link. | |
243 | + * | |
244 | + * @param tenantId the tenantId | |
245 | + * @param edgeId the edgeId | |
246 | + * @param deviceProfileId the deviceProfileId | |
247 | + * @param pageLink the page link | |
248 | + * @return the list of device objects | |
249 | + */ | |
250 | + PageData<Device> findDevicesByTenantIdAndEdgeIdAndDeviceProfileId(UUID tenantId, UUID edgeId, UUID deviceProfileId, TimePageLink pageLink); | |
251 | + | |
229 | 252 | } | ... | ... |
... | ... | @@ -515,6 +515,26 @@ public class DeviceServiceImpl extends AbstractEntityService implements DeviceSe |
515 | 515 | return deviceDao.findDevicesByTenantIdAndEdgeId(tenantId.getId(), edgeId.getId(), pageLink); |
516 | 516 | } |
517 | 517 | |
518 | + @Override | |
519 | + public PageData<Device> findDevicesByTenantIdAndEdgeIdAndType(TenantId tenantId, EdgeId edgeId, String type, TimePageLink pageLink) { | |
520 | + log.trace("Executing findDevicesByTenantIdAndEdgeIdAndType, tenantId [{}], edgeId [{}], type [{}], pageLink [{}]", tenantId, edgeId, type, pageLink); | |
521 | + validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | |
522 | + validateId(edgeId, INCORRECT_EDGE_ID + edgeId); | |
523 | + validateString(type, "Incorrect type " + type); | |
524 | + validatePageLink(pageLink); | |
525 | + return deviceDao.findDevicesByTenantIdAndEdgeIdAndType(tenantId.getId(), edgeId.getId(), type, pageLink); | |
526 | + } | |
527 | + | |
528 | + @Override | |
529 | + public PageData<Device> findDevicesByTenantIdAndEdgeIdAndDeviceProfileId(TenantId tenantId, EdgeId edgeId, DeviceProfileId deviceProfileId, TimePageLink pageLink) { | |
530 | + log.trace("Executing findDevicesByTenantIdAndEdgeIdAndDeviceProfileId, tenantId [{}], edgeId [{}], deviceProfileId [{}], pageLink [{}]", tenantId, edgeId, deviceProfileId, pageLink); | |
531 | + validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | |
532 | + validateId(edgeId, INCORRECT_EDGE_ID + edgeId); | |
533 | + validateId(deviceProfileId, INCORRECT_DEVICE_PROFILE_ID + deviceProfileId); | |
534 | + validatePageLink(pageLink); | |
535 | + return deviceDao.findDevicesByTenantIdAndEdgeIdAndDeviceProfileId(tenantId.getId(), edgeId.getId(), deviceProfileId.getId(), pageLink); | |
536 | + } | |
537 | + | |
518 | 538 | private DataValidator<Device> deviceValidator = |
519 | 539 | new DataValidator<Device>() { |
520 | 540 | ... | ... |
... | ... | @@ -165,4 +165,18 @@ public interface EntityViewDao extends Dao<EntityView> { |
165 | 165 | UUID edgeId, |
166 | 166 | PageLink pageLink); |
167 | 167 | |
168 | + /** | |
169 | + * Find entity views by tenantId, edgeId, type and page link. | |
170 | + * | |
171 | + * @param tenantId the tenantId | |
172 | + * @param edgeId the edgeId | |
173 | + * @param type the type | |
174 | + * @param pageLink the page link | |
175 | + * @return the list of entity view objects | |
176 | + */ | |
177 | + PageData<EntityView> findEntityViewsByTenantIdAndEdgeIdAndType(UUID tenantId, | |
178 | + UUID edgeId, | |
179 | + String type, | |
180 | + PageLink pageLink); | |
181 | + | |
168 | 182 | } | ... | ... |
... | ... | @@ -390,6 +390,16 @@ public class EntityViewServiceImpl extends AbstractEntityService implements Enti |
390 | 390 | return entityViewDao.findEntityViewsByTenantIdAndEdgeId(tenantId.getId(), edgeId.getId(), pageLink); |
391 | 391 | } |
392 | 392 | |
393 | + @Override | |
394 | + public PageData<EntityView> findEntityViewsByTenantIdAndEdgeIdAndType(TenantId tenantId, EdgeId edgeId, String type, TimePageLink pageLink) { | |
395 | + log.trace("Executing findEntityViewsByTenantIdAndEdgeIdAndType, tenantId [{}], edgeId [{}], type [{}], pageLink [{}]", tenantId, edgeId, type, pageLink); | |
396 | + validateId(tenantId, INCORRECT_TENANT_ID + tenantId); | |
397 | + validateId(edgeId, INCORRECT_EDGE_ID + edgeId); | |
398 | + validateString(type, "Incorrect type " + type); | |
399 | + validatePageLink(pageLink); | |
400 | + return entityViewDao.findEntityViewsByTenantIdAndEdgeIdAndType(tenantId.getId(), edgeId.getId(), type, pageLink); | |
401 | + } | |
402 | + | |
393 | 403 | private DataValidator<EntityView> entityViewValidator = |
394 | 404 | new DataValidator<EntityView>() { |
395 | 405 | ... | ... |
... | ... | @@ -20,7 +20,6 @@ import org.springframework.data.domain.Pageable; |
20 | 20 | import org.springframework.data.jpa.repository.Query; |
21 | 21 | import org.springframework.data.repository.PagingAndSortingRepository; |
22 | 22 | import org.springframework.data.repository.query.Param; |
23 | -import org.thingsboard.server.dao.model.sql.AssetEntity; | |
24 | 23 | import org.thingsboard.server.dao.model.sql.DeviceEntity; |
25 | 24 | import org.thingsboard.server.dao.model.sql.DeviceInfoEntity; |
26 | 25 | |
... | ... | @@ -179,4 +178,42 @@ public interface DeviceRepository extends PagingAndSortingRepository<DeviceEntit |
179 | 178 | @Param("searchText") String searchText, |
180 | 179 | Pageable pageable); |
181 | 180 | |
181 | + @Query("SELECT d FROM DeviceEntity d, RelationEntity re WHERE d.tenantId = :tenantId " + | |
182 | + "AND d.id = re.toId AND re.toType = 'DEVICE' AND re.relationTypeGroup = 'EDGE' " + | |
183 | + "AND re.relationType = 'Contains' AND re.fromId = :edgeId AND re.fromType = 'EDGE' " + | |
184 | + "AND d.type = :type " + | |
185 | + "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") | |
186 | + Page<DeviceEntity> findByTenantIdAndEdgeIdAndType(@Param("tenantId") UUID tenantId, | |
187 | + @Param("edgeId") UUID edgeId, | |
188 | + @Param("type") String type, | |
189 | + @Param("searchText") String searchText, | |
190 | + Pageable pageable); | |
191 | + | |
192 | + @Query("SELECT d FROM DeviceEntity d, RelationEntity re " + | |
193 | + "LEFT JOIN DeviceProfileEntity p on p.id = d.deviceProfileId " + | |
194 | + "WHERE d.tenantId = :tenantId " + | |
195 | + "AND d.id = re.toId AND re.toType = 'DEVICE' AND re.relationTypeGroup = 'EDGE' " + | |
196 | + "AND re.relationType = 'Contains' AND re.fromId = :edgeId AND re.fromType = 'EDGE' " + | |
197 | + "AND d.deviceProfileId = :deviceProfileId " + | |
198 | + "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") | |
199 | + Page<DeviceEntity> findDevicesByTenantIdAndEdgeIdAndDeviceProfileId(@Param("tenantId") UUID tenantId, | |
200 | + @Param("edgeId") UUID edgeId, | |
201 | + @Param("deviceProfileId") UUID deviceProfileId, | |
202 | + @Param("searchText") String searchText, | |
203 | + Pageable pageable); | |
204 | + | |
205 | +// @Query("SELECT new org.thingsboard.server.dao.model.sql.DeviceInfoEntity(d, c.title, c.additionalInfo, p.name) " + | |
206 | +// "FROM DeviceEntity d " + | |
207 | +// "LEFT JOIN CustomerEntity c on c.id = d.customerId " + | |
208 | +// "LEFT JOIN DeviceProfileEntity p on p.id = d.deviceProfileId " + | |
209 | +// "WHERE d.tenantId = :tenantId " + | |
210 | +// "AND d.customerId = :customerId " + | |
211 | +// "AND d.deviceProfileId = :deviceProfileId " + | |
212 | +// "AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))") | |
213 | +// Page<DeviceInfoEntity> findDeviceInfosByTenantIdAndCustomerIdAndDeviceProfileId2(@Param("tenantId") UUID tenantId, | |
214 | +// @Param("customerId") UUID customerId, | |
215 | +// @Param("deviceProfileId") UUID deviceProfileId, | |
216 | +// @Param("textSearch") String textSearch, | |
217 | +// Pageable pageable); | |
218 | + | |
182 | 219 | } | ... | ... |
... | ... | @@ -243,4 +243,28 @@ public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> |
243 | 243 | Objects.toString(pageLink.getTextSearch(), ""), |
244 | 244 | DaoUtil.toPageable(pageLink))); |
245 | 245 | } |
246 | + | |
247 | + @Override | |
248 | + public PageData<Device> findDevicesByTenantIdAndEdgeIdAndType(UUID tenantId, UUID edgeId, String type, TimePageLink pageLink) { | |
249 | + log.debug("Try to find devices by tenantId [{}], edgeId [{}], type [{}] and pageLink [{}]", tenantId, edgeId, type, pageLink); | |
250 | + return DaoUtil.toPageData(deviceRepository | |
251 | + .findByTenantIdAndEdgeIdAndType( | |
252 | + tenantId, | |
253 | + edgeId, | |
254 | + type, | |
255 | + Objects.toString(pageLink.getTextSearch(), ""), | |
256 | + DaoUtil.toPageable(pageLink))); | |
257 | + } | |
258 | + | |
259 | + @Override | |
260 | + public PageData<Device> findDevicesByTenantIdAndEdgeIdAndDeviceProfileId(UUID tenantId, UUID edgeId, UUID deviceProfileId, TimePageLink pageLink) { | |
261 | + log.debug("Try to find devices by tenantId [{}], edgeId [{}], deviceProfileId [{}] and pageLink [{}]", tenantId, edgeId, deviceProfileId, pageLink); | |
262 | + return DaoUtil.toPageData(deviceRepository | |
263 | + .findDevicesByTenantIdAndEdgeIdAndDeviceProfileId( | |
264 | + tenantId, | |
265 | + edgeId, | |
266 | + deviceProfileId, | |
267 | + Objects.toString(pageLink.getTextSearch(), ""), | |
268 | + DaoUtil.toPageable(pageLink))); | |
269 | + } | |
246 | 270 | } | ... | ... |
... | ... | @@ -129,4 +129,15 @@ public interface EntityViewRepository extends PagingAndSortingRepository<EntityV |
129 | 129 | @Param("edgeId") UUID edgeId, |
130 | 130 | @Param("searchText") String searchText, |
131 | 131 | Pageable pageable); |
132 | + | |
133 | + @Query("SELECT ev FROM EntityViewEntity ev, RelationEntity re WHERE ev.tenantId = :tenantId " + | |
134 | + "AND ev.id = re.toId AND re.toType = 'ENTITY_VIEW' AND re.relationTypeGroup = 'EDGE' " + | |
135 | + "AND re.relationType = 'Contains' AND re.fromId = :edgeId AND re.fromType = 'EDGE' " + | |
136 | + "AND ev.type = :type " + | |
137 | + "AND LOWER(ev.searchText) LIKE LOWER(CONCAT(:searchText, '%'))") | |
138 | + Page<EntityViewEntity> findByTenantIdAndEdgeIdAndType(@Param("tenantId") UUID tenantId, | |
139 | + @Param("edgeId") UUID edgeId, | |
140 | + @Param("type") String type, | |
141 | + @Param("searchText") String searchText, | |
142 | + Pageable pageable); | |
132 | 143 | } | ... | ... |
... | ... | @@ -192,4 +192,16 @@ public class JpaEntityViewDao extends JpaAbstractSearchTextDao<EntityViewEntity, |
192 | 192 | Objects.toString(pageLink.getTextSearch(), ""), |
193 | 193 | DaoUtil.toPageable(pageLink))); |
194 | 194 | } |
195 | + | |
196 | + @Override | |
197 | + public PageData<EntityView> findEntityViewsByTenantIdAndEdgeIdAndType(UUID tenantId, UUID edgeId, String type, PageLink pageLink) { | |
198 | + log.debug("Try to find entity views by tenantId [{}], edgeId [{}], type [{}] and pageLink [{}]", tenantId, edgeId, type, pageLink); | |
199 | + return DaoUtil.toPageData(entityViewRepository | |
200 | + .findByTenantIdAndEdgeIdAndType( | |
201 | + tenantId, | |
202 | + edgeId, | |
203 | + type, | |
204 | + Objects.toString(pageLink.getTextSearch(), ""), | |
205 | + DaoUtil.toPageable(pageLink))); | |
206 | + } | |
195 | 207 | } | ... | ... |