Updated and added to get request processing data 44/98744/1
authorBoslet, Cory <cory.boslet@att.com>
Fri, 22 Nov 2019 01:48:40 +0000 (20:48 -0500)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Fri, 22 Nov 2019 01:48:41 +0000 (20:48 -0500)
Updated and added to get request processing data by internal data flag
Committing file that I forgot to commit.
Added junit test and change method to not use bowman client.
Added and updated orch request unit test
ran formatter so verify job will pass and not cry
Added an intergration test for new jpa method.
Format unit test class for the verify job build
Update param key in jpa and also changed return type.
Updated method name in request client to avoid confusion

Issue-ID: SO-2534
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: I420f1a887835dd0d9d0ad991e5b17dddb1db5376

adapters/mso-requests-db-adapter/src/main/resources/db/migration/V6.6__UpdateRequestProcessingData.sql [new file with mode: 0644]
adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestdb/rest/RequestProcessingDataRequestDbQueryTest.java
adapters/mso-requests-db-adapter/src/test/resources/db/migration/afterMigrate.sql
mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java
mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java
mso-api-handlers/mso-api-handler-infra/src/test/resources/OrchestrationRequest/getRequestProcessingDataArray.json [new file with mode: 0644]
mso-api-handlers/mso-requests-db-repositories/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java
mso-api-handlers/mso-requests-db/pom.xml
mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java
mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java
mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/db/request/client/RequestDbClientTest.java

diff --git a/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V6.6__UpdateRequestProcessingData.sql b/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V6.6__UpdateRequestProcessingData.sql
new file mode 100644 (file)
index 0000000..70d1d3f
--- /dev/null
@@ -0,0 +1,9 @@
+use requestdb;
+
+UPDATE request_processing_data 
+SET IS_DATA_INTERNAL = 1
+WHERE TAG = 'BPMNExecutionData';
+
+UPDATE request_processing_data 
+SET IS_DATA_INTERNAL = 0
+WHERE TAG = 'StackInformation' OR TAG = 'pincFabricConfigRequest';
\ No newline at end of file
index abc70ed..9641cb8 100644 (file)
@@ -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.
@@ -86,4 +86,28 @@ public class RequestProcessingDataRequestDbQueryTest {
         assertEquals(dataFound.get(1).getValue(), secondEntry.getValue());
         assertEquals(dataFound.get(1).getTag(), secondEntry.getTag());
     }
+
+    @Test
+    @Transactional
+    public void testGetRequestProcessingDataBySoRequestIdAndIsInternalData() {
+        String soRequestId = "00032ab7-na18-42e5-965d-8ea592502018";
+        String tag = "pincFabricConfigRequest";
+        RequestProcessingData firstEntry = new RequestProcessingData();
+        List<RequestProcessingData> expectedList = new ArrayList<>();
+        firstEntry.setSoRequestId(soRequestId);
+        firstEntry.setGroupingId("7d2e8c07-4d10-456d-bddc-37abf38ca715");
+        firstEntry.setName("configurationId");
+        firstEntry.setValue("52234bc0-d6a6-41d4-a901-79015e4877e2");
+        firstEntry.setTag(tag);
+        expectedList.add(firstEntry);
+
+        List<RequestProcessingData> dataFound = client.getExternalRequestProcessingDataBySoRequestId(soRequestId);
+
+        assertEquals(1, dataFound.size());
+        assertEquals(dataFound.get(0).getSoRequestId(), firstEntry.getSoRequestId());
+        assertEquals(dataFound.get(0).getGroupingId(), firstEntry.getGroupingId());
+        assertEquals(dataFound.get(0).getName(), firstEntry.getName());
+        assertEquals(dataFound.get(0).getValue(), firstEntry.getValue());
+        assertEquals(dataFound.get(0).getTag(), firstEntry.getTag());
+    }
 }
index a86065d..b34b272 100644 (file)
@@ -31,11 +31,11 @@ insert into watchdog_service_mod_ver_id_lookup(distribution_id, service_model_ve
 insert into site_status(site_name, status, creation_timestamp) values
 ('testsite', 0, '2017-11-30 15:48:09');
 
-INSERT INTO requestdb.request_processing_data (ID, SO_REQUEST_ID, GROUPING_ID, NAME, VALUE, TAG)
+INSERT INTO requestdb.request_processing_data (ID, SO_REQUEST_ID, GROUPING_ID, NAME, VALUE, TAG, IS_DATA_INTERNAL)
 VALUES
-(1, '00032ab7-na18-42e5-965d-8ea592502018', '7d2e8c07-4d10-456d-bddc-37abf38ca714', 'requestAction', 'assign', 'pincFabricConfigRequest'),
-(2, '00032ab7-na18-42e5-965d-8ea592502018', '7d2e8c07-4d10-456d-bddc-37abf38ca715', 'configurationId', '52234bc0-d6a6-41d4-a901-79015e4877e2', 'pincFabricConfigRequest'),
-(3, '5ffbabd6-b793-4377-a1ab-082670fbc7ac', '5ffbabd6-b793-4377-a1ab-082670fbc7ac', 'configId', '52234bc0-d6a6-41d4-a901-79015e4877e2', 'pincFabricConfig');
+(1, '00032ab7-na18-42e5-965d-8ea592502018', '7d2e8c07-4d10-456d-bddc-37abf38ca714', 'requestAction', 'assign', 'pincFabricConfigRequest', 1),
+(2, '00032ab7-na18-42e5-965d-8ea592502018', '7d2e8c07-4d10-456d-bddc-37abf38ca715', 'configurationId', '52234bc0-d6a6-41d4-a901-79015e4877e2', 'pincFabricConfigRequest', 0),
+(3, '5ffbabd6-b793-4377-a1ab-082670fbc7ac', '5ffbabd6-b793-4377-a1ab-082670fbc7ac', 'configId', '52234bc0-d6a6-41d4-a901-79015e4877e2', 'pincFabricConfig', 1);
 
 INSERT INTO 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, VNF_OPERATIONAL_ENV_ID)
 VALUES
index cf4e635..12f2a07 100644 (file)
@@ -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);
index 151785d..a0b9fea 100644 (file)
@@ -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 (file)
index 0000000..c746020
--- /dev/null
@@ -0,0 +1,8 @@
+[{
+       "id": 1,
+       "soRequestId": "00032ab7-na18-42e5-965d-8ea592502018",
+       "groupingId": "7d2e8c07-4d10-456d-bddc-37abf38ca714",
+       "name": "requestAction",
+       "value": "assign",
+       "tag": "pincFabricConfigRequest"
+}]
index 7081713..cb02b7c 100644 (file)
@@ -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);
 }
index 651f35f..031f862 100644 (file)
       <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>
index 3c81555..e386789 100644 (file)
@@ -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) {
index 132ec28..655ae60 100644 (file)
@@ -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);
index fff6ad1..0ad8d14 100644 (file)
@@ -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));
+    }
+
 }