Renaming Files having BluePrint to have Blueprint
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / designer-api / src / main / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / designer / api / ResourceDictionaryController.kt
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 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
37
38 @RestController
39 @RequestMapping(value = ["/api/v1/dictionary"])
40 @Api(
41     value = "Resource dictionary",
42     description = "Interaction with stored dictionaries"
43 )
44 open class ResourceDictionaryController(private val resourceDictionaryHandler: ResourceDictionaryHandler) {
45
46     @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE])
47     @ApiOperation(
48         value = "Retrieve a resource dictionary",
49         notes = "Retrieve a resource dictionary by name provided.",
50         response = ResourceDictionary::class
51     )
52     @ResponseBody
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)
60         }
61
62     @PostMapping(
63         produces = [MediaType.APPLICATION_JSON_VALUE],
64         consumes = [MediaType.APPLICATION_JSON_VALUE]
65     )
66     @ApiOperation(
67         value = "Save a resource dictionary",
68         notes = "Save a resource dictionary by dictionary provided.",
69         response = ResourceDictionary::class
70     )
71     @ResponseBody
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)
79         }
80
81     @PostMapping(
82         path = ["/definition"],
83         produces = [MediaType.APPLICATION_JSON_VALUE],
84         consumes = [MediaType.APPLICATION_JSON_VALUE]
85     )
86     @ApiOperation(
87         value = "Save a resource dictionary",
88         notes = "Save a resource dictionary by resource definition provided.",
89         nickname = "ResourceDictionaryController_saveResourceDictionary_1_POST.org.onap.ccsdk.cds.blueprintsprocessor.designer.api",
90         response = ResourceDefinition::class
91     )
92     @ResponseBody
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)
100         }
101
102     @DeleteMapping(path = ["/{name}"])
103     @ApiOperation(
104         value = "Remove a resource dictionary",
105         notes = "Remove a resource dictionary by name provided."
106     )
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)
112     }
113
114     @PostMapping(
115         path = ["/by-names"],
116         produces = [MediaType.APPLICATION_JSON_VALUE],
117         consumes = [MediaType.APPLICATION_JSON_VALUE]
118     )
119     @ApiOperation(
120         value = "Search for a resource dictionary",
121         notes = "Search for a resource dictionary by names provided.",
122         responseContainer = "List",
123         response = ResourceDictionary::class
124     )
125     @ResponseBody
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)
132         }
133
134     @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
135     @ApiOperation(
136         value = "Search for a resource dictionary",
137         notes = "Search for a resource dictionary by tags provided.",
138         responseContainer = "List",
139         response = ResourceDictionary::class
140     )
141     @ResponseBody
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)
148         }
149
150     @GetMapping(path = ["/source-mapping"], produces = [MediaType.APPLICATION_JSON_VALUE])
151     @ApiOperation(
152         value = "Search for a source mapping",
153         notes = "Search for a source mapping.",
154         response = ResourceSourceMapping::class
155     )
156     @ResponseBody
157     suspend fun getResourceSourceMapping(): ResourceSourceMapping = mdcWebCoroutineScope {
158         resourceDictionaryHandler.getResourceSourceMapping()
159     }
160
161     @GetMapping(path = ["/resource_dictionary_group"], produces = [MediaType.APPLICATION_JSON_VALUE])
162     @ApiOperation(
163         value = "Retrieve all resource dictionary groups",
164         notes = "Retrieve all resource dictionary groups.",
165         responseContainer = "List",
166         response = String::class
167     )
168     @ResponseBody
169     suspend fun getResourceDictionaryDistinct(): List<String> = mdcWebCoroutineScope {
170         resourceDictionaryHandler.getResourceDictionaryDistinct()
171     }
172 }