blob: f6c7aece9d7712fec7fbbc4af2af1958765906b1 [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.common.dto.ChassisDTO;
import org.onap.osam.common.dto.OLTChassisDTO;
import org.onap.osam.common.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-provision")
public ResponseEntity<ONTDTO> provisionONTDevice(@RequestBody ONTDTO ontDTO){
try {
ONTDevice ont = deviceService.provisionONTDevice(DTOMapper.convertToONTDevice(ontDTO), DeviceService.OntProvisioningType.PROVISION);
return new ResponseEntity<> (DTOMapper.convertFromONTDevice(ont),HttpStatus.CREATED);
}catch (Exception e){
return super.proceedException(e);
}
}
@PostMapping("/chassis/olt/ont-full")
public ResponseEntity<ONTDTO> provisionONTDeviceFull(@RequestBody ONTDTO ontDTO){
try {
ONTDevice ont = deviceService.provisionONTDevice(DTOMapper.convertToONTDevice(ontDTO), DeviceService.OntProvisioningType.FULL);
return new ResponseEntity<> (DTOMapper.convertFromONTDevice(ont),HttpStatus.CREATED);
}catch (Exception e){
return super.proceedException(e);
}
}
@PostMapping("/chassis/olt/ont-preprovision")
public ResponseEntity<ONTDTO> preprovisionONTDevice(@RequestBody ONTDTO ontDTO){
try {
ONTDevice ont = deviceService.provisionONTDevice(DTOMapper.convertToONTDevice(ontDTO), DeviceService.OntProvisioningType.PREPROVISION);
return new ResponseEntity<> (DTOMapper.convertFromONTDevice(ont),HttpStatus.CREATED);
}catch (Exception e){
return super.proceedException(e);
}
}
@DeleteMapping("chassis/olt/ont/{ontid}")
public ResponseEntity deleteOntById(@PathVariable("ontid") String ontid) {
try{
this.deviceService.deleteONTDevice(new Long(ontid));
return ResponseEntity.ok().build();
}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);
}
}
}