diff --git a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java index 179902d1d3..91d9e1bfec 100644 --- a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java +++ b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java @@ -45,10 +45,14 @@ import org.thingsboard.server.common.data.Tenant; import org.thingsboard.server.common.data.UpdateMessage; import org.thingsboard.server.common.data.User; import org.thingsboard.server.common.data.alarm.Alarm; +import org.thingsboard.server.common.data.alarm.AlarmId; import org.thingsboard.server.common.data.alarm.AlarmInfo; +import org.thingsboard.server.common.data.alarm.AlarmSearchStatus; 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.AssetSearchQuery; +import org.thingsboard.server.common.data.audit.ActionType; import org.thingsboard.server.common.data.audit.AuditLog; import org.thingsboard.server.common.data.device.DeviceSearchQuery; import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery; @@ -57,6 +61,14 @@ import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.DashboardId; import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.common.data.id.EntityId; +import org.thingsboard.server.common.data.id.EntityViewId; +import org.thingsboard.server.common.data.id.RuleChainId; +import org.thingsboard.server.common.data.id.RuleNodeId; +import org.thingsboard.server.common.data.id.TenantId; +import org.thingsboard.server.common.data.id.UserId; +import org.thingsboard.server.common.data.id.WidgetTypeId; +import org.thingsboard.server.common.data.id.WidgetsBundleId; +import org.thingsboard.server.common.data.kv.Aggregation; import org.thingsboard.server.common.data.kv.AttributeKvEntry; import org.thingsboard.server.common.data.kv.TsKvEntry; import org.thingsboard.server.common.data.page.TextPageData; @@ -64,9 +76,11 @@ import org.thingsboard.server.common.data.page.TextPageLink; import org.thingsboard.server.common.data.page.TimePageData; import org.thingsboard.server.common.data.page.TimePageLink; import org.thingsboard.server.common.data.plugin.ComponentDescriptor; +import org.thingsboard.server.common.data.plugin.ComponentType; import org.thingsboard.server.common.data.relation.EntityRelation; import org.thingsboard.server.common.data.relation.EntityRelationInfo; import org.thingsboard.server.common.data.relation.EntityRelationsQuery; +import org.thingsboard.server.common.data.relation.RelationTypeGroup; import org.thingsboard.server.common.data.rule.RuleChain; import org.thingsboard.server.common.data.rule.RuleChainMetaData; import org.thingsboard.server.common.data.security.DeviceCredentials; @@ -87,6 +101,7 @@ import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; +import java.util.stream.Collectors; import static org.springframework.util.StringUtils.isEmpty; @@ -106,8 +121,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { protected static final String ACTIVATE_TOKEN_REGEX = "/api/noauth/activate?activateToken="; public RestClient(String baseURL) { - this.restTemplate = new RestTemplate(); - this.baseURL = baseURL; + this(new RestTemplate(), baseURL); } public RestClient(RestTemplate restTemplate, String baseURL) { @@ -279,18 +293,6 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return restTemplate.postForEntity(baseURL + "/api/alarm", alarm, Alarm.class).getBody(); } - public void deleteCustomer(CustomerId customerId) { - restTemplate.delete(baseURL + "/api/customer/{customerId}", customerId); - } - - public void deleteDevice(DeviceId deviceId) { - restTemplate.delete(baseURL + "/api/device/{deviceId}", deviceId); - } - - public void deleteAsset(AssetId assetId) { - restTemplate.delete(baseURL + "/api/asset/{assetId}", assetId); - } - public Device assignDevice(CustomerId customerId, DeviceId deviceId) { return restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/device/{deviceId}", null, Device.class, customerId.toString(), deviceId.toString()).getBody(); @@ -313,10 +315,6 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return restTemplate.postForEntity(baseURL + "/api/dashboard", dashboard, Dashboard.class).getBody(); } - public void deleteDashboard(DashboardId dashboardId) { - restTemplate.delete(baseURL + "/api/dashboard/{dashboardId}", dashboardId); - } - public List findTenantDashboards() { try { ResponseEntity> dashboards = @@ -391,9 +389,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional getAlarmById(String alarmId) { + public Optional getAlarmById(AlarmId alarmId) { try { - ResponseEntity alarm = restTemplate.getForEntity(baseURL + "/api/alarm/{alarmId}", Alarm.class, alarmId); + ResponseEntity alarm = restTemplate.getForEntity(baseURL + "/api/alarm/{alarmId}", Alarm.class, alarmId.getId()); return Optional.ofNullable(alarm.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -404,9 +402,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional getAlarmInfoById(String alarmId) { + public Optional getAlarmInfoById(AlarmId alarmId) { try { - ResponseEntity alarmInfo = restTemplate.getForEntity(baseURL + "/api/alarm/info/{alarmId}", AlarmInfo.class, alarmId); + ResponseEntity alarmInfo = restTemplate.getForEntity(baseURL + "/api/alarm/info/{alarmId}", AlarmInfo.class, alarmId.getId()); return Optional.ofNullable(alarmInfo.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -421,70 +419,42 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return restTemplate.postForEntity(baseURL + "/api/alarm", alarm, Alarm.class).getBody(); } - public void deleteAlarm(String alarmId) { - restTemplate.delete(baseURL + "/api/alarm/{alarmId}", alarmId); + public void deleteAlarm(AlarmId alarmId) { + restTemplate.delete(baseURL + "/api/alarm/{alarmId}", alarmId.getId()); } - public void ackAlarm(String alarmId) { - restTemplate.postForLocation(baseURL + "/api/alarm/{alarmId}/ack", null, alarmId); + public void ackAlarm(AlarmId alarmId) { + restTemplate.postForLocation(baseURL + "/api/alarm/{alarmId}/ack", null, alarmId.getId()); } - public void clearAlarm(String alarmId) { - restTemplate.postForLocation(baseURL + "/api/alarm/{alarmId}/clear", null, alarmId); + public void clearAlarm(AlarmId alarmId) { + restTemplate.postForLocation(baseURL + "/api/alarm/{alarmId}/clear", null, alarmId.getId()); } - public TimePageData getAlarms(EntityId entityId, String searchStatus, String status, TimePageLink pageLink, Boolean fetchOriginator) { + public TimePageData getAlarms(EntityId entityId, AlarmSearchStatus searchStatus, AlarmStatus status, TimePageLink pageLink, Boolean fetchOriginator) { Map params = new HashMap<>(); params.put("entityType", entityId.getEntityType().name()); params.put("entityId", entityId.getId().toString()); - params.put("searchStatus", searchStatus); - params.put("status", status); + params.put("searchStatus", searchStatus.name()); + params.put("status", status.name()); params.put("fetchOriginator", String.valueOf(fetchOriginator)); addPageLinkToParam(params, pageLink); - String urlParams = getUrlParams(pageLink); return restTemplate.exchange( baseURL + "/api/alarm/{entityType}/{entityId}?searchStatus={searchStatus}&status={status}&fetchOriginator={fetchOriginator}&" + getUrlParams(pageLink), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }, params).getBody(); + }, + params).getBody(); } - private String getUrlParams(TimePageLink pageLink) { - String urlParams = "limit={limit}&ascOrder={ascOrder}"; - if (pageLink.getStartTime() != null) { - urlParams += "&startTime={startTime}"; - } - if (pageLink.getEndTime() != null) { - urlParams += "&endTime={endTime}"; - } - if (pageLink.getIdOffset() != null) { - urlParams += "&offset={offset}"; - } - return urlParams; - } - - private String getUrlParams(TextPageLink pageLink) { - String urlParams = "limit={limit}"; - if (!isEmpty(pageLink.getTextSearch())) { - urlParams += "&textSearch={textSearch}"; - } - if (!isEmpty(pageLink.getIdOffset())) { - urlParams += "&idOffset={idOffset}"; - } - if (!isEmpty(pageLink.getTextOffset())) { - urlParams += "&textOffset={textOffset}"; - } - return urlParams; - } - - public Optional getHighestAlarmSeverity(EntityId entityId, String searchStatus, String status) { + public Optional getHighestAlarmSeverity(EntityId entityId, AlarmSearchStatus searchStatus, AlarmStatus status) { Map params = new HashMap<>(); params.put("entityType", entityId.getEntityType().name()); params.put("entityId", entityId.getId().toString()); - params.put("searchStatus", searchStatus); - params.put("status", status); + params.put("searchStatus", searchStatus.name()); + params.put("status", status.name()); try { ResponseEntity alarmSeverity = restTemplate.getForEntity(baseURL + "/api/alarm/highestSeverity/{entityType}/{entityId}?searchStatus={searchStatus}&status={status}", AlarmSeverity.class, params); return Optional.ofNullable(alarmSeverity.getBody()); @@ -497,9 +467,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional getAssetById(String assetId) { + public Optional getAssetById(AssetId assetId) { try { - ResponseEntity asset = restTemplate.getForEntity(baseURL + "/api/asset/{assetId}", Asset.class, assetId); + ResponseEntity asset = restTemplate.getForEntity(baseURL + "/api/asset/{assetId}", Asset.class, assetId.getId()); return Optional.ofNullable(asset.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -514,15 +484,14 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return restTemplate.postForEntity(baseURL + "/api/asset", asset, Asset.class).getBody(); } - public void deleteAsset(String assetId) { - restTemplate.delete(baseURL + "/api/asset/{assetId}", assetId); + public void deleteAsset(AssetId assetId) { + restTemplate.delete(baseURL + "/api/asset/{assetId}", assetId.getId()); } - public Optional assignAssetToCustomer(String customerId, - String assetId) { + public Optional assignAssetToCustomer(CustomerId customerId, AssetId assetId) { Map params = new HashMap<>(); - params.put("customerId", customerId); - params.put("assetId", assetId); + params.put("customerId", customerId.getId().toString()); + params.put("assetId", assetId.getId().toString()); try { ResponseEntity asset = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/asset/{assetId}", null, Asset.class, params); @@ -536,9 +505,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional unassignAssetFromCustomer(String assetId) { + public Optional unassignAssetFromCustomer(AssetId assetId) { try { - ResponseEntity asset = restTemplate.exchange(baseURL + "/api/customer/asset/{assetId}", HttpMethod.DELETE, HttpEntity.EMPTY, Asset.class, assetId); + ResponseEntity asset = restTemplate.exchange(baseURL + "/api/customer/asset/{assetId}", HttpMethod.DELETE, HttpEntity.EMPTY, Asset.class, assetId.getId()); return Optional.ofNullable(asset.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -549,9 +518,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional assignAssetToPublicCustomer(String assetId) { + public Optional assignAssetToPublicCustomer(AssetId assetId) { try { - ResponseEntity asset = restTemplate.postForEntity(baseURL + "/api/customer/public/asset/{assetId}", null, Asset.class, assetId); + ResponseEntity asset = restTemplate.postForEntity(baseURL + "/api/customer/public/asset/{assetId}", null, Asset.class, assetId.getId()); return Optional.ofNullable(asset.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -562,9 +531,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public TextPageData getTenantAssets(TextPageLink pageLink, String type) { + public TextPageData getTenantAssets(TextPageLink pageLink, String assetType) { Map params = new HashMap<>(); - params.put("type", type); + params.put("type", assetType); addPageLinkToParam(params, pageLink); ResponseEntity> assets = restTemplate.exchange( @@ -589,10 +558,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public TextPageData getCustomerAssets(String customerId, TextPageLink pageLink, String type) { + public TextPageData getCustomerAssets(CustomerId customerId, TextPageLink pageLink, String assetType) { Map params = new HashMap<>(); - params.put("customerId", customerId); - params.put("type", type); + params.put("customerId", customerId.getId().toString()); + params.put("type", assetType); addPageLinkToParam(params, pageLink); ResponseEntity> assets = restTemplate.exchange( @@ -605,14 +574,15 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return assets.getBody(); } - public List getAssetsByIds(List assetIds) { + public List getAssetsByIds(List assetIds) { return restTemplate.exchange( baseURL + "/api/assets?assetIds={assetIds}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, - listToString(assetIds)).getBody(); + listIdsToString(assetIds)) + .getBody(); } public List findByQuery(AssetSearchQuery query) { @@ -633,10 +603,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { }).getBody(); } - public TimePageData getAuditLogsByCustomerId(String customerId, TimePageLink pageLink, String actionTypes) { + public TimePageData getAuditLogsByCustomerId(CustomerId customerId, TimePageLink pageLink, List actionTypes) { Map params = new HashMap<>(); - params.put("customerId", customerId); - params.put("actionTypes", actionTypes); + params.put("customerId", customerId.getId().toString()); + params.put("actionTypes", listEnumToString(actionTypes)); addPageLinkToParam(params, pageLink); ResponseEntity> auditLog = restTemplate.exchange( @@ -649,10 +619,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return auditLog.getBody(); } - public TimePageData getAuditLogsByUserId(String userId, TimePageLink pageLink, String actionTypes) { + public TimePageData getAuditLogsByUserId(UserId userId, TimePageLink pageLink, List actionTypes) { Map params = new HashMap<>(); - params.put("userId", userId); - params.put("actionTypes", actionTypes); + params.put("userId", userId.getId().toString()); + params.put("actionTypes", listEnumToString(actionTypes)); addPageLinkToParam(params, pageLink); ResponseEntity> auditLog = restTemplate.exchange( @@ -665,11 +635,11 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return auditLog.getBody(); } - public TimePageData getAuditLogsByEntityId(EntityId entityId, String actionTypes, TimePageLink pageLink) { + public TimePageData getAuditLogsByEntityId(EntityId entityId, List actionTypes, TimePageLink pageLink) { Map params = new HashMap<>(); params.put("entityType", entityId.getEntityType().name()); params.put("entityId", entityId.getId().toString()); - params.put("actionTypes", actionTypes); + params.put("actionTypes", listEnumToString(actionTypes)); addPageLinkToParam(params, pageLink); ResponseEntity> auditLog = restTemplate.exchange( @@ -682,9 +652,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return auditLog.getBody(); } - public TimePageData getAuditLogs(TimePageLink pageLink, String actionTypes) { + public TimePageData getAuditLogs(TimePageLink pageLink, List actionTypes) { Map params = new HashMap<>(); - params.put("actionTypes", actionTypes); + params.put("actionTypes", listEnumToString(actionTypes)); addPageLinkToParam(params, pageLink); ResponseEntity> auditLog = restTemplate.exchange( @@ -697,7 +667,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return auditLog.getBody(); } - public String getActivateToken(String userId) { + public String getActivateToken(UserId userId) { String activationLink = getActivationLink(userId); return StringUtils.delete(activationLink, baseURL + ACTIVATE_TOKEN_REGEX); } @@ -731,7 +701,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public ResponseEntity checkActivateToken(String userId) { + public ResponseEntity checkActivateToken(UserId userId) { String activateToken = getActivateToken(userId); return restTemplate.getForEntity(baseURL + "/api/noauth/activate?activateToken={activateToken}", String.class, activateToken); } @@ -742,7 +712,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { restTemplate.postForLocation(baseURL + "/api/noauth/resetPasswordByEmail", resetPasswordByEmailRequest); } - public Optional activateUser(String userId, String password) { + public Optional activateUser(UserId userId, String password) { ObjectNode activateRequest = objectMapper.createObjectNode(); activateRequest.put("activateToken", getActivateToken(userId)); activateRequest.put("password", password); @@ -771,7 +741,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public List getComponentDescriptorsByType(String componentType) { + public List getComponentDescriptorsByType(ComponentType componentType) { return restTemplate.exchange( baseURL + "/api/components?componentType={componentType}", HttpMethod.GET, HttpEntity.EMPTY, @@ -780,19 +750,20 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { componentType).getBody(); } - public List getComponentDescriptorsByTypes(List componentTypes) { + public List getComponentDescriptorsByTypes(List componentTypes) { return restTemplate.exchange( baseURL + "/api/components?componentTypes={componentTypes}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, - listToString(componentTypes)).getBody(); + listEnumToString(componentTypes)) + .getBody(); } - public Optional getCustomerById(String customerId) { + public Optional getCustomerById(CustomerId customerId) { try { - ResponseEntity customer = restTemplate.getForEntity(baseURL + "/api/customer/{customerId}", Customer.class, customerId); + ResponseEntity customer = restTemplate.getForEntity(baseURL + "/api/customer/{customerId}", Customer.class, customerId.getId()); return Optional.ofNullable(customer.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -803,9 +774,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional getShortCustomerInfoById(String customerId) { + public Optional getShortCustomerInfoById(CustomerId customerId) { try { - ResponseEntity customerInfo = restTemplate.getForEntity(baseURL + "/api/customer/{customerId}/shortInfo", JsonNode.class, customerId); + ResponseEntity customerInfo = restTemplate.getForEntity(baseURL + "/api/customer/{customerId}/shortInfo", JsonNode.class, customerId.getId()); return Optional.ofNullable(customerInfo.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -816,16 +787,16 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public String getCustomerTitleById(String customerId) { - return restTemplate.getForObject(baseURL + "/api/customer/{customerId}/title", String.class, customerId); + public String getCustomerTitleById(CustomerId customerId) { + return restTemplate.getForObject(baseURL + "/api/customer/{customerId}/title", String.class, customerId.getId()); } public Customer saveCustomer(Customer customer) { return restTemplate.postForEntity(baseURL + "/api/customer", customer, Customer.class).getBody(); } - public void deleteCustomer(String customerId) { - restTemplate.delete(baseURL + "/api/customer/{customerId}", customerId); + public void deleteCustomer(CustomerId customerId) { + restTemplate.delete(baseURL + "/api/customer/{customerId}", customerId.getId()); } public TextPageData getCustomers(TextPageLink pageLink) { @@ -863,9 +834,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return restTemplate.getForObject(baseURL + "/api/dashboard/maxDatapointsLimit", Long.class); } - public Optional getDashboardInfoById(String dashboardId) { + public Optional getDashboardInfoById(DashboardId dashboardId) { try { - ResponseEntity dashboardInfo = restTemplate.getForEntity(baseURL + "/api/dashboard/info/{dashboardId}", DashboardInfo.class, dashboardId); + ResponseEntity dashboardInfo = restTemplate.getForEntity(baseURL + "/api/dashboard/info/{dashboardId}", DashboardInfo.class, dashboardId.getId()); return Optional.ofNullable(dashboardInfo.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -876,9 +847,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional getDashboardById(String dashboardId) { + public Optional getDashboardById(DashboardId dashboardId) { try { - ResponseEntity dashboard = restTemplate.getForEntity(baseURL + "/api/dashboard/{dashboardId}", Dashboard.class, dashboardId); + ResponseEntity dashboard = restTemplate.getForEntity(baseURL + "/api/dashboard/{dashboardId}", Dashboard.class, dashboardId.getId()); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -893,13 +864,13 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return restTemplate.postForEntity(baseURL + "/api/dashboard", dashboard, Dashboard.class).getBody(); } - public void deleteDashboard(String dashboardId) { - restTemplate.delete(baseURL + "/api/dashboard/{dashboardId}", dashboardId); + public void deleteDashboard(DashboardId dashboardId) { + restTemplate.delete(baseURL + "/api/dashboard/{dashboardId}", dashboardId.getId()); } - public Optional assignDashboardToCustomer(String customerId, String dashboardId) { + public Optional assignDashboardToCustomer(CustomerId customerId, DashboardId dashboardId) { try { - ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/dashboard/{dashboardId}", null, Dashboard.class, customerId, dashboardId); + ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/dashboard/{dashboardId}", null, Dashboard.class, customerId.getId(), dashboardId.getId()); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -910,9 +881,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional unassignDashboardFromCustomer(String customerId, String dashboardId) { + public Optional unassignDashboardFromCustomer(CustomerId customerId, DashboardId dashboardId) { try { - ResponseEntity dashboard = restTemplate.exchange(baseURL + "/api/customer/{customerId}/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, customerId, dashboardId); + ResponseEntity dashboard = restTemplate.exchange(baseURL + "/api/customer/{customerId}/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, customerId.getId(), dashboardId.getId()); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -923,9 +894,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional updateDashboardCustomers(String dashboardId, List customerIds) { + public Optional updateDashboardCustomers(DashboardId dashboardId, List customerIds) { + Object[] customerIdArray = customerIds.stream().map(customerId -> customerId.getId().toString()).toArray(); try { - ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers", customerIds, Dashboard.class, dashboardId); + ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers", customerIdArray, Dashboard.class, dashboardId.getId()); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -936,9 +908,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional addDashboardCustomers(String dashboardId, List customerIds) { + public Optional addDashboardCustomers(DashboardId dashboardId, List customerIds) { + Object[] customerIdArray = customerIds.stream().map(customerId -> customerId.getId().toString()).toArray(); try { - ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers/add", customerIds, Dashboard.class, dashboardId); + ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers/add", customerIdArray, Dashboard.class, dashboardId.getId()); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -949,9 +922,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional removeDashboardCustomers(String dashboardId, List customerIds) { + public Optional removeDashboardCustomers(DashboardId dashboardId, List customerIds) { + Object[] customerIdArray = customerIds.stream().map(customerId -> customerId.getId().toString()).toArray(); try { - ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers/remove", customerIds, Dashboard.class, dashboardId); + ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers/remove", customerIdArray, Dashboard.class, dashboardId.getId()); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -962,9 +936,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional assignDashboardToPublicCustomer(String dashboardId) { + public Optional assignDashboardToPublicCustomer(DashboardId dashboardId) { try { - ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/customer/public/dashboard/{dashboardId}", null, Dashboard.class, dashboardId); + ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/customer/public/dashboard/{dashboardId}", null, Dashboard.class, dashboardId.getId()); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -975,9 +949,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional unassignDashboardFromPublicCustomer(String dashboardId) { + public Optional unassignDashboardFromPublicCustomer(DashboardId dashboardId) { try { - ResponseEntity dashboard = restTemplate.exchange(baseURL + "/api/customer/public/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, dashboardId); + ResponseEntity dashboard = restTemplate.exchange(baseURL + "/api/customer/public/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, dashboardId.getId()); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -988,17 +962,15 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public TextPageData getTenantDashboards(String tenantId, TextPageLink pageLink) { + public TextPageData getTenantDashboards(TenantId tenantId, TextPageLink pageLink) { Map params = new HashMap<>(); - params.put("tenantId", tenantId); + params.put("tenantId", tenantId.getId().toString()); addPageLinkToParam(params, pageLink); return restTemplate.exchange( baseURL + "/api/tenant/{tenantId}/dashboards?" + getUrlParams(pageLink), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }, - params - ).getBody(); + }, params).getBody(); } public TextPageData getTenantDashboards(TextPageLink pageLink) { @@ -1008,27 +980,23 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { baseURL + "/api/tenant/dashboards?" + getUrlParams(pageLink), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }, - params - ).getBody(); + }, params).getBody(); } - public TimePageData getCustomerDashboards(String customerId, TimePageLink pageLink) { + public TimePageData getCustomerDashboards(CustomerId customerId, TimePageLink pageLink) { Map params = new HashMap<>(); - params.put("customerId", customerId); + params.put("customerId", customerId.getId().toString()); addPageLinkToParam(params, pageLink); return restTemplate.exchange( baseURL + "/api/customer/{customerId}/dashboards?" + getUrlParams(pageLink), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }, - params - ).getBody(); + }, params).getBody(); } - public Optional getDeviceById(String deviceId) { + public Optional getDeviceById(DeviceId deviceId) { try { - ResponseEntity device = restTemplate.getForEntity(baseURL + "/api/device/{deviceId}", Device.class, deviceId); + ResponseEntity device = restTemplate.getForEntity(baseURL + "/api/device/{deviceId}", Device.class, deviceId.getId()); return Optional.ofNullable(device.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1043,13 +1011,13 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return restTemplate.postForEntity(baseURL + "/api/device", device, Device.class).getBody(); } - public void deleteDevice(String deviceId) { - restTemplate.delete(baseURL + "/api/device/{deviceId}", deviceId); + public void deleteDevice(DeviceId deviceId) { + restTemplate.delete(baseURL + "/api/device/{deviceId}", deviceId.getId()); } - public Optional assignDeviceToCustomer(String customerId, String deviceId) { + public Optional assignDeviceToCustomer(CustomerId customerId, DeviceId deviceId) { try { - ResponseEntity device = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/device/{deviceId}", null, Device.class, customerId, deviceId); + ResponseEntity device = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/device/{deviceId}", null, Device.class, customerId.getId(), deviceId.getId()); return Optional.ofNullable(device.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1060,9 +1028,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional unassignDeviceFromCustomer(String deviceId) { + public Optional unassignDeviceFromCustomer(DeviceId deviceId) { try { - ResponseEntity device = restTemplate.exchange(baseURL + "/api/customer/device/{deviceId}", HttpMethod.DELETE, HttpEntity.EMPTY, Device.class, deviceId); + ResponseEntity device = restTemplate.exchange(baseURL + "/api/customer/device/{deviceId}", HttpMethod.DELETE, HttpEntity.EMPTY, Device.class, deviceId.getId()); return Optional.ofNullable(device.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1073,9 +1041,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional assignDeviceToPublicCustomer(String deviceId) { + public Optional assignDeviceToPublicCustomer(DeviceId deviceId) { try { - ResponseEntity device = restTemplate.postForEntity(baseURL + "/api/customer/public/device/{deviceId}", null, Device.class, deviceId); + ResponseEntity device = restTemplate.postForEntity(baseURL + "/api/customer/public/device/{deviceId}", null, Device.class, deviceId.getId()); return Optional.ofNullable(device.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1086,9 +1054,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional getDeviceCredentialsByDeviceId(String deviceId) { + public Optional getDeviceCredentialsByDeviceId(DeviceId deviceId) { try { - ResponseEntity deviceCredentials = restTemplate.getForEntity(baseURL + "/api/device/{deviceId}/credentials", DeviceCredentials.class, deviceId); + ResponseEntity deviceCredentials = restTemplate.getForEntity(baseURL + "/api/device/{deviceId}/credentials", DeviceCredentials.class, deviceId.getId()); return Optional.ofNullable(deviceCredentials.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1111,9 +1079,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { baseURL + "/api/tenant/devices?type={type}&" + getUrlParams(pageLink), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }, - params) - .getBody(); + }, params).getBody(); } public Optional getTenantDevice(String deviceName) { @@ -1129,26 +1095,23 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public TextPageData getCustomerDevices(String customerId, String type, TextPageLink pageLink) { + public TextPageData getCustomerDevices(CustomerId customerId, String deviceType, TextPageLink pageLink) { Map params = new HashMap<>(); - params.put("customerId", customerId); - params.put("type", type); + params.put("customerId", customerId.getId().toString()); + params.put("type", deviceType); addPageLinkToParam(params, pageLink); return restTemplate.exchange( baseURL + "/api/customer/{customerId}/devices?type={type}&" + getUrlParams(pageLink), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }, - params) - .getBody(); + }, params).getBody(); } - public List getDevicesByIds(List deviceIds) { + public List getDevicesByIds(List deviceIds) { return restTemplate.exchange(baseURL + "/api/devices?deviceIds={deviceIds}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }, - listToString(deviceIds)).getBody(); + }, listIdsToString(deviceIds)).getBody(); } public List findByQuery(DeviceSearchQuery query) { @@ -1175,8 +1138,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { HttpMethod.POST, new HttpEntity<>(claimRequest), new ParameterizedTypeReference() { - }, - deviceName).getBody(); + }, deviceName).getBody(); } public void reClaimDevice(String deviceName) { @@ -1187,14 +1149,14 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { restTemplate.postForLocation(baseURL + "/api/relation", null); } - public void deleteRelation(String fromId, String fromType, String relationType, String relationTypeGroup, String toId, String toType) { + public void deleteRelation(EntityId fromId, String relationType, RelationTypeGroup relationTypeGroup, EntityId toId) { Map params = new HashMap<>(); - params.put("fromId", fromId); - params.put("fromType", fromType); + params.put("fromId", fromId.getId().toString()); + params.put("fromType", fromId.getEntityType().name()); params.put("relationType", relationType); - params.put("relationTypeGroup", relationTypeGroup); - params.put("toId", toId); - params.put("toType", toType); + params.put("relationTypeGroup", relationTypeGroup.name()); + params.put("toId", toId.getId().toString()); + params.put("toType", toId.getEntityType().name()); restTemplate.delete(baseURL + "/api/relation?fromId={fromId}&fromType={fromType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}&toId={toId}&toType={toType}", params); } @@ -1202,14 +1164,14 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { restTemplate.delete(baseURL + "/api/relations?entityId={entityId}&entityType={entityType}", entityId.getId().toString(), entityId.getEntityType().name()); } - public Optional getRelation(String fromId, String fromType, String relationType, String relationTypeGroup, String toId, String toType) { + public Optional getRelation(EntityId fromId, String relationType, RelationTypeGroup relationTypeGroup, EntityId toId) { Map params = new HashMap<>(); - params.put("fromId", fromId); - params.put("fromType", fromType); + params.put("fromId", fromId.getId().toString()); + params.put("fromType", fromId.getEntityType().name()); params.put("relationType", relationType); - params.put("relationTypeGroup", relationTypeGroup); - params.put("toId", toId); - params.put("toType", toType); + params.put("relationTypeGroup", relationTypeGroup.name()); + params.put("toId", toId.getId().toString()); + params.put("toType", toId.getEntityType().name()); try { ResponseEntity entityRelation = restTemplate.getForEntity( @@ -1226,11 +1188,11 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public List findByFrom(String fromId, String fromType, String relationTypeGroup) { + public List findByFrom(EntityId fromId, RelationTypeGroup relationTypeGroup) { Map params = new HashMap<>(); - params.put("fromId", fromId); - params.put("fromType", fromType); - params.put("relationTypeGroup", relationTypeGroup); + params.put("fromId", fromId.getId().toString()); + params.put("fromType", fromId.getEntityType().name()); + params.put("relationTypeGroup", relationTypeGroup.name()); return restTemplate.exchange( baseURL + "/api/relations?fromId={fromId}&fromType={fromType}&relationTypeGroup={relationTypeGroup}", @@ -1241,11 +1203,11 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { params).getBody(); } - public List findInfoByFrom(String fromId, String fromType, String relationTypeGroup) { + public List findInfoByFrom(EntityId fromId, RelationTypeGroup relationTypeGroup) { Map params = new HashMap<>(); - params.put("fromId", fromId); - params.put("fromType", fromType); - params.put("relationTypeGroup", relationTypeGroup); + params.put("fromId", fromId.getId().toString()); + params.put("fromType", fromId.getEntityType().name()); + params.put("relationTypeGroup", relationTypeGroup.name()); return restTemplate.exchange( baseURL + "/api/relations/info?fromId={fromId}&fromType={fromType}&relationTypeGroup={relationTypeGroup}", @@ -1256,12 +1218,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { params).getBody(); } - public List findByFrom(String fromId, String fromType, String relationType, String relationTypeGroup) { + public List findByFrom(EntityId fromId, String relationType, RelationTypeGroup relationTypeGroup) { Map params = new HashMap<>(); - params.put("fromId", fromId); - params.put("fromType", fromType); + params.put("fromId", fromId.getId().toString()); + params.put("fromType", fromId.getEntityType().name()); params.put("relationType", relationType); - params.put("relationTypeGroup", relationTypeGroup); + params.put("relationTypeGroup", relationTypeGroup.name()); return restTemplate.exchange( baseURL + "/api/relations?fromId={fromId}&fromType={fromType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}", @@ -1272,11 +1234,11 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { params).getBody(); } - public List findByTo(String toId, String toType, String relationTypeGroup) { + public List findByTo(EntityId toId, RelationTypeGroup relationTypeGroup) { Map params = new HashMap<>(); - params.put("toId", toId); - params.put("toType", toType); - params.put("relationTypeGroup", relationTypeGroup); + params.put("toId", toId.getId().toString()); + params.put("toType", toId.getEntityType().name()); + params.put("relationTypeGroup", relationTypeGroup.name()); return restTemplate.exchange( baseURL + "/api/relations?toId={toId}&toType={toType}&relationTypeGroup={relationTypeGroup}", @@ -1287,11 +1249,11 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { params).getBody(); } - public List findInfoByTo(String toId, String toType, String relationTypeGroup) { + public List findInfoByTo(EntityId toId, RelationTypeGroup relationTypeGroup) { Map params = new HashMap<>(); - params.put("toId", toId); - params.put("toType", toType); - params.put("relationTypeGroup", relationTypeGroup); + params.put("toId", toId.getId().toString()); + params.put("toType", toId.getEntityType().name()); + params.put("relationTypeGroup", relationTypeGroup.name()); return restTemplate.exchange( baseURL + "/api/relations?toId={toId}&toType={toType}&relationTypeGroup={relationTypeGroup}", @@ -1302,12 +1264,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { params).getBody(); } - public List findByTo(String toId, String toType, String relationType, String relationTypeGroup) { + public List findByTo(EntityId toId, String relationType, RelationTypeGroup relationTypeGroup) { Map params = new HashMap<>(); - params.put("toId", toId); - params.put("toType", toType); + params.put("toId", toId.getId().toString()); + params.put("toType", toId.getEntityType().name()); params.put("relationType", relationType); - params.put("relationTypeGroup", relationTypeGroup); + params.put("relationTypeGroup", relationTypeGroup.name()); return restTemplate.exchange( baseURL + "/api/relations?toId={toId}&toType={toType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}", @@ -1336,9 +1298,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { }).getBody(); } - public Optional getEntityViewById(String entityViewId) { + public Optional getEntityViewById(EntityViewId entityViewId) { try { - ResponseEntity entityView = restTemplate.getForEntity(baseURL + "/api/entityView/{entityViewId}", EntityView.class, entityViewId); + ResponseEntity entityView = restTemplate.getForEntity(baseURL + "/api/entityView/{entityViewId}", EntityView.class, entityViewId.getId()); return Optional.ofNullable(entityView.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1370,9 +1332,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional assignEntityViewToCustomer(String customerId, String entityViewId) { + public Optional assignEntityViewToCustomer(CustomerId customerId, EntityViewId entityViewId) { try { - ResponseEntity entityView = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/entityView/{entityViewId}", null, EntityView.class, customerId, entityViewId); + ResponseEntity entityView = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/entityView/{entityViewId}", null, EntityView.class, customerId.getId(), entityViewId.getId()); return Optional.ofNullable(entityView.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1383,13 +1345,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional unassignEntityViewFromCustomer(String entityViewId) { + public Optional unassignEntityViewFromCustomer(EntityViewId entityViewId) { try { - ResponseEntity entityView = restTemplate.exchange( - baseURL + "/api/customer/entityView/{entityViewId}", - HttpMethod.DELETE, - HttpEntity.EMPTY, - EntityView.class, entityViewId); + ResponseEntity entityView = restTemplate.exchange(baseURL + "/api/customer/entityView/{entityViewId}", HttpMethod.DELETE, HttpEntity.EMPTY, EntityView.class, entityViewId.getId()); return Optional.ofNullable(entityView.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1400,31 +1358,29 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public TextPageData getCustomerEntityViews(String customerId, String type, TextPageLink pageLink) { + public TextPageData getCustomerEntityViews(CustomerId customerId, String entityViewType, TextPageLink pageLink) { Map params = new HashMap<>(); - params.put("customerId", customerId); - params.put("type", type); + params.put("customerId", customerId.getId().toString()); + params.put("type", entityViewType); addPageLinkToParam(params, pageLink); return restTemplate.exchange( baseURL + "/api/customer/{customerId}/entityViews?type={type}&" + getUrlParams(pageLink), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }, - params).getBody(); + }, params).getBody(); } - public TextPageData getTenantEntityViews(String type, TextPageLink pageLink) { + public TextPageData getTenantEntityViews(String entityViewType, TextPageLink pageLink) { Map params = new HashMap<>(); - params.put("type", type); + params.put("type", entityViewType); addPageLinkToParam(params, pageLink); return restTemplate.exchange( baseURL + "/api/tenant/entityViews?type={type}&" + getUrlParams(pageLink), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }, - params).getBody(); + }, params).getBody(); } public List findByQuery(EntityViewSearchQuery query) { @@ -1437,9 +1393,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { }).getBody(); } - public Optional assignEntityViewToPublicCustomer(String entityViewId) { + public Optional assignEntityViewToPublicCustomer(EntityViewId entityViewId) { try { - ResponseEntity entityView = restTemplate.postForEntity(baseURL + "/api/customer/public/entityView/{entityViewId}", null, EntityView.class, entityViewId); + ResponseEntity entityView = restTemplate.postForEntity(baseURL + "/api/customer/public/entityView/{entityViewId}", null, EntityView.class, entityViewId.getId()); return Optional.ofNullable(entityView.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1450,12 +1406,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public TimePageData getEvents(EntityId entityId, String eventType, String tenantId, TimePageLink pageLink) { + public TimePageData getEvents(EntityId entityId, String eventType, TenantId tenantId, TimePageLink pageLink) { Map params = new HashMap<>(); params.put("entityType", entityId.getEntityType().name()); params.put("entityId", entityId.getId().toString()); params.put("eventType", eventType); - params.put("tenantId", tenantId); + params.put("tenantId", tenantId.getId().toString()); addPageLinkToParam(params, pageLink); return restTemplate.exchange( @@ -1467,11 +1423,11 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { params).getBody(); } - public TimePageData getEvents(EntityId entityId, String tenantId, TimePageLink pageLink) { + public TimePageData getEvents(EntityId entityId, TenantId tenantId, TimePageLink pageLink) { Map params = new HashMap<>(); params.put("entityType", entityId.getEntityType().name()); params.put("entityId", entityId.getId().toString()); - params.put("tenantId", tenantId); + params.put("tenantId", tenantId.getId().toString()); addPageLinkToParam(params, pageLink); return restTemplate.exchange( @@ -1483,8 +1439,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { params).getBody(); } - public void handleOneWayDeviceRPCRequest(String deviceId, JsonNode requestBody) { - restTemplate.postForLocation(baseURL + "/api/plugins/rpc/oneway/{deviceId}", requestBody, deviceId); + public void handleOneWayDeviceRPCRequest(DeviceId deviceId, JsonNode requestBody) { + restTemplate.postForLocation(baseURL + "/api/plugins/rpc/oneway/{deviceId}", requestBody, deviceId.getId()); } public JsonNode handleTwoWayDeviceRPCRequest(String deviceId, JsonNode requestBody) { @@ -1497,9 +1453,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { deviceId).getBody(); } - public Optional getRuleChainById(String ruleChainId) { + public Optional getRuleChainById(RuleChainId ruleChainId) { try { - ResponseEntity ruleChain = restTemplate.getForEntity(baseURL + "/api/ruleChain/{ruleChainId}", RuleChain.class, ruleChainId); + ResponseEntity ruleChain = restTemplate.getForEntity(baseURL + "/api/ruleChain/{ruleChainId}", RuleChain.class, ruleChainId.getId()); return Optional.ofNullable(ruleChain.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1510,9 +1466,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } - public Optional getRuleChainMetaData(String ruleChainId) { + public Optional getRuleChainMetaData(RuleChainId ruleChainId) { try { - ResponseEntity ruleChainMetaData = restTemplate.getForEntity(baseURL + "/api/ruleChain/{ruleChainId}/metadata", RuleChainMetaData.class, ruleChainId); + ResponseEntity ruleChainMetaData = restTemplate.getForEntity(baseURL + "/api/ruleChain/{ruleChainId}/metadata", RuleChainMetaData.class, ruleChainId.getId()); return Optional.ofNullable(ruleChainMetaData.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1527,9 +1483,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return restTemplate.postForEntity(baseURL + "/api/ruleChain", ruleChain, RuleChain.class).getBody(); } - public Optional setRootRuleChain(String ruleChainId) { + public Optional setRootRuleChain(RuleChainId ruleChainId) { try { - ResponseEntity ruleChain = restTemplate.postForEntity(baseURL + "/api/ruleChain/{ruleChainId}/root", null, RuleChain.class, ruleChainId); + ResponseEntity ruleChain = restTemplate.postForEntity(baseURL + "/api/ruleChain/{ruleChainId}/root", null, RuleChain.class, ruleChainId.getId()); return Optional.ofNullable(ruleChain.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1548,21 +1504,21 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { Map params = new HashMap<>(); addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/api/ruleChains" + getUrlParams(pageLink), + baseURL + "/api/ruleChains?" + getUrlParams(pageLink), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - } - ).getBody(); + }, + params).getBody(); } - public void deleteRuleChain(String ruleChainId) { - restTemplate.delete(baseURL + "/api/ruleChain/{ruleChainId}", ruleChainId); + public void deleteRuleChain(RuleChainId ruleChainId) { + restTemplate.delete(baseURL + "/api/ruleChain/{ruleChainId}", ruleChainId.getId()); } - public Optional getLatestRuleNodeDebugInput(String ruleNodeId) { + public Optional getLatestRuleNodeDebugInput(RuleNodeId ruleNodeId) { try { - ResponseEntity jsonNode = restTemplate.getForEntity(baseURL + "/api/ruleNode/{ruleNodeId}/debugIn", JsonNode.class, ruleNodeId); + ResponseEntity jsonNode = restTemplate.getForEntity(baseURL + "/api/ruleNode/{ruleNodeId}/debugIn", JsonNode.class, ruleNodeId.getId()); return Optional.ofNullable(jsonNode.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1668,19 +1624,17 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } - public List getTimeseries(EntityId entityId, List keys, Long startTs, Long endTs, Long interval, Integer limit, String agg) { + public List getTimeseries(EntityId entityId, List keys, Long interval, Aggregation agg, TimePageLink pageLink) { Map params = new HashMap<>(); + addPageLinkToParam(params, pageLink); params.put("entityType", entityId.getEntityType().name()); params.put("entityId", entityId.getId().toString()); params.put("keys", listToString(keys)); - params.put("startTs", startTs.toString()); - params.put("endTs", endTs.toString()); params.put("interval", interval == null ? "0" : interval.toString()); - params.put("limit", limit == null ? "100" : limit.toString()); - params.put("agg", agg == null ? "NONE" : agg); + params.put("agg", agg == null ? "NONE" : agg.name()); Map> timeseries = restTemplate.exchange( - baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/values/timeseries?keys={keys}&startTs={startTs}&endTs={endTs}&interval={interval}&limit={limit}&agg={agg}", + baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/values/timeseries?keys={keys}&interval={interval}&agg={agg}&" + getUrlParams(pageLink), HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>>() { @@ -1807,9 +1761,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } - public Optional getTenantById(String tenantId) { + public Optional getTenantById(TenantId tenantId) { try { - ResponseEntity tenant = restTemplate.getForEntity(baseURL + "/api/tenant/{tenantId}", Tenant.class, tenantId); + ResponseEntity tenant = restTemplate.getForEntity(baseURL + "/api/tenant/{tenantId}", Tenant.class, tenantId.getId()); return Optional.ofNullable(tenant.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1824,8 +1778,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return restTemplate.postForEntity(baseURL + "/api/tenant", tenant, Tenant.class).getBody(); } - public void deleteTenant(String tenantId) { - restTemplate.delete(baseURL + "/api/tenant/{tenantId}", tenantId); + public void deleteTenant(TenantId tenantId) { + restTemplate.delete(baseURL + "/api/tenant/{tenantId}", tenantId.getId()); } public TextPageData getTenants(TextPageLink pageLink) { @@ -1836,13 +1790,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }, - params).getBody(); + }, params).getBody(); } - public Optional getUserById(String userId) { + public Optional getUserById(UserId userId) { try { - ResponseEntity user = restTemplate.getForEntity(baseURL + "/api/user/{userId}", User.class, userId); + ResponseEntity user = restTemplate.getForEntity(baseURL + "/api/user/{userId}", User.class, userId.getId()); return Optional.ofNullable(user.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1857,9 +1810,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return restTemplate.getForEntity(baseURL + "/api/user/tokenAccessEnabled", Boolean.class).getBody(); } - public Optional getUserToken(String userId) { + public Optional getUserToken(UserId userId) { try { - ResponseEntity userToken = restTemplate.getForEntity(baseURL + "/api/user/{userId}/token", JsonNode.class, userId); + ResponseEntity userToken = restTemplate.getForEntity(baseURL + "/api/user/{userId}/token", JsonNode.class, userId.getId()); return Optional.ofNullable(userToken.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1878,17 +1831,17 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { restTemplate.postForLocation(baseURL + "/api/user/sendActivationMail?email={email}", null, email); } - public String getActivationLink(String userId) { - return restTemplate.getForEntity(baseURL + "/api/user/{userId}/activationLink", String.class, userId).getBody(); + public String getActivationLink(UserId userId) { + return restTemplate.getForEntity(baseURL + "/api/user/{userId}/activationLink", String.class, userId.getId()).getBody(); } - public void deleteUser(String userId) { - restTemplate.delete(baseURL + "/api/user/{userId}", userId); + public void deleteUser(UserId userId) { + restTemplate.delete(baseURL + "/api/user/{userId}", userId.getId()); } - public TextPageData getTenantAdmins(String tenantId, TextPageLink pageLink) { + public TextPageData getTenantAdmins(TenantId tenantId, TextPageLink pageLink) { Map params = new HashMap<>(); - params.put("tenantId", tenantId); + params.put("tenantId", tenantId.getId().toString()); addPageLinkToParam(params, pageLink); return restTemplate.exchange( @@ -1896,13 +1849,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }, - params).getBody(); + }, params).getBody(); } - public TextPageData getCustomerUsers(String customerId, TextPageLink pageLink) { + public TextPageData getCustomerUsers(CustomerId customerId, TextPageLink pageLink) { Map params = new HashMap<>(); - params.put("customerId", customerId); + params.put("customerId", customerId.getId().toString()); addPageLinkToParam(params, pageLink); return restTemplate.exchange( @@ -1910,22 +1862,21 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }, - params).getBody(); + }, params).getBody(); } - public void setUserCredentialsEnabled(String userId, boolean userCredentialsEnabled) { + public void setUserCredentialsEnabled(UserId userId, boolean userCredentialsEnabled) { restTemplate.postForLocation( baseURL + "/api/user/{userId}/userCredentialsEnabled?serCredentialsEnabled={serCredentialsEnabled}", null, - userId, + userId.getId(), userCredentialsEnabled); } - public Optional getWidgetsBundleById(String widgetsBundleId) { + public Optional getWidgetsBundleById(WidgetsBundleId widgetsBundleId) { try { ResponseEntity widgetsBundle = - restTemplate.getForEntity(baseURL + "/api/widgetsBundle/{widgetsBundleId}", WidgetsBundle.class, widgetsBundleId); + restTemplate.getForEntity(baseURL + "/api/widgetsBundle/{widgetsBundleId}", WidgetsBundle.class, widgetsBundleId.getId()); return Optional.ofNullable(widgetsBundle.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1940,8 +1891,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return restTemplate.postForEntity(baseURL + "/api/widgetsBundle", widgetsBundle, WidgetsBundle.class).getBody(); } - public void deleteWidgetsBundle(String widgetsBundleId) { - restTemplate.delete(baseURL + "/api/widgetsBundle/{widgetsBundleId}", widgetsBundleId); + public void deleteWidgetsBundle(WidgetsBundleId widgetsBundleId) { + restTemplate.delete(baseURL + "/api/widgetsBundle/{widgetsBundleId}", widgetsBundleId.getId()); } public TextPageData getWidgetsBundles(TextPageLink pageLink) { @@ -1952,7 +1903,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { - }).getBody(); + }, params).getBody(); } public List getWidgetsBundles() { @@ -1964,10 +1915,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { }).getBody(); } - public Optional getWidgetTypeById(String widgetTypeId) { + public Optional getWidgetTypeById(WidgetsBundleId widgetTypeId) { try { ResponseEntity widgetType = - restTemplate.getForEntity(baseURL + "/api/widgetType/{widgetTypeId}", WidgetType.class, widgetTypeId); + restTemplate.getForEntity(baseURL + "/api/widgetType/{widgetTypeId}", WidgetType.class, widgetTypeId.getId()); return Optional.ofNullable(widgetType.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1982,8 +1933,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return restTemplate.postForEntity(baseURL + "/api/widgetType", widgetType, WidgetType.class).getBody(); } - public void deleteWidgetType(String widgetTypeId) { - restTemplate.delete(baseURL + "/api/widgetType/{widgetTypeId}", widgetTypeId); + public void deleteWidgetType(WidgetTypeId widgetTypeId) { + restTemplate.delete(baseURL + "/api/widgetType/{widgetTypeId}", widgetTypeId.getId()); } public List getBundleWidgetTypes(boolean isSystem, String bundleAlias) { @@ -2016,6 +1967,34 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { } } + private String getUrlParams(TimePageLink pageLink) { + String urlParams = "limit={limit}&ascOrder={ascOrder}"; + if (pageLink.getStartTime() != null) { + urlParams += "&startTime={startTime}"; + } + if (pageLink.getEndTime() != null) { + urlParams += "&endTime={endTime}"; + } + if (pageLink.getIdOffset() != null) { + urlParams += "&offset={offset}"; + } + return urlParams; + } + + private String getUrlParams(TextPageLink pageLink) { + String urlParams = "limit={limit}"; + if (!isEmpty(pageLink.getTextSearch())) { + urlParams += "&textSearch={textSearch}"; + } + if (!isEmpty(pageLink.getIdOffset())) { + urlParams += "&idOffset={idOffset}"; + } + if (!isEmpty(pageLink.getTextOffset())) { + urlParams += "&textOffset={textOffset}"; + } + return urlParams; + } + private void addPageLinkToParam(Map params, TimePageLink pageLink) { params.put("limit", String.valueOf(pageLink.getLimit())); if (pageLink.getStartTime() != null) { @@ -2049,6 +2028,14 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { return String.join(",", list); } + private String listIdsToString(List list) { + return listToString(list.stream().map(id -> id.getId().toString()).collect(Collectors.toList())); + } + + private String listEnumToString(List list) { + return listToString(list.stream().map(Enum::name).collect(Collectors.toList())); + } + @Override public void close() { if (service != null) {