Merge "Fix errors in INFO.yaml"
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / designer-api / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / designer / api / ResourceDictionaryController.kt
1 /*
2  *  Copyright © 2019 IBM.
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.cds.blueprintsprocessor.designer.api
18
19 import kotlinx.coroutines.runBlocking
20 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
21 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ResourceDictionaryHandler
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
23 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping
24 import org.springframework.http.MediaType
25 import org.springframework.web.bind.annotation.*
26
27 @RestController
28 @RequestMapping(value = ["/api/v1/dictionary"])
29 open class ResourceDictionaryController(private val resourceDictionaryHandler: ResourceDictionaryHandler) {
30
31     @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE])
32     @ResponseBody
33     @Throws(BluePrintException::class)
34     fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary = runBlocking {
35         resourceDictionaryHandler.getResourceDictionaryByName(name)
36     }
37
38     @PostMapping(path = [""], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE])
39     @ResponseBody
40     @Throws(BluePrintException::class)
41     fun saveResourceDictionary(@RequestBody dataDictionary: ResourceDictionary): ResourceDictionary = runBlocking {
42         resourceDictionaryHandler.saveResourceDictionary(dataDictionary)
43     }
44
45     @DeleteMapping(path = ["/{name}"])
46     fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) = runBlocking {
47         resourceDictionaryHandler.deleteResourceDictionary(name)
48     }
49
50     @PostMapping(path = ["/by-names"], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE])
51     @ResponseBody
52     fun searchResourceDictionaryByNames(@RequestBody names: List<String>): List<ResourceDictionary> = runBlocking {
53         resourceDictionaryHandler.searchResourceDictionaryByNames(names)
54     }
55
56     @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
57     @ResponseBody
58     fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List<ResourceDictionary> = runBlocking {
59         resourceDictionaryHandler.searchResourceDictionaryByTags(tags)
60
61     }
62
63     @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE])
64     @ResponseBody
65     fun getResourceSourceMapping(): ResourceSourceMapping = runBlocking {
66         resourceDictionaryHandler.getResourceSourceMapping()
67     }
68
69 }