2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.vendorlicense.licenseartifacts.impl;
23 import org.openecomp.core.utilities.file.FileContentHandler;
24 import org.openecomp.sdc.common.utils.CommonUtil;
25 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
26 import org.openecomp.sdc.vendorlicense.HealingServiceFactory;
27 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
28 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
29 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel;
30 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
31 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
32 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
33 import org.openecomp.sdc.vendorlicense.healing.HealingService;
34 import org.openecomp.sdc.vendorlicense.licenseartifacts.VendorLicenseArtifactsService;
35 import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.VendorLicenseArtifact;
36 import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.types.VnfLicenseArtifact;
37 import org.openecomp.sdc.vendorlicense.licenseartifacts.impl.util.VendorLicenseArtifactsServiceUtils;
38 import org.openecomp.sdc.versioning.dao.types.Version;
40 import java.util.HashSet;
41 import java.util.List;
43 import java.util.stream.Collectors;
45 import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH;
46 import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VNF_ARTIFACT_NAME_WITH_PATH;
48 public class VendorLicenseArtifactsServiceImpl implements VendorLicenseArtifactsService {
50 public static final VendorLicenseFacade vendorLicenseFacade =
51 VendorLicenseFacadeFactory.getInstance().createInterface();
52 public static final HealingService healingService =
53 HealingServiceFactory.getInstance().createInterface();
54 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
57 static byte[] createVnfArtifact(String vspId, String vlmId, Version vlmVersion, String vendorName,
58 List<String> featureGroups, String user) {
61 mdcDataDebugMessage.debugEntryMessage("VLM name", vendorName);
63 VnfLicenseArtifact artifact = new VnfLicenseArtifact();
65 artifact.setVspId(vspId);
66 artifact.setVendorName(vendorName);
67 for (String featureGroupId : featureGroups) {
68 FeatureGroupModel featureGroupModel = vendorLicenseFacade
69 .getFeatureGroupModel(new FeatureGroupEntity(vlmId, vlmVersion, featureGroupId), user);
70 Set<EntitlementPoolEntity> entitlementPoolEntities = featureGroupModel.getEntitlementPools();
71 Set<LicenseKeyGroupEntity> licenseKeyGroupEntities = featureGroupModel.getLicenseKeyGroups();
73 featureGroupModel.setEntitlementPools(entitlementPoolEntities.stream().map(
74 entitlementPoolEntity -> (EntitlementPoolEntity) healingService
75 .heal(entitlementPoolEntity, user)).collect(Collectors.toSet()));
76 featureGroupModel.setLicenseKeyGroups(licenseKeyGroupEntities.stream().map(
77 licenseKeyGroupEntity -> (LicenseKeyGroupEntity) healingService
78 .heal(licenseKeyGroupEntity, user)).collect(Collectors.toSet()));
79 artifact.getFeatureGroups().add(featureGroupModel);
82 mdcDataDebugMessage.debugExitMessage("VLM name", vendorName);
83 return artifact.toXml().getBytes();
86 static byte[] createVendorLicenseArtifact(String vlmId, String vendorName, String user) {
89 mdcDataDebugMessage.debugEntryMessage("VLM name", vendorName);
91 VendorLicenseArtifact vendorLicenseArtifact = new VendorLicenseArtifact();
92 vendorLicenseArtifact.setVendorName(vendorName);
93 Set<EntitlementPoolEntity> entitlementPoolEntities = new HashSet<>();
94 Set<LicenseKeyGroupEntity> licenseKeyGroupEntities = new HashSet<>();
96 List<Version> finalVersions = VendorLicenseArtifactsServiceUtils.getFinalVersionsForVlm(vlmId);
97 for (Version finalVersion : finalVersions) {
98 entitlementPoolEntities
99 .addAll(vendorLicenseFacade.listEntitlementPools(vlmId, finalVersion, user));
100 licenseKeyGroupEntities
101 .addAll(vendorLicenseFacade.listLicenseKeyGroups(vlmId, finalVersion, user));
105 entitlementPoolEntities = VendorLicenseArtifactsServiceUtils
107 VendorLicenseArtifactsServiceUtils.filterChangedEntities(entitlementPoolEntities));
108 licenseKeyGroupEntities = VendorLicenseArtifactsServiceUtils
110 VendorLicenseArtifactsServiceUtils.filterChangedEntities(licenseKeyGroupEntities));
112 vendorLicenseArtifact.setEntitlementPoolEntities(entitlementPoolEntities);
113 vendorLicenseArtifact.setLicenseKeyGroupEntities(licenseKeyGroupEntities);
115 mdcDataDebugMessage.debugExitMessage("VLM name", vendorName);
116 return vendorLicenseArtifact.toXml().getBytes();
121 * Create License Artifacts.
124 * @param vlmVersion vlmVersion
125 * @param featureGroups featureGroups
127 * @return FileContentHandler
129 public FileContentHandler createLicenseArtifacts(String vspId, String vlmId, Version vlmVersion,
130 List<String> featureGroups, String user) {
133 mdcDataDebugMessage.debugEntryMessage("VSP Id", vspId);
135 FileContentHandler artifacts = new FileContentHandler();
136 String vendorName = VendorLicenseArtifactsServiceUtils.getVendorName(vlmId, user);
138 artifacts.addFile(VNF_ARTIFACT_NAME_WITH_PATH,
139 createVnfArtifact(vspId, vlmId, vlmVersion, vendorName, featureGroups, user));
140 artifacts.addFile(VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH,
141 createVendorLicenseArtifact(vlmId, vendorName, user));
143 mdcDataDebugMessage.debugExitMessage("VSP Id", vspId);