2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.vendorlicense.impl;
23 import org.openecomp.core.util.UniqueValueUtil;
24 import org.openecomp.sdc.common.errors.CoreException;
25 import org.openecomp.sdc.common.errors.ErrorCode;
26 import org.openecomp.sdc.datatypes.error.ErrorLevel;
27 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
28 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
29 import org.openecomp.sdc.logging.types.LoggerConstants;
30 import org.openecomp.sdc.logging.types.LoggerErrorCode;
31 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
32 import org.openecomp.sdc.logging.types.LoggerServiceName;
33 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
34 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
35 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
36 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
37 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
38 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao;
39 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
40 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
41 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
42 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
43 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
44 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel;
45 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
46 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementModel;
47 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
48 import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity;
49 import org.openecomp.sdc.vendorlicense.dao.types.LimitType;
50 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
51 import org.openecomp.sdc.vendorlicense.errors.InvalidDateErrorBuilder;
52 import org.openecomp.sdc.vendorlicense.errors.LimitErrorBuilder;
53 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
54 import org.openecomp.sdc.versioning.VersioningUtil;
55 import org.openecomp.sdc.versioning.dao.types.Version;
57 import java.time.LocalDate;
58 import java.time.format.DateTimeFormatter;
59 import java.util.Collection;
60 import java.util.Optional;
63 public class VendorLicenseManagerImpl implements VendorLicenseManager {
64 private VendorLicenseFacade vendorLicenseFacade;
65 private VendorLicenseModelDao vendorLicenseModelDao;
66 private LicenseAgreementDao licenseAgreementDao;
67 private FeatureGroupDao featureGroupDao;
68 private EntitlementPoolDao entitlementPoolDao;
69 private LicenseKeyGroupDao licenseKeyGroupDao;
70 private LimitDao limitDao;
72 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
74 public VendorLicenseManagerImpl(VendorLicenseFacade vendorLicenseFacade,
75 VendorLicenseModelDao vendorLicenseModelDao,
76 LicenseAgreementDao licenseAgreementDao,
77 FeatureGroupDao featureGroupDao,
78 EntitlementPoolDao entitlementPoolDao,
79 LicenseKeyGroupDao licenseKeyGroupDao,
81 this.vendorLicenseFacade = vendorLicenseFacade;
82 this.vendorLicenseModelDao = vendorLicenseModelDao;
83 this.licenseAgreementDao = licenseAgreementDao;
84 this.featureGroupDao = featureGroupDao;
85 this.entitlementPoolDao = entitlementPoolDao;
86 this.licenseKeyGroupDao = licenseKeyGroupDao;
87 this.limitDao = limitDao;
92 public void validate(String vendorLicenseModelId, Version version) {
93 mdcDataDebugMessage.debugEntryMessage("VLM id", vendorLicenseModelId);
95 vendorLicenseFacade.validate(vendorLicenseModelId, version);
97 mdcDataDebugMessage.debugExitMessage("VLM id", vendorLicenseModelId);
101 public VendorLicenseModelEntity createVendorLicenseModel(
102 VendorLicenseModelEntity vendorLicenseModelEntity) {
103 mdcDataDebugMessage.debugEntryMessage(null);
105 vendorLicenseModelDao.create(vendorLicenseModelEntity);
106 mdcDataDebugMessage.debugExitMessage(null);
108 return vendorLicenseModelEntity;
112 public void updateVendorLicenseModel(VendorLicenseModelEntity vendorLicenseModelEntity) {
113 mdcDataDebugMessage.debugEntryMessage("VLM id", vendorLicenseModelEntity.getId());
115 String existingVendorName = vendorLicenseModelDao.get(vendorLicenseModelEntity).getVendorName();
117 updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME, existingVendorName,
118 vendorLicenseModelEntity.getVendorName());
119 vendorLicenseModelDao.update(vendorLicenseModelEntity);
121 mdcDataDebugMessage.debugExitMessage("VLM id", vendorLicenseModelEntity.getId());
125 public VendorLicenseModelEntity getVendorLicenseModel(String vlmId, Version version) {
126 return vendorLicenseFacade.getVendorLicenseModel(vlmId, version);
130 public void deleteVendorLicenseModel(String vlmId, Version version) {
131 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
132 LoggerTragetServiceName.DELETE_ENTITY, ErrorLevel.ERROR.name(),
133 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.UNSUPPORTED_OPERATION);
134 throw new UnsupportedOperationException(VendorLicenseConstants.UNSUPPORTED_OPERATION_ERROR);
138 public Collection<LicenseAgreementEntity> listLicenseAgreements(String vlmId, Version version) {
139 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
140 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
141 return licenseAgreementDao.list(new LicenseAgreementEntity(vlmId, version, null));
145 public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement) {
147 .debugEntryMessage("VLM id", licenseAgreement.getVendorLicenseModelId());
149 .debugExitMessage("VLM id", licenseAgreement.getVendorLicenseModelId());
150 return vendorLicenseFacade.createLicenseAgreement(licenseAgreement);
154 public void updateLicenseAgreement(LicenseAgreementEntity licenseAgreement,
155 Set<String> addedFeatureGroupIds,
156 Set<String> removedFeatureGroupIds) {
157 mdcDataDebugMessage.debugEntryMessage("VLM id, LA id", licenseAgreement
158 .getVendorLicenseModelId(), licenseAgreement.getId());
160 LicenseAgreementEntity retrieved = licenseAgreementDao.get(licenseAgreement);
162 .validateEntityExistence(retrieved, licenseAgreement, VendorLicenseModelEntity.ENTITY_TYPE);
163 VersioningUtil.validateContainedEntitiesExistence(new FeatureGroupEntity().getEntityType(),
164 removedFeatureGroupIds, retrieved, retrieved.getFeatureGroupIds());
165 VersioningUtil.validateEntitiesExistence(addedFeatureGroupIds,
166 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
167 licenseAgreement.getVersion(),
169 featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
171 updateUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
172 retrieved.getName(), licenseAgreement.getName(), licenseAgreement.getVendorLicenseModelId(),
173 licenseAgreement.getVersion().getId());
174 licenseAgreementDao.updateColumnsAndDeltaFeatureGroupIds(licenseAgreement, addedFeatureGroupIds,
175 removedFeatureGroupIds);
177 addFeatureGroupsToLicenseAgreementRef(addedFeatureGroupIds, licenseAgreement);
178 removeFeatureGroupsToLicenseAgreementRef(removedFeatureGroupIds, licenseAgreement);
180 mdcDataDebugMessage.debugExitMessage("VLM id, LA id", licenseAgreement
181 .getVendorLicenseModelId(), licenseAgreement.getId());
185 public LicenseAgreementModel getLicenseAgreementModel(String vlmId, Version version,
186 String licenseAgreementId) {
188 mdcDataDebugMessage.debugEntryMessage("VLM id, LA id", vlmId, licenseAgreementId);
189 mdcDataDebugMessage.debugExitMessage("VLM id, LA id", vlmId, licenseAgreementId);
190 return vendorLicenseFacade.getLicenseAgreementModel(vlmId, version, licenseAgreementId);
194 public void deleteLicenseAgreement(String vlmId, Version version, String licenseAgreementId) {
195 mdcDataDebugMessage.debugEntryMessage("VLM id, LA id", vlmId, licenseAgreementId);
197 LicenseAgreementEntity input =
198 new LicenseAgreementEntity(vlmId, version, licenseAgreementId);
199 LicenseAgreementEntity retrieved = licenseAgreementDao.get(input);
200 VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE);
202 removeFeatureGroupsToLicenseAgreementRef(retrieved.getFeatureGroupIds(), retrieved);
204 licenseAgreementDao.delete(retrieved);
206 deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
207 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
208 retrieved.getName());
210 mdcDataDebugMessage.debugExitMessage("VLM id, LA id", vlmId, licenseAgreementId);
214 public Collection<FeatureGroupEntity> listFeatureGroups(String vlmId, Version version) {
215 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
216 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
217 return vendorLicenseFacade.listFeatureGroups(vlmId, version);
221 public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup) {
223 .debugEntryMessage("VLM id", featureGroup.getVendorLicenseModelId());
224 mdcDataDebugMessage.debugExitMessage("VLM id", featureGroup.getId());
225 return vendorLicenseFacade.createFeatureGroup(featureGroup);
229 public void updateFeatureGroup(FeatureGroupEntity featureGroup,
230 Set<String> addedLicenseKeyGroups,
231 Set<String> removedLicenseKeyGroups,
232 Set<String> addedEntitlementPools,
233 Set<String> removedEntitlementPools) {
234 mdcDataDebugMessage.debugEntryMessage("VLM id, FG id", featureGroup
235 .getVendorLicenseModelId(), featureGroup.getId());
237 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
239 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
241 VersioningUtil.validateContainedEntitiesExistence(new LicenseKeyGroupEntity().getEntityType(),
242 removedLicenseKeyGroups, retrieved, retrieved.getLicenseKeyGroupIds());
243 VersioningUtil.validateContainedEntitiesExistence(new EntitlementPoolEntity().getEntityType(),
244 removedEntitlementPools, retrieved, retrieved.getEntitlementPoolIds());
246 VersioningUtil.validateEntitiesExistence(addedLicenseKeyGroups,
247 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(),
249 licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
250 VersioningUtil.validateEntitiesExistence(addedEntitlementPools,
251 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(),
253 entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE);
255 updateUniqueName(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
256 retrieved.getName(), featureGroup.getName(), featureGroup.getVendorLicenseModelId(),
257 featureGroup.getVersion().getId());
259 addLicenseKeyGroupsToFeatureGroupsRef(addedLicenseKeyGroups, featureGroup);
260 removeLicenseKeyGroupsToFeatureGroupsRef(removedLicenseKeyGroups, featureGroup);
261 addEntitlementPoolsToFeatureGroupsRef(addedEntitlementPools, featureGroup);
262 removeEntitlementPoolsToFeatureGroupsRef(removedEntitlementPools, featureGroup);
264 featureGroupDao.updateFeatureGroup(featureGroup, addedEntitlementPools, removedEntitlementPools,
265 addedLicenseKeyGroups, removedLicenseKeyGroups);
267 mdcDataDebugMessage.debugExitMessage("VLM id, FG id", featureGroup
268 .getVendorLicenseModelId(), featureGroup.getId());
272 public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup) {
273 mdcDataDebugMessage.debugEntryMessage("VLM id, FG id",
274 featureGroup.getVendorLicenseModelId(), featureGroup.getId());
276 mdcDataDebugMessage.debugExitMessage("VLM id, FG id",
277 featureGroup.getVendorLicenseModelId(), featureGroup.getId());
278 return vendorLicenseFacade.getFeatureGroupModel(featureGroup);
282 public void deleteFeatureGroup(FeatureGroupEntity featureGroup) {
283 mdcDataDebugMessage.debugEntryMessage("VLM id, FG id",
284 featureGroup.getVendorLicenseModelId(), featureGroup.getId());
286 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
288 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
290 removeLicenseKeyGroupsToFeatureGroupsRef(retrieved.getLicenseKeyGroupIds(), featureGroup);
291 removeEntitlementPoolsToFeatureGroupsRef(retrieved.getEntitlementPoolIds(), featureGroup);
293 for (String licenceAgreementId : retrieved.getReferencingLicenseAgreements()) {
294 licenseAgreementDao.removeFeatureGroup(
295 new LicenseAgreementEntity(featureGroup.getVendorLicenseModelId(),
296 featureGroup.getVersion(),
297 licenceAgreementId), featureGroup.getId());
300 featureGroupDao.delete(featureGroup);
302 deleteUniqueName(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
303 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
304 retrieved.getName());
307 .debugExitMessage("VLM id, FG id",
308 featureGroup.getVendorLicenseModelId(), featureGroup.getId());
312 public Collection<EntitlementPoolEntity> listEntitlementPools(String vlmId, Version version) {
313 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
314 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
315 return vendorLicenseFacade.listEntitlementPools(vlmId, version);
319 public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool) {
321 .debugEntryMessage("VLM id", entitlementPool.getVendorLicenseModelId());
323 .debugExitMessage("VLM id", entitlementPool.getVendorLicenseModelId());
325 entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool
326 .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + "T00:00:00Z"
328 entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool
329 .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + "T23:59:59Z"
332 validateCreateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(),
333 entitlementPool.getVendorLicenseModelId());
334 return vendorLicenseFacade.createEntitlementPool(entitlementPool);
337 private void validateCreateDate(String startDate, String expiryDate,
338 String vendorLicenseModelId) {
339 mdcDataDebugMessage.debugEntryMessage("Start date and end date", startDate
342 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy'T'HH:mm:ss'Z'");
344 if (startDate != null && expiryDate != null) {
345 if (LocalDate.parse(startDate, formatter).atStartOfDay().isBefore
346 (LocalDate.now().atStartOfDay()) || LocalDate.parse(expiryDate, formatter).atStartOfDay()
347 .isEqual(LocalDate.parse(startDate, formatter).atStartOfDay()) || LocalDate
348 .parse(expiryDate, formatter).isBefore(LocalDate.parse(startDate, formatter))) {
349 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
350 LoggerTragetServiceName.VALIDATE_DATE_RANGE, ErrorLevel.ERROR.name(),
351 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE);
352 throw new CoreException(
353 new InvalidDateErrorBuilder(vendorLicenseModelId)
358 if (startDate != null && expiryDate == null) {
359 if (LocalDate.parse(startDate, formatter).atStartOfDay().isBefore
360 (LocalDate.now().atStartOfDay())) {
361 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
362 LoggerTragetServiceName.VALIDATE_DATE_RANGE, ErrorLevel.ERROR.name(),
363 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE);
364 throw new CoreException(
365 new InvalidDateErrorBuilder(vendorLicenseModelId)
370 if (startDate == null && expiryDate != null) {
371 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
372 LoggerTragetServiceName.VALIDATE_DATE_RANGE, ErrorLevel.ERROR.name(),
373 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE);
374 throw new CoreException(
375 new InvalidDateErrorBuilder(vendorLicenseModelId)
380 mdcDataDebugMessage.debugExitMessage(null);
383 private void validateUpdateDate(String startDate, String expiryDate,
384 String vendorLicenseModelId) {
385 mdcDataDebugMessage.debugEntryMessage("Start date and end date", startDate
388 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy'T'HH:mm:ss'Z'");
390 if (startDate != null && expiryDate != null) {
391 if (LocalDate.parse(expiryDate, formatter).atStartOfDay()
392 .isEqual(LocalDate.parse(startDate, formatter).atStartOfDay()) ||
393 LocalDate.parse(expiryDate, formatter).isBefore(LocalDate.parse(startDate, formatter))) {
394 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
395 LoggerTragetServiceName.VALIDATE_DATE_RANGE, ErrorLevel.ERROR.name(),
396 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE);
397 throw new CoreException(
398 new InvalidDateErrorBuilder(vendorLicenseModelId)
403 if (startDate == null && expiryDate != null) {
404 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
405 LoggerTragetServiceName.VALIDATE_DATE_RANGE, ErrorLevel.ERROR.name(),
406 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE);
407 throw new CoreException(
408 new InvalidDateErrorBuilder(vendorLicenseModelId)
413 mdcDataDebugMessage.debugExitMessage(null);
417 public void updateEntitlementPool(EntitlementPoolEntity entitlementPool) {
418 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", entitlementPool
419 .getVendorLicenseModelId(), entitlementPool.getId());
421 entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool
422 .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + "T00:00:00Z"
424 entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool
425 .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + "T23:59:59Z"
428 validateUpdateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(),
429 entitlementPool.getVendorLicenseModelId());
430 vendorLicenseFacade.updateEntitlementPool(entitlementPool);
432 mdcDataDebugMessage.debugExitMessage("VLM id, EP id", entitlementPool
433 .getVendorLicenseModelId(), entitlementPool.getId());
437 public EntitlementPoolEntity getEntitlementPool(EntitlementPoolEntity entitlementPool) {
438 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", entitlementPool
439 .getVendorLicenseModelId(), entitlementPool.getId());
441 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
443 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
445 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy'T'HH:mm:ss'Z'");
446 DateTimeFormatter targetFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
447 if (retrieved.getStartDate() != null) {
448 retrieved.setStartDate(LocalDate.parse(retrieved.getStartDate(), formatter).format
452 if (retrieved.getExpiryDate() != null) {
453 retrieved.setExpiryDate(LocalDate.parse(retrieved.getExpiryDate(), formatter).format
457 mdcDataDebugMessage.debugExitMessage("VLM id, EP id", entitlementPool
458 .getVendorLicenseModelId(), entitlementPool.getId());
463 public void deleteEntitlementPool(EntitlementPoolEntity entitlementPool) {
464 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", entitlementPool
465 .getVendorLicenseModelId(), entitlementPool.getId());
467 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
469 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
471 for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) {
472 featureGroupDao.removeEntitlementPool(
473 new FeatureGroupEntity(entitlementPool.getVendorLicenseModelId(),
474 entitlementPool.getVersion(),
475 referencingFeatureGroupId), entitlementPool.getId());
478 deleteChildLimits(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion(),
479 entitlementPool.getId());
481 entitlementPoolDao.delete(entitlementPool);
483 deleteUniqueName(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
484 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
485 retrieved.getName());
487 mdcDataDebugMessage.debugExitMessage("VLM id, EP id", entitlementPool
488 .getVendorLicenseModelId(), entitlementPool.getId());
491 protected void deleteChildLimits(String vlmId, Version version, String epLkgId) {
492 Optional<Collection<LimitEntity>> limitEntities = Optional.ofNullable(
493 listLimits(vlmId, version, epLkgId));
494 limitEntities.ifPresent(entities -> entities.forEach(this::deleteLimit));
498 public Collection<LicenseKeyGroupEntity> listLicenseKeyGroups(String vlmId, Version version) {
499 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
500 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
501 return vendorLicenseFacade.listLicenseKeyGroups(vlmId, version);
505 public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
507 .debugEntryMessage("VLM id", licenseKeyGroup.getVendorLicenseModelId());
509 mdcDataDebugMessage.debugExitMessage("VLM id", licenseKeyGroup
510 .getVendorLicenseModelId());
512 licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup
513 .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate() + "T00:00:00Z"
515 licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup
516 .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate() + "T23:59:59Z"
519 validateCreateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(),
520 licenseKeyGroup.getVendorLicenseModelId());
521 return vendorLicenseFacade.createLicenseKeyGroup(licenseKeyGroup);
525 public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
526 mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", licenseKeyGroup
527 .getVendorLicenseModelId(), licenseKeyGroup.getId());
529 licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup
530 .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate() + "T00:00:00Z"
532 licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup
533 .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate() + "T23:59:59Z"
536 validateUpdateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(),
537 licenseKeyGroup.getVendorLicenseModelId());
538 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroup);
540 mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", licenseKeyGroup
541 .getVendorLicenseModelId(), licenseKeyGroup.getId());
545 public LicenseKeyGroupEntity getLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
546 mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", licenseKeyGroup
547 .getVendorLicenseModelId(), licenseKeyGroup.getId());
549 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
551 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
553 mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", licenseKeyGroup
554 .getVendorLicenseModelId(), licenseKeyGroup.getId());
559 public void deleteLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
560 mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", licenseKeyGroup
561 .getVendorLicenseModelId(), licenseKeyGroup.getId());
563 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
565 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
567 for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) {
568 featureGroupDao.removeLicenseKeyGroup(
569 new FeatureGroupEntity(licenseKeyGroup.getVendorLicenseModelId(),
570 licenseKeyGroup.getVersion(),
571 referencingFeatureGroupId), licenseKeyGroup.getId());
574 deleteChildLimits(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion(),
575 licenseKeyGroup.getId());
577 licenseKeyGroupDao.delete(licenseKeyGroup);
579 deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
580 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
581 retrieved.getName());
583 mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", licenseKeyGroup
584 .getVendorLicenseModelId(), licenseKeyGroup.getId());
588 public LimitEntity createLimit(LimitEntity limit) {
590 .debugEntryMessage("VLM id", limit.getVendorLicenseModelId(), "EP/LKGId", limit
593 .debugExitMessage("VLM id", limit.getVendorLicenseModelId(), "EP/LKGId", limit
595 validateLimit(limit);
596 LimitEntity createdLimit = vendorLicenseFacade.createLimit(limit);
597 updateParentForLimit(limit);
601 private void validateLimit(LimitEntity limit) {
602 Collection<LimitEntity> limitList =
603 listLimits(limit.getVendorLicenseModelId(), limit.getVersion()
604 , limit.getEpLkgId());
606 if (!isLimitNameUnique(limitList, limit.getName(), limit.getType(), limit.getId())) {
607 final ErrorCode duplicateLimitNameErrorBuilder =
608 LimitErrorBuilder.getDuplicateNameErrorbuilder(limit.getName(), limit.getType().name());
609 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
610 LoggerServiceName.Create_LIMIT.toString(), ErrorLevel.ERROR.name(),
611 LoggerErrorCode.DATA_ERROR.getErrorCode(),
612 duplicateLimitNameErrorBuilder.message());
613 throw new CoreException(duplicateLimitNameErrorBuilder);
617 private boolean isLimitNameUnique(Collection<LimitEntity> limitList, String name, LimitType
619 for (LimitEntity limit : limitList) {
620 if (limit.getName().equalsIgnoreCase(name) &&
621 limit.getType().name().equalsIgnoreCase(type.name())) {
622 if (id != null && limit.getId().equals(id)) {
632 public Collection<LimitEntity> listLimits(String vlmId, Version version, String epLkgId) {
633 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId, "EP/LKGId", epLkgId);
634 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId, "EP/LKGId", epLkgId);
635 return vendorLicenseFacade.listLimits(vlmId, version, epLkgId);
639 public void deleteLimit(LimitEntity limitEntity) {
640 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id, Limit Id", limitEntity
641 .getVendorLicenseModelId(), limitEntity.getEpLkgId(), limitEntity.getId());
643 if (!isLimitPresent(limitEntity)) {
645 .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
647 LimitEntity retrieved = limitDao.get(limitEntity);
649 .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
651 limitDao.delete(limitEntity);
653 updateParentForLimit(limitEntity);
655 mdcDataDebugMessage.debugExitMessage("VLM id, EP id, Limit Id", limitEntity
656 .getVendorLicenseModelId(), limitEntity.getEpLkgId(), limitEntity.getId());
660 public void updateLimit(LimitEntity limit) {
662 .debugEntryMessage("VLM id", limit.getVendorLicenseModelId(), "EP/LKGId", limit
665 validateLimit(limit);
666 vendorLicenseFacade.updateLimit(limit);
667 updateParentForLimit(limit);
669 .debugExitMessage("VLM id", limit.getVendorLicenseModelId(), "EP/LKGId", limit
673 private boolean isLimitPresent(LimitEntity limit) {
674 return limitDao.isLimitPresent(limit);
678 public LimitEntity getLimit(LimitEntity limitEntity) {
679 mdcDataDebugMessage.debugEntryMessage("VLM id", limitEntity.getVendorLicenseModelId(),
680 "EP/LKGId", limitEntity.getEpLkgId());
682 if (!isLimitPresent(limitEntity)) {
684 .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
686 LimitEntity retrieved = limitDao.get(limitEntity);
688 .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
690 mdcDataDebugMessage.debugExitMessage("VLM id", limitEntity.getVendorLicenseModelId(),
691 "EP/LKGId", limitEntity.getEpLkgId());
696 * update Parent of limit (EP/LKG) versionuuid when limit is modified so that limit updates are
697 * captured in VLM XML
699 private void updateParentForLimit(LimitEntity limit) {
700 mdcDataDebugMessage.debugEntryMessage("VLM id", limit.getVendorLicenseModelId(),
701 "EP/LKGId", limit.getEpLkgId(), "Limit Parent ", limit.getParent());
702 if ("EntitlementPool".equals(limit.getParent())) {
703 EntitlementPoolEntity entitlementPoolEntity =
704 entitlementPoolDao.get(new EntitlementPoolEntity(limit.getVendorLicenseModelId(),
705 limit.getVersion(), limit.getEpLkgId()));
706 vendorLicenseFacade.updateEntitlementPool(entitlementPoolEntity);
709 if ("LicenseKeyGroup".equals(limit.getParent())) {
710 LicenseKeyGroupEntity licenseKeyGroupEntity = licenseKeyGroupDao.get(
711 new LicenseKeyGroupEntity(limit.getVendorLicenseModelId(), limit.getVersion(),
712 limit.getEpLkgId()));
713 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroupEntity);
716 mdcDataDebugMessage.debugEntryMessage("VLM id", limit.getVendorLicenseModelId(),
717 "EP/LKGId", limit.getEpLkgId(), "Limit Parent ", limit.getParent());
720 protected void addFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds,
721 LicenseAgreementEntity licenseAgreement) {
722 if (featureGroupIds != null) {
723 for (String featureGroupId : featureGroupIds) {
724 featureGroupDao.addReferencingLicenseAgreement(
725 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
726 licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId());
731 protected void removeFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds,
732 LicenseAgreementEntity licenseAgreement) {
733 if (featureGroupIds != null) {
734 for (String featureGroupId : featureGroupIds) {
735 featureGroupDao.removeReferencingLicenseAgreement(
736 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
737 licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId());
742 protected void addLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds,
743 FeatureGroupEntity featureGroup) {
744 if (licenseKeyGroupIds != null) {
745 for (String licenseKeyGroupId : licenseKeyGroupIds) {
746 licenseKeyGroupDao.addReferencingFeatureGroup(
747 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
748 featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId());
753 protected void removeLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds,
754 FeatureGroupEntity featureGroup) {
755 if (licenseKeyGroupIds != null) {
756 for (String licenseKeyGroupId : licenseKeyGroupIds) {
757 licenseKeyGroupDao.removeReferencingFeatureGroup(
758 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
759 featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId());
764 protected void addEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds,
765 FeatureGroupEntity featureGroup) {
766 if (entitlementPoolIds != null) {
767 for (String entitlementPoolId : entitlementPoolIds) {
768 entitlementPoolDao.addReferencingFeatureGroup(
769 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(),
770 featureGroup.getVersion(), entitlementPoolId), featureGroup.getId());
775 protected void removeEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds,
776 FeatureGroupEntity featureGroup) {
777 if (entitlementPoolIds != null) {
778 for (String entitlementPoolId : entitlementPoolIds) {
779 entitlementPoolDao.removeReferencingFeatureGroup(
780 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(),
781 featureGroup.getVersion(), entitlementPoolId), featureGroup.getId());
786 protected void updateUniqueName(String uniqueValueType, String oldName, String newName, String...
789 .updateUniqueValue(uniqueValueType, oldName, newName, context);
792 protected void deleteUniqueName(String uniqueValueType, String... uniqueCombination) {
793 UniqueValueUtil.deleteUniqueValue(uniqueValueType, uniqueCombination);