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.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();
50 private VendorLicenseManager vendorLicenseManager =
51 VendorLicenseManagerFactory.getInstance().createInterface();
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, new Version(versionId));
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);
98 entitlementPoolEntity.setVersion(new Version(versionId));
100 EntitlementPoolEntity createdEntitlementPool =
101 vendorLicenseManager.createEntitlementPool(entitlementPoolEntity);
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.setVersion(new Version(versionId));
131 entitlementPoolEntity.setId(entitlementPoolId);
133 vendorLicenseManager.updateEntitlementPool(entitlementPoolEntity);
135 mdcDataDebugMessage.debugExitMessage("VLM id, EP id", vlmId, entitlementPoolId);
137 return Response.ok().build();
141 * Gets entitlement pool.
143 * @param vlmId the vlm id
144 * @param versionId the version id
145 * @param entitlementPoolId the entitlement pool id
146 * @param user the user
147 * @return the entitlement pool
149 public Response getEntitlementPool(String vlmId, String versionId, String entitlementPoolId,
152 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", vlmId, entitlementPoolId);
154 MdcUtil.initMdc(LoggerServiceName.Get_EP.toString());
155 EntitlementPoolEntity epInput = new EntitlementPoolEntity();
156 epInput.setVendorLicenseModelId(vlmId);
157 epInput.setVersion(new Version(versionId));
158 epInput.setId(entitlementPoolId);
159 EntitlementPoolEntity entitlementPool = vendorLicenseManager.getEntitlementPool(epInput);
161 EntitlementPoolEntityDto entitlementPoolEntityDto = entitlementPool == null ? null :
162 new MapEntitlementPoolEntityToEntitlementPoolEntityDto()
163 .applyMapping(entitlementPool, EntitlementPoolEntityDto.class);
165 mdcDataDebugMessage.debugExitMessage("VLM id, EP id", vlmId, entitlementPoolId);
167 return Response.ok(entitlementPoolEntityDto).build();
171 * Delete entitlement pool response.
173 * @param vlmId the vlm id
174 * @param entitlementPoolId the entitlement pool id
175 * @param user the user
176 * @return the response
178 public Response deleteEntitlementPool(String vlmId, String versionId, String entitlementPoolId,
181 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", vlmId, entitlementPoolId);
183 MdcUtil.initMdc(LoggerServiceName.Delete_EP.toString());
184 EntitlementPoolEntity epInput = new EntitlementPoolEntity();
185 epInput.setVendorLicenseModelId(vlmId);
186 epInput.setId(entitlementPoolId);
187 epInput.setVersion(new Version(versionId));
188 vendorLicenseManager.deleteEntitlementPool(epInput);
190 mdcDataDebugMessage.debugExitMessage("VLM id, EP id", vlmId, entitlementPoolId);
192 return Response.ok().build();