Sending workflow data from UI to SO
[vid.git] / vid-app-common / src / main / java / org / onap / vid / controller / WorkflowsController.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.vid.controller;
22
23 import java.util.List;
24 import java.util.UUID;
25
26 import org.onap.vid.changeManagement.UIWorkflowsRequest;
27 import org.onap.vid.model.LocalWorkflowParameterDefinitions;
28 import org.onap.vid.model.SOWorkflow;
29 import org.onap.vid.model.SOWorkflowParameterDefinitions;
30 import org.onap.vid.mso.MsoResponseWrapper;
31 import org.onap.vid.services.ChangeManagementService;
32 import org.onap.vid.services.ExternalWorkflowsService;
33 import org.onap.vid.services.LocalWorkflowsService;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.web.bind.annotation.PathVariable;
36 import org.springframework.web.bind.annotation.RequestBody;
37 import org.springframework.web.bind.annotation.RequestMapping;
38 import org.springframework.web.bind.annotation.RequestMethod;
39 import org.springframework.web.bind.annotation.RequestParam;
40 import org.springframework.web.bind.annotation.RestController;
41
42 import javax.servlet.http.HttpServletRequest;
43
44 @RestController
45 @RequestMapping(WorkflowsController.WORKFLOWS_MANAGEMENT)
46 public class WorkflowsController extends VidRestrictedBaseController {
47     static final String WORKFLOWS_MANAGEMENT = "workflows-management";
48
49     private ExternalWorkflowsService externalWorkflowsService;
50     private LocalWorkflowsService localWorkflowsService;
51     private ChangeManagementService changeManagementService;
52
53     @Autowired
54     public WorkflowsController(ExternalWorkflowsService externalWorkflowsService, LocalWorkflowsService localWorkflowsService,ChangeManagementService changeManagementService) {
55         this.externalWorkflowsService = externalWorkflowsService;
56         this.localWorkflowsService = localWorkflowsService;
57         this.changeManagementService = changeManagementService;
58     }
59
60     @RequestMapping(value = "workflows", method = RequestMethod.GET)
61     public List<SOWorkflow> getWorkflows(@RequestParam(value = "vnfModelId") String vnfModelId){
62         return externalWorkflowsService.getWorkflows(vnfModelId);
63     }
64
65     @RequestMapping(value = "remote-workflow-parameters/{id}", method = RequestMethod.GET)
66     SOWorkflowParameterDefinitions getParameters(@PathVariable Long id) {
67         return externalWorkflowsService.getWorkflowParameterDefinitions(id);
68     }
69
70     @RequestMapping(value = "local-workflow-parameters/{name}", method = RequestMethod.GET)
71     LocalWorkflowParameterDefinitions getParameters(@PathVariable String name) {
72         return localWorkflowsService.getWorkflowParameterDefinitions(name);
73     }
74
75     @RequestMapping(value = "{serviceInstanceId}/{vnfInstanceId}/{workflow_UUID}", method = RequestMethod.POST)
76     public MsoResponseWrapper getWorkflowFromUI(HttpServletRequest request, @PathVariable("serviceInstanceId") UUID serviceInstanceId, @PathVariable("vnfInstanceId") UUID vnfInstanceId, @PathVariable("workflow_UUID") UUID workflow_UUID, @RequestBody UIWorkflowsRequest requestBody) {
77         return changeManagementService.invokeVnfWorkflow(request,requestBody.getRequestDetails(), serviceInstanceId, vnfInstanceId, workflow_UUID);
78     }
79
80 }
81