2 * Copyright © 2019 IBM.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
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.DeleteMapping
26 import org.springframework.web.bind.annotation.GetMapping
27 import org.springframework.web.bind.annotation.PathVariable
28 import org.springframework.web.bind.annotation.PostMapping
29 import org.springframework.web.bind.annotation.RequestBody
30 import org.springframework.web.bind.annotation.RequestMapping
31 import org.springframework.web.bind.annotation.ResponseBody
32 import org.springframework.web.bind.annotation.RestController
35 @RequestMapping(value = ["/api/v1/dictionary"])
36 open class ResourceDictionaryController(private val resourceDictionaryHandler: ResourceDictionaryHandler) {
38 @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE])
40 @Throws(BluePrintException::class)
41 fun getResourceDictionaryByName(@PathVariable(value = "name") name: String): ResourceDictionary = runBlocking {
42 resourceDictionaryHandler.getResourceDictionaryByName(name)
45 @PostMapping(path = [""], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE])
47 @Throws(BluePrintException::class)
48 fun saveResourceDictionary(@RequestBody dataDictionary: ResourceDictionary): ResourceDictionary = runBlocking {
49 resourceDictionaryHandler.saveResourceDictionary(dataDictionary)
52 @DeleteMapping(path = ["/{name}"])
53 fun deleteResourceDictionaryByName(@PathVariable(value = "name") name: String) = runBlocking {
54 resourceDictionaryHandler.deleteResourceDictionary(name)
57 @PostMapping(path = ["/by-names"], produces = [MediaType.APPLICATION_JSON_VALUE], consumes = [MediaType.APPLICATION_JSON_VALUE])
59 fun searchResourceDictionaryByNames(@RequestBody names: List<String>): List<ResourceDictionary> = runBlocking {
60 resourceDictionaryHandler.searchResourceDictionaryByNames(names)
63 @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
65 fun searchResourceDictionaryByTags(@PathVariable(value = "tags") tags: String): List<ResourceDictionary> = runBlocking {
66 resourceDictionaryHandler.searchResourceDictionaryByTags(tags)
69 @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE])
71 fun getResourceSourceMapping(): ResourceSourceMapping = runBlocking {
72 resourceDictionaryHandler.getResourceSourceMapping()