aboutsummaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java61
1 files changed, 51 insertions, 10 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 925d10179f..0d0e6ee92f 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
@@ -23,6 +23,8 @@ 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;
@@ -90,21 +92,40 @@ public class WorkflowSpecificationsHandler {
@Transactional
public Response queryWorkflowSpecifications(@QueryParam("vnfModelVersionId") String vnfModelVersionId,
- @PathParam("version") String version) throws Exception {
-
+ @QueryParam("pnfModelVersionId") String pnfModelVersionId, @PathParam("version") String version)
+ throws Exception {
String apiVersion = version.substring(1);
- ObjectMapper mapper1 = new ObjectMapper();
- mapper1.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-
- List<Workflow> workflows = catalogDbClient.findWorkflowByModelUUID(vnfModelVersionId);
+ List<Workflow> workflows = new ArrayList<>();
+ if (vnfModelVersionId == null && pnfModelVersionId == null) {
+ workflows.addAll(queryWorkflowSpecificationsForAll());
+ } else {
+ // 1. query workflow specifications for given vnfModelVersionId if need.
+ if (vnfModelVersionId != null) {
+ List<Workflow> vnfWorkflows = queryWorkflowSpecificationsForVnf(vnfModelVersionId);
+ logger.debug("Retrieved " + vnfWorkflows.size() + " workflows for given vnfModelVersionId.");
+ if (vnfWorkflows.size() > 0) {
+ workflows.addAll(vnfWorkflows);
+ }
+ }
- List<Workflow> nativeWorkflows = catalogDbClient.findWorkflowBySource(NATIVE_WORKFLOW);
- if (nativeWorkflows != null && !nativeWorkflows.isEmpty()) {
- workflows.addAll(nativeWorkflows);
+ // 2. query workflow specifications for given pnfModelVersionId if need.
+ if (pnfModelVersionId != null) {
+ List<Workflow> pnfWorkflows = queryWorkflowSpecificationsForPnf(pnfModelVersionId);
+ logger.debug("Retrieved " + pnfWorkflows.size() + " workflows for given pnfModelVerionId.");
+ if (pnfWorkflows.size() > 0) {
+ workflows.addAll(pnfWorkflows);
+ }
+ }
}
- WorkflowSpecifications workflowSpecifications = mapWorkflowsToWorkflowSpecifications(workflows);
+ // Deduplication
+ List<Workflow> retWorkflows = workflows.stream()
+ .collect(Collectors.collectingAndThen(
+ Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Workflow::getArtifactUUID))),
+ ArrayList::new));
+
+ WorkflowSpecifications workflowSpecifications = mapWorkflowsToWorkflowSpecifications(retWorkflows);
String jsonResponse;
try {
@@ -239,4 +260,24 @@ public class WorkflowSpecificationsHandler {
}
return validationList;
}
+
+ private List<Workflow> queryWorkflowSpecificationsForAll() {
+ List<Workflow> workflows = catalogDbClient.findWorkflowBySource(NATIVE_WORKFLOW);
+ return workflows;
+ }
+
+ private List<Workflow> queryWorkflowSpecificationsForVnf(String vnfModelVersionId) {
+ List<Workflow> workflows = catalogDbClient.findWorkflowByVnfModelUUID(vnfModelVersionId);
+
+ List<Workflow> nativeWorkflows = catalogDbClient.findWorkflowBySource(NATIVE_WORKFLOW);
+ if (!nativeWorkflows.isEmpty()) {
+ workflows.addAll(nativeWorkflows);
+ }
+ return workflows;
+ }
+
+ private List<Workflow> queryWorkflowSpecificationsForPnf(String pnfModelVersionId) {
+ List<Workflow> workflows = catalogDbClient.findWorkflowByPnfModelUUID(pnfModelVersionId);
+ return workflows;
+ }
}