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 org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType
21 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ModelTypeHandler
22 import org.onap.ccsdk.cds.blueprintsprocessor.rest.service.mdcWebCoroutineScope
23 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
24 import org.springframework.http.MediaType
25 import org.springframework.web.bind.annotation.DeleteMapping
26 import org.springframework.web.bind.annotation.GetMapping
27 import org.springframework.web.bind.annotation.PathVariable
28 import org.springframework.web.bind.annotation.PostMapping
29 import org.springframework.web.bind.annotation.RequestBody
30 import org.springframework.web.bind.annotation.RequestMapping
31 import org.springframework.web.bind.annotation.ResponseBody
32 import org.springframework.web.bind.annotation.RestController
35 @RequestMapping(value = ["/api/v1/model-type"])
36 open class ModelTypeController(private val modelTypeHandler: ModelTypeHandler) {
38 @GetMapping(path = ["/{name}"], produces = [MediaType.APPLICATION_JSON_VALUE])
39 suspend fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? = mdcWebCoroutineScope {
40 modelTypeHandler.getModelTypeByName(name)
43 @GetMapping(path = ["/search/{tags}"], produces = [MediaType.APPLICATION_JSON_VALUE])
44 suspend fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> = mdcWebCoroutineScope {
45 modelTypeHandler.searchModelTypes(tags)
48 @GetMapping(path = ["/by-definition/{definitionType}"], produces = [MediaType.APPLICATION_JSON_VALUE])
50 suspend fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> =
51 mdcWebCoroutineScope {
52 modelTypeHandler.getModelTypeByDefinitionType(definitionType)
57 produces = [MediaType.APPLICATION_JSON_VALUE],
58 consumes = [MediaType.APPLICATION_JSON_VALUE]
61 @Throws(BluePrintException::class)
62 suspend fun saveModelType(@RequestBody modelType: ModelType): ModelType = mdcWebCoroutineScope {
63 modelTypeHandler.saveModel(modelType)
66 @DeleteMapping(path = ["/{name}"])
67 suspend fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = mdcWebCoroutineScope {
68 modelTypeHandler.deleteByModelName(name)