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.core;
|
| 24 |
|
| 25 | import org.onap.osam.external.aai.AaiClient;
|
| 26 | import org.onap.osam.external.aai.model.PNF;
|
| 27 | import org.onap.osam.model.dao.AccessPod;
|
| 28 | import org.onap.osam.common.exception.NotFoundException;
|
| 29 | import org.onap.osam.model.repository.AccessPodRepository;
|
| 30 | import org.onap.osam.api.service.AccessPodService;
|
| 31 | import org.springframework.beans.factory.annotation.Autowired;
|
| 32 | import org.springframework.stereotype.Service;
|
| 33 |
|
| 34 | import java.util.List;
|
| 35 | import java.util.Optional;
|
| 36 |
|
| 37 | /**
|
| 38 | * Created by cemturker on 26.09.2018.
|
| 39 | */
|
| 40 | @Service
|
| 41 | public 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) | 0a8080c | 2018-11-22 15:45:19 +0200 | [diff] [blame] | 56 | //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) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 59 | 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 Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 87 | 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) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 89 | }
|
| 90 | return accessPodOp.get();
|
| 91 | }
|
| 92 |
|
| 93 | @Override
|
| 94 | public void removeByPnfId(String pnfId) {
|
| 95 | accessPodRepository.removeByPnfId(pnfId);
|
| 96 | }
|
| 97 | }
|