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.EntitlementPoolEntity;
25 import org.openecomp.sdc.versioning.dao.types.Version;
27 import org.openecomp.sdcrests.vendorlicense.rest.EntitlementPools;
28 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapEntitlementPoolEntityToEntitlementPoolEntityDto;
29 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapEntitlementPoolRequestDtoToEntitlementPoolEntity;
30 import org.openecomp.sdcrests.vendorlicense.types.EntitlementPoolEntityDto;
31 import org.openecomp.sdcrests.vendorlicense.types.EntitlementPoolRequestDto;
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;
39 import java.util.Collection;
40 import javax.inject.Named;
41 import javax.ws.rs.core.Response;
44 @Service("entitlementPools")
45 @Scope(value = "prototype")
46 public class EntitlementPoolsImpl implements EntitlementPools {
49 private VendorLicenseManager vendorLicenseManager;
52 * List entitlement pools response.
54 * @param vlmId the vlm id
55 * @param version the version
56 * @param user the user
57 * @return the response
59 public Response listEntitlementPools(String vlmId, String version, String user) {
60 Collection<EntitlementPoolEntity> entitlementPools =
61 vendorLicenseManager.listEntitlementPools(vlmId, Version.valueOf(version), user);
63 GenericCollectionWrapper<EntitlementPoolEntityDto> result = new GenericCollectionWrapper<>();
64 MapEntitlementPoolEntityToEntitlementPoolEntityDto outputMapper =
65 new MapEntitlementPoolEntityToEntitlementPoolEntityDto();
66 for (EntitlementPoolEntity ep : entitlementPools) {
67 result.add(outputMapper.applyMapping(ep, EntitlementPoolEntityDto.class));
70 return Response.ok(result).build();
74 * Create entitlement pool response.
76 * @param request the request
77 * @param vlmId the vlm id
78 * @param user the user
79 * @return the response
81 public Response createEntitlementPool(EntitlementPoolRequestDto request, String vlmId,
83 EntitlementPoolEntity entitlementPoolEntity =
84 new MapEntitlementPoolRequestDtoToEntitlementPoolEntity()
85 .applyMapping(request, EntitlementPoolEntity.class);
86 entitlementPoolEntity.setVendorLicenseModelId(vlmId);
88 EntitlementPoolEntity createdEntitlementPool =
89 vendorLicenseManager.createEntitlementPool(entitlementPoolEntity, user);
90 StringWrapperResponse result =
91 createdEntitlementPool != null ? new StringWrapperResponse(createdEntitlementPool.getId())
94 return Response.ok(result).build();
98 * Update entitlement pool response.
100 * @param request the request
101 * @param vlmId the vlm id
102 * @param entitlementPoolId the entitlement pool id
103 * @param user the user
104 * @return the response
106 public Response updateEntitlementPool(EntitlementPoolRequestDto request, String vlmId,
107 String entitlementPoolId, String user) {
108 EntitlementPoolEntity entitlementPoolEntity =
109 new MapEntitlementPoolRequestDtoToEntitlementPoolEntity()
110 .applyMapping(request, EntitlementPoolEntity.class);
112 entitlementPoolEntity.setVendorLicenseModelId(vlmId);
113 entitlementPoolEntity.setId(entitlementPoolId);
115 vendorLicenseManager.updateEntitlementPool(entitlementPoolEntity, user);
116 return Response.ok().build();
120 * Gets entitlement pool.
122 * @param vlmId the vlm id
123 * @param version the version
124 * @param entitlementPoolId the entitlement pool id
125 * @param user the user
126 * @return the entitlement pool
128 public Response getEntitlementPool(String vlmId, String version, String entitlementPoolId,
130 EntitlementPoolEntity epInput = new EntitlementPoolEntity();
131 epInput.setVendorLicenseModelId(vlmId);
132 epInput.setVersion(Version.valueOf(version));
133 epInput.setId(entitlementPoolId);
134 EntitlementPoolEntity entitlementPool = vendorLicenseManager.getEntitlementPool(epInput, user);
136 EntitlementPoolEntityDto entitlementPoolEntityDto = entitlementPool == null ? null :
137 new MapEntitlementPoolEntityToEntitlementPoolEntityDto()
138 .applyMapping(entitlementPool, EntitlementPoolEntityDto.class);
139 return Response.ok(entitlementPoolEntityDto).build();
143 * Delete entitlement pool response.
145 * @param vlmId the vlm id
146 * @param entitlementPoolId the entitlement pool id
147 * @param user the user
148 * @return the response
150 public Response deleteEntitlementPool(String vlmId, String entitlementPoolId, String user) {
151 EntitlementPoolEntity epInput = new EntitlementPoolEntity();
152 epInput.setVendorLicenseModelId(vlmId);
153 epInput.setId(entitlementPoolId);
154 vendorLicenseManager.deleteEntitlementPool(epInput, user);
155 return Response.ok().build();