fix rest client

This commit is contained in:
Dima Landiak 2017-12-29 11:07:43 +02:00
parent f67a192e2b
commit 0aba2fcfe6

View File

@ -77,6 +77,21 @@ public class RestClient implements ClientHttpRequestInterceptor {
}
}
public Optional<Customer> findCustomer(String title) {
Map<String, String> params = new HashMap<String, String>();
params.put("customerTitle", title);
try {
ResponseEntity<Customer> customerEntity = restTemplate.getForEntity(baseURL + "/api/tenant/customers?customerTitle={customerTitle}", Customer.class, params);
return Optional.of(customerEntity.getBody());
} catch (HttpClientErrorException exception) {
if (exception.getStatusCode() == HttpStatus.NOT_FOUND) {
return Optional.empty();
} else {
throw exception;
}
}
}
public Optional<Asset> findAsset(String name) {
Map<String, String> params = new HashMap<String, String>();
params.put("assetName", name);
@ -138,10 +153,6 @@ public class RestClient implements ClientHttpRequestInterceptor {
return restTemplate.getForEntity(baseURL + "/api/device/" + id.getId().toString() + "/credentials", DeviceCredentials.class).getBody();
}
public Customer getCustomerByTitle(String title) {
return restTemplate.getForEntity(baseURL + "/api/tenant/customers?customerTitle=" + title, Customer.class).getBody();
}
public RestTemplate getRestTemplate() {
return restTemplate;
}