diff --git a/application/src/main/java/org/thingsboard/server/controller/AssetController.java b/application/src/main/java/org/thingsboard/server/controller/AssetController.java index 7e64ec428a..58b9376f1f 100644 --- a/application/src/main/java/org/thingsboard/server/controller/AssetController.java +++ b/application/src/main/java/org/thingsboard/server/controller/AssetController.java @@ -397,10 +397,12 @@ public class AssetController extends BaseController { } @ApiOperation(value = "Get Asset Types (getAssetTypes)", - notes = "Returns a set of unique asset types based on assets that are either owned by the tenant or assigned to the customer which user is performing the request.", produces = MediaType.APPLICATION_JSON_VALUE) + notes = "Deprecated. See 'getAssetProfileNames' API from Asset Profile Controller instead." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH, + produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") @RequestMapping(value = "/asset/types", method = RequestMethod.GET) @ResponseBody + @Deprecated(since = "3.6.2") public List getAssetTypes() throws ThingsboardException, ExecutionException, InterruptedException { SecurityUser user = getCurrentUser(); TenantId tenantId = user.getTenantId(); diff --git a/application/src/main/java/org/thingsboard/server/controller/AssetProfileController.java b/application/src/main/java/org/thingsboard/server/controller/AssetProfileController.java index d9a2923d52..59c9670a0c 100644 --- a/application/src/main/java/org/thingsboard/server/controller/AssetProfileController.java +++ b/application/src/main/java/org/thingsboard/server/controller/AssetProfileController.java @@ -29,18 +29,23 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.asset.AssetProfile; import org.thingsboard.server.common.data.asset.AssetProfileInfo; import org.thingsboard.server.common.data.exception.ThingsboardException; import org.thingsboard.server.common.data.id.AssetProfileId; +import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.dao.resource.ImageService; import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.service.entitiy.asset.profile.TbAssetProfileService; +import org.thingsboard.server.service.security.model.SecurityUser; import org.thingsboard.server.service.security.permission.Operation; import org.thingsboard.server.service.security.permission.Resource; +import java.util.List; + import static org.thingsboard.server.controller.ControllerConstants.ASSET_PROFILE_ID; import static org.thingsboard.server.controller.ControllerConstants.ASSET_PROFILE_ID_PARAM_DESCRIPTION; import static org.thingsboard.server.controller.ControllerConstants.ASSET_PROFILE_INFO_DESCRIPTION; @@ -212,4 +217,19 @@ public class AssetProfileController extends BaseController { PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); return checkNotNull(assetProfileService.findAssetProfileInfos(getTenantId(), pageLink)); } + + @ApiOperation(value = "Get Asset Profile names (getAssetProfileNames)", + notes = "Returns a set of unique asset profile names owned by the tenant." + + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH) + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") + @RequestMapping(value = "/assetProfile/names", method = RequestMethod.GET) + @ResponseBody + public List getAssetProfileNames( + @ApiParam(value = "Flag indicating whether to retrieve exclusively the names of asset profiles that are referenced by tenant's assets.") + @RequestParam(value = "activeOnly", required = false, defaultValue = "false") boolean activeOnly) throws ThingsboardException { + SecurityUser user = getCurrentUser(); + TenantId tenantId = user.getTenantId(); + return checkNotNull(assetProfileService.findAssetProfileNamesByTenantId(tenantId, activeOnly)); + } + } diff --git a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java index c05cf5cd6c..1761056051 100644 --- a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java +++ b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java @@ -194,14 +194,14 @@ public class DeviceController extends BaseController { "Requires to provide the Device Credentials object as well as an existing device profile ID or use \"default\".\n" + "You may find the example of device with different type of credentials below: \n\n" + "- Credentials type: \"Access token\" with device profile ID below: \n\n" + - DEVICE_WITH_DEVICE_CREDENTIALS_PARAM_ACCESS_TOKEN_DESCRIPTION_MARKDOWN + "\n\n" + + DEVICE_WITH_DEVICE_CREDENTIALS_PARAM_ACCESS_TOKEN_DESCRIPTION_MARKDOWN + "\n\n" + "- Credentials type: \"Access token\" with device profile default below: \n\n" + - DEVICE_WITH_DEVICE_CREDENTIALS_PARAM_ACCESS_TOKEN_DEFAULT_DESCRIPTION_MARKDOWN + "\n\n" + + DEVICE_WITH_DEVICE_CREDENTIALS_PARAM_ACCESS_TOKEN_DEFAULT_DESCRIPTION_MARKDOWN + "\n\n" + "- Credentials type: \"X509\" with device profile ID below: \n\n" + "Note: credentialsId - format Sha3Hash, certificateValue - format PEM (with \"--BEGIN CERTIFICATE----\" and -\"----END CERTIFICATE-\").\n\n" + - DEVICE_WITH_DEVICE_CREDENTIALS_PARAM_X509_CERTIFICATE_DESCRIPTION_MARKDOWN + "\n\n" + + DEVICE_WITH_DEVICE_CREDENTIALS_PARAM_X509_CERTIFICATE_DESCRIPTION_MARKDOWN + "\n\n" + "- Credentials type: \"MQTT_BASIC\" with device profile ID below: \n\n" + - DEVICE_WITH_DEVICE_CREDENTIALS_PARAM_MQTT_BASIC_DESCRIPTION_MARKDOWN + "\n\n" + + DEVICE_WITH_DEVICE_CREDENTIALS_PARAM_MQTT_BASIC_DESCRIPTION_MARKDOWN + "\n\n" + "- You may find the example of LwM2M device and RPK credentials below: \n\n" + "Note: LwM2M device - only existing device profile ID (Transport configuration -> Transport type: \"LWM2M\".\n\n" + DEVICE_WITH_DEVICE_CREDENTIALS_PARAM_LVM2M_RPK_DESCRIPTION_MARKDOWN + "\n\n" + @@ -304,12 +304,12 @@ public class DeviceController extends BaseController { "The structure of device credentials id and value is simple for the 'ACCESS_TOKEN' but is much more complex for the 'MQTT_BASIC' or 'LWM2M_CREDENTIALS'.\n" + "You may find the example of device with different type of credentials below: \n\n" + "- Credentials type: \"Access token\" with device ID and with device ID below: \n\n" + - DEVICE_UPDATE_CREDENTIALS_PARAM_ACCESS_TOKEN_DESCRIPTION_MARKDOWN + "\n\n" + + DEVICE_UPDATE_CREDENTIALS_PARAM_ACCESS_TOKEN_DESCRIPTION_MARKDOWN + "\n\n" + "- Credentials type: \"X509\" with device profile ID below: \n\n" + "Note: credentialsId - format Sha3Hash, certificateValue - format PEM (with \"--BEGIN CERTIFICATE----\" and -\"----END CERTIFICATE-\").\n\n" + - DEVICE_UPDATE_CREDENTIALS_PARAM_X509_CERTIFICATE_DESCRIPTION_MARKDOWN + "\n\n" + + DEVICE_UPDATE_CREDENTIALS_PARAM_X509_CERTIFICATE_DESCRIPTION_MARKDOWN + "\n\n" + "- Credentials type: \"MQTT_BASIC\" with device profile ID below: \n\n" + - DEVICE_UPDATE_CREDENTIALS_PARAM_MQTT_BASIC_DESCRIPTION_MARKDOWN + "\n\n" + + DEVICE_UPDATE_CREDENTIALS_PARAM_MQTT_BASIC_DESCRIPTION_MARKDOWN + "\n\n" + "- You may find the example of LwM2M device and RPK credentials below: \n\n" + "Note: LwM2M device - only existing device profile ID (Transport configuration -> Transport type: \"LWM2M\".\n\n" + DEVICE_UPDATE_CREDENTIALS_PARAM_LVM2M_RPK_DESCRIPTION_MARKDOWN + "\n\n" + @@ -534,11 +534,12 @@ public class DeviceController extends BaseController { } @ApiOperation(value = "Get Device Types (getDeviceTypes)", - notes = "Returns a set of unique device profile names based on devices that are either owned by the tenant or assigned to the customer which user is performing the request." - + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH) + notes = "Deprecated. See 'getDeviceProfileNames' API from Device Profile Controller instead." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH, + produces = MediaType.APPLICATION_JSON_VALUE) @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") @RequestMapping(value = "/device/types", method = RequestMethod.GET) @ResponseBody + @Deprecated(since = "3.6.2") public List getDeviceTypes() throws ThingsboardException, ExecutionException, InterruptedException { SecurityUser user = getCurrentUser(); TenantId tenantId = user.getTenantId(); diff --git a/application/src/main/java/org/thingsboard/server/controller/DeviceProfileController.java b/application/src/main/java/org/thingsboard/server/controller/DeviceProfileController.java index 3c07946309..c16e201bad 100644 --- a/application/src/main/java/org/thingsboard/server/controller/DeviceProfileController.java +++ b/application/src/main/java/org/thingsboard/server/controller/DeviceProfileController.java @@ -32,15 +32,18 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.DeviceProfileInfo; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.exception.ThingsboardException; import org.thingsboard.server.common.data.id.DeviceProfileId; +import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.dao.resource.ImageService; import org.thingsboard.server.dao.timeseries.TimeseriesService; import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.service.entitiy.device.profile.TbDeviceProfileService; +import org.thingsboard.server.service.security.model.SecurityUser; import org.thingsboard.server.service.security.permission.Operation; import org.thingsboard.server.service.security.permission.Resource; @@ -273,4 +276,19 @@ public class DeviceProfileController extends BaseController { PageLink pageLink = createPageLink(pageSize, page, textSearch, sortProperty, sortOrder); return checkNotNull(deviceProfileService.findDeviceProfileInfos(getTenantId(), pageLink, transportType)); } + + @ApiOperation(value = "Get Device Profile names (getDeviceProfileNames)", + notes = "Returns a set of unique device profile names owned by the tenant." + + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH) + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')") + @RequestMapping(value = "/deviceProfile/names", method = RequestMethod.GET) + @ResponseBody + public List getDeviceProfileNames( + @ApiParam(value = "Flag indicating whether to retrieve exclusively the names of device profiles that are referenced by tenant's devices.") + @RequestParam(value = "activeOnly", required = false, defaultValue = "false") boolean activeOnly) throws ThingsboardException { + SecurityUser user = getCurrentUser(); + TenantId tenantId = user.getTenantId(); + return checkNotNull(deviceProfileService.findDeviceProfileNamesByTenantId(tenantId, activeOnly)); + } + } diff --git a/application/src/test/java/org/thingsboard/server/controller/AssetProfileControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/AssetProfileControllerTest.java index 38420c3e32..34b1006ffb 100644 --- a/application/src/test/java/org/thingsboard/server/controller/AssetProfileControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/AssetProfileControllerTest.java @@ -28,6 +28,7 @@ import org.springframework.context.annotation.Primary; import org.springframework.test.context.ContextConfiguration; import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Dashboard; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.Tenant; import org.thingsboard.server.common.data.User; @@ -46,11 +47,13 @@ import org.thingsboard.server.dao.service.DaoSqlTest; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; import static org.hamcrest.Matchers.containsString; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.thingsboard.server.common.data.DataConstants.DEFAULT_DEVICE_TYPE; @ContextConfiguration(classes = {AssetProfileControllerTest.Config.class}) @DaoSqlTest @@ -459,6 +462,62 @@ public class AssetProfileControllerTest extends AbstractControllerTest { testEntityDaoWithRelationsTransactionalException(assetProfileDao, savedTenant.getId(), assetProfileId, "/api/assetProfile/" + assetProfileId); } + @Test + public void testGetAssetProfileNames() throws Exception { + var pageLink = new PageLink(Integer.MAX_VALUE); + var assetProfileInfos = doGetTypedWithPageLink("/api/assetProfileInfos?", + new TypeReference>() { + }, pageLink); + Assert.assertNotNull("Asset Profile Infos page data is null!", assetProfileInfos); + Assert.assertEquals("Asset Profile Infos Page data is empty! Expected to have default profile created!", 1, assetProfileInfos.getTotalElements()); + List expectedAssetProfileNames = assetProfileInfos.getData().stream() + .map(info -> new EntityInfo(info.getId(), info.getName())) + .sorted(Comparator.comparing(EntityInfo::getName)) + .collect(Collectors.toList()); + var assetProfileNames = doGetTyped("/api/assetProfile/names", new TypeReference>() { + }); + Assert.assertNotNull("Asset Profile Names list is null!", assetProfileNames); + Assert.assertFalse("Asset Profile Names list is empty!", assetProfileNames.isEmpty()); + Assert.assertEquals(expectedAssetProfileNames, assetProfileNames); + Assert.assertEquals(1, assetProfileNames.size()); + Assert.assertEquals(DEFAULT_DEVICE_TYPE, assetProfileNames.get(0).getName()); + + int count = 3; + for (int i = 0; i < count; i++) { + Asset asset = new Asset(); + asset.setName("AssetName" + i); + asset.setType("AssetProfileName" + i); + Asset savedAsset = doPost("/api/asset", asset, Asset.class); + Assert.assertNotNull(savedAsset); + } + assetProfileInfos = doGetTypedWithPageLink("/api/assetProfileInfos?", + new TypeReference<>() { + }, pageLink); + Assert.assertNotNull("Asset Profile Infos page data is null!", assetProfileInfos); + Assert.assertEquals("Asset Profile Infos Page data is empty! Expected to have default profile created + count value!", 1 + count, assetProfileInfos.getTotalElements()); + expectedAssetProfileNames = assetProfileInfos.getData().stream() + .map(info -> new EntityInfo(info.getId(), info.getName())) + .sorted(Comparator.comparing(EntityInfo::getName)) + .collect(Collectors.toList()); + + assetProfileNames = doGetTyped("/api/assetProfile/names", new TypeReference<>() { + }); + Assert.assertNotNull("Asset Profile Names list is null!", assetProfileNames); + Assert.assertFalse("Asset Profile Names list is empty!", assetProfileNames.isEmpty()); + Assert.assertEquals(expectedAssetProfileNames, assetProfileNames); + Assert.assertEquals(1 + count, assetProfileNames.size()); + + assetProfileNames = doGetTyped("/api/assetProfile/names?activeOnly=true", new TypeReference<>() { + }); + Assert.assertNotNull("Asset Profile Names list is null!", assetProfileNames); + Assert.assertFalse("Asset Profile Names list is empty!", assetProfileNames.isEmpty()); + var expectedAssetProfileNamesWithoutDefault = expectedAssetProfileNames.stream() + .filter(entityInfo -> !entityInfo.getName().equals(DEFAULT_DEVICE_TYPE)) + .collect(Collectors.toList()); + Assert.assertEquals(expectedAssetProfileNamesWithoutDefault, assetProfileNames); + Assert.assertEquals(count, assetProfileNames.size()); + } + private AssetProfile savedAssetProfile(String name) { AssetProfile assetProfile = createAssetProfile(name); return doPost("/api/assetProfile", assetProfile, AssetProfile.class); diff --git a/application/src/test/java/org/thingsboard/server/controller/DeviceProfileControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/DeviceProfileControllerTest.java index 14b052d93c..7cdfa10ea0 100644 --- a/application/src/test/java/org/thingsboard/server/controller/DeviceProfileControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/DeviceProfileControllerTest.java @@ -35,6 +35,7 @@ import org.thingsboard.server.common.data.DeviceProfileInfo; import org.thingsboard.server.common.data.DeviceProfileProvisionType; import org.thingsboard.server.common.data.DeviceProfileType; import org.thingsboard.server.common.data.DeviceTransportType; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.OtaPackageInfo; import org.thingsboard.server.common.data.SaveOtaPackageInfoRequest; import org.thingsboard.server.common.data.StringUtils; @@ -55,11 +56,13 @@ import org.thingsboard.server.dao.service.DaoSqlTest; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; import static org.hamcrest.Matchers.containsString; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.thingsboard.server.common.data.DataConstants.DEFAULT_DEVICE_TYPE; import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE; import static org.thingsboard.server.common.data.ota.OtaPackageType.SOFTWARE; @@ -1045,6 +1048,62 @@ public class DeviceProfileControllerTest extends AbstractControllerTest { testEntityDaoWithRelationsTransactionalException(deviceProfileDao, savedTenant.getId(), deviceProfileId, "/api/deviceProfile/" + deviceProfileId); } + @Test + public void testGetDeviceProfileNames() throws Exception { + var pageLink = new PageLink(Integer.MAX_VALUE); + var deviceProfileInfos = doGetTypedWithPageLink("/api/deviceProfileInfos?", + new TypeReference>() { + }, pageLink); + Assert.assertNotNull("Device Profile Infos page data is null!", deviceProfileInfos); + Assert.assertEquals("Device Profile Infos Page data is empty! Expected to have default profile created!", 1, deviceProfileInfos.getTotalElements()); + List expectedDeviceProfileNames = deviceProfileInfos.getData().stream() + .map(info -> new EntityInfo(info.getId(), info.getName())) + .sorted(Comparator.comparing(EntityInfo::getName)) + .collect(Collectors.toList()); + var deviceProfileNames = doGetTyped("/api/deviceProfile/names", new TypeReference>() { + }); + Assert.assertNotNull("Device Profile Names list is null!", deviceProfileNames); + Assert.assertFalse("Device Profile Names list is empty!", deviceProfileNames.isEmpty()); + Assert.assertEquals(expectedDeviceProfileNames, deviceProfileNames); + Assert.assertEquals(1, deviceProfileNames.size()); + Assert.assertEquals(DEFAULT_DEVICE_TYPE, deviceProfileNames.get(0).getName()); + + int count = 3; + for (int i = 0; i < count; i++) { + Device device = new Device(); + device.setName("DeviceName" + i); + device.setType("DeviceProfileName" + i); + Device savedDevice = doPost("/api/device", device, Device.class); + Assert.assertNotNull(savedDevice); + } + deviceProfileInfos = doGetTypedWithPageLink("/api/deviceProfileInfos?", + new TypeReference<>() { + }, pageLink); + Assert.assertNotNull("Device Profile Infos page data is null!", deviceProfileInfos); + Assert.assertEquals("Device Profile Infos Page data is empty! Expected to have default profile created + count value!", 1 + count, deviceProfileInfos.getTotalElements()); + expectedDeviceProfileNames = deviceProfileInfos.getData().stream() + .map(info -> new EntityInfo(info.getId(), info.getName())) + .sorted(Comparator.comparing(EntityInfo::getName)) + .collect(Collectors.toList()); + + deviceProfileNames = doGetTyped("/api/deviceProfile/names", new TypeReference<>() { + }); + Assert.assertNotNull("Device Profile Names list is null!", deviceProfileNames); + Assert.assertFalse("Device Profile Names list is empty!", deviceProfileNames.isEmpty()); + Assert.assertEquals(expectedDeviceProfileNames, deviceProfileNames); + Assert.assertEquals(1 + count, deviceProfileNames.size()); + + deviceProfileNames = doGetTyped("/api/deviceProfile/names?activeOnly=true", new TypeReference<>() { + }); + Assert.assertNotNull("Device Profile Names list is null!", deviceProfileNames); + Assert.assertFalse("Device Profile Names list is empty!", deviceProfileNames.isEmpty()); + var expectedDeviceProfileNamesWithoutDefault = expectedDeviceProfileNames.stream() + .filter(entityInfo -> !entityInfo.getName().equals(DEFAULT_DEVICE_TYPE)) + .collect(Collectors.toList()); + Assert.assertEquals(expectedDeviceProfileNamesWithoutDefault, deviceProfileNames); + Assert.assertEquals(count, deviceProfileNames.size()); + } + private DeviceProfile savedDeviceProfile(String name) { DeviceProfile deviceProfile = createDeviceProfile(name); return doPost("/api/deviceProfile", deviceProfile, DeviceProfile.class); diff --git a/common/dao-api/src/main/java/org/thingsboard/server/dao/asset/AssetProfileService.java b/common/dao-api/src/main/java/org/thingsboard/server/dao/asset/AssetProfileService.java index 477c352b54..7d7769411e 100644 --- a/common/dao-api/src/main/java/org/thingsboard/server/dao/asset/AssetProfileService.java +++ b/common/dao-api/src/main/java/org/thingsboard/server/dao/asset/AssetProfileService.java @@ -15,6 +15,7 @@ */ package org.thingsboard.server.dao.asset; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.asset.AssetProfile; import org.thingsboard.server.common.data.asset.AssetProfileInfo; import org.thingsboard.server.common.data.id.AssetProfileId; @@ -23,6 +24,8 @@ import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.dao.entity.EntityDaoService; +import java.util.List; + public interface AssetProfileService extends EntityDaoService { AssetProfile findAssetProfileById(TenantId tenantId, AssetProfileId assetProfileId); @@ -57,4 +60,6 @@ public interface AssetProfileService extends EntityDaoService { void deleteAssetProfilesByTenantId(TenantId tenantId); + List findAssetProfileNamesByTenantId(TenantId tenantId, boolean activeOnly); + } diff --git a/common/dao-api/src/main/java/org/thingsboard/server/dao/asset/AssetService.java b/common/dao-api/src/main/java/org/thingsboard/server/dao/asset/AssetService.java index 722eeff365..cec8dd9007 100644 --- a/common/dao-api/src/main/java/org/thingsboard/server/dao/asset/AssetService.java +++ b/common/dao-api/src/main/java/org/thingsboard/server/dao/asset/AssetService.java @@ -81,6 +81,7 @@ public interface AssetService extends EntityDaoService { ListenableFuture> findAssetsByQuery(TenantId tenantId, AssetSearchQuery query); + @Deprecated(since = "3.6.2", forRemoval = true) ListenableFuture> findAssetTypesByTenantId(TenantId tenantId); Asset assignAssetToEdge(TenantId tenantId, AssetId assetId, EdgeId edgeId); diff --git a/common/dao-api/src/main/java/org/thingsboard/server/dao/device/DeviceProfileService.java b/common/dao-api/src/main/java/org/thingsboard/server/dao/device/DeviceProfileService.java index 5d325aa1a6..066254d28d 100644 --- a/common/dao-api/src/main/java/org/thingsboard/server/dao/device/DeviceProfileService.java +++ b/common/dao-api/src/main/java/org/thingsboard/server/dao/device/DeviceProfileService.java @@ -17,12 +17,15 @@ package org.thingsboard.server.dao.device; import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.DeviceProfileInfo; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.id.DeviceProfileId; import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.dao.entity.EntityDaoService; +import java.util.List; + public interface DeviceProfileService extends EntityDaoService { DeviceProfile findDeviceProfileById(TenantId tenantId, DeviceProfileId deviceProfileId); @@ -59,4 +62,6 @@ public interface DeviceProfileService extends EntityDaoService { void deleteDeviceProfilesByTenantId(TenantId tenantId); + List findDeviceProfileNamesByTenantId(TenantId tenantId, boolean activeOnly); + } diff --git a/common/dao-api/src/main/java/org/thingsboard/server/dao/device/DeviceService.java b/common/dao-api/src/main/java/org/thingsboard/server/dao/device/DeviceService.java index a90ea9a572..0bb0dbf50e 100644 --- a/common/dao-api/src/main/java/org/thingsboard/server/dao/device/DeviceService.java +++ b/common/dao-api/src/main/java/org/thingsboard/server/dao/device/DeviceService.java @@ -95,6 +95,7 @@ public interface DeviceService extends EntityDaoService { ListenableFuture> findDevicesByQuery(TenantId tenantId, DeviceSearchQuery query); + @Deprecated(since = "3.6.2", forRemoval = true) ListenableFuture> findDeviceTypesByTenantId(TenantId tenantId); Device assignDeviceToTenant(TenantId tenantId, Device device); diff --git a/dao/src/main/java/org/thingsboard/server/dao/DaoUtil.java b/dao/src/main/java/org/thingsboard/server/dao/DaoUtil.java index 76f5a1948b..e7c2c9d42d 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/DaoUtil.java +++ b/dao/src/main/java/org/thingsboard/server/dao/DaoUtil.java @@ -19,6 +19,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.util.CollectionUtils; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.EntitySubtype; import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.id.TenantId; @@ -163,4 +164,17 @@ public abstract class DaoUtil { } return list; } + + public static List convertTenantEntityInfosToDto(UUID tenantId, EntityType entityType, List entityInfos) { + if (CollectionUtils.isEmpty(entityInfos)) { + return Collections.emptyList(); + } + + List list = new ArrayList<>(entityInfos.size()); + for (var info : entityInfos) { + list.add(new EntitySubtype(TenantId.fromUUID(tenantId), entityType, info.getName())); + } + return list; + } + } diff --git a/dao/src/main/java/org/thingsboard/server/dao/asset/AssetDao.java b/dao/src/main/java/org/thingsboard/server/dao/asset/AssetDao.java index 37d5dcea7c..4cdb64348b 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/asset/AssetDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/asset/AssetDao.java @@ -24,10 +24,8 @@ import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.util.TbPair; -import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.dao.Dao; import org.thingsboard.server.dao.ExportableEntityDao; -import org.thingsboard.server.dao.ImageContainerDao; import org.thingsboard.server.dao.TenantEntityDao; import java.util.List; @@ -191,6 +189,7 @@ public interface AssetDao extends Dao, TenantEntityDao, ExportableEntityD * * @return the list of tenant asset type objects */ + @Deprecated(since = "3.6.2", forRemoval = true) ListenableFuture> findTenantAssetTypesAsync(UUID tenantId); Long countAssetsByAssetProfileId(TenantId tenantId, UUID assetProfileId); diff --git a/dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileDao.java b/dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileDao.java index 87e9177d66..7dc188000c 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileDao.java @@ -15,6 +15,7 @@ */ package org.thingsboard.server.dao.asset; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.asset.AssetProfile; import org.thingsboard.server.common.data.asset.AssetProfileInfo; import org.thingsboard.server.common.data.id.AssetProfileId; @@ -25,6 +26,7 @@ import org.thingsboard.server.dao.Dao; import org.thingsboard.server.dao.ExportableEntityDao; import org.thingsboard.server.dao.ImageContainerDao; +import java.util.List; import java.util.UUID; public interface AssetProfileDao extends Dao, ExportableEntityDao, ImageContainerDao { @@ -47,4 +49,6 @@ public interface AssetProfileDao extends Dao, ExportableEntityDao< PageData findAllWithImages(PageLink pageLink); + List findTenantAssetProfileNames(UUID tenantId, boolean activeOnly); + } diff --git a/dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileServiceImpl.java index 86cafcd10b..0b9e949c7c 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileServiceImpl.java +++ b/dao/src/main/java/org/thingsboard/server/dao/asset/AssetProfileServiceImpl.java @@ -21,6 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.event.TransactionalEventListener; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.asset.Asset; @@ -42,9 +43,11 @@ import org.thingsboard.server.dao.service.PaginatedRemover; import org.thingsboard.server.dao.service.Validator; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; import static org.thingsboard.server.dao.service.Validator.validateId; @@ -318,7 +321,16 @@ public class AssetProfileServiceImpl extends AbstractCachedEntityService tenantAssetProfilesRemover = + @Override + public List findAssetProfileNamesByTenantId(TenantId tenantId, boolean activeOnly) { + log.trace("Executing findAssetProfileNamesByTenantId, tenantId [{}]", tenantId); + validateId(tenantId, INCORRECT_TENANT_ID + tenantId); + return assetProfileDao.findTenantAssetProfileNames(tenantId.getId(), activeOnly) + .stream().sorted(Comparator.comparing(EntityInfo::getName)) + .collect(Collectors.toList()); + } + + private final PaginatedRemover tenantAssetProfilesRemover = new PaginatedRemover<>() { @Override diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java index e6b19b271d..1638c7d872 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceDao.java @@ -162,6 +162,7 @@ public interface DeviceDao extends Dao, TenantEntityDao, ExportableEntit * * @return the list of tenant device type objects */ + @Deprecated(since = "3.6.2", forRemoval = true) ListenableFuture> findTenantDeviceTypesAsync(UUID tenantId); /** diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileDao.java b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileDao.java index 7bca5ebf8f..95336e8f4a 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileDao.java @@ -17,6 +17,7 @@ package org.thingsboard.server.dao.device; import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.DeviceProfileInfo; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.id.DeviceProfileId; import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.page.PageData; @@ -25,6 +26,7 @@ import org.thingsboard.server.dao.Dao; import org.thingsboard.server.dao.ExportableEntityDao; import org.thingsboard.server.dao.ImageContainerDao; +import java.util.List; import java.util.UUID; public interface DeviceProfileDao extends Dao, ExportableEntityDao, ImageContainerDao { @@ -49,4 +51,6 @@ public interface DeviceProfileDao extends Dao, ExportableEntityDa PageData findAllWithImages(PageLink pageLink); + List findTenantDeviceProfileNames(UUID tenantId, boolean activeOnly); + } diff --git a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java index 847811cd4f..7e3567c888 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java +++ b/dao/src/main/java/org/thingsboard/server/dao/device/DeviceProfileServiceImpl.java @@ -28,6 +28,7 @@ import org.thingsboard.server.common.data.DeviceProfileInfo; import org.thingsboard.server.common.data.DeviceProfileProvisionType; import org.thingsboard.server.common.data.DeviceProfileType; import org.thingsboard.server.common.data.DeviceTransportType; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.device.profile.DefaultDeviceProfileConfiguration; @@ -57,11 +58,13 @@ import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import static org.thingsboard.server.dao.service.Validator.validateId; import static org.thingsboard.server.dao.service.Validator.validateString; @@ -373,7 +376,16 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService tenantDeviceProfilesRemover = + @Override + public List findDeviceProfileNamesByTenantId(TenantId tenantId, boolean activeOnly) { + log.trace("Executing findDeviceProfileNamesByTenantId, tenantId [{}]", tenantId); + validateId(tenantId, INCORRECT_TENANT_ID + tenantId); + return deviceProfileDao.findTenantDeviceProfileNames(tenantId.getId(), activeOnly) + .stream().sorted(Comparator.comparing(EntityInfo::getName)) + .collect(Collectors.toList()); + } + + private final PaginatedRemover tenantDeviceProfilesRemover = new PaginatedRemover<>() { @Override @@ -422,7 +434,8 @@ public class DeviceProfileServiceImpl extends AbstractCachedEntityService 1) { return EncryptionUtil.certTrimNewLinesForChainInDeviceProfile(certificateValue); } - } catch (CertificateException ignored) {} + } catch (CertificateException ignored) { + } return EncryptionUtil.certTrimNewLines(certificateValue); } diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetProfileRepository.java b/dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetProfileRepository.java index a9acef8608..08ea3c0872 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetProfileRepository.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetProfileRepository.java @@ -20,6 +20,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.asset.AssetProfileInfo; import org.thingsboard.server.dao.ExportableEntityRepository; import org.thingsboard.server.dao.model.sql.AssetProfileEntity; @@ -71,4 +72,12 @@ public interface AssetProfileRepository extends JpaRepository findAllByImageNotNull(Pageable pageable); + @Query("SELECT new org.thingsboard.server.common.data.EntityInfo(ap.id, 'ASSET_PROFILE', ap.name) " + + "FROM AssetProfileEntity ap WHERE ap.tenantId = :tenantId AND EXISTS (SELECT 1 FROM AssetEntity a WHERE a.tenantId = :tenantId AND a.assetProfileId = ap.id)") + List findActiveTenantAssetProfileNames(@Param("tenantId") UUID tenantId); + + @Query("SELECT new org.thingsboard.server.common.data.EntityInfo(a.id, 'ASSET_PROFILE', a.name) " + + "FROM AssetProfileEntity a WHERE a.tenantId = :tenantId") + List findAllTenantAssetProfileNames(@Param("tenantId") UUID tenantId); + } diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetRepository.java b/dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetRepository.java index c16afc9983..0c2db8ec66 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetRepository.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/asset/AssetRepository.java @@ -167,9 +167,6 @@ public interface AssetRepository extends JpaRepository, Expor @Param("textSearch") String textSearch, Pageable pageable); - @Query("SELECT DISTINCT a.type FROM AssetEntity a WHERE a.tenantId = :tenantId") - List findTenantAssetTypes(@Param("tenantId") UUID tenantId); - Long countByAssetProfileId(UUID assetProfileId); @Query("SELECT a FROM AssetEntity a, RelationEntity re WHERE a.tenantId = :tenantId " + diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/asset/JpaAssetDao.java b/dao/src/main/java/org/thingsboard/server/dao/sql/asset/JpaAssetDao.java index e2fe60945d..48dd0996de 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/asset/JpaAssetDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/asset/JpaAssetDao.java @@ -39,11 +39,10 @@ import org.thingsboard.server.dao.util.SqlDao; import java.util.Arrays; import java.util.List; -import java.util.Objects; import java.util.Optional; import java.util.UUID; -import static org.thingsboard.server.dao.DaoUtil.convertTenantEntityTypesToDto; +import static org.thingsboard.server.dao.DaoUtil.convertTenantEntityInfosToDto; import static org.thingsboard.server.dao.asset.BaseAssetService.TB_SERVICE_QUEUE; /** @@ -57,6 +56,9 @@ public class JpaAssetDao extends JpaAbstractDao implements A @Autowired private AssetRepository assetRepository; + @Autowired + private AssetProfileRepository assetProfileRepository; + @Override protected Class getEntityClass() { return AssetEntity.class; @@ -193,7 +195,7 @@ public class JpaAssetDao extends JpaAbstractDao implements A @Override public ListenableFuture> findTenantAssetTypesAsync(UUID tenantId) { - return service.submit(() -> convertTenantEntityTypesToDto(tenantId, EntityType.ASSET, assetRepository.findTenantAssetTypes(tenantId))); + return service.submit(() -> convertTenantEntityInfosToDto(tenantId, EntityType.ASSET, assetProfileRepository.findActiveTenantAssetProfileNames(tenantId))); } @Override diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/asset/JpaAssetProfileDao.java b/dao/src/main/java/org/thingsboard/server/dao/sql/asset/JpaAssetProfileDao.java index b57e5c0c40..d409b2c4d2 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/asset/JpaAssetProfileDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/asset/JpaAssetProfileDao.java @@ -20,6 +20,7 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.asset.AssetProfile; import org.thingsboard.server.common.data.asset.AssetProfileInfo; @@ -103,6 +104,13 @@ public class JpaAssetProfileDao extends JpaAbstractDao findTenantAssetProfileNames(UUID tenantId, boolean activeOnly) { + return activeOnly ? + assetProfileRepository.findActiveTenantAssetProfileNames(tenantId) : + assetProfileRepository.findAllTenantAssetProfileNames(tenantId); + } + @Override public AssetProfile findByTenantIdAndExternalId(UUID tenantId, UUID externalId) { return DaoUtil.getData(assetProfileRepository.findByTenantIdAndExternalId(tenantId, externalId)); diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceProfileRepository.java b/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceProfileRepository.java index a9baf60e60..2093404bb0 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceProfileRepository.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceProfileRepository.java @@ -22,7 +22,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.thingsboard.server.common.data.DeviceProfileInfo; import org.thingsboard.server.common.data.DeviceTransportType; -import org.thingsboard.server.common.data.asset.AssetProfileInfo; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.dao.ExportableEntityRepository; import org.thingsboard.server.dao.model.sql.DeviceProfileEntity; @@ -83,4 +83,12 @@ public interface DeviceProfileRepository extends JpaRepository findAllByImageNotNull(Pageable pageable); + @Query("SELECT new org.thingsboard.server.common.data.EntityInfo(dp.id, 'DEVICE_PROFILE', dp.name) " + + "FROM DeviceProfileEntity dp WHERE dp.tenantId = :tenantId AND EXISTS (SELECT 1 FROM DeviceEntity dv WHERE dv.tenantId = :tenantId AND dv.deviceProfileId = dp.id)") + List findActiveTenantDeviceProfileNames(@Param("tenantId") UUID tenantId); + + @Query("SELECT new org.thingsboard.server.common.data.EntityInfo(d.id, 'DEVICE_PROFILE', d.name) " + + "FROM DeviceProfileEntity d WHERE d.tenantId = :tenantId") + List findAllTenantDeviceProfileNames(@Param("tenantId") UUID tenantId); + } diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java b/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java index 3ca96e7087..97ddb94b88 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/device/DeviceRepository.java @@ -145,9 +145,6 @@ public interface DeviceRepository extends JpaRepository, Exp @Param("textSearch") String textSearch, Pageable pageable); - @Query("SELECT DISTINCT d.type FROM DeviceEntity d WHERE d.tenantId = :tenantId") - List findTenantDeviceTypes(@Param("tenantId") UUID tenantId); - DeviceEntity findByTenantIdAndName(UUID tenantId, String name); List findDevicesByTenantIdAndCustomerIdAndIdIn(UUID tenantId, UUID customerId, List deviceIds); diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java b/dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java index bf7d8670b1..d022c42af6 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceDao.java @@ -44,11 +44,10 @@ import org.thingsboard.server.dao.sql.JpaAbstractDao; import org.thingsboard.server.dao.util.SqlDao; import java.util.List; -import java.util.Objects; import java.util.Optional; import java.util.UUID; -import static org.thingsboard.server.dao.DaoUtil.convertTenantEntityTypesToDto; +import static org.thingsboard.server.dao.DaoUtil.convertTenantEntityInfosToDto; /** * Created by Valerii Sosliuk on 5/6/2017. @@ -64,6 +63,9 @@ public class JpaDeviceDao extends JpaAbstractDao implement @Autowired private NativeDeviceRepository nativeDeviceRepository; + @Autowired + private DeviceProfileRepository deviceProfileRepository; + @Override protected Class getEntityClass() { return DeviceEntity.class; @@ -217,7 +219,7 @@ public class JpaDeviceDao extends JpaAbstractDao implement @Override public ListenableFuture> findTenantDeviceTypesAsync(UUID tenantId) { - return service.submit(() -> convertTenantEntityTypesToDto(tenantId, EntityType.DEVICE, deviceRepository.findTenantDeviceTypes(tenantId))); + return service.submit(() -> convertTenantEntityInfosToDto(tenantId, EntityType.DEVICE, deviceProfileRepository.findActiveTenantDeviceProfileNames(tenantId))); } @Override diff --git a/dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceProfileDao.java b/dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceProfileDao.java index 12a91e3cf7..9109f223a9 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceProfileDao.java +++ b/dao/src/main/java/org/thingsboard/server/dao/sql/device/JpaDeviceProfileDao.java @@ -23,6 +23,7 @@ import org.springframework.transaction.annotation.Transactional; import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.DeviceProfileInfo; import org.thingsboard.server.common.data.DeviceTransportType; +import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.id.DeviceProfileId; @@ -121,6 +122,13 @@ public class JpaDeviceProfileDao extends JpaAbstractDao findTenantDeviceProfileNames(UUID tenantId, boolean activeOnly) { + return activeOnly ? + deviceProfileRepository.findActiveTenantDeviceProfileNames(tenantId) : + deviceProfileRepository.findAllTenantDeviceProfileNames(tenantId); + } + @Override public DeviceProfile findByTenantIdAndExternalId(UUID tenantId, UUID externalId) { return DaoUtil.getData(deviceProfileRepository.findByTenantIdAndExternalId(tenantId, externalId)); diff --git a/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java b/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java index fb878a33b6..8b17cef6c1 100644 --- a/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java +++ b/rest-client/src/main/java/org/thingsboard/rest/client/RestClient.java @@ -505,7 +505,7 @@ public class RestClient implements Closeable { HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }).getBody(); + }).getBody(); } public AlarmComment saveAlarmComment(AlarmId alarmId, AlarmComment alarmComment) { @@ -703,6 +703,7 @@ public class RestClient implements Closeable { }).getBody(); } + @Deprecated(since = "3.6.2") public List getAssetTypes() { return restTemplate.exchange(URI.create( baseURL + "/api/asset/types"), @@ -712,6 +713,15 @@ public class RestClient implements Closeable { }).getBody(); } + public List getAssetProfileNames(boolean activeOnly) { + return restTemplate.exchange( + baseURL + "/api/assetProfile/names?activeOnly={activeOnly}", + HttpMethod.GET, + HttpEntity.EMPTY, + new ParameterizedTypeReference>() { + }, activeOnly).getBody(); + } + public BulkImportResult processAssetsBulkImport(BulkImportRequest request) { return restTemplate.exchange( baseURL + "/api/asset/bulk_import", @@ -1394,6 +1404,7 @@ public class RestClient implements Closeable { }).getBody(); } + @Deprecated(since = "3.6.2") public List getDeviceTypes() { return restTemplate.exchange( baseURL + "/api/device/types", @@ -1403,6 +1414,15 @@ public class RestClient implements Closeable { }).getBody(); } + public List getDeviceProfileNames(boolean activeOnly) { + return restTemplate.exchange( + baseURL + "/api/deviceProfile/names?activeOnly={activeOnly}", + HttpMethod.GET, + HttpEntity.EMPTY, + new ParameterizedTypeReference>() { + }, activeOnly).getBody(); + } + public JsonNode claimDevice(String deviceName, ClaimRequest claimRequest) { return restTemplate.exchange( baseURL + "/api/customer/device/{deviceName}/claim",