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.designer.api.utils.DictionarySortByOption
25 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
26 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
27 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
28 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceSourceMapping
29 import org.springframework.data.domain.Page
30 import org.springframework.data.domain.PageRequest
31 import org.springframework.data.domain.Sort
32 import org.springframework.http.MediaType
33 import org.springframework.web.bind.annotation.DeleteMapping
34 import org.springframework.web.bind.annotation.GetMapping
35 import org.springframework.web.bind.annotation.PathVariable
36 import org.springframework.web.bind.annotation.PostMapping
37 import org.springframework.web.bind.annotation.RequestBody
38 import org.springframework.web.bind.annotation.RequestMapping
39 import org.springframework.web.bind.annotation.RequestParam
40 import org.springframework.web.bind.annotation.ResponseBody
41 import org.springframework.web.bind.annotation.RestController
44 @RequestMapping(value = ["/api/v1/dictionary"])
46 value = "Resource Dictionary",
47 description = "Interaction with stored dictionaries"
49 open class ResourceDictionaryController(private val resourceDictionaryHandler: ResourceDictionaryHandler) {
51 @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE])
53 value = "Retrieve a resource dictionary",
54 notes = "Retrieve a resource dictionary by name provided.",
55 response = ResourceDictionary::class
58 @Throws(BluePrintException::class)
59 suspend fun getResourceDictionaryByName(
60 @ApiParam(value = "Name of the resource", required = true, example = "\"hostname\"")
61 @PathVariable(value = "name") name: String
62 ): ResourceDictionary =
63 mdcWebCoroutineScope {
64 resourceDictionaryHandler.getResourceDictionaryByName(name)
67 @GetMapping("/paged", produces = [MediaType.APPLICATION_JSON_VALUE])
69 value = "Get Blueprints Dictionary ordered",
70 notes = "Lists all blueprint Dictionary which are saved in CDS in an ordered mode.",
71 nickname = "BlueprintModelController_allBlueprintDictionaryPaged_GET.org.onap.ccsdk.cds.blueprintsprocessor.designer.api"
74 suspend fun allBlueprintModel(
75 @ApiParam(value = "Maximum number of returned blueprint dictionary") @RequestParam(defaultValue = "20") limit: Int,
76 @ApiParam(value = "Offset") @RequestParam(defaultValue = "0") offset: Int,
77 @ApiParam(value = "Order of returned blueprint dictionary") @RequestParam(defaultValue = "DATE") sort: DictionarySortByOption,
78 @ApiParam(value = "Ascend or descend ordering") @RequestParam(defaultValue = "ASC") sortType: String
79 ): Page<ResourceDictionary> {
80 val pageRequest = PageRequest.of(
82 Sort.Direction.fromString(sortType), sort.columnName
84 return resourceDictionaryHandler.getAllDictionary(pageRequest)
88 produces = [MediaType.APPLICATION_JSON_VALUE],
89 consumes = [MediaType.APPLICATION_JSON_VALUE]
92 value = "Save a resource dictionary",
93 notes = "Save a resource dictionary by dictionary provided.",
94 response = ResourceDictionary::class
97 @Throws(BluePrintException::class)
98 suspend fun saveResourceDictionary(
99 @ApiParam(value = "Resource dictionary to store", required = true)
100 @RequestBody resourceDictionary: ResourceDictionary
101 ): ResourceDictionary =
102 mdcWebCoroutineScope {
103 resourceDictionaryHandler.saveResourceDictionary(resourceDictionary)
107 path = ["/definition"],
108 produces = [MediaType.APPLICATION_JSON_VALUE],
109 consumes = [MediaType.APPLICATION_JSON_VALUE]
112 value = "Save a resource dictionary",
113 notes = "Save a resource dictionary by provided resource definition json.",
114 nickname = "ResourceDictionaryController_saveResourceDictionary_1_POST.org.onap.ccsdk.cds.blueprintsprocessor.designer.api",
115 response = ResourceDictionary::class
118 @Throws(BluePrintException::class)
119 suspend fun saveResourceDefinition(
120 @ApiParam(value = "Resource definition to generate Resource Dictionary", required = true)
121 @RequestBody resourceDefinition: ResourceDefinition
122 ): ResourceDictionary =
123 mdcWebCoroutineScope {
124 resourceDictionaryHandler.saveResourceDefinition(resourceDefinition)
128 path = ["/definition-bulk"],
129 produces = [MediaType.APPLICATION_JSON_VALUE],
130 consumes = [MediaType.APPLICATION_JSON_VALUE]
133 value = "Save multiple resource dictionaries",
134 notes = "Save multiple resource dictionaries by provided resource definition json array.",
135 nickname = "ResourceDictionaryController_saveAllResourceDictionary_1_POST.org.onap.ccsdk.cds.blueprintsprocessor.designer.api",
136 response = ResourceDictionary::class
139 @Throws(BluePrintException::class)
140 suspend fun saveAllResourceDictionary(
141 @ApiParam(value = "Resource definition json array to generate Resource Dictionaries", required = true)
142 @RequestBody resourceDefinition: List<ResourceDefinition>
143 ): MutableList<ResourceDictionary> =
144 mdcWebCoroutineScope {
145 resourceDictionaryHandler.saveAllResourceDefinition(resourceDefinition)
148 @DeleteMapping(path = ["/{name}"])
150 value = "Remove a resource dictionary",
151 notes = "Remove a resource dictionary by name provided."
153 suspend fun deleteResourceDictionaryByName(
154 @ApiParam(value = "Name of the resource", required = true)
155 @PathVariable(value = "name") name: String
156 ) = mdcWebCoroutineScope {
157 resourceDictionaryHandler.deleteResourceDictionary(name)
161 path = ["/by-names"],
162 produces = [MediaType.APPLICATION_JSON_VALUE],
163 consumes = [MediaType.APPLICATION_JSON_VALUE]
166 value = "Search for a resource dictionary",
167 notes = "Search for a resource dictionary by names provided.",
168 responseContainer = "List",
169 response = ResourceDictionary::class
172 suspend fun searchResourceDictionaryByNames(
173 @ApiParam(value = "List of names", required = true)
174 @RequestBody names: List<String>
175 ): List<ResourceDictionary> =
176 mdcWebCoroutineScope {
177 resourceDictionaryHandler.searchResourceDictionaryByNames(names)
180 @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
182 value = "Search for a resource dictionary",
183 notes = "Search for a resource dictionary by tags provided.",
184 responseContainer = "List",
185 response = ResourceDictionary::class
188 suspend fun searchResourceDictionaryByTags(
189 @ApiParam(value = "Tags list", required = true, example = "\"status\"")
190 @PathVariable(value = "tags") tags: String
191 ): List<ResourceDictionary> =
192 mdcWebCoroutineScope {
193 resourceDictionaryHandler.searchResourceDictionaryByTags(tags)
196 @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE])
198 value = "Search for a source mapping",
199 notes = "Search for a source mapping.",
200 response = ResourceSourceMapping::class
203 suspend fun getResourceSourceMapping(): ResourceSourceMapping = mdcWebCoroutineScope {
204 resourceDictionaryHandler.getResourceSourceMapping()
207 @GetMapping(path = ["/resource_dictionary_group"], produces = [MediaType.APPLICATION_JSON_VALUE])
209 value = "Retrieve all resource dictionary groups",
210 notes = "Retrieve all resource dictionary groups.",
211 responseContainer = "List",
212 response = String::class
215 suspend fun getResourceDictionaryDistinct(): List<String> = mdcWebCoroutineScope {
216 resourceDictionaryHandler.getResourceDictionaryDistinct()