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.dao.types.EntitlementPoolEntity;
9 import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity;
10 import org.openecomp.sdc.versioning.dao.types.Version;
11 import org.openecomp.sdcrests.vendorlicense.rest.EntitlementPoolLimits;
12 import org.openecomp.sdcrests.vendorlicense.rest.mapping.LimitCreationDto;
13 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitEntityToLimitCreationDto;
14 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitEntityToLimitDto;
15 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitRequestDtoToLimitEntity;
16 import org.openecomp.sdcrests.vendorlicense.types.LimitEntityDto;
17 import org.openecomp.sdcrests.vendorlicense.types.LimitRequestDto;
18 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
19 import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
20 import org.springframework.beans.factory.annotation.Autowired;
21 import org.springframework.context.annotation.Scope;
22 import org.springframework.stereotype.Service;
24 import java.util.Collection;
25 import javax.inject.Named;
26 import javax.ws.rs.core.Response;
29 @Service("entitlementPoolLimits")
30 @Scope(value = "prototype")
31 public class EntitlementPoolLimitsImpl implements EntitlementPoolLimits {
32 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
34 private VendorLicenseManager vendorLicenseManager;
37 public Response createLimit(LimitRequestDto request,
40 String entitlementPoolId,
42 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId, "EP id", entitlementPoolId);
44 MdcUtil.initMdc(LoggerServiceName.Create_LIMIT.toString());
45 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
46 (versionId), entitlementPoolId), user);
48 LimitEntity limitEntity =
49 new MapLimitRequestDtoToLimitEntity()
50 .applyMapping(request, LimitEntity.class);
51 limitEntity.setEpLkgId(entitlementPoolId);
52 limitEntity.setVendorLicenseModelId(vlmId);
54 LimitEntity createdLimit = vendorLicenseManager.createLimit(limitEntity, user);
55 MapLimitEntityToLimitCreationDto mapper = new MapLimitEntityToLimitCreationDto();
56 LimitCreationDto createdLimitDto = mapper.applyMapping(createdLimit, LimitCreationDto
59 /*StringWrapperResponse result =
60 createdLimit != null ? new StringWrapperResponse(createdLimit.getId())
63 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId, "EP id", entitlementPoolId);
65 //return Response.ok(result).build();
66 return Response.ok(createdLimitDto != null ? createdLimitDto : null)
71 public Response listLimits(String vlmId, String versionId, String entitlementPoolId, String
73 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId, "EP id", entitlementPoolId);
75 MdcUtil.initMdc(LoggerServiceName.List_EP.toString());
76 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
77 (versionId), entitlementPoolId), user);
79 Collection<LimitEntity> limits =
80 vendorLicenseManager.listLimits(vlmId, Version.valueOf(versionId), entitlementPoolId, user);
82 GenericCollectionWrapper<LimitEntityDto> result = new GenericCollectionWrapper<>();
83 MapLimitEntityToLimitDto outputMapper =
84 new MapLimitEntityToLimitDto();
85 for (LimitEntity limit : limits) {
86 result.add(outputMapper.applyMapping(limit, LimitEntityDto.class));
89 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId, "EP id", entitlementPoolId);
91 return Response.ok(result).build();
95 public Response getLimit( String vlmId, String versionId, String entitlementPoolId,
96 String limitId, String user) {
97 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id, Limit Id", vlmId, entitlementPoolId,
100 MdcUtil.initMdc(LoggerServiceName.Get_LIMIT.toString());
102 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
103 (versionId), entitlementPoolId), user);
104 LimitEntity epInput = new LimitEntity();
105 epInput.setVendorLicenseModelId(vlmId);
106 epInput.setVersion(Version.valueOf(versionId));
107 epInput.setEpLkgId(entitlementPoolId);
108 epInput.setId(limitId);
109 LimitEntity limit = vendorLicenseManager.getLimit(epInput, user);
111 LimitEntityDto entitlementPoolEntityDto = limit == null ? null :
112 new MapLimitEntityToLimitDto()
113 .applyMapping(limit, LimitEntityDto.class);
115 mdcDataDebugMessage.debugExitMessage("VLM id, EP id, Limit Id", vlmId, entitlementPoolId,
118 return Response.ok(entitlementPoolEntityDto).build();
122 public Response updateLimit(LimitRequestDto request,
125 String entitlementPoolId,
128 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId, "EP id", entitlementPoolId, "limit Id",
131 MdcUtil.initMdc(LoggerServiceName.Update_LIMIT.toString());
133 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
134 (versionId), entitlementPoolId), user);
136 LimitEntity limitEntity =
137 new MapLimitRequestDtoToLimitEntity()
138 .applyMapping(request, LimitEntity.class);
139 limitEntity.setEpLkgId(entitlementPoolId);
140 limitEntity.setVendorLicenseModelId(vlmId);
141 limitEntity.setId(limitId);
143 vendorLicenseManager.updateLimit(limitEntity, user);
145 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId, "EP id", entitlementPoolId, "limit Id",
148 return Response.ok().build();
152 * Delete entitlement pool.
154 * @param vlmId the vlm id
155 * @param entitlementPoolId the entitlement pool id
156 * @param limitId the limitId
157 * @param user the user
158 * @return the response
160 public Response deleteLimit(String vlmId, String versionId, String entitlementPoolId,
161 String limitId, String user) {
162 mdcDataDebugMessage.debugEntryMessage("VLM id, Verison Id, EP id, Limit Id", vlmId, versionId, entitlementPoolId, limitId);
164 MdcUtil.initMdc(LoggerServiceName.Delete_LIMIT.toString());
165 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
166 (versionId), entitlementPoolId), user);
168 LimitEntity limitInput = new LimitEntity();
169 limitInput.setVendorLicenseModelId(vlmId);
170 limitInput.setEpLkgId(entitlementPoolId);
171 limitInput.setId(limitId);
172 vendorLicenseManager.deleteLimit(limitInput, user);
174 mdcDataDebugMessage.debugExitMessage("VLM id, Verison Id, EP id, Limit Id", vlmId, versionId, entitlementPoolId, limitId);
176 return Response.ok().build();