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,10 +192,11 @@ public class DeviceProfileController extends BaseController {
192 @RequestParam int page, 192 @RequestParam int page,
193 @RequestParam(required = false) String textSearch, 193 @RequestParam(required = false) String textSearch,
194 @RequestParam(required = false) String sortProperty, 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 try { 197 try {
197 PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); 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 } catch (Exception e) { 200 } catch (Exception e) {
200 throw handleException(e); 201 throw handleException(e);
201 } 202 }
@@ -37,7 +37,7 @@ public interface DeviceProfileService { @@ -37,7 +37,7 @@ public interface DeviceProfileService {
37 37
38 PageData<DeviceProfile> findDeviceProfiles(TenantId tenantId, PageLink pageLink); 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 DeviceProfile findOrCreateDeviceProfile(TenantId tenantId, String profileName); 42 DeviceProfile findOrCreateDeviceProfile(TenantId tenantId, String profileName);
43 43
@@ -32,7 +32,7 @@ public interface DeviceProfileDao extends Dao<DeviceProfile> { @@ -32,7 +32,7 @@ public interface DeviceProfileDao extends Dao<DeviceProfile> {
32 32
33 PageData<DeviceProfile> findDeviceProfiles(TenantId tenantId, PageLink pageLink); 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 DeviceProfile findDefaultDeviceProfile(TenantId tenantId); 37 DeviceProfile findDefaultDeviceProfile(TenantId tenantId);
38 38
@@ -178,11 +178,11 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D @@ -178,11 +178,11 @@ public class DeviceProfileServiceImpl extends AbstractEntityService implements D
178 } 178 }
179 179
180 @Override 180 @Override
181 - public PageData<DeviceProfileInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink) { 181 + public PageData<DeviceProfileInfo> findDeviceProfileInfos(TenantId tenantId, PageLink pageLink, String transportType) {
182 log.trace("Executing findDeviceProfileInfos tenantId [{}], pageLink [{}]", tenantId, pageLink); 182 log.trace("Executing findDeviceProfileInfos tenantId [{}], pageLink [{}]", tenantId, pageLink);
183 validateId(tenantId, INCORRECT_TENANT_ID + tenantId); 183 validateId(tenantId, INCORRECT_TENANT_ID + tenantId);
184 Validator.validatePageLink(pageLink); 184 Validator.validatePageLink(pageLink);
185 - return deviceProfileDao.findDeviceProfileInfos(tenantId, pageLink); 185 + return deviceProfileDao.findDeviceProfileInfos(tenantId, pageLink, transportType);
186 } 186 }
187 187
188 @Cacheable(cacheNames = DEVICE_PROFILE_CACHE, key = "{#tenantId.id, #name}") 188 @Cacheable(cacheNames = DEVICE_PROFILE_CACHE, key = "{#tenantId.id, #name}")
@@ -22,6 +22,7 @@ import org.springframework.data.repository.PagingAndSortingRepository; @@ -22,6 +22,7 @@ import org.springframework.data.repository.PagingAndSortingRepository;
22 import org.springframework.data.repository.query.Param; 22 import org.springframework.data.repository.query.Param;
23 import org.thingsboard.server.common.data.DeviceProfile; 23 import org.thingsboard.server.common.data.DeviceProfile;
24 import org.thingsboard.server.common.data.DeviceProfileInfo; 24 import org.thingsboard.server.common.data.DeviceProfileInfo;
  25 +import org.thingsboard.server.common.data.DeviceTransportType;
25 import org.thingsboard.server.dao.model.sql.DeviceProfileEntity; 26 import org.thingsboard.server.dao.model.sql.DeviceProfileEntity;
26 27
27 import java.util.UUID; 28 import java.util.UUID;
@@ -46,6 +47,14 @@ public interface DeviceProfileRepository extends PagingAndSortingRepository<Devi @@ -46,6 +47,14 @@ public interface DeviceProfileRepository extends PagingAndSortingRepository<Devi
46 @Param("textSearch") String textSearch, 47 @Param("textSearch") String textSearch,
47 Pageable pageable); 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 @Query("SELECT d FROM DeviceProfileEntity d " + 58 @Query("SELECT d FROM DeviceProfileEntity d " +
50 "WHERE d.tenantId = :tenantId AND d.isDefault = true") 59 "WHERE d.tenantId = :tenantId AND d.isDefault = true")
51 DeviceProfileEntity findByDefaultTrueAndTenantId(@Param("tenantId") UUID tenantId); 60 DeviceProfileEntity findByDefaultTrueAndTenantId(@Param("tenantId") UUID tenantId);
@@ -15,11 +15,13 @@ @@ -15,11 +15,13 @@
15 */ 15 */
16 package org.thingsboard.server.dao.sql.device; 16 package org.thingsboard.server.dao.sql.device;
17 17
  18 +import org.apache.commons.lang.StringUtils;
18 import org.springframework.beans.factory.annotation.Autowired; 19 import org.springframework.beans.factory.annotation.Autowired;
19 import org.springframework.data.repository.CrudRepository; 20 import org.springframework.data.repository.CrudRepository;
20 import org.springframework.stereotype.Component; 21 import org.springframework.stereotype.Component;
21 import org.thingsboard.server.common.data.DeviceProfile; 22 import org.thingsboard.server.common.data.DeviceProfile;
22 import org.thingsboard.server.common.data.DeviceProfileInfo; 23 import org.thingsboard.server.common.data.DeviceProfileInfo;
  24 +import org.thingsboard.server.common.data.DeviceTransportType;
23 import org.thingsboard.server.common.data.id.TenantId; 25 import org.thingsboard.server.common.data.id.TenantId;
24 import org.thingsboard.server.common.data.page.PageData; 26 import org.thingsboard.server.common.data.page.PageData;
25 import org.thingsboard.server.common.data.page.PageLink; 27 import org.thingsboard.server.common.data.page.PageLink;
@@ -62,12 +64,21 @@ public class JpaDeviceProfileDao extends JpaAbstractSearchTextDao<DeviceProfileE @@ -62,12 +64,21 @@ public class JpaDeviceProfileDao extends JpaAbstractSearchTextDao<DeviceProfileE
62 } 64 }
63 65
64 @Override 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 @Override 84 @Override
@@ -260,7 +260,7 @@ public class BaseDeviceProfileServiceTest extends AbstractServiceTest { @@ -260,7 +260,7 @@ public class BaseDeviceProfileServiceTest extends AbstractServiceTest {
260 pageLink = new PageLink(17); 260 pageLink = new PageLink(17);
261 PageData<DeviceProfileInfo> pageData; 261 PageData<DeviceProfileInfo> pageData;
262 do { 262 do {
263 - pageData = deviceProfileService.findDeviceProfileInfos(tenantId, pageLink); 263 + pageData = deviceProfileService.findDeviceProfileInfos(tenantId, pageLink, null);
264 loadedDeviceProfileInfos.addAll(pageData.getData()); 264 loadedDeviceProfileInfos.addAll(pageData.getData());
265 if (pageData.hasNext()) { 265 if (pageData.hasNext()) {
266 pageLink = pageLink.nextPageLink(); 266 pageLink = pageLink.nextPageLink();
@@ -284,7 +284,7 @@ public class BaseDeviceProfileServiceTest extends AbstractServiceTest { @@ -284,7 +284,7 @@ public class BaseDeviceProfileServiceTest extends AbstractServiceTest {
284 } 284 }
285 285
286 pageLink = new PageLink(17); 286 pageLink = new PageLink(17);
287 - pageData = deviceProfileService.findDeviceProfileInfos(tenantId, pageLink); 287 + pageData = deviceProfileService.findDeviceProfileInfos(tenantId, pageLink, null);
288 Assert.assertFalse(pageData.hasNext()); 288 Assert.assertFalse(pageData.hasNext());
289 Assert.assertEquals(1, pageData.getTotalElements()); 289 Assert.assertEquals(1, pageData.getTotalElements());
290 } 290 }