From 87c6dd0ae5477e1c20ebbef1c0d1036af313ea4e Mon Sep 17 00:00:00 2001 From: "Smokowski, Steven" Date: Thu, 12 Dec 2019 15:39:21 -0500 Subject: Add simple query format, to limit response content Add simple query format, to limit response content Add simple query format, to limit response content Add simple query format, to limit response content Issue-ID: SO-2570 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I7570828d7c47e0635239dba50d0f7f76bd17f4a8 --- .../so/constants/OrchestrationRequestFormat.java | 2 +- .../so/apihandlerinfra/OrchestrationRequests.java | 50 ++++++++++++++-------- .../apihandlerinfra/OrchestrationRequestsTest.java | 35 ++++++++++++++- 3 files changed, 68 insertions(+), 19 deletions(-) diff --git a/common/src/main/java/org/onap/so/constants/OrchestrationRequestFormat.java b/common/src/main/java/org/onap/so/constants/OrchestrationRequestFormat.java index ccfd2f4de6..641bbb28c7 100644 --- a/common/src/main/java/org/onap/so/constants/OrchestrationRequestFormat.java +++ b/common/src/main/java/org/onap/so/constants/OrchestrationRequestFormat.java @@ -21,5 +21,5 @@ package org.onap.so.constants; public enum OrchestrationRequestFormat { - DETAIL, STATUSDETAIL + DETAIL, STATUSDETAIL, SIMPLE } 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 6ccef65e46..ab51d491eb 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 @@ -130,25 +130,29 @@ public class OrchestrationRequests { infraActiveRequest = infraActiveRequestLookup(requestId); - try { - requestProcessingData = requestsDbClient.getExternalRequestProcessingDataBySoRequestId(requestId); - } catch (Exception e) { - logger.error("Exception occurred while communicating with RequestDb during requestProcessingData lookup ", - e); - ErrorLoggerInfo errorLoggerInfo = - new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.AvailabilityError).build(); + if (isRequestProcessingDataRequired(format)) { + try { + requestProcessingData = requestsDbClient.getExternalRequestProcessingDataBySoRequestId(requestId); + } catch (Exception e) { + logger.error( + "Exception occurred while communicating with RequestDb during requestProcessingData lookup ", + e); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.AvailabilityError) + .build(); - ValidateException validateException = new ValidateException.Builder( - "Exception occurred while communicating with RequestDb during requestProcessingData lookup", - HttpStatus.SC_NOT_FOUND, ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB).cause(e) - .errorInfo(errorLoggerInfo).build(); + ValidateException validateException = new ValidateException.Builder( + "Exception occurred while communicating with RequestDb during requestProcessingData lookup", + HttpStatus.SC_NOT_FOUND, ErrorNumbers.NO_COMMUNICATION_TO_REQUESTS_DB).cause(e) + .errorInfo(errorLoggerInfo).build(); - throw validateException; + throw validateException; + } } Request request = mapInfraActiveRequestToRequest(infraActiveRequest, includeCloudRequest, format); - if (!requestProcessingData.isEmpty()) { + if (null != requestProcessingData && !requestProcessingData.isEmpty()) { request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData)); } request.setRequestId(requestId); @@ -196,15 +200,19 @@ public class OrchestrationRequests { orchestrationList = new GetOrchestrationListResponse(); List requestLists = new ArrayList<>(); + for (InfraActiveRequests infraActive : activeRequests) { - List requestProcessingData = - requestsDbClient.getRequestProcessingDataBySoRequestId(infraActive.getRequestId()); RequestList requestList = new RequestList(); Request request = mapInfraActiveRequestToRequest(infraActive, includeCloudRequest, format); - if (!requestProcessingData.isEmpty()) { - request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData)); + if (isRequestProcessingDataRequired(format)) { + List requestProcessingData = + requestsDbClient.getRequestProcessingDataBySoRequestId(infraActive.getRequestId()); + if (null != requestProcessingData && !requestProcessingData.isEmpty()) { + request.setRequestProcessingData(mapRequestProcessingData(requestProcessingData)); + } } + requestList.setRequest(request); requestLists.add(requestList); } @@ -524,6 +532,14 @@ public class OrchestrationRequests { return addedRequestProcessingData; } + protected boolean isRequestProcessingDataRequired(String format) { + if (StringUtils.isNotEmpty(format) && format.equalsIgnoreCase(OrchestrationRequestFormat.SIMPLE.name())) { + return false; + } else { + return true; + } + } + protected InfraActiveRequests infraActiveRequestLookup(String requestId) throws ApiException { InfraActiveRequests infraActiveRequest = null; try { 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 e64f689624..23c2892c78 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 @@ -64,7 +64,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.util.UriComponentsBuilder; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -162,6 +161,39 @@ public class OrchestrationRequestsTest extends BaseTest { assertNotNull(response.getBody().getRequest().getFinishTime()); } + @Test + public void getOrchestrationRequestSimpleTest() throws Exception { + setupTestGetOrchestrationRequest(); + // TEST VALID REQUEST + GetOrchestrationResponse testResponse = new GetOrchestrationResponse(); + + Request request = ORCHESTRATION_LIST.getRequestList().get(1).getRequest(); + request.setRequestProcessingData(null); + testResponse.setRequest(request); + + String testRequestId = request.getRequestId(); + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type", MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity(null, headers); + UriComponentsBuilder builder = UriComponentsBuilder + .fromHttpUrl(createURLWithPort("/onap/so/infra/orchestrationRequests/v7/" + testRequestId)) + .queryParam("format", "simple"); + + ResponseEntity response = + restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, GetOrchestrationResponse.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + assertThat(response.getBody(), sameBeanAs(testResponse).ignoring("request.startTime") + .ignoring("request.finishTime").ignoring("request.requestStatus.timeStamp")); + assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0)); + assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0)); + assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0)); + assertEquals("7.0.0", response.getHeaders().get("X-LatestVersion").get(0)); + assertEquals("00032ab7-1a18-42e5-965d-8ea592502018", response.getHeaders().get("X-TransactionID").get(0)); + assertNotNull(response.getBody().getRequest().getFinishTime()); + } + @Test public void testGetOrchestrationRequestInstanceGroup() throws Exception { setupTestGetOrchestrationRequestInstanceGroup(); @@ -448,6 +480,7 @@ public class OrchestrationRequestsTest extends BaseTest { assertThat(actualProcessingData, sameBeanAs(expectedDataList)); } + public void setupTestGetOrchestrationRequest() throws Exception { // For testGetOrchestrationRequest wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-1a18-42e5-965d-8ea592502018")) -- cgit 1.2.3-korg