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.vendorlicense.VendorLicenseManager;
25 import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory;
26 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
27 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
28 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel;
29 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
30 import org.openecomp.sdc.versioning.dao.types.Version;
31 import org.openecomp.sdcrests.vendorlicense.rest.FeatureGroups;
32 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapEntitlementPoolEntityToEntitlementPoolEntityDto;
33 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapFeatureGroupDescriptorDtoToFeatureGroupEntity;
34 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapFeatureGroupEntityToFeatureGroupDescriptorDto;
35 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto;
36 import org.openecomp.sdcrests.vendorlicense.types.EntitlementPoolEntityDto;
37 import org.openecomp.sdcrests.vendorlicense.types.FeatureGroupEntityDto;
38 import org.openecomp.sdcrests.vendorlicense.types.FeatureGroupModelDto;
39 import org.openecomp.sdcrests.vendorlicense.types.FeatureGroupRequestDto;
40 import org.openecomp.sdcrests.vendorlicense.types.FeatureGroupUpdateRequestDto;
41 import org.openecomp.sdcrests.vendorlicense.types.LicenseKeyGroupEntityDto;
42 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
43 import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
44 import org.springframework.context.annotation.Scope;
45 import org.springframework.stereotype.Service;
47 import javax.inject.Named;
48 import javax.ws.rs.core.Response;
49 import java.util.Collection;
50 import java.util.HashSet;
53 @Service("featureGroups")
54 @Scope(value = "prototype")
55 public class FeatureGroupsImpl implements FeatureGroups {
56 private VendorLicenseManager vendorLicenseManager =
57 VendorLicenseManagerFactory.getInstance().createInterface();
60 public Response listFeatureGroups(String vlmId, String versionId, String user) {
61 Collection<FeatureGroupEntity> featureGroupEntities =
62 vendorLicenseManager.listFeatureGroups(vlmId, new Version(versionId));
64 MapFeatureGroupEntityToFeatureGroupDescriptorDto outputMapper =
65 new MapFeatureGroupEntityToFeatureGroupDescriptorDto();
66 GenericCollectionWrapper<FeatureGroupEntityDto> results = new GenericCollectionWrapper<>();
68 for (FeatureGroupEntity fg : featureGroupEntities) {
69 FeatureGroupEntityDto fgDto = new FeatureGroupEntityDto();
70 fgDto.setId(fg.getId());
71 fgDto.setLicenseKeyGroupsIds(fg.getLicenseKeyGroupIds());
72 fgDto.setEntitlementPoolsIds(fg.getEntitlementPoolIds());
73 fgDto.setReferencingLicenseAgreements(fg.getReferencingLicenseAgreements());
74 fgDto.setManufacturerReferenceNumber(fg.getManufacturerReferenceNumber());
75 outputMapper.doMapping(fg, fgDto);
78 return Response.ok(results).build();
82 public Response createFeatureGroup(FeatureGroupRequestDto request, String vlmId, String versionId,
84 FeatureGroupEntity featureGroupEntity = new MapFeatureGroupDescriptorDtoToFeatureGroupEntity()
85 .applyMapping(request, FeatureGroupEntity.class);
86 featureGroupEntity.setVendorLicenseModelId(vlmId);
87 featureGroupEntity.setVersion(new Version(versionId));
88 featureGroupEntity.setLicenseKeyGroupIds(request.getAddedLicenseKeyGroupsIds());
89 featureGroupEntity.setEntitlementPoolIds(request.getAddedEntitlementPoolsIds());
91 FeatureGroupEntity createdFeatureGroup =
92 vendorLicenseManager.createFeatureGroup(featureGroupEntity);
94 StringWrapperResponse result =
95 createdFeatureGroup != null ? new StringWrapperResponse(createdFeatureGroup.getId()) : null;
96 return Response.ok(result).build();
100 public Response updateFeatureGroup(FeatureGroupUpdateRequestDto request, String vlmId,
101 String versionId, String featureGroupId, String user) {
102 FeatureGroupEntity featureGroupEntity = new MapFeatureGroupDescriptorDtoToFeatureGroupEntity()
103 .applyMapping(request, FeatureGroupEntity.class);
104 featureGroupEntity.setVendorLicenseModelId(vlmId);
105 featureGroupEntity.setVersion(new Version(versionId));
106 featureGroupEntity.setId(featureGroupId);
109 .updateFeatureGroup(featureGroupEntity, request.getAddedLicenseKeyGroupsIds(),
110 request.getRemovedLicenseKeyGroupsIds(), request.getAddedEntitlementPoolsIds(),
111 request.getRemovedEntitlementPoolsIds());
112 return Response.ok().build();
116 public Response getFeatureGroup(String vlmId, String versionId, String featureGroupId,
118 FeatureGroupEntity fgInput = new FeatureGroupEntity();
119 fgInput.setVendorLicenseModelId(vlmId);
120 fgInput.setVersion(new Version(versionId));
121 fgInput.setId(featureGroupId);
122 FeatureGroupModel featureGroupModel = vendorLicenseManager.getFeatureGroupModel(fgInput);
124 if (featureGroupModel == null) {
125 return Response.ok().build();
128 FeatureGroupModelDto fgmDto = new FeatureGroupModelDto();
129 fgmDto.setId(featureGroupModel.getFeatureGroup().getId());
130 fgmDto.setReferencingLicenseAgreements(
131 featureGroupModel.getFeatureGroup().getReferencingLicenseAgreements());
132 new MapFeatureGroupEntityToFeatureGroupDescriptorDto()
133 .doMapping(featureGroupModel.getFeatureGroup(), fgmDto);
135 if (!CommonMethods.isEmpty(featureGroupModel.getLicenseKeyGroups())) {
136 fgmDto.setLicenseKeyGroups(new HashSet<>());
138 MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto lkgMapper =
139 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto();
140 for (LicenseKeyGroupEntity lkg : featureGroupModel.getLicenseKeyGroups()) {
141 fgmDto.getLicenseKeyGroups()
142 .add(lkgMapper.applyMapping(lkg, LicenseKeyGroupEntityDto.class));
146 if (!CommonMethods.isEmpty(featureGroupModel.getEntitlementPools())) {
147 fgmDto.setEntitlementPools(new HashSet<>());
149 MapEntitlementPoolEntityToEntitlementPoolEntityDto epMapper =
150 new MapEntitlementPoolEntityToEntitlementPoolEntityDto();
151 for (EntitlementPoolEntity ep : featureGroupModel.getEntitlementPools()) {
152 fgmDto.getEntitlementPools().add(epMapper.applyMapping(ep, EntitlementPoolEntityDto.class));
156 return Response.ok(fgmDto).build();
160 public Response deleteFeatureGroup(String vlmId, String versionId, String featureGroupId,
162 FeatureGroupEntity fgInput = new FeatureGroupEntity();
163 fgInput.setVendorLicenseModelId(vlmId);
164 fgInput.setVersion(new Version(versionId));
165 fgInput.setId(featureGroupId);
166 vendorLicenseManager.deleteFeatureGroup(fgInput);
167 return Response.ok().build();