blob: 4113d1bd1e6c7dee6a4df26e7d9cb52099c16647 [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.core;
24
25import org.onap.osam.external.aai.AaiClient;
26import org.onap.osam.external.aai.model.PNF;
27import org.onap.osam.model.dao.AccessPod;
28import org.onap.osam.common.exception.NotFoundException;
29import org.onap.osam.model.repository.AccessPodRepository;
30import org.onap.osam.api.service.AccessPodService;
31import org.springframework.beans.factory.annotation.Autowired;
32import org.springframework.stereotype.Service;
33
34import java.util.List;
35import java.util.Optional;
36
37/**
38 * Created by cemturker on 26.09.2018.
39 */
40@Service
41public class AccessPodServiceImpl extends AbstractBaseServiceImpl implements AccessPodService {
42
43 private AccessPodRepository accessPodRepository;
44
45 private AaiClient aaiClient;
46
47 @Autowired
48 public AccessPodServiceImpl(AccessPodRepository accessPodRepository, AaiClient aaiClient) {
49 this.accessPodRepository = accessPodRepository;
50 this.aaiClient = aaiClient;
51 }
52
53
54 @Override
55 public AccessPod addOrUpdate(AccessPod value) {
Aharoni, Pavel (pa0916)0a8080c2018-11-22 15:45:19 +020056 //aai logic is commented out, to allow manual registering of SEBA PODs in OSAM Core
57 //PNF pnf = aaiClient.queryPnf(value.getPnfId());
58 Optional<AccessPod> accessPodOptional = accessPodRepository.findByPnfId(value.getPnfId());
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +030059 if (accessPodOptional.isPresent()) {
60 AccessPod tmp = accessPodOptional.get();
61 value.setId(tmp.getId());
62 }
63 add(value,accessPodRepository);
64 //TODO need to update connection to grpc!!
65 return value;
66 }
67
68 @Override
69 public void removeById(Long key) {
70 remove(key,accessPodRepository,AccessPod.class);
71 }
72
73 @Override
74 public AccessPod getById(Long key) {
75 return get(key,accessPodRepository);
76 }
77
78 @Override
79 public List<AccessPod> getAll() {
80 return getAll(accessPodRepository);
81 }
82
83 @Override
84 public AccessPod findByPnfId(String pnfId) {
85 Optional<AccessPod> accessPodOp = accessPodRepository.findByPnfId(pnfId);
86 if (!accessPodOp.isPresent()) {
Zafer Kabanb0a16682018-12-04 11:16:24 +030087 log.error("Access POD with pnfId : {} is not found", pnfId);
88 throw new NotFoundException("Access POD with pnfId : {} is not found", pnfId);
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +030089 }
90 return accessPodOp.get();
91 }
92
93 @Override
94 public void removeByPnfId(String pnfId) {
95 accessPodRepository.removeByPnfId(pnfId);
96 }
97}