Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / controllerblueprints / modules / service / src / main / kotlin / org / onap / ccsdk / cds / controllerblueprints / service / controller / ModelTypeController.kt
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.ccsdk.cds.controllerblueprints.service.controller
18
19 import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
20 import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType
21 import org.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler
22 import org.springframework.http.MediaType
23 import org.springframework.web.bind.annotation.*
24
25 @RestController
26 @RequestMapping(value = arrayOf("/api/v1/model-type"))
27 open class ModelTypeController(private val modelTypeHandler: ModelTypeHandler) {
28
29     @GetMapping(path = arrayOf("/{name}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
30     fun getModelTypeByName(@PathVariable(value = "name") name: String): ModelType? {
31         return modelTypeHandler.getModelTypeByName(name)
32     }
33
34     @GetMapping(path = arrayOf("/search/{tags}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
35     fun searchModelTypes(@PathVariable(value = "tags") tags: String): List<ModelType> {
36         return modelTypeHandler.searchModelTypes(tags)
37     }
38
39     @GetMapping(path = arrayOf("/by-definition/{definitionType}"), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE))
40     @ResponseBody
41     fun getModelTypeByDefinitionType(@PathVariable(value = "definitionType") definitionType: String): List<ModelType> {
42         return modelTypeHandler.getModelTypeByDefinitionType(definitionType)
43     }
44
45     @PostMapping(path = arrayOf(""), produces = arrayOf(MediaType.APPLICATION_JSON_VALUE), consumes = arrayOf(MediaType.APPLICATION_JSON_VALUE))
46     @ResponseBody
47     @Throws(BluePrintException::class)
48     fun saveModelType(@RequestBody modelType: ModelType): ModelType {
49         return modelTypeHandler.saveModel(modelType)
50     }
51
52     @DeleteMapping(path = arrayOf("/{name}"))
53     fun deleteModelTypeByName(@PathVariable(value = "name") name: String) {
54         modelTypeHandler.deleteByModelName(name)
55     }
56 }