1 package org.openecomp.sdcrests.vendorlicense.rest.services;
4 import org.openecomp.sdc.logging.context.MdcUtil;
5 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
6 import org.openecomp.sdc.logging.types.LoggerServiceName;
7 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
8 import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory;
9 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
10 import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity;
11 import org.openecomp.sdc.versioning.dao.types.Version;
12 import org.openecomp.sdcrests.vendorlicense.rest.EntitlementPoolLimits;
13 import org.openecomp.sdcrests.vendorlicense.rest.mapping.LimitCreationDto;
14 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitEntityToLimitCreationDto;
15 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitEntityToLimitDto;
16 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitRequestDtoToLimitEntity;
17 import org.openecomp.sdcrests.vendorlicense.types.LimitEntityDto;
18 import org.openecomp.sdcrests.vendorlicense.types.LimitRequestDto;
19 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
20 import org.springframework.context.annotation.Scope;
21 import org.springframework.stereotype.Service;
23 import javax.inject.Named;
24 import javax.ws.rs.core.Response;
25 import java.util.Collection;
28 @Service("entitlementPoolLimits")
29 @Scope(value = "prototype")
30 public class EntitlementPoolLimitsImpl implements EntitlementPoolLimits {
31 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
32 private VendorLicenseManager vendorLicenseManager =
33 VendorLicenseManagerFactory.getInstance().createInterface();
35 public static final String parent = "EntitlementPool";
38 public Response createLimit(LimitRequestDto request,
41 String entitlementPoolId,
43 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId, "EP id", entitlementPoolId);
45 MdcUtil.initMdc(LoggerServiceName.Create_LIMIT.toString());
46 Version version = new Version(versionId);
48 .getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId));
50 LimitEntity limitEntity =
51 new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class);
52 limitEntity.setVendorLicenseModelId(vlmId);
53 limitEntity.setVersion(version);
54 limitEntity.setEpLkgId(entitlementPoolId);
55 limitEntity.setParent(parent);
57 LimitEntity createdLimit = vendorLicenseManager.createLimit(limitEntity);
58 MapLimitEntityToLimitCreationDto mapper = new MapLimitEntityToLimitCreationDto();
59 LimitCreationDto createdLimitDto = mapper.applyMapping(createdLimit, LimitCreationDto.class);
61 /*StringWrapperResponse result =
62 createdLimit != null ? new StringWrapperResponse(createdLimit.getId())
65 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId, "EP id", entitlementPoolId);
67 //return Response.ok(result).build();
68 return Response.ok(createdLimitDto != null ? createdLimitDto : null).build();
72 public Response listLimits(String vlmId, String versionId, String entitlementPoolId, String
74 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId, "EP id", entitlementPoolId);
76 MdcUtil.initMdc(LoggerServiceName.List_EP.toString());
77 Version version = new Version(versionId);
79 .getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId));
81 Collection<LimitEntity> limits =
82 vendorLicenseManager.listLimits(vlmId, version, entitlementPoolId);
84 GenericCollectionWrapper<LimitEntityDto> result = new GenericCollectionWrapper<>();
85 MapLimitEntityToLimitDto outputMapper =
86 new MapLimitEntityToLimitDto();
87 for (LimitEntity limit : limits) {
88 result.add(outputMapper.applyMapping(limit, LimitEntityDto.class));
91 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId, "EP id", entitlementPoolId);
93 return Response.ok(result).build();
97 public Response getLimit(String vlmId, String versionId, String entitlementPoolId,
98 String limitId, String user) {
100 .debugEntryMessage("VLM id, EP id, Limit Id", vlmId, entitlementPoolId, limitId);
102 MdcUtil.initMdc(LoggerServiceName.Get_LIMIT.toString());
104 Version version = new Version(versionId);
106 .getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId));
107 LimitEntity limitInput = new LimitEntity();
108 limitInput.setVendorLicenseModelId(vlmId);
109 limitInput.setVersion(version);
110 limitInput.setEpLkgId(entitlementPoolId);
111 limitInput.setId(limitId);
112 LimitEntity limit = vendorLicenseManager.getLimit(limitInput);
114 LimitEntityDto entitlementPoolEntityDto = limit == null ? null :
115 new MapLimitEntityToLimitDto().applyMapping(limit, LimitEntityDto.class);
118 .debugExitMessage("VLM id, EP id, Limit Id", vlmId, entitlementPoolId, limitId);
120 return Response.ok(entitlementPoolEntityDto).build();
124 public Response updateLimit(LimitRequestDto request,
127 String entitlementPoolId,
131 .debugEntryMessage("VLM id", vlmId, "EP id", entitlementPoolId, "limit Id", limitId);
133 MdcUtil.initMdc(LoggerServiceName.Update_LIMIT.toString());
135 Version version = new Version(versionId);
137 .getEntitlementPool(new EntitlementPoolEntity(vlmId, version, entitlementPoolId));
139 LimitEntity limitEntity =
140 new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class);
141 limitEntity.setVendorLicenseModelId(vlmId);
142 limitEntity.setVersion(version);
143 limitEntity.setEpLkgId(entitlementPoolId);
144 limitEntity.setId(limitId);
145 limitEntity.setParent(parent);
147 vendorLicenseManager.updateLimit(limitEntity);
150 .debugExitMessage("VLM id", vlmId, "EP id", entitlementPoolId, "limit Id", limitId);
152 return Response.ok().build();
156 * Delete entitlement pool.
158 * @param vlmId the vlm id
159 * @param entitlementPoolId the entitlement pool id
160 * @param limitId the limitId
161 * @param user the user
162 * @return the response
164 public Response deleteLimit(String vlmId, String versionId, String entitlementPoolId,
165 String limitId, String user) {
166 mdcDataDebugMessage.debugEntryMessage("VLM id, Verison Id, EP id, Limit Id", vlmId, versionId,
167 entitlementPoolId, limitId);
168 MdcUtil.initMdc(LoggerServiceName.Delete_LIMIT.toString());
170 Version version = new Version(versionId);
171 vendorLicenseManager.getEntitlementPool(
172 new EntitlementPoolEntity(vlmId, version, entitlementPoolId));
174 LimitEntity limitInput = new LimitEntity();
175 limitInput.setVendorLicenseModelId(vlmId);
176 limitInput.setVersion(version);
177 limitInput.setEpLkgId(entitlementPoolId);
178 limitInput.setId(limitId);
179 limitInput.setParent(parent);
181 vendorLicenseManager.deleteLimit(limitInput);
183 mdcDataDebugMessage.debugExitMessage("VLM id, Verison Id, EP id, Limit Id", vlmId, versionId,
184 entitlementPoolId, limitId);
186 return Response.ok().build();