Merge "Add support for async REST"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / selfservice-api / src / main / kotlin / org / onap / ccsdk / apps / blueprintsprocessor / selfservice / api / ExecutionServiceController.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
18
19 import io.swagger.annotations.ApiOperation
20 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
21 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput
22 import org.springframework.beans.factory.annotation.Autowired
23 import org.springframework.http.MediaType
24 import org.springframework.http.codec.multipart.FilePart
25 import org.springframework.web.bind.annotation.PostMapping
26 import org.springframework.web.bind.annotation.RequestBody
27 import org.springframework.web.bind.annotation.RequestMapping
28 import org.springframework.web.bind.annotation.RequestMethod
29 import org.springframework.web.bind.annotation.RequestPart
30 import org.springframework.web.bind.annotation.ResponseBody
31 import org.springframework.web.bind.annotation.RestController
32 import reactor.core.publisher.Mono
33
34 @RestController
35 @RequestMapping("/api/v1/execution-service")
36 class ExecutionServiceController {
37
38     @Autowired
39     lateinit var executionServiceHandler: ExecutionServiceHandler
40
41     @RequestMapping(path = ["/ping"], method = [RequestMethod.GET], produces = [MediaType.APPLICATION_JSON_VALUE])
42     @ResponseBody
43     fun ping(): Mono<String> {
44         return Mono.just("Success")
45     }
46
47     @PostMapping(path = ["/upload"], consumes = [MediaType.MULTIPART_FORM_DATA_VALUE])
48     @ApiOperation(value = "Upload CBA", notes = "Takes a File and load it in the runtime database")
49     @ResponseBody
50     fun upload(@RequestPart("file") parts: Mono<FilePart>): Mono<String> {
51         return parts
52                 .filter { it is FilePart }
53                 .ofType(FilePart::class.java)
54                 .flatMap(executionServiceHandler::upload)
55     }
56
57     @RequestMapping(path = ["/process"], method = [RequestMethod.POST], produces = [MediaType.APPLICATION_JSON_VALUE])
58     @ApiOperation(value = "Resolve Resource Mappings", notes = "Takes the blueprint information and process as per the payload")
59     @ResponseBody
60     fun process(@RequestBody executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {
61         return executionServiceHandler.process(executionServiceInput)
62     }
63 }