diff options
author | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-09-19 09:56:15 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-09-20 16:01:40 -0400 |
commit | a9696cdf3dd5da824eb23456b39e2897a15f03a8 (patch) | |
tree | 88b631cb9fad84b4be4c53e5236c40f7fa589531 /mso-api-handlers | |
parent | 7728df703f403ffc09e79b1bb85df412aa3cbd0d (diff) |
various bugfixes for casablanca
fixed unit tests after addition of A&AI edge label
added option for edgelabel between vnf inst group
added belongs to in connecting a vnf to instance group
- Adding test for
getRainyDayHandlerStatusByFlowNameAndServiceTypeAndVnfTypeAndErrorCodeAn
dWorkStep method in the catalogdb client
correct default RainyDay table search input
updated custom resolver to include float and added comment to explain
timestamp configuration
added a custom resolver and updated snake yaml version
Replacing bowman client with restTemplate.exchange | Add Accept and
Content-Type to headers
Removing the unused imports as well
Implementing some review comments for hte tests being ignored
Replacing bowman client with restTemplate.exchange |Fixing Junits
Replacing bowman client with restTemplate.exchange | Making Data
inserts to go specifically in requestDB
Replacing bowman client with restTemplate.exchange | Adding Junits
Replacing bowman client with restTemplate.exchange | Adding Junits
Replacing bowman client with restTemplate.exchange | Adding Junits
Replacing bowman client with restTemplate.exchange
- Updated tosca parser version to 1.4.3 and upgraded vnfc test case
with new csar to pass with latest parser code.
added test case for when workflow has not called all flows
fixed issue with rollback and retry in workflowaction
Reverted homing changes and changes assign vnf to use the homing
produced GeneralBuildingBlock.
fixed unit test to build the correct format hashmap
reverted extraction back to LinkedHashMap
marshal sdnc output to an object
removed unused variables and imports
extract response code/message from embedded map
add junits to parse SDNC assign response
removed missed org.openecomp.mso imports from bpmn
Change-Id: Ib2b6591a744ecb5b08c522494cdf1ad7dae18a08
Issue-ID: SO-1069
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-api-handlers')
3 files changed, 90 insertions, 100 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java index 9a5334081f..29fa1a34b3 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfStatusOperationalEnvironmentTest.java @@ -76,8 +76,8 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{ private final int retryCountThree = 3; private final int retryCountTwo = 2; private final int retryCountZero = 0; + private final String sdcDistributionId1 = "TEST_distributionId1"; private final String sdcDistributionId = "TEST_distributionId"; - private final String sdcDistributionId1 = "TEST_distributionId1"; private final String statusOk = Status.DISTRIBUTION_COMPLETE_OK.toString(); private final String statusError = DistributionStatus.DISTRIBUTION_COMPLETE_ERROR.toString(); private final String statusSent = "SENT"; @@ -221,12 +221,12 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{ .withBody(mapper.writeValueAsString(iar)) .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/")) - .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"recoveryAction\":\"RETRY\",\"retryCount\":0,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}")) + .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"recoveryAction\":\"RETRY\",\"retryCount\":0,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null}")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/")) - .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}")) + .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null}")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); @@ -290,12 +290,11 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{ .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/")) - .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId1\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"SENT\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null}")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/")) - .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"SENT\",\"recoveryAction\":\"RETRY\",\"retryCount\":2,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}")) + .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"SENT\",\"recoveryAction\":\"RETRY\",\"retryCount\":2,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null}")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); @@ -491,12 +490,12 @@ public class ActivateVnfStatusOperationalEnvironmentTest extends BaseTest{ .withBody(mapper.writeValueAsString(iar)) .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/operationalEnvServiceModelStatus/")) - .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"recoveryAction\":\"SKIP\",\"retryCount\":0,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}")) + .withRequestBody(equalTo("{\"requestId\":\"TEST_requestIdOrig\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"serviceModelVersionDistrStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"recoveryAction\":\"SKIP\",\"retryCount\":0,\"workloadContext\":\"TEST_workloadContext\",\"createTime\":null,\"modifyTime\":null}")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); stubFor(post(urlPathEqualTo("/operationalEnvDistributionStatus/")) - .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null,\"handler\":{}}")) + .withRequestBody(equalTo("{\"distributionId\":\"TEST_distributionId\",\"operationalEnvId\":\"TEST_operationalEnvironmentId\",\"serviceModelVersionId\":\"TEST_serviceModelVersionId\",\"requestId\":\"TEST_requestIdOrig\",\"distributionIdStatus\":\"DISTRIBUTION_COMPLETE_OK\",\"distributionIdErrorReason\":\"\",\"createTime\":null,\"modifyTime\":null}")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withStatus(HttpStatus.SC_OK))); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/data.sql b/mso-api-handlers/mso-api-handler-infra/src/test/resources/data.sql index 70c0791055..afcd7330f3 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/data.sql +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/data.sql @@ -275,7 +275,16 @@ VALUES ('vfModule', 'replaceInstance', '1', 'Gr api recipe to replace vf-module', '/mso/async/services/WorkflowActionBB', 180, 'GR-API-DEFAULT'), ('vfModule', 'deactivateAndCloudDelete', '1', 'Gr api recipe to deactivateAndCloudDelete vf-module', '/mso/async/services/WorkflowActionBB', 180, 'GR-API-DEFAULT'), ('vfModule', 'scaleOut', '1', 'Gr api recipe to scale out vfModule', '/mso/async/services/WorkflowActionBB', '180', 'GR-API-DEFAULT'); +INSERT INTO requestdb.activate_operational_env_service_model_distribution_status (OPERATIONAL_ENV_ID, SERVICE_MODEL_VERSION_ID, REQUEST_ID,SERVICE_MOD_VER_FINAL_DISTR_STATUS,RECOVERY_ACTION,RETRY_COUNT_LEFT,WORKLOAD_CONTEXT, CREATE_TIME, MODIFY_TIME) +VALUES +('1234', 'TEST1234', '00032ab7-3fb3-42e5-965d-8ea592502017', "Test", "Test", 1, 'DEFAULT', '2018-08-14 16:50:59', '2018-08-14 16:50:59'); +INSERT INTO requestdb.activate_operational_env_service_model_distribution_status (OPERATIONAL_ENV_ID, SERVICE_MODEL_VERSION_ID, REQUEST_ID,SERVICE_MOD_VER_FINAL_DISTR_STATUS,RECOVERY_ACTION,RETRY_COUNT_LEFT,WORKLOAD_CONTEXT, CREATE_TIME, MODIFY_TIME) +VALUES +('1234', 'TEST1235', '00032ab7-3fb3-42e5-965d-8ea592502017', "Test", "Test", 2, 'DEFAULT', '2018-08-14 16:50:59', '2018-08-14 16:50:59'); +INSERT INTO requestdb.activate_operational_env_per_distributionid_status (DISTRIBUTION_ID, DISTRIBUTION_ID_STATUS, DISTRIBUTION_ID_ERROR_REASON, CREATE_TIME, MODIFY_TIME, OPERATIONAL_ENV_ID, SERVICE_MODEL_VERSION_ID, REQUEST_ID) +VALUES +('111', 'TEST', 'ERROR', '2018-09-12 19:29:24', '2018-09-12 19:29:25', '1234', 'TEST1234', '00032ab7-3fb3-42e5-965d-8ea592502017'); UPDATE vnf_components_recipe SET vf_module_model_uuid = 'VNF-API-DEFAULT' diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java index 6ab92853d1..e68bdb3772 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java @@ -36,36 +36,29 @@ import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest; import org.onap.so.logging.jaxrs.filter.SpringClientFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Primary; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.http.HttpRequest; import org.springframework.http.client.BufferingClientHttpRequestFactory; -import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestFactory; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.stereotype.Component; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; -import uk.co.blackpepper.bowman.Client; import uk.co.blackpepper.bowman.ClientFactory; import uk.co.blackpepper.bowman.Configuration; -import uk.co.blackpepper.bowman.RestTemplateConfigurer; import javax.annotation.PostConstruct; +import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; -import java.io.IOException; import java.net.URI; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Iterator; @Component("RequestsDbClient") @Primary @@ -74,14 +67,10 @@ public class RequestsDbClient { private static final String SERVICE_ID = "SERVICE_ID"; private static final String OPERATION_ID = "OPERATION_ID"; private static final String SO_REQUEST_ID = "SO_REQUEST_ID"; - private static final String GROUPING_ID = "GROUPING_ID"; private static final String REQUEST_ID = "REQUEST_ID"; - private static final String OPERATIONAL_ENVIRONMENT_ID = "OPERATIONAL_ENVIRONMENT_ID"; + private static final String OPERATIONAL_ENVIRONMENT_ID = "OPERATIONAL_ENV_ID"; private static final String SERVICE_MODEL_VERSION_ID = "SERVICE_MODEL_VERSION_ID"; - private static final String NAME = "NAME"; - private static final String VALUE = "VALUE"; - private static final String TAG = "TAG"; - + @Value("${mso.adapters.requestDb.endpoint}") protected String endpoint; @@ -112,9 +101,7 @@ public class RequestsDbClient { private String requestProcessingDataURI = "/requestProcessingData"; - private String findOneBySoRequestIdAndGroupingIdAndNameAndTagURI = "/requestProcessingData/search/findOneBySoRequestIdAndGroupingIdAndNameAndTag/"; - - private String findBySoRequestIdOrderByGroupingIdDesc = "/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/"; + private final String findBySoRequestIdOrderByGroupingIdDesc = "/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc"; @Autowired @@ -137,8 +124,8 @@ public class RequestsDbClient { findAllByOperationalEnvIdAndRequestIdURI = endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findAllByOperationalEnvIdAndRequestIdURI; } - public ClientFactory getClientFactory(){ - URI baseUri = UriBuilder.fromUri(endpoint).build(); + private ClientFactory getClientFactory(){ + URI baseUri = UriBuilder.fromUri(endpoint).build(); ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory()); return Configuration.builder().setBaseUri(baseUri).setClientHttpRequestFactory(factory).setRestTemplateConfigurer(restTemplate -> { @@ -152,11 +139,10 @@ public class RequestsDbClient { }).build().buildClientFactory(); } - + public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive(Map<String, String> orchestrationMap){ URI uri = getUri(cloudOrchestrationFiltersFromInfraActive); - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); + HttpHeaders headers = getHttpHeaders(); HttpEntity<Map> entity = new HttpEntity<>(orchestrationMap, headers); try{ return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {}).getBody(); @@ -170,10 +156,8 @@ public class RequestsDbClient { public InfraActiveRequests getInfraActiveRequestbyRequestId(String requestId) { try { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); - HttpEntity<?> entity = new HttpEntity<>(headers); - InfraActiveRequests infraActiveRequests = restTemplate.exchange(getUri(endpoint + "/infraActiveRequests/" + requestId), HttpMethod.GET, entity, InfraActiveRequests.class).getBody(); + HttpEntity<?> entity = getHttpEntity(); + InfraActiveRequests infraActiveRequests = restTemplate.exchange(getUri(endpoint + "/infraActiveRequests/" + requestId), HttpMethod.GET, entity, InfraActiveRequests.class).getBody(); if (infraActiveRequests != null) { infraActiveRequests.setRequestId(requestId); } @@ -187,24 +171,20 @@ public class RequestsDbClient { } public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive(Map<String, List<String>> orchestrationMap) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); + HttpHeaders headers = getHttpHeaders(); URI uri = getUri(getOrchestrationFilterURI); HttpEntity<Map<String, List<String>>> entity = new HttpEntity<>(orchestrationMap, headers); return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {}).getBody(); } public InfraActiveRequests checkVnfIdStatus(String operationalEnvironmentId) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); - HttpEntity<?> entity = new HttpEntity<>(headers); + HttpEntity<?> entity = getHttpEntity(); URI uri = getUri(checkVnfIdStatus + operationalEnvironmentId); return restTemplate.exchange(uri, HttpMethod.GET, entity, InfraActiveRequests.class).getBody(); } public InfraActiveRequests checkInstanceNameDuplicate(HashMap<String, String> instanceIdMap, String instanceName, String requestScope) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); + HttpHeaders headers = getHttpHeaders(); URI uri = getUri(checkInstanceNameDuplicate); HttpEntity<InstanceNameDuplicateCheckRequest> entity = new HttpEntity<>(new InstanceNameDuplicateCheckRequest(instanceIdMap, instanceName, requestScope), headers); try{ @@ -220,13 +200,11 @@ public class RequestsDbClient { public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId) { try { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); - HttpEntity<?> entity = new HttpEntity<>(headers); - OperationStatus operationStatus = restTemplate.exchange(UriBuilder.fromUri(getUri(findOneByServiceIdAndOperationIdURI)) + HttpEntity<?> entity = getHttpEntity(); + OperationStatus operationStatus = restTemplate.exchange(getUri(UriBuilder.fromUri(getUri(findOneByServiceIdAndOperationIdURI)) .queryParam(SERVICE_ID, serviceId) .queryParam(OPERATION_ID, operationId) - .build(), HttpMethod.GET, entity, OperationStatus.class).getBody(); + .build().toString()), HttpMethod.GET, entity, OperationStatus.class).getBody(); if (operationStatus != null) { operationStatus.setServiceId(serviceId); operationStatus.setOperationId(operationId); @@ -240,27 +218,49 @@ public class RequestsDbClient { throw e; } } - + public OperationalEnvServiceModelStatus findOneByOperationalEnvIdAndServiceModelVersionId(String operationalEnvironmentId, String serviceModelVersionId) { - return this.getSingleOperationalEnvServiceModelStatus(UriBuilder.fromUri(findOneByOperationalEnvIdAndServiceModelVersionIdURI) - .queryParam(OPERATIONAL_ENVIRONMENT_ID,operationalEnvironmentId) - .queryParam(SERVICE_MODEL_VERSION_ID,serviceModelVersionId) - .build()); + try { + HttpEntity<?> entity = getHttpEntity(); + OperationalEnvServiceModelStatus modelStatus = restTemplate.exchange(getUri(UriBuilder.fromUri(findOneByOperationalEnvIdAndServiceModelVersionIdURI) + .queryParam(OPERATIONAL_ENVIRONMENT_ID, operationalEnvironmentId) + .queryParam(SERVICE_MODEL_VERSION_ID, serviceModelVersionId) + .build().toString()), HttpMethod.GET, entity, OperationalEnvServiceModelStatus.class).getBody(); + if (null != modelStatus) { + modelStatus.setOperationalEnvId(operationalEnvironmentId); + modelStatus.setServiceModelVersionId(serviceModelVersionId); + } + return modelStatus; + }catch(HttpClientErrorException e){ + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + return null; + } + throw e; + } } public List<OperationalEnvServiceModelStatus> getAllByOperationalEnvIdAndRequestId(String operationalEnvironmentId, String requestId){ - return this.getMultipleOperationalEnvServiceModelStatus(UriBuilder.fromUri(findAllByOperationalEnvIdAndRequestIdURI) + return this.getMultipleOperationalEnvServiceModelStatus(getUri(UriBuilder.fromUri(findAllByOperationalEnvIdAndRequestIdURI) .queryParam(OPERATIONAL_ENVIRONMENT_ID,operationalEnvironmentId) .queryParam(REQUEST_ID,requestId) - .build()); + .build().toString())); } public OperationalEnvDistributionStatus getDistributionStatusById(String distributionId){ - return this.getSingleOperationalEnvDistributionStatus(UriBuilder.fromUri(operationalEnvDistributionStatusURI+distributionId).build()); - } - - private OperationalEnvServiceModelStatus getSingleOperationalEnvServiceModelStatus(URI uri){ - return getClientFactory().create(OperationalEnvServiceModelStatus.class).get(uri); + try { + HttpEntity<?> entity = getHttpEntity(); + OperationalEnvDistributionStatus distributionStatus = restTemplate.exchange(getUri(operationalEnvDistributionStatusURI + distributionId), + HttpMethod.GET, entity, OperationalEnvDistributionStatus.class).getBody(); + if(null != distributionStatus){ + distributionStatus.setDistributionId(distributionId); + } + return distributionStatus; + }catch(HttpClientErrorException e){ + if(HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()){ + return null; + } + throw e; + } } private List<OperationalEnvServiceModelStatus> getMultipleOperationalEnvServiceModelStatus(URI uri){ @@ -270,32 +270,23 @@ public class RequestsDbClient { statusIterator.forEachRemaining(serviceModelStatuses::add); return serviceModelStatuses; } - + public void save(InfraActiveRequests infraActiveRequests) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); + HttpHeaders headers = getHttpHeaders(); URI uri = getUri(infraActiveRequestURI); HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(infraActiveRequests, headers); restTemplate.postForLocation(uri, entity); } public <T> void save(T object){ - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); + HttpHeaders headers = getHttpHeaders(); URI uri = getUri(endpoint+classURLMapper.getURI(object.getClass())); HttpEntity<T> entity = new HttpEntity<>(object, headers); restTemplate.postForLocation(uri, entity); } - private OperationalEnvDistributionStatus getSingleOperationalEnvDistributionStatus(URI uri){ - return getClientFactory().create(OperationalEnvDistributionStatus.class).get(uri); - } - - public void updateInfraActiveRequests(InfraActiveRequests request) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); - headers.set(HttpHeaders.CONTENT_TYPE,"application/json"); - headers.set(HttpHeaders.ACCEPT, "application/json"); + public void updateInfraActiveRequests(InfraActiveRequests request) { + HttpHeaders headers = getHttpHeaders(); URI uri = getUri(infraActiveRequestURI+request.getRequestId()); HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(request, headers); restTemplate.put(uri, entity); @@ -306,32 +297,18 @@ public class RequestsDbClient { } public void saveRequestProcessingData(RequestProcessingData requestProcessingData) { - HttpHeaders headers = new HttpHeaders(); - headers.set("Authorization", msoAdaptersAuth); + HttpHeaders headers = getHttpHeaders(); URI uri = getUri(endpoint + requestProcessingDataURI); HttpEntity<RequestProcessingData> entity = new HttpEntity<>(requestProcessingData, headers); restTemplate.postForLocation(uri, entity); } - - public RequestProcessingData getRequestProcessingDataBySoRequestIdAndGroupingIdAndNameAndTag(String soRequestId, - String groupingId, String name, String tag) { - return this.getSingleRequestProcessingData(UriBuilder.fromUri(endpoint + findOneBySoRequestIdAndGroupingIdAndNameAndTagURI) - .queryParam(SO_REQUEST_ID,soRequestId) - .queryParam(GROUPING_ID,groupingId) - .queryParam(NAME,name) - .queryParam(TAG,tag) - .build()); - } + public List<RequestProcessingData> getRequestProcessingDataBySoRequestId(String soRequestId) { - return this.getRequestProcessingData(UriBuilder.fromUri(endpoint + findBySoRequestIdOrderByGroupingIdDesc) + return this.getRequestProcessingData(getUri(UriBuilder.fromUri(endpoint + findBySoRequestIdOrderByGroupingIdDesc) .queryParam(SO_REQUEST_ID,soRequestId) - .build()); + .build().toString())); } - - public RequestProcessingData getSingleRequestProcessingData(URI uri){ - return getClientFactory().create(RequestProcessingData.class).get(uri); - } - + private List<RequestProcessingData> getRequestProcessingData(URI uri) { Iterable<RequestProcessingData> requestProcessingDataIterator = getClientFactory().create(RequestProcessingData.class).getAll(uri); List<RequestProcessingData> requestProcessingDataList = new ArrayList<>(); @@ -339,15 +316,6 @@ public class RequestsDbClient { it.forEachRemaining(requestProcessingDataList::add); return requestProcessingDataList; } - - public List<RequestProcessingData> getAllRequestProcessingData() { - - return (List<RequestProcessingData>) this.getAllRequestProcessingData(UriBuilder.fromUri(endpoint + "/requestProcessingData").build()); - } - - private Iterable<RequestProcessingData> getAllRequestProcessingData(URI uri) { - return getClientFactory().create(RequestProcessingData.class).getAll(uri); - } @Component static class ClassURLMapper { @@ -385,4 +353,18 @@ public class RequestsDbClient { public void removePortFromEndpoint() { endpoint = endpoint.substring(0, endpoint.lastIndexOf(':') + 1); } + + private HttpHeaders getHttpHeaders() { + HttpHeaders headers = new HttpHeaders(); + headers.set(HttpHeaders.AUTHORIZATION, msoAdaptersAuth); + headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); + headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); + return headers; + } + + private HttpEntity<?> getHttpEntity() { + HttpHeaders headers = getHttpHeaders(); + return new HttpEntity<>(headers); + } + } |