Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 1 | /*-
|
| 2 | * ============LICENSE_START=======================================================
|
| 3 | * OSAM Core
|
| 4 | * ================================================================================
|
| 5 | * Copyright (C) 2018 Netsia
|
| 6 | * ================================================================================
|
| 7 | * Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 | * you may not use this file except in compliance with the License.
|
| 9 | * You may obtain a copy of the License at
|
| 10 | *
|
| 11 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 12 | *
|
| 13 | * Unless required by applicable law or agreed to in writing, software
|
| 14 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 | * See the License for the specific language governing permissions and
|
| 17 | * limitations under the License.
|
| 18 | * ============LICENSE_END=========================================================
|
| 19 | */
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 | package org.onap.osam.controller;
|
| 24 |
|
| 25 | import lombok.extern.slf4j.Slf4j;
|
| 26 | import org.onap.osam.model.dao.SpeedProfile;
|
| 27 | import org.onap.osam.model.dao.TechnologyProfile;
|
| 28 | import org.onap.osam.api.service.BroadBandService;
|
| 29 | import org.springframework.beans.factory.annotation.Autowired;
|
| 30 | import org.springframework.http.HttpStatus;
|
| 31 | import org.springframework.http.ResponseEntity;
|
| 32 | import org.springframework.web.bind.annotation.DeleteMapping;
|
| 33 | import org.springframework.web.bind.annotation.GetMapping;
|
| 34 | import org.springframework.web.bind.annotation.PathVariable;
|
| 35 | import org.springframework.web.bind.annotation.PostMapping;
|
| 36 | import org.springframework.web.bind.annotation.RequestBody;
|
| 37 | import org.springframework.web.bind.annotation.RequestMapping;
|
| 38 | import org.springframework.web.bind.annotation.RestController;
|
| 39 |
|
| 40 | import java.util.List;
|
| 41 |
|
| 42 | /**
|
| 43 | * Created by cemturker on 19.09.2018.
|
| 44 | */
|
| 45 | @RestController
|
| 46 | @RequestMapping("/service")
|
| 47 | @Slf4j
|
| 48 | public class ServiceController extends AbstractController {
|
| 49 |
|
| 50 | private BroadBandService broadBandService;
|
| 51 |
|
| 52 | //TODOs add validations for post reqs...
|
| 53 |
|
| 54 | @Autowired
|
| 55 | public ServiceController(BroadBandService broadBandService){
|
| 56 | super(log);
|
| 57 | this.broadBandService = broadBandService;
|
| 58 | }
|
| 59 |
|
| 60 | @GetMapping("/speedProfile")
|
| 61 | public ResponseEntity<List<SpeedProfile>> getSpeedProfiles() {
|
| 62 | try{
|
| 63 | return ResponseEntity.ok(this.broadBandService.getSpeedProfiles());
|
| 64 | }catch (Exception e){
|
| 65 | return super.proceedException(e);
|
| 66 | }
|
| 67 | }
|
| 68 |
|
| 69 | @GetMapping("/speedProfile/{id}")
|
| 70 | public ResponseEntity<SpeedProfile> getSpeedProfile(@PathVariable("id") Long id) {
|
| 71 | try {
|
| 72 | return ResponseEntity.ok(this.broadBandService.getSpeedProfile(id));
|
| 73 | }catch (Exception e) {
|
| 74 | return super.proceedException(e);
|
| 75 | }
|
| 76 | }
|
| 77 |
|
| 78 | @DeleteMapping("/speedProfile/{id}")
|
| 79 | public ResponseEntity deleteSpeedProfile(@PathVariable("id") Long id) {
|
| 80 | try {
|
| 81 | this.broadBandService.removeSpeedProfile(id);
|
| 82 | return ResponseEntity.ok().build();
|
| 83 | }catch (Exception e) {
|
| 84 | return super.proceedException(e);
|
| 85 | }
|
| 86 | }
|
| 87 |
|
| 88 | @PostMapping("/speedProfile")
|
| 89 | public ResponseEntity<SpeedProfile> createSpeedProfile(@RequestBody SpeedProfile speedProfile) {
|
| 90 | try {
|
| 91 | return new ResponseEntity<>(this.broadBandService.addSpeedProfile(speedProfile),
|
| 92 | HttpStatus.CREATED);
|
| 93 | }catch (Exception e) {
|
| 94 | return super.proceedException(e);
|
| 95 | }
|
| 96 |
|
| 97 | }
|
| 98 |
|
| 99 | @GetMapping("/technologyProfile")
|
| 100 | public ResponseEntity<List<TechnologyProfile>> getTechnologyProfiles() {
|
| 101 | try {
|
| 102 | return ResponseEntity.ok(this.broadBandService.getTechnologyProfiles());
|
| 103 | }catch (Exception e) {
|
| 104 | return super.proceedException(e);
|
| 105 | }
|
| 106 | }
|
| 107 |
|
| 108 | @GetMapping("/technologyProfile/{id}")
|
| 109 | public ResponseEntity<TechnologyProfile> getTechnologyProfile(@PathVariable("id") Long id) {
|
| 110 | try {
|
| 111 | return ResponseEntity.ok(this.broadBandService.getTechnologyProfile(id));
|
| 112 | }catch (Exception e) {
|
| 113 | return super.proceedException(e);
|
| 114 | }
|
| 115 | }
|
| 116 |
|
| 117 | @DeleteMapping("/technologyProfile/{id}")
|
| 118 | public ResponseEntity deleteTechnologyProfile(@PathVariable("id") Long id) {
|
| 119 | try {
|
| 120 | this.broadBandService.removeSpeedProfile(id);
|
| 121 | return ResponseEntity.ok().build();
|
| 122 | }catch (Exception e){
|
| 123 | return super.proceedException(e);
|
| 124 | }
|
| 125 | }
|
| 126 |
|
| 127 | @PostMapping("/technologyProfile")
|
| 128 | public ResponseEntity<TechnologyProfile> createTechnologyProfile(@RequestBody TechnologyProfile technologyProfile) {
|
| 129 | try {
|
| 130 | return new ResponseEntity<>(this.broadBandService.addTechnologyProfile(technologyProfile),HttpStatus.CREATED);
|
| 131 | }catch (Exception e){
|
| 132 | return super.proceedException(e);
|
| 133 | }
|
| 134 | }
|
| 135 | }
|