From eb7c2f1659fea2a1b065c4d8a2eceeb630a16478 Mon Sep 17 00:00:00 2001 From: YevhenBondarenko <56396344+YevhenBondarenko@users.noreply.github.com> Date: Fri, 29 Nov 2019 13:48:31 +0200 Subject: [PATCH] Feature/rest client (#2218) * added methods from admin-controller, alarm-controller, asset-controller, audit-log-controller * refactored rest client and added methods from auth controller * added methods from component-descriptor-controller * added methods from customer controller * added methods from dashboard controller * added methods from device controller * refactored url pageLink params * added methods from entity relation controller * added methods from entity view controller * refactored * added methods from event controller * added methods from rpc controller * added methods from rule chain controller * added methods from telemetry controller * added methods from tenant controller * added methods from user controller * added methods from widgets bundle controller * added methods from widget type controller * created method refreshToken * moved classes SecuritySettings, UserPasswordPolicy, ClaimRequest, UpdateMessage, to common module, and added "/api" to urls where this part was missing --- .../server/controller/AdminController.java | 4 +- .../server/controller/AuthController.java | 7 +- .../server/controller/DeviceController.java | 2 +- .../system/DefaultSystemSecurityService.java | 5 +- .../system/SystemSecurityService.java | 2 +- .../service/update/DefaultUpdateService.java | 2 +- .../server/service/update/UpdateService.java | 2 +- .../server/common}/data/ClaimRequest.java | 2 +- .../server/common/data}/UpdateMessage.java | 2 +- .../security/model/SecuritySettings.java | 2 +- .../security/model/UserPasswordPolicy.java | 2 +- .../thingsboard/client/tools/RestClient.java | 331 ++++++++++-------- 12 files changed, 204 insertions(+), 159 deletions(-) rename {application/src/main/java/org/thingsboard/server/controller/claim => common/data/src/main/java/org/thingsboard/server/common}/data/ClaimRequest.java (92%) rename {application/src/main/java/org/thingsboard/server/service/update/model => common/data/src/main/java/org/thingsboard/server/common/data}/UpdateMessage.java (93%) rename {application/src/main/java/org/thingsboard/server/service => common/data/src/main/java/org/thingsboard/server/common/data}/security/model/SecuritySettings.java (93%) rename {application/src/main/java/org/thingsboard/server/service => common/data/src/main/java/org/thingsboard/server/common/data}/security/model/UserPasswordPolicy.java (94%) diff --git a/application/src/main/java/org/thingsboard/server/controller/AdminController.java b/application/src/main/java/org/thingsboard/server/controller/AdminController.java index a6122dd82e..81415ae35d 100644 --- a/application/src/main/java/org/thingsboard/server/controller/AdminController.java +++ b/application/src/main/java/org/thingsboard/server/controller/AdminController.java @@ -28,12 +28,12 @@ import org.thingsboard.server.common.data.AdminSettings; import org.thingsboard.server.common.data.exception.ThingsboardException; import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.dao.settings.AdminSettingsService; -import org.thingsboard.server.service.security.model.SecuritySettings; +import org.thingsboard.server.common.data.security.model.SecuritySettings; import org.thingsboard.server.service.security.permission.Operation; import org.thingsboard.server.service.security.permission.Resource; import org.thingsboard.server.service.security.system.SystemSecurityService; import org.thingsboard.server.service.update.UpdateService; -import org.thingsboard.server.service.update.model.UpdateMessage; +import org.thingsboard.server.common.data.UpdateMessage; @RestController @RequestMapping("/api/admin") diff --git a/application/src/main/java/org/thingsboard/server/controller/AuthController.java b/application/src/main/java/org/thingsboard/server/controller/AuthController.java index 690ba76a0f..f744f5d822 100644 --- a/application/src/main/java/org/thingsboard/server/controller/AuthController.java +++ b/application/src/main/java/org/thingsboard/server/controller/AuthController.java @@ -24,7 +24,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.security.core.Authentication; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -43,14 +42,12 @@ import org.thingsboard.server.common.data.security.UserCredentials; import org.thingsboard.server.dao.audit.AuditLogService; import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRepository; import org.thingsboard.server.service.security.auth.rest.RestAuthenticationDetails; -import org.thingsboard.server.service.security.model.SecuritySettings; +import org.thingsboard.server.common.data.security.model.SecuritySettings; import org.thingsboard.server.service.security.model.SecurityUser; -import org.thingsboard.server.service.security.model.UserPasswordPolicy; +import org.thingsboard.server.common.data.security.model.UserPasswordPolicy; import org.thingsboard.server.service.security.model.UserPrincipal; import org.thingsboard.server.service.security.model.token.JwtToken; import org.thingsboard.server.service.security.model.token.JwtTokenFactory; -import org.thingsboard.server.service.security.permission.Operation; -import org.thingsboard.server.service.security.permission.Resource; import org.thingsboard.server.service.security.system.SystemSecurityService; import ua_parser.Client; diff --git a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java index f497c4fefa..698dcfb3f3 100644 --- a/application/src/main/java/org/thingsboard/server/controller/DeviceController.java +++ b/application/src/main/java/org/thingsboard/server/controller/DeviceController.java @@ -44,7 +44,7 @@ import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.page.TextPageData; import org.thingsboard.server.common.data.page.TextPageLink; import org.thingsboard.server.common.data.security.DeviceCredentials; -import org.thingsboard.server.controller.claim.data.ClaimRequest; +import org.thingsboard.server.common.data.ClaimRequest; import org.thingsboard.server.dao.device.claim.ClaimResponse; import org.thingsboard.server.dao.device.claim.ClaimResult; import org.thingsboard.server.dao.exception.IncorrectParameterException; diff --git a/application/src/main/java/org/thingsboard/server/service/security/system/DefaultSystemSecurityService.java b/application/src/main/java/org/thingsboard/server/service/security/system/DefaultSystemSecurityService.java index 94d0fea86f..3eb4d115e3 100644 --- a/application/src/main/java/org/thingsboard/server/service/security/system/DefaultSystemSecurityService.java +++ b/application/src/main/java/org/thingsboard/server/service/security/system/DefaultSystemSecurityService.java @@ -42,14 +42,13 @@ import org.thingsboard.server.common.data.User; import org.thingsboard.server.common.data.exception.ThingsboardException; import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.security.UserCredentials; -import org.thingsboard.server.dao.audit.AuditLogService; import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.settings.AdminSettingsService; import org.thingsboard.server.dao.user.UserService; import org.thingsboard.server.dao.user.UserServiceImpl; import org.thingsboard.server.service.security.exception.UserPasswordExpiredException; -import org.thingsboard.server.service.security.model.SecuritySettings; -import org.thingsboard.server.service.security.model.UserPasswordPolicy; +import org.thingsboard.server.common.data.security.model.SecuritySettings; +import org.thingsboard.server.common.data.security.model.UserPasswordPolicy; import javax.annotation.Resource; import java.util.ArrayList; diff --git a/application/src/main/java/org/thingsboard/server/service/security/system/SystemSecurityService.java b/application/src/main/java/org/thingsboard/server/service/security/system/SystemSecurityService.java index 50265863b3..1425600cc4 100644 --- a/application/src/main/java/org/thingsboard/server/service/security/system/SystemSecurityService.java +++ b/application/src/main/java/org/thingsboard/server/service/security/system/SystemSecurityService.java @@ -19,7 +19,7 @@ import org.springframework.security.core.AuthenticationException; import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.security.UserCredentials; import org.thingsboard.server.dao.exception.DataValidationException; -import org.thingsboard.server.service.security.model.SecuritySettings; +import org.thingsboard.server.common.data.security.model.SecuritySettings; public interface SystemSecurityService { diff --git a/application/src/main/java/org/thingsboard/server/service/update/DefaultUpdateService.java b/application/src/main/java/org/thingsboard/server/service/update/DefaultUpdateService.java index 4a6fa6f271..14cbf95861 100644 --- a/application/src/main/java/org/thingsboard/server/service/update/DefaultUpdateService.java +++ b/application/src/main/java/org/thingsboard/server/service/update/DefaultUpdateService.java @@ -22,7 +22,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; -import org.thingsboard.server.service.update.model.UpdateMessage; +import org.thingsboard.server.common.data.UpdateMessage; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; diff --git a/application/src/main/java/org/thingsboard/server/service/update/UpdateService.java b/application/src/main/java/org/thingsboard/server/service/update/UpdateService.java index 4ddc6dc3df..016c573399 100644 --- a/application/src/main/java/org/thingsboard/server/service/update/UpdateService.java +++ b/application/src/main/java/org/thingsboard/server/service/update/UpdateService.java @@ -15,7 +15,7 @@ */ package org.thingsboard.server.service.update; -import org.thingsboard.server.service.update.model.UpdateMessage; +import org.thingsboard.server.common.data.UpdateMessage; public interface UpdateService { diff --git a/application/src/main/java/org/thingsboard/server/controller/claim/data/ClaimRequest.java b/common/data/src/main/java/org/thingsboard/server/common/data/ClaimRequest.java similarity index 92% rename from application/src/main/java/org/thingsboard/server/controller/claim/data/ClaimRequest.java rename to common/data/src/main/java/org/thingsboard/server/common/data/ClaimRequest.java index 6620aa187e..8845edb872 100644 --- a/application/src/main/java/org/thingsboard/server/controller/claim/data/ClaimRequest.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/ClaimRequest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.controller.claim.data; +package org.thingsboard.server.common.data; import lombok.Data; diff --git a/application/src/main/java/org/thingsboard/server/service/update/model/UpdateMessage.java b/common/data/src/main/java/org/thingsboard/server/common/data/UpdateMessage.java similarity index 93% rename from application/src/main/java/org/thingsboard/server/service/update/model/UpdateMessage.java rename to common/data/src/main/java/org/thingsboard/server/common/data/UpdateMessage.java index b4e61f7bc2..19a0341dfe 100644 --- a/application/src/main/java/org/thingsboard/server/service/update/model/UpdateMessage.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/UpdateMessage.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.service.update.model; +package org.thingsboard.server.common.data; import lombok.Data; diff --git a/application/src/main/java/org/thingsboard/server/service/security/model/SecuritySettings.java b/common/data/src/main/java/org/thingsboard/server/common/data/security/model/SecuritySettings.java similarity index 93% rename from application/src/main/java/org/thingsboard/server/service/security/model/SecuritySettings.java rename to common/data/src/main/java/org/thingsboard/server/common/data/security/model/SecuritySettings.java index bfc9176b4b..ee531fd4fd 100644 --- a/application/src/main/java/org/thingsboard/server/service/security/model/SecuritySettings.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/security/model/SecuritySettings.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.service.security.model; +package org.thingsboard.server.common.data.security.model; import lombok.Data; diff --git a/application/src/main/java/org/thingsboard/server/service/security/model/UserPasswordPolicy.java b/common/data/src/main/java/org/thingsboard/server/common/data/security/model/UserPasswordPolicy.java similarity index 94% rename from application/src/main/java/org/thingsboard/server/service/security/model/UserPasswordPolicy.java rename to common/data/src/main/java/org/thingsboard/server/common/data/security/model/UserPasswordPolicy.java index 0c50b5f6e0..9718c4ecb2 100644 --- a/application/src/main/java/org/thingsboard/server/service/security/model/UserPasswordPolicy.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/security/model/UserPasswordPolicy.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.thingsboard.server.service.security.model; +package org.thingsboard.server.common.data.security.model; import lombok.Data; diff --git a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java index 2d789ac706..248a93fef1 100644 --- a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java +++ b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java @@ -31,6 +31,7 @@ import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import org.springframework.web.context.request.async.DeferredResult; import org.thingsboard.server.common.data.AdminSettings; +import org.thingsboard.server.common.data.ClaimRequest; import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Dashboard; import org.thingsboard.server.common.data.DashboardInfo; @@ -39,6 +40,7 @@ import org.thingsboard.server.common.data.EntitySubtype; import org.thingsboard.server.common.data.EntityView; import org.thingsboard.server.common.data.Event; import org.thingsboard.server.common.data.Tenant; +import org.thingsboard.server.common.data.UpdateMessage; import org.thingsboard.server.common.data.User; import org.thingsboard.server.common.data.alarm.Alarm; import org.thingsboard.server.common.data.alarm.AlarmInfo; @@ -65,6 +67,8 @@ import org.thingsboard.server.common.data.rule.RuleChain; import org.thingsboard.server.common.data.rule.RuleChainMetaData; import org.thingsboard.server.common.data.security.DeviceCredentials; import org.thingsboard.server.common.data.security.DeviceCredentialsType; +import org.thingsboard.server.common.data.security.model.SecuritySettings; +import org.thingsboard.server.common.data.security.model.UserPasswordPolicy; import org.thingsboard.server.common.data.widget.WidgetType; import org.thingsboard.server.common.data.widget.WidgetsBundle; @@ -85,6 +89,7 @@ public class RestClient implements ClientHttpRequestInterceptor { protected final RestTemplate restTemplate = new RestTemplate(); protected final String baseURL; private String token; + private String refreshToken; private final static String TIME_PAGE_LINK_URL_PARAMS = "limit={limit}&startTime={startTime}&endTime={endTime}&ascOrder={ascOrder}&offset={offset}"; private final static String TEXT_PAGE_LINK_URL_PARAMS = "limit={limit}&textSearch{textSearch}&idOffset={idOffset}&textOffset{textOffset}"; @@ -93,7 +98,23 @@ public class RestClient implements ClientHttpRequestInterceptor { public ClientHttpResponse intercept(HttpRequest request, byte[] bytes, ClientHttpRequestExecution execution) throws IOException { HttpRequest wrapper = new HttpRequestWrapper(request); wrapper.getHeaders().set(JWT_TOKEN_HEADER_PARAM, "Bearer " + token); - return execution.execute(wrapper, bytes); + ClientHttpResponse response = execution.execute(wrapper, bytes); + if (response.getStatusCode() == HttpStatus.UNAUTHORIZED) { + synchronized (this) { + restTemplate.getInterceptors().remove(this); + refreshToken(); + wrapper.getHeaders().set(JWT_TOKEN_HEADER_PARAM, "Bearer " + token); + return execution.execute(wrapper, bytes); + } + } + return response; + } + + public void refreshToken() { + Map refreshTokenRequest = new HashMap<>(); + refreshTokenRequest.put("refreshToken", refreshToken); + ResponseEntity tokenInfo = restTemplate.postForEntity(baseURL + "/api/auth/token", refreshTokenRequest, JsonNode.class); + setTokenInfo(tokenInfo.getBody()); } public void login(String username, String password) { @@ -101,8 +122,13 @@ public class RestClient implements ClientHttpRequestInterceptor { loginRequest.put("username", username); loginRequest.put("password", password); ResponseEntity tokenInfo = restTemplate.postForEntity(baseURL + "/api/auth/login", loginRequest, JsonNode.class); - this.token = tokenInfo.getBody().get("token").asText(); - restTemplate.setInterceptors(Collections.singletonList(this)); + setTokenInfo(tokenInfo.getBody()); + } + + private void setTokenInfo(JsonNode tokenInfo) { + this.token = tokenInfo.get("token").asText(); + this.refreshToken = tokenInfo.get("refreshToken").asText(); + restTemplate.getInterceptors().add(this); } public Optional findDevice(String name) { @@ -289,28 +315,42 @@ public class RestClient implements ClientHttpRequestInterceptor { } public AdminSettings saveAdminSettings(AdminSettings adminSettings) { - return restTemplate.postForEntity(baseURL + "/api/settings", adminSettings, AdminSettings.class).getBody(); + return restTemplate.postForEntity(baseURL + "/api/admin/settings", adminSettings, AdminSettings.class).getBody(); } public void sendTestMail(AdminSettings adminSettings) { - restTemplate.postForEntity(baseURL + "/api/settings/testMail", adminSettings, AdminSettings.class); + restTemplate.postForEntity(baseURL + "/api/admin/settings/testMail", adminSettings, AdminSettings.class); } - //TODO: -// @RequestMapping(value = "/securitySettings", method = RequestMethod.GET) -// public SecuritySettings getSecuritySettings() { -// -// } - //TODO: -// @RequestMapping(value = "/securitySettings", method = RequestMethod.POST) -// public SecuritySettings saveSecuritySettings(SecuritySettings securitySettings) { -// -// } - //TODO: -// @RequestMapping(value = "/updates", method = RequestMethod.GET) -// public UpdateMessage checkUpdates() { -// -// } + public Optional getSecuritySettings() { + try { + ResponseEntity securitySettings = restTemplate.getForEntity(baseURL + "/api/admin/securitySettings", SecuritySettings.class); + return Optional.ofNullable(securitySettings.getBody()); + } catch (HttpClientErrorException exception) { + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { + return Optional.empty(); + } else { + throw exception; + } + } + } + + public SecuritySettings saveSecuritySettings(SecuritySettings securitySettings) { + return restTemplate.postForEntity(baseURL + "/api/admin/securitySettings", securitySettings, SecuritySettings.class).getBody(); + } + + public Optional checkUpdates() { + try { + ResponseEntity updateMsg = restTemplate.getForEntity(baseURL + "/api/admin/updates", UpdateMessage.class); + return Optional.ofNullable(updateMsg.getBody()); + } catch (HttpClientErrorException exception) { + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { + return Optional.empty(); + } else { + throw exception; + } + } + } public Optional getAlarmById(String alarmId) { try { @@ -488,7 +528,7 @@ public class RestClient implements ClientHttpRequestInterceptor { addPageLinkToParam(params, pageLink); ResponseEntity> assets = restTemplate.exchange( - baseURL + "/customer/{customerId}/assets?type={type}&" + TEXT_PAGE_LINK_URL_PARAMS, + baseURL + "/api/customer/{customerId}/assets?type={type}&" + TEXT_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -532,7 +572,7 @@ public class RestClient implements ClientHttpRequestInterceptor { addPageLinkToParam(params, pageLink); ResponseEntity> auditLog = restTemplate.exchange( - baseURL + "/audit/logs/customer/{customerId}?actionTypes={actionTypes}&" + TIME_PAGE_LINK_URL_PARAMS, + baseURL + "/api/audit/logs/customer/{customerId}?actionTypes={actionTypes}&" + TIME_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -548,7 +588,7 @@ public class RestClient implements ClientHttpRequestInterceptor { addPageLinkToParam(params, pageLink); ResponseEntity> auditLog = restTemplate.exchange( - baseURL + "/audit/logs/user/{userId}?actionTypes={actionTypes}&" + TIME_PAGE_LINK_URL_PARAMS, + baseURL + "/api/audit/logs/user/{userId}?actionTypes={actionTypes}&" + TIME_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -565,7 +605,7 @@ public class RestClient implements ClientHttpRequestInterceptor { addPageLinkToParam(params, pageLink); ResponseEntity> auditLog = restTemplate.exchange( - baseURL + "/audit/logs/entity/{entityType}/{entityId}?actionTypes={actionTypes}&" + TIME_PAGE_LINK_URL_PARAMS, + baseURL + "/api/audit/logs/entity/{entityType}/{entityId}?actionTypes={actionTypes}&" + TIME_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -580,7 +620,7 @@ public class RestClient implements ClientHttpRequestInterceptor { addPageLinkToParam(params, pageLink); ResponseEntity> auditLog = restTemplate.exchange( - baseURL + "/audit/logs?actionTypes={actionTypes}&" + TIME_PAGE_LINK_URL_PARAMS, + baseURL + "/api/audit/logs?actionTypes={actionTypes}&" + TIME_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -590,40 +630,47 @@ public class RestClient implements ClientHttpRequestInterceptor { } public Optional getUser() { - ResponseEntity user = restTemplate.getForEntity(baseURL + "/auth/user", User.class); + ResponseEntity user = restTemplate.getForEntity(baseURL + "/api/auth/user", User.class); return Optional.ofNullable(user.getBody()); } public void logout() { - restTemplate.exchange(URI.create(baseURL + "/auth/logout"), HttpMethod.POST, HttpEntity.EMPTY, Object.class); + restTemplate.exchange(URI.create(baseURL + "/api/auth/logout"), HttpMethod.POST, HttpEntity.EMPTY, Object.class); } public void changePassword(JsonNode changePasswordRequest) { - restTemplate.exchange(URI.create(baseURL + "/auth/changePassword"), HttpMethod.POST, new HttpEntity<>(changePasswordRequest), Object.class); + restTemplate.exchange(URI.create(baseURL + "/api/auth/changePassword"), HttpMethod.POST, new HttpEntity<>(changePasswordRequest), Object.class); } - //TODO: -// @RequestMapping(value = "/noauth/userPasswordPolicy", method = RequestMethod.GET) -// public UserPasswordPolicy getUserPasswordPolicy() { -// -// } + public Optional getUserPasswordPolicy() { + try { + ResponseEntity userPasswordPolicy = restTemplate.getForEntity(baseURL + "/api/noauth/userPasswordPolicy", UserPasswordPolicy.class); + return Optional.ofNullable(userPasswordPolicy.getBody()); + } catch (HttpClientErrorException exception) { + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { + return Optional.empty(); + } else { + throw exception; + } + } + } public ResponseEntity checkActivateToken(String activateToken) { - return restTemplate.getForEntity(baseURL + "/noauth/activate?activateToken={activateToken}", String.class, activateToken); + return restTemplate.getForEntity(baseURL + "/api/noauth/activate?activateToken={activateToken}", String.class, activateToken); } public void requestResetPasswordByEmail(JsonNode resetPasswordByEmailRequest) { - restTemplate.exchange(URI.create(baseURL + "/noauth/resetPasswordByEmail"), HttpMethod.POST, new HttpEntity<>(resetPasswordByEmailRequest), Object.class); + restTemplate.exchange(URI.create(baseURL + "/api/noauth/resetPasswordByEmail"), HttpMethod.POST, new HttpEntity<>(resetPasswordByEmailRequest), Object.class); } public ResponseEntity checkResetToken(String resetToken) { - return restTemplate.getForEntity(baseURL + "noauth/resetPassword?resetToken={resetToken}", String.class, resetToken); + return restTemplate.getForEntity(baseURL + "/api/noauth/resetPassword?resetToken={resetToken}", String.class, resetToken); } public Optional activateUser(JsonNode activateRequest) { try { - ResponseEntity jsonNode = restTemplate.postForEntity(baseURL + "/noauth/activate", activateRequest, JsonNode.class); + ResponseEntity jsonNode = restTemplate.postForEntity(baseURL + "/api/noauth/activate", activateRequest, JsonNode.class); return Optional.ofNullable(jsonNode.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -636,7 +683,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional resetPassword(JsonNode resetPasswordRequest) { try { - ResponseEntity jsonNode = restTemplate.postForEntity(baseURL + "/noauth/resetPassword", resetPasswordRequest, JsonNode.class); + ResponseEntity jsonNode = restTemplate.postForEntity(baseURL + "/api/noauth/resetPassword", resetPasswordRequest, JsonNode.class); return Optional.ofNullable(jsonNode.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -649,7 +696,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getComponentDescriptorByClazz(String componentDescriptorClazz) { try { - ResponseEntity componentDescriptor = restTemplate.getForEntity(baseURL + "/component/{componentDescriptorClazz}", ComponentDescriptor.class); + ResponseEntity componentDescriptor = restTemplate.getForEntity(baseURL + "/api/component/{componentDescriptorClazz}", ComponentDescriptor.class); return Optional.ofNullable(componentDescriptor.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -662,7 +709,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public List getComponentDescriptorsByType(String componentType) { return restTemplate.exchange( - baseURL + "/components?componentType={componentType}", + baseURL + "/api/components?componentType={componentType}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, @@ -671,7 +718,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public List getComponentDescriptorsByTypes(String[] componentTypes) { return restTemplate.exchange( - baseURL + "/components?componentTypes={componentTypes}", + baseURL + "/api/components?componentTypes={componentTypes}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -681,7 +728,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getCustomerById(String customerId) { try { - ResponseEntity customer = restTemplate.getForEntity(baseURL + "/customer/{customerId}", Customer.class, customerId); + ResponseEntity customer = restTemplate.getForEntity(baseURL + "/api/customer/{customerId}", Customer.class, customerId); return Optional.ofNullable(customer.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -694,7 +741,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getShortCustomerInfoById(String customerId) { try { - ResponseEntity customerInfo = restTemplate.getForEntity(baseURL + "/customer/{customerId}/shortInfo", JsonNode.class, customerId); + ResponseEntity customerInfo = restTemplate.getForEntity(baseURL + "/api/customer/{customerId}/shortInfo", JsonNode.class, customerId); return Optional.ofNullable(customerInfo.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -706,15 +753,15 @@ public class RestClient implements ClientHttpRequestInterceptor { } public String getCustomerTitleById(String customerId) { - return restTemplate.getForObject(baseURL + "/customer/{customerId}/title", String.class, customerId); + return restTemplate.getForObject(baseURL + "/api/customer/{customerId}/title", String.class, customerId); } public Customer saveCustomer(Customer customer) { - return restTemplate.postForEntity(baseURL + "/customer", customer, Customer.class).getBody(); + return restTemplate.postForEntity(baseURL + "/api/customer", customer, Customer.class).getBody(); } public void deleteCustomer(String customerId) { - restTemplate.delete(baseURL + "/customer/{customerId}", customerId); + restTemplate.delete(baseURL + "/api/customer/{customerId}", customerId); } public TextPageData getCustomers(TextPageLink pageLink) { @@ -722,7 +769,7 @@ public class RestClient implements ClientHttpRequestInterceptor { addPageLinkToParam(params, pageLink); ResponseEntity> customer = restTemplate.exchange( - baseURL + "/customers?" + TEXT_PAGE_LINK_URL_PARAMS, + baseURL + "/api/customers?" + TEXT_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -733,7 +780,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getTenantCustomer(String customerTitle) { try { - ResponseEntity customer = restTemplate.getForEntity(baseURL + "/tenant/customers?customerTitle={customerTitle}", Customer.class, customerTitle); + ResponseEntity customer = restTemplate.getForEntity(baseURL + "/api/tenant/customers?customerTitle={customerTitle}", Customer.class, customerTitle); return Optional.ofNullable(customer.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -745,16 +792,16 @@ public class RestClient implements ClientHttpRequestInterceptor { } public Long getServerTime() { - return restTemplate.getForObject(baseURL + "/dashboard/serverTime", Long.class); + return restTemplate.getForObject(baseURL + "/api/dashboard/serverTime", Long.class); } public Long getMaxDatapointsLimit() { - return restTemplate.getForObject(baseURL + "/dashboard/maxDatapointsLimit", Long.class); + return restTemplate.getForObject(baseURL + "/api/dashboard/maxDatapointsLimit", Long.class); } public Optional getDashboardInfoById(String dashboardId) { try { - ResponseEntity dashboardInfo = restTemplate.getForEntity(baseURL + "/dashboard/info/{dashboardId}", DashboardInfo.class, dashboardId); + ResponseEntity dashboardInfo = restTemplate.getForEntity(baseURL + "/api/dashboard/info/{dashboardId}", DashboardInfo.class, dashboardId); return Optional.ofNullable(dashboardInfo.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -767,7 +814,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getDashboardById(String dashboardId) { try { - ResponseEntity dashboard = restTemplate.getForEntity(baseURL + "/dashboard/{dashboardId}", Dashboard.class, dashboardId); + ResponseEntity dashboard = restTemplate.getForEntity(baseURL + "/api/dashboard/{dashboardId}", Dashboard.class, dashboardId); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -779,16 +826,16 @@ public class RestClient implements ClientHttpRequestInterceptor { } public Dashboard saveDashboard(Dashboard dashboard) { - return restTemplate.postForEntity(baseURL + "/dashboard", dashboard, Dashboard.class).getBody(); + return restTemplate.postForEntity(baseURL + "/api/dashboard", dashboard, Dashboard.class).getBody(); } public void deleteDashboard(String dashboardId) { - restTemplate.delete(baseURL + "/dashboard/{dashboardId}", dashboardId); + restTemplate.delete(baseURL + "/api/dashboard/{dashboardId}", dashboardId); } public Optional assignDashboardToCustomer(String customerId, String dashboardId) { try { - ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/customer/{customerId}/dashboard/{dashboardId}", null, Dashboard.class, customerId, dashboardId); + ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/dashboard/{dashboardId}", null, Dashboard.class, customerId, dashboardId); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -801,7 +848,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional unassignDashboardFromCustomer(String customerId, String dashboardId) { try { - ResponseEntity dashboard = restTemplate.exchange(baseURL + "/customer/{customerId}/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, customerId, dashboardId); + ResponseEntity dashboard = restTemplate.exchange(baseURL + "/api/customer/{customerId}/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, customerId, dashboardId); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -814,7 +861,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional updateDashboardCustomers(String dashboardId, String[] customerIds) { try { - ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/dashboard/{dashboardId}/customers", customerIds, Dashboard.class, dashboardId); + ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers", customerIds, Dashboard.class, dashboardId); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -827,7 +874,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional addDashboardCustomers(String dashboardId, String[] customerIds) { try { - ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/dashboard/{dashboardId}/customers/add", customerIds, Dashboard.class, dashboardId); + ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers/add", customerIds, Dashboard.class, dashboardId); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -840,7 +887,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional removeDashboardCustomers(String dashboardId, String[] customerIds) { try { - ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/dashboard/{dashboardId}/customers/remove", customerIds, Dashboard.class, dashboardId); + ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/dashboard/{dashboardId}/customers/remove", customerIds, Dashboard.class, dashboardId); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -853,7 +900,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional assignDashboardToPublicCustomer(String dashboardId) { try { - ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/customer/public/dashboard/{dashboardId}", null, Dashboard.class, dashboardId); + ResponseEntity dashboard = restTemplate.postForEntity(baseURL + "/api/customer/public/dashboard/{dashboardId}", null, Dashboard.class, dashboardId); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -866,7 +913,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional unassignDashboardFromPublicCustomer(String dashboardId) { try { - ResponseEntity dashboard = restTemplate.exchange(baseURL + "/customer/public/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, dashboardId); + ResponseEntity dashboard = restTemplate.exchange(baseURL + "/api/customer/public/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, dashboardId); return Optional.ofNullable(dashboard.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -882,7 +929,7 @@ public class RestClient implements ClientHttpRequestInterceptor { params.put("tenantId", tenantId); addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/tenant/{tenantId}/dashboards?" + TEXT_PAGE_LINK_URL_PARAMS, + baseURL + "/api/tenant/{tenantId}/dashboards?" + TEXT_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, @@ -894,7 +941,7 @@ public class RestClient implements ClientHttpRequestInterceptor { Map params = new HashMap<>(); addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/tenant/dashboards?" + TEXT_PAGE_LINK_URL_PARAMS, + baseURL + "/api/tenant/dashboards?" + TEXT_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, @@ -907,7 +954,7 @@ public class RestClient implements ClientHttpRequestInterceptor { params.put("customerId", customerId); addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/customer/{customerId}/dashboards?" + TEXT_PAGE_LINK_URL_PARAMS, + baseURL + "/api/customer/{customerId}/dashboards?" + TEXT_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, @@ -917,7 +964,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getDeviceById(String deviceId) { try { - ResponseEntity device = restTemplate.getForEntity(baseURL + "/device/{deviceId}", Device.class, deviceId); + ResponseEntity device = restTemplate.getForEntity(baseURL + "/api/device/{deviceId}", Device.class, deviceId); return Optional.ofNullable(device.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -929,16 +976,16 @@ public class RestClient implements ClientHttpRequestInterceptor { } public Device saveDevice(Device device) { - return restTemplate.postForEntity(baseURL + "/device", device, Device.class).getBody(); + return restTemplate.postForEntity(baseURL + "/api/device", device, Device.class).getBody(); } public void deleteDevice(String deviceId) { - restTemplate.delete(baseURL + "/device/{deviceId}", deviceId); + restTemplate.delete(baseURL + "/api/device/{deviceId}", deviceId); } public Optional assignDeviceToCustomer(String customerId, String deviceId) { try { - ResponseEntity device = restTemplate.postForEntity(baseURL + "/customer/{customerId}/device/{deviceId}", null, Device.class, customerId, deviceId); + ResponseEntity device = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/device/{deviceId}", null, Device.class, customerId, deviceId); return Optional.ofNullable(device.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -951,7 +998,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional unassignDeviceFromCustomer(String deviceId) { try { - ResponseEntity device = restTemplate.exchange(baseURL + "/customer/device/{deviceId}", HttpMethod.DELETE, HttpEntity.EMPTY, Device.class, deviceId); + ResponseEntity device = restTemplate.exchange(baseURL + "/api/customer/device/{deviceId}", HttpMethod.DELETE, HttpEntity.EMPTY, Device.class, deviceId); return Optional.ofNullable(device.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -964,7 +1011,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional assignDeviceToPublicCustomer(String deviceId) { try { - ResponseEntity device = restTemplate.postForEntity(baseURL + "/customer/public/device/{deviceId}", null, Device.class, deviceId); + ResponseEntity device = restTemplate.postForEntity(baseURL + "/api/customer/public/device/{deviceId}", null, Device.class, deviceId); return Optional.ofNullable(device.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -977,7 +1024,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getDeviceCredentialsByDeviceId(String deviceId) { try { - ResponseEntity deviceCredentials = restTemplate.getForEntity(baseURL + "/device/{deviceId}/credentials", DeviceCredentials.class, deviceId); + ResponseEntity deviceCredentials = restTemplate.getForEntity(baseURL + "/api/device/{deviceId}/credentials", DeviceCredentials.class, deviceId); return Optional.ofNullable(deviceCredentials.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -997,7 +1044,7 @@ public class RestClient implements ClientHttpRequestInterceptor { params.put("type", type); addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/tenant/devices?type={type}&" + TEXT_PAGE_LINK_URL_PARAMS, + baseURL + "/api/tenant/devices?type={type}&" + TEXT_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, @@ -1007,7 +1054,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getTenantDevice(String deviceName) { try { - ResponseEntity device = restTemplate.getForEntity(baseURL + "/tenant/devices?deviceName={deviceName}", Device.class, deviceName); + ResponseEntity device = restTemplate.getForEntity(baseURL + "/api/tenant/devices?deviceName={deviceName}", Device.class, deviceName); return Optional.ofNullable(device.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1024,7 +1071,7 @@ public class RestClient implements ClientHttpRequestInterceptor { params.put("type", type); addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/customer/{customerId}/devices?type={type}&" + TEXT_PAGE_LINK_URL_PARAMS, + baseURL + "/api/customer/{customerId}/devices?type={type}&" + TEXT_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, @@ -1033,7 +1080,7 @@ public class RestClient implements ClientHttpRequestInterceptor { } public List getDevicesByIds(String[] deviceIds) { - return restTemplate.exchange(baseURL + "/devices?deviceIds={deviceIds}", + return restTemplate.exchange(baseURL + "/api/devices?deviceIds={deviceIds}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, @@ -1042,7 +1089,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public List findByQuery(DeviceSearchQuery query) { return restTemplate.exchange( - baseURL + "/devices", + baseURL + "/api/devices", HttpMethod.POST, new HttpEntity<>(query), new ParameterizedTypeReference>() { @@ -1051,23 +1098,26 @@ public class RestClient implements ClientHttpRequestInterceptor { public List getDeviceTypes() { return restTemplate.exchange( - baseURL + "/devices", + baseURL + "/api/devices", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }).getBody(); } - //TODO: ClaimRequest class -// @RequestMapping(value = "/customer/device/{deviceName}/claim", method = RequestMethod.POST) -// public DeferredResult claimDevice(String deviceName, ClaimRequest claimRequest) { -// return restTemplate.exchange(baseURL + "/customer/device/{deviceName}/claim", HttpMethod.POST, new HttpEntity<>(claimRequest), new ParameterizedTypeReference>() { -// }, deviceName).getBody(); -// } + public DeferredResult claimDevice(String deviceName, ClaimRequest claimRequest) { + return restTemplate.exchange( + baseURL + "/api/customer/device/{deviceName}/claim", + HttpMethod.POST, + new HttpEntity<>(claimRequest), + new ParameterizedTypeReference>() { + }, + deviceName).getBody(); + } public DeferredResult reClaimDevice(String deviceName) { return restTemplate.exchange( - baseURL + "/customer/device/{deviceName}/claim", + baseURL + "/api/customer/device/{deviceName}/claim", HttpMethod.DELETE, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1076,7 +1126,7 @@ public class RestClient implements ClientHttpRequestInterceptor { } public void saveRelation(EntityRelation relation) { - restTemplate.postForEntity(baseURL + "/relation", relation, Object.class); + restTemplate.postForEntity(baseURL + "/api/relation", relation, Object.class); } public void deleteRelation(String fromId, String fromType, String relationType, String relationTypeGroup, String toId, String toType) { @@ -1087,11 +1137,11 @@ public class RestClient implements ClientHttpRequestInterceptor { params.put("relationTypeGroup", relationTypeGroup); params.put("toId", toId); params.put("toType", toType); - restTemplate.delete(baseURL + "/relation?fromId={fromId}&fromType={fromType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}&toId={toId}&toType={toType}", params); + restTemplate.delete(baseURL + "/api/relation?fromId={fromId}&fromType={fromType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}&toId={toId}&toType={toType}", params); } public void deleteRelations(String entityId, String entityType) { - restTemplate.delete(baseURL + "/relations?entityId={entityId}&entityType={entityType}", entityId, entityType); + restTemplate.delete(baseURL + "/api/relations?entityId={entityId}&entityType={entityType}", entityId, entityType); } public Optional getRelation(String fromId, String fromType, String relationType, String relationTypeGroup, String toId, String toType) { @@ -1105,7 +1155,7 @@ public class RestClient implements ClientHttpRequestInterceptor { try { ResponseEntity entityRelation = restTemplate.getForEntity( - baseURL + "/relation?fromId={fromId}&fromType={fromType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}&toId={toId}&toType={toType}", + baseURL + "/api/relation?fromId={fromId}&fromType={fromType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}&toId={toId}&toType={toType}", EntityRelation.class, params); return Optional.ofNullable(entityRelation.getBody()); @@ -1125,7 +1175,7 @@ public class RestClient implements ClientHttpRequestInterceptor { params.put("relationTypeGroup", relationTypeGroup); return restTemplate.exchange( - baseURL + "/relations?fromId={fromId}&fromType={fromType}&relationTypeGroup={relationTypeGroup}", + baseURL + "/api/relations?fromId={fromId}&fromType={fromType}&relationTypeGroup={relationTypeGroup}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1134,14 +1184,13 @@ public class RestClient implements ClientHttpRequestInterceptor { } public List findInfoByFrom(String fromId, String fromType, String relationTypeGroup) { - Map params = new HashMap<>(); params.put("fromId", fromId); params.put("fromType", fromType); params.put("relationTypeGroup", relationTypeGroup); return restTemplate.exchange( - baseURL + "/relations/info?fromId={fromId}&fromType={fromType}&relationTypeGroup={relationTypeGroup}", + baseURL + "/api/relations/info?fromId={fromId}&fromType={fromType}&relationTypeGroup={relationTypeGroup}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1157,7 +1206,7 @@ public class RestClient implements ClientHttpRequestInterceptor { params.put("relationTypeGroup", relationTypeGroup); return restTemplate.exchange( - baseURL + "/relations?fromId={fromId}&fromType={fromType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}", + baseURL + "/api/relations?fromId={fromId}&fromType={fromType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1172,7 +1221,7 @@ public class RestClient implements ClientHttpRequestInterceptor { params.put("relationTypeGroup", relationTypeGroup); return restTemplate.exchange( - baseURL + "/relations?toId={toId}&toType={toType}&relationTypeGroup={relationTypeGroup}", + baseURL + "/api/relations?toId={toId}&toType={toType}&relationTypeGroup={relationTypeGroup}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1187,7 +1236,7 @@ public class RestClient implements ClientHttpRequestInterceptor { params.put("relationTypeGroup", relationTypeGroup); return restTemplate.exchange( - baseURL + "/relations?toId={toId}&toType={toType}&relationTypeGroup={relationTypeGroup}", + baseURL + "/api/relations?toId={toId}&toType={toType}&relationTypeGroup={relationTypeGroup}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1203,7 +1252,7 @@ public class RestClient implements ClientHttpRequestInterceptor { params.put("relationTypeGroup", relationTypeGroup); return restTemplate.exchange( - baseURL + "/relations?toId={toId}&toType={toType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}", + baseURL + "/api/relations?toId={toId}&toType={toType}&relationType={relationType}&relationTypeGroup={relationTypeGroup}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1213,7 +1262,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public List findByQuery(EntityRelationsQuery query) { return restTemplate.exchange( - baseURL + "/relations", + baseURL + "/api/relations", HttpMethod.POST, new HttpEntity<>(query), new ParameterizedTypeReference>() { @@ -1222,7 +1271,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public List findInfoByQuery(EntityRelationsQuery query) { return restTemplate.exchange( - baseURL + "/relations", + baseURL + "/api/relations", HttpMethod.POST, new HttpEntity<>(query), new ParameterizedTypeReference>() { @@ -1231,7 +1280,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getEntityViewById(String entityViewId) { try { - ResponseEntity entityView = restTemplate.getForEntity(baseURL + "/entityView/{entityViewId}", EntityView.class, entityViewId); + ResponseEntity entityView = restTemplate.getForEntity(baseURL + "/api/entityView/{entityViewId}", EntityView.class, entityViewId); return Optional.ofNullable(entityView.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1243,16 +1292,16 @@ public class RestClient implements ClientHttpRequestInterceptor { } public EntityView saveEntityView(EntityView entityView) { - return restTemplate.postForEntity(baseURL + "entityView", entityView, EntityView.class).getBody(); + return restTemplate.postForEntity(baseURL + "/api/entityView", entityView, EntityView.class).getBody(); } public void deleteEntityView(String entityViewId) { - restTemplate.delete(baseURL + "/entityView/{entityViewId}", entityViewId); + restTemplate.delete(baseURL + "/api/entityView/{entityViewId}", entityViewId); } public Optional getTenantEntityView(String entityViewName) { try { - ResponseEntity entityView = restTemplate.getForEntity(baseURL + "/tenant/entityViews?entityViewName={entityViewName}", EntityView.class, entityViewName); + ResponseEntity entityView = restTemplate.getForEntity(baseURL + "/api/tenant/entityViews?entityViewName={entityViewName}", EntityView.class, entityViewName); return Optional.ofNullable(entityView.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1265,7 +1314,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional assignEntityViewToCustomer(String customerId, String entityViewId) { try { - ResponseEntity entityView = restTemplate.postForEntity(baseURL + "/customer/{customerId}/entityView/{entityViewId}", null, EntityView.class, customerId, entityViewId); + ResponseEntity entityView = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/entityView/{entityViewId}", null, EntityView.class, customerId, entityViewId); return Optional.ofNullable(entityView.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1279,7 +1328,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional unassignEntityViewFromCustomer(String entityViewId) { try { ResponseEntity entityView = restTemplate.exchange( - baseURL + "/customer/entityView/{entityViewId}", + baseURL + "/api/customer/entityView/{entityViewId}", HttpMethod.DELETE, HttpEntity.EMPTY, EntityView.class, entityViewId); @@ -1299,7 +1348,7 @@ public class RestClient implements ClientHttpRequestInterceptor { params.put("type", type); addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/customer/{customerId}/entityViews?type={type}&" + TEXT_PAGE_LINK_URL_PARAMS, + baseURL + "/api/customer/{customerId}/entityViews?type={type}&" + TEXT_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1312,7 +1361,7 @@ public class RestClient implements ClientHttpRequestInterceptor { params.put("type", type); addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/tenant/entityViews?type={type}&" + TEXT_PAGE_LINK_URL_PARAMS, + baseURL + "/api/tenant/entityViews?type={type}&" + TEXT_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1321,18 +1370,18 @@ public class RestClient implements ClientHttpRequestInterceptor { } public List findByQuery(EntityViewSearchQuery query) { - return restTemplate.exchange(baseURL + "/entityViews", HttpMethod.POST, new HttpEntity<>(query), new ParameterizedTypeReference>() { + return restTemplate.exchange(baseURL + "/api/entityViews", HttpMethod.POST, new HttpEntity<>(query), new ParameterizedTypeReference>() { }).getBody(); } public List getEntityViewTypes() { - return restTemplate.exchange(baseURL + "/entityView/types", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { + return restTemplate.exchange(baseURL + "/api/entityView/types", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }).getBody(); } public Optional assignEntityViewToPublicCustomer(String entityViewId) { try { - ResponseEntity entityView = restTemplate.postForEntity(baseURL + "customer/public/entityView/{entityViewId}", null, EntityView.class, entityViewId); + ResponseEntity entityView = restTemplate.postForEntity(baseURL + "/api/customer/public/entityView/{entityViewId}", null, EntityView.class, entityViewId); return Optional.ofNullable(entityView.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1352,7 +1401,7 @@ public class RestClient implements ClientHttpRequestInterceptor { addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/events/{entityType}/{entityId}/{eventType}?tenantId={tenantId}&" + TIME_PAGE_LINK_URL_PARAMS, + baseURL + "/api/events/{entityType}/{entityId}/{eventType}?tenantId={tenantId}&" + TIME_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1368,7 +1417,7 @@ public class RestClient implements ClientHttpRequestInterceptor { addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/events/{entityType}/{entityId}?tenantId={tenantId}&" + TIME_PAGE_LINK_URL_PARAMS, + baseURL + "/api/events/{entityType}/{entityId}?tenantId={tenantId}&" + TIME_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1398,7 +1447,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getRuleChainById(String ruleChainId) { try { - ResponseEntity ruleChain = restTemplate.getForEntity(baseURL + "/ruleChain/{ruleChainId}", RuleChain.class, ruleChainId); + ResponseEntity ruleChain = restTemplate.getForEntity(baseURL + "/api/ruleChain/{ruleChainId}", RuleChain.class, ruleChainId); return Optional.ofNullable(ruleChain.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1411,7 +1460,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getRuleChainMetaData(String ruleChainId) { try { - ResponseEntity ruleChainMetaData = restTemplate.getForEntity(baseURL + "/ruleChain/{ruleChainId}/metadata", RuleChainMetaData.class, ruleChainId); + ResponseEntity ruleChainMetaData = restTemplate.getForEntity(baseURL + "/api/ruleChain/{ruleChainId}/metadata", RuleChainMetaData.class, ruleChainId); return Optional.ofNullable(ruleChainMetaData.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1423,12 +1472,12 @@ public class RestClient implements ClientHttpRequestInterceptor { } public RuleChain saveRuleChain(RuleChain ruleChain) { - return restTemplate.postForEntity(baseURL + "/ruleChain", ruleChain, RuleChain.class).getBody(); + return restTemplate.postForEntity(baseURL + "/api/ruleChain", ruleChain, RuleChain.class).getBody(); } public Optional setRootRuleChain(String ruleChainId) { try { - ResponseEntity ruleChain = restTemplate.postForEntity(baseURL + "/ruleChain/{ruleChainId}/root", null, RuleChain.class, ruleChainId); + ResponseEntity ruleChain = restTemplate.postForEntity(baseURL + "/api/ruleChain/{ruleChainId}/root", null, RuleChain.class, ruleChainId); return Optional.ofNullable(ruleChain.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1440,14 +1489,14 @@ public class RestClient implements ClientHttpRequestInterceptor { } public RuleChainMetaData saveRuleChainMetaData(RuleChainMetaData ruleChainMetaData) { - return restTemplate.postForEntity(baseURL + "/ruleChain/metadata", ruleChainMetaData, RuleChainMetaData.class).getBody(); + return restTemplate.postForEntity(baseURL + "/api/ruleChain/metadata", ruleChainMetaData, RuleChainMetaData.class).getBody(); } public TextPageData getRuleChains(TextPageLink pageLink) { Map params = new HashMap<>(); addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/ruleChains" + TEXT_PAGE_LINK_URL_PARAMS, + baseURL + "/api/ruleChains" + TEXT_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1456,12 +1505,12 @@ public class RestClient implements ClientHttpRequestInterceptor { } public void deleteRuleChain(String ruleChainId) { - restTemplate.delete(baseURL + "/ruleChain/{ruleChainId}", ruleChainId); + restTemplate.delete(baseURL + "/api/ruleChain/{ruleChainId}", ruleChainId); } public Optional getLatestRuleNodeDebugInput(String ruleNodeId) { try { - ResponseEntity jsonNode = restTemplate.getForEntity(baseURL + "/ruleNode/{ruleNodeId}/debugIn", JsonNode.class, ruleNodeId); + ResponseEntity jsonNode = restTemplate.getForEntity(baseURL + "/api/ruleNode/{ruleNodeId}/debugIn", JsonNode.class, ruleNodeId); return Optional.ofNullable(jsonNode.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1474,7 +1523,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional testScript(JsonNode inputParams) { try { - ResponseEntity jsonNode = restTemplate.postForEntity(baseURL + "/ruleChain/testScript", inputParams, JsonNode.class); + ResponseEntity jsonNode = restTemplate.postForEntity(baseURL + "/api/ruleChain/testScript", inputParams, JsonNode.class); return Optional.ofNullable(jsonNode.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1689,7 +1738,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getTenantById(String tenantId) { try { - ResponseEntity tenant = restTemplate.getForEntity(baseURL + "/tenant/{tenantId}", Tenant.class, tenantId); + ResponseEntity tenant = restTemplate.getForEntity(baseURL + "/api/tenant/{tenantId}", Tenant.class, tenantId); return Optional.ofNullable(tenant.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1701,11 +1750,11 @@ public class RestClient implements ClientHttpRequestInterceptor { } public Tenant saveTenant(Tenant tenant) { - return restTemplate.postForEntity(baseURL + "/tenant", tenant, Tenant.class).getBody(); + return restTemplate.postForEntity(baseURL + "/api/tenant", tenant, Tenant.class).getBody(); } public void deleteTenant(String tenantId) { - restTemplate.delete(baseURL + "/tenant/{tenantId}", tenantId); + restTemplate.delete(baseURL + "/api/tenant/{tenantId}", tenantId); } public TextPageData getTenants(TextPageLink pageLink) { @@ -1722,7 +1771,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getUserById(String userId) { try { - ResponseEntity user = restTemplate.getForEntity(baseURL + "/user/{userId}", User.class, userId); + ResponseEntity user = restTemplate.getForEntity(baseURL + "/api/user/{userId}", User.class, userId); return Optional.ofNullable(user.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1734,12 +1783,12 @@ public class RestClient implements ClientHttpRequestInterceptor { } public Boolean isUserTokenAccessEnabled() { - return restTemplate.getForEntity(baseURL + "/user/tokenAccessEnabled", Boolean.class).getBody(); + return restTemplate.getForEntity(baseURL + "/api/user/tokenAccessEnabled", Boolean.class).getBody(); } public Optional getUserToken(String userId) { try { - ResponseEntity userToken = restTemplate.getForEntity(baseURL + "/user/{userId}/token", JsonNode.class, userId); + ResponseEntity userToken = restTemplate.getForEntity(baseURL + "/api/user/{userId}/token", JsonNode.class, userId); return Optional.ofNullable(userToken.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1751,16 +1800,16 @@ public class RestClient implements ClientHttpRequestInterceptor { } public User saveUser(User user, boolean sendActivationMail) { - return restTemplate.postForEntity(baseURL + "/user?sendActivationMail={sendActivationMail}", user, User.class, sendActivationMail).getBody(); + return restTemplate.postForEntity(baseURL + "/api/user?sendActivationMail={sendActivationMail}", user, User.class, sendActivationMail).getBody(); } public void sendActivationEmail(String email) { - restTemplate.postForEntity(baseURL + "/user/sendActivationMail?email={email}", null, Object.class, email); + restTemplate.postForEntity(baseURL + "/api/user/sendActivationMail?email={email}", null, Object.class, email); } public Optional getActivationLink(String userId) { try { - ResponseEntity activationLink = restTemplate.getForEntity(baseURL + "/user/{userId}/activationLink", String.class, userId); + ResponseEntity activationLink = restTemplate.getForEntity(baseURL + "/api/user/{userId}/activationLink", String.class, userId); return Optional.ofNullable(activationLink.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1772,7 +1821,7 @@ public class RestClient implements ClientHttpRequestInterceptor { } public void deleteUser(String userId) { - restTemplate.delete(baseURL + "/user/{userId}", userId); + restTemplate.delete(baseURL + "/api/user/{userId}", userId); } // @RequestMapping(value = "/tenant/{tenantId}/users", params = {"limit"}, method = RequestMethod.GET) @@ -1796,7 +1845,7 @@ public class RestClient implements ClientHttpRequestInterceptor { addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/customer/{customerId}/users?" + TEXT_PAGE_LINK_URL_PARAMS, + baseURL + "/api/customer/{customerId}/users?" + TEXT_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1806,7 +1855,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public void setUserCredentialsEnabled(String userId, boolean userCredentialsEnabled) { restTemplate.postForEntity( - baseURL + "/user/{userId}/userCredentialsEnabled?serCredentialsEnabled={serCredentialsEnabled}", + baseURL + "/api/user/{userId}/userCredentialsEnabled?serCredentialsEnabled={serCredentialsEnabled}", null, Object.class, userId, @@ -1816,7 +1865,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getWidgetsBundleById(String widgetsBundleId) { try { ResponseEntity widgetsBundle = - restTemplate.getForEntity(baseURL + "/widgetsBundle/{widgetsBundleId}", WidgetsBundle.class, widgetsBundleId); + restTemplate.getForEntity(baseURL + "/api/widgetsBundle/{widgetsBundleId}", WidgetsBundle.class, widgetsBundleId); return Optional.ofNullable(widgetsBundle.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1828,18 +1877,18 @@ public class RestClient implements ClientHttpRequestInterceptor { } public WidgetsBundle saveWidgetsBundle(WidgetsBundle widgetsBundle) { - return restTemplate.postForEntity(baseURL + "/widgetsBundle", widgetsBundle, WidgetsBundle.class).getBody(); + return restTemplate.postForEntity(baseURL + "/api/widgetsBundle", widgetsBundle, WidgetsBundle.class).getBody(); } public void deleteWidgetsBundle(String widgetsBundleId) { - restTemplate.delete(baseURL + "/widgetsBundle/{widgetsBundleId}", widgetsBundleId); + restTemplate.delete(baseURL + "/api/widgetsBundle/{widgetsBundleId}", widgetsBundleId); } public TextPageData getWidgetsBundles(TextPageLink pageLink) { Map params = new HashMap<>(); addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/widgetsBundles?" + TEXT_PAGE_LINK_URL_PARAMS, + baseURL + "/api/widgetsBundles?" + TEXT_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1848,7 +1897,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public List getWidgetsBundles() { return restTemplate.exchange( - baseURL + "/widgetsBundles", + baseURL + "/api/widgetsBundles", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1858,7 +1907,7 @@ public class RestClient implements ClientHttpRequestInterceptor { public Optional getWidgetTypeById(String widgetTypeId) { try { ResponseEntity widgetType = - restTemplate.getForEntity(baseURL + "/widgetType/{widgetTypeId}", WidgetType.class, widgetTypeId); + restTemplate.getForEntity(baseURL + "/api/widgetType/{widgetTypeId}", WidgetType.class, widgetTypeId); return Optional.ofNullable(widgetType.getBody()); } catch (HttpClientErrorException exception) { if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { @@ -1870,16 +1919,16 @@ public class RestClient implements ClientHttpRequestInterceptor { } public WidgetType saveWidgetType(WidgetType widgetType) { - return restTemplate.postForEntity(baseURL + "/widgetType", widgetType, WidgetType.class).getBody(); + return restTemplate.postForEntity(baseURL + "/api/widgetType", widgetType, WidgetType.class).getBody(); } public void deleteWidgetType(String widgetTypeId) { - restTemplate.delete(baseURL + "/widgetType/{widgetTypeId}", widgetTypeId); + restTemplate.delete(baseURL + "/api/widgetType/{widgetTypeId}", widgetTypeId); } public List getBundleWidgetTypes(boolean isSystem, String bundleAlias) { return restTemplate.exchange( - baseURL + "/widgetTypes?isSystem={isSystem}&bundleAlias={bundleAlias}", + baseURL + "/api/widgetTypes?isSystem={isSystem}&bundleAlias={bundleAlias}", HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { @@ -1892,7 +1941,7 @@ public class RestClient implements ClientHttpRequestInterceptor { try { ResponseEntity widgetType = restTemplate.getForEntity( - baseURL + "/widgetType?isSystem={isSystem}&bundleAlias={bundleAlias}&alias={alias}", + baseURL + "/api/widgetType?isSystem={isSystem}&bundleAlias={bundleAlias}&alias={alias}", WidgetType.class, isSystem, bundleAlias,