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.context.impl.MdcDataDebugMessage;
34 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
35 import org.openecomp.sdc.logging.types.LoggerConstants;
36 import org.openecomp.sdc.logging.types.LoggerErrorCode;
37 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
38 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
39 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
40 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
41 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDaoFactory;
42 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
43 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory;
44 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao;
45 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDaoFactory;
46 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
47 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDaoFactory;
48 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
49 import org.openecomp.sdc.vendorlicense.dao.LimitDaoFactory;
50 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
51 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDaoFactory;
52 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
53 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
54 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel;
55 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
56 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementModel;
57 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
58 import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity;
59 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
60 import org.openecomp.sdc.vendorlicense.errors.SubmitUncompletedLicenseModelErrorBuilder;
61 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseModelNotFoundErrorBuilder;
62 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
63 import org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel;
64 import org.openecomp.sdc.versioning.VersioningManager;
65 import org.openecomp.sdc.versioning.VersioningManagerFactory;
66 import org.openecomp.sdc.versioning.VersioningUtil;
67 import org.openecomp.sdc.versioning.dao.types.Version;
68 import org.openecomp.sdc.versioning.errors.RequestedVersionInvalidErrorBuilder;
69 import org.openecomp.sdc.versioning.errors.VersionableSubEntityNotFoundErrorBuilder;
70 import org.openecomp.sdc.versioning.types.VersionInfo;
71 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
75 public class VendorLicenseFacadeImpl implements VendorLicenseFacade {
77 private static final VersioningManager versioningManager =
78 VersioningManagerFactory.getInstance().createInterface();
80 private static final VendorLicenseModelDao
81 vendorLicenseModelDao = VendorLicenseModelDaoFactory.getInstance().createInterface();
82 private static final LicenseAgreementDao
83 licenseAgreementDao = LicenseAgreementDaoFactory.getInstance().createInterface();
84 private static final FeatureGroupDao featureGroupDao =
85 FeatureGroupDaoFactory.getInstance().createInterface();
86 private static final EntitlementPoolDao
87 entitlementPoolDao = EntitlementPoolDaoFactory.getInstance().createInterface();
88 private static final LicenseKeyGroupDao
89 licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface();
90 private static final LimitDao limitDao = LimitDaoFactory.getInstance().createInterface();
91 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
94 * Instantiates a new Vendor license facade.
96 public VendorLicenseFacadeImpl() {
97 vendorLicenseModelDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
98 licenseAgreementDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
99 featureGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
100 entitlementPoolDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
101 licenseKeyGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
102 limitDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
106 public Version checkin(String vendorLicenseModelId, String user) {
107 Version newVersion = versioningManager
108 .checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user, null);
109 updateVlmLastModificationTime(vendorLicenseModelId, newVersion);
114 public Version submit(String vendorLicenseModelId, String user) {
115 validateCompletedVendorLicenseModel(vendorLicenseModelId, user);
116 Version newVersion = versioningManager
117 .submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user, null);
118 updateVlmLastModificationTime(vendorLicenseModelId, newVersion);
123 public FeatureGroupEntity getFeatureGroup(FeatureGroupEntity featureGroup, String user) {
124 Version version = VersioningUtil.resolveVersion(featureGroup.getVersion(),
125 getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Read,
127 featureGroup.setVersion(version);
128 return getFeatureGroup(featureGroup);
131 private FeatureGroupEntity getFeatureGroup(FeatureGroupEntity featureGroup) {
132 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
134 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
135 if (retrieved.getManufacturerReferenceNumber() == null) {
136 updateManufacturerNumberInFeatureGroup(retrieved);
142 public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup, String user) {
143 FeatureGroupEntity retrieved = getFeatureGroup(featureGroup, user);
145 FeatureGroupModel featureGroupModel = new FeatureGroupModel();
146 featureGroupModel.setFeatureGroup(retrieved);
148 for (String licenseKeyGroupId : retrieved.getLicenseKeyGroupIds()) {
149 featureGroupModel.getLicenseKeyGroups().add(licenseKeyGroupDao.get(
150 new LicenseKeyGroupEntity(retrieved.getVendorLicenseModelId(), retrieved.getVersion(),
151 licenseKeyGroupId)));
153 for (String entitlementPoolId : retrieved.getEntitlementPoolIds()) {
154 featureGroupModel.getEntitlementPools().add(entitlementPoolDao.get(
155 new EntitlementPoolEntity(retrieved.getVendorLicenseModelId(), retrieved.getVersion(),
156 entitlementPoolId)));
159 return featureGroupModel;
163 public LicenseAgreementModel getLicenseAgreementModel(String vlmId, Version version,
164 String licenseAgreementId, String user) {
165 LicenseAgreementEntity retrieved =
166 getLicenseAgreement(vlmId, version, licenseAgreementId, user);
168 LicenseAgreementModel licenseAgreementModel = new LicenseAgreementModel();
169 licenseAgreementModel.setLicenseAgreement(retrieved);
171 for (String featureGroupId : retrieved.getFeatureGroupIds()) {
172 licenseAgreementModel.getFeatureGroups().add(featureGroupDao
173 .get(new FeatureGroupEntity(vlmId, retrieved.getVersion(), featureGroupId)));
176 return licenseAgreementModel;
180 public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool,
182 entitlementPool.setVersion(VersioningUtil.resolveVersion(entitlementPool.getVersion(),
183 getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write,
185 //entitlementPool.setId(CommonMethods.nextUuId());
186 entitlementPool.setVersionUuId(CommonMethods.nextUuId());
187 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
188 entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().toString(),
189 entitlementPool.getName());
190 entitlementPoolDao.create(entitlementPool);
191 updateVlmLastModificationTime(entitlementPool.getVendorLicenseModelId(),
192 entitlementPool.getVersion());
193 return entitlementPool;
197 public void updateEntitlementPool(EntitlementPoolEntity entitlementPool, String user) {
198 entitlementPool.setVersion(VersioningUtil.resolveVersion(entitlementPool.getVersion(),
199 getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write,
201 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
203 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
205 UniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
206 retrieved.getName(), entitlementPool.getName(), entitlementPool.getVendorLicenseModelId(),
207 entitlementPool.getVersion().toString());
208 entitlementPool.setVersionUuId(CommonMethods.nextUuId());
209 entitlementPoolDao.update(entitlementPool);
211 updateVlmLastModificationTime(entitlementPool.getVendorLicenseModelId(),
212 entitlementPool.getVersion());
217 public Collection<LicenseKeyGroupEntity> listLicenseKeyGroups(String vlmId, Version version,
219 return licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlmId, VersioningUtil
220 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user),
225 public Collection<EntitlementPoolEntity> listEntitlementPools(String vlmId, Version version,
227 return entitlementPoolDao.list(new EntitlementPoolEntity(vlmId, VersioningUtil
228 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user),
233 public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, String user) {
234 licenseKeyGroup.setVersion(VersioningUtil.resolveVersion(licenseKeyGroup.getVersion(),
235 getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write,
237 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
238 licenseKeyGroup.setVersionUuId((CommonMethods.nextUuId()));
240 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
241 UniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
242 retrieved.getName(), licenseKeyGroup.getName(), licenseKeyGroup.getVendorLicenseModelId(),
243 licenseKeyGroup.getVersion().toString());
244 licenseKeyGroupDao.update(licenseKeyGroup);
246 updateVlmLastModificationTime(licenseKeyGroup.getVendorLicenseModelId(),
247 licenseKeyGroup.getVersion());
251 public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup,
253 licenseKeyGroup.setVersion(VersioningUtil.resolveVersion(licenseKeyGroup.getVersion(),
254 getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write,
256 //licenseKeyGroup.setId(CommonMethods.nextUuId());
257 licenseKeyGroup.setVersionUuId(CommonMethods.nextUuId());
258 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
259 licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().toString(),
260 licenseKeyGroup.getName());
261 licenseKeyGroupDao.create(licenseKeyGroup);
262 updateVlmLastModificationTime(licenseKeyGroup.getVendorLicenseModelId(),
263 licenseKeyGroup.getVersion());
264 return licenseKeyGroup;
268 public VersionedVendorLicenseModel getVendorLicenseModel(String vlmId, Version version,
270 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
272 VersionInfo versionInfo = getVersionInfo(vlmId, VersionableEntityAction.Read, user);
274 VendorLicenseModelEntity vendorLicenseModel = vendorLicenseModelDao.get(
275 new VendorLicenseModelEntity(vlmId,
276 VersioningUtil.resolveVersion(version, versionInfo, user)));
277 if (vendorLicenseModel == null) {
278 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
279 LoggerTragetServiceName.GET_VLM, ErrorLevel.ERROR.name(),
280 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.ENTITY_NOT_FOUND);
281 throw new CoreException(new VendorLicenseModelNotFoundErrorBuilder(vlmId).build());
284 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
285 return new VersionedVendorLicenseModel(vendorLicenseModel, versionInfo);
289 public VendorLicenseModelEntity createVendorLicenseModel(
290 VendorLicenseModelEntity vendorLicenseModelEntity, String user) {
292 mdcDataDebugMessage.debugEntryMessage(null, null);
294 UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
295 vendorLicenseModelEntity.getVendorName());
296 //vendorLicenseModelEntity.setId(CommonMethods.nextUuId());
298 vendorLicenseModelDao.create(vendorLicenseModelEntity);
299 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
300 vendorLicenseModelEntity.getVendorName());
302 Version version = versioningManager
303 .create(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelEntity.getId(), user);
304 vendorLicenseModelEntity.setVersion(version);
306 mdcDataDebugMessage.debugExitMessage(null, null);
307 return vendorLicenseModelEntity;
311 public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement,
313 Version version = VersioningUtil.resolveVersion(licenseAgreement.getVersion(),
314 getVersionInfo(licenseAgreement.getVendorLicenseModelId(), VersionableEntityAction.Write,
316 licenseAgreement.setVersion(version);
317 //licenseAgreement.setId(CommonMethods.nextUuId());
318 VersioningUtil.validateEntitiesExistence(licenseAgreement.getFeatureGroupIds(),
319 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), version, null),
320 featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
322 UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
323 licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().toString(),
324 licenseAgreement.getName());
326 licenseAgreementDao.create(licenseAgreement);
327 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
328 licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().toString(),
329 licenseAgreement.getName());
330 if (licenseAgreement.getFeatureGroupIds() != null) {
331 for (String addedFgId : licenseAgreement.getFeatureGroupIds()) {
332 featureGroupDao.addReferencingLicenseAgreement(
333 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), version,
334 addedFgId), licenseAgreement.getId());
337 updateVlmLastModificationTime(licenseAgreement.getVendorLicenseModelId(),
338 licenseAgreement.getVersion());
340 return licenseAgreement;
344 public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup, String user) {
345 Version version = VersioningUtil.resolveVersion(featureGroup.getVersion(),
346 getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Write,
348 //featureGroup.setId(CommonMethods.nextUuId());
349 featureGroup.setVersion(version);
350 VersioningUtil.validateEntitiesExistence(featureGroup.getLicenseKeyGroupIds(),
351 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), version, null),
352 licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
353 VersioningUtil.validateEntitiesExistence(featureGroup.getEntitlementPoolIds(),
354 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), version, null),
355 entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE);
356 UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
357 featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().toString(),
358 featureGroup.getName());
360 featureGroupDao.create(featureGroup);
361 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
362 featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().toString(),
363 featureGroup.getName());
365 if (featureGroup.getLicenseKeyGroupIds() != null) {
366 for (String addedLkgId : featureGroup.getLicenseKeyGroupIds()) {
367 licenseKeyGroupDao.addReferencingFeatureGroup(
368 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), version, addedLkgId),
369 featureGroup.getId());
373 if (featureGroup.getEntitlementPoolIds() != null) {
374 for (String addedEpId : featureGroup.getEntitlementPoolIds()) {
375 entitlementPoolDao.addReferencingFeatureGroup(
376 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), version, addedEpId),
377 featureGroup.getId());
381 updateVlmLastModificationTime(featureGroup.getVendorLicenseModelId(),
382 featureGroup.getVersion());
388 public Collection<FeatureGroupEntity> listFeatureGroups(String vlmId, Version version,
390 Collection<FeatureGroupEntity> featureGroupEntities =
391 featureGroupDao.list(new FeatureGroupEntity(vlmId, VersioningUtil
392 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user),
394 featureGroupEntities.stream()
395 .filter(fgEntity -> Objects.isNull(fgEntity.getManufacturerReferenceNumber()))
396 .forEach(fgEntity -> updateManufacturerNumberInFeatureGroup(fgEntity));
397 return featureGroupEntities;
402 public Collection<ErrorCode> validateLicensingData(String vlmId, Version version,
403 String licenseAgreementId,
404 Collection<String> featureGroupIds) {
406 VersionInfo versionInfo = getVersionInfo(vlmId, VersionableEntityAction.Read, "");
407 if (version == null || !version.isFinal()
408 || !versionInfo.getViewableVersions().contains(version)) {
409 return Collections.singletonList(new RequestedVersionInvalidErrorBuilder().build());
411 } catch (CoreException exception) {
412 return Collections.singletonList(exception.code());
415 List<ErrorCode> errorMessages = new ArrayList<>();
418 getLicenseAgreement(vlmId, licenseAgreementId, version);
419 } catch (CoreException exception) {
420 errorMessages.add(exception.code());
423 for (String featureGroupId : featureGroupIds) {
425 FeatureGroupEntity featureGroup =
426 getFeatureGroup(new FeatureGroupEntity(vlmId, version, featureGroupId));
427 if (!featureGroup.getReferencingLicenseAgreements().contains(licenseAgreementId)) {
428 errorMessages.add(new VersionableSubEntityNotFoundErrorBuilder(
429 featureGroup.getEntityType(),
431 LicenseAgreementEntity.ENTITY_TYPE,
435 } catch (CoreException exception) {
436 errorMessages.add(exception.code());
440 return errorMessages;
444 public VersionInfo getVersionInfo(String vendorLicenseModelId, VersionableEntityAction action,
446 return versioningManager
447 .getEntityVersionInfo(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user,
452 public void updateVlmLastModificationTime(String vendorLicenseModelId, Version version) {
453 VendorLicenseModelEntity retrieved =
454 vendorLicenseModelDao.get(new VendorLicenseModelEntity(vendorLicenseModelId, version));
455 vendorLicenseModelDao.update(retrieved);
459 public LicenseAgreementEntity getLicenseAgreement(String vlmId, Version version,
460 String licenseAgreementId, String user) {
461 return getLicenseAgreement(vlmId, licenseAgreementId, VersioningUtil
462 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user));
466 public LimitEntity createLimit(LimitEntity limit, String user) {
467 limit.setVersion(VersioningUtil.resolveVersion(limit.getVersion(),
468 getVersionInfo(limit.getVendorLicenseModelId(), VersionableEntityAction.Write,
470 //limit.setVersionUuId(CommonMethods.nextUuId());
471 limitDao.create(limit);
472 updateVlmLastModificationTime(limit.getVendorLicenseModelId(),
478 public Collection<LimitEntity> listLimits(String vlmId, Version version, String epLkgId,
480 return limitDao.list(new LimitEntity(vlmId, VersioningUtil
481 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user),
487 public void updateLimit(LimitEntity limit, String user) {
488 limit.setVersion(VersioningUtil.resolveVersion(limit.getVersion(),
489 getVersionInfo(limit.getVendorLicenseModelId(), VersionableEntityAction.Write,
491 //limit.setVersionUuId(CommonMethods.nextUuId());
492 limitDao.update(limit);
493 updateVlmLastModificationTime(limit.getVendorLicenseModelId(),
497 private LicenseAgreementEntity getLicenseAgreement(String vlmId, String licenseAgreementId,
499 LicenseAgreementEntity input = new LicenseAgreementEntity(vlmId, version, licenseAgreementId);
500 LicenseAgreementEntity retrieved = licenseAgreementDao.get(input);
501 VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE);
505 private void updateManufacturerNumberInFeatureGroup(FeatureGroupEntity featureGroupEntity) {
506 if (CollectionUtils.isNotEmpty(featureGroupEntity.getEntitlementPoolIds())) {
507 Object[] entitlementPoolIdsList = featureGroupEntity.getEntitlementPoolIds().toArray();
508 if (entitlementPoolIdsList != null && entitlementPoolIdsList.length > 0) {
509 String entitlementPoolId = entitlementPoolIdsList[0].toString();
510 EntitlementPoolEntity entitlementPoolEntity =
511 new EntitlementPoolEntity(featureGroupEntity.getVendorLicenseModelId(),
512 featureGroupEntity.getVersion(), entitlementPoolId);
513 entitlementPoolEntity = entitlementPoolDao.get(entitlementPoolEntity);
514 featureGroupEntity.setManufacturerReferenceNumber(
515 entitlementPoolDao.getManufacturerReferenceNumber(entitlementPoolEntity));
516 featureGroupDao.update(featureGroupEntity);
520 private void validateCompletedVendorLicenseModel(String vendorLicenseModelId, String user) {
521 Collection<String> allFeatureGroupEntities = new HashSet<>();
522 Version version = VersioningUtil.resolveVersion(null,
523 getVersionInfo(vendorLicenseModelId, VersionableEntityAction.Read, user), user);
524 Collection<LicenseAgreementEntity> licenseAgreements = licenseAgreementDao
525 .list(new LicenseAgreementEntity(vendorLicenseModelId, version, null));
527 if (CollectionUtils.isNotEmpty(licenseAgreements)) {
528 licenseAgreements.forEach(licenseAgreement -> {
529 if (CollectionUtils.isEmpty(licenseAgreement.getFeatureGroupIds())) {
530 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
531 LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
532 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.SUBMIT_ENTITY);
533 throw new CoreException(
534 new SubmitUncompletedLicenseModelErrorBuilder(SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG).build());
536 allFeatureGroupEntities.addAll(licenseAgreement.getFeatureGroupIds());
539 allFeatureGroupEntities.forEach(fg -> {
540 FeatureGroupEntity featureGroupEntity = featureGroupDao.get(new FeatureGroupEntity(vendorLicenseModelId, version, fg));
541 if(CollectionUtils.isEmpty(featureGroupEntity.getEntitlementPoolIds())) {
542 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
543 LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
544 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.SUBMIT_ENTITY);
545 throw new CoreException(
546 new SubmitUncompletedLicenseModelErrorBuilder(SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP).build());