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.sdcrests.vendorlicense.rest.services;
23 import org.openecomp.core.utilities.CommonMethods;
24 import org.openecomp.sdc.logging.context.MdcUtil;
25 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
26 import org.openecomp.sdc.logging.types.LoggerServiceName;
27 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
28 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
29 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
30 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel;
31 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
32 import org.openecomp.sdc.versioning.dao.types.Version;
33 import org.openecomp.sdcrests.vendorlicense.rest.FeatureGroups;
34 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapEntitlementPoolEntityToEntitlementPoolEntityDto;
35 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapFeatureGroupDescriptorDtoToFeatureGroupEntity;
36 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapFeatureGroupEntityToFeatureGroupDescriptorDto;
37 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto;
38 import org.openecomp.sdcrests.vendorlicense.types.EntitlementPoolEntityDto;
39 import org.openecomp.sdcrests.vendorlicense.types.FeatureGroupEntityDto;
40 import org.openecomp.sdcrests.vendorlicense.types.FeatureGroupModelDto;
41 import org.openecomp.sdcrests.vendorlicense.types.FeatureGroupRequestDto;
42 import org.openecomp.sdcrests.vendorlicense.types.FeatureGroupUpdateRequestDto;
43 import org.openecomp.sdcrests.vendorlicense.types.LicenseKeyGroupEntityDto;
44 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
45 import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.context.annotation.Scope;
48 import org.springframework.stereotype.Service;
50 import javax.inject.Named;
51 import javax.ws.rs.core.Response;
52 import java.util.Collection;
53 import java.util.HashSet;
56 @Service("featureGroups")
57 @Scope(value = "prototype")
58 public class FeatureGroupsImpl implements FeatureGroups {
60 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
62 private VendorLicenseManager vendorLicenseManager;
65 public Response listFeatureGroups(String vlmId, String versionId, String user) {
67 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
69 MdcUtil.initMdc(LoggerServiceName.List_FG.toString());
70 Collection<FeatureGroupEntity> featureGroupEntities =
71 vendorLicenseManager.listFeatureGroups(vlmId, Version.valueOf(versionId), user);
73 MapFeatureGroupEntityToFeatureGroupDescriptorDto outputMapper =
74 new MapFeatureGroupEntityToFeatureGroupDescriptorDto();
75 GenericCollectionWrapper<FeatureGroupEntityDto> results = new GenericCollectionWrapper<>();
77 for (FeatureGroupEntity fg : featureGroupEntities) {
78 FeatureGroupEntityDto fgDto = new FeatureGroupEntityDto();
79 fgDto.setId(fg.getId());
80 fgDto.setLicenseKeyGroupsIds(fg.getLicenseKeyGroupIds());
81 fgDto.setEntitlementPoolsIds(fg.getEntitlementPoolIds());
82 fgDto.setReferencingLicenseAgreements(fg.getReferencingLicenseAgreements());
83 fgDto.setManufacturerReferenceNumber(fg.getManufacturerReferenceNumber());
84 outputMapper.doMapping(fg, fgDto);
88 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
90 return Response.ok(results).build();
94 public Response createFeatureGroup(FeatureGroupRequestDto request, String vlmId, String versionId,
97 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
99 MdcUtil.initMdc(LoggerServiceName.Create_FG.toString());
100 FeatureGroupEntity featureGroupEntity = new MapFeatureGroupDescriptorDtoToFeatureGroupEntity()
101 .applyMapping(request, FeatureGroupEntity.class);
102 featureGroupEntity.setVendorLicenseModelId(vlmId);
103 featureGroupEntity.setLicenseKeyGroupIds(request.getAddedLicenseKeyGroupsIds());
104 featureGroupEntity.setEntitlementPoolIds(request.getAddedEntitlementPoolsIds());
106 FeatureGroupEntity createdFeatureGroup =
107 vendorLicenseManager.createFeatureGroup(featureGroupEntity, user);
109 StringWrapperResponse result =
110 createdFeatureGroup != null ? new StringWrapperResponse(createdFeatureGroup.getId()) : null;
112 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
114 return Response.ok(result).build();
118 public Response updateFeatureGroup(FeatureGroupUpdateRequestDto request, String vlmId,
119 String versionId, String featureGroupId, String user) {
121 mdcDataDebugMessage.debugEntryMessage("VLM id, FG id", vlmId, featureGroupId);
123 MdcUtil.initMdc(LoggerServiceName.Update_FG.toString());
124 FeatureGroupEntity featureGroupEntity = new MapFeatureGroupDescriptorDtoToFeatureGroupEntity()
125 .applyMapping(request, FeatureGroupEntity.class);
126 featureGroupEntity.setVendorLicenseModelId(vlmId);
127 featureGroupEntity.setId(featureGroupId);
130 .updateFeatureGroup(featureGroupEntity, request.getAddedLicenseKeyGroupsIds(),
131 request.getRemovedLicenseKeyGroupsIds(), request.getAddedEntitlementPoolsIds(),
132 request.getRemovedEntitlementPoolsIds(), user);
134 mdcDataDebugMessage.debugExitMessage("VLM id, FG id", vlmId, featureGroupId);
136 return Response.ok().build();
140 public Response getFeatureGroup(String vlmId, String versionId, String featureGroupId,
143 mdcDataDebugMessage.debugEntryMessage("VLM id, FG id", vlmId, featureGroupId);
145 MdcUtil.initMdc(LoggerServiceName.Get_FG.toString());
146 FeatureGroupEntity fgInput = new FeatureGroupEntity();
147 fgInput.setVendorLicenseModelId(vlmId);
148 fgInput.setVersion(Version.valueOf(versionId));
149 fgInput.setId(featureGroupId);
150 FeatureGroupModel featureGroupModel = vendorLicenseManager.getFeatureGroupModel(fgInput, user);
152 if (featureGroupModel == null) {
153 return Response.ok().build();
156 FeatureGroupModelDto fgmDto = new FeatureGroupModelDto();
157 fgmDto.setId(featureGroupModel.getFeatureGroup().getId());
158 fgmDto.setReferencingLicenseAgreements(
159 featureGroupModel.getFeatureGroup().getReferencingLicenseAgreements());
160 new MapFeatureGroupEntityToFeatureGroupDescriptorDto()
161 .doMapping(featureGroupModel.getFeatureGroup(), fgmDto);
163 if (!CommonMethods.isEmpty(featureGroupModel.getLicenseKeyGroups())) {
164 fgmDto.setLicenseKeyGroups(new HashSet<>());
166 MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto lkgMapper =
167 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto();
168 for (LicenseKeyGroupEntity lkg : featureGroupModel.getLicenseKeyGroups()) {
169 fgmDto.getLicenseKeyGroups()
170 .add(lkgMapper.applyMapping(lkg, LicenseKeyGroupEntityDto.class));
174 if (!CommonMethods.isEmpty(featureGroupModel.getEntitlementPools())) {
175 fgmDto.setEntitlementPools(new HashSet<>());
177 MapEntitlementPoolEntityToEntitlementPoolEntityDto epMapper =
178 new MapEntitlementPoolEntityToEntitlementPoolEntityDto();
179 for (EntitlementPoolEntity ep : featureGroupModel.getEntitlementPools()) {
180 fgmDto.getEntitlementPools().add(epMapper.applyMapping(ep, EntitlementPoolEntityDto.class));
185 mdcDataDebugMessage.debugExitMessage("VLM id, FG id", vlmId, featureGroupId);
187 return Response.ok(fgmDto).build();
191 public Response deleteFeatureGroup(String vlmId, String versionId, String featureGroupId,
194 mdcDataDebugMessage.debugEntryMessage("VLM id, FG id", vlmId, featureGroupId);
196 MdcUtil.initMdc(LoggerServiceName.Delete_FG.toString());
197 FeatureGroupEntity fgInput = new FeatureGroupEntity();
198 fgInput.setVendorLicenseModelId(vlmId);
199 fgInput.setId(featureGroupId);
200 vendorLicenseManager.deleteFeatureGroup(fgInput, user);
202 mdcDataDebugMessage.debugExitMessage("VLM id, FG id", vlmId, featureGroupId);
204 return Response.ok().build();