75403d479ab580833fb1ed7ec9dbb53eef2351fa
[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 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.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     fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary = runBlocking {
43         resourceDictionaryHandler.getResourceDictionaryByName(name)
44     }
45
46     @PostMapping(path = [""], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE])
47     @ResponseBody
48     @Throws(BluePrintException::class)
49     fun saveResourceDictionary(@RequestBody dataDictionary: ResourceDictionary): ResourceDictionary = runBlocking {
50         resourceDictionaryHandler.saveResourceDictionary(dataDictionary)
51     }
52
53     @PostMapping(path = ["/definition"], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE])
54     @ResponseBody
55     @Throws(BluePrintException::class)
56     fun saveResourceDictionary(@RequestBody resourceDefinition: ResourceDefinition): ResourceDefinition = runBlocking {
57         resourceDictionaryHandler.saveResourceDefinition(resourceDefinition)
58     }
59
60     @DeleteMapping(path = ["/{name}"])
61     fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) = runBlocking {
62         resourceDictionaryHandler.deleteResourceDictionary(name)
63     }
64
65     @PostMapping(path = ["/by-names"], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE])
66     @ResponseBody
67     fun searchResourceDictionaryByNames(@RequestBody names: List<String>): List<ResourceDictionary> = runBlocking {
68         resourceDictionaryHandler.searchResourceDictionaryByNames(names)
69     }
70
71     @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
72     @ResponseBody
73     fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List<ResourceDictionary> = runBlocking {
74         resourceDictionaryHandler.searchResourceDictionaryByTags(tags)
75     }
76
77     @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE])
78     @ResponseBody
79     fun getResourceSourceMapping(): ResourceSourceMapping = runBlocking {
80         resourceDictionaryHandler.getResourceSourceMapping()
81     }
82
83     @GetMapping(path = ["/resource_dictionary_group"], produces = [MediaType.APPLICATION_JSON_VALUE])
84     @ResponseBody
85     fun getResourceDictionaryDistinct(): List<String> = runBlocking {
86         resourceDictionaryHandler.getResourceDictionaryDistinct()
87     }
88 }