From c79087597e1861d12b691d1db4011641a78ab3c1 Mon Sep 17 00:00:00 2001 From: Wojciech Sliwka Date: Wed, 13 Feb 2019 10:38:09 +0100 Subject: workflow parameters API Change-Id: If79e410608a0562ddef86d9a3a451d4addf66a0f Issue-ID: VID-419 Signed-off-by: Wojciech Sliwka --- .../onap/vid/controller/WorkflowsController.java | 7 +++++++ .../main/java/org/onap/vid/model/SOWorkflows.kt | 10 ++++++++- .../vid/mso/rest/MockedWorkflowsRestClient.java | 19 +++++++++++++++++ .../org/onap/vid/services/ExtWorkflowsService.java | 3 +++ .../onap/vid/services/ExtWorkflowsServiceImpl.java | 24 ++++++++++++++++------ 5 files changed, 56 insertions(+), 7 deletions(-) (limited to 'vid-app-common/src/main') diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java b/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java index be1976a48..b693805d1 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java @@ -3,8 +3,10 @@ package org.onap.vid.controller; import java.util.List; import org.onap.portalsdk.core.controller.RestrictedBaseController; import org.onap.vid.model.SOWorkflow; +import org.onap.vid.model.SOWorkflowParameterDefinitions; import org.onap.vid.services.ExtWorkflowsService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @@ -27,5 +29,10 @@ public class WorkflowsController extends RestrictedBaseController { return extWorkflowsService.getWorkflows(vnfName); } + @RequestMapping(value = "workflow-parameters/{id}", method = RequestMethod.GET) + SOWorkflowParameterDefinitions getParameters(@PathVariable Long id) { + return extWorkflowsService.getWorkflowParameterDefinitions(id); + } + } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt b/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt index c85bfd7d4..25125cea6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt +++ b/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt @@ -10,4 +10,12 @@ data class SOWorkflows @JvmOverloads constructor(var workflows: List fun clone(): SOWorkflows { return copy(workflows?.toMutableList()) } -} \ No newline at end of file +} + + +enum class SOWorkflowType(var type: String? = "STRING") { + STRING("STRING") +} + +data class SOWorkflowParameterDefinition(var id: Long? = null, var name: String? = null, var pattern: String? = null, var type: SOWorkflowType? = null, val required: Boolean? = null) +data class SOWorkflowParameterDefinitions(var parameterDefinitions: List? = null) \ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MockedWorkflowsRestClient.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MockedWorkflowsRestClient.java index 313710ebd..f2d1b7c42 100644 --- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/MockedWorkflowsRestClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MockedWorkflowsRestClient.java @@ -3,6 +3,7 @@ package org.onap.vid.mso.rest; import java.util.Collections; import org.jetbrains.annotations.NotNull; import org.onap.vid.client.SyncRestClient; +import org.onap.vid.model.SOWorkflowParameterDefinitions; import org.onap.vid.model.SOWorkflows; import org.onap.vid.mso.MsoResponseWrapper2; @@ -25,9 +26,27 @@ public class MockedWorkflowsRestClient { SOWorkflows.class)); } + public MsoResponseWrapper2 getWorkflowParameterDefinitions(Long workflowId) { + return new MsoResponseWrapper2<>(syncRestClient + .get((workflowId <= 3 && workflowId > 0) ? getParametersUrl(workflowId) : getParametersUrl(), + Collections.emptyMap(), + Collections.emptyMap(), + SOWorkflowParameterDefinitions.class)); + } + @NotNull private String getWorkflowsUrl() { return baseUrl + "so/workflows"; } + + @NotNull + private String getParametersUrl() { + return baseUrl + "so/workflow-parameters"; + } + + @NotNull + private String getParametersUrl(Long workflowId) { + return baseUrl + "so/workflow-parameters/" + workflowId; + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java b/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java index 4ed26a14a..a62837c35 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java @@ -2,7 +2,10 @@ package org.onap.vid.services; import java.util.List; import org.onap.vid.model.SOWorkflow; +import org.onap.vid.model.SOWorkflowParameterDefinitions; public interface ExtWorkflowsService { List getWorkflows(String vnfName); + + SOWorkflowParameterDefinitions getWorkflowParameterDefinitions(Long workflowId); } diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java index d5170b6e5..a06e0b587 100644 --- a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java @@ -2,6 +2,7 @@ package org.onap.vid.services; import java.util.List; import org.onap.vid.model.SOWorkflow; +import org.onap.vid.model.SOWorkflowParameterDefinitions; import org.onap.vid.model.SOWorkflows; import org.onap.vid.mso.MsoResponseWrapper2; import org.onap.vid.mso.rest.MockedWorkflowsRestClient; @@ -21,25 +22,36 @@ public class ExtWorkflowsServiceImpl implements ExtWorkflowsService { @Override public List getWorkflows(String vnfName) { MsoResponseWrapper2 msoResponse = mockedWorkflowsRestClient.getWorkflows(vnfName); - if (msoResponse.getStatus() >= 400 || msoResponse.getEntity() == null) { - throw new BadResponseFromMso(msoResponse); - } + validateSOResponse(msoResponse, SOWorkflows.class); return convertMsoResponseToWorkflowList(msoResponse); } + @Override + public SOWorkflowParameterDefinitions getWorkflowParameterDefinitions(Long workflowId) { + MsoResponseWrapper2 msoResponse = mockedWorkflowsRestClient.getWorkflowParameterDefinitions(workflowId); + validateSOResponse(msoResponse, SOWorkflowParameterDefinitions.class); + return (SOWorkflowParameterDefinitions) msoResponse.getEntity(); + } + private List convertMsoResponseToWorkflowList(MsoResponseWrapper2 msoResponse) { SOWorkflows soWorkflows = (SOWorkflows) msoResponse.getEntity(); return soWorkflows.getWorkflows(); } + private void validateSOResponse(MsoResponseWrapper2 response, Class expectedResponseClass){ + if (response.getStatus() >= 400 || !expectedResponseClass.isInstance(response.getEntity())) { + throw new BadResponseFromMso(response); + } + } + public static class BadResponseFromMso extends RuntimeException { - private final MsoResponseWrapper2 msoResponse; + private final MsoResponseWrapper2 msoResponse; - public BadResponseFromMso(MsoResponseWrapper2 msoResponse) { + BadResponseFromMso(MsoResponseWrapper2 msoResponse) { this.msoResponse = msoResponse; } - public MsoResponseWrapper2 getMsoResponse() { + public MsoResponseWrapper2 getMsoResponse() { return msoResponse; } } -- cgit 1.2.3-korg