diff options
Diffstat (limited to 'mso-api-handlers')
8 files changed, 117 insertions, 12 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java index cf4e63529c..12f2a07993 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java @@ -9,9 +9,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -131,7 +131,7 @@ public class OrchestrationRequests { infraActiveRequest = infraActiveRequestLookup(requestId); try { - requestProcessingData = requestsDbClient.getRequestProcessingDataBySoRequestId(requestId); + requestProcessingData = requestsDbClient.getExternalRequestProcessingDataBySoRequestId(requestId); } catch (Exception e) { logger.error("Exception occurred while communicating with RequestDb during requestProcessingData lookup ", e); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java index 151785dbeb..a0b9fead4e 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java @@ -107,6 +107,18 @@ public class OrchestrationRequestsTest extends BaseTest { .withBody(new String(Files.readAllBytes(Paths.get( "src/test/resources/OrchestrationRequest/ActivityInstanceHistoryResponse.json")))) .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get( + ("/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc?SO_REQUEST_ID=00032ab7-1a18-42e5-965d-8ea592502018&IS_INTERNAL_DATA=false")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(new String(Files.readAllBytes(Paths.get( + "src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json")))) + .withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get( + ("/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc?SO_REQUEST_ID=00032ab7-3fb3-42e5-965d-8ea592502017&IS_INTERNAL_DATA=false")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(new String(Files.readAllBytes(Paths.get( + "src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json")))) + .withStatus(HttpStatus.SC_OK))); } @Test @@ -117,6 +129,16 @@ public class OrchestrationRequestsTest extends BaseTest { Request request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest(); testResponse.setRequest(request); + testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>()); + RequestProcessingData e = new RequestProcessingData(); + e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714"); + e.setTag("pincFabricConfigRequest"); + List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>(); + HashMap<String, String> data1 = new HashMap<String, String>(); + data1.put("requestAction", "assign"); + data.add(data1); + e.setDataPairs(data); + testResponse.getRequest().getRequestProcessingData().add(e); String testRequestId = request.getRequestId(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON); @@ -148,6 +170,16 @@ public class OrchestrationRequestsTest extends BaseTest { Request request = ORCHESTRATION_LIST.getRequestList().get(8).getRequest(); testResponse.setRequest(request); + testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>()); + RequestProcessingData e = new RequestProcessingData(); + e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714"); + e.setTag("pincFabricConfigRequest"); + List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>(); + HashMap<String, String> data1 = new HashMap<String, String>(); + data1.put("requestAction", "assign"); + data.add(data1); + e.setDataPairs(data); + testResponse.getRequest().getRequestProcessingData().add(e); String testRequestId = request.getRequestId(); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON); @@ -184,6 +216,16 @@ public class OrchestrationRequestsTest extends BaseTest { request.setCloudRequestData(cloudRequestData); testResponse.setRequest(request); String testRequestId = request.getRequestId(); + testResponse.getRequest().setRequestProcessingData(new ArrayList<RequestProcessingData>()); + RequestProcessingData e = new RequestProcessingData(); + e.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca714"); + e.setTag("pincFabricConfigRequest"); + List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>(); + HashMap<String, String> data1 = new HashMap<String, String>(); + data1.put("requestAction", "assign"); + data.add(data1); + e.setDataPairs(data); + testResponse.getRequest().getRequestProcessingData().add(e); HttpHeaders headers = new HttpHeaders(); headers.set("Accept", MediaType.APPLICATION_JSON); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json new file mode 100644 index 0000000000..c746020e7f --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json @@ -0,0 +1,8 @@ +[{ + "id": 1, + "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018", + "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca714", + "name": "requestAction", + "value": "assign", + "tag": "pincFabricConfigRequest" +}] diff --git a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java index 708171366d..cb02b7c491 100644 --- a/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java +++ b/mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java @@ -39,6 +39,9 @@ public interface RequestProcessingDataRepository extends JpaRepository<RequestPr List<RequestProcessingData> findBySoRequestIdOrderByGroupingIdDesc(@Param("SO_REQUEST_ID") String soRequestId); + RequestProcessingData[] findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc( + @Param("SO_REQUEST_ID") String soRequestId, @Param("IS_INTERNAL_DATA") Boolean isDataInternal); + List<RequestProcessingData> findByGroupingIdAndNameAndTag(@Param("GROUPING_ID") String groupingId, @Param("NAME") String name, @Param("TAG") String tag); } diff --git a/mso-api-handlers/mso-requests-db/pom.xml b/mso-api-handlers/mso-requests-db/pom.xml index 651f35fd5c..031f86282a 100644 --- a/mso-api-handlers/mso-requests-db/pom.xml +++ b/mso-api-handlers/mso-requests-db/pom.xml @@ -31,6 +31,11 @@ <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.glassfish.jersey.core</groupId> + <artifactId>jersey-common</artifactId> + <scope>test</scope> + </dependency> </dependencies> <packaging>jar</packaging> <build> diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java index 3c81555b99..e386789c7f 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -42,7 +42,7 @@ import com.openpojo.business.annotation.BusinessKey; * persist the request identifiers created when MSO POSTs a request to PINC <br> * <p> * </p> - * + * * @author * @version */ @@ -54,7 +54,7 @@ import com.openpojo.business.annotation.BusinessKey; public class RequestProcessingData implements Serializable { /** - * + * */ private static final long serialVersionUID = -3497593687393936143L; @@ -87,7 +87,7 @@ public class RequestProcessingData implements Serializable { private Date created = null; @Column(name = "IS_DATA_INTERNAL") - private Boolean isDataInternal = true; + private Boolean isDataInternal = false; @Override public boolean equals(final Object other) { 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 132ec28e31..655ae60f47 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 @@ -22,6 +22,7 @@ package org.onap.so.db.request.client; import java.net.URI; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -70,6 +71,7 @@ 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 IS_INTERNAL_DATA = "IS_INTERNAL_DATA"; private static final String NAME = "NAME"; private static final String GROUPING_ID = "GROUPING_ID"; private static final String REQUEST_ID = "REQUEST_ID"; @@ -83,7 +85,7 @@ public class RequestsDbClient { protected String endpoint; @Value("${mso.adapters.requestDb.auth:#{null}}") - private String msoAdaptersAuth; + protected String msoAdaptersAuth; private String getOrchestrationFilterURI = "/infraActiveRequests/getOrchestrationFiltersFromInfraActive/"; private static final String OPERATION_STATUS_SEARCH = "/operationStatus/search"; @@ -125,6 +127,9 @@ public class RequestsDbClient { private static final String findBySoRequestIdOrderByGroupingIdDesc = "/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc"; + private static final String findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc = + "/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc"; + private static final String findByGroupingIdAndNameAndTag = "/requestProcessingData/search/findByGroupingIdAndNameAndTag"; @@ -153,8 +158,12 @@ public class RequestsDbClient { findOneByRequestId = endpoint + findOneByRequestId; } - private ClientFactory getClientFactory() { - URI baseUri = UriBuilder.fromUri(endpoint).build(); + protected String getEndpoint() { + return endpoint; + } + + protected ClientFactory getClientFactory() { + URI baseUri = UriBuilder.fromUri(getEndpoint()).build(); ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new HttpComponentsClientHttpRequestFactory()); @@ -386,6 +395,18 @@ public class RequestsDbClient { .queryParam(SO_REQUEST_ID, soRequestId).build().toString())); } + public List<RequestProcessingData> getExternalRequestProcessingDataBySoRequestId(String soRequestId) { + URI uri = getUri(UriBuilder.fromUri(getEndpoint() + findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc) + .queryParam(SO_REQUEST_ID, soRequestId).queryParam(IS_INTERNAL_DATA, false).build().toString()); + ResponseEntity<RequestProcessingData[]> array = + restTemplate.exchange(uri, HttpMethod.GET, getHttpEntity(), RequestProcessingData[].class); + if (array != null) { + return Arrays.asList(array.getBody()); + } else { + return null; + } + } + public RequestProcessingData getRequestProcessingDataBySoRequestIdAndNameAndGrouping(String soRequestId, String name, String groupingId) { return getClientFactory().create(RequestProcessingData.class) @@ -424,6 +445,7 @@ public class RequestsDbClient { rpd.setSoRequestId(requestId); rpd.setValue(flowExecutionPath); rpd.setTag(BPMN_EXECUTION_DATA_TAG); + rpd.setIsDataInternal(true); HttpEntity<RequestProcessingData> entity = new HttpEntity<>(rpd, headers); restTemplate.postForLocation(uri, entity); diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java index fff6ad1013..0ad8d1458e 100644 --- a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java @@ -4,22 +4,35 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.times; import java.net.URI; +import javax.ws.rs.core.UriBuilder; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; +import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import org.onap.logging.filter.spring.SpringClientPayloadFilter; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.beans.RequestProcessingData; +import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.BufferingClientHttpRequestFactory; +import org.springframework.http.client.ClientHttpRequestFactory; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; +import uk.co.blackpepper.bowman.ClientFactory; +import uk.co.blackpepper.bowman.Configuration; @RunWith(MockitoJUnitRunner.class) public class RequestDbClientTest { - + @Spy @InjectMocks protected RequestsDbClient requestsDbClient; @@ -44,4 +57,16 @@ public class RequestDbClientTest { Mockito.verify(restTemplate, times(1)).exchange(eq(uri), eq(HttpMethod.PATCH), isA(HttpEntity.class), eq(String.class)); } + + @Test + public void testGetRequestProcessingDataBySoRequestIdAndIsInternalData() { + Mockito.doReturn("host").when(requestsDbClient).getEndpoint(); + requestsDbClient.getExternalRequestProcessingDataBySoRequestId("12345"); + URI uri = URI.create(UriBuilder + .fromUri("host/requestProcessingData/search/findBySoRequestIdAndIsDataInternalOrderByGroupingIdDesc") + .queryParam("SO_REQUEST_ID", "12345").queryParam("IS_INTERNAL_DATA", false).build().toString()); + Mockito.verify(restTemplate, times(1)).exchange(eq(uri), eq(HttpMethod.GET), isA(HttpEntity.class), + eq(RequestProcessingData[].class)); + } + } |