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.vendorlicense.VendorLicenseManager;
24 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
25 import org.openecomp.sdc.versioning.dao.types.Version;
27 import org.openecomp.sdcrests.vendorlicense.rest.LicenseKeyGroups;
28 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto;
29 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity;
30 import org.openecomp.sdcrests.vendorlicense.types.LicenseKeyGroupEntityDto;
31 import org.openecomp.sdcrests.vendorlicense.types.LicenseKeyGroupRequestDto;
32 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
33 import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.context.annotation.Scope;
37 import org.springframework.stereotype.Service;
38 import org.springframework.validation.annotation.Validated;
40 import java.util.Collection;
41 import javax.inject.Named;
42 import javax.ws.rs.core.Response;
45 @Service("licenseKeyGroups")
46 @Scope(value = "prototype")
48 public class LicenseKeyGroupsImpl implements LicenseKeyGroups {
51 private VendorLicenseManager vendorLicenseManager;
54 * List license key groups response.
56 * @param vlmId the vlm id
57 * @param version the version
58 * @param user the user
59 * @return the response
61 public Response listLicenseKeyGroups(String vlmId, String version, String user) {
62 Collection<LicenseKeyGroupEntity> licenseKeyGroups =
63 vendorLicenseManager.listLicenseKeyGroups(vlmId, Version.valueOf(version), user);
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));
72 return Response.ok(result).build();
76 * Create license key group response.
78 * @param request the request
79 * @param vlmId the vlm id
80 * @param user the user
81 * @return the response
83 public Response createLicenseKeyGroup(LicenseKeyGroupRequestDto request, String vlmId,
85 LicenseKeyGroupEntity licenseKeyGroupEntity =
86 new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity()
87 .applyMapping(request, LicenseKeyGroupEntity.class);
88 licenseKeyGroupEntity.setVendorLicenseModelId(vlmId);
90 LicenseKeyGroupEntity createdLicenseKeyGroup =
91 vendorLicenseManager.createLicenseKeyGroup(licenseKeyGroupEntity, user);
92 StringWrapperResponse result =
93 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,
109 String licenseKeyGroupId, String user) {
110 LicenseKeyGroupEntity licenseKeyGroupEntity =
111 new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity()
112 .applyMapping(request, LicenseKeyGroupEntity.class);
114 licenseKeyGroupEntity.setVendorLicenseModelId(vlmId);
115 licenseKeyGroupEntity.setId(licenseKeyGroupId);
117 vendorLicenseManager.updateLicenseKeyGroup(licenseKeyGroupEntity, user);
118 return Response.ok().build();
122 * Gets license key group.
124 * @param vlmId the vlm id
125 * @param version the version
126 * @param licenseKeyGroupId the license key group id
127 * @param user the user
128 * @return the license key group
130 public Response getLicenseKeyGroup(String vlmId, String version, String licenseKeyGroupId,
132 LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity();
133 lkgInput.setVendorLicenseModelId(vlmId);
134 lkgInput.setVersion(Version.valueOf(version));
135 lkgInput.setId(licenseKeyGroupId);
136 LicenseKeyGroupEntity licenseKeyGroup = vendorLicenseManager.getLicenseKeyGroup(lkgInput, user);
138 LicenseKeyGroupEntityDto licenseKeyGroupEntityDto = licenseKeyGroup == null ? null :
139 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto()
140 .applyMapping(licenseKeyGroup, LicenseKeyGroupEntityDto.class);
141 return Response.ok(licenseKeyGroupEntityDto).build();
145 * Delete license key group response.
147 * @param vlmId the vlm id
148 * @param licenseKeyGroupId the license key group id
149 * @param user the user
150 * @return the response
152 public Response deleteLicenseKeyGroup(String vlmId, String licenseKeyGroupId, String user) {
153 LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity();
154 lkgInput.setVendorLicenseModelId(vlmId);
155 lkgInput.setId(licenseKeyGroupId);
156 vendorLicenseManager.deleteLicenseKeyGroup(lkgInput, user);
157 return Response.ok().build();