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.apache.commons.collections.CollectionUtils;
20 import org.openecomp.core.dao.UniqueValueDao;
21 import org.openecomp.core.util.UniqueValueUtil;
22 import org.openecomp.core.utilities.CommonMethods;
23 import org.openecomp.sdc.common.errors.CoreException;
24 import org.openecomp.sdc.common.errors.ErrorCode;
25 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
26 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
27 import org.openecomp.sdc.vendorlicense.dao.*;
28 import org.openecomp.sdc.vendorlicense.dao.types.*;
29 import org.openecomp.sdc.vendorlicense.errors.InvalidDateErrorBuilder;
30 import org.openecomp.sdc.vendorlicense.errors.LimitErrorBuilder;
31 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
32 import org.openecomp.sdc.versioning.VersioningUtil;
33 import org.openecomp.sdc.versioning.dao.types.Version;
35 import java.time.LocalDate;
36 import java.time.format.DateTimeFormatter;
37 import java.util.Collection;
38 import java.util.Objects;
39 import java.util.Optional;
42 public class VendorLicenseManagerImpl implements VendorLicenseManager {
43 private final UniqueValueUtil uniqueValueUtil;
44 private final VendorLicenseFacade vendorLicenseFacade;
45 private final VendorLicenseModelDao vendorLicenseModelDao;
46 private final LicenseAgreementDao licenseAgreementDao;
47 private final FeatureGroupDao featureGroupDao;
48 private final EntitlementPoolDao entitlementPoolDao;
49 private final LicenseKeyGroupDao licenseKeyGroupDao;
50 private final LimitDao limitDao;
52 private static final String EP_POOL_START_TIME = "T00:00:00Z";
53 private static final String EP_POOL_EXPIRY_TIME = "T23:59:59Z";
54 private static final DateTimeFormatter FORMATTER
55 = DateTimeFormatter.ofPattern("MM/dd/yyyy'T'HH:mm:ss'Z'");
56 public VendorLicenseManagerImpl(VendorLicenseFacade vendorLicenseFacade,
57 VendorLicenseModelDao vendorLicenseModelDao,
58 LicenseAgreementDao licenseAgreementDao,
59 FeatureGroupDao featureGroupDao,
60 EntitlementPoolDao entitlementPoolDao,
61 LicenseKeyGroupDao licenseKeyGroupDao,
63 UniqueValueDao uniqueValueDao) {
64 this.vendorLicenseFacade = vendorLicenseFacade;
65 this.vendorLicenseModelDao = vendorLicenseModelDao;
66 this.licenseAgreementDao = licenseAgreementDao;
67 this.featureGroupDao = featureGroupDao;
68 this.entitlementPoolDao = entitlementPoolDao;
69 this.licenseKeyGroupDao = licenseKeyGroupDao;
70 this.limitDao = limitDao;
71 this.uniqueValueUtil = new UniqueValueUtil(uniqueValueDao);
76 public void validate(String vendorLicenseModelId, Version version) {
77 vendorLicenseFacade.validate(vendorLicenseModelId, version);
81 public VendorLicenseModelEntity createVendorLicenseModel(
82 VendorLicenseModelEntity vendorLicenseModelEntity) {
83 vendorLicenseModelDao.create(vendorLicenseModelEntity);
84 return vendorLicenseModelEntity;
88 public void updateVendorLicenseModel(VendorLicenseModelEntity vendorLicenseModelEntity) {
89 VendorLicenseModelEntity retrieved = vendorLicenseModelDao.get(vendorLicenseModelEntity);
90 if (retrieved == null){
91 throw new CoreException((new ErrorCode.ErrorCodeBuilder()
92 .withMessage(String.format("Vlm with id %s and version %s does not exist.",
93 vendorLicenseModelEntity.getId(), vendorLicenseModelEntity.getVersion().getId()))).build());
96 String existingVendorName = retrieved.getVendorName();
98 updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME, existingVendorName,
99 vendorLicenseModelEntity.getVendorName());
100 vendorLicenseModelDao.update(vendorLicenseModelEntity);
104 public VendorLicenseModelEntity getVendorLicenseModel(String vlmId, Version version) {
105 return vendorLicenseFacade.getVendorLicenseModel(vlmId, version);
109 public void deleteVendorLicenseModel(String vlmId, Version version) {
110 throw new UnsupportedOperationException(VendorLicenseConstants.UNSUPPORTED_OPERATION_ERROR);
114 public Collection<LicenseAgreementEntity> listLicenseAgreements(String vlmId, Version version) {
115 return licenseAgreementDao.list(new LicenseAgreementEntity(vlmId, version, null));
119 public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement) {
120 return vendorLicenseFacade.createLicenseAgreement(licenseAgreement);
124 public void updateLicenseAgreement(LicenseAgreementEntity licenseAgreement,
125 Set<String> addedFeatureGroupIds,
126 Set<String> removedFeatureGroupIds) {
127 LicenseAgreementEntity retrieved = licenseAgreementDao.get(licenseAgreement);
129 .validateEntityExistence(retrieved, licenseAgreement, VendorLicenseModelEntity.ENTITY_TYPE);
130 VersioningUtil.validateContainedEntitiesExistence(new FeatureGroupEntity().getEntityType(),
131 removedFeatureGroupIds, retrieved, retrieved.getFeatureGroupIds());
132 VersioningUtil.validateEntitiesExistence(addedFeatureGroupIds,
133 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
134 licenseAgreement.getVersion(),
136 featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
138 updateUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
139 retrieved.getName(), licenseAgreement.getName(), licenseAgreement.getVendorLicenseModelId(),
140 licenseAgreement.getVersion().getId());
141 licenseAgreementDao.updateColumnsAndDeltaFeatureGroupIds(licenseAgreement, addedFeatureGroupIds,
142 removedFeatureGroupIds);
144 addFeatureGroupsToLicenseAgreementRef(addedFeatureGroupIds, licenseAgreement);
145 removeFeatureGroupsToLicenseAgreementRef(removedFeatureGroupIds, licenseAgreement);
149 public LicenseAgreementModel getLicenseAgreementModel(String vlmId, Version version,
150 String licenseAgreementId) {
151 return vendorLicenseFacade.getLicenseAgreementModel(vlmId, version, licenseAgreementId);
155 public void deleteLicenseAgreement(String vlmId, Version version, String licenseAgreementId) {
156 LicenseAgreementEntity input =
157 new LicenseAgreementEntity(vlmId, version, licenseAgreementId);
158 LicenseAgreementEntity retrieved = licenseAgreementDao.get(input);
159 VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE);
161 removeFeatureGroupsToLicenseAgreementRef(retrieved.getFeatureGroupIds(), retrieved);
163 licenseAgreementDao.delete(retrieved);
165 deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
166 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
167 retrieved.getName());
171 public Collection<FeatureGroupEntity> listFeatureGroups(String vlmId, Version version) {
172 return vendorLicenseFacade.listFeatureGroups(vlmId, version);
176 public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup) {
177 return vendorLicenseFacade.createFeatureGroup(featureGroup);
181 public void updateFeatureGroup(FeatureGroupEntity featureGroup,
182 Set<String> addedLicenseKeyGroups,
183 Set<String> removedLicenseKeyGroups,
184 Set<String> addedEntitlementPools,
185 Set<String> removedEntitlementPools) {
186 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
188 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
190 VersioningUtil.validateContainedEntitiesExistence(new LicenseKeyGroupEntity().getEntityType(),
191 removedLicenseKeyGroups, retrieved, retrieved.getLicenseKeyGroupIds());
192 VersioningUtil.validateContainedEntitiesExistence(new EntitlementPoolEntity().getEntityType(),
193 removedEntitlementPools, retrieved, retrieved.getEntitlementPoolIds());
195 VersioningUtil.validateEntitiesExistence(addedLicenseKeyGroups,
196 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(),
198 licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
199 VersioningUtil.validateEntitiesExistence(addedEntitlementPools,
200 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(),
202 entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE);
204 updateUniqueName(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
205 retrieved.getName(), featureGroup.getName(), featureGroup.getVendorLicenseModelId(),
206 featureGroup.getVersion().getId());
208 addLicenseKeyGroupsToFeatureGroupsRef(addedLicenseKeyGroups, featureGroup);
209 removeLicenseKeyGroupsToFeatureGroupsRef(removedLicenseKeyGroups, featureGroup);
210 addEntitlementPoolsToFeatureGroupsRef(addedEntitlementPools, featureGroup);
211 removeEntitlementPoolsToFeatureGroupsRef(removedEntitlementPools, featureGroup);
213 featureGroupDao.updateFeatureGroup(featureGroup, addedEntitlementPools, removedEntitlementPools,
214 addedLicenseKeyGroups, removedLicenseKeyGroups);
216 updateEpLkgOnMrnChange(featureGroup, addedLicenseKeyGroups, addedEntitlementPools, retrieved);
220 * If MRN is updated in feature group then update all linked EPs and Lkgs with new versionUuId
221 * @param featureGroup - Feature Group entity which is requested for update
222 * @param addedLicenseKeyGroups - LicenseKeyGroups added with Feature Group
223 * @param addedEntitlementPools - EntitlementPools added with Feature Group
224 * @param retrieved - Feature Group entity fetched from database
226 private void updateEpLkgOnMrnChange(FeatureGroupEntity featureGroup,
227 Set<String> addedLicenseKeyGroups,
228 Set<String> addedEntitlementPools,
229 FeatureGroupEntity retrieved) {
230 if (Objects.nonNull(retrieved.getManufacturerReferenceNumber())
231 && !retrieved.getManufacturerReferenceNumber().equals(featureGroup
232 .getManufacturerReferenceNumber())) {
233 if (CollectionUtils.isEmpty(addedEntitlementPools)) {
234 updateEntitlementPool(featureGroup, retrieved.getEntitlementPoolIds());
236 updateEntitlementPool(featureGroup, addedEntitlementPools);
239 if (CollectionUtils.isEmpty(addedLicenseKeyGroups)) {
240 updateLicenseKeyGroup(featureGroup, retrieved.getLicenseKeyGroupIds());
242 updateLicenseKeyGroup(featureGroup, addedLicenseKeyGroups);
247 private void updateEntitlementPool(FeatureGroupEntity featureGroup,
248 Set<String> entitlementPoolIds) {
249 for (String epId: entitlementPoolIds) {
250 final EntitlementPoolEntity entitlementPoolEntity = entitlementPoolDao
251 .get(new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup
252 .getVersion(), epId));
253 if (Objects.nonNull(entitlementPoolEntity)) {
254 entitlementPoolEntity.setVersionUuId(CommonMethods.nextUuId());
255 entitlementPoolDao.update(entitlementPoolEntity);
260 private void updateLicenseKeyGroup(FeatureGroupEntity featureGroup,
261 Set<String> licenseKeyGroupIds) {
262 for (String lkgId: licenseKeyGroupIds) {
263 final LicenseKeyGroupEntity licenseKeyGroupEntity = licenseKeyGroupDao
264 .get(new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
265 featureGroup.getVersion(), lkgId));
266 if (Objects.nonNull(licenseKeyGroupEntity)) {
267 licenseKeyGroupEntity.setVersionUuId(CommonMethods.nextUuId());
268 licenseKeyGroupDao.update(licenseKeyGroupEntity);
274 public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup) {
275 return vendorLicenseFacade.getFeatureGroupModel(featureGroup);
279 public void deleteFeatureGroup(FeatureGroupEntity featureGroup) {
280 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
282 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
284 removeLicenseKeyGroupsToFeatureGroupsRef(retrieved.getLicenseKeyGroupIds(), featureGroup);
285 removeEntitlementPoolsToFeatureGroupsRef(retrieved.getEntitlementPoolIds(), featureGroup);
287 for (String licenceAgreementId : retrieved.getReferencingLicenseAgreements()) {
288 licenseAgreementDao.removeFeatureGroup(
289 new LicenseAgreementEntity(featureGroup.getVendorLicenseModelId(),
290 featureGroup.getVersion(),
291 licenceAgreementId), featureGroup.getId());
294 featureGroupDao.delete(featureGroup);
296 deleteUniqueName(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
297 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
298 retrieved.getName());
302 public Collection<EntitlementPoolEntity> listEntitlementPools(String vlmId, Version version) {
303 return vendorLicenseFacade.listEntitlementPools(vlmId, version);
307 public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool) {
308 entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool
309 .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME
311 entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool
312 .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME
315 validateCreateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(),
316 entitlementPool.getVendorLicenseModelId());
317 return vendorLicenseFacade.createEntitlementPool(entitlementPool);
320 private void validateCreateDate(String startDate, String expiryDate,
321 String vendorLicenseModelId) {
322 LocalDate parsedStartDate = parseLocalDate(startDate);
323 LocalDate parsedExpiryDate = parseLocalDate(expiryDate);
326 validateIfStartAndExpiryDateIsNotNull(startDate, expiryDate,
327 vendorLicenseModelId, parsedStartDate, parsedExpiryDate);
329 if (startDate != null && expiryDate == null
330 && parsedStartDate.atStartOfDay().isBefore
331 (LocalDate.now().atStartOfDay())) {
332 throw new CoreException(
333 new InvalidDateErrorBuilder(vendorLicenseModelId)
337 if (startDate == null && expiryDate != null) {
338 throw new CoreException(
339 new InvalidDateErrorBuilder(vendorLicenseModelId)
345 private void validateIfStartAndExpiryDateIsNotNull(String startDate, String expiryDate,
346 String vendorLicenseModelId,
347 LocalDate parsedStartDate,
348 LocalDate parsedExpiryDate) {
349 if (startDate != null && expiryDate != null
350 && isValidatStartAndExpiryDate(parsedStartDate, parsedExpiryDate)) {
351 throw new CoreException(
352 new InvalidDateErrorBuilder(vendorLicenseModelId)
357 private boolean isValidatStartAndExpiryDate(LocalDate parsedStartDate,
358 LocalDate parsedExpiryDate) {
359 return parsedStartDate.atStartOfDay().isBefore(LocalDate.now().atStartOfDay())
360 || parsedExpiryDate.atStartOfDay().isEqual(parsedStartDate.atStartOfDay())
361 || parsedExpiryDate.isBefore(parsedStartDate);
364 private static LocalDate parseLocalDate(String date) {
365 if (date == null || date.isEmpty()) {
369 return LocalDate.parse(date, FORMATTER );
372 private void validateUpdateDate(String startDate, String expiryDate,
373 String vendorLicenseModelId) {
374 LocalDate parsedStartDate = parseLocalDate(startDate);
375 LocalDate parsedExpiryDate = parseLocalDate(expiryDate);
377 if (startDate != null && expiryDate != null
378 && (parsedExpiryDate.atStartOfDay()
379 .isEqual(parsedStartDate.atStartOfDay())
380 || parsedExpiryDate.isBefore(parsedStartDate ))) {
381 throw new CoreException(
382 new InvalidDateErrorBuilder(vendorLicenseModelId)
386 if (startDate == null && expiryDate != null) {
387 throw new CoreException(
388 new InvalidDateErrorBuilder(vendorLicenseModelId)
395 public void updateEntitlementPool(EntitlementPoolEntity entitlementPool) {
396 entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool
397 .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME
399 entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool
400 .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME
403 validateUpdateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(),
404 entitlementPool.getVendorLicenseModelId());
405 vendorLicenseFacade.updateEntitlementPool(entitlementPool);
409 public EntitlementPoolEntity getEntitlementPool(EntitlementPoolEntity entitlementPool) {
410 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
412 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
413 DateTimeFormatter targetFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
414 if (retrieved.getStartDate() != null) {
415 retrieved.setStartDate(LocalDate.parse(retrieved.getStartDate(), FORMATTER ).format
419 if (retrieved.getExpiryDate() != null) {
420 retrieved.setExpiryDate(LocalDate.parse(retrieved.getExpiryDate(), FORMATTER ).format
427 public void deleteEntitlementPool(EntitlementPoolEntity entitlementPool) {
428 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
430 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
432 for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) {
433 featureGroupDao.removeEntitlementPool(
434 new FeatureGroupEntity(entitlementPool.getVendorLicenseModelId(),
435 entitlementPool.getVersion(),
436 referencingFeatureGroupId), entitlementPool.getId());
439 deleteChildLimits(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion(),
440 entitlementPool.getId());
442 entitlementPoolDao.delete(entitlementPool);
444 deleteUniqueName(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
445 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
446 retrieved.getName());
449 protected void deleteChildLimits(String vlmId, Version version, String epLkgId) {
450 Optional<Collection<LimitEntity>> limitEntities = Optional.ofNullable(
451 listLimits(vlmId, version, epLkgId));
452 limitEntities.ifPresent(entities -> entities.forEach(this::deleteLimit));
456 public Collection<LicenseKeyGroupEntity> listLicenseKeyGroups(String vlmId, Version version) {
457 return vendorLicenseFacade.listLicenseKeyGroups(vlmId, version);
461 public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
462 licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup
463 .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate() + EP_POOL_START_TIME
465 licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup
466 .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate() + EP_POOL_EXPIRY_TIME
469 validateCreateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(),
470 licenseKeyGroup.getVendorLicenseModelId());
471 return vendorLicenseFacade.createLicenseKeyGroup(licenseKeyGroup);
475 public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
476 licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup
477 .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate() + EP_POOL_START_TIME
479 licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup
480 .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate() + EP_POOL_EXPIRY_TIME
483 validateUpdateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(),
484 licenseKeyGroup.getVendorLicenseModelId());
485 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroup);
489 public LicenseKeyGroupEntity getLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
490 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
492 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
497 public void deleteLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
498 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
500 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
502 for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) {
503 featureGroupDao.removeLicenseKeyGroup(
504 new FeatureGroupEntity(licenseKeyGroup.getVendorLicenseModelId(),
505 licenseKeyGroup.getVersion(),
506 referencingFeatureGroupId), licenseKeyGroup.getId());
509 deleteChildLimits(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion(),
510 licenseKeyGroup.getId());
512 licenseKeyGroupDao.delete(licenseKeyGroup);
514 deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
515 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
516 retrieved.getName());
520 public LimitEntity createLimit(LimitEntity limit) {
521 validateLimit(limit);
522 LimitEntity createdLimit = vendorLicenseFacade.createLimit(limit);
523 updateParentForLimit(limit);
527 private void validateLimit(LimitEntity limit) {
528 Collection<LimitEntity> limitList =
529 listLimits(limit.getVendorLicenseModelId(), limit.getVersion()
530 , limit.getEpLkgId());
532 if (!isLimitNameUnique(limitList, limit.getName(), limit.getType(), limit.getId())) {
533 final ErrorCode duplicateLimitNameErrorBuilder =
534 LimitErrorBuilder.getDuplicateNameErrorbuilder(limit.getName(), limit.getType().name());
535 throw new CoreException(duplicateLimitNameErrorBuilder);
539 private boolean isLimitNameUnique(Collection<LimitEntity> limitList, String name, LimitType
541 for (LimitEntity limit : limitList) {
542 if (limit.getName().equalsIgnoreCase(name) &&
543 limit.getType().name().equalsIgnoreCase(type.name())) {
544 if (id != null && limit.getId().equals(id)) {
554 public Collection<LimitEntity> listLimits(String vlmId, Version version, String epLkgId) {
555 return vendorLicenseFacade.listLimits(vlmId, version, epLkgId);
559 public void deleteLimit(LimitEntity limitEntity) {
560 if (!isLimitPresent(limitEntity)) {
562 .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
564 LimitEntity retrieved = limitDao.get(limitEntity);
566 .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
568 limitDao.delete(limitEntity);
570 updateParentForLimit(limitEntity);
574 public void updateLimit(LimitEntity limit) {
576 validateLimit(limit);
577 vendorLicenseFacade.updateLimit(limit);
578 updateParentForLimit(limit);
581 private boolean isLimitPresent(LimitEntity limit) {
582 return limitDao.isLimitPresent(limit);
586 public LimitEntity getLimit(LimitEntity limitEntity) {
587 if (!isLimitPresent(limitEntity)) {
589 .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
591 LimitEntity retrieved = limitDao.get(limitEntity);
593 .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
598 * update Parent of limit (EP/LKG) versionuuid when limit is modified so that limit updates are
599 * captured in VLM XML
601 private void updateParentForLimit(LimitEntity limit) {
602 if ("EntitlementPool".equals(limit.getParent())) {
603 EntitlementPoolEntity entitlementPoolEntity =
604 entitlementPoolDao.get(new EntitlementPoolEntity(limit.getVendorLicenseModelId(),
605 limit.getVersion(), limit.getEpLkgId()));
606 vendorLicenseFacade.updateEntitlementPool(entitlementPoolEntity);
609 if ("LicenseKeyGroup".equals(limit.getParent())) {
610 LicenseKeyGroupEntity licenseKeyGroupEntity = licenseKeyGroupDao.get(
611 new LicenseKeyGroupEntity(limit.getVendorLicenseModelId(), limit.getVersion(),
612 limit.getEpLkgId()));
613 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroupEntity);
617 protected void addFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds,
618 LicenseAgreementEntity licenseAgreement) {
619 if (featureGroupIds != null) {
620 for (String featureGroupId : featureGroupIds) {
621 featureGroupDao.addReferencingLicenseAgreement(
622 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
623 licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId());
628 protected void removeFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds,
629 LicenseAgreementEntity licenseAgreement) {
630 if (featureGroupIds != null) {
631 for (String featureGroupId : featureGroupIds) {
632 featureGroupDao.removeReferencingLicenseAgreement(
633 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
634 licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId());
639 protected void addLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds,
640 FeatureGroupEntity featureGroup) {
641 if (licenseKeyGroupIds != null) {
642 for (String licenseKeyGroupId : licenseKeyGroupIds) {
643 licenseKeyGroupDao.addReferencingFeatureGroup(
644 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
645 featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId());
650 protected void removeLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds,
651 FeatureGroupEntity featureGroup) {
652 if (licenseKeyGroupIds != null) {
653 for (String licenseKeyGroupId : licenseKeyGroupIds) {
654 licenseKeyGroupDao.removeReferencingFeatureGroup(
655 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
656 featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId());
661 protected void addEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds,
662 FeatureGroupEntity featureGroup) {
663 if (entitlementPoolIds != null) {
664 for (String entitlementPoolId : entitlementPoolIds) {
665 entitlementPoolDao.addReferencingFeatureGroup(
666 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(),
667 featureGroup.getVersion(), entitlementPoolId), featureGroup.getId());
672 protected void removeEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds,
673 FeatureGroupEntity featureGroup) {
674 if (entitlementPoolIds != null) {
675 for (String entitlementPoolId : entitlementPoolIds) {
676 entitlementPoolDao.removeReferencingFeatureGroup(
677 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(),
678 featureGroup.getVersion(), entitlementPoolId), featureGroup.getId());
683 protected void updateUniqueName(String uniqueValueType, String oldName, String newName, String...
686 .updateUniqueValue(uniqueValueType, oldName, newName, context);
689 protected void deleteUniqueName(String uniqueValueType, String... uniqueCombination) {
690 uniqueValueUtil.deleteUniqueValue(uniqueValueType, uniqueCombination);