...
Code Block | ||||
---|---|---|---|---|
| ||||
private void validateProperty (String propertyValue, String authorization) throws HookException { //Validate property with catalogue entry if (propertyValue != null) { if (!propertyValue.isBlank()) { String url = "http://catalog/api/catalogs/" + catalogueName + "/" + propertyValue; HttpHeaders headers = new HttpHeaders(); headers.set("Authorization", authorization); HttpEntity requestEntity = new HttpEntity<>(null, headers); try { ResponseEntity<Void> response = this.restTemplate.exchange(url, HttpMethod.HEAD, requestEntity, Void.class); if (HttpStatus.OK.equals(response.getStatusCode().is2xxSuccessful()) { LOGGER.debug("Property [" + propertyValue + "] validation was successful"); } else { throw new HookException("Catalogue [" + catalogueName + "] does not exist or property [" + propertyValue + "] does not match any catalogue entry."); } } catch (HttpStatusCodeException e) { if (HttpStatus.NOT_FOUND.equals(e.getStatusCode())) { throw new HookException("Catalogue [" + catalogueName + "] does not exist or property [" + propertyValue + "] does not match any catalogue entry."); } else { //Error handling throw new HookException("Something went wrong."); } } } else { throw new HookException("The property [" + propertyId + "] is empty."); } } else { LOGGER.debug("This object does not have the property: " + propertyId); } } |
...