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 kotlinx.coroutines.runBlocking
21 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ModelType
22 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler.ModelTypeHandler
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 = arrayOf("/api/v1/model-type"))
36 open class ModelTypeController(private val modelTypeHandler: ModelTypeHandler) {
38 @GetMapping(path = arrayOf("/{name}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
39 fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? = runBlocking {
40 modelTypeHandler.getModelTypeByName(name)
43 @GetMapping(path = arrayOf("/search/{tags}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
44 fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> = runBlocking {
45 modelTypeHandler.searchModelTypes(tags)
48 @GetMapping(path = arrayOf("/by-definition/{definitionType}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
50 fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> = runBlocking {
51 modelTypeHandler.getModelTypeByDefinitionType(definitionType)
54 @PostMapping(path = arrayOf(""), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE), consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE))
56 @Throws(BluePrintException::class)
57 fun saveModelType(@RequestBody modelType: ModelType): ModelType = runBlocking {
58 modelTypeHandler.saveModel(modelType)
61 @DeleteMapping(path = arrayOf("/{name}"))
62 fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = runBlocking {
63 modelTypeHandler.deleteByModelName(name)