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 VendorLicenseModelEntity retrieved = vendorLicenseModelDao.get(vendorLicenseModelEntity);
98 if (retrieved == null){
99 throw new CoreException((new ErrorCode.ErrorCodeBuilder()
100 .withMessage(String.format("Vlm with id %s and version %s does not exist.",
101 vendorLicenseModelEntity.getId(), vendorLicenseModelEntity.getVersion().getId()))).build());
104 String existingVendorName = retrieved.getVendorName();
106 updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME, existingVendorName,
107 vendorLicenseModelEntity.getVendorName());
108 vendorLicenseModelDao.update(vendorLicenseModelEntity);
112 public VendorLicenseModelEntity getVendorLicenseModel(String vlmId, Version version) {
113 return vendorLicenseFacade.getVendorLicenseModel(vlmId, version);
117 public void deleteVendorLicenseModel(String vlmId, Version version) {
118 throw new UnsupportedOperationException(VendorLicenseConstants.UNSUPPORTED_OPERATION_ERROR);
122 public Collection<LicenseAgreementEntity> listLicenseAgreements(String vlmId, Version version) {
123 return licenseAgreementDao.list(new LicenseAgreementEntity(vlmId, version, null));
127 public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement) {
128 return vendorLicenseFacade.createLicenseAgreement(licenseAgreement);
132 public void updateLicenseAgreement(LicenseAgreementEntity licenseAgreement,
133 Set<String> addedFeatureGroupIds,
134 Set<String> removedFeatureGroupIds) {
135 LicenseAgreementEntity retrieved = licenseAgreementDao.get(licenseAgreement);
137 .validateEntityExistence(retrieved, licenseAgreement, VendorLicenseModelEntity.ENTITY_TYPE);
138 VersioningUtil.validateContainedEntitiesExistence(new FeatureGroupEntity().getEntityType(),
139 removedFeatureGroupIds, retrieved, retrieved.getFeatureGroupIds());
140 VersioningUtil.validateEntitiesExistence(addedFeatureGroupIds,
141 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
142 licenseAgreement.getVersion(),
144 featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
146 updateUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
147 retrieved.getName(), licenseAgreement.getName(), licenseAgreement.getVendorLicenseModelId(),
148 licenseAgreement.getVersion().getId());
149 licenseAgreementDao.updateColumnsAndDeltaFeatureGroupIds(licenseAgreement, addedFeatureGroupIds,
150 removedFeatureGroupIds);
152 addFeatureGroupsToLicenseAgreementRef(addedFeatureGroupIds, licenseAgreement);
153 removeFeatureGroupsToLicenseAgreementRef(removedFeatureGroupIds, licenseAgreement);
157 public LicenseAgreementModel getLicenseAgreementModel(String vlmId, Version version,
158 String licenseAgreementId) {
159 return vendorLicenseFacade.getLicenseAgreementModel(vlmId, version, licenseAgreementId);
163 public void deleteLicenseAgreement(String vlmId, Version version, String licenseAgreementId) {
164 LicenseAgreementEntity input =
165 new LicenseAgreementEntity(vlmId, version, licenseAgreementId);
166 LicenseAgreementEntity retrieved = licenseAgreementDao.get(input);
167 VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE);
169 removeFeatureGroupsToLicenseAgreementRef(retrieved.getFeatureGroupIds(), retrieved);
171 licenseAgreementDao.delete(retrieved);
173 deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
174 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
175 retrieved.getName());
179 public Collection<FeatureGroupEntity> listFeatureGroups(String vlmId, Version version) {
180 return vendorLicenseFacade.listFeatureGroups(vlmId, version);
184 public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup) {
185 return vendorLicenseFacade.createFeatureGroup(featureGroup);
189 public void updateFeatureGroup(FeatureGroupEntity featureGroup,
190 Set<String> addedLicenseKeyGroups,
191 Set<String> removedLicenseKeyGroups,
192 Set<String> addedEntitlementPools,
193 Set<String> removedEntitlementPools) {
194 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
196 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
198 VersioningUtil.validateContainedEntitiesExistence(new LicenseKeyGroupEntity().getEntityType(),
199 removedLicenseKeyGroups, retrieved, retrieved.getLicenseKeyGroupIds());
200 VersioningUtil.validateContainedEntitiesExistence(new EntitlementPoolEntity().getEntityType(),
201 removedEntitlementPools, retrieved, retrieved.getEntitlementPoolIds());
203 VersioningUtil.validateEntitiesExistence(addedLicenseKeyGroups,
204 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(),
206 licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
207 VersioningUtil.validateEntitiesExistence(addedEntitlementPools,
208 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup.getVersion(),
210 entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE);
212 updateUniqueName(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
213 retrieved.getName(), featureGroup.getName(), featureGroup.getVendorLicenseModelId(),
214 featureGroup.getVersion().getId());
216 addLicenseKeyGroupsToFeatureGroupsRef(addedLicenseKeyGroups, featureGroup);
217 removeLicenseKeyGroupsToFeatureGroupsRef(removedLicenseKeyGroups, featureGroup);
218 addEntitlementPoolsToFeatureGroupsRef(addedEntitlementPools, featureGroup);
219 removeEntitlementPoolsToFeatureGroupsRef(removedEntitlementPools, featureGroup);
221 featureGroupDao.updateFeatureGroup(featureGroup, addedEntitlementPools, removedEntitlementPools,
222 addedLicenseKeyGroups, removedLicenseKeyGroups);
224 updateEpLkgOnMrnChange(featureGroup, addedLicenseKeyGroups, addedEntitlementPools, retrieved);
228 * If MRN is updated in feature group then update all linked EPs and Lkgs with new versionUuId
229 * @param featureGroup - Feature Group entity which is requested for update
230 * @param addedLicenseKeyGroups - LicenseKeyGroups added with Feature Group
231 * @param addedEntitlementPools - EntitlementPools added with Feature Group
232 * @param retrieved - Feature Group entity fetched from database
234 private void updateEpLkgOnMrnChange(FeatureGroupEntity featureGroup,
235 Set<String> addedLicenseKeyGroups,
236 Set<String> addedEntitlementPools,
237 FeatureGroupEntity retrieved) {
238 if (Objects.nonNull(retrieved.getManufacturerReferenceNumber())
239 && !retrieved.getManufacturerReferenceNumber().equals(featureGroup
240 .getManufacturerReferenceNumber())) {
241 if (CollectionUtils.isEmpty(addedEntitlementPools)) {
242 updateEntitlementPool(featureGroup, retrieved.getEntitlementPoolIds());
244 updateEntitlementPool(featureGroup, addedEntitlementPools);
247 if (CollectionUtils.isEmpty(addedLicenseKeyGroups)) {
248 updateLicenseKeyGroup(featureGroup, retrieved.getLicenseKeyGroupIds());
250 updateLicenseKeyGroup(featureGroup, addedLicenseKeyGroups);
255 private void updateEntitlementPool(FeatureGroupEntity featureGroup,
256 Set<String> entitlementPoolIds) {
257 for (String epId: entitlementPoolIds) {
258 final EntitlementPoolEntity entitlementPoolEntity = entitlementPoolDao
259 .get(new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), featureGroup
260 .getVersion(), epId));
261 if (Objects.nonNull(entitlementPoolEntity)) {
262 entitlementPoolEntity.setVersionUuId(CommonMethods.nextUuId());
263 entitlementPoolDao.update(entitlementPoolEntity);
268 private void updateLicenseKeyGroup(FeatureGroupEntity featureGroup,
269 Set<String> licenseKeyGroupIds) {
270 for (String lkgId: licenseKeyGroupIds) {
271 final LicenseKeyGroupEntity licenseKeyGroupEntity = licenseKeyGroupDao
272 .get(new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
273 featureGroup.getVersion(), lkgId));
274 if (Objects.nonNull(licenseKeyGroupEntity)) {
275 licenseKeyGroupEntity.setVersionUuId(CommonMethods.nextUuId());
276 licenseKeyGroupDao.update(licenseKeyGroupEntity);
282 public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup) {
283 return vendorLicenseFacade.getFeatureGroupModel(featureGroup);
287 public void deleteFeatureGroup(FeatureGroupEntity featureGroup) {
288 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
290 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
292 removeLicenseKeyGroupsToFeatureGroupsRef(retrieved.getLicenseKeyGroupIds(), featureGroup);
293 removeEntitlementPoolsToFeatureGroupsRef(retrieved.getEntitlementPoolIds(), featureGroup);
295 for (String licenceAgreementId : retrieved.getReferencingLicenseAgreements()) {
296 licenseAgreementDao.removeFeatureGroup(
297 new LicenseAgreementEntity(featureGroup.getVendorLicenseModelId(),
298 featureGroup.getVersion(),
299 licenceAgreementId), featureGroup.getId());
302 featureGroupDao.delete(featureGroup);
304 deleteUniqueName(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
305 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
306 retrieved.getName());
310 public Collection<EntitlementPoolEntity> listEntitlementPools(String vlmId, Version version) {
311 return vendorLicenseFacade.listEntitlementPools(vlmId, version);
315 public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool) {
316 entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool
317 .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME
319 entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool
320 .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME
323 validateCreateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(),
324 entitlementPool.getVendorLicenseModelId());
325 return vendorLicenseFacade.createEntitlementPool(entitlementPool);
328 private void validateCreateDate(String startDate, String expiryDate,
329 String vendorLicenseModelId) {
330 LocalDate parsedStartDate = parseLocalDate(startDate);
331 LocalDate parsedExpiryDate = parseLocalDate(expiryDate);
334 validateIfStartAndExpiryDateIsNotNull(startDate, expiryDate,
335 vendorLicenseModelId, parsedStartDate, parsedExpiryDate);
337 if (startDate != null && expiryDate == null
338 && parsedStartDate.atStartOfDay().isBefore
339 (LocalDate.now().atStartOfDay())) {
340 throw new CoreException(
341 new InvalidDateErrorBuilder(vendorLicenseModelId)
345 if (startDate == null && expiryDate != null) {
346 throw new CoreException(
347 new InvalidDateErrorBuilder(vendorLicenseModelId)
353 private void validateIfStartAndExpiryDateIsNotNull(String startDate, String expiryDate,
354 String vendorLicenseModelId,
355 LocalDate parsedStartDate,
356 LocalDate parsedExpiryDate) {
357 if (startDate != null && expiryDate != null
358 && isValidatStartAndExpiryDate(parsedStartDate, parsedExpiryDate)) {
359 throw new CoreException(
360 new InvalidDateErrorBuilder(vendorLicenseModelId)
365 private boolean isValidatStartAndExpiryDate(LocalDate parsedStartDate,
366 LocalDate parsedExpiryDate) {
367 return parsedStartDate.atStartOfDay().isBefore(LocalDate.now().atStartOfDay())
368 || parsedExpiryDate.atStartOfDay().isEqual(parsedStartDate.atStartOfDay())
369 || parsedExpiryDate.isBefore(parsedStartDate);
372 private static LocalDate parseLocalDate(String date) {
373 if (date == null || date.isEmpty()) {
377 return LocalDate.parse(date, FORMATTER );
380 private void validateUpdateDate(String startDate, String expiryDate,
381 String vendorLicenseModelId) {
382 LocalDate parsedStartDate = parseLocalDate(startDate);
383 LocalDate parsedExpiryDate = parseLocalDate(expiryDate);
385 if (startDate != null && expiryDate != null
386 && (parsedExpiryDate.atStartOfDay()
387 .isEqual(parsedStartDate.atStartOfDay())
388 || parsedExpiryDate.isBefore(parsedStartDate ))) {
389 throw new CoreException(
390 new InvalidDateErrorBuilder(vendorLicenseModelId)
394 if (startDate == null && expiryDate != null) {
395 throw new CoreException(
396 new InvalidDateErrorBuilder(vendorLicenseModelId)
403 public void updateEntitlementPool(EntitlementPoolEntity entitlementPool) {
404 entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool
405 .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate() + EP_POOL_START_TIME
407 entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool
408 .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate() + EP_POOL_EXPIRY_TIME
411 validateUpdateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(),
412 entitlementPool.getVendorLicenseModelId());
413 vendorLicenseFacade.updateEntitlementPool(entitlementPool);
417 public EntitlementPoolEntity getEntitlementPool(EntitlementPoolEntity entitlementPool) {
418 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
420 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
421 DateTimeFormatter targetFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy");
422 if (retrieved.getStartDate() != null) {
423 retrieved.setStartDate(LocalDate.parse(retrieved.getStartDate(), FORMATTER ).format
427 if (retrieved.getExpiryDate() != null) {
428 retrieved.setExpiryDate(LocalDate.parse(retrieved.getExpiryDate(), FORMATTER ).format
435 public void deleteEntitlementPool(EntitlementPoolEntity entitlementPool) {
436 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
438 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
440 for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) {
441 featureGroupDao.removeEntitlementPool(
442 new FeatureGroupEntity(entitlementPool.getVendorLicenseModelId(),
443 entitlementPool.getVersion(),
444 referencingFeatureGroupId), entitlementPool.getId());
447 deleteChildLimits(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion(),
448 entitlementPool.getId());
450 entitlementPoolDao.delete(entitlementPool);
452 deleteUniqueName(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
453 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
454 retrieved.getName());
457 protected void deleteChildLimits(String vlmId, Version version, String epLkgId) {
458 Optional<Collection<LimitEntity>> limitEntities = Optional.ofNullable(
459 listLimits(vlmId, version, epLkgId));
460 limitEntities.ifPresent(entities -> entities.forEach(this::deleteLimit));
464 public Collection<LicenseKeyGroupEntity> listLicenseKeyGroups(String vlmId, Version version) {
465 return vendorLicenseFacade.listLicenseKeyGroups(vlmId, version);
469 public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
470 licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup
471 .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate() + EP_POOL_START_TIME
473 licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup
474 .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate() + EP_POOL_EXPIRY_TIME
477 validateCreateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(),
478 licenseKeyGroup.getVendorLicenseModelId());
479 return vendorLicenseFacade.createLicenseKeyGroup(licenseKeyGroup);
483 public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
484 licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup
485 .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate() + EP_POOL_START_TIME
487 licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup
488 .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate() + EP_POOL_EXPIRY_TIME
491 validateUpdateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(),
492 licenseKeyGroup.getVendorLicenseModelId());
493 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroup);
497 public LicenseKeyGroupEntity getLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
498 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
500 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
505 public void deleteLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup) {
506 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
508 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
510 for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) {
511 featureGroupDao.removeLicenseKeyGroup(
512 new FeatureGroupEntity(licenseKeyGroup.getVendorLicenseModelId(),
513 licenseKeyGroup.getVersion(),
514 referencingFeatureGroupId), licenseKeyGroup.getId());
517 deleteChildLimits(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion(),
518 licenseKeyGroup.getId());
520 licenseKeyGroupDao.delete(licenseKeyGroup);
522 deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
523 retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(),
524 retrieved.getName());
528 public LimitEntity createLimit(LimitEntity limit) {
529 validateLimit(limit);
530 LimitEntity createdLimit = vendorLicenseFacade.createLimit(limit);
531 updateParentForLimit(limit);
535 private void validateLimit(LimitEntity limit) {
536 Collection<LimitEntity> limitList =
537 listLimits(limit.getVendorLicenseModelId(), limit.getVersion()
538 , limit.getEpLkgId());
540 if (!isLimitNameUnique(limitList, limit.getName(), limit.getType(), limit.getId())) {
541 final ErrorCode duplicateLimitNameErrorBuilder =
542 LimitErrorBuilder.getDuplicateNameErrorbuilder(limit.getName(), limit.getType().name());
543 throw new CoreException(duplicateLimitNameErrorBuilder);
547 private boolean isLimitNameUnique(Collection<LimitEntity> limitList, String name, LimitType
549 for (LimitEntity limit : limitList) {
550 if (limit.getName().equalsIgnoreCase(name) &&
551 limit.getType().name().equalsIgnoreCase(type.name())) {
552 if (id != null && limit.getId().equals(id)) {
562 public Collection<LimitEntity> listLimits(String vlmId, Version version, String epLkgId) {
563 return vendorLicenseFacade.listLimits(vlmId, version, epLkgId);
567 public void deleteLimit(LimitEntity limitEntity) {
568 if (!isLimitPresent(limitEntity)) {
570 .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
572 LimitEntity retrieved = limitDao.get(limitEntity);
574 .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
576 limitDao.delete(limitEntity);
578 updateParentForLimit(limitEntity);
582 public void updateLimit(LimitEntity limit) {
584 validateLimit(limit);
585 vendorLicenseFacade.updateLimit(limit);
586 updateParentForLimit(limit);
589 private boolean isLimitPresent(LimitEntity limit) {
590 return limitDao.isLimitPresent(limit);
594 public LimitEntity getLimit(LimitEntity limitEntity) {
595 if (!isLimitPresent(limitEntity)) {
597 .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
599 LimitEntity retrieved = limitDao.get(limitEntity);
601 .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE);
606 * update Parent of limit (EP/LKG) versionuuid when limit is modified so that limit updates are
607 * captured in VLM XML
609 private void updateParentForLimit(LimitEntity limit) {
610 if ("EntitlementPool".equals(limit.getParent())) {
611 EntitlementPoolEntity entitlementPoolEntity =
612 entitlementPoolDao.get(new EntitlementPoolEntity(limit.getVendorLicenseModelId(),
613 limit.getVersion(), limit.getEpLkgId()));
614 vendorLicenseFacade.updateEntitlementPool(entitlementPoolEntity);
617 if ("LicenseKeyGroup".equals(limit.getParent())) {
618 LicenseKeyGroupEntity licenseKeyGroupEntity = licenseKeyGroupDao.get(
619 new LicenseKeyGroupEntity(limit.getVendorLicenseModelId(), limit.getVersion(),
620 limit.getEpLkgId()));
621 vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroupEntity);
625 protected void addFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds,
626 LicenseAgreementEntity licenseAgreement) {
627 if (featureGroupIds != null) {
628 for (String featureGroupId : featureGroupIds) {
629 featureGroupDao.addReferencingLicenseAgreement(
630 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
631 licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId());
636 protected void removeFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds,
637 LicenseAgreementEntity licenseAgreement) {
638 if (featureGroupIds != null) {
639 for (String featureGroupId : featureGroupIds) {
640 featureGroupDao.removeReferencingLicenseAgreement(
641 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(),
642 licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId());
647 protected void addLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds,
648 FeatureGroupEntity featureGroup) {
649 if (licenseKeyGroupIds != null) {
650 for (String licenseKeyGroupId : licenseKeyGroupIds) {
651 licenseKeyGroupDao.addReferencingFeatureGroup(
652 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
653 featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId());
658 protected void removeLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds,
659 FeatureGroupEntity featureGroup) {
660 if (licenseKeyGroupIds != null) {
661 for (String licenseKeyGroupId : licenseKeyGroupIds) {
662 licenseKeyGroupDao.removeReferencingFeatureGroup(
663 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(),
664 featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId());
669 protected void addEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds,
670 FeatureGroupEntity featureGroup) {
671 if (entitlementPoolIds != null) {
672 for (String entitlementPoolId : entitlementPoolIds) {
673 entitlementPoolDao.addReferencingFeatureGroup(
674 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(),
675 featureGroup.getVersion(), entitlementPoolId), featureGroup.getId());
680 protected void removeEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds,
681 FeatureGroupEntity featureGroup) {
682 if (entitlementPoolIds != null) {
683 for (String entitlementPoolId : entitlementPoolIds) {
684 entitlementPoolDao.removeReferencingFeatureGroup(
685 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(),
686 featureGroup.getVersion(), entitlementPoolId), featureGroup.getId());
691 protected void updateUniqueName(String uniqueValueType, String oldName, String newName, String...
694 .updateUniqueValue(uniqueValueType, oldName, newName, context);
697 protected void deleteUniqueName(String uniqueValueType, String... uniqueCombination) {
698 UniqueValueUtil.deleteUniqueValue(uniqueValueType, uniqueCombination);