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.controllerblueprints.service.controller
20 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
21 import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType
22 import org.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler
23 import kotlinx.coroutines.runBlocking
24 import org.springframework.http.MediaType
25 import org.springframework.web.bind.annotation.*
28 @RequestMapping(value = arrayOf("/api/v1/model-type"))
29 open class ModelTypeController(private val modelTypeHandler: ModelTypeHandler) {
31 @GetMapping(path = arrayOf("/{name}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
32 fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? = runBlocking {
33 modelTypeHandler.getModelTypeByName(name)
36 @GetMapping(path = arrayOf("/search/{tags}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
37 fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> = runBlocking {
38 modelTypeHandler.searchModelTypes(tags)
41 @GetMapping(path = arrayOf("/by-definition/{definitionType}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
43 fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> = runBlocking {
44 modelTypeHandler.getModelTypeByDefinitionType(definitionType)
47 @PostMapping(path = arrayOf(""), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE), consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE))
49 @Throws(BluePrintException::class)
50 fun saveModelType(@RequestBody modelType: ModelType): ModelType = runBlocking {
51 modelTypeHandler.saveModel(modelType)
54 @DeleteMapping(path = arrayOf("/{name}"))
55 fun deleteModelTypeByName(@PathVariable(value = "name") name: String) = runBlocking {
56 modelTypeHandler.deleteByModelName(name)