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();
37 public static final String parent = "EntitlementPool";
40 public Response createLimit(LimitRequestDto request,
43 String entitlementPoolId,
45 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId, "EP id", entitlementPoolId);
47 MdcUtil.initMdc(LoggerServiceName.Create_LIMIT.toString());
48 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
49 (versionId), entitlementPoolId), user);
51 LimitEntity limitEntity =
52 new MapLimitRequestDtoToLimitEntity()
53 .applyMapping(request, LimitEntity.class);
54 limitEntity.setEpLkgId(entitlementPoolId);
55 limitEntity.setVendorLicenseModelId(vlmId);
56 limitEntity.setParent(parent);
58 LimitEntity createdLimit = vendorLicenseManager.createLimit(limitEntity, user);
59 MapLimitEntityToLimitCreationDto mapper = new MapLimitEntityToLimitCreationDto();
60 LimitCreationDto createdLimitDto = mapper.applyMapping(createdLimit, LimitCreationDto
63 /*StringWrapperResponse result =
64 createdLimit != null ? new StringWrapperResponse(createdLimit.getId())
67 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId, "EP id", entitlementPoolId);
69 //return Response.ok(result).build();
70 return Response.ok(createdLimitDto != null ? createdLimitDto : null)
75 public Response listLimits(String vlmId, String versionId, String entitlementPoolId, String
77 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId, "EP id", entitlementPoolId);
79 MdcUtil.initMdc(LoggerServiceName.List_EP.toString());
80 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
81 (versionId), entitlementPoolId), user);
83 Collection<LimitEntity> limits =
84 vendorLicenseManager.listLimits(vlmId, Version.valueOf(versionId), entitlementPoolId, user);
86 GenericCollectionWrapper<LimitEntityDto> result = new GenericCollectionWrapper<>();
87 MapLimitEntityToLimitDto outputMapper =
88 new MapLimitEntityToLimitDto();
89 for (LimitEntity limit : limits) {
90 result.add(outputMapper.applyMapping(limit, LimitEntityDto.class));
93 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId, "EP id", entitlementPoolId);
95 return Response.ok(result).build();
99 public Response getLimit( String vlmId, String versionId, String entitlementPoolId,
100 String limitId, String user) {
101 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id, Limit Id", vlmId, entitlementPoolId,
104 MdcUtil.initMdc(LoggerServiceName.Get_LIMIT.toString());
106 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
107 (versionId), entitlementPoolId), user);
108 LimitEntity epInput = new LimitEntity();
109 epInput.setVendorLicenseModelId(vlmId);
110 epInput.setVersion(Version.valueOf(versionId));
111 epInput.setEpLkgId(entitlementPoolId);
112 epInput.setId(limitId);
113 LimitEntity limit = vendorLicenseManager.getLimit(epInput, user);
115 LimitEntityDto entitlementPoolEntityDto = limit == null ? null :
116 new MapLimitEntityToLimitDto()
117 .applyMapping(limit, LimitEntityDto.class);
119 mdcDataDebugMessage.debugExitMessage("VLM id, EP id, Limit Id", vlmId, entitlementPoolId,
122 return Response.ok(entitlementPoolEntityDto).build();
126 public Response updateLimit(LimitRequestDto request,
129 String entitlementPoolId,
132 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId, "EP id", entitlementPoolId, "limit Id",
135 MdcUtil.initMdc(LoggerServiceName.Update_LIMIT.toString());
137 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
138 (versionId), entitlementPoolId), user);
140 LimitEntity limitEntity =
141 new MapLimitRequestDtoToLimitEntity()
142 .applyMapping(request, LimitEntity.class);
143 limitEntity.setEpLkgId(entitlementPoolId);
144 limitEntity.setVendorLicenseModelId(vlmId);
145 limitEntity.setId(limitId);
146 limitEntity.setParent(parent);
148 vendorLicenseManager.updateLimit(limitEntity, user);
150 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId, "EP id", entitlementPoolId, "limit Id",
153 return Response.ok().build();
157 * Delete entitlement pool.
159 * @param vlmId the vlm id
160 * @param entitlementPoolId the entitlement pool id
161 * @param limitId the limitId
162 * @param user the user
163 * @return the response
165 public Response deleteLimit(String vlmId, String versionId, String entitlementPoolId,
166 String limitId, String user) {
167 mdcDataDebugMessage.debugEntryMessage("VLM id, Verison Id, EP id, Limit Id", vlmId, versionId, entitlementPoolId, limitId);
169 MdcUtil.initMdc(LoggerServiceName.Delete_LIMIT.toString());
170 vendorLicenseManager.getEntitlementPool(new EntitlementPoolEntity(vlmId, Version.valueOf
171 (versionId), entitlementPoolId), user);
173 LimitEntity limitInput = new LimitEntity();
174 limitInput.setVendorLicenseModelId(vlmId);
175 limitInput.setEpLkgId(entitlementPoolId);
176 limitInput.setId(limitId);
177 limitInput.setParent(parent);
179 vendorLicenseManager.deleteLimit(limitInput, user);
181 mdcDataDebugMessage.debugExitMessage("VLM id, Verison Id, EP id, Limit Id", vlmId, versionId, entitlementPoolId, limitId);
183 return Response.ok().build();