blob: f6c7aece9d7712fec7fbbc4af2af1958765906b1 [file] [log] [blame]
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +03001/*-
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
23package org.onap.osam.controller;
24
25import lombok.extern.slf4j.Slf4j;
26import org.onap.osam.api.service.DeviceService;
Aharoni, Pavel (pa0916)0a8080c2018-11-22 15:45:19 +020027import org.onap.osam.common.dto.ChassisDTO;
28import org.onap.osam.common.dto.OLTChassisDTO;
29import org.onap.osam.common.dto.ONTDTO;
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +030030import org.onap.osam.helper.DTOMapper;
31import org.onap.osam.model.dao.*;
32import org.springframework.beans.factory.annotation.Autowired;
33import org.springframework.http.HttpStatus;
34import org.springframework.http.ResponseEntity;
35import org.springframework.web.bind.annotation.*;
36
37import java.util.List;
38import java.util.Map;
39
40/**
41 * Created by Zafer Kaban on 27.09.2018.
42 */
43@CrossOrigin
44@RestController
45@RequestMapping("/device")
46@Slf4j
47public class DeviceController extends AbstractController {
48
49 private DeviceService deviceService;
50
51 @Autowired
52 public DeviceController(DeviceService deviceService) {
53 super(log);
54 this.deviceService = deviceService;
55 }
56
57 @PostMapping("/chassis")
58 public ResponseEntity<ChassisDTO> postChassis(@RequestBody ChassisDTO chassisDTO){
59 try {
60 log.info("postChassis request is received {}",chassisDTO);
61 Chassis chassis = DTOMapper.convertToChassis(chassisDTO);
62 chassis = deviceService.addChassis(chassis);
63 return new ResponseEntity<>(DTOMapper.convertChassisToDTO(chassis),HttpStatus.CREATED);
64 }catch (Exception e){
65 return super.proceedException(e);
66 }
67
68 }
69
70 @DeleteMapping("chassis/{clli}")
71 public ResponseEntity deleteChassisByClli(@PathVariable("clli") String clli) {
72 try{
73 this.deviceService.deleteChassisByClli(clli);
74 return ResponseEntity.ok().build();
75 }catch (Exception e) {
76 return super.proceedException(e);
77 }
78
79 }
80
81
82 @PostMapping("/chassis/olt")
83 public ResponseEntity<OLTChassisDTO> postOLTChassis(@RequestBody OLTChassisDTO oltChassisDTO){
84 try {
85 Chassis chassis = this.deviceService.getChassisByClli(oltChassisDTO.getClli());
86 OLTSlot oltSlot = DTOMapper.convertToOLT(oltChassisDTO);
87 oltSlot.setChassis(chassis);
88 this.deviceService.addOLTSlot(oltSlot, chassis);
89 return new ResponseEntity<> (DTOMapper.convertFromOLT(oltSlot),HttpStatus.CREATED);
90 }catch (Exception e){
91 return super.proceedException(e);
92 }
93
94 }
95
Zafer Kabanb0a16682018-12-04 11:16:24 +030096 @PostMapping("/chassis/olt/ont-provision")
97 public ResponseEntity<ONTDTO> provisionONTDevice(@RequestBody ONTDTO ontDTO){
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +030098 try {
Zafer Kabanb0a16682018-12-04 11:16:24 +030099 ONTDevice ont = deviceService.provisionONTDevice(DTOMapper.convertToONTDevice(ontDTO), DeviceService.OntProvisioningType.PROVISION);
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +0300100 return new ResponseEntity<> (DTOMapper.convertFromONTDevice(ont),HttpStatus.CREATED);
101 }catch (Exception e){
102 return super.proceedException(e);
103 }
104
105 }
106
Zafer Kabanb0a16682018-12-04 11:16:24 +0300107 @PostMapping("/chassis/olt/ont-full")
108 public ResponseEntity<ONTDTO> provisionONTDeviceFull(@RequestBody ONTDTO ontDTO){
109 try {
110 ONTDevice ont = deviceService.provisionONTDevice(DTOMapper.convertToONTDevice(ontDTO), DeviceService.OntProvisioningType.FULL);
111 return new ResponseEntity<> (DTOMapper.convertFromONTDevice(ont),HttpStatus.CREATED);
112 }catch (Exception e){
113 return super.proceedException(e);
114 }
115
116 }
117
118 @PostMapping("/chassis/olt/ont-preprovision")
119 public ResponseEntity<ONTDTO> preprovisionONTDevice(@RequestBody ONTDTO ontDTO){
120 try {
121 ONTDevice ont = deviceService.provisionONTDevice(DTOMapper.convertToONTDevice(ontDTO), DeviceService.OntProvisioningType.PREPROVISION);
122 return new ResponseEntity<> (DTOMapper.convertFromONTDevice(ont),HttpStatus.CREATED);
123 }catch (Exception e){
124 return super.proceedException(e);
125 }
126
127 }
128
129 @DeleteMapping("chassis/olt/ont/{ontid}")
130 public ResponseEntity deleteOntById(@PathVariable("ontid") String ontid) {
131 try{
132 this.deviceService.deleteONTDevice(new Long(ontid));
133 return ResponseEntity.ok().build();
134 }catch (Exception e) {
135 return super.proceedException(e);
136 }
137
138 }
139
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +0300140 @GetMapping("/chassis")
141 public ResponseEntity<List<ChassisDTO>> getAllChassis(){
142 try {
143 return new ResponseEntity<> (DTOMapper.convertChassisToDTO(deviceService.getAllChassis()), HttpStatus.OK);
144 }catch (Exception e){
145 return super.proceedException(e);
146 }
147 }
148
149 @GetMapping("/chassis/olt")
150 public ResponseEntity<Map<String, List<OLTChassisDTO>>> getAllOLTDevices(){
151 try {
152 return new ResponseEntity<> (DTOMapper.convertFromOLT(deviceService.getAllOLTSlots()), HttpStatus.OK);
153 }catch (Exception e){
154 return super.proceedException(e);
155 }
156 }
157
158 @GetMapping("/chassis/olt/ont")
159 public ResponseEntity<Map<String, List<ONTDTO>>> getAllONTDevices(){
160 try {
161 return new ResponseEntity<> (DTOMapper.convertFromONTDevice(deviceService.getAllONTDevices()), HttpStatus.OK);
162 }catch (Exception e){
163 return super.proceedException(e);
164 }
165 }
166}