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.dao.types.EntitlementPoolEntity;
28 import org.openecomp.sdc.versioning.dao.types.Version;
29 import org.openecomp.sdcrests.vendorlicense.rest.EntitlementPools;
30 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapEntitlementPoolEntityToEntitlementPoolEntityDto;
31 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapEntitlementPoolRequestDtoToEntitlementPoolEntity;
32 import org.openecomp.sdcrests.vendorlicense.types.EntitlementPoolEntityDto;
33 import org.openecomp.sdcrests.vendorlicense.types.EntitlementPoolRequestDto;
34 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
35 import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
36 import org.springframework.beans.factory.annotation.Autowired;
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("entitlementPools")
46 @Scope(value = "prototype")
47 public class EntitlementPoolsImpl implements EntitlementPools {
49 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
51 private VendorLicenseManager vendorLicenseManager;
54 * List entitlement pools response.
56 * @param vlmId the vlm id
57 * @param versionId the version
58 * @param user the user
59 * @return the response
61 public Response listEntitlementPools(String vlmId, String versionId, String user) {
62 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
64 MdcUtil.initMdc(LoggerServiceName.List_EP.toString());
65 Collection<EntitlementPoolEntity> entitlementPools =
66 vendorLicenseManager.listEntitlementPools(vlmId, Version.valueOf(versionId), user);
68 GenericCollectionWrapper<EntitlementPoolEntityDto> result = new GenericCollectionWrapper<>();
69 MapEntitlementPoolEntityToEntitlementPoolEntityDto outputMapper =
70 new MapEntitlementPoolEntityToEntitlementPoolEntityDto();
71 for (EntitlementPoolEntity ep : entitlementPools) {
72 result.add(outputMapper.applyMapping(ep, EntitlementPoolEntityDto.class));
75 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
77 return Response.ok(result).build();
81 * Create entitlement pool response.
83 * @param request the request
84 * @param vlmId the vlm id
85 * @param user the user
86 * @return the response
88 public Response createEntitlementPool(EntitlementPoolRequestDto request, String vlmId,
89 String versionId, String user) {
91 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
93 MdcUtil.initMdc(LoggerServiceName.Create_EP.toString());
94 EntitlementPoolEntity entitlementPoolEntity =
95 new MapEntitlementPoolRequestDtoToEntitlementPoolEntity()
96 .applyMapping(request, EntitlementPoolEntity.class);
97 entitlementPoolEntity.setVendorLicenseModelId(vlmId);
99 EntitlementPoolEntity createdEntitlementPool =
100 vendorLicenseManager.createEntitlementPool(entitlementPoolEntity, user);
101 StringWrapperResponse result =
102 createdEntitlementPool != null ? new StringWrapperResponse(createdEntitlementPool.getId())
105 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
107 return Response.ok(result).build();
111 * Update entitlement pool response.
113 * @param request the request
114 * @param vlmId the vlm id
115 * @param entitlementPoolId the entitlement pool id
116 * @param user the user
117 * @return the response
119 public Response updateEntitlementPool(EntitlementPoolRequestDto request, String vlmId,
120 String versionId, String entitlementPoolId, String user) {
122 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", vlmId, entitlementPoolId);
124 MdcUtil.initMdc(LoggerServiceName.Update_EP.toString());
125 EntitlementPoolEntity entitlementPoolEntity =
126 new MapEntitlementPoolRequestDtoToEntitlementPoolEntity()
127 .applyMapping(request, EntitlementPoolEntity.class);
128 entitlementPoolEntity.setVendorLicenseModelId(vlmId);
129 entitlementPoolEntity.setId(entitlementPoolId);
131 vendorLicenseManager.updateEntitlementPool(entitlementPoolEntity, user);
133 mdcDataDebugMessage.debugExitMessage("VLM id, EP id", vlmId, entitlementPoolId);
135 return Response.ok().build();
139 * Gets entitlement pool.
141 * @param vlmId the vlm id
142 * @param version the version
143 * @param entitlementPoolId the entitlement pool id
144 * @param user the user
145 * @return the entitlement pool
147 public Response getEntitlementPool(String vlmId, String version, String entitlementPoolId,
150 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", vlmId, entitlementPoolId);
152 MdcUtil.initMdc(LoggerServiceName.Get_EP.toString());
153 EntitlementPoolEntity epInput = new EntitlementPoolEntity();
154 epInput.setVendorLicenseModelId(vlmId);
155 epInput.setVersion(Version.valueOf(version));
156 epInput.setId(entitlementPoolId);
157 EntitlementPoolEntity entitlementPool = vendorLicenseManager.getEntitlementPool(epInput, user);
159 EntitlementPoolEntityDto entitlementPoolEntityDto = entitlementPool == null ? null :
160 new MapEntitlementPoolEntityToEntitlementPoolEntityDto()
161 .applyMapping(entitlementPool, EntitlementPoolEntityDto.class);
163 mdcDataDebugMessage.debugExitMessage("VLM id, EP id", vlmId, entitlementPoolId);
165 return Response.ok(entitlementPoolEntityDto).build();
169 * Delete entitlement pool response.
171 * @param vlmId the vlm id
172 * @param entitlementPoolId the entitlement pool id
173 * @param user the user
174 * @return the response
176 public Response deleteEntitlementPool(String vlmId, String versionId, String entitlementPoolId,
179 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", vlmId, entitlementPoolId);
181 MdcUtil.initMdc(LoggerServiceName.Delete_EP.toString());
182 EntitlementPoolEntity epInput = new EntitlementPoolEntity();
183 epInput.setVendorLicenseModelId(vlmId);
184 epInput.setId(entitlementPoolId);
185 vendorLicenseManager.deleteEntitlementPool(epInput, user);
187 mdcDataDebugMessage.debugExitMessage("VLM id, EP id", vlmId, entitlementPoolId);
189 return Response.ok().build();