|
|
|
@ -45,7 +45,8 @@ 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.id.AlarmId; |
|
|
|
import org.thingsboard.server.common.data.edge.Edge; |
|
|
|
import org.thingsboard.server.common.data.edge.EdgeSearchQuery; |
|
|
|
import org.thingsboard.server.common.data.alarm.AlarmInfo; |
|
|
|
import org.thingsboard.server.common.data.alarm.AlarmSearchStatus; |
|
|
|
import org.thingsboard.server.common.data.alarm.AlarmSeverity; |
|
|
|
@ -56,10 +57,12 @@ import org.thingsboard.server.common.data.audit.ActionType; |
|
|
|
import org.thingsboard.server.common.data.audit.AuditLog; |
|
|
|
import org.thingsboard.server.common.data.device.DeviceSearchQuery; |
|
|
|
import org.thingsboard.server.common.data.entityview.EntityViewSearchQuery; |
|
|
|
import org.thingsboard.server.common.data.id.AlarmId; |
|
|
|
import org.thingsboard.server.common.data.id.AssetId; |
|
|
|
import org.thingsboard.server.common.data.id.CustomerId; |
|
|
|
import org.thingsboard.server.common.data.id.DashboardId; |
|
|
|
import org.thingsboard.server.common.data.id.DeviceId; |
|
|
|
import org.thingsboard.server.common.data.id.EdgeId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityId; |
|
|
|
import org.thingsboard.server.common.data.id.EntityViewId; |
|
|
|
import org.thingsboard.server.common.data.id.RuleChainId; |
|
|
|
@ -1978,6 +1981,190 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Edge saveEdge(Edge edge) { |
|
|
|
return restTemplate.postForEntity(baseURL + "/api/edge", edge, Edge.class).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public void deleteEdge(EdgeId edgeId) { |
|
|
|
restTemplate.delete(baseURL + "/api/edge/{edgeId}", edgeId.getId()); |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<Edge> getEdgeById(EdgeId edgeId) { |
|
|
|
try { |
|
|
|
ResponseEntity<Edge> edge = restTemplate.getForEntity(baseURL + "/api/edge/{edgeId}", Edge.class, edgeId.getId()); |
|
|
|
return Optional.ofNullable(edge.getBody()); |
|
|
|
} catch (HttpClientErrorException exception) { |
|
|
|
if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { |
|
|
|
return Optional.empty(); |
|
|
|
} else { |
|
|
|
throw exception; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<Edge> assignEdgeToCustomer(CustomerId customerId, EdgeId edgeId) { |
|
|
|
try { |
|
|
|
ResponseEntity<Edge> edge = restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/edge/{edgeId}", null, Edge.class, customerId.getId(), edgeId.getId()); |
|
|
|
return Optional.ofNullable(edge.getBody()); |
|
|
|
} catch (HttpClientErrorException exception) { |
|
|
|
if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { |
|
|
|
return Optional.empty(); |
|
|
|
} else { |
|
|
|
throw exception; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<Edge> unassignEdgeFromCustomer(EdgeId edgeId) { |
|
|
|
try { |
|
|
|
ResponseEntity<Edge> edge = restTemplate.exchange(baseURL + "/api/customer/edge/{edgeId}", HttpMethod.DELETE, HttpEntity.EMPTY, Edge.class, edgeId.getId()); |
|
|
|
return Optional.ofNullable(edge.getBody()); |
|
|
|
} catch (HttpClientErrorException exception) { |
|
|
|
if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { |
|
|
|
return Optional.empty(); |
|
|
|
} else { |
|
|
|
throw exception; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<Device> assignDeviceToEdge(EdgeId edgeId, DeviceId deviceId) { |
|
|
|
try { |
|
|
|
ResponseEntity<Device> device = restTemplate.postForEntity(baseURL + "/api/edge/{edgeId}/device/{deviceId}", null, Device.class, edgeId.getId(), deviceId.getId()); |
|
|
|
return Optional.ofNullable(device.getBody()); |
|
|
|
} catch (HttpClientErrorException exception) { |
|
|
|
if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { |
|
|
|
return Optional.empty(); |
|
|
|
} else { |
|
|
|
throw exception; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<Device> unassignDeviceFromEdge(DeviceId deviceId) { |
|
|
|
try { |
|
|
|
ResponseEntity<Device> device = restTemplate.exchange(baseURL + "/api/edge/device/{deviceId}", HttpMethod.DELETE, HttpEntity.EMPTY, Device.class, deviceId.getId()); |
|
|
|
return Optional.ofNullable(device.getBody()); |
|
|
|
} catch (HttpClientErrorException exception) { |
|
|
|
if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { |
|
|
|
return Optional.empty(); |
|
|
|
} else { |
|
|
|
throw exception; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public TextPageData<Device> getEdgeDevices(EdgeId edgeId, String deviceType, TextPageLink pageLink) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("edgeId", edgeId.getId().toString()); |
|
|
|
params.put("type", deviceType); |
|
|
|
addPageLinkToParam(params, pageLink); |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/edge/{edgeId}/devices?type={type}&" + getUrlParams(pageLink), |
|
|
|
HttpMethod.GET, HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<TextPageData<Device>>() { |
|
|
|
}, params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<Asset> assignAssetToEdge(EdgeId edgeId, AssetId assetId) { |
|
|
|
try { |
|
|
|
ResponseEntity<Asset> asset = restTemplate.postForEntity(baseURL + "/api/edge/{edgeId}/asset/{assetId}", null, Asset.class, edgeId.getId(), assetId.getId()); |
|
|
|
return Optional.ofNullable(asset.getBody()); |
|
|
|
} catch (HttpClientErrorException exception) { |
|
|
|
if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { |
|
|
|
return Optional.empty(); |
|
|
|
} else { |
|
|
|
throw exception; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<Asset> unassignAssetFromEdge(AssetId assetId) { |
|
|
|
try { |
|
|
|
ResponseEntity<Asset> asset = restTemplate.exchange(baseURL + "/api/edge/asset/{assetId}", HttpMethod.DELETE, HttpEntity.EMPTY, Asset.class, assetId.getId()); |
|
|
|
return Optional.ofNullable(asset.getBody()); |
|
|
|
} catch (HttpClientErrorException exception) { |
|
|
|
if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { |
|
|
|
return Optional.empty(); |
|
|
|
} else { |
|
|
|
throw exception; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public TextPageData<Asset> getEdgeAssets(EdgeId edgeId, String assetType, TextPageLink pageLink) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("edgeId", edgeId.getId().toString()); |
|
|
|
params.put("type", assetType); |
|
|
|
addPageLinkToParam(params, pageLink); |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/edge/{edgeId}/assets?type={type}&" + getUrlParams(pageLink), |
|
|
|
HttpMethod.GET, HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<TextPageData<Asset>>() { |
|
|
|
}, params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public TextPageData<Edge> getTenantEdges(String type, TextPageLink pageLink) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("type", type); |
|
|
|
addPageLinkToParam(params, pageLink); |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/tenant/edges?type={type}&" + getUrlParams(pageLink), |
|
|
|
HttpMethod.GET, HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<TextPageData<Edge>>() { |
|
|
|
}, params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public Optional<Edge> getTenantEdge(String edgeName) { |
|
|
|
try { |
|
|
|
ResponseEntity<Edge> edge = restTemplate.getForEntity(baseURL + "/api/tenant/edges?edgeName={edgeName}", Edge.class, edgeName); |
|
|
|
return Optional.ofNullable(edge.getBody()); |
|
|
|
} catch (HttpClientErrorException exception) { |
|
|
|
if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { |
|
|
|
return Optional.empty(); |
|
|
|
} else { |
|
|
|
throw exception; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public TextPageData<Edge> getCustomerEdges(CustomerId customerId, String edgeType, TextPageLink pageLink) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
params.put("customerId", customerId.getId().toString()); |
|
|
|
params.put("type", edgeType); |
|
|
|
addPageLinkToParam(params, pageLink); |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/customer/{customerId}/edges?type={type}&" + getUrlParams(pageLink), |
|
|
|
HttpMethod.GET, HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<TextPageData<Edge>>() { |
|
|
|
}, params).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public List<Edge> getEdgesByIds(List<EdgeId> edgeIds) { |
|
|
|
return restTemplate.exchange(baseURL + "/api/edges?edgeIds={edgeIds}", |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, new ParameterizedTypeReference<List<Edge>>() { |
|
|
|
}, listIdsToString(edgeIds)).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public List<Edge> findByQuery(EdgeSearchQuery query) { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/edges", |
|
|
|
HttpMethod.POST, |
|
|
|
new HttpEntity<>(query), |
|
|
|
new ParameterizedTypeReference<List<Edge>>() { |
|
|
|
}).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
public List<EntitySubtype> getEdgeTypes() { |
|
|
|
return restTemplate.exchange( |
|
|
|
baseURL + "/api/edge/types", |
|
|
|
HttpMethod.GET, |
|
|
|
HttpEntity.EMPTY, |
|
|
|
new ParameterizedTypeReference<List<EntitySubtype>>() { |
|
|
|
}).getBody(); |
|
|
|
} |
|
|
|
|
|
|
|
@Deprecated |
|
|
|
public Optional<JsonNode> getAttributes(String accessToken, String clientKeys, String sharedKeys) { |
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|