blob: 026ec1738cf7c3c575d44c53c03a35655566a231 [file] [log] [blame]
/*-
* ============LICENSE_START=======================================================
* OSAM Core
* ================================================================================
* Copyright (C) 2018 Netsia
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.onap.osam.controller;
import lombok.extern.slf4j.Slf4j;
import org.onap.osam.api.service.DeviceService;
import org.onap.osam.dto.ChassisDTO;
import org.onap.osam.dto.OLTChassisDTO;
import org.onap.osam.dto.ONTDTO;
import org.onap.osam.helper.DTOMapper;
import org.onap.osam.model.dao.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
/**
* Created by Zafer Kaban on 27.09.2018.
*/
@CrossOrigin
@RestController
@RequestMapping("/device")
@Slf4j
public class DeviceController extends AbstractController {
private DeviceService deviceService;
@Autowired
public DeviceController(DeviceService deviceService) {
super(log);
this.deviceService = deviceService;
}
@PostMapping("/chassis")
public ResponseEntity<ChassisDTO> postChassis(@RequestBody ChassisDTO chassisDTO){
try {
log.info("postChassis request is received {}",chassisDTO);
Chassis chassis = DTOMapper.convertToChassis(chassisDTO);
chassis = deviceService.addChassis(chassis);
return new ResponseEntity<>(DTOMapper.convertChassisToDTO(chassis),HttpStatus.CREATED);
}catch (Exception e){
return super.proceedException(e);
}
}
@DeleteMapping("chassis/{clli}")
public ResponseEntity deleteChassisByClli(@PathVariable("clli") String clli) {
try{
this.deviceService.deleteChassisByClli(clli);
return ResponseEntity.ok().build();
}catch (Exception e) {
return super.proceedException(e);
}
}
@PostMapping("/chassis/olt")
public ResponseEntity<OLTChassisDTO> postOLTChassis(@RequestBody OLTChassisDTO oltChassisDTO){
try {
Chassis chassis = this.deviceService.getChassisByClli(oltChassisDTO.getClli());
OLTSlot oltSlot = DTOMapper.convertToOLT(oltChassisDTO);
oltSlot.setChassis(chassis);
this.deviceService.addOLTSlot(oltSlot, chassis);
return new ResponseEntity<> (DTOMapper.convertFromOLT(oltSlot),HttpStatus.CREATED);
}catch (Exception e){
return super.proceedException(e);
}
}
@PostMapping("/chassis/olt/ont")
public ResponseEntity<ONTDTO> postONTDevice(@RequestBody ONTDTO ontDTO){
try {
ONTDevice ont = deviceService.addONTDevice(ontDTO.getClli()
,ontDTO.getSlotNumber()
,ontDTO.getPortNumber()
,ontDTO.getSerialNumber());
return new ResponseEntity<> (DTOMapper.convertFromONTDevice(ont),HttpStatus.CREATED);
}catch (Exception e){
return super.proceedException(e);
}
}
@GetMapping("/chassis")
public ResponseEntity<List<ChassisDTO>> getAllChassis(){
try {
return new ResponseEntity<> (DTOMapper.convertChassisToDTO(deviceService.getAllChassis()), HttpStatus.OK);
}catch (Exception e){
return super.proceedException(e);
}
}
@GetMapping("/chassis/olt")
public ResponseEntity<Map<String, List<OLTChassisDTO>>> getAllOLTDevices(){
try {
return new ResponseEntity<> (DTOMapper.convertFromOLT(deviceService.getAllOLTSlots()), HttpStatus.OK);
}catch (Exception e){
return super.proceedException(e);
}
}
@GetMapping("/chassis/olt/ont")
public ResponseEntity<Map<String, List<ONTDTO>>> getAllONTDevices(){
try {
return new ResponseEntity<> (DTOMapper.convertFromONTDevice(deviceService.getAllONTDevices()), HttpStatus.OK);
}catch (Exception e){
return super.proceedException(e);
}
}
}