7f569cfbacfac165ab4e26960cace5b800092d61
[ccsdk/cds.git] /
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 org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
20 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ResourceDictionaryHandler
21 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
22 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
23 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
24 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping
25 import org.springframework.http.MediaType
26 import org.springframework.web.bind.annotation.DeleteMapping
27 import org.springframework.web.bind.annotation.GetMapping
28 import org.springframework.web.bind.annotation.PathVariable
29 import org.springframework.web.bind.annotation.PostMapping
30 import org.springframework.web.bind.annotation.RequestBody
31 import org.springframework.web.bind.annotation.RequestMapping
32 import org.springframework.web.bind.annotation.ResponseBody
33 import org.springframework.web.bind.annotation.RestController
34
35 @RestController
36 @RequestMapping(value = ["/api/v1/dictionary"])
37 open class ResourceDictionaryController(private val resourceDictionaryHandler: ResourceDictionaryHandler) {
38
39     @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE])
40     @ResponseBody
41     @Throws(BluePrintException::class)
42     suspend fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary =
43         mdcWebCoroutineScope {
44             resourceDictionaryHandler.getResourceDictionaryByName(name)
45         }
46
47     @PostMapping(
48         path = [""],
49         produces = [MediaType.APPLICATION_JSON_VALUE],
50         consumes = [MediaType.APPLICATION_JSON_VALUE]
51     )
52     @ResponseBody
53     @Throws(BluePrintException::class)
54     suspend fun saveResourceDictionary(@RequestBody dataDictionary: ResourceDictionary): ResourceDictionary =
55         mdcWebCoroutineScope {
56             resourceDictionaryHandler.saveResourceDictionary(dataDictionary)
57         }
58
59     @PostMapping(
60         path = ["/definition"],
61         produces = [MediaType.APPLICATION_JSON_VALUE],
62         consumes = [MediaType.APPLICATION_JSON_VALUE]
63     )
64     @ResponseBody
65     @Throws(BluePrintException::class)
66     suspend fun saveResourceDictionary(@RequestBody resourceDefinition: ResourceDefinition): ResourceDefinition =
67         mdcWebCoroutineScope {
68             resourceDictionaryHandler.saveResourceDefinition(resourceDefinition)
69         }
70
71     @DeleteMapping(path = ["/{name}"])
72     suspend fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) = mdcWebCoroutineScope {
73         resourceDictionaryHandler.deleteResourceDictionary(name)
74     }
75
76     @PostMapping(
77         path = ["/by-names"],
78         produces = [MediaType.APPLICATION_JSON_VALUE],
79         consumes = [MediaType.APPLICATION_JSON_VALUE]
80     )
81     @ResponseBody
82     suspend fun searchResourceDictionaryByNames(@RequestBody names: List<String>): List<ResourceDictionary> =
83         mdcWebCoroutineScope {
84             resourceDictionaryHandler.searchResourceDictionaryByNames(names)
85         }
86
87     @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
88     @ResponseBody
89     suspend fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List<ResourceDictionary> =
90         mdcWebCoroutineScope {
91             resourceDictionaryHandler.searchResourceDictionaryByTags(tags)
92         }
93
94     @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE])
95     @ResponseBody
96     suspend fun getResourceSourceMapping(): ResourceSourceMapping = mdcWebCoroutineScope {
97         resourceDictionaryHandler.getResourceSourceMapping()
98     }
99
100     @GetMapping(path = ["/resource_dictionary_group"], produces = [MediaType.APPLICATION_JSON_VALUE])
101     @ResponseBody
102     suspend fun getResourceDictionaryDistinct(): List<String> = mdcWebCoroutineScope {
103         resourceDictionaryHandler.getResourceDictionaryDistinct()
104     }
105 }