blob: 46b21f72b3936f91895126fbc4278b7cee2e43ee [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;
Aharoni, Pavel (pa0916)0a8080c2018-11-22 15:45:19 +020026import org.onap.osam.common.dto.AccessPodDTO;
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +030027import org.onap.osam.helper.DTOMapper;
28import org.onap.osam.model.dao.AccessPod;
29import org.onap.osam.api.service.AccessPodService;
30import org.springframework.beans.factory.annotation.Autowired;
31import org.springframework.http.HttpStatus;
32import org.springframework.http.ResponseEntity;
33import org.springframework.web.bind.annotation.DeleteMapping;
34import org.springframework.web.bind.annotation.GetMapping;
35import org.springframework.web.bind.annotation.PathVariable;
36import org.springframework.web.bind.annotation.PostMapping;
37import org.springframework.web.bind.annotation.RequestBody;
38import org.springframework.web.bind.annotation.RequestMapping;
39import org.springframework.web.bind.annotation.RestController;
40
41import java.util.List;
42
43/**
44 * Created by cemturker on 27.09.2018.
45 */
46@RestController
47@RequestMapping("/accessPod")
48@Slf4j
49public 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 Kabanb0a16682018-12-04 11:16:24 +030068 AccessPod accessPod = DTOMapper.convertDtoToAccessPod(accessPodDTO);
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +030069 accessPod = accessPodService.addOrUpdate(accessPod);
Zafer Kabanb0a16682018-12-04 11:16:24 +030070 return new ResponseEntity<>(DTOMapper.convertAccessPodToDto(accessPod),HttpStatus.CREATED);
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +030071 }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}