6f3573981c8eb1e0df7166cb22944d0327eb2787
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.vendorlicense.facade.impl;
22
23 import org.openecomp.core.util.UniqueValueUtil;
24 import org.openecomp.core.utilities.CommonMethods;
25 import org.openecomp.sdc.common.errors.CoreException;
26 import org.openecomp.sdc.common.errors.ErrorCode;
27 import org.openecomp.sdc.datatypes.error.ErrorLevel;
28 import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage;
29 import org.openecomp.sdc.logging.context.impl.MdcDataErrorMessage;
30 import org.openecomp.sdc.logging.types.LoggerConstants;
31 import org.openecomp.sdc.logging.types.LoggerErrorCode;
32 import org.openecomp.sdc.logging.types.LoggerErrorDescription;
33 import org.openecomp.sdc.logging.types.LoggerTragetServiceName;
34 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
35 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
36 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDaoFactory;
37 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
38 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory;
39 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao;
40 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDaoFactory;
41 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
42 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDaoFactory;
43 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
44 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDaoFactory;
45 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
46 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
47 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel;
48 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity;
49 import org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementModel;
50 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
51 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
52 import org.openecomp.sdc.vendorlicense.errors.SubmitUncompletedLicenseModelErrorBuilder;
53 import org.openecomp.sdc.vendorlicense.errors.VendorLicenseModelNotFoundErrorBuilder;
54 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
55 import org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel;
56 import org.openecomp.sdc.versioning.VersioningManager;
57 import org.openecomp.sdc.versioning.VersioningManagerFactory;
58 import org.openecomp.sdc.versioning.VersioningUtil;
59 import org.openecomp.sdc.versioning.dao.types.Version;
60 import org.openecomp.sdc.versioning.errors.RequestedVersionInvalidErrorBuilder;
61 import org.openecomp.sdc.versioning.errors.VersionableSubEntityNotFoundErrorBuilder;
62 import org.openecomp.sdc.versioning.types.VersionInfo;
63 import org.openecomp.sdc.versioning.types.VersionableEntityAction;
64
65 import java.util.ArrayList;
66 import java.util.Collection;
67 import java.util.Collections;
68 import java.util.List;
69
70 import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE;
71 import static org.openecomp.sdc.vendorlicense.errors.UncompletedVendorLicenseModelErrorType.SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP;
72 import static org.openecomp.sdc.vendorlicense.errors.UncompletedVendorLicenseModelErrorType.SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG;
73 import static org.openecomp.sdc.vendorlicense.errors.UncompletedVendorLicenseModelErrorType.SUBMIT_UNCOMPLETED_VLM_MSG_MISSING_LA;
74
75 public class VendorLicenseFacadeImpl implements VendorLicenseFacade {
76
77   private static final VersioningManager versioningManager =
78       VersioningManagerFactory.getInstance().createInterface();
79
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 MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
91
92   /**
93    * Instantiates a new Vendor license facade.
94    */
95   public VendorLicenseFacadeImpl() {
96     vendorLicenseModelDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
97     licenseAgreementDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
98     featureGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
99     entitlementPoolDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
100     licenseKeyGroupDao.registerVersioning(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE);
101   }
102
103   @Override
104   public Version checkin(String vendorLicenseModelId, String user) {
105     Version newVersion = versioningManager
106         .checkin(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user, null);
107     updateVlmLastModificationTime(vendorLicenseModelId, newVersion);
108     return newVersion;
109   }
110
111   @Override
112   public Version submit(String vendorLicenseModelId, String user) {
113     validateCompletedVendorLicenseModel(vendorLicenseModelId, user);
114     Version newVersion = versioningManager
115         .submit(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user, null);
116     updateVlmLastModificationTime(vendorLicenseModelId, newVersion);
117     return newVersion;
118   }
119
120   @Override
121   public FeatureGroupEntity getFeatureGroup(FeatureGroupEntity featureGroup, String user) {
122     Version version = VersioningUtil.resolveVersion(featureGroup.getVersion(),
123         getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Read,
124             user), user);
125     featureGroup.setVersion(version);
126     return getFeatureGroup(featureGroup);
127   }
128
129   private FeatureGroupEntity getFeatureGroup(FeatureGroupEntity featureGroup) {
130     FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup);
131     VersioningUtil
132         .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE);
133     return retrieved;
134   }
135
136   @Override
137   public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup, String user) {
138     FeatureGroupEntity retrieved = getFeatureGroup(featureGroup, user);
139
140     FeatureGroupModel featureGroupModel = new FeatureGroupModel();
141     featureGroupModel.setFeatureGroup(retrieved);
142
143     for (String licenseKeyGroupId : retrieved.getLicenseKeyGroupIds()) {
144       featureGroupModel.getLicenseKeyGroups().add(licenseKeyGroupDao.get(
145           new LicenseKeyGroupEntity(retrieved.getVendorLicenseModelId(), retrieved.getVersion(),
146               licenseKeyGroupId)));
147     }
148     for (String entitlementPoolId : retrieved.getEntitlementPoolIds()) {
149       featureGroupModel.getEntitlementPools().add(entitlementPoolDao.get(
150           new EntitlementPoolEntity(retrieved.getVendorLicenseModelId(), retrieved.getVersion(),
151               entitlementPoolId)));
152     }
153
154     return featureGroupModel;
155   }
156
157   @Override
158   public LicenseAgreementModel getLicenseAgreementModel(String vlmId, Version version,
159                                                         String licenseAgreementId, String user) {
160     LicenseAgreementEntity retrieved =
161         getLicenseAgreement(vlmId, version, licenseAgreementId, user);
162
163     LicenseAgreementModel licenseAgreementModel = new LicenseAgreementModel();
164     licenseAgreementModel.setLicenseAgreement(retrieved);
165
166     for (String featureGroupId : retrieved.getFeatureGroupIds()) {
167       licenseAgreementModel.getFeatureGroups().add(featureGroupDao
168           .get(new FeatureGroupEntity(vlmId, retrieved.getVersion(), featureGroupId)));
169     }
170
171     return licenseAgreementModel;
172   }
173
174   @Override
175   public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool,
176                                                      String user) {
177     entitlementPool.setVersion(VersioningUtil.resolveVersion(entitlementPool.getVersion(),
178         getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write,
179             user), user));
180     //entitlementPool.setId(CommonMethods.nextUuId());
181     entitlementPool.setVersionUuId(CommonMethods.nextUuId());
182     UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
183         entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion().toString(),
184         entitlementPool.getName());
185     entitlementPoolDao.create(entitlementPool);
186     updateVlmLastModificationTime(entitlementPool.getVendorLicenseModelId(),
187         entitlementPool.getVersion());
188     return entitlementPool;
189   }
190
191   @Override
192   public void updateEntitlementPool(EntitlementPoolEntity entitlementPool, String user) {
193     entitlementPool.setVersion(VersioningUtil.resolveVersion(entitlementPool.getVersion(),
194         getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write,
195             user), user));
196     EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool);
197     VersioningUtil
198         .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE);
199
200     UniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME,
201         retrieved.getName(), entitlementPool.getName(), entitlementPool.getVendorLicenseModelId(),
202         entitlementPool.getVersion().toString());
203     entitlementPool.setVersionUuId(CommonMethods.nextUuId());
204     entitlementPoolDao.update(entitlementPool);
205
206     updateVlmLastModificationTime(entitlementPool.getVendorLicenseModelId(),
207         entitlementPool.getVersion());
208
209   }
210
211   @Override
212   public Collection<LicenseKeyGroupEntity> listLicenseKeyGroups(String vlmId, Version version,
213                                                                 String user) {
214     return licenseKeyGroupDao.list(new LicenseKeyGroupEntity(vlmId, VersioningUtil
215         .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user),
216         null));
217   }
218
219   @Override
220   public Collection<EntitlementPoolEntity> listEntitlementPools(String vlmId, Version version,
221                                                                 String user) {
222     return entitlementPoolDao.list(new EntitlementPoolEntity(vlmId, VersioningUtil
223         .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user),
224         null));
225   }
226
227   @Override
228   public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, String user) {
229     licenseKeyGroup.setVersion(VersioningUtil.resolveVersion(licenseKeyGroup.getVersion(),
230         getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write,
231             user), user));
232     LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup);
233     licenseKeyGroup.setVersionUuId((CommonMethods.nextUuId()));
234     VersioningUtil
235         .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE);
236     UniqueValueUtil.updateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
237         retrieved.getName(), licenseKeyGroup.getName(), licenseKeyGroup.getVendorLicenseModelId(),
238         licenseKeyGroup.getVersion().toString());
239     licenseKeyGroupDao.update(licenseKeyGroup);
240
241     updateVlmLastModificationTime(licenseKeyGroup.getVendorLicenseModelId(),
242         licenseKeyGroup.getVersion());
243   }
244
245   @Override
246   public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup,
247                                                      String user) {
248     licenseKeyGroup.setVersion(VersioningUtil.resolveVersion(licenseKeyGroup.getVersion(),
249         getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write,
250             user), user));
251     //licenseKeyGroup.setId(CommonMethods.nextUuId());
252     licenseKeyGroup.setVersionUuId(CommonMethods.nextUuId());
253     UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME,
254         licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion().toString(),
255         licenseKeyGroup.getName());
256     licenseKeyGroupDao.create(licenseKeyGroup);
257     updateVlmLastModificationTime(licenseKeyGroup.getVendorLicenseModelId(),
258         licenseKeyGroup.getVersion());
259     return licenseKeyGroup;
260   }
261
262   @Override
263   public VersionedVendorLicenseModel getVendorLicenseModel(String vlmId, Version version,
264                                                            String user) {
265     mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId);
266
267     VersionInfo versionInfo = getVersionInfo(vlmId, VersionableEntityAction.Read, user);
268
269     VendorLicenseModelEntity vendorLicenseModel = vendorLicenseModelDao.get(
270         new VendorLicenseModelEntity(vlmId,
271             VersioningUtil.resolveVersion(version, versionInfo, user)));
272     if (vendorLicenseModel == null) {
273       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
274           LoggerTragetServiceName.GET_VLM, ErrorLevel.ERROR.name(),
275           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.ENTITY_NOT_FOUND);
276       throw new CoreException(new VendorLicenseModelNotFoundErrorBuilder(vlmId).build());
277     }
278
279     mdcDataDebugMessage.debugExitMessage("VLM id", vlmId);
280     return new VersionedVendorLicenseModel(vendorLicenseModel, versionInfo);
281   }
282
283   @Override
284   public VendorLicenseModelEntity createVendorLicenseModel(
285       VendorLicenseModelEntity vendorLicenseModelEntity, String user) {
286
287     mdcDataDebugMessage.debugEntryMessage(null, null);
288
289     UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
290         vendorLicenseModelEntity.getVendorName());
291     //vendorLicenseModelEntity.setId(CommonMethods.nextUuId());
292
293     vendorLicenseModelDao.create(vendorLicenseModelEntity);
294     UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
295         vendorLicenseModelEntity.getVendorName());
296
297     Version version = versioningManager
298         .create(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelEntity.getId(), user);
299     vendorLicenseModelEntity.setVersion(version);
300
301     mdcDataDebugMessage.debugExitMessage(null, null);
302     return vendorLicenseModelEntity;
303   }
304
305   @Override
306   public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement,
307                                                        String user) {
308     Version version = VersioningUtil.resolveVersion(licenseAgreement.getVersion(),
309         getVersionInfo(licenseAgreement.getVendorLicenseModelId(), VersionableEntityAction.Write,
310             user), user);
311     licenseAgreement.setVersion(version);
312     //licenseAgreement.setId(CommonMethods.nextUuId());
313     VersioningUtil.validateEntitiesExistence(licenseAgreement.getFeatureGroupIds(),
314         new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), version, null),
315         featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
316
317     UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
318         licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().toString(),
319         licenseAgreement.getName());
320
321     licenseAgreementDao.create(licenseAgreement);
322     UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME,
323         licenseAgreement.getVendorLicenseModelId(), licenseAgreement.getVersion().toString(),
324         licenseAgreement.getName());
325     if (licenseAgreement.getFeatureGroupIds() != null) {
326       for (String addedFgId : licenseAgreement.getFeatureGroupIds()) {
327         featureGroupDao.addReferencingLicenseAgreement(
328             new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), version,
329                 addedFgId), licenseAgreement.getId());
330       }
331     }
332     updateVlmLastModificationTime(licenseAgreement.getVendorLicenseModelId(),
333         licenseAgreement.getVersion());
334
335     return licenseAgreement;
336   }
337
338   @Override
339   public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup, String user) {
340     Version version = VersioningUtil.resolveVersion(featureGroup.getVersion(),
341         getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Write,
342             user), user);
343     //featureGroup.setId(CommonMethods.nextUuId());
344     featureGroup.setVersion(version);
345     VersioningUtil.validateEntitiesExistence(featureGroup.getLicenseKeyGroupIds(),
346         new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), version, null),
347         licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE);
348     VersioningUtil.validateEntitiesExistence(featureGroup.getEntitlementPoolIds(),
349         new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), version, null),
350         entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE);
351     UniqueValueUtil.validateUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
352         featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().toString(),
353         featureGroup.getName());
354
355     featureGroupDao.create(featureGroup);
356     UniqueValueUtil.createUniqueValue(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME,
357         featureGroup.getVendorLicenseModelId(), featureGroup.getVersion().toString(),
358         featureGroup.getName());
359
360     if (featureGroup.getLicenseKeyGroupIds() != null) {
361       for (String addedLkgId : featureGroup.getLicenseKeyGroupIds()) {
362         licenseKeyGroupDao.addReferencingFeatureGroup(
363             new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), version, addedLkgId),
364             featureGroup.getId());
365       }
366     }
367
368     if (featureGroup.getEntitlementPoolIds() != null) {
369       for (String addedEpId : featureGroup.getEntitlementPoolIds()) {
370         entitlementPoolDao.addReferencingFeatureGroup(
371             new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), version, addedEpId),
372             featureGroup.getId());
373       }
374     }
375
376     updateVlmLastModificationTime(featureGroup.getVendorLicenseModelId(),
377         featureGroup.getVersion());
378
379     return featureGroup;
380   }
381
382   @Override
383   public Collection<ErrorCode> validateLicensingData(String vlmId, Version version,
384                                                      String licenseAgreementId,
385                                                      Collection<String> featureGroupIds) {
386     try {
387       VersionInfo versionInfo = getVersionInfo(vlmId, VersionableEntityAction.Read, "");
388       if (version == null || !version.isFinal()
389           || !versionInfo.getViewableVersions().contains(version)) {
390         return Collections.singletonList(new RequestedVersionInvalidErrorBuilder().build());
391       }
392     } catch (CoreException exception) {
393       return Collections.singletonList(exception.code());
394     }
395
396     List<ErrorCode> errorMessages = new ArrayList<>();
397
398     try {
399       getLicenseAgreement(vlmId, licenseAgreementId, version);
400     } catch (CoreException exception) {
401       errorMessages.add(exception.code());
402     }
403
404     for (String featureGroupId : featureGroupIds) {
405       try {
406         FeatureGroupEntity featureGroup =
407             getFeatureGroup(new FeatureGroupEntity(vlmId, version, featureGroupId));
408         if (!featureGroup.getReferencingLicenseAgreements().contains(licenseAgreementId)) {
409           errorMessages.add(new VersionableSubEntityNotFoundErrorBuilder(
410               featureGroup.getEntityType(),
411               featureGroupId,
412               LicenseAgreementEntity.ENTITY_TYPE,
413               licenseAgreementId,
414               version).build());
415         }
416       } catch (CoreException exception) {
417         errorMessages.add(exception.code());
418       }
419     }
420
421     return errorMessages;
422   }
423
424   @Override
425   public VersionInfo getVersionInfo(String vendorLicenseModelId, VersionableEntityAction action,
426                                     String user) {
427     return versioningManager
428         .getEntityVersionInfo(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user,
429             action);
430   }
431
432   @Override
433   public void updateVlmLastModificationTime(String vendorLicenseModelId, Version version) {
434     VendorLicenseModelEntity retrieved =
435         vendorLicenseModelDao.get(new VendorLicenseModelEntity(vendorLicenseModelId, version));
436     vendorLicenseModelDao.update(retrieved);
437   }
438
439   @Override
440   public LicenseAgreementEntity getLicenseAgreement(String vlmId, Version version,
441                                                     String licenseAgreementId, String user) {
442     return getLicenseAgreement(vlmId, licenseAgreementId, VersioningUtil
443         .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user));
444   }
445
446   private LicenseAgreementEntity getLicenseAgreement(String vlmId, String licenseAgreementId,
447                                                      Version version) {
448     LicenseAgreementEntity input = new LicenseAgreementEntity(vlmId, version, licenseAgreementId);
449     LicenseAgreementEntity retrieved = licenseAgreementDao.get(input);
450     VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE);
451     return retrieved;
452   }
453
454   private void validateCompletedVendorLicenseModel(String vendorLicenseModelId, String user) {
455     Version version = VersioningUtil.resolveVersion(null,
456         getVersionInfo(vendorLicenseModelId, VersionableEntityAction.Read, user), user);
457     Collection<LicenseAgreementEntity> licenseAgreements = licenseAgreementDao
458         .list(new LicenseAgreementEntity(vendorLicenseModelId, version, null));
459
460     if (licenseAgreements == null || licenseAgreements.isEmpty()) {
461       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
462           LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
463           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.SUBMIT_ENTITY);
464       throw new CoreException(
465               new SubmitUncompletedLicenseModelErrorBuilder(SUBMIT_UNCOMPLETED_VLM_MSG_MISSING_LA).build());
466     }
467
468     for (LicenseAgreementEntity licenseAgreement : licenseAgreements) {
469         if (licenseAgreement.getFeatureGroupIds() == null || licenseAgreement.getFeatureGroupIds().isEmpty()) {
470         MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
471             LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
472             LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.SUBMIT_ENTITY);
473         throw new CoreException(
474                 new SubmitUncompletedLicenseModelErrorBuilder(SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG).build());
475       }
476     }
477
478     Collection<FeatureGroupEntity> featureGroupEntities =
479         featureGroupDao.list(new FeatureGroupEntity(vendorLicenseModelId, version, null));
480     for (FeatureGroupEntity featureGroupEntity : featureGroupEntities) {
481         if (featureGroupEntity.getEntitlementPoolIds() == null || featureGroupEntity.getEntitlementPoolIds().isEmpty()) {
482         MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB,
483             LoggerTragetServiceName.SUBMIT_ENTITY, ErrorLevel.ERROR.name(),
484             LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.SUBMIT_ENTITY);
485         throw new CoreException(
486                 new SubmitUncompletedLicenseModelErrorBuilder(SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP).build());
487       }
488     }
489
490   }
491 }