Specify a model while creating a VSP
[sdc.git] / openecomp-be / lib / openecomp-sdc-vendor-software-product-lib / openecomp-sdc-vendor-software-product-core / src / main / java / org / openecomp / sdc / vendorsoftwareproduct / dao / impl / zusammen / convertor / ElementToVSPGeneralConvertor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2021 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.convertor;
22
23 import com.amdocs.zusammen.adaptor.inbound.api.types.item.Element;
24 import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo;
25 import com.amdocs.zusammen.datatypes.item.Info;
26 import com.amdocs.zusammen.datatypes.item.Item;
27 import org.openecomp.convertor.ElementConvertor;
28 import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl;
29 import org.openecomp.sdc.vendorsoftwareproduct.dao.impl.zusammen.VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName;
30 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
31 import org.openecomp.sdc.versioning.dao.types.Version;
32
33 public class ElementToVSPGeneralConvertor extends ElementConvertor<VspDetails> {
34
35     @Override
36     public VspDetails convert(Element element) {
37         if (element == null) {
38             return null;
39         }
40         return mapInfoToVspDetails(element.getInfo());
41     }
42
43     @Override
44     public VspDetails convert(Item item) {
45         if (item == null) {
46             return null;
47         }
48         var vspDetails = mapInfoToVspDetails(item.getInfo());
49         vspDetails.setId(item.getId().getValue());
50         return vspDetails;
51     }
52
53     @Override
54     public VspDetails convert(ElementInfo elementInfo) {
55         if (elementInfo == null) {
56             return null;
57         }
58         return mapInfoToVspDetails(elementInfo.getInfo());
59     }
60
61     private VspDetails mapInfoToVspDetails(final Info info) {
62         final var vspDetails = new VspDetails();
63         vspDetails.setName(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.NAME.getValue()));
64         vspDetails.setDescription(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.DESCRIPTION.getValue()));
65         vspDetails.setIcon(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.ICON.getValue()));
66         vspDetails.setCategory(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.CATEGORY.getValue()));
67         vspDetails.setSubCategory(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.SUB_CATEGORY.getValue()));
68         vspDetails.setVendorId(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_ID.getValue()));
69         vspDetails.setVendorName(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_NAME.getValue()));
70         if (info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_VERSION.getValue()) != null) {
71             vspDetails
72                 .setVlmVersion(new Version(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.VENDOR_VERSION.getValue())));
73         }
74         vspDetails.setLicenseType(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.LICENSE_TYPE.getValue()));
75         vspDetails.setLicenseAgreement(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.LICENSE_AGREEMENT.getValue()));
76         vspDetails.setFeatureGroups(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.FEATURE_GROUPS.getValue()));
77         vspDetails.setOnboardingMethod(info.getProperty(VendorSoftwareProductInfoDaoZusammenImpl.InfoPropertyName.ON_BOARDING_METHOD.getValue()));
78         vspDetails.setModelIdList(info.getProperty(InfoPropertyName.MODELS.getValue()));
79         return vspDetails;
80     }
81 }