summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/main/java')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java6
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java31
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt13
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java32
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/rest/MockedWorkflowsRestClient.java33
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java8
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java47
7 files changed, 154 insertions, 16 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java b/vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java
index 7f90d6a43..efe6c206a 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/MsoConfig.java
@@ -29,6 +29,7 @@ import org.onap.vid.mso.MsoBusinessLogic;
import org.onap.vid.mso.MsoBusinessLogicImpl;
import org.onap.vid.mso.MsoInterface;
import org.onap.vid.mso.MsoProperties;
+import org.onap.vid.mso.rest.MockedWorkflowsRestClient;
import org.onap.vid.mso.rest.MsoRestClientNew;
import org.onap.vid.services.CloudOwnerService;
import org.onap.vid.services.CloudOwnerServiceImpl;
@@ -53,6 +54,11 @@ public class MsoConfig {
}
@Bean
+ public MockedWorkflowsRestClient mockedWorkflowsClient(ObjectMapper unirestObjectMapper){
+ return new MockedWorkflowsRestClient(new SyncRestClient(unirestObjectMapper), "http://vid-simulator:1080/");
+ }
+
+ @Bean
public MsoBusinessLogic getMsoBusinessLogic(MsoInterface msoClient, FeatureManager featureManager){
return new MsoBusinessLogicImpl(msoClient, featureManager);
}
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
new file mode 100644
index 000000000..be1976a48
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java
@@ -0,0 +1,31 @@
+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.services.ExtWorkflowsService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping(WorkflowsController.WORKFLOWS_MANAGEMENT)
+public class WorkflowsController extends RestrictedBaseController {
+ static final String WORKFLOWS_MANAGEMENT = "workflows-management";
+
+ private ExtWorkflowsService extWorkflowsService;
+
+ @Autowired
+ public WorkflowsController(ExtWorkflowsService extWorkflowsService) {
+ this.extWorkflowsService = extWorkflowsService;
+ }
+
+ @RequestMapping(value = "workflows", method = RequestMethod.GET)
+ public List<SOWorkflow> getWorkflows(@RequestParam(value = "vnfName") String vnfName){
+ return extWorkflowsService.getWorkflows(vnfName);
+ }
+
+}
+
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
new file mode 100644
index 000000000..c85bfd7d4
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt
@@ -0,0 +1,13 @@
+package org.onap.vid.model
+
+data class SOWorkflow @JvmOverloads constructor(var id: Long? = null, var name: String? = null) {
+ fun clone(): SOWorkflow {
+ return copy()
+ }
+}
+
+data class SOWorkflows @JvmOverloads constructor(var workflows: List<SOWorkflow>? = emptyList()) {
+ fun clone(): SOWorkflows {
+ return copy(workflows?.toMutableList())
+ }
+} \ No newline at end of file
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java b/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java
index fff14ebc3..3bda76406 100644
--- a/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/MsoResponseWrapper2.java
@@ -28,8 +28,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.joshworks.restclient.http.HttpResponse;
@JsonPropertyOrder({
- "status",
- "entity"
+ "status",
+ "entity"
})
/*
@@ -41,8 +41,8 @@ public class MsoResponseWrapper2<T> implements MsoResponseWrapperInterface {
static final ObjectMapper objectMapper = new ObjectMapper();
- private final int status;
- private final T entity;
+ private final int status;
+ private T entity;
private final String raw;
public MsoResponseWrapper2(RestObject<T> msoResponse) {
@@ -51,23 +51,23 @@ public class MsoResponseWrapper2<T> implements MsoResponseWrapperInterface {
this.raw = msoResponse.getRaw();
}
- public MsoResponseWrapper2(HttpResponse<T> msoResponse) {
- this.status = msoResponse.getStatus();
- this.entity = msoResponse.getBody();
- this.raw = msoResponse.getBody().toString();
- }
+ public MsoResponseWrapper2(HttpResponse<T> msoResponse) {
+ this.status = msoResponse.getStatus();
+ this.entity = msoResponse.getBody();
+ this.raw = msoResponse.getBody().toString();
+ }
public MsoResponseWrapper2(
- @JsonProperty(value = "status", required = true) int status,
- @JsonProperty(value = "entity", required = true) T entity) {
+ @JsonProperty(value = "status", required = true) int status,
+ @JsonProperty(value = "entity", required = true) T entity) {
this.status = status;
this.entity = entity;
this.raw = null;
}
public int getStatus() {
- return status;
- }
+ return status;
+ }
@Override
@JsonIgnore
@@ -80,8 +80,8 @@ public class MsoResponseWrapper2<T> implements MsoResponseWrapperInterface {
}
@JsonProperty
- public Object getEntity() {
- return entity != null ? entity : raw;
- }
+ public Object getEntity() {
+ return entity != null ? entity : raw;
+ }
}
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
new file mode 100644
index 000000000..313710ebd
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/MockedWorkflowsRestClient.java
@@ -0,0 +1,33 @@
+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.SOWorkflows;
+import org.onap.vid.mso.MsoResponseWrapper2;
+
+public class MockedWorkflowsRestClient {
+
+ private SyncRestClient syncRestClient;
+ private String baseUrl;
+
+ public MockedWorkflowsRestClient(SyncRestClient syncRestClient, String baseUrl) {
+ this.syncRestClient = syncRestClient;
+ this.baseUrl = baseUrl;
+ }
+
+ public MsoResponseWrapper2<SOWorkflows> getWorkflows(String vnfName) {
+ // Temporary skip vnfName and call mocked service
+ return new MsoResponseWrapper2<>(syncRestClient
+ .get(getWorkflowsUrl(),
+ Collections.emptyMap(),
+ Collections.emptyMap(),
+ SOWorkflows.class));
+ }
+
+ @NotNull
+ private String getWorkflowsUrl() {
+ return baseUrl + "so/workflows";
+ }
+
+}
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
new file mode 100644
index 000000000..4ed26a14a
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java
@@ -0,0 +1,8 @@
+package org.onap.vid.services;
+
+import java.util.List;
+import org.onap.vid.model.SOWorkflow;
+
+public interface ExtWorkflowsService {
+ List<SOWorkflow> getWorkflows(String vnfName);
+}
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
new file mode 100644
index 000000000..d5170b6e5
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java
@@ -0,0 +1,47 @@
+package org.onap.vid.services;
+
+import java.util.List;
+import org.onap.vid.model.SOWorkflow;
+import org.onap.vid.model.SOWorkflows;
+import org.onap.vid.mso.MsoResponseWrapper2;
+import org.onap.vid.mso.rest.MockedWorkflowsRestClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ExtWorkflowsServiceImpl implements ExtWorkflowsService {
+
+ private MockedWorkflowsRestClient mockedWorkflowsRestClient;
+
+ @Autowired
+ public ExtWorkflowsServiceImpl(MockedWorkflowsRestClient mockedWorkflowsRestClient) {
+ this.mockedWorkflowsRestClient = mockedWorkflowsRestClient;
+ }
+
+ @Override
+ public List<SOWorkflow> getWorkflows(String vnfName) {
+ MsoResponseWrapper2<SOWorkflows> msoResponse = mockedWorkflowsRestClient.getWorkflows(vnfName);
+ if (msoResponse.getStatus() >= 400 || msoResponse.getEntity() == null) {
+ throw new BadResponseFromMso(msoResponse);
+ }
+ return convertMsoResponseToWorkflowList(msoResponse);
+ }
+
+ private List<SOWorkflow> convertMsoResponseToWorkflowList(MsoResponseWrapper2<SOWorkflows> msoResponse) {
+ SOWorkflows soWorkflows = (SOWorkflows) msoResponse.getEntity();
+ return soWorkflows.getWorkflows();
+ }
+
+ public static class BadResponseFromMso extends RuntimeException {
+ private final MsoResponseWrapper2<SOWorkflows> msoResponse;
+
+ public BadResponseFromMso(MsoResponseWrapper2<SOWorkflows> msoResponse) {
+ this.msoResponse = msoResponse;
+ }
+
+ public MsoResponseWrapper2<SOWorkflows> getMsoResponse() {
+ return msoResponse;
+ }
+ }
+
+}