6eca00e8aaeb1611023b9ccb3f287affcafebfce
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / vendor-software-products-rest / vendor-software-products-rest-services / src / main / java / org / openecomp / sdcrests / vsp / rest / mapping / MapVersionedVendorSoftwareProductInfoToVspDetailsDto.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdcrests.vsp.rest.mapping;
22
23 import org.openecomp.core.utilities.CommonMethods;
24 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails;
25 import org.openecomp.sdc.vendorsoftwareproduct.types.LicensingData;
26 import org.openecomp.sdc.vendorsoftwareproduct.types.VersionedVendorSoftwareProductInfo;
27 import org.openecomp.sdcrests.common.types.VersionDto;
28 import org.openecomp.sdcrests.mapping.MappingBase;
29 import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspDetailsDto;
30
31 import java.util.stream.Collectors;
32
33 public class MapVersionedVendorSoftwareProductInfoToVspDetailsDto
34     extends MappingBase<VersionedVendorSoftwareProductInfo, VspDetailsDto> {
35
36   @Override
37   public void doMapping(VersionedVendorSoftwareProductInfo source, VspDetailsDto target) {
38     VspDetails vsp = source.getVspDetails();
39
40     target.setId(vsp.getId());
41     target.setVersion(new VersionDto(vsp.getVersion().toString(), vsp.getVersion().toString()));
42     target.setName(vsp.getName());
43     target.setDescription(vsp.getDescription());
44     target.setCategory(vsp.getCategory());
45     target.setSubCategory(vsp.getSubCategory());
46     target.setVendorId(vsp.getVendorId());
47     target.setVendorName(vsp.getVendorName());
48     target.setLicensingVersion(vsp.getVlmVersion() == null ? null : new VersionDto(vsp.getVlmVersion().toString(), vsp.getVlmVersion().toString()));
49     target.setIsOldVersion("False");
50
51     if (vsp.getLicenseAgreement() != null || vsp.getFeatureGroups() != null) {
52       LicensingData licensingData = new LicensingData();
53       licensingData.setLicenseAgreement(vsp.getLicenseAgreement());
54       licensingData.setFeatureGroups(vsp.getFeatureGroups());
55       target.setLicensingData(licensingData);
56     }
57
58     target.setValidationData(vsp.getValidationDataStructure());
59
60     target.setStatus(source.getVersionInfo().getStatus());
61     target.setLockingUser(source.getVersionInfo().getLockingUser());
62
63     if (!CommonMethods.isEmpty(source.getVersionInfo().getViewableVersions())) {
64       target.setViewableVersions(
65           source.getVersionInfo().getViewableVersions().stream()
66               .map(version -> new VersionDto(version.toString(), version.toString()))
67               .collect(Collectors.toList()));
68     }
69
70     if (!CommonMethods.isEmpty(source.getVersionInfo().getFinalVersions())) {
71       target.setFinalVersions(
72           source.getVersionInfo().getFinalVersions().stream()
73               .map(version -> new VersionDto(version.toString(), version.toString()))
74               .collect(Collectors.toList()));
75     }
76   }
77 }