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.openecomp.sdcrests.wrappers.StringWrapperResponse;
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.context.annotation.Scope;
23 import org.springframework.stereotype.Service;
25 import java.util.Collection;
26 import javax.inject.Named;
27 import javax.ws.rs.core.Response;
30 @Service("entitlementPoolLimits")
31 @Scope(value = "prototype")
32 public class EntitlementPoolLimitsImpl implements EntitlementPoolLimits {
33 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
34 private VendorLicenseManager vendorLicenseManager =
35 VendorLicenseManagerFactory.getInstance().createInterface();
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 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
47 (versionId), entitlementPoolId), user);
49 LimitEntity limitEntity =
50 new MapLimitRequestDtoToLimitEntity()
51 .applyMapping(request, LimitEntity.class);
52 limitEntity.setEpLkgId(entitlementPoolId);
53 limitEntity.setVendorLicenseModelId(vlmId);
55 LimitEntity createdLimit = vendorLicenseManager.createLimit(limitEntity, user);
56 MapLimitEntityToLimitCreationDto mapper = new MapLimitEntityToLimitCreationDto();
57 LimitCreationDto createdLimitDto = mapper.applyMapping(createdLimit, LimitCreationDto
60 /*StringWrapperResponse result =
61 createdLimit != null ? new StringWrapperResponse(createdLimit.getId())
64 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId, "EP id", entitlementPoolId);
66 //return Response.ok(result).build();
67 return Response.ok(createdLimitDto != null ? createdLimitDto : null)
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 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
78 (versionId), entitlementPoolId), user);
80 Collection<LimitEntity> limits =
81 vendorLicenseManager.listLimits(vlmId, Version.valueOf(versionId), entitlementPoolId, user);
83 GenericCollectionWrapper<LimitEntityDto> result = new GenericCollectionWrapper<>();
84 MapLimitEntityToLimitDto outputMapper =
85 new MapLimitEntityToLimitDto();
86 for (LimitEntity limit : limits) {
87 result.add(outputMapper.applyMapping(limit, LimitEntityDto.class));
90 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId, "EP id", entitlementPoolId);
92 return Response.ok(result).build();
96 public Response getLimit( String vlmId, String versionId, String entitlementPoolId,
97 String limitId, String user) {
98 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id, Limit Id", vlmId, entitlementPoolId,
101 MdcUtil.initMdc(LoggerServiceName.Get_LIMIT.toString());
103 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
104 (versionId), entitlementPoolId), user);
105 LimitEntity epInput = new LimitEntity();
106 epInput.setVendorLicenseModelId(vlmId);
107 epInput.setVersion(Version.valueOf(versionId));
108 epInput.setEpLkgId(entitlementPoolId);
109 epInput.setId(limitId);
110 LimitEntity limit = vendorLicenseManager.getLimit(epInput, user);
112 LimitEntityDto entitlementPoolEntityDto = limit == null ? null :
113 new MapLimitEntityToLimitDto()
114 .applyMapping(limit, LimitEntityDto.class);
116 mdcDataDebugMessage.debugExitMessage("VLM id, EP id, Limit Id", vlmId, entitlementPoolId,
119 return Response.ok(entitlementPoolEntityDto).build();
123 public Response updateLimit(LimitRequestDto request,
126 String entitlementPoolId,
129 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId, "EP id", entitlementPoolId, "limit Id",
132 MdcUtil.initMdc(LoggerServiceName.Update_LIMIT.toString());
134 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
135 (versionId), entitlementPoolId), user);
137 LimitEntity limitEntity =
138 new MapLimitRequestDtoToLimitEntity()
139 .applyMapping(request, LimitEntity.class);
140 limitEntity.setEpLkgId(entitlementPoolId);
141 limitEntity.setVendorLicenseModelId(vlmId);
142 limitEntity.setId(limitId);
144 vendorLicenseManager.updateLimit(limitEntity, user);
146 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId, "EP id", entitlementPoolId, "limit Id",
149 return Response.ok().build();
153 * Delete entitlement pool.
155 * @param vlmId the vlm id
156 * @param entitlementPoolId the entitlement pool id
157 * @param limitId the limitId
158 * @param user the user
159 * @return the response
161 public Response deleteLimit(String vlmId, String versionId, String entitlementPoolId,
162 String limitId, String user) {
163 mdcDataDebugMessage.debugEntryMessage("VLM id, Verison Id, EP id, Limit Id", vlmId, versionId, entitlementPoolId, limitId);
165 MdcUtil.initMdc(LoggerServiceName.Delete_LIMIT.toString());
166 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
167 (versionId), entitlementPoolId), user);
169 LimitEntity limitInput = new LimitEntity();
170 limitInput.setVendorLicenseModelId(vlmId);
171 limitInput.setEpLkgId(entitlementPoolId);
172 limitInput.setId(limitId);
173 vendorLicenseManager.deleteLimit(limitInput, user);
175 mdcDataDebugMessage.debugExitMessage("VLM id, Verison Id, EP id, Limit Id", vlmId, versionId, entitlementPoolId, limitId);
177 return Response.ok().build();