Commit a670b77251f09e6d4b9c9aa197cf0e8a64ac916a

Authored by YevhenBondarenko
Committed by Andrew Shvayka
1 parent 4c3d6a3c

refactored and improvement Rest Client

... ... @@ -45,10 +45,14 @@ import org.thingsboard.server.common.data.Tenant;
45 45 import org.thingsboard.server.common.data.UpdateMessage;
46 46 import org.thingsboard.server.common.data.User;
47 47 import org.thingsboard.server.common.data.alarm.Alarm;
  48 +import org.thingsboard.server.common.data.alarm.AlarmId;
48 49 import org.thingsboard.server.common.data.alarm.AlarmInfo;
  50 +import org.thingsboard.server.common.data.alarm.AlarmSearchStatus;
49 51 import org.thingsboard.server.common.data.alarm.AlarmSeverity;
  52 +import org.thingsboard.server.common.data.alarm.AlarmStatus;
50 53 import org.thingsboard.server.common.data.asset.Asset;
51 54 import org.thingsboard.server.common.data.asset.AssetSearchQuery;
  55 +import org.thingsboard.server.common.data.audit.ActionType;
52 56 import org.thingsboard.server.common.data.audit.AuditLog;
53 57 import org.thingsboard.server.common.data.device.DeviceSearchQuery;
54 58 import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery;
... ... @@ -57,6 +61,14 @@ import org.thingsboard.server.common.data.id.CustomerId;
57 61 import org.thingsboard.server.common.data.id.DashboardId;
58 62 import org.thingsboard.server.common.data.id.DeviceId;
59 63 import org.thingsboard.server.common.data.id.EntityId;
  64 +import org.thingsboard.server.common.data.id.EntityViewId;
  65 +import org.thingsboard.server.common.data.id.RuleChainId;
  66 +import org.thingsboard.server.common.data.id.RuleNodeId;
  67 +import org.thingsboard.server.common.data.id.TenantId;
  68 +import org.thingsboard.server.common.data.id.UserId;
  69 +import org.thingsboard.server.common.data.id.WidgetTypeId;
  70 +import org.thingsboard.server.common.data.id.WidgetsBundleId;
  71 +import org.thingsboard.server.common.data.kv.Aggregation;
60 72 import org.thingsboard.server.common.data.kv.AttributeKvEntry;
61 73 import org.thingsboard.server.common.data.kv.TsKvEntry;
62 74 import org.thingsboard.server.common.data.page.TextPageData;
... ... @@ -64,9 +76,11 @@ import org.thingsboard.server.common.data.page.TextPageLink;
64 76 import org.thingsboard.server.common.data.page.TimePageData;
65 77 import org.thingsboard.server.common.data.page.TimePageLink;
66 78 import org.thingsboard.server.common.data.plugin.ComponentDescriptor;
  79 +import org.thingsboard.server.common.data.plugin.ComponentType;
67 80 import org.thingsboard.server.common.data.relation.EntityRelation;
68 81 import org.thingsboard.server.common.data.relation.EntityRelationInfo;
69 82 import org.thingsboard.server.common.data.relation.EntityRelationsQuery;
  83 +import org.thingsboard.server.common.data.relation.RelationTypeGroup;
70 84 import org.thingsboard.server.common.data.rule.RuleChain;
71 85 import org.thingsboard.server.common.data.rule.RuleChainMetaData;
72 86 import org.thingsboard.server.common.data.security.DeviceCredentials;
... ... @@ -87,6 +101,7 @@ import java.util.Optional;
87 101 import java.util.concurrent.ExecutorService;
88 102 import java.util.concurrent.Executors;
89 103 import java.util.concurrent.Future;
  104 +import java.util.stream.Collectors;
90 105
91 106 import static org.springframework.util.StringUtils.isEmpty;
92 107
... ... @@ -106,8 +121,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
106 121 protected static final String ACTIVATE_TOKEN_REGEX = "/api/noauth/activate?activateToken=";
107 122
108 123 public RestClient(String baseURL) {
109   - this.restTemplate = new RestTemplate();
110   - this.baseURL = baseURL;
  124 + this(new RestTemplate(), baseURL);
111 125 }
112 126
113 127 public RestClient(RestTemplate restTemplate, String baseURL) {
... ... @@ -279,18 +293,6 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
279 293 return restTemplate.postForEntity(baseURL + "/api/alarm", alarm, Alarm.class).getBody();
280 294 }
281 295
282   - public void deleteCustomer(CustomerId customerId) {
283   - restTemplate.delete(baseURL + "/api/customer/{customerId}", customerId);
284   - }
285   -
286   - public void deleteDevice(DeviceId deviceId) {
287   - restTemplate.delete(baseURL + "/api/device/{deviceId}", deviceId);
288   - }
289   -
290   - public void deleteAsset(AssetId assetId) {
291   - restTemplate.delete(baseURL + "/api/asset/{assetId}", assetId);
292   - }
293   -
294 296 public Device assignDevice(CustomerId customerId, DeviceId deviceId) {
295 297 return restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/device/{deviceId}", null, Device.class,
296 298 customerId.toString(), deviceId.toString()).getBody();
... ... @@ -313,10 +315,6 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
313 315 return restTemplate.postForEntity(baseURL + "/api/dashboard", dashboard, Dashboard.class).getBody();
314 316 }
315 317
316   - public void deleteDashboard(DashboardId dashboardId) {
317   - restTemplate.delete(baseURL + "/api/dashboard/{dashboardId}", dashboardId);
318   - }
319   -
320 318 public List<DashboardInfo> findTenantDashboards() {
321 319 try {
322 320 ResponseEntity<TextPageData<DashboardInfo>> dashboards =
... ... @@ -391,9 +389,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
391 389 }
392 390 }
393 391
394   - public Optional<Alarm> getAlarmById(String alarmId) {
  392 + public Optional<Alarm> getAlarmById(AlarmId alarmId) {
395 393 try {
396   - ResponseEntity<Alarm> alarm = restTemplate.getForEntity(baseURL + "/api/alarm/{alarmId}", Alarm.class, alarmId);
  394 + ResponseEntity<Alarm> alarm = restTemplate.getForEntity(baseURL + "/api/alarm/{alarmId}", Alarm.class, alarmId.getId());
397 395 return Optional.ofNullable(alarm.getBody());
398 396 } catch (HttpClientErrorException exception) {
399 397 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -404,9 +402,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
404 402 }
405 403 }
406 404
407   - public Optional<AlarmInfo> getAlarmInfoById(String alarmId) {
  405 + public Optional<AlarmInfo> getAlarmInfoById(AlarmId alarmId) {
408 406 try {
409   - ResponseEntity<AlarmInfo> alarmInfo = restTemplate.getForEntity(baseURL + "/api/alarm/info/{alarmId}", AlarmInfo.class, alarmId);
  407 + ResponseEntity<AlarmInfo> alarmInfo = restTemplate.getForEntity(baseURL + "/api/alarm/info/{alarmId}", AlarmInfo.class, alarmId.getId());
410 408 return Optional.ofNullable(alarmInfo.getBody());
411 409 } catch (HttpClientErrorException exception) {
412 410 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -421,70 +419,42 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
421 419 return restTemplate.postForEntity(baseURL + "/api/alarm", alarm, Alarm.class).getBody();
422 420 }
423 421
424   - public void deleteAlarm(String alarmId) {
425   - restTemplate.delete(baseURL + "/api/alarm/{alarmId}", alarmId);
  422 + public void deleteAlarm(AlarmId alarmId) {
  423 + restTemplate.delete(baseURL + "/api/alarm/{alarmId}", alarmId.getId());
426 424 }
427 425
428   - public void ackAlarm(String alarmId) {
429   - restTemplate.postForLocation(baseURL + "/api/alarm/{alarmId}/ack", null, alarmId);
  426 + public void ackAlarm(AlarmId alarmId) {
  427 + restTemplate.postForLocation(baseURL + "/api/alarm/{alarmId}/ack", null, alarmId.getId());
430 428 }
431 429
432   - public void clearAlarm(String alarmId) {
433   - restTemplate.postForLocation(baseURL + "/api/alarm/{alarmId}/clear", null, alarmId);
  430 + public void clearAlarm(AlarmId alarmId) {
  431 + restTemplate.postForLocation(baseURL + "/api/alarm/{alarmId}/clear", null, alarmId.getId());
434 432 }
435 433
436   - public TimePageData<AlarmInfo> getAlarms(EntityId entityId, String searchStatus, String status, TimePageLink pageLink, Boolean fetchOriginator) {
  434 + public TimePageData<AlarmInfo> getAlarms(EntityId entityId, AlarmSearchStatus searchStatus, AlarmStatus status, TimePageLink pageLink, Boolean fetchOriginator) {
437 435 Map<String, String> params = new HashMap<>();
438 436 params.put("entityType", entityId.getEntityType().name());
439 437 params.put("entityId", entityId.getId().toString());
440   - params.put("searchStatus", searchStatus);
441   - params.put("status", status);
  438 + params.put("searchStatus", searchStatus.name());
  439 + params.put("status", status.name());
442 440 params.put("fetchOriginator", String.valueOf(fetchOriginator));
443 441 addPageLinkToParam(params, pageLink);
444 442
445   - String urlParams = getUrlParams(pageLink);
446 443 return restTemplate.exchange(
447 444 baseURL + "/api/alarm/{entityType}/{entityId}?searchStatus={searchStatus}&status={status}&fetchOriginator={fetchOriginator}&" + getUrlParams(pageLink),
448 445 HttpMethod.GET,
449 446 HttpEntity.EMPTY,
450 447 new ParameterizedTypeReference<TimePageData<AlarmInfo>>() {
451   - }, params).getBody();
452   - }
453   -
454   - private String getUrlParams(TimePageLink pageLink) {
455   - String urlParams = "limit={limit}&ascOrder={ascOrder}";
456   - if (pageLink.getStartTime() != null) {
457   - urlParams += "&startTime={startTime}";
458   - }
459   - if (pageLink.getEndTime() != null) {
460   - urlParams += "&endTime={endTime}";
461   - }
462   - if (pageLink.getIdOffset() != null) {
463   - urlParams += "&offset={offset}";
464   - }
465   - return urlParams;
466   - }
467   -
468   - private String getUrlParams(TextPageLink pageLink) {
469   - String urlParams = "limit={limit}";
470   - if (!isEmpty(pageLink.getTextSearch())) {
471   - urlParams += "&textSearch={textSearch}";
472   - }
473   - if (!isEmpty(pageLink.getIdOffset())) {
474   - urlParams += "&idOffset={idOffset}";
475   - }
476   - if (!isEmpty(pageLink.getTextOffset())) {
477   - urlParams += "&textOffset={textOffset}";
478   - }
479   - return urlParams;
  448 + },
  449 + params).getBody();
480 450 }
481 451
482   - public Optional<AlarmSeverity> getHighestAlarmSeverity(EntityId entityId, String searchStatus, String status) {
  452 + public Optional<AlarmSeverity> getHighestAlarmSeverity(EntityId entityId, AlarmSearchStatus searchStatus, AlarmStatus status) {
483 453 Map<String, String> params = new HashMap<>();
484 454 params.put("entityType", entityId.getEntityType().name());
485 455 params.put("entityId", entityId.getId().toString());
486   - params.put("searchStatus", searchStatus);
487   - params.put("status", status);
  456 + params.put("searchStatus", searchStatus.name());
  457 + params.put("status", status.name());
488 458 try {
489 459 ResponseEntity<AlarmSeverity> alarmSeverity = restTemplate.getForEntity(baseURL + "/api/alarm/highestSeverity/{entityType}/{entityId}?searchStatus={searchStatus}&status={status}", AlarmSeverity.class, params);
490 460 return Optional.ofNullable(alarmSeverity.getBody());
... ... @@ -497,9 +467,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
497 467 }
498 468 }
499 469
500   - public Optional<Asset> getAssetById(String assetId) {
  470 + public Optional<Asset> getAssetById(AssetId assetId) {
501 471 try {
502   - ResponseEntity<Asset> asset = restTemplate.getForEntity(baseURL + "/api/asset/{assetId}", Asset.class, assetId);
  472 + ResponseEntity<Asset> asset = restTemplate.getForEntity(baseURL + "/api/asset/{assetId}", Asset.class, assetId.getId());
503 473 return Optional.ofNullable(asset.getBody());
504 474 } catch (HttpClientErrorException exception) {
505 475 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -514,15 +484,14 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
514 484 return restTemplate.postForEntity(baseURL + "/api/asset", asset, Asset.class).getBody();
515 485 }
516 486
517   - public void deleteAsset(String assetId) {
518   - restTemplate.delete(baseURL + "/api/asset/{assetId}", assetId);
  487 + public void deleteAsset(AssetId assetId) {
  488 + restTemplate.delete(baseURL + "/api/asset/{assetId}", assetId.getId());
519 489 }
520 490
521   - public Optional<Asset> assignAssetToCustomer(String customerId,
522   - String assetId) {
  491 + public Optional<Asset> assignAssetToCustomer(CustomerId customerId, AssetId assetId) {
523 492 Map<String, String> params = new HashMap<>();
524   - params.put("customerId", customerId);
525   - params.put("assetId", assetId);
  493 + params.put("customerId", customerId.getId().toString());
  494 + params.put("assetId", assetId.getId().toString());
526 495
527 496 try {
528 497 ResponseEntity<Asset> asset = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/asset/{assetId}", null, Asset.class, params);
... ... @@ -536,9 +505,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
536 505 }
537 506 }
538 507
539   - public Optional<Asset> unassignAssetFromCustomer(String assetId) {
  508 + public Optional<Asset> unassignAssetFromCustomer(AssetId assetId) {
540 509 try {
541   - ResponseEntity<Asset> asset = restTemplate.exchange(baseURL + "/api/customer/asset/{assetId}", HttpMethod.DELETE, HttpEntity.EMPTY, Asset.class, assetId);
  510 + ResponseEntity<Asset> asset = restTemplate.exchange(baseURL + "/api/customer/asset/{assetId}", HttpMethod.DELETE, HttpEntity.EMPTY, Asset.class, assetId.getId());
542 511 return Optional.ofNullable(asset.getBody());
543 512 } catch (HttpClientErrorException exception) {
544 513 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -549,9 +518,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
549 518 }
550 519 }
551 520
552   - public Optional<Asset> assignAssetToPublicCustomer(String assetId) {
  521 + public Optional<Asset> assignAssetToPublicCustomer(AssetId assetId) {
553 522 try {
554   - ResponseEntity<Asset> asset = restTemplate.postForEntity(baseURL + "/api/customer/public/asset/{assetId}", null, Asset.class, assetId);
  523 + ResponseEntity<Asset> asset = restTemplate.postForEntity(baseURL + "/api/customer/public/asset/{assetId}", null, Asset.class, assetId.getId());
555 524 return Optional.ofNullable(asset.getBody());
556 525 } catch (HttpClientErrorException exception) {
557 526 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -562,9 +531,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
562 531 }
563 532 }
564 533
565   - public TextPageData<Asset> getTenantAssets(TextPageLink pageLink, String type) {
  534 + public TextPageData<Asset> getTenantAssets(TextPageLink pageLink, String assetType) {
566 535 Map<String, String> params = new HashMap<>();
567   - params.put("type", type);
  536 + params.put("type", assetType);
568 537 addPageLinkToParam(params, pageLink);
569 538
570 539 ResponseEntity<TextPageData<Asset>> assets = restTemplate.exchange(
... ... @@ -589,10 +558,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
589 558 }
590 559 }
591 560
592   - public TextPageData<Asset> getCustomerAssets(String customerId, TextPageLink pageLink, String type) {
  561 + public TextPageData<Asset> getCustomerAssets(CustomerId customerId, TextPageLink pageLink, String assetType) {
593 562 Map<String, String> params = new HashMap<>();
594   - params.put("customerId", customerId);
595   - params.put("type", type);
  563 + params.put("customerId", customerId.getId().toString());
  564 + params.put("type", assetType);
596 565 addPageLinkToParam(params, pageLink);
597 566
598 567 ResponseEntity<TextPageData<Asset>> assets = restTemplate.exchange(
... ... @@ -605,14 +574,15 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
605 574 return assets.getBody();
606 575 }
607 576
608   - public List<Asset> getAssetsByIds(List<String> assetIds) {
  577 + public List<Asset> getAssetsByIds(List<AssetId> assetIds) {
609 578 return restTemplate.exchange(
610 579 baseURL + "/api/assets?assetIds={assetIds}",
611 580 HttpMethod.GET,
612 581 HttpEntity.EMPTY,
613 582 new ParameterizedTypeReference<List<Asset>>() {
614 583 },
615   - listToString(assetIds)).getBody();
  584 + listIdsToString(assetIds))
  585 + .getBody();
616 586 }
617 587
618 588 public List<Asset> findByQuery(AssetSearchQuery query) {
... ... @@ -633,10 +603,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
633 603 }).getBody();
634 604 }
635 605
636   - public TimePageData<AuditLog> getAuditLogsByCustomerId(String customerId, TimePageLink pageLink, String actionTypes) {
  606 + public TimePageData<AuditLog> getAuditLogsByCustomerId(CustomerId customerId, TimePageLink pageLink, List<ActionType> actionTypes) {
637 607 Map<String, String> params = new HashMap<>();
638   - params.put("customerId", customerId);
639   - params.put("actionTypes", actionTypes);
  608 + params.put("customerId", customerId.getId().toString());
  609 + params.put("actionTypes", listEnumToString(actionTypes));
640 610 addPageLinkToParam(params, pageLink);
641 611
642 612 ResponseEntity<TimePageData<AuditLog>> auditLog = restTemplate.exchange(
... ... @@ -649,10 +619,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
649 619 return auditLog.getBody();
650 620 }
651 621
652   - public TimePageData<AuditLog> getAuditLogsByUserId(String userId, TimePageLink pageLink, String actionTypes) {
  622 + public TimePageData<AuditLog> getAuditLogsByUserId(UserId userId, TimePageLink pageLink, List<ActionType> actionTypes) {
653 623 Map<String, String> params = new HashMap<>();
654   - params.put("userId", userId);
655   - params.put("actionTypes", actionTypes);
  624 + params.put("userId", userId.getId().toString());
  625 + params.put("actionTypes", listEnumToString(actionTypes));
656 626 addPageLinkToParam(params, pageLink);
657 627
658 628 ResponseEntity<TimePageData<AuditLog>> auditLog = restTemplate.exchange(
... ... @@ -665,11 +635,11 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
665 635 return auditLog.getBody();
666 636 }
667 637
668   - public TimePageData<AuditLog> getAuditLogsByEntityId(EntityId entityId, String actionTypes, TimePageLink pageLink) {
  638 + public TimePageData<AuditLog> getAuditLogsByEntityId(EntityId entityId, List<ActionType> actionTypes, TimePageLink pageLink) {
669 639 Map<String, String> params = new HashMap<>();
670 640 params.put("entityType", entityId.getEntityType().name());
671 641 params.put("entityId", entityId.getId().toString());
672   - params.put("actionTypes", actionTypes);
  642 + params.put("actionTypes", listEnumToString(actionTypes));
673 643 addPageLinkToParam(params, pageLink);
674 644
675 645 ResponseEntity<TimePageData<AuditLog>> auditLog = restTemplate.exchange(
... ... @@ -682,9 +652,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
682 652 return auditLog.getBody();
683 653 }
684 654
685   - public TimePageData<AuditLog> getAuditLogs(TimePageLink pageLink, String actionTypes) {
  655 + public TimePageData<AuditLog> getAuditLogs(TimePageLink pageLink, List<ActionType> actionTypes) {
686 656 Map<String, String> params = new HashMap<>();
687   - params.put("actionTypes", actionTypes);
  657 + params.put("actionTypes", listEnumToString(actionTypes));
688 658 addPageLinkToParam(params, pageLink);
689 659
690 660 ResponseEntity<TimePageData<AuditLog>> auditLog = restTemplate.exchange(
... ... @@ -697,7 +667,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
697 667 return auditLog.getBody();
698 668 }
699 669
700   - public String getActivateToken(String userId) {
  670 + public String getActivateToken(UserId userId) {
701 671 String activationLink = getActivationLink(userId);
702 672 return StringUtils.delete(activationLink, baseURL + ACTIVATE_TOKEN_REGEX);
703 673 }
... ... @@ -731,7 +701,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
731 701 }
732 702 }
733 703
734   - public ResponseEntity<String> checkActivateToken(String userId) {
  704 + public ResponseEntity<String> checkActivateToken(UserId userId) {
735 705 String activateToken = getActivateToken(userId);
736 706 return restTemplate.getForEntity(baseURL + "/api/noauth/activate?activateToken={activateToken}", String.class, activateToken);
737 707 }
... ... @@ -742,7 +712,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
742 712 restTemplate.postForLocation(baseURL + "/api/noauth/resetPasswordByEmail", resetPasswordByEmailRequest);
743 713 }
744 714
745   - public Optional<JsonNode> activateUser(String userId, String password) {
  715 + public Optional<JsonNode> activateUser(UserId userId, String password) {
746 716 ObjectNode activateRequest = objectMapper.createObjectNode();
747 717 activateRequest.put("activateToken", getActivateToken(userId));
748 718 activateRequest.put("password", password);
... ... @@ -771,7 +741,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
771 741 }
772 742 }
773 743
774   - public List<ComponentDescriptor> getComponentDescriptorsByType(String componentType) {
  744 + public List<ComponentDescriptor> getComponentDescriptorsByType(ComponentType componentType) {
775 745 return restTemplate.exchange(
776 746 baseURL + "/api/components?componentType={componentType}",
777 747 HttpMethod.GET, HttpEntity.EMPTY,
... ... @@ -780,19 +750,20 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
780 750 componentType).getBody();
781 751 }
782 752
783   - public List<ComponentDescriptor> getComponentDescriptorsByTypes(List<String> componentTypes) {
  753 + public List<ComponentDescriptor> getComponentDescriptorsByTypes(List<ComponentType> componentTypes) {
784 754 return restTemplate.exchange(
785 755 baseURL + "/api/components?componentTypes={componentTypes}",
786 756 HttpMethod.GET,
787 757 HttpEntity.EMPTY,
788 758 new ParameterizedTypeReference<List<ComponentDescriptor>>() {
789 759 },
790   - listToString(componentTypes)).getBody();
  760 + listEnumToString(componentTypes))
  761 + .getBody();
791 762 }
792 763
793   - public Optional<Customer> getCustomerById(String customerId) {
  764 + public Optional<Customer> getCustomerById(CustomerId customerId) {
794 765 try {
795   - ResponseEntity<Customer> customer = restTemplate.getForEntity(baseURL + "/api/customer/{customerId}", Customer.class, customerId);
  766 + ResponseEntity<Customer> customer = restTemplate.getForEntity(baseURL + "/api/customer/{customerId}", Customer.class, customerId.getId());
796 767 return Optional.ofNullable(customer.getBody());
797 768 } catch (HttpClientErrorException exception) {
798 769 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -803,9 +774,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
803 774 }
804 775 }
805 776
806   - public Optional<JsonNode> getShortCustomerInfoById(String customerId) {
  777 + public Optional<JsonNode> getShortCustomerInfoById(CustomerId customerId) {
807 778 try {
808   - ResponseEntity<JsonNode> customerInfo = restTemplate.getForEntity(baseURL + "/api/customer/{customerId}/shortInfo", JsonNode.class, customerId);
  779 + ResponseEntity<JsonNode> customerInfo = restTemplate.getForEntity(baseURL + "/api/customer/{customerId}/shortInfo", JsonNode.class, customerId.getId());
809 780 return Optional.ofNullable(customerInfo.getBody());
810 781 } catch (HttpClientErrorException exception) {
811 782 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -816,16 +787,16 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
816 787 }
817 788 }
818 789
819   - public String getCustomerTitleById(String customerId) {
820   - return restTemplate.getForObject(baseURL + "/api/customer/{customerId}/title", String.class, customerId);
  790 + public String getCustomerTitleById(CustomerId customerId) {
  791 + return restTemplate.getForObject(baseURL + "/api/customer/{customerId}/title", String.class, customerId.getId());
821 792 }
822 793
823 794 public Customer saveCustomer(Customer customer) {
824 795 return restTemplate.postForEntity(baseURL + "/api/customer", customer, Customer.class).getBody();
825 796 }
826 797
827   - public void deleteCustomer(String customerId) {
828   - restTemplate.delete(baseURL + "/api/customer/{customerId}", customerId);
  798 + public void deleteCustomer(CustomerId customerId) {
  799 + restTemplate.delete(baseURL + "/api/customer/{customerId}", customerId.getId());
829 800 }
830 801
831 802 public TextPageData<Customer> getCustomers(TextPageLink pageLink) {
... ... @@ -863,9 +834,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
863 834 return restTemplate.getForObject(baseURL + "/api/dashboard/maxDatapointsLimit", Long.class);
864 835 }
865 836
866   - public Optional<DashboardInfo> getDashboardInfoById(String dashboardId) {
  837 + public Optional<DashboardInfo> getDashboardInfoById(DashboardId dashboardId) {
867 838 try {
868   - ResponseEntity<DashboardInfo> dashboardInfo = restTemplate.getForEntity(baseURL + "/api/dashboard/info/{dashboardId}", DashboardInfo.class, dashboardId);
  839 + ResponseEntity<DashboardInfo> dashboardInfo = restTemplate.getForEntity(baseURL + "/api/dashboard/info/{dashboardId}", DashboardInfo.class, dashboardId.getId());
869 840 return Optional.ofNullable(dashboardInfo.getBody());
870 841 } catch (HttpClientErrorException exception) {
871 842 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -876,9 +847,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
876 847 }
877 848 }
878 849
879   - public Optional<Dashboard> getDashboardById(String dashboardId) {
  850 + public Optional<Dashboard> getDashboardById(DashboardId dashboardId) {
880 851 try {
881   - ResponseEntity<Dashboard> dashboard = restTemplate.getForEntity(baseURL + "/api/dashboard/{dashboardId}", Dashboard.class, dashboardId);
  852 + ResponseEntity<Dashboard> dashboard = restTemplate.getForEntity(baseURL + "/api/dashboard/{dashboardId}", Dashboard.class, dashboardId.getId());
882 853 return Optional.ofNullable(dashboard.getBody());
883 854 } catch (HttpClientErrorException exception) {
884 855 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -893,13 +864,13 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
893 864 return restTemplate.postForEntity(baseURL + "/api/dashboard", dashboard, Dashboard.class).getBody();
894 865 }
895 866
896   - public void deleteDashboard(String dashboardId) {
897   - restTemplate.delete(baseURL + "/api/dashboard/{dashboardId}", dashboardId);
  867 + public void deleteDashboard(DashboardId dashboardId) {
  868 + restTemplate.delete(baseURL + "/api/dashboard/{dashboardId}", dashboardId.getId());
898 869 }
899 870
900   - public Optional<Dashboard> assignDashboardToCustomer(String customerId, String dashboardId) {
  871 + public Optional<Dashboard> assignDashboardToCustomer(CustomerId customerId, DashboardId dashboardId) {
901 872 try {
902   - ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/dashboard/{dashboardId}", null, Dashboard.class, customerId, dashboardId);
  873 + ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/dashboard/{dashboardId}", null, Dashboard.class, customerId.getId(), dashboardId.getId());
903 874 return Optional.ofNullable(dashboard.getBody());
904 875 } catch (HttpClientErrorException exception) {
905 876 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -910,9 +881,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
910 881 }
911 882 }
912 883
913   - public Optional<Dashboard> unassignDashboardFromCustomer(String customerId, String dashboardId) {
  884 + public Optional<Dashboard> unassignDashboardFromCustomer(CustomerId customerId, DashboardId dashboardId) {
914 885 try {
915   - ResponseEntity<Dashboard> dashboard = restTemplate.exchange(baseURL + "/api/customer/{customerId}/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, customerId, dashboardId);
  886 + ResponseEntity<Dashboard> dashboard = restTemplate.exchange(baseURL + "/api/customer/{customerId}/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, customerId.getId(), dashboardId.getId());
916 887 return Optional.ofNullable(dashboard.getBody());
917 888 } catch (HttpClientErrorException exception) {
918 889 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -923,9 +894,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
923 894 }
924 895 }
925 896
926   - public Optional<Dashboard> updateDashboardCustomers(String dashboardId, List<String> customerIds) {
  897 + public Optional<Dashboard> updateDashboardCustomers(DashboardId dashboardId, List<CustomerId> customerIds) {
  898 + Object[] customerIdArray = customerIds.stream().map(customerId -> customerId.getId().toString()).toArray();
927 899 try {
928   - ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers", customerIds, Dashboard.class, dashboardId);
  900 + ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers", customerIdArray, Dashboard.class, dashboardId.getId());
929 901 return Optional.ofNullable(dashboard.getBody());
930 902 } catch (HttpClientErrorException exception) {
931 903 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -936,9 +908,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
936 908 }
937 909 }
938 910
939   - public Optional<Dashboard> addDashboardCustomers(String dashboardId, List<String> customerIds) {
  911 + public Optional<Dashboard> addDashboardCustomers(DashboardId dashboardId, List<CustomerId> customerIds) {
  912 + Object[] customerIdArray = customerIds.stream().map(customerId -> customerId.getId().toString()).toArray();
940 913 try {
941   - ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers/add", customerIds, Dashboard.class, dashboardId);
  914 + ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers/add", customerIdArray, Dashboard.class, dashboardId.getId());
942 915 return Optional.ofNullable(dashboard.getBody());
943 916 } catch (HttpClientErrorException exception) {
944 917 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -949,9 +922,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
949 922 }
950 923 }
951 924
952   - public Optional<Dashboard> removeDashboardCustomers(String dashboardId, List<String> customerIds) {
  925 + public Optional<Dashboard> removeDashboardCustomers(DashboardId dashboardId, List<CustomerId> customerIds) {
  926 + Object[] customerIdArray = customerIds.stream().map(customerId -> customerId.getId().toString()).toArray();
953 927 try {
954   - ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers/remove", customerIds, Dashboard.class, dashboardId);
  928 + ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers/remove", customerIdArray, Dashboard.class, dashboardId.getId());
955 929 return Optional.ofNullable(dashboard.getBody());
956 930 } catch (HttpClientErrorException exception) {
957 931 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -962,9 +936,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
962 936 }
963 937 }
964 938
965   - public Optional<Dashboard> assignDashboardToPublicCustomer(String dashboardId) {
  939 + public Optional<Dashboard> assignDashboardToPublicCustomer(DashboardId dashboardId) {
966 940 try {
967   - ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/customer/public/dashboard/{dashboardId}", null, Dashboard.class, dashboardId);
  941 + ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/customer/public/dashboard/{dashboardId}", null, Dashboard.class, dashboardId.getId());
968 942 return Optional.ofNullable(dashboard.getBody());
969 943 } catch (HttpClientErrorException exception) {
970 944 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -975,9 +949,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
975 949 }
976 950 }
977 951
978   - public Optional<Dashboard> unassignDashboardFromPublicCustomer(String dashboardId) {
  952 + public Optional<Dashboard> unassignDashboardFromPublicCustomer(DashboardId dashboardId) {
979 953 try {
980   - ResponseEntity<Dashboard> dashboard = restTemplate.exchange(baseURL + "/api/customer/public/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, dashboardId);
  954 + ResponseEntity<Dashboard> dashboard = restTemplate.exchange(baseURL + "/api/customer/public/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, dashboardId.getId());
981 955 return Optional.ofNullable(dashboard.getBody());
982 956 } catch (HttpClientErrorException exception) {
983 957 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -988,17 +962,15 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
988 962 }
989 963 }
990 964
991   - public TextPageData<DashboardInfo> getTenantDashboards(String tenantId, TextPageLink pageLink) {
  965 + public TextPageData<DashboardInfo> getTenantDashboards(TenantId tenantId, TextPageLink pageLink) {
992 966 Map<String, String> params = new HashMap<>();
993   - params.put("tenantId", tenantId);
  967 + params.put("tenantId", tenantId.getId().toString());
994 968 addPageLinkToParam(params, pageLink);
995 969 return restTemplate.exchange(
996 970 baseURL + "/api/tenant/{tenantId}/dashboards?" + getUrlParams(pageLink),
997 971 HttpMethod.GET, HttpEntity.EMPTY,
998 972 new ParameterizedTypeReference<TextPageData<DashboardInfo>>() {
999   - },
1000   - params
1001   - ).getBody();
  973 + }, params).getBody();
1002 974 }
1003 975
1004 976 public TextPageData<DashboardInfo> getTenantDashboards(TextPageLink pageLink) {
... ... @@ -1008,27 +980,23 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1008 980 baseURL + "/api/tenant/dashboards?" + getUrlParams(pageLink),
1009 981 HttpMethod.GET, HttpEntity.EMPTY,
1010 982 new ParameterizedTypeReference<TextPageData<DashboardInfo>>() {
1011   - },
1012   - params
1013   - ).getBody();
  983 + }, params).getBody();
1014 984 }
1015 985
1016   - public TimePageData<DashboardInfo> getCustomerDashboards(String customerId, TimePageLink pageLink) {
  986 + public TimePageData<DashboardInfo> getCustomerDashboards(CustomerId customerId, TimePageLink pageLink) {
1017 987 Map<String, String> params = new HashMap<>();
1018   - params.put("customerId", customerId);
  988 + params.put("customerId", customerId.getId().toString());
1019 989 addPageLinkToParam(params, pageLink);
1020 990 return restTemplate.exchange(
1021 991 baseURL + "/api/customer/{customerId}/dashboards?" + getUrlParams(pageLink),
1022 992 HttpMethod.GET, HttpEntity.EMPTY,
1023 993 new ParameterizedTypeReference<TimePageData<DashboardInfo>>() {
1024   - },
1025   - params
1026   - ).getBody();
  994 + }, params).getBody();
1027 995 }
1028 996
1029   - public Optional<Device> getDeviceById(String deviceId) {
  997 + public Optional<Device> getDeviceById(DeviceId deviceId) {
1030 998 try {
1031   - ResponseEntity<Device> device = restTemplate.getForEntity(baseURL + "/api/device/{deviceId}", Device.class, deviceId);
  999 + ResponseEntity<Device> device = restTemplate.getForEntity(baseURL + "/api/device/{deviceId}", Device.class, deviceId.getId());
1032 1000 return Optional.ofNullable(device.getBody());
1033 1001 } catch (HttpClientErrorException exception) {
1034 1002 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1043,13 +1011,13 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1043 1011 return restTemplate.postForEntity(baseURL + "/api/device", device, Device.class).getBody();
1044 1012 }
1045 1013
1046   - public void deleteDevice(String deviceId) {
1047   - restTemplate.delete(baseURL + "/api/device/{deviceId}", deviceId);
  1014 + public void deleteDevice(DeviceId deviceId) {
  1015 + restTemplate.delete(baseURL + "/api/device/{deviceId}", deviceId.getId());
1048 1016 }
1049 1017
1050   - public Optional<Device> assignDeviceToCustomer(String customerId, String deviceId) {
  1018 + public Optional<Device> assignDeviceToCustomer(CustomerId customerId, DeviceId deviceId) {
1051 1019 try {
1052   - ResponseEntity<Device> device = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/device/{deviceId}", null, Device.class, customerId, deviceId);
  1020 + ResponseEntity<Device> device = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/device/{deviceId}", null, Device.class, customerId.getId(), deviceId.getId());
1053 1021 return Optional.ofNullable(device.getBody());
1054 1022 } catch (HttpClientErrorException exception) {
1055 1023 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1060,9 +1028,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1060 1028 }
1061 1029 }
1062 1030
1063   - public Optional<Device> unassignDeviceFromCustomer(String deviceId) {
  1031 + public Optional<Device> unassignDeviceFromCustomer(DeviceId deviceId) {
1064 1032 try {
1065   - ResponseEntity<Device> device = restTemplate.exchange(baseURL + "/api/customer/device/{deviceId}", HttpMethod.DELETE, HttpEntity.EMPTY, Device.class, deviceId);
  1033 + ResponseEntity<Device> device = restTemplate.exchange(baseURL + "/api/customer/device/{deviceId}", HttpMethod.DELETE, HttpEntity.EMPTY, Device.class, deviceId.getId());
1066 1034 return Optional.ofNullable(device.getBody());
1067 1035 } catch (HttpClientErrorException exception) {
1068 1036 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1073,9 +1041,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1073 1041 }
1074 1042 }
1075 1043
1076   - public Optional<Device> assignDeviceToPublicCustomer(String deviceId) {
  1044 + public Optional<Device> assignDeviceToPublicCustomer(DeviceId deviceId) {
1077 1045 try {
1078   - ResponseEntity<Device> device = restTemplate.postForEntity(baseURL + "/api/customer/public/device/{deviceId}", null, Device.class, deviceId);
  1046 + ResponseEntity<Device> device = restTemplate.postForEntity(baseURL + "/api/customer/public/device/{deviceId}", null, Device.class, deviceId.getId());
1079 1047 return Optional.ofNullable(device.getBody());
1080 1048 } catch (HttpClientErrorException exception) {
1081 1049 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1086,9 +1054,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1086 1054 }
1087 1055 }
1088 1056
1089   - public Optional<DeviceCredentials> getDeviceCredentialsByDeviceId(String deviceId) {
  1057 + public Optional<DeviceCredentials> getDeviceCredentialsByDeviceId(DeviceId deviceId) {
1090 1058 try {
1091   - ResponseEntity<DeviceCredentials> deviceCredentials = restTemplate.getForEntity(baseURL + "/api/device/{deviceId}/credentials", DeviceCredentials.class, deviceId);
  1059 + ResponseEntity<DeviceCredentials> deviceCredentials = restTemplate.getForEntity(baseURL + "/api/device/{deviceId}/credentials", DeviceCredentials.class, deviceId.getId());
1092 1060 return Optional.ofNullable(deviceCredentials.getBody());
1093 1061 } catch (HttpClientErrorException exception) {
1094 1062 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1111,9 +1079,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1111 1079 baseURL + "/api/tenant/devices?type={type}&" + getUrlParams(pageLink),
1112 1080 HttpMethod.GET, HttpEntity.EMPTY,
1113 1081 new ParameterizedTypeReference<TextPageData<Device>>() {
1114   - },
1115   - params)
1116   - .getBody();
  1082 + }, params).getBody();
1117 1083 }
1118 1084
1119 1085 public Optional<Device> getTenantDevice(String deviceName) {
... ... @@ -1129,26 +1095,23 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1129 1095 }
1130 1096 }
1131 1097
1132   - public TextPageData<Device> getCustomerDevices(String customerId, String type, TextPageLink pageLink) {
  1098 + public TextPageData<Device> getCustomerDevices(CustomerId customerId, String deviceType, TextPageLink pageLink) {
1133 1099 Map<String, String> params = new HashMap<>();
1134   - params.put("customerId", customerId);
1135   - params.put("type", type);
  1100 + params.put("customerId", customerId.getId().toString());
  1101 + params.put("type", deviceType);
1136 1102 addPageLinkToParam(params, pageLink);
1137 1103 return restTemplate.exchange(
1138 1104 baseURL + "/api/customer/{customerId}/devices?type={type}&" + getUrlParams(pageLink),
1139 1105 HttpMethod.GET, HttpEntity.EMPTY,
1140 1106 new ParameterizedTypeReference<TextPageData<Device>>() {
1141   - },
1142   - params)
1143   - .getBody();
  1107 + }, params).getBody();
1144 1108 }
1145 1109
1146   - public List<Device> getDevicesByIds(List<String> deviceIds) {
  1110 + public List<Device> getDevicesByIds(List<DeviceId> deviceIds) {
1147 1111 return restTemplate.exchange(baseURL + "/api/devices?deviceIds={deviceIds}",
1148 1112 HttpMethod.GET,
1149 1113 HttpEntity.EMPTY, new ParameterizedTypeReference<List<Device>>() {
1150   - },
1151   - listToString(deviceIds)).getBody();
  1114 + }, listIdsToString(deviceIds)).getBody();
1152 1115 }
1153 1116
1154 1117 public List<Device> findByQuery(DeviceSearchQuery query) {
... ... @@ -1175,8 +1138,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1175 1138 HttpMethod.POST,
1176 1139 new HttpEntity<>(claimRequest),
1177 1140 new ParameterizedTypeReference<JsonNode>() {
1178   - },
1179   - deviceName).getBody();
  1141 + }, deviceName).getBody();
1180 1142 }
1181 1143
1182 1144 public void reClaimDevice(String deviceName) {
... ... @@ -1187,14 +1149,14 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1187 1149 restTemplate.postForLocation(baseURL + "/api/relation", null);
1188 1150 }
1189 1151
1190   - public void deleteRelation(String fromId, String fromType, String relationType, String relationTypeGroup, String toId, String toType) {
  1152 + public void deleteRelation(EntityId fromId, String relationType, RelationTypeGroup relationTypeGroup, EntityId toId) {
1191 1153 Map<String, String> params = new HashMap<>();
1192   - params.put("fromId", fromId);
1193   - params.put("fromType", fromType);
  1154 + params.put("fromId", fromId.getId().toString());
  1155 + params.put("fromType", fromId.getEntityType().name());
1194 1156 params.put("relationType", relationType);
1195   - params.put("relationTypeGroup", relationTypeGroup);
1196   - params.put("toId", toId);
1197   - params.put("toType", toType);
  1157 + params.put("relationTypeGroup", relationTypeGroup.name());
  1158 + params.put("toId", toId.getId().toString());
  1159 + params.put("toType", toId.getEntityType().name());
1198 1160 restTemplate.delete(baseURL + "/api/relation?fromId={fromId}&fromType={fromType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}&toId={toId}&toType={toType}", params);
1199 1161 }
1200 1162
... ... @@ -1202,14 +1164,14 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1202 1164 restTemplate.delete(baseURL + "/api/relations?entityId={entityId}&entityType={entityType}", entityId.getId().toString(), entityId.getEntityType().name());
1203 1165 }
1204 1166
1205   - public Optional<EntityRelation> getRelation(String fromId, String fromType, String relationType, String relationTypeGroup, String toId, String toType) {
  1167 + public Optional<EntityRelation> getRelation(EntityId fromId, String relationType, RelationTypeGroup relationTypeGroup, EntityId toId) {
1206 1168 Map<String, String> params = new HashMap<>();
1207   - params.put("fromId", fromId);
1208   - params.put("fromType", fromType);
  1169 + params.put("fromId", fromId.getId().toString());
  1170 + params.put("fromType", fromId.getEntityType().name());
1209 1171 params.put("relationType", relationType);
1210   - params.put("relationTypeGroup", relationTypeGroup);
1211   - params.put("toId", toId);
1212   - params.put("toType", toType);
  1172 + params.put("relationTypeGroup", relationTypeGroup.name());
  1173 + params.put("toId", toId.getId().toString());
  1174 + params.put("toType", toId.getEntityType().name());
1213 1175
1214 1176 try {
1215 1177 ResponseEntity<EntityRelation> entityRelation = restTemplate.getForEntity(
... ... @@ -1226,11 +1188,11 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1226 1188 }
1227 1189 }
1228 1190
1229   - public List<EntityRelation> findByFrom(String fromId, String fromType, String relationTypeGroup) {
  1191 + public List<EntityRelation> findByFrom(EntityId fromId, RelationTypeGroup relationTypeGroup) {
1230 1192 Map<String, String> params = new HashMap<>();
1231   - params.put("fromId", fromId);
1232   - params.put("fromType", fromType);
1233   - params.put("relationTypeGroup", relationTypeGroup);
  1193 + params.put("fromId", fromId.getId().toString());
  1194 + params.put("fromType", fromId.getEntityType().name());
  1195 + params.put("relationTypeGroup", relationTypeGroup.name());
1234 1196
1235 1197 return restTemplate.exchange(
1236 1198 baseURL + "/api/relations?fromId={fromId}&fromType={fromType}&relationTypeGroup={relationTypeGroup}",
... ... @@ -1241,11 +1203,11 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1241 1203 params).getBody();
1242 1204 }
1243 1205
1244   - public List<EntityRelationInfo> findInfoByFrom(String fromId, String fromType, String relationTypeGroup) {
  1206 + public List<EntityRelationInfo> findInfoByFrom(EntityId fromId, RelationTypeGroup relationTypeGroup) {
1245 1207 Map<String, String> params = new HashMap<>();
1246   - params.put("fromId", fromId);
1247   - params.put("fromType", fromType);
1248   - params.put("relationTypeGroup", relationTypeGroup);
  1208 + params.put("fromId", fromId.getId().toString());
  1209 + params.put("fromType", fromId.getEntityType().name());
  1210 + params.put("relationTypeGroup", relationTypeGroup.name());
1249 1211
1250 1212 return restTemplate.exchange(
1251 1213 baseURL + "/api/relations/info?fromId={fromId}&fromType={fromType}&relationTypeGroup={relationTypeGroup}",
... ... @@ -1256,12 +1218,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1256 1218 params).getBody();
1257 1219 }
1258 1220
1259   - public List<EntityRelation> findByFrom(String fromId, String fromType, String relationType, String relationTypeGroup) {
  1221 + public List<EntityRelation> findByFrom(EntityId fromId, String relationType, RelationTypeGroup relationTypeGroup) {
1260 1222 Map<String, String> params = new HashMap<>();
1261   - params.put("fromId", fromId);
1262   - params.put("fromType", fromType);
  1223 + params.put("fromId", fromId.getId().toString());
  1224 + params.put("fromType", fromId.getEntityType().name());
1263 1225 params.put("relationType", relationType);
1264   - params.put("relationTypeGroup", relationTypeGroup);
  1226 + params.put("relationTypeGroup", relationTypeGroup.name());
1265 1227
1266 1228 return restTemplate.exchange(
1267 1229 baseURL + "/api/relations?fromId={fromId}&fromType={fromType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}",
... ... @@ -1272,11 +1234,11 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1272 1234 params).getBody();
1273 1235 }
1274 1236
1275   - public List<EntityRelation> findByTo(String toId, String toType, String relationTypeGroup) {
  1237 + public List<EntityRelation> findByTo(EntityId toId, RelationTypeGroup relationTypeGroup) {
1276 1238 Map<String, String> params = new HashMap<>();
1277   - params.put("toId", toId);
1278   - params.put("toType", toType);
1279   - params.put("relationTypeGroup", relationTypeGroup);
  1239 + params.put("toId", toId.getId().toString());
  1240 + params.put("toType", toId.getEntityType().name());
  1241 + params.put("relationTypeGroup", relationTypeGroup.name());
1280 1242
1281 1243 return restTemplate.exchange(
1282 1244 baseURL + "/api/relations?toId={toId}&toType={toType}&relationTypeGroup={relationTypeGroup}",
... ... @@ -1287,11 +1249,11 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1287 1249 params).getBody();
1288 1250 }
1289 1251
1290   - public List<EntityRelationInfo> findInfoByTo(String toId, String toType, String relationTypeGroup) {
  1252 + public List<EntityRelationInfo> findInfoByTo(EntityId toId, RelationTypeGroup relationTypeGroup) {
1291 1253 Map<String, String> params = new HashMap<>();
1292   - params.put("toId", toId);
1293   - params.put("toType", toType);
1294   - params.put("relationTypeGroup", relationTypeGroup);
  1254 + params.put("toId", toId.getId().toString());
  1255 + params.put("toType", toId.getEntityType().name());
  1256 + params.put("relationTypeGroup", relationTypeGroup.name());
1295 1257
1296 1258 return restTemplate.exchange(
1297 1259 baseURL + "/api/relations?toId={toId}&toType={toType}&relationTypeGroup={relationTypeGroup}",
... ... @@ -1302,12 +1264,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1302 1264 params).getBody();
1303 1265 }
1304 1266
1305   - public List<EntityRelation> findByTo(String toId, String toType, String relationType, String relationTypeGroup) {
  1267 + public List<EntityRelation> findByTo(EntityId toId, String relationType, RelationTypeGroup relationTypeGroup) {
1306 1268 Map<String, String> params = new HashMap<>();
1307   - params.put("toId", toId);
1308   - params.put("toType", toType);
  1269 + params.put("toId", toId.getId().toString());
  1270 + params.put("toType", toId.getEntityType().name());
1309 1271 params.put("relationType", relationType);
1310   - params.put("relationTypeGroup", relationTypeGroup);
  1272 + params.put("relationTypeGroup", relationTypeGroup.name());
1311 1273
1312 1274 return restTemplate.exchange(
1313 1275 baseURL + "/api/relations?toId={toId}&toType={toType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}",
... ... @@ -1336,9 +1298,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1336 1298 }).getBody();
1337 1299 }
1338 1300
1339   - public Optional<EntityView> getEntityViewById(String entityViewId) {
  1301 + public Optional<EntityView> getEntityViewById(EntityViewId entityViewId) {
1340 1302 try {
1341   - ResponseEntity<EntityView> entityView = restTemplate.getForEntity(baseURL + "/api/entityView/{entityViewId}", EntityView.class, entityViewId);
  1303 + ResponseEntity<EntityView> entityView = restTemplate.getForEntity(baseURL + "/api/entityView/{entityViewId}", EntityView.class, entityViewId.getId());
1342 1304 return Optional.ofNullable(entityView.getBody());
1343 1305 } catch (HttpClientErrorException exception) {
1344 1306 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1370,9 +1332,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1370 1332 }
1371 1333 }
1372 1334
1373   - public Optional<EntityView> assignEntityViewToCustomer(String customerId, String entityViewId) {
  1335 + public Optional<EntityView> assignEntityViewToCustomer(CustomerId customerId, EntityViewId entityViewId) {
1374 1336 try {
1375   - ResponseEntity<EntityView> entityView = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/entityView/{entityViewId}", null, EntityView.class, customerId, entityViewId);
  1337 + ResponseEntity<EntityView> entityView = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/entityView/{entityViewId}", null, EntityView.class, customerId.getId(), entityViewId.getId());
1376 1338 return Optional.ofNullable(entityView.getBody());
1377 1339 } catch (HttpClientErrorException exception) {
1378 1340 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1383,13 +1345,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1383 1345 }
1384 1346 }
1385 1347
1386   - public Optional<EntityView> unassignEntityViewFromCustomer(String entityViewId) {
  1348 + public Optional<EntityView> unassignEntityViewFromCustomer(EntityViewId entityViewId) {
1387 1349 try {
1388   - ResponseEntity<EntityView> entityView = restTemplate.exchange(
1389   - baseURL + "/api/customer/entityView/{entityViewId}",
1390   - HttpMethod.DELETE,
1391   - HttpEntity.EMPTY,
1392   - EntityView.class, entityViewId);
  1350 + ResponseEntity<EntityView> entityView = restTemplate.exchange(baseURL + "/api/customer/entityView/{entityViewId}", HttpMethod.DELETE, HttpEntity.EMPTY, EntityView.class, entityViewId.getId());
1393 1351 return Optional.ofNullable(entityView.getBody());
1394 1352 } catch (HttpClientErrorException exception) {
1395 1353 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1400,31 +1358,29 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1400 1358 }
1401 1359 }
1402 1360
1403   - public TextPageData<EntityView> getCustomerEntityViews(String customerId, String type, TextPageLink pageLink) {
  1361 + public TextPageData<EntityView> getCustomerEntityViews(CustomerId customerId, String entityViewType, TextPageLink pageLink) {
1404 1362 Map<String, String> params = new HashMap<>();
1405   - params.put("customerId", customerId);
1406   - params.put("type", type);
  1363 + params.put("customerId", customerId.getId().toString());
  1364 + params.put("type", entityViewType);
1407 1365 addPageLinkToParam(params, pageLink);
1408 1366 return restTemplate.exchange(
1409 1367 baseURL + "/api/customer/{customerId}/entityViews?type={type}&" + getUrlParams(pageLink),
1410 1368 HttpMethod.GET,
1411 1369 HttpEntity.EMPTY,
1412 1370 new ParameterizedTypeReference<TextPageData<EntityView>>() {
1413   - },
1414   - params).getBody();
  1371 + }, params).getBody();
1415 1372 }
1416 1373
1417   - public TextPageData<EntityView> getTenantEntityViews(String type, TextPageLink pageLink) {
  1374 + public TextPageData<EntityView> getTenantEntityViews(String entityViewType, TextPageLink pageLink) {
1418 1375 Map<String, String> params = new HashMap<>();
1419   - params.put("type", type);
  1376 + params.put("type", entityViewType);
1420 1377 addPageLinkToParam(params, pageLink);
1421 1378 return restTemplate.exchange(
1422 1379 baseURL + "/api/tenant/entityViews?type={type}&" + getUrlParams(pageLink),
1423 1380 HttpMethod.GET,
1424 1381 HttpEntity.EMPTY,
1425 1382 new ParameterizedTypeReference<TextPageData<EntityView>>() {
1426   - },
1427   - params).getBody();
  1383 + }, params).getBody();
1428 1384 }
1429 1385
1430 1386 public List<EntityView> findByQuery(EntityViewSearchQuery query) {
... ... @@ -1437,9 +1393,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1437 1393 }).getBody();
1438 1394 }
1439 1395
1440   - public Optional<EntityView> assignEntityViewToPublicCustomer(String entityViewId) {
  1396 + public Optional<EntityView> assignEntityViewToPublicCustomer(EntityViewId entityViewId) {
1441 1397 try {
1442   - ResponseEntity<EntityView> entityView = restTemplate.postForEntity(baseURL + "/api/customer/public/entityView/{entityViewId}", null, EntityView.class, entityViewId);
  1398 + ResponseEntity<EntityView> entityView = restTemplate.postForEntity(baseURL + "/api/customer/public/entityView/{entityViewId}", null, EntityView.class, entityViewId.getId());
1443 1399 return Optional.ofNullable(entityView.getBody());
1444 1400 } catch (HttpClientErrorException exception) {
1445 1401 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1450,12 +1406,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1450 1406 }
1451 1407 }
1452 1408
1453   - public TimePageData<Event> getEvents(EntityId entityId, String eventType, String tenantId, TimePageLink pageLink) {
  1409 + public TimePageData<Event> getEvents(EntityId entityId, String eventType, TenantId tenantId, TimePageLink pageLink) {
1454 1410 Map<String, String> params = new HashMap<>();
1455 1411 params.put("entityType", entityId.getEntityType().name());
1456 1412 params.put("entityId", entityId.getId().toString());
1457 1413 params.put("eventType", eventType);
1458   - params.put("tenantId", tenantId);
  1414 + params.put("tenantId", tenantId.getId().toString());
1459 1415 addPageLinkToParam(params, pageLink);
1460 1416
1461 1417 return restTemplate.exchange(
... ... @@ -1467,11 +1423,11 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1467 1423 params).getBody();
1468 1424 }
1469 1425
1470   - public TimePageData<Event> getEvents(EntityId entityId, String tenantId, TimePageLink pageLink) {
  1426 + public TimePageData<Event> getEvents(EntityId entityId, TenantId tenantId, TimePageLink pageLink) {
1471 1427 Map<String, String> params = new HashMap<>();
1472 1428 params.put("entityType", entityId.getEntityType().name());
1473 1429 params.put("entityId", entityId.getId().toString());
1474   - params.put("tenantId", tenantId);
  1430 + params.put("tenantId", tenantId.getId().toString());
1475 1431 addPageLinkToParam(params, pageLink);
1476 1432
1477 1433 return restTemplate.exchange(
... ... @@ -1483,8 +1439,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1483 1439 params).getBody();
1484 1440 }
1485 1441
1486   - public void handleOneWayDeviceRPCRequest(String deviceId, JsonNode requestBody) {
1487   - restTemplate.postForLocation(baseURL + "/api/plugins/rpc/oneway/{deviceId}", requestBody, deviceId);
  1442 + public void handleOneWayDeviceRPCRequest(DeviceId deviceId, JsonNode requestBody) {
  1443 + restTemplate.postForLocation(baseURL + "/api/plugins/rpc/oneway/{deviceId}", requestBody, deviceId.getId());
1488 1444 }
1489 1445
1490 1446 public JsonNode handleTwoWayDeviceRPCRequest(String deviceId, JsonNode requestBody) {
... ... @@ -1497,9 +1453,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1497 1453 deviceId).getBody();
1498 1454 }
1499 1455
1500   - public Optional<RuleChain> getRuleChainById(String ruleChainId) {
  1456 + public Optional<RuleChain> getRuleChainById(RuleChainId ruleChainId) {
1501 1457 try {
1502   - ResponseEntity<RuleChain> ruleChain = restTemplate.getForEntity(baseURL + "/api/ruleChain/{ruleChainId}", RuleChain.class, ruleChainId);
  1458 + ResponseEntity<RuleChain> ruleChain = restTemplate.getForEntity(baseURL + "/api/ruleChain/{ruleChainId}", RuleChain.class, ruleChainId.getId());
1503 1459 return Optional.ofNullable(ruleChain.getBody());
1504 1460 } catch (HttpClientErrorException exception) {
1505 1461 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1510,9 +1466,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1510 1466 }
1511 1467 }
1512 1468
1513   - public Optional<RuleChainMetaData> getRuleChainMetaData(String ruleChainId) {
  1469 + public Optional<RuleChainMetaData> getRuleChainMetaData(RuleChainId ruleChainId) {
1514 1470 try {
1515   - ResponseEntity<RuleChainMetaData> ruleChainMetaData = restTemplate.getForEntity(baseURL + "/api/ruleChain/{ruleChainId}/metadata", RuleChainMetaData.class, ruleChainId);
  1471 + ResponseEntity<RuleChainMetaData> ruleChainMetaData = restTemplate.getForEntity(baseURL + "/api/ruleChain/{ruleChainId}/metadata", RuleChainMetaData.class, ruleChainId.getId());
1516 1472 return Optional.ofNullable(ruleChainMetaData.getBody());
1517 1473 } catch (HttpClientErrorException exception) {
1518 1474 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1527,9 +1483,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1527 1483 return restTemplate.postForEntity(baseURL + "/api/ruleChain", ruleChain, RuleChain.class).getBody();
1528 1484 }
1529 1485
1530   - public Optional<RuleChain> setRootRuleChain(String ruleChainId) {
  1486 + public Optional<RuleChain> setRootRuleChain(RuleChainId ruleChainId) {
1531 1487 try {
1532   - ResponseEntity<RuleChain> ruleChain = restTemplate.postForEntity(baseURL + "/api/ruleChain/{ruleChainId}/root", null, RuleChain.class, ruleChainId);
  1488 + ResponseEntity<RuleChain> ruleChain = restTemplate.postForEntity(baseURL + "/api/ruleChain/{ruleChainId}/root", null, RuleChain.class, ruleChainId.getId());
1533 1489 return Optional.ofNullable(ruleChain.getBody());
1534 1490 } catch (HttpClientErrorException exception) {
1535 1491 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1548,21 +1504,21 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1548 1504 Map<String, String> params = new HashMap<>();
1549 1505 addPageLinkToParam(params, pageLink);
1550 1506 return restTemplate.exchange(
1551   - baseURL + "/api/ruleChains" + getUrlParams(pageLink),
  1507 + baseURL + "/api/ruleChains?" + getUrlParams(pageLink),
1552 1508 HttpMethod.GET,
1553 1509 HttpEntity.EMPTY,
1554 1510 new ParameterizedTypeReference<TextPageData<RuleChain>>() {
1555   - }
1556   - ).getBody();
  1511 + },
  1512 + params).getBody();
1557 1513 }
1558 1514
1559   - public void deleteRuleChain(String ruleChainId) {
1560   - restTemplate.delete(baseURL + "/api/ruleChain/{ruleChainId}", ruleChainId);
  1515 + public void deleteRuleChain(RuleChainId ruleChainId) {
  1516 + restTemplate.delete(baseURL + "/api/ruleChain/{ruleChainId}", ruleChainId.getId());
1561 1517 }
1562 1518
1563   - public Optional<JsonNode> getLatestRuleNodeDebugInput(String ruleNodeId) {
  1519 + public Optional<JsonNode> getLatestRuleNodeDebugInput(RuleNodeId ruleNodeId) {
1564 1520 try {
1565   - ResponseEntity<JsonNode> jsonNode = restTemplate.getForEntity(baseURL + "/api/ruleNode/{ruleNodeId}/debugIn", JsonNode.class, ruleNodeId);
  1521 + ResponseEntity<JsonNode> jsonNode = restTemplate.getForEntity(baseURL + "/api/ruleNode/{ruleNodeId}/debugIn", JsonNode.class, ruleNodeId.getId());
1566 1522 return Optional.ofNullable(jsonNode.getBody());
1567 1523 } catch (HttpClientErrorException exception) {
1568 1524 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1668,19 +1624,17 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1668 1624 }
1669 1625
1670 1626
1671   - public List<TsKvEntry> getTimeseries(EntityId entityId, List<String> keys, Long startTs, Long endTs, Long interval, Integer limit, String agg) {
  1627 + public List<TsKvEntry> getTimeseries(EntityId entityId, List<String> keys, Long interval, Aggregation agg, TimePageLink pageLink) {
1672 1628 Map<String, String> params = new HashMap<>();
  1629 + addPageLinkToParam(params, pageLink);
1673 1630 params.put("entityType", entityId.getEntityType().name());
1674 1631 params.put("entityId", entityId.getId().toString());
1675 1632 params.put("keys", listToString(keys));
1676   - params.put("startTs", startTs.toString());
1677   - params.put("endTs", endTs.toString());
1678 1633 params.put("interval", interval == null ? "0" : interval.toString());
1679   - params.put("limit", limit == null ? "100" : limit.toString());
1680   - params.put("agg", agg == null ? "NONE" : agg);
  1634 + params.put("agg", agg == null ? "NONE" : agg.name());
1681 1635
1682 1636 Map<String, List<JsonNode>> timeseries = restTemplate.exchange(
1683   - baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/values/timeseries?keys={keys}&startTs={startTs}&endTs={endTs}&interval={interval}&limit={limit}&agg={agg}",
  1637 + baseURL + "/api/plugins/telemetry/{entityType}/{entityId}/values/timeseries?keys={keys}&interval={interval}&agg={agg}&" + getUrlParams(pageLink),
1684 1638 HttpMethod.GET,
1685 1639 HttpEntity.EMPTY,
1686 1640 new ParameterizedTypeReference<Map<String, List<JsonNode>>>() {
... ... @@ -1807,9 +1761,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1807 1761
1808 1762 }
1809 1763
1810   - public Optional<Tenant> getTenantById(String tenantId) {
  1764 + public Optional<Tenant> getTenantById(TenantId tenantId) {
1811 1765 try {
1812   - ResponseEntity<Tenant> tenant = restTemplate.getForEntity(baseURL + "/api/tenant/{tenantId}", Tenant.class, tenantId);
  1766 + ResponseEntity<Tenant> tenant = restTemplate.getForEntity(baseURL + "/api/tenant/{tenantId}", Tenant.class, tenantId.getId());
1813 1767 return Optional.ofNullable(tenant.getBody());
1814 1768 } catch (HttpClientErrorException exception) {
1815 1769 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1824,8 +1778,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1824 1778 return restTemplate.postForEntity(baseURL + "/api/tenant", tenant, Tenant.class).getBody();
1825 1779 }
1826 1780
1827   - public void deleteTenant(String tenantId) {
1828   - restTemplate.delete(baseURL + "/api/tenant/{tenantId}", tenantId);
  1781 + public void deleteTenant(TenantId tenantId) {
  1782 + restTemplate.delete(baseURL + "/api/tenant/{tenantId}", tenantId.getId());
1829 1783 }
1830 1784
1831 1785 public TextPageData<Tenant> getTenants(TextPageLink pageLink) {
... ... @@ -1836,13 +1790,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1836 1790 HttpMethod.GET,
1837 1791 HttpEntity.EMPTY,
1838 1792 new ParameterizedTypeReference<TextPageData<Tenant>>() {
1839   - },
1840   - params).getBody();
  1793 + }, params).getBody();
1841 1794 }
1842 1795
1843   - public Optional<User> getUserById(String userId) {
  1796 + public Optional<User> getUserById(UserId userId) {
1844 1797 try {
1845   - ResponseEntity<User> user = restTemplate.getForEntity(baseURL + "/api/user/{userId}", User.class, userId);
  1798 + ResponseEntity<User> user = restTemplate.getForEntity(baseURL + "/api/user/{userId}", User.class, userId.getId());
1846 1799 return Optional.ofNullable(user.getBody());
1847 1800 } catch (HttpClientErrorException exception) {
1848 1801 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1857,9 +1810,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1857 1810 return restTemplate.getForEntity(baseURL + "/api/user/tokenAccessEnabled", Boolean.class).getBody();
1858 1811 }
1859 1812
1860   - public Optional<JsonNode> getUserToken(String userId) {
  1813 + public Optional<JsonNode> getUserToken(UserId userId) {
1861 1814 try {
1862   - ResponseEntity<JsonNode> userToken = restTemplate.getForEntity(baseURL + "/api/user/{userId}/token", JsonNode.class, userId);
  1815 + ResponseEntity<JsonNode> userToken = restTemplate.getForEntity(baseURL + "/api/user/{userId}/token", JsonNode.class, userId.getId());
1863 1816 return Optional.ofNullable(userToken.getBody());
1864 1817 } catch (HttpClientErrorException exception) {
1865 1818 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1878,17 +1831,17 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1878 1831 restTemplate.postForLocation(baseURL + "/api/user/sendActivationMail?email={email}", null, email);
1879 1832 }
1880 1833
1881   - public String getActivationLink(String userId) {
1882   - return restTemplate.getForEntity(baseURL + "/api/user/{userId}/activationLink", String.class, userId).getBody();
  1834 + public String getActivationLink(UserId userId) {
  1835 + return restTemplate.getForEntity(baseURL + "/api/user/{userId}/activationLink", String.class, userId.getId()).getBody();
1883 1836 }
1884 1837
1885   - public void deleteUser(String userId) {
1886   - restTemplate.delete(baseURL + "/api/user/{userId}", userId);
  1838 + public void deleteUser(UserId userId) {
  1839 + restTemplate.delete(baseURL + "/api/user/{userId}", userId.getId());
1887 1840 }
1888 1841
1889   - public TextPageData<User> getTenantAdmins(String tenantId, TextPageLink pageLink) {
  1842 + public TextPageData<User> getTenantAdmins(TenantId tenantId, TextPageLink pageLink) {
1890 1843 Map<String, String> params = new HashMap<>();
1891   - params.put("tenantId", tenantId);
  1844 + params.put("tenantId", tenantId.getId().toString());
1892 1845 addPageLinkToParam(params, pageLink);
1893 1846
1894 1847 return restTemplate.exchange(
... ... @@ -1896,13 +1849,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1896 1849 HttpMethod.GET,
1897 1850 HttpEntity.EMPTY,
1898 1851 new ParameterizedTypeReference<TextPageData<User>>() {
1899   - },
1900   - params).getBody();
  1852 + }, params).getBody();
1901 1853 }
1902 1854
1903   - public TextPageData<User> getCustomerUsers(String customerId, TextPageLink pageLink) {
  1855 + public TextPageData<User> getCustomerUsers(CustomerId customerId, TextPageLink pageLink) {
1904 1856 Map<String, String> params = new HashMap<>();
1905   - params.put("customerId", customerId);
  1857 + params.put("customerId", customerId.getId().toString());
1906 1858 addPageLinkToParam(params, pageLink);
1907 1859
1908 1860 return restTemplate.exchange(
... ... @@ -1910,22 +1862,21 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1910 1862 HttpMethod.GET,
1911 1863 HttpEntity.EMPTY,
1912 1864 new ParameterizedTypeReference<TextPageData<User>>() {
1913   - },
1914   - params).getBody();
  1865 + }, params).getBody();
1915 1866 }
1916 1867
1917   - public void setUserCredentialsEnabled(String userId, boolean userCredentialsEnabled) {
  1868 + public void setUserCredentialsEnabled(UserId userId, boolean userCredentialsEnabled) {
1918 1869 restTemplate.postForLocation(
1919 1870 baseURL + "/api/user/{userId}/userCredentialsEnabled?serCredentialsEnabled={serCredentialsEnabled}",
1920 1871 null,
1921   - userId,
  1872 + userId.getId(),
1922 1873 userCredentialsEnabled);
1923 1874 }
1924 1875
1925   - public Optional<WidgetsBundle> getWidgetsBundleById(String widgetsBundleId) {
  1876 + public Optional<WidgetsBundle> getWidgetsBundleById(WidgetsBundleId widgetsBundleId) {
1926 1877 try {
1927 1878 ResponseEntity<WidgetsBundle> widgetsBundle =
1928   - restTemplate.getForEntity(baseURL + "/api/widgetsBundle/{widgetsBundleId}", WidgetsBundle.class, widgetsBundleId);
  1879 + restTemplate.getForEntity(baseURL + "/api/widgetsBundle/{widgetsBundleId}", WidgetsBundle.class, widgetsBundleId.getId());
1929 1880 return Optional.ofNullable(widgetsBundle.getBody());
1930 1881 } catch (HttpClientErrorException exception) {
1931 1882 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1940,8 +1891,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1940 1891 return restTemplate.postForEntity(baseURL + "/api/widgetsBundle", widgetsBundle, WidgetsBundle.class).getBody();
1941 1892 }
1942 1893
1943   - public void deleteWidgetsBundle(String widgetsBundleId) {
1944   - restTemplate.delete(baseURL + "/api/widgetsBundle/{widgetsBundleId}", widgetsBundleId);
  1894 + public void deleteWidgetsBundle(WidgetsBundleId widgetsBundleId) {
  1895 + restTemplate.delete(baseURL + "/api/widgetsBundle/{widgetsBundleId}", widgetsBundleId.getId());
1945 1896 }
1946 1897
1947 1898 public TextPageData<WidgetsBundle> getWidgetsBundles(TextPageLink pageLink) {
... ... @@ -1952,7 +1903,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1952 1903 HttpMethod.GET,
1953 1904 HttpEntity.EMPTY,
1954 1905 new ParameterizedTypeReference<TextPageData<WidgetsBundle>>() {
1955   - }).getBody();
  1906 + }, params).getBody();
1956 1907 }
1957 1908
1958 1909 public List<WidgetsBundle> getWidgetsBundles() {
... ... @@ -1964,10 +1915,10 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1964 1915 }).getBody();
1965 1916 }
1966 1917
1967   - public Optional<WidgetType> getWidgetTypeById(String widgetTypeId) {
  1918 + public Optional<WidgetType> getWidgetTypeById(WidgetsBundleId widgetTypeId) {
1968 1919 try {
1969 1920 ResponseEntity<WidgetType> widgetType =
1970   - restTemplate.getForEntity(baseURL + "/api/widgetType/{widgetTypeId}", WidgetType.class, widgetTypeId);
  1921 + restTemplate.getForEntity(baseURL + "/api/widgetType/{widgetTypeId}", WidgetType.class, widgetTypeId.getId());
1971 1922 return Optional.ofNullable(widgetType.getBody());
1972 1923 } catch (HttpClientErrorException exception) {
1973 1924 if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
... ... @@ -1982,8 +1933,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
1982 1933 return restTemplate.postForEntity(baseURL + "/api/widgetType", widgetType, WidgetType.class).getBody();
1983 1934 }
1984 1935
1985   - public void deleteWidgetType(String widgetTypeId) {
1986   - restTemplate.delete(baseURL + "/api/widgetType/{widgetTypeId}", widgetTypeId);
  1936 + public void deleteWidgetType(WidgetTypeId widgetTypeId) {
  1937 + restTemplate.delete(baseURL + "/api/widgetType/{widgetTypeId}", widgetTypeId.getId());
1987 1938 }
1988 1939
1989 1940 public List<WidgetType> getBundleWidgetTypes(boolean isSystem, String bundleAlias) {
... ... @@ -2016,6 +1967,34 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
2016 1967 }
2017 1968 }
2018 1969
  1970 + private String getUrlParams(TimePageLink pageLink) {
  1971 + String urlParams = "limit={limit}&ascOrder={ascOrder}";
  1972 + if (pageLink.getStartTime() != null) {
  1973 + urlParams += "&startTime={startTime}";
  1974 + }
  1975 + if (pageLink.getEndTime() != null) {
  1976 + urlParams += "&endTime={endTime}";
  1977 + }
  1978 + if (pageLink.getIdOffset() != null) {
  1979 + urlParams += "&offset={offset}";
  1980 + }
  1981 + return urlParams;
  1982 + }
  1983 +
  1984 + private String getUrlParams(TextPageLink pageLink) {
  1985 + String urlParams = "limit={limit}";
  1986 + if (!isEmpty(pageLink.getTextSearch())) {
  1987 + urlParams += "&textSearch={textSearch}";
  1988 + }
  1989 + if (!isEmpty(pageLink.getIdOffset())) {
  1990 + urlParams += "&idOffset={idOffset}";
  1991 + }
  1992 + if (!isEmpty(pageLink.getTextOffset())) {
  1993 + urlParams += "&textOffset={textOffset}";
  1994 + }
  1995 + return urlParams;
  1996 + }
  1997 +
2019 1998 private void addPageLinkToParam(Map<String, String> params, TimePageLink pageLink) {
2020 1999 params.put("limit", String.valueOf(pageLink.getLimit()));
2021 2000 if (pageLink.getStartTime() != null) {
... ... @@ -2049,6 +2028,14 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
2049 2028 return String.join(",", list);
2050 2029 }
2051 2030
  2031 + private String listIdsToString(List<? extends EntityId> list) {
  2032 + return listToString(list.stream().map(id -> id.getId().toString()).collect(Collectors.toList()));
  2033 + }
  2034 +
  2035 + private String listEnumToString(List<? extends Enum> list) {
  2036 + return listToString(list.stream().map(Enum::name).collect(Collectors.toList()));
  2037 + }
  2038 +
2052 2039 @Override
2053 2040 public void close() {
2054 2041 if (service != null) {
... ...