Merge pull request #17 from BohdanSmetanyuk/ce_edge
more rest client methods for working with edge
This commit is contained in:
		
						commit
						4c626c4335
					
				@ -46,6 +46,7 @@ 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.edge.Edge;
 | 
			
		||||
import org.thingsboard.server.common.data.edge.EdgeEvent;
 | 
			
		||||
import org.thingsboard.server.common.data.edge.EdgeSearchQuery;
 | 
			
		||||
import org.thingsboard.server.common.data.alarm.AlarmInfo;
 | 
			
		||||
import org.thingsboard.server.common.data.alarm.AlarmSearchStatus;
 | 
			
		||||
@ -2015,6 +2016,42 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<Edge> assignEdgeToPublicCustomer(EdgeId edgeId) {
 | 
			
		||||
        try {
 | 
			
		||||
            ResponseEntity<Edge> edge = restTemplate.postForEntity(baseURL + "/api/customer/public/edge/{edgeId}", null, 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<RuleChain> setRootRuleChain(RuleChainId ruleChainId, EdgeId edgeId) {
 | 
			
		||||
        try {
 | 
			
		||||
            ResponseEntity<RuleChain> ruleChain = restTemplate.postForEntity(baseURL + "/api/edge/{edgeId}/{ruleChainId}/root", null, RuleChain.class, edgeId.getId(), ruleChainId.getId());
 | 
			
		||||
            return Optional.ofNullable(ruleChain.getBody());
 | 
			
		||||
        } catch (HttpClientErrorException exception) {
 | 
			
		||||
            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
 | 
			
		||||
                return Optional.empty();
 | 
			
		||||
            } else {
 | 
			
		||||
                throw exception;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TextPageData<Edge> getEdges(TextPageLink pageLink) {
 | 
			
		||||
        Map<String, String> params = new HashMap<>();
 | 
			
		||||
        addPageLinkToParam(params, pageLink);
 | 
			
		||||
        return restTemplate.exchange(
 | 
			
		||||
                baseURL + "/api/edges?" + getUrlParams(pageLink),
 | 
			
		||||
                HttpMethod.GET, HttpEntity.EMPTY,
 | 
			
		||||
                new ParameterizedTypeReference<TextPageData<Edge>>() {
 | 
			
		||||
                }, params).getBody();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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());
 | 
			
		||||
@ -2041,9 +2078,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<Device> unassignDeviceFromEdge(DeviceId deviceId) {
 | 
			
		||||
    public Optional<Device> unassignDeviceFromEdge(EdgeId edgeId, DeviceId deviceId) {
 | 
			
		||||
        try {
 | 
			
		||||
            ResponseEntity<Device> device = restTemplate.exchange(baseURL + "/api/edge/device/{deviceId}", HttpMethod.DELETE, HttpEntity.EMPTY, Device.class, deviceId.getId());
 | 
			
		||||
            ResponseEntity<Device> device = restTemplate.exchange(baseURL + "/api/edge/{edgeId}/device/{deviceId}", HttpMethod.DELETE, HttpEntity.EMPTY, Device.class, edgeId.getId(), deviceId.getId());
 | 
			
		||||
            return Optional.ofNullable(device.getBody());
 | 
			
		||||
        } catch (HttpClientErrorException exception) {
 | 
			
		||||
            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
 | 
			
		||||
@ -2054,13 +2091,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TextPageData<Device> getEdgeDevices(EdgeId edgeId, String deviceType, TextPageLink pageLink) {
 | 
			
		||||
    public TextPageData<Device> getEdgeDevices(EdgeId edgeId, 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),
 | 
			
		||||
                baseURL + "/api/edge/{edgeId}/devices?" + getUrlParams(pageLink),
 | 
			
		||||
                HttpMethod.GET, HttpEntity.EMPTY,
 | 
			
		||||
                new ParameterizedTypeReference<TextPageData<Device>>() {
 | 
			
		||||
                }, params).getBody();
 | 
			
		||||
@ -2079,9 +2115,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<Asset> unassignAssetFromEdge(AssetId assetId) {
 | 
			
		||||
    public Optional<Asset> unassignAssetFromEdge(EdgeId edgeId, AssetId assetId) {
 | 
			
		||||
        try {
 | 
			
		||||
            ResponseEntity<Asset> asset = restTemplate.exchange(baseURL + "/api/edge/asset/{assetId}", HttpMethod.DELETE, HttpEntity.EMPTY, Asset.class, assetId.getId());
 | 
			
		||||
            ResponseEntity<Asset> asset = restTemplate.exchange(baseURL + "/api/edge/{edgeId}/asset/{assetId}", HttpMethod.DELETE, HttpEntity.EMPTY, Asset.class, edgeId.getId(), assetId.getId());
 | 
			
		||||
            return Optional.ofNullable(asset.getBody());
 | 
			
		||||
        } catch (HttpClientErrorException exception) {
 | 
			
		||||
            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
 | 
			
		||||
@ -2092,18 +2128,129 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TextPageData<Asset> getEdgeAssets(EdgeId edgeId, String assetType, TextPageLink pageLink) {
 | 
			
		||||
    public TextPageData<Asset> getEdgeAssets(EdgeId edgeId, 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),
 | 
			
		||||
                baseURL + "/api/edge/{edgeId}/assets?" + getUrlParams(pageLink),
 | 
			
		||||
                HttpMethod.GET, HttpEntity.EMPTY,
 | 
			
		||||
                new ParameterizedTypeReference<TextPageData<Asset>>() {
 | 
			
		||||
                }, params).getBody();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<Dashboard> assignDashboardToEdge(EdgeId edgeId, DashboardId dashboardId) {
 | 
			
		||||
        try {
 | 
			
		||||
            ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/edge/{edgeId}/dashboard/{dashboardId}", null, Dashboard.class, edgeId.getId(), dashboardId.getId());
 | 
			
		||||
            return Optional.ofNullable(dashboard.getBody());
 | 
			
		||||
        } catch (HttpClientErrorException exception) {
 | 
			
		||||
            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
 | 
			
		||||
                return Optional.empty();
 | 
			
		||||
            } else {
 | 
			
		||||
                throw exception;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<Dashboard> unassignDashboardFromEdge(EdgeId edgeId, DashboardId dashboardId) {
 | 
			
		||||
        try {
 | 
			
		||||
            ResponseEntity<Dashboard> dashboard = restTemplate.exchange(baseURL + "/api/edge/{edgeId}/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, edgeId.getId(), dashboardId.getId());
 | 
			
		||||
            return Optional.ofNullable(dashboard.getBody());
 | 
			
		||||
        } catch (HttpClientErrorException exception) {
 | 
			
		||||
            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
 | 
			
		||||
                return Optional.empty();
 | 
			
		||||
            } else {
 | 
			
		||||
                throw exception;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TimePageData<DashboardInfo> getEdgeDashboards(EdgeId edgeId, TimePageLink pageLink) {
 | 
			
		||||
        Map<String, String> params = new HashMap<>();
 | 
			
		||||
        params.put("edgeId", edgeId.getId().toString());
 | 
			
		||||
        addPageLinkToParam(params, pageLink);
 | 
			
		||||
        return restTemplate.exchange(
 | 
			
		||||
                baseURL + "/api/edge/{edgeId}/dashboards?" + getUrlParams(pageLink),
 | 
			
		||||
                HttpMethod.GET, HttpEntity.EMPTY,
 | 
			
		||||
                new ParameterizedTypeReference<TimePageData<DashboardInfo>>() {
 | 
			
		||||
                }, params).getBody();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<EntityView> assignEntityViewToEdge(EdgeId edgeId, EntityViewId entityViewId) {
 | 
			
		||||
        try {
 | 
			
		||||
            ResponseEntity<EntityView> entityView = restTemplate.postForEntity(baseURL + "/api/edge/{edgeId}/entityView/{entityViewId}", null, EntityView.class, edgeId.getId(), entityViewId.getId());
 | 
			
		||||
            return Optional.ofNullable(entityView.getBody());
 | 
			
		||||
        } catch (HttpClientErrorException exception) {
 | 
			
		||||
            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
 | 
			
		||||
                return Optional.empty();
 | 
			
		||||
            } else {
 | 
			
		||||
                throw exception;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<EntityView> unassignEntityViewFromEdge(EdgeId edgeId, EntityViewId entityViewId) {
 | 
			
		||||
        try {
 | 
			
		||||
            ResponseEntity<EntityView> entityView = restTemplate.exchange(baseURL + "/api/edge/{edgeId}/entityView/{entityViewId}", HttpMethod.DELETE, HttpEntity.EMPTY, EntityView.class, edgeId.getId(), entityViewId.getId());
 | 
			
		||||
            return Optional.ofNullable(entityView.getBody());
 | 
			
		||||
        } catch (HttpClientErrorException exception) {
 | 
			
		||||
            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
 | 
			
		||||
                return Optional.empty();
 | 
			
		||||
            } else {
 | 
			
		||||
                throw exception;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TextPageData<EntityView> getEdgeEntityViews(EdgeId edgeId, TextPageLink pageLink) {
 | 
			
		||||
        Map<String, String> params = new HashMap<>();
 | 
			
		||||
        params.put("edgeId", edgeId.getId().toString());
 | 
			
		||||
        addPageLinkToParam(params, pageLink);
 | 
			
		||||
        return restTemplate.exchange(
 | 
			
		||||
                baseURL + "/api/edge/{edgeId}/entityViews?" + getUrlParams(pageLink),
 | 
			
		||||
                HttpMethod.GET,
 | 
			
		||||
                HttpEntity.EMPTY,
 | 
			
		||||
                new ParameterizedTypeReference<TextPageData<EntityView>>() {
 | 
			
		||||
                }, params).getBody();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<RuleChain> assignRuleChainToEdge(EdgeId edgeId, RuleChainId ruleChainId) {
 | 
			
		||||
        try {
 | 
			
		||||
            ResponseEntity<RuleChain> ruleChain = restTemplate.postForEntity(baseURL + "/api/edge/{edgeId}/ruleChain/{ruleChainId}", null, RuleChain.class, edgeId.getId(), ruleChainId.getId());
 | 
			
		||||
            return Optional.ofNullable(ruleChain.getBody());
 | 
			
		||||
        } catch (HttpClientErrorException exception) {
 | 
			
		||||
            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
 | 
			
		||||
                return Optional.empty();
 | 
			
		||||
            } else {
 | 
			
		||||
                throw exception;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<RuleChain> unassignRuleChainFromEdge(EdgeId edgeId, RuleChainId ruleChainId) {
 | 
			
		||||
        try {
 | 
			
		||||
            ResponseEntity<RuleChain> ruleChain = restTemplate.exchange(baseURL + "/api/edge/{edgeId}/ruleChain/{ruleChainId}", HttpMethod.DELETE, HttpEntity.EMPTY, RuleChain.class, edgeId.getId(), ruleChainId.getId());
 | 
			
		||||
            return Optional.ofNullable(ruleChain.getBody());
 | 
			
		||||
        } catch (HttpClientErrorException exception) {
 | 
			
		||||
            if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
 | 
			
		||||
                return Optional.empty();
 | 
			
		||||
            } else {
 | 
			
		||||
                throw exception;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TimePageData<RuleChain> getEdgeRuleChains(EdgeId edgeId, TimePageLink pageLink) {
 | 
			
		||||
        Map<String, String> params = new HashMap<>();
 | 
			
		||||
        params.put("edgeId", edgeId.getId().toString());
 | 
			
		||||
        addPageLinkToParam(params, pageLink);
 | 
			
		||||
        return restTemplate.exchange(
 | 
			
		||||
                baseURL + "/api/edge/{edgeId}/ruleChains?" + getUrlParams(pageLink),
 | 
			
		||||
                HttpMethod.GET, HttpEntity.EMPTY,
 | 
			
		||||
                new ParameterizedTypeReference<TimePageData<RuleChain>>() {
 | 
			
		||||
                }, params).getBody();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TextPageData<Edge> getTenantEdges(String type, TextPageLink pageLink) {
 | 
			
		||||
        Map<String, String> params = new HashMap<>();
 | 
			
		||||
        params.put("type", type);
 | 
			
		||||
@ -2165,6 +2312,19 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable {
 | 
			
		||||
                }).getBody();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TimePageData<EdgeEvent> getEdgeEvents(EdgeId edgeId, TimePageLink pageLink) {
 | 
			
		||||
        Map<String, String> params = new HashMap<>();
 | 
			
		||||
        params.put("edgeId", edgeId.toString());
 | 
			
		||||
        addPageLinkToParam(params, pageLink);
 | 
			
		||||
        return restTemplate.exchange(
 | 
			
		||||
                baseURL + "/api/edge/{edgeId}/events?" + getUrlParams(pageLink),
 | 
			
		||||
                HttpMethod.GET,
 | 
			
		||||
                HttpEntity.EMPTY,
 | 
			
		||||
                new ParameterizedTypeReference<TimePageData<EdgeEvent>>() {
 | 
			
		||||
                },
 | 
			
		||||
                params).getBody();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @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