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.http.MediaType;
\r 
  23 import org.springframework.stereotype.Component;
\r 
  24 import org.springframework.stereotype.Service;
\r 
  25 import org.springframework.web.bind.annotation.*;
\r 
  27 import java.util.List;
\r 
  33 @RequestMapping(value = "/api/v1/model-type")
\r 
  34 public class ModelTypeRest {
\r 
  36     private ModelTypeService modelTypeService;
\r 
  39      * This is a ModelTypeResourceImpl, used to save and get the model types stored in database
\r 
  41      * @param modelTypeService Model Type Service
\r 
  43     public ModelTypeRest(ModelTypeService modelTypeService) {
\r 
  44         this.modelTypeService = modelTypeService;
\r 
  47     @GetMapping(path = "/{name}", produces = MediaType.APPLICATION_JSON_VALUE)
\r 
  48     public ModelType getModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException {
\r 
  50             return modelTypeService.getModelTypeByName(name);
\r 
  51         } catch (Exception e) {
\r 
  52             throw new BluePrintException(1000, e.getMessage(), e);
\r 
  56     @GetMapping(path = "/search/{tags}", produces = MediaType.APPLICATION_JSON_VALUE)
\r 
  57     public List<ModelType> searchModelTypes(@PathVariable(value = "tags") String tags) throws BluePrintException {
\r 
  59             return modelTypeService.searchModelTypes(tags);
\r 
  60         } catch (Exception e) {
\r 
  61             throw new BluePrintException(1001, e.getMessage(), e);
\r 
  65     @GetMapping(path = "/by-definition/{definitionType}", produces = MediaType.APPLICATION_JSON_VALUE)
\r 
  66     public @ResponseBody
\r 
  67     List<ModelType> getModelTypeByDefinitionType(@PathVariable(value = "definitionType") String definitionType) throws BluePrintException {
\r 
  69             return modelTypeService.getModelTypeByDefinitionType(definitionType);
\r 
  70         } catch (Exception e) {
\r 
  71             throw new BluePrintException(1002, e.getMessage(), e);
\r 
  75     @PostMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
\r 
  76     public @ResponseBody
\r 
  77     ModelType saveModelType(@RequestBody ModelType modelType) throws BluePrintException {
\r 
  79             return modelTypeService.saveModel(modelType);
\r 
  80         } catch (Exception e) {
\r 
  81             throw new BluePrintException(1100, e.getMessage(), e);
\r 
  85     @DeleteMapping(path = "/{name}")
\r 
  86     public void deleteModelTypeByName(@PathVariable(value = "name") String name) throws BluePrintException {
\r 
  88             modelTypeService.deleteByModelName(name);
\r 
  89         } catch (Exception e) {
\r 
  90             throw new BluePrintException(1400, e.getMessage(), e);
\r