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.util.UniqueValueUtil;
21 import org.openecomp.core.utilities.CommonMethods;
22 import org.openecomp.sdc.common.errors.CoreException;
23 import org.openecomp.sdc.common.errors.ErrorCode;
24 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
25 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
26 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
27 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
28 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao;
29 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
30 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
31 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
32 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
33 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
34 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel;
35 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
36 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementModel;
37 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
38 import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity;
39 import org.openecomp.sdc.vendorlicense.dao.types.LimitType;
40 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
41 import org.openecomp.sdc.vendorlicense.errors.InvalidDateErrorBuilder;
42 import org.openecomp.sdc.vendorlicense.errors.LimitErrorBuilder;
43 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
44 import org.openecomp.sdc.versioning.VersioningUtil;
45 import org.openecomp.sdc.versioning.dao.types.Version;
47 import java.time.LocalDate;
48 import java.time.format.DateTimeFormatter;
49 import java.util.Collection;
50 import java.util.Objects;
51 import java.util.Optional;
54 public class VendorLicenseManagerImpl implements VendorLicenseManager {
55 private VendorLicenseFacade vendorLicenseFacade;
56 private VendorLicenseModelDao vendorLicenseModelDao;
57 private LicenseAgreementDao licenseAgreementDao;
58 private FeatureGroupDao featureGroupDao;
59 private EntitlementPoolDao entitlementPoolDao;
60 private LicenseKeyGroupDao licenseKeyGroupDao;
61 private LimitDao limitDao;
62 private static final String EP_POOL_START_TIME = "T00:00:00Z";
63 private static final String EP_POOL_EXPIRY_TIME = "T23:59:59Z";
64 private static final DateTimeFormatter FORMATTER
65 = DateTimeFormatter.ofPattern("MM/dd/yyyy'T'HH:mm:ss'Z'");
66 public VendorLicenseManagerImpl(VendorLicenseFacade vendorLicenseFacade,
67 VendorLicenseModelDao vendorLicenseModelDao,
68 LicenseAgreementDao licenseAgreementDao,
69 FeatureGroupDao featureGroupDao,
70 EntitlementPoolDao entitlementPoolDao,
71 LicenseKeyGroupDao licenseKeyGroupDao,
73 this.vendorLicenseFacade = vendorLicenseFacade;
74 this.vendorLicenseModelDao = vendorLicenseModelDao;
75 this.licenseAgreementDao = licenseAgreementDao;
76 this.featureGroupDao = featureGroupDao;
77 this.entitlementPoolDao = entitlementPoolDao;
78 this.licenseKeyGroupDao = licenseKeyGroupDao;
79 this.limitDao = limitDao;
84 public void validate(String vendorLicenseModelId, Version version) {
85 vendorLicenseFacade.validate(vendorLicenseModelId, version);
89 public VendorLicenseModelEntity createVendorLicenseModel(
90 VendorLicenseModelEntity vendorLicenseModelEntity) {
91 vendorLicenseModelDao.create(vendorLicenseModelEntity);
92 return vendorLicenseModelEntity;
96 public void updateVendorLicenseModel(VendorLicenseModelEntity vendorLicenseModelEntity) {
97 String existingVendorName = vendorLicenseModelDao.get(vendorLicenseModelEntity).getVendorName();
99 updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME, existingVendorName,
100 vendorLicenseModelEntity.getVendorName());
101 vendorLicenseModelDao.update(vendorLicenseModelEntity);
105 public VendorLicenseModelEntity getVendorLicenseModel(String vlmId, Version version) {
106 return vendorLicenseFacade.getVendorLicenseModel(vlmId, version);
110 public void deleteVendorLicenseModel(String vlmId, Version version) {
111 throw new UnsupportedOperationException(VendorLicenseConstants.UNSUPPORTED_OPERATION_ERROR);
115 public Collection<LicenseAgreementEntity> listLicenseAgreements(String vlmId, Version version) {
116 return licenseAgreementDao.list(new LicenseAgreementEntity(vlmId, version, null));
120 public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement) {
121 return vendorLicenseFacade.createLicenseAgreement(licenseAgreement);
125 public void updateLicenseAgreement(LicenseAgreementEntity licenseAgreement,
126 Set<String> addedFeatureGroupIds,
127 Set<String> removedFeatureGroupIds) {
128 LicenseAgreementEntity retrieved = licenseAgreementDao.get(licenseAgreement);
130 .validateEntityExistence(retrieved, licenseAgreement, VendorLicenseModelEntity.ENTITY_TYPE);
131 VersioningUtil.validateContainedEntitiesExistence(new FeatureGroupEntity().getEntityType(),
132 removedFeatureGroupIds, retrieved, retrieved.getFeatureGroupIds());
133 VersioningUtil.validateEntitiesExistence(addedFeatureGroupIds,
134 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
135 licenseAgreement.getVersion(),
137 featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
139 updateUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
140 retrieved.getName(), licenseAgreement.getName(), licenseAgreement.getVendorLicenseModelId(),
141 licenseAgreement.getVersion().getId());
142 licenseAgreementDao.updateColumnsAndDeltaFeatureGroupIds(licenseAgreement, addedFeatureGroupIds,
143 removedFeatureGroupIds);
145 addFeatureGroupsToLicenseAgreementRef(addedFeatureGroupIds, licenseAgreement);
146 removeFeatureGroupsToLicenseAgreementRef(removedFeatureGroupIds, licenseAgreement);
150 public LicenseAgreementModel getLicenseAgreementModel(String vlmId, Version version,
151 String licenseAgreementId) {
152 return vendorLicenseFacade.getLicenseAgreementModel(vlmId, version, licenseAgreementId);
156 public void deleteLicenseAgreement(String vlmId, Version version, String licenseAgreementId) {
157 LicenseAgreementEntity input =
158 new LicenseAgreementEntity(vlmId, version, licenseAgreementId);
159 LicenseAgreementEntity retrieved = licenseAgreementDao.get(input);
160 VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE);
162 removeFeatureGroupsToLicenseAgreementRef(retrieved.getFeatureGroupIds(), retrieved);
164 licenseAgreementDao.delete(retrieved);
166 deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
167 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
168 retrieved.getName());
172 public Collection<FeatureGroupEntity> listFeatureGroups(String vlmId, Version version) {
173 return vendorLicenseFacade.listFeatureGroups(vlmId, version);
177 public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup) {
178 return vendorLicenseFacade.createFeatureGroup(featureGroup);
182 public void updateFeatureGroup(FeatureGroupEntity featureGroup,
183 Set<String> addedLicenseKeyGroups,
184 Set<String> removedLicenseKeyGroups,
185 Set<String> addedEntitlementPools,
186 Set<String> removedEntitlementPools) {
187 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
189 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
191 VersioningUtil.validateContainedEntitiesExistence(new LicenseKeyGroupEntity().getEntityType(),
192 removedLicenseKeyGroups, retrieved, retrieved.getLicenseKeyGroupIds());
193 VersioningUtil.validateContainedEntitiesExistence(new EntitlementPoolEntity().getEntityType(),
194 removedEntitlementPools, retrieved, retrieved.getEntitlementPoolIds());
196 VersioningUtil.validateEntitiesExistence(addedLicenseKeyGroups,
197 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(),
199 licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
200 VersioningUtil.validateEntitiesExistence(addedEntitlementPools,
201 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(),
203 entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE);
205 updateUniqueName(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
206 retrieved.getName(), featureGroup.getName(), featureGroup.getVendorLicenseModelId(),
207 featureGroup.getVersion().getId());
209 addLicenseKeyGroupsToFeatureGroupsRef(addedLicenseKeyGroups, featureGroup);
210 removeLicenseKeyGroupsToFeatureGroupsRef(removedLicenseKeyGroups, featureGroup);
211 addEntitlementPoolsToFeatureGroupsRef(addedEntitlementPools, featureGroup);
212 removeEntitlementPoolsToFeatureGroupsRef(removedEntitlementPools, featureGroup);
214 featureGroupDao.updateFeatureGroup(featureGroup, addedEntitlementPools, removedEntitlementPools,
215 addedLicenseKeyGroups, removedLicenseKeyGroups);
217 updateEpLkgOnMrnChange(featureGroup, addedLicenseKeyGroups, addedEntitlementPools, retrieved);
221 * If MRN is updated in feature group then update all linked EPs and Lkgs with new versionUuId
222 * @param featureGroup - Feature Group entity which is requested for update
223 * @param addedLicenseKeyGroups - LicenseKeyGroups added with Feature Group
224 * @param addedEntitlementPools - EntitlementPools added with Feature Group
225 * @param retrieved - Feature Group entity fetched from database
227 private void updateEpLkgOnMrnChange(FeatureGroupEntity featureGroup,
228 Set<String> addedLicenseKeyGroups,
229 Set<String> addedEntitlementPools,
230 FeatureGroupEntity retrieved) {
231 if (Objects.nonNull(retrieved.getManufacturerReferenceNumber())
232 && !retrieved.getManufacturerReferenceNumber().equals(featureGroup
233 .getManufacturerReferenceNumber())) {
234 if (CollectionUtils.isEmpty(addedEntitlementPools)) {
235 updateEntitlementPool(featureGroup, retrieved.getEntitlementPoolIds());
237 updateEntitlementPool(featureGroup, addedEntitlementPools);
240 if (CollectionUtils.isEmpty(addedLicenseKeyGroups)) {
241 updateLicenseKeyGroup(featureGroup, retrieved.getLicenseKeyGroupIds());
243 updateLicenseKeyGroup(featureGroup, addedLicenseKeyGroups);
248 private void updateEntitlementPool(FeatureGroupEntity featureGroup,
249 Set<String> entitlementPoolIds) {
250 for (String epId: entitlementPoolIds) {
251 final EntitlementPoolEntity entitlementPoolEntity = entitlementPoolDao
252 .get(new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup
253 .getVersion(), epId));
254 if (Objects.nonNull(entitlementPoolEntity)) {
255 entitlementPoolEntity.setVersionUuId(CommonMethods.nextUuId());
256 entitlementPoolDao.update(entitlementPoolEntity);
261 private void updateLicenseKeyGroup(FeatureGroupEntity featureGroup,
262 Set<String> licenseKeyGroupIds) {
263 for (String lkgId: licenseKeyGroupIds) {
264 final LicenseKeyGroupEntity licenseKeyGroupEntity = licenseKeyGroupDao
265 .get(new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
266 featureGroup.getVersion(), lkgId));
267 if (Objects.nonNull(licenseKeyGroupEntity)) {
268 licenseKeyGroupEntity.setVersionUuId(CommonMethods.nextUuId());
269 licenseKeyGroupDao.update(licenseKeyGroupEntity);
275 public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup) {
276 return vendorLicenseFacade.getFeatureGroupModel(featureGroup);
280 public void deleteFeatureGroup(FeatureGroupEntity featureGroup) {
281 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
283 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
285 removeLicenseKeyGroupsToFeatureGroupsRef(retrieved.getLicenseKeyGroupIds(), featureGroup);
286 removeEntitlementPoolsToFeatureGroupsRef(retrieved.getEntitlementPoolIds(), featureGroup);
288 for (String licenceAgreementId : retrieved.getReferencingLicenseAgreements()) {
289 licenseAgreementDao.removeFeatureGroup(
290 new LicenseAgreementEntity(featureGroup.getVendorLicenseModelId(),
291 featureGroup.getVersion(),
292 licenceAgreementId), featureGroup.getId());
295 featureGroupDao.delete(featureGroup);
297 deleteUniqueName(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
298 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
299 retrieved.getName());
303 public Collection<EntitlementPoolEntity> listEntitlementPools(String vlmId, Version version) {
304 return vendorLicenseFacade.listEntitlementPools(vlmId, version);
308 public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool) {
309 entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool
310 .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME
312 entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool
313 .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME
316 validateCreateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(),
317 entitlementPool.getVendorLicenseModelId());
318 return vendorLicenseFacade.createEntitlementPool(entitlementPool);
321 private void validateCreateDate(String startDate, String expiryDate,
322 String vendorLicenseModelId) {
323 LocalDate parsedStartDate = parseLocalDate(startDate);
324 LocalDate parsedExpiryDate = parseLocalDate(expiryDate);
327 validateIfStartAndExpiryDateIsNotNull(startDate, expiryDate,
328 vendorLicenseModelId, parsedStartDate, parsedExpiryDate);
330 if (startDate != null && expiryDate == null
331 && parsedStartDate.atStartOfDay().isBefore
332 (LocalDate.now().atStartOfDay())) {
333 throw new CoreException(
334 new InvalidDateErrorBuilder(vendorLicenseModelId)
338 if (startDate == null && expiryDate != null) {
339 throw new CoreException(
340 new InvalidDateErrorBuilder(vendorLicenseModelId)
346 private void validateIfStartAndExpiryDateIsNotNull(String startDate, String expiryDate,
347 String vendorLicenseModelId,
348 LocalDate parsedStartDate,
349 LocalDate parsedExpiryDate) {
350 if (startDate != null && expiryDate != null
351 && isValidatStartAndExpiryDate(parsedStartDate, parsedExpiryDate)) {
352 throw new CoreException(
353 new InvalidDateErrorBuilder(vendorLicenseModelId)
358 private boolean isValidatStartAndExpiryDate(LocalDate parsedStartDate,
359 LocalDate parsedExpiryDate) {
360 return parsedStartDate.atStartOfDay().isBefore(LocalDate.now().atStartOfDay())
361 || parsedExpiryDate.atStartOfDay().isEqual(parsedStartDate.atStartOfDay())
362 || parsedExpiryDate.isBefore(parsedStartDate);
365 private static LocalDate parseLocalDate(String date) {
366 if (date == null || date.isEmpty()) {
370 return LocalDate.parse(date, FORMATTER );
373 private void validateUpdateDate(String startDate, String expiryDate,
374 String vendorLicenseModelId) {
375 LocalDate parsedStartDate = parseLocalDate(startDate);
376 LocalDate parsedExpiryDate = parseLocalDate(expiryDate);
378 if (startDate != null && expiryDate != null
379 && (parsedExpiryDate.atStartOfDay()
380 .isEqual(parsedStartDate.atStartOfDay())
381 || parsedExpiryDate.isBefore(parsedStartDate ))) {
382 throw new CoreException(
383 new InvalidDateErrorBuilder(vendorLicenseModelId)
387 if (startDate == null && expiryDate != null) {
388 throw new CoreException(
389 new InvalidDateErrorBuilder(vendorLicenseModelId)
396 public void updateEntitlementPool(EntitlementPoolEntity entitlementPool) {
397 entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool
398 .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME
400 entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool
401 .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME
404 validateUpdateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(),
405 entitlementPool.getVendorLicenseModelId());
406 vendorLicenseFacade.updateEntitlementPool(entitlementPool);
410 public EntitlementPoolEntity getEntitlementPool(EntitlementPoolEntity entitlementPool) {
411 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
413 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
414 DateTimeFormatter targetFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
415 if (retrieved.getStartDate() != null) {
416 retrieved.setStartDate(LocalDate.parse(retrieved.getStartDate(), FORMATTER ).format
420 if (retrieved.getExpiryDate() != null) {
421 retrieved.setExpiryDate(LocalDate.parse(retrieved.getExpiryDate(), FORMATTER ).format
428 public void deleteEntitlementPool(EntitlementPoolEntity entitlementPool) {
429 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
431 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
433 for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) {
434 featureGroupDao.removeEntitlementPool(
435 new FeatureGroupEntity(entitlementPool.getVendorLicenseModelId(),
436 entitlementPool.getVersion(),
437 referencingFeatureGroupId), entitlementPool.getId());
440 deleteChildLimits(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion(),
441 entitlementPool.getId());
443 entitlementPoolDao.delete(entitlementPool);
445 deleteUniqueName(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
446 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
447 retrieved.getName());
450 protected void deleteChildLimits(String vlmId, Version version, String epLkgId) {
451 Optional<Collection<LimitEntity>> limitEntities = Optional.ofNullable(
452 listLimits(vlmId, version, epLkgId));
453 limitEntities.ifPresent(entities -> entities.forEach(this::deleteLimit));
457 public Collection<LicenseKeyGroupEntity> listLicenseKeyGroups(String vlmId, Version version) {
458 return vendorLicenseFacade.listLicenseKeyGroups(vlmId, version);
462 public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
463 licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup
464 .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate() + EP_POOL_START_TIME
466 licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup
467 .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate() + EP_POOL_EXPIRY_TIME
470 validateCreateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(),
471 licenseKeyGroup.getVendorLicenseModelId());
472 return vendorLicenseFacade.createLicenseKeyGroup(licenseKeyGroup);
476 public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
477 licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup
478 .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate() + EP_POOL_START_TIME
480 licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup
481 .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate() + EP_POOL_EXPIRY_TIME
484 validateUpdateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(),
485 licenseKeyGroup.getVendorLicenseModelId());
486 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroup);
490 public LicenseKeyGroupEntity getLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
491 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
493 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
498 public void deleteLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
499 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
501 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
503 for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) {
504 featureGroupDao.removeLicenseKeyGroup(
505 new FeatureGroupEntity(licenseKeyGroup.getVendorLicenseModelId(),
506 licenseKeyGroup.getVersion(),
507 referencingFeatureGroupId), licenseKeyGroup.getId());
510 deleteChildLimits(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion(),
511 licenseKeyGroup.getId());
513 licenseKeyGroupDao.delete(licenseKeyGroup);
515 deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
516 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
517 retrieved.getName());
521 public LimitEntity createLimit(LimitEntity limit) {
522 validateLimit(limit);
523 LimitEntity createdLimit = vendorLicenseFacade.createLimit(limit);
524 updateParentForLimit(limit);
528 private void validateLimit(LimitEntity limit) {
529 Collection<LimitEntity> limitList =
530 listLimits(limit.getVendorLicenseModelId(), limit.getVersion()
531 , limit.getEpLkgId());
533 if (!isLimitNameUnique(limitList, limit.getName(), limit.getType(), limit.getId())) {
534 final ErrorCode duplicateLimitNameErrorBuilder =
535 LimitErrorBuilder.getDuplicateNameErrorbuilder(limit.getName(), limit.getType().name());
536 throw new CoreException(duplicateLimitNameErrorBuilder);
540 private boolean isLimitNameUnique(Collection<LimitEntity> limitList, String name, LimitType
542 for (LimitEntity limit : limitList) {
543 if (limit.getName().equalsIgnoreCase(name) &&
544 limit.getType().name().equalsIgnoreCase(type.name())) {
545 if (id != null && limit.getId().equals(id)) {
555 public Collection<LimitEntity> listLimits(String vlmId, Version version, String epLkgId) {
556 return vendorLicenseFacade.listLimits(vlmId, version, epLkgId);
560 public void deleteLimit(LimitEntity limitEntity) {
561 if (!isLimitPresent(limitEntity)) {
563 .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
565 LimitEntity retrieved = limitDao.get(limitEntity);
567 .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
569 limitDao.delete(limitEntity);
571 updateParentForLimit(limitEntity);
575 public void updateLimit(LimitEntity limit) {
577 validateLimit(limit);
578 vendorLicenseFacade.updateLimit(limit);
579 updateParentForLimit(limit);
582 private boolean isLimitPresent(LimitEntity limit) {
583 return limitDao.isLimitPresent(limit);
587 public LimitEntity getLimit(LimitEntity limitEntity) {
588 if (!isLimitPresent(limitEntity)) {
590 .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
592 LimitEntity retrieved = limitDao.get(limitEntity);
594 .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
599 * update Parent of limit (EP/LKG) versionuuid when limit is modified so that limit updates are
600 * captured in VLM XML
602 private void updateParentForLimit(LimitEntity limit) {
603 if ("EntitlementPool".equals(limit.getParent())) {
604 EntitlementPoolEntity entitlementPoolEntity =
605 entitlementPoolDao.get(new EntitlementPoolEntity(limit.getVendorLicenseModelId(),
606 limit.getVersion(), limit.getEpLkgId()));
607 vendorLicenseFacade.updateEntitlementPool(entitlementPoolEntity);
610 if ("LicenseKeyGroup".equals(limit.getParent())) {
611 LicenseKeyGroupEntity licenseKeyGroupEntity = licenseKeyGroupDao.get(
612 new LicenseKeyGroupEntity(limit.getVendorLicenseModelId(), limit.getVersion(),
613 limit.getEpLkgId()));
614 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroupEntity);
618 protected void addFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds,
619 LicenseAgreementEntity licenseAgreement) {
620 if (featureGroupIds != null) {
621 for (String featureGroupId : featureGroupIds) {
622 featureGroupDao.addReferencingLicenseAgreement(
623 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
624 licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId());
629 protected void removeFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds,
630 LicenseAgreementEntity licenseAgreement) {
631 if (featureGroupIds != null) {
632 for (String featureGroupId : featureGroupIds) {
633 featureGroupDao.removeReferencingLicenseAgreement(
634 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
635 licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId());
640 protected void addLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds,
641 FeatureGroupEntity featureGroup) {
642 if (licenseKeyGroupIds != null) {
643 for (String licenseKeyGroupId : licenseKeyGroupIds) {
644 licenseKeyGroupDao.addReferencingFeatureGroup(
645 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
646 featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId());
651 protected void removeLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds,
652 FeatureGroupEntity featureGroup) {
653 if (licenseKeyGroupIds != null) {
654 for (String licenseKeyGroupId : licenseKeyGroupIds) {
655 licenseKeyGroupDao.removeReferencingFeatureGroup(
656 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
657 featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId());
662 protected void addEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds,
663 FeatureGroupEntity featureGroup) {
664 if (entitlementPoolIds != null) {
665 for (String entitlementPoolId : entitlementPoolIds) {
666 entitlementPoolDao.addReferencingFeatureGroup(
667 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(),
668 featureGroup.getVersion(), entitlementPoolId), featureGroup.getId());
673 protected void removeEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds,
674 FeatureGroupEntity featureGroup) {
675 if (entitlementPoolIds != null) {
676 for (String entitlementPoolId : entitlementPoolIds) {
677 entitlementPoolDao.removeReferencingFeatureGroup(
678 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(),
679 featureGroup.getVersion(), entitlementPoolId), featureGroup.getId());
684 protected void updateUniqueName(String uniqueValueType, String oldName, String newName, String...
687 .updateUniqueValue(uniqueValueType, oldName, newName, context);
690 protected void deleteUniqueName(String uniqueValueType, String... uniqueCombination) {
691 UniqueValueUtil.deleteUniqueValue(uniqueValueType, uniqueCombination);