Commit b0126a9d47f435922bf9bfe08c85754f67afced1

Authored by YevhenBondarenko
Committed by Andrew Shvayka
1 parent 2b3a1ce8

added new APIs

... ... @@ -38,10 +38,18 @@ import org.thingsboard.server.common.data.Customer;
38 38 import org.thingsboard.server.common.data.Dashboard;
39 39 import org.thingsboard.server.common.data.DashboardInfo;
40 40 import org.thingsboard.server.common.data.Device;
  41 +import org.thingsboard.server.common.data.DeviceInfo;
  42 +import org.thingsboard.server.common.data.DeviceProfile;
  43 +import org.thingsboard.server.common.data.DeviceProfileInfo;
  44 +import org.thingsboard.server.common.data.DeviceTransportType;
  45 +import org.thingsboard.server.common.data.EntityInfo;
41 46 import org.thingsboard.server.common.data.EntitySubtype;
42 47 import org.thingsboard.server.common.data.EntityView;
  48 +import org.thingsboard.server.common.data.EntityViewInfo;
43 49 import org.thingsboard.server.common.data.Event;
44 50 import org.thingsboard.server.common.data.Tenant;
  51 +import org.thingsboard.server.common.data.TenantInfo;
  52 +import org.thingsboard.server.common.data.TenantProfile;
45 53 import org.thingsboard.server.common.data.UpdateMessage;
46 54 import org.thingsboard.server.common.data.User;
47 55 import org.thingsboard.server.common.data.alarm.Alarm;
... ... @@ -50,6 +58,7 @@ import org.thingsboard.server.common.data.alarm.AlarmSearchStatus;
50 58 import org.thingsboard.server.common.data.alarm.AlarmSeverity;
51 59 import org.thingsboard.server.common.data.alarm.AlarmStatus;
52 60 import org.thingsboard.server.common.data.asset.Asset;
  61 +import org.thingsboard.server.common.data.asset.AssetInfo;
53 62 import org.thingsboard.server.common.data.asset.AssetSearchQuery;
54 63 import org.thingsboard.server.common.data.audit.ActionType;
55 64 import org.thingsboard.server.common.data.audit.AuditLog;
... ... @@ -60,28 +69,41 @@ import org.thingsboard.server.common.data.id.AssetId;
60 69 import org.thingsboard.server.common.data.id.CustomerId;
61 70 import org.thingsboard.server.common.data.id.DashboardId;
62 71 import org.thingsboard.server.common.data.id.DeviceId;
  72 +import org.thingsboard.server.common.data.id.DeviceProfileId;
63 73 import org.thingsboard.server.common.data.id.EntityId;
64 74 import org.thingsboard.server.common.data.id.EntityViewId;
  75 +import org.thingsboard.server.common.data.id.OAuth2ClientRegistrationTemplateId;
65 76 import org.thingsboard.server.common.data.id.RuleChainId;
66 77 import org.thingsboard.server.common.data.id.RuleNodeId;
67 78 import org.thingsboard.server.common.data.id.TenantId;
  79 +import org.thingsboard.server.common.data.id.TenantProfileId;
68 80 import org.thingsboard.server.common.data.id.UserId;
69 81 import org.thingsboard.server.common.data.id.WidgetTypeId;
70 82 import org.thingsboard.server.common.data.id.WidgetsBundleId;
71 83 import org.thingsboard.server.common.data.kv.Aggregation;
72 84 import org.thingsboard.server.common.data.kv.AttributeKvEntry;
73 85 import org.thingsboard.server.common.data.kv.TsKvEntry;
  86 +import org.thingsboard.server.common.data.oauth2.OAuth2ClientInfo;
  87 +import org.thingsboard.server.common.data.oauth2.OAuth2ClientRegistrationTemplate;
  88 +import org.thingsboard.server.common.data.oauth2.OAuth2ClientsParams;
74 89 import org.thingsboard.server.common.data.page.PageData;
75 90 import org.thingsboard.server.common.data.page.PageLink;
76 91 import org.thingsboard.server.common.data.page.SortOrder;
77 92 import org.thingsboard.server.common.data.page.TimePageLink;
78 93 import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
79 94 import org.thingsboard.server.common.data.plugin.ComponentType;
  95 +import org.thingsboard.server.common.data.query.AlarmData;
  96 +import org.thingsboard.server.common.data.query.AlarmDataQuery;
  97 +import org.thingsboard.server.common.data.query.EntityCountQuery;
  98 +import org.thingsboard.server.common.data.query.EntityData;
  99 +import org.thingsboard.server.common.data.query.EntityDataQuery;
80 100 import org.thingsboard.server.common.data.relation.EntityRelation;
81 101 import org.thingsboard.server.common.data.relation.EntityRelationInfo;
82 102 import org.thingsboard.server.common.data.relation.EntityRelationsQuery;
83 103 import org.thingsboard.server.common.data.relation.RelationTypeGroup;
  104 +import org.thingsboard.server.common.data.rule.DefaultRuleChainCreateRequest;
84 105 import org.thingsboard.server.common.data.rule.RuleChain;
  106 +import org.thingsboard.server.common.data.rule.RuleChainData;
85 107 import org.thingsboard.server.common.data.rule.RuleChainMetaData;
86 108 import org.thingsboard.server.common.data.security.DeviceCredentials;
87 109 import org.thingsboard.server.common.data.security.DeviceCredentialsType;
... ... @@ -325,6 +347,19 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
325 347 }
326 348 }
327 349
  350 + public Optional<AssetInfo> getAssetInfoById(AssetId assetId) {
  351 + try {
  352 + ResponseEntity<AssetInfo> asset = restTemplate.getForEntity(baseURL + "/api/asset/info/{assetId}", AssetInfo.class, assetId.getId());
  353 + return Optional.ofNullable(asset.getBody());
  354 + } catch (HttpClientErrorException exception) {
  355 + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
  356 + return Optional.empty();
  357 + } else {
  358 + throw exception;
  359 + }
  360 + }
  361 + }
  362 +
328 363 public Asset saveAsset(Asset asset) {
329 364 return restTemplate.postForEntity(baseURL + "/api/asset", asset, Asset.class).getBody();
330 365 }
... ... @@ -390,6 +425,20 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
390 425 return assets.getBody();
391 426 }
392 427
  428 + public PageData<AssetInfo> getTenantAssetInfos(PageLink pageLink, String assetType) {
  429 + Map<String, String> params = new HashMap<>();
  430 + params.put("type", assetType);
  431 + addPageLinkToParam(params, pageLink);
  432 +
  433 + ResponseEntity<PageData<AssetInfo>> assets = restTemplate.exchange(
  434 + baseURL + "/api/tenant/assetInfos?type={type}&" + getUrlParams(pageLink),
  435 + HttpMethod.GET, HttpEntity.EMPTY,
  436 + new ParameterizedTypeReference<PageData<AssetInfo>>() {
  437 + },
  438 + params);
  439 + return assets.getBody();
  440 + }
  441 +
393 442 public Optional<Asset> getTenantAsset(String assetName) {
394 443 try {
395 444 ResponseEntity<Asset> asset = restTemplate.getForEntity(baseURL + "/api/tenant/assets?assetName={assetName}", Asset.class, assetName);
... ... @@ -419,6 +468,22 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
419 468 return assets.getBody();
420 469 }
421 470
  471 + public PageData<AssetInfo> getCustomerAssetInfos(CustomerId customerId, PageLink pageLink, String assetType) {
  472 + Map<String, String> params = new HashMap<>();
  473 + params.put("customerId", customerId.getId().toString());
  474 + params.put("type", assetType);
  475 + addPageLinkToParam(params, pageLink);
  476 +
  477 + ResponseEntity<PageData<AssetInfo>> assets = restTemplate.exchange(
  478 + baseURL + "/api/customer/{customerId}/assetInfos?type={type}&" + getUrlParams(pageLink),
  479 + HttpMethod.GET,
  480 + HttpEntity.EMPTY,
  481 + new ParameterizedTypeReference<PageData<AssetInfo>>() {
  482 + },
  483 + params);
  484 + return assets.getBody();
  485 + }
  486 +
422 487 public List<Asset> getAssetsByIds(List<AssetId> assetIds) {
423 488 return restTemplate.exchange(
424 489 baseURL + "/api/assets?assetIds={assetIds}",
... ... @@ -593,11 +658,15 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
593 658 }
594 659
595 660 public Optional<JsonNode> activateUser(UserId userId, String password) {
  661 + return activateUser(userId, password, true);
  662 + }
  663 +
  664 + public Optional<JsonNode> activateUser(UserId userId, String password, boolean sendActivationMail) {
596 665 ObjectNode activateRequest = objectMapper.createObjectNode();
597 666 activateRequest.put("activateToken", getActivateToken(userId));
598 667 activateRequest.put("password", password);
599 668 try {
600   - ResponseEntity<JsonNode> jsonNode = restTemplate.postForEntity(baseURL + "/api/noauth/activate", activateRequest, JsonNode.class);
  669 + ResponseEntity<JsonNode> jsonNode = restTemplate.postForEntity(baseURL + "/api/noauth/activate?sendActivationMail={sendActivationMail}", activateRequest, JsonNode.class, sendActivationMail);
601 670 return Optional.ofNullable(jsonNode.getBody());
602 671 } catch (HttpClientErrorException exception) {
603 672 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -936,8 +1005,25 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
936 1005 }
937 1006 }
938 1007
  1008 + public Optional<DeviceInfo> getDeviceInfoById(DeviceId deviceId) {
  1009 + try {
  1010 + ResponseEntity<DeviceInfo> device = restTemplate.getForEntity(baseURL + "/api/device/info/{deviceId}", DeviceInfo.class, deviceId);
  1011 + return Optional.ofNullable(device.getBody());
  1012 + } catch (HttpClientErrorException exception) {
  1013 + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
  1014 + return Optional.empty();
  1015 + } else {
  1016 + throw exception;
  1017 + }
  1018 + }
  1019 + }
  1020 +
939 1021 public Device saveDevice(Device device) {
940   - return restTemplate.postForEntity(baseURL + "/api/device", device, Device.class).getBody();
  1022 + return saveDevice(device, null);
  1023 + }
  1024 +
  1025 + public Device saveDevice(Device device, String accessToken) {
  1026 + return restTemplate.postForEntity(baseURL + "/api/device?accessToken={accessToken}", device, Device.class, accessToken).getBody();
941 1027 }
942 1028
943 1029 public void deleteDevice(DeviceId deviceId) {
... ... @@ -1011,6 +1097,18 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1011 1097 }, params).getBody();
1012 1098 }
1013 1099
  1100 + public PageData<DeviceInfo> getTenantDeviceInfos(String type, DeviceProfileId deviceProfileId, PageLink pageLink) {
  1101 + Map<String, String> params = new HashMap<>();
  1102 + params.put("type", type);
  1103 + params.put("deviceProfileId", deviceProfileId != null ? deviceProfileId.toString() : null);
  1104 + addPageLinkToParam(params, pageLink);
  1105 + return restTemplate.exchange(
  1106 + baseURL + "/api/tenant/deviceInfos?type={type}&deviceProfileId={deviceProfileId}&" + getUrlParams(pageLink),
  1107 + HttpMethod.GET, HttpEntity.EMPTY,
  1108 + new ParameterizedTypeReference<PageData<DeviceInfo>>() {
  1109 + }, params).getBody();
  1110 + }
  1111 +
1014 1112 public Optional<Device> getTenantDevice(String deviceName) {
1015 1113 try {
1016 1114 ResponseEntity<Device> device = restTemplate.getForEntity(baseURL + "/api/tenant/devices?deviceName={deviceName}", Device.class, deviceName);
... ... @@ -1036,6 +1134,19 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1036 1134 }, params).getBody();
1037 1135 }
1038 1136
  1137 + public PageData<DeviceInfo> getCustomerDeviceInfos(CustomerId customerId, String deviceType, DeviceProfileId deviceProfileId, PageLink pageLink) {
  1138 + Map<String, String> params = new HashMap<>();
  1139 + params.put("customerId", customerId.toString());
  1140 + params.put("type", deviceType);
  1141 + params.put("deviceProfileId", deviceProfileId != null ? deviceProfileId.toString() : null);
  1142 + addPageLinkToParam(params, pageLink);
  1143 + return restTemplate.exchange(
  1144 + baseURL + "/api/customer/{customerId}/devices?type={type}&deviceProfileId={deviceProfileId}&" + getUrlParams(pageLink),
  1145 + HttpMethod.GET, HttpEntity.EMPTY,
  1146 + new ParameterizedTypeReference<PageData<DeviceInfo>>() {
  1147 + }, params).getBody();
  1148 + }
  1149 +
1039 1150 public List<Device> getDevicesByIds(List<DeviceId> deviceIds) {
1040 1151 return restTemplate.exchange(baseURL + "/api/devices?deviceIds={deviceIds}",
1041 1152 HttpMethod.GET,
... ... @@ -1074,6 +1185,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1074 1185 restTemplate.delete(baseURL + "/api/customer/device/{deviceName}/claim", deviceName);
1075 1186 }
1076 1187
  1188 + public Device assignDeviceToTenant(TenantId tenantId, DeviceId deviceId) {
  1189 + return restTemplate.postForEntity(
  1190 + baseURL + "/api/tenant/{tenantId}/device/{deviceId}",
  1191 + HttpEntity.EMPTY, Device.class, tenantId, deviceId).getBody();
  1192 + }
  1193 +
1077 1194 @Deprecated
1078 1195 public Device createDevice(String name, String type) {
1079 1196 Device device = new Device();
... ... @@ -1138,6 +1255,91 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1138 1255 customerId.toString(), deviceId.toString()).getBody();
1139 1256 }
1140 1257
  1258 + public Optional<DeviceProfile> getDeviceProfileById(DeviceProfileId deviceProfileId) {
  1259 + try {
  1260 + ResponseEntity<DeviceProfile> deviceProfile = restTemplate.getForEntity(baseURL + "/api/deviceProfile/{deviceProfileId}", DeviceProfile.class, deviceProfileId);
  1261 + return Optional.ofNullable(deviceProfile.getBody());
  1262 + } catch (HttpClientErrorException exception) {
  1263 + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
  1264 + return Optional.empty();
  1265 + } else {
  1266 + throw exception;
  1267 + }
  1268 + }
  1269 + }
  1270 +
  1271 + public Optional<DeviceProfileInfo> getDeviceProfileInfoById(DeviceProfileId deviceProfileId) {
  1272 + try {
  1273 + ResponseEntity<DeviceProfileInfo> deviceProfileInfo = restTemplate.getForEntity(baseURL + "/api/deviceProfileInfo/{deviceProfileId}", DeviceProfileInfo.class, deviceProfileId);
  1274 + return Optional.ofNullable(deviceProfileInfo.getBody());
  1275 + } catch (HttpClientErrorException exception) {
  1276 + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
  1277 + return Optional.empty();
  1278 + } else {
  1279 + throw exception;
  1280 + }
  1281 + }
  1282 + }
  1283 +
  1284 + public DeviceProfileInfo getDefaultDeviceProfileInfo() {
  1285 + return restTemplate.getForEntity(baseURL + "/api/deviceProfileInfo/default", DeviceProfileInfo.class).getBody();
  1286 + }
  1287 +
  1288 + public DeviceProfile saveDeviceProfile(DeviceProfile deviceProfile) {
  1289 + return restTemplate.postForEntity(baseURL + "/api/deviceProfile", deviceProfile, DeviceProfile.class).getBody();
  1290 + }
  1291 +
  1292 + public void deleteDeviceProfile(DeviceProfileId deviceProfileId) {
  1293 + restTemplate.delete(baseURL + "/api/deviceProfile/{deviceProfileId}", deviceProfileId);
  1294 + }
  1295 +
  1296 + public DeviceProfile setDefaultDeviceProfile(DeviceProfileId deviceProfileId) {
  1297 + return restTemplate.postForEntity(
  1298 + baseURL + "/api/deviceProfile/{deviceProfileId}/default",
  1299 + HttpEntity.EMPTY, DeviceProfile.class, deviceProfileId).getBody();
  1300 + }
  1301 +
  1302 + public PageData<DeviceProfile> getTenantDevices(PageLink pageLink) {
  1303 + Map<String, String> params = new HashMap<>();
  1304 + addPageLinkToParam(params, pageLink);
  1305 + return restTemplate.exchange(
  1306 + baseURL + "/api/deviceProfiles?" + getUrlParams(pageLink),
  1307 + HttpMethod.GET, HttpEntity.EMPTY,
  1308 + new ParameterizedTypeReference<PageData<DeviceProfile>>() {
  1309 + }, params).getBody();
  1310 + }
  1311 +
  1312 + public PageData<DeviceProfileInfo> getDeviceProfileInfos(PageLink pageLink, DeviceTransportType deviceTransportType) {
  1313 + Map<String, String> params = new HashMap<>();
  1314 + params.put("deviceTransportType", deviceTransportType != null ? deviceTransportType.name() : null);
  1315 + addPageLinkToParam(params, pageLink);
  1316 + return restTemplate.exchange(
  1317 + baseURL + "/api/deviceProfileInfos?deviceTransportType={deviceTransportType}&" + getUrlParams(pageLink),
  1318 + HttpMethod.GET, HttpEntity.EMPTY,
  1319 + new ParameterizedTypeReference<PageData<DeviceProfileInfo>>() {
  1320 + }, params).getBody();
  1321 + }
  1322 +
  1323 + public Long countEntitiesByQuery(EntityCountQuery query) {
  1324 + return restTemplate.postForObject(baseURL + "/api/entitiesQuery/count", query, Long.class);
  1325 + }
  1326 +
  1327 + public PageData<EntityData> findEntityDataByQuery(EntityDataQuery query) {
  1328 + return restTemplate.exchange(
  1329 + baseURL + "/api/entitiesQuery/find",
  1330 + HttpMethod.POST, new HttpEntity<>(query),
  1331 + new ParameterizedTypeReference<PageData<EntityData>>() {
  1332 + }).getBody();
  1333 + }
  1334 +
  1335 + public PageData<AlarmData> findAlarmDataByQuery(AlarmDataQuery query) {
  1336 + return restTemplate.exchange(
  1337 + baseURL + "/api/alarmsQuery/find",
  1338 + HttpMethod.POST, new HttpEntity<>(query),
  1339 + new ParameterizedTypeReference<PageData<AlarmData>>() {
  1340 + }).getBody();
  1341 + }
  1342 +
1141 1343 public void saveRelation(EntityRelation relation) {
1142 1344 restTemplate.postForLocation(baseURL + "/api/relation", relation);
1143 1345 }
... ... @@ -1313,6 +1515,19 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1313 1515 }
1314 1516 }
1315 1517
  1518 + public Optional<EntityViewInfo> getEntityViewInfoById(EntityViewId entityViewId) {
  1519 + try {
  1520 + ResponseEntity<EntityViewInfo> entityView = restTemplate.getForEntity(baseURL + "/api/entityView/info/{entityViewId}", EntityViewInfo.class, entityViewId);
  1521 + return Optional.ofNullable(entityView.getBody());
  1522 + } catch (HttpClientErrorException exception) {
  1523 + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
  1524 + return Optional.empty();
  1525 + } else {
  1526 + throw exception;
  1527 + }
  1528 + }
  1529 + }
  1530 +
1316 1531 public EntityView saveEntityView(EntityView entityView) {
1317 1532 return restTemplate.postForEntity(baseURL + "/api/entityView", entityView, EntityView.class).getBody();
1318 1533 }
... ... @@ -1373,6 +1588,19 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1373 1588 }, params).getBody();
1374 1589 }
1375 1590
  1591 + public PageData<EntityViewInfo> getCustomerEntityViewInfos(CustomerId customerId, String entityViewType, PageLink pageLink) {
  1592 + Map<String, String> params = new HashMap<>();
  1593 + params.put("customerId", customerId.toString());
  1594 + params.put("type", entityViewType);
  1595 + addPageLinkToParam(params, pageLink);
  1596 + return restTemplate.exchange(
  1597 + baseURL + "/api/customer/{customerId}/entityViewInfos?type={type}&" + getUrlParams(pageLink),
  1598 + HttpMethod.GET,
  1599 + HttpEntity.EMPTY,
  1600 + new ParameterizedTypeReference<PageData<EntityViewInfo>>() {
  1601 + }, params).getBody();
  1602 + }
  1603 +
1376 1604 public PageData<EntityView> getTenantEntityViews(String entityViewType, PageLink pageLink) {
1377 1605 Map<String, String> params = new HashMap<>();
1378 1606 params.put("type", entityViewType);
... ... @@ -1385,6 +1613,18 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1385 1613 }, params).getBody();
1386 1614 }
1387 1615
  1616 + public PageData<EntityViewInfo> getTenantEntityViewInfos(String entityViewType, PageLink pageLink) {
  1617 + Map<String, String> params = new HashMap<>();
  1618 + params.put("type", entityViewType);
  1619 + addPageLinkToParam(params, pageLink);
  1620 + return restTemplate.exchange(
  1621 + baseURL + "/api/tenant/entityViewInfos?type={type}&" + getUrlParams(pageLink),
  1622 + HttpMethod.GET,
  1623 + HttpEntity.EMPTY,
  1624 + new ParameterizedTypeReference<PageData<EntityViewInfo>>() {
  1625 + }, params).getBody();
  1626 + }
  1627 +
1388 1628 public List<EntityView> findByQuery(EntityViewSearchQuery query) {
1389 1629 return restTemplate.exchange(baseURL + "/api/entityViews", HttpMethod.POST, new HttpEntity<>(query), new ParameterizedTypeReference<List<EntityView>>() {
1390 1630 }).getBody();
... ... @@ -1437,8 +1677,41 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1437 1677 HttpMethod.GET,
1438 1678 HttpEntity.EMPTY,
1439 1679 new ParameterizedTypeReference<PageData<Event>>() {
1440   - },
1441   - params).getBody();
  1680 + }, params).getBody();
  1681 + }
  1682 +
  1683 + public OAuth2ClientRegistrationTemplate saveClientRegistrationTemplate(OAuth2ClientRegistrationTemplate clientRegistrationTemplate) {
  1684 + return restTemplate.postForEntity(baseURL + "/api/oauth2/config/template", clientRegistrationTemplate, OAuth2ClientRegistrationTemplate.class).getBody();
  1685 + }
  1686 +
  1687 + public void deleteClientRegistrationTemplate(OAuth2ClientRegistrationTemplateId oAuth2ClientRegistrationTemplateId) {
  1688 + restTemplate.delete(baseURL + "/api/oauth2/config/template/{clientRegistrationTemplateId}", oAuth2ClientRegistrationTemplateId);
  1689 + }
  1690 +
  1691 + public List<OAuth2ClientRegistrationTemplate> getClientRegistrationTemplates() {
  1692 + return restTemplate.exchange(
  1693 + baseURL + "/api/oauth2/config/template",
  1694 + HttpMethod.GET,
  1695 + HttpEntity.EMPTY,
  1696 + new ParameterizedTypeReference<List<OAuth2ClientRegistrationTemplate>>() {
  1697 + }).getBody();
  1698 + }
  1699 +
  1700 + public List<OAuth2ClientInfo> getOAuth2Clients() {
  1701 + return restTemplate.exchange(
  1702 + baseURL + "/api/noauth/oauth2Clients",
  1703 + HttpMethod.POST,
  1704 + HttpEntity.EMPTY,
  1705 + new ParameterizedTypeReference<List<OAuth2ClientInfo>>() {
  1706 + }).getBody();
  1707 + }
  1708 +
  1709 + public OAuth2ClientsParams getCurrentOAuth2Params() {
  1710 + return restTemplate.getForEntity(baseURL + "/api/oauth2/config", OAuth2ClientsParams.class).getBody();
  1711 + }
  1712 +
  1713 + public OAuth2ClientsParams saveOAuth2Params(OAuth2ClientsParams oauth2Params) {
  1714 + return restTemplate.postForEntity(baseURL + "/api/oauth2/config", oauth2Params, OAuth2ClientsParams.class).getBody();
1442 1715 }
1443 1716
1444 1717 public void handleOneWayDeviceRPCRequest(DeviceId deviceId, JsonNode requestBody) {
... ... @@ -1485,6 +1758,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1485 1758 return restTemplate.postForEntity(baseURL + "/api/ruleChain", ruleChain, RuleChain.class).getBody();
1486 1759 }
1487 1760
  1761 + public RuleChain saveRuleChain(DefaultRuleChainCreateRequest request) {
  1762 + return restTemplate.postForEntity(baseURL + "/api/ruleChain/device/default", request, RuleChain.class).getBody();
  1763 + }
  1764 +
1488 1765 public Optional<RuleChain> setRootRuleChain(RuleChainId ruleChainId) {
1489 1766 try {
1490 1767 ResponseEntity<RuleChain> ruleChain = restTemplate.postForEntity(baseURL + "/api/ruleChain/{ruleChainId}/root", null, RuleChain.class, ruleChainId.getId());
... ... @@ -1544,6 +1821,14 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1544 1821 }
1545 1822 }
1546 1823
  1824 + public RuleChainData exportRuleChains(int limit) {
  1825 + return restTemplate.getForEntity(baseURL + "/api/ruleChains/export?limit=" + limit, RuleChainData.class).getBody();
  1826 + }
  1827 +
  1828 + public void importRuleChains(RuleChainData ruleChainData, boolean overwrite) {
  1829 + restTemplate.postForLocation(baseURL + "/api/ruleChains/import?overwrite=" + overwrite, ruleChainData);
  1830 + }
  1831 +
1547 1832 public List<String> getAttributeKeys(EntityId entityId) {
1548 1833 return restTemplate.exchange(
1549 1834 baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/keys/attributes",
... ... @@ -1805,6 +2090,19 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1805 2090 }
1806 2091 }
1807 2092
  2093 + public Optional<TenantInfo> getTenantInfoById(TenantId tenantId) {
  2094 + try {
  2095 + ResponseEntity<TenantInfo> tenant = restTemplate.getForEntity(baseURL + "/api/tenant/info/{tenantId}", TenantInfo.class, tenantId);
  2096 + return Optional.ofNullable(tenant.getBody());
  2097 + } catch (HttpClientErrorException exception) {
  2098 + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
  2099 + return Optional.empty();
  2100 + } else {
  2101 + throw exception;
  2102 + }
  2103 + }
  2104 + }
  2105 +
1808 2106 public Tenant saveTenant(Tenant tenant) {
1809 2107 return restTemplate.postForEntity(baseURL + "/api/tenant", tenant, Tenant.class).getBody();
1810 2108 }
... ... @@ -1824,6 +2122,81 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1824 2122 }, params).getBody();
1825 2123 }
1826 2124
  2125 + public PageData<TenantInfo> getTenantInfos(PageLink pageLink) {
  2126 + Map<String, String> params = new HashMap<>();
  2127 + addPageLinkToParam(params, pageLink);
  2128 + return restTemplate.exchange(
  2129 + baseURL + "/api/tenantInfos?" + getUrlParams(pageLink),
  2130 + HttpMethod.GET,
  2131 + HttpEntity.EMPTY,
  2132 + new ParameterizedTypeReference<PageData<TenantInfo>>() {
  2133 + }, params).getBody();
  2134 + }
  2135 +
  2136 + public Optional<TenantProfile> getTenantProfileById(TenantProfileId tenantProfileId) {
  2137 + try {
  2138 + ResponseEntity<TenantProfile> tenantProfile = restTemplate.getForEntity(baseURL + "/api/tenantProfile/{tenantProfileId}", TenantProfile.class, tenantProfileId);
  2139 + return Optional.ofNullable(tenantProfile.getBody());
  2140 + } catch (HttpClientErrorException exception) {
  2141 + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
  2142 + return Optional.empty();
  2143 + } else {
  2144 + throw exception;
  2145 + }
  2146 + }
  2147 + }
  2148 +
  2149 + public Optional<EntityInfo> getTenantProfileInfoById(TenantProfileId tenantProfileId) {
  2150 + try {
  2151 + ResponseEntity<EntityInfo> entityInfo = restTemplate.getForEntity(baseURL + "/api/tenantProfileInfo/{tenantProfileId}", EntityInfo.class, tenantProfileId);
  2152 + return Optional.ofNullable(entityInfo.getBody());
  2153 + } catch (HttpClientErrorException exception) {
  2154 + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
  2155 + return Optional.empty();
  2156 + } else {
  2157 + throw exception;
  2158 + }
  2159 + }
  2160 + }
  2161 +
  2162 + public EntityInfo getDefaultTenantProfileInfo() {
  2163 + return restTemplate.getForEntity(baseURL + "/api/tenantProfileInfo/default", EntityInfo.class).getBody();
  2164 + }
  2165 +
  2166 + public TenantProfile saveTenantProfile(TenantProfile tenantProfile) {
  2167 + return restTemplate.postForEntity(baseURL + "/api/tenantProfile", tenantProfile, TenantProfile.class).getBody();
  2168 + }
  2169 +
  2170 + public void deleteTenantProfile(TenantProfileId tenantProfileId) {
  2171 + restTemplate.delete(baseURL + "/api/tenantProfile/{tenantProfileId}", tenantProfileId);
  2172 + }
  2173 +
  2174 + public TenantProfile setDefaultTenantProfile(TenantProfileId tenantProfileId) {
  2175 + return restTemplate.exchange(baseURL + "/api/tenantProfile/{tenantProfileId}/default", HttpMethod.POST, HttpEntity.EMPTY, TenantProfile.class, tenantProfileId).getBody();
  2176 + }
  2177 +
  2178 + public PageData<TenantProfile> getTenantProfiles(PageLink pageLink) {
  2179 + Map<String, String> params = new HashMap<>();
  2180 + addPageLinkToParam(params, pageLink);
  2181 + return restTemplate.exchange(
  2182 + baseURL + "/api/tenantProfiles" + getUrlParams(pageLink),
  2183 + HttpMethod.GET,
  2184 + HttpEntity.EMPTY,
  2185 + new ParameterizedTypeReference<PageData<TenantProfile>>() {
  2186 + }, params).getBody();
  2187 + }
  2188 +
  2189 + public PageData<EntityInfo> getTenantProfileInfos(PageLink pageLink) {
  2190 + Map<String, String> params = new HashMap<>();
  2191 + addPageLinkToParam(params, pageLink);
  2192 + return restTemplate.exchange(
  2193 + baseURL + "/api/tenantProfileInfos" + getUrlParams(pageLink),
  2194 + HttpMethod.GET,
  2195 + HttpEntity.EMPTY,
  2196 + new ParameterizedTypeReference<PageData<EntityInfo>>() {
  2197 + }, params).getBody();
  2198 + }
  2199 +
1827 2200 public Optional<User> getUserById(UserId userId) {
1828 2201 try {
1829 2202 ResponseEntity<User> user = restTemplate.getForEntity(baseURL + "/api/user/{userId}", User.class, userId.getId());
... ... @@ -1870,6 +2243,17 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1870 2243 restTemplate.delete(baseURL + "/api/user/{userId}", userId.getId());
1871 2244 }
1872 2245
  2246 + public PageData<User> getUsers(PageLink pageLink) {
  2247 + Map<String, String> params = new HashMap<>();
  2248 + addPageLinkToParam(params, pageLink);
  2249 + return restTemplate.exchange(
  2250 + baseURL + "/api/users" + getUrlParams(pageLink),
  2251 + HttpMethod.GET,
  2252 + HttpEntity.EMPTY,
  2253 + new ParameterizedTypeReference<PageData<User>>() {
  2254 + }, params).getBody();
  2255 + }
  2256 +
1873 2257 public PageData<User> getTenantAdmins(TenantId tenantId, PageLink pageLink) {
1874 2258 Map<String, String> params = new HashMap<>();
1875 2259 params.put("tenantId", tenantId.getId().toString());
... ...