Add Tests for VNF Package Mgmt - Subscribe and Notify
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / vnfm-simulator / vnfm-service / src / main / java / org / onap / so / svnfm / simulator / services / providers / VnfPkgOnboardingNotificationCacheServiceProviderImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.svnfm.simulator.services.providers;
21
22 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.notification.model.VnfPackageOnboardingNotification;
23 import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider;
24 import org.onap.so.svnfm.simulator.constants.Constant;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.cache.Cache;
29 import org.springframework.cache.CacheManager;
30 import org.springframework.stereotype.Service;
31 import java.util.Optional;
32
33 /**
34  * @author Andrew Lamb (andrew.a.lamb@est.tech)
35  */
36 @Service
37 public class VnfPkgOnboardingNotificationCacheServiceProviderImpl extends AbstractCacheServiceProvider
38         implements VnfPkgOnboardingNotificationCacheServiceProvider {
39
40     private static final Logger LOGGER = LoggerFactory.getLogger(VnfPkgOnboardingNotificationCacheServiceProviderImpl.class);
41
42     @Autowired
43     public VnfPkgOnboardingNotificationCacheServiceProviderImpl(final CacheManager cacheManager) {
44         super(cacheManager);
45     }
46
47     @Override public void addVnfPkgOnboardingNotification(final String vnfPkgId,
48             final VnfPackageOnboardingNotification vnfPackageOnboardingNotification) {
49         LOGGER.debug("Adding {} to cache with vnfPkgId: {}", vnfPackageOnboardingNotification, vnfPkgId);
50         getCache(Constant.VNF_PKG_ONBOARDING_NOTIFICATION_CACHE).put(vnfPkgId, vnfPackageOnboardingNotification);
51     }
52
53     @Override public Optional<VnfPackageOnboardingNotification> getVnfPkgOnboardingNotification(final String vnfPkgId) {
54         LOGGER.debug("Getting vnfPkgOnboardingNotification from cache using vnfPkgId: {}", vnfPkgId);
55         final Cache cache = getCache(Constant.VNF_PKG_ONBOARDING_NOTIFICATION_CACHE);
56         final VnfPackageOnboardingNotification vnfPackageOnboardingNotification = cache.get(vnfPkgId, VnfPackageOnboardingNotification.class);
57         if (vnfPackageOnboardingNotification != null) {
58             return Optional.of(vnfPackageOnboardingNotification);
59         }
60         LOGGER.error("Unable to find vnfPkgOnboardingNotification in cache using vnfPkgId: {}", vnfPkgId);
61         return Optional.empty();
62     }
63 }