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;
24 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
25 import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory;
26 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
27 import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity;
28 import org.openecomp.sdc.versioning.dao.types.Version;
29 import org.openecomp.sdcrests.vendorlicense.rest.EntitlementPoolLimits;
30 import org.openecomp.sdcrests.vendorlicense.rest.mapping.LimitCreationDto;
31 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitEntityToLimitCreationDto;
32 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitEntityToLimitDto;
33 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitRequestDtoToLimitEntity;
34 import org.openecomp.sdcrests.vendorlicense.types.LimitEntityDto;
35 import org.openecomp.sdcrests.vendorlicense.types.LimitRequestDto;
36 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
37 import org.springframework.context.annotation.Scope;
38 import org.springframework.stereotype.Service;
40 import javax.inject.Named;
41 import javax.ws.rs.core.Response;
42 import java.util.Collection;
45 @Service("entitlementPoolLimits")
46 @Scope(value = "prototype")
47 public class EntitlementPoolLimitsImpl implements EntitlementPoolLimits {
48 private VendorLicenseManager vendorLicenseManager =
49 VendorLicenseManagerFactory.getInstance().createInterface();
51 private static final String PARENT = "EntitlementPool";
54 public Response createLimit(LimitRequestDto request,
57 String entitlementPoolId,
59 Version version = new Version(versionId);
61 .getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId));
63 LimitEntity limitEntity =
64 new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class);
65 limitEntity.setVendorLicenseModelId(vlmId);
66 limitEntity.setVersion(version);
67 limitEntity.setEpLkgId(entitlementPoolId);
68 limitEntity.setParent(PARENT);
70 LimitEntity createdLimit = vendorLicenseManager.createLimit(limitEntity);
71 MapLimitEntityToLimitCreationDto mapper = new MapLimitEntityToLimitCreationDto();
72 LimitCreationDto createdLimitDto = mapper.applyMapping(createdLimit, LimitCreationDto.class);
74 return Response.ok(createdLimitDto != null ? createdLimitDto : null).build();
78 public Response listLimits(String vlmId, String versionId, String entitlementPoolId, String
80 Version version = new Version(versionId);
82 .getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId));
84 Collection<LimitEntity> limits =
85 vendorLicenseManager.listLimits(vlmId, version, entitlementPoolId);
87 GenericCollectionWrapper<LimitEntityDto> result = new GenericCollectionWrapper<>();
88 MapLimitEntityToLimitDto outputMapper =
89 new MapLimitEntityToLimitDto();
90 for (LimitEntity limit : limits) {
91 result.add(outputMapper.applyMapping(limit, LimitEntityDto.class));
93 return Response.ok(result).build();
97 public Response getLimit(String vlmId, String versionId, String entitlementPoolId,
98 String limitId, String user) {
99 Version version = new Version(versionId);
101 .getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId));
102 LimitEntity limitInput = new LimitEntity();
103 limitInput.setVendorLicenseModelId(vlmId);
104 limitInput.setVersion(version);
105 limitInput.setEpLkgId(entitlementPoolId);
106 limitInput.setId(limitId);
107 LimitEntity limit = vendorLicenseManager.getLimit(limitInput);
109 LimitEntityDto entitlementPoolEntityDto = limit == null ? null :
110 new MapLimitEntityToLimitDto().applyMapping(limit, LimitEntityDto.class);
111 return Response.ok(entitlementPoolEntityDto).build();
115 public Response updateLimit(LimitRequestDto request,
118 String entitlementPoolId,
121 Version version = new Version(versionId);
123 .getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId));
125 LimitEntity limitEntity =
126 new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class);
127 limitEntity.setVendorLicenseModelId(vlmId);
128 limitEntity.setVersion(version);
129 limitEntity.setEpLkgId(entitlementPoolId);
130 limitEntity.setId(limitId);
131 limitEntity.setParent(PARENT);
133 vendorLicenseManager.updateLimit(limitEntity);
134 return Response.ok().build();
138 * Delete entitlement pool.
140 * @param vlmId the vlm id
141 * @param entitlementPoolId the entitlement pool id
142 * @param limitId the limitId
143 * @param user the user
144 * @return the response
146 public Response deleteLimit(String vlmId, String versionId, String entitlementPoolId,
147 String limitId, String user) {
148 Version version = new Version(versionId);
149 vendorLicenseManager.getEntitlementPool(
150 new EntitlementPoolEntity(vlmId, version, entitlementPoolId));
152 LimitEntity limitInput = new LimitEntity();
153 limitInput.setVendorLicenseModelId(vlmId);
154 limitInput.setVersion(version);
155 limitInput.setEpLkgId(entitlementPoolId);
156 limitInput.setId(limitId);
157 limitInput.setParent(PARENT);
159 vendorLicenseManager.deleteLimit(limitInput);
160 return Response.ok().build();