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.beans.factory.annotation.Autowired;
38 import org.springframework.context.annotation.Scope;
39 import org.springframework.stereotype.Service;
40 import org.springframework.validation.annotation.Validated;
42 import javax.inject.Named;
43 import javax.ws.rs.core.Response;
44 import java.util.Collection;
47 @Service("licenseKeyGroups")
48 @Scope(value = "prototype")
50 public class LicenseKeyGroupsImpl implements LicenseKeyGroups {
52 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
53 private VendorLicenseManager vendorLicenseManager =
54 VendorLicenseManagerFactory.getInstance().createInterface();
57 * List license key groups response.
59 * @param vlmId the vlm id
60 * @param versionId the version
61 * @param user the user
62 * @return the response
64 public Response listLicenseKeyGroups(String vlmId, String versionId, String user) {
66 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
68 MdcUtil.initMdc(LoggerServiceName.List_LKG.toString());
69 Collection<LicenseKeyGroupEntity> licenseKeyGroups =
70 vendorLicenseManager.listLicenseKeyGroups(vlmId, Version.valueOf(versionId), user);
72 GenericCollectionWrapper<LicenseKeyGroupEntityDto> result = new GenericCollectionWrapper<>();
73 MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto outputMapper =
74 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto();
75 for (LicenseKeyGroupEntity ep : licenseKeyGroups) {
76 result.add(outputMapper.applyMapping(ep, LicenseKeyGroupEntityDto.class));
79 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
81 return Response.ok(result).build();
85 * Create license key group response.
87 * @param request the request
88 * @param vlmId the vlm id
89 * @param user the user
90 * @return the response
92 public Response createLicenseKeyGroup(LicenseKeyGroupRequestDto request, String vlmId,
93 String versionId, String user) {
95 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
97 MdcUtil.initMdc(LoggerServiceName.Create_LKG.toString());
98 LicenseKeyGroupEntity licenseKeyGroupEntity =
99 new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity()
100 .applyMapping(request, LicenseKeyGroupEntity.class);
101 licenseKeyGroupEntity.setVendorLicenseModelId(vlmId);
103 LicenseKeyGroupEntity createdLicenseKeyGroup =
104 vendorLicenseManager.createLicenseKeyGroup(licenseKeyGroupEntity, user);
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.setId(licenseKeyGroupId);
136 vendorLicenseManager.updateLicenseKeyGroup(licenseKeyGroupEntity, user);
138 mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
140 return Response.ok().build();
144 * Gets license key group.
146 * @param vlmId the vlm id
147 * @param versionId the version
148 * @param licenseKeyGroupId the license key group id
149 * @param user the user
150 * @return the license key group
152 public Response getLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId,
155 mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
157 MdcUtil.initMdc(LoggerServiceName.Get_LKG.toString());
158 LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity();
159 lkgInput.setVendorLicenseModelId(vlmId);
160 lkgInput.setVersion(Version.valueOf(versionId));
161 lkgInput.setId(licenseKeyGroupId);
162 LicenseKeyGroupEntity licenseKeyGroup = vendorLicenseManager.getLicenseKeyGroup(lkgInput, user);
164 LicenseKeyGroupEntityDto licenseKeyGroupEntityDto = licenseKeyGroup == null ? null :
165 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto()
166 .applyMapping(licenseKeyGroup, LicenseKeyGroupEntityDto.class);
168 mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
170 return Response.ok(licenseKeyGroupEntityDto).build();
174 * Delete license key group response.
176 * @param vlmId the vlm id
177 * @param licenseKeyGroupId the license key group id
178 * @param user the user
179 * @return the response
181 public Response deleteLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId,
184 mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
186 MdcUtil.initMdc(LoggerServiceName.Delete_LKG.toString());
187 LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity();
188 lkgInput.setVendorLicenseModelId(vlmId);
189 lkgInput.setId(licenseKeyGroupId);
190 vendorLicenseManager.deleteLicenseKeyGroup(lkgInput, user);
192 mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", vlmId, licenseKeyGroupId);
194 return Response.ok().build();