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.types.LoggerServiceName;
25 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
26 import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory;
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.context.annotation.Scope;
37 import org.springframework.stereotype.Service;
38 import org.springframework.validation.annotation.Validated;
40 import javax.inject.Named;
41 import javax.ws.rs.core.Response;
42 import java.util.Collection;
45 @Service("licenseKeyGroups")
46 @Scope(value = "prototype")
48 public class LicenseKeyGroupsImpl implements LicenseKeyGroups {
49 private VendorLicenseManager vendorLicenseManager =
50 VendorLicenseManagerFactory.getInstance().createInterface();
53 * List license key groups response.
55 * @param vlmId the vlm id
56 * @param versionId the version
57 * @param user the user
58 * @return the response
60 public Response listLicenseKeyGroups(String vlmId, String versionId, String user) {
61 MdcUtil.initMdc(LoggerServiceName.List_LKG.toString());
62 Collection<LicenseKeyGroupEntity> licenseKeyGroups =
63 vendorLicenseManager.listLicenseKeyGroups(vlmId, new Version(versionId));
65 GenericCollectionWrapper<LicenseKeyGroupEntityDto> result = new GenericCollectionWrapper<>();
66 MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto outputMapper =
67 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto();
68 for (LicenseKeyGroupEntity ep : licenseKeyGroups) {
69 result.add(outputMapper.applyMapping(ep, LicenseKeyGroupEntityDto.class));
71 return Response.ok(result).build();
75 * Create license key group response.
77 * @param request the request
78 * @param vlmId the vlm id
79 * @param user the user
80 * @return the response
82 public Response createLicenseKeyGroup(LicenseKeyGroupRequestDto request, String vlmId,
83 String versionId, String user) {
84 MdcUtil.initMdc(LoggerServiceName.Create_LKG.toString());
85 LicenseKeyGroupEntity licenseKeyGroupEntity =
86 new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity()
87 .applyMapping(request, LicenseKeyGroupEntity.class);
88 licenseKeyGroupEntity.setVendorLicenseModelId(vlmId);
89 licenseKeyGroupEntity.setVersion(new Version(versionId));
91 LicenseKeyGroupEntity createdLicenseKeyGroup =
92 vendorLicenseManager.createLicenseKeyGroup(licenseKeyGroupEntity);
93 StringWrapperResponse result =
94 createdLicenseKeyGroup != null ? new StringWrapperResponse(createdLicenseKeyGroup.getId())
96 return Response.ok(result).build();
100 * Update license key group response.
102 * @param request the request
103 * @param vlmId the vlm id
104 * @param licenseKeyGroupId the license key group id
105 * @param user the user
106 * @return the response
108 public Response updateLicenseKeyGroup(LicenseKeyGroupRequestDto request, String vlmId,
110 String licenseKeyGroupId, String user) {
111 MdcUtil.initMdc(LoggerServiceName.Update_LKG.toString());
112 LicenseKeyGroupEntity licenseKeyGroupEntity =
113 new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity()
114 .applyMapping(request, LicenseKeyGroupEntity.class);
115 licenseKeyGroupEntity.setVendorLicenseModelId(vlmId);
116 licenseKeyGroupEntity.setVersion(new Version(versionId));
117 licenseKeyGroupEntity.setId(licenseKeyGroupId);
119 vendorLicenseManager.updateLicenseKeyGroup(licenseKeyGroupEntity);
120 return Response.ok().build();
124 * Gets license key group.
126 * @param vlmId the vlm id
127 * @param versionId the version
128 * @param licenseKeyGroupId the license key group id
129 * @param user the user
130 * @return the license key group
132 public Response getLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId,
134 MdcUtil.initMdc(LoggerServiceName.Get_LKG.toString());
135 LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity();
136 lkgInput.setVendorLicenseModelId(vlmId);
137 lkgInput.setVersion(new Version(versionId));
138 lkgInput.setId(licenseKeyGroupId);
139 LicenseKeyGroupEntity licenseKeyGroup = vendorLicenseManager.getLicenseKeyGroup(lkgInput);
141 LicenseKeyGroupEntityDto licenseKeyGroupEntityDto = licenseKeyGroup == null ? null :
142 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto()
143 .applyMapping(licenseKeyGroup, LicenseKeyGroupEntityDto.class);
144 return Response.ok(licenseKeyGroupEntityDto).build();
148 * Delete license key group response.
150 * @param vlmId the vlm id
151 * @param licenseKeyGroupId the license key group id
152 * @param user the user
153 * @return the response
155 public Response deleteLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId,
157 MdcUtil.initMdc(LoggerServiceName.Delete_LKG.toString());
158 LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity();
159 lkgInput.setVendorLicenseModelId(vlmId);
160 lkgInput.setVersion(new Version(versionId));
161 lkgInput.setId(licenseKeyGroupId);
162 vendorLicenseManager.deleteLicenseKeyGroup(lkgInput);
163 return Response.ok().build();