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