Commit b38f8b61f429ca16a02c68253b320ffdceccd90d
1 parent
1cfb7fa5
added all methods for working with Edge
Showing
1 changed file
with
157 additions
and
10 deletions
... | ... | @@ -2015,6 +2015,42 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { |
2015 | 2015 | } |
2016 | 2016 | } |
2017 | 2017 | |
2018 | + public Optional<Edge> assignEdgeToPublicCustomer(EdgeId edgeId) { | |
2019 | + try { | |
2020 | + ResponseEntity<Edge> edge = restTemplate.postForEntity(baseURL + "/api/customer/public/edge/{edgeId}", null, Edge.class, edgeId.getId()); | |
2021 | + return Optional.ofNullable(edge.getBody()); | |
2022 | + } catch (HttpClientErrorException exception) { | |
2023 | + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { | |
2024 | + return Optional.empty(); | |
2025 | + } else { | |
2026 | + throw exception; | |
2027 | + } | |
2028 | + } | |
2029 | + } | |
2030 | + | |
2031 | + public Optional<RuleChain> setRootRuleChain(RuleChainId ruleChainId, EdgeId edgeId) { | |
2032 | + try { | |
2033 | + ResponseEntity<RuleChain> ruleChain = restTemplate.postForEntity(baseURL + "/api/edge/{edgeId}/{ruleChainId}/root", null, RuleChain.class, edgeId.getId(), ruleChainId.getId()); | |
2034 | + return Optional.ofNullable(ruleChain.getBody()); | |
2035 | + } catch (HttpClientErrorException exception) { | |
2036 | + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { | |
2037 | + return Optional.empty(); | |
2038 | + } else { | |
2039 | + throw exception; | |
2040 | + } | |
2041 | + } | |
2042 | + } | |
2043 | + | |
2044 | + public TextPageData<Edge> getEdges(TextPageLink pageLink) { | |
2045 | + Map<String, String> params = new HashMap<>(); | |
2046 | + addPageLinkToParam(params, pageLink); | |
2047 | + return restTemplate.exchange( | |
2048 | + baseURL + "/api/edges?" + getUrlParams(pageLink), | |
2049 | + HttpMethod.GET, HttpEntity.EMPTY, | |
2050 | + new ParameterizedTypeReference<TextPageData<Edge>>() { | |
2051 | + }, params).getBody(); | |
2052 | + } | |
2053 | + | |
2018 | 2054 | public Optional<Edge> unassignEdgeFromCustomer(EdgeId edgeId) { |
2019 | 2055 | try { |
2020 | 2056 | ResponseEntity<Edge> edge = restTemplate.exchange(baseURL + "/api/customer/edge/{edgeId}", HttpMethod.DELETE, HttpEntity.EMPTY, Edge.class, edgeId.getId()); |
... | ... | @@ -2041,9 +2077,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { |
2041 | 2077 | } |
2042 | 2078 | } |
2043 | 2079 | |
2044 | - public Optional<Device> unassignDeviceFromEdge(DeviceId deviceId) { | |
2080 | + public Optional<Device> unassignDeviceFromEdge(EdgeId edgeId, DeviceId deviceId) { | |
2045 | 2081 | try { |
2046 | - ResponseEntity<Device> device = restTemplate.exchange(baseURL + "/api/edge/device/{deviceId}", HttpMethod.DELETE, HttpEntity.EMPTY, Device.class, deviceId.getId()); | |
2082 | + ResponseEntity<Device> device = restTemplate.exchange(baseURL + "/api/edge/{edgeId}/device/{deviceId}", HttpMethod.DELETE, HttpEntity.EMPTY, Device.class, edgeId.getId(), deviceId.getId()); | |
2047 | 2083 | return Optional.ofNullable(device.getBody()); |
2048 | 2084 | } catch (HttpClientErrorException exception) { |
2049 | 2085 | if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { |
... | ... | @@ -2054,13 +2090,12 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { |
2054 | 2090 | } |
2055 | 2091 | } |
2056 | 2092 | |
2057 | - public TextPageData<Device> getEdgeDevices(EdgeId edgeId, String deviceType, TextPageLink pageLink) { | |
2093 | + public TextPageData<Device> getEdgeDevices(EdgeId edgeId, TextPageLink pageLink) { | |
2058 | 2094 | Map<String, String> params = new HashMap<>(); |
2059 | 2095 | params.put("edgeId", edgeId.getId().toString()); |
2060 | - params.put("type", deviceType); | |
2061 | 2096 | addPageLinkToParam(params, pageLink); |
2062 | 2097 | return restTemplate.exchange( |
2063 | - baseURL + "/api/edge/{edgeId}/devices?type={type}&" + getUrlParams(pageLink), | |
2098 | + baseURL + "/api/edge/{edgeId}/devices?" + getUrlParams(pageLink), | |
2064 | 2099 | HttpMethod.GET, HttpEntity.EMPTY, |
2065 | 2100 | new ParameterizedTypeReference<TextPageData<Device>>() { |
2066 | 2101 | }, params).getBody(); |
... | ... | @@ -2079,9 +2114,9 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { |
2079 | 2114 | } |
2080 | 2115 | } |
2081 | 2116 | |
2082 | - public Optional<Asset> unassignAssetFromEdge(AssetId assetId) { | |
2117 | + public Optional<Asset> unassignAssetFromEdge(EdgeId edgeId, AssetId assetId) { | |
2083 | 2118 | try { |
2084 | - ResponseEntity<Asset> asset = restTemplate.exchange(baseURL + "/api/edge/asset/{assetId}", HttpMethod.DELETE, HttpEntity.EMPTY, Asset.class, assetId.getId()); | |
2119 | + ResponseEntity<Asset> asset = restTemplate.exchange(baseURL + "/api/edge/{edgeId}/asset/{assetId}", HttpMethod.DELETE, HttpEntity.EMPTY, Asset.class, edgeId.getId(), assetId.getId()); | |
2085 | 2120 | return Optional.ofNullable(asset.getBody()); |
2086 | 2121 | } catch (HttpClientErrorException exception) { |
2087 | 2122 | if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { |
... | ... | @@ -2092,18 +2127,130 @@ public class RestClient implements ClientHttpRequestInterceptor, Closeable { |
2092 | 2127 | } |
2093 | 2128 | } |
2094 | 2129 | |
2095 | - public TextPageData<Asset> getEdgeAssets(EdgeId edgeId, String assetType, TextPageLink pageLink) { | |
2130 | + public TextPageData<Asset> getEdgeAssets(EdgeId edgeId, TextPageLink pageLink) { | |
2096 | 2131 | Map<String, String> params = new HashMap<>(); |
2097 | 2132 | params.put("edgeId", edgeId.getId().toString()); |
2098 | - params.put("type", assetType); | |
2099 | 2133 | addPageLinkToParam(params, pageLink); |
2100 | 2134 | return restTemplate.exchange( |
2101 | - baseURL + "/api/edge/{edgeId}/assets?type={type}&" + getUrlParams(pageLink), | |
2135 | + baseURL + "/api/edge/{edgeId}/assets?" + getUrlParams(pageLink), | |
2102 | 2136 | HttpMethod.GET, HttpEntity.EMPTY, |
2103 | 2137 | new ParameterizedTypeReference<TextPageData<Asset>>() { |
2104 | 2138 | }, params).getBody(); |
2105 | 2139 | } |
2106 | 2140 | |
2141 | + public Optional<Dashboard> assignDashboardToEdge(EdgeId edgeId, DashboardId dashboardId) { | |
2142 | + try { | |
2143 | + ResponseEntity<Dashboard> dashboard = restTemplate.postForEntity(baseURL + "/api/edge/{edgeId}/dashboard/{dashboardId}", null, Dashboard.class, edgeId.getId(), dashboardId.getId()); | |
2144 | + return Optional.ofNullable(dashboard.getBody()); | |
2145 | + } catch (HttpClientErrorException exception) { | |
2146 | + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { | |
2147 | + return Optional.empty(); | |
2148 | + } else { | |
2149 | + throw exception; | |
2150 | + } | |
2151 | + } | |
2152 | + } | |
2153 | + | |
2154 | + public Optional<Dashboard> unassignDashboardFromEdge(EdgeId edgeId, DashboardId dashboardId) { | |
2155 | + try { | |
2156 | + ResponseEntity<Dashboard> dashboard = restTemplate.exchange(baseURL + "/api/edge/{edgeId}/dashboard/{dashboardId}", HttpMethod.DELETE, HttpEntity.EMPTY, Dashboard.class, edgeId.getId(), dashboardId.getId()); | |
2157 | + return Optional.ofNullable(dashboard.getBody()); | |
2158 | + } catch (HttpClientErrorException exception) { | |
2159 | + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { | |
2160 | + return Optional.empty(); | |
2161 | + } else { | |
2162 | + throw exception; | |
2163 | + } | |
2164 | + } | |
2165 | + } | |
2166 | + | |
2167 | + public TimePageData<DashboardInfo> getEdgeDashboards(EdgeId edgeId, TimePageLink pageLink) { | |
2168 | + Map<String, String> params = new HashMap<>(); | |
2169 | + params.put("edgeId", edgeId.getId().toString()); | |
2170 | + addPageLinkToParam(params, pageLink); | |
2171 | + return restTemplate.exchange( | |
2172 | + baseURL + "/api/edge/{edgeId}/dashboards?" + getUrlParams(pageLink), | |
2173 | + HttpMethod.GET, HttpEntity.EMPTY, | |
2174 | + new ParameterizedTypeReference<TimePageData<DashboardInfo>>() { | |
2175 | + }, params).getBody(); | |
2176 | + } | |
2177 | + | |
2178 | + public Optional<EntityView> assignEntityViewToEdge(EdgeId edgeId, EntityViewId entityViewId) { | |
2179 | + try { | |
2180 | + ResponseEntity<EntityView> entityView = restTemplate.postForEntity(baseURL + "/api/edge/{edgeId}/entityView/{entityViewId}", null, EntityView.class, edgeId.getId(), entityViewId.getId()); | |
2181 | + return Optional.ofNullable(entityView.getBody()); | |
2182 | + } catch (HttpClientErrorException exception) { | |
2183 | + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { | |
2184 | + return Optional.empty(); | |
2185 | + } else { | |
2186 | + throw exception; | |
2187 | + } | |
2188 | + } | |
2189 | + } | |
2190 | + | |
2191 | + public Optional<EntityView> unassignEntityViewFromEdge(EdgeId edgeId, EntityViewId entityViewId) { | |
2192 | + try { | |
2193 | + ResponseEntity<EntityView> entityView = restTemplate.exchange(baseURL + "/api/edge/{edgeId}/entityView/{entityViewId}", HttpMethod.DELETE, HttpEntity.EMPTY, EntityView.class, edgeId.getId(), entityViewId.getId()); | |
2194 | + return Optional.ofNullable(entityView.getBody()); | |
2195 | + } catch (HttpClientErrorException exception) { | |
2196 | + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { | |
2197 | + return Optional.empty(); | |
2198 | + } else { | |
2199 | + throw exception; | |
2200 | + } | |
2201 | + } | |
2202 | + } | |
2203 | + | |
2204 | + public TextPageData<EntityView> getEdgeEntityViews(EdgeId edgeId, String entityViewType, TextPageLink pageLink) { | |
2205 | + Map<String, String> params = new HashMap<>(); | |
2206 | + params.put("edgeId", edgeId.getId().toString()); | |
2207 | + params.put("type", entityViewType); | |
2208 | + addPageLinkToParam(params, pageLink); | |
2209 | + return restTemplate.exchange( | |
2210 | + baseURL + "/api/edge/{edgeId}/entityViews?type={type}&" + getUrlParams(pageLink), | |
2211 | + HttpMethod.GET, | |
2212 | + HttpEntity.EMPTY, | |
2213 | + new ParameterizedTypeReference<TextPageData<EntityView>>() { | |
2214 | + }, params).getBody(); | |
2215 | + } | |
2216 | + | |
2217 | + public Optional<RuleChain> assignRuleChainToEdge(EdgeId edgeId, RuleChainId ruleChainId) { | |
2218 | + try { | |
2219 | + ResponseEntity<RuleChain> ruleChain = restTemplate.postForEntity(baseURL + "/api/edge/{edgeId}/ruleChain/{ruleChainId}", null, RuleChain.class, edgeId.getId(), ruleChainId.getId()); | |
2220 | + return Optional.ofNullable(ruleChain.getBody()); | |
2221 | + } catch (HttpClientErrorException exception) { | |
2222 | + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { | |
2223 | + return Optional.empty(); | |
2224 | + } else { | |
2225 | + throw exception; | |
2226 | + } | |
2227 | + } | |
2228 | + } | |
2229 | + | |
2230 | + public Optional<RuleChain> unassignRuleChainFromEdge(EdgeId edgeId, RuleChainId ruleChainId) { | |
2231 | + try { | |
2232 | + ResponseEntity<RuleChain> ruleChain = restTemplate.exchange(baseURL + "/api/edge/{edgeId}/ruleChain/{ruleChainId}", HttpMethod.DELETE, HttpEntity.EMPTY, RuleChain.class, edgeId.getId(), ruleChainId.getId()); | |
2233 | + return Optional.ofNullable(ruleChain.getBody()); | |
2234 | + } catch (HttpClientErrorException exception) { | |
2235 | + if (exception.getStatusCode() == HttpStatus.NOT_FOUND) { | |
2236 | + return Optional.empty(); | |
2237 | + } else { | |
2238 | + throw exception; | |
2239 | + } | |
2240 | + } | |
2241 | + } | |
2242 | + | |
2243 | + public TimePageData<RuleChain> getEdgeRuleChains(EdgeId edgeId, TimePageLink pageLink) { | |
2244 | + Map<String, String> params = new HashMap<>(); | |
2245 | + params.put("edgeId", edgeId.getId().toString()); | |
2246 | + addPageLinkToParam(params, pageLink); | |
2247 | + return restTemplate.exchange( | |
2248 | + baseURL + "/api/edge/{edgeId}/ruleChains?" + getUrlParams(pageLink), | |
2249 | + HttpMethod.GET, HttpEntity.EMPTY, | |
2250 | + new ParameterizedTypeReference<TimePageData<RuleChain>>() { | |
2251 | + }, params).getBody(); | |
2252 | + } | |
2253 | + | |
2107 | 2254 | public TextPageData<Edge> getTenantEdges(String type, TextPageLink pageLink) { |
2108 | 2255 | Map<String, String> params = new HashMap<>(); |
2109 | 2256 | params.put("type", type); | ... | ... |