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.VendorLicenseManagerFactory;
28 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
29 import org.openecomp.sdc.versioning.dao.types.Version;
30 import org.openecomp.sdcrests.vendorlicense.rest.LicenseKeyGroups;
31 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto;
32 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity;
33 import org.openecomp.sdcrests.vendorlicense.types.LicenseKeyGroupEntityDto;
34 import org.openecomp.sdcrests.vendorlicense.types.LicenseKeyGroupRequestDto;
35 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
36 import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
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();
52 private VendorLicenseManager vendorLicenseManager =
53 VendorLicenseManagerFactory.getInstance().createInterface();
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, new Version(versionId));
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);
101 licenseKeyGroupEntity.setVersion(new Version(versionId));
103 LicenseKeyGroupEntity createdLicenseKeyGroup =
104 vendorLicenseManager.createLicenseKeyGroup(licenseKeyGroupEntity);
105 StringWrapperResponse result =
106 createdLicenseKeyGroup != null ? new StringWrapperResponse(createdLicenseKeyGroup.getId())
109 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
111 return Response.ok(result).build();
115 * Update license key group response.
117 * @param request the request
118 * @param vlmId the vlm id
119 * @param licenseKeyGroupId the license key group id
120 * @param user the user
121 * @return the response
123 public Response updateLicenseKeyGroup(LicenseKeyGroupRequestDto request, String vlmId,
125 String licenseKeyGroupId, String user) {
127 mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
129 MdcUtil.initMdc(LoggerServiceName.Update_LKG.toString());
130 LicenseKeyGroupEntity licenseKeyGroupEntity =
131 new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity()
132 .applyMapping(request, LicenseKeyGroupEntity.class);
133 licenseKeyGroupEntity.setVendorLicenseModelId(vlmId);
134 licenseKeyGroupEntity.setVersion(new Version(versionId));
135 licenseKeyGroupEntity.setId(licenseKeyGroupId);
137 vendorLicenseManager.updateLicenseKeyGroup(licenseKeyGroupEntity);
139 mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
141 return Response.ok().build();
145 * Gets license key group.
147 * @param vlmId the vlm id
148 * @param versionId the version
149 * @param licenseKeyGroupId the license key group id
150 * @param user the user
151 * @return the license key group
153 public Response getLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId,
156 mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
158 MdcUtil.initMdc(LoggerServiceName.Get_LKG.toString());
159 LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity();
160 lkgInput.setVendorLicenseModelId(vlmId);
161 lkgInput.setVersion(new Version(versionId));
162 lkgInput.setId(licenseKeyGroupId);
163 LicenseKeyGroupEntity licenseKeyGroup = vendorLicenseManager.getLicenseKeyGroup(lkgInput);
165 LicenseKeyGroupEntityDto licenseKeyGroupEntityDto = licenseKeyGroup == null ? null :
166 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto()
167 .applyMapping(licenseKeyGroup, LicenseKeyGroupEntityDto.class);
169 mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
171 return Response.ok(licenseKeyGroupEntityDto).build();
175 * Delete license key group response.
177 * @param vlmId the vlm id
178 * @param licenseKeyGroupId the license key group id
179 * @param user the user
180 * @return the response
182 public Response deleteLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId,
185 mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
187 MdcUtil.initMdc(LoggerServiceName.Delete_LKG.toString());
188 LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity();
189 lkgInput.setVendorLicenseModelId(vlmId);
190 lkgInput.setVersion(new Version(versionId));
191 lkgInput.setId(licenseKeyGroupId);
192 vendorLicenseManager.deleteLicenseKeyGroup(lkgInput);
194 mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
196 return Response.ok().build();