2 * Copyright © 2016-2017 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.vendorlicense.impl;
19 import org.openecomp.core.util.UniqueValueUtil;
20 import org.openecomp.sdc.common.errors.CoreException;
21 import org.openecomp.sdc.common.errors.ErrorCode;
22 import org.openecomp.sdc.datatypes.error.ErrorLevel;
23 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
24 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
25 import org.openecomp.sdc.logging.types.LoggerConstants;
26 import org.openecomp.sdc.logging.types.LoggerErrorCode;
27 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
28 import org.openecomp.sdc.logging.types.LoggerServiceName;
29 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
30 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
31 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
32 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
33 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
34 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao;
35 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
36 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
37 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
38 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
39 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
40 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel;
41 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
42 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementModel;
43 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
44 import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity;
45 import org.openecomp.sdc.vendorlicense.dao.types.LimitType;
46 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
47 import org.openecomp.sdc.vendorlicense.errors.InvalidDateErrorBuilder;
48 import org.openecomp.sdc.vendorlicense.errors.LimitErrorBuilder;
49 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
50 import org.openecomp.sdc.versioning.VersioningUtil;
51 import org.openecomp.sdc.versioning.dao.types.Version;
53 import java.time.LocalDate;
54 import java.time.format.DateTimeFormatter;
55 import java.util.Collection;
56 import java.util.Optional;
59 public class VendorLicenseManagerImpl implements VendorLicenseManager {
60 private VendorLicenseFacade vendorLicenseFacade;
61 private VendorLicenseModelDao vendorLicenseModelDao;
62 private LicenseAgreementDao licenseAgreementDao;
63 private FeatureGroupDao featureGroupDao;
64 private EntitlementPoolDao entitlementPoolDao;
65 private LicenseKeyGroupDao licenseKeyGroupDao;
66 private LimitDao limitDao;
67 private static final String VLM_ID = "VLM id";
68 private static final String EP_LKGID = "EP/LKGId";
69 private static final String VLM_ID_LKG_ID = "VLM id, LKG id";
70 private static final String VLM_ID_LA_ID = "VLM id, LA id";
71 private static final String VLM_ID_FG_ID = "VLM id, FG id";
72 private static final String VLM_ID_EP_ID = "VLM id, EP id";
73 private static final String EP_POOL_START_TIME = "T00:00:00Z";
74 private static final String EP_POOL_EXPIRY_TIME = "T23:59:59Z";
75 private static final DateTimeFormatter FORMATTER
76 = DateTimeFormatter.ofPattern("MM/dd/yyyy'T'HH:mm:ss'Z'");
79 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
81 public VendorLicenseManagerImpl(VendorLicenseFacade vendorLicenseFacade,
82 VendorLicenseModelDao vendorLicenseModelDao,
83 LicenseAgreementDao licenseAgreementDao,
84 FeatureGroupDao featureGroupDao,
85 EntitlementPoolDao entitlementPoolDao,
86 LicenseKeyGroupDao licenseKeyGroupDao,
88 this.vendorLicenseFacade = vendorLicenseFacade;
89 this.vendorLicenseModelDao = vendorLicenseModelDao;
90 this.licenseAgreementDao = licenseAgreementDao;
91 this.featureGroupDao = featureGroupDao;
92 this.entitlementPoolDao = entitlementPoolDao;
93 this.licenseKeyGroupDao = licenseKeyGroupDao;
94 this.limitDao = limitDao;
99 public void validate(String vendorLicenseModelId, Version version) {
100 mdcDataDebugMessage.debugEntryMessage(VLM_ID, vendorLicenseModelId);
102 vendorLicenseFacade.validate(vendorLicenseModelId, version);
104 mdcDataDebugMessage.debugExitMessage(VLM_ID, vendorLicenseModelId);
108 public VendorLicenseModelEntity createVendorLicenseModel(
109 VendorLicenseModelEntity vendorLicenseModelEntity) {
110 mdcDataDebugMessage.debugEntryMessage(null);
112 vendorLicenseModelDao.create(vendorLicenseModelEntity);
113 mdcDataDebugMessage.debugExitMessage(null);
115 return vendorLicenseModelEntity;
119 public void updateVendorLicenseModel(VendorLicenseModelEntity vendorLicenseModelEntity) {
120 mdcDataDebugMessage.debugEntryMessage(VLM_ID, vendorLicenseModelEntity.getId());
122 String existingVendorName = vendorLicenseModelDao.get(vendorLicenseModelEntity).getVendorName();
124 updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME, existingVendorName,
125 vendorLicenseModelEntity.getVendorName());
126 vendorLicenseModelDao.update(vendorLicenseModelEntity);
128 mdcDataDebugMessage.debugExitMessage(VLM_ID, vendorLicenseModelEntity.getId());
132 public VendorLicenseModelEntity getVendorLicenseModel(String vlmId, Version version) {
133 return vendorLicenseFacade.getVendorLicenseModel(vlmId, version);
137 public void deleteVendorLicenseModel(String vlmId, Version version) {
138 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
139 LoggerTragetServiceName.DELETE_ENTITY, ErrorLevel.ERROR.name(),
140 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.UNSUPPORTED_OPERATION);
141 throw new UnsupportedOperationException(VendorLicenseConstants.UNSUPPORTED_OPERATION_ERROR);
145 public Collection<LicenseAgreementEntity> listLicenseAgreements(String vlmId, Version version) {
146 mdcDataDebugMessage.debugEntryMessage(VLM_ID, vlmId);
147 mdcDataDebugMessage.debugExitMessage(VLM_ID, vlmId);
148 return licenseAgreementDao.list(new LicenseAgreementEntity(vlmId, version, null));
152 public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement) {
154 .debugEntryMessage(VLM_ID, licenseAgreement.getVendorLicenseModelId());
156 .debugExitMessage(VLM_ID, licenseAgreement.getVendorLicenseModelId());
157 return vendorLicenseFacade.createLicenseAgreement(licenseAgreement);
161 public void updateLicenseAgreement(LicenseAgreementEntity licenseAgreement,
162 Set<String> addedFeatureGroupIds,
163 Set<String> removedFeatureGroupIds) {
164 mdcDataDebugMessage.debugEntryMessage(VLM_ID_LA_ID, licenseAgreement
165 .getVendorLicenseModelId(), licenseAgreement.getId());
167 LicenseAgreementEntity retrieved = licenseAgreementDao.get(licenseAgreement);
169 .validateEntityExistence(retrieved, licenseAgreement, VendorLicenseModelEntity.ENTITY_TYPE);
170 VersioningUtil.validateContainedEntitiesExistence(new FeatureGroupEntity().getEntityType(),
171 removedFeatureGroupIds, retrieved, retrieved.getFeatureGroupIds());
172 VersioningUtil.validateEntitiesExistence(addedFeatureGroupIds,
173 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
174 licenseAgreement.getVersion(),
176 featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
178 updateUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
179 retrieved.getName(), licenseAgreement.getName(), licenseAgreement.getVendorLicenseModelId(),
180 licenseAgreement.getVersion().getId());
181 licenseAgreementDao.updateColumnsAndDeltaFeatureGroupIds(licenseAgreement, addedFeatureGroupIds,
182 removedFeatureGroupIds);
184 addFeatureGroupsToLicenseAgreementRef(addedFeatureGroupIds, licenseAgreement);
185 removeFeatureGroupsToLicenseAgreementRef(removedFeatureGroupIds, licenseAgreement);
187 mdcDataDebugMessage.debugExitMessage(VLM_ID_LA_ID, licenseAgreement
188 .getVendorLicenseModelId(), licenseAgreement.getId());
192 public LicenseAgreementModel getLicenseAgreementModel(String vlmId, Version version,
193 String licenseAgreementId) {
195 mdcDataDebugMessage.debugEntryMessage(VLM_ID_LA_ID, vlmId, licenseAgreementId);
196 mdcDataDebugMessage.debugExitMessage(VLM_ID_LA_ID, vlmId, licenseAgreementId);
197 return vendorLicenseFacade.getLicenseAgreementModel(vlmId, version, licenseAgreementId);
201 public void deleteLicenseAgreement(String vlmId, Version version, String licenseAgreementId) {
202 mdcDataDebugMessage.debugEntryMessage(VLM_ID_LA_ID, vlmId, licenseAgreementId);
204 LicenseAgreementEntity input =
205 new LicenseAgreementEntity(vlmId, version, licenseAgreementId);
206 LicenseAgreementEntity retrieved = licenseAgreementDao.get(input);
207 VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE);
209 removeFeatureGroupsToLicenseAgreementRef(retrieved.getFeatureGroupIds(), retrieved);
211 licenseAgreementDao.delete(retrieved);
213 deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
214 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
215 retrieved.getName());
217 mdcDataDebugMessage.debugExitMessage(VLM_ID_LA_ID, vlmId, licenseAgreementId);
221 public Collection<FeatureGroupEntity> listFeatureGroups(String vlmId, Version version) {
222 mdcDataDebugMessage.debugEntryMessage(VLM_ID, vlmId);
223 mdcDataDebugMessage.debugExitMessage(VLM_ID, vlmId);
224 return vendorLicenseFacade.listFeatureGroups(vlmId, version);
228 public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup) {
230 .debugEntryMessage(VLM_ID, featureGroup.getVendorLicenseModelId());
231 mdcDataDebugMessage.debugExitMessage(VLM_ID, featureGroup.getId());
232 return vendorLicenseFacade.createFeatureGroup(featureGroup);
236 public void updateFeatureGroup(FeatureGroupEntity featureGroup,
237 Set<String> addedLicenseKeyGroups,
238 Set<String> removedLicenseKeyGroups,
239 Set<String> addedEntitlementPools,
240 Set<String> removedEntitlementPools) {
241 mdcDataDebugMessage.debugEntryMessage(VLM_ID_FG_ID, featureGroup
242 .getVendorLicenseModelId(), featureGroup.getId());
244 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
246 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
248 VersioningUtil.validateContainedEntitiesExistence(new LicenseKeyGroupEntity().getEntityType(),
249 removedLicenseKeyGroups, retrieved, retrieved.getLicenseKeyGroupIds());
250 VersioningUtil.validateContainedEntitiesExistence(new EntitlementPoolEntity().getEntityType(),
251 removedEntitlementPools, retrieved, retrieved.getEntitlementPoolIds());
253 VersioningUtil.validateEntitiesExistence(addedLicenseKeyGroups,
254 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(),
256 licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
257 VersioningUtil.validateEntitiesExistence(addedEntitlementPools,
258 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(),
260 entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE);
262 updateUniqueName(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
263 retrieved.getName(), featureGroup.getName(), featureGroup.getVendorLicenseModelId(),
264 featureGroup.getVersion().getId());
266 addLicenseKeyGroupsToFeatureGroupsRef(addedLicenseKeyGroups, featureGroup);
267 removeLicenseKeyGroupsToFeatureGroupsRef(removedLicenseKeyGroups, featureGroup);
268 addEntitlementPoolsToFeatureGroupsRef(addedEntitlementPools, featureGroup);
269 removeEntitlementPoolsToFeatureGroupsRef(removedEntitlementPools, featureGroup);
271 featureGroupDao.updateFeatureGroup(featureGroup, addedEntitlementPools, removedEntitlementPools,
272 addedLicenseKeyGroups, removedLicenseKeyGroups);
274 mdcDataDebugMessage.debugExitMessage(VLM_ID_FG_ID, featureGroup
275 .getVendorLicenseModelId(), featureGroup.getId());
279 public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup) {
280 mdcDataDebugMessage.debugEntryMessage(VLM_ID_FG_ID,
281 featureGroup.getVendorLicenseModelId(), featureGroup.getId());
283 mdcDataDebugMessage.debugExitMessage(VLM_ID_FG_ID,
284 featureGroup.getVendorLicenseModelId(), featureGroup.getId());
285 return vendorLicenseFacade.getFeatureGroupModel(featureGroup);
289 public void deleteFeatureGroup(FeatureGroupEntity featureGroup) {
290 mdcDataDebugMessage.debugEntryMessage(VLM_ID_FG_ID,
291 featureGroup.getVendorLicenseModelId(), featureGroup.getId());
293 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
295 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
297 removeLicenseKeyGroupsToFeatureGroupsRef(retrieved.getLicenseKeyGroupIds(), featureGroup);
298 removeEntitlementPoolsToFeatureGroupsRef(retrieved.getEntitlementPoolIds(), featureGroup);
300 for (String licenceAgreementId : retrieved.getReferencingLicenseAgreements()) {
301 licenseAgreementDao.removeFeatureGroup(
302 new LicenseAgreementEntity(featureGroup.getVendorLicenseModelId(),
303 featureGroup.getVersion(),
304 licenceAgreementId), featureGroup.getId());
307 featureGroupDao.delete(featureGroup);
309 deleteUniqueName(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
310 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
311 retrieved.getName());
314 .debugExitMessage(VLM_ID_FG_ID,
315 featureGroup.getVendorLicenseModelId(), featureGroup.getId());
319 public Collection<EntitlementPoolEntity> listEntitlementPools(String vlmId, Version version) {
320 mdcDataDebugMessage.debugEntryMessage(VLM_ID, vlmId);
321 mdcDataDebugMessage.debugExitMessage(VLM_ID, vlmId);
322 return vendorLicenseFacade.listEntitlementPools(vlmId, version);
326 public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool) {
328 .debugEntryMessage(VLM_ID, entitlementPool.getVendorLicenseModelId());
330 .debugExitMessage(VLM_ID, entitlementPool.getVendorLicenseModelId());
332 entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool
333 .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME
335 entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool
336 .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME
339 validateCreateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(),
340 entitlementPool.getVendorLicenseModelId());
341 return vendorLicenseFacade.createEntitlementPool(entitlementPool);
344 private void validateCreateDate(String startDate, String expiryDate,
345 String vendorLicenseModelId) {
346 mdcDataDebugMessage.debugEntryMessage("Start date and end date", startDate
349 LocalDate parsedStartDate = parseLocalDate(startDate);
350 LocalDate parsedExpiryDate = parseLocalDate(expiryDate);
353 validateIfStartAndExpiryDateIsNotNull(startDate, expiryDate,
354 vendorLicenseModelId, parsedStartDate, parsedExpiryDate);
356 if (startDate != null && expiryDate == null
357 && parsedStartDate.atStartOfDay().isBefore
358 (LocalDate.now().atStartOfDay())) {
359 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
360 LoggerTragetServiceName.VALIDATE_DATE_RANGE, ErrorLevel.ERROR.name(),
361 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE);
362 throw new CoreException(
363 new InvalidDateErrorBuilder(vendorLicenseModelId)
367 if (startDate == null && expiryDate != null) {
368 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
369 LoggerTragetServiceName.VALIDATE_DATE_RANGE, ErrorLevel.ERROR.name(),
370 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE);
371 throw new CoreException(
372 new InvalidDateErrorBuilder(vendorLicenseModelId)
377 mdcDataDebugMessage.debugExitMessage(null);
380 private void validateIfStartAndExpiryDateIsNotNull(String startDate, String expiryDate,
381 String vendorLicenseModelId,
382 LocalDate parsedStartDate,
383 LocalDate parsedExpiryDate) {
384 if (startDate != null && expiryDate != null
385 && isValidatStartAndExpiryDate(parsedStartDate, parsedExpiryDate)) {
386 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
387 LoggerTragetServiceName.VALIDATE_DATE_RANGE, ErrorLevel.ERROR.name(),
388 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE);
389 throw new CoreException(
390 new InvalidDateErrorBuilder(vendorLicenseModelId)
395 private boolean isValidatStartAndExpiryDate(LocalDate parsedStartDate,
396 LocalDate parsedExpiryDate) {
397 return parsedStartDate.atStartOfDay().isBefore(LocalDate.now().atStartOfDay())
398 || parsedExpiryDate.atStartOfDay().isEqual(parsedStartDate.atStartOfDay())
399 || parsedExpiryDate.isBefore(parsedStartDate);
402 private static LocalDate parseLocalDate(String date) {
403 if (date == null || date.isEmpty()) {
407 return LocalDate.parse(date, FORMATTER );
410 private void validateUpdateDate(String startDate, String expiryDate,
411 String vendorLicenseModelId) {
412 mdcDataDebugMessage.debugEntryMessage("Start date and end date", startDate
415 LocalDate parsedStartDate = parseLocalDate(startDate);
416 LocalDate parsedExpiryDate = parseLocalDate(expiryDate);
418 if (startDate != null && expiryDate != null
419 && (parsedExpiryDate.atStartOfDay()
420 .isEqual(parsedStartDate.atStartOfDay())
421 || parsedExpiryDate.isBefore(parsedStartDate ))) {
422 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
423 LoggerTragetServiceName.VALIDATE_DATE_RANGE,ErrorLevel.ERROR.name(),
424 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE);
425 throw new CoreException(
426 new InvalidDateErrorBuilder(vendorLicenseModelId)
430 if (startDate == null && expiryDate != null) {
431 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
432 LoggerTragetServiceName.VALIDATE_DATE_RANGE, ErrorLevel.ERROR.name(),
433 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE);
434 throw new CoreException(
435 new InvalidDateErrorBuilder(vendorLicenseModelId)
440 mdcDataDebugMessage.debugExitMessage(null);
444 public void updateEntitlementPool(EntitlementPoolEntity entitlementPool) {
445 mdcDataDebugMessage.debugEntryMessage(VLM_ID_EP_ID, entitlementPool
446 .getVendorLicenseModelId(), entitlementPool.getId());
448 entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool
449 .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME
451 entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool
452 .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME
455 validateUpdateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(),
456 entitlementPool.getVendorLicenseModelId());
457 vendorLicenseFacade.updateEntitlementPool(entitlementPool);
459 mdcDataDebugMessage.debugExitMessage(VLM_ID_EP_ID, entitlementPool
460 .getVendorLicenseModelId(), entitlementPool.getId());
464 public EntitlementPoolEntity getEntitlementPool(EntitlementPoolEntity entitlementPool) {
465 mdcDataDebugMessage.debugEntryMessage(VLM_ID_EP_ID, entitlementPool
466 .getVendorLicenseModelId(), entitlementPool.getId());
468 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
470 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
471 DateTimeFormatter targetFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
472 if (retrieved.getStartDate() != null) {
473 retrieved.setStartDate(LocalDate.parse(retrieved.getStartDate(), FORMATTER ).format
477 if (retrieved.getExpiryDate() != null) {
478 retrieved.setExpiryDate(LocalDate.parse(retrieved.getExpiryDate(), FORMATTER ).format
482 mdcDataDebugMessage.debugExitMessage(VLM_ID_EP_ID, entitlementPool
483 .getVendorLicenseModelId(), entitlementPool.getId());
488 public void deleteEntitlementPool(EntitlementPoolEntity entitlementPool) {
489 mdcDataDebugMessage.debugEntryMessage(VLM_ID_EP_ID, entitlementPool
490 .getVendorLicenseModelId(), entitlementPool.getId());
492 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
494 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
496 for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) {
497 featureGroupDao.removeEntitlementPool(
498 new FeatureGroupEntity(entitlementPool.getVendorLicenseModelId(),
499 entitlementPool.getVersion(),
500 referencingFeatureGroupId), entitlementPool.getId());
503 deleteChildLimits(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion(),
504 entitlementPool.getId());
506 entitlementPoolDao.delete(entitlementPool);
508 deleteUniqueName(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
509 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
510 retrieved.getName());
512 mdcDataDebugMessage.debugExitMessage(VLM_ID_EP_ID, entitlementPool
513 .getVendorLicenseModelId(), entitlementPool.getId());
516 protected void deleteChildLimits(String vlmId, Version version, String epLkgId) {
517 Optional<Collection<LimitEntity>> limitEntities = Optional.ofNullable(
518 listLimits(vlmId, version, epLkgId));
519 limitEntities.ifPresent(entities -> entities.forEach(this::deleteLimit));
523 public Collection<LicenseKeyGroupEntity> listLicenseKeyGroups(String vlmId, Version version) {
524 mdcDataDebugMessage.debugEntryMessage(VLM_ID, vlmId);
525 mdcDataDebugMessage.debugExitMessage(VLM_ID, vlmId);
526 return vendorLicenseFacade.listLicenseKeyGroups(vlmId, version);
530 public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
532 .debugEntryMessage(VLM_ID, licenseKeyGroup.getVendorLicenseModelId());
534 mdcDataDebugMessage.debugExitMessage(VLM_ID, licenseKeyGroup
535 .getVendorLicenseModelId());
537 licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup
538 .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate() + EP_POOL_START_TIME
540 licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup
541 .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate() + EP_POOL_EXPIRY_TIME
544 validateCreateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(),
545 licenseKeyGroup.getVendorLicenseModelId());
546 return vendorLicenseFacade.createLicenseKeyGroup(licenseKeyGroup);
550 public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
551 mdcDataDebugMessage.debugEntryMessage(VLM_ID_LKG_ID, licenseKeyGroup
552 .getVendorLicenseModelId(), licenseKeyGroup.getId());
554 licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup
555 .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate() + EP_POOL_START_TIME
557 licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup
558 .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate() + EP_POOL_EXPIRY_TIME
561 validateUpdateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(),
562 licenseKeyGroup.getVendorLicenseModelId());
563 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroup);
565 mdcDataDebugMessage.debugExitMessage(VLM_ID_LKG_ID, licenseKeyGroup
566 .getVendorLicenseModelId(), licenseKeyGroup.getId());
570 public LicenseKeyGroupEntity getLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
571 mdcDataDebugMessage.debugEntryMessage(VLM_ID_LKG_ID, licenseKeyGroup
572 .getVendorLicenseModelId(), licenseKeyGroup.getId());
574 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
576 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
578 mdcDataDebugMessage.debugExitMessage(VLM_ID_LKG_ID, licenseKeyGroup
579 .getVendorLicenseModelId(), licenseKeyGroup.getId());
584 public void deleteLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
585 mdcDataDebugMessage.debugEntryMessage(VLM_ID_LKG_ID, licenseKeyGroup
586 .getVendorLicenseModelId(), licenseKeyGroup.getId());
588 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
590 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
592 for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) {
593 featureGroupDao.removeLicenseKeyGroup(
594 new FeatureGroupEntity(licenseKeyGroup.getVendorLicenseModelId(),
595 licenseKeyGroup.getVersion(),
596 referencingFeatureGroupId), licenseKeyGroup.getId());
599 deleteChildLimits(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion(),
600 licenseKeyGroup.getId());
602 licenseKeyGroupDao.delete(licenseKeyGroup);
604 deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
605 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
606 retrieved.getName());
608 mdcDataDebugMessage.debugExitMessage(VLM_ID_LKG_ID, licenseKeyGroup
609 .getVendorLicenseModelId(), licenseKeyGroup.getId());
613 public LimitEntity createLimit(LimitEntity limit) {
615 .debugEntryMessage(VLM_ID, limit.getVendorLicenseModelId(), EP_LKGID, limit
618 .debugExitMessage(VLM_ID, limit.getVendorLicenseModelId(), EP_LKGID, limit
620 validateLimit(limit);
621 LimitEntity createdLimit = vendorLicenseFacade.createLimit(limit);
622 updateParentForLimit(limit);
626 private void validateLimit(LimitEntity limit) {
627 Collection<LimitEntity> limitList =
628 listLimits(limit.getVendorLicenseModelId(), limit.getVersion()
629 , limit.getEpLkgId());
631 if (!isLimitNameUnique(limitList, limit.getName(), limit.getType(), limit.getId())) {
632 final ErrorCode duplicateLimitNameErrorBuilder =
633 LimitErrorBuilder.getDuplicateNameErrorbuilder(limit.getName(), limit.getType().name());
634 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
635 LoggerServiceName.Create_LIMIT.toString(), ErrorLevel.ERROR.name(),
636 LoggerErrorCode.DATA_ERROR.getErrorCode(),
637 duplicateLimitNameErrorBuilder.message());
638 throw new CoreException(duplicateLimitNameErrorBuilder);
642 private boolean isLimitNameUnique(Collection<LimitEntity> limitList, String name, LimitType
644 for (LimitEntity limit : limitList) {
645 if (limit.getName().equalsIgnoreCase(name) &&
646 limit.getType().name().equalsIgnoreCase(type.name())) {
647 if (id != null && limit.getId().equals(id)) {
657 public Collection<LimitEntity> listLimits(String vlmId, Version version, String epLkgId) {
658 mdcDataDebugMessage.debugEntryMessage(VLM_ID, vlmId, EP_LKGID, epLkgId);
659 mdcDataDebugMessage.debugExitMessage(VLM_ID, vlmId, EP_LKGID, epLkgId);
660 return vendorLicenseFacade.listLimits(vlmId, version, epLkgId);
664 public void deleteLimit(LimitEntity limitEntity) {
665 mdcDataDebugMessage.debugEntryMessage("VLM id, EP id, Limit Id", limitEntity
666 .getVendorLicenseModelId(), limitEntity.getEpLkgId(), limitEntity.getId());
668 if (!isLimitPresent(limitEntity)) {
670 .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
672 LimitEntity retrieved = limitDao.get(limitEntity);
674 .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
676 limitDao.delete(limitEntity);
678 updateParentForLimit(limitEntity);
680 mdcDataDebugMessage.debugExitMessage("VLM id, EP id, Limit Id", limitEntity
681 .getVendorLicenseModelId(), limitEntity.getEpLkgId(), limitEntity.getId());
685 public void updateLimit(LimitEntity limit) {
687 .debugEntryMessage(VLM_ID, limit.getVendorLicenseModelId(), EP_LKGID, limit
690 validateLimit(limit);
691 vendorLicenseFacade.updateLimit(limit);
692 updateParentForLimit(limit);
694 .debugExitMessage(VLM_ID, limit.getVendorLicenseModelId(), EP_LKGID, limit
698 private boolean isLimitPresent(LimitEntity limit) {
699 return limitDao.isLimitPresent(limit);
703 public LimitEntity getLimit(LimitEntity limitEntity) {
704 mdcDataDebugMessage.debugEntryMessage(VLM_ID, limitEntity.getVendorLicenseModelId(),
705 EP_LKGID, limitEntity.getEpLkgId());
707 if (!isLimitPresent(limitEntity)) {
709 .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
711 LimitEntity retrieved = limitDao.get(limitEntity);
713 .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
715 mdcDataDebugMessage.debugExitMessage(VLM_ID, limitEntity.getVendorLicenseModelId(),
716 EP_LKGID, limitEntity.getEpLkgId());
721 * update Parent of limit (EP/LKG) versionuuid when limit is modified so that limit updates are
722 * captured in VLM XML
724 private void updateParentForLimit(LimitEntity limit) {
725 mdcDataDebugMessage.debugEntryMessage(VLM_ID, limit.getVendorLicenseModelId(),
726 EP_LKGID, limit.getEpLkgId(), "Limit Parent ", limit.getParent());
727 if ("EntitlementPool".equals(limit.getParent())) {
728 EntitlementPoolEntity entitlementPoolEntity =
729 entitlementPoolDao.get(new EntitlementPoolEntity(limit.getVendorLicenseModelId(),
730 limit.getVersion(), limit.getEpLkgId()));
731 vendorLicenseFacade.updateEntitlementPool(entitlementPoolEntity);
734 if ("LicenseKeyGroup".equals(limit.getParent())) {
735 LicenseKeyGroupEntity licenseKeyGroupEntity = licenseKeyGroupDao.get(
736 new LicenseKeyGroupEntity(limit.getVendorLicenseModelId(), limit.getVersion(),
737 limit.getEpLkgId()));
738 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroupEntity);
741 mdcDataDebugMessage.debugEntryMessage(VLM_ID, limit.getVendorLicenseModelId(),
742 EP_LKGID, limit.getEpLkgId(), "Limit Parent ", limit.getParent());
745 protected void addFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds,
746 LicenseAgreementEntity licenseAgreement) {
747 if (featureGroupIds != null) {
748 for (String featureGroupId : featureGroupIds) {
749 featureGroupDao.addReferencingLicenseAgreement(
750 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
751 licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId());
756 protected void removeFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds,
757 LicenseAgreementEntity licenseAgreement) {
758 if (featureGroupIds != null) {
759 for (String featureGroupId : featureGroupIds) {
760 featureGroupDao.removeReferencingLicenseAgreement(
761 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
762 licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId());
767 protected void addLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds,
768 FeatureGroupEntity featureGroup) {
769 if (licenseKeyGroupIds != null) {
770 for (String licenseKeyGroupId : licenseKeyGroupIds) {
771 licenseKeyGroupDao.addReferencingFeatureGroup(
772 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
773 featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId());
778 protected void removeLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds,
779 FeatureGroupEntity featureGroup) {
780 if (licenseKeyGroupIds != null) {
781 for (String licenseKeyGroupId : licenseKeyGroupIds) {
782 licenseKeyGroupDao.removeReferencingFeatureGroup(
783 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
784 featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId());
789 protected void addEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds,
790 FeatureGroupEntity featureGroup) {
791 if (entitlementPoolIds != null) {
792 for (String entitlementPoolId : entitlementPoolIds) {
793 entitlementPoolDao.addReferencingFeatureGroup(
794 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(),
795 featureGroup.getVersion(), entitlementPoolId), featureGroup.getId());
800 protected void removeEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds,
801 FeatureGroupEntity featureGroup) {
802 if (entitlementPoolIds != null) {
803 for (String entitlementPoolId : entitlementPoolIds) {
804 entitlementPoolDao.removeReferencingFeatureGroup(
805 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(),
806 featureGroup.getVersion(), entitlementPoolId), featureGroup.getId());
811 protected void updateUniqueName(String uniqueValueType, String oldName, String newName, String...
814 .updateUniqueValue(uniqueValueType, oldName, newName, context);
817 protected void deleteUniqueName(String uniqueValueType, String... uniqueCombination) {
818 UniqueValueUtil.deleteUniqueValue(uniqueValueType, uniqueCombination);