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.EntitlementPoolEntity;
26 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;
34 import org.springframework.context.annotation.Scope;
35 import org.springframework.stereotype.Service;
37 import javax.inject.Named;
38 import javax.ws.rs.core.Response;
39 import java.util.Collection;
42 @Service("entitlementPools")
43 @Scope(value = "prototype")
44 public class EntitlementPoolsImpl implements EntitlementPools {
45 private VendorLicenseManager vendorLicenseManager =
46 VendorLicenseManagerFactory.getInstance().createInterface();
49 * List entitlement pools response.
51 * @param vlmId the vlm id
52 * @param versionId the version
53 * @param user the user
54 * @return the response
56 public Response listEntitlementPools(String vlmId, String versionId, String user) {
57 Collection<EntitlementPoolEntity> entitlementPools =
58 vendorLicenseManager.listEntitlementPools(vlmId, new Version(versionId));
60 GenericCollectionWrapper<EntitlementPoolEntityDto> result = new GenericCollectionWrapper<>();
61 MapEntitlementPoolEntityToEntitlementPoolEntityDto outputMapper =
62 new MapEntitlementPoolEntityToEntitlementPoolEntityDto();
63 for (EntitlementPoolEntity ep : entitlementPools) {
64 result.add(outputMapper.applyMapping(ep, EntitlementPoolEntityDto.class));
66 return Response.ok(result).build();
70 * Create entitlement pool response.
72 * @param request the request
73 * @param vlmId the vlm id
74 * @param user the user
75 * @return the response
77 public Response createEntitlementPool(EntitlementPoolRequestDto request, String vlmId,
78 String versionId, String user) {
79 EntitlementPoolEntity entitlementPoolEntity =
80 new MapEntitlementPoolRequestDtoToEntitlementPoolEntity()
81 .applyMapping(request, EntitlementPoolEntity.class);
82 entitlementPoolEntity.setVendorLicenseModelId(vlmId);
83 entitlementPoolEntity.setVersion(new Version(versionId));
85 EntitlementPoolEntity createdEntitlementPool =
86 vendorLicenseManager.createEntitlementPool(entitlementPoolEntity);
87 StringWrapperResponse result =
88 createdEntitlementPool != null ? new StringWrapperResponse(createdEntitlementPool.getId())
90 return Response.ok(result).build();
94 * Update entitlement pool response.
96 * @param request the request
97 * @param vlmId the vlm id
98 * @param entitlementPoolId the entitlement pool id
99 * @param user the user
100 * @return the response
102 public Response updateEntitlementPool(EntitlementPoolRequestDto request, String vlmId,
103 String versionId, String entitlementPoolId, String user) {
104 EntitlementPoolEntity entitlementPoolEntity =
105 new MapEntitlementPoolRequestDtoToEntitlementPoolEntity()
106 .applyMapping(request, EntitlementPoolEntity.class);
107 entitlementPoolEntity.setVendorLicenseModelId(vlmId);
108 entitlementPoolEntity.setVersion(new Version(versionId));
109 entitlementPoolEntity.setId(entitlementPoolId);
111 vendorLicenseManager.updateEntitlementPool(entitlementPoolEntity);
112 return Response.ok().build();
116 * Gets entitlement pool.
118 * @param vlmId the vlm id
119 * @param versionId the version id
120 * @param entitlementPoolId the entitlement pool id
121 * @param user the user
122 * @return the entitlement pool
124 public Response getEntitlementPool(String vlmId, String versionId, String entitlementPoolId,
126 EntitlementPoolEntity epInput = new EntitlementPoolEntity();
127 epInput.setVendorLicenseModelId(vlmId);
128 epInput.setVersion(new Version(versionId));
129 epInput.setId(entitlementPoolId);
130 EntitlementPoolEntity entitlementPool = vendorLicenseManager.getEntitlementPool(epInput);
132 EntitlementPoolEntityDto entitlementPoolEntityDto = entitlementPool == null ? null :
133 new MapEntitlementPoolEntityToEntitlementPoolEntityDto()
134 .applyMapping(entitlementPool, EntitlementPoolEntityDto.class);
135 return Response.ok(entitlementPoolEntityDto).build();
139 * Delete entitlement pool response.
141 * @param vlmId the vlm id
142 * @param entitlementPoolId the entitlement pool id
143 * @param user the user
144 * @return the response
146 public Response deleteEntitlementPool(String vlmId, String versionId, String entitlementPoolId,
148 EntitlementPoolEntity epInput = new EntitlementPoolEntity();
149 epInput.setVendorLicenseModelId(vlmId);
150 epInput.setId(entitlementPoolId);
151 epInput.setVersion(new Version(versionId));
152 vendorLicenseManager.deleteEntitlementPool(epInput);
153 return Response.ok().build();