summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortragait <rahul.tyagi@est.tech>2020-02-14 17:48:50 +0000
committertragait <rahul.tyagi@est.tech>2020-02-19 10:10:18 +0000
commit0b6f485d1ba5007056eb71b779bc844b4948de36 (patch)
treedf9a6d2a534e856d331891f156af09b542a34518
parent493477ef59ce12d082683f188e0253fe2d34bdff (diff)
SO API extenstion to retrieve all PNF workflow
This commit implements SO request handler API onap/so/infra/workflowSpecifications/v[x]/pnfWorkFlows. It is used to get all the pnf workflows exist in catalogdb. Issue-ID: SO-2660 Change-Id: Ieeca8a6afef917b6e3ba927d38ed5509dcaf253c Signed-off-by: tragait <rahul.tyagi@est.tech>
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java118
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java108
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/Empty_workflowActivitySpecSequence_Response.json2
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnf.json2
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnfWorkflows_Response.json41
-rw-r--r--mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java12
-rw-r--r--mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java6
-rw-r--r--mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java16
-rw-r--r--mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java10
-rw-r--r--pom.xml44
10 files changed, 247 insertions, 112 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java
index 0d0e6ee92f..d9955352c6 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java
@@ -6,6 +6,8 @@
* ================================================================================
* Modifications Copyright (c) 2019 Samsung
* ================================================================================
+ * Modifications Copyright (c) 2020 Nordix
+ * ================================================================================
* 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
@@ -21,36 +23,23 @@
*/
package org.onap.so.apihandlerinfra;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.TreeSet;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import javax.transaction.Transactional;
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.Response;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.swagger.v3.oas.annotations.OpenAPIDefinition;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.info.Info;
+import io.swagger.v3.oas.annotations.media.ArraySchema;
+import io.swagger.v3.oas.annotations.media.Content;
+import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
import org.apache.http.HttpStatus;
import org.onap.so.apihandler.common.ErrorNumbers;
import org.onap.so.apihandler.common.ResponseBuilder;
import org.onap.so.apihandlerinfra.exceptions.ValidateException;
import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo;
-import org.onap.so.apihandlerinfra.workflowspecificationbeans.ActivitySequence;
-import org.onap.so.apihandlerinfra.workflowspecificationbeans.ArtifactInfo;
-import org.onap.so.apihandlerinfra.workflowspecificationbeans.Validation;
-import org.onap.so.apihandlerinfra.workflowspecificationbeans.WorkflowInputParameter;
-import org.onap.so.apihandlerinfra.workflowspecificationbeans.WorkflowSpecification;
-import org.onap.so.apihandlerinfra.workflowspecificationbeans.WorkflowSpecificationList;
-import org.onap.so.apihandlerinfra.workflowspecificationbeans.WorkflowSpecifications;
-import org.onap.so.db.catalog.beans.ActivitySpec;
-import org.onap.so.db.catalog.beans.ActivitySpecUserParameters;
-import org.onap.so.db.catalog.beans.UserParameters;
-import org.onap.so.db.catalog.beans.Workflow;
-import org.onap.so.db.catalog.beans.WorkflowActivitySpecSequence;
+import org.onap.so.apihandlerinfra.workflowspecificationbeans.*;
+import org.onap.so.db.catalog.beans.*;
import org.onap.so.db.catalog.client.CatalogDbClient;
import org.onap.so.logger.ErrorCode;
import org.onap.so.logger.MessageEnum;
@@ -58,16 +47,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import io.swagger.v3.oas.annotations.OpenAPIDefinition;
-import io.swagger.v3.oas.annotations.Operation;
-import io.swagger.v3.oas.annotations.info.Info;
-import io.swagger.v3.oas.annotations.media.ArraySchema;
-import io.swagger.v3.oas.annotations.media.Content;
-import io.swagger.v3.oas.annotations.media.Schema;
-import io.swagger.v3.oas.annotations.responses.ApiResponse;
+import javax.transaction.Transactional;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+import java.util.*;
+import java.util.stream.Collectors;
+
@Path("onap/so/infra/workflowSpecifications")
@OpenAPIDefinition(info = @Info(title = "onap/so/infra/workflowSpecifications",
@@ -84,6 +72,7 @@ public class WorkflowSpecificationsHandler {
private static Logger logger = LoggerFactory.getLogger(WorkflowSpecificationsHandler.class);
private static final String ARTIFACT_TYPE_WORKFLOW = "workflow";
private static final String NATIVE_WORKFLOW = "native";
+ private static final String EMPTY_BODY = "";
@Path("/{version:[vV]1}/workflows")
@GET
@@ -125,24 +114,29 @@ public class WorkflowSpecificationsHandler {
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Workflow::getArtifactUUID))),
ArrayList::new));
- WorkflowSpecifications workflowSpecifications = mapWorkflowsToWorkflowSpecifications(retWorkflows);
+ Optional<String> optional = getResponseByWorkflowSpec(retWorkflows);
+ return builder.buildResponse(HttpStatus.SC_OK, "", optional.isPresent() ? optional.get() : EMPTY_BODY,
+ apiVersion);
+ }
- String jsonResponse;
- try {
- ObjectMapper mapper = new ObjectMapper();
- jsonResponse = mapper.writeValueAsString(workflowSpecifications);
- } catch (JsonProcessingException e) {
- ErrorLoggerInfo errorLoggerInfo =
- new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError)
- .build();
- ValidateException validateException =
- new ValidateException.Builder("Mapping of request to JSON object failed : " + e.getMessage(),
- HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e)
- .errorInfo(errorLoggerInfo).build();
- throw validateException;
- }
+ @Path("/{version:[vV]1}/pnfWorkflows")
+ @GET
+ @Operation(description = "Finds pnf workflow specifications", responses = @ApiResponse(
+ content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))))
+ @Transactional
+ public Response getWorkflowsSpecForPnf(@PathParam("version") String version) throws Exception {
+
+ final String pnf_resource = "pnf";
+ String apiVersion = version.substring(1);
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
- return builder.buildResponse(HttpStatus.SC_OK, "", jsonResponse, apiVersion);
+ List<Workflow> workflows = catalogDbClient.findWorkflowByResourceTarget(pnf_resource);
+
+ Optional<String> optional = getResponseByWorkflowSpec(workflows);
+ return builder.buildResponse(HttpStatus.SC_OK, "", optional.isPresent() ? optional.get() : EMPTY_BODY,
+ apiVersion);
}
protected WorkflowSpecifications mapWorkflowsToWorkflowSpecifications(List<Workflow> workflows) {
@@ -165,6 +159,28 @@ public class WorkflowSpecificationsHandler {
return workflowSpecifications;
}
+ private Optional<String> getResponseByWorkflowSpec(List<Workflow> workflows) throws ValidateException {
+ WorkflowSpecifications workflowSpecifications = mapWorkflowsToWorkflowSpecifications(workflows);
+
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ return Optional.of(mapper.writeValueAsString(workflowSpecifications));
+ } catch (JsonProcessingException e) {
+ catchAndThrowValidationEx(e);
+ }
+ return Optional.empty();
+ }
+
+ private Response catchAndThrowValidationEx(JsonProcessingException e) throws ValidateException {
+ ErrorLoggerInfo errorLoggerInfo =
+ new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
+ ValidateException validateException =
+ new ValidateException.Builder("Mapping of request to JSON object failed : " + e.getMessage(),
+ HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo)
+ .build();
+ throw validateException;
+ }
+
private ArtifactInfo buildArtifactInfo(Workflow workflow) {
ArtifactInfo artifactInfo = new ArtifactInfo();
artifactInfo.setArtifactType(ARTIFACT_TYPE_WORKFLOW);
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java
index 7af92cb8ef..21e6d53c14 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandlerTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2020 Nordix
+ * ================================================================================
* 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
@@ -20,30 +22,15 @@
package org.onap.so.apihandlerinfra;
-import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
-import static com.github.tomakehurst.wiremock.client.WireMock.get;
-import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
-import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.List;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONException;
import org.junit.Test;
import org.onap.so.apihandlerinfra.workflowspecificationbeans.WorkflowInputParameter;
import org.onap.so.apihandlerinfra.workflowspecificationbeans.WorkflowSpecifications;
-import org.onap.so.db.catalog.beans.ActivitySpec;
-import org.onap.so.db.catalog.beans.ActivitySpecUserParameters;
-import org.onap.so.db.catalog.beans.UserParameters;
-import org.onap.so.db.catalog.beans.Workflow;
-import org.onap.so.db.catalog.beans.WorkflowActivitySpecSequence;
+import org.onap.so.db.catalog.beans.*;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -53,10 +40,19 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ResourceUtils;
import org.springframework.web.util.UriComponentsBuilder;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonMappingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.List;
+import static com.github.tomakehurst.wiremock.client.WireMock.*;
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
public class WorkflowSpecificationsHandlerTest extends BaseTest {
@Autowired
@@ -65,12 +61,13 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
@Value("${wiremock.server.port}")
private String wiremockPort;
- private final String basePath = "onap/so/infra/workflowSpecifications/v1/workflows";
+ private final String basePath = "onap/so/infra/workflowSpecifications";
@Test
public void queryWorkflowSpecificationsByVnfModelUUID_Test_Success()
throws ParseException, JSONException, JsonParseException, JsonMappingException, IOException {
+ final String urlPath = basePath + "/v1/workflows";
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON);
headers.set("Content-Type", MediaType.APPLICATION_JSON);
@@ -147,7 +144,7 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
.withBody(getWiremockResponseForCatalogdb("UserParameters6_Response.json"))
.withStatus(org.apache.http.HttpStatus.SC_OK)));
- UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath))
+ UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(urlPath))
.queryParam("vnfModelVersionId", "b5fa707a-f55a-11e7-a796-005056856d52");
ResponseEntity<String> response =
@@ -174,7 +171,7 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
@Test
public void mapWorkflowsToWorkflowSpecifications_Test_Success() throws Exception {
- List<Workflow> workflows = new ArrayList<Workflow>();
+ List<Workflow> workflows = new ArrayList<>();
Workflow workflow = new Workflow();
workflow.setArtifactUUID("ab6478e4-ea33-3346-ac12-ab121484a333");
workflow.setArtifactName("inPlaceSoftwareUpdate-1_0.bpmn");
@@ -267,8 +264,7 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
activitySpecUserParameter6.setUserParameters(userParameter6);
activitySpecUserParameters.add(activitySpecUserParameter6);
- List<WorkflowActivitySpecSequence> workflowActivitySpecSequences =
- new ArrayList<WorkflowActivitySpecSequence>();
+ List<WorkflowActivitySpecSequence> workflowActivitySpecSequences = new ArrayList<>();
ActivitySpec activitySpec1 = new ActivitySpec();
activitySpec1.setName("VNFQuiesceTrafficActivity");
@@ -325,9 +321,9 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
}
@Test
- public void queryWorkflowSpecificationsByPnfModelUUID_Test_Success()
- throws ParseException, JSONException, JsonParseException, JsonMappingException, IOException {
+ public void queryWorkflowSpecificationsByPnfModelUUID_Test_Success() throws JSONException, IOException {
+ final String urlPath = basePath + "/v1/workflows";
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON);
headers.set("Content-Type", MediaType.APPLICATION_JSON);
@@ -345,7 +341,7 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
.withBody(getWiremockResponseForCatalogdb("Empty_workflowActivitySpecSequence_Response.json"))
.withStatus(org.apache.http.HttpStatus.SC_OK)));
- UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath))
+ UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(urlPath))
.queryParam("pnfModelVersionId", "f2d1f2b2-88bb-49da-b716-36ae420ccbff");
ResponseEntity<String> response =
@@ -370,6 +366,54 @@ public class WorkflowSpecificationsHandlerTest extends BaseTest {
assertEquals("1.0.0", response.getHeaders().get("X-LatestVersion").get(0));
}
+ @Test
+ public void testWorkflowSpecificationsForPnf_Success() throws JSONException, IOException {
+
+ final String urlPath = basePath + "/v1/pnfWorkflows";
+ HttpHeaders headers = new HttpHeaders();
+ headers.set("Accept", MediaType.APPLICATION_JSON);
+ headers.set("Content-Type", MediaType.APPLICATION_JSON);
+ HttpEntity<String> entity = new HttpEntity(null, headers);
+
+ wireMockServer.stubFor(get(urlMatching("/workflow/search/findByResourceTarget[?]resource_target=pnf"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(
+ getWiremockResponseForCatalogdb("WorkflowSpecificationsForPnfWorkflows_Response.json"))
+ .withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ wireMockServer.stubFor(get(urlMatching("/infraActiveRequests.*"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ wireMockServer.stubFor(get(urlMatching("/workflow/1/workflowActivitySpecSequence"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(getWiremockResponseForCatalogdb("Empty_workflowActivitySpecSequence_Response.json"))
+ .withStatus(org.apache.http.HttpStatus.SC_OK)));
+
+ UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(urlPath));
+
+ ResponseEntity<String> response =
+ restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+
+ WorkflowSpecifications expectedResponse = mapper.readValue(
+ new String(Files.readAllBytes(
+ Paths.get("src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnf.json"))),
+ WorkflowSpecifications.class);
+ WorkflowSpecifications realResponse = mapper.readValue(response.getBody(), WorkflowSpecifications.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+ assertThat(expectedResponse, sameBeanAs(realResponse));
+ 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("1.0.0", response.getHeaders().get("X-LatestVersion").get(0));
+ }
+
private String getWiremockResponseForCatalogdb(String file) {
try {
File resource = ResourceUtils.getFile("classpath:__files/catalogdb/" + file);
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/Empty_workflowActivitySpecSequence_Response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/Empty_workflowActivitySpecSequence_Response.json
index 89675e8f02..6779c1f3e4 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/Empty_workflowActivitySpecSequence_Response.json
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/Empty_workflowActivitySpecSequence_Response.json
@@ -2,4 +2,4 @@
"_embedded": {
"workflowActivitySpecSequence": []
}
-}
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnf.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnf.json
index 257b9dc843..b5b93873c8 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnf.json
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnf.json
@@ -17,4 +17,4 @@
}
}
]
-}
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnfWorkflows_Response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnfWorkflows_Response.json
new file mode 100644
index 0000000000..2447617897
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnfWorkflows_Response.json
@@ -0,0 +1,41 @@
+{
+ "_embedded": {
+ "workflow": [
+ {
+ "artifactChecksum": "MANUAL RECORD",
+ "artifactName": "DummyPnfWorkflow",
+ "artifactUUID": "b2fd5627-55e4-4f4f-8064-9e6f443e9152",
+ "body": null,
+ "created": "2020-02-18T08:28:15.000+0000",
+ "description": "Dummy Pnf Workflow to test custom Pnf workflow",
+ "id": 4,
+ "name": "Dummy Pnf Workflow",
+ "operationName": "DummyPnfWorkflow",
+ "pnfResourceWorkflow": null,
+ "resourceTarget": "pnf",
+ "source": "native",
+ "timeoutMinutes": null,
+ "version": 1.0,
+ "_links": {
+ "self": {
+ "href": "http://localhost:8090/workflow/search/findByResourceTarget?resource_target=pnf"
+ },
+ "workflow": {
+ "href": "http://localhost:8090/workflow/4"
+ },
+ "workflowActivitySpecSequence": {
+ "href": "http://localhost:8090/workflow/4/workflowActivitySpecSequence"
+ }
+ }
+ }
+ ]
+ },
+ "_links": {
+ "self": {
+ "href": "http://localhost:8090/workflow/search/findByResourceTarget?resource_target=pnf"
+ },
+ "workflowActivitySpecSequence": {
+ "href": "http://localhost:8090/workflow/4/workflowActivitySpecSequence"
+ }
+ }
+} \ No newline at end of file
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 cf066f9721..26c33941ed 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
@@ -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.
@@ -158,6 +158,7 @@ public class CatalogDbClient {
protected static final String HOMING_INSTANCE = "/homingInstance";
protected static final String ARTIFACT_UUID = "artifactUUID";
protected static final String SOURCE = "source";
+ protected static final String RESOURCE_TARGET = "resource_target";
private static final String TARGET_ENTITY = "SO:CatalogDB";
private static final String ASTERISK = "*";
@@ -209,6 +210,7 @@ public class CatalogDbClient {
private String findVnfResourceCustomizationByModelUuid = "/findVnfResourceCustomizationByModelUuid";
private String findBBNameSelectionReferenceByControllerActorAndScopeAndAction =
"/findBBNameSelectionReferenceByControllerActorAndScopeAndAction";
+ private String findWorkflowByResourceTarget = "/findByResourceTarget";
private String serviceURI;
private String vfModuleURI;
@@ -348,6 +350,7 @@ public class CatalogDbClient {
findWorkflowByVnfModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByVnfModelUUID;
findWorkflowByPnfModelUUID = endpoint + WORKFLOW + SEARCH + findWorkflowByPnfModelUUID;
findWorkflowBySource = endpoint + WORKFLOW + SEARCH + findWorkflowBySource;
+ findWorkflowByResourceTarget = endpoint + WORKFLOW + SEARCH + findWorkflowByResourceTarget;
findVnfResourceCustomizationByModelUuid =
endpoint + VNF_RESOURCE_CUSTOMIZATION + SEARCH + findVnfResourceCustomizationByModelUuid;
@@ -1084,6 +1087,11 @@ public class CatalogDbClient {
getUri(UriBuilder.fromUri(findWorkflowBySource).queryParam(SOURCE, source).build().toString()));
}
+ public List<Workflow> findWorkflowByResourceTarget(String resourceTarget) {
+ return this.getMultipleResources(workflowClient, getUri(UriBuilder.fromUri(findWorkflowByResourceTarget)
+ .queryParam(RESOURCE_TARGET, resourceTarget).build().toString()));
+ }
+
public String getEndpoint() {
return endpoint;
}
diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java
index 91c6940e95..93ec54a2eb 100644
--- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.java
+++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/WorkflowRepository.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.
@@ -33,6 +33,8 @@ public interface WorkflowRepository extends JpaRepository<Workflow, Integer> {
List<Workflow> findBySource(String source);
+ List<Workflow> findByResourceTarget(String resourceTarget);
+
/**
* Used to fetch the @{link Workflow} by the Model UUID.
*
diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java
index 66fc0f5dc5..79e3cbcc08 100644
--- a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java
+++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* ================================================================================
+ * Modifications Copyright (c) 2020 Nordix
+ * ================================================================================
* 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
@@ -179,7 +181,7 @@ public class CatalogDbClientTest {
}
@Test
- public final void testFindWorkflowByPnfModelUUID() throws Exception {
+ public final void testFindWorkflowByPnfModelUUID() {
String pnfResourceModelUUID = "f2d1f2b2-88bb-49da-b716-36ae420ccbff";
doReturn(new ArrayList()).when(catalogDbClient).getMultipleResources(any(), any());
@@ -190,4 +192,16 @@ public class CatalogDbClientTest {
}
+ @Test
+ public final void testFindWorkflowByResourceTarget() {
+ // when
+ final String pnf_resource = "pnf";
+ doReturn(new ArrayList()).when(catalogDbClient).getMultipleResources(any(), any());
+ catalogDbClient.findWorkflowByResourceTarget(pnf_resource);
+
+ // verify
+ verify(catalogDbClient).getMultipleResources(any(Client.class), eq(UriBuilder.fromUri("/findByResourceTarget")
+ .queryParam(CatalogDbClient.RESOURCE_TARGET, pnf_resource).build()));
+ }
+
}
diff --git a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java
index b07e82b8a8..e47c61d8b4 100644
--- a/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java
+++ b/mso-catalog-db/src/test/java/org/onap/so/db/catalog/data/repository/WorkflowRepositoryTest.java
@@ -55,4 +55,14 @@ public class WorkflowRepositoryTest extends BaseTest {
Assert.assertTrue("testingWorkflow.bpmn".equals(workflows.get(0).getArtifactName()));
}
+ @Test
+ public void findByResourceTargetTest() {
+ List<Workflow> workflows = workflowRepository.findByResourceTarget("pnf");
+
+ Assert.assertTrue(workflows != null);
+ Assert.assertTrue(workflows.size() == 1);
+
+ Assert.assertTrue("DummyPnfWorkflow".equals(workflows.get(0).getArtifactName()));
+ }
+
}
diff --git a/pom.xml b/pom.xml
index 0955338a4e..0719b205df 100644
--- a/pom.xml
+++ b/pom.xml
@@ -337,28 +337,28 @@
</configuration>
</plugin>
<plugin>
- <groupId>org.jacoco</groupId>
- <artifactId>jacoco-maven-plugin</artifactId>
- <version>${jacoco.version}</version>
- <executions>
- <execution>
- <id>prepare-agent</id>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- </execution>
- <execution>
- <id>report</id>
- <goals>
- <goal>report</goal>
- </goals>
- <configuration>
- <dataFile>${project.build.directory}/code-coverage/jacoco.exec</dataFile>
- <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>${jacoco.version}</version>
+ <executions>
+ <execution>
+ <id>prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>report</id>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ <configuration>
+ <dataFile>${project.build.directory}/code-coverage/jacoco.exec</dataFile>
+ <outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>