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;
|
Aharoni, Pavel (pa0916) | 0a8080c | 2018-11-22 15:45:19 +0200 | [diff] [blame^] | 26 | import org.onap.osam.common.dto.AccessPodDTO;
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 27 | import org.onap.osam.helper.DTOMapper;
|
| 28 | import org.onap.osam.model.dao.AccessPod;
|
| 29 | import org.onap.osam.api.service.AccessPodService;
|
| 30 | import org.springframework.beans.factory.annotation.Autowired;
|
| 31 | import org.springframework.http.HttpStatus;
|
| 32 | import org.springframework.http.ResponseEntity;
|
| 33 | import org.springframework.web.bind.annotation.DeleteMapping;
|
| 34 | import org.springframework.web.bind.annotation.GetMapping;
|
| 35 | import org.springframework.web.bind.annotation.PathVariable;
|
| 36 | import org.springframework.web.bind.annotation.PostMapping;
|
| 37 | import org.springframework.web.bind.annotation.RequestBody;
|
| 38 | import org.springframework.web.bind.annotation.RequestMapping;
|
| 39 | import org.springframework.web.bind.annotation.RestController;
|
| 40 |
|
| 41 | import java.util.List;
|
| 42 |
|
| 43 | /**
|
| 44 | * Created by cemturker on 27.09.2018.
|
| 45 | */
|
| 46 | @RestController
|
| 47 | @RequestMapping("/accessPod")
|
| 48 | @Slf4j
|
| 49 | public class AccessPodRestController extends AbstractController {
|
| 50 |
|
| 51 | private AccessPodService accessPodService;
|
| 52 |
|
| 53 | @Autowired
|
| 54 | public AccessPodRestController(AccessPodService accessPodService) {
|
| 55 | super(log);
|
| 56 | this.accessPodService = accessPodService;
|
| 57 | }
|
| 58 |
|
| 59 | @GetMapping
|
| 60 | public List<AccessPodDTO> getAccessPods(){
|
| 61 | return DTOMapper.covertAccessPodsToDtos(accessPodService.getAll());
|
| 62 | }
|
| 63 |
|
| 64 | @PostMapping
|
| 65 | public ResponseEntity<AccessPodDTO> postAccessPod(@RequestBody AccessPodDTO accessPodDTO){
|
| 66 | try {
|
| 67 | log.info("Post request for {} is received",accessPodDTO);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 68 | AccessPod accessPod = DTOMapper.convertDtoToAccessPod(accessPodDTO);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 69 | accessPod = accessPodService.addOrUpdate(accessPod);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 70 | return new ResponseEntity<>(DTOMapper.convertAccessPodToDto(accessPod),HttpStatus.CREATED);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 71 | }catch (Exception e){
|
| 72 | return super.proceedException(e);
|
| 73 | }
|
| 74 | }
|
| 75 |
|
| 76 | @DeleteMapping("pnf/{pnfId}")
|
| 77 | public ResponseEntity deleteAccessPodByPnfId(@PathVariable("pnfId") String pnfId) {
|
| 78 | try{
|
| 79 | this.accessPodService.removeByPnfId(pnfId);
|
| 80 | return ResponseEntity.ok().build();
|
| 81 | }catch (Exception e) {
|
| 82 | return super.proceedException(e);
|
| 83 | }
|
| 84 |
|
| 85 | }
|
| 86 |
|
| 87 | @DeleteMapping("/{id}")
|
| 88 | public ResponseEntity deleteAccessPod(@PathVariable("id") Long id) {
|
| 89 | try {
|
| 90 | this.accessPodService.removeById(id);
|
| 91 | }catch (Exception e) {
|
| 92 | return super.proceedException(e);
|
| 93 | }
|
| 94 | return ResponseEntity.ok().build();
|
| 95 | }
|
| 96 |
|
| 97 | }
|