2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.etsisol003adapter.pkgm.converters.sol003.etsicatalog;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26 import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.Version;
27 import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfProducts;
28 import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfProductsProviders;
29 import org.onap.so.adapters.etsisol003adapter.pkgm.model.PkgmSubscriptionRequest;
30 import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilter1;
31 import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilter1.NotificationTypesEnum;
32 import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilter1.OperationalStateEnum;
33 import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilter1.UsageStateEnum;
34 import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilterVersions;
35 import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilterVnfProducts;
36 import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilterVnfProductsFromProviders;
37 import org.springframework.core.convert.converter.Converter;
38 import org.springframework.stereotype.Service;
41 * Converter to convert from an Etsi Catalog Manager {@link PkgmSubscriptionRequest} Object to its equivalent ETSI
42 * Catalog Manager Object
44 * @author Ronan Kenny (ronan.kenny@est.tech)
45 * @author Gareth Roper (gareth.roper@est.tech)
48 public class PkgmSubscriptionRequestConverter implements
49 Converter<PkgmSubscriptionRequest, org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest> {
52 public org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest convert(
53 final PkgmSubscriptionRequest pkgmSubscriptionRequest) {
54 final org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest =
55 new org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest();
57 etsiCatalogManagerSubscriptionRequest
58 .setFilter(getPkgmNotificationsFilter(pkgmSubscriptionRequest.getFilter()));
60 return etsiCatalogManagerSubscriptionRequest;
64 private org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter getPkgmNotificationsFilter(
65 final SubscriptionsFilter1 sol003SubscriptionsFilter) {
66 final org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter etsiCatalogManagerFilters =
67 new org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter();
69 if (sol003SubscriptionsFilter.getNotificationTypes() != null) {
70 etsiCatalogManagerFilters.setNotificationTypes(
71 getPkgmNotificationsFilterNotificationTypes(sol003SubscriptionsFilter.getNotificationTypes()));
74 etsiCatalogManagerFilters.setVnfProductsFromProviders(
75 getVnfProductsProviders(sol003SubscriptionsFilter.getVnfProductsFromProviders()));
77 etsiCatalogManagerFilters.setVnfdId(getVnfdIds(sol003SubscriptionsFilter.getVnfdId()));
79 etsiCatalogManagerFilters.setVnfPkgId(getVnfPkgIds(sol003SubscriptionsFilter.getVnfPkgId()));
81 etsiCatalogManagerFilters
82 .setOperationalState(getOperationalState(sol003SubscriptionsFilter.getOperationalState()));
84 etsiCatalogManagerFilters.setUsageState(getUsageState(sol003SubscriptionsFilter.getUsageState()));
86 return etsiCatalogManagerFilters;
90 private List<org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.UsageStateEnum> getUsageState(
91 final List<UsageStateEnum> usageStates) {
92 if (usageStates != null) {
93 final List<org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.UsageStateEnum> etsiCatalogUsageStates =
95 usageStates.stream().forEach(state -> {
96 etsiCatalogUsageStates.add(
97 org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.UsageStateEnum
98 .fromValue(state.getValue()));
100 return etsiCatalogUsageStates;
102 return Collections.emptyList();
106 private List<org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.OperationalStateEnum> getOperationalState(
107 final List<OperationalStateEnum> operationalStates) {
108 if (operationalStates != null) {
109 final List<org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.OperationalStateEnum> etsiCatalogOperationalStates =
111 operationalStates.forEach(state -> {
112 etsiCatalogOperationalStates.add(
113 org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.OperationalStateEnum
114 .fromValue(state.getValue()));
117 return etsiCatalogOperationalStates;
119 return Collections.emptyList();
122 private List<String> getVnfPkgIds(final List<String> vnfPkgId) {
123 if (vnfPkgId != null) {
124 final List<String> etsiCatalogManagerVnfPkgId = new ArrayList<>();
125 vnfPkgId.forEach(type -> {
126 etsiCatalogManagerVnfPkgId.add(type);
128 return etsiCatalogManagerVnfPkgId;
130 return Collections.emptyList();
133 private List<String> getVnfdIds(final List<String> vnfdId) {
134 if (vnfdId != null) {
135 final List<String> etsiCatalogManagerVnfdId = new ArrayList<>();
136 vnfdId.forEach(type -> {
137 etsiCatalogManagerVnfdId.add(type);
139 return etsiCatalogManagerVnfdId;
141 return Collections.emptyList();
144 private List<VnfProductsProviders> getVnfProductsProviders(
145 final List<SubscriptionsFilterVnfProductsFromProviders> filterProductsFromProvider) {
147 if (filterProductsFromProvider != null && !filterProductsFromProvider.isEmpty()) {
148 final List<VnfProductsProviders> etsiCatalogManagerVnfProductsProviders = new ArrayList<>();
149 filterProductsFromProvider.forEach(vnfProduct -> {
150 etsiCatalogManagerVnfProductsProviders
151 .add(new VnfProductsProviders().vnfProvider(vnfProduct.getVnfProvider())
152 .vnfProducts(getVnfProducts(vnfProduct.getVnfProducts())));
154 return etsiCatalogManagerVnfProductsProviders;
156 return Collections.emptyList();
159 private List<VnfProducts> getVnfProducts(final List<SubscriptionsFilterVnfProducts> sol003VnfProducts) {
160 if (sol003VnfProducts != null) {
161 final List<VnfProducts> etsiCatalogManagerVnfProductsList = new ArrayList<>();
162 sol003VnfProducts.forEach(vnfProduct -> {
163 etsiCatalogManagerVnfProductsList.add(new VnfProducts().vnfProductName(vnfProduct.getVnfProductName())
164 .versions(getVersion(vnfProduct.getVersions())));
166 return etsiCatalogManagerVnfProductsList;
168 return Collections.emptyList();
171 private List<Version> getVersion(final List<SubscriptionsFilterVersions> sol003FilterVersions) {
172 if (sol003FilterVersions != null && !sol003FilterVersions.isEmpty()) {
173 final List<Version> etsiCatalogVersionList = new ArrayList<>();
174 sol003FilterVersions.forEach(vnfFilterVersion -> {
175 etsiCatalogVersionList.add(new Version().vnfSoftwareVersion(vnfFilterVersion.getVnfSoftwareVersion())
176 .vnfdVersions(vnfFilterVersion.getVnfdVersions()));
178 return etsiCatalogVersionList;
180 return Collections.emptyList();
183 private List<org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.NotificationTypesEnum> getPkgmNotificationsFilterNotificationTypes(
184 final List<NotificationTypesEnum> notificationTypes) {
186 if (notificationTypes != null && !notificationTypes.isEmpty()) {
187 final List<org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.NotificationTypesEnum> etsiCatalogNotificationTypes =
189 notificationTypes.forEach(type -> etsiCatalogNotificationTypes.add(
190 org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter.NotificationTypesEnum
191 .fromValue(type.getValue())));
192 return etsiCatalogNotificationTypes;
194 return Collections.emptyList();