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.datatypes.error.ErrorLevel;
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.Objects;
57 import java.util.Optional;
60 public class VendorLicenseManagerImpl implements VendorLicenseManager {
61 private VendorLicenseFacade vendorLicenseFacade;
62 private VendorLicenseModelDao vendorLicenseModelDao;
63 private LicenseAgreementDao licenseAgreementDao;
64 private FeatureGroupDao featureGroupDao;
65 private EntitlementPoolDao entitlementPoolDao;
66 private LicenseKeyGroupDao licenseKeyGroupDao;
67 private LimitDao limitDao;
68 private static final String VLM_ID = "VLM id";
69 private static final String EP_LKGID = "EP/LKGId";
70 private static final String VLM_ID_LKG_ID = "VLM id, LKG id";
71 private static final String VLM_ID_LA_ID = "VLM id, LA id";
72 private static final String VLM_ID_FG_ID = "VLM id, FG id";
73 private static final String VLM_ID_EP_ID = "VLM id, EP id";
74 private static final String EP_POOL_START_TIME = "T00:00:00Z";
75 private static final String EP_POOL_EXPIRY_TIME = "T23:59:59Z";
76 private static final DateTimeFormatter FORMATTER
77 = DateTimeFormatter.ofPattern("MM/dd/yyyy'T'HH:mm:ss'Z'");
78 public VendorLicenseManagerImpl(VendorLicenseFacade vendorLicenseFacade,
79 VendorLicenseModelDao vendorLicenseModelDao,
80 LicenseAgreementDao licenseAgreementDao,
81 FeatureGroupDao featureGroupDao,
82 EntitlementPoolDao entitlementPoolDao,
83 LicenseKeyGroupDao licenseKeyGroupDao,
85 this.vendorLicenseFacade = vendorLicenseFacade;
86 this.vendorLicenseModelDao = vendorLicenseModelDao;
87 this.licenseAgreementDao = licenseAgreementDao;
88 this.featureGroupDao = featureGroupDao;
89 this.entitlementPoolDao = entitlementPoolDao;
90 this.licenseKeyGroupDao = licenseKeyGroupDao;
91 this.limitDao = limitDao;
96 public void validate(String vendorLicenseModelId, Version version) {
97 vendorLicenseFacade.validate(vendorLicenseModelId, version);
101 public VendorLicenseModelEntity createVendorLicenseModel(
102 VendorLicenseModelEntity vendorLicenseModelEntity) {
103 vendorLicenseModelDao.create(vendorLicenseModelEntity);
104 return vendorLicenseModelEntity;
108 public void updateVendorLicenseModel(VendorLicenseModelEntity vendorLicenseModelEntity) {
109 String existingVendorName = vendorLicenseModelDao.get(vendorLicenseModelEntity).getVendorName();
111 updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME, existingVendorName,
112 vendorLicenseModelEntity.getVendorName());
113 vendorLicenseModelDao.update(vendorLicenseModelEntity);
117 public VendorLicenseModelEntity getVendorLicenseModel(String vlmId, Version version) {
118 return vendorLicenseFacade.getVendorLicenseModel(vlmId, version);
122 public void deleteVendorLicenseModel(String vlmId, Version version) {
123 throw new UnsupportedOperationException(VendorLicenseConstants.UNSUPPORTED_OPERATION_ERROR);
127 public Collection<LicenseAgreementEntity> listLicenseAgreements(String vlmId, Version version) {
128 return licenseAgreementDao.list(new LicenseAgreementEntity(vlmId, version, null));
132 public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement) {
133 return vendorLicenseFacade.createLicenseAgreement(licenseAgreement);
137 public void updateLicenseAgreement(LicenseAgreementEntity licenseAgreement,
138 Set<String> addedFeatureGroupIds,
139 Set<String> removedFeatureGroupIds) {
140 LicenseAgreementEntity retrieved = licenseAgreementDao.get(licenseAgreement);
142 .validateEntityExistence(retrieved, licenseAgreement, VendorLicenseModelEntity.ENTITY_TYPE);
143 VersioningUtil.validateContainedEntitiesExistence(new FeatureGroupEntity().getEntityType(),
144 removedFeatureGroupIds, retrieved, retrieved.getFeatureGroupIds());
145 VersioningUtil.validateEntitiesExistence(addedFeatureGroupIds,
146 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
147 licenseAgreement.getVersion(),
149 featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
151 updateUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
152 retrieved.getName(), licenseAgreement.getName(), licenseAgreement.getVendorLicenseModelId(),
153 licenseAgreement.getVersion().getId());
154 licenseAgreementDao.updateColumnsAndDeltaFeatureGroupIds(licenseAgreement, addedFeatureGroupIds,
155 removedFeatureGroupIds);
157 addFeatureGroupsToLicenseAgreementRef(addedFeatureGroupIds, licenseAgreement);
158 removeFeatureGroupsToLicenseAgreementRef(removedFeatureGroupIds, licenseAgreement);
162 public LicenseAgreementModel getLicenseAgreementModel(String vlmId, Version version,
163 String licenseAgreementId) {
164 return vendorLicenseFacade.getLicenseAgreementModel(vlmId, version, licenseAgreementId);
168 public void deleteLicenseAgreement(String vlmId, Version version, String licenseAgreementId) {
169 LicenseAgreementEntity input =
170 new LicenseAgreementEntity(vlmId, version, licenseAgreementId);
171 LicenseAgreementEntity retrieved = licenseAgreementDao.get(input);
172 VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE);
174 removeFeatureGroupsToLicenseAgreementRef(retrieved.getFeatureGroupIds(), retrieved);
176 licenseAgreementDao.delete(retrieved);
178 deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
179 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
180 retrieved.getName());
184 public Collection<FeatureGroupEntity> listFeatureGroups(String vlmId, Version version) {
185 return vendorLicenseFacade.listFeatureGroups(vlmId, version);
189 public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup) {
190 return vendorLicenseFacade.createFeatureGroup(featureGroup);
194 public void updateFeatureGroup(FeatureGroupEntity featureGroup,
195 Set<String> addedLicenseKeyGroups,
196 Set<String> removedLicenseKeyGroups,
197 Set<String> addedEntitlementPools,
198 Set<String> removedEntitlementPools) {
199 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
201 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
203 VersioningUtil.validateContainedEntitiesExistence(new LicenseKeyGroupEntity().getEntityType(),
204 removedLicenseKeyGroups, retrieved, retrieved.getLicenseKeyGroupIds());
205 VersioningUtil.validateContainedEntitiesExistence(new EntitlementPoolEntity().getEntityType(),
206 removedEntitlementPools, retrieved, retrieved.getEntitlementPoolIds());
208 VersioningUtil.validateEntitiesExistence(addedLicenseKeyGroups,
209 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(),
211 licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
212 VersioningUtil.validateEntitiesExistence(addedEntitlementPools,
213 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(),
215 entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE);
217 updateUniqueName(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
218 retrieved.getName(), featureGroup.getName(), featureGroup.getVendorLicenseModelId(),
219 featureGroup.getVersion().getId());
221 addLicenseKeyGroupsToFeatureGroupsRef(addedLicenseKeyGroups, featureGroup);
222 removeLicenseKeyGroupsToFeatureGroupsRef(removedLicenseKeyGroups, featureGroup);
223 addEntitlementPoolsToFeatureGroupsRef(addedEntitlementPools, featureGroup);
224 removeEntitlementPoolsToFeatureGroupsRef(removedEntitlementPools, featureGroup);
226 featureGroupDao.updateFeatureGroup(featureGroup, addedEntitlementPools, removedEntitlementPools,
227 addedLicenseKeyGroups, removedLicenseKeyGroups);
229 updateEpLkgOnMrnChange(featureGroup, addedLicenseKeyGroups, addedEntitlementPools, retrieved);
233 * If MRN is updated in feature group then update all linked EPs and Lkgs with new versionUuId
234 * @param featureGroup - Feature Group entity which is requested for update
235 * @param addedLicenseKeyGroups - LicenseKeyGroups added with Feature Group
236 * @param addedEntitlementPools - EntitlementPools added with Feature Group
237 * @param retrieved - Feature Group entity fetched from database
239 private void updateEpLkgOnMrnChange(FeatureGroupEntity featureGroup,
240 Set<String> addedLicenseKeyGroups,
241 Set<String> addedEntitlementPools,
242 FeatureGroupEntity retrieved) {
243 if (Objects.nonNull(retrieved.getManufacturerReferenceNumber())
244 && !retrieved.getManufacturerReferenceNumber().equals(featureGroup
245 .getManufacturerReferenceNumber())) {
246 if (CollectionUtils.isEmpty(addedEntitlementPools)) {
247 updateEntitlementPool(featureGroup, retrieved.getEntitlementPoolIds());
249 updateEntitlementPool(featureGroup, addedEntitlementPools);
252 if (CollectionUtils.isEmpty(addedLicenseKeyGroups)) {
253 updateLicenseKeyGroup(featureGroup, retrieved.getLicenseKeyGroupIds());
255 updateLicenseKeyGroup(featureGroup, addedLicenseKeyGroups);
260 private void updateEntitlementPool(FeatureGroupEntity featureGroup,
261 Set<String> entitlementPoolIds) {
262 for (String epId: entitlementPoolIds) {
263 final EntitlementPoolEntity entitlementPoolEntity = entitlementPoolDao
264 .get(new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup
265 .getVersion(), epId));
266 if (Objects.nonNull(entitlementPoolEntity)) {
267 entitlementPoolEntity.setVersionUuId(CommonMethods.nextUuId());
268 entitlementPoolDao.update(entitlementPoolEntity);
273 private void updateLicenseKeyGroup(FeatureGroupEntity featureGroup,
274 Set<String> licenseKeyGroupIds) {
275 for (String lkgId: licenseKeyGroupIds) {
276 final LicenseKeyGroupEntity licenseKeyGroupEntity = licenseKeyGroupDao
277 .get(new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
278 featureGroup.getVersion(), lkgId));
279 if (Objects.nonNull(licenseKeyGroupEntity)) {
280 licenseKeyGroupEntity.setVersionUuId(CommonMethods.nextUuId());
281 licenseKeyGroupDao.update(licenseKeyGroupEntity);
287 public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup) {
288 return vendorLicenseFacade.getFeatureGroupModel(featureGroup);
292 public void deleteFeatureGroup(FeatureGroupEntity featureGroup) {
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());
315 public Collection<EntitlementPoolEntity> listEntitlementPools(String vlmId, Version version) {
316 return vendorLicenseFacade.listEntitlementPools(vlmId, version);
320 public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool) {
321 entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool
322 .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME
324 entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool
325 .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME
328 validateCreateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(),
329 entitlementPool.getVendorLicenseModelId());
330 return vendorLicenseFacade.createEntitlementPool(entitlementPool);
333 private void validateCreateDate(String startDate, String expiryDate,
334 String vendorLicenseModelId) {
335 LocalDate parsedStartDate = parseLocalDate(startDate);
336 LocalDate parsedExpiryDate = parseLocalDate(expiryDate);
339 validateIfStartAndExpiryDateIsNotNull(startDate, expiryDate,
340 vendorLicenseModelId, parsedStartDate, parsedExpiryDate);
342 if (startDate != null && expiryDate == null
343 && parsedStartDate.atStartOfDay().isBefore
344 (LocalDate.now().atStartOfDay())) {
345 throw new CoreException(
346 new InvalidDateErrorBuilder(vendorLicenseModelId)
350 if (startDate == null && expiryDate != null) {
351 throw new CoreException(
352 new InvalidDateErrorBuilder(vendorLicenseModelId)
358 private void validateIfStartAndExpiryDateIsNotNull(String startDate, String expiryDate,
359 String vendorLicenseModelId,
360 LocalDate parsedStartDate,
361 LocalDate parsedExpiryDate) {
362 if (startDate != null && expiryDate != null
363 && isValidatStartAndExpiryDate(parsedStartDate, parsedExpiryDate)) {
364 throw new CoreException(
365 new InvalidDateErrorBuilder(vendorLicenseModelId)
370 private boolean isValidatStartAndExpiryDate(LocalDate parsedStartDate,
371 LocalDate parsedExpiryDate) {
372 return parsedStartDate.atStartOfDay().isBefore(LocalDate.now().atStartOfDay())
373 || parsedExpiryDate.atStartOfDay().isEqual(parsedStartDate.atStartOfDay())
374 || parsedExpiryDate.isBefore(parsedStartDate);
377 private static LocalDate parseLocalDate(String date) {
378 if (date == null || date.isEmpty()) {
382 return LocalDate.parse(date, FORMATTER );
385 private void validateUpdateDate(String startDate, String expiryDate,
386 String vendorLicenseModelId) {
387 LocalDate parsedStartDate = parseLocalDate(startDate);
388 LocalDate parsedExpiryDate = parseLocalDate(expiryDate);
390 if (startDate != null && expiryDate != null
391 && (parsedExpiryDate.atStartOfDay()
392 .isEqual(parsedStartDate.atStartOfDay())
393 || parsedExpiryDate.isBefore(parsedStartDate ))) {
394 throw new CoreException(
395 new InvalidDateErrorBuilder(vendorLicenseModelId)
399 if (startDate == null && expiryDate != null) {
400 throw new CoreException(
401 new InvalidDateErrorBuilder(vendorLicenseModelId)
408 public void updateEntitlementPool(EntitlementPoolEntity entitlementPool) {
409 entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool
410 .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME
412 entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool
413 .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME
416 validateUpdateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(),
417 entitlementPool.getVendorLicenseModelId());
418 vendorLicenseFacade.updateEntitlementPool(entitlementPool);
422 public EntitlementPoolEntity getEntitlementPool(EntitlementPoolEntity entitlementPool) {
423 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
425 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
426 DateTimeFormatter targetFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
427 if (retrieved.getStartDate() != null) {
428 retrieved.setStartDate(LocalDate.parse(retrieved.getStartDate(), FORMATTER ).format
432 if (retrieved.getExpiryDate() != null) {
433 retrieved.setExpiryDate(LocalDate.parse(retrieved.getExpiryDate(), FORMATTER ).format
440 public void deleteEntitlementPool(EntitlementPoolEntity entitlementPool) {
441 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
443 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
445 for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) {
446 featureGroupDao.removeEntitlementPool(
447 new FeatureGroupEntity(entitlementPool.getVendorLicenseModelId(),
448 entitlementPool.getVersion(),
449 referencingFeatureGroupId), entitlementPool.getId());
452 deleteChildLimits(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion(),
453 entitlementPool.getId());
455 entitlementPoolDao.delete(entitlementPool);
457 deleteUniqueName(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
458 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
459 retrieved.getName());
462 protected void deleteChildLimits(String vlmId, Version version, String epLkgId) {
463 Optional<Collection<LimitEntity>> limitEntities = Optional.ofNullable(
464 listLimits(vlmId, version, epLkgId));
465 limitEntities.ifPresent(entities -> entities.forEach(this::deleteLimit));
469 public Collection<LicenseKeyGroupEntity> listLicenseKeyGroups(String vlmId, Version version) {
470 return vendorLicenseFacade.listLicenseKeyGroups(vlmId, version);
474 public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
475 licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup
476 .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate() + EP_POOL_START_TIME
478 licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup
479 .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate() + EP_POOL_EXPIRY_TIME
482 validateCreateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(),
483 licenseKeyGroup.getVendorLicenseModelId());
484 return vendorLicenseFacade.createLicenseKeyGroup(licenseKeyGroup);
488 public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
489 licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup
490 .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate() + EP_POOL_START_TIME
492 licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup
493 .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate() + EP_POOL_EXPIRY_TIME
496 validateUpdateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(),
497 licenseKeyGroup.getVendorLicenseModelId());
498 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroup);
502 public LicenseKeyGroupEntity getLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
503 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
505 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
510 public void deleteLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
511 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
513 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
515 for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) {
516 featureGroupDao.removeLicenseKeyGroup(
517 new FeatureGroupEntity(licenseKeyGroup.getVendorLicenseModelId(),
518 licenseKeyGroup.getVersion(),
519 referencingFeatureGroupId), licenseKeyGroup.getId());
522 deleteChildLimits(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion(),
523 licenseKeyGroup.getId());
525 licenseKeyGroupDao.delete(licenseKeyGroup);
527 deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
528 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
529 retrieved.getName());
533 public LimitEntity createLimit(LimitEntity limit) {
534 validateLimit(limit);
535 LimitEntity createdLimit = vendorLicenseFacade.createLimit(limit);
536 updateParentForLimit(limit);
540 private void validateLimit(LimitEntity limit) {
541 Collection<LimitEntity> limitList =
542 listLimits(limit.getVendorLicenseModelId(), limit.getVersion()
543 , limit.getEpLkgId());
545 if (!isLimitNameUnique(limitList, limit.getName(), limit.getType(), limit.getId())) {
546 final ErrorCode duplicateLimitNameErrorBuilder =
547 LimitErrorBuilder.getDuplicateNameErrorbuilder(limit.getName(), limit.getType().name());
548 throw new CoreException(duplicateLimitNameErrorBuilder);
552 private boolean isLimitNameUnique(Collection<LimitEntity> limitList, String name, LimitType
554 for (LimitEntity limit : limitList) {
555 if (limit.getName().equalsIgnoreCase(name) &&
556 limit.getType().name().equalsIgnoreCase(type.name())) {
557 if (id != null && limit.getId().equals(id)) {
567 public Collection<LimitEntity> listLimits(String vlmId, Version version, String epLkgId) {
568 return vendorLicenseFacade.listLimits(vlmId, version, epLkgId);
572 public void deleteLimit(LimitEntity limitEntity) {
573 if (!isLimitPresent(limitEntity)) {
575 .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
577 LimitEntity retrieved = limitDao.get(limitEntity);
579 .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
581 limitDao.delete(limitEntity);
583 updateParentForLimit(limitEntity);
587 public void updateLimit(LimitEntity limit) {
589 validateLimit(limit);
590 vendorLicenseFacade.updateLimit(limit);
591 updateParentForLimit(limit);
594 private boolean isLimitPresent(LimitEntity limit) {
595 return limitDao.isLimitPresent(limit);
599 public LimitEntity getLimit(LimitEntity limitEntity) {
600 if (!isLimitPresent(limitEntity)) {
602 .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
604 LimitEntity retrieved = limitDao.get(limitEntity);
606 .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
611 * update Parent of limit (EP/LKG) versionuuid when limit is modified so that limit updates are
612 * captured in VLM XML
614 private void updateParentForLimit(LimitEntity limit) {
615 if ("EntitlementPool".equals(limit.getParent())) {
616 EntitlementPoolEntity entitlementPoolEntity =
617 entitlementPoolDao.get(new EntitlementPoolEntity(limit.getVendorLicenseModelId(),
618 limit.getVersion(), limit.getEpLkgId()));
619 vendorLicenseFacade.updateEntitlementPool(entitlementPoolEntity);
622 if ("LicenseKeyGroup".equals(limit.getParent())) {
623 LicenseKeyGroupEntity licenseKeyGroupEntity = licenseKeyGroupDao.get(
624 new LicenseKeyGroupEntity(limit.getVendorLicenseModelId(), limit.getVersion(),
625 limit.getEpLkgId()));
626 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroupEntity);
630 protected void addFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds,
631 LicenseAgreementEntity licenseAgreement) {
632 if (featureGroupIds != null) {
633 for (String featureGroupId : featureGroupIds) {
634 featureGroupDao.addReferencingLicenseAgreement(
635 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
636 licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId());
641 protected void removeFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds,
642 LicenseAgreementEntity licenseAgreement) {
643 if (featureGroupIds != null) {
644 for (String featureGroupId : featureGroupIds) {
645 featureGroupDao.removeReferencingLicenseAgreement(
646 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
647 licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId());
652 protected void addLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds,
653 FeatureGroupEntity featureGroup) {
654 if (licenseKeyGroupIds != null) {
655 for (String licenseKeyGroupId : licenseKeyGroupIds) {
656 licenseKeyGroupDao.addReferencingFeatureGroup(
657 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
658 featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId());
663 protected void removeLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds,
664 FeatureGroupEntity featureGroup) {
665 if (licenseKeyGroupIds != null) {
666 for (String licenseKeyGroupId : licenseKeyGroupIds) {
667 licenseKeyGroupDao.removeReferencingFeatureGroup(
668 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
669 featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId());
674 protected void addEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds,
675 FeatureGroupEntity featureGroup) {
676 if (entitlementPoolIds != null) {
677 for (String entitlementPoolId : entitlementPoolIds) {
678 entitlementPoolDao.addReferencingFeatureGroup(
679 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(),
680 featureGroup.getVersion(), entitlementPoolId), featureGroup.getId());
685 protected void removeEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds,
686 FeatureGroupEntity featureGroup) {
687 if (entitlementPoolIds != null) {
688 for (String entitlementPoolId : entitlementPoolIds) {
689 entitlementPoolDao.removeReferencingFeatureGroup(
690 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(),
691 featureGroup.getVersion(), entitlementPoolId), featureGroup.getId());
696 protected void updateUniqueName(String uniqueValueType, String oldName, String newName, String...
699 .updateUniqueValue(uniqueValueType, oldName, newName, context);
702 protected void deleteUniqueName(String uniqueValueType, String... uniqueCombination) {
703 UniqueValueUtil.deleteUniqueValue(uniqueValueType, uniqueCombination);