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.VendorLicenseManagerFactory;
25 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
26 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;
34 import org.springframework.context.annotation.Scope;
35 import org.springframework.stereotype.Service;
36 import org.springframework.validation.annotation.Validated;
38 import javax.inject.Named;
39 import javax.ws.rs.core.Response;
40 import java.util.Collection;
43 @Service("licenseKeyGroups")
44 @Scope(value = "prototype")
46 public class LicenseKeyGroupsImpl implements LicenseKeyGroups {
47 private VendorLicenseManager vendorLicenseManager =
48 VendorLicenseManagerFactory.getInstance().createInterface();
51 * List license key groups response.
53 * @param vlmId the vlm id
54 * @param versionId the version
55 * @param user the user
56 * @return the response
58 public Response listLicenseKeyGroups(String vlmId, String versionId, String user) {
59 Collection<LicenseKeyGroupEntity> licenseKeyGroups =
60 vendorLicenseManager.listLicenseKeyGroups(vlmId, new Version(versionId));
62 GenericCollectionWrapper<LicenseKeyGroupEntityDto> result = new GenericCollectionWrapper<>();
63 MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto outputMapper =
64 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto();
65 for (LicenseKeyGroupEntity ep : licenseKeyGroups) {
66 result.add(outputMapper.applyMapping(ep, LicenseKeyGroupEntityDto.class));
68 return Response.ok(result).build();
72 * Create license key group response.
74 * @param request the request
75 * @param vlmId the vlm id
76 * @param user the user
77 * @return the response
79 public Response createLicenseKeyGroup(LicenseKeyGroupRequestDto request, String vlmId,
80 String versionId, String user) {
81 LicenseKeyGroupEntity licenseKeyGroupEntity =
82 new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity()
83 .applyMapping(request, LicenseKeyGroupEntity.class);
84 licenseKeyGroupEntity.setVendorLicenseModelId(vlmId);
85 licenseKeyGroupEntity.setVersion(new Version(versionId));
87 LicenseKeyGroupEntity createdLicenseKeyGroup =
88 vendorLicenseManager.createLicenseKeyGroup(licenseKeyGroupEntity);
89 StringWrapperResponse result =
90 createdLicenseKeyGroup != null ? new StringWrapperResponse(createdLicenseKeyGroup.getId())
92 return Response.ok(result).build();
96 * Update license key group response.
98 * @param request the request
99 * @param vlmId the vlm id
100 * @param licenseKeyGroupId the license key group id
101 * @param user the user
102 * @return the response
104 public Response updateLicenseKeyGroup(LicenseKeyGroupRequestDto request, String vlmId,
106 String licenseKeyGroupId, String user) {
107 LicenseKeyGroupEntity licenseKeyGroupEntity =
108 new MapLicenseKeyGroupRequestDtoToLicenseKeyGroupEntity()
109 .applyMapping(request, LicenseKeyGroupEntity.class);
110 licenseKeyGroupEntity.setVendorLicenseModelId(vlmId);
111 licenseKeyGroupEntity.setVersion(new Version(versionId));
112 licenseKeyGroupEntity.setId(licenseKeyGroupId);
114 vendorLicenseManager.updateLicenseKeyGroup(licenseKeyGroupEntity);
115 return Response.ok().build();
119 * Gets license key group.
121 * @param vlmId the vlm id
122 * @param versionId the version
123 * @param licenseKeyGroupId the license key group id
124 * @param user the user
125 * @return the license key group
127 public Response getLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId,
129 LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity();
130 lkgInput.setVendorLicenseModelId(vlmId);
131 lkgInput.setVersion(new Version(versionId));
132 lkgInput.setId(licenseKeyGroupId);
133 LicenseKeyGroupEntity licenseKeyGroup = vendorLicenseManager.getLicenseKeyGroup(lkgInput);
135 LicenseKeyGroupEntityDto licenseKeyGroupEntityDto = licenseKeyGroup == null ? null :
136 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto()
137 .applyMapping(licenseKeyGroup, LicenseKeyGroupEntityDto.class);
138 return Response.ok(licenseKeyGroupEntityDto).build();
142 * Delete license key group response.
144 * @param vlmId the vlm id
145 * @param licenseKeyGroupId the license key group id
146 * @param user the user
147 * @return the response
149 public Response deleteLicenseKeyGroup(String vlmId, String versionId, String licenseKeyGroupId,
151 LicenseKeyGroupEntity lkgInput = new LicenseKeyGroupEntity();
152 lkgInput.setVendorLicenseModelId(vlmId);
153 lkgInput.setVersion(new Version(versionId));
154 lkgInput.setId(licenseKeyGroupId);
155 vendorLicenseManager.deleteLicenseKeyGroup(lkgInput);
156 return Response.ok().build();