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 c1402b93ad..21a18534ed 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 @@ -72,6 +72,8 @@ import org.thingsboard.server.common.data.alarm.AlarmSeverity; import org.thingsboard.server.common.data.alarm.AlarmStatus; import org.thingsboard.server.common.data.asset.Asset; import org.thingsboard.server.common.data.asset.AssetInfo; +import org.thingsboard.server.common.data.asset.AssetProfile; +import org.thingsboard.server.common.data.asset.AssetProfileInfo; import org.thingsboard.server.common.data.asset.AssetSearchQuery; import org.thingsboard.server.common.data.audit.ActionType; import org.thingsboard.server.common.data.audit.AuditLog; @@ -83,6 +85,7 @@ import org.thingsboard.server.common.data.edge.EdgeSearchQuery; import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery; import org.thingsboard.server.common.data.id.AlarmId; import org.thingsboard.server.common.data.id.AssetId; +import org.thingsboard.server.common.data.id.AssetProfileId; import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.DashboardId; import org.thingsboard.server.common.data.id.DeviceId; @@ -532,13 +535,14 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return assets.getBody(); } - public PageData getTenantAssetInfos(PageLink pageLink, String assetType) { + public PageData getTenantAssetInfos(String type, AssetProfileId assetProfileId, PageLink pageLink) { Map params = new HashMap<>(); - params.put("type", assetType); + params.put("type", type); + params.put("assetProfileId", assetProfileId != null ? assetProfileId.toString() : null); addPageLinkToParam(params, pageLink); ResponseEntity> assets = restTemplate.exchange( - baseURL + "/api/tenant/assetInfos?type={type}&" + getUrlParams(pageLink), + baseURL + "/api/tenant/assetInfos?type={type}&assetProfileId={assetProfileId}&" + getUrlParams(pageLink), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, @@ -575,14 +579,15 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return assets.getBody(); } - public PageData getCustomerAssetInfos(CustomerId customerId, PageLink pageLink, String assetType) { + public PageData getCustomerAssetInfos(CustomerId customerId, String assetType, AssetProfileId assetProfileId, PageLink pageLink) { Map params = new HashMap<>(); params.put("customerId", customerId.getId().toString()); params.put("type", assetType); + params.put("assetProfileId", assetProfileId != null ? assetProfileId.toString() : null); addPageLinkToParam(params, pageLink); ResponseEntity> assets = restTemplate.exchange( - baseURL + "/api/customer/{customerId}/assetInfos?type={type}&" + getUrlParams(pageLink), + baseURL + "/api/customer/{customerId}/assetInfos?type={type}&assetProfileId={assetProfileId}&" + getUrlParams(pageLink), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1483,6 +1488,70 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { }, params).getBody(); } + public Optional getAssetProfileById(AssetProfileId assetProfileId) { + try { + ResponseEntity assetProfile = restTemplate.getForEntity(baseURL + "/api/assetProfile/{assetProfileId}", AssetProfile.class, assetProfileId); + return Optional.ofNullable(assetProfile.getBody()); + } catch (HttpClientErrorException exception) { + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { + return Optional.empty(); + } else { + throw exception; + } + } + } + + public Optional getAssetProfileInfoById(AssetProfileId assetProfileId) { + try { + ResponseEntity assetProfileInfo = restTemplate.getForEntity(baseURL + "/api/assetProfileInfo/{assetProfileId}", AssetProfileInfo.class, assetProfileId); + return Optional.ofNullable(assetProfileInfo.getBody()); + } catch (HttpClientErrorException exception) { + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { + return Optional.empty(); + } else { + throw exception; + } + } + } + + public AssetProfileInfo getDefaultAssetProfileInfo() { + return restTemplate.getForEntity(baseURL + "/api/assetProfileInfo/default", AssetProfileInfo.class).getBody(); + } + + public AssetProfile saveAssetProfile(AssetProfile assetProfile) { + return restTemplate.postForEntity(baseURL + "/api/assetProfile", assetProfile, AssetProfile.class).getBody(); + } + + public void deleteAssetProfile(AssetProfileId assetProfileId) { + restTemplate.delete(baseURL + "/api/assetProfile/{assetProfileId}", assetProfileId); + } + + public AssetProfile setDefaultAssetProfile(AssetProfileId assetProfileId) { + return restTemplate.postForEntity( + baseURL + "/api/assetProfile/{assetProfileId}/default", + HttpEntity.EMPTY, AssetProfile.class, assetProfileId).getBody(); + } + + public PageData getAssetProfiles(PageLink pageLink) { + Map params = new HashMap<>(); + addPageLinkToParam(params, pageLink); + return restTemplate.exchange( + baseURL + "/api/assetProfiles?" + getUrlParams(pageLink), + HttpMethod.GET, HttpEntity.EMPTY, + new ParameterizedTypeReference>() { + }, params).getBody(); + } + + public PageData getAssetProfileInfos(PageLink pageLink) { + Map params = new HashMap<>(); + addPageLinkToParam(params, pageLink); + return restTemplate.exchange( + baseURL + "/api/assetProfileInfos?" + getUrlParams(pageLink), + HttpMethod.GET, HttpEntity.EMPTY, + new ParameterizedTypeReference>() { + }, params).getBody(); + } + public Long countEntitiesByQuery(EntityCountQuery query) { return restTemplate.postForObject(baseURL + "/api/entitiesQuery/count", query, Long.class); }