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;
26 import static org.openecomp.sdc.vendorlicense.errors.UncompletedVendorLicenseModelErrorType.SUBMIT_UNCOMPLETED_VLM_MSG_MISSING_LA;
28 import org.apache.commons.collections4.CollectionUtils;
29 import org.openecomp.core.util.UniqueValueUtil;
30 import org.openecomp.core.utilities.CommonMethods;
31 import org.openecomp.sdc.common.errors.CoreException;
32 import org.openecomp.sdc.common.errors.ErrorCode;
33 import org.openecomp.sdc.datatypes.error.ErrorLevel;
34 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
35 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
36 import org.openecomp.sdc.logging.types.LoggerConstants;
37 import org.openecomp.sdc.logging.types.LoggerErrorCode;
38 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
39 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
40 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
41 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
42 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDaoFactory;
43 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
44 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory;
45 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao;
46 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDaoFactory;
47 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
48 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDaoFactory;
49 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
50 import org.openecomp.sdc.vendorlicense.dao.LimitDaoFactory;
51 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
52 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDaoFactory;
53 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
54 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
55 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel;
56 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
57 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementModel;
58 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
59 import org.openecomp.sdc.vendorlicense.dao.types.LimitEntity;
60 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
61 import org.openecomp.sdc.vendorlicense.errors.SubmitUncompletedLicenseModelErrorBuilder;
62 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseModelNotFoundErrorBuilder;
63 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
64 import org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel;
65 import org.openecomp.sdc.versioning.VersioningManager;
66 import org.openecomp.sdc.versioning.VersioningManagerFactory;
67 import org.openecomp.sdc.versioning.VersioningUtil;
68 import org.openecomp.sdc.versioning.dao.types.Version;
69 import org.openecomp.sdc.versioning.errors.RequestedVersionInvalidErrorBuilder;
70 import org.openecomp.sdc.versioning.errors.VersionableSubEntityNotFoundErrorBuilder;
71 import org.openecomp.sdc.versioning.types.VersionInfo;
72 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
76 public class VendorLicenseFacadeImpl implements VendorLicenseFacade {
78 private static final VersioningManager versioningManager =
79 VersioningManagerFactory.getInstance().createInterface();
81 private static final VendorLicenseModelDao
82 vendorLicenseModelDao = VendorLicenseModelDaoFactory.getInstance().createInterface();
83 private static final LicenseAgreementDao
84 licenseAgreementDao = LicenseAgreementDaoFactory.getInstance().createInterface();
85 private static final FeatureGroupDao featureGroupDao =
86 FeatureGroupDaoFactory.getInstance().createInterface();
87 private static final EntitlementPoolDao
88 entitlementPoolDao = EntitlementPoolDaoFactory.getInstance().createInterface();
89 private static final LicenseKeyGroupDao
90 licenseKeyGroupDao = LicenseKeyGroupDaoFactory.getInstance().createInterface();
91 private static final LimitDao limitDao = LimitDaoFactory.getInstance().createInterface();
92 private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
95 * Instantiates a new Vendor license facade.
97 public VendorLicenseFacadeImpl() {
98 vendorLicenseModelDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
99 licenseAgreementDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
100 featureGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
101 entitlementPoolDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
102 licenseKeyGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
103 limitDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
107 public Version checkin(String vendorLicenseModelId, String user) {
108 Version newVersion = versioningManager
109 .checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user, null);
110 updateVlmLastModificationTime(vendorLicenseModelId, newVersion);
115 public Version submit(String vendorLicenseModelId, String user) {
116 validateCompletedVendorLicenseModel(vendorLicenseModelId, user);
117 Version newVersion = versioningManager
118 .submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user, null);
119 updateVlmLastModificationTime(vendorLicenseModelId, newVersion);
124 public FeatureGroupEntity getFeatureGroup(FeatureGroupEntity featureGroup, String user) {
125 Version version = VersioningUtil.resolveVersion(featureGroup.getVersion(),
126 getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Read,
128 featureGroup.setVersion(version);
129 return getFeatureGroup(featureGroup);
132 private FeatureGroupEntity getFeatureGroup(FeatureGroupEntity featureGroup) {
133 FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
135 .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
136 if (retrieved.getManufacturerReferenceNumber() == null) {
137 updateManufacturerNumberInFeatureGroup(retrieved);
143 public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup, String user) {
144 FeatureGroupEntity retrieved = getFeatureGroup(featureGroup, user);
146 FeatureGroupModel featureGroupModel = new FeatureGroupModel();
147 featureGroupModel.setFeatureGroup(retrieved);
149 for (String licenseKeyGroupId : retrieved.getLicenseKeyGroupIds()) {
150 featureGroupModel.getLicenseKeyGroups().add(licenseKeyGroupDao.get(
151 new LicenseKeyGroupEntity(retrieved.getVendorLicenseModelId(), retrieved.getVersion(),
152 licenseKeyGroupId)));
154 for (String entitlementPoolId : retrieved.getEntitlementPoolIds()) {
155 featureGroupModel.getEntitlementPools().add(entitlementPoolDao.get(
156 new EntitlementPoolEntity(retrieved.getVendorLicenseModelId(), retrieved.getVersion(),
157 entitlementPoolId)));
160 return featureGroupModel;
164 public LicenseAgreementModel getLicenseAgreementModel(String vlmId, Version version,
165 String licenseAgreementId, String user) {
166 LicenseAgreementEntity retrieved =
167 getLicenseAgreement(vlmId, version, licenseAgreementId, user);
169 LicenseAgreementModel licenseAgreementModel = new LicenseAgreementModel();
170 licenseAgreementModel.setLicenseAgreement(retrieved);
172 for (String featureGroupId : retrieved.getFeatureGroupIds()) {
173 licenseAgreementModel.getFeatureGroups().add(featureGroupDao
174 .get(new FeatureGroupEntity(vlmId, retrieved.getVersion(), featureGroupId)));
177 return licenseAgreementModel;
181 public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool,
183 entitlementPool.setVersion(VersioningUtil.resolveVersion(entitlementPool.getVersion(),
184 getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write,
186 //entitlementPool.setId(CommonMethods.nextUuId());
187 entitlementPool.setVersionUuId(CommonMethods.nextUuId());
188 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
189 entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().toString(),
190 entitlementPool.getName());
191 entitlementPoolDao.create(entitlementPool);
192 updateVlmLastModificationTime(entitlementPool.getVendorLicenseModelId(),
193 entitlementPool.getVersion());
194 return entitlementPool;
198 public void updateEntitlementPool(EntitlementPoolEntity entitlementPool, String user) {
199 entitlementPool.setVersion(VersioningUtil.resolveVersion(entitlementPool.getVersion(),
200 getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write,
202 EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
204 .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
206 UniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
207 retrieved.getName(), entitlementPool.getName(), entitlementPool.getVendorLicenseModelId(),
208 entitlementPool.getVersion().toString());
209 entitlementPool.setVersionUuId(CommonMethods.nextUuId());
210 entitlementPoolDao.update(entitlementPool);
212 updateVlmLastModificationTime(entitlementPool.getVendorLicenseModelId(),
213 entitlementPool.getVersion());
218 public Collection<LicenseKeyGroupEntity> listLicenseKeyGroups(String vlmId, Version version,
220 return licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlmId, VersioningUtil
221 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user),
226 public Collection<EntitlementPoolEntity> listEntitlementPools(String vlmId, Version version,
228 return entitlementPoolDao.list(new EntitlementPoolEntity(vlmId, VersioningUtil
229 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user),
234 public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, String user) {
235 licenseKeyGroup.setVersion(VersioningUtil.resolveVersion(licenseKeyGroup.getVersion(),
236 getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write,
238 LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
239 licenseKeyGroup.setVersionUuId((CommonMethods.nextUuId()));
241 .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
242 UniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
243 retrieved.getName(), licenseKeyGroup.getName(), licenseKeyGroup.getVendorLicenseModelId(),
244 licenseKeyGroup.getVersion().toString());
245 licenseKeyGroupDao.update(licenseKeyGroup);
247 updateVlmLastModificationTime(licenseKeyGroup.getVendorLicenseModelId(),
248 licenseKeyGroup.getVersion());
252 public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup,
254 licenseKeyGroup.setVersion(VersioningUtil.resolveVersion(licenseKeyGroup.getVersion(),
255 getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write,
257 //licenseKeyGroup.setId(CommonMethods.nextUuId());
258 licenseKeyGroup.setVersionUuId(CommonMethods.nextUuId());
259 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
260 licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().toString(),
261 licenseKeyGroup.getName());
262 licenseKeyGroupDao.create(licenseKeyGroup);
263 updateVlmLastModificationTime(licenseKeyGroup.getVendorLicenseModelId(),
264 licenseKeyGroup.getVersion());
265 return licenseKeyGroup;
269 public VersionedVendorLicenseModel getVendorLicenseModel(String vlmId, Version version,
271 mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
273 VersionInfo versionInfo = getVersionInfo(vlmId, VersionableEntityAction.Read, user);
275 VendorLicenseModelEntity vendorLicenseModel = vendorLicenseModelDao.get(
276 new VendorLicenseModelEntity(vlmId,
277 VersioningUtil.resolveVersion(version, versionInfo, user)));
278 if (vendorLicenseModel == null) {
279 MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
280 LoggerTragetServiceName.GET_VLM, ErrorLevel.ERROR.name(),
281 LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.ENTITY_NOT_FOUND);
282 throw new CoreException(new VendorLicenseModelNotFoundErrorBuilder(vlmId).build());
285 mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
286 return new VersionedVendorLicenseModel(vendorLicenseModel, versionInfo);
290 public VendorLicenseModelEntity createVendorLicenseModel(
291 VendorLicenseModelEntity vendorLicenseModelEntity, String user) {
293 mdcDataDebugMessage.debugEntryMessage(null, null);
295 UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
296 vendorLicenseModelEntity.getVendorName());
297 //vendorLicenseModelEntity.setId(CommonMethods.nextUuId());
299 vendorLicenseModelDao.create(vendorLicenseModelEntity);
300 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
301 vendorLicenseModelEntity.getVendorName());
303 Version version = versioningManager
304 .create(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelEntity.getId(), user);
305 vendorLicenseModelEntity.setVersion(version);
307 mdcDataDebugMessage.debugExitMessage(null, null);
308 return vendorLicenseModelEntity;
312 public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement,
314 Version version = VersioningUtil.resolveVersion(licenseAgreement.getVersion(),
315 getVersionInfo(licenseAgreement.getVendorLicenseModelId(), VersionableEntityAction.Write,
317 licenseAgreement.setVersion(version);
318 //licenseAgreement.setId(CommonMethods.nextUuId());
319 VersioningUtil.validateEntitiesExistence(licenseAgreement.getFeatureGroupIds(),
320 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), version, null),
321 featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
323 UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
324 licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().toString(),
325 licenseAgreement.getName());
327 licenseAgreementDao.create(licenseAgreement);
328 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
329 licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().toString(),
330 licenseAgreement.getName());
331 if (licenseAgreement.getFeatureGroupIds() != null) {
332 for (String addedFgId : licenseAgreement.getFeatureGroupIds()) {
333 featureGroupDao.addReferencingLicenseAgreement(
334 new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), version,
335 addedFgId), licenseAgreement.getId());
338 updateVlmLastModificationTime(licenseAgreement.getVendorLicenseModelId(),
339 licenseAgreement.getVersion());
341 return licenseAgreement;
345 public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup, String user) {
346 Version version = VersioningUtil.resolveVersion(featureGroup.getVersion(),
347 getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Write,
349 //featureGroup.setId(CommonMethods.nextUuId());
350 featureGroup.setVersion(version);
351 VersioningUtil.validateEntitiesExistence(featureGroup.getLicenseKeyGroupIds(),
352 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), version, null),
353 licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
354 VersioningUtil.validateEntitiesExistence(featureGroup.getEntitlementPoolIds(),
355 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), version, null),
356 entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE);
357 UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
358 featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().toString(),
359 featureGroup.getName());
361 featureGroupDao.create(featureGroup);
362 UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
363 featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().toString(),
364 featureGroup.getName());
366 if (featureGroup.getLicenseKeyGroupIds() != null) {
367 for (String addedLkgId : featureGroup.getLicenseKeyGroupIds()) {
368 licenseKeyGroupDao.addReferencingFeatureGroup(
369 new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), version, addedLkgId),
370 featureGroup.getId());
374 if (featureGroup.getEntitlementPoolIds() != null) {
375 for (String addedEpId : featureGroup.getEntitlementPoolIds()) {
376 entitlementPoolDao.addReferencingFeatureGroup(
377 new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), version, addedEpId),
378 featureGroup.getId());
382 updateVlmLastModificationTime(featureGroup.getVendorLicenseModelId(),
383 featureGroup.getVersion());
389 public Collection<FeatureGroupEntity> listFeatureGroups(String vlmId, Version version,
391 Collection<FeatureGroupEntity> featureGroupEntities =
392 featureGroupDao.list(new FeatureGroupEntity(vlmId, VersioningUtil
393 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user),
395 featureGroupEntities.stream()
396 .filter(fgEntity -> Objects.isNull(fgEntity.getManufacturerReferenceNumber()))
397 .forEach(fgEntity -> updateManufacturerNumberInFeatureGroup(fgEntity));
398 return featureGroupEntities;
403 public Collection<ErrorCode> validateLicensingData(String vlmId, Version version,
404 String licenseAgreementId,
405 Collection<String> featureGroupIds) {
407 VersionInfo versionInfo = getVersionInfo(vlmId, VersionableEntityAction.Read, "");
408 if (version == null || !version.isFinal()
409 || !versionInfo.getViewableVersions().contains(version)) {
410 return Collections.singletonList(new RequestedVersionInvalidErrorBuilder().build());
412 } catch (CoreException exception) {
413 return Collections.singletonList(exception.code());
416 List<ErrorCode> errorMessages = new ArrayList<>();
419 getLicenseAgreement(vlmId, licenseAgreementId, version);
420 } catch (CoreException exception) {
421 errorMessages.add(exception.code());
424 for (String featureGroupId : featureGroupIds) {
426 FeatureGroupEntity featureGroup =
427 getFeatureGroup(new FeatureGroupEntity(vlmId, version, featureGroupId));
428 if (!featureGroup.getReferencingLicenseAgreements().contains(licenseAgreementId)) {
429 errorMessages.add(new VersionableSubEntityNotFoundErrorBuilder(
430 featureGroup.getEntityType(),
432 LicenseAgreementEntity.ENTITY_TYPE,
436 } catch (CoreException exception) {
437 errorMessages.add(exception.code());
441 return errorMessages;
445 public VersionInfo getVersionInfo(String vendorLicenseModelId, VersionableEntityAction action,
447 return versioningManager
448 .getEntityVersionInfo(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user,
453 public void updateVlmLastModificationTime(String vendorLicenseModelId, Version version) {
454 VendorLicenseModelEntity retrieved =
455 vendorLicenseModelDao.get(new VendorLicenseModelEntity(vendorLicenseModelId, version));
456 vendorLicenseModelDao.update(retrieved);
460 public LicenseAgreementEntity getLicenseAgreement(String vlmId, Version version,
461 String licenseAgreementId, String user) {
462 return getLicenseAgreement(vlmId, licenseAgreementId, VersioningUtil
463 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user));
467 public LimitEntity createLimit(LimitEntity limit, String user) {
468 limit.setVersion(VersioningUtil.resolveVersion(limit.getVersion(),
469 getVersionInfo(limit.getVendorLicenseModelId(), VersionableEntityAction.Write,
471 //limit.setVersionUuId(CommonMethods.nextUuId());
472 limitDao.create(limit);
473 updateVlmLastModificationTime(limit.getVendorLicenseModelId(),
479 public Collection<LimitEntity> listLimits(String vlmId, Version version, String epLkgId,
481 return limitDao.list(new LimitEntity(vlmId, VersioningUtil
482 .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user),
488 public void updateLimit(LimitEntity limit, String user) {
489 limit.setVersion(VersioningUtil.resolveVersion(limit.getVersion(),
490 getVersionInfo(limit.getVendorLicenseModelId(), VersionableEntityAction.Write,
492 //limit.setVersionUuId(CommonMethods.nextUuId());
493 limitDao.update(limit);
494 updateVlmLastModificationTime(limit.getVendorLicenseModelId(),
498 private LicenseAgreementEntity getLicenseAgreement(String vlmId, String licenseAgreementId,
500 LicenseAgreementEntity input = new LicenseAgreementEntity(vlmId, version, licenseAgreementId);
501 LicenseAgreementEntity retrieved = licenseAgreementDao.get(input);
502 VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE);
506 private void updateManufacturerNumberInFeatureGroup(FeatureGroupEntity featureGroupEntity) {
507 if (CollectionUtils.isNotEmpty(featureGroupEntity.getEntitlementPoolIds())) {
508 Object[] entitlementPoolIdsList = featureGroupEntity.getEntitlementPoolIds().toArray();
509 if (entitlementPoolIdsList != null && entitlementPoolIdsList.length > 0) {
510 String entitlementPoolId = entitlementPoolIdsList[0].toString();
511 EntitlementPoolEntity entitlementPoolEntity =
512 new EntitlementPoolEntity(featureGroupEntity.getVendorLicenseModelId(),
513 featureGroupEntity.getVersion(), entitlementPoolId);
514 entitlementPoolEntity = entitlementPoolDao.get(entitlementPoolEntity);
515 featureGroupEntity.setManufacturerReferenceNumber(
516 entitlementPoolDao.getManufacturerReferenceNumber(entitlementPoolEntity));
517 featureGroupDao.update(featureGroupEntity);
521 private void validateCompletedVendorLicenseModel(String vendorLicenseModelId, String user) {
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());
538 Collection<FeatureGroupEntity> featureGroupEntities = featureGroupDao.list(
539 new FeatureGroupEntity(vendorLicenseModelId, version, null));
540 featureGroupEntities.forEach(featureGroupEntity -> {
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());