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 io.swagger.annotations.Api
20 import io.swagger.annotations.ApiOperation
21 import io.swagger.annotations.ApiParam
22 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
23 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ResourceDictionaryHandler
24 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
25 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
26 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
27 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping
28 import org.springframework.http.MediaType
29 import org.springframework.web.bind.annotation.DeleteMapping
30 import org.springframework.web.bind.annotation.GetMapping
31 import org.springframework.web.bind.annotation.PathVariable
32 import org.springframework.web.bind.annotation.PostMapping
33 import org.springframework.web.bind.annotation.RequestBody
34 import org.springframework.web.bind.annotation.RequestMapping
35 import org.springframework.web.bind.annotation.ResponseBody
36 import org.springframework.web.bind.annotation.RestController
39 @RequestMapping(value = ["/api/v1/dictionary"])
41 value = "Resource dictionary",
42 description = "Interaction with stored dictionaries."
44 open class ResourceDictionaryController(private val resourceDictionaryHandler: ResourceDictionaryHandler) {
46 @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE])
48 value = "Retrieve a resource dictionary.",
49 notes = "Retrieve a resource dictionary by name provided.",
50 response = ResourceDictionary::class
53 @Throws(BluePrintException::class)
54 suspend fun getResourceDictionaryByName(
55 @ApiParam(value = "Name of the resource.", required = true, example = "\"hostname\"")
56 @PathVariable(value = "name") name: String
57 ): ResourceDictionary =
58 mdcWebCoroutineScope {
59 resourceDictionaryHandler.getResourceDictionaryByName(name)
63 produces = [MediaType.APPLICATION_JSON_VALUE],
64 consumes = [MediaType.APPLICATION_JSON_VALUE]
67 value = "Saves a resource dictionary.",
68 notes = "Saves a resource dictionary by dictionary provided.",
69 response = ResourceDictionary::class
72 @Throws(BluePrintException::class)
73 suspend fun saveResourceDictionary(
74 @ApiParam(value = "Resource dictionary to store.", required = true)
75 @RequestBody dataDictionary: ResourceDictionary
76 ): ResourceDictionary =
77 mdcWebCoroutineScope {
78 resourceDictionaryHandler.saveResourceDictionary(dataDictionary)
82 path = ["/definition"],
83 produces = [MediaType.APPLICATION_JSON_VALUE],
84 consumes = [MediaType.APPLICATION_JSON_VALUE]
87 value = "Saves a resource dictionary.",
88 notes = "Saves a resource dictionary by resource definition provided.",
89 nickname = "ResourceDictionaryController_saveResourceDictionary_1_POST.org.onap.ccsdk.cds.blueprintsprocessor.designer.api",
90 response = ResourceDefinition::class
93 @Throws(BluePrintException::class)
94 suspend fun saveResourceDictionary(
95 @ApiParam(value = "Resource definition to generate.", required = true)
96 @RequestBody resourceDefinition: ResourceDefinition
97 ): ResourceDefinition =
98 mdcWebCoroutineScope {
99 resourceDictionaryHandler.saveResourceDefinition(resourceDefinition)
102 @DeleteMapping(path = ["/{name}"])
104 value = "Removes a resource dictionary.",
105 notes = "Removes a resource dictionary by name provided."
107 suspend fun deleteResourceDictionaryByName(
108 @ApiParam(value = "Name of the resource.", required = true)
109 @PathVariable(value = "name") name: String
110 ) = mdcWebCoroutineScope {
111 resourceDictionaryHandler.deleteResourceDictionary(name)
115 path = ["/by-names"],
116 produces = [MediaType.APPLICATION_JSON_VALUE],
117 consumes = [MediaType.APPLICATION_JSON_VALUE]
120 value = "Searches for a resource dictionary.",
121 notes = "Searches for a resource dictionary by names provided.",
122 responseContainer = "List",
123 response = ResourceDictionary::class
126 suspend fun searchResourceDictionaryByNames(
127 @ApiParam(value = "List of names.", required = true)
128 @RequestBody names: List<String>
129 ): List<ResourceDictionary> =
130 mdcWebCoroutineScope {
131 resourceDictionaryHandler.searchResourceDictionaryByNames(names)
134 @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
136 value = "Searches for a resource dictionary.",
137 notes = "Searches for a resource dictionary by tags provided.",
138 responseContainer = "List",
139 response = ResourceDictionary::class
142 suspend fun searchResourceDictionaryByTags(
143 @ApiParam(value = "Tags list.", required = true, example = "\"status\"")
144 @PathVariable(value = "tags") tags: String
145 ): List<ResourceDictionary> =
146 mdcWebCoroutineScope {
147 resourceDictionaryHandler.searchResourceDictionaryByTags(tags)
150 @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE])
152 value = "Searches for a source mapping.",
153 notes = "Searches for a source mapping.",
154 response = ResourceSourceMapping::class
157 suspend fun getResourceSourceMapping(): ResourceSourceMapping = mdcWebCoroutineScope {
158 resourceDictionaryHandler.getResourceSourceMapping()
161 @GetMapping(path = ["/resource_dictionary_group"], produces = [MediaType.APPLICATION_JSON_VALUE])
163 value = "Retrieve all resource dictionary groups.",
164 notes = "Retrieve all resource dictionary groups.",
165 responseContainer = "List",
166 response = String::class
169 suspend fun getResourceDictionaryDistinct(): List<String> = mdcWebCoroutineScope {
170 resourceDictionaryHandler.getResourceDictionaryDistinct()