Revert "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 / ModelTypeController.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  * Modifications Copyright © 2019 IBM.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
19
20 import io.swagger.annotations.Api
21 import io.swagger.annotations.ApiOperation
22 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType
23 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ModelTypeHandler
24 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
25 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
26 import org.springframework.http.MediaType
27 import org.springframework.web.bind.annotation.DeleteMapping
28 import org.springframework.web.bind.annotation.GetMapping
29 import org.springframework.web.bind.annotation.PathVariable
30 import org.springframework.web.bind.annotation.PostMapping
31 import org.springframework.web.bind.annotation.RequestBody
32 import org.springframework.web.bind.annotation.RequestMapping
33 import org.springframework.web.bind.annotation.ResponseBody
34 import org.springframework.web.bind.annotation.RestController
35
36 @RestController
37 @RequestMapping(value = ["/api/v1/model-type"])
38 @Api(
39     value = "Model Type Catalog",
40     description = "Manages data types in CDS"
41 )
42 open class ModelTypeController(private val modelTypeHandler: ModelTypeHandler) {
43
44     @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE])
45     @ApiOperation(
46         value = "Retrieve a model type",
47         notes = "Retrieve a model type by name provided.",
48         response = ModelType::class
49     )
50     suspend fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? = mdcWebCoroutineScope {
51         modelTypeHandler.getModelTypeByName(name)
52     }
53
54     @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
55     @ApiOperation(
56         value = "Retrieve a list of model types",
57         notes = "Retrieve a list of model types by tags provided.",
58         responseContainer = "List",
59         response = ModelType::class
60     )
61     suspend fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> = mdcWebCoroutineScope {
62         modelTypeHandler.searchModelTypes(tags)
63     }
64
65     @GetMapping(path = ["/by-definition/{definitionType}"], produces = [MediaType.APPLICATION_JSON_VALUE])
66     @ApiOperation(
67         value = "Retrieve a list of model types",
68         notes = "Retrieve a list of model types by definition type provided.",
69         responseContainer = "List",
70         response = ModelType::class
71     )
72     @ResponseBody
73     suspend fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> =
74         mdcWebCoroutineScope {
75             modelTypeHandler.getModelTypeByDefinitionType(definitionType)
76         }
77
78     @PostMapping(
79         path = ["/"],
80         produces = [MediaType.APPLICATION_JSON_VALUE],
81         consumes = [MediaType.APPLICATION_JSON_VALUE]
82     )
83     @ApiOperation(
84         value = "Save a model type",
85         notes = "Save a model type by model type definition provided.",
86         response = ModelType::class
87     )
88     @ResponseBody
89     @Throws(BluePrintException::class)
90     suspend fun saveModelType(@RequestBody modelType: ModelType): ModelType = mdcWebCoroutineScope {
91         modelTypeHandler.saveModel(modelType)
92     }
93
94     @DeleteMapping(path = ["/{name}"])
95     @ApiOperation(
96         value = "Remove a model type",
97         notes = "Remove a model type by name provided.",
98         response = ModelType::class
99     )
100     suspend fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = mdcWebCoroutineScope {
101         modelTypeHandler.deleteByModelName(name)
102     }
103 }