2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.ccsdk.apps.controllerblueprints.service.rs;
\r
19 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;
\r
20 import org.onap.ccsdk.apps.controllerblueprints.service.ModelTypeService;
\r
21 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;
\r
22 import org.springframework.stereotype.Component;
\r
23 import org.springframework.stereotype.Service;
\r
24 import org.springframework.web.bind.annotation.*;
\r
26 import java.util.List;
\r
32 @RequestMapping("/api/v1/model-type")
\r
33 public class ModelTypeRest {
\r
35 private ModelTypeService modelTypeService;
\r
38 * This is a ModelTypeResourceImpl, used to save and get the model types stored in database
\r
40 * @param modelTypeService Model Type Service
\r
42 public ModelTypeRest(ModelTypeService modelTypeService) {
\r
43 this.modelTypeService = modelTypeService;
\r
46 @GetMapping(path = "/{name}")
\r
47 public ModelType getModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException {
\r
49 return modelTypeService.getModelTypeByName(name);
\r
50 } catch (Exception e) {
\r
51 throw new BluePrintException(1000, e.getMessage(), e);
\r
55 @GetMapping(path = "/search/{tags}")
\r
56 public List<ModelType> searchModelTypes(@PathVariable(value = "tags") String tags) throws BluePrintException {
\r
58 return modelTypeService.searchModelTypes(tags);
\r
59 } catch (Exception e) {
\r
60 throw new BluePrintException(1001, e.getMessage(), e);
\r
64 @GetMapping(path = "/by-definition/{definitionType}")
\r
65 public @ResponseBody
\r
66 List<ModelType> getModelTypeByDefinitionType(@PathVariable(value = "definitionType") String definitionType) throws BluePrintException {
\r
68 return modelTypeService.getModelTypeByDefinitionType(definitionType);
\r
69 } catch (Exception e) {
\r
70 throw new BluePrintException(1002, e.getMessage(), e);
\r
74 @PostMapping(path = "/")
\r
75 public @ResponseBody
\r
76 ModelType saveModelType(@RequestBody ModelType modelType) throws BluePrintException {
\r
78 return modelTypeService.saveModel(modelType);
\r
79 } catch (Exception e) {
\r
80 throw new BluePrintException(1100, e.getMessage(), e);
\r
84 @DeleteMapping(path = "/{name}")
\r
85 public void deleteModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException {
\r
87 modelTypeService.deleteByModelName(name);
\r
88 } catch (Exception e) {
\r
89 throw new BluePrintException(1400, e.getMessage(), e);
\r