2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.vendorlicense.dao.types.LimitEntity;
27 import org.openecomp.sdc.versioning.dao.types.Version;
28 import org.openecomp.sdcrests.vendorlicense.rest.LicenseKeyGroupLimits;
29 import org.openecomp.sdcrests.vendorlicense.rest.mapping.LimitCreationDto;
30 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitEntityToLimitCreationDto;
31 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitEntityToLimitDto;
32 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitRequestDtoToLimitEntity;
33 import org.openecomp.sdcrests.vendorlicense.types.LimitEntityDto;
34 import org.openecomp.sdcrests.vendorlicense.types.LimitRequestDto;
35 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
36 import org.springframework.context.annotation.Scope;
37 import org.springframework.stereotype.Service;
39 import javax.inject.Named;
40 import javax.ws.rs.core.Response;
41 import java.util.Collection;
44 @Service("licenseKeyGroupLimits")
45 @Scope(value = "prototype")
46 public class LicenseKeyGroupLimitsImpl implements LicenseKeyGroupLimits {
47 private VendorLicenseManager vendorLicenseManager =
48 VendorLicenseManagerFactory.getInstance().createInterface();
50 private static final String PARENT = "LicenseKeyGroup";
54 public Response createLimit(LimitRequestDto request,
57 String licenseKeyGroupId,
59 Version version = new Version(versionId);
60 vendorLicenseManager.getLicenseKeyGroup(
61 new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId));
63 LimitEntity limitEntity =
64 new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class);
65 limitEntity.setVendorLicenseModelId(vlmId);
66 limitEntity.setVersion(version);
67 limitEntity.setEpLkgId(licenseKeyGroupId);
68 limitEntity.setParent(PARENT);
70 LimitEntity createdLimit = vendorLicenseManager.createLimit(limitEntity);
71 MapLimitEntityToLimitCreationDto mapper = new MapLimitEntityToLimitCreationDto();
72 LimitCreationDto createdLimitDto = mapper.applyMapping(createdLimit, LimitCreationDto.class);
73 return Response.ok(createdLimitDto != null ? createdLimitDto : null).build();
77 public Response listLimits(String vlmId, String versionId, String licenseKeyGroupId,
79 Version version = new Version(versionId);
81 .getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId));
83 Collection<LimitEntity> limits =
84 vendorLicenseManager.listLimits(vlmId, version, licenseKeyGroupId);
86 GenericCollectionWrapper<LimitEntityDto> result = new GenericCollectionWrapper<>();
87 MapLimitEntityToLimitDto outputMapper =
88 new MapLimitEntityToLimitDto();
89 for (LimitEntity limit : limits) {
90 result.add(outputMapper.applyMapping(limit, LimitEntityDto.class));
92 return Response.ok(result).build();
96 public Response updateLimit(LimitRequestDto request,
99 String licenseKeyGroupId,
102 Version version = new Version(versionId);
104 .getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId));
106 LimitEntity limitEntity =
107 new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class);
108 limitEntity.setVendorLicenseModelId(vlmId);
109 limitEntity.setVersion(version);
110 limitEntity.setEpLkgId(licenseKeyGroupId);
111 limitEntity.setId(limitId);
112 limitEntity.setParent(PARENT);
114 vendorLicenseManager.updateLimit(limitEntity);
115 return Response.ok().build();
119 * Delete License Key Group.
121 * @param vlmId the vlm id
122 * @param licenseKeyGroupId the license Key Group id
123 * @param limitId the limitId
124 * @param user the user
125 * @return the response
127 public Response deleteLimit(String vlmId, String versionId, String licenseKeyGroupId,
128 String limitId, String user) {
129 Version version = new Version(versionId);
131 .getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId));
133 LimitEntity limitInput = new LimitEntity();
134 limitInput.setVendorLicenseModelId(vlmId);
135 limitInput.setVersion(version);
136 limitInput.setEpLkgId(licenseKeyGroupId);
137 limitInput.setId(limitId);
138 limitInput.setParent(PARENT);
140 vendorLicenseManager.deleteLimit(limitInput);
141 return Response.ok().build();
145 public Response getLimit(String vlmId, String versionId, String licenseKeyGroupId,
146 String limitId, String user) {
147 Version version = new Version(versionId);
149 .getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId));
150 LimitEntity limitInput = new LimitEntity();
151 limitInput.setVendorLicenseModelId(vlmId);
152 limitInput.setVersion(version);
153 limitInput.setEpLkgId(licenseKeyGroupId);
154 limitInput.setId(limitId);
155 LimitEntity limit = vendorLicenseManager.getLimit(limitInput);
157 LimitEntityDto entitlementPoolEntityDto = limit == null ? null
158 : new MapLimitEntityToLimitDto().applyMapping(limit, LimitEntityDto.class);
159 return Response.ok(entitlementPoolEntityDto).build();