diff options
author | KrupaNagabhushan <krupa.nagabhushan@est.tech> | 2021-07-26 12:50:21 +0100 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2021-08-04 15:21:35 +0000 |
commit | 4959218f8ced87d458151d14a38891b1fdc70c7d (patch) | |
tree | d76430e0ff7862a8401186e635de0ed51bf9bc04 /catalog-be/src/main | |
parent | 865af7fcb1c1af73498dedaf426ee55e9f373537 (diff) |
Consider component model when retrieving group and policy types
Issue-ID: SDC-3659
Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech>
Change-Id: I6d58e51e70085adf114e6efd0c29b00b14358b39
Diffstat (limited to 'catalog-be/src/main')
9 files changed, 126 insertions, 36 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java index 2ab68e8db1..eefe47f69c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java @@ -592,7 +592,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { resource.setDeploymentArtifacts(createdArtifactsMap); if (groupName != null && !groupName.isEmpty()) { Either<GroupDefinition, ResponseFormat> groupDefinitionEither = buildGroupDefinition(createdArtifacts, heatGroups, groupTemplateInfo, - groupName, artifactsGroup, artifactsUUIDGroup); + groupName, artifactsGroup, artifactsUUIDGroup, resource.getModel()); if (groupDefinitionEither.isRight()) { return Either.right(groupDefinitionEither.right().value()); } @@ -611,7 +611,8 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { private Either<GroupDefinition, ResponseFormat> buildGroupDefinition(List<ArtifactDefinition> createdArtifacts, List<GroupDefinition> heatGroups, ArtifactTemplateInfo groupTemplateInfo, String groupName, - Set<String> artifactsGroup, Set<String> artifactsUUIDGroup) { + Set<String> artifactsGroup, Set<String> artifactsUUIDGroup, + String model) { Map<String, String> members = new HashMap<>(); associateMembersToArtifacts(createdArtifacts, null, heatGroups, artifactsGroup, members); List<String> artifactsList = new ArrayList<>(artifactsGroup); @@ -630,7 +631,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { prop.setValue(Boolean.toString(groupTemplateInfo.isBase())); properties.add(prop); Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeRes = groupTypeOperation - .getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, true); + .getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, model); if (getLatestGroupTypeRes.isRight()) { return Either.right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getLatestGroupTypeRes.right().value()))); } @@ -1197,7 +1198,7 @@ public class CsarArtifactsAndGroupsBusinessLogic extends BaseBusinessLogic { createdArtifacts.addAll(createdNewArtifacts); createdArtifacts.addAll(artifactsFromResource); Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeRes = groupTypeOperation - .getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, true); + .getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, resource.getModel()); if (getLatestGroupTypeRes.isRight()) { return Either .right(componentsUtils.getResponseFormat(componentsUtils.convertFromStorageResponse(getLatestGroupTypeRes.right().value()))); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java index e04a4011cc..5d4549406c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java @@ -135,9 +135,9 @@ public class YamlTemplateParsingHandler { findToscaElement(mappedToscaTemplate, TOPOLOGY_TEMPLATE, ToscaElementTypeEnum.ALL).left().on(err -> failIfNotTopologyTemplate(fileName)); parsedToscaYamlInfo.setInputs(getInputs(mappedToscaTemplate)); parsedToscaYamlInfo.setInstances(getInstances(fileName, mappedToscaTemplate, createdNodesToscaResourceNames)); - parsedToscaYamlInfo.setGroups(getGroups(fileName, mappedToscaTemplate)); + parsedToscaYamlInfo.setGroups(getGroups(fileName, mappedToscaTemplate, component.getModel())); if (component instanceof Resource) { - parsedToscaYamlInfo.setPolicies(getPolicies(fileName, mappedToscaTemplate)); + parsedToscaYamlInfo.setPolicies(getPolicies(fileName, mappedToscaTemplate, component.getModel())); } log.debug("#parseResourceInfoFromYAML - The yaml {} has been parsed ", fileName); return parsedToscaYamlInfo; @@ -176,15 +176,15 @@ public class YamlTemplateParsingHandler { return inputs; } - private Map<String, PolicyDefinition> getPolicies(String fileName, Map<String, Object> toscaJson) { + private Map<String, PolicyDefinition> getPolicies(String fileName, Map<String, Object> toscaJson, String model) { Map<String, Object> foundPolicies = findFirstToscaMapElement(toscaJson, POLICIES).left().on(err -> logPoliciesNotFound(fileName)); if (MapUtils.isNotEmpty(foundPolicies)) { - return foundPolicies.entrySet().stream().map(this::createPolicy).collect(Collectors.toMap(PolicyDefinition::getName, p -> p)); + return foundPolicies.entrySet().stream().map(policyToCreate -> createPolicy(policyToCreate, model)).collect(Collectors.toMap(PolicyDefinition::getName, p -> p)); } return Collections.emptyMap(); } - private PolicyDefinition createPolicy(Map.Entry<String, Object> policyNameValue) { + private PolicyDefinition createPolicy(Map.Entry<String, Object> policyNameValue, String model) { PolicyDefinition emptyPolicyDef = new PolicyDefinition(); String policyName = policyNameValue.getKey(); emptyPolicyDef.setName(policyName); @@ -192,7 +192,7 @@ public class YamlTemplateParsingHandler { // There's no need to null test in conjunction with an instanceof test. null is not an instanceof anything, so a null check is redundant. if (policyNameValue.getValue() instanceof Map) { Map<String, Object> policyTemplateJsonMap = (Map<String, Object>) policyNameValue.getValue(); - validateAndFillPolicy(emptyPolicyDef, policyTemplateJsonMap); + validateAndFillPolicy(emptyPolicyDef, policyTemplateJsonMap, model); } else { rollbackWithException(ActionStatus.NOT_TOPOLOGY_TOSCA_TEMPLATE); } @@ -208,7 +208,7 @@ public class YamlTemplateParsingHandler { return Collections.emptyMap(); } - private void validateAndFillPolicy(PolicyDefinition emptyPolicyDefinition, Map<String, Object> policyTemplateJsonMap) { + private void validateAndFillPolicy(PolicyDefinition emptyPolicyDefinition, Map<String, Object> policyTemplateJsonMap, String model) { String policyTypeName = (String) policyTemplateJsonMap.get(TYPE.getElementName()); if (StringUtils.isEmpty(policyTypeName)) { log.debug("#validateAndFillPolicy - The 'type' member is not found under policy {}", emptyPolicyDefinition.getName()); @@ -217,13 +217,13 @@ public class YamlTemplateParsingHandler { emptyPolicyDefinition.setType(policyTypeName); // set policy targets emptyPolicyDefinition.setTargets(validateFillPolicyTargets(policyTemplateJsonMap)); - PolicyTypeDefinition policyTypeDefinition = validateGetPolicyTypeDefinition(policyTypeName); + PolicyTypeDefinition policyTypeDefinition = validateGetPolicyTypeDefinition(policyTypeName, model); // set policy properties emptyPolicyDefinition.setProperties(validateFillPolicyProperties(policyTypeDefinition, policyTemplateJsonMap)); } - private PolicyTypeDefinition validateGetPolicyTypeDefinition(String policyType) { - PolicyTypeDefinition policyTypeDefinition = policyTypeBusinessLogic.getLatestPolicyTypeByType(policyType); + private PolicyTypeDefinition validateGetPolicyTypeDefinition(String policyType, String modelName) { + PolicyTypeDefinition policyTypeDefinition = policyTypeBusinessLogic.getLatestPolicyTypeByType(policyType, modelName); if (policyTypeDefinition == null) { log.debug("#validateAndFillPolicy - The policy type {} not found", policyType); rollbackWithException(ActionStatus.POLICY_TYPE_IS_INVALID, policyType); @@ -293,10 +293,10 @@ public class YamlTemplateParsingHandler { } @SuppressWarnings("unchecked") - private Map<String, GroupDefinition> getGroups(String fileName, Map<String, Object> toscaJson) { + private Map<String, GroupDefinition> getGroups(String fileName, Map<String, Object> toscaJson, String model) { Map<String, Object> foundGroups = findFirstToscaMapElement(toscaJson, GROUPS).left().on(err -> logGroupsNotFound(fileName)); if (MapUtils.isNotEmpty(foundGroups) && matcheKey(foundGroups)) { - Map<String, GroupDefinition> groups = foundGroups.entrySet().stream().map(this::createGroup) + Map<String, GroupDefinition> groups = foundGroups.entrySet().stream().map(groupToCreate -> createGroup(groupToCreate, model)) .collect(Collectors.toMap(GroupDefinition::getName, g -> g)); Map<String, Object> substitutionMappings = getSubstitutionMappings(toscaJson); if (capabilitiesSubstitutionMappingsExist(substitutionMappings)) { @@ -343,13 +343,13 @@ public class YamlTemplateParsingHandler { return substitutionMappings != null && substitutionMappings.containsKey(CAPABILITIES.getElementName()); } - private GroupDefinition createGroup(Map.Entry<String, Object> groupNameValue) { + private GroupDefinition createGroup(Map.Entry<String, Object> groupNameValue, String model) { GroupDefinition group = new GroupDefinition(); group.setName(groupNameValue.getKey()); try { if (groupNameValue.getValue() instanceof Map) { Map<String, Object> groupTemplateJsonMap = (Map<String, Object>) groupNameValue.getValue(); - validateAndFillGroup(group, groupTemplateJsonMap); + validateAndFillGroup(group, groupTemplateJsonMap, model); validateUpdateGroupProperties(group, groupTemplateJsonMap); validateUpdateGroupCapabilities(group, groupTemplateJsonMap); } else { @@ -443,14 +443,14 @@ public class YamlTemplateParsingHandler { } } - private void validateAndFillGroup(GroupDefinition groupInfo, Map<String, Object> groupTemplateJsonMap) { + private void validateAndFillGroup(GroupDefinition groupInfo, Map<String, Object> groupTemplateJsonMap, String model) { String type = (String) groupTemplateJsonMap.get(TYPE.getElementName()); if (StringUtils.isEmpty(type)) { log.debug("#validateAndFillGroup - The 'type' member is not found under group {}", groupInfo.getName()); rollbackWithException(ActionStatus.GROUP_MISSING_GROUP_TYPE, groupInfo.getName()); } groupInfo.setType(type); - GroupTypeDefinition groupType = groupTypeBusinessLogic.getLatestGroupTypeByType(type); + GroupTypeDefinition groupType = groupTypeBusinessLogic.getLatestGroupTypeByType(type, model); if (groupType == null) { log.debug("#validateAndFillGroup - The group type {} not found", groupInfo.getName()); rollbackWithException(ActionStatus.GROUP_TYPE_IS_INVALID, type); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java index b4e1594a41..9a77aad0b2 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java @@ -340,6 +340,95 @@ public class CommonImportManager { } } + protected <T> Either<List<ImmutablePair<T, Boolean>>, ResponseFormat> createElementTypesWithVersionByDao(List<T> elementTypesToCreate, + Function<T, Either<ActionStatus, ResponseFormat>> validator, + Function<T, ImmutablePair<ElementTypeEnum, String>> elementInfoGetter, + BiFunction<String, String, Either<T, StorageOperationStatus>> elementFetcher, + Function<T, Either<T, StorageOperationStatus>> elementAdder, + BiFunction<T, T, Either<T, StorageOperationStatus>> elementUpgrader, + String modelName) { + + List<ImmutablePair<T, Boolean>> createdElementTypes = new ArrayList<>(); + + Either<List<ImmutablePair<T, Boolean>>, ResponseFormat> eitherResult = Either.left(createdElementTypes); + Iterator<T> elementTypeItr = elementTypesToCreate.iterator(); + + try { + while (elementTypeItr.hasNext()) { + T elementType = elementTypeItr.next(); + eitherResult = handleTypeByDao(elementType, validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader, modelName) + .left() + .map(elem -> append(createdElementTypes, elem)); + + if (eitherResult.isRight()) { + break; + } + + if (!elementTypeItr.hasNext()) { + log.info("all {} were created successfully!!!", elementType); + } + } + } catch (Exception e) { + eitherResult = Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR)); + throw e; + } finally { + if (eitherResult.isLeft()) { + propertyOperation.getJanusGraphGenericDao().commit(); + } else { + propertyOperation.getJanusGraphGenericDao().rollback(); + } + } + + return eitherResult; + } + + private <T> Either<ImmutablePair<T, Boolean>, ResponseFormat> handleTypeByDao(T elementType, + Function<T, Either<ActionStatus, ResponseFormat>> validator, + Function<T, ImmutablePair<ElementTypeEnum, String>> elementInfoGetter, + BiFunction<String, String, Either<T, StorageOperationStatus>> elementFetcher, + Function<T, Either<T, StorageOperationStatus>> elementAdder, + BiFunction<T, T, Either<T, StorageOperationStatus>> elementUpgrader, + String modelName) { + + final ImmutablePair<ElementTypeEnum, String> elementInfo = elementInfoGetter.apply(elementType); + ElementTypeEnum elementTypeEnum = elementInfo.left; + String elementName = elementInfo.right; + + Either<ActionStatus, ResponseFormat> validateElementType = validator.apply(elementType); + if (validateElementType.isRight()) { + ResponseFormat responseFormat = validateElementType.right().value(); + log.debug("Failed in validation of element type: {}. Response is {}", elementType, responseFormat.getFormattedMessage()); + return Either.right(responseFormat); + } + + log.info("send {} : {} to dao for create", elementTypeEnum, elementName); + + Either<T, StorageOperationStatus> findElementType = elementFetcher.apply(elementName, modelName); + if (findElementType.isRight()) { + StorageOperationStatus status = findElementType.right().value(); + log.debug("searched {} finished with result:{}", elementTypeEnum, status); + if (status != StorageOperationStatus.NOT_FOUND) { + ResponseFormat responseFormat = getResponseFormatForElementType(convertFromStorageResponseForElementType(status, elementTypeEnum), + elementTypeEnum, elementType); + return Either.right(responseFormat); + } else { + return addElementType(elementType, elementAdder, elementTypeEnum, elementName); + } + } else { + + if (elementUpgrader != null) { + return updateElementType(elementType, elementUpgrader, elementTypeEnum, elementName, findElementType.left().value()); + + } else { + // mshitrit Once GroupType Versions are supported add + // code here + log.debug("{} : {} already exists.", elementTypeEnum, elementName); + return Either.left(new ImmutablePair<>(elementType, false)); + } + + } + } + private <T> Either<ImmutablePair<T, Boolean>, ResponseFormat> addElementType(T elementType, Function<T, Either<T, StorageOperationStatus>> elementAdder, ElementTypeEnum elementTypeEnum, String elementName) { @@ -384,7 +473,7 @@ public class CommonImportManager { public <T extends ToscaTypeDataDefinition> Either<List<ImmutablePair<T, Boolean>>, ResponseFormat> createElementTypes( ToscaTypeImportData toscaTypeImportData, BiFunction<String, String, Either<List<T>, ActionStatus>> elementTypeFromYmlCreater, - Function<List<T>, Either<List<ImmutablePair<T, Boolean>>, ResponseFormat>> elementTypeDaoCreater, String modelName) { + BiFunction<List<T>, String, Either<List<ImmutablePair<T, Boolean>>, ResponseFormat>> elementTypeDaoCreater, String modelName) { Either<List<T>, ActionStatus> elementTypes = elementTypeFromYmlCreater.apply(toscaTypeImportData.getToscaTypesYml(), modelName); return elementTypes .right() @@ -392,7 +481,7 @@ public class CommonImportManager { .left() .map(toscaTypes -> enrichTypesWithNonToscaMetadata(toscaTypes, toscaTypeImportData.getToscaTypeMetadata())) .left() - .bind(elementTypeDaoCreater::apply); + .bind(elementTypeList -> elementTypeDaoCreater.apply(elementTypeList, modelName)); } public <T extends ToscaDataDefinition> List<ImmutablePair<T, Boolean>> createElementTypes(String toscaTypesYml, diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java index 45d6b74f8d..0d85675c45 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java @@ -948,7 +948,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic { public GroupDefinition createGroup(String componentId, ComponentTypeEnum componentTypeEnum, String groupType, String userId) { Component component = accessValidations.validateUserCanWorkOnComponent(componentId, componentTypeEnum, userId, CREATE_GROUP); validateGroupTypePerComponent(groupType, component); - GroupTypeDefinition groupTypeDefinition = groupTypeOperation.getLatestGroupTypeByType(groupType, false).left() + GroupTypeDefinition groupTypeDefinition = groupTypeOperation.getLatestGroupTypeByType(groupType, component.getModel(), false).left() .on(se -> onGroupTypeNotFound(component)); boolean hasExistingGroups = CollectionUtils.isNotEmpty(component.getGroups()); GroupDefinition groupDefinition = new GroupDefinition(); @@ -1240,7 +1240,7 @@ public class GroupBusinessLogic extends BaseBusinessLogic { if (StringUtils.isEmpty(groupType)) { return Either.right(componentsUtils.getResponseFormat(ActionStatus.GROUP_MISSING_GROUP_TYPE, groupDefinitionName)); } - Either<GroupTypeDefinition, StorageOperationStatus> getGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType, true); + Either<GroupTypeDefinition, StorageOperationStatus> getGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType, component.getModel(), true); if (getGroupType.isRight()) { StorageOperationStatus status = getGroupType.right().value(); if (status == StorageOperationStatus.NOT_FOUND) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java index 823612e4e1..5ee62c0b19 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java @@ -69,8 +69,8 @@ public class GroupTypeBusinessLogic { } } - public GroupTypeDefinition getLatestGroupTypeByType(String groupTypeName) { - return groupTypeOperation.getLatestGroupTypeByType(groupTypeName, true).left().on(e -> failOnGetGroupType(e, groupTypeName)); + public GroupTypeDefinition getLatestGroupTypeByType(String groupTypeName, String modelName) { + return groupTypeOperation.getLatestGroupTypeByType(groupTypeName, modelName).left().on(e -> failOnGetGroupType(e, groupTypeName)); } public Set<String> getExcludedGroupTypes(String internalComponentType) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java index 8015685403..4983c0160f 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java @@ -77,11 +77,11 @@ public class GroupTypeImportManager { } private Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> upsertGroupTypesByDao( - List<GroupTypeDefinition> groupTypesToCreate) { - return commonImportManager.createElementTypesByDao(groupTypesToCreate, this::validateGroupType, + List<GroupTypeDefinition> groupTypesToCreate, String modelName) { + return commonImportManager.createElementTypesWithVersionByDao(groupTypesToCreate, this::validateGroupType, groupType -> new ImmutablePair<>(ElementTypeEnum.GROUP_TYPE, UniqueIdBuilder.buildGroupTypeUid(groupType.getModel(), groupType.getType(), groupType.getVersion(), NodeTypeEnum.GroupType.getName()).toLowerCase()), groupTypeOperation::getLatestGroupTypeByType, - groupTypeOperation::addGroupType, this::updateGroupType); + groupTypeOperation::addGroupType, this::updateGroupType, modelName); } private Either<GroupTypeDefinition, StorageOperationStatus> updateGroupType(GroupTypeDefinition newGroupType, GroupTypeDefinition oldGroupType) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java index 8c18d07495..f8aab3def1 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java @@ -554,7 +554,7 @@ public class PolicyBusinessLogic extends BaseBusinessLogic { } private PolicyTypeDefinition validatePolicyTypeOnCreatePolicy(String policyTypeName, Component component) { - Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyTypeByType = policyTypeOperation.getLatestPolicyTypeByType(policyTypeName); + Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyTypeByType = policyTypeOperation.getLatestPolicyTypeByType(policyTypeName, component.getModel()); if (latestPolicyTypeByType.isRight()) { throw new ByActionStatusComponentException(componentsUtils.convertFromStorageResponse(latestPolicyTypeByType.right().value())); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java index 99b56e7330..1e0a55fd07 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java @@ -60,8 +60,8 @@ public class PolicyTypeBusinessLogic { return getPolicyTypes(excludedPolicyTypes, modelName); } - public PolicyTypeDefinition getLatestPolicyTypeByType(String policyTypeName) { - return policyTypeOperation.getLatestPolicyTypeByType(policyTypeName).left().on(e -> failOnPolicyType(e, policyTypeName)); + public PolicyTypeDefinition getLatestPolicyTypeByType(String policyTypeName, String modelName) { + return policyTypeOperation.getLatestPolicyTypeByType(policyTypeName, modelName).left().on(e -> failOnPolicyType(e, policyTypeName)); } public Set<String> getExcludedPolicyTypes(String internalComponentType) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java index 48519d9abe..d10680db0d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java @@ -77,11 +77,11 @@ public class PolicyTypeImportManager { } private Either<List<ImmutablePair<PolicyTypeDefinition, Boolean>>, ResponseFormat> upsertPolicyTypesByDao( - List<PolicyTypeDefinition> policyTypesToCreate) { - return commonImportManager.createElementTypesByDao(policyTypesToCreate, this::validatePolicyType, + List<PolicyTypeDefinition> policyTypesToCreate, String modelName) { + return commonImportManager.createElementTypesWithVersionByDao(policyTypesToCreate, this::validatePolicyType, policyType -> new ImmutablePair<>(ElementTypeEnum.POLICY_TYPE, UniqueIdBuilder.buildPolicyTypeUid(policyType.getModel(), policyType.getType(), policyType.getVersion(), NodeTypeEnum.PolicyType.getName()).toLowerCase()), policyTypeOperation::getLatestPolicyTypeByType, - policyTypeOperation::addPolicyType, this::updatePolicyType); + policyTypeOperation::addPolicyType, this::updatePolicyType, modelName); } private Either<PolicyTypeDefinition, StorageOperationStatus> updatePolicyType(PolicyTypeDefinition newPolicyType, @@ -108,7 +108,7 @@ public class PolicyTypeImportManager { boolean isValid = toscaOperationFacade.getLatestByToscaResourceName(targetId).isLeft(); if (!isValid) { // check if it is a groupType final Either<GroupTypeDefinition, StorageOperationStatus> groupTypeFound = groupTypeOperation - .getLatestGroupTypeByType(targetId, false); + .getLatestGroupTypeByType(targetId, policyType.getModel(), false); isValid = groupTypeFound.isLeft() && !groupTypeFound.left().value().isEmpty(); } if (!isValid) { |