1 package org.openecomp.sdcrests.vendorlicense.rest.services;
3 import org.openecomp.sdc.logging.context.MdcUtil;
4 import org.openecomp.sdc.logging.types.LoggerServiceName;
5 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
6 import org.openecomp.sdc.vendorlicense.VendorLicenseManagerFactory;
7 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
8 import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity;
9 import org.openecomp.sdc.versioning.dao.types.Version;
10 import org.openecomp.sdcrests.vendorlicense.rest.LicenseKeyGroupLimits;
11 import org.openecomp.sdcrests.vendorlicense.rest.mapping.LimitCreationDto;
12 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitEntityToLimitCreationDto;
13 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitEntityToLimitDto;
14 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitRequestDtoToLimitEntity;
15 import org.openecomp.sdcrests.vendorlicense.types.LimitEntityDto;
16 import org.openecomp.sdcrests.vendorlicense.types.LimitRequestDto;
17 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
18 import org.springframework.context.annotation.Scope;
19 import org.springframework.stereotype.Service;
21 import javax.inject.Named;
22 import javax.ws.rs.core.Response;
23 import java.util.Collection;
26 @Service("licenseKeyGroupLimits")
27 @Scope(value = "prototype")
28 public class LicenseKeyGroupLimitsImpl implements LicenseKeyGroupLimits {
29 private VendorLicenseManager vendorLicenseManager =
30 VendorLicenseManagerFactory.getInstance().createInterface();
32 public static final String parent = "LicenseKeyGroup";
36 public Response createLimit(LimitRequestDto request,
39 String licenseKeyGroupId,
41 MdcUtil.initMdc(LoggerServiceName.Create_LIMIT.toString());
42 Version version = new Version(versionId);
43 vendorLicenseManager.getLicenseKeyGroup(
44 new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId));
46 LimitEntity limitEntity =
47 new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class);
48 limitEntity.setVendorLicenseModelId(vlmId);
49 limitEntity.setVersion(version);
50 limitEntity.setEpLkgId(licenseKeyGroupId);
51 limitEntity.setParent(parent);
53 LimitEntity createdLimit = vendorLicenseManager.createLimit(limitEntity);
54 MapLimitEntityToLimitCreationDto mapper = new MapLimitEntityToLimitCreationDto();
55 LimitCreationDto createdLimitDto = mapper.applyMapping(createdLimit, LimitCreationDto.class);
56 /*StringWrapperResponse result =
57 createdLimit != null ? new StringWrapperResponse(createdLimit.getId())
59 //return Response.ok(result).build();
60 return Response.ok(createdLimitDto != null ? createdLimitDto : null).build();
64 public Response listLimits(String vlmId, String versionId, String licenseKeyGroupId,
66 MdcUtil.initMdc(LoggerServiceName.List_EP.toString());
67 Version version = new Version(versionId);
69 .getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId));
71 Collection<LimitEntity> limits =
72 vendorLicenseManager.listLimits(vlmId, version, licenseKeyGroupId);
74 GenericCollectionWrapper<LimitEntityDto> result = new GenericCollectionWrapper<>();
75 MapLimitEntityToLimitDto outputMapper =
76 new MapLimitEntityToLimitDto();
77 for (LimitEntity limit : limits) {
78 result.add(outputMapper.applyMapping(limit, LimitEntityDto.class));
80 return Response.ok(result).build();
84 public Response updateLimit(LimitRequestDto request,
87 String licenseKeyGroupId,
90 MdcUtil.initMdc(LoggerServiceName.Update_LIMIT.toString());
92 Version version = new Version(versionId);
94 .getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId));
96 LimitEntity limitEntity =
97 new MapLimitRequestDtoToLimitEntity().applyMapping(request, LimitEntity.class);
98 limitEntity.setVendorLicenseModelId(vlmId);
99 limitEntity.setVersion(version);
100 limitEntity.setEpLkgId(licenseKeyGroupId);
101 limitEntity.setId(limitId);
102 limitEntity.setParent(parent);
104 vendorLicenseManager.updateLimit(limitEntity);
105 return Response.ok().build();
109 * Delete License Key Group.
111 * @param vlmId the vlm id
112 * @param licenseKeyGroupId the license Key Group id
113 * @param limitId the limitId
114 * @param user the user
115 * @return the response
117 public Response deleteLimit(String vlmId, String versionId, String licenseKeyGroupId,
118 String limitId, String user) {
119 MdcUtil.initMdc(LoggerServiceName.Delete_LIMIT.toString());
121 Version version = new Version(versionId);
123 .getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId));
125 LimitEntity limitInput = new LimitEntity();
126 limitInput.setVendorLicenseModelId(vlmId);
127 limitInput.setVersion(version);
128 limitInput.setEpLkgId(licenseKeyGroupId);
129 limitInput.setId(limitId);
130 limitInput.setParent(parent);
132 vendorLicenseManager.deleteLimit(limitInput);
133 return Response.ok().build();
137 public Response getLimit(String vlmId, String versionId, String licenseKeyGroupId,
138 String limitId, String user) {
139 MdcUtil.initMdc(LoggerServiceName.Get_LIMIT.toString());
140 Version version = new Version(versionId);
142 .getLicenseKeyGroup(new LicenseKeyGroupEntity(vlmId, version, licenseKeyGroupId));
143 LimitEntity limitInput = new LimitEntity();
144 limitInput.setVendorLicenseModelId(vlmId);
145 limitInput.setVersion(version);
146 limitInput.setEpLkgId(licenseKeyGroupId);
147 limitInput.setId(limitId);
148 LimitEntity limit = vendorLicenseManager.getLimit(limitInput);
150 LimitEntityDto entitlementPoolEntityDto = limit == null ? null
151 : new MapLimitEntityToLimitDto().applyMapping(limit, LimitEntityDto.class);
152 return Response.ok(entitlementPoolEntityDto).build();