Merge "remove sub process error handling that silent successes"
[so.git] / 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
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 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.etsisol003adapter.pkgm.converters.etsicatalog.sol003;
22
23 import static org.slf4j.LoggerFactory.getLogger;
24 import org.onap.so.adapters.etsi.sol003.adapter.common.VnfmAdapterUrlProvider;
25 import org.onap.so.adapters.etsisol003adapter.etsicatalog.notification.model.PkgChangeNotification;
26 import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.vnfm.notification.model.VnfPackageChangeNotification;
27 import org.slf4j.Logger;
28 import org.springframework.core.convert.converter.Converter;
29 import org.springframework.stereotype.Service;
30
31 /**
32  * Converter to convert from an Etsi Catalog Manager {@link PkgChangeNotification} Object to its equivalent SOL003
33  * {@link VnfPackageChangeNotification} Object
34  *
35  * @author andrew.a.lamb@est.tech
36  */
37 @Service
38 public class PkgChangeNotificationConverter extends AbstractPkgNotificationConverter
39         implements Converter<PkgChangeNotification, VnfPackageChangeNotification> {
40     private static final Logger logger = getLogger(PkgChangeNotificationConverter.class);
41
42     public PkgChangeNotificationConverter(final VnfmAdapterUrlProvider vnfmAdapterUrlProvider) {
43         super(vnfmAdapterUrlProvider);
44     }
45
46     /**
47      * Convert a {@link PkgChangeNotification} Object to an {@link VnfPackageChangeNotification} Object
48      * 
49      * @param pkgChangeNotification The PkgChangeNotification Object to Convert
50      * @return The Converted VnfPackageChangeNotification Object
51      */
52     @Override
53     public VnfPackageChangeNotification convert(final PkgChangeNotification pkgChangeNotification) {
54         logger.info("Converting PkgChangeNotification\n{}", pkgChangeNotification.toString());
55         final VnfPackageChangeNotification vnfPackageChangeNotification = new VnfPackageChangeNotification();
56         vnfPackageChangeNotification.setId(pkgChangeNotification.getId());
57
58         if (pkgChangeNotification.getNotificationType() != null) {
59             vnfPackageChangeNotification.setNotificationType(VnfPackageChangeNotification.NotificationTypeEnum
60                     .fromValue(pkgChangeNotification.getNotificationType().getValue()));
61         }
62
63         vnfPackageChangeNotification.setSubscriptionId(pkgChangeNotification.getSubscriptionId());
64         vnfPackageChangeNotification.setTimeStamp(pkgChangeNotification.getTimeStamp());
65         vnfPackageChangeNotification.setVnfPkgId(pkgChangeNotification.getVnfPkgId());
66
67         vnfPackageChangeNotification.setVnfdId(pkgChangeNotification.getVnfdId());
68
69         if (pkgChangeNotification.getChangeType() != null) {
70             vnfPackageChangeNotification.setChangeType(VnfPackageChangeNotification.ChangeTypeEnum
71                     .fromValue(pkgChangeNotification.getChangeType().getValue()));
72         }
73
74         if (pkgChangeNotification.getOperationalState() != null) {
75             vnfPackageChangeNotification.setOperationalState(VnfPackageChangeNotification.OperationalStateEnum
76                     .fromValue(pkgChangeNotification.getOperationalState().getValue()));
77         }
78
79         vnfPackageChangeNotification.setLinks(convert(pkgChangeNotification.getLinks(),
80                 pkgChangeNotification.getVnfPkgId(), pkgChangeNotification.getSubscriptionId()));
81
82         return vnfPackageChangeNotification;
83     }
84
85 }