diff options
author | Elena Kuleshov <evn@att.com> | 2019-04-08 22:08:29 -0400 |
---|---|---|
committer | Elena Kuleshov <evn@att.com> | 2019-04-09 02:21:13 -0400 |
commit | fd4d683baf4344b058090e0b0203929103cacedf (patch) | |
tree | 6502f61ed2ea62545cd93156856cc3d7876b0e7f /mso-api-handlers/mso-api-handler-infra/src/main/java | |
parent | ed66a29ce8e0068740466e13fa6517791cce9aeb (diff) |
Query CatalogDB for WorkflowSpecifications
Query CatalogDB for WorkflowSpecifications fron APIH
Change-Id: I5eef5ba9b49c0a7420ef93a5425121bfe7225b1b
Issue-ID: SO-1727
Signed-off-by: Kuleshov, Elena <evn@att.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/main/java')
-rw-r--r-- | mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/WorkflowSpecificationsHandler.java | 148 |
1 files changed, 141 insertions, 7 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 bc4f389469..c480bdfbd3 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 @@ -19,8 +19,11 @@ */ package org.onap.so.apihandlerinfra; -import java.nio.file.Files; -import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +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; @@ -32,7 +35,19 @@ 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.db.catalog.client.CatalogDbClient; import org.onap.so.logger.ErrorCode; import org.onap.so.logger.MessageEnum; import org.springframework.beans.factory.annotation.Autowired; @@ -51,11 +66,17 @@ public class WorkflowSpecificationsHandler { @Autowired private ResponseBuilder builder; + @Autowired + private CatalogDbClient catalogDbClient; + + private static final String ARTIFACT_TYPE_WORKFLOW = "workflow"; + @Path("/{version:[vV]1}/workflows") @GET @ApiOperation(value = "Finds Workflow Specifications", response = Response.class) @Transactional - public Response queryFilters(@QueryParam("vnfModelVersionId") String vnfModelVersionId, + + public Response queryWorkflowSpecifications(@QueryParam("vnfModelVersionId") String vnfModelVersionId, @PathParam("version") String version) throws Exception { String apiVersion = version.substring(1); @@ -63,10 +84,8 @@ public class WorkflowSpecificationsHandler { ObjectMapper mapper1 = new ObjectMapper(); mapper1.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - // Replace with Catalog DB Query - WorkflowSpecifications workflowSpecifications = mapper1.readValue( - new String(Files.readAllBytes(Paths.get("src/test/resources/__files/WorkflowSpecifications.json"))), - WorkflowSpecifications.class); + List<Workflow> workflows = catalogDbClient.findWorkflowByModelUUID(vnfModelVersionId); + WorkflowSpecifications workflowSpecifications = mapWorkflowsToWorkflowSpecifications(workflows); String jsonResponse = null; try { @@ -85,4 +104,119 @@ public class WorkflowSpecificationsHandler { return builder.buildResponse(HttpStatus.SC_OK, "", jsonResponse, apiVersion); } + + protected WorkflowSpecifications mapWorkflowsToWorkflowSpecifications(List<Workflow> workflows) { + if (workflows == null || workflows.size() == 0) { + return null; + } + WorkflowSpecifications workflowSpecifications = new WorkflowSpecifications(); + List<WorkflowSpecificationList> workflowSpecificationList = new ArrayList<WorkflowSpecificationList>(); + + for (Workflow workflow : workflows) { + WorkflowSpecificationList workflowSpecificationListItem = new WorkflowSpecificationList(); + WorkflowSpecification workflowSpecification = new WorkflowSpecification(); + workflowSpecification.setArtifactInfo(buildArtifactInfo(workflow)); + workflowSpecification.setActivitySequence(buildActivitySequence(workflow)); + workflowSpecification.setWorkflowInputParameters(buildWorkflowInputParameters(workflow)); + workflowSpecificationListItem.setWorkflowSpecification(workflowSpecification); + workflowSpecificationList.add(workflowSpecificationListItem); + } + workflowSpecifications.setWorkflowSpecificationList(workflowSpecificationList); + return workflowSpecifications; + } + + private ArtifactInfo buildArtifactInfo(Workflow workflow) { + ArtifactInfo artifactInfo = new ArtifactInfo(); + artifactInfo.setArtifactType(ARTIFACT_TYPE_WORKFLOW); + artifactInfo.setArtifactUuid(workflow.getArtifactUUID()); + artifactInfo.setArtifactName(workflow.getArtifactName()); + if (workflow.getVersion() != null) { + artifactInfo.setArtifactVersion(workflow.getVersion().toString()); + } + artifactInfo.setArtifactDescription(workflow.getDescription()); + artifactInfo.setWorkflowName(workflow.getName()); + artifactInfo.setOperationName(workflow.getOperationName()); + artifactInfo.setWorkflowSource(workflow.getSource()); + artifactInfo.setWorkflowResourceTarget(workflow.getResourceTarget()); + return artifactInfo; + } + + private List<ActivitySequence> buildActivitySequence(Workflow workflow) { + List<WorkflowActivitySpecSequence> workflowActivitySpecSequences = workflow.getWorkflowActivitySpecSequence(); + if (workflowActivitySpecSequences == null || workflowActivitySpecSequences.size() == 0) { + return null; + } + List<ActivitySequence> activitySequences = new ArrayList<ActivitySequence>(); + for (WorkflowActivitySpecSequence workflowActivitySpecSequence : workflowActivitySpecSequences) { + if (workflowActivitySpecSequence != null) { + ActivitySpec activitySpec = workflowActivitySpecSequence.getActivitySpec(); + if (activitySpec != null) { + ActivitySequence activitySequence = new ActivitySequence(); + activitySequence.setName(activitySpec.getName()); + activitySequence.setDescription(activitySpec.getDescription()); + activitySequences.add(activitySequence); + } + } + } + return activitySequences; + } + + private List<WorkflowInputParameter> buildWorkflowInputParameters(Workflow workflow) { + List<WorkflowActivitySpecSequence> workflowActivitySpecSequences = workflow.getWorkflowActivitySpecSequence(); + if (workflowActivitySpecSequences == null || workflowActivitySpecSequences.size() == 0) { + return null; + } + Map<String, WorkflowInputParameter> workflowInputParameterMap = new HashMap<String, WorkflowInputParameter>(); + for (WorkflowActivitySpecSequence workflowActivitySpecSequence : workflowActivitySpecSequences) { + if (workflowActivitySpecSequence != null) { + ActivitySpec activitySpec = workflowActivitySpecSequence.getActivitySpec(); + if (activitySpec != null) { + List<ActivitySpecUserParameters> activitySpecUserParameters = + activitySpec.getActivitySpecUserParameters(); + if (activitySpecUserParameters != null && activitySpecUserParameters.size() != 0) { + for (ActivitySpecUserParameters activitySpecUserParameter : activitySpecUserParameters) { + UserParameters userParameter = activitySpecUserParameter.getUserParameters(); + if (userParameter != null) { + WorkflowInputParameter workflowInputParameter = + buildWorkflowInputParameter(userParameter); + workflowInputParameterMap.put(userParameter.getName(), workflowInputParameter); + } + } + } + } + } + } + + if (workflowInputParameterMap.size() == 0) { + return null; + } + List<WorkflowInputParameter> workflowInputParameterList = + workflowInputParameterMap.values().stream().collect(Collectors.toList()); + return workflowInputParameterList; + } + + private WorkflowInputParameter buildWorkflowInputParameter(UserParameters userParameter) { + WorkflowInputParameter workflowInputParameter = new WorkflowInputParameter(); + workflowInputParameter.setLabel(userParameter.getLabel()); + workflowInputParameter.setInputType(userParameter.getType()); + workflowInputParameter.setRequired(userParameter.getIsRequried()); + workflowInputParameter.setSoFieldName(userParameter.getName()); + workflowInputParameter.setSoPayloadLocation(userParameter.getPayloadLocation()); + workflowInputParameter.setValidation(buildValidationList(userParameter)); + return workflowInputParameter; + } + + private List<Validation> buildValidationList(UserParameters userParameter) { + List<Validation> validationList = null; + if (userParameter.getMaxLength() != null || userParameter.getAllowableChars() != null) { + validationList = new ArrayList<Validation>(); + Validation validation = new Validation(); + if (userParameter.getMaxLength() != null) { + validation.setMaxLength(userParameter.getMaxLength().toString()); + } + validation.setAllowableChars(userParameter.getAllowableChars()); + validationList.add(validation); + } + return validationList; + } } |