diff options
Diffstat (limited to 'openecomp-be/backend')
44 files changed, 2489 insertions, 1379 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java index a755fe8957..1acd44511a 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-license-manager/src/main/java/org/openecomp/sdc/vendorlicense/impl/VendorLicenseManagerImpl.java @@ -98,7 +98,7 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); private static final Logger logger = - LoggerFactory.getLogger(VendorLicenseManagerImpl.class); + LoggerFactory.getLogger(VendorLicenseManagerImpl.class); public VendorLicenseManagerImpl(VersioningManager versioningManager, VendorLicenseFacade vendorLicenseFacade, @@ -122,9 +122,9 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { private static void sortVlmListByModificationTimeDescOrder( - List<VersionedVendorLicenseModel> vendorLicenseModels) { + List<VersionedVendorLicenseModel> vendorLicenseModels) { vendorLicenseModels.sort((o1, o2) -> o2.getVendorLicenseModel().getWritetimeMicroSeconds() - .compareTo(o1.getVendorLicenseModel().getWritetimeMicroSeconds())); + .compareTo(o1.getVendorLicenseModel().getWritetimeMicroSeconds())); } @Override @@ -133,7 +133,7 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { mdcDataDebugMessage.debugEntryMessage("VLM id", vendorLicenseModelId); Version newVersion = versioningManager - .checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user); + .checkout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user); ActivityLogEntity activityLogEntity = new ActivityLogEntity(vendorLicenseModelId, String.valueOf(newVersion.getMajor()+1), ActivityType.CHECKOUT.toString(), user, true, "", ""); @@ -151,7 +151,7 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { mdcDataDebugMessage.debugEntryMessage("VLM id", vendorLicenseModelId); Version newVersion = versioningManager - .undoCheckout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user); + .undoCheckout(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, vendorLicenseModelId, user); vendorLicenseFacade.updateVlmLastModificationTime(vendorLicenseModelId, newVersion); mdcDataDebugMessage.debugExitMessage("VLM id", vendorLicenseModelId); @@ -191,8 +191,8 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { mdcDataDebugMessage.debugEntryMessage(null); Map<String, VersionInfo> idToVersionsInfo = versioningManager - .listEntitiesVersionInfo(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, user, - VersionableEntityAction.Read); + .listEntitiesVersionInfo(VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, user, + VersionableEntityAction.Read); List<VersionedVendorLicenseModel> vendorLicenseModels = new ArrayList<>(); for (Map.Entry<String, VersionInfo> entry : idToVersionsInfo.entrySet()) { @@ -213,7 +213,7 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { try { VendorLicenseModelEntity vlm = - vendorLicenseModelDao.get(new VendorLicenseModelEntity(entry.getKey(), version)); + vendorLicenseModelDao.get(new VendorLicenseModelEntity(entry.getKey(), version)); if (vlm != null) { VersionedVendorLicenseModel versionedVlm = new VersionedVendorLicenseModel(); versionedVlm.setVendorLicenseModel(vlm); @@ -221,11 +221,11 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { vendorLicenseModels.add(versionedVlm); } }catch(RuntimeException rte){ - logger.error("Error trying to retrieve vlm["+entry.getKey()+"] version["+version.toString - ()+"] " + - "message:"+rte - .getMessage()); - } + logger.error("Error trying to retrieve vlm["+entry.getKey()+"] version["+version.toString + ()+"] " + + "message:"+rte + .getMessage()); + } } sortVlmListByModificationTimeDescOrder(vendorLicenseModels); @@ -253,18 +253,18 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { mdcDataDebugMessage.debugEntryMessage("VLM id", vendorLicenseModelEntity.getId()); Version version = resloveVersion(vendorLicenseModelEntity.getId(),null, - getVersionInfo(vendorLicenseModelEntity.getId(), VersionableEntityAction.Write, user), - user); + getVersionInfo(vendorLicenseModelEntity.getId(), VersionableEntityAction.Write, user), + user); vendorLicenseModelEntity.setVersion(version); String existingVendorName = vendorLicenseModelDao.get(vendorLicenseModelEntity).getVendorName(); updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME, existingVendorName, - vendorLicenseModelEntity.getVendorName()); + vendorLicenseModelEntity.getVendorName()); vendorLicenseModelDao.update(vendorLicenseModelEntity); vendorLicenseFacade - .updateVlmLastModificationTime(vendorLicenseModelEntity.getId(), version); + .updateVlmLastModificationTime(vendorLicenseModelEntity.getId(), version); mdcDataDebugMessage.debugExitMessage("VLM id", vendorLicenseModelEntity.getId()); } @@ -278,8 +278,8 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { @Override public void deleteVendorLicenseModel(String vlmId, String user) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.DELETE_ENTITY, ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.UNSUPPORTED_OPERATION); + LoggerTragetServiceName.DELETE_ENTITY, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.UNSUPPORTED_OPERATION); throw new UnsupportedOperationException(VendorLicenseConstants.UNSUPPORTED_OPERATION_ERROR); } @@ -289,7 +289,7 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { mdcDataDebugMessage.debugEntryMessage("VLM id", vlmId); mdcDataDebugMessage.debugExitMessage("VLM id", vlmId); LicenseAgreementEntity licenseAgreementEntity = createLicenseAgreementForList(vlmId, version, - user); + user); // return licenseAgreementDao.list(new LicenseAgreementEntity(vlmId, VersioningUtil // .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user), // null)); @@ -300,9 +300,9 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { public LicenseAgreementEntity createLicenseAgreement(LicenseAgreementEntity licenseAgreement, String user) { mdcDataDebugMessage - .debugEntryMessage("VLM id", licenseAgreement.getVendorLicenseModelId()); + .debugEntryMessage("VLM id", licenseAgreement.getVendorLicenseModelId()); mdcDataDebugMessage - .debugExitMessage("VLM id", licenseAgreement.getVendorLicenseModelId()); + .debugExitMessage("VLM id", licenseAgreement.getVendorLicenseModelId()); return vendorLicenseFacade.createLicenseAgreement(licenseAgreement, user); } @@ -311,35 +311,35 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { Set<String> addedFeatureGroupIds, Set<String> removedFeatureGroupIds, String user) { mdcDataDebugMessage.debugEntryMessage("VLM id, LA id", licenseAgreement - .getVendorLicenseModelId(), licenseAgreement.getId()); + .getVendorLicenseModelId(), licenseAgreement.getId()); Version version = VersioningUtil.resolveVersion(licenseAgreement.getVersion(), - getVersionInfo(licenseAgreement.getVendorLicenseModelId(), VersionableEntityAction.Write, - user), user); + getVersionInfo(licenseAgreement.getVendorLicenseModelId(), VersionableEntityAction.Write, + user), user); licenseAgreement.setVersion(version); LicenseAgreementEntity retrieved = licenseAgreementDao.get(licenseAgreement); VersioningUtil - .validateEntityExistence(retrieved, licenseAgreement, VendorLicenseModelEntity.ENTITY_TYPE); + .validateEntityExistence(retrieved, licenseAgreement, VendorLicenseModelEntity.ENTITY_TYPE); VersioningUtil.validateContainedEntitiesExistence(new FeatureGroupEntity().getEntityType(), - removedFeatureGroupIds, retrieved, retrieved.getFeatureGroupIds()); + removedFeatureGroupIds, retrieved, retrieved.getFeatureGroupIds()); VersioningUtil.validateEntitiesExistence(addedFeatureGroupIds, - new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), version, null), - featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE); + new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), version, null), + featureGroupDao, VendorLicenseModelEntity.ENTITY_TYPE); updateUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME, - retrieved.getName(), licenseAgreement.getName(), licenseAgreement.getVendorLicenseModelId(), - licenseAgreement.getVersion().toString()); + retrieved.getName(), licenseAgreement.getName(), licenseAgreement.getVendorLicenseModelId(), + licenseAgreement.getVersion().toString()); licenseAgreementDao.updateColumnsAndDeltaFeatureGroupIds(licenseAgreement, addedFeatureGroupIds, - removedFeatureGroupIds); + removedFeatureGroupIds); addFeatureGroupsToLicenseAgreementRef(addedFeatureGroupIds, licenseAgreement); removeFeatureGroupsToLicenseAgreementRef(removedFeatureGroupIds, licenseAgreement); vendorLicenseFacade - .updateVlmLastModificationTime(licenseAgreement.getVendorLicenseModelId(), version); + .updateVlmLastModificationTime(licenseAgreement.getVendorLicenseModelId(), version); mdcDataDebugMessage.debugExitMessage("VLM id, LA id", licenseAgreement - .getVendorLicenseModelId(), licenseAgreement.getId()); + .getVendorLicenseModelId(), licenseAgreement.getId()); } @Override @@ -357,9 +357,9 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { mdcDataDebugMessage.debugEntryMessage("VLM id, LA id", vlmId, licenseAgreementId); version = VersioningUtil - .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Write, user), user); + .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Write, user), user); LicenseAgreementEntity input = - new LicenseAgreementEntity(vlmId, version, licenseAgreementId); + new LicenseAgreementEntity(vlmId, version, licenseAgreementId); LicenseAgreementEntity retrieved = licenseAgreementDao.get(input); VersioningUtil.validateEntityExistence(retrieved, input, VendorLicenseModelEntity.ENTITY_TYPE); @@ -368,11 +368,11 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { licenseAgreementDao.delete(retrieved); deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_AGREEMENT_NAME, - retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(), - retrieved.getName()); + retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(), + retrieved.getName()); vendorLicenseFacade - .updateVlmLastModificationTime(input.getVendorLicenseModelId(), input.getVersion()); + .updateVlmLastModificationTime(input.getVendorLicenseModelId(), input.getVersion()); mdcDataDebugMessage.debugExitMessage("VLM id, LA id", vlmId, licenseAgreementId); } @@ -388,7 +388,7 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { @Override public FeatureGroupEntity createFeatureGroup(FeatureGroupEntity featureGroup, String user) { mdcDataDebugMessage - .debugEntryMessage("VLM id", featureGroup.getVendorLicenseModelId()); + .debugEntryMessage("VLM id", featureGroup.getVendorLicenseModelId()); mdcDataDebugMessage.debugExitMessage("VLM id", featureGroup.getId()); return vendorLicenseFacade.createFeatureGroup(featureGroup, user); } @@ -401,32 +401,32 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { Set<String> removedEntitlementPools, String user) { mdcDataDebugMessage.debugEntryMessage("VLM id, FG id", featureGroup - .getVendorLicenseModelId(), featureGroup.getId()); + .getVendorLicenseModelId(), featureGroup.getId()); Version version = VersioningUtil.resolveVersion(featureGroup.getVersion(), - getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Write, user), - user); + getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Write, user), + user); featureGroup.setVersion(version); FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup); VersioningUtil - .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE); + .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE); VersioningUtil.validateContainedEntitiesExistence(new LicenseKeyGroupEntity().getEntityType(), - removedLicenseKeyGroups, retrieved, retrieved.getLicenseKeyGroupIds()); + removedLicenseKeyGroups, retrieved, retrieved.getLicenseKeyGroupIds()); VersioningUtil.validateContainedEntitiesExistence(new EntitlementPoolEntity().getEntityType(), - removedEntitlementPools, retrieved, retrieved.getEntitlementPoolIds()); + removedEntitlementPools, retrieved, retrieved.getEntitlementPoolIds()); VersioningUtil.validateEntitiesExistence(addedLicenseKeyGroups, - new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), version, null), - licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE); + new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), version, null), + licenseKeyGroupDao, VendorLicenseModelEntity.ENTITY_TYPE); VersioningUtil.validateEntitiesExistence(addedEntitlementPools, - new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), version, null), - entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE); + new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), version, null), + entitlementPoolDao, VendorLicenseModelEntity.ENTITY_TYPE); updateUniqueName(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME, - retrieved.getName(), featureGroup.getName(), featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion().toString()); + retrieved.getName(), featureGroup.getName(), featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion().toString()); addLicenseKeyGroupsToFeatureGroupsRef(addedLicenseKeyGroups, featureGroup); removeLicenseKeyGroupsToFeatureGroupsRef(removedLicenseKeyGroups, featureGroup); @@ -434,59 +434,59 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { removeEntitlementPoolsToFeatureGroupsRef(removedEntitlementPools, featureGroup); featureGroupDao.updateFeatureGroup(featureGroup, addedEntitlementPools, removedEntitlementPools, - addedLicenseKeyGroups, removedLicenseKeyGroups); + addedLicenseKeyGroups, removedLicenseKeyGroups); vendorLicenseFacade - .updateVlmLastModificationTime(featureGroup.getVendorLicenseModelId(), version); + .updateVlmLastModificationTime(featureGroup.getVendorLicenseModelId(), version); mdcDataDebugMessage.debugExitMessage("VLM id, FG id", featureGroup - .getVendorLicenseModelId(), featureGroup.getId()); + .getVendorLicenseModelId(), featureGroup.getId()); } @Override public FeatureGroupModel getFeatureGroupModel(FeatureGroupEntity featureGroup, String user) { mdcDataDebugMessage.debugEntryMessage("VLM id, FG id", - featureGroup.getVendorLicenseModelId(), featureGroup.getId()); + featureGroup.getVendorLicenseModelId(), featureGroup.getId()); mdcDataDebugMessage.debugExitMessage("VLM id, FG id", - featureGroup.getVendorLicenseModelId(), featureGroup.getId()); + featureGroup.getVendorLicenseModelId(), featureGroup.getId()); return vendorLicenseFacade.getFeatureGroupModel(featureGroup, user); } @Override public void deleteFeatureGroup(FeatureGroupEntity featureGroup, String user) { mdcDataDebugMessage.debugEntryMessage("VLM id, FG id", - featureGroup.getVendorLicenseModelId(), featureGroup.getId()); + featureGroup.getVendorLicenseModelId(), featureGroup.getId()); Version version = VersioningUtil.resolveVersion(featureGroup.getVersion(), - getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Write, - user), user); + getVersionInfo(featureGroup.getVendorLicenseModelId(), VersionableEntityAction.Write, + user), user); featureGroup.setVersion(version); FeatureGroupEntity retrieved = featureGroupDao.get(featureGroup); VersioningUtil - .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE); + .validateEntityExistence(retrieved, featureGroup, VendorLicenseModelEntity.ENTITY_TYPE); removeLicenseKeyGroupsToFeatureGroupsRef(retrieved.getLicenseKeyGroupIds(), featureGroup); removeEntitlementPoolsToFeatureGroupsRef(retrieved.getEntitlementPoolIds(), featureGroup); for (String licenceAgreementId : retrieved.getReferencingLicenseAgreements()) { licenseAgreementDao.removeFeatureGroup( - new LicenseAgreementEntity(featureGroup.getVendorLicenseModelId(), version, - licenceAgreementId), featureGroup.getId()); + new LicenseAgreementEntity(featureGroup.getVendorLicenseModelId(), version, + licenceAgreementId), featureGroup.getId()); } featureGroupDao.delete(featureGroup); deleteUniqueName(VendorLicenseConstants.UniqueValues.FEATURE_GROUP_NAME, - retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(), - retrieved.getName()); + retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(), + retrieved.getName()); vendorLicenseFacade.updateVlmLastModificationTime(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion()); + featureGroup.getVersion()); mdcDataDebugMessage - .debugExitMessage("VLM id, FG id", - featureGroup.getVendorLicenseModelId(), featureGroup.getId()); + .debugExitMessage("VLM id, FG id", + featureGroup.getVendorLicenseModelId(), featureGroup.getId()); } @Override @@ -501,61 +501,61 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { public EntitlementPoolEntity createEntitlementPool(EntitlementPoolEntity entitlementPool, String user) { mdcDataDebugMessage - .debugEntryMessage("VLM id", entitlementPool.getVendorLicenseModelId()); + .debugEntryMessage("VLM id", entitlementPool.getVendorLicenseModelId()); mdcDataDebugMessage - .debugExitMessage("VLM id", entitlementPool.getVendorLicenseModelId()); + .debugExitMessage("VLM id", entitlementPool.getVendorLicenseModelId()); entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool - .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate()+"T00:00:00Z" - : null) : null); + .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate()+"T00:00:00Z" + : null) : null); entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool - .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate()+"T23:59:59Z" - : null) : null); + .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate()+"T23:59:59Z" + : null) : null); validateCreateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(), - entitlementPool.getVendorLicenseModelId()); + entitlementPool.getVendorLicenseModelId()); return vendorLicenseFacade.createEntitlementPool(entitlementPool, user); } private void validateCreateDate(String startDate, String expiryDate, String vendorLicenseModelId){ mdcDataDebugMessage.debugEntryMessage("Start date and end date", startDate - +" "+expiryDate); + +" "+expiryDate); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy'T'HH:mm:ss'Z'"); if(startDate != null && expiryDate != null) { if (LocalDate.parse(startDate, formatter).atStartOfDay().isBefore - (LocalDate.now().atStartOfDay()) || LocalDate.parse(expiryDate, formatter).atStartOfDay() + (LocalDate.now().atStartOfDay()) || LocalDate.parse(expiryDate, formatter).atStartOfDay() .isEqual(LocalDate.parse(startDate, formatter).atStartOfDay()) || LocalDate - .parse(expiryDate, formatter).isBefore(LocalDate.parse(startDate, formatter))) { + .parse(expiryDate, formatter).isBefore(LocalDate.parse(startDate, formatter))) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.VALIDATE_DATE_RANGE,ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE); + LoggerTragetServiceName.VALIDATE_DATE_RANGE,ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE); throw new CoreException( - new InvalidDateErrorBuilder(vendorLicenseModelId) - .build()); + new InvalidDateErrorBuilder(vendorLicenseModelId) + .build()); } } if(startDate != null && expiryDate == null) { if (LocalDate.parse(startDate, formatter).atStartOfDay().isBefore - (LocalDate.now().atStartOfDay())) { + (LocalDate.now().atStartOfDay())) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.VALIDATE_DATE_RANGE,ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE); + LoggerTragetServiceName.VALIDATE_DATE_RANGE,ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE); throw new CoreException( - new InvalidDateErrorBuilder(vendorLicenseModelId) - .build()); + new InvalidDateErrorBuilder(vendorLicenseModelId) + .build()); } } if(startDate == null && expiryDate != null) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.VALIDATE_DATE_RANGE,ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE); + LoggerTragetServiceName.VALIDATE_DATE_RANGE,ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE); throw new CoreException( - new InvalidDateErrorBuilder(vendorLicenseModelId) - .build()); + new InvalidDateErrorBuilder(vendorLicenseModelId) + .build()); } @@ -564,30 +564,30 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { private void validateUpdateDate(String startDate, String expiryDate, String vendorLicenseModelId){ mdcDataDebugMessage.debugEntryMessage("Start date and end date", startDate - +" "+ expiryDate); + +" "+ expiryDate); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy'T'HH:mm:ss'Z'"); if(startDate != null && expiryDate != null) { if (LocalDate.parse(expiryDate, formatter).atStartOfDay() - .isEqual(LocalDate.parse(startDate, formatter).atStartOfDay()) || - LocalDate.parse(expiryDate, formatter).isBefore(LocalDate.parse(startDate, formatter))) { + .isEqual(LocalDate.parse(startDate, formatter).atStartOfDay()) || + LocalDate.parse(expiryDate, formatter).isBefore(LocalDate.parse(startDate, formatter))) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.VALIDATE_DATE_RANGE,ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE); + LoggerTragetServiceName.VALIDATE_DATE_RANGE,ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE); throw new CoreException( - new InvalidDateErrorBuilder(vendorLicenseModelId) - .build()); + new InvalidDateErrorBuilder(vendorLicenseModelId) + .build()); } } if(startDate == null && expiryDate != null) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.VALIDATE_DATE_RANGE,ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE); + LoggerTragetServiceName.VALIDATE_DATE_RANGE,ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_VALUE); throw new CoreException( - new InvalidDateErrorBuilder(vendorLicenseModelId) - .build()); + new InvalidDateErrorBuilder(vendorLicenseModelId) + .build()); } @@ -597,77 +597,77 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { @Override public void updateEntitlementPool(EntitlementPoolEntity entitlementPool, String user) { mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", entitlementPool - .getVendorLicenseModelId(), entitlementPool.getId()); + .getVendorLicenseModelId(), entitlementPool.getId()); entitlementPool.setStartDate(entitlementPool.getStartDate() != null ? (entitlementPool - .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate()+"T00:00:00Z" - : null) : null); + .getStartDate().trim().length() != 0 ? entitlementPool.getStartDate()+"T00:00:00Z" + : null) : null); entitlementPool.setExpiryDate(entitlementPool.getExpiryDate() != null ? (entitlementPool - .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate()+"T23:59:59Z" - : null) : null); + .getExpiryDate().trim().length() != 0 ? entitlementPool.getExpiryDate()+"T23:59:59Z" + : null) : null); validateUpdateDate(entitlementPool.getStartDate(), entitlementPool.getExpiryDate(), - entitlementPool.getVendorLicenseModelId()); + entitlementPool.getVendorLicenseModelId()); Version version = VersioningUtil.resolveVersion(entitlementPool.getVersion(), - getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write, - user), user); + getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write, + user), user); vendorLicenseFacade - .updateVlmLastModificationTime(entitlementPool.getVendorLicenseModelId(), version); + .updateVlmLastModificationTime(entitlementPool.getVendorLicenseModelId(), version); vendorLicenseFacade.updateEntitlementPool(entitlementPool, user); mdcDataDebugMessage.debugExitMessage("VLM id, EP id", entitlementPool - .getVendorLicenseModelId(), entitlementPool.getId()); + .getVendorLicenseModelId(), entitlementPool.getId()); } @Override public EntitlementPoolEntity getEntitlementPool(EntitlementPoolEntity entitlementPool, String user) { mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", entitlementPool - .getVendorLicenseModelId(), entitlementPool.getId()); + .getVendorLicenseModelId(), entitlementPool.getId()); entitlementPool.setVersion(VersioningUtil.resolveVersion(entitlementPool.getVersion(), - getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Read, - user), user)); + getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Read, + user), user)); EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool); VersioningUtil - .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE); + .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy'T'HH:mm:ss'Z'"); DateTimeFormatter targetFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); if(retrieved.getStartDate() != null){ retrieved.setStartDate(LocalDate.parse(retrieved.getStartDate(),formatter).format - (targetFormatter)); + (targetFormatter)); } if(retrieved.getExpiryDate() != null){ retrieved.setExpiryDate(LocalDate.parse(retrieved.getExpiryDate(),formatter).format - (targetFormatter)); + (targetFormatter)); } mdcDataDebugMessage.debugExitMessage("VLM id, EP id", entitlementPool - .getVendorLicenseModelId(), entitlementPool.getId()); + .getVendorLicenseModelId(), entitlementPool.getId()); return retrieved; } @Override public void deleteEntitlementPool(EntitlementPoolEntity entitlementPool, String user) { mdcDataDebugMessage.debugEntryMessage("VLM id, EP id", entitlementPool - .getVendorLicenseModelId(), entitlementPool.getId()); + .getVendorLicenseModelId(), entitlementPool.getId()); Version version = VersioningUtil.resolveVersion(entitlementPool.getVersion(), - getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write, - user), user); + getVersionInfo(entitlementPool.getVendorLicenseModelId(), VersionableEntityAction.Write, + user), user); entitlementPool.setVersion(version); EntitlementPoolEntity retrieved = entitlementPoolDao.get(entitlementPool); VersioningUtil - .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE); + .validateEntityExistence(retrieved, entitlementPool, VendorLicenseModelEntity.ENTITY_TYPE); for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) { featureGroupDao.removeEntitlementPool( - new FeatureGroupEntity(entitlementPool.getVendorLicenseModelId(), version, - referencingFeatureGroupId), entitlementPool.getId()); + new FeatureGroupEntity(entitlementPool.getVendorLicenseModelId(), version, + referencingFeatureGroupId), entitlementPool.getId()); } deleteChildLimits(entitlementPool.getVendorLicenseModelId(), entitlementPool.getVersion(), entitlementPool.getId(), user); @@ -675,22 +675,22 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { entitlementPoolDao.delete(entitlementPool); deleteUniqueName(VendorLicenseConstants.UniqueValues.ENTITLEMENT_POOL_NAME, - retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(), - retrieved.getName()); + retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(), + retrieved.getName()); vendorLicenseFacade.updateVlmLastModificationTime(entitlementPool.getVendorLicenseModelId(), - entitlementPool.getVersion()); + entitlementPool.getVersion()); mdcDataDebugMessage.debugExitMessage("VLM id, EP id", entitlementPool - .getVendorLicenseModelId(), entitlementPool.getId()); + .getVendorLicenseModelId(), entitlementPool.getId()); } protected void deleteChildLimits(String vlmId, Version version, String epLkgId, String user) { - Optional<Collection<LimitEntity>> limitEntities = Optional.ofNullable( - listLimits(vlmId, version, epLkgId, user)); - limitEntities.ifPresent(entities-> - entities.forEach(entity-> - deleteLimit(entity, user))); + Optional<Collection<LimitEntity>> limitEntities = Optional.ofNullable( + listLimits(vlmId, version, epLkgId, user)); + limitEntities.ifPresent(entities-> + entities.forEach(entity-> + deleteLimit(entity, user))); } @Override @@ -705,87 +705,87 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { public LicenseKeyGroupEntity createLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, String user) { mdcDataDebugMessage - .debugEntryMessage("VLM id", licenseKeyGroup.getVendorLicenseModelId()); + .debugEntryMessage("VLM id", licenseKeyGroup.getVendorLicenseModelId()); mdcDataDebugMessage.debugExitMessage("VLM id", licenseKeyGroup - .getVendorLicenseModelId()); + .getVendorLicenseModelId()); licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup - .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate()+"T00:00:00Z" - : null) : null); + .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate()+"T00:00:00Z" + : null) : null); licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup - .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate()+"T23:59:59Z" - : null) : null); + .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate()+"T23:59:59Z" + : null) : null); validateCreateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(), - licenseKeyGroup.getVendorLicenseModelId()); + licenseKeyGroup.getVendorLicenseModelId()); return vendorLicenseFacade.createLicenseKeyGroup(licenseKeyGroup, user); } @Override public void updateLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, String user) { mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", licenseKeyGroup - .getVendorLicenseModelId(), licenseKeyGroup.getId()); + .getVendorLicenseModelId(), licenseKeyGroup.getId()); licenseKeyGroup.setStartDate(licenseKeyGroup.getStartDate() != null ? (licenseKeyGroup - .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate()+"T00:00:00Z" - : null) : null); + .getStartDate().trim().length() != 0 ? licenseKeyGroup.getStartDate()+"T00:00:00Z" + : null) : null); licenseKeyGroup.setExpiryDate(licenseKeyGroup.getExpiryDate() != null ? (licenseKeyGroup - .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate()+"T23:59:59Z" - : null) : null); + .getExpiryDate().trim().length() != 0 ? licenseKeyGroup.getExpiryDate()+"T23:59:59Z" + : null) : null); validateUpdateDate(licenseKeyGroup.getStartDate(), licenseKeyGroup.getExpiryDate(), - licenseKeyGroup.getVendorLicenseModelId()); + licenseKeyGroup.getVendorLicenseModelId()); Version version = VersioningUtil.resolveVersion(licenseKeyGroup.getVersion(), - getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write, - user), user); + getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write, + user), user); vendorLicenseFacade - .updateVlmLastModificationTime(licenseKeyGroup.getVendorLicenseModelId(), version); + .updateVlmLastModificationTime(licenseKeyGroup.getVendorLicenseModelId(), version); vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroup, user); mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", licenseKeyGroup - .getVendorLicenseModelId(), licenseKeyGroup.getId()); + .getVendorLicenseModelId(), licenseKeyGroup.getId()); } @Override public LicenseKeyGroupEntity getLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, String user) { mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", licenseKeyGroup - .getVendorLicenseModelId(), licenseKeyGroup.getId()); + .getVendorLicenseModelId(), licenseKeyGroup.getId()); licenseKeyGroup.setVersion(VersioningUtil.resolveVersion(licenseKeyGroup.getVersion(), - getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Read, - user), user)); + getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Read, + user), user)); LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup); VersioningUtil - .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE); + .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE); mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", licenseKeyGroup - .getVendorLicenseModelId(), licenseKeyGroup.getId()); + .getVendorLicenseModelId(), licenseKeyGroup.getId()); return retrieved; } @Override public void deleteLicenseKeyGroup(LicenseKeyGroupEntity licenseKeyGroup, String user) { mdcDataDebugMessage.debugEntryMessage("VLM id, LKG id", licenseKeyGroup - .getVendorLicenseModelId(), licenseKeyGroup.getId()); + .getVendorLicenseModelId(), licenseKeyGroup.getId()); Version version = VersioningUtil.resolveVersion(licenseKeyGroup.getVersion(), - getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write, - user), user); + getVersionInfo(licenseKeyGroup.getVendorLicenseModelId(), VersionableEntityAction.Write, + user), user); licenseKeyGroup.setVersion(version); LicenseKeyGroupEntity retrieved = licenseKeyGroupDao.get(licenseKeyGroup); VersioningUtil - .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE); + .validateEntityExistence(retrieved, licenseKeyGroup, VendorLicenseModelEntity.ENTITY_TYPE); for (String referencingFeatureGroupId : retrieved.getReferencingFeatureGroups()) { featureGroupDao.removeLicenseKeyGroup( - new FeatureGroupEntity(licenseKeyGroup.getVendorLicenseModelId(), version, - referencingFeatureGroupId), licenseKeyGroup.getId()); + new FeatureGroupEntity(licenseKeyGroup.getVendorLicenseModelId(), version, + referencingFeatureGroupId), licenseKeyGroup.getId()); } deleteChildLimits(licenseKeyGroup.getVendorLicenseModelId(), licenseKeyGroup.getVersion(), licenseKeyGroup.getId(), user); @@ -793,51 +793,53 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { licenseKeyGroupDao.delete(licenseKeyGroup); deleteUniqueName(VendorLicenseConstants.UniqueValues.LICENSE_KEY_GROUP_NAME, - retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(), - retrieved.getName()); + retrieved.getVendorLicenseModelId(), retrieved.getVersion().toString(), + retrieved.getName()); vendorLicenseFacade.updateVlmLastModificationTime(licenseKeyGroup.getVendorLicenseModelId(), - licenseKeyGroup.getVersion()); + licenseKeyGroup.getVersion()); mdcDataDebugMessage.debugExitMessage("VLM id, LKG id", licenseKeyGroup - .getVendorLicenseModelId(), licenseKeyGroup.getId()); + .getVendorLicenseModelId(), licenseKeyGroup.getId()); } @Override public LimitEntity createLimit(LimitEntity limit, String user) { mdcDataDebugMessage - .debugEntryMessage("VLM id", limit.getVendorLicenseModelId(), "EP/LKGId", limit - .getEpLkgId()); + .debugEntryMessage("VLM id", limit.getVendorLicenseModelId(), "EP/LKGId", limit + .getEpLkgId()); mdcDataDebugMessage - .debugExitMessage("VLM id", limit.getVendorLicenseModelId(), "EP/LKGId", limit - .getEpLkgId()); + .debugExitMessage("VLM id", limit.getVendorLicenseModelId(), "EP/LKGId", limit + .getEpLkgId()); validateLimit(limit, user); - return vendorLicenseFacade.createLimit(limit, user); + LimitEntity createdLimit = vendorLicenseFacade.createLimit(limit, user); + updateParentForLimit(limit,user); + return createdLimit; } private void validateLimit(LimitEntity limit, String user) { Version version = VersioningUtil.resolveVersion(limit.getVersion(), - getVersionInfo(limit.getVendorLicenseModelId(), VersionableEntityAction.Write, - user), user); + getVersionInfo(limit.getVendorLicenseModelId(), VersionableEntityAction.Write, + user), user); Collection<LimitEntity> limitList = listLimits(limit.getVendorLicenseModelId(),version - ,limit.getEpLkgId(), user); + ,limit.getEpLkgId(), user); if (!isLimitNameUnique(limitList,limit.getName(), limit.getType(), limit.getId())) { final ErrorCode duplicateLimitNameErrorBuilder = - LimitErrorBuilder.getDuplicateNameErrorbuilder(limit.getName(), limit.getType().name()); + LimitErrorBuilder.getDuplicateNameErrorbuilder(limit.getName(), limit.getType().name()); MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerServiceName.Create_LIMIT.toString(), ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), - duplicateLimitNameErrorBuilder.message()); + LoggerServiceName.Create_LIMIT.toString(), ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), + duplicateLimitNameErrorBuilder.message()); throw new CoreException(duplicateLimitNameErrorBuilder); } } private boolean isLimitNameUnique(Collection<LimitEntity> limitList, String name, LimitType - type, String id) { + type, String id) { for (LimitEntity limit : limitList) { if(limit.getName().equalsIgnoreCase(name) && - limit.getType().name().equalsIgnoreCase(type.name())) { + limit.getType().name().equalsIgnoreCase(type.name())) { if(id != null && limit.getId().equals(id)){ continue; } @@ -865,9 +867,9 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { user), user); limitEntity.setVersion(version); - if(!isLimitPresent(limitEntity)){ + if ( !isLimitPresent(limitEntity)) { VersioningUtil - .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE); + .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE); } LimitEntity retrieved = limitDao.get(limitEntity); VersioningUtil @@ -878,6 +880,8 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { vendorLicenseFacade.updateVlmLastModificationTime(limitEntity.getVendorLicenseModelId(), limitEntity.getVersion()); + updateParentForLimit(limitEntity,user); + mdcDataDebugMessage.debugExitMessage("VLM id, EP id, Limit Id", limitEntity .getVendorLicenseModelId(), limitEntity.getEpLkgId(), limitEntity.getId()); } @@ -885,14 +889,15 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { @Override public void updateLimit(LimitEntity limit, String user) { mdcDataDebugMessage - .debugEntryMessage("VLM id", limit.getVendorLicenseModelId(), "EP/LKGId", limit - .getEpLkgId()); + .debugEntryMessage("VLM id", limit.getVendorLicenseModelId(), "EP/LKGId", limit + .getEpLkgId()); getLimit(limit,user); validateLimit(limit, user); vendorLicenseFacade.updateLimit(limit, user); + updateParentForLimit(limit,user); mdcDataDebugMessage - .debugExitMessage("VLM id", limit.getVendorLicenseModelId(), "EP/LKGId", limit - .getEpLkgId()); + .debugExitMessage("VLM id", limit.getVendorLicenseModelId(), "EP/LKGId", limit + .getEpLkgId()); } private boolean isLimitPresent(LimitEntity limit) { @@ -901,108 +906,135 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { @Override public LimitEntity getLimit(LimitEntity limitEntity, - String user) { + String user) { mdcDataDebugMessage.debugEntryMessage("VLM id", limitEntity.getVendorLicenseModelId(), - "EP/LKGId", limitEntity.getEpLkgId()); + "EP/LKGId", limitEntity.getEpLkgId()); limitEntity.setVersion(VersioningUtil.resolveVersion(limitEntity.getVersion(), - getVersionInfo(limitEntity.getVendorLicenseModelId(), VersionableEntityAction.Read, - user), user)); + getVersionInfo(limitEntity.getVendorLicenseModelId(), VersionableEntityAction.Read, + user), user)); if(!isLimitPresent(limitEntity)){ VersioningUtil - .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE); + .validateEntityExistence(null, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE); } LimitEntity retrieved = limitDao.get(limitEntity); VersioningUtil - .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE); + .validateEntityExistence(retrieved, limitEntity, VendorLicenseModelEntity.ENTITY_TYPE); mdcDataDebugMessage.debugExitMessage("VLM id", limitEntity.getVendorLicenseModelId(), - "EP/LKGId", limitEntity.getEpLkgId()); + "EP/LKGId", limitEntity.getEpLkgId()); return retrieved; } + /** + * update Parent of limit (EP/LKG) versionuuid when limit is modified so that limit updates are + * captured in VLM XML + * @param limit + * @param user + */ + private void updateParentForLimit(LimitEntity limit, String user) { + mdcDataDebugMessage.debugEntryMessage("VLM id", limit.getVendorLicenseModelId(), + "EP/LKGId", limit.getEpLkgId(), "Limit Parent ", limit.getParent()); + if ("EntitlementPool".equals(limit.getParent()) ) { + EntitlementPoolEntity entitlementPoolEntity = + entitlementPoolDao.get(new EntitlementPoolEntity(limit.getVendorLicenseModelId(), + limit.getVersion(), limit.getEpLkgId())); + vendorLicenseFacade.updateEntitlementPool(entitlementPoolEntity, user); + } + + if ("LicenseKeyGroup".equals(limit.getParent())) { + LicenseKeyGroupEntity licenseKeyGroupEntity = licenseKeyGroupDao.get( + new LicenseKeyGroupEntity(limit.getVendorLicenseModelId(), limit.getVersion(), + limit.getEpLkgId())); + vendorLicenseFacade.updateLicenseKeyGroup(licenseKeyGroupEntity, user); + } + + mdcDataDebugMessage.debugEntryMessage("VLM id", limit.getVendorLicenseModelId(), + "EP/LKGId", limit.getEpLkgId(), "Limit Parent ", limit.getParent()); + } + protected void addFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds, - LicenseAgreementEntity licenseAgreement) { + LicenseAgreementEntity licenseAgreement) { if (featureGroupIds != null) { for (String featureGroupId : featureGroupIds) { featureGroupDao.addReferencingLicenseAgreement( - new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), - licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId()); + new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), + licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId()); } } } protected void removeFeatureGroupsToLicenseAgreementRef(Set<String> featureGroupIds, - LicenseAgreementEntity licenseAgreement) { + LicenseAgreementEntity licenseAgreement) { if (featureGroupIds != null) { for (String featureGroupId : featureGroupIds) { featureGroupDao.removeReferencingLicenseAgreement( - new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), - licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId()); + new FeatureGroupEntity(licenseAgreement.getVendorLicenseModelId(), + licenseAgreement.getVersion(), featureGroupId), licenseAgreement.getId()); } } } protected void addLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds, - FeatureGroupEntity featureGroup) { + FeatureGroupEntity featureGroup) { if (licenseKeyGroupIds != null) { for (String licenseKeyGroupId : licenseKeyGroupIds) { licenseKeyGroupDao.addReferencingFeatureGroup( - new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId()); + new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId()); } } } protected void removeLicenseKeyGroupsToFeatureGroupsRef(Set<String> licenseKeyGroupIds, - FeatureGroupEntity featureGroup) { + FeatureGroupEntity featureGroup) { if (licenseKeyGroupIds != null) { for (String licenseKeyGroupId : licenseKeyGroupIds) { licenseKeyGroupDao.removeReferencingFeatureGroup( - new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId()); + new LicenseKeyGroupEntity(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion(), licenseKeyGroupId), featureGroup.getId()); } } } protected void addEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds, - FeatureGroupEntity featureGroup) { + FeatureGroupEntity featureGroup) { if (entitlementPoolIds != null) { for (String entitlementPoolId : entitlementPoolIds) { entitlementPoolDao.addReferencingFeatureGroup( - new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion(), entitlementPoolId), featureGroup.getId()); + new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion(), entitlementPoolId), featureGroup.getId()); } } } protected void removeEntitlementPoolsToFeatureGroupsRef(Set<String> entitlementPoolIds, - FeatureGroupEntity featureGroup) { + FeatureGroupEntity featureGroup) { if (entitlementPoolIds != null) { for (String entitlementPoolId : entitlementPoolIds) { entitlementPoolDao.removeReferencingFeatureGroup( - new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), - featureGroup.getVersion(), entitlementPoolId), featureGroup.getId()); + new EntitlementPoolEntity(featureGroup.getVendorLicenseModelId(), + featureGroup.getVersion(), entitlementPoolId), featureGroup.getId()); } } } protected VersionInfo getVersionInfo(String vendorLicenseModelId, VersionableEntityAction action, - String user) { + String user) { return vendorLicenseFacade.getVersionInfo(vendorLicenseModelId, action, user); } protected LicenseAgreementEntity createLicenseAgreementForList(String vlmId, Version version, String user) { return new LicenseAgreementEntity(vlmId, VersioningUtil - .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user), - null); + .resolveVersion(version, getVersionInfo(vlmId, VersionableEntityAction.Read, user), user), + null); } protected void updateUniqueName(String uniqueValueType ,String oldName, String newName,String ... - context) { + context) { UniqueValueUtil - .updateUniqueValue(uniqueValueType, oldName, newName,context); + .updateUniqueValue(uniqueValueType, oldName, newName,context); } protected void deleteUniqueName(String uniqueValueType,String ... uniqueCombination) { @@ -1011,8 +1043,8 @@ public class VendorLicenseManagerImpl implements VendorLicenseManager { protected Version resloveVersion(String vlmId,Version requestedVersion, VersionInfo versionInfo, String user){ - return VersioningUtil.resolveVersion(null, - getVersionInfo(vlmId, VersionableEntityAction.Write, user), user); + return VersioningUtil.resolveVersion(null, + getVersionInfo(vlmId, VersionableEntityAction.Write, user), user); } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/C36B4399FCB942B19D493F839CFA10E2_0_1_General_6E70545C4854465D82DBDB9BCBEF0FB5 b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/C36B4399FCB942B19D493F839CFA10E2_0_1_General_6E70545C4854465D82DBDB9BCBEF0FB5 deleted file mode 100644 index 58e6f9e5e2..0000000000 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/C36B4399FCB942B19D493F839CFA10E2_0_1_General_6E70545C4854465D82DBDB9BCBEF0FB5 +++ /dev/null @@ -1 +0,0 @@ -bla bla
\ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml index ba95d4a3e4..b3fc9aa797 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/pom.xml @@ -16,6 +16,18 @@ <dependencies> <dependency> <groupId>org.openecomp.sdc.common</groupId> + <artifactId>openecomp-configuration-management-core</artifactId> + <version>${openecomp.sdc.common.version}</version> + <scope>runtime</scope> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.openecomp.sdc.common</groupId> <artifactId>openecomp-tosca-datatype</artifactId> <version>${openecomp.sdc.common.version}</version> </dependency> @@ -185,6 +197,21 @@ <artifactId>openecomp-sdc-tosca-generator-core</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-orchesrtation-core</artifactId> + <version>1.1.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-tosca-converter-api</artifactId> + <version>1.1.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-tosca-converter-core</artifactId> + <version>1.1.0-SNAPSHOT</version> + </dependency> </dependencies> <build> <plugins> diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java index e648ccef26..e2ef86149b 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/OrchestrationTemplateCandidateManager.java @@ -20,6 +20,7 @@ package org.openecomp.sdc.vendorsoftwareproduct; +import org.apache.commons.lang3.tuple.Pair; import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; @@ -32,7 +33,7 @@ import java.util.Optional; public interface OrchestrationTemplateCandidateManager { UploadFileResponse upload(String vspId, Version version, InputStream heatFileToUpload, - String user); + String user, String filePrefix, String networkPackageName); OrchestrationTemplateActionResponse process(String vspId, Version version, String user); @@ -41,5 +42,5 @@ public interface OrchestrationTemplateCandidateManager { ValidationResponse updateFilesDataStructure(String vspId, Version version, String user, FilesDataStructure fileDataStructure); - Optional<byte[]> get(String vspId, Version version, String user) throws IOException; + Optional<Pair<String, byte[]>> get(String vspId, Version version, String user) throws IOException; } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/DeploymentFlavorErrorBuilder.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/DeploymentFlavorErrorBuilder.java index 97476a2dfd..f0a9f8f31c 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/DeploymentFlavorErrorBuilder.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/errors/DeploymentFlavorErrorBuilder.java @@ -9,24 +9,25 @@ public class DeploymentFlavorErrorBuilder { private static final String CREATE_DEPLOYMENT_FLAVOR_NOT_ALLOWED_IN_HEAT_ONBOARDING_MSG= "Deployment Flavor cannot be added for VSPs onboarded with HEAT."; private static final String FEATURE_GROUP_NOT_EXIST_FOR_VSP_MSG= - "Invalid request,Feature Group with Id %s does not exist for Vsp with Id %s and version " + - "%s."; + "Invalid request,Feature Group with Id %s does not exist for Vsp with Id %s and version " + + "%s."; private static final String INVALID_COMPONENT_COMPUTE_ASSOCIATION_MSG - ="Invalid request,for valid association please provide ComponentId for Compute Flavor"; + ="Invalid request,for valid association please provide ComponentId for Compute Flavor"; private static final String SAME_VFC_ASSOCIATION_MORE_THAN_ONCE_NOT_ALLOWED_MSG= - "Invalid Request,Same Vfc cannot be associated more than once."; + "Invalid Request,Same Vfc cannot be associated more than once."; private static final String DUPLICATE_DEPLOYMENT_FLAVOR_MODEL_NOT_ALLOWED_MSG = - "Invalid request, Deployment Flavor with model %s already exists for Vsp with Id %s."; + "Invalid request, Deployment Flavor with model %s already exists for Vsp with Id %s."; private static final String DEPLOYMENT_FLAVOUR_NAME_FORMAT_MSG = "Field does not conform to predefined criteria" + ": name : must match %s"; private static final String INVALID_COMPUTE_FLAVOR_ID_MSG = - "Invalid request, Compute Flavor with Id %s does not exist for VFC with Id %s."; + "Invalid request, Compute Flavor with Id %s does not exist for VFC with Id %s."; private static final String INVALID_COMPONENT_COMPUTE_ASSOCIATION_ERROR_MSG="VSP cannot be " + - "submitted with an invalid Deployment Flavor. All Deployment Flavor should have atleast a VFC included with it's required Compute needs. Please fix the Deployment Flavor and re-submit the VSP."; + "submitted with an invalid Deployment Flavor. All Deployment Flavor should have atleast a VFC included with it's required Compute needs. " + + "Please fix the Deployment Flavor %s and re-submit the VSP."; private static final String FEATUREGROUP_REQUIRED_IN_DEPLOYMENT_FLAVOR_MSG = "VSP cannot be " + - "submitted with an invalid Deployment Flavor. All Deployment Flavor should have " + - "FeatureGroup. Please fix the Deployment Flavor and re-submit the VSP."; + "submitted with an invalid Deployment Flavor. All Deployment Flavor should have " + + "FeatureGroup. Please fix the Deployment Flavor %s and re-submit the VSP."; public static ErrorCode getAddDeploymentNotSupportedHeatOnboardErrorBuilder(){ ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); @@ -37,12 +38,12 @@ public class DeploymentFlavorErrorBuilder { } public static ErrorCode getFeatureGroupNotexistErrorBuilder( String featureGroupId, String - VspId, Version activeVersion){ + VspId, Version activeVersion){ ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); builder.withId(VendorSoftwareProductErrorCodes.FEATURE_GROUP_NOT_EXIST_FOR_VSP); builder.withCategory(ErrorCategory.APPLICATION); builder.withMessage(String.format(FEATURE_GROUP_NOT_EXIST_FOR_VSP_MSG,featureGroupId, - VspId,activeVersion.toString())); + VspId,activeVersion.toString())); return builder.build(); } @@ -70,28 +71,28 @@ public class DeploymentFlavorErrorBuilder { return builder.build(); } public static ErrorCode getInvalidComputeIdErrorBuilder( String computeFlavorId, String - vfcId){ + vfcId){ ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); builder.withId(VendorSoftwareProductErrorCodes.INVALID_COMPUTE_FLAVOR_ID); builder.withCategory(ErrorCategory.APPLICATION); builder.withMessage(String.format(INVALID_COMPUTE_FLAVOR_ID_MSG,computeFlavorId, - vfcId)); + vfcId)); return builder.build(); } - public static ErrorCode getInvalidComponentComputeAssociationErrorBuilder(){ + public static ErrorCode getInvalidComponentComputeAssociationErrorBuilder(String model){ ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); builder.withId(VendorSoftwareProductErrorCodes.INVALID_COMPONENT_COMPUTE_ASSOCIATION); builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage(String.format(INVALID_COMPONENT_COMPUTE_ASSOCIATION_ERROR_MSG)); + builder.withMessage(String.format(INVALID_COMPONENT_COMPUTE_ASSOCIATION_ERROR_MSG, model)); return builder.build(); } - public static ErrorCode getFeatureGroupMandatoryErrorBuilder(){ + public static ErrorCode getFeatureGroupMandatoryErrorBuilder(String model){ ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder(); builder.withId(VendorSoftwareProductErrorCodes.FEATUREGROUP_REQUIRED_IN_DEPLOYMENT_FLAVOR); builder.withCategory(ErrorCategory.APPLICATION); - builder.withMessage(String.format(FEATUREGROUP_REQUIRED_IN_DEPLOYMENT_FLAVOR_MSG)); + builder.withMessage(String.format(FEATUREGROUP_REQUIRED_IN_DEPLOYMENT_FLAVOR_MSG, model)); return builder.build(); } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java index b54570f13c..9daec08d49 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImpl.java @@ -12,7 +12,6 @@ import org.openecomp.sdc.logging.types.LoggerConstants; import org.openecomp.sdc.logging.types.LoggerErrorCode; import org.openecomp.sdc.logging.types.LoggerTragetServiceName; import org.openecomp.sdc.vendorsoftwareproduct.ImageManager; -import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; import org.openecomp.sdc.vendorsoftwareproduct.dao.ImageDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; @@ -45,9 +44,9 @@ public class ImageManagerImpl implements ImageManager { private CompositionEntityDataManager compositionEntityDataManager; public ImageManagerImpl( - VendorSoftwareProductInfoDao vspInfoDao, - ImageDao imageDao, - CompositionEntityDataManager compositionEntityDataManager + VendorSoftwareProductInfoDao vspInfoDao, + ImageDao imageDao, + CompositionEntityDataManager compositionEntityDataManager ) { @@ -67,18 +66,17 @@ public class ImageManagerImpl implements ImageManager { if (!isManual) { ErrorCode errorCode = NotSupportedHeatOnboardMethodErrorBuilder - .getAddImageNotSupportedHeatOnboardMethodErrorBuilder(); + .getAddImageNotSupportedHeatOnboardMethodErrorBuilder(); MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.CREATE_IMAGE, ErrorLevel.ERROR.name(), - errorCode.id(), errorCode.message()); + LoggerTragetServiceName.CREATE_IMAGE, ErrorLevel.ERROR.name(), + errorCode.id(), errorCode.message()); throw new CoreException(errorCode); } - Collection<ImageEntity> vfcImageList = listImages(imageEntity.getVspId() , - imageEntity.getVersion(), imageEntity.getComponentId()); - validateVfcImage(isManual, imageEntity, vfcImageList, LoggerTragetServiceName.CREATE_IMAGE); + /*Collection<ImageEntity> vfcImageList = listImages(imageEntity.getVspId() , + imageEntity.getVersion(), imageEntity.getComponentId());*/ compositionEntityDataManager.createImage(imageEntity); return imageEntity; } @@ -115,10 +113,10 @@ public class ImageManagerImpl implements ImageManager { @Override public CompositionEntityResponse<Image> getImage(String vspId, Version version, String - componentId, String imageId, String user) { + componentId, String imageId, String user) { mdcDataDebugMessage.debugEntryMessage("VSP id, componentId, image id", vspId, componentId, - imageId); + imageId); /*version = VersioningUtil .resolveVersion(version, getVersionInfo(vspId, VersionableEntityAction.Read, user));*/ @@ -139,14 +137,14 @@ public class ImageManagerImpl implements ImageManager { response.setSchema(getImageCompositionSchema(schemaInput)); mdcDataDebugMessage.debugExitMessage("VSP id, componentId, image id", vspId, componentId, - imageId); + imageId); return response; } @Override public QuestionnaireResponse getImageQuestionnaire(String vspId, Version version, String - componentId, String imageId, String user) { + componentId, String imageId, String user) { mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); /*version = VersioningUtil @@ -168,9 +166,9 @@ public class ImageManagerImpl implements ImageManager { @Override public void deleteImage(String vspId, Version version, String componentId, String imageId, String - user) { + user) { mdcDataDebugMessage - .debugEntryMessage("VSP id, component id", vspId, componentId, imageId); + .debugEntryMessage("VSP id, component id", vspId, componentId, imageId); /*Version activeVersion = getVersionInfo(vspId, VersionableEntityAction.Write, user).getActiveVersion(); @@ -178,19 +176,19 @@ public class ImageManagerImpl implements ImageManager { ImageEntity imageEntity = getImageEntity(vspId, version, componentId, imageId); if (!vspInfoDao.isManual(vspId, version)) { final ErrorCode deleteImageErrorBuilder = - NotSupportedHeatOnboardMethodErrorBuilder - .getDelImageNotSupportedHeatOnboardMethodErrorBuilder(); + NotSupportedHeatOnboardMethodErrorBuilder + .getDelImageNotSupportedHeatOnboardMethodErrorBuilder(); MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.DELETE_IMAGE, ErrorLevel.ERROR.name(), - LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), - deleteImageErrorBuilder.message()); + LoggerTragetServiceName.DELETE_IMAGE, ErrorLevel.ERROR.name(), + LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), + deleteImageErrorBuilder.message()); throw new CoreException(deleteImageErrorBuilder); } if (imageEntity != null) { imageDao.delete(new ImageEntity(vspId, version, componentId, imageId)); } mdcDataDebugMessage - .debugExitMessage("VSP id, component id", vspId, componentId, imageId); + .debugExitMessage("VSP id, component id", vspId, componentId, imageId); } private void validateHeatVspImageUpdate(String name, String value, String retrivedValue) { @@ -198,12 +196,12 @@ public class ImageManagerImpl implements ImageManager { if(value != null && !value.equals(retrivedValue)) { final ErrorCode updateHeatImageErrorBuilder = - ImageErrorBuilder.getImageHeatReadOnlyErrorBuilder(name); + ImageErrorBuilder.getImageHeatReadOnlyErrorBuilder(name); MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.UPDATE_IMAGE, ErrorLevel.ERROR.name(), - LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), - updateHeatImageErrorBuilder.message()); + LoggerTragetServiceName.UPDATE_IMAGE, ErrorLevel.ERROR.name(), + LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), + updateHeatImageErrorBuilder.message()); throw new CoreException(updateHeatImageErrorBuilder); } } @@ -211,33 +209,32 @@ public class ImageManagerImpl implements ImageManager { @Override public CompositionEntityValidationData updateImage(ImageEntity image, String user) { mdcDataDebugMessage - .debugEntryMessage("VSP id, component id", image.getVspId(), image.getComponentId(), - image.getId()); + .debugEntryMessage("VSP id, component id", image.getVspId(), image.getComponentId(), + image.getId()); /*Version activeVersion = getVersionInfo(image.getVspId(), VersionableEntityAction.Write, user).getActiveVersion(); image.setVersion(activeVersion);*/ boolean isManual = vspInfoDao.isManual(image.getVspId(), image.getVersion()); ImageEntity retrieved = getImageEntity(image.getVspId(), image.getVersion(), image.getComponentId(), - image.getId()); + image.getId()); if(!isManual) { final Image imageCompositionData = image.getImageCompositionData(); final String fileName = imageCompositionData.getFileName(); //final String format = imageCompositionData.getFormat(); validateHeatVspImageUpdate("fileName", fileName, retrieved.getImageCompositionData() - .getFileName()); + .getFileName()); /*validateHeatVspImageUpdate("format", format, retrieved.getImageCompositionData() .getFormat());*/ } Collection<ImageEntity> vfcImageList = listImages(image.getVspId() , - image.getVersion(), image.getComponentId()); + image.getVersion(), image.getComponentId()); //Set to null so that retrieved object is equal to one in list and gets removed. retrieved.setQuestionnaireData(null); vfcImageList.remove(retrieved); - validateVfcImage(isManual, image, vfcImageList, LoggerTragetServiceName.UPDATE_IMAGE); //Set format to default value in order to handle FTL validation when image format is null /*if(image.getImageCompositionData().getFormat() == null) @@ -247,23 +244,23 @@ public class ImageManagerImpl implements ImageManager { schemaInput.setImage(image.getImageCompositionData()); CompositionEntityValidationData validationData = compositionEntityDataManager - .validateEntity(image, SchemaTemplateContext.composition, schemaInput); + .validateEntity(image, SchemaTemplateContext.composition, schemaInput); if (CollectionUtils.isEmpty(validationData.getErrors())) { imageDao.update(image); } mdcDataDebugMessage - .debugExitMessage("VSP id, component id", image.getVspId(), image.getComponentId(), - image.getId()); + .debugExitMessage("VSP id, component id", image.getVspId(), image.getComponentId(), + image.getId()); return validationData; } @Override public void updateImageQuestionnaire(String vspId, Version version, String componentId, String - imageId, String questionnaireData, String user) { + imageId, String questionnaireData, String user) { mdcDataDebugMessage.debugEntryMessage("VSP id, component id, imageId", vspId, componentId, - imageId); + imageId); getImageEntity(vspId, version, componentId, imageId); @@ -281,15 +278,15 @@ public class ImageManagerImpl implements ImageManager { } catch (IllegalArgumentException exception) { ErrorCode errorCode = ImageErrorBuilder.getInvalidImageFormatErrorBuilder(); MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.UPDATE_IMAGE, ErrorLevel.ERROR.name(), - errorCode.id(), errorCode.message() ); + LoggerTragetServiceName.UPDATE_IMAGE, ErrorLevel.ERROR.name(), + errorCode.id(), errorCode.message() ); throw new CoreException(errorCode); } //Validate Format is read only for HEAT Onboarding if (!vspInfoDao.isManual(vspId, version)) { final QuestionnaireResponse imageQuestionnaire = getImageQuestionnaire(vspId, version, - componentId, imageId, user); + componentId, imageId, user); final String data = imageQuestionnaire.getData(); if (data != null) { String retrivedFormat = JsonUtil.json2Object(data, ImageDetails.class).getFormat(); @@ -299,19 +296,19 @@ public class ImageManagerImpl implements ImageManager { if(!isImageVersionUnique(vspId, version, componentId, imageId, image, user)) { - ErrorCode errorCode = ImageErrorBuilder.getDuplicateImageVersionErrorBuilder(image - .getVersion(), componentId); + ErrorCode errorCode = ImageErrorBuilder.getDuplicateImageVersionErrorBuilder(image + .getVersion(), componentId); - MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.UPDATE_IMAGE, ErrorLevel.ERROR.name(), - errorCode.id(),errorCode.message()); + MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, + LoggerTragetServiceName.UPDATE_IMAGE, ErrorLevel.ERROR.name(), + errorCode.id(),errorCode.message()); - throw new CoreException(errorCode); + throw new CoreException(errorCode); } imageDao.updateQuestionnaireData(vspId, version, componentId, imageId, questionnaireData); mdcDataDebugMessage.debugExitMessage("VSP id, component id, imageId", vspId, componentId, - imageId); + imageId); } private boolean isImageVersionUnique(String vspId, Version version, String componentId, String imageId, @@ -320,15 +317,15 @@ public class ImageManagerImpl implements ImageManager { boolean isPresent = true; if(image!=null && image.getVersion()!=null) { - Collection<ImageEntity> imageEntities = imageDao.list(new ImageEntity(vspId, version, componentId, null)); - if(CollectionUtils.isNotEmpty(imageEntities)) - { - imageEntities = imageEntities.stream().filter(imageEntity -> image.getVersion().trim().equalsIgnoreCase( - getImageVersion(vspId, version, componentId, imageEntity, user)) - && !imageEntity.getId().equals(imageId)).collect(Collectors.toList()); - - isPresent = CollectionUtils.isEmpty(imageEntities); - } + Collection<ImageEntity> imageEntities = imageDao.list(new ImageEntity(vspId, version, componentId, null)); + if(CollectionUtils.isNotEmpty(imageEntities)) + { + imageEntities = imageEntities.stream().filter(imageEntity -> image.getVersion().trim().equalsIgnoreCase( + getImageVersion(vspId, version, componentId, imageEntity, user)) + && !imageEntity.getId().equals(imageId)).collect(Collectors.toList()); + + isPresent = CollectionUtils.isEmpty(imageEntities); + } } return isPresent; @@ -336,11 +333,11 @@ public class ImageManagerImpl implements ImageManager { private String getImageVersion(String vspId, Version version, String componentId, ImageEntity imageEntity, String user) { - QuestionnaireResponse imageQuestionnaire = getImageQuestionnaire(vspId, version, - componentId, imageEntity.getId(), user); - ImageDetails imageDetails = JsonUtil.json2Object(imageQuestionnaire.getData(), ImageDetails.class); + QuestionnaireResponse imageQuestionnaire = getImageQuestionnaire(vspId, version, + componentId, imageEntity.getId(), user); + ImageDetails imageDetails = JsonUtil.json2Object(imageQuestionnaire.getData(), ImageDetails.class); - return imageDetails==null?null:imageDetails.getVersion()!=null?imageDetails.getVersion().trim():null; + return imageDetails==null?null:imageDetails.getVersion()!=null?imageDetails.getVersion().trim():null; } private ImageEntity getImageEntity(String vspId, Version version, String componentId, String imageId) { @@ -349,7 +346,7 @@ public class ImageManagerImpl implements ImageManager { ImageEntity imageEntity = imageDao.get(new ImageEntity(vspId, version, componentId, imageId)); VersioningUtil.validateEntityExistence(imageEntity, new ImageEntity(vspId, version, componentId, - imageId), VspDetails.ENTITY_TYPE); + imageId), VspDetails.ENTITY_TYPE); return imageEntity; } @@ -363,26 +360,12 @@ public class ImageManagerImpl implements ImageManager { return false; } - private void validateVfcImage(boolean isManual, ImageEntity image, - Collection<ImageEntity> vfcImageList, String event) { - if (isImageNameDuplicate(vfcImageList,image.getImageCompositionData().getFileName())) { - ErrorCode errorCode = ImageErrorBuilder.getDuplicateImageNameErrorBuilder(image - .getImageCompositionData().getFileName(), image.getComponentId()); - - MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - event, ErrorLevel.ERROR.name(), - errorCode.id(),errorCode.message()); - - throw new CoreException(errorCode); - } - } - protected String getImageCompositionSchema(SchemaTemplateInput schemaInput) { mdcDataDebugMessage.debugEntryMessage(null, null); mdcDataDebugMessage.debugExitMessage(null, null); return SchemaGenerator - .generate(SchemaTemplateContext.composition, CompositionEntityType.image, - schemaInput); + .generate(SchemaTemplateContext.composition, CompositionEntityType.image, + schemaInput); } protected String getImageQuestionnaireSchema(SchemaTemplateInput schemaInput) { @@ -390,7 +373,7 @@ public class ImageManagerImpl implements ImageManager { mdcDataDebugMessage.debugExitMessage(null, null); return SchemaGenerator - .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.image, - schemaInput); + .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.image, + schemaInput); } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java index 73558b465a..fcf54eef2f 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/MonitoringUploadsManagerImpl.java @@ -25,6 +25,7 @@ import org.openecomp.core.enrichment.types.MonitoringUploadType; import org.openecomp.core.utilities.CommonMethods; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.activityLog.ActivityLogManager; import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.common.errors.CoreException; @@ -44,6 +45,7 @@ import org.openecomp.sdc.logging.types.LoggerTragetServiceName; import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager; import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.MonitoringUploadErrorBuilder; @@ -67,6 +69,7 @@ public class MonitoringUploadsManagerImpl implements MonitoringUploadsManager { private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); private ActivityLogManager activityLogManager; private ComponentArtifactDao componentArtifactDao; + private VendorSoftwareProductDao vendorSoftwareProductDao; private static final Logger logger = LoggerFactory.getLogger(VendorSoftwareProductManagerImpl.class); @@ -253,7 +256,7 @@ public class MonitoringUploadsManagerImpl implements MonitoringUploadsManager { Map<String, List<ErrorMessage>> errors) { FileContentHandler contentMap; try { - contentMap = CommonUtil.validateAndUploadFileContent(uploadedFileData); + contentMap = CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.ZIP, uploadedFileData); VendorSoftwareProductUtils.validateContentZipData(contentMap, errors); } catch (IOException exception) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java index 07e84803aa..3f6ffcc622 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImpl.java @@ -21,29 +21,20 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; -import org.openecomp.core.translator.datatypes.TranslatorOutput; -import org.openecomp.core.util.UniqueValueUtil; -import org.openecomp.core.utilities.file.FileContentHandler; -import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.core.validation.util.MessageContainerUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.activityLog.ActivityLogManager; -import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.Messages; -import org.openecomp.sdc.common.utils.CommonUtil; import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.healing.types.HealCode; -import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; -import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; -import org.openecomp.sdc.heat.services.tree.HeatTreeManager; -import org.openecomp.sdc.heat.services.tree.HeatTreeManagerUtil; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.logging.api.annotations.Metrics; @@ -52,8 +43,6 @@ import org.openecomp.sdc.logging.messages.AuditMessages; import org.openecomp.sdc.logging.types.LoggerServiceName; import org.openecomp.sdc.logging.types.LoggerTragetServiceName; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; -import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil; -import org.openecomp.sdc.validation.util.ValidationManagerUtil; import org.openecomp.sdc.vendorsoftwareproduct.OrchestrationTemplateCandidateManager; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; @@ -62,40 +51,29 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadData; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.errors.OrchestrationTemplateNotFoundErrorBuilder; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationTemplateFileHandler; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUploadFactory; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationProcessFactory; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationTemplateProcessHandler; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; -import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder; import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; -import org.openecomp.sdc.vendorsoftwareproduct.utils.VendorSoftwareProductUtils; import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdcrests.activitylog.types.ActivityType; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.ByteBuffer; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; -import static org.openecomp.sdc.logging.messages.AuditMessages.HEAT_VALIDATION_ERROR; -import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.GENERAL_COMPONENT_ID; -import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME; - public class OrchestrationTemplateCandidateManagerImpl implements OrchestrationTemplateCandidateManager { private static final Logger logger = @@ -162,65 +140,31 @@ public class OrchestrationTemplateCandidateManagerImpl @Override @Metrics - public UploadFileResponse upload(String vspId, Version version, InputStream heatFileToUpload, - String user) { + public UploadFileResponse upload(String vspId, Version version, InputStream fileToUpload, + String user, String filePrefix, + String networkPackageName) { mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); - + OrchestrationTemplateFileHandler orchestrationTemplateFileHandler = + OrchestrationUploadFactory.createOrchestrationTemplateFileHandler(filePrefix); VspDetails vspDetails = getVspDetails(vspId, version); + UploadFileResponse uploadResponse = orchestrationTemplateFileHandler + .upload(vspId, version, fileToUpload, user, candidateService, + vspDetails); + vspDetails.setOnboardingOrigin(filePrefix); + vspDetails.setNetworkPackageName(networkPackageName); + vspInfoDao.update(vspDetails); + + uploadResponse.setNetworkPackageName(networkPackageName); + return uploadResponse; + } - UploadFileResponse uploadFileResponse = new UploadFileResponse(); - if (isNotEmptyFileToUpload(heatFileToUpload, uploadFileResponse)) { - return uploadFileResponse; - } - - byte[] uploadedFileData = FileUtils.toByteArray(heatFileToUpload); - if (isInvalidRawZipData(uploadFileResponse, uploadedFileData)) { - return uploadFileResponse; - } - - Optional<FileContentHandler> optionalContentMap = - getZipContentMap(uploadFileResponse, uploadedFileData); - if (!optionalContentMap.isPresent()) { - logger.error(Messages.ZIP_CONTENT_MAP.getErrorMessage()); - uploadFileResponse - .addStructureError( - SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, Messages.ZIP_CONTENT_MAP.getErrorMessage())); - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return uploadFileResponse; - } - - if (!MapUtils.isEmpty(uploadFileResponse.getErrors())) { - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return uploadFileResponse; - } - try { - OrchestrationTemplateCandidateData candidateData = - new CandidateEntityBuilder(candidateService) - .buildCandidateEntityFromZip(vspDetails, uploadedFileData, optionalContentMap.get(), - uploadFileResponse.getErrors(), user); - candidateService.updateCandidateUploadData(candidateData, vspDetails.getId()); - } catch (Exception exception) { - logger.error(Messages.ZIP_CONTENT_MAP.getErrorMessage()); - uploadFileResponse - .addStructureError( - SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return uploadFileResponse; - } - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return uploadFileResponse; - } @Override public OrchestrationTemplateActionResponse process(String vspId, Version version, String user) { mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); + OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); Optional<OrchestrationTemplateCandidateData> candidate = fetchCandidateDataEntity(vspId, version); @@ -228,97 +172,15 @@ public class OrchestrationTemplateCandidateManagerImpl throw new CoreException(new OrchestrationTemplateNotFoundErrorBuilder(vspId).build()); } - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_VALIDATION_STARTED + vspId); - OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); - UploadFileResponse uploadFileResponse = new UploadFileResponse(); - OrchestrationTemplateCandidateData candidateDataEntity = candidate.get(); - Optional<FileContentHandler> fileContent = - getZipContentMap(uploadFileResponse, candidateDataEntity.getContentData().array()); - if (!fileContent.isPresent()) { - response.addStructureErrors(uploadFileResponse.getErrors()); - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, - HEAT_VALIDATION_ERROR)); - return response; - } - - Map<String, List<ErrorMessage>> uploadErrors = uploadFileResponse.getErrors(); - FileContentHandler fileContentMap = fileContent.get(); - FilesDataStructure structure = - JsonUtil.json2Object(candidateDataEntity.getFilesDataStructure(), FilesDataStructure.class); - - if (CollectionUtils.isNotEmpty(structure.getUnassigned())) { - response.addErrorMessageToMap(SdcCommon.UPLOAD_FILE, - Messages.FOUND_UNASSIGNED_FILES.getErrorMessage(), ErrorLevel.ERROR); - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, - HEAT_VALIDATION_ERROR)); - return response; - } - VspDetails vspDetails = getVspDetails(vspId, version); + Optional<OrchestrationTemplateProcessHandler> processInstance = + OrchestrationProcessFactory.getInstance(vspDetails.getOnboardingOrigin()); - String manifest = candidateService.createManifest(vspDetails, structure); - fileContentMap.addFile(SdcCommon.MANIFEST_NAME, manifest.getBytes()); - - Optional<ByteArrayInputStream> zipByteArrayInputStream = candidateService - .fetchZipFileByteArrayInputStream(vspId, candidateDataEntity, manifest, uploadErrors); - if (!zipByteArrayInputStream.isPresent()) { - response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, - HEAT_VALIDATION_ERROR)); - return response; - } - - HeatStructureTree tree = createAndValidateHeatTree(response, fileContentMap); - - Map<String, String> componentsQuestionnaire = new HashMap<>(); - Map<String, Map<String, String>> componentNicsQuestionnaire = new HashMap<>(); - Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList = new HashMap<>(); - Map<String, Collection<ProcessEntity>> processes = new HashMap<>(); - Map<String, ProcessEntity> processArtifact = new HashMap<>(); - - backupComponentsQuestionnaireBeforeDelete(vspId, version, componentsQuestionnaire, - componentNicsQuestionnaire, componentMibList, processes, processArtifact); - - deleteUploadDataAndContent(vspId, version); - saveHotData(vspId, version, zipByteArrayInputStream.get(), fileContentMap, tree); - - response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, - HEAT_VALIDATION_ERROR)); - if ( MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, response.getErrors - ()))) { - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_VALIDATION_COMPLETED + vspId); + if(processInstance.isPresent()){ + response = processInstance.get().process(vspDetails, candidate.get(), user); } - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_STARTED + vspId); - - TranslatorOutput translatorOutput = - HeatToToscaUtil.loadAndTranslateTemplateData(fileContentMap); - - ToscaServiceModel toscaServiceModel = translatorOutput.getToscaServiceModel(); - if (toscaServiceModel != null) { - serviceModelDao.storeServiceModel(vspId, version, toscaServiceModel); - //Extracting the compostion data from the output service model of the first phase of - // translation - compositionEntityDataManager.saveCompositionData(vspId, version, - compositionDataExtractor.extractServiceCompositionData(translatorOutput - .getNonUnifiedToscaServiceModel())); - retainComponentQuestionnaireData(vspId, version, componentsQuestionnaire, - componentNicsQuestionnaire, componentMibList, processes, processArtifact); - - logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_COMPLETED + vspId); - } - - uploadFileResponse.addStructureErrors(uploadErrors); - - ActivityLogEntity activityLogEntity = - new ActivityLogEntity(vspId, String.valueOf(version.getMajor() + 1), - ActivityType.UPLOAD_HEAT.toString(), user, true, "", ""); - activityLogManager.addActionLog(activityLogEntity, user); - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); return response; } @@ -374,7 +236,7 @@ public class OrchestrationTemplateCandidateManagerImpl @Override - public Optional<byte[]> get(String vspId, Version version, String user) + public Optional<Pair<String, byte[]>> get(String vspId, Version version, String user) throws IOException { mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); @@ -393,15 +255,25 @@ public class OrchestrationTemplateCandidateManagerImpl .debugExitMessage("VSP id", vspId); return Optional.empty(); } + OnboardingTypesEnum type = + OnboardingTypesEnum.getOnboardingTypesEnum(vspDetails.getOnboardingOrigin()); - FilesDataStructure structure = JsonUtil - .json2Object(candidateDataEntity.get().getFilesDataStructure(), FilesDataStructure.class); - String manifest = candidateService.createManifest(vspDetails, structure); + if(vspDetails.getOnboardingOrigin().equals(OnboardingTypesEnum.ZIP.toString())) { + FilesDataStructure structure = JsonUtil + .json2Object(candidateDataEntity.get().getFilesDataStructure(), FilesDataStructure.class); + String manifest = candidateService.createManifest(vspDetails, structure); - mdcDataDebugMessage - .debugExitMessage("VSP id", vspId); - return Optional.ofNullable(candidateService - .replaceManifestInZip(candidateDataEntity.get().getContentData(), manifest, vspId)); + mdcDataDebugMessage + .debugExitMessage("VSP id", vspId); + return Optional.ofNullable( + new ImmutablePair<>(OnboardingTypesEnum.ZIP.toString(),candidateService + .replaceManifestInZip(candidateDataEntity.get().getContentData(), + manifest, vspId, type))); + } + + return Optional.ofNullable( + new ImmutablePair<>(vspDetails.getOnboardingOrigin(),candidateDataEntity.get() + .getContentData().array())); } private Optional<OrchestrationTemplateCandidateData> fetchCandidateDataEntity( @@ -410,213 +282,6 @@ public class OrchestrationTemplateCandidateManagerImpl .ofNullable(candidateService.getOrchestrationTemplateCandidate(vspId, version)); } - private void retainComponentQuestionnaireData(String vspId, Version activeVersion, - Map<String, String> componentsQustanniare, - Map<String, Map<String, String>> - componentNicsQustanniare, - Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList, - Map<String, Collection<ProcessEntity>> processes, - Map<String, ProcessEntity> processArtifact) { - //VSP processes - restoreProcess(vspId, activeVersion, GENERAL_COMPONENT_ID, GENERAL_COMPONENT_ID, processes, - processArtifact); - Collection<ComponentEntity> - components = vendorSoftwareProductDao.listComponents(vspId, activeVersion); - components.forEach(componentEntity -> { - String componentName = componentEntity.getComponentCompositionData().getName(); - if (componentsQustanniare.containsKey(componentName)) { - componentDao.updateQuestionnaireData(vspId, activeVersion, - componentEntity.getId(), - componentsQustanniare.get(componentEntity.getComponentCompositionData() - .getName())); - if (componentNicsQustanniare.containsKey(componentName)) { - Map<String, String> nicsQustanniare = componentNicsQustanniare.get(componentName); - Collection<NicEntity> - nics = - nicDao.list(new NicEntity(vspId, activeVersion, componentEntity.getId(), null)); - nics.forEach(nicEntity -> { - if (nicsQustanniare.containsKey(nicEntity.getNicCompositionData().getName())) { - nicDao.updateQuestionnaireData(vspId, activeVersion, - componentEntity.getId(), nicEntity.getId(), - nicsQustanniare.get(nicEntity.getNicCompositionData().getName())); - } - }); - } - //MIB //todo add for VES_EVENTS - if (componentMibList.containsKey(componentName)) { - Collection<ComponentMonitoringUploadEntity> mibList = - componentMibList.get(componentName); - mibList.forEach(mib -> { - mib.setComponentId(componentEntity.getId()); - componentArtifactDao.create(mib); - }); - } - //VFC processes - restoreProcess(vspId, activeVersion, componentEntity.getId(), componentName, processes, - processArtifact); - } - }); - } - - private void backupComponentsQuestionnaireBeforeDelete(String vspId, Version activeVersion, - Map<String, String> componentsQustanniare, - Map<String, Map<String, String>> - componentNicsQustanniare, - Map<String, Collection<ComponentMonitoringUploadEntity>> - componentMibList, - Map<String, Collection<ProcessEntity>> - componentProcesses, - Map<String, ProcessEntity> processArtifact) { - //backup VSP processes - backupProcess(vspId, activeVersion, GENERAL_COMPONENT_ID, GENERAL_COMPONENT_ID, - componentProcesses, processArtifact); - Collection<ComponentEntity> componentsCompositionAndQuestionnaire = vendorSoftwareProductDao - .listComponentsCompositionAndQuestionnaire(vspId, - activeVersion); - componentsCompositionAndQuestionnaire.forEach(componentEntity -> { - String componentName = componentEntity.getComponentCompositionData().getName(); - componentsQustanniare.put(componentName, componentEntity - .getQuestionnaireData()); - Collection<NicEntity> - nics = nicDao.list(new NicEntity(vspId, activeVersion, componentEntity.getId(), null)); - //backup mib - Collection<ComponentMonitoringUploadEntity> componentMib = - componentArtifactDao.listArtifacts(new - ComponentMonitoringUploadEntity(vspId, activeVersion, componentEntity.getId(), - null)); - if (CollectionUtils.isNotEmpty(componentMib)) { - componentMibList.put(componentName,componentMib); - } - - //backup component processes - backupProcess(vspId, activeVersion, componentEntity.getId(), componentName, - componentProcesses, processArtifact); - if (CollectionUtils.isNotEmpty(nics)) { - Map<String, String> nicsQustanniare = new HashMap<>(); - nics.forEach(nicEntity -> { - NicEntity nic = nicDao.get(new NicEntity(vspId, activeVersion, componentEntity.getId(), - nicEntity.getId())); - NicEntity nicQuestionnaire = nicDao.getQuestionnaireData(vspId, activeVersion, - componentEntity.getId(), nicEntity.getId()); - - nicsQustanniare - .put(nicEntity.getNicCompositionData().getName(), - nicQuestionnaire.getQuestionnaireData()); - }); - componentNicsQustanniare.put(componentName, nicsQustanniare); - } - }); - } - - private void backupProcess(String vspId, Version activeVersion, String componentId, - String componentName, Map<String, - Collection<ProcessEntity>> processes, - Map<String, ProcessEntity> processArtifact) { - Collection<ProcessEntity> processList = vendorSoftwareProductDao.listProcesses(vspId, - activeVersion, componentId); - if (!processList.isEmpty()) { - processes.put(componentName, processList); - processList.forEach(process -> { - //ProcessArtifactEntity artifact = vendorSoftwareProductDao.getProcessArtifact(vspId, - // activeVersion, componentId, process.getId()); - ProcessEntity artifact = - processDao.get(new ProcessEntity(vspId, activeVersion, componentId, process.getId())); - if (artifact.getArtifact() != null) { - processArtifact.put(process.getId(), artifact); - } - }); - } - } - - private void restoreProcess(String vspId, Version activeVersion, String componentId, - String componentName, - Map<String, Collection<ProcessEntity>> processes, - Map<String, ProcessEntity> processArtifact) { - if (processes.containsKey(componentName)) { - Collection<ProcessEntity> processList = processes.get(componentName); - processList.forEach(process -> { - //Reatin VFC process - if (!GENERAL_COMPONENT_ID.equals(componentId) && processArtifact.containsKey(process.getId - ())) { - ProcessEntity artifact = processArtifact.get(process.getId()); - artifact.setComponentId(componentId); - UniqueValueUtil.createUniqueValue(PROCESS_NAME, vspId, activeVersion.toString(), - componentId, process.getName()); - vendorSoftwareProductDao.createProcess(artifact); - } - }); - } - } - - private HeatStructureTree createAndValidateHeatTree(OrchestrationTemplateActionResponse response, - FileContentHandler fileContentMap) { - VendorSoftwareProductUtils.addFileNamesToUploadFileResponse(fileContentMap, response); - Map<String, List<ErrorMessage>> validationErrors = - ValidationManagerUtil.initValidationManager(fileContentMap).validate(); - response.getErrors().putAll(validationErrors); - - HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileContentMap); - heatTreeManager.createTree(); - heatTreeManager.addErrors(validationErrors); - return heatTreeManager.getTree(); - } - - private void saveHotData(String vspId, Version activeVersion, InputStream uploadedFileData, - FileContentHandler fileContentMap, HeatStructureTree tree) { - Map<String, Object> manifestAsMap = - (Map<String, Object>) JsonUtil.json2Object(fileContentMap.getFileContent( - SdcCommon.MANIFEST_NAME), Map.class); - - UploadData uploadData = new UploadData(); - uploadData.setPackageName((String) manifestAsMap.get("name")); - uploadData.setPackageVersion((String) manifestAsMap.get("version")); - uploadData.setContentData(ByteBuffer.wrap(FileUtils.toByteArray(uploadedFileData))); - uploadData.setValidationDataStructure(new ValidationStructureList(tree)); - orchestrationTemplateDataDao.updateOrchestrationTemplateData(vspId, uploadData); - } - - private void deleteUploadDataAndContent(String vspId, Version version) { - //fixme change this when more tables are zusammenized - vendorSoftwareProductDao.deleteUploadData(vspId, version); - } - - private boolean isInvalidRawZipData(UploadFileResponse uploadFileResponse, - byte[] uploadedFileData) { - Optional<ErrorMessage> errorMessage; - errorMessage = candidateService.validateRawZipData(uploadedFileData); - if (errorMessage.isPresent()) { - uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); - return true; - } - return false; - } - - private boolean isNotEmptyFileToUpload(InputStream heatFileToUpload, - UploadFileResponse uploadFileResponse) { - Optional<ErrorMessage> errorMessage = - candidateService.validateNonEmptyFileToUpload(heatFileToUpload); - if (errorMessage.isPresent()) { - uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); - return true; - } - return false; - } - - private Optional<FileContentHandler> getZipContentMap(UploadFileResponse uploadFileResponse, - byte[] uploadedFileData) { - FileContentHandler contentMap = null; - try { - contentMap = CommonUtil.validateAndUploadFileContent(uploadedFileData); - } catch (IOException exception) { - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage())); - } catch (CoreException coreException) { - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); - } - return Optional.ofNullable(contentMap); - } // todo *************************** move to reusable place! ************************* @@ -646,4 +311,4 @@ public class OrchestrationTemplateCandidateManagerImpl }); } - } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java index de33ce8cfb..78c4cbf5d9 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImpl.java @@ -22,6 +22,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.impl; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.converter.datatypes.Constants; import org.openecomp.core.enrichment.api.EnrichmentManager; import org.openecomp.core.enrichment.factory.EnrichmentManagerFactory; import org.openecomp.core.model.dao.EnrichedServiceModelDao; @@ -31,6 +32,7 @@ import org.openecomp.core.util.UniqueValueUtil; import org.openecomp.core.utilities.file.FileContentHandler; import org.openecomp.core.utilities.json.JsonSchemaDataGenerator; import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.core.validation.api.ValidationManager; import org.openecomp.core.validation.util.MessageContainerUtil; import org.openecomp.sdc.activityLog.ActivityLogManager; @@ -94,8 +96,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataMana import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; import org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator.SchemaGenerator; -import org.openecomp.sdc.vendorsoftwareproduct.types.ComponentValidationResult; -import org.openecomp.sdc.vendorsoftwareproduct.types.DeploymentFlavorValidationResult; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireValidationResult; import org.openecomp.sdc.vendorsoftwareproduct.types.ValidationResponse; @@ -130,7 +130,6 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -148,7 +147,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); private static final Logger logger = - LoggerFactory.getLogger(VendorSoftwareProductManagerImpl.class); + LoggerFactory.getLogger(VendorSoftwareProductManagerImpl.class); private OrchestrationTemplateDao orchestrationTemplateDao; private VendorSoftwareProductInfoDao vspInfoDao; @@ -178,7 +177,6 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa * @param enrichedServiceModelDao the enriched service model dao * @param healingManager the healing manager * @param licenseArtifactsService the license artifacts service - * @param compositionEntityDataManager the composition entity data manager * @param informationArtifactGenerator the information artifact generator * @param packageInfoDao the package info dao * @param activityLogManager the activity log manager @@ -186,21 +184,21 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa * @param nicDao the nic dao */ public VendorSoftwareProductManagerImpl( - VersioningManager versioningManager, - VendorSoftwareProductDao vendorSoftwareProductDao, - OrchestrationTemplateDao orchestrationTemplateDataDao, - VendorSoftwareProductInfoDao vspInfoDao, - VendorLicenseFacade vendorLicenseFacade, - ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao, - EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao, - HealingManager healingManager, - VendorLicenseArtifactsService licenseArtifactsService, - InformationArtifactGenerator informationArtifactGenerator, - PackageInfoDao packageInfoDao, - ActivityLogManager activityLogManager, - DeploymentFlavorDao deploymentFlavorDao, - NicDao nicDao, - ManualVspToscaManager manualVspToscaManager) { + VersioningManager versioningManager, + VendorSoftwareProductDao vendorSoftwareProductDao, + OrchestrationTemplateDao orchestrationTemplateDataDao, + VendorSoftwareProductInfoDao vspInfoDao, + VendorLicenseFacade vendorLicenseFacade, + ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDao, + EnrichedServiceModelDao<ToscaServiceModel, ServiceElement> enrichedServiceModelDao, + HealingManager healingManager, + VendorLicenseArtifactsService licenseArtifactsService, + InformationArtifactGenerator informationArtifactGenerator, + PackageInfoDao packageInfoDao, + ActivityLogManager activityLogManager, + DeploymentFlavorDao deploymentFlavorDao, + NicDao nicDao, + ManualVspToscaManager manualVspToscaManager) { this.versioningManager = versioningManager; this.vendorSoftwareProductDao = vendorSoftwareProductDao; this.orchestrationTemplateDao = orchestrationTemplateDataDao; @@ -222,11 +220,11 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa private void registerToVersioning() { vendorSoftwareProductDao.registerVersioning( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE); serviceModelDao.registerVersioning( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE); enrichedServiceModelDao.registerVersioning( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE); } @Override @@ -235,13 +233,13 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa MDC.put(LoggerConstants.SERVICE_NAME, LoggerServiceName.Checkout_Entity.toString()); Version newVersion = versioningManager - .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, - vendorSoftwareProductId, user); + .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, + vendorSoftwareProductId, user); if (newVersion != null) { ActivityLogEntity activityLogEntity = - new ActivityLogEntity(vendorSoftwareProductId, String.valueOf(newVersion.getMajor() + 1), - ActivityType.CHECKOUT.toString(), user, true, "", ""); + new ActivityLogEntity(vendorSoftwareProductId, String.valueOf(newVersion.getMajor() + 1), + ActivityType.CHECKOUT.toString(), user, true, "", ""); activityLogManager.addActionLog(activityLogEntity, user); } @@ -255,18 +253,18 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa mdcDataDebugMessage.debugEntryMessage("VSP id", vendorSoftwareProductId); Version version = - getVersionInfo(vendorSoftwareProductId, VersionableEntityAction.Read, user) - .getActiveVersion(); + getVersionInfo(vendorSoftwareProductId, VersionableEntityAction.Read, user) + .getActiveVersion(); String preVspName = vspInfoDao - .get(new VspDetails(vendorSoftwareProductId, version)).getName(); + .get(new VspDetails(vendorSoftwareProductId, version)).getName(); Version newVersion = versioningManager.undoCheckout( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, - vendorSoftwareProductId, user); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, + vendorSoftwareProductId, user); String postVspName = vspInfoDao - .get(new VspDetails(vendorSoftwareProductId, newVersion)) - .getName(); + .get(new VspDetails(vendorSoftwareProductId, newVersion)) + .getName(); updateUniqueName(preVspName, postVspName); @@ -280,13 +278,13 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa mdcDataDebugMessage.debugEntryMessage("VSP id", vendorSoftwareProductId); Version newVersion = versioningManager.checkin( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, - vendorSoftwareProductId, user, null); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, + vendorSoftwareProductId, user, null); if (newVersion != null) { ActivityLogEntity activityLogEntity = - new ActivityLogEntity(vendorSoftwareProductId, String.valueOf(newVersion.getMajor() + 1), - ActivityType.CHECKIN.toString(), user, true, "", ""); + new ActivityLogEntity(vendorSoftwareProductId, String.valueOf(newVersion.getMajor() + 1), + ActivityType.CHECKIN.toString(), user, true, "", ""); activityLogManager.addActionLog(activityLogEntity, user); } @@ -303,53 +301,66 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa VspDetails vspDetails = getVsp(vspId, version, user); UploadDataEntity uploadData = orchestrationTemplateDao.getOrchestrationTemplate(vspId, version); ToscaServiceModel serviceModel = - serviceModelDao.getServiceModel(vspId, vspDetails.getVersion()); + serviceModelDao.getServiceModel(vspId, vspDetails.getVersion()); ValidationResponse validationResponse = new ValidationResponse(); validationResponse - .setVspErrors(validateCompletedVendorSoftwareProduct(vspDetails, uploadData, serviceModel), - LoggerServiceName.Submit_VSP, LoggerTragetServiceName.SUBMIT_VSP); + .setVspErrors(validateCompletedVendorSoftwareProduct(vspDetails, uploadData, serviceModel), + LoggerServiceName.Submit_VSP, LoggerTragetServiceName.SUBMIT_VSP); if (isCyclicDependencyInComponents(vspId, vspDetails.getVersion())) { Collection<ErrorCode> vspErrors = validationResponse.getVspErrors() == null - ? new ArrayList<>() - : validationResponse.getVspErrors(); + ? new ArrayList<>() + : validationResponse.getVspErrors(); vspErrors.add(ComponentDependencyModelErrorBuilder - .getcyclicDependencyComponentErrorBuilder()); + .getcyclicDependencyComponentErrorBuilder()); validationResponse.setVspErrors(vspErrors, LoggerServiceName.Submit_VSP, - LoggerTragetServiceName.SUBMIT_VSP); + LoggerTragetServiceName.SUBMIT_VSP); } validationResponse.setLicensingDataErrors(validateLicensingData(vspDetails)); validationResponse - .setUploadDataErrors(validateUploadData(uploadData), LoggerServiceName.Submit_VSP, - LoggerTragetServiceName.SUBMIT_VSP); + .setUploadDataErrors(validateUploadData(uploadData,vspDetails), LoggerServiceName.Submit_VSP, + LoggerTragetServiceName.SUBMIT_VSP); validationResponse.setQuestionnaireValidationResult( - validateQuestionnaire(vspDetails.getId(), vspDetails.getVersion(), vspDetails - .getOnboardingMethod())); + validateQuestionnaire(vspDetails.getId(), vspDetails.getVersion(), vspDetails + .getOnboardingMethod())); if (vspDetails.getOnboardingMethod().equals("Manual")) { - validationResponse.setDeploymentFlavorValidationResult( - deploymentFlavorValidation(vspDetails.getId(), vspDetails.getVersion())); - validationResponse.setComponentValidationResult( - componentValidation(vspDetails.getId(), vspDetails.getVersion())); + Collection<ErrorCode> deploymentFlavourValidationErrList = deploymentFlavorValidation(vspDetails.getId(), vspDetails.getVersion()); + if (validationResponse.getVspErrors() != null) { + if(deploymentFlavourValidationErrList != null) + validationResponse.getVspErrors().addAll(deploymentFlavourValidationErrList); + } else { + validationResponse.setVspErrors(deploymentFlavourValidationErrList, LoggerServiceName.Submit_VSP, + LoggerTragetServiceName.SUBMIT_VSP); + } + + Set<CompositionEntityValidationData> compositionEntityValidationData = componentValidation(vspDetails.getId(), vspDetails.getVersion()); + if (validationResponse.getQuestionnaireValidationResult() != null) { + if(!CollectionUtils.isEmpty(compositionEntityValidationData)) + validationResponse.getQuestionnaireValidationResult().getValidationData().addAll(compositionEntityValidationData); + } else { + validationResponse.setQuestionnaireValidationResult(CollectionUtils.isEmpty(compositionEntityValidationData) ? null : + new QuestionnaireValidationResult(compositionEntityValidationData)); + } + //Generate Tosca service model for Manual Onboarding flow VspModelInfo vspModelInfo = manualVspToscaManager.gatherVspInformation(vspId, version, user); serviceModel = manualVspToscaManager.generateToscaModel(vspModelInfo); } - validationResponse.setCompilationErrors( - compile(vspId, vspDetails.getVersion(), serviceModel), - LoggerServiceName.Submit_VSP, LoggerTragetServiceName.SUBMIT_VSP); + compile(vspId, vspDetails.getVersion(), serviceModel), + LoggerServiceName.Submit_VSP, LoggerTragetServiceName.SUBMIT_VSP); if (validationResponse.isValid()) { Version newVersion = versioningManager.submit( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, - vspId, user, null); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, + vspId, user, null); ActivityLogEntity activityLogEntity = new ActivityLogEntity(vspDetails.getId(), String - .valueOf(newVersion.getMajor()), - ActivityType.SUBMIT.toString(), user, true, "", ""); + .valueOf(newVersion.getMajor()), + ActivityType.SUBMIT.toString(), user, true, "", ""); activityLogManager.addActionLog(activityLogEntity, user); } @@ -360,7 +371,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa private boolean isCyclicDependencyInComponents(String vendorSoftwareProductId, Version version) { final Collection<ComponentDependencyModelEntity> componentDependencyModelEntities = - vendorSoftwareProductDao.listComponentDependencies(vendorSoftwareProductId, version); + vendorSoftwareProductDao.listComponentDependencies(vendorSoftwareProductId, version); ComponentDependencyTracker dependencyTracker = new ComponentDependencyTracker(); for (ComponentDependencyModelEntity entity : componentDependencyModelEntities) { @@ -369,76 +380,60 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa return dependencyTracker.isCyclicDependencyPresent(); } - private DeploymentFlavorValidationResult deploymentFlavorValidation(String vspId, - Version version) { + private Collection<ErrorCode> deploymentFlavorValidation(String vspId, + Version version) { mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); Set<CompositionEntityValidationData> validationData = new HashSet<>(); + Collection<ErrorCode> errorCodeList = new ArrayList<>(); Collection<DeploymentFlavorEntity> deploymentFlavors = - vendorSoftwareProductDao.listDeploymentFlavors(vspId, version); + vendorSoftwareProductDao.listDeploymentFlavors(vspId, version); if (!CollectionUtils.isEmpty(deploymentFlavors)) { deploymentFlavors.forEach(deploymentFlavor -> { DeploymentFlavorEntity deployment = vendorSoftwareProductDao.getDeploymentFlavor(vspId, - version, deploymentFlavor.getId()); + version, deploymentFlavor.getId()); DeploymentFlavor deploymentlocalFlavor = deployment.getDeploymentFlavorCompositionData(); if (deploymentlocalFlavor != null) { if (deploymentlocalFlavor.getFeatureGroupId() == null ) { ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder. - getFeatureGroupMandatoryErrorBuilder(); - CompositionEntityValidationData compositionEntityValidationData = new - CompositionEntityValidationData(CompositionEntityType.deployment, - deploymentFlavor.getId()); - compositionEntityValidationData.setEntityName(deploymentlocalFlavor.getModel()); - List<String> errors = new ArrayList<>(); - errors.add(deploymentFlavorErrorBuilder.message()); - compositionEntityValidationData.setErrors(errors); - validationData.add(compositionEntityValidationData); + getFeatureGroupMandatoryErrorBuilder(deploymentlocalFlavor.getModel()); + errorCodeList.add(deploymentFlavorErrorBuilder); } List<ComponentComputeAssociation> componetComputeAssociations = new ArrayList<>(); componetComputeAssociations = deploymentlocalFlavor.getComponentComputeAssociations(); if (CollectionUtils.isEmpty(componetComputeAssociations)) { CompositionEntityValidationData compositionEntityValidationData = new - CompositionEntityValidationData(CompositionEntityType.deployment,deploymentFlavor - .getId()); + CompositionEntityValidationData(CompositionEntityType.deployment,deploymentFlavor + .getId()); compositionEntityValidationData.setEntityName(deployment - .getDeploymentFlavorCompositionData().getModel()); + .getDeploymentFlavorCompositionData().getModel()); ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder - .getInvalidComponentComputeAssociationErrorBuilder(); - List<String> errors = new ArrayList<>(); - errors.add(deploymentFlavorErrorBuilder.message()); - compositionEntityValidationData.setErrors(errors); - validationData.add(compositionEntityValidationData); + .getInvalidComponentComputeAssociationErrorBuilder(deploymentlocalFlavor.getModel()); + + errorCodeList.add(deploymentFlavorErrorBuilder); } else { componetComputeAssociations.forEach(componetComputeAssociation -> { if (componetComputeAssociation == null - || !(componetComputeAssociation.getComponentId() != null + || !(componetComputeAssociation.getComponentId() != null && componetComputeAssociation.getComputeFlavorId() != null)) { CompositionEntityValidationData compositionEntityValidationData = new - CompositionEntityValidationData(CompositionEntityType.deployment, - deploymentFlavor.getId()); + CompositionEntityValidationData(CompositionEntityType.deployment, + deploymentFlavor.getId()); compositionEntityValidationData.setEntityName(deployment - .getDeploymentFlavorCompositionData().getModel()); + .getDeploymentFlavorCompositionData().getModel()); ErrorCode deploymentFlavorErrorBuilder = DeploymentFlavorErrorBuilder - .getInvalidComponentComputeAssociationErrorBuilder(); - List<String> errors = new ArrayList<>(); - errors.add(deploymentFlavorErrorBuilder.message()); - compositionEntityValidationData.setErrors(errors); - validationData.add(compositionEntityValidationData); + .getInvalidComponentComputeAssociationErrorBuilder(deploymentlocalFlavor.getModel()); + + errorCodeList.add(deploymentFlavorErrorBuilder); } }); } } }); } - if (CollectionUtils.isEmpty(validationData)) { - return null; - } - DeploymentFlavorValidationResult deploymentFlavorValidationResult = new - DeploymentFlavorValidationResult(validationData); - return deploymentFlavorValidationResult; - + return errorCodeList; } - private ComponentValidationResult componentValidation(String vspId, Version version) { + private Set<CompositionEntityValidationData> componentValidation(String vspId, Version version) { mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); Set<CompositionEntityValidationData> validationData = new HashSet<>(); @@ -450,12 +445,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa }); } - if (CollectionUtils.isEmpty(validationData)) { - return null; - } - ComponentValidationResult componentValidationResult = - new ComponentValidationResult(validationData); - return componentValidationResult; + + return validationData; } private void validateNic(String vspId, Version version, @@ -465,15 +456,15 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa if (CollectionUtils.isNotEmpty(nics)) { nics.forEach(nicEntity -> { NicEntity nic = nicDao.get(new NicEntity(vspId, version, component.getId(), - nicEntity.getId())); + nicEntity.getId())); NetworkType networkType = nic.getNicCompositionData().getNetworkType(); String networkId = nic.getNicCompositionData().getNetworkId(); if (networkType.equals(NetworkType.Internal) && networkId == null) { CompositionEntityValidationData compositionEntityValidationData = new - CompositionEntityValidationData(CompositionEntityType.nic, nic.getId()); + CompositionEntityValidationData(CompositionEntityType.nic, nic.getId()); compositionEntityValidationData.setEntityName(nic.getNicCompositionData().getName()); ErrorCode nicInternalNetworkErrorBuilder = NicInternalNetworkErrorBuilder - .getNicNullNetworkIdInternalNetworkIdErrorBuilder(); + .getNicNullNetworkIdInternalNetworkIdErrorBuilder(); List<String> errors = new ArrayList<>(); errors.add(nicInternalNetworkErrorBuilder.message()); compositionEntityValidationData.setErrors(errors); @@ -487,14 +478,14 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa Set<CompositionEntityValidationData> validationData, ComponentEntity component) { Collection<ImageEntity> images = vendorSoftwareProductDao.listImages(vspId,version, - component.getId()); + component.getId()); if (CollectionUtils.isEmpty(images)) { CompositionEntityValidationData compositionEntityValidationData = new - CompositionEntityValidationData(component.getType(),component.getId()); + CompositionEntityValidationData(component.getType(),component.getId()); compositionEntityValidationData.setEntityName(component.getComponentCompositionData() - .getDisplayName()); + .getDisplayName()); ErrorCode vfcMissingImageErrorBuilder = - ComponentErrorBuilder.VfcMissingImageErrorBuilder(); + ComponentErrorBuilder.VfcMissingImageErrorBuilder(); List<String> errors = new ArrayList<>(); errors.add(vfcMissingImageErrorBuilder.message()); compositionEntityValidationData.setErrors(errors); @@ -505,7 +496,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa private List<ErrorCode> validateCompletedVendorSoftwareProduct( - VspDetails vspDetails, UploadDataEntity uploadData, Object serviceModel) { + VspDetails vspDetails, UploadDataEntity uploadData, Object serviceModel) { List<ErrorCode> errors = new ArrayList<>(); @@ -527,10 +518,10 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa if (vspDetails.getOnboardingMethod().equals("Manual")) { //Manual Onboarding specific validations Collection<DeploymentFlavorEntity> deploymentFlavorEntities = vendorSoftwareProductDao - .listDeploymentFlavors(vspDetails.getId(), vspDetails.getVersion()); + .listDeploymentFlavors(vspDetails.getId(), vspDetails.getVersion()); if (CollectionUtils.isEmpty(deploymentFlavorEntities) ) { ErrorCode vspMissingDeploymentFlavorErrorBuilder = - VendorSoftwareProductInvalidErrorBuilder.VspMissingDeploymentFlavorErrorBuilder(); + VendorSoftwareProductInvalidErrorBuilder.VspMissingDeploymentFlavorErrorBuilder(); errors.add(vspMissingDeploymentFlavorErrorBuilder); } errors.addAll(validateMandatoryLicenseFields(vspDetails)); @@ -539,10 +530,10 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa if (uploadData == null || uploadData.getContentData() == null || serviceModel == null) { errors.add(VendorSoftwareProductInvalidErrorBuilder .VendorSoftwareProductMissingServiceModelErrorBuilder(vspDetails.getId(), - vspDetails.getVersion())); + vspDetails.getVersion())); } if (vspDetails.getVlmVersion() != null || vspDetails.getLicenseAgreement() != null - || vspDetails.getFeatureGroups() != null) { + || vspDetails.getFeatureGroups() != null) { errors.addAll(validateMandatoryLicenseFields(vspDetails)); } } @@ -553,7 +544,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa List<ErrorCode> errors = new ArrayList<>(); if (vspDetails.getVlmVersion() == null) { errors.add(createMissingMandatoryFieldError( - "licensing version (in the format of: {integer}.{integer})")); + "licensing version (in the format of: {integer}.{integer})")); } if (vspDetails.getLicenseAgreement() == null) { errors.add(createMissingMandatoryFieldError("license agreement")); @@ -572,13 +563,13 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa mdcDataDebugMessage.debugEntryMessage(null); mdcDataDebugMessage.debugExitMessage(null); return SchemaGenerator - .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, schemaInput); + .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, schemaInput); } private static void sortVspListByModificationTimeDescOrder( - List<VersionedVendorSoftwareProductInfo> vsps) { + List<VersionedVendorSoftwareProductInfo> vsps) { vsps.sort((o1, o2) -> o2.getVspDetails().getWritetimeMicroSeconds() - .compareTo(o1.getVspDetails().getWritetimeMicroSeconds())); + .compareTo(o1.getVspDetails().getWritetimeMicroSeconds())); } @@ -591,21 +582,21 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa enrichedServiceModelDao.deleteAll(vendorSoftwareProductId, version); EnrichmentManager<ToscaServiceModel> enrichmentManager = - EnrichmentManagerFactory.getInstance().createInterface(); + EnrichmentManagerFactory.getInstance().createInterface(); enrichmentManager.init(vendorSoftwareProductId, version); enrichmentManager.setModel(serviceModel); Map<String, List<ErrorMessage>> enrichErrors = enrichmentManager.enrich(); if (MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, enrichErrors))) { logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.ENRICHMENT_COMPLETED - + vendorSoftwareProductId); + + vendorSoftwareProductId); } else { enrichErrors.values().forEach(errorList -> - auditIfContainsErrors(errorList,vendorSoftwareProductId,AuditMessages.ENRICHMENT_ERROR)); + auditIfContainsErrors(errorList,vendorSoftwareProductId,AuditMessages.ENRICHMENT_ERROR)); } enrichedServiceModelDao - .storeServiceModel(vendorSoftwareProductId, version, enrichmentManager.getModel()); + .storeServiceModel(vendorSoftwareProductId, version, enrichmentManager.getModel()); return enrichErrors; } @@ -614,15 +605,15 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa mdcDataDebugMessage.debugEntryMessage("VSP id", vspDetails.getId()); if (vspDetails.getVendorId() == null || vspDetails.getVlmVersion() == null - || vspDetails.getLicenseAgreement() == null - || CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) { + || vspDetails.getLicenseAgreement() == null + || CollectionUtils.isEmpty(vspDetails.getFeatureGroups())) { return null; } mdcDataDebugMessage.debugExitMessage("VSP id", vspDetails.getId()); return vendorLicenseFacade - .validateLicensingData(vspDetails.getVendorId(), vspDetails.getVlmVersion(), - vspDetails.getLicenseAgreement(), vspDetails.getFeatureGroups()); + .validateLicensingData(vspDetails.getVendorId(), vspDetails.getVlmVersion(), + vspDetails.getLicenseAgreement(), vspDetails.getFeatureGroups()); } @Override @@ -637,8 +628,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa vspInfoDao.create(validationVsp); Version version = versioningManager.create( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, - validationVsp.getId(), user); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, + validationVsp.getId(), user); validationVsp.setVersion(version); createUniqueName(VALIDATION_VSP_NAME); @@ -652,17 +643,19 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa validateUniqueName(vspDetails.getName()); + vspDetails.setOnboardingOrigin(OnboardingTypesEnum.NONE.toString()); + vspInfoDao.create(vspDetails);//id will be set in the dao vspInfoDao.updateQuestionnaireData(vspDetails.getId(), null, - new JsonSchemaDataGenerator(getVspQuestionnaireSchema(null)).generateData()); + new JsonSchemaDataGenerator(getVspQuestionnaireSchema(null)).generateData()); Version version = versioningManager - .create(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, - vspDetails.getId(), user); + .create(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, + vspDetails.getId(), user); vspDetails.setVersion(version); ActivityLogEntity activityLogEntity = new ActivityLogEntity(vspDetails.getId(), String - .valueOf(vspDetails.getVersion().getMajor() + 1), - ActivityType.CREATE_NEW.toString(), user, true, "", ""); + .valueOf(vspDetails.getVersion().getMajor() + 1), + ActivityType.CREATE_NEW.toString(), user, true, "", ""); activityLogManager.addActionLog(activityLogEntity, user); String vspName = vspDetails.getName(); createUniqueName(vspName); @@ -675,8 +668,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa mdcDataDebugMessage.debugEntryMessage(null); Map<String, VersionInfo> idToVersionsInfo = versioningManager.listEntitiesVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, user, - VersionableEntityAction.Read); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, user, + VersionableEntityAction.Read); List<VersionedVendorSoftwareProductInfo> vsps = new ArrayList<>(); for (Map.Entry<String, VersionInfo> entry : idToVersionsInfo.entrySet()) { @@ -702,10 +695,10 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } } catch (RuntimeException rte) { logger.error( - "Error trying to retrieve vsp[" + entry.getKey() + "] version[" + version.toString - () + "] " + - "message:" + rte - .getMessage()); + "Error trying to retrieve vsp[" + entry.getKey() + "] version[" + version.toString + () + "] " + + "message:" + rte + .getMessage()); } } @@ -723,11 +716,11 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa VspDetails retrieved = vspInfoDao.get(vspDetails); if (!retrieved.getOnboardingMethod().equals(vspDetails.getOnboardingMethod())) { final ErrorCode onboardingMethodUpdateErrorCode = OnboardingMethodErrorBuilder - .getOnboardingUpdateError(); + .getOnboardingUpdateError(); MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.UPDATE_VSP, ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), onboardingMethodUpdateErrorCode.message()); + LoggerTragetServiceName.UPDATE_VSP, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), onboardingMethodUpdateErrorCode.message()); throw new CoreException(onboardingMethodUpdateErrorCode); } @@ -747,20 +740,20 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa private void updateDeploymentFlavor(VspDetails vspDetails, String user) { final List<String> featureGroups = vspDetails.getFeatureGroups(); - if (featureGroups != null && !featureGroups.isEmpty() ) { + if (featureGroups != null) { final Collection<DeploymentFlavorEntity> deploymentFlavorEntities = deploymentFlavorDao - .list(new DeploymentFlavorEntity(vspDetails.getId(), vspDetails - .getVersion(), null)); + .list(new DeploymentFlavorEntity(vspDetails.getId(), vspDetails + .getVersion(), null)); if (Objects.nonNull(deploymentFlavorEntities)) { deploymentFlavorEntities.forEach(deploymentFlavorEntity -> { final String featureGroupId = - deploymentFlavorEntity.getDeploymentFlavorCompositionData().getFeatureGroupId(); + deploymentFlavorEntity.getDeploymentFlavorCompositionData().getFeatureGroupId(); if ( !featureGroups.contains(featureGroupId)) { DeploymentFlavor deploymentFlavorCompositionData = - deploymentFlavorEntity.getDeploymentFlavorCompositionData(); + deploymentFlavorEntity.getDeploymentFlavorCompositionData(); deploymentFlavorCompositionData.setFeatureGroupId(null); deploymentFlavorEntity.setDeploymentFlavorCompositionData - (deploymentFlavorCompositionData); + (deploymentFlavorCompositionData); vendorSoftwareProductDao.updateDeploymentFlavor(deploymentFlavorEntity); } }); @@ -776,12 +769,20 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa VspDetails vsp = vspInfoDao.get(new VspDetails(vspId, version)); if (vsp == null) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.GET_VSP, ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), "Requested VSP not found"); + LoggerTragetServiceName.GET_VSP, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), "Requested VSP not found"); throw new CoreException(new VendorSoftwareProductNotFoundErrorBuilder(vspId).build()); } vsp.setValidationData(orchestrationTemplateDao.getValidationData(vspId, version)); + if(Objects.isNull(vsp.getOnboardingOrigin())){ + vsp.setOnboardingOrigin(OnboardingTypesEnum.ZIP.toString()); + } + + if(Objects.isNull(vsp.getNetworkPackageName())){ + vsp.setNetworkPackageName("Upload File"); + } + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); return vsp; } @@ -789,12 +790,12 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa @Override public Version callAutoHeal(String vspId, VersionInfo versionInfo, VspDetails vendorSoftwareProductInfo, String user) - throws Exception { + throws Exception { switch (versionInfo.getStatus()) { case Locked: if (user.equals(versionInfo.getLockingUser())) { autoHeal(vspId, versionInfo.getActiveVersion(), vendorSoftwareProductInfo, - versionInfo.getLockingUser()); + versionInfo.getLockingUser()); } return versionInfo.getActiveVersion(); case Available: @@ -830,12 +831,12 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa mdcDataDebugMessage.debugEntryMessage("VSP id", vspId); MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.DELETE_VSP, ErrorLevel.ERROR.name(), - LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Unsupported operation"); + LoggerTragetServiceName.DELETE_VSP, ErrorLevel.ERROR.name(), + LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Unsupported operation"); mdcDataDebugMessage.debugExitMessage("VSP id", vspId); throw new UnsupportedOperationException( - VendorSoftwareProductConstants.UNSUPPORTED_OPERATION_ERROR); + VendorSoftwareProductConstants.UNSUPPORTED_OPERATION_ERROR); } @Override @@ -845,8 +846,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa VersionInfo versionInfo = getVersionInfo(vspId, VersionableEntityAction.Read, user); version = VersionStatus.Locked.equals(versionInfo.getStatus()) - ? versionInfo.getActiveVersion() - : checkout(vspId, user); + ? versionInfo.getActiveVersion() + : checkout(vspId, user); version.setStatus(VersionStatus.Locked); healingManager.healAll(getHealingParamsAsMap(vspId, version, user)); @@ -896,24 +897,24 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa if (version == null) { errorMessage = "Package not found"; MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.GET_TRANSLATED_FILE, ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage); + LoggerTragetServiceName.GET_TRANSLATED_FILE, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage); throw new CoreException(new PackageNotFoundErrorBuilder(vspId).build()); } else if (!version.isFinal()) { errorMessage = "Invalid requested version"; MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.GET_VERSION_INFO, ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage); + LoggerTragetServiceName.GET_VERSION_INFO, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage); throw new CoreException(new RequestedVersionInvalidErrorBuilder().build()); } PackageInfo packageInfo = - packageInfoDao.get(new PackageInfo(vspId, version)); + packageInfoDao.get(new PackageInfo(vspId, version)); if (packageInfo == null) { errorMessage = "Package not found"; MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.GET_TRANSLATED_FILE, ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage); + LoggerTragetServiceName.GET_TRANSLATED_FILE, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage); throw new CoreException(new PackageNotFoundErrorBuilder(vspId, version).build()); } @@ -921,8 +922,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa if (translatedFileBuffer == null) { errorMessage = "Package not found"; MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.GET_TRANSLATED_FILE, ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage); + LoggerTragetServiceName.GET_TRANSLATED_FILE, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage); throw new CoreException(new PackageInvalidErrorBuilder(vspId, version).build()); } @@ -935,10 +936,10 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } catch (IOException exception) { errorMessage = "Can't create package"; MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.CREATE_TRANSLATED_FILE, ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage); + LoggerTragetServiceName.CREATE_TRANSLATED_FILE, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), errorMessage); throw new CoreException(new TranslationFileCreationErrorBuilder(vspId, version).build(), - exception); + exception); } mdcDataDebugMessage.debugExitMessage("VSP id", vspId); @@ -961,12 +962,12 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa try (final ZipOutputStream zos = new ZipOutputStream(baos); ZipInputStream zipStream = new ZipInputStream( - new ByteArrayInputStream(contentData.array()))) { + new ByteArrayInputStream(contentData.array()))) { zos.write(contentData.array()); } catch (IOException exception) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.GET_UPLOADED_HEAT, ErrorLevel.ERROR.name(), - LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't get uploaded HEAT"); + LoggerTragetServiceName.GET_UPLOADED_HEAT, ErrorLevel.ERROR.name(), + LoggerErrorCode.DATA_ERROR.getErrorCode(), "Can't get uploaded HEAT"); throw new CoreException(new FileCreationErrorBuilder(vspId).build(), exception); } @@ -980,11 +981,11 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa if (!version.isFinal()) { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_DB, - LoggerTragetServiceName.CREATE_PACKAGE, ErrorLevel.ERROR.name(), - LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't create package"); + LoggerTragetServiceName.CREATE_PACKAGE, ErrorLevel.ERROR.name(), + LoggerErrorCode.PERMISSION_ERROR.getErrorCode(), "Can't create package"); throw new CoreException( - new CreatePackageForNonFinalVendorSoftwareProductErrorBuilder(vspId, version) - .build()); + new CreatePackageForNonFinalVendorSoftwareProductErrorBuilder(vspId, version) + .build()); } ToscaServiceModel toscaServiceModel = enrichedServiceModelDao.getServiceModel(vspId, version); @@ -994,13 +995,13 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa PackageInfo packageInfo = createPackageInfo(vspId, vspDetails); ToscaFileOutputServiceCsarImpl toscaServiceTemplateServiceCsar = - new ToscaFileOutputServiceCsarImpl(); + new ToscaFileOutputServiceCsarImpl(); FileContentHandler licenseArtifacts = licenseArtifactsService - .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, - vspDetails.getFeatureGroups(), user); + .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, + vspDetails.getFeatureGroups(), user); //todo add tosca validation here packageInfo.setTranslatedFile(ByteBuffer.wrap( - toscaServiceTemplateServiceCsar.createOutputFile(toscaServiceModel, licenseArtifacts))); + toscaServiceTemplateServiceCsar.createOutputFile(toscaServiceModel, licenseArtifacts))); packageInfoDao.create(packageInfo); @@ -1031,7 +1032,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa VspQuestionnaireEntity retrieved = vspInfoDao.getQuestionnaire(vspId, version); VersioningUtil.validateEntityExistence(retrieved, new VspQuestionnaireEntity(vspId, version), - VspDetails.ENTITY_TYPE); + VspDetails.ENTITY_TYPE); String questionnaireData = retrieved.getQuestionnaireData(); @@ -1055,8 +1056,9 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } - private Map<String, List<ErrorMessage>> validateUploadData(UploadDataEntity uploadData) - throws IOException { + private Map<String, List<ErrorMessage>> validateUploadData(UploadDataEntity uploadData, + VspDetails vspDetails) + throws IOException { Map<String, List<ErrorMessage>> validationErrors = new HashMap<>(); if (uploadData == null || uploadData.getContentData() == null) { @@ -1064,22 +1066,24 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } FileContentHandler fileContentMap = - CommonUtil.validateAndUploadFileContent(uploadData.getContentData().array()); + CommonUtil.validateAndUploadFileContent(OnboardingTypesEnum.getOnboardingTypesEnum + (vspDetails.getOnboardingOrigin()), + uploadData.getContentData().array()); //todo - check ValidationManager validationManager = - ValidationManagerUtil.initValidationManager(fileContentMap); + ValidationManagerUtil.initValidationManager(fileContentMap); validationErrors.putAll(validationManager.validate()); return - MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, validationErrors)) - ? null : validationErrors; + MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, validationErrors)) + ? null : validationErrors; } private VersionInfo getVersionInfo(String vendorSoftwareProductId, VersionableEntityAction action, String user) { return versioningManager.getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, - vendorSoftwareProductId, user, action); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, + vendorSoftwareProductId, user, action); } @@ -1090,9 +1094,9 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa // The apis of CompositionEntityDataManager used here are stateful! // so, it must be re-created from scratch when it is used! CompositionEntityDataManager compositionEntityDataManager = - CompositionEntityDataManagerFactory.getInstance().createInterface(); + CompositionEntityDataManagerFactory.getInstance().createInterface(); compositionEntityDataManager - .addEntity(vspInfoDao.getQuestionnaire(vspId, version), null); + .addEntity(vspInfoDao.getQuestionnaire(vspId, version), null); Collection<NicEntity> nics = vendorSoftwareProductDao.listNicsByVsp(vspId, version); @@ -1103,16 +1107,16 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa Nic nic = nicEntity.getNicCompositionData(); if (nic != null && nic.getName() != null) { List<String> nicNames = - nicNamesByComponent.computeIfAbsent(nicEntity.getComponentId(), k -> new ArrayList<>()); + nicNamesByComponent.computeIfAbsent(nicEntity.getComponentId(), k -> new ArrayList<>()); nicNames.add(nic.getName()); } } Collection<ComponentEntity> components = - vendorSoftwareProductDao.listComponentsCompositionAndQuestionnaire(vspId, version); + vendorSoftwareProductDao.listComponentsCompositionAndQuestionnaire(vspId, version); components.forEach(component -> compositionEntityDataManager.addEntity(component, - new ComponentQuestionnaireSchemaInput(nicNamesByComponent.get(component.getId()), - JsonUtil.json2Object(component.getQuestionnaireData(), Map.class)))); + new ComponentQuestionnaireSchemaInput(nicNamesByComponent.get(component.getId()), + JsonUtil.json2Object(component.getQuestionnaireData(), Map.class)))); Collection<ComputeEntity> computes = vendorSoftwareProductDao.listComputesByVsp(vspId, version); computes.forEach(compute -> compositionEntityDataManager.addEntity(compute, null)); @@ -1123,7 +1127,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa } Map<CompositionEntityId, Collection<String>> errorsByEntityId = - compositionEntityDataManager.validateEntitiesQuestionnaire(); + compositionEntityDataManager.validateEntitiesQuestionnaire(); if (MapUtils.isNotEmpty(errorsByEntityId)) { compositionEntityDataManager.buildTrees(); compositionEntityDataManager.addErrorsToTrees(errorsByEntityId); @@ -1133,7 +1137,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa mdcDataDebugMessage.debugExitMessage("VSP id", vspId); return new QuestionnaireValidationResult( - compositionEntityDataManager.getAllErrorsByVsp(vspId)); + compositionEntityDataManager.getAllErrorsByVsp(vspId)); } mdcDataDebugMessage.debugExitMessage("VSP id", vspId); @@ -1154,11 +1158,11 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa File infoArtifactFile; try { infoArtifactAsByteBuffer = ByteBuffer.wrap(informationArtifactGenerator.generate(vspId, - version).getBytes()); + version).getBytes()); infoArtifactFile = - new File( - String.format(VendorSoftwareProductConstants.INFORMATION_ARTIFACT_NAME, vspName)); + new File( + String.format(VendorSoftwareProductConstants.INFORMATION_ARTIFACT_NAME, vspName)); OutputStream out = new BufferedOutputStream(new FileOutputStream(infoArtifactFile)); out.write(infoArtifactAsByteBuffer.array()); out.close(); @@ -1172,18 +1176,18 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa void validateUniqueName(String vspName) { UniqueValueUtil.validateUniqueValue( - VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, vspName); + VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, vspName); } void createUniqueName(String vspName) { UniqueValueUtil.createUniqueValue( - VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, vspName); + VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, vspName); } void updateUniqueName(String oldVspName, String newVspName) { UniqueValueUtil.updateUniqueValue( - VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, - oldVspName, newVspName); + VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, + oldVspName, newVspName); } @Override @@ -1197,7 +1201,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa errorList.forEach(errorMessage -> { if (errorMessage.getLevel().equals(ErrorLevel.ERROR)) { logger.audit(AuditMessages.AUDIT_MSG + String.format(auditType, errorMessage.getMessage(), - vspId)); + vspId)); } }); } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java new file mode 100644 index 0000000000..c7fb43770d --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/BaseOrchestrationTemplateHandler.java @@ -0,0 +1,100 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.io.InputStream; +import java.util.Optional; +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; +public abstract class BaseOrchestrationTemplateHandler implements OrchestrationTemplateFileHandler { + protected static final Logger logger = + LoggerFactory.getLogger(BaseOrchestrationTemplateHandler.class); + protected static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + + @Override + public UploadFileResponse upload(String vspId, Version version, InputStream fileToUpload, String user, + CandidateService candidateService, VspDetails vspDetails) { + UploadFileResponse uploadFileResponse = new UploadFileResponse(); + uploadFileResponse.setOnboardingType(getHandlerType()); + if (isNotEmptyFileToUpload(fileToUpload, uploadFileResponse, candidateService)) { + return uploadFileResponse; + } + + byte[] uploadedFileData = FileUtils.toByteArray(fileToUpload); + if (isInvalidRawZipData(uploadFileResponse, uploadedFileData, candidateService)) { + return uploadFileResponse; + } + + Optional<FileContentHandler> optionalContentMap = + getFileContentMap(uploadFileResponse, uploadedFileData); + if (!optionalContentMap.isPresent()) { + logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), getHandlerType().toString())); + uploadFileResponse + .addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), getHandlerType().toString()))); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return uploadFileResponse; + } + + if (!MapUtils.isEmpty(uploadFileResponse.getErrors())) { + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return uploadFileResponse; + } + if (updateCandidateData(vspId, user, candidateService, vspDetails, uploadFileResponse, + uploadedFileData, optionalContentMap)) + return uploadFileResponse; + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return uploadFileResponse; + + } + + protected abstract boolean updateCandidateData(String vspId, String user, CandidateService candidateService, + VspDetails vspDetails, UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, + Optional<FileContentHandler> optionalContentMap); + + + private boolean isNotEmptyFileToUpload(InputStream fileToUpload, + UploadFileResponse uploadFileResponse, CandidateService candidateService) { + Optional<ErrorMessage> errorMessage = + candidateService.validateNonEmptyFileToUpload(fileToUpload); + if (errorMessage.isPresent()) { + uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); + return true; + } + return false; + } + + protected boolean isInvalidRawZipData(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, CandidateService candidateService) { + Optional<ErrorMessage> errorMessage; + errorMessage = candidateService.validateRawZipData(uploadedFileData); + if (errorMessage.isPresent()) { + uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, errorMessage.get()); + return true; + } + return false; + } + + public abstract Optional<FileContentHandler> getFileContentMap(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData); + protected abstract OnboardingTypesEnum getHandlerType(); +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java new file mode 100644 index 0000000000..53d34749e7 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java @@ -0,0 +1,154 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.apache.commons.lang3.tuple.Pair; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.CommonUtil; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.OnboardingManifest; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CSARConstants.*; +public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateHandler + implements OrchestrationTemplateFileHandler { + + + @Override + public Optional<FileContentHandler> getFileContentMap(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData) { + FileContentHandler contentMap = null; + List<String> folderList = new ArrayList<>(); + try { + Pair<FileContentHandler, List<String>> fileContentMapFromOrchestrationCandidateZip = CommonUtil.getFileContentMapFromOrchestrationCandidateZip(uploadedFileData); + contentMap = fileContentMapFromOrchestrationCandidateZip.getKey(); + folderList = fileContentMapFromOrchestrationCandidateZip.getRight(); + } catch (IOException exception) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_CSAR_FILE.getErrorMessage())); + } catch (CoreException coreException) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); + } + validateContent(uploadFileResponse, contentMap, folderList); + return Optional.ofNullable(contentMap); + } + + private void validateContent(UploadFileResponse uploadFileResponse, FileContentHandler contentMap, List<String> folderList) { + validateManifest(uploadFileResponse, contentMap); + validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME); + validateNoExtraFiles(uploadFileResponse, contentMap); + validateFolders(uploadFileResponse, folderList); + } + + private void validateManifest(UploadFileResponse uploadFileResponse, FileContentHandler contentMap) { + if (!validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)){ + return; + } + InputStream fileContent = contentMap.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME); + OnboardingManifest onboardingManifest = new OnboardingManifest(fileContent); + if (!onboardingManifest.isValid()){ + onboardingManifest.getErrors().forEach(error -> uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, error))); + } + } + + private void validateNoExtraFiles(UploadFileResponse uploadFileResponse, FileContentHandler contentMap) { + List<String> unwantedFiles = contentMap.getFileList().stream() + .filter(this::filterFiles).collect(Collectors.toList()); + if (!unwantedFiles.isEmpty()) { + unwantedFiles.stream().filter(this::filterFiles).forEach(unwantedFile -> + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.CSAR_FILES_NOT_ALLOWED.getErrorMessage(), + unwantedFile)))); + + ; + } + } + + private void validateFolders(UploadFileResponse uploadFileResponse, List<String> folderList) { + List<String> filterResult = folderList.stream().filter(this::filterFolders).collect(Collectors.toList()); + if (!filterResult.isEmpty()) { + folderList.stream().filter(this::filterFolders).forEach( unwantedFolder -> + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.CSAR_DIRECTORIES_NOT_ALLOWED.getErrorMessage(), + unwantedFolder)))); + + } + } + private boolean filterFiles(String inFileName) { + boolean valid = ELIGIBLE_FILES.stream().anyMatch(fileName -> fileName.equals(inFileName)); + if (valid){ + return !valid; + } + return filterFolders(inFileName); + } + + private boolean filterFolders(String fileName) { + return !ELIGBLE_FOLDERS.stream().anyMatch(dirName -> fileName.startsWith(dirName)); + } + + private boolean validateFileExist(UploadFileResponse uploadFileResponse, FileContentHandler contentMap, String fileName) { + + boolean containsFile = contentMap.containsFile(fileName); + if (!containsFile) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage(), fileName))); + } + return containsFile; + } + + @Override + protected boolean updateCandidateData(String vspId, String user, CandidateService candidateService, + VspDetails vspDetails, UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, Optional<FileContentHandler> optionalContentMap) { + try { + candidateService.updateCandidateUploadData(new OrchestrationTemplateCandidateData( + ByteBuffer.wrap(uploadedFileData), ""), vspDetails.getId()); + } catch (Exception exception) { + logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), + getHandlerType().toString()), exception); + uploadFileResponse + .addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return true; + } + return false; + } + + + @Override + protected OnboardingTypesEnum getHandlerType() { + return OnboardingTypesEnum.CSAR; + } + + @Override + protected boolean isInvalidRawZipData(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, CandidateService candidateService) { + return super.isInvalidRawZipData(uploadFileResponse, uploadedFileData, candidateService); + + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java new file mode 100644 index 0000000000..3f7d18de9f --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateFileHandler.java @@ -0,0 +1,12 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.io.InputStream; +public interface OrchestrationTemplateFileHandler { + UploadFileResponse upload(String vspId, Version version, InputStream fileToUpload, String user, + CandidateService candidateService, VspDetails vspDetails); +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java new file mode 100644 index 0000000000..626d941911 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateZipHandler.java @@ -0,0 +1,55 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.services.utils.CandidateEntityBuilder; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; + +import java.util.Optional; + +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; +public class OrchestrationTemplateZipHandler extends BaseOrchestrationTemplateHandler + implements OrchestrationTemplateFileHandler { + + @Override + public Optional<FileContentHandler> getFileContentMap(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData) { + return OrchestrationUtil.getFileContentMap(OnboardingTypesEnum.ZIP, uploadFileResponse, uploadedFileData); + } + + @Override + protected boolean updateCandidateData(String vspId, String user, CandidateService candidateService, + VspDetails vspDetails, UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, Optional<FileContentHandler> optionalContentMap) { + try { + OrchestrationTemplateCandidateData candidateData = + new CandidateEntityBuilder(candidateService) + .buildCandidateEntityFromZip(vspDetails, uploadedFileData, optionalContentMap.get(), + uploadFileResponse.getErrors(), user); + candidateService.updateCandidateUploadData(candidateData, vspDetails.getId()); + } catch (Exception exception) { + logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), + getHandlerType().toString()),exception); + uploadFileResponse + .addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return true; + } + return false; + } + + @Override + protected OnboardingTypesEnum getHandlerType() { + return OnboardingTypesEnum.ZIP; + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java new file mode 100644 index 0000000000..85f92662ea --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUploadFactory.java @@ -0,0 +1,29 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.openecomp.config.api.Configuration; +import org.openecomp.config.api.ConfigurationManager; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_IMPL_KEY; + +public class OrchestrationUploadFactory { + private static Map<String, ImplementationConfiguration> fileHanlders; + + static { + Configuration config = ConfigurationManager.lookup(); + fileHanlders = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE, + ORCHESTRATION_IMPL_KEY, ImplementationConfiguration.class)); + + } + + public static final OrchestrationTemplateFileHandler createOrchestrationTemplateFileHandler(String filePrefix) { + ImplementationConfiguration orchestrationTemplateFileHandler = fileHanlders.get(filePrefix); + return CommonMethods.newInstance(orchestrationTemplateFileHandler.getImplementationClass(), + OrchestrationTemplateFileHandler.class); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java new file mode 100644 index 0000000000..9d7421f336 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationUtil.java @@ -0,0 +1,282 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration; + +import org.apache.commons.collections4.CollectionUtils; +import org.openecomp.core.model.dao.ServiceModelDao; +import org.openecomp.core.model.dao.ServiceModelDaoFactory; +import org.openecomp.core.util.UniqueValueUtil; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.CommonUtil; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.heat.datatypes.structure.ValidationStructureList; +import org.openecomp.sdc.heat.services.tree.HeatTreeManager; +import org.openecomp.sdc.heat.services.tree.HeatTreeManagerUtil; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.MonitoringUploadDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.NicDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadData; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionDataExtractorFactory; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.ByteBuffer; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + +import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.GENERAL_COMPONENT_ID; +import static org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants.UniqueValues.PROCESS_NAME; + +public class OrchestrationUtil { + + public static final String ORCHESTRATION_CONFIG_NAMESPACE = "orchestration"; + public static final String ORCHESTRATION_IMPL_KEY = "orchestration_impl"; + + + private static VendorSoftwareProductDao vendorSoftwareProductDao = + VendorSoftwareProductDaoFactory.getInstance().createInterface(); + private static NicDao nicDao = NicDaoFactory.getInstance().createInterface(); + private static ComponentArtifactDao componentArtifactDao = MonitoringUploadDaoFactory.getInstance().createInterface(); + private static ProcessDao processDao = ProcessDaoFactory.getInstance().createInterface(); + private static OrchestrationTemplateDao orchestrationTemplateDataDao = + OrchestrationTemplateDaoFactory.getInstance().createInterface(); + private static ComponentDao componentDao = + ComponentDaoFactory.getInstance().createInterface(); + private static ServiceModelDao serviceModelDao = ServiceModelDaoFactory.getInstance() + .createInterface(); + private static CompositionEntityDataManager compositionEntityDataManager = + CompositionEntityDataManagerFactory.getInstance().createInterface(); + private static CompositionDataExtractor compositionDataExtractor = + CompositionDataExtractorFactory.getInstance().createInterface(); + + public static Optional<FileContentHandler> getFileContentMap(OnboardingTypesEnum type, + UploadFileResponse uploadFileResponse, + byte[] uploadedFileData) { + FileContentHandler contentMap = null; + try { + contentMap = CommonUtil.validateAndUploadFileContent(type, uploadedFileData); + } catch (IOException exception) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage())); + } catch (CoreException coreException) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); + } + return Optional.ofNullable(contentMap); + } + + public static void backupComponentsQuestionnaireBeforeDelete(String vspId, Version activeVersion, + Map<String, String> componentsQustanniare, + Map<String, Map<String, String>> + componentNicsQustanniare, + Map<String, Collection<ComponentMonitoringUploadEntity>> + componentMibList, + Map<String, Collection<ProcessEntity>> + componentProcesses, + Map<String, ProcessEntity> processArtifact) { + //backup VSP processes + backupProcess(vspId, activeVersion, GENERAL_COMPONENT_ID, GENERAL_COMPONENT_ID, + componentProcesses, processArtifact); + Collection<ComponentEntity> componentsCompositionAndQuestionnaire = vendorSoftwareProductDao + .listComponentsCompositionAndQuestionnaire(vspId, + activeVersion); + componentsCompositionAndQuestionnaire.forEach(componentEntity -> { + String componentName = componentEntity.getComponentCompositionData().getName(); + componentsQustanniare.put(componentName, componentEntity + .getQuestionnaireData()); + Collection<NicEntity> + nics = nicDao.list(new NicEntity(vspId, activeVersion, componentEntity.getId(), null)); + //backup mib + Collection<ComponentMonitoringUploadEntity> componentMib = + componentArtifactDao.listArtifacts(new + ComponentMonitoringUploadEntity(vspId, activeVersion, componentEntity.getId(), + null)); + if (CollectionUtils.isNotEmpty(componentMib)) { + componentMibList.put(componentName,componentMib); + } + + //backup component processes + backupProcess(vspId, activeVersion, componentEntity.getId(), componentName, + componentProcesses, processArtifact); + if (CollectionUtils.isNotEmpty(nics)) { + Map<String, String> nicsQustanniare = new HashMap<>(); + nics.forEach(nicEntity -> { + NicEntity nic = nicDao.get(new NicEntity(vspId, activeVersion, componentEntity.getId(), + nicEntity.getId())); + NicEntity nicQuestionnaire = nicDao.getQuestionnaireData(vspId, activeVersion, + componentEntity.getId(), nicEntity.getId()); + + nicsQustanniare + .put(nicEntity.getNicCompositionData().getName(), + nicQuestionnaire.getQuestionnaireData()); + }); + componentNicsQustanniare.put(componentName, nicsQustanniare); + } + }); + } + + private static void backupProcess(String vspId, Version activeVersion, String componentId, + String componentName, Map<String, + Collection<ProcessEntity>> processes, + Map<String, ProcessEntity> processArtifact) { + Collection<ProcessEntity> processList = vendorSoftwareProductDao.listProcesses(vspId, + activeVersion, componentId); + if (!processList.isEmpty()) { + processes.put(componentName, processList); + processList.forEach(process -> { + //ProcessArtifactEntity artifact = vendorSoftwareProductDao.getProcessArtifact(vspId, + // activeVersion, componentId, process.getId()); + ProcessEntity artifact = + processDao.get(new ProcessEntity(vspId, activeVersion, componentId, process.getId())); + if (artifact.getArtifact() != null) { + processArtifact.put(process.getId(), artifact); + } + }); + } + } + + public static void retainComponentQuestionnaireData(String vspId, Version activeVersion, + Map<String, String> componentsQustanniare, + Map<String, Map<String, String>> + componentNicsQustanniare, + Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList, + Map<String, Collection<ProcessEntity>> processes, + Map<String, ProcessEntity> processArtifact) { + //VSP processes + restoreProcess(vspId, activeVersion, GENERAL_COMPONENT_ID, GENERAL_COMPONENT_ID, processes, + processArtifact); + Collection<ComponentEntity> + components = vendorSoftwareProductDao.listComponents(vspId, activeVersion); + components.forEach(componentEntity -> { + String componentName = componentEntity.getComponentCompositionData().getName(); + if (componentsQustanniare.containsKey(componentName)) { + componentDao.updateQuestionnaireData(vspId, activeVersion, + componentEntity.getId(), + componentsQustanniare.get(componentEntity.getComponentCompositionData() + .getName())); + if (componentNicsQustanniare.containsKey(componentName)) { + Map<String, String> nicsQustanniare = componentNicsQustanniare.get(componentName); + Collection<NicEntity> + nics = + nicDao.list(new NicEntity(vspId, activeVersion, componentEntity.getId(), null)); + nics.forEach(nicEntity -> { + if (nicsQustanniare.containsKey(nicEntity.getNicCompositionData().getName())) { + nicDao.updateQuestionnaireData(vspId, activeVersion, + componentEntity.getId(), nicEntity.getId(), + nicsQustanniare.get(nicEntity.getNicCompositionData().getName())); + } + }); + } + //MIB //todo add for VES_EVENTS + if (componentMibList.containsKey(componentName)) { + Collection<ComponentMonitoringUploadEntity> mibList = + componentMibList.get(componentName); + mibList.forEach(mib -> { + mib.setComponentId(componentEntity.getId()); + componentArtifactDao.create(mib); + }); + } + //VFC processes + restoreProcess(vspId, activeVersion, componentEntity.getId(), componentName, processes, + processArtifact); + } + }); + } + + private static void restoreProcess(String vspId, Version activeVersion, String componentId, + String componentName, + Map<String, Collection<ProcessEntity>> processes, + Map<String, ProcessEntity> processArtifact) { + if (processes.containsKey(componentName)) { + Collection<ProcessEntity> processList = processes.get(componentName); + processList.forEach(process -> { + //Reatin VFC process + if (!GENERAL_COMPONENT_ID.equals(componentId) && processArtifact.containsKey(process.getId + ())) { + ProcessEntity artifact = processArtifact.get(process.getId()); + artifact.setComponentId(componentId); + UniqueValueUtil.createUniqueValue(PROCESS_NAME, vspId, activeVersion.toString(), + componentId, process.getName()); + vendorSoftwareProductDao.createProcess(artifact); + } + }); + } + } + + public static void deleteUploadDataAndContent(String vspId, Version version) { + //fixme change this when more tables are zusammenized + vendorSoftwareProductDao.deleteUploadData(vspId, version); + } + + public static void saveUploadData(String vspId, Version activeVersion, InputStream uploadedFileData, + FileContentHandler fileContentMap, HeatStructureTree tree) { + Map<String, Object> manifestAsMap = + fileContentMap.containsFile(SdcCommon.MANIFEST_NAME) ? + (Map<String, Object>) JsonUtil.json2Object(fileContentMap.getFileContent( + SdcCommon.MANIFEST_NAME), Map.class) + : new HashMap<>(); + + UploadData uploadData = new UploadData(); + uploadData.setContentData(ByteBuffer.wrap(FileUtils.toByteArray(uploadedFileData))); + uploadData.setValidationDataStructure(new ValidationStructureList(tree)); + uploadData.setPackageName(Objects.isNull(manifestAsMap.get("name")) ? null : + (String) manifestAsMap.get("name")); + uploadData.setPackageVersion(Objects.isNull(manifestAsMap.get("version")) ? null : + (String) manifestAsMap.get("version")); + orchestrationTemplateDataDao.updateOrchestrationTemplateData(vspId, uploadData); + } + + public static void saveServiceModel(String vspId, + Version version, + ToscaServiceModel serviceModelToExtract, + ToscaServiceModel serviceModelToStore){ + if (serviceModelToExtract != null) { + serviceModelDao.storeServiceModel(vspId, version, serviceModelToStore); + //Extracting the compostion data from the output service model of the first phase of + // translation + compositionEntityDataManager.saveCompositionData(vspId, version, + compositionDataExtractor.extractServiceCompositionData(serviceModelToExtract)); +// OrchestrationUtil.retainComponentQuestionnaireData(vspId, version, componentsQuestionnaire, +// componentNicsQuestionnaire, componentMibList, processes, processArtifact); + } + } + + public static HeatStructureTree createHeatTree(FileContentHandler fileContentMap, + Map<String, List<ErrorMessage>> validationErrors){ + HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(fileContentMap); + heatTreeManager.createTree(); + heatTreeManager.addErrors(validationErrors); + return heatTreeManager.getTree(); + } + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java new file mode 100644 index 0000000000..0d204ef2c0 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/CSARConstants.java @@ -0,0 +1,18 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar; + +import com.google.common.collect.ImmutableSet; +import static com.google.common.collect.ImmutableSet.of; +public class CSARConstants { + + public static final ImmutableSet<String> ELIGBLE_FOLDERS = of("Artifacts/","Definitions/", + "Licenses/", "TOSCA-Metadata/"); + + public static final String MAIN_SERVICE_TEMPLATE_MF_FILE_NAME = "MainServiceTemplate.mf"; + public static final String MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME = "MainServiceTemplate.yaml"; + public static final ImmutableSet<String> ELIGIBLE_FILES = + of(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME,MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME); + + public static final String METADATA_MF_ATTRIBUTE = "metadata"; + public static final String SOURCE_MF_ATTRIBUTE = "source"; + public static final String SEPERATOR_MF_ATTRIBUTE = ":"; +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java new file mode 100644 index 0000000000..d88d883e67 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/csar/OnboardingManifest.java @@ -0,0 +1,141 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import org.apache.commons.lang.StringUtils; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; + +import java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.*; + +import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CSARConstants.*; + +public class OnboardingManifest { + private static final Logger logger = LoggerFactory.getLogger(OnboardingManifest.class); + private Map<String, String> metadata; + private List<String> sources; + private List<String> errors; + private State state; + private enum State { + Start, ProcessMetadata, ProcessSources, Error + } + + public OnboardingManifest(InputStream is) { + errors = new ArrayList<>(); + sources = new ArrayList<>(); + metadata = new HashMap<>(); + parseManifest(is); + } + + private void parseManifest(InputStream is) { + try { + ImmutableList<String> lines = readAllLines(is); + state = State.Start; + + for (String line : lines) { + line = line.trim(); + if (!StringUtils.isEmpty(line.trim())) { + state = processLine(state, line); + } + } + if (errors.isEmpty()) { + if (metadata.isEmpty()) { + errors.add(Messages.MANIFEST_NO_METADATA.getErrorMessage()); + } + if (sources.isEmpty()) { + errors.add(Messages.MANIFEST_NO_SOURCES.getErrorMessage()); + } + } + } catch (IOException e){ + logger.error(e.getMessage(),e); + errors.add(Messages.MANIFEST_PARSER_INTERNAL.getErrorMessage()); + } + } + + private State processLine(State state, String line) { + switch (state) { + case Start: + if (line.trim().equals(METADATA_MF_ATTRIBUTE + SEPERATOR_MF_ATTRIBUTE)) { + state = State.ProcessMetadata; + } else { + reportError(line); + } + break; + case ProcessMetadata: + String[] metaSplit = line.split(SEPERATOR_MF_ATTRIBUTE); + if (metaSplit.length < 2){ + reportError(line); + break; + } + if (!metaSplit[0].equals(SOURCE_MF_ATTRIBUTE)){ + String value = line.replace(metaSplit[0] + SEPERATOR_MF_ATTRIBUTE, "").trim(); + metadata.put(metaSplit[0],value); + } else { + state = State.ProcessSources; + processSourceLine(line); + } + break; + case ProcessSources: + processSourceLine(line); + + break; + case Error: + break; + + } return state; + } + + private void processSourceLine(String line) { + if (line.startsWith(SOURCE_MF_ATTRIBUTE+SEPERATOR_MF_ATTRIBUTE)){ + String value = line.replaceAll(SOURCE_MF_ATTRIBUTE + SEPERATOR_MF_ATTRIBUTE, "").trim(); + sources.add(value); + }else { + reportError(line); + } + } + + private void reportError(String line) { + errors.add(getErrorWithParameters(Messages.MANIFEST_INVALID_LINE.getErrorMessage(), line)); + state = State.Error; + } + + private ImmutableList<String> readAllLines(InputStream is) throws IOException { + ImmutableList.Builder<String> builder = ImmutableList.<String> builder(); + try (Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8.newDecoder()); + BufferedReader bufferedReader = new BufferedReader(reader);) { + for (; ; ) { + String line = bufferedReader.readLine(); + if (line == null) + break; + builder.add(line); + } + } + return builder.build(); + } + + public Map<String, String> getMetadata() { + if (!isValid()){ + return Collections.EMPTY_MAP; + } + return ImmutableMap.copyOf(metadata); + } + + public List<String> getSources() { + if (!isValid()){ + return Collections.EMPTY_LIST; + } + return ImmutableList.copyOf(sources); + } + + public List<String> getErrors() { + return ImmutableList.copyOf(errors); + } + + public boolean isValid() { + return errors.isEmpty(); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java new file mode 100644 index 0000000000..db43e0084e --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationProcessFactory.java @@ -0,0 +1,64 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; + +import org.openecomp.config.api.Configuration; +import org.openecomp.config.api.ConfigurationManager; +import org.openecomp.core.utilities.CommonMethods; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration; +import org.openecomp.sdc.vendorsoftwareproduct.types.ConfigConstants; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; + +import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil.ORCHESTRATION_CONFIG_NAMESPACE; +public class OrchestrationProcessFactory { + + private static final String confFile = "config-orchestration.json"; + private static Map<String, ImplementationConfiguration> processImplMap; + + static { + Configuration config = ConfigurationManager.lookup(); + processImplMap = new ConcurrentHashMap<>(config.populateMap(ORCHESTRATION_CONFIG_NAMESPACE, + ConfigConstants.PROCESS_IMPL_KEY, ImplementationConfiguration.class)); + + } + + public static Optional<OrchestrationTemplateProcessHandler> getInstance(String filePrefix) { + filePrefix = filePrefix == null ? null : filePrefix.toLowerCase().trim(); + if (filePrefix == null) { + return Optional.empty(); + } + + OnboardingTypesEnum onboardingTypesEnum = OnboardingTypesEnum.getOnboardingTypesEnum(filePrefix); + if (onboardingTypesEnum == null) { + return Optional.empty(); + } + + try { + return Optional.of(createInstance(processImplMap.get(onboardingTypesEnum.toString()))); + }catch (Exception e){ + return Optional.empty(); + } + } + + private static Map<String, String> getOrchestrationImplMap(){ + try { + return FileUtils.readViaInputStream(confFile, + stream -> JsonUtil.json2Object(stream, Map.class)); + }catch (Exception e){ + return new HashMap<>(); + } + } + + private static OrchestrationTemplateProcessHandler createInstance(ImplementationConfiguration implClass) + throws Exception { + OrchestrationTemplateProcessHandler handler; + handler = + CommonMethods.newInstance(implClass.getImplementationClass(), OrchestrationTemplateProcessHandler.class); + return handler; + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java new file mode 100644 index 0000000000..4866d93411 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessCsarHandler.java @@ -0,0 +1,133 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; + +import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.converter.ToscaConverter; +import org.openecomp.core.impl.ToscaConverterImpl; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.core.validation.util.MessageContainerUtil; +import org.openecomp.sdc.common.errors.CoreException; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.heat.services.tree.ToscaTreeManager; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.logging.messages.AuditMessages; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CandidateServiceFactory; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class OrchestrationTemplateProcessCsarHandler implements OrchestrationTemplateProcessHandler { + + private static Logger logger = + LoggerFactory.getLogger(OrchestrationTemplateProcessCsarHandler.class); + private ToscaConverter toscaConverter = new ToscaConverterImpl(); + private CandidateService candidateService = + CandidateServiceFactory.getInstance().createInterface(); + ToscaTreeManager toscaTreeManager = new ToscaTreeManager(); + + @Override + public OrchestrationTemplateActionResponse process(VspDetails vspDetails, + OrchestrationTemplateCandidateData candidateData, + String user) { + String vspId = vspDetails.getId(); + Version version = vspDetails.getVersion(); + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.CSAR_VALIDATION_STARTED + vspId); + OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); + UploadFileResponse uploadFileResponse = new UploadFileResponse(); + Optional<FileContentHandler> fileContent = + OrchestrationUtil + .getFileContentMap( + OnboardingTypesEnum.CSAR, uploadFileResponse, candidateData.getContentData().array()); + + if(fileContent.isPresent()){ + try { + FileContentHandler fileContentHandler = fileContent.get(); + processCsar(vspId, version, fileContentHandler, candidateData, response); + } catch (CoreException e){ + logger.error(e.getMessage()); + throw e; + } catch (Exception e){ + logger.error(e.getMessage()); + } + } + + return response; + } + + private void processCsar(String vspId, Version version, + FileContentHandler fileContentHandler, + OrchestrationTemplateCandidateData candidateData, + OrchestrationTemplateActionResponse response) throws IOException { + + + response.setFileNames(new ArrayList<>(fileContentHandler.getFileList())); + Map<String, List<ErrorMessage>> errors = validateCsar(fileContentHandler, response); + if(!isValid(errors)){ + return; + } + + HeatStructureTree tree = toscaTreeManager.getTree(); + + Map<String, String> componentsQuestionnaire = new HashMap<>(); + Map<String, Map<String, String>> componentNicsQuestionnaire = new HashMap<>(); + Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList = new HashMap<>(); + Map<String, Collection<ProcessEntity>> processes = new HashMap<>(); + Map<String, ProcessEntity> processArtifact = new HashMap<>(); + + OrchestrationUtil.backupComponentsQuestionnaireBeforeDelete(vspId, + version, componentsQuestionnaire, + componentNicsQuestionnaire, componentMibList, processes, processArtifact); + + Optional<ByteArrayInputStream> zipByteArrayInputStream = candidateService + .fetchZipFileByteArrayInputStream(vspId, candidateData, null, OnboardingTypesEnum.CSAR, errors); + + OrchestrationUtil.deleteUploadDataAndContent(vspId, version); + OrchestrationUtil.saveUploadData( + vspId, version, zipByteArrayInputStream.get(), fileContentHandler, tree); + + ToscaServiceModel toscaServiceModel = toscaConverter.convert(fileContentHandler); + OrchestrationUtil.saveServiceModel(vspId, version, toscaServiceModel, toscaServiceModel); + + } + + private void addFiles(FileContentHandler fileContentHandler){ + for(Map.Entry<String, byte[]> fileEntry : fileContentHandler.getFiles().entrySet()){ + toscaTreeManager.addFile(fileEntry.getKey(), fileEntry.getValue()); + } + } + + private Map<String, List<ErrorMessage>> validateCsar(FileContentHandler fileContentHandler, + OrchestrationTemplateActionResponse response){ + + + Map<String, List<ErrorMessage>> errors = new HashMap<>(); + addFiles(fileContentHandler); + toscaTreeManager.createTree(); + toscaTreeManager.addErrors(errors); + //todo - add tosca validation here to the existing validation framework + return errors; + } + + private boolean isValid(Map<String, List<ErrorMessage>> errors){ + return MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, errors)); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessHandler.java new file mode 100644 index 0000000000..8b513b4347 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessHandler.java @@ -0,0 +1,12 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; + + +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; + +public interface OrchestrationTemplateProcessHandler { + OrchestrationTemplateActionResponse process(VspDetails vspDetails, + OrchestrationTemplateCandidateData candidateData, + String user); +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java new file mode 100644 index 0000000000..cceacd47b3 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/process/OrchestrationTemplateProcessZipHandler.java @@ -0,0 +1,184 @@ +package org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.openecomp.core.model.dao.ServiceModelDao; +import org.openecomp.core.model.dao.ServiceModelDaoFactory; +import org.openecomp.core.translator.datatypes.TranslatorOutput; +import org.openecomp.core.utilities.file.FileContentHandler; +import org.openecomp.core.utilities.json.JsonUtil; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.core.validation.util.MessageContainerUtil; +import org.openecomp.sdc.activityLog.ActivityLogManager; +import org.openecomp.sdc.activityLog.ActivityLogManagerFactory; +import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.common.utils.SdcCommon; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree; +import org.openecomp.sdc.logging.api.Logger; +import org.openecomp.sdc.logging.api.LoggerFactory; +import org.openecomp.sdc.logging.context.impl.MdcDataDebugMessage; +import org.openecomp.sdc.logging.messages.AuditMessages; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil; +import org.openecomp.sdc.validation.util.ValidationManagerUtil; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentMonitoringUploadEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateCandidateData; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CandidateServiceFactory; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionDataExtractorFactory; +import org.openecomp.sdc.vendorsoftwareproduct.factory.CompositionEntityDataManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationUtil; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; +import org.openecomp.sdc.vendorsoftwareproduct.types.OrchestrationTemplateActionResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.vendorsoftwareproduct.types.candidateheat.FilesDataStructure; +import org.openecomp.sdc.vendorsoftwareproduct.utils.VendorSoftwareProductUtils; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdcrests.activitylog.types.ActivityType; + +import java.io.ByteArrayInputStream; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static org.openecomp.sdc.logging.messages.AuditMessages.HEAT_VALIDATION_ERROR; + +public class OrchestrationTemplateProcessZipHandler implements OrchestrationTemplateProcessHandler { + Logger logger = LoggerFactory.getLogger(OrchestrationTemplateProcessZipHandler.class); + private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + private CandidateService candidateService = + CandidateServiceFactory.getInstance().createInterface(); + private ServiceModelDao serviceModelDao = ServiceModelDaoFactory.getInstance().createInterface(); + private CompositionEntityDataManager compositionEntityDataManager = + CompositionEntityDataManagerFactory.getInstance().createInterface(); + private CompositionDataExtractor compositionDataExtractor = + CompositionDataExtractorFactory.getInstance().createInterface(); + private ActivityLogManager activityLogManager = + ActivityLogManagerFactory.getInstance().createInterface(); + + + public OrchestrationTemplateProcessZipHandler(){} + + public OrchestrationTemplateActionResponse process(VspDetails vspDetails, + OrchestrationTemplateCandidateData candidateData, + String user) { + String vspId = vspDetails.getId(); + Version version = vspDetails.getVersion(); + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_VALIDATION_STARTED + + vspId); + OrchestrationTemplateActionResponse response = new OrchestrationTemplateActionResponse(); + UploadFileResponse uploadFileResponse = new UploadFileResponse(); + Optional<FileContentHandler> fileContent = + OrchestrationUtil + .getFileContentMap( + OnboardingTypesEnum.ZIP, uploadFileResponse, candidateData.getContentData().array()); + if (!fileContent.isPresent()) { + response.addStructureErrors(uploadFileResponse.getErrors()); + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, + HEAT_VALIDATION_ERROR)); + return response; + } + + Map<String, List<ErrorMessage>> uploadErrors = uploadFileResponse.getErrors(); + FileContentHandler fileContentMap = fileContent.get(); + FilesDataStructure structure = + JsonUtil.json2Object(candidateData.getFilesDataStructure(), FilesDataStructure.class); + + if (CollectionUtils.isNotEmpty(structure.getUnassigned())) { + response.addErrorMessageToMap(SdcCommon.UPLOAD_FILE, + Messages.FOUND_UNASSIGNED_FILES.getErrorMessage(), ErrorLevel.ERROR); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, + HEAT_VALIDATION_ERROR)); + return response; + } + + + String manifest = candidateService.createManifest(vspDetails, structure); + fileContentMap.addFile(SdcCommon.MANIFEST_NAME, manifest.getBytes()); + + Optional<ByteArrayInputStream> zipByteArrayInputStream = candidateService + .fetchZipFileByteArrayInputStream( + vspId, candidateData, manifest, OnboardingTypesEnum.ZIP, uploadErrors); + if (!zipByteArrayInputStream.isPresent()) { + response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, + HEAT_VALIDATION_ERROR)); + return response; + } + + HeatStructureTree tree = createAndValidateHeatTree(response, fileContentMap); + + Map<String, String> componentsQuestionnaire = new HashMap<>(); + Map<String, Map<String, String>> componentNicsQuestionnaire = new HashMap<>(); + Map<String, Collection<ComponentMonitoringUploadEntity>> componentMibList = new HashMap<>(); + Map<String, Collection<ProcessEntity>> processes = new HashMap<>(); + Map<String, ProcessEntity> processArtifact = new HashMap<>(); + + OrchestrationUtil.backupComponentsQuestionnaireBeforeDelete(vspId, + version, componentsQuestionnaire, + componentNicsQuestionnaire, componentMibList, processes, processArtifact); + + OrchestrationUtil.deleteUploadDataAndContent(vspId, version); + OrchestrationUtil.saveUploadData(vspId, version, zipByteArrayInputStream.get(), fileContentMap, + tree); + + response.getErrors().values().forEach(errorList -> printAuditForErrors(errorList,vspId, + HEAT_VALIDATION_ERROR)); + if ( MapUtils.isEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, response.getErrors + ()))) { + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_VALIDATION_COMPLETED + vspId); + } + + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_STARTED + vspId); + + TranslatorOutput translatorOutput = + HeatToToscaUtil.loadAndTranslateTemplateData(fileContentMap); + + ToscaServiceModel toscaServiceModel = translatorOutput.getToscaServiceModel(); + OrchestrationUtil.saveServiceModel(vspId, version, translatorOutput + .getNonUnifiedToscaServiceModel(), toscaServiceModel); + OrchestrationUtil.retainComponentQuestionnaireData(vspId, version, componentsQuestionnaire, + componentNicsQuestionnaire, componentMibList, processes, processArtifact); + + logger.audit(AuditMessages.AUDIT_MSG + AuditMessages.HEAT_TRANSLATION_COMPLETED + vspId); + uploadFileResponse.addStructureErrors(uploadErrors); + + ActivityLogEntity activityLogEntity = + new ActivityLogEntity(vspId, String.valueOf(version.getMajor() + 1), + ActivityType.UPLOAD_HEAT.toString(), user, true, "", ""); + activityLogManager.addActionLog(activityLogEntity, user); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspId); + return response; + } + + private HeatStructureTree createAndValidateHeatTree(OrchestrationTemplateActionResponse response, + FileContentHandler fileContentMap) { + VendorSoftwareProductUtils.addFileNamesToUploadFileResponse(fileContentMap, response); + Map<String, List<ErrorMessage>> validationErrors = + ValidationManagerUtil.initValidationManager(fileContentMap).validate(); + response.getErrors().putAll(validationErrors); + + return OrchestrationUtil.createHeatTree(fileContentMap, validationErrors); + } + + private void printAuditForErrors(List<ErrorMessage> errorList, String vspId, String auditType) { + + errorList.forEach(errorMessage -> { + if (errorMessage.getLevel().equals(ErrorLevel.ERROR)) { + logger.audit(AuditMessages.AUDIT_MSG + String.format(auditType, errorMessage.getMessage(), + vspId)); + } + }); + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ConfigConstants.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ConfigConstants.java new file mode 100644 index 0000000000..85c6fcb7b5 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ConfigConstants.java @@ -0,0 +1,6 @@ +package org.openecomp.sdc.vendorsoftwareproduct.types; + +public class ConfigConstants { + public static final String NAMESPACE = "Orchestration"; + public static final String PROCESS_IMPL_KEY = "process_impl"; +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java index 99f3fa1fdf..ca0eed2153 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/UploadFileResponse.java @@ -21,6 +21,7 @@ package org.openecomp.sdc.vendorsoftwareproduct.types; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; @@ -35,6 +36,8 @@ import java.util.Map; public class UploadFileResponse { private Map<String, List<ErrorMessage>> errors = new HashMap<>(); private UploadFileStatus status = UploadFileStatus.Success; + private OnboardingTypesEnum onboardingType; + private String networkPackageName; public UploadFileStatus getStatus() { return status; @@ -44,6 +47,22 @@ public class UploadFileResponse { this.status = status; } + public OnboardingTypesEnum getOnboardingType() { + return onboardingType; + } + + public void setOnboardingType(OnboardingTypesEnum onboardingTypesEnum) { + this.onboardingType = onboardingTypesEnum; + } + + public String getNetworkPackageName() { + return networkPackageName; + } + + public void setNetworkPackageName(String networkPackageName) { + this.networkPackageName = networkPackageName; + } + /** * Add structure error. * diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ValidationResponse.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ValidationResponse.java index ea5bef13dc..09e7a40ec5 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ValidationResponse.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/types/ValidationResponse.java @@ -41,9 +41,6 @@ public class ValidationResponse { private Map<String, List<ErrorMessage>> uploadDataErrors; private Map<String, List<ErrorMessage>> compilationErrors; private QuestionnaireValidationResult questionnaireValidationResult; - private ComponentValidationResult componentValidationResult; - private DeploymentFlavorValidationResult deploymentFlavorValidationResult; - public boolean isValid() { return valid; @@ -106,7 +103,7 @@ public class ValidationResponse { } VendorSoftwareProductUtils - .setErrorsIntoLogger(uploadDataErrors, serviceName, targetServiceName); + .setErrorsIntoLogger(uploadDataErrors, serviceName, targetServiceName); } public Map<String, List<ErrorMessage>> getCompilationErrors() { @@ -128,7 +125,7 @@ public class ValidationResponse { } VendorSoftwareProductUtils - .setErrorsIntoLogger(uploadDataErrors, serviceName, targetServiceName); + .setErrorsIntoLogger(uploadDataErrors, serviceName, targetServiceName); } public QuestionnaireValidationResult getQuestionnaireValidationResult() { @@ -141,48 +138,10 @@ public class ValidationResponse { * @param questionnaireValidationResult the questionnaire validation result */ public void setQuestionnaireValidationResult( - QuestionnaireValidationResult questionnaireValidationResult) { + QuestionnaireValidationResult questionnaireValidationResult) { this.questionnaireValidationResult = questionnaireValidationResult; if (questionnaireValidationResult != null && !questionnaireValidationResult.isValid()) { valid = false; } } - - - public ComponentValidationResult getComponentValidationResult() { - return componentValidationResult; - } - - /** - * Sets Component validation result. - * - * @param componentValidationResult the Component validation result - */ - public void setComponentValidationResult( - ComponentValidationResult componentValidationResult) { - this.componentValidationResult = componentValidationResult; - if (componentValidationResult != null && !componentValidationResult.isValid()) { - valid = false; - } - } - - - public DeploymentFlavorValidationResult getDeploymentFlavorValidationResult() { - return deploymentFlavorValidationResult; - } - - /** - * Sets Deployment validation result. - * - * @param deploymentFlavorValidationResult the Deployment validation result - */ - public void setDeploymentFlavorValidationResult( - DeploymentFlavorValidationResult deploymentFlavorValidationResult) { - this.deploymentFlavorValidationResult = deploymentFlavorValidationResult; - if (deploymentFlavorValidationResult != null && !deploymentFlavorValidationResult.isValid()) { - valid = false; - } - } - - } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/config-orchestration.json b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/config-orchestration.json new file mode 100644 index 0000000000..9193b818b7 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/config-orchestration.json @@ -0,0 +1,26 @@ +{ + "orchestration_impl": { + "zip": { + "enable": true, + "implementationClass": "org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationTemplateZipHandler" + }, + "csar": { + "enable": true, + "implementationClass": "org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.OrchestrationTemplateCSARHandler" + } + }, + "process_impl": { + "zip" : { + "enzble": true, + "implementationClass" : "org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationTemplateProcessZipHandler" + }, + "csar": { + "enable": true, + "implementationClass": "org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.OrchestrationTemplateProcessCsarHandler" + } + }, + + "_config":{ + "namespace": "orchestration" + } +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/orchestrationConfiguration.json b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/orchestrationConfiguration.json new file mode 100644 index 0000000000..7509094b56 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/resources/orchestrationConfiguration.json @@ -0,0 +1,3 @@ +{ + "zip" :"org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.process.orchestrationTemplateProcessZipHandler" +}
\ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ImagesTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ImagesTest.java index afd797573a..5dcb7f9b62 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ImagesTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/ImagesTest.java @@ -1,32 +1,70 @@ package org.openecomp.sdc.vendorsoftwareproduct; -import org.openecomp.core.utilities.CommonMethods; -import org.openecomp.core.utilities.json.JsonUtil; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; import org.openecomp.sdc.common.errors.CoreException; -import org.openecomp.sdc.common.errors.ErrorCode; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDaoFactory; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; -import org.openecomp.sdc.vendorsoftwareproduct.errors.ImageErrorBuilder; -import org.openecomp.sdc.vendorsoftwareproduct.errors.NotSupportedHeatOnboardMethodErrorBuilder; import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; -import org.openecomp.sdc.vendorsoftwareproduct.impl.VendorSoftwareProductManagerImpl; -import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; -import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; -import org.openecomp.sdc.vendorsoftwareproduct.types.composition.Image; -import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.image.ImageDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.ImageManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.errors.VersioningErrorCodes; import org.testng.Assert; -import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.util.Collection; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.verify; public class ImagesTest { + private static String VSP_ID = "VSP_ID"; + private static String COMP_ID = "COMP_ID"; + private static String ID = "ID"; + private static String USER = "USER"; + public static final Version VERSION01 = new Version(0, 1); + + @Mock + private VendorSoftwareProductInfoDao vendorSoftwareProductInfoDao; + + @Mock + private CompositionEntityDataManager compositionEntityDataManager; + + @InjectMocks + @Spy + private ImageManagerImpl imageManager; + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void createImage() + { + ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID); + doReturn(true).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject()); + + imageManager.createImage(imageEntity, USER); + verify(compositionEntityDataManager).createImage(imageEntity); + } + + @Test + public void createImageHeat() + { + ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION01, COMP_ID, ID); + doReturn(false).when(vendorSoftwareProductInfoDao).isManual(anyObject(), anyObject()); + + try { + imageManager.createImage(imageEntity, USER); + Assert.fail(); + } catch (CoreException exception) { + Assert.assertEquals(exception.code().id(), VendorSoftwareProductErrorCodes.ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING); + } + } /*private static final String USER1 = "imageTestUser1"; private static final String USER2 = "imageTestUser2"; private static final Version VERSION01 = new Version(0, 1); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java index 948d46ba10..3e42a23c6a 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/QuestionnaireDataServiceTest.java @@ -48,7 +48,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.types.questionnaire.component.Com import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.io.InputStream; import java.util.List; @@ -112,7 +111,7 @@ public class QuestionnaireDataServiceTest { public void testQuestionnaireDataAfterIllegalUpload() { InputStream zipInputStream = uploadFileTest.getZipInputStream("/missingYml"); UploadFileResponse uploadFileResponse = candidateManager - .upload(vspId, VERSION, zipInputStream, USER1); + .upload(vspId, VERSION, zipInputStream, USER1, "zip", "missingYml"); InformationArtifactData informationArtifactData = questionnaireDataService .generateQuestionnaireDataForInformationArtifact(vspId, vspActiveVersion); @@ -124,7 +123,7 @@ public class QuestionnaireDataServiceTest { InputStream zipInputStream = uploadFileTest.getZipInputStream(filePath); UploadFileResponse uploadFileResponse = candidateManager .upload(vspId, VERSION, - zipInputStream, USER1); + zipInputStream, USER1,"zip", "file"); candidateManager.process(vspId, VERSION, USER1); Assert.assertTrue(MapUtils.isEmpty( diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java index d617bf9a47..741b1bf2ea 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/ImageManagerImplTest.java @@ -37,9 +37,9 @@ import static org.mockito.Mockito.verify; public class ImageManagerImplTest { private static final String IMAGE_NOT_EXIST_MSG = - "Vendor Software Product Image with Id image1 does not exist for Vendor Software Product with" + - " " + - "id VSP_ID and version 0.1"; + "Vendor Software Product Image with Id image1 does not exist for Vendor Software Product with" + + " " + + "id VSP_ID and version 0.1"; private static final String USER = "imageTestUser"; private static final String VSP_ID = "VSP_ID"; @@ -66,7 +66,7 @@ public class ImageManagerImplTest { @Test public void testListWhenNone() { final Collection<ImageEntity> imageEntities = - imageManager.listImages(VSP_ID, VERSION, COMPONENT_ID, USER); + imageManager.listImages(VSP_ID, VERSION, COMPONENT_ID, USER); Assert.assertEquals(imageEntities.size(), 0); } @@ -74,17 +74,17 @@ public class ImageManagerImplTest { public void testList() { doReturn(Arrays.asList( - createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID), - createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE2_ID))) - .when(imageDao).list(anyObject()); + createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID), + createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE2_ID))) + .when(imageDao).list(anyObject()); final Collection<ImageEntity> images = - imageManager.listImages(VSP_ID, VERSION, COMPONENT_ID, USER); + imageManager.listImages(VSP_ID, VERSION, COMPONENT_ID, USER); Assert.assertEquals(images.size(), 2); for (ImageEntity image : images) { Assert.assertEquals(image.getImageCompositionData().getFileName(), - IMAGE1_ID.equals(image.getId()) ? IMAGE1_ID+"_name" : IMAGE2_ID+"_name" ); + IMAGE1_ID.equals(image.getId()) ? IMAGE1_ID+"_name" : IMAGE2_ID+"_name" ); } } @@ -92,7 +92,7 @@ public class ImageManagerImplTest { public void testCreateOnNotManualImage_negative() { testCreate_negative(new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, null), USER, - VendorSoftwareProductErrorCodes.ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING); + VendorSoftwareProductErrorCodes.ADD_IMAGE_NOT_ALLOWED_IN_HEAT_ONBOARDING); } @Test @@ -104,7 +104,7 @@ public class ImageManagerImplTest { verify(compositionEntityDataManagerMock).createImage(expected); } - @Test + /*@Test public void testCreateManualImageWithDuplicateName() { ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); @@ -124,22 +124,22 @@ public class ImageManagerImplTest { Assert.assertEquals(VendorSoftwareProductErrorCodes.DUPLICATE_IMAGE_NAME_NOT_ALLOWED, ex.code().id()); } - } + }*/ @Test public void testUpdateNonExistingImageId_negative() { testUpdate_negative(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER, - VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @Test public void testUpdateImage() { doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)) - .when(imageDao).get(anyObject()); + .when(imageDao).get(anyObject()); doReturn(new CompositionEntityValidationData(CompositionEntityType.image, IMAGE1_ID)) - .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .when(compositionEntityDataManagerMock) + .validateEntity(anyObject(), anyObject(), anyObject()); ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); Image imageData = new Image(); @@ -148,7 +148,7 @@ public class ImageManagerImplTest { imageEntity.setImageCompositionData(imageData); CompositionEntityValidationData validationData = - imageManager.updateImage(imageEntity, USER); + imageManager.updateImage(imageEntity, USER); Assert.assertTrue(validationData == null || validationData.getErrors() == null); verify(imageDao).update(imageEntity); } @@ -156,16 +156,16 @@ public class ImageManagerImplTest { @Test public void testIllegalImageUpdate() { doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)) - .when(imageDao).get(anyObject()); + .when(imageDao).get(anyObject()); doReturn(true).when(vspInfoDao).isManual(anyObject(), anyObject()); CompositionEntityValidationData toBeReturned = - new CompositionEntityValidationData(CompositionEntityType.image, IMAGE1_ID); + new CompositionEntityValidationData(CompositionEntityType.image, IMAGE1_ID); toBeReturned.setErrors(Arrays.asList("error1", "error2")); doReturn(toBeReturned) - .when(compositionEntityDataManagerMock) - .validateEntity(anyObject(), anyObject(), anyObject()); + .when(compositionEntityDataManagerMock) + .validateEntity(anyObject(), anyObject(), anyObject()); ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); Image imageData = new Image(); @@ -183,7 +183,7 @@ public class ImageManagerImplTest { @Test public void testUpdateHEATImageFileName() throws Exception { doReturn(createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID)) - .when(imageDao).get(anyObject()); + .when(imageDao).get(anyObject()); ImageEntity imageEntity = new ImageEntity(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); Image imageData = new Image(); imageData.setFileName(IMAGE1_ID + " name updated"); @@ -202,7 +202,7 @@ public class ImageManagerImplTest { @Test public void testGetNonExistingImageId_negative() { testGet_negative(VSP_ID, VERSION, COMPONENT_ID, "non existing image id", USER, - VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @Test @@ -213,12 +213,12 @@ public class ImageManagerImplTest { doReturn(compositionSchema).when(imageManager).getImageCompositionSchema(anyObject()); CompositionEntityResponse<Image> response = - imageManager.getImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER); + imageManager.getImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER); Assert.assertEquals(response.getId(), expected.getId()); Assert.assertEquals(response.getData().getFileName(), expected.getImageCompositionData(). - getFileName()); + getFileName()); Assert.assertEquals(response.getData().getDescription(), expected.getImageCompositionData(). - getDescription()); + getDescription()); Assert.assertEquals(response.getSchema(), compositionSchema); } @@ -227,13 +227,13 @@ public class ImageManagerImplTest { ImageEntity expected = createImage(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID); doReturn(expected).when(imageDao).get(anyObject()); testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER, - VendorSoftwareProductErrorCodes.DELETE_IMAGE_NOT_ALLOWED); + VendorSoftwareProductErrorCodes.DELETE_IMAGE_NOT_ALLOWED); } @Test public void testDeleteOnNotExistImage() { testDelete_negative(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER, - VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); + VersioningErrorCodes.VERSIONABLE_SUB_ENTITY_NOT_FOUND); } @Test @@ -255,7 +255,7 @@ public class ImageManagerImplTest { doReturn(schema).when(imageManager).getImageQuestionnaireSchema(anyObject()); QuestionnaireResponse questionnaire = - imageManager.getImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER); + imageManager.getImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, USER); Assert.assertNotNull(questionnaire); Assert.assertEquals(questionnaire.getData(), image.getQuestionnaireData()); Assert.assertEquals(questionnaire.getSchema(), schema); @@ -334,7 +334,7 @@ public class ImageManagerImplTest { String updJson = "{\"format\" :\"a22\"}"; try { imageManager.updateImageQuestionnaire(VSP_ID, VERSION, COMPONENT_ID, IMAGE1_ID, updJson, - USER); + USER); Assert.fail(); } catch(CoreException ex) { @@ -383,7 +383,7 @@ public class ImageManagerImplTest { } private void testUpdate_negative(String vspId, Version version, String componentId, String - imageId, String user, String expectedErrorCode) { + imageId, String user, String expectedErrorCode) { try { imageManager.updateImage(new ImageEntity(vspId, version, componentId, imageId), user); Assert.fail(); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java index e6d06f2e2c..252e152740 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/OrchestrationTemplateCandidateManagerImplTest.java @@ -6,6 +6,7 @@ import org.mockito.MockitoAnnotations; import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; @@ -23,7 +24,6 @@ import org.openecomp.sdc.vendorsoftwareproduct.utils.ZipFileUtils; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.Assert; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; import java.io.IOException; import java.nio.ByteBuffer; @@ -90,7 +90,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { doReturn("{}").when(candidateServiceMock).createManifest(anyObject(), anyObject()); doReturn(Optional.empty()).when(candidateServiceMock) - .fetchZipFileByteArrayInputStream(anyObject(), anyObject(), anyObject(), anyObject()); + .fetchZipFileByteArrayInputStream(anyObject(), anyObject(), anyObject(), OnboardingTypesEnum.ZIP, anyObject()); OrchestrationTemplateActionResponse response = @@ -123,7 +123,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { UploadFileResponse uploadFileResponse = candidateManager .upload(VSP_ID, VERSION01, new ZipFileUtils().getZipInputStream("/legalUploadWithWarning"), - USER1); + USER1, "zip", "legalUploadWithWarning"); Assert.assertTrue(uploadFileResponse.getStatus() == UploadFileStatus.Success); Assert.assertTrue( uploadFileResponse.getErrors().get("uploadFile").get(0).getLevel() == ErrorLevel.WARNING); @@ -136,7 +136,7 @@ public class OrchestrationTemplateCandidateManagerImplTest { public void testUploadWithManifest() { UploadFileResponse uploadFileResponse = candidateManager .upload(VSP_ID, VERSION01, new ZipFileUtils().getZipInputStream("/legalUploadWithWarning"), - USER1); + USER1, "zip", "legalUploadWithWarning"); Assert.assertTrue(uploadFileResponse.getStatus() == UploadFileStatus.Success); Assert.assertTrue( uploadFileResponse.getErrors().get("uploadFile").get(0).getLevel() == ErrorLevel.WARNING); diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java index 2fc4385563..e0e00f8d9d 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/impl/VendorSoftwareProductManagerImplTest.java @@ -39,7 +39,6 @@ import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.common.errors.ErrorCategory; import org.openecomp.sdc.common.errors.ErrorCode; import org.openecomp.sdc.common.errors.Messages; -import org.openecomp.sdc.common.errors.ValidationErrorBuilder; import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.tosca.datatypes.model.CapabilityDefinition; @@ -54,14 +53,10 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.PackageInfoDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.PackageInfo; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.UploadDataEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; -import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspQuestionnaireEntity; -import org.openecomp.sdc.vendorsoftwareproduct.errors.VendorSoftwareProductErrorCodes; import org.openecomp.sdc.vendorsoftwareproduct.impl.mock.EnrichmentManagerFactoryImpl; import org.openecomp.sdc.vendorsoftwareproduct.informationArtifact.InformationArtifactGenerator; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; @@ -92,7 +87,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -169,10 +163,10 @@ public class VendorSoftwareProductManagerImplTest { @Test public void testListWhenNone() { doReturn(new HashMap<>()).when(versioningManagerMock).listEntitiesVersionInfo - (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, - VersionableEntityAction.Read); + (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, + VersionableEntityAction.Read); List<VersionedVendorSoftwareProductInfo> vsps = - vendorSoftwareProductManager.listVsps(null, USER1); + vendorSoftwareProductManager.listVsps(null, USER1); Assert.assertEquals(vsps.size(), 0); } @@ -191,16 +185,16 @@ public class VendorSoftwareProductManagerImplTest { vspsTobeReturned.put(vsp2id, versionInfo2); doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo - (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, - VersionableEntityAction.Read); + (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, + VersionableEntityAction.Read); VspDetails vsp1 = new VspDetails(vsp1id, VERSION01); vsp1.setWritetimeMicroSeconds(8L); doReturn(vsp1).when(vspInfoDaoMock) - .get(any(VspDetails.class)); + .get(any(VspDetails.class)); List<VersionedVendorSoftwareProductInfo> vsps = - vendorSoftwareProductManager.listVsps(null, USER1); + vendorSoftwareProductManager.listVsps(null, USER1); Assert.assertEquals(vsps.size(), 2); } @@ -219,11 +213,11 @@ public class VendorSoftwareProductManagerImplTest { vspsTobeReturned.put(vsp2id, versionInfo2); doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo - (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, - VersionableEntityAction.Read); + (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, + VersionableEntityAction.Read); List<VersionedVendorSoftwareProductInfo> vsps = - vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1); + vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1); Assert.assertEquals(vsps.size(), 0); } @@ -243,27 +237,27 @@ public class VendorSoftwareProductManagerImplTest { vspsTobeReturned.put(vsp2id, versionInfo2); doReturn(vspsTobeReturned).when(versioningManagerMock).listEntitiesVersionInfo - (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, - VersionableEntityAction.Read); + (VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, USER1, + VersionableEntityAction.Read); VspDetails vsp2 = new VspDetails(vsp2id, VERSION10); vsp2.setWritetimeMicroSeconds(8L); doReturn(vsp2).when(vspInfoDaoMock) - .get(any(VspDetails.class)); + .get(any(VspDetails.class)); List<VersionedVendorSoftwareProductInfo> vsps = - vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1); + vendorSoftwareProductManager.listVsps(VersionStatus.Final.name(), USER1); Assert.assertEquals(vsps.size(), 1); } @Test(expectedExceptions = CoreException.class) public void testCreateWithExistingName_negative() { doThrow(new CoreException( - new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build())) - .when(vendorSoftwareProductManager).validateUniqueName("Vsp1"); + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build())) + .when(vendorSoftwareProductManager).validateUniqueName("Vsp1"); VspDetails expectedVsp = - createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", - "category", "subCategory", "123", null); + createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", + "category", "subCategory", "123", null); vendorSoftwareProductManager.createVsp(expectedVsp, USER1); } @@ -274,11 +268,11 @@ public class VendorSoftwareProductManagerImplTest { doNothing().when(vendorSoftwareProductManager).createUniqueName("Vsp1"); doReturn(VERSION01).when(versioningManagerMock).create(anyObject(), anyObject(), anyObject()); doReturn("{}") - .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject()); + .when(vendorSoftwareProductManager).getVspQuestionnaireSchema(anyObject()); VspDetails vspToCreate = - createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", - "category", "subCategory", "123", null); + createVspDetails(null, null, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", + "category", "subCategory", "123", null); VspDetails vsp = vendorSoftwareProductManager.createVsp(vspToCreate, USER1); @@ -297,21 +291,21 @@ public class VendorSoftwareProductManagerImplTest { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(VERSION01); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - VersionableEntityAction.Write); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + VersionableEntityAction.Write); VspDetails existingVsp = - createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id", - "icon", "category", "subCategory", "123", null); + createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-existingVsp", "vendorName", "vlm1Id", + "icon", "category", "subCategory", "123", null); VspDetails updatedVsp = - createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName", - "vlm1Id", "icon", "category", "subCategory", "123", null); + createVspDetails(VSP_ID, VERSION01, "Vsp1_updated", "Test-existingVsp", "vendorName", + "vlm1Id", "icon", "category", "subCategory", "123", null); doReturn(existingVsp).when(vspInfoDaoMock) - .get(any(VspDetails.class)); + .get(any(VspDetails.class)); doThrow(new CoreException( - new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build())) - .when(vendorSoftwareProductManager) - .updateUniqueName(existingVsp.getName(), updatedVsp.getName()); + new ErrorCode.ErrorCodeBuilder().withCategory(ErrorCategory.APPLICATION).build())) + .when(vendorSoftwareProductManager) + .updateUniqueName(existingVsp.getName(), updatedVsp.getName()); vendorSoftwareProductManager.updateVsp(updatedVsp, USER1); } @@ -321,21 +315,21 @@ public class VendorSoftwareProductManagerImplTest { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(VERSION01); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - VersionableEntityAction.Write); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + VersionableEntityAction.Write); VspDetails existingVsp = - createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", - "category", - "subCategory", "456", null); + createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", + "category", + "subCategory", "456", null); VspDetails updatedVsp = - createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon", - "category_updated", - "subCategory", "456", null); + createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon", + "category_updated", + "subCategory", "456", null); existingVsp.setWritetimeMicroSeconds(8L); doReturn(existingVsp).when(vspInfoDaoMock) - .get(any(VspDetails.class)); + .get(any(VspDetails.class)); doNothing().when(vendorSoftwareProductManager) - .updateUniqueName(existingVsp.getName(), updatedVsp.getName()); + .updateUniqueName(existingVsp.getName(), updatedVsp.getName()); vendorSoftwareProductManager.updateVsp(updatedVsp, USER1); @@ -347,26 +341,26 @@ public class VendorSoftwareProductManagerImplTest { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(VERSION01); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - VersionableEntityAction.Write); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + VersionableEntityAction.Write); List<String> fgs = new ArrayList<String>(); fgs.add("fg1"); fgs.add("fg2"); VspDetails existingVsp = - createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", - "category", - "subCategory", "456", fgs); + createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", + "category", + "subCategory", "456", fgs); List<String> updFgs = new ArrayList<String>(); updFgs.add("fg2"); VspDetails updatedVsp = - createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon", - "category_updated", - "subCategory", "456", updFgs); + createVspDetails(VSP_ID, VERSION01, "VSP1_updated", null, "vendorName", "vlm1Id", "icon", + "category_updated", + "subCategory", "456", updFgs); existingVsp.setWritetimeMicroSeconds(8L); doReturn(existingVsp).when(vspInfoDaoMock) - .get(any(VspDetails.class)); + .get(any(VspDetails.class)); doNothing().when(vendorSoftwareProductManager) - .updateUniqueName(existingVsp.getName(), updatedVsp.getName()); + .updateUniqueName(existingVsp.getName(), updatedVsp.getName()); DeploymentFlavorEntity dfEntity = new DeploymentFlavorEntity(VSP_ID,VERSION01,"DF_ID"); DeploymentFlavor flavor = new DeploymentFlavor(); @@ -400,18 +394,18 @@ public class VendorSoftwareProductManagerImplTest { versionInfo.setStatus(VersionStatus.Locked); versionInfo.setLockingUser(USER1); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - VersionableEntityAction.Read); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + VersionableEntityAction.Read); VspDetails existingVsp = - createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", - "category", - "subCategory", "456", null); + createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", + "category", + "subCategory", "456", null); existingVsp.setWritetimeMicroSeconds(8L); doReturn(existingVsp).when(vspInfoDaoMock).get(any(VspDetails.class)); VspDetails actualVsp = - vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1); + vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1); assertVspsEquals(actualVsp, existingVsp); } @@ -424,37 +418,37 @@ public class VendorSoftwareProductManagerImplTest { versionInfo.setStatus(VersionStatus.Locked); versionInfo.setLockingUser(USER2); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - VersionableEntityAction.Read); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + VersionableEntityAction.Read); VspDetails existingVsp = - createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", - "category", - "subCategory", "456", null); + createVspDetails(VSP_ID, VERSION01, "VSP1", null, "vendorName", "vlm1Id", "icon", + "category", + "subCategory", "456", null); existingVsp.setWritetimeMicroSeconds(8L); doReturn(existingVsp) - .when(vspInfoDaoMock).get(any(VspDetails.class)); + .when(vspInfoDaoMock).get(any(VspDetails.class)); VspDetails actualVsp = - vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1); + vendorSoftwareProductManager.getVsp(VSP_ID, VERSION01, USER1); VspDetails expectedVsp = - vspInfoDaoMock - .get(new VspDetails(VSP_ID, VERSION01)); + vspInfoDaoMock + .get(new VspDetails(VSP_ID, VERSION01)); assertVspsEquals(actualVsp, expectedVsp); } @Test public void testCheckin() { doReturn(VERSION01).when(versioningManagerMock) - .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, - USER1, null); + .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, + USER1, null); Version version = vendorSoftwareProductManager.checkin(VSP_ID, USER1); Assert.assertEquals(version, VERSION01); verify(versioningManagerMock) - .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, - USER1, null); + .checkin(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, + USER1, null); verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1)); ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue(); Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION01.getMajor() + 1)); @@ -464,14 +458,14 @@ public class VendorSoftwareProductManagerImplTest { @Test public void testCheckout() { doReturn(VERSION01).when(versioningManagerMock) - .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, - USER1); + .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, + USER1); Version version = vendorSoftwareProductManager.checkout(VSP_ID, USER1); Assert.assertEquals(version, VERSION01); verify(versioningManagerMock) - .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, - USER1); + .checkout(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, + USER1); verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1)); ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue(); @@ -486,11 +480,11 @@ public class VendorSoftwareProductManagerImplTest { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(existingVersion); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, - VSP_ID, USER1, VersionableEntityAction.Read); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, + VSP_ID, USER1, VersionableEntityAction.Read); doReturn(VERSION01).when(versioningManagerMock).undoCheckout(VendorSoftwareProductConstants - .VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1); + .VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1); VspDetails vsp = new VspDetails(VSP_ID, existingVersion); vsp.setName("ExistingName"); @@ -552,22 +546,22 @@ public class VendorSoftwareProductManagerImplTest { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(VERSION01); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, - VSP_ID, USER1, VersionableEntityAction.Read); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, + VSP_ID, USER1, VersionableEntityAction.Read); VspDetails vsp = - createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", - "category", "subCategory", "licenseAgreementId", - Collections.singletonList("featureGroupId")); + createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", + "category", "subCategory", "licenseAgreementId", + Collections.singletonList("featureGroupId")); doReturn(vsp).when(vspInfoDaoMock).get(anyObject()); UploadDataEntity uploadData = new UploadDataEntity(VSP_ID, VERSION01); uploadData.setContentData( - ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition")))); + ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition")))); doReturn(uploadData).when(orchestrationTemplateDataDaoMock) - .getOrchestrationTemplate(anyObject(), anyObject()); + .getOrchestrationTemplate(anyObject(), anyObject()); doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), - "MainServiceTemplate.yaml")) - .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01); + "MainServiceTemplate.yaml")) + .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01); ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1); Assert.assertNotNull(validationResponse); @@ -576,8 +570,8 @@ public class VendorSoftwareProductManagerImplTest { Assert.assertEquals(validationResponse.getLicensingDataErrors(), 1); verify(versioningManagerMock, never()) - .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, - USER1, null); + .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, + USER1, null); //TODO - check.. verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1)); @@ -590,20 +584,20 @@ public class VendorSoftwareProductManagerImplTest { EnrichmentManagerFactory.getInstance(); AbstractFactoryBase - .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class); + .registerFactory(EnrichmentManagerFactory.class, EnrichmentManagerFactoryImpl.class); VspDetails vsp = - createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", - "category", "subCategory", "123", Collections.singletonList("fg1")); + createVspDetails(VSP_ID, VERSION01, "Vsp1", "Test-vsp", "vendorName", "vlm1Id", "icon", + "category", "subCategory", "123", Collections.singletonList("fg1")); doReturn(vsp).when(vspInfoDaoMock).get(anyObject()); UploadDataEntity uploadData = new UploadDataEntity(VSP_ID, VERSION01); uploadData.setContentData( - ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition")))); + ByteBuffer.wrap(FileUtils.toByteArray(getFileInputStream("/emptyComposition")))); doReturn(uploadData).when(orchestrationTemplateDataDaoMock) - .getOrchestrationTemplate(anyObject(), anyObject()); + .getOrchestrationTemplate(anyObject(), anyObject()); doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), - "MainServiceTemplate.yaml")) - .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01); + "MainServiceTemplate.yaml")) + .when(serviceModelDaoMock).getServiceModel(VSP_ID, VERSION01); ValidationResponse validationResponse = vendorSoftwareProductManager.submit(VSP_ID, USER1); Assert.assertTrue(validationResponse.isValid()); @@ -613,8 +607,8 @@ public class VendorSoftwareProductManagerImplTest { Assert.assertNull(vsp2.getVersionInfo().getLockingUser());*/ verify(versioningManagerMock) - .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, - USER1, null); + .submit(VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, + USER1, null); verify(activityLogManagerMock).addActionLog(activityLogEntityArg.capture(), eq(USER1)); ActivityLogEntity activityLogEntity = activityLogEntityArg.getValue(); Assert.assertEquals(activityLogEntity.getVersionId(), String.valueOf(VERSION10.getMajor())); @@ -633,11 +627,11 @@ public class VendorSoftwareProductManagerImplTest { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(VERSION10); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - VersionableEntityAction.Read); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + VersionableEntityAction.Read); doReturn(new ToscaServiceModel(new FileContentHandler(), new HashMap<>(), "")).when - (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10); + (enrichedServiceModelDaoMock).getServiceModel(VSP_ID, VERSION10); VspDetails vsp = new VspDetails(VSP_ID, VERSION10); vsp.setVendorId("vendorId"); @@ -646,8 +640,8 @@ public class VendorSoftwareProductManagerImplTest { doReturn(vsp).when(vspInfoDaoMock).get(any(VspDetails.class)); doReturn(new FileContentHandler()).when(licenseArtifactsServiceMock) - .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups(), - USER1); + .createLicenseArtifacts(VSP_ID, vsp.getVendorId(), VERSION10, vsp.getFeatureGroups(), + USER1); PackageInfo packageInfo = vendorSoftwareProductManager.createPackage(VSP_ID, VERSION10, USER1); Assert.assertNotNull(packageInfo.getVspId()); @@ -659,7 +653,7 @@ public class VendorSoftwareProductManagerImplTest { InputStream zis = getFileInputStream("/vspmanager/zips/missingYml.zip"); UploadFileResponse uploadFileResponse = - candidateManager.upload(VSP_ID, VERSION01, zis, USER1); + candidateManager.upload(VSP_ID, VERSION01, zis, USER1, "zip", "missingYml"); Assert.assertEquals(uploadFileResponse.getErrors().size(), 0); } @@ -671,8 +665,8 @@ public class VendorSoftwareProductManagerImplTest { try { candidateManager - .upload(VSP_ID, VERSION01, - url.openStream(), USER1); + .upload(VSP_ID, VERSION01, + url.openStream(), USER1, "zip", "notZipFile"); candidateManager.process(VSP_ID, VERSION01, USER1); } catch (Exception ce) { Assert.assertEquals(ce.getMessage(), Messages.CREATE_MANIFEST_FROM_ZIP.getErrorMessage()); @@ -680,118 +674,18 @@ public class VendorSoftwareProductManagerImplTest { verify(activityLogManagerMock, never()).addActionLog(any(ActivityLogEntity.class), eq(USER1)); } -/* - @Test - public void testEnrichModelInSubmit() { - UniqueValueUtil - .deleteUniqueValue(VendorSoftwareProductConstants.UniqueValues.VENDOR_SOFTWARE_PRODUCT_NAME, - "VSP_syb"); - VspDetails vspDetails = vendorSoftwareProductManager.createVsp( - createVspDetails(null, null, "VSP_syb", "Test-vsp_syb", "vendorName", "vlm1Id", "icon", - "category", "subCategory", "456", null), USER1); - String id = vspDetails.getId(); - - //upload file - InputStream zis = getFileInputStream("/vspmanager/zips/fullComposition.zip"); - candidateManager.upload(id, VERSION01, zis, USER1); - OrchestrationTemplateActionResponse uploadFileResponse = - candidateManager.process(id, VERSION01, USER1); - - //check in - vendorSoftwareProductManager.checkin(id, USER1); - //submit - try { - ValidationResponse result = vendorSoftwareProductManager.submit(id, USER1); - } catch (IOException exception) { - Assert.fail(); - } - VersionedVendorSoftwareProductInfo details = - vendorSoftwareProductManager.getVsp(id, null, USER1); - Collection<ComponentEntity> components =vendorSoftwareProductManager - .listComponents(id, details.getVersionInfo().getActiveVersion(), USER1); - - ToscaServiceModel model = - (ToscaServiceModel) EnrichedServiceModelDaoFactory.getInstance().createInterface() - .getServiceModel(id, details.getVersionInfo().getActiveVersion()); - - Map<String, CapabilityDefinition> capabilities = new HashMap<>(); - for (ComponentEntity component : components) { - model.getServiceTemplates(). - entrySet(). - stream(). - filter(entryValue -> entryValue.getValue() != null && - entryValue.getValue().getNode_types() != null && - entryValue.getValue(). - getNode_types(). - containsKey(component.getComponentCompositionData().getName())). - forEach(entryValue -> entryValue.getValue().getNode_types(). - values(). - stream(). - filter(type -> MapUtils.isNotEmpty(type.getCapabilities())). - forEach(type -> type.getCapabilities(). - entrySet(). - forEach(entry -> addCapability(entryValue.getKey(), capabilities, entry.getKey(), - entry.getValue())))); - - } - - Assert.assertNotNull(capabilities); - } - - @Test(dependsOnMethods = {"testCreatePackage"}) - public void testEnrichedFilesDeletedOnNewUpload() throws IOException { - Version activeVersion; - - createPackageFromUpload(VSP_ID, USER1, "/fullComposition"); - activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo() - .getActiveVersion(); - - List<ServiceArtifact> firstExternalArtifacts = enrichedServiceModelDaoMock - .getExternalArtifacts(VSP_ID, activeVersion); - ToscaServiceModel firstServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID, - activeVersion); - - createPackageFromUpload(VSP_ID, USER1, "/emptyComposition"); - activeVersion = vendorSoftwareProductManager.getVsp(VSP_ID, null, USER1).getVersionInfo() - .getActiveVersion(); - - List<ServiceArtifact> secondExternalArtifacts = enrichedServiceModelDaoMock - .getExternalArtifacts(VSP_ID, activeVersion); - ToscaServiceModel secondServiceModel = enrichedServiceModelDaoMock.getServiceModel(VSP_ID, - activeVersion); - - Assert.assertNotEquals(firstExternalArtifacts, secondExternalArtifacts); - Assert.assertNotEquals(firstServiceModel, secondServiceModel); - - } - - @Test(dependsOnMethods = {"testMibsDeletedInCsar"}) - public void testServiceTemplatesAreDeletedInCsarOnNewUpload() throws IOException { - String nestedPath = "Definitions" + File.separator + "nested"; - - uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullCompositionNested.zip"); - checkinSubmitCreatePackage(VSP_ID, USER1); - List<String> nestedFileNamesServiceTemplates = - getWantedFileNamesFromCsar(nestedPath); - uploadFileAndProcess(VSP_ID, USER1, "/vspmanager/zips/fullComposition.zip"); - checkinSubmitCreatePackage(VSP_ID, USER1); - List<String> emptyNestedNamesList = getWantedFileNamesFromCsar(nestedPath); - - Assert.assertEquals(emptyNestedNamesList.size(), 0); - Assert.assertNotEquals(emptyNestedNamesList.size(), nestedFileNamesServiceTemplates.size()); - }*/ private List<String> getWantedFileNamesFromCsar(String pathInCsar) - throws IOException { + throws IOException { File translatedFile = vendorSoftwareProductManager.getTranslatedFile(VSP_ID, VERSION10, USER1); return getFileNamesFromFolderInCsar(translatedFile, - pathInCsar); + pathInCsar); } private List<String> getFileNamesFromFolderInCsar(File csar, String folderName) - throws IOException { + throws IOException { List<String> fileNames = new ArrayList<>(); ZipInputStream zip = new ZipInputStream(new FileInputStream(csar)); @@ -806,31 +700,16 @@ public class VendorSoftwareProductManagerImplTest { return fileNames; } - /* - //Disabled for sonar null pointer issue for componentEntities - private Pair<String, String> uploadMib(String vspId, String user, String filePath, - String fileName) { - List<ComponentEntity> componentEntities = null; - //(List<ComponentEntity>) vendorSoftwareProductManager.listComponents(vspId, null, user); - monitoringUploadsManager.upload(getFileInputStream(filePath), - fileName, vspId, - VERSION01, componentEntities.get(0).getId(), MonitoringUploadType.SNMP_POLL, user); - //TODO: add validate of addActionLog() func call - - return new ImmutablePair<>(componentEntities.get(0).getId(), - componentEntities.get(0).getComponentCompositionData() - .getDisplayName()); - }*/ private void createPackageFromUpload(String vspId, String user, String filePath) - throws IOException { + throws IOException { uploadFileAndProcess(vspId, user, filePath); checkinSubmitCreatePackage(vspId, user); } private void uploadFileAndProcess(String vspId, String user, String filePath) { vendorSoftwareProductManager.checkout(vspId, user); - candidateManager.upload(vspId, VERSION01, getFileInputStream(filePath), user); + candidateManager.upload(vspId, VERSION01, getFileInputStream(filePath), user, "zip", "file"); candidateManager.process(vspId, VERSION01, user); } @@ -888,11 +767,11 @@ public class VendorSoftwareProductManagerImplTest { */ private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { - candidateManager.upload(vspId, VERSION01, upload, USER1); + candidateManager.upload(vspId, VERSION01, upload, USER1, "zip", "file"); candidateManager.process(vspId, VERSION01, user); UploadDataEntity uploadData = - orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version); + orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version); Assert.assertNotNull(uploadData); } @@ -914,28 +793,11 @@ public class VendorSoftwareProductManagerImplTest { private void assertVSPInWantedLocationInVSPList(String vspId, int location, String user) { List<VersionedVendorSoftwareProductInfo> vspList = - vendorSoftwareProductManager.listVsps(null, user); + vendorSoftwareProductManager.listVsps(null, user); Assert.assertEquals(vspList.get(location).getVspDetails().getId(), vspId); } - // private void assertInfoArtifactIsInRightPathInCsar(String vspId, String zipFileName) -// throws IOException { -// ZipInputStream inputZipStream = new ZipInputStream(new FileInputStream(new File(zipFileName))); -// boolean isInfoArtifactInZip = false; -// -// ZipEntry zipEntry; -// while ((zipEntry = inputZipStream.getNextEntry()) != null) { -// String currentEntryName = zipEntry.getName(); -// if(currentEntryName.equals("Artifacts\\Informative\\Guide\\VSP_" + -// vspId + "_Information.txt")){ -// isInfoArtifactInZip = true; -// break; -// } -// } -// -// Assert.assertTrue(isInfoArtifactInZip); -// } static VspDetails createVspDetails(String id, Version version, String name, String desc, String vendorName, String vlm, String icon, String category, String subCategory, @@ -969,68 +831,30 @@ public class VendorSoftwareProductManagerImplTest { Assert.assertEquals(actual.getFeatureGroups(), expected.getFeatureGroups()); } - -// @Test -// public void testDownloadFile() throws IOException { -// VspDetails expectedVsp = VSPCommon.createVspDetails(null, null, String.format("VSP-test-%s", vlm1Id), "Test-vsp", "vendorName", "vlm1Id", "icon", "category", "subCategory", "123", null); -// VspDetails createdVsp = vendorSoftwareProductManager.createVsp(expectedVsp, USER1); -// -// id005 = createdVsp.getId(); -// Assert.assertNotNull(id005); -// Assert.assertNotNull(createdVsp.getVersion()); -// -// try (InputStream zipInputStream = new ZipFileUtils().getZipInputStream("/legalUploadWithWarning")) { -// -// UploadFileResponse uploadFileResponse = vendorSoftwareProductManager.upload(id005, zipInputStream, USER1); -// vendorSoftwareProductManager.process(id005, USER1); -// Optional<File> fileCandidate = vendorSoftwareProductManager.get(id005, USER1); -// -// File latestHeatPackage = fileCandidate.get(); -// -// zipInputStream.reset(); -// byte[] uploaded = IOUtils.toByteArray(zipInputStream); -// -// Optional<FileContentHandler> zipContentMap = vendorSoftwareProductManager.getZipContentMap(uploadFileResponse, uploaded); -// FileContentHandler fileContentHandler = new FileContentHandler(); -// if(zipContentMap.isPresent()){ -// fileContentHandler = zipContentMap.get(); -// } -// -// uploaded = IOUtils.toByteArray(fileContentHandler.getFiles().values()); -// -// byte[] downloaded; -// try (BufferedInputStream fileStream = new BufferedInputStream(new FileInputStream(latestHeatPackage))) { -// downloaded = IOUtils.toByteArray(fileStream); -// } -// -// Assert.assertTrue(Arrays.equals(uploaded, downloaded)); -// } -// } - - // todo ********************** move to common ************************************** + // todo ********************** move to common ************************************** private void mockVersioning(VersionableEntityAction action) { VersionInfo versionInfo = new VersionInfo(); versionInfo.setActiveVersion(VERSION01); doReturn(versionInfo).when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, - action); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1, + action); } private void mockVersioningEntityNotExist(VersionableEntityAction action, String vspId) { doThrow(new CoreException(new EntityNotExistErrorBuilder( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId).build())) - .when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId, USER1, - action); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId).build())) + .when(versioningManagerMock).getEntityVersionInfo( + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, vspId, USER1, + action); } private void MockVersioningEntityLocked(VersionableEntityAction action) { doThrow(new CoreException(new EditOnEntityLockedByOtherErrorBuilder( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1) - .build())) - .when(versioningManagerMock).getEntityVersionInfo( - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER2, - action); + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER1) + .build())) + .when(versioningManagerMock).getEntityVersionInfo( + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE, VSP_ID, USER2, + action); } }
\ No newline at end of file diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java index 236b7e7594..dfb7409bd0 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/tree/UploadFileTest.java @@ -27,6 +27,7 @@ import org.mockito.MockitoAnnotations; import org.mockito.Spy; import org.openecomp.core.model.dao.ServiceModelDao; import org.openecomp.core.model.types.ServiceElement; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; import org.openecomp.sdc.healing.api.HealingManager; import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; @@ -37,92 +38,86 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; -import org.openecomp.sdc.vendorsoftwareproduct.services.filedatastructuremodule.CandidateService; import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; import org.openecomp.sdc.vendorsoftwareproduct.utils.VSPCommon; import org.openecomp.sdc.versioning.dao.types.Version; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; +import java.io.*; import java.net.URL; import java.util.zip.ZipOutputStream; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doReturn; +import static org.testng.Assert.assertEquals; public class UploadFileTest { - private static final String USER1 = "vspTestUser1"; - - public static final Version VERSION01 = new Version(0, 1); - @Mock - private VendorSoftwareProductDao vendorSoftwareProductDaoMock; - @Mock - private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; - @Spy - private CandidateServiceImpl candidateService; - @Mock - private HealingManager healingManagerMock; - @Mock - private CompositionDataExtractor compositionDataExtractorMock; - @Mock - private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock; - @Mock - private CompositionEntityDataManager compositionEntityDataManagerMock; - @Mock - private VendorSoftwareProductInfoDao vspInfoDaoMock; - - @InjectMocks - private OrchestrationTemplateCandidateManagerImpl candidateManager; - - private static String vlm1Id; - public static String id001 = null; - public static String id002 = null; - - public static Version activeVersion002 = null; - - - @BeforeMethod - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testUploadFile() { - VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); - doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); - candidateManager.upload(id001, activeVersion002, getZipInputStream("/legalUpload"), USER1); - } - - - private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { - candidateManager.upload(vspId, activeVersion002, upload, user); - - UploadDataEntity uploadData = - orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version); - - } - - public InputStream getZipInputStream(String name) { - URL url = this.getClass().getResource(name); - File templateDir = new File(url.getFile()); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ZipOutputStream zos = new ZipOutputStream(baos); - - VSPCommon.zipDir(templateDir, "", zos, true); - try { - zos.close(); - } catch (IOException e) { - e.printStackTrace(); + private static final String USER1 = "vspTestUser1"; + + public static final Version VERSION01 = new Version(0, 1); + @Mock + private VendorSoftwareProductDao vendorSoftwareProductDaoMock; + @Mock + private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; + @Spy + private CandidateServiceImpl candidateService; + @Mock + private HealingManager healingManagerMock; + @Mock + private CompositionDataExtractor compositionDataExtractorMock; + @Mock + private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock; + @Mock + private CompositionEntityDataManager compositionEntityDataManagerMock; + @Mock + private VendorSoftwareProductInfoDao vspInfoDaoMock; + + @InjectMocks + private OrchestrationTemplateCandidateManagerImpl candidateManager; + + private static String vlm1Id; + public static String id001 = null; + public static String id002 = null; + + public static Version activeVersion002 = null; + + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testUploadFile() { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + candidateManager.upload(id001, activeVersion002, getZipInputStream("/legalUpload"), USER1, OnboardingTypesEnum.ZIP.toString(), "legalUpload"); + } + + + private void testLegalUpload(String vspId, Version version, InputStream upload, String user) { + UploadFileResponse uploadFileResponse = candidateManager.upload(vspId, activeVersion002, + upload, user, OnboardingTypesEnum.ZIP.toString(),"file" ); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.ZIP); + UploadDataEntity uploadData = + orchestrationTemplateDataDaoMock.getOrchestrationTemplate(vspId, version); + + } + + public InputStream getZipInputStream(String name) { + URL url = this.getClass().getResource(name); + File templateDir = new File(url.getFile()); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ZipOutputStream zos = new ZipOutputStream(baos)) { + VSPCommon.zipDir(templateDir, "", zos, true); + } catch (IOException e) { + e.printStackTrace(); + } + return new ByteArrayInputStream(baos.toByteArray()); } - return new ByteArrayInputStream(baos.toByteArray()); - } } diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java new file mode 100644 index 0000000000..3332e81e36 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/ManifestParsingTest.java @@ -0,0 +1,58 @@ +package org.openecomp.sdc.vendorsoftwareproduct.upload.csar; + +import org.junit.Test; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.OnboardingManifest; + +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.Assert.*; + +public class ManifestParsingTest { + + @Test + public void testSuccessfulParsing() throws IOException { + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/ValidTosca.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertTrue(onboardingManifest.isValid()); + assertEquals(onboardingManifest.getMetadata().size(), 4); + assertEquals(onboardingManifest.getSources().size(), 5); + } + } + + @Test + public void testNoMetadataParsing() throws IOException { + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca1.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertFalse(onboardingManifest.isValid()); + assertTrue(onboardingManifest.getErrors().stream(). + filter(error -> error.contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))) + .findAny().isPresent()); + } + } + + @Test + public void testBrokenMDParsing() throws IOException { + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca2.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertFalse(onboardingManifest.isValid()); + assertTrue(onboardingManifest.getErrors().stream(). + filter(error -> error.contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))) + .findAny().isPresent()); + } + } + + @Test + public void testNoMetaParsing() throws IOException { + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca4.mf")) { + OnboardingManifest onboardingManifest = new OnboardingManifest(is); + assertFalse(onboardingManifest.isValid()); + assertTrue(onboardingManifest.getErrors().stream(). + filter(error -> error.contains(Messages.MANIFEST_NO_METADATA.getErrorMessage().substring(0, 10))) + .findAny().isPresent()); + } + } + + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java new file mode 100644 index 0000000000..a7fc0e1ba0 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/upload/csar/UploadCSARFileTest.java @@ -0,0 +1,221 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.vendorsoftwareproduct.upload.csar; + + +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.Spy; +import org.openecomp.core.model.dao.ServiceModelDao; +import org.openecomp.core.model.types.ServiceElement; +import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum; +import org.openecomp.sdc.common.errors.Messages; +import org.openecomp.sdc.datatypes.error.ErrorMessage; +import org.openecomp.sdc.healing.api.HealingManager; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateCandidateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.OrchestrationTemplateDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductInfoDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.VspDetails; +import org.openecomp.sdc.vendorsoftwareproduct.impl.OrchestrationTemplateCandidateManagerImpl; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionDataExtractor; +import org.openecomp.sdc.vendorsoftwareproduct.services.composition.CompositionEntityDataManager; +import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.CandidateServiceImpl; +import org.openecomp.sdc.vendorsoftwareproduct.services.impl.filedatastructuremodule.ManifestCreatorNamingConventionImpl; +import org.openecomp.sdc.vendorsoftwareproduct.types.UploadFileResponse; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.List; +import java.util.function.Predicate; + +import static org.junit.Assert.*; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; + +public class UploadCSARFileTest { + private static final String USER1 = "vspTestUser1"; + + public static final Version VERSION01 = new Version(0, 1); + + @Mock + private VendorSoftwareProductDao vendorSoftwareProductDaoMock; + @Mock + private OrchestrationTemplateDao orchestrationTemplateDataDaoMock; + + @Spy + private CandidateServiceImpl candidateService; + @Mock + private HealingManager healingManagerMock; + @Mock + private CompositionDataExtractor compositionDataExtractorMock; + @Mock + private ServiceModelDao<ToscaServiceModel, ServiceElement> serviceModelDaoMock; + @Mock + private CompositionEntityDataManager compositionEntityDataManagerMock; + @Mock + private VendorSoftwareProductInfoDao vspInfoDaoMock; + @Mock + private OrchestrationTemplateCandidateDao orchestrationTemplateCandidateDao; + @Mock + private ManifestCreatorNamingConventionImpl manifestCreator; + + private OrchestrationTemplateCandidateManagerImpl candidateManager; + + + public static String id001 = null; + + public static Version activeVersion002 = null; + + + @BeforeMethod + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + candidateService = new CandidateServiceImpl(manifestCreator,orchestrationTemplateCandidateDao); + candidateManager = new OrchestrationTemplateCandidateManagerImpl( vendorSoftwareProductDaoMock, + vspInfoDaoMock, + orchestrationTemplateDataDaoMock, + candidateService, healingManagerMock, + compositionDataExtractorMock, + serviceModelDaoMock, + compositionEntityDataManagerMock, + null, + null, + null, + null, + null); + } + + @Test + public void testSuccessfulUploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmock.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, "csar", "SDCmock"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(0, uploadFileResponse.getErrors().size()); + assertTrue(uploadFileResponse.getErrors().isEmpty()); + } + } + + @Test + public void testFail1UploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail1.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, + "csar", "SDCmockFail1"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + assertTrue( uploadFileResponse.getErrors().values().stream() + .filter(getListPredicate(Messages.CSAR_FILES_NOT_ALLOWED + .getErrorMessage().substring(0, 7))).findAny().isPresent()); + } + } + + private Predicate<List<ErrorMessage>> getListPredicate(String substring) { + return error -> isEquals(substring, error); + } + + private boolean isEquals(String substring, List<ErrorMessage> error) { + return error.iterator().next().getMessage().contains(substring); + } + + @Test + public void testFail2UploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail2.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, + "csar", "SDCmockFail2"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + assertTrue( uploadFileResponse.getErrors().values().stream() + .filter(getListPredicate(Messages.CSAR_FILE_NOT_FOUND + .getErrorMessage().substring(0,7))).findAny().isPresent()); + } + } + @Test + public void testFail3UploadFile() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockFail3.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, + "csar", "SDCmockFail3"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + } + } + + @Test + public void testUploadFileIsNotZip() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = new ByteArrayInputStream( "Thia is not a zip file".getBytes() );) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, + "csar", "file"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertFalse(uploadFileResponse.getErrors().isEmpty()); + assertTrue( uploadFileResponse.getErrors().values().stream() + .filter(getListPredicate(Messages.CSAR_FILE_NOT_FOUND + .getErrorMessage().substring(0,7))).findAny().isPresent()); + } + } + @Test + public void testUploadFileIsEmpty() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = new ByteArrayInputStream( new byte[]{} )) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, + activeVersion002, is, USER1, "csar", "file"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + } + } + + @Test + public void testMFError() throws Exception { + VspDetails vspDetails = new VspDetails("dummyId", new Version(1, 0)); + doReturn(vspDetails).when(vspInfoDaoMock).get(any(VspDetails.class)); + + try (InputStream is = getClass().getResourceAsStream("/vspmanager.csar/SDCmockBrokenMF.csar")) { + UploadFileResponse uploadFileResponse = candidateManager.upload(id001, activeVersion002, is, USER1, "csar", "SDCmockBrokenMF"); + assertEquals(uploadFileResponse.getOnboardingType(), OnboardingTypesEnum.CSAR); + assertEquals(1, uploadFileResponse.getErrors().size()); + assertTrue( uploadFileResponse.getErrors() + .values().stream() + .filter(getListPredicate(Messages.MANIFEST_NO_METADATA.getErrorMessage())).findAny().isPresent()); + + } + } + + +} diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar Binary files differnew file mode 100644 index 0000000000..f69efd2bb8 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmock.csar diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar Binary files differnew file mode 100644 index 0000000000..02593a1d2f --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockBrokenMF.csar diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar Binary files differnew file mode 100644 index 0000000000..5e3ee6f387 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail1.csar diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar Binary files differnew file mode 100644 index 0000000000..4874578ad9 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail2.csar diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar Binary files differnew file mode 100644 index 0000000000..c009a042e4 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/SDCmockFail3.csar diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca1.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca1.mf new file mode 100644 index 0000000000..f28014e2d6 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca1.mf @@ -0,0 +1,11 @@ + + +source: MainServiceTemplate.yaml + +source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml + +source: Artifacts/install.sh + +source: Artifacts/create_stack.sh + +source: Licenses/license.xml diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca2.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca2.mf new file mode 100644 index 0000000000..95f7a41d68 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca2.mf @@ -0,0 +1,18 @@ +metadata: + vnf_product_name: Mock + vnf_provider_id: ZTE + +source: MainServiceTemplate.yaml + + vnf_package_version: 1.0 + vnf_release_data_time: 2017.01.01T10:00+03:00 + + + +source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml + +source: Artifacts/install.sh + +source: Artifacts/create_stack.sh + +source: Licenses/license.xml diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca3.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca3.mf new file mode 100644 index 0000000000..64e9445f7f --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca3.mf @@ -0,0 +1,7 @@ +metadata: + vnf_product_name: Mock + vnf_provider_id: ZTE + vnf_package_version: 1.0 + vnf_release_data_time: 2017.01.01T10:00+03:00 + + diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca4.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca4.mf new file mode 100644 index 0000000000..a563ddd581 --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/InvalidTosca4.mf @@ -0,0 +1,12 @@ +metadata: + + +source: MainServiceTemplate.yaml + +source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml + +source: Artifacts/install.sh + +source: Artifacts/create_stack.sh + +source: Licenses/license.xml diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/ValidTosca.mf b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/ValidTosca.mf new file mode 100644 index 0000000000..88c67517ce --- /dev/null +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/test/resources/vspmanager.csar/manifest/ValidTosca.mf @@ -0,0 +1,15 @@ +metadata: + vnf_product_name: Mock + vnf_provider_id: ZTE + vnf_package_version: 1.0 + vnf_release_data_time: 2017.01.01T10:00+03:00 + +source: MainServiceTemplate.yaml + +source: Definitions/GlobalSubstitutionTypesServiceTemplate.yaml + +source: Artifacts/install.sh + +source: Artifacts/create_stack.sh + +source: Licenses/license.xml |