diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2021-02-19 09:18:44 +0000 |
---|---|---|
committer | waqas.ikram <waqas.ikram@est.tech> | 2021-02-19 11:38:51 +0000 |
commit | f8e38b54b043d358114a6752a19b95183522abe9 (patch) | |
tree | a103179fc41e261cb57d20637eb8748bc068b2d9 /adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main | |
parent | 92f39dea69eac0ddb4e61cf716bdf248d1fa5e44 (diff) |
Removing etsi-sol003-adapter module
Change-Id: If35f94bd8459c08c11d5e178ae872f70a36fd9fa
Issue-ID: SO-3486
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main')
43 files changed, 0 insertions, 3798 deletions
diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/ConversionServiceConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/ConversionServiceConfiguration.java deleted file mode 100644 index fd19d0e0a1..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/ConversionServiceConfiguration.java +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm; - -import org.onap.so.adapters.etsi.sol003.adapter.common.VnfmAdapterUrlProvider; -import org.onap.so.adapters.etsisol003adapter.pkgm.converters.etsicatalog.sol003.PkgChangeNotificationConverter; -import org.onap.so.adapters.etsisol003adapter.pkgm.converters.etsicatalog.sol003.PkgOnboardingNotificationConverter; -import org.onap.so.adapters.etsisol003adapter.pkgm.converters.etsicatalog.sol003.VnfPkgInfoConverter; -import org.onap.so.adapters.etsisol003adapter.pkgm.converters.sol003.etsicatalog.PkgmSubscriptionRequestConverter; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.core.convert.ConversionService; -import org.springframework.core.convert.support.DefaultConversionService; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public class ConversionServiceConfiguration { - - private final VnfmAdapterUrlProvider vnfmAdapterUrlProvider; - - @Autowired - public ConversionServiceConfiguration(final VnfmAdapterUrlProvider vnfmAdapterUrlProvider) { - this.vnfmAdapterUrlProvider = vnfmAdapterUrlProvider; - } - - @Bean - public ConversionService conversionService() { - final DefaultConversionService service = new DefaultConversionService(); - service.addConverter(new VnfPkgInfoConverter(vnfmAdapterUrlProvider)); - service.addConverter(new PkgmSubscriptionRequestConverter()); - service.addConverter(new PkgChangeNotificationConverter(vnfmAdapterUrlProvider)); - service.addConverter(new PkgOnboardingNotificationConverter(vnfmAdapterUrlProvider)); - return service; - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/PackageManagementConstants.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/PackageManagementConstants.java deleted file mode 100644 index 5922aab9ca..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/PackageManagementConstants.java +++ /dev/null @@ -1,39 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm; - -/** - * ETSI SOL003 VNF Package Management Adapter constants - * - * @author Ronan Kenny (ronan.kenny@est.tech) - * @author Gareth Roper (gareth.roper@est.tech) - */ -public class PackageManagementConstants { - - public static final String APPLICATION_ZIP = "application/zip"; - - /** - * Name of the subscription cache - */ - public static final String PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE = "PackageManagementSubscriptionCache"; - - private PackageManagementConstants() {} -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/AbstractCacheServiceProvider.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/AbstractCacheServiceProvider.java deleted file mode 100644 index 6dd67faa9e..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/AbstractCacheServiceProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.cache; - -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; - -/** - * @author Ronan Kenny (ronan.kenny@est.tech) - * @author Gareth Roper (gareth.roper@est.tech) - */ -public abstract class AbstractCacheServiceProvider { - - private final CacheManager cacheManager; - private final String cacheName; - - public AbstractCacheServiceProvider(final String cacheName, final CacheManager cacheManager) { - this.cacheName = cacheName; - this.cacheManager = cacheManager; - } - - public Cache getCache() { - final Cache cache = cacheManager.getCache(cacheName); - if (cache == null) { - throw new CacheNotFoundException("Unable to find " + cacheName + " cache"); - } - return cache; - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/CacheManagerConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/CacheManagerConfiguration.java deleted file mode 100644 index c184a25bef..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/CacheManagerConfiguration.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.cache; - -import java.util.Arrays; -import org.onap.so.adapters.etsisol003adapter.pkgm.PackageManagementConstants; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; -import org.springframework.cache.concurrent.ConcurrentMapCache; -import org.springframework.cache.support.SimpleCacheManager; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author Ronan Kenny (ronan.kenny@est.tech) - * @author Gareth Roper (gareth.roper@est.tech) - */ -@Configuration -public class CacheManagerConfiguration { - - @Bean - public CacheManager cacheManager() { - final SimpleCacheManager manager = new SimpleCacheManager(); - manager.setCaches(Arrays.asList(getCache(PackageManagementConstants.PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE))); - - return manager; - } - - private Cache getCache(final String name) { - return new ConcurrentMapCache(name); - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/CacheNotFoundException.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/CacheNotFoundException.java deleted file mode 100644 index 6b2f4710da..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/CacheNotFoundException.java +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.cache; - -/** - * Exception for failure to find the cache. - * - * @author Ronan Kenny (ronan.kenny@est.tech) - * @author Gareth Roper (gareth.roper@est.tech) - * - */ -public class CacheNotFoundException extends RuntimeException { - - private static final long serialVersionUID = -372361485260755367L; - - public CacheNotFoundException(final String message) { - super(message); - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/PkgmCacheServiceProvider.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/PkgmCacheServiceProvider.java deleted file mode 100644 index 34ed1cfc0c..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/PkgmCacheServiceProvider.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.cache; - -import java.util.Map; -import java.util.Optional; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.PkgmSubscriptionRequest; - -/** - * Interface which provides methods for communicating with the cache - * - * @author Ronan Kenny (ronan.kenny@est.tech) - * @author Gareth Roper (gareth.roper@est.tech) - * - */ -public interface PkgmCacheServiceProvider { - - /** - * Checks cache if subscription request Id is already present. If not, it adds the subscription to the cache. - * - * @param subscriptionId - * @param pkgmSubscriptionRequest - */ - void addSubscription(final String subscriptionId, final PkgmSubscriptionRequest pkgmSubscriptionRequest); - - /** - * Gets individual subscription from cache - * - * @param subscriptionId - * @return <AbstractMap.SimpleImmutableEntry<String, PkgmSubscriptionRequest>> - */ - Optional<PkgmSubscriptionRequest> getSubscription(final String subscriptionId); - - /** - * Gets Map of subscriptions from cache - * - * @return Map<String, PkgmSubscriptionRequest>> - */ - Map<String, PkgmSubscriptionRequest> getSubscriptions(); - - /** - * Delete subscription from cache - * - * @param subscriptionId - * @return Boolean - */ - boolean deleteSubscription(final String subscriptionId); - - /** - * Checks if subscription exists in cache and return its subscriptionId - * - * @param pkgmSubscriptionRequest - * @return Subscription Id - */ - Optional<String> getSubscriptionId(final PkgmSubscriptionRequest pkgmSubscriptionRequest); -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/PkgmCacheServiceProviderImpl.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/PkgmCacheServiceProviderImpl.java deleted file mode 100644 index 4811132e92..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/cache/PkgmCacheServiceProviderImpl.java +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.cache; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import org.onap.so.adapters.etsisol003adapter.pkgm.PackageManagementConstants; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.PkgmSubscriptionRequest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; -import org.springframework.stereotype.Service; - -/** - * Implementation which provides methods for communicating with the cache - * - * @author Ronan Kenny (ronan.kenny@est.tech) - * @author Gareth Roper (gareth.roper@est.tech) - */ -@Service -public class PkgmCacheServiceProviderImpl extends AbstractCacheServiceProvider implements PkgmCacheServiceProvider { - - private static final Logger LOGGER = LoggerFactory.getLogger(PkgmCacheServiceProviderImpl.class); - - @Autowired - public PkgmCacheServiceProviderImpl(final CacheManager cacheManager) { - super(PackageManagementConstants.PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE, cacheManager); - } - - @Override - public void addSubscription(final String subscriptionId, final PkgmSubscriptionRequest pkgmSubscriptionRequest) { - LOGGER.debug("Adding {} to cache with subscription id: {}", pkgmSubscriptionRequest, subscriptionId); - getCache().put(subscriptionId, pkgmSubscriptionRequest); - } - - @Override - public Optional<PkgmSubscriptionRequest> getSubscription(final String subscriptionId) { - LOGGER.debug("Getting subscription from cache using Id: {}", subscriptionId); - final Cache cache = getCache(); - final PkgmSubscriptionRequest cacheValue = cache.get(subscriptionId, PkgmSubscriptionRequest.class); - if (cacheValue != null) { - return Optional.of(cacheValue); - } - LOGGER.error("Unable to find Subscription in cache using Id: {}", subscriptionId); - return Optional.empty(); - } - - @Override - public Map<String, PkgmSubscriptionRequest> getSubscriptions() { - LOGGER.info("Getting all subscriptions from cache"); - final Cache cache = getCache(); - - final Object nativeCache = cache.getNativeCache(); - if (nativeCache instanceof ConcurrentHashMap) { - @SuppressWarnings("unchecked") - final ConcurrentHashMap<Object, Object> concurrentHashMap = (ConcurrentHashMap<Object, Object>) nativeCache; - final Map<String, PkgmSubscriptionRequest> result = new HashMap<>(); - concurrentHashMap.keySet().forEach(key -> { - final Optional<PkgmSubscriptionRequest> optional = getSubscription(key.toString()); - optional.ifPresent(pkgmSubscriptionRequest -> result.put(key.toString(), pkgmSubscriptionRequest)); - }); - return result; - } - LOGGER.error("Unable to find Subscriptions in cache"); - return Collections.emptyMap(); - } - - @Override - public boolean deleteSubscription(final String subscriptionId) { - final Cache cache = getCache(); - final Optional<PkgmSubscriptionRequest> optional = getSubscription(subscriptionId); - if (optional.isPresent()) { - cache.evict(subscriptionId); - return true; - } - return false; - } - - @Override - public Optional<String> getSubscriptionId(final PkgmSubscriptionRequest pkgmSubscriptionRequest) { - final Cache cache = getCache(); - final Object nativeCache = cache.getNativeCache(); - if (nativeCache instanceof ConcurrentHashMap) { - @SuppressWarnings("unchecked") - final ConcurrentHashMap<Object, Object> concurrentHashMap = (ConcurrentHashMap<Object, Object>) nativeCache; - final Optional<Entry<Object, Object>> optional = concurrentHashMap.entrySet().stream() - .filter(entry -> entry.getValue().equals(pkgmSubscriptionRequest)).findAny(); - if (optional.isPresent()) { - return Optional.of(optional.get().getKey().toString()); - } - } - return Optional.empty(); - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/etsicatalog/sol003/AbstractPkgNotificationConverter.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/etsicatalog/sol003/AbstractPkgNotificationConverter.java deleted file mode 100644 index 5f2ee1d5ab..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/etsicatalog/sol003/AbstractPkgNotificationConverter.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.converters.etsicatalog.sol003; - -import org.onap.so.adapters.etsi.sol003.adapter.common.VnfmAdapterUrlProvider; -import org.onap.so.adapters.etsisol003adapter.etsicatalog.notification.model.PkgmLinks; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.vnfm.notification.model.URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinks; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.vnfm.notification.model.URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinksVnfPackage; - -/** - * A base class that can be extended by classes for converting Etsi Catalog Manager Pkg Notification classes. Provides - * common methods that will be useful to those classes. - * - * @author andrew.a.lamb@est.tech - */ -abstract public class AbstractPkgNotificationConverter { - - private final VnfmAdapterUrlProvider vnfmAdapterUrlProvider; - - public AbstractPkgNotificationConverter(final VnfmAdapterUrlProvider vnfmAdapterUrlProvider) { - this.vnfmAdapterUrlProvider = vnfmAdapterUrlProvider; - } - - protected URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinks convert( - final PkgmLinks pkgmLinks, final String vnfPkgId, final String subscriptionId) { - final URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinksVnfPackage linksVnfPackage = - new URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinksVnfPackage(); - if (pkgmLinks.getVnfPackage() != null) { - linksVnfPackage.setHref(vnfmAdapterUrlProvider.getVnfPackageUrl(vnfPkgId)); - } - - final URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinksVnfPackage linksSubscription = - new URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinksVnfPackage(); - if (pkgmLinks.getSubscription() != null) { - linksSubscription.setHref(vnfmAdapterUrlProvider.getSubscriptionUriString(subscriptionId)); - } - - final URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinks links = - new URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinks(); - links.setVnfPackage(linksVnfPackage); - links.setSubscription(linksSubscription); - return links; - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/etsicatalog/sol003/PkgChangeNotificationConverter.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/etsicatalog/sol003/PkgChangeNotificationConverter.java deleted file mode 100644 index 5787d35b9a..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/etsicatalog/sol003/PkgChangeNotificationConverter.java +++ /dev/null @@ -1,85 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.converters.etsicatalog.sol003; - -import static org.slf4j.LoggerFactory.getLogger; -import org.onap.so.adapters.etsi.sol003.adapter.common.VnfmAdapterUrlProvider; -import org.onap.so.adapters.etsisol003adapter.etsicatalog.notification.model.PkgChangeNotification; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.vnfm.notification.model.VnfPackageChangeNotification; -import org.slf4j.Logger; -import org.springframework.core.convert.converter.Converter; -import org.springframework.stereotype.Service; - -/** - * Converter to convert from an Etsi Catalog Manager {@link PkgChangeNotification} Object to its equivalent SOL003 - * {@link VnfPackageChangeNotification} Object - * - * @author andrew.a.lamb@est.tech - */ -@Service -public class PkgChangeNotificationConverter extends AbstractPkgNotificationConverter - implements Converter<PkgChangeNotification, VnfPackageChangeNotification> { - private static final Logger logger = getLogger(PkgChangeNotificationConverter.class); - - public PkgChangeNotificationConverter(final VnfmAdapterUrlProvider vnfmAdapterUrlProvider) { - super(vnfmAdapterUrlProvider); - } - - /** - * Convert a {@link PkgChangeNotification} Object to an {@link VnfPackageChangeNotification} Object - * - * @param pkgChangeNotification The PkgChangeNotification Object to Convert - * @return The Converted VnfPackageChangeNotification Object - */ - @Override - public VnfPackageChangeNotification convert(final PkgChangeNotification pkgChangeNotification) { - logger.info("Converting PkgChangeNotification\n{}", pkgChangeNotification.toString()); - final VnfPackageChangeNotification vnfPackageChangeNotification = new VnfPackageChangeNotification(); - vnfPackageChangeNotification.setId(pkgChangeNotification.getId()); - - if (pkgChangeNotification.getNotificationType() != null) { - vnfPackageChangeNotification.setNotificationType(VnfPackageChangeNotification.NotificationTypeEnum - .fromValue(pkgChangeNotification.getNotificationType().getValue())); - } - - vnfPackageChangeNotification.setSubscriptionId(pkgChangeNotification.getSubscriptionId()); - vnfPackageChangeNotification.setTimeStamp(pkgChangeNotification.getTimeStamp()); - vnfPackageChangeNotification.setVnfPkgId(pkgChangeNotification.getVnfPkgId()); - - vnfPackageChangeNotification.setVnfdId(pkgChangeNotification.getVnfdId()); - - if (pkgChangeNotification.getChangeType() != null) { - vnfPackageChangeNotification.setChangeType(VnfPackageChangeNotification.ChangeTypeEnum - .fromValue(pkgChangeNotification.getChangeType().getValue())); - } - - if (pkgChangeNotification.getOperationalState() != null) { - vnfPackageChangeNotification.setOperationalState(VnfPackageChangeNotification.OperationalStateEnum - .fromValue(pkgChangeNotification.getOperationalState().getValue())); - } - - vnfPackageChangeNotification.setLinks(convert(pkgChangeNotification.getLinks(), - pkgChangeNotification.getVnfPkgId(), pkgChangeNotification.getSubscriptionId())); - - return vnfPackageChangeNotification; - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/etsicatalog/sol003/PkgOnboardingNotificationConverter.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/etsicatalog/sol003/PkgOnboardingNotificationConverter.java deleted file mode 100644 index 96a5d827e6..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/etsicatalog/sol003/PkgOnboardingNotificationConverter.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.converters.etsicatalog.sol003; - -import static org.slf4j.LoggerFactory.getLogger; -import org.onap.so.adapters.etsi.sol003.adapter.common.VnfmAdapterUrlProvider; -import org.onap.so.adapters.etsisol003adapter.etsicatalog.notification.model.PkgOnboardingNotification; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.vnfm.notification.model.VnfPackageOnboardingNotification; -import org.slf4j.Logger; -import org.springframework.core.convert.converter.Converter; -import org.springframework.stereotype.Service; - -/** - * Converter to convert from an Etsi Catalog Manager {@link PkgOnboardingNotification} Object to its equivalent SOL003 - * {@link VnfPackageOnboardingNotification} Object - * - * @author andrew.a.lamb@est.tech - */ -@Service -public class PkgOnboardingNotificationConverter extends AbstractPkgNotificationConverter - implements Converter<PkgOnboardingNotification, VnfPackageOnboardingNotification> { - private static final Logger logger = getLogger(PkgOnboardingNotificationConverter.class); - - public PkgOnboardingNotificationConverter(final VnfmAdapterUrlProvider vnfmAdapterUrlProvider) { - super(vnfmAdapterUrlProvider); - } - - - /** - * Convert a {@link PkgOnboardingNotification} Object to an {@link VnfPackageOnboardingNotification} Object - * - * @param pkgOnboardingNotification The PkgOnboardingNotification Object to Convert - * @return The Converted VnfPackageOnboardingNotification Object - */ - @Override - public VnfPackageOnboardingNotification convert(final PkgOnboardingNotification pkgOnboardingNotification) { - logger.info("Converting PkgChangeNotification\n{}", pkgOnboardingNotification.toString()); - final VnfPackageOnboardingNotification vnfPackageOnboardingNotification = - new VnfPackageOnboardingNotification(); - vnfPackageOnboardingNotification.setId(pkgOnboardingNotification.getId()); - - if (pkgOnboardingNotification.getNotificationType() != null) { - vnfPackageOnboardingNotification.setNotificationType(VnfPackageOnboardingNotification.NotificationTypeEnum - .fromValue(pkgOnboardingNotification.getNotificationType().getValue())); - } - - vnfPackageOnboardingNotification.setSubscriptionId(pkgOnboardingNotification.getSubscriptionId()); - vnfPackageOnboardingNotification.setTimeStamp(pkgOnboardingNotification.getTimeStamp()); - vnfPackageOnboardingNotification.setVnfPkgId(pkgOnboardingNotification.getVnfPkgId()); - vnfPackageOnboardingNotification.setVnfdId(pkgOnboardingNotification.getVnfdId()); - - vnfPackageOnboardingNotification.setLinks(convert(pkgOnboardingNotification.getLinks(), - pkgOnboardingNotification.getVnfPkgId(), pkgOnboardingNotification.getSubscriptionId())); - - return vnfPackageOnboardingNotification; - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/etsicatalog/sol003/VnfPkgInfoConverter.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/etsicatalog/sol003/VnfPkgInfoConverter.java deleted file mode 100644 index 0121cc5885..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/etsicatalog/sol003/VnfPkgInfoConverter.java +++ /dev/null @@ -1,198 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.converters.etsicatalog.sol003; - -import java.util.ArrayList; -import java.util.List; -import org.onap.so.adapters.etsi.sol003.adapter.common.VnfmAdapterUrlProvider; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.Checksum; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VNFPKGMLinkSerializer; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPackageArtifactInfo; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPackageSoftwareImageInfo; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPkgInfo; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.InlineResponse2001; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.VnfPackagesAdditionalArtifacts; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.VnfPackagesChecksum; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.VnfPackagesLinks; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.VnfPackagesLinksSelf; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.VnfPackagesSoftwareImages; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.convert.converter.Converter; -import org.springframework.stereotype.Service; - -/** - * Converter to convert from an Etsi Catalog Manager {@link VnfPkgInfo} Object to its equivalent SOL003 Object - * {@link InlineResponse2001} Object - * - * @author andrew.a.lamb@est.tech - */ -@Service -public class VnfPkgInfoConverter implements Converter<VnfPkgInfo, InlineResponse2001> { - private static final Logger logger = LoggerFactory.getLogger(VnfPkgInfoConverter.class); - private final VnfmAdapterUrlProvider vnfmAdapterUrlProvider; - - public VnfPkgInfoConverter(final VnfmAdapterUrlProvider vnfmAdapterUrlProvider) { - this.vnfmAdapterUrlProvider = vnfmAdapterUrlProvider; - } - - /** - * Convert a {@link VnfPkgInfo} Object to an {@link InlineResponse2001} Object - * - * @param vnfPkgInfo The VnfPkgInfo Object to Convert - * @return The Converted InlineResponse2001 Object - */ - @Override - public InlineResponse2001 convert(final VnfPkgInfo vnfPkgInfo) { - if (vnfPkgInfo == null) { - logger.error("No VnfPkgInfo Object Provided for Conversion. (Null object received, returning Null)"); - return null; - } - final InlineResponse2001 response = new InlineResponse2001(); - response.setId(vnfPkgInfo.getId()); - response.setVnfdId(vnfPkgInfo.getVnfdId()); - response.setVnfProvider(vnfPkgInfo.getVnfProvider()); - response.setVnfProductName(vnfPkgInfo.getVnfProductName()); - response.setVnfSoftwareVersion(vnfPkgInfo.getVnfSoftwareVersion()); - response.setVnfdVersion(vnfPkgInfo.getVnfdVersion()); - response.setChecksum(convertChecksumToVnfPackagesChecksum(vnfPkgInfo.getChecksum())); - response.setSoftwareImages( - convertVnfPackageSoftwareImageInfoListToVnfPackagesSoftwareImagesList(vnfPkgInfo.getSoftwareImages())); - response.setAdditionalArtifacts(convertVnfPackageArtifactInfoListToVnfPackagesAdditionalArtifactsList( - vnfPkgInfo.getAdditionalArtifacts())); - - if (vnfPkgInfo.getOnboardingState() != null) { - response.setOnboardingState( - InlineResponse2001.OnboardingStateEnum.fromValue(vnfPkgInfo.getOnboardingState().getValue())); - } - - if (vnfPkgInfo.getOperationalState() != null) { - response.setOperationalState( - InlineResponse2001.OperationalStateEnum.fromValue(vnfPkgInfo.getOperationalState().getValue())); - } - - response.setUserDefinedData((vnfPkgInfo.getUserDefinedData())); - - if (vnfPkgInfo.getLinks() != null) { - response.setLinks(getVnfPackagesLinks(vnfPkgInfo.getLinks(), vnfPkgInfo.getId())); - } - - return response; - } - - private VnfPackagesChecksum convertChecksumToVnfPackagesChecksum(final Checksum checksum) { - final VnfPackagesChecksum vnfPackagesChecksum = new VnfPackagesChecksum(); - if (checksum != null) { - vnfPackagesChecksum.setAlgorithm(checksum.getAlgorithm()); - vnfPackagesChecksum.setHash(checksum.getHash()); - } - return vnfPackagesChecksum; - } - - private List<VnfPackagesSoftwareImages> convertVnfPackageSoftwareImageInfoListToVnfPackagesSoftwareImagesList( - final List<VnfPackageSoftwareImageInfo> vnfPackageSoftwareImageInfoList) { - final List<VnfPackagesSoftwareImages> vnfPackagesSoftwareImages = new ArrayList<>(); - if (vnfPackageSoftwareImageInfoList != null) { - for (final VnfPackageSoftwareImageInfo vnfPackageSoftwareImageInfo : vnfPackageSoftwareImageInfoList) { - final VnfPackagesSoftwareImages softwareImage = - convertVnfPackageSoftwareImageInfoToVnfPackagesSoftwareImages(vnfPackageSoftwareImageInfo); - vnfPackagesSoftwareImages.add(softwareImage); - } - } - return vnfPackagesSoftwareImages; - } - - private VnfPackagesSoftwareImages convertVnfPackageSoftwareImageInfoToVnfPackagesSoftwareImages( - final VnfPackageSoftwareImageInfo vnfPackageSoftwareImageInfo) { - final VnfPackagesSoftwareImages vnfPackagesSoftwareImages = new VnfPackagesSoftwareImages(); - vnfPackagesSoftwareImages.setId(vnfPackageSoftwareImageInfo.getId()); - vnfPackagesSoftwareImages.setName(vnfPackageSoftwareImageInfo.getName()); - vnfPackagesSoftwareImages.setProvider(vnfPackageSoftwareImageInfo.getProvider()); - vnfPackagesSoftwareImages.setVersion(vnfPackageSoftwareImageInfo.getVersion()); - vnfPackagesSoftwareImages - .setChecksum(convertChecksumToVnfPackagesChecksum(vnfPackageSoftwareImageInfo.getChecksum())); - if (vnfPackageSoftwareImageInfo.getContainerFormat() != null) { - vnfPackagesSoftwareImages.setContainerFormat(VnfPackagesSoftwareImages.ContainerFormatEnum - .fromValue(vnfPackageSoftwareImageInfo.getContainerFormat().getValue())); - } - - if (vnfPackageSoftwareImageInfo.getDiskFormat() != null) { - vnfPackagesSoftwareImages.setDiskFormat(VnfPackagesSoftwareImages.DiskFormatEnum - .fromValue(vnfPackageSoftwareImageInfo.getDiskFormat().getValue())); - } - - vnfPackagesSoftwareImages.setCreatedAt(vnfPackageSoftwareImageInfo.getCreatedAt()); - vnfPackagesSoftwareImages.setMinDisk(vnfPackageSoftwareImageInfo.getMinDisk()); - vnfPackagesSoftwareImages.setMinRam(vnfPackageSoftwareImageInfo.getMinRam()); - vnfPackagesSoftwareImages.setSize(vnfPackageSoftwareImageInfo.getSize()); - vnfPackagesSoftwareImages.setUserMetadata(vnfPackageSoftwareImageInfo.getUserMetadata()); - vnfPackagesSoftwareImages.setImagePath(vnfPackageSoftwareImageInfo.getImagePath()); - return vnfPackagesSoftwareImages; - } - - private List<VnfPackagesAdditionalArtifacts> convertVnfPackageArtifactInfoListToVnfPackagesAdditionalArtifactsList( - final List<VnfPackageArtifactInfo> vnfPackageArtifactInfoList) { - if (vnfPackageArtifactInfoList != null) { - final List<VnfPackagesAdditionalArtifacts> additionalArtifacts = new ArrayList<>(); - for (final VnfPackageArtifactInfo artifactInfo : vnfPackageArtifactInfoList) { - final VnfPackagesAdditionalArtifacts artifact = - convertVnfPackageArtifactInfoToVnfPackagesAdditionalArtifacts(artifactInfo); - additionalArtifacts.add(artifact); - } - return additionalArtifacts; - } - return null; - } - - private VnfPackagesAdditionalArtifacts convertVnfPackageArtifactInfoToVnfPackagesAdditionalArtifacts( - final VnfPackageArtifactInfo vnfPackageArtifactInfo) { - final VnfPackagesAdditionalArtifacts vnfPackagesAdditionalArtifacts = new VnfPackagesAdditionalArtifacts(); - vnfPackagesAdditionalArtifacts.setArtifactPath(vnfPackageArtifactInfo.getArtifactPath()); - vnfPackagesAdditionalArtifacts - .setChecksum(convertChecksumToVnfPackagesChecksum(vnfPackageArtifactInfo.getChecksum())); - vnfPackagesAdditionalArtifacts.setMetadata(vnfPackageArtifactInfo.getMetadata()); - return vnfPackagesAdditionalArtifacts; - } - - private VnfPackagesLinks getVnfPackagesLinks(final VNFPKGMLinkSerializer links, final String vnfPkgId) { - final VnfPackagesLinks vnfPackagesLinks = new VnfPackagesLinks(); - - if (links.getSelf() != null) { - vnfPackagesLinks.setSelf(getVnfPackagesLinksSelf(vnfmAdapterUrlProvider.getVnfPackageUrl(vnfPkgId))); - } - - if (links.getVnfd() != null) { - vnfPackagesLinks.setVnfd(getVnfPackagesLinksSelf(vnfmAdapterUrlProvider.getVnfPackageVnfdUrl(vnfPkgId))); - } - - if (links.getPackageContent() != null) { - vnfPackagesLinks.setPackageContent( - getVnfPackagesLinksSelf(vnfmAdapterUrlProvider.getVnfPackageContentUrl(vnfPkgId))); - } - - return vnfPackagesLinks; - } - - private VnfPackagesLinksSelf getVnfPackagesLinksSelf(final String href) { - return new VnfPackagesLinksSelf().href(href); - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/sol003/etsicatalog/PkgmSubscriptionRequestConverter.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/sol003/etsicatalog/PkgmSubscriptionRequestConverter.java deleted file mode 100644 index f63ada9c75..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/converters/sol003/etsicatalog/PkgmSubscriptionRequestConverter.java +++ /dev/null @@ -1,198 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.converters.sol003.etsicatalog; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.Version; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfProducts; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfProductsProviders; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.PkgmSubscriptionRequest; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilter1; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilter1.NotificationTypesEnum; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilter1.OperationalStateEnum; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilter1.UsageStateEnum; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilterVersions; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilterVnfProducts; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilterVnfProductsFromProviders; -import org.springframework.core.convert.converter.Converter; -import org.springframework.stereotype.Service; - -/** - * Converter to convert from an Etsi Catalog Manager {@link PkgmSubscriptionRequest} Object to its equivalent ETSI - * Catalog Manager Object - * - * @author Ronan Kenny (ronan.kenny@est.tech) - * @author Gareth Roper (gareth.roper@est.tech) - */ -@Service -public class PkgmSubscriptionRequestConverter implements - Converter<PkgmSubscriptionRequest, org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest> { - - @Override - public org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest convert( - final PkgmSubscriptionRequest pkgmSubscriptionRequest) { - final org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest = - new org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest(); - - etsiCatalogManagerSubscriptionRequest - .setFilter(getPkgmNotificationsFilter(pkgmSubscriptionRequest.getFilter())); - - return etsiCatalogManagerSubscriptionRequest; - } - - - private org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter getPkgmNotificationsFilter( - final SubscriptionsFilter1 sol003SubscriptionsFilter) { - final org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter etsiCatalogManagerFilters = - new org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter(); - - if (sol003SubscriptionsFilter.getNotificationTypes() != null) { - etsiCatalogManagerFilters.setNotificationTypes( - getPkgmNotificationsFilterNotificationTypes(sol003SubscriptionsFilter.getNotificationTypes())); - } - - etsiCatalogManagerFilters.setVnfProductsFromProviders( - getVnfProductsProviders(sol003SubscriptionsFilter.getVnfProductsFromProviders())); - - etsiCatalogManagerFilters.setVnfdId(getVnfdIds(sol003SubscriptionsFilter.getVnfdId())); - - etsiCatalogManagerFilters.setVnfPkgId(getVnfPkgIds(sol003SubscriptionsFilter.getVnfPkgId())); - - etsiCatalogManagerFilters - .setOperationalState(getOperationalState(sol003SubscriptionsFilter.getOperationalState())); - - etsiCatalogManagerFilters.setUsageState(getUsageState(sol003SubscriptionsFilter.getUsageState())); - - return etsiCatalogManagerFilters; - } - - - private List<org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.UsageStateEnum> getUsageState( - final List<UsageStateEnum> usageStates) { - if (usageStates != null) { - final List<org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.UsageStateEnum> etsiCatalogUsageStates = - new ArrayList<>(); - usageStates.stream().forEach(state -> { - etsiCatalogUsageStates.add( - org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.UsageStateEnum - .fromValue(state.getValue())); - }); - return etsiCatalogUsageStates; - } - return Collections.emptyList(); - } - - - private List<org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.OperationalStateEnum> getOperationalState( - final List<OperationalStateEnum> operationalStates) { - if (operationalStates != null) { - final List<org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.OperationalStateEnum> etsiCatalogOperationalStates = - new ArrayList<>(); - operationalStates.forEach(state -> { - etsiCatalogOperationalStates.add( - org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.OperationalStateEnum - .fromValue(state.getValue())); - }); - - return etsiCatalogOperationalStates; - } - return Collections.emptyList(); - } - - private List<String> getVnfPkgIds(final List<String> vnfPkgId) { - if (vnfPkgId != null) { - final List<String> etsiCatalogManagerVnfPkgId = new ArrayList<>(); - vnfPkgId.forEach(type -> { - etsiCatalogManagerVnfPkgId.add(type); - }); - return etsiCatalogManagerVnfPkgId; - } - return Collections.emptyList(); - } - - private List<String> getVnfdIds(final List<String> vnfdId) { - if (vnfdId != null) { - final List<String> etsiCatalogManagerVnfdId = new ArrayList<>(); - vnfdId.forEach(type -> { - etsiCatalogManagerVnfdId.add(type); - }); - return etsiCatalogManagerVnfdId; - } - return Collections.emptyList(); - } - - private List<VnfProductsProviders> getVnfProductsProviders( - final List<SubscriptionsFilterVnfProductsFromProviders> filterProductsFromProvider) { - - if (filterProductsFromProvider != null && !filterProductsFromProvider.isEmpty()) { - final List<VnfProductsProviders> etsiCatalogManagerVnfProductsProviders = new ArrayList<>(); - filterProductsFromProvider.forEach(vnfProduct -> { - etsiCatalogManagerVnfProductsProviders - .add(new VnfProductsProviders().vnfProvider(vnfProduct.getVnfProvider()) - .vnfProducts(getVnfProducts(vnfProduct.getVnfProducts()))); - }); - return etsiCatalogManagerVnfProductsProviders; - } - return Collections.emptyList(); - } - - private List<VnfProducts> getVnfProducts(final List<SubscriptionsFilterVnfProducts> sol003VnfProducts) { - if (sol003VnfProducts != null) { - final List<VnfProducts> etsiCatalogManagerVnfProductsList = new ArrayList<>(); - sol003VnfProducts.forEach(vnfProduct -> { - etsiCatalogManagerVnfProductsList.add(new VnfProducts().vnfProductName(vnfProduct.getVnfProductName()) - .versions(getVersion(vnfProduct.getVersions()))); - }); - return etsiCatalogManagerVnfProductsList; - } - return Collections.emptyList(); - } - - private List<Version> getVersion(final List<SubscriptionsFilterVersions> sol003FilterVersions) { - if (sol003FilterVersions != null && !sol003FilterVersions.isEmpty()) { - final List<Version> etsiCatalogVersionList = new ArrayList<>(); - sol003FilterVersions.forEach(vnfFilterVersion -> { - etsiCatalogVersionList.add(new Version().vnfSoftwareVersion(vnfFilterVersion.getVnfSoftwareVersion()) - .vnfdVersions(vnfFilterVersion.getVnfdVersions())); - }); - return etsiCatalogVersionList; - } - return Collections.emptyList(); - } - - private List<org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.NotificationTypesEnum> getPkgmNotificationsFilterNotificationTypes( - final List<NotificationTypesEnum> notificationTypes) { - - if (notificationTypes != null && !notificationTypes.isEmpty()) { - final List<org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.NotificationTypesEnum> etsiCatalogNotificationTypes = - new ArrayList<>(); - notificationTypes.forEach(type -> etsiCatalogNotificationTypes.add( - org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.NotificationTypesEnum - .fromValue(type.getValue()))); - return etsiCatalogNotificationTypes; - } - return Collections.emptyList(); - } - - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProvider.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProvider.java deleted file mode 100644 index db3c24bd1c..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProvider.java +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog; - -import java.util.Optional; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.InlineResponse2001; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public interface EtsiCatalogPackageManagementServiceProvider { - - /** - * GET Package Content, from VNF Package. - * - * @param vnfPkgId The ID of the VNF Package from which the "package_content" will be retrieved. - * @return The Package Content of a VNF Package ("vnfPkgId"). - */ - Optional<byte[]> getVnfPackageContent(final String vnfPkgId); - - /** - * GET VNF packages information from ETSI Catalog. Will return zero or more VNF package representations. - * - * @return An Array of all VNF packages retrieved from the ETSI Catalog. - */ - Optional<InlineResponse2001[]> getVnfPackages(); - - /** - * GET specific VNF package information from ETSI Catalog. - * - * @param vnfPkgId The ID of the VNF Package that you want to query. - * @return The VNF package retrieved from the ETSI Catalog - */ - Optional<InlineResponse2001> getVnfPackage(final String vnfPkgId); - - /** - * GET specific VNF package VNFD from ETSI Catalog. - * - * @param vnfPkgId The ID of the VNF Package that you want to query. - * @return The VNF package retrieved from the ETSI Catalog - */ - Optional<byte[]> getVnfPackageVnfd(final String vnfPkgId); - - /** - * GET Package Artifact, from VNF Package. - * - * @param vnfPkgId The ID of the VNF Package from which the artifact will be retrieved. - * @param artifactPath Sequence of one or more path segments representing the path of the artifact within the VNF - * Package, e.g., foo/bar/run.sh - * @return The Package Artifact of a VNF Package ("vnfPkgId", "artifactPath"). - */ - Optional<byte[]> getVnfPackageArtifact(final String vnfPkgId, final String artifactPath); - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogServiceProvider.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogServiceProvider.java deleted file mode 100644 index f11fc5c39a..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogServiceProvider.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog; - -/** - * Provides methods for invoking REST calls to the ETSI Catalog Manager. - * - * @author gareth.roper@est.tech - */ -public interface EtsiCatalogServiceProvider - extends EtsiCatalogSubscriptionServiceProvider, EtsiCatalogPackageManagementServiceProvider { - - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java deleted file mode 100644 index 1ff3672df9..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java +++ /dev/null @@ -1,176 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog; - -import java.io.IOException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; -import java.util.concurrent.TimeUnit; -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.config.Registry; -import org.apache.http.config.RegistryBuilder; -import org.apache.http.conn.socket.ConnectionSocketFactory; -import org.apache.http.conn.socket.PlainConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.apache.http.ssl.SSLContextBuilder; -import org.onap.logging.filter.spring.SpringClientPayloadFilter; -import org.onap.so.adapters.etsi.sol003.adapter.common.configuration.AbstractServiceProviderConfiguration; -import org.onap.so.configuration.rest.BasicHttpHeadersProvider; -import org.onap.so.configuration.rest.HttpClientConnectionConfiguration; -import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; -import org.onap.so.rest.service.HttpRestServiceProvider; -import org.onap.so.rest.service.HttpRestServiceProviderImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.Resource; -import org.springframework.http.client.BufferingClientHttpRequestFactory; -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.springframework.web.client.RestTemplate; -import com.google.gson.Gson; - -/** - * Configures the HttpRestServiceProvider to make REST calls to the ETSI Catalog Manager - * - * @author gareth.roper@est.tech - */ - -@Configuration -public class EtsiCatalogServiceProviderConfiguration extends AbstractServiceProviderConfiguration { - - public static final String ETSI_CATALOG_REST_TEMPLATE_BEAN = "etsiCatalogRestTemplate"; - - public static final String ETSI_CATALOG_SERVICE_PROVIDER_BEAN = "etsiCatalogServiceProvider"; - - private final static Logger LOGGER = LoggerFactory.getLogger(EtsiCatalogServiceProviderConfiguration.class); - - private final HttpClientConnectionConfiguration clientConnectionConfiguration; - - @Value("${etsi-catalog-manager.http.client.ssl.trust-store:#{null}}") - private Resource trustStore; - @Value("${etsi-catalog-manager.http.client.ssl.trust-store-password:#{null}}") - private String trustStorePassword; - - @Autowired - public EtsiCatalogServiceProviderConfiguration( - final HttpClientConnectionConfiguration clientConnectionConfiguration) { - this.clientConnectionConfiguration = clientConnectionConfiguration; - } - - @Bean - @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN) - public RestTemplate etsiCatalogRestTemplate() { - final RestTemplate restTemplate = new RestTemplate(); - restTemplate.getInterceptors().add(new SOSpringClientFilter()); - restTemplate.getInterceptors().add((new SpringClientPayloadFilter())); - return restTemplate; - } - - @Bean - @Qualifier(ETSI_CATALOG_SERVICE_PROVIDER_BEAN) - public HttpRestServiceProvider etsiCatalogHttpRestServiceProvider( - @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN) final RestTemplate restTemplate) { - setGsonMessageConverter(restTemplate); - - final HttpClientBuilder httpClientBuilder = getHttpClientBuilder(); - if (trustStore != null) { - try { - LOGGER.debug("Setting up HttpComponentsClientHttpRequestFactory with SSL Context"); - LOGGER.debug("Setting client trust-store: {}", trustStore.getURL()); - LOGGER.debug("Creating SSLConnectionSocketFactory with AllowAllHostsVerifier ... "); - final SSLContext sslContext = new SSLContextBuilder() - .loadTrustMaterial(trustStore.getURL(), trustStorePassword.toCharArray()).build(); - final SSLConnectionSocketFactory sslConnectionSocketFactory = - new SSLConnectionSocketFactory(sslContext, AllowAllHostsVerifier.INSTANCE); - httpClientBuilder.setSSLSocketFactory(sslConnectionSocketFactory); - final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder - .<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE) - .register("https", sslConnectionSocketFactory).build(); - - httpClientBuilder.setConnectionManager(getConnectionManager(socketFactoryRegistry)); - } catch (final KeyManagementException | NoSuchAlgorithmException | KeyStoreException | CertificateException - | IOException exception) { - LOGGER.error("Error reading truststore, TLS connection will fail.", exception); - } - - } else { - LOGGER.debug("Setting connection manager without SSL ConnectionSocketFactory ..."); - httpClientBuilder.setConnectionManager(getConnectionManager()); - } - - final HttpComponentsClientHttpRequestFactory factory = - new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build()); - restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(factory)); - - return new HttpRestServiceProviderImpl(restTemplate, new BasicHttpHeadersProvider().getHttpHeaders()); - } - - private PoolingHttpClientConnectionManager getConnectionManager( - final Registry<ConnectionSocketFactory> socketFactoryRegistry) { - return new PoolingHttpClientConnectionManager(socketFactoryRegistry, null, null, null, - clientConnectionConfiguration.getTimeToLiveInMins(), TimeUnit.MINUTES); - } - - private PoolingHttpClientConnectionManager getConnectionManager() { - return new PoolingHttpClientConnectionManager(clientConnectionConfiguration.getTimeToLiveInMins(), - TimeUnit.MINUTES); - } - - private HttpClientBuilder getHttpClientBuilder() { - return HttpClientBuilder.create().setMaxConnPerRoute(clientConnectionConfiguration.getMaxConnectionsPerRoute()) - .setMaxConnTotal(clientConnectionConfiguration.getMaxConnections()) - .setDefaultRequestConfig(getRequestConfig()); - } - - private RequestConfig getRequestConfig() { - return RequestConfig.custom().setSocketTimeout(clientConnectionConfiguration.getSocketTimeOutInMiliSeconds()) - .setConnectTimeout(clientConnectionConfiguration.getConnectionTimeOutInMilliSeconds()).build(); - } - - private static final class AllowAllHostsVerifier implements HostnameVerifier { - - private static final AllowAllHostsVerifier INSTANCE = new AllowAllHostsVerifier(); - - @Override - public boolean verify(final String hostname, final SSLSession session) { - LOGGER.debug("Skipping hostname verification ..."); - return true; - } - - } - - @Override - protected Gson getGson() { - return new JSON().getGson(); - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java deleted file mode 100644 index a4e5550061..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java +++ /dev/null @@ -1,281 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog; - -import static org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.EtsiCatalogServiceProviderConfiguration.ETSI_CATALOG_SERVICE_PROVIDER_BEAN; -import java.util.Optional; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdmSubscription; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscription; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPkgInfo; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.InlineResponse2001; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.EtsiCatalogManagerBadRequestException; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.EtsiCatalogManagerRequestFailureException; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.SubscriptionNotFoundException; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.VnfPkgBadRequestException; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.VnfPkgConflictException; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.VnfPkgNotFoundException; -import org.onap.so.rest.exceptions.HttpResouceNotFoundException; -import org.onap.so.rest.exceptions.InvalidRestRequestException; -import org.onap.so.rest.exceptions.RestProcessingException; -import org.onap.so.rest.service.HttpRestServiceProvider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.core.convert.ConversionService; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; - -/** - * Provides the implementations of the REST Requests to the ETSI Catalog Manager. - * - * @author gareth.roper@est.tech - */ -@Service -public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvider { - private static final Logger logger = LoggerFactory.getLogger(EtsiCatalogServiceProviderImpl.class); - - private final HttpRestServiceProvider httpServiceProvider; - private final EtsiCatalogUrlProvider etsiCatalogUrlProvider; - private final ConversionService conversionService; - - @Autowired - public EtsiCatalogServiceProviderImpl(final EtsiCatalogUrlProvider etsiCatalogUrlProvider, - @Qualifier(ETSI_CATALOG_SERVICE_PROVIDER_BEAN) final HttpRestServiceProvider httpServiceProvider, - final ConversionService conversionService) { - this.etsiCatalogUrlProvider = etsiCatalogUrlProvider; - this.httpServiceProvider = httpServiceProvider; - this.conversionService = conversionService; - } - - @Override - public Optional<byte[]> getVnfPackageContent(final String vnfPkgId) - throws EtsiCatalogManagerRequestFailureException { - final String vnfRequestUrl = etsiCatalogUrlProvider.getVnfPackageContentUrl(vnfPkgId); - final String vnfRequestName = "getVnfPackageContent"; - return requestVnfElement(vnfPkgId, vnfRequestUrl, vnfRequestName); - } - - @Override - public Optional<byte[]> getVnfPackageArtifact(final String vnfPkgId, final String artifactPath) { - try { - final ResponseEntity<byte[]> response = httpServiceProvider.getHttpResponse( - etsiCatalogUrlProvider.getVnfPackageArtifactUrl(vnfPkgId, artifactPath), byte[].class); - logger.info("getVnfPackageArtifact Request to ETSI Catalog Manager Status Code: {}", - response.getStatusCodeValue()); - if (response.getStatusCode().is2xxSuccessful()) { - return Optional.ofNullable(response.getBody()); - } - } catch (final HttpResouceNotFoundException httpResouceNotFoundException) { - logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException); - throw new VnfPkgNotFoundException("No Vnf Package Artifact found with vnfPkgId: \"" + vnfPkgId - + "\" and artifactPath: \"" + artifactPath + "\"."); - } catch (final RestProcessingException restProcessingException) { - logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(), - restProcessingException); - if (restProcessingException.getStatusCode() == HttpStatus.CONFLICT.value()) { - throw new VnfPkgConflictException("A conflict occurred with the state of the resource,\n" - + "due to the attribute: onboardingState not being set to ONBOARDED."); - } - } - throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred."); - } - - @Override - public Optional<InlineResponse2001[]> getVnfPackages() { - try { - final ResponseEntity<VnfPkgInfo[]> response = - httpServiceProvider.getHttpResponse(etsiCatalogUrlProvider.getVnfPackagesUrl(), VnfPkgInfo[].class); - logger.info("getVnfPackages Request to ETSI Catalog Manager Status Code: {}", - response.getStatusCodeValue()); - if (response.getStatusCode().is2xxSuccessful()) { - if (response.hasBody()) { - final VnfPkgInfo[] vnfPackages = response.getBody(); - assert (vnfPackages != null); - final InlineResponse2001[] responses = new InlineResponse2001[vnfPackages.length]; - for (int index = 0; index < vnfPackages.length; index++) { - if (conversionService.canConvert(vnfPackages[index].getClass(), InlineResponse2001.class)) { - final InlineResponse2001 inlineResponse2001 = - conversionService.convert(vnfPackages[index], InlineResponse2001.class); - if (inlineResponse2001 != null) { - responses[index] = inlineResponse2001; - } - } else { - logger.error("Unable to find Converter for response class: {}", - vnfPackages[index].getClass()); - } - } - return Optional.of(responses); - } - logger.error("Received response without body ..."); - } - logger.error("Unexpected status code received {}", response.getStatusCode()); - return Optional.empty(); - } catch (final InvalidRestRequestException invalidRestRequestException) { - logger.error("Caught InvalidRestRequestException", invalidRestRequestException); - throw new VnfPkgBadRequestException("Error: Bad Request Received"); - } catch (final HttpResouceNotFoundException httpResouceNotFoundException) { - logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException); - throw new VnfPkgNotFoundException("No Vnf Packages found"); - } catch (final RestProcessingException restProcessingException) { - logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(), - restProcessingException); - throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred."); - } - } - - @Override - public Optional<InlineResponse2001> getVnfPackage(final String vnfPkgId) { - try { - final ResponseEntity<VnfPkgInfo> response = httpServiceProvider - .getHttpResponse(etsiCatalogUrlProvider.getVnfPackageUrl(vnfPkgId), VnfPkgInfo.class); - logger.info("getVnfPackage Request for vnfPkgId {} to ETSI Catalog Manager Status Code: {}", vnfPkgId, - response.getStatusCodeValue()); - if (response.getStatusCode().is2xxSuccessful()) { - if (response.hasBody()) { - final VnfPkgInfo vnfPkgInfo = response.getBody(); - if (conversionService.canConvert(vnfPkgInfo.getClass(), InlineResponse2001.class)) { - return Optional.ofNullable(conversionService.convert(vnfPkgInfo, InlineResponse2001.class)); - } - logger.error("Unable to find Converter for response class: {}", vnfPkgInfo.getClass()); - } - logger.error("Received response without body ...."); - } - return Optional.empty(); - } catch (final InvalidRestRequestException invalidRestRequestException) { - logger.error("Caught InvalidRestRequestException", invalidRestRequestException); - throw new VnfPkgBadRequestException("Error: Bad Request Received"); - } catch (final HttpResouceNotFoundException httpResouceNotFoundException) { - logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException); - throw new VnfPkgNotFoundException("No Vnf Package found with vnfPkgId: " + vnfPkgId); - } catch (final RestProcessingException restProcessingException) { - logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(), - restProcessingException); - throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred."); - } - } - - @Override - public Optional<byte[]> getVnfPackageVnfd(final String vnfPkgId) { - final String vnfRequestUrl = etsiCatalogUrlProvider.getVnfPackageVnfdUrl(vnfPkgId); - final String vnfRequestName = "getVnfPackageVnfd"; - return requestVnfElement(vnfPkgId, vnfRequestUrl, vnfRequestName); - } - - @Override - public Optional<PkgmSubscription> postSubscription( - final org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest) { - try { - final ResponseEntity<PkgmSubscription> responseEntity = - httpServiceProvider.postHttpRequest(etsiCatalogManagerSubscriptionRequest, - etsiCatalogUrlProvider.getSubscriptionUrl(), PkgmSubscription.class); - if (responseEntity.getStatusCode().is2xxSuccessful()) { - if (responseEntity.hasBody()) { - return Optional.of(responseEntity.getBody()); - } - logger.error("Received response without body on postSubscription"); - } - logger.error("Unexpected Status Code Received on postSubscription: {}", responseEntity.getStatusCode()); - return Optional.empty(); - } catch (final InvalidRestRequestException invalidRestRequestException) { - logger.error("Caught InvalidRestRequestException", invalidRestRequestException); - throw new EtsiCatalogManagerBadRequestException( - "Bad Request Received on postSubscription call to ETSI Catalog Manager."); - } catch (final RestProcessingException restProcessingException) { - logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(), - restProcessingException); - throw new EtsiCatalogManagerRequestFailureException( - "Internal Server Error Occurred. On postSubscription with StatusCode: " - + restProcessingException.getStatusCode()); - } - } - - @Override - public boolean deleteSubscription(final String subscriptionId) { - try { - final ResponseEntity<Void> responseEntity = httpServiceProvider - .deleteHttpRequest(etsiCatalogUrlProvider.getSubscriptionUrl() + "/" + subscriptionId, Void.class); - - if (responseEntity.getStatusCode().is2xxSuccessful()) { - logger.info("Subscription with ID: {} has been successfully deleted from the ETSI Catalog Manager", - subscriptionId); - return true; - } - logger.error("Unexpected Status Code Received on deleteSubscription: {}", responseEntity.getStatusCode()); - return false; - } catch (final HttpResouceNotFoundException resouceNotFoundException) { - final String message = "Unable to find subscription in ETSI Catalog Manager using id: " + subscriptionId; - logger.error(message); - throw new SubscriptionNotFoundException(message); - } catch (final InvalidRestRequestException invalidRestRequestException) { - logger.error("Caught InvalidRestRequestException on deleteSubscription call to ETSI Catalog Manager.", - invalidRestRequestException); - throw new EtsiCatalogManagerBadRequestException( - "Bad Request Received on deleteSubscription call to ETSI Catalog Manager."); - } - } - - @Override - public Optional<NsdmSubscription> getSubscription(final String subscriptionId) { - try { - final ResponseEntity<NsdmSubscription> responseEntity = httpServiceProvider.getHttpResponse( - etsiCatalogUrlProvider.getSubscriptionUrl() + "/" + subscriptionId, NsdmSubscription.class); - - if (responseEntity.getStatusCode().is2xxSuccessful()) { - logger.debug("Found subscription with ID: {} in ETSI Catalog Manager", subscriptionId); - return Optional.ofNullable(responseEntity.getBody()); - } - logger.error("Unexpected Status Code Received on getting subscription from ETSI Catalog Manager: {}", - responseEntity.getStatusCode()); - } catch (final HttpResouceNotFoundException resouceNotFoundException) { - logger.error("Unable to find subscription in ETSI Catalog Manager using id: {}", subscriptionId); - return Optional.empty(); - } catch (final RestProcessingException | InvalidRestRequestException exception) { - logger.error("Unable to query ETSI Catalog Manager for subscription using id: {}", subscriptionId, - exception); - } - throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred."); - } - - private Optional<byte[]> requestVnfElement(final String vnfPkgId, final String vnfRequestUrl, - final String vnfRequestName) { - try { - final ResponseEntity<byte[]> response = httpServiceProvider.getHttpResponse(vnfRequestUrl, byte[].class); - logger.info("{} Request to ETSI Catalog Manager Status Code: {}", vnfRequestName, - response.getStatusCodeValue()); - if (response.getStatusCode() == HttpStatus.OK) { - return Optional.ofNullable(response.getBody()); - } - } catch (final HttpResouceNotFoundException httpResouceNotFoundException) { - logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException); - throw new VnfPkgNotFoundException("No Vnf Package found with vnfPkgId: " + vnfPkgId); - } catch (final RestProcessingException restProcessingException) { - logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(), - restProcessingException); - if (restProcessingException.getStatusCode() == HttpStatus.CONFLICT.value()) { - throw new VnfPkgConflictException("A conflict occurred with the state of the resource,\n" - + "due to the attribute: onboardingState not being set to ONBOARDED."); - } - } - throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred."); - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogSubscriptionServiceProvider.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogSubscriptionServiceProvider.java deleted file mode 100644 index d561f8734b..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogSubscriptionServiceProvider.java +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog; - -import java.util.Optional; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdmSubscription; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscription; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -public interface EtsiCatalogSubscriptionServiceProvider { - - /** - * POST the SubscriptionRequest Object. - * - * @return The ETSI Catalog Manager's PkgmSubscription object. - */ - Optional<PkgmSubscription> postSubscription( - final org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest); - - /** - * Get the Subscription from ETSI Catalog. - * - * @param subscriptionId Subscription ID - * @return The Subscription {@link NsdmSubscription} from ETSI Catalog - */ - Optional<NsdmSubscription> getSubscription(final String subscriptionId); - - /** - * DELETE the SubscriptionRequest Object. - * - * @return A Boolean representing if the delete was successful or not. - */ - boolean deleteSubscription(final String subscriptionId); - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogUrlProvider.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogUrlProvider.java deleted file mode 100644 index 1725bf9fba..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogUrlProvider.java +++ /dev/null @@ -1,113 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog; - -import static org.slf4j.LoggerFactory.getLogger; -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; - -/** - * Provides the URLs for the REST Requests to the ETSI Catalog Manager. - * - * @author gareth.roper@est.tech - */ -@Service -public class EtsiCatalogUrlProvider { - - private static final Logger logger = getLogger(EtsiCatalogUrlProvider.class); - - @Value("${etsi-catalog-manager.vnfpkgm.endpoint}") - private String etsiCatalogManagerEndpoint; - - public EtsiCatalogUrlProvider() {} - - /** - * Get the URL for retrieving the Package Content from the ETSI Catalog.". - * - * @param vnfPkgId The ID of the VNF Package - * @return the URL for the GET operation - */ - public String getVnfPackageContentUrl(final String vnfPkgId) { - final String url = etsiCatalogManagerEndpoint + "/vnf_packages/" + vnfPkgId + "/package_content"; - logger.info("getEtsiCatalogVnfPackageContentUrl: {}", url); - return url; - } - - /** - * Get the URL for retrieving VNF packages information from ETSI Catalog.". - * - * @return the URL for the GET operation - */ - public String getVnfPackagesUrl() { - final String url = etsiCatalogManagerEndpoint + "/vnf_packages"; - logger.info("getEtsiCatalogVnfPackagesEndpoint: {}", url); - return url; - } - - /** - * Get the URL for retrieving specific VNF package information from the ETSI Catalog.". - * - * @param vnfPkgId The ID of the VNF Package - * @return the URL for the GET operation - */ - public String getVnfPackageUrl(final String vnfPkgId) { - final String url = etsiCatalogManagerEndpoint + "/vnf_packages/" + vnfPkgId; - logger.info("getEtsiCatalogVnfPackageEndpoint: {}", url); - return url; - } - - /** - * Get the URL for retrieving VNF Package Artifacts - * - * @param vnfPkgId The ID of the VNF Package - * @param artifactPath The path to the Artifact - * @return the URL for the GET operation - */ - public String getVnfPackageArtifactUrl(final String vnfPkgId, final String artifactPath) { - final String url = etsiCatalogManagerEndpoint + "/vnf_packages/" + vnfPkgId + "/artifacts/" + artifactPath; - logger.info("getVnfPackageArtifactUrl: {}", url); - return url; - } - - /** - * Get the URL for retrieving VNF packages vnfd from ETSI Catalog. - * - * @param vnfPkgId The ID of the VNF Package - * @return the URL for the GET operation - */ - public String getVnfPackageVnfdUrl(final String vnfPkgId) { - final String url = etsiCatalogManagerEndpoint + "/vnf_packages/" + vnfPkgId + "/vnfd"; - logger.info("getEtsiCatalogVnfPackageVnfd: {}", url); - return url; - } - - /** - * Get the URL for posting/retrieving a Subscription - * - * @return the URL for the operation - */ - public String getSubscriptionUrl() { - final String url = etsiCatalogManagerEndpoint + "/subscriptions"; - logger.info("getSubscriptionNotificationUrl: {}", url); - return url; - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/vnfm/VnfmHttpServiceProviderConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/vnfm/VnfmHttpServiceProviderConfiguration.java deleted file mode 100644 index 22bbef9c01..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/vnfm/VnfmHttpServiceProviderConfiguration.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.extclients.vnfm; - -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; -import java.time.LocalDateTime; -import java.time.OffsetDateTime; -import org.onap.so.adapters.etsi.sol003.adapter.common.configuration.AbstractServiceProviderConfiguration; -import org.onap.so.adapters.etsisol003adapter.pkgm.JSON; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.EtsiSubscriptionNotificationController; -import org.onap.so.configuration.rest.BasicHttpHeadersProvider; -import org.onap.so.rest.service.HttpRestServiceProvider; -import org.onap.so.rest.service.HttpRestServiceProviderImpl; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.client.RestTemplate; -import com.google.gson.Gson; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ -@Configuration -public class VnfmHttpServiceProviderConfiguration extends AbstractServiceProviderConfiguration { - private final JSON.OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new JSON.OffsetDateTimeTypeAdapter(); - - public static final String VNFM_ADAPTER_HTTP_SERVICE_PROVIDER_BEAN = "vnfmAdapterHttpServiceProvider"; - - @Bean - @Qualifier(VNFM_ADAPTER_HTTP_SERVICE_PROVIDER_BEAN) - public HttpRestServiceProvider vnfmAdapterHttpRestServiceProvider( - @Autowired @Qualifier(CONFIGURABLE_REST_TEMPLATE) RestTemplate restTemplate) { - setGsonMessageConverter(restTemplate); - return new HttpRestServiceProviderImpl(restTemplate, new BasicHttpHeadersProvider().getHttpHeaders()); - } - - @Override - protected Gson getGson() { - return JSON.createGson().registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter) - .registerTypeAdapter(LocalDateTime.class, - new EtsiSubscriptionNotificationController.LocalDateTimeTypeAdapter()) - .create(); - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/EtsiSubscriptionNotificationController.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/EtsiSubscriptionNotificationController.java deleted file mode 100644 index 2b4b486fa8..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/EtsiSubscriptionNotificationController.java +++ /dev/null @@ -1,166 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.rest; - -import static org.onap.so.adapters.etsi.sol003.adapter.common.CommonConstants.ETSI_SUBSCRIPTION_NOTIFICATION_CONTROLLER_BASE_URL; -import static org.slf4j.LoggerFactory.getLogger; -import java.io.IOException; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.AbstractMap; -import java.util.Map.Entry; -import javax.ws.rs.core.MediaType; -import org.onap.so.adapters.etsisol003adapter.etsicatalog.notification.model.PkgChangeNotification; -import org.onap.so.adapters.etsisol003adapter.etsicatalog.notification.model.PkgOnboardingNotification; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.InternalServerErrorException; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.NotificationTypeNotSupportedException; -import org.onap.so.adapters.etsisol003adapter.pkgm.subscriptionmgmt.NotificationManager; -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.TypeAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; - -/** - * This controller handles the ETSI Subscription Notification Endpoints. - * - * @author Ronan Kenny (ronan.kenny@est.tech) - * @author Gareth Roper (gareth.roper@est.tech) - * @author Andrew Lamb (andrew.a.lamb@est.tech) - */ -@Controller -@RequestMapping(value = ETSI_SUBSCRIPTION_NOTIFICATION_CONTROLLER_BASE_URL) -public class EtsiSubscriptionNotificationController { - - private static final Logger logger = getLogger(EtsiSubscriptionNotificationController.class); - private final NotificationManager notificationManager; - private final Gson gson; - - @Autowired - public EtsiSubscriptionNotificationController(final NotificationManager notificationManager) { - this.notificationManager = notificationManager; - this.gson = new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeTypeAdapter()).create(); - } - - @GetMapping(value = "/notification") - public ResponseEntity<Void> testSubscriptionNotificationEndPoint() { - logger.debug("Testing Notification Endpoint"); - return ResponseEntity.noContent().build(); - } - - /** - * POST notification on to subscriber. - * - * @param notification The notification to send. - * @return Response Code: 204 No Content if Successful, ProblemDetails Object if not. - */ - @PostMapping(value = "/notification", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON) - public ResponseEntity<?> postSubscriptionNotification(@RequestBody final Object notification) { - logger.info("Posting subscription notification class: {} \n{}", notification.getClass(), notification); - final String notificationString = gson.toJson(notification); - - final Entry<String, Object> notificationObject = getNotificationObject(notificationString); - if (notificationManager.processSubscriptionNotification(notificationObject.getValue(), - notificationObject.getKey())) { - logger.info("Notification Delivered Successfully"); - return ResponseEntity.noContent().build(); - } - final String errorMessage = "An error occurred. Sending of notification to VNFM failed."; - logger.error(errorMessage); - throw new InternalServerErrorException(errorMessage); - } - - private Entry<String, Object> getNotificationObject(final String notification) { - logger.info("getNotificationObject() notification: {}", notification); - final String notificationType = getNotificationType(notification); - if (PkgOnboardingNotification.NotificationTypeEnum.VNFPACKAGEONBOARDINGNOTIFICATION.getValue() - .equals(notificationType)) { - final PkgOnboardingNotification pkgOnboardingNotification = - gson.fromJson(notification, PkgOnboardingNotification.class); - logger.info("Onboarding notification received:\n{}", pkgOnboardingNotification); - return new AbstractMap.SimpleEntry<>(pkgOnboardingNotification.getSubscriptionId(), - pkgOnboardingNotification); - } - if (PkgChangeNotification.NotificationTypeEnum.VNFPACKAGECHANGENOTIFICATION.getValue() - .equals(notificationType)) { - final PkgChangeNotification pkgChangeNotification = - gson.fromJson(notification, PkgChangeNotification.class); - logger.info("Change notification received:\n{}", pkgChangeNotification); - return new AbstractMap.SimpleEntry<>(pkgChangeNotification.getSubscriptionId(), pkgChangeNotification); - - } - - final String errorMessage = "An error occurred. Notification type not supported for: " + notificationType; - logger.error(errorMessage); - throw new NotificationTypeNotSupportedException(errorMessage); - - } - - private String getNotificationType(final String notification) { - try { - logger.info("getNotificationType() notification: {}", notification); - final JsonParser parser = new JsonParser(); - final JsonObject element = (JsonObject) parser.parse(notification); - return element.get("notificationType").getAsString(); - } catch (final Exception e) { - logger.error("An error occurred processing notificiation: {}", e.getMessage()); - } - throw new NotificationTypeNotSupportedException( - "Unable to parse notification type in object \n" + notification); - } - - public static class LocalDateTimeTypeAdapter extends TypeAdapter<LocalDateTime> { - - private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - - @Override - public void write(final JsonWriter out, final LocalDateTime localDateTime) throws IOException { - if (localDateTime == null) { - out.nullValue(); - } else { - out.value(FORMATTER.format(localDateTime)); - } - } - - @Override - public LocalDateTime read(final JsonReader in) throws IOException { - switch (in.peek()) { - case NULL: - in.nextNull(); - return null; - default: - final String dateTime = in.nextString(); - return LocalDateTime.parse(dateTime, FORMATTER); - } - } - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementController.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementController.java deleted file mode 100644 index 6c1e5e5506..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementController.java +++ /dev/null @@ -1,176 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.rest; - -import static org.onap.so.adapters.etsi.sol003.adapter.common.CommonConstants.PACKAGE_MANAGEMENT_BASE_URL; -import static org.onap.so.adapters.etsisol003adapter.pkgm.PackageManagementConstants.APPLICATION_ZIP; -import static org.slf4j.LoggerFactory.getLogger; -import java.util.Optional; -import javax.ws.rs.core.MediaType; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.EtsiCatalogServiceProvider; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.ProblemDetails; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.InlineResponse2001; -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * Controller for handling the VNF Package Management. For further information please read: - * https://www.etsi.org/deliver/etsi_gs/NFV-SOL/001_099/003/02.05.01_60/gs_nfv-sol003v020501p.pdf Use the section number - * above each endpoint to find the corresponding section in the above document. - * - * @author gareth.roper@est.tech - */ -@Controller -@RequestMapping(value = PACKAGE_MANAGEMENT_BASE_URL, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) -public class Sol003PackageManagementController { - - private final EtsiCatalogServiceProvider etsiCatalogServiceProvider; - private static final String LOG_REQUEST_RECEIVED = "VNF PackageManagement Controller: {} {} {} {}"; - private static final Logger logger = getLogger(Sol003PackageManagementController.class); - - @Autowired - Sol003PackageManagementController(final EtsiCatalogServiceProvider etsiCatalogServiceProvider) { - this.etsiCatalogServiceProvider = etsiCatalogServiceProvider; - } - - /** - * GET VNF packages information. Will return zero or more VNF package representations that match the attribute - * filter. These representations will be in a list. Section Number: 10.4.2 - * - * @return An Array of all VNF packages. Object: InlineResponse2001[] Response Code: 200 OK - */ - @GetMapping(value = "/vnf_packages", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity<?> getVnfPackages() { - logger.info(LOG_REQUEST_RECEIVED, "getVnfPackages."); - final Optional<InlineResponse2001[]> response = etsiCatalogServiceProvider.getVnfPackages(); - if (response.isPresent()) { - logger.info(LOG_REQUEST_RECEIVED, "getVnfPackages Response: ", HttpStatus.OK); - return ResponseEntity.ok().body(response.get()); - } - final String errorMessage = "An error occurred, a null response was received by the\n" - + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" \n" - + "endpoint."; - logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ProblemDetails().detail(errorMessage)); - } - - /** - * GET VNF package information. Will return a specific VNF package representation that match the attribute filter. - * Section Number: 10.4.3 - * - * @param vnfPkgId The ID of the VNF Package that you want to query. - * @return A VNF package based on vnfPkgId. Object: VnfPkgInfo Response Code: 200 OK - */ - @GetMapping(value = "/vnf_packages/{vnfPkgId}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity<?> getVnfPackage(@PathVariable("vnfPkgId") final String vnfPkgId) { - logger.info(LOG_REQUEST_RECEIVED, "getVnfPackage: ", vnfPkgId); - final Optional<InlineResponse2001> response = etsiCatalogServiceProvider.getVnfPackage(vnfPkgId); - if (response.isPresent()) { - logger.info(LOG_REQUEST_RECEIVED, "getVnfPackage Response: ", HttpStatus.OK); - return ResponseEntity.ok().body(response.get()); - } - final String errorMessage = "An error occurred, a null response was received by the\n" - + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" by vnfPkgId: \"" - + vnfPkgId + "\" \n" + "endpoint."; - logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ProblemDetails().detail(errorMessage)); - } - - /** - * GET VNFD, from VNF package. Will return a copy of the file representing the VNFD or a ZIP file that contains the - * file/multiple files representing the VNFD specified. Section Number: 10.4.4 - * - * @param vnfPkgId The ID of the VNF Package that you want to retrieve the VNFD from. - * @return The VNFD of a VNF Package as a single file or within a ZIP file. Object: byte[] Response Code: 200 OK - */ - @GetMapping(value = "/vnf_packages/{vnfPkgId}/vnfd", - produces = {MediaType.TEXT_PLAIN, APPLICATION_ZIP, MediaType.APPLICATION_JSON}) - public ResponseEntity<?> getVnfPackageVnfd(@PathVariable("vnfPkgId") final String vnfPkgId) { - logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageVnfd Endpoint Invoked with VNF Package ID: ", vnfPkgId); - final Optional<byte[]> response = etsiCatalogServiceProvider.getVnfPackageVnfd(vnfPkgId); - if (response.isPresent()) { - logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageVnfd Response: ", HttpStatus.OK); - return new ResponseEntity<>(response.get(), HttpStatus.OK); - } - final String errorMessage = "An error occurred, a null response was received by the\n" - + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnfd\" \n" - + "endpoint."; - - logger.error(errorMessage); - return new ResponseEntity<>(new ProblemDetails().detail(errorMessage), HttpStatus.INTERNAL_SERVER_ERROR); - } - - /** - * GET Package Content, from VNF Package. Will return a copy of the VNF package file that you specified. Section - * Number: 10.4.5 - * - * @param vnfPkgId The ID of the VNF Package that you want to retrieve the "package_content" from. - * @return The Package Content of a VNF Package. Object: byte[] Response Code: 200 OK - */ - @GetMapping(value = "/vnf_packages/{vnfPkgId}/package_content", - produces = {MediaType.APPLICATION_JSON, APPLICATION_ZIP, MediaType.APPLICATION_OCTET_STREAM}) - public ResponseEntity<?> getVnfPackageContent(@PathVariable("vnfPkgId") final String vnfPkgId) { - logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageContent Endpoint Invoked with VNF Package ID: ", vnfPkgId); - final Optional<byte[]> response = etsiCatalogServiceProvider.getVnfPackageContent(vnfPkgId); - if (response.isPresent()) { - logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageContent Response: ", HttpStatus.OK); - return ResponseEntity.ok().body(response.get()); - } - final String errorMessage = "An error occurred, a null response was received by the\n" - + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"package_content\" \n" - + "endpoint."; - logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ProblemDetails().detail(errorMessage)); - } - - /** - * GET Artifact, from VNF Package Will return a the content of the artifact that you specified. Section Number: - * 10.4.6 - * - * @param vnfPkgId The ID of the VNF Package that you want to retrieve an artifact from. - * @param artifactPath The path of the artifact that you want to retrieve. - * @return An Artifact from a VNF Package. Object: byte[] Response Code: 200 OK - */ - @GetMapping(value = "/vnf_packages/{vnfPkgId}/artifacts/{artifactPath}", - produces = {MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON}) - public ResponseEntity<?> getVnfPackageArtifact(@PathVariable("vnfPkgId") final String vnfPkgId, - @PathVariable("artifactPath") final String artifactPath) { - logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageArtifact: vnfPkgId= ", vnfPkgId, " artifactPath=", - artifactPath); - final Optional<byte[]> response = etsiCatalogServiceProvider.getVnfPackageArtifact(vnfPkgId, artifactPath); - if (response.isPresent()) { - logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageArtifact Response: ", HttpStatus.OK); - return ResponseEntity.ok().body(response.get()); - } - final String errorMessage = "An error occurred, a null response was received by the\n" - + " Sol003PackageManagementController from the EtsiCatalogManager using the\n GET \"vnf_packages\" by vnfPkgId: \"" - + vnfPkgId + "\" for artifactPath: \"" + artifactPath + "\"\n" + "endpoint."; - logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ProblemDetails().detail(errorMessage)); - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementSubscriptionController.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementSubscriptionController.java deleted file mode 100644 index 7314f6aa2e..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementSubscriptionController.java +++ /dev/null @@ -1,172 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.rest; - -import static org.onap.so.adapters.etsi.sol003.adapter.common.CommonConstants.PACKAGE_MANAGEMENT_BASE_URL; -import static org.slf4j.LoggerFactory.getLogger; -import java.net.URI; -import java.security.GeneralSecurityException; -import java.util.List; -import java.util.Optional; -import javax.ws.rs.core.MediaType; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.ProblemDetails; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.InlineResponse201; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.PkgmSubscriptionRequest; -import org.onap.so.adapters.etsisol003adapter.pkgm.subscriptionmgmt.SubscriptionManager; -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * Controller for handling the Subscription Management. The client can use this resource to subscribe to notifications - * related to the VNF package management, and to query its subscriptions. For further information please read: - * https://www.etsi.org/deliver/etsi_gs/NFV-SOL/001_099/003/02.05.01_60/gs_nfv-sol003v020501p.pdf Use the section number - * above each endpoint to find the corresponding section in the above document. - * - * @author Ronan Kenny (ronan.kenny@est.tech) - * @author Gareth Roper (gareth.roper@est.tech) - */ -@Controller -@RequestMapping(value = PACKAGE_MANAGEMENT_BASE_URL, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, - consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) -public class Sol003PackageManagementSubscriptionController { - - private static final String LOG_REQUEST_RECEIVED = "Subscription Management Controller: {} {}"; - private static final Logger logger = getLogger(Sol003PackageManagementSubscriptionController.class); - private final SubscriptionManager subscriptionManager; - - @Autowired - public Sol003PackageManagementSubscriptionController(final SubscriptionManager subscriptionManager) { - this.subscriptionManager = subscriptionManager; - } - - /** - * POST Subscribe request. Will send request and respond with the subscription that you subscribed to, if - * successful. Section Number: 10.4.7 - * - * @param pkgmSubscriptionRequest This includes the details of the subscription to be created. - * @return The subscription requested, if successful. Object: InlineRespone2002 Response Code: 201 Created Response - * Code: 303 Duplicate Subscription - * @throws GeneralSecurityException - */ - @PostMapping(value = "/subscriptions") - public ResponseEntity<?> postSubscriptionRequest(@RequestBody final PkgmSubscriptionRequest pkgmSubscriptionRequest) - throws GeneralSecurityException { - logger.info(LOG_REQUEST_RECEIVED, " postSubscriptionRequest Endpoint Called", pkgmSubscriptionRequest); - - // Check if subscription exists already. - final Optional<String> exists = subscriptionManager.getSubscriptionId(pkgmSubscriptionRequest); - - if (exists.isPresent()) { - final URI subscriptionUri = subscriptionManager.getSubscriptionUri(exists.get()); - final HttpHeaders headers = createLocationHeader(subscriptionUri); - logger.info("PkgmSubscriptionRequest already exists with uri {} ", subscriptionUri); - return new ResponseEntity<>(headers, HttpStatus.SEE_OTHER); - } - - logger.debug("No duplicate Subscription exists, continuing with POST."); - final Optional<InlineResponse201> optionalInlineResponse = - subscriptionManager.createSubscription(pkgmSubscriptionRequest); - - if (optionalInlineResponse.isPresent()) { - InlineResponse201 inlineResponse = optionalInlineResponse.get(); - final URI subscriptionUri = subscriptionManager.getSubscriptionUri(inlineResponse.getId()); - final HttpHeaders headers = createLocationHeader(subscriptionUri); - logger.debug("Sending response with uri {} ", subscriptionUri); - return new ResponseEntity<>(inlineResponse, headers, HttpStatus.CREATED); - } - final String errorMessage = "A null response was received during the postSubscriptionRequest call."; - logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ProblemDetails().detail(errorMessage)); - } - - /** - * GET all subscriptions. Will return a list of all subscriptions currently active. Section Number: 10.4.7 - * - * @return All of the current active subscriptions. Object: List<InlineResponse2002> Response Code: 200 OK - */ - @GetMapping(value = "/subscriptions") - public ResponseEntity<List<InlineResponse201>> getSubscriptions() { - logger.info(LOG_REQUEST_RECEIVED, " getSubscriptions."); - List<InlineResponse201> subscriptionsList = subscriptionManager.getSubscriptions(); - return new ResponseEntity<>(subscriptionsList, HttpStatus.OK); - } - - /** - * GET a specific subscription, by subscriptionId. Section Number: 10.4.8 - * - * @param subscriptionId The ID of the subscription that you wish to retrieve. - * @return A subscription based on subscriptionId. Object: InlineResponse2002 Response Code: 200 OK - */ - @GetMapping(value = "/subscriptions/{subscriptionId}") - public ResponseEntity<?> getSubscription(@PathVariable("subscriptionId") final String subscriptionId) { - logger.info(LOG_REQUEST_RECEIVED, " Getting Subscription: ", subscriptionId); - final Optional<InlineResponse201> optional = subscriptionManager.getSubscription(subscriptionId); - if (optional.isPresent()) { - logger.debug("Return subscription with id {} and body {}", subscriptionId, optional); - return new ResponseEntity<>(optional.get(), HttpStatus.OK); - } - final String errorMessage = - "The requested subscription: " + subscriptionId + " was not found on call getSubscription"; - logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ProblemDetails().detail(errorMessage)); - } - - /** - * DELETE a specific subscription, by subscriptionId. Section Number: 10.4.8.3.5 - * - * @param subscriptionId The ID of the subscription that you wish to delete. - * @return Empty response if successful. Object: Void Response Code: 204 No Content - */ - @DeleteMapping(value = "/subscriptions/{subscriptionId}") - public ResponseEntity<?> deleteSubscription(@PathVariable("subscriptionId") final String subscriptionId) { - if (subscriptionManager.deleteSubscription(subscriptionId)) { - logger.debug("Successfully deleted subscription with id {}", subscriptionId); - return ResponseEntity.noContent().build(); - } - final String errorMessage = - "The requested subscription: " + subscriptionId + " was not found on call deleteSubscription"; - logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ProblemDetails().detail(errorMessage)); - } - - /** - * Method to set the Location in the header with the URI parameter - * - * @param subscriptionUri - * @return header with callbackUri in Location - */ - private HttpHeaders createLocationHeader(final URI subscriptionUri) { - final HttpHeaders headers = new HttpHeaders(); - headers.setLocation(subscriptionUri); - return headers; - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/AuthenticationTypeNotSupportedException.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/AuthenticationTypeNotSupportedException.java deleted file mode 100644 index 6e1330140f..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/AuthenticationTypeNotSupportedException.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * Exception for an unsupported authentication type - * - * @author Andrew Lamb (andrew.a.lamb@est.tech) - */ -@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR) -public class AuthenticationTypeNotSupportedException extends RuntimeException { - - private static final long serialVersionUID = 2939423208362066902L; - - public AuthenticationTypeNotSupportedException(final String message) { - super(message); - } - - @Override - public synchronized Throwable fillInStackTrace() { - return this; - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/ConversionFailedException.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/ConversionFailedException.java deleted file mode 100644 index 9e9cb8e352..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/ConversionFailedException.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * Exception for Conversion Failures - * - * @author Gareth Roper (gareth.roper@est.tech) - * @author Andrew Lamb (andrew.a.lamb@est.tech) - */ -@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR) -public class ConversionFailedException extends RuntimeException { - - private static final long serialVersionUID = 45898561453196895L; - - public ConversionFailedException(final String message) { - super(message); - } - - @Override - public synchronized Throwable fillInStackTrace() { - return this; - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/EtsiCatalogManagerBadRequestException.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/EtsiCatalogManagerBadRequestException.java deleted file mode 100644 index 7d9d5fc17a..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/EtsiCatalogManagerBadRequestException.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * Exception for an ETSI Catalog Manager Bad Request Exception. - * - * @author Gareth Roper (gareth.roper@est.tech - */ -@ResponseStatus(code = HttpStatus.BAD_REQUEST) -public class EtsiCatalogManagerBadRequestException extends RuntimeException { - - private static final long serialVersionUID = 6571317418914258768L; - - public EtsiCatalogManagerBadRequestException(final String message) { - super(message); - } - - @Override - public synchronized Throwable fillInStackTrace() { - return this; - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/EtsiCatalogManagerRequestFailureException.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/EtsiCatalogManagerRequestFailureException.java deleted file mode 100644 index 110826a6d3..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/EtsiCatalogManagerRequestFailureException.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * Exception for an ETSI Catalog Manager Request Failure - * - * @author gareth.roper@est.tech - */ -@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR) -public class EtsiCatalogManagerRequestFailureException extends RuntimeException { - - private static final long serialVersionUID = 66862444537194516L; - - public EtsiCatalogManagerRequestFailureException(final String message) { - super(message); - } - - public EtsiCatalogManagerRequestFailureException(final String message, final Throwable cause) { - super(message, cause); - } - - @Override - public synchronized Throwable fillInStackTrace() { - return this; - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/EtsiSubscriptionNotificationControllerExceptionHandler.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/EtsiSubscriptionNotificationControllerExceptionHandler.java deleted file mode 100644 index 645ef96326..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/EtsiSubscriptionNotificationControllerExceptionHandler.java +++ /dev/null @@ -1,112 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions; - -import static org.slf4j.LoggerFactory.getLogger; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.ProblemDetails; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.EtsiSubscriptionNotificationController; -import org.onap.so.rest.exceptions.HttpResouceNotFoundException; -import org.onap.so.rest.exceptions.InvalidRestRequestException; -import org.onap.so.rest.exceptions.RestProcessingException; -import org.slf4j.Logger; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; - -/** - * Exception Handler for the Etsi Subscription Notification Controller {@link EtsiSubscriptionNotificationController - * EtsiSubscriptionNotificationController} - * - * @author Andrew Lamb (andrew.a.lamb@est.tech) - */ -@ControllerAdvice(assignableTypes = EtsiSubscriptionNotificationController.class) -public class EtsiSubscriptionNotificationControllerExceptionHandler { - - private static final Logger logger = getLogger(EtsiSubscriptionNotificationControllerExceptionHandler.class); - - @ExceptionHandler(InvalidRestRequestException.class) - public ResponseEntity<ProblemDetails> handleInvalidRestRequestException( - final InvalidRestRequestException invalidRestRequestException) { - final String errorMessage = "An error occurred. Sending of notification to VNFM failed with response: " - + HttpStatus.BAD_REQUEST + ".\n" + invalidRestRequestException.getMessage(); - logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ProblemDetails().detail(errorMessage)); - } - - @ExceptionHandler(HttpResouceNotFoundException.class) - public ResponseEntity<ProblemDetails> handleHttpResourceNotFoundException( - final HttpResouceNotFoundException httpResourceNotFoundException) { - final String errorMessage = "An error occurred. Sending of notification to VNFM failed with response: " - + HttpStatus.NOT_FOUND + ".\n" + httpResourceNotFoundException.getMessage(); - logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ProblemDetails().detail(errorMessage)); - } - - @ExceptionHandler(RestProcessingException.class) - public ResponseEntity<ProblemDetails> handleRestProcessingException( - final RestProcessingException restProcessingException) { - final String errorMessage = "An error occurred. Sending of notification to VNFM failed with response: " - + restProcessingException.getStatusCode() + ".\n" + restProcessingException.getMessage(); - logger.error(errorMessage); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ProblemDetails().detail(errorMessage)); - } - - @ExceptionHandler(InternalServerErrorException.class) - public ResponseEntity<ProblemDetails> handleInternalServerErrorException( - final InternalServerErrorException internalServerErrorException) { - logger.error(internalServerErrorException.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(new ProblemDetails().detail(internalServerErrorException.getMessage())); - } - - @ExceptionHandler(AuthenticationTypeNotSupportedException.class) - public ResponseEntity<ProblemDetails> handleAuthenticationTypeNotSupportedException( - final AuthenticationTypeNotSupportedException authenticationTypeNotSupportedException) { - logger.error(authenticationTypeNotSupportedException.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(new ProblemDetails().detail(authenticationTypeNotSupportedException.getMessage())); - } - - @ExceptionHandler(ConversionFailedException.class) - public ResponseEntity<ProblemDetails> handleConversionFailedException( - final ConversionFailedException conversionFailedException) { - logger.error(conversionFailedException.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(new ProblemDetails().detail(conversionFailedException.getMessage())); - } - - @ExceptionHandler(NotificationTypeNotSupportedException.class) - public ResponseEntity<ProblemDetails> handleNotificationTypeNotSupportedException( - final NotificationTypeNotSupportedException notificationTypeNotSupportedException) { - logger.error(notificationTypeNotSupportedException.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(new ProblemDetails().detail(notificationTypeNotSupportedException.getMessage())); - } - - @ExceptionHandler(SubscriptionNotFoundException.class) - public ResponseEntity<ProblemDetails> handleSubscriptionNotFoundException( - final SubscriptionNotFoundException subscriptionNotFoundException) { - logger.error(subscriptionNotFoundException.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body(new ProblemDetails().detail(subscriptionNotFoundException.getMessage())); - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/InternalServerErrorException.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/InternalServerErrorException.java deleted file mode 100644 index 9dd7f1b7b2..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/InternalServerErrorException.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * Exception for an ETSI Catalog Manager Request Failure - * - * @author gareth.roper@est.tech - */ -@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR) -public class InternalServerErrorException extends RuntimeException { - - private static final long serialVersionUID = 66864561537194516L; - - public InternalServerErrorException(final String message) { - super(message); - } - - @Override - public synchronized Throwable fillInStackTrace() { - return this; - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/NotificationTypeNotSupportedException.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/NotificationTypeNotSupportedException.java deleted file mode 100644 index 7716037342..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/NotificationTypeNotSupportedException.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * Exception for an unsupported notification type - * - * @author Andrew Lamb (andrew.a.lamb@est.tech) - */ -@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR) -public class NotificationTypeNotSupportedException extends RuntimeException { - - private static final long serialVersionUID = 2939423208362066902L; - - public NotificationTypeNotSupportedException(final String message) { - super(message); - } - - @Override - public synchronized Throwable fillInStackTrace() { - return this; - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/Sol003PackageManagementControllerExceptionHandler.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/Sol003PackageManagementControllerExceptionHandler.java deleted file mode 100644 index 9f97b4ae02..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/Sol003PackageManagementControllerExceptionHandler.java +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions; - -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.ProblemDetails; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.Sol003PackageManagementController; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; - -/** - * Exception Handler for the Package Management Controller {@link Sol003PackageManagementController Sol003Controller} - * - * @author gareth.roper@est.tech - */ -@ControllerAdvice(assignableTypes = Sol003PackageManagementController.class) - -public class Sol003PackageManagementControllerExceptionHandler { - - @ExceptionHandler(EtsiCatalogManagerRequestFailureException.class) - public ResponseEntity<ProblemDetails> handleEtsiCatalogManagerRequestFailureException( - final EtsiCatalogManagerRequestFailureException etsiCatalogManagerRequestFailureException) { - final ProblemDetails problemDetails = new ProblemDetails(); - problemDetails.setDetail(etsiCatalogManagerRequestFailureException.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(problemDetails); - } - - @ExceptionHandler(EtsiCatalogManagerBadRequestException.class) - public ResponseEntity<ProblemDetails> handleEtsiCatalogManagerBadRequestFailureException( - final EtsiCatalogManagerBadRequestException etsiCatalogManagerBadRequestException) { - final ProblemDetails problemDetails = new ProblemDetails(); - problemDetails.setDetail(etsiCatalogManagerBadRequestException.getMessage()); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(problemDetails); - } - - @ExceptionHandler(SubscriptionNotFoundException.class) - public ResponseEntity<ProblemDetails> handleSubscriptionNotFoundException( - final SubscriptionNotFoundException subscriptionNotFoundException) { - final ProblemDetails problemDetails = new ProblemDetails(); - problemDetails.setDetail(subscriptionNotFoundException.getMessage()); - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetails); - } - - @ExceptionHandler(ConversionFailedException.class) - public ResponseEntity<ProblemDetails> handleConversionFailedException( - final ConversionFailedException conversionFailedException) { - final ProblemDetails problemDetails = new ProblemDetails(); - problemDetails.setDetail(conversionFailedException.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(problemDetails); - } - - @ExceptionHandler(VnfPkgConflictException.class) - public ResponseEntity<ProblemDetails> handleVnfPkgConflictException( - final VnfPkgConflictException vnfPkgConflictException) { - final ProblemDetails problemDetails = new ProblemDetails(); - problemDetails.setDetail(vnfPkgConflictException.getMessage()); - return ResponseEntity.status(HttpStatus.CONFLICT).body(problemDetails); - } - - @ExceptionHandler(VnfPkgNotFoundException.class) - public ResponseEntity<ProblemDetails> handleVnfPkgNotFoundException( - final VnfPkgNotFoundException vnfPkgNotFoundException) { - final ProblemDetails problemDetails = new ProblemDetails(); - problemDetails.setDetail(vnfPkgNotFoundException.getMessage()); - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetails); - } - - @ExceptionHandler(VnfPkgBadRequestException.class) - public ResponseEntity<ProblemDetails> handleVnfPkgBadRequestException( - final VnfPkgBadRequestException vnfPkgBadRequestException) { - final ProblemDetails problemDetails = new ProblemDetails(); - problemDetails.setDetail(vnfPkgBadRequestException.getMessage()); - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(problemDetails); - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/SubscriptionNotFoundException.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/SubscriptionNotFoundException.java deleted file mode 100644 index af409e7399..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/SubscriptionNotFoundException.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * Exception for an ETSI Catalog Manager Request Failure - * - * @author gareth.roper@est.tech - */ -@ResponseStatus(code = HttpStatus.NOT_FOUND) -public class SubscriptionNotFoundException extends RuntimeException { - - private static final long serialVersionUID = 85268561453194516L; - - public SubscriptionNotFoundException(final String message) { - super(message); - } - - @Override - public synchronized Throwable fillInStackTrace() { - return this; - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/VnfPkgBadRequestException.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/VnfPkgBadRequestException.java deleted file mode 100644 index 5c318da89f..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/VnfPkgBadRequestException.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * Exception for a Vnfpkg Bad Request failure, due to state of resource. - * - * @author andrew.a.lamb@est.tech - */ -@ResponseStatus(code = HttpStatus.BAD_REQUEST) -public class VnfPkgBadRequestException extends RuntimeException { - - private static final long serialVersionUID = 3301317418914258411L; - - public VnfPkgBadRequestException(final String message) { - super(message); - } - - @Override - public synchronized Throwable fillInStackTrace() { - return this; - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/VnfPkgConflictException.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/VnfPkgConflictException.java deleted file mode 100644 index 7cb7a0c860..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/VnfPkgConflictException.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * Exception for a VnfPkg Conflict failures, due to state of resource. - * - * @author gareth.roper@est.tech - */ -@ResponseStatus(code = HttpStatus.CONFLICT) -public class VnfPkgConflictException extends RuntimeException { - - private static final long serialVersionUID = 26862444537198441L; - - public VnfPkgConflictException(final String message) { - super(message); - } - - @Override - public synchronized Throwable fillInStackTrace() { - return this; - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/VnfPkgNotFoundException.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/VnfPkgNotFoundException.java deleted file mode 100644 index 5ed4847173..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/VnfPkgNotFoundException.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions; - -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; - -/** - * Exception for VnfPkg Not Found Failures - * - * @author gareth.roper@est.tech - */ -@ResponseStatus(code = HttpStatus.NOT_FOUND) -public class VnfPkgNotFoundException extends RuntimeException { - - private static final long serialVersionUID = 26862444537198441L; - - public VnfPkgNotFoundException(final String message) { - super(message); - } - - @Override - public synchronized Throwable fillInStackTrace() { - return this; - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/AbstractNotificationServiceProvider.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/AbstractNotificationServiceProvider.java deleted file mode 100644 index b6ba1ede95..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/AbstractNotificationServiceProvider.java +++ /dev/null @@ -1,59 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.subscriptionmgmt; - -import static org.onap.so.adapters.etsisol003adapter.pkgm.extclients.vnfm.VnfmHttpServiceProviderConfiguration.VNFM_ADAPTER_HTTP_SERVICE_PROVIDER_BEAN; -import java.nio.charset.StandardCharsets; -import org.apache.commons.codec.binary.Base64; -import org.onap.so.configuration.rest.BasicHttpHeadersProvider; -import org.onap.so.rest.service.HttpRestServiceProvider; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; - -/** - * A base class that can be extended by classes for providing notification services. Provides common methods that will - * be useful to those classes. - * - * @author Waqas Ikram (waqas.ikram@est.tech) - * @author Andrew Lamb (andrew.a.lamb@est.tech) - */ -public abstract class AbstractNotificationServiceProvider { - - @Autowired - @Qualifier(VNFM_ADAPTER_HTTP_SERVICE_PROVIDER_BEAN) - private HttpRestServiceProvider httpRestServiceProvider; - - protected HttpRestServiceProvider getHttpRestServiceProvider() { - return httpRestServiceProvider; - } - - protected BasicHttpHeadersProvider getBasicHttpHeadersProviderWithBasicAuth(final String username, - final String password) { - final byte[] encodedAuth = getBasicAuth(username, password); - final String authHeader = "Basic " + new String(encodedAuth); - return new BasicHttpHeadersProvider(authHeader); - } - - protected byte[] getBasicAuth(final String username, final String password) { - final String auth = username + ":" + password; - return Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)); - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/BasicAuthNotificationServiceProvider.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/BasicAuthNotificationServiceProvider.java deleted file mode 100644 index ffe8529c93..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/BasicAuthNotificationServiceProvider.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.subscriptionmgmt; - -import static org.slf4j.LoggerFactory.getLogger; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthentication; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthentication.AuthTypeEnum; -import org.onap.so.configuration.rest.HttpHeadersProvider; -import org.onap.so.rest.service.HttpRestServiceProvider; -import org.slf4j.Logger; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; - -/** - * Implementation of a NotificationServiceProvider which supports Basic Authentication - * - * @author Waqas Ikram (waqas.ikram@est.tech) - * @author Andrew Lamb (andrew.a.lamb@est.tech) - */ -@Service -public class BasicAuthNotificationServiceProvider extends AbstractNotificationServiceProvider - implements NotificationServiceProvider { - - private static final Logger logger = getLogger(BasicAuthNotificationServiceProvider.class); - - @Override - public boolean send(final Object notification, final SubscriptionsAuthentication subscriptionsAuthentication, - final String callbackUri) { - logger.info("Sending notification to uri: {}", callbackUri); - final HttpHeadersProvider httpHeadersProvider = - getBasicHttpHeadersProviderWithBasicAuth(subscriptionsAuthentication.getParamsBasic().getUserName(), - subscriptionsAuthentication.getParamsBasic().getPassword()); - final HttpRestServiceProvider httpRestServiceProvider = getHttpRestServiceProvider(); - - final ResponseEntity<Void> responseEntity = httpRestServiceProvider.postHttpRequest(notification, callbackUri, - httpHeadersProvider.getHttpHeaders(), Void.class); - if (responseEntity.getStatusCode().is2xxSuccessful()) { - logger.info("Notification sent successfully."); - return true; - } - - logger.error("Failed to send notification."); - return false; - } - - @Override - public AuthTypeEnum getAuthType() { - return AuthTypeEnum.BASIC; - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/NotificationManager.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/NotificationManager.java deleted file mode 100644 index 82b1a7d4c3..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/NotificationManager.java +++ /dev/null @@ -1,137 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.subscriptionmgmt; - -import static org.slf4j.LoggerFactory.getLogger; -import java.util.List; -import java.util.Optional; -import org.onap.so.adapters.etsisol003adapter.etsicatalog.notification.model.PkgChangeNotification; -import org.onap.so.adapters.etsisol003adapter.etsicatalog.notification.model.PkgOnboardingNotification; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.vnfm.notification.model.VnfPackageChangeNotification; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.vnfm.notification.model.VnfPackageOnboardingNotification; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.PkgmSubscriptionRequest; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthentication; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthentication.AuthTypeEnum; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.AuthenticationTypeNotSupportedException; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.ConversionFailedException; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.NotificationTypeNotSupportedException; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.SubscriptionNotFoundException; -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.convert.ConversionService; -import org.springframework.stereotype.Service; - -/** - * Manages package management subscription notifications to the VNFMs - * - * @author Andrew Lamb (andrew.a.lamb@est.tech) - * - */ -@Service -public class NotificationManager { - - private static final Logger logger = getLogger(NotificationManager.class); - private final ConversionService conversionService; - private final SubscriptionManager subscriptionManager; - private final NotificationServiceProviderFactory notificationServiceProviderFactory; - - @Autowired - public NotificationManager(final SubscriptionManager subscriptionManager, final ConversionService conversionService, - final NotificationServiceProviderFactory notificationServiceProviderFactory) { - this.subscriptionManager = subscriptionManager; - this.conversionService = conversionService; - this.notificationServiceProviderFactory = notificationServiceProviderFactory; - } - - /** - * Process a subscription notification. Checks for a subscription request stored in the adapter and if there is, it - * sends the notification to the subscribed vnfm. - * - * @param notification the notification to send to the vnfm - * @param subscriptionId the id of the subscription request - * @return true if the notification is successfully sent - */ - public boolean processSubscriptionNotification(final Object notification, final String subscriptionId) { - final Optional<PkgmSubscriptionRequest> optionalSubscription = - subscriptionManager.getSubscriptionRequest(subscriptionId); - if (optionalSubscription.isPresent()) { - final PkgmSubscriptionRequest subscriptionRequest = optionalSubscription.get(); - return notifyVnfm(subscriptionRequest, notification); - } - final String errorMessage = "No subscription found with subscriptionId " + subscriptionId - + ". Unable to forward notification to subscriber."; - logger.error(errorMessage); - throw new SubscriptionNotFoundException(errorMessage); - } - - private boolean notifyVnfm(final PkgmSubscriptionRequest subscriptionRequest, final Object notification) { - if (!(notification instanceof PkgOnboardingNotification) && !(notification instanceof PkgChangeNotification)) { - final String errorMessage = - "An error occurred. Notification type not supported for: " + notification.getClass(); - logger.error(errorMessage); - throw new NotificationTypeNotSupportedException(errorMessage); - } - - final SubscriptionsAuthentication subscriptionsAuthentication = subscriptionRequest.getAuthentication(); - final AuthTypeEnum authType = getAuthType(subscriptionsAuthentication.getAuthType()); - final NotificationServiceProvider sender = notificationServiceProviderFactory.getNotificationSender(authType); - - final Object vnfmNotificationObject = convertEtsiCatalogNotification(notification); - - if (sender.send(vnfmNotificationObject, subscriptionsAuthentication, subscriptionRequest.getCallbackUri())) { - logger.info("Notification delivered successfully {}", notification); - return true; - } - - logger.error("Failed to deliver notification."); - return false; - } - - private SubscriptionsAuthentication.AuthTypeEnum getAuthType(final List<AuthTypeEnum> authTypes) { - if (authTypes.contains(SubscriptionsAuthentication.AuthTypeEnum.TLS_CERT)) { - return SubscriptionsAuthentication.AuthTypeEnum.TLS_CERT; - } - if (authTypes.contains(SubscriptionsAuthentication.AuthTypeEnum.OAUTH2_CLIENT_CREDENTIALS)) { - return SubscriptionsAuthentication.AuthTypeEnum.OAUTH2_CLIENT_CREDENTIALS; - } - if (authTypes.contains(SubscriptionsAuthentication.AuthTypeEnum.BASIC)) { - return SubscriptionsAuthentication.AuthTypeEnum.BASIC; - } - final String errorMessage = - "An error occurred. No supported authentication type provided in subscription request."; - logger.error(errorMessage); - throw new AuthenticationTypeNotSupportedException(errorMessage); - } - - private Object convertEtsiCatalogNotification(final Object etsiCatalogNotification) { - logger.info("Converting notification:\n {}", etsiCatalogNotification); - if (conversionService.canConvert(etsiCatalogNotification.getClass(), VnfPackageOnboardingNotification.class)) { - return conversionService.convert(etsiCatalogNotification, VnfPackageOnboardingNotification.class); - } else if (conversionService.canConvert(etsiCatalogNotification.getClass(), - VnfPackageChangeNotification.class)) { - return conversionService.convert(etsiCatalogNotification, VnfPackageChangeNotification.class); - } - final String errorMessage = "An error occurred. Unable to convert provided notification object."; - logger.error(errorMessage + "\n" + etsiCatalogNotification); - throw new ConversionFailedException(errorMessage); - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/NotificationServiceProvider.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/NotificationServiceProvider.java deleted file mode 100644 index 2fc7e19eb6..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/NotificationServiceProvider.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.subscriptionmgmt; - -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthentication; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthentication.AuthTypeEnum; - -/** - * Interface which lays out requirements for a Notification Service Provider - * - * @author Waqas Ikram (waqas.ikram@est.tech) - * @author Andrew Lamb (andrew.a.lamb@est.tech) - */ -public interface NotificationServiceProvider { - - /** - * Method to send a notification to a uri, given the subscription authentication - * - * @param notification The notification to send - * @param subscriptionsAuthentication Object containing the authentication details - * @param callbackUri The uri to send the notification to - * @return true if notification is delivered successfully, otherwise false - */ - boolean send(final Object notification, final SubscriptionsAuthentication subscriptionsAuthentication, - final String callbackUri); - - /** - * Method to get the supported authorization type of the service provider - * - * @return the supported AuthTypeEnum - */ - AuthTypeEnum getAuthType(); - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/NotificationServiceProviderFactory.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/NotificationServiceProviderFactory.java deleted file mode 100644 index 2b8e818c9c..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/NotificationServiceProviderFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.subscriptionmgmt; - -import static org.slf4j.LoggerFactory.getLogger; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthentication.AuthTypeEnum; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.AuthenticationTypeNotSupportedException; -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * Factory to provide a notification services - * - * @author Waqas Ikram (waqas.ikram@est.tech) - * @author Andrew Lamb (andrew.a.lamb@est.tech) - */ -@Component -public class NotificationServiceProviderFactory { - - private static final Logger logger = getLogger(NotificationServiceProviderFactory.class); - private static final Map<AuthTypeEnum, NotificationServiceProvider> CACHE = new HashMap<>(); - - @Autowired - public NotificationServiceProviderFactory(final List<NotificationServiceProvider> services) { - for (final NotificationServiceProvider notificationServiceProvider : services) { - logger.debug("Adding {} of type {} to cache", notificationServiceProvider.getClass().getCanonicalName(), - notificationServiceProvider.getAuthType()); - CACHE.put(notificationServiceProvider.getAuthType(), notificationServiceProvider); - } - } - - /** - * Get a notification service for a given authorization type - * - * @param type the type of authentication required - * @return the notification service - */ - public NotificationServiceProvider getNotificationSender(final AuthTypeEnum type) { - final NotificationServiceProvider service = CACHE.get(type); - if (service == null) { - throw new AuthenticationTypeNotSupportedException("Unknown type: " + type); - } - return service; - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/OAuthNotificationServiceProvider.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/OAuthNotificationServiceProvider.java deleted file mode 100644 index 81dc743a22..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/OAuthNotificationServiceProvider.java +++ /dev/null @@ -1,104 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.subscriptionmgmt; - -import static org.slf4j.LoggerFactory.getLogger; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthentication; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthentication.AuthTypeEnum; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.InternalServerErrorException; -import org.onap.so.configuration.rest.BasicHttpHeadersProvider; -import org.onap.so.configuration.rest.HttpHeadersProvider; -import org.onap.so.rest.service.HttpRestServiceProvider; -import org.slf4j.Logger; -import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Service; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * @author Andrew Lamb (andrew.a.lamb@est.tech) - * - */ -@Service -public class OAuthNotificationServiceProvider extends AbstractNotificationServiceProvider - implements NotificationServiceProvider { - - private static final Logger logger = getLogger(OAuthNotificationServiceProvider.class); - - @Override - public boolean send(final Object notification, final SubscriptionsAuthentication subscriptionsAuthentication, - final String callbackUri) { - logger.info("Sending notification to uri: {}", callbackUri); - logger.info("Object: {}", notification); - final String token = getAccessToken(subscriptionsAuthentication); - - if (token == null) { - logger.error("Failed to get access token"); - return false; - } - - final HttpHeadersProvider httpHeadersProvider = getHttpHeadersProvider(token); - final HttpRestServiceProvider httpRestServiceProvider = getHttpRestServiceProvider(); - final ResponseEntity<Void> responseEntity = httpRestServiceProvider.postHttpRequest(notification, callbackUri, - httpHeadersProvider.getHttpHeaders(), Void.class); - if (responseEntity.getStatusCode().is2xxSuccessful()) { - logger.info("Notification sent successfully."); - return true; - } - - logger.error("Failed to send notification."); - return false; - } - - @Override - public AuthTypeEnum getAuthType() { - return AuthTypeEnum.OAUTH2_CLIENT_CREDENTIALS; - } - - private BasicHttpHeadersProvider getHttpHeadersProvider(final String token) { - final String authHeader = "Bearer " + token; - return new BasicHttpHeadersProvider(authHeader); - } - - private String getAccessToken(final SubscriptionsAuthentication subscriptionsAuthentication) { - logger.info("Requesting Access Token."); - - final String tokenEndpoint = subscriptionsAuthentication.getParamsOauth2ClientCredentials().getTokenEndpoint(); - - final HttpHeadersProvider httpHeadersProvider = getBasicHttpHeadersProviderWithBasicAuth( - subscriptionsAuthentication.getParamsOauth2ClientCredentials().getClientId(), - subscriptionsAuthentication.getParamsOauth2ClientCredentials().getClientPassword()); - - final HttpRestServiceProvider httpRestServiceProvider = getHttpRestServiceProvider(); - final ResponseEntity<OAuthTokenResponse> responseEntity = httpRestServiceProvider.postHttpRequest(null, - tokenEndpoint, httpHeadersProvider.getHttpHeaders(), OAuthTokenResponse.class); - if (responseEntity.getStatusCode().is2xxSuccessful()) { - if (responseEntity.getBody() != null) { - logger.info("Returning Access Token."); - return responseEntity.getBody().getAccessToken(); - } - } - - final String errorMessage = "An error occurred. Unable to retrieve OAuth Token from VNFM for notification."; - logger.error(errorMessage); - throw new InternalServerErrorException(errorMessage); - } - - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/OAuthTokenResponse.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/OAuthTokenResponse.java deleted file mode 100644 index 3e6f7bde2b..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/OAuthTokenResponse.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.subscriptionmgmt; - -import java.io.Serializable; -import javax.xml.bind.annotation.XmlElement; -import com.google.gson.annotations.SerializedName; - -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * @author Andrew Lamb (andrew.a.lamb@est.tech) - */ -public class OAuthTokenResponse implements Serializable { - - private static final long serialVersionUID = -6455742984985959926L; - - @XmlElement(name = "access_token") - @SerializedName("access_token") - private String accessToken; - - /** - * Get the Accees Token - * - * @return the Access Token - */ - public String getAccessToken() { - return accessToken; - } - - /** - * Set the Access Token - * - * @param accessToken - */ - public void setAccessToken(final String accessToken) { - this.accessToken = accessToken; - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/SubscriptionManager.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/SubscriptionManager.java deleted file mode 100644 index edae41525e..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/SubscriptionManager.java +++ /dev/null @@ -1,209 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.so.adapters.etsisol003adapter.pkgm.subscriptionmgmt; - -import static org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.SubscriptionAuthentication.AuthTypeEnum.BASIC; -import static org.slf4j.LoggerFactory.getLogger; -import java.net.URI; -import java.security.GeneralSecurityException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.onap.so.adapters.etsi.sol003.adapter.common.VnfmAdapterUrlProvider; -import org.onap.so.adapters.etsisol003adapter.pkgm.cache.PkgmCacheServiceProvider; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.EtsiCatalogServiceProvider; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.BasicAuth; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdmSubscription; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscription; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.InlineResponse201; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.PkgmSubscriptionRequest; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsLinks; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.VnfPackagesLinksSelf; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.ConversionFailedException; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.InternalServerErrorException; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.SubscriptionNotFoundException; -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.convert.ConversionService; -import org.springframework.stereotype.Service; - -/** - * Manages package management subscriptions from the VNFMs - * - * @author Ronan Kenny (ronan.kenny@est.tech) - * @author Gareth Roper (gareth.roper@est.tech) - */ -@Service -public class SubscriptionManager { - - private static final Logger logger = getLogger(SubscriptionManager.class); - private final PkgmCacheServiceProvider packageManagementCacheServiceProvider; - private final ConversionService conversionService; - private final EtsiCatalogServiceProvider etsiCatalogServiceProvider; - private final VnfmAdapterUrlProvider vnfmAdapterUrlProvider; - - @Autowired - public SubscriptionManager(final PkgmCacheServiceProvider packageManagementCacheServiceProvider, - final ConversionService conversionService, final EtsiCatalogServiceProvider etsiCatalogServiceProvider, - final VnfmAdapterUrlProvider vnfmAdapterUrlProvider) { - this.packageManagementCacheServiceProvider = packageManagementCacheServiceProvider; - this.conversionService = conversionService; - this.etsiCatalogServiceProvider = etsiCatalogServiceProvider; - this.vnfmAdapterUrlProvider = vnfmAdapterUrlProvider; - } - - public Optional<InlineResponse201> createSubscription(final PkgmSubscriptionRequest pkgmSubscriptionRequest) - throws GeneralSecurityException { - - final org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest = - buildEtsiCatalogManagerPkgmSubscriptionRequest(pkgmSubscriptionRequest); - - final Optional<PkgmSubscription> optionalEtsiCatalogManagerSubscription = - etsiCatalogServiceProvider.postSubscription(etsiCatalogManagerSubscriptionRequest); - - if (optionalEtsiCatalogManagerSubscription.isPresent()) { - final PkgmSubscription etsiCatalogManagerSubscription = optionalEtsiCatalogManagerSubscription.get(); - logger.debug("postPkgmSubscriptionRequest Response SubscriptionId: {}", - Objects.requireNonNull(etsiCatalogManagerSubscription.getId())); - final String subscriptionId = etsiCatalogManagerSubscription.getId(); - - packageManagementCacheServiceProvider.addSubscription(subscriptionId, pkgmSubscriptionRequest); - - final InlineResponse201 response = new InlineResponse201(); - response.setId(subscriptionId); - response.setFilter(pkgmSubscriptionRequest.getFilter()); - response.setCallbackUri(vnfmAdapterUrlProvider.getSubscriptionUriString(subscriptionId)); - response.setLinks(new SubscriptionsLinks() - .self(new VnfPackagesLinksSelf().href(getSubscriptionUri(subscriptionId).toString()))); - - return Optional.of(response); - } - throw new InternalServerErrorException( - "Received empty response from POST to ETSI Catalog Manager Subscription Endpoint."); - } - - public Optional<String> getSubscriptionId(final PkgmSubscriptionRequest pkgmSubscriptionRequest) { - return packageManagementCacheServiceProvider.getSubscriptionId(pkgmSubscriptionRequest); - } - - public Optional<InlineResponse201> getSubscription(final String subscriptionId) { - - logger.debug("Checking if subscrition with id: {} exists in ETSI Catalog Manager", subscriptionId); - final Optional<NsdmSubscription> etsiCatalogSubscriptionOption = - etsiCatalogServiceProvider.getSubscription(subscriptionId); - - if (!etsiCatalogSubscriptionOption.isPresent()) { - logger.debug("Unable to find subscription in ETSI Catalog Manager using id: {}", subscriptionId); - if (packageManagementCacheServiceProvider.getSubscription(subscriptionId).isPresent()) { - logger.debug("will remove subcription with id: {} from local cache", subscriptionId); - packageManagementCacheServiceProvider.deleteSubscription(subscriptionId); - } - } - - final Optional<PkgmSubscriptionRequest> optional = - packageManagementCacheServiceProvider.getSubscription(subscriptionId); - if (optional.isPresent()) { - final PkgmSubscriptionRequest subscription = optional.get(); - return Optional.of(getInlineResponse2002(subscriptionId, subscription)); - } - return Optional.empty(); - } - - public List<InlineResponse201> getSubscriptions() { - final Map<String, PkgmSubscriptionRequest> subscriptions = - packageManagementCacheServiceProvider.getSubscriptions(); - final List<InlineResponse201> response = new ArrayList<>(); - subscriptions.forEach((key, value) -> { - final Optional<InlineResponse201> optional = getSubscription(key); - if (optional.isPresent()) { - response.add(optional.get()); - } - }); - return response; - } - - public boolean deleteSubscription(final String subscriptionId) { - if (packageManagementCacheServiceProvider.getSubscription(subscriptionId).isPresent()) { - try { - if (etsiCatalogServiceProvider.deleteSubscription(subscriptionId)) { - return packageManagementCacheServiceProvider.deleteSubscription(subscriptionId); - } - } catch (final SubscriptionNotFoundException subscriptionNotFoundException) { - logger.error( - "Unable to find subscription in ETSI Catalog Manager using id: {} will delete it from local cache", - subscriptionId); - return packageManagementCacheServiceProvider.deleteSubscription(subscriptionId); - } - } - return false; - } - - public URI getSubscriptionUri(final String subscriptionId) { - return vnfmAdapterUrlProvider.getSubscriptionUri(subscriptionId); - } - - public Optional<PkgmSubscriptionRequest> getSubscriptionRequest(final String subscriptionId) { - return packageManagementCacheServiceProvider.getSubscription(subscriptionId); - } - - private InlineResponse201 getInlineResponse2002(final String id, final PkgmSubscriptionRequest subscription) { - return new InlineResponse201().id(id).filter(subscription.getFilter()) - .callbackUri(subscription.getCallbackUri()); - } - - private org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest buildEtsiCatalogManagerPkgmSubscriptionRequest( - final PkgmSubscriptionRequest pkgmSubscriptionRequest) throws GeneralSecurityException { - - final org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest; - try { - etsiCatalogManagerSubscriptionRequest = conversionService.convert(pkgmSubscriptionRequest, - org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest.class); - } catch (final org.springframework.core.convert.ConversionException conversionException) { - logger.error(conversionException.getMessage()); - throw new ConversionFailedException( - "Could not convert Sol003 PkgmSubscriptionRequest to ETSI-Catalog Manager PkgmSubscriptionRequest"); - } catch (final Exception exception) { - logger.error(exception.getMessage()); - throw new InternalServerErrorException( - "Could not convert Sol003 PkgmSubscriptionRequest to ETSI-Catalog Manager PkgmSubscriptionRequest"); - } - - if (etsiCatalogManagerSubscriptionRequest != null) { - etsiCatalogManagerSubscriptionRequest - .setCallbackUri(vnfmAdapterUrlProvider.getEtsiSubscriptionNotificationBaseUrl()); - - final ImmutablePair<String, String> immutablePair = vnfmAdapterUrlProvider.getDecryptAuth(); - if (!immutablePair.equals(ImmutablePair.nullPair())) { - etsiCatalogManagerSubscriptionRequest.setAuthentication( - new org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.SubscriptionAuthentication() - .addAuthTypeItem(BASIC).paramsBasic(new BasicAuth().userName(immutablePair.getLeft()) - .password(immutablePair.getRight()))); - } - return etsiCatalogManagerSubscriptionRequest; - } - throw new ConversionFailedException( - "Failed to convert Sol003 PkgmSubscriptionRequest to ETSI-Catalog Manager PkgmSubscriptionRequest"); - } - -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/TlsNotificationServiceProvider.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/TlsNotificationServiceProvider.java deleted file mode 100644 index 69ff5da3ec..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/subscriptionmgmt/TlsNotificationServiceProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.adapters.etsisol003adapter.pkgm.subscriptionmgmt; - -import static org.slf4j.LoggerFactory.getLogger; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthentication; -import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthentication.AuthTypeEnum; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.AuthenticationTypeNotSupportedException; -import org.slf4j.Logger; -import org.springframework.stereotype.Service; - -/** - * - * @author Waqas Ikram (waqas.ikram@est.tech) - * @author Andrew Lamb (andrew.a.lamb@est.tech) - */ -@Service -public class TlsNotificationServiceProvider extends AbstractNotificationServiceProvider - implements NotificationServiceProvider { - - private static final Logger logger = getLogger(TlsNotificationServiceProvider.class); - - @Override - public boolean send(final Object notification, final SubscriptionsAuthentication subscriptionsAuthentication, - final String callbackUri) { - final String errorMessage = "An error occurred. Authentication type " - + subscriptionsAuthentication.getAuthType().toString() + " not currently supported."; - logger.error(errorMessage); - throw new AuthenticationTypeNotSupportedException(errorMessage); - } - - - @Override - public AuthTypeEnum getAuthType() { - return AuthTypeEnum.TLS_CERT; - } - - - -} |