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.sdc.logging.context.MdcUtil;
24 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
25 import org.openecomp.sdc.logging.types.LoggerServiceName;
26 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
27 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
28 import org.openecomp.sdc.versioning.dao.types.Version;
29 import org.openecomp.sdcrests.vendorlicense.rest.LicenseKeyGroups;
30 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto;
31 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity;
32 import org.openecomp.sdcrests.vendorlicense.types.LicenseKeyGroupEntityDto;
33 import org.openecomp.sdcrests.vendorlicense.types.LicenseKeyGroupRequestDto;
34 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
35 import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.context.annotation.Scope;
38 import org.springframework.stereotype.Service;
39 import org.springframework.validation.annotation.Validated;
41 import javax.inject.Named;
42 import javax.ws.rs.core.Response;
43 import java.util.Collection;
46 @Service("licenseKeyGroups")
47 @Scope(value = "prototype")
49 public class LicenseKeyGroupsImpl implements LicenseKeyGroups {
51 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
53 private VendorLicenseManager vendorLicenseManager;
56 * List license key groups response.
58 * @param vlmId the vlm id
59 * @param versionId the version
60 * @param user the user
61 * @return the response
63 public Response listLicenseKeyGroups(String vlmId, String versionId, String user) {
65 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
67 MdcUtil.initMdc(LoggerServiceName.List_LKG.toString());
68 Collection<LicenseKeyGroupEntity> licenseKeyGroups =
69 vendorLicenseManager.listLicenseKeyGroups(vlmId, Version.valueOf(versionId), user);
71 GenericCollectionWrapper<LicenseKeyGroupEntityDto> result = new GenericCollectionWrapper<>();
72 MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto outputMapper =
73 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto();
74 for (LicenseKeyGroupEntity ep : licenseKeyGroups) {
75 result.add(outputMapper.applyMapping(ep, LicenseKeyGroupEntityDto.class));
78 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
80 return Response.ok(result).build();
84 * Create license key group response.
86 * @param request the request
87 * @param vlmId the vlm id
88 * @param user the user
89 * @return the response
91 public Response createLicenseKeyGroup(LicenseKeyGroupRequestDto request, String vlmId,
92 String versionId, String user) {
94 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
96 MdcUtil.initMdc(LoggerServiceName.Create_LKG.toString());
97 LicenseKeyGroupEntity licenseKeyGroupEntity =
98 new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity()
99 .applyMapping(request, LicenseKeyGroupEntity.class);
100 licenseKeyGroupEntity.setVendorLicenseModelId(vlmId);
102 LicenseKeyGroupEntity createdLicenseKeyGroup =
103 vendorLicenseManager.createLicenseKeyGroup(licenseKeyGroupEntity, user);
104 StringWrapperResponse result =
105 createdLicenseKeyGroup != null ? new StringWrapperResponse(createdLicenseKeyGroup.getId())
108 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
110 return Response.ok(result).build();
114 * Update license key group response.
116 * @param request the request
117 * @param vlmId the vlm id
118 * @param licenseKeyGroupId the license key group id
119 * @param user the user
120 * @return the response
122 public Response updateLicenseKeyGroup(LicenseKeyGroupRequestDto request, String vlmId,
124 String licenseKeyGroupId, String user) {
126 mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
128 MdcUtil.initMdc(LoggerServiceName.Update_LKG.toString());
129 LicenseKeyGroupEntity licenseKeyGroupEntity =
130 new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity()
131 .applyMapping(request, LicenseKeyGroupEntity.class);
132 licenseKeyGroupEntity.setVendorLicenseModelId(vlmId);
133 licenseKeyGroupEntity.setId(licenseKeyGroupId);
135 vendorLicenseManager.updateLicenseKeyGroup(licenseKeyGroupEntity, user);
137 mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
139 return Response.ok().build();
143 * Gets license key group.
145 * @param vlmId the vlm id
146 * @param versionId the version
147 * @param licenseKeyGroupId the license key group id
148 * @param user the user
149 * @return the license key group
151 public Response getLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId,
154 mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
156 MdcUtil.initMdc(LoggerServiceName.Get_LKG.toString());
157 LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity();
158 lkgInput.setVendorLicenseModelId(vlmId);
159 lkgInput.setVersion(Version.valueOf(versionId));
160 lkgInput.setId(licenseKeyGroupId);
161 LicenseKeyGroupEntity licenseKeyGroup = vendorLicenseManager.getLicenseKeyGroup(lkgInput, user);
163 LicenseKeyGroupEntityDto licenseKeyGroupEntityDto = licenseKeyGroup == null ? null :
164 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto()
165 .applyMapping(licenseKeyGroup, LicenseKeyGroupEntityDto.class);
167 mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
169 return Response.ok(licenseKeyGroupEntityDto).build();
173 * Delete license key group response.
175 * @param vlmId the vlm id
176 * @param licenseKeyGroupId the license key group id
177 * @param user the user
178 * @return the response
180 public Response deleteLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId,
183 mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
185 MdcUtil.initMdc(LoggerServiceName.Delete_LKG.toString());
186 LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity();
187 lkgInput.setVendorLicenseModelId(vlmId);
188 lkgInput.setId(licenseKeyGroupId);
189 vendorLicenseManager.deleteLicenseKeyGroup(lkgInput, user);
191 mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
193 return Response.ok().build();