added queue to rest client
This commit is contained in:
parent
4dd2310a53
commit
a5c1cce884
@ -15,10 +15,7 @@
|
||||
*/
|
||||
package org.thingsboard.server.controller;
|
||||
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@ -38,14 +35,7 @@ import org.thingsboard.server.service.entitiy.queue.TbQueueService;
|
||||
import org.thingsboard.server.service.security.permission.Operation;
|
||||
import org.thingsboard.server.service.security.permission.Resource;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.thingsboard.server.controller.ControllerConstants.QUEUE_SERVICE_TYPE_ALLOWABLE_VALUES;
|
||||
import static org.thingsboard.server.controller.ControllerConstants.QUEUE_SERVICE_TYPE_DESCRIPTION;
|
||||
import static org.thingsboard.server.controller.ControllerConstants.TENANT_AUTHORITY_PARAGRAPH;
|
||||
|
||||
@RestController
|
||||
@TbCoreComponent
|
||||
|
||||
@ -37,7 +37,6 @@ import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.thingsboard.common.util.ThingsBoardExecutors;
|
||||
import org.thingsboard.rest.client.utils.RestJsonConverter;
|
||||
import org.thingsboard.server.common.data.AdminSettings;
|
||||
@ -91,6 +90,7 @@ import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.EntityViewId;
|
||||
import org.thingsboard.server.common.data.id.OAuth2ClientRegistrationTemplateId;
|
||||
import org.thingsboard.server.common.data.id.OtaPackageId;
|
||||
import org.thingsboard.server.common.data.id.QueueId;
|
||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||
import org.thingsboard.server.common.data.id.RuleNodeId;
|
||||
import org.thingsboard.server.common.data.id.TbResourceId;
|
||||
@ -119,6 +119,7 @@ import org.thingsboard.server.common.data.query.AlarmDataQuery;
|
||||
import org.thingsboard.server.common.data.query.EntityCountQuery;
|
||||
import org.thingsboard.server.common.data.query.EntityData;
|
||||
import org.thingsboard.server.common.data.query.EntityDataQuery;
|
||||
import org.thingsboard.server.common.data.queue.Queue;
|
||||
import org.thingsboard.server.common.data.relation.EntityRelation;
|
||||
import org.thingsboard.server.common.data.relation.EntityRelationInfo;
|
||||
import org.thingsboard.server.common.data.relation.EntityRelationsQuery;
|
||||
@ -146,7 +147,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.Collectors;
|
||||
@ -328,11 +328,11 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
params.put("entityType", entityId.getEntityType().name());
|
||||
params.put("entityId", entityId.getId().toString());
|
||||
params.put("fetchOriginator", String.valueOf(fetchOriginator));
|
||||
if(searchStatus != null) {
|
||||
if (searchStatus != null) {
|
||||
params.put("searchStatus", searchStatus.name());
|
||||
urlSecondPart += "&searchStatus={searchStatus}";
|
||||
}
|
||||
if(status != null) {
|
||||
if (status != null) {
|
||||
params.put("status", status.name());
|
||||
urlSecondPart += "&status={status}";
|
||||
}
|
||||
@ -340,7 +340,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
addTimePageLinkToParam(params, pageLink);
|
||||
|
||||
return restTemplate.exchange(
|
||||
baseURL + urlSecondPart + "&" + getTimeUrlParams(pageLink),
|
||||
baseURL + urlSecondPart + "&" + getTimeUrlParams(pageLink),
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<PageData<AlarmInfo>>() {
|
||||
@ -523,12 +523,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
|
||||
public List<Asset> getAssetsByIds(List<AssetId> assetIds) {
|
||||
return restTemplate.exchange(
|
||||
baseURL + "/api/assets?assetIds={assetIds}",
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<List<Asset>>() {
|
||||
},
|
||||
listIdsToString(assetIds))
|
||||
baseURL + "/api/assets?assetIds={assetIds}",
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<List<Asset>>() {
|
||||
},
|
||||
listIdsToString(assetIds))
|
||||
.getBody();
|
||||
}
|
||||
|
||||
@ -543,7 +543,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
|
||||
public List<EntitySubtype> getAssetTypes() {
|
||||
return restTemplate.exchange(URI.create(
|
||||
baseURL + "/api/asset/types"),
|
||||
baseURL + "/api/asset/types"),
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<List<EntitySubtype>>() {
|
||||
@ -746,13 +746,13 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
|
||||
public List<ComponentDescriptor> getComponentDescriptorsByTypes(List<ComponentType> componentTypes, RuleChainType ruleChainType) {
|
||||
return restTemplate.exchange(
|
||||
baseURL + "/api/components?componentTypes={componentTypes}&ruleChainType={ruleChainType}",
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<List<ComponentDescriptor>>() {
|
||||
},
|
||||
listEnumToString(componentTypes),
|
||||
ruleChainType)
|
||||
baseURL + "/api/components?componentTypes={componentTypes}&ruleChainType={ruleChainType}",
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<List<ComponentDescriptor>>() {
|
||||
},
|
||||
listEnumToString(componentTypes),
|
||||
ruleChainType)
|
||||
.getBody();
|
||||
}
|
||||
|
||||
@ -2904,7 +2904,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
baseURL + "/api/resource/{resourceId}/download",
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<>() {},
|
||||
new ParameterizedTypeReference<>() {
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
@ -2917,7 +2918,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
baseURL + "/api/resource/info/{resourceId}",
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<TbResourceInfo>() {},
|
||||
new ParameterizedTypeReference<TbResourceInfo>() {
|
||||
},
|
||||
params
|
||||
).getBody();
|
||||
}
|
||||
@ -2930,7 +2932,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
baseURL + "/api/resource/{resourceId}",
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<TbResource>() {},
|
||||
new ParameterizedTypeReference<TbResource>() {
|
||||
},
|
||||
params
|
||||
).getBody();
|
||||
}
|
||||
@ -2950,7 +2953,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
baseURL + "/api/resource?" + getUrlParams(pageLink),
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<PageData<TbResourceInfo>>() {},
|
||||
new ParameterizedTypeReference<PageData<TbResourceInfo>>() {
|
||||
},
|
||||
params
|
||||
).getBody();
|
||||
}
|
||||
@ -2967,7 +2971,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
baseURL + "/api/otaPackage/{otaPackageId}/download",
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<>() {},
|
||||
new ParameterizedTypeReference<>() {
|
||||
},
|
||||
params
|
||||
);
|
||||
}
|
||||
@ -2980,7 +2985,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
baseURL + "/api/otaPackage/info/{otaPackageId}",
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<OtaPackageInfo>() {},
|
||||
new ParameterizedTypeReference<OtaPackageInfo>() {
|
||||
},
|
||||
params
|
||||
).getBody();
|
||||
}
|
||||
@ -2993,7 +2999,8 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
baseURL + "/api/otaPackage/{otaPackageId}",
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<OtaPackage>() {},
|
||||
new ParameterizedTypeReference<OtaPackage>() {
|
||||
},
|
||||
params
|
||||
).getBody();
|
||||
}
|
||||
@ -3004,13 +3011,13 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
return restTemplate.postForEntity(baseURL + "/api/otaPackage?isUrl={isUrl}", otaPackageInfo, OtaPackageInfo.class, params).getBody();
|
||||
}
|
||||
|
||||
public OtaPackageInfo saveOtaPackageData(OtaPackageId otaPackageId, String checkSum, ChecksumAlgorithm checksumAlgorithm, MultipartFile file) throws Exception {
|
||||
public OtaPackageInfo saveOtaPackageData(OtaPackageId otaPackageId, String checkSum, ChecksumAlgorithm checksumAlgorithm, String fileName, byte[] fileBytes) throws Exception {
|
||||
HttpHeaders header = new HttpHeaders();
|
||||
header.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
|
||||
MultiValueMap<String, String> fileMap = new LinkedMultiValueMap<>();
|
||||
fileMap.add(HttpHeaders.CONTENT_DISPOSITION, "form-data; name=file; filename=" + file.getName());
|
||||
HttpEntity<ByteArrayResource> fileEntity = new HttpEntity<>(new ByteArrayResource(file.getBytes()), fileMap);
|
||||
fileMap.add(HttpHeaders.CONTENT_DISPOSITION, "form-data; name=file; filename=" + fileName);
|
||||
HttpEntity<ByteArrayResource> fileEntity = new HttpEntity<>(new ByteArrayResource(fileBytes), fileMap);
|
||||
|
||||
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
|
||||
body.add("file", fileEntity);
|
||||
@ -3021,7 +3028,7 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
params.put("checksumAlgorithm", checksumAlgorithm.name());
|
||||
String url = "/api/otaPackage/{otaPackageId}?checksumAlgorithm={checksumAlgorithm}";
|
||||
|
||||
if(checkSum != null) {
|
||||
if (checkSum != null) {
|
||||
url += "&checkSum={checkSum}";
|
||||
}
|
||||
|
||||
@ -3068,6 +3075,39 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
|
||||
restTemplate.delete(baseURL + "/api/otaPackage/{otaPackageId}", otaPackageId.getId().toString());
|
||||
}
|
||||
|
||||
public PageData<Queue> getQueuesByServiceType(String serviceType, PageLink pageLink) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("serviceType", serviceType);
|
||||
addPageLinkToParam(params, pageLink);
|
||||
|
||||
return restTemplate.exchange(
|
||||
baseURL + "/api/queues?{serviceType}&" + getUrlParams(pageLink),
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<PageData<Queue>>() {
|
||||
},
|
||||
params
|
||||
).getBody();
|
||||
}
|
||||
|
||||
public Queue getQueueById(QueueId queueId) {
|
||||
return restTemplate.exchange(
|
||||
baseURL + "/api/queue/" + queueId,
|
||||
HttpMethod.GET,
|
||||
HttpEntity.EMPTY,
|
||||
new ParameterizedTypeReference<Queue>() {
|
||||
}
|
||||
).getBody();
|
||||
}
|
||||
|
||||
public Queue saveQueue(Queue queue, String serviceType) {
|
||||
return restTemplate.postForEntity(baseURL + "/api/queues?serviceType=" + serviceType, queue, Queue.class).getBody();
|
||||
}
|
||||
|
||||
public void deleteQueue(QueueId queueId) {
|
||||
restTemplate.delete(baseURL + "/api/queues/" + queueId);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Optional<JsonNode> getAttributes(String accessToken, String clientKeys, String sharedKeys) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user