From 5ba5518f6b9dffbf0fed7f3655b1635cd818bc1e Mon Sep 17 00:00:00 2001 From: "Smokowski, Steven" Date: Wed, 12 Feb 2020 11:13:08 -0500 Subject: mso to add support for creating the cloud region Initial check in to support cloud region create Add additional junit tests Add additional integration tests Updated junit to use spy and removed setter method Issue-ID: SO-2657 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I6a93f3b4caf7d640ffa5842981247d284b9013ad --- .../onap/so/db/catalog/client/CatalogDbClient.java | 57 +++++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) (limited to 'mso-catalog-db') diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java index 7f5907e9bf..161ca2a2fb 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java @@ -764,8 +764,61 @@ public class CatalogDbClient { return this.getSingleResource(cloudSiteClient, getUri(uri + id)); } - public void postCloudSite(CloudSite cloudSite) { - this.postSingleResource(cloudSiteClient, cloudSite); + public CloudSite postCloudSite(CloudSite cloudSite) { + if (cloudSite == null) { + throw new EntityNotFoundException("CloudSite passed as null"); + } + try { + HttpHeaders headers = getHttpHeaders(); + HttpEntity entity = new HttpEntity<>(cloudSite, headers); + CloudSite updatedCloudSite = restTemplate + .exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite").build().encode().toString(), + HttpMethod.POST, entity, CloudSite.class) + .getBody(); + return updatedCloudSite; + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSite.getId()); + } + throw e; + } + } + + public CloudSite updateCloudSite(CloudSite cloudSite) { + if (cloudSite == null) { + throw new EntityNotFoundException("CloudSite passed as null"); + } + try { + HttpHeaders headers = getHttpHeaders(); + HttpEntity entity = new HttpEntity<>(cloudSite, headers); + CloudSite updatedCloudSite = restTemplate + .exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite/" + cloudSite.getId()).build() + .encode().toString(), HttpMethod.PUT, entity, CloudSite.class) + .getBody(); + return updatedCloudSite; + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSite.getId()); + } + throw e; + } + } + + public void deleteCloudSite(String cloudSiteId) { + if (cloudSiteId == null) { + throw new EntityNotFoundException("CloudSiteId passed as null"); + } + try { + HttpHeaders headers = getHttpHeaders(); + HttpEntity entity = new HttpEntity<>(null, headers); + restTemplate.exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite/" + cloudSiteId).build() + .encode().toString(), HttpMethod.DELETE, entity, CloudSite.class).getBody(); + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSiteId); + } + throw e; + } } public List getCloudSites() { -- cgit 1.2.3-korg