diff --git a/application/src/main/java/org/thingsboard/server/controller/EventController.java b/application/src/main/java/org/thingsboard/server/controller/EventController.java index 8d08179409..1812a4f90f 100644 --- a/application/src/main/java/org/thingsboard/server/controller/EventController.java +++ b/application/src/main/java/org/thingsboard/server/controller/EventController.java @@ -24,7 +24,6 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.thingsboard.server.common.data.Event; -import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; import org.thingsboard.server.common.data.exception.ThingsboardException; import org.thingsboard.server.common.data.id.EntityId; import org.thingsboard.server.common.data.id.EntityIdFactory; @@ -32,9 +31,7 @@ import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.page.TimePageData; import org.thingsboard.server.common.data.page.TimePageLink; import org.thingsboard.server.dao.event.EventService; -import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.service.security.permission.Operation; -import org.thingsboard.server.service.security.permission.Resource; @RestController @RequestMapping("/api") 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 5296ea8129..e2d1326380 100644 --- a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java +++ b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java @@ -18,7 +18,6 @@ package org.thingsboard.client.tools; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; -import lombok.RequiredArgsConstructor; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; @@ -86,10 +85,9 @@ import java.util.Optional; /** * @author Andrew Shvayka */ -@RequiredArgsConstructor public class RestClient implements ClientHttpRequestInterceptor { private static final String JWT_TOKEN_HEADER_PARAM = "X-Authorization"; - protected final RestTemplate restTemplate = new RestTemplate(); + protected final RestTemplate restTemplate; protected final String baseURL; private String token; private String refreshToken; @@ -97,8 +95,19 @@ public class RestClient implements ClientHttpRequestInterceptor { 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}"; + protected static final String ACTIVATE_TOKEN_REGEX = "/api/noauth/activate?activateToken="; + public RestClient(String baseURL) { + this.restTemplate = new RestTemplate(); + this.baseURL = baseURL; + } + + public RestClient(RestTemplate restTemplate, String baseURL) { + this.restTemplate = restTemplate; + this.baseURL = baseURL; + } + @Override public ClientHttpResponse intercept(HttpRequest request, byte[] bytes, ClientHttpRequestExecution execution) throws IOException { HttpRequest wrapper = new HttpRequestWrapper(request); @@ -553,7 +562,7 @@ public class RestClient implements ClientHttpRequestInterceptor { HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, - assetIds).getBody(); + String.join(",", assetIds)).getBody(); } public List findByQuery(AssetSearchQuery query) { @@ -672,7 +681,8 @@ public class RestClient implements ClientHttpRequestInterceptor { } } - public ResponseEntity checkActivateToken(String activateToken) { + public ResponseEntity checkActivateToken(String userId) { + String activateToken = getActivateToken(userId); return restTemplate.getForEntity(baseURL + "/api/noauth/activate?activateToken={activateToken}", String.class, activateToken); } @@ -682,10 +692,6 @@ public class RestClient implements ClientHttpRequestInterceptor { restTemplate.exchange(URI.create(baseURL + "/api/noauth/resetPasswordByEmail"), HttpMethod.POST, new HttpEntity<>(resetPasswordByEmailRequest), Object.class); } - public ResponseEntity checkResetToken(String resetToken) { - return restTemplate.getForEntity(baseURL + "/api/noauth/resetPassword?resetToken={resetToken}", String.class, resetToken); - } - public Optional activateUser(String userId, String password) { ObjectNode activateRequest = objectMapper.createObjectNode(); activateRequest.put("activateToken", getActivateToken(userId)); @@ -702,22 +708,6 @@ public class RestClient implements ClientHttpRequestInterceptor { } } - public Optional resetPassword(String resetToken, String resetPassword) { - ObjectNode resetPasswordRequest = objectMapper.createObjectNode(); - resetPasswordRequest.put("resetToken", resetToken); - resetPasswordRequest.put("resetPassword", resetPassword); - try { - 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) { - return Optional.empty(); - } else { - throw exception; - } - } - } - public Optional getComponentDescriptorByClazz(String componentDescriptorClazz) { try { ResponseEntity componentDescriptor = restTemplate.getForEntity(baseURL + "/api/component/{componentDescriptorClazz}", ComponentDescriptor.class, componentDescriptorClazz); @@ -747,7 +737,7 @@ public class RestClient implements ClientHttpRequestInterceptor { HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, - componentTypes).getBody(); + String.join(",", componentTypes)).getBody(); } public Optional getCustomerById(String customerId) { @@ -1108,7 +1098,7 @@ public class RestClient implements ClientHttpRequestInterceptor { HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() { }, - deviceIds).getBody(); + String.join(",", deviceIds)).getBody(); } public List findByQuery(DeviceSearchQuery query) { @@ -1785,7 +1775,7 @@ public class RestClient implements ClientHttpRequestInterceptor { Map params = new HashMap<>(); addPageLinkToParam(params, pageLink); return restTemplate.exchange( - baseURL + "/tenants?" + TEXT_PAGE_LINK_URL_PARAMS, + baseURL + "/api/tenants?" + TEXT_PAGE_LINK_URL_PARAMS, HttpMethod.GET, HttpEntity.EMPTY, new ParameterizedTypeReference>() {