2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 IBM.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api
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
37 @RequestMapping(value = ["/api/v1/model-type"])
39 value = "Model Type Catalog",
40 description = "Manages data types in CDS"
42 open class ModelTypeController(private val modelTypeHandler: ModelTypeHandler) {
44 @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE])
46 value = "Retrieve a model type",
47 notes = "Retrieve a model type by name provided.",
48 response = ModelType::class
50 suspend fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? = mdcWebCoroutineScope {
51 modelTypeHandler.getModelTypeByName(name)
54 @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
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
61 suspend fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> = mdcWebCoroutineScope {
62 modelTypeHandler.searchModelTypes(tags)
65 @GetMapping(path = ["/by-definition/{definitionType}"], produces = [MediaType.APPLICATION_JSON_VALUE])
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
73 suspend fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> =
74 mdcWebCoroutineScope {
75 modelTypeHandler.getModelTypeByDefinitionType(definitionType)
80 produces = [MediaType.APPLICATION_JSON_VALUE],
81 consumes = [MediaType.APPLICATION_JSON_VALUE]
84 value = "Save a model type",
85 notes = "Save a model type by model type definition provided.",
86 response = ModelType::class
89 @Throws(BluePrintException::class)
90 suspend fun saveModelType(@RequestBody modelType: ModelType): ModelType = mdcWebCoroutineScope {
91 modelTypeHandler.saveModel(modelType)
94 @DeleteMapping(path = ["/{name}"])
96 value = "Remove a model type",
97 notes = "Remove a model type by name provided.",
98 response = ModelType::class
100 suspend fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = mdcWebCoroutineScope {
101 modelTypeHandler.deleteByModelName(name)