2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.vendorlicense.facade.impl;
23 import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE;
24 import static org.openecomp.sdc.vendorlicense.errors.UncompletedVendorLicenseModelErrorType.SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP;
25 import static org.openecomp.sdc.vendorlicense.errors.UncompletedVendorLicenseModelErrorType.SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG;
27 import org.apache.commons.collections4.CollectionUtils;
28 import org.openecomp.core.util.UniqueValueUtil;
29 import org.openecomp.core.utilities.CommonMethods;
30 import org.openecomp.sdc.common.errors.CoreException;
31 import org.openecomp.sdc.common.errors.ErrorCode;
32 import org.openecomp.sdc.datatypes.error.ErrorLevel;
33 import org.openecomp.sdc.logging.api.Logger;
34 import org.openecomp.sdc.logging.api.LoggerFactory;
35 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
36 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
37 import org.openecomp.sdc.logging.types.LoggerConstants;
38 import org.openecomp.sdc.logging.types.LoggerErrorCode;
39 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
40 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
41 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
42 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
43 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDaoFactory;
44 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
45 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory;
46 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao;
47 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDaoFactory;
48 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
49 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDaoFactory;
50 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
51 import org.openecomp.sdc.vendorlicense.dao.LimitDaoFactory;
52 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
53 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDaoFactory;
54 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
55 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
56 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel;
57 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
58 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementModel;
59 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
60 import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity;
61 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
62 import org.openecomp.sdc.vendorlicense.errors.SubmitUncompletedLicenseModelErrorBuilder;
63 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseModelNotFoundErrorBuilder;
64 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
65 import org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel;
66 import org.openecomp.sdc.versioning.VersioningManager;
67 import org.openecomp.sdc.versioning.VersioningManagerFactory;
68 import org.openecomp.sdc.versioning.VersioningUtil;
69 import org.openecomp.sdc.versioning.dao.types.Version;
70 import org.openecomp.sdc.versioning.errors.RequestedVersionInvalidErrorBuilder;
71 import org.openecomp.sdc.versioning.errors.VersionableSubEntityNotFoundErrorBuilder;
72 import org.openecomp.sdc.versioning.types.VersionInfo;
73 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
77 public class VendorLicenseFacadeImpl implements VendorLicenseFacade {
79 private static final VersioningManager versioningManager =
80 VersioningManagerFactory.getInstance().createInterface();
82 private static final VendorLicenseModelDao
83 vendorLicenseModelDao = VendorLicenseModelDaoFactory.getInstance().createInterface();
84 private static final LicenseAgreementDao
85 licenseAgreementDao = LicenseAgreementDaoFactory.getInstance().createInterface();
86 private static final FeatureGroupDao featureGroupDao =
87 FeatureGroupDaoFactory.getInstance().createInterface();
88 private static final EntitlementPoolDao
89 entitlementPoolDao = EntitlementPoolDaoFactory.getInstance().createInterface();
90 private static final LicenseKeyGroupDao
91 licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface();
92 private static final LimitDao limitDao = LimitDaoFactory.getInstance().createInterface();
93 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
94 private final Logger log = (Logger) LoggerFactory.getLogger(this.getClass().getName());
97 * Instantiates a new Vendor license facade.
99 public VendorLicenseFacadeImpl() {
100 vendorLicenseModelDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
101 licenseAgreementDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
102 featureGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
103 entitlementPoolDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
104 licenseKeyGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
105 limitDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
109 public Version checkin(String vendorLicenseModelId, String user) {
110 Version newVersion = versioningManager
111 .checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user, null);
112 updateVlmLastModificationTime(vendorLicenseModelId, newVersion);
117 public Version submit(String vendorLicenseModelId, String user) {
118 validateCompletedVendorLicenseModel(vendorLicenseModelId, user);
119 Version newVersion = versioningManager
120 .submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user, null);
121 updateVlmLastModificationTime(vendorLicenseModelId, newVersion);
126 public FeatureGroupEntity getFeatureGroup(FeatureGroupEntity featureGroup, String user) {
127 Version version = VersioningUtil.resolveVersion(featureGroup.getVersion(),
128 getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Read,
130 featureGroup.setVersion(version);
131 return getFeatureGroup(featureGroup);
134 private FeatureGroupEntity getFeatureGroup(FeatureGroupEntity featureGroup) {
135 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
137 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
138 if (retrieved.getManufacturerReferenceNumber() == null) {
139 updateManufacturerNumberInFeatureGroup(retrieved);
145 public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup, String user) {
146 FeatureGroupEntity retrieved = getFeatureGroup(featureGroup, user);
148 FeatureGroupModel featureGroupModel = new FeatureGroupModel();
149 featureGroupModel.setFeatureGroup(retrieved);
151 for (String licenseKeyGroupId : retrieved.getLicenseKeyGroupIds()) {
152 featureGroupModel.getLicenseKeyGroups().add(licenseKeyGroupDao.get(
153 new LicenseKeyGroupEntity(retrieved.getVendorLicenseModelId(), retrieved.getVersion(),
154 licenseKeyGroupId)));
156 for (String entitlementPoolId : retrieved.getEntitlementPoolIds()) {
157 featureGroupModel.getEntitlementPools().add(entitlementPoolDao.get(
158 new EntitlementPoolEntity(retrieved.getVendorLicenseModelId(), retrieved.getVersion(),
159 entitlementPoolId)));
162 return featureGroupModel;
166 public LicenseAgreementModel getLicenseAgreementModel(String vlmId, Version version,
167 String licenseAgreementId, String user) {
168 LicenseAgreementEntity retrieved =
169 getLicenseAgreement(vlmId, version, licenseAgreementId, user);
171 LicenseAgreementModel licenseAgreementModel = new LicenseAgreementModel();
172 licenseAgreementModel.setLicenseAgreement(retrieved);
174 for (String featureGroupId : retrieved.getFeatureGroupIds()) {
175 licenseAgreementModel.getFeatureGroups().add(featureGroupDao
176 .get(new FeatureGroupEntity(vlmId, retrieved.getVersion(), featureGroupId)));
179 return licenseAgreementModel;
183 public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool,
185 entitlementPool.setVersion(VersioningUtil.resolveVersion(entitlementPool.getVersion(),
186 getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write,
188 //entitlementPool.setId(CommonMethods.nextUuId());
189 entitlementPool.setVersionUuId(CommonMethods.nextUuId());
190 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
191 entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().toString(),
192 entitlementPool.getName());
193 entitlementPoolDao.create(entitlementPool);
194 updateVlmLastModificationTime(entitlementPool.getVendorLicenseModelId(),
195 entitlementPool.getVersion());
196 return entitlementPool;
200 public void updateEntitlementPool(EntitlementPoolEntity entitlementPool, String user) {
201 entitlementPool.setVersion(VersioningUtil.resolveVersion(entitlementPool.getVersion(),
202 getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write,
204 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
206 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
208 UniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
209 retrieved.getName(), entitlementPool.getName(), entitlementPool.getVendorLicenseModelId(),
210 entitlementPool.getVersion().toString());
211 entitlementPool.setVersionUuId(CommonMethods.nextUuId());
212 entitlementPoolDao.update(entitlementPool);
214 updateVlmLastModificationTime(entitlementPool.getVendorLicenseModelId(),
215 entitlementPool.getVersion());
220 public Collection<LicenseKeyGroupEntity> listLicenseKeyGroups(String vlmId, Version version,
222 return licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlmId, VersioningUtil
223 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user),
228 public Collection<EntitlementPoolEntity> listEntitlementPools(String vlmId, Version version,
230 return entitlementPoolDao.list(new EntitlementPoolEntity(vlmId, VersioningUtil
231 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user),
236 public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, String user) {
237 licenseKeyGroup.setVersion(VersioningUtil.resolveVersion(licenseKeyGroup.getVersion(),
238 getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write,
240 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
241 licenseKeyGroup.setVersionUuId((CommonMethods.nextUuId()));
243 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
244 UniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
245 retrieved.getName(), licenseKeyGroup.getName(), licenseKeyGroup.getVendorLicenseModelId(),
246 licenseKeyGroup.getVersion().toString());
247 licenseKeyGroupDao.update(licenseKeyGroup);
249 updateVlmLastModificationTime(licenseKeyGroup.getVendorLicenseModelId(),
250 licenseKeyGroup.getVersion());
254 public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup,
256 licenseKeyGroup.setVersion(VersioningUtil.resolveVersion(licenseKeyGroup.getVersion(),
257 getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write,
259 //licenseKeyGroup.setId(CommonMethods.nextUuId());
260 licenseKeyGroup.setVersionUuId(CommonMethods.nextUuId());
261 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
262 licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().toString(),
263 licenseKeyGroup.getName());
264 licenseKeyGroupDao.create(licenseKeyGroup);
265 updateVlmLastModificationTime(licenseKeyGroup.getVendorLicenseModelId(),
266 licenseKeyGroup.getVersion());
267 return licenseKeyGroup;
271 public VersionedVendorLicenseModel getVendorLicenseModel(String vlmId, Version version,
273 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
275 VersionInfo versionInfo = getVersionInfo(vlmId, VersionableEntityAction.Read, user);
277 VendorLicenseModelEntity vendorLicenseModel = vendorLicenseModelDao.get(
278 new VendorLicenseModelEntity(vlmId,
279 VersioningUtil.resolveVersion(version, versionInfo, user)));
280 if (vendorLicenseModel == null) {
281 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
282 LoggerTragetServiceName.GET_VLM, ErrorLevel.ERROR.name(),
283 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.ENTITY_NOT_FOUND);
284 throw new CoreException(new VendorLicenseModelNotFoundErrorBuilder(vlmId).build());
287 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
288 return new VersionedVendorLicenseModel(vendorLicenseModel, versionInfo);
292 public VendorLicenseModelEntity createVendorLicenseModel(
293 VendorLicenseModelEntity vendorLicenseModelEntity, String user) {
295 mdcDataDebugMessage.debugEntryMessage(null, null);
297 UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
298 vendorLicenseModelEntity.getVendorName());
299 //vendorLicenseModelEntity.setId(CommonMethods.nextUuId());
301 vendorLicenseModelDao.create(vendorLicenseModelEntity);
302 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
303 vendorLicenseModelEntity.getVendorName());
305 Version version = versioningManager
306 .create(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelEntity.getId(), user);
307 vendorLicenseModelEntity.setVersion(version);
309 mdcDataDebugMessage.debugExitMessage(null, null);
310 return vendorLicenseModelEntity;
314 public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement,
316 Version version = VersioningUtil.resolveVersion(licenseAgreement.getVersion(),
317 getVersionInfo(licenseAgreement.getVendorLicenseModelId(), VersionableEntityAction.Write,
319 licenseAgreement.setVersion(version);
320 //licenseAgreement.setId(CommonMethods.nextUuId());
321 VersioningUtil.validateEntitiesExistence(licenseAgreement.getFeatureGroupIds(),
322 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), version, null),
323 featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
325 UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
326 licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().toString(),
327 licenseAgreement.getName());
329 licenseAgreementDao.create(licenseAgreement);
330 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
331 licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().toString(),
332 licenseAgreement.getName());
333 if (licenseAgreement.getFeatureGroupIds() != null) {
334 for (String addedFgId : licenseAgreement.getFeatureGroupIds()) {
335 featureGroupDao.addReferencingLicenseAgreement(
336 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), version,
337 addedFgId), licenseAgreement.getId());
340 updateVlmLastModificationTime(licenseAgreement.getVendorLicenseModelId(),
341 licenseAgreement.getVersion());
343 return licenseAgreement;
347 public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup, String user) {
348 Version version = VersioningUtil.resolveVersion(featureGroup.getVersion(),
349 getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Write,
351 //featureGroup.setId(CommonMethods.nextUuId());
352 featureGroup.setVersion(version);
353 VersioningUtil.validateEntitiesExistence(featureGroup.getLicenseKeyGroupIds(),
354 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), version, null),
355 licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
356 VersioningUtil.validateEntitiesExistence(featureGroup.getEntitlementPoolIds(),
357 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), version, null),
358 entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE);
359 UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
360 featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().toString(),
361 featureGroup.getName());
363 featureGroupDao.create(featureGroup);
364 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
365 featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().toString(),
366 featureGroup.getName());
368 if (featureGroup.getLicenseKeyGroupIds() != null) {
369 for (String addedLkgId : featureGroup.getLicenseKeyGroupIds()) {
370 licenseKeyGroupDao.addReferencingFeatureGroup(
371 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), version, addedLkgId),
372 featureGroup.getId());
376 if (featureGroup.getEntitlementPoolIds() != null) {
377 for (String addedEpId : featureGroup.getEntitlementPoolIds()) {
378 entitlementPoolDao.addReferencingFeatureGroup(
379 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), version, addedEpId),
380 featureGroup.getId());
384 updateVlmLastModificationTime(featureGroup.getVendorLicenseModelId(),
385 featureGroup.getVersion());
391 public Collection<FeatureGroupEntity> listFeatureGroups(String vlmId, Version version,
393 Collection<FeatureGroupEntity> featureGroupEntities =
394 featureGroupDao.list(new FeatureGroupEntity(vlmId, VersioningUtil
395 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user),
397 featureGroupEntities.stream()
398 .filter(fgEntity -> Objects.isNull(fgEntity.getManufacturerReferenceNumber()))
399 .forEach(fgEntity -> updateManufacturerNumberInFeatureGroup(fgEntity));
400 return featureGroupEntities;
405 public Collection<ErrorCode> validateLicensingData(String vlmId, Version version,
406 String licenseAgreementId,
407 Collection<String> featureGroupIds) {
409 VersionInfo versionInfo = getVersionInfo(vlmId, VersionableEntityAction.Read, "");
410 if (version == null || !version.isFinal()
411 || !versionInfo.getViewableVersions().contains(version)) {
412 return Collections.singletonList(new RequestedVersionInvalidErrorBuilder().build());
414 } catch (CoreException exception) {
415 log.debug("",exception);
416 return Collections.singletonList(exception.code());
419 List<ErrorCode> errorMessages = new ArrayList<>();
422 getLicenseAgreement(vlmId, licenseAgreementId, version);
423 } catch (CoreException exception) {
424 log.debug("",exception);
425 errorMessages.add(exception.code());
428 for (String featureGroupId : featureGroupIds) {
430 FeatureGroupEntity featureGroup =
431 getFeatureGroup(new FeatureGroupEntity(vlmId, version, featureGroupId));
432 if (!featureGroup.getReferencingLicenseAgreements().contains(licenseAgreementId)) {
433 errorMessages.add(new VersionableSubEntityNotFoundErrorBuilder(
434 featureGroup.getEntityType(),
436 LicenseAgreementEntity.ENTITY_TYPE,
440 } catch (CoreException exception) {
441 log.debug("",exception);
442 errorMessages.add(exception.code());
446 return errorMessages;
450 public VersionInfo getVersionInfo(String vendorLicenseModelId, VersionableEntityAction action,
452 return versioningManager
453 .getEntityVersionInfo(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user,
458 public void updateVlmLastModificationTime(String vendorLicenseModelId, Version version) {
459 VendorLicenseModelEntity retrieved =
460 vendorLicenseModelDao.get(new VendorLicenseModelEntity(vendorLicenseModelId, version));
461 vendorLicenseModelDao.update(retrieved);
465 public LicenseAgreementEntity getLicenseAgreement(String vlmId, Version version,
466 String licenseAgreementId, String user) {
467 return getLicenseAgreement(vlmId, licenseAgreementId, VersioningUtil
468 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user));
472 public LimitEntity createLimit(LimitEntity limit, String user) {
473 limit.setVersion(VersioningUtil.resolveVersion(limit.getVersion(),
474 getVersionInfo(limit.getVendorLicenseModelId(), VersionableEntityAction.Write,
476 //limit.setVersionUuId(CommonMethods.nextUuId());
477 limitDao.create(limit);
478 updateVlmLastModificationTime(limit.getVendorLicenseModelId(),
484 public Collection<LimitEntity> listLimits(String vlmId, Version version, String epLkgId,
486 return limitDao.list(new LimitEntity(vlmId, VersioningUtil
487 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user),
493 public void updateLimit(LimitEntity limit, String user) {
494 limit.setVersion(VersioningUtil.resolveVersion(limit.getVersion(),
495 getVersionInfo(limit.getVendorLicenseModelId(), VersionableEntityAction.Write,
497 //limit.setVersionUuId(CommonMethods.nextUuId());
498 limitDao.update(limit);
499 updateVlmLastModificationTime(limit.getVendorLicenseModelId(),
503 private LicenseAgreementEntity getLicenseAgreement(String vlmId, String licenseAgreementId,
505 LicenseAgreementEntity input = new LicenseAgreementEntity(vlmId, version, licenseAgreementId);
506 LicenseAgreementEntity retrieved = licenseAgreementDao.get(input);
507 VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE);
511 private void updateManufacturerNumberInFeatureGroup(FeatureGroupEntity featureGroupEntity) {
512 if (CollectionUtils.isNotEmpty(featureGroupEntity.getEntitlementPoolIds())) {
513 Object[] entitlementPoolIdsList = featureGroupEntity.getEntitlementPoolIds().toArray();
514 if (entitlementPoolIdsList != null && entitlementPoolIdsList.length > 0) {
515 String entitlementPoolId = entitlementPoolIdsList[0].toString();
516 EntitlementPoolEntity entitlementPoolEntity =
517 new EntitlementPoolEntity(featureGroupEntity.getVendorLicenseModelId(),
518 featureGroupEntity.getVersion(), entitlementPoolId);
519 entitlementPoolEntity = entitlementPoolDao.get(entitlementPoolEntity);
520 featureGroupEntity.setManufacturerReferenceNumber(
521 entitlementPoolDao.getManufacturerReferenceNumber(entitlementPoolEntity));
522 featureGroupDao.update(featureGroupEntity);
526 private void validateCompletedVendorLicenseModel(String vendorLicenseModelId, String user) {
527 Collection<String> allFeatureGroupEntities = new HashSet<>();
528 Version version = VersioningUtil.resolveVersion(null,
529 getVersionInfo(vendorLicenseModelId, VersionableEntityAction.Read, user), user);
530 Collection<LicenseAgreementEntity> licenseAgreements = licenseAgreementDao
531 .list(new LicenseAgreementEntity(vendorLicenseModelId, version, null));
533 if (CollectionUtils.isNotEmpty(licenseAgreements)) {
534 licenseAgreements.forEach(licenseAgreement -> {
535 if (CollectionUtils.isEmpty(licenseAgreement.getFeatureGroupIds())) {
536 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
537 LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
538 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.SUBMIT_ENTITY);
539 throw new CoreException(
540 new SubmitUncompletedLicenseModelErrorBuilder(SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG).build());
542 allFeatureGroupEntities.addAll(licenseAgreement.getFeatureGroupIds());
545 allFeatureGroupEntities.forEach(fg -> {
546 FeatureGroupEntity featureGroupEntity = featureGroupDao.get(new FeatureGroupEntity(vendorLicenseModelId, version, fg));
547 if(CollectionUtils.isEmpty(featureGroupEntity.getEntitlementPoolIds())) {
548 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
549 LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
550 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.SUBMIT_ENTITY);
551 throw new CoreException(
552 new SubmitUncompletedLicenseModelErrorBuilder(SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP).build());