Commit e740e4368a8d5b6e326032c5c1c36068c0065177

Authored by Vladyslav_Prykhodko
1 parent 08b346da

Added parameter filter for transport type in deviceProfile API

... ... @@ -192,10 +192,11 @@ public class DeviceProfileController extends BaseController {
192 192 @RequestParam int page,
193 193 @RequestParam(required = false) String textSearch,
194 194 @RequestParam(required = false) String sortProperty,
195   - @RequestParam(required = false) String sortOrder) throws ThingsboardException {
  195 + @RequestParam(required = false) String sortOrder,
  196 + @RequestParam(required = false) String transportType) throws ThingsboardException {
196 197 try {
197 198 PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder);
198   - return checkNotNull(deviceProfileService.findDeviceProfileInfos(getTenantId(), pageLink));
  199 + return checkNotNull(deviceProfileService.findDeviceProfileInfos(getTenantId(), pageLink, transportType));
199 200 } catch (Exception e) {
200 201 throw handleException(e);
201 202 }
... ...
... ... @@ -37,7 +37,7 @@ public interface DeviceProfileService {
37 37
38 38 PageData<DeviceProfile> findDeviceProfiles(TenantId tenantId, PageLink pageLink);
39 39
40   - PageData<DeviceProfileInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink);
  40 + PageData<DeviceProfileInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink, String transportType);
41 41
42 42 DeviceProfile findOrCreateDeviceProfile(TenantId tenantId, String profileName);
43 43
... ...
... ... @@ -32,7 +32,7 @@ public interface DeviceProfileDao extends Dao<DeviceProfile> {
32 32
33 33 PageData<DeviceProfile> findDeviceProfiles(TenantId tenantId, PageLink pageLink);
34 34
35   - PageData<DeviceProfileInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink);
  35 + PageData<DeviceProfileInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink, String transportType);
36 36
37 37 DeviceProfile findDefaultDeviceProfile(TenantId tenantId);
38 38
... ...
... ... @@ -178,11 +178,11 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D
178 178 }
179 179
180 180 @Override
181   - public PageData<DeviceProfileInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink) {
  181 + public PageData<DeviceProfileInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink, String transportType) {
182 182 log.trace("Executing findDeviceProfileInfos tenantId [{}], pageLink [{}]", tenantId, pageLink);
183 183 validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
184 184 Validator.validatePageLink(pageLink);
185   - return deviceProfileDao.findDeviceProfileInfos(tenantId, pageLink);
  185 + return deviceProfileDao.findDeviceProfileInfos(tenantId, pageLink, transportType);
186 186 }
187 187
188 188 @Cacheable(cacheNames = DEVICE_PROFILE_CACHE, key = "{#tenantId.id, #name}")
... ...
... ... @@ -22,6 +22,7 @@ import org.springframework.data.repository.PagingAndSortingRepository;
22 22 import org.springframework.data.repository.query.Param;
23 23 import org.thingsboard.server.common.data.DeviceProfile;
24 24 import org.thingsboard.server.common.data.DeviceProfileInfo;
  25 +import org.thingsboard.server.common.data.DeviceTransportType;
25 26 import org.thingsboard.server.dao.model.sql.DeviceProfileEntity;
26 27
27 28 import java.util.UUID;
... ... @@ -46,6 +47,14 @@ public interface DeviceProfileRepository extends PagingAndSortingRepository<Devi
46 47 @Param("textSearch") String textSearch,
47 48 Pageable pageable);
48 49
  50 + @Query("SELECT new org.thingsboard.server.common.data.DeviceProfileInfo(d.id, d.name, d.type, d.transportType) " +
  51 + "FROM DeviceProfileEntity d WHERE " +
  52 + "d.tenantId = :tenantId AND d.transportType = :transportType AND LOWER(d.searchText) LIKE LOWER(CONCAT(:textSearch, '%'))")
  53 + Page<DeviceProfileInfo> findDeviceProfileInfos(@Param("tenantId") UUID tenantId,
  54 + @Param("textSearch") String textSearch,
  55 + @Param("transportType") DeviceTransportType transportType,
  56 + Pageable pageable);
  57 +
49 58 @Query("SELECT d FROM DeviceProfileEntity d " +
50 59 "WHERE d.tenantId = :tenantId AND d.isDefault = true")
51 60 DeviceProfileEntity findByDefaultTrueAndTenantId(@Param("tenantId") UUID tenantId);
... ...
... ... @@ -15,11 +15,13 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.device;
17 17
  18 +import org.apache.commons.lang.StringUtils;
18 19 import org.springframework.beans.factory.annotation.Autowired;
19 20 import org.springframework.data.repository.CrudRepository;
20 21 import org.springframework.stereotype.Component;
21 22 import org.thingsboard.server.common.data.DeviceProfile;
22 23 import org.thingsboard.server.common.data.DeviceProfileInfo;
  24 +import org.thingsboard.server.common.data.DeviceTransportType;
23 25 import org.thingsboard.server.common.data.id.TenantId;
24 26 import org.thingsboard.server.common.data.page.PageData;
25 27 import org.thingsboard.server.common.data.page.PageLink;
... ... @@ -62,12 +64,21 @@ public class JpaDeviceProfileDao extends JpaAbstractSearchTextDao<DeviceProfileE
62 64 }
63 65
64 66 @Override
65   - public PageData<DeviceProfileInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink) {
66   - return DaoUtil.pageToPageData(
67   - deviceProfileRepository.findDeviceProfileInfos(
68   - tenantId.getId(),
69   - Objects.toString(pageLink.getTextSearch(), ""),
70   - DaoUtil.toPageable(pageLink)));
  67 + public PageData<DeviceProfileInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink, String transportType) {
  68 + if (StringUtils.isNotEmpty(transportType)) {
  69 + return DaoUtil.pageToPageData(
  70 + deviceProfileRepository.findDeviceProfileInfos(
  71 + tenantId.getId(),
  72 + Objects.toString(pageLink.getTextSearch(), ""),
  73 + DeviceTransportType.valueOf(transportType),
  74 + DaoUtil.toPageable(pageLink)));
  75 + } else {
  76 + return DaoUtil.pageToPageData(
  77 + deviceProfileRepository.findDeviceProfileInfos(
  78 + tenantId.getId(),
  79 + Objects.toString(pageLink.getTextSearch(), ""),
  80 + DaoUtil.toPageable(pageLink)));
  81 + }
71 82 }
72 83
73 84 @Override
... ...
... ... @@ -260,7 +260,7 @@ public class BaseDeviceProfileServiceTest extends AbstractServiceTest {
260 260 pageLink = new PageLink(17);
261 261 PageData<DeviceProfileInfo> pageData;
262 262 do {
263   - pageData = deviceProfileService.findDeviceProfileInfos(tenantId, pageLink);
  263 + pageData = deviceProfileService.findDeviceProfileInfos(tenantId, pageLink, null);
264 264 loadedDeviceProfileInfos.addAll(pageData.getData());
265 265 if (pageData.hasNext()) {
266 266 pageLink = pageLink.nextPageLink();
... ... @@ -284,7 +284,7 @@ public class BaseDeviceProfileServiceTest extends AbstractServiceTest {
284 284 }
285 285
286 286 pageLink = new PageLink(17);
287   - pageData = deviceProfileService.findDeviceProfileInfos(tenantId, pageLink);
  287 + pageData = deviceProfileService.findDeviceProfileInfos(tenantId, pageLink, null);
288 288 Assert.assertFalse(pageData.hasNext());
289 289 Assert.assertEquals(1, pageData.getTotalElements());
290 290 }
... ...