c6d51c99aa023d4732a017a22f2f3f5f9eca86fe
[so.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.vnfmadapter.converters.sol003.etsicatalog;
22
23 import static org.slf4j.LoggerFactory.getLogger;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.Optional;
29 import java.util.UUID;
30 import javax.swing.text.html.Option;
31 import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.Version;
32 import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfProducts;
33 import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfProductsProviders;
34 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest;
35 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter;
36 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter.NotificationTypesEnum;
37 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter.OperationalStateEnum;
38 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilterVersions;
39 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilterVnfProducts;
40 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilterVnfProductsFromProviders;
41 import org.slf4j.Logger;
42 import org.springframework.core.convert.converter.Converter;
43 import org.springframework.stereotype.Service;
44
45 /**
46  * Converter to convert from an Etsi Catalog Manager {@link PkgmSubscriptionRequest} Object to its equivalent ETSI
47  * Catalog Manager Object
48  *
49  * @author Ronan Kenny (ronan.kenny@est.tech)
50  * @author Gareth Roper (gareth.roper@est.tech)
51  *
52  */
53 @Service
54 public class PkgmSubscriptionRequestConverter implements
55         Converter<PkgmSubscriptionRequest, org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest> {
56
57     private static final Logger logger = getLogger(PkgmSubscriptionRequestConverter.class);
58
59     @Override
60     public org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest convert(
61             PkgmSubscriptionRequest pkgmSubscriptionRequest) {
62         final org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest =
63                 new org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest();
64
65         etsiCatalogManagerSubscriptionRequest
66                 .setFilters(getPkgmNotificationsFilter(pkgmSubscriptionRequest.getFilter()));
67
68         return etsiCatalogManagerSubscriptionRequest;
69     }
70
71
72     private org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter getPkgmNotificationsFilter(
73             final SubscriptionsFilter sol003SubscriptionsFilter) {
74         final org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter etsiCatalogManagerFilters =
75                 new org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter();
76
77         if (sol003SubscriptionsFilter.getNotificationTypes() != null) {
78             etsiCatalogManagerFilters.setNotificationTypes(
79                     getPkgmNotificationsFilterNotificationTypes(sol003SubscriptionsFilter.getNotificationTypes()));
80         }
81
82         etsiCatalogManagerFilters.setVnfProductsFromProviders(
83                 getVnfProductsProviders(sol003SubscriptionsFilter.getVnfProductsFromProviders()));
84
85         etsiCatalogManagerFilters.setVnfdId(getVnfdIds(sol003SubscriptionsFilter.getVnfdId()));
86
87         etsiCatalogManagerFilters.setVnfPkgId(getVnfPkgIds(sol003SubscriptionsFilter.getVnfPkgId()));
88
89         etsiCatalogManagerFilters
90                 .setOperationalState(getOperationalState(sol003SubscriptionsFilter.getOperationalState()));
91
92         etsiCatalogManagerFilters.setUsageState(null);
93
94         return etsiCatalogManagerFilters;
95     }
96
97     // TODO 'operationalState' in the Sol003 Swagger is type 'OperationalStateEnum'. The ETSI Catalog Manager Swagger
98     // 'operationalState' is type 'List<OperationalStateEnum>'. This method needs to be updated once swagger is updated.
99     private List<org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter.OperationalStateEnum> getOperationalState(
100             final OperationalStateEnum operationalState) {
101         if (operationalState != null) {
102             return Arrays.asList(
103                     org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter.OperationalStateEnum
104                             .fromValue(operationalState.getValue()));
105         }
106         return Collections.emptyList();
107     }
108
109     private List<String> getVnfPkgIds(final List<String> vnfPkgId) {
110         if (vnfPkgId != null) {
111             final List<String> etsiCatalogManagerVnfPkgId = new ArrayList<>();
112             vnfPkgId.forEach(type -> {
113                 etsiCatalogManagerVnfPkgId.add(type);
114             });
115         }
116         return Collections.emptyList();
117     }
118
119     private List<String> getVnfdIds(final List<String> vnfdId) {
120         if (vnfdId != null) {
121             final List<String> etsiCatalogManagerVnfdId = new ArrayList<>();
122             vnfdId.forEach(type -> {
123                 etsiCatalogManagerVnfdId.add(type);
124             });
125         }
126         return Collections.emptyList();
127     }
128
129     private List<VnfProductsProviders> getVnfProductsProviders(
130             final List<SubscriptionsFilterVnfProductsFromProviders> filterProductsFromProvider) {
131
132         if (filterProductsFromProvider != null && !filterProductsFromProvider.isEmpty()) {
133             final List<VnfProductsProviders> etsiCatalogManagerVnfProductsProviders = new ArrayList<>();
134             filterProductsFromProvider.forEach(vnfProduct -> {
135                 etsiCatalogManagerVnfProductsProviders
136                         .add(new VnfProductsProviders().vnfProducts(getVnfProducts(vnfProduct.getVnfProducts())));
137             });
138             return etsiCatalogManagerVnfProductsProviders;
139         }
140         return Collections.emptyList();
141     }
142
143     private List<VnfProducts> getVnfProducts(final List<SubscriptionsFilterVnfProducts> sol003VnfProducts) {
144         if (sol003VnfProducts != null) {
145             final List<VnfProducts> etsiCatalogManagerVnfProductsList = new ArrayList<>();
146             sol003VnfProducts.forEach(vnfProduct -> {
147                 etsiCatalogManagerVnfProductsList.add(new VnfProducts().vnfProductName(vnfProduct.getVnfProductName())
148                         .versions(getVersion(vnfProduct.getVersions())));
149             });
150             return etsiCatalogManagerVnfProductsList;
151         }
152         return Collections.emptyList();
153     }
154
155     private List<Version> getVersion(final List<SubscriptionsFilterVersions> sol003FilterVersions) {
156         if (sol003FilterVersions != null && !sol003FilterVersions.isEmpty()) {
157             List<Version> etsiCatalogVersionList = new ArrayList<>();
158             sol003FilterVersions.forEach(vnfFilterVersion -> {
159                 etsiCatalogVersionList.add(new Version().vnfSoftwareVersion(vnfFilterVersion.getVnfSoftwareVersion())
160                         .vnfdVersions(vnfFilterVersion.getVnfdVersions()));
161             });
162             return etsiCatalogVersionList;
163         }
164         return Collections.emptyList();
165     }
166
167     private List<org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter.NotificationTypesEnum> getPkgmNotificationsFilterNotificationTypes(
168             final List<NotificationTypesEnum> notificationTypes) {
169
170         if (notificationTypes != null && !notificationTypes.isEmpty()) {
171             final List<org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter.NotificationTypesEnum> etsiCatalogManagerNotificationTypes =
172                     new ArrayList<>();
173             notificationTypes.forEach(type -> etsiCatalogManagerNotificationTypes.add(
174                     org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter.NotificationTypesEnum
175                             .fromValue(type.getValue())));
176         }
177         return Collections.emptyList();
178     }
179
180
181 }