diff options
author | vasraz <vasyl.razinkov@est.tech> | 2022-08-26 13:59:23 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2022-09-14 08:24:38 +0000 |
commit | e4a10c8950c35f21fd192f54c8a293af2dd02b1a (patch) | |
tree | a3f6760d9b9424b6fed62f2755ba079c02776f75 | |
parent | 1db6e26a7fa6b1afcf1562b239866198dc54ed92 (diff) |
Fix 'Optional license in onboarding'-bug
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Change-Id: I6b63629e834b8a5002372d6af59ae0a3a9460542
Issue-ID: SDC-3601
8 files changed, 143 insertions, 136 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java index 99d7dddcdd..92158d0aab 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogic.java @@ -73,7 +73,6 @@ import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.L import org.openecomp.sdc.be.components.merge.TopologyComparator; import org.openecomp.sdc.be.components.merge.property.PropertyDataValueMergeBusinessLogic; import org.openecomp.sdc.be.components.merge.resource.ResourceDataMergeBusinessLogic; -import org.openecomp.sdc.be.components.merge.utils.MergeInstanceUtils; import org.openecomp.sdc.be.components.property.PropertyConstraintsUtils; import org.openecomp.sdc.be.components.validation.component.ComponentContactIdValidator; import org.openecomp.sdc.be.components.validation.component.ComponentDescriptionValidator; @@ -214,7 +213,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { private final CompositionBusinessLogic compositionBusinessLogic; private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic; private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic; - private final MergeInstanceUtils mergeInstanceUtils; private final UiComponentDataConverter uiComponentDataConverter; private final CsarBusinessLogic csarBusinessLogic; private final PropertyBusinessLogic propertyBusinessLogic; @@ -248,16 +246,15 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { final OutputsBusinessLogic outputsBusinessLogic, final CompositionBusinessLogic compositionBusinessLogic, final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic, final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic, - final MergeInstanceUtils mergeInstanceUtils, final UiComponentDataConverter uiComponentDataConverter, - final CsarBusinessLogic csarBusinessLogic, final ArtifactsOperations artifactToscaOperation, - final PropertyBusinessLogic propertyBusinessLogic, final ComponentContactIdValidator componentContactIdValidator, - final ComponentNameValidator componentNameValidator, final ComponentTagsValidator componentTagsValidator, - final ComponentValidator componentValidator, final ComponentIconValidator componentIconValidator, + final UiComponentDataConverter uiComponentDataConverter, final CsarBusinessLogic csarBusinessLogic, + final ArtifactsOperations artifactToscaOperation, final PropertyBusinessLogic propertyBusinessLogic, + final ComponentContactIdValidator componentContactIdValidator, final ComponentNameValidator componentNameValidator, + final ComponentTagsValidator componentTagsValidator, final ComponentValidator componentValidator, + final ComponentIconValidator componentIconValidator, final ComponentProjectCodeValidator componentProjectCodeValidator, final ComponentDescriptionValidator componentDescriptionValidator, final PolicyBusinessLogic policyBusinessLogic, - final ModelBusinessLogic modelBusinessLogic, - final DataTypeBusinessLogic dataTypeBusinessLogic, final PolicyTypeBusinessLogic policyTypeBusinessLogic, - final ModelOperation modelOperation) { + final ModelBusinessLogic modelBusinessLogic, final DataTypeBusinessLogic dataTypeBusinessLogic, + final PolicyTypeBusinessLogic policyTypeBusinessLogic, final ModelOperation modelOperation) { super(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, artifactToscaOperation, componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator); @@ -268,7 +265,6 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { this.compositionBusinessLogic = compositionBusinessLogic; this.resourceDataMergeBusinessLogic = resourceDataMergeBusinessLogic; this.csarArtifactsAndGroupsBusinessLogic = csarArtifactsAndGroupsBusinessLogic; - this.mergeInstanceUtils = mergeInstanceUtils; this.uiComponentDataConverter = uiComponentDataConverter; this.csarBusinessLogic = csarBusinessLogic; this.propertyBusinessLogic = propertyBusinessLogic; @@ -1512,7 +1508,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { createResourcePropertiesOnGraph(resource); final Map<String, UploadComponentInstanceInfo> instancesToCreate = getInstancesToCreate(parsedToscaYamlInfo, resource.getModel()); - + if (MapUtils.isNotEmpty(instancesToCreate)) { log.trace("************* Going to create nodes, RI's and Relations from yaml {}", yamlName); loggerSupportability @@ -2087,12 +2083,12 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { Constants.VENDOR_LICENSE_MODEL, ArtifactTypeEnum.VENDOR_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, Constants.VENDOR_LICENSE_LABEL, Constants.VENDOR_LICENSE_DISPLAY_NAME, Constants.VENDOR_LICENSE_DESCRIPTION, vendorLicenseModelId, artifactOperation, null, true, shouldLock, inTransaction); - createOrUpdateSingleNonMetaArtifact(resource, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL, Constants.VF_LICENSE_MODEL, - ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, Constants.VF_LICENSE_LABEL, - Constants.VF_LICENSE_DISPLAY_NAME, Constants.VF_LICENSE_DESCRIPTION, vfLicenseModelId, artifactOperation, null, true, shouldLock, - inTransaction); - Either<Resource, ResponseFormat> eitherCreateResult = createOrUpdateNonMetaArtifacts(csarInfo, resource, createdArtifacts, shouldLock, - inTransaction, artifactOperation); + createOrUpdateSingleNonMetaArtifact(resource, csarInfo, CsarUtils.ARTIFACTS_PATH + Constants.VF_LICENSE_MODEL, + Constants.VF_LICENSE_MODEL, ArtifactTypeEnum.VF_LICENSE.getType(), ArtifactGroupTypeEnum.DEPLOYMENT, + Constants.VF_LICENSE_LABEL, Constants.VF_LICENSE_DISPLAY_NAME, Constants.VF_LICENSE_DESCRIPTION, vfLicenseModelId, + artifactOperation, null, true, shouldLock, inTransaction); + Either<Resource, ResponseFormat> eitherCreateResult + = createOrUpdateNonMetaArtifacts(csarInfo, resource, createdArtifacts, shouldLock, inTransaction, artifactOperation); if (eitherCreateResult.isRight()) { return Either.right(eitherCreateResult.right().value()); } @@ -3477,7 +3473,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { nodeForceCertification(resource, user, lifecycleChangeInfo, inTransaction, needLock); } if (resource.getLifecycleState() == LifecycleStateEnum.CERTIFIED) { - Either<ArtifactDefinition, Operation> eitherPopulated = populateToscaArtifacts(resource, user, false, inTransaction, needLock, false); + populateToscaArtifacts(resource, user, false, inTransaction, needLock, false); return resource; } return nodeFullCertification(resource.getUniqueId(), user, lifecycleChangeInfo, inTransaction, needLock); @@ -4333,7 +4329,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } else { newResource.setDerivedFrom(null); } - Either<Resource, ResponseFormat> dataModelResponse = updateResourceMetadata(resourceIdToUpdate, newResource, user, currentResource, false, + Either<Resource, ResponseFormat> dataModelResponse = updateResourceMetadata(resourceIdToUpdate, newResource, user, currentResource, true); if (dataModelResponse.isRight()) { log.debug("failed to update resource metadata!!!"); @@ -4355,7 +4351,7 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } private Either<Resource, ResponseFormat> updateResourceMetadata(String resourceIdToUpdate, Resource newResource, User user, - Resource currentResource, boolean shouldLock, boolean inTransaction) { + Resource currentResource, boolean inTransaction) { updateVfModuleGroupsNames(currentResource, newResource); validateResourceFieldsBeforeUpdate(currentResource, newResource, inTransaction, false); // Setting last updater and uniqueId @@ -5033,44 +5029,41 @@ public class ResourceBusinessLogic extends ComponentBusinessLogic { } public void iterateOverProperties(List<PropertyDefinition> properties, String model) { - String type = null; - String innerType = null; for (PropertyDefinition property : properties) { if (!propertyOperation.isPropertyTypeValid(property, model)) { log.info("Invalid type for property {}", property); throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY_TYPE, property.getType(), property.getName()); } Map<String, DataTypeDefinition> allDataTypes = componentsUtils.getAllDataTypes(applicationDataTypeCache, model); - type = property.getType(); + String type = property.getType(); if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) { - ResponseFormat responseFormat = validateMapOrListPropertyType(property, innerType, allDataTypes); + ResponseFormat responseFormat = validateMapOrListPropertyType(property, allDataTypes); if (responseFormat != null) { break; } } - validateDefaultPropertyValue(property, allDataTypes, type, innerType); + validateDefaultPropertyValue(property, allDataTypes, type); } } - private void validateDefaultPropertyValue(PropertyDefinition property, Map<String, DataTypeDefinition> allDataTypes, String type, - String innerType) { + private void validateDefaultPropertyValue(PropertyDefinition property, Map<String, DataTypeDefinition> allDataTypes, String type) { if (!propertyOperation.isPropertyDefaultValueValid(property, allDataTypes)) { log.info("Invalid default value for property {}", property); ResponseFormat responseFormat; if (type.equals(ToscaPropertyType.LIST.getType()) || type.equals(ToscaPropertyType.MAP.getType())) { - throw new ByActionStatusComponentException(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type, innerType, + throw new ByActionStatusComponentException(ActionStatus.INVALID_COMPLEX_DEFAULT_VALUE, property.getName(), type, property.getDefaultValue()); } throw new ByActionStatusComponentException(ActionStatus.INVALID_DEFAULT_VALUE, property.getName(), type, property.getDefaultValue()); } } - private ResponseFormat validateMapOrListPropertyType(PropertyDefinition property, String innerType, + private ResponseFormat validateMapOrListPropertyType(PropertyDefinition property, Map<String, DataTypeDefinition> allDataTypes) { ResponseFormat responseFormat = null; ImmutablePair<String, Boolean> propertyInnerTypeValid = propertyOperation.isPropertyInnerTypeValid(property, allDataTypes); - innerType = propertyInnerTypeValid.getLeft(); - if (!propertyInnerTypeValid.getRight()) { + String innerType = propertyInnerTypeValid.getLeft(); + if (Boolean.FALSE.equals(propertyInnerTypeValid.getRight())) { log.info("Invalid inner type for property {}", property); responseFormat = componentsUtils.getResponseFormat(ActionStatus.INVALID_PROPERTY_INNER_TYPE, innerType, property.getName()); } diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java index cee47ec984..714ec20c10 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/ResourceBusinessLogicTest.java @@ -322,7 +322,7 @@ class ResourceBusinessLogicTest { bl = new ResourceBusinessLogic(mockElementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactManager, componentInstanceBusinessLogic, resourceImportManager, inputsBusinessLogic, outputsBusinessLogic, compositionBusinessLogic, resourceDataMergeBusinessLogic, - csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, uiComponentDataConverter, csarBusinessLogic, + csarArtifactsAndGroupsBusinessLogic, uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation, propertyBusinessLogic, componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator, policyBusinessLogic, modelBusinessLogic, dataTypeBusinessLogic, policyTypeBusinessLogic, modelOperation); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java index 765be0a779..8650f9a10b 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/lifecycle/CheckoutTest.java @@ -20,6 +20,8 @@ package org.openecomp.sdc.be.components.lifecycle; +import static org.junit.jupiter.api.Assertions.assertTrue; + import fj.data.Either; import org.junit.Before; import org.junit.Test; @@ -52,19 +54,17 @@ import org.openecomp.sdc.be.model.operations.impl.ModelOperation; import org.openecomp.sdc.be.user.Role; import org.openecomp.sdc.exception.ResponseFormat; -import static org.junit.Assert.assertTrue; - public class CheckoutTest extends LifecycleTestBase { - private CheckoutTransition checkoutObj = null; - private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class); - private final ResourceImportManager resourceImportManager = Mockito.mock(ResourceImportManager.class); - private final InputsBusinessLogic inputsBusinessLogic = Mockito.mock(InputsBusinessLogic.class); - private final OutputsBusinessLogic outputsBusinessLogic = Mockito.mock(OutputsBusinessLogic.class); - private final CompositionBusinessLogic compositionBusinessLogic = Mockito.mock(CompositionBusinessLogic.class); - private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic = Mockito.mock(ResourceDataMergeBusinessLogic.class); - private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = Mockito.mock(CsarArtifactsAndGroupsBusinessLogic.class); - private final MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class); + private CheckoutTransition checkoutObj = null; + private final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class); + private final ResourceImportManager resourceImportManager = Mockito.mock(ResourceImportManager.class); + private final InputsBusinessLogic inputsBusinessLogic = Mockito.mock(InputsBusinessLogic.class); + private final OutputsBusinessLogic outputsBusinessLogic = Mockito.mock(OutputsBusinessLogic.class); + private final CompositionBusinessLogic compositionBusinessLogic = Mockito.mock(CompositionBusinessLogic.class); + private final ResourceDataMergeBusinessLogic resourceDataMergeBusinessLogic = Mockito.mock(ResourceDataMergeBusinessLogic.class); + private final CsarArtifactsAndGroupsBusinessLogic csarArtifactsAndGroupsBusinessLogic = Mockito.mock(CsarArtifactsAndGroupsBusinessLogic.class); + private final MergeInstanceUtils mergeInstanceUtils = Mockito.mock(MergeInstanceUtils.class); private final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class); private final CsarBusinessLogic csarBusinessLogic = Mockito.mock(CsarBusinessLogic.class); private final PropertyBusinessLogic propertyBusinessLogic = Mockito.mock(PropertyBusinessLogic.class); @@ -78,11 +78,10 @@ public class CheckoutTest extends LifecycleTestBase { ResourceBusinessLogic bl = new ResourceBusinessLogic(elementDao, groupOperation, groupInstanceOperation, groupTypeOperation, groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation, artifactsBusinessLogic, - componentInstanceBusinessLogic, resourceImportManager, inputsBusinessLogic, outputsBusinessLogic,compositionBusinessLogic, - resourceDataMergeBusinessLogic, csarArtifactsAndGroupsBusinessLogic, mergeInstanceUtils, - uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation, propertyBusinessLogic, - componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator, - componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator ,policyBusinessLogic, modelBusinessLogic, + componentInstanceBusinessLogic, resourceImportManager, inputsBusinessLogic, outputsBusinessLogic, compositionBusinessLogic, + resourceDataMergeBusinessLogic, csarArtifactsAndGroupsBusinessLogic, uiComponentDataConverter, csarBusinessLogic, artifactToscaOperation, + propertyBusinessLogic, componentContactIdValidator, componentNameValidator, componentTagsValidator, componentValidator, + componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator, policyBusinessLogic, modelBusinessLogic, dataTypeBusinessLogic, policyTypeBusinessLogic, modelOperation); @Before @@ -99,69 +98,73 @@ public class CheckoutTest extends LifecycleTestBase { } - @Test - public void testCheckoutStateValidation() { - Either<? extends Component, ResponseFormat> changeStateResult; - Resource resource = createResourceObject(); + @Test + public void testCheckoutStateValidation() { + Either<? extends Component, ResponseFormat> changeStateResult; + Resource resource = createResourceObject(); - resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN); - Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE); - assertTrue(ownerResponse.isLeft()); - User owner = ownerResponse.left().value(); - changeStateResult = checkoutObj.changeState(ComponentTypeEnum.RESOURCE, resource, bl, user, owner, false, false); - assertTrue(changeStateResult.isLeft()); + resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN); + Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE); + assertTrue(ownerResponse.isLeft()); + User owner = ownerResponse.left().value(); + changeStateResult = checkoutObj.changeState(ComponentTypeEnum.RESOURCE, resource, bl, user, owner, false, false); + assertTrue(changeStateResult.isLeft()); - resource.setLifecycleState(LifecycleStateEnum.CERTIFIED); + resource.setLifecycleState(LifecycleStateEnum.CERTIFIED); changeStateResult = checkoutObj.changeState(ComponentTypeEnum.RESOURCE, resource, bl, user, owner, false, false); assertTrue(changeStateResult.isLeft()); } - @Test - public void testAlreadyCheckout() { - Either<Resource, ResponseFormat> changeStateResult; - Resource resource = createResourceObject(); - - resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); - Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE); - assertTrue(ownerResponse.isLeft()); - User owner = ownerResponse.left().value(); - Either<Boolean, ResponseFormat> validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); - assertTrue(validateBeforeTransition.isRight()); - changeStateResult = Either.right(validateBeforeTransition.right().value()); - - assertTrue(changeStateResult.isRight()); - assertResponse(changeStateResult, ActionStatus.COMPONENT_IN_CHECKOUT_STATE, resource.getName(), ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId()); - - } - - @Test - public void testRoles() { - Either<Resource, ResponseFormat> changeStateResult; - Resource resource = createResourceObject(); - - resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN); - - User modifier = new User(); - modifier.setUserId("modifier"); - modifier.setFirstName("Albert"); - modifier.setLastName("Einstein"); - modifier.setRole(Role.DESIGNER.name()); - Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE); - assertTrue(ownerResponse.isLeft()); - User owner = ownerResponse.left().value(); - // changeStateResult = checkoutObj.changeStateOperation(resource, - // modifier, owner); - Either<Boolean, ResponseFormat> validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN); - assertTrue(validateBeforeTransition.isLeft()); - - modifier.setRole(Role.TESTER.name()); - // changeStateResult = checkoutObj.changeStateOperation(resource, - // modifier, owner); - validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN); - assertTrue(validateBeforeTransition.isRight()); - changeStateResult = Either.right(validateBeforeTransition.right().value()); - assertResponse(changeStateResult, ActionStatus.RESTRICTED_OPERATION); - - } + @Test + public void testAlreadyCheckout() { + Either<Resource, ResponseFormat> changeStateResult; + Resource resource = createResourceObject(); + + resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); + Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE); + assertTrue(ownerResponse.isLeft()); + User owner = ownerResponse.left().value(); + Either<Boolean, ResponseFormat> validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, user, + owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT); + assertTrue(validateBeforeTransition.isRight()); + changeStateResult = Either.right(validateBeforeTransition.right().value()); + + assertTrue(changeStateResult.isRight()); + assertResponse(changeStateResult, ActionStatus.COMPONENT_IN_CHECKOUT_STATE, resource.getName(), + ComponentTypeEnum.RESOURCE.name().toLowerCase(), user.getFirstName(), user.getLastName(), user.getUserId()); + + } + + @Test + public void testRoles() { + Either<Resource, ResponseFormat> changeStateResult; + Resource resource = createResourceObject(); + + resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN); + + User modifier = new User(); + modifier.setUserId("modifier"); + modifier.setFirstName("Albert"); + modifier.setLastName("Einstein"); + modifier.setRole(Role.DESIGNER.name()); + Either<User, ResponseFormat> ownerResponse = checkoutObj.getComponentOwner(resource, ComponentTypeEnum.RESOURCE); + assertTrue(ownerResponse.isLeft()); + User owner = ownerResponse.left().value(); + // changeStateResult = checkoutObj.changeStateOperation(resource, + // modifier, owner); + Either<Boolean, ResponseFormat> validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, + modifier, owner, LifecycleStateEnum.NOT_CERTIFIED_CHECKIN); + assertTrue(validateBeforeTransition.isLeft()); + + modifier.setRole(Role.TESTER.name()); + // changeStateResult = checkoutObj.changeStateOperation(resource, + // modifier, owner); + validateBeforeTransition = checkoutObj.validateBeforeTransition(resource, ComponentTypeEnum.RESOURCE, modifier, owner, + LifecycleStateEnum.NOT_CERTIFIED_CHECKIN); + assertTrue(validateBeforeTransition.isRight()); + changeStateResult = Either.right(validateBeforeTransition.right().value()); + assertResponse(changeStateResult, ActionStatus.RESTRICTED_OPERATION); + + } } 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 234ee43f05..001c6c7e37 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 @@ -99,6 +99,7 @@ import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComputeEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.DeploymentFlavorEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ImageEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.LicenseType; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.NicEntity; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OnboardingMethod; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.OrchestrationTemplateEntity; @@ -142,7 +143,7 @@ import org.openecomp.sdc.versioning.dao.types.Version; public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductManager { - private static final Logger LOGGER = LoggerFactory.getLogger(VendorSoftwareProductManager.class); + private static final Logger LOGGER = LoggerFactory.getLogger(VendorSoftwareProductManagerImpl.class); private VspMergeDao vspMergeDao; private OrchestrationTemplateDao orchestrationTemplateDao; private OrchestrationTemplateCandidateManager orchestrationTemplateCandidateManager; @@ -386,7 +387,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa private Map<String, List<ErrorMessage>> compile(String vendorSoftwareProductId, Version version, ToscaServiceModel serviceModel) { if (isServiceModelMissing(serviceModel)) { - return null; + return Collections.emptyMap(); } enrichedServiceModelDao.deleteAll(vendorSoftwareProductId, version); if (CollectionUtils.isNotEmpty(serviceModel.getModelList())) { @@ -552,9 +553,8 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa populateVersionsForVlm(vspDetails.getVendorId(), vlmVersion); } final PackageInfo packageInfo = createPackageInfo(vspDetails); - final ToscaFileOutputServiceCsarImpl toscaServiceTemplateServiceCsar = new ToscaFileOutputServiceCsarImpl(new AsdPackageHelper(new ManifestUtils())); - final FileContentHandler licenseArtifacts = licenseArtifactsService - .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups()); + final ToscaFileOutputServiceCsarImpl toscaServiceTemplateServiceCsar = new ToscaFileOutputServiceCsarImpl( + new AsdPackageHelper(new ManifestUtils())); final ETSIService etsiService = new ETSIServiceImpl(); if (etsiService.hasEtsiSol261Metadata(toscaServiceModel.getArtifactFiles())) { final FileContentHandler handler = toscaServiceModel.getArtifactFiles(); @@ -566,6 +566,11 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa packageInfo.setVendorRelease(etsiService.getHighestCompatibleSpecificationVersion(handler).getOriginalValue()); } } + FileContentHandler licenseArtifacts = null; + if (!LicenseType.EXTERNAL.name().equals(vspDetails.getLicenseType())) { + licenseArtifacts = licenseArtifactsService + .createLicenseArtifacts(vspDetails.getId(), vspDetails.getVendorId(), vlmVersion, vspDetails.getFeatureGroups()); + } packageInfo.setTranslatedFile(ByteBuffer.wrap(toscaServiceTemplateServiceCsar.createOutputFile(toscaServiceModel, licenseArtifacts))); packageInfoDao.create(packageInfo); return packageInfo; @@ -613,7 +618,7 @@ public class VendorSoftwareProductManagerImpl implements VendorSoftwareProductMa private Map<String, List<ErrorMessage>> validateOrchestrationTemplate(OrchestrationTemplateEntity orchestrationTemplate) throws IOException { if (isOrchestrationTemplateMissing(orchestrationTemplate)) { - return null; + return Collections.emptyMap(); } Map<String, List<ErrorMessage>> validationErrors = new HashMap<>(); FileContentHandler fileContentMap = CommonUtil diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/VendorLicenseConstants.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/VendorLicenseConstants.java index d43797e498..2f1d385e48 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/VendorLicenseConstants.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-api/src/main/java/org/openecomp/sdc/vendorlicense/VendorLicenseConstants.java @@ -19,18 +19,24 @@ */ package org.openecomp.sdc.vendorlicense; +import static org.openecomp.sdc.common.api.Constants.VENDOR_LICENSE_MODEL; +import static org.openecomp.sdc.common.api.Constants.VF_LICENSE_MODEL; + import java.io.File; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; public final class VendorLicenseConstants { public static final String VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE = "VendorLicenseModel"; public static final String EXTERNAL_ARTIFACTS_DIR = "Artifacts"; //todo change when separating external from internal artifacts - public static final String VNF_ARTIFACT_NAME_WITH_PATH = EXTERNAL_ARTIFACTS_DIR + File.separator + "vf-license-model.xml"; - public static final String VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH = EXTERNAL_ARTIFACTS_DIR + File.separator + "vendor-license-model.xml"; + public static final String VNF_ARTIFACT_NAME_WITH_PATH = EXTERNAL_ARTIFACTS_DIR + File.separator + VF_LICENSE_MODEL; + public static final String VENDOR_LICENSE_MODEL_ARTIFACT_NAME_WITH_PATH = EXTERNAL_ARTIFACTS_DIR + File.separator + VENDOR_LICENSE_MODEL; public static final String VENDOR_LICENSE_MODEL_ARTIFACT_REGEX_REMOVE = " xmlns=\"\""; public static final String UNSUPPORTED_OPERATION_ERROR = "An error has occurred: Unsupported operation for 1707 release."; + @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class UniqueValues { public static final String VENDOR_NAME = "Vendor name"; diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VendorLicenseModelDaoZusammenImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VendorLicenseModelDaoZusammenImpl.java index 8f974c4df8..0453b305f3 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VendorLicenseModelDaoZusammenImpl.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/VendorLicenseModelDaoZusammenImpl.java @@ -15,6 +15,7 @@ */ package org.openecomp.sdc.vendorlicense.dao.impl.zusammen; +import static org.openecomp.sdc.vendorlicense.VendorLicenseConstants.VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE; import static org.openecomp.sdc.versioning.dao.impl.zusammen.ItemZusammenDaoImpl.ItemInfoProperty.ITEM_TYPE; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; @@ -44,7 +45,8 @@ public class VendorLicenseModelDaoZusammenImpl implements VendorLicenseModelDao @Override public void registerVersioning(String versionableEntityType) { - VersionableEntityMetadata metadata = new VersionableEntityMetadata(VersionableEntityStoreType.Zusammen, "VendorLicenseModel", null, null); + VersionableEntityMetadata metadata = new VersionableEntityMetadata(VersionableEntityStoreType.Zusammen, VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE, + null, null); ActionVersioningManagerFactory.getInstance().createInterface().register(versionableEntityType, metadata); } @@ -52,7 +54,7 @@ public class VendorLicenseModelDaoZusammenImpl implements VendorLicenseModelDao public Collection<VendorLicenseModelEntity> list(VendorLicenseModelEntity vendorLicenseModelEntity) { ElementToVLMGeneralConvertor convertor = new ElementToVLMGeneralConvertor(); return zusammenAdaptor.listItems(ZusammenUtil.createSessionContext()).stream() - .filter(item -> "VendorLicenseModel".equals(item.getInfo().getProperty(ITEM_TYPE.getName()))).map(item -> { + .filter(item -> VENDOR_LICENSE_MODEL_VERSIONABLE_TYPE.equals(item.getInfo().getProperty(ITEM_TYPE.getName()))).map(item -> { VendorLicenseModelEntity entity = convertor.convert(item); entity.setId(item.getId().getValue()); entity.setVersion(null); @@ -109,10 +111,10 @@ public class VendorLicenseModelDaoZusammenImpl implements VendorLicenseModelDao } private void addVlmToInfo(Info info, VendorLicenseModelEntity vendorLicenseModel) { - info.addProperty(InfoPropertyName.name.name(), vendorLicenseModel.getVendorName()); - info.addProperty(InfoPropertyName.description.name(), vendorLicenseModel.getDescription()); - info.addProperty(InfoPropertyName.iconRef.name(), vendorLicenseModel.getIconRef()); + info.addProperty(InfoPropertyName.NAME.name(), vendorLicenseModel.getVendorName()); + info.addProperty(InfoPropertyName.DESCRIPTION.name(), vendorLicenseModel.getDescription()); + info.addProperty(InfoPropertyName.ICON_REF.name(), vendorLicenseModel.getIconRef()); } - public enum InfoPropertyName {name, description, iconRef,} + public enum InfoPropertyName {NAME, DESCRIPTION, ICON_REF,} } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertor.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertor.java index e274e264c0..aef20cf490 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertor.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/main/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertor.java @@ -55,9 +55,9 @@ public class ElementToVLMGeneralConvertor extends ElementConvertor { private VendorLicenseModelEntity mapInfoToVendorLicenseModelEntity(Info info) { VendorLicenseModelEntity vendorLicenseModelEntity = new VendorLicenseModelEntity(); - vendorLicenseModelEntity.setVendorName(info.getProperty(VendorLicenseModelDaoZusammenImpl.InfoPropertyName.name.name())); - vendorLicenseModelEntity.setDescription(info.getProperty(VendorLicenseModelDaoZusammenImpl.InfoPropertyName.description.name())); - vendorLicenseModelEntity.setIconRef(info.getProperty(VendorLicenseModelDaoZusammenImpl.InfoPropertyName.iconRef.name())); + vendorLicenseModelEntity.setVendorName(info.getProperty(VendorLicenseModelDaoZusammenImpl.InfoPropertyName.NAME.name())); + vendorLicenseModelEntity.setDescription(info.getProperty(VendorLicenseModelDaoZusammenImpl.InfoPropertyName.DESCRIPTION.name())); + vendorLicenseModelEntity.setIconRef(info.getProperty(VendorLicenseModelDaoZusammenImpl.InfoPropertyName.ICON_REF.name())); return vendorLicenseModelEntity; } } diff --git a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/test/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertorTest.java b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/test/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertorTest.java index 45660a6854..9d9f002c9b 100644 --- a/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/test/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertorTest.java +++ b/openecomp-be/lib/openecomp-sdc-vendor-license-lib/openecomp-sdc-vendor-license-core/src/test/java/org/openecomp/sdc/vendorlicense/dao/impl/zusammen/convertor/ElementToVLMGeneralConvertorTest.java @@ -15,15 +15,16 @@ */ package org.openecomp.sdc.vendorlicense.dao.impl.zusammen.convertor; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ElementInfo; import com.amdocs.zusammen.adaptor.inbound.api.types.item.ZusammenElement; import com.amdocs.zusammen.datatypes.item.Info; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.vendorlicense.dao.impl.zusammen.VendorLicenseModelDaoZusammenImpl; import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity; -public class ElementToVLMGeneralConvertorTest { +class ElementToVLMGeneralConvertorTest { private static final String ENTITY_NAME = "entityTestName"; private static final String ENTITY_DESCRIPTION = "entityTestDesc"; @@ -31,30 +32,27 @@ public class ElementToVLMGeneralConvertorTest { private ElementToVLMGeneralConvertor converter = new ElementToVLMGeneralConvertor(); @Test - public void shouldConvertElementToVendorLicenseModelEntity() { + void shouldConvertElementToVendorLicenseModelEntity() { ZusammenElement elementToConvert = new ZusammenElement(); Info info = new Info(); - info.addProperty("name",ENTITY_NAME); - info.addProperty("description",ENTITY_DESCRIPTION); + info.addProperty(VendorLicenseModelDaoZusammenImpl.InfoPropertyName.NAME.name(), ENTITY_NAME); + info.addProperty(VendorLicenseModelDaoZusammenImpl.InfoPropertyName.DESCRIPTION.name(), ENTITY_DESCRIPTION); elementToConvert.setInfo(info); VendorLicenseModelEntity result = converter.convert(elementToConvert); assertEquals(ENTITY_NAME, result.getVendorName()); assertEquals(ENTITY_DESCRIPTION, result.getDescription()); - - } @Test - public void shouldConvertElementInfoToVendorLicenseModelEntity() { + void shouldConvertElementInfoToVendorLicenseModelEntity() { ElementInfo elementInfo = new ElementInfo(); Info info = new Info(); - info.addProperty("name",ENTITY_NAME); - info.addProperty("description",ENTITY_DESCRIPTION); + info.addProperty(VendorLicenseModelDaoZusammenImpl.InfoPropertyName.NAME.name(), ENTITY_NAME); + info.addProperty(VendorLicenseModelDaoZusammenImpl.InfoPropertyName.DESCRIPTION.name(), ENTITY_DESCRIPTION); elementInfo.setInfo(info); VendorLicenseModelEntity result = converter.convert(elementInfo); assertEquals(ENTITY_NAME, result.getVendorName()); assertEquals(ENTITY_DESCRIPTION, result.getDescription()); } - } |