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.logging.context.MdcUtil;
24 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
25 import org.openecomp.sdc.logging.types.LoggerServiceName;
26 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
27 import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory;
28 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
29 import org.openecomp.sdc.versioning.dao.types.Version;
30 import org.openecomp.sdcrests.vendorlicense.rest.EntitlementPools;
31 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapEntitlementPoolEntityToEntitlementPoolEntityDto;
32 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapEntitlementPoolRequestDtoToEntitlementPoolEntity;
33 import org.openecomp.sdcrests.vendorlicense.types.EntitlementPoolEntityDto;
34 import org.openecomp.sdcrests.vendorlicense.types.EntitlementPoolRequestDto;
35 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
36 import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.context.annotation.Scope;
39 import org.springframework.stereotype.Service;
41 import javax.inject.Named;
42 import javax.ws.rs.core.Response;
43 import java.util.Collection;
46 @Service("entitlementPools")
47 @Scope(value = "prototype")
48 public class EntitlementPoolsImpl implements EntitlementPools {
50 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
51 private VendorLicenseManager vendorLicenseManager =
52 VendorLicenseManagerFactory.getInstance().createInterface();
55 * List entitlement pools response.
57 * @param vlmId the vlm id
58 * @param versionId the version
59 * @param user the user
60 * @return the response
62 public Response listEntitlementPools(String vlmId, String versionId, String user) {
63 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
65 MdcUtil.initMdc(LoggerServiceName.List_EP.toString());
66 Collection<EntitlementPoolEntity> entitlementPools =
67 vendorLicenseManager.listEntitlementPools(vlmId, Version.valueOf(versionId), user);
69 GenericCollectionWrapper<EntitlementPoolEntityDto> result = new GenericCollectionWrapper<>();
70 MapEntitlementPoolEntityToEntitlementPoolEntityDto outputMapper =
71 new MapEntitlementPoolEntityToEntitlementPoolEntityDto();
72 for (EntitlementPoolEntity ep : entitlementPools) {
73 result.add(outputMapper.applyMapping(ep, EntitlementPoolEntityDto.class));
76 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
78 return Response.ok(result).build();
82 * Create entitlement pool response.
84 * @param request the request
85 * @param vlmId the vlm id
86 * @param user the user
87 * @return the response
89 public Response createEntitlementPool(EntitlementPoolRequestDto request, String vlmId,
90 String versionId, String user) {
92 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
94 MdcUtil.initMdc(LoggerServiceName.Create_EP.toString());
95 EntitlementPoolEntity entitlementPoolEntity =
96 new MapEntitlementPoolRequestDtoToEntitlementPoolEntity()
97 .applyMapping(request, EntitlementPoolEntity.class);
98 entitlementPoolEntity.setVendorLicenseModelId(vlmId);
100 EntitlementPoolEntity createdEntitlementPool =
101 vendorLicenseManager.createEntitlementPool(entitlementPoolEntity, user);
102 StringWrapperResponse result =
103 createdEntitlementPool != null ? new StringWrapperResponse(createdEntitlementPool.getId())
106 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
108 return Response.ok(result).build();
112 * Update entitlement pool response.
114 * @param request the request
115 * @param vlmId the vlm id
116 * @param entitlementPoolId the entitlement pool id
117 * @param user the user
118 * @return the response
120 public Response updateEntitlementPool(EntitlementPoolRequestDto request, String vlmId,
121 String versionId, String entitlementPoolId, String user) {
123 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", vlmId, entitlementPoolId);
125 MdcUtil.initMdc(LoggerServiceName.Update_EP.toString());
126 EntitlementPoolEntity entitlementPoolEntity =
127 new MapEntitlementPoolRequestDtoToEntitlementPoolEntity()
128 .applyMapping(request, EntitlementPoolEntity.class);
129 entitlementPoolEntity.setVendorLicenseModelId(vlmId);
130 entitlementPoolEntity.setId(entitlementPoolId);
132 vendorLicenseManager.updateEntitlementPool(entitlementPoolEntity, user);
134 mdcDataDebugMessage.debugExitMessage("VLM id, EP id", vlmId, entitlementPoolId);
136 return Response.ok().build();
140 * Gets entitlement pool.
142 * @param vlmId the vlm id
143 * @param version the version
144 * @param entitlementPoolId the entitlement pool id
145 * @param user the user
146 * @return the entitlement pool
148 public Response getEntitlementPool(String vlmId, String version, String entitlementPoolId,
151 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", vlmId, entitlementPoolId);
153 MdcUtil.initMdc(LoggerServiceName.Get_EP.toString());
154 EntitlementPoolEntity epInput = new EntitlementPoolEntity();
155 epInput.setVendorLicenseModelId(vlmId);
156 epInput.setVersion(Version.valueOf(version));
157 epInput.setId(entitlementPoolId);
158 EntitlementPoolEntity entitlementPool = vendorLicenseManager.getEntitlementPool(epInput, user);
160 EntitlementPoolEntityDto entitlementPoolEntityDto = entitlementPool == null ? null :
161 new MapEntitlementPoolEntityToEntitlementPoolEntityDto()
162 .applyMapping(entitlementPool, EntitlementPoolEntityDto.class);
164 mdcDataDebugMessage.debugExitMessage("VLM id, EP id", vlmId, entitlementPoolId);
166 return Response.ok(entitlementPoolEntityDto).build();
170 * Delete entitlement pool response.
172 * @param vlmId the vlm id
173 * @param entitlementPoolId the entitlement pool id
174 * @param user the user
175 * @return the response
177 public Response deleteEntitlementPool(String vlmId, String versionId, String entitlementPoolId,
180 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", vlmId, entitlementPoolId);
182 MdcUtil.initMdc(LoggerServiceName.Delete_EP.toString());
183 EntitlementPoolEntity epInput = new EntitlementPoolEntity();
184 epInput.setVendorLicenseModelId(vlmId);
185 epInput.setId(entitlementPoolId);
186 vendorLicenseManager.deleteEntitlementPool(epInput, user);
188 mdcDataDebugMessage.debugExitMessage("VLM id, EP id", vlmId, entitlementPoolId);
190 return Response.ok().build();