summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarArtifactsAndGroupsBusinessLogic.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java32
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java93
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java6
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogic.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogic.java4
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/PolicyTypeImportManager.java8
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java6
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java8
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java6
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java9
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupTypeOperation.java8
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java2
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java68
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java43
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java24
-rw-r--r--catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java20
19 files changed, 214 insertions, 142 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) {
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java
index ebc5702913..2520e44aca 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/GroupBusinessLogicTest.java
@@ -147,7 +147,7 @@ class GroupBusinessLogicTest {
GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition();
Map<String, DataTypeDefinition> map = new HashMap<>();
when(dataTypeCache.getAll()).thenReturn(Either.left(map));
- when(groupTypeOperation.getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, true)).thenReturn(Either.left(groupTypeDefinition));
+ when(groupTypeOperation.getLatestGroupTypeByType(Constants.DEFAULT_GROUP_VF_MODULE, null, true)).thenReturn(Either.left(groupTypeDefinition));
when(groupsOperation.createGroups(any(Component.class), anyMap())).thenReturn(Either.left(groupDefinitions));
when(groupsOperation.addCalculatedCapabilitiesWithProperties(anyString(), anyMap(), anyMap())).thenReturn(StorageOperationStatus.OK);
result = test.createGroups(component, groupDefinitions, true);
@@ -213,9 +213,9 @@ class GroupBusinessLogicTest {
List<PropertyDefinition> properties = asList(
buildProperty("network_collection_type", "l3-network", "network collection type, defined with default value"));
groupTypeDefinition.setProperties(properties);
- when(groupTypeOperation.getLatestGroupTypeByType(grpType, false)).thenReturn(Either.left(groupTypeDefinition));
+ when(groupTypeOperation.getLatestGroupTypeByType(grpType, component.getModel(), false)).thenReturn(Either.left(groupTypeDefinition));
when(toscaOperationFacade.canAddGroups(componentId)).thenReturn(true);
- when(groupTypeOperation.getLatestGroupTypeByType(grpType, true)).thenReturn(Either.left(groupTypeDefinition));
+ when(groupTypeOperation.getLatestGroupTypeByType(grpType, component.getModel(), true)).thenReturn(Either.left(groupTypeDefinition));
when(propertyOperation.checkInnerType(any(PropertyDefinition.class))).thenReturn(Either.left("ok"));
when(propertyOperation.validateAndUpdatePropertyValue("string", null, "ok", map)).thenReturn(Either.left(component));
when(groupsOperation.addGroups(any(Resource.class), any())).thenReturn(Either.left(groupDefList));
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
index c759c15094..627c536720 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyBusinessLogicTest.java
@@ -172,7 +172,7 @@ public class PolicyBusinessLogicTest {
@Test
public void createPolicySuccessTest(){
stubValidateAndLockSuccess(CREATE_POLICY);
- when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither);
+ when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(policySuccessEither);
stubUnlockAndCommit();
PolicyDefinition response = businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
@@ -201,7 +201,7 @@ public class PolicyBusinessLogicTest {
newResource.setPolicies(policies);
newResource.setComponentInstances(instanceList);
- when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither);
+ when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(Either.left(policy));
when(toscaOperationFacade.getToscaFullElement(eq(COMPONENT_ID))).thenReturn(Either.left(newResource));
when(toscaOperationFacade.updatePolicyOfComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), any(PromoteVersionEnum.class))).thenReturn(Either.left(policy));
@@ -249,7 +249,7 @@ public class PolicyBusinessLogicTest {
public void createPolicyPolicyTypeFailureTest(){
stubValidateAndLockSuccess(CREATE_POLICY);
Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeFailed = Either.right(StorageOperationStatus.NOT_FOUND);
- when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeFailed);
+ when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeFailed);
when(componentsUtils.convertFromStorageResponse(eq(getPolicyTypeFailed.right().value()))).thenReturn(ActionStatus.RESOURCE_NOT_FOUND);
stubUnlockAndRollback();
businessLogic.createPolicy(ComponentTypeEnum.RESOURCE, COMPONENT_ID, POLICY_TYPE_NAME, USER_ID, true);
@@ -258,7 +258,7 @@ public class PolicyBusinessLogicTest {
@Test(expected = ComponentException.class)
public void createPolicyComponentTypeFailureTest(){
stubValidateAndLockSuccess(CREATE_POLICY);
- when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME))).thenReturn(getPolicyTypeSuccessEither);
+ when(policyTypeOperation.getLatestPolicyTypeByType(eq(POLICY_TYPE_NAME), any())).thenReturn(getPolicyTypeSuccessEither);
Either<PolicyDefinition, StorageOperationStatus> addPolicyRes = Either.right(StorageOperationStatus.BAD_REQUEST);
when(toscaOperationFacade.associatePolicyToComponent(eq(COMPONENT_ID), any(PolicyDefinition.class), eq(0))).thenReturn(addPolicyRes);
when(componentsUtils.convertFromStorageResponse(eq(addPolicyRes.right().value()))).thenReturn(ActionStatus.INVALID_CONTENT);
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java
index d3a27a8615..7391d91309 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/PolicyTypeBusinessLogicTest.java
@@ -122,9 +122,9 @@ public class PolicyTypeBusinessLogicTest {
@Test
public void getLatestPolicyTypeByTypeTest() {
PolicyTypeDefinition policyTypeDefinition = new PolicyTypeBuilder().setType("org.openecomp.policies.placement.Antilocate").build();
- when(policyTypeOperation.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate")).thenReturn(
+ when(policyTypeOperation.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate", null)).thenReturn(
Either.left(policyTypeDefinition));
- assertThat(policyTypeOperation.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate"))
- .isEqualTo(Either.left(testInstance.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate")));
+ assertThat(policyTypeOperation.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate", null))
+ .isEqualTo(Either.left(testInstance.getLatestPolicyTypeByType("org.openecomp.policies.placement.Antilocate", null)));
}
} \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java
index ac64e06917..69367e962c 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/utils/YamlTemplateParsingHandlerTest.java
@@ -66,6 +66,7 @@ import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS;
@@ -266,9 +267,9 @@ public class YamlTemplateParsingHandlerTest {
}
private void stubGetGroupType() {
- when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(VFC_GROUP_TYPE))).thenReturn(VfcInstanceGroupType);
- when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE))).thenReturn(heatGroupType);
- when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(ROOT_GROUP_TYPE))).thenReturn(rootGroupType);
+ when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(VFC_GROUP_TYPE), any())).thenReturn(VfcInstanceGroupType);
+ when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(HEAT_GROUP_TYPE), any())).thenReturn(heatGroupType);
+ when(groupTypeBusinessLogic.getLatestGroupTypeByType(eq(ROOT_GROUP_TYPE), any())).thenReturn(rootGroupType);
}
private static GroupTypeDefinition buildRootGroupType() {
@@ -366,7 +367,7 @@ public class YamlTemplateParsingHandlerTest {
}
private void stubGetPolicyType () {
- when(policyTypeBusinessLogic.getLatestPolicyTypeByType(eq(OPENECOMP_ANTILOCATE_POLICY_TYPE))).thenReturn(
+ when(policyTypeBusinessLogic.getLatestPolicyTypeByType(eq(OPENECOMP_ANTILOCATE_POLICY_TYPE), any())).thenReturn(
OPENECOMP_POLICY_TYPE);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupTypeOperation.java
index d601a2fd49..62f51210f4 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IGroupTypeOperation.java
@@ -32,11 +32,11 @@ public interface IGroupTypeOperation {
Either<GroupTypeDefinition, StorageOperationStatus> getGroupType(String uniqueId, boolean inTransaction);
- Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String name);
+ Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String name, String model);
- Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String name, boolean inTransaction);
+ Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String name, String model, boolean inTransaction);
- Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String name, String version);
+ Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String name, String version, String model);
- Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String name, String version, boolean inTransaction);
+ Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String name, String version, String model, boolean inTransaction);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java
index bba124ec0d..fce683e52f 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/api/IPolicyTypeOperation.java
@@ -26,7 +26,7 @@ import org.openecomp.sdc.be.model.PolicyTypeDefinition;
public interface IPolicyTypeOperation {
- Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String policyTypeName);
+ Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String policyTypeName, String modelName);
Either<PolicyTypeDefinition, StorageOperationStatus> addPolicyType(PolicyTypeDefinition policyType);
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
index 7cf0d29a13..621ba97cb3 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperation.java
@@ -20,7 +20,6 @@
package org.openecomp.sdc.be.model.operations.impl;
import static org.openecomp.sdc.be.dao.janusgraph.JanusGraphUtils.buildNotInPredicate;
-import static org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR;
import com.google.common.base.Strings;
import fj.data.Either;
@@ -30,6 +29,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -312,41 +312,19 @@ public class GroupTypeOperation implements IGroupTypeOperation {
}
}
- public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String type) {
- return getLatestGroupTypeByType(type, true);
+ public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String type, String model) {
+ return getLatestGroupTypeByType(type, model, true);
}
- public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String type, boolean inTransaction) {
+ public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(String type, String model, boolean inTransaction) {
Map<String, Object> mapCriteria = new HashMap<>();
mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type);
mapCriteria.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true);
- return getGroupTypeByCriteria(type, mapCriteria, inTransaction);
- }
-
- public Either<GroupTypeDefinition, StorageOperationStatus> getLatestGroupTypeByType(final String groupType, final String model) {
- final Either<GroupTypeData, JanusGraphOperationStatus> groupTypeRes = janusGraphGenericDao
- .getNode(GraphPropertiesDictionary.TYPE.getProperty(), groupType, GroupTypeData.class, model);
- if (groupTypeRes.isRight()) {
- final JanusGraphOperationStatus status = groupTypeRes.right().value();
- log.error("GroupTypeData cannot be found in graph. status is {}", status);
- return Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(status));
- }
- Either<GroupTypeDefinition, StorageOperationStatus> groupTypeDefinition = getGroupTypeByUid(groupTypeRes.left().value().getUniqueId());
- if (groupTypeDefinition.isRight()) {
- final StorageOperationStatus status = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(groupTypeRes.right().value());
- log.error("GroupTypeDefinition cannot be found in graph. status is {}", status);
- return Either.right(status);
- }
- final Either<ImmutablePair<ModelData, GraphEdge>, JanusGraphOperationStatus> modelName = janusGraphGenericDao.getParentNode(
- UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), groupTypeRes.left().value().getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT,
- NodeTypeEnum.Model, ModelData.class);
- if (modelName.isLeft()) {
- groupTypeDefinition.left().value().setModel(modelName.left().value().getLeft().getName());
- }
- return groupTypeDefinition;
+ return getGroupTypeByCriteria(type, mapCriteria, model, inTransaction);
}
public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByCriteria(String type, Map<String, Object> properties,
+ String model,
boolean inTransaction) {
Either<GroupTypeDefinition, StorageOperationStatus> result = null;
try {
@@ -355,8 +333,8 @@ public class GroupTypeOperation implements IGroupTypeOperation {
result = Either.right(StorageOperationStatus.INVALID_ID);
return result;
}
- Either<List<GroupTypeData>, StorageOperationStatus> groupTypeEither = janusGraphGenericDao
- .getByCriteria(NodeTypeEnum.GroupType, properties, GroupTypeData.class).right()
+ Either<List<GroupTypeData>, StorageOperationStatus> groupTypeEither = janusGraphGenericDao
+ .getByCriteriaForModel(NodeTypeEnum.GroupType, properties, model, GroupTypeData.class).right()
.map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus);
if (groupTypeEither.isRight()) {
result = Either.right(groupTypeEither.right().value());
@@ -373,10 +351,24 @@ public class GroupTypeOperation implements IGroupTypeOperation {
private Either<GroupTypeDefinition, StorageOperationStatus> buildGroupTypeDefinition(String uniqueId, GroupTypeData groupTypeNode) {
GroupTypeDefinition groupType = new GroupTypeDefinition(groupTypeNode.getGroupTypeDataDefinition());
+ Optional<String> modelName = getAssociatedModelName(uniqueId);
+ if(modelName.isPresent()) {
+ groupType.setModel(modelName.get());
+ }
return fillDerivedFrom(uniqueId, groupType).left().map(derivedFrom -> fillProperties(uniqueId, groupType, derivedFrom)).left()
.bind(props -> fillCapabilities(uniqueId, groupType));
}
+ public Optional<String> getAssociatedModelName(String uniqueId) {
+ final Either<ImmutablePair<ModelData, GraphEdge>, JanusGraphOperationStatus> modelName = janusGraphGenericDao.getParentNode(
+ UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.GroupType), uniqueId, GraphEdgeLabels.MODEL_ELEMENT,
+ NodeTypeEnum.Model, ModelData.class);
+ if(modelName.isRight()) {
+ return Optional.empty();
+ }
+ return Optional.ofNullable(modelName.left().value().getLeft().getName());
+ }
+
private Either<GroupTypeDefinition, StorageOperationStatus> fillCapabilities(String uniqueId, GroupTypeDefinition groupType) {
return getCapablities(uniqueId).left().map(capabilities -> {
groupType.setCapabilities(asCapabilitiesMap(capabilities));
@@ -436,15 +428,15 @@ public class GroupTypeOperation implements IGroupTypeOperation {
return derivedFrom;
}
- public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String type, String version) {
- return getGroupTypeByTypeAndVersion(type, version, false);
+ public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String type, String version, String model) {
+ return getGroupTypeByTypeAndVersion(type, version, model, false);
}
- public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String type, String version, boolean inTransaction) {
+ public Either<GroupTypeDefinition, StorageOperationStatus> getGroupTypeByTypeAndVersion(String type, String version, String model, boolean inTransaction) {
Map<String, Object> mapCriteria = new HashMap<>();
mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type);
mapCriteria.put(GraphPropertiesDictionary.VERSION.getProperty(), version);
- return getGroupTypeByCriteria(type, mapCriteria, inTransaction);
+ return getGroupTypeByCriteria(type, mapCriteria, model, inTransaction);
}
/**
@@ -618,7 +610,7 @@ public class GroupTypeOperation implements IGroupTypeOperation {
String groupTypeId = updatedGroupType.getUniqueId();
if (StringUtils.equals(updatedGroupType.getDerivedFrom(), currDerivedFromGroupType)) {
return Strings.isNullOrEmpty(currDerivedFromGroupType) ? Either.right(StorageOperationStatus.OK)
- : getLatestGroupTypeByType(currDerivedFromGroupType, true).left().map(def -> null);
+ : getLatestGroupTypeByType(currDerivedFromGroupType, updatedGroupType.getModel()).left().map(def -> null);
}
StorageOperationStatus status = isLegalToReplaceParent(currDerivedFromGroupType, updatedGroupType.getDerivedFrom(),
updatedGroupType.getType());
@@ -628,7 +620,7 @@ public class GroupTypeOperation implements IGroupTypeOperation {
log.debug(
"#updateGroupDerivedFrom - updating group derived from relation for group type with id {}. old derived type {}. new derived type {}",
groupTypeId, currDerivedFromGroupType, updatedGroupType.getDerivedFrom());
- StorageOperationStatus deleteDerivedRelationStatus = deleteDerivedFromGroupType(groupTypeId, currDerivedFromGroupType);
+ StorageOperationStatus deleteDerivedRelationStatus = deleteDerivedFromGroupType(groupTypeId, currDerivedFromGroupType, updatedGroupType.getModel());
if (deleteDerivedRelationStatus != StorageOperationStatus.OK) {
return Either.right(deleteDerivedRelationStatus);
}
@@ -651,13 +643,13 @@ public class GroupTypeOperation implements IGroupTypeOperation {
derivedFromGroup -> derivedFromOperation.addDerivedFromRelation(gtUniqueId, derivedFromGroup.getUniqueId(), NodeTypeEnum.GroupType));
}
- private StorageOperationStatus deleteDerivedFromGroupType(String groupTypeId, String derivedFromType) {
+ private StorageOperationStatus deleteDerivedFromGroupType(String groupTypeId, String derivedFromType, String model) {
if (derivedFromType == null) {
return StorageOperationStatus.OK;
}
log.debug("#deleteDerivedFromGroupType - deleting derivedFrom relation for group type with id {} and its derived type {}", groupTypeId,
derivedFromType);
- return getLatestGroupTypeByType(derivedFromType, true).either(
+ return getLatestGroupTypeByType(derivedFromType, model).either(
derivedFromNode -> derivedFromOperation.removeDerivedFromRelation(groupTypeId, derivedFromNode.getUniqueId(), NodeTypeEnum.GroupType),
err -> err);
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
index 9bc4cfc4b8..99a284168e 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperation.java
@@ -27,6 +27,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.ImmutablePair;
@@ -66,35 +67,23 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp
@Autowired
private OperationUtils operationUtils;
+
@Override
- public Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String type) {
+ public Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String type, String model) {
Map<String, Object> mapCriteria = new HashMap<>();
mapCriteria.put(GraphPropertiesDictionary.TYPE.getProperty(), type);
mapCriteria.put(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty(), true);
- return getPolicyTypeByCriteria(type, mapCriteria);
+ return getPolicyTypeByCriteria(type, mapCriteria, model);
}
- public Either<PolicyTypeDefinition, StorageOperationStatus> getLatestPolicyTypeByType(String type, String model) {
- final Either<PolicyTypeData, JanusGraphOperationStatus> policyTypesRes = janusGraphGenericDao
- .getNode(GraphPropertiesDictionary.TYPE.getProperty(), type, PolicyTypeData.class, model);
- if (policyTypesRes.isRight()) {
- final StorageOperationStatus status = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(policyTypesRes.right().value());
- log.error("PolicyTypeData cannot be found in graph. status is {}", status);
- return Either.right(status);
- }
- Either<PolicyTypeDefinition, StorageOperationStatus> policyTypeDefinition = getPolicyTypeByUid(policyTypesRes.left().value().getUniqueId());
- if (policyTypeDefinition.isRight()) {
- final StorageOperationStatus status = DaoStatusConverter.convertJanusGraphStatusToStorageStatus(policyTypesRes.right().value());
- log.error("PolicyTypeDefinition cannot be found in graph. status is {}", status);
- return Either.right(status);
- }
+ public Optional<String> getAssociatedModelName(String uniqueId) {
final Either<ImmutablePair<ModelData, GraphEdge>, JanusGraphOperationStatus> modelName = janusGraphGenericDao.getParentNode(
- UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), policyTypesRes.left().value().getUniqueId(), GraphEdgeLabels.MODEL_ELEMENT,
+ UniqueIdBuilder.getKeyByNodeType(NodeTypeEnum.PolicyType), uniqueId, GraphEdgeLabels.MODEL_ELEMENT,
NodeTypeEnum.Model, ModelData.class);
- if (modelName.isLeft()) {
- policyTypeDefinition.left().value().setModel(modelName.left().value().getLeft().getName());
+ if (modelName.isRight()) {
+ return Optional.empty();
}
- return policyTypeDefinition;
+ return Optional.ofNullable(modelName.left().value().getLeft().getName());
}
@Override
@@ -176,7 +165,7 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp
return janusGraphGenericDao.createRelation(from , to, GraphEdgeLabels.MODEL_ELEMENT, Collections.emptyMap()).right().map(DaoStatusConverter::convertJanusGraphStatusToStorageStatus);
}
- private Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeByCriteria(String type, Map<String, Object> properties) {
+ private Either<PolicyTypeDefinition, StorageOperationStatus> getPolicyTypeByCriteria(String type, Map<String, Object> properties, String model) {
Either<PolicyTypeDefinition, StorageOperationStatus> result;
if (type == null || type.isEmpty()) {
log.error("type is empty");
@@ -184,7 +173,7 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp
return result;
}
Either<List<PolicyTypeData>, JanusGraphOperationStatus> eitherPolicyData = janusGraphGenericDao
- .getByCriteria(NodeTypeEnum.PolicyType, properties, PolicyTypeData.class);
+ .getByCriteriaForModel(NodeTypeEnum.PolicyType, properties, model, PolicyTypeData.class);
if (eitherPolicyData.isRight()) {
result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(eitherPolicyData.right().value()));
} else {
@@ -204,6 +193,10 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp
private Either<PolicyTypeDefinition, StorageOperationStatus> createPolicyTypeDefinition(String uniqueId, PolicyTypeData policyTypeNode) {
PolicyTypeDefinition policyType = new PolicyTypeDefinition(policyTypeNode.getPolicyTypeDataDefinition());
+ Optional<String> modelName = getAssociatedModelName(uniqueId);
+ if (modelName.isPresent()) {
+ policyType.setModel(modelName.get());
+ }
return fillDerivedFrom(uniqueId, policyType).left().map(derivedFrom -> fillProperties(uniqueId, policyType, derivedFrom)).left()
.map(props -> policyType);
}
@@ -294,7 +287,7 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp
log.debug(
"#updatePolicyDerivedFrom - updating policy derived from relation for policy type with id {}. old derived type {}. new derived type {}",
policyTypeId, currDerivedFromPolicyType, updatedPolicyType.getDerivedFrom());
- StorageOperationStatus deleteDerivedRelationStatus = deleteDerivedFromPolicyType(policyTypeId, currDerivedFromPolicyType);
+ StorageOperationStatus deleteDerivedRelationStatus = deleteDerivedFromPolicyType(policyTypeId, currDerivedFromPolicyType, updatedPolicyType.getModel());
if (deleteDerivedRelationStatus != StorageOperationStatus.OK) {
return Either.right(deleteDerivedRelationStatus);
}
@@ -312,13 +305,13 @@ public class PolicyTypeOperation extends AbstractOperation implements IPolicyTyp
derivedFromPolicy -> derivedFromOperation.addDerivedFromRelation(ptUniqueId, derivedFromPolicy.getUniqueId(), NodeTypeEnum.PolicyType));
}
- private StorageOperationStatus deleteDerivedFromPolicyType(String policyTypeId, String derivedFromType) {
+ private StorageOperationStatus deleteDerivedFromPolicyType(String policyTypeId, String derivedFromType, String model) {
if (derivedFromType == null) {
return StorageOperationStatus.OK;
}
log.debug("#deleteDerivedFromPolicyType - deleting derivedFrom relation for policy type with id {} and its derived type {}", policyTypeId,
derivedFromType);
- return getLatestPolicyTypeByType(derivedFromType).either(
+ return getLatestPolicyTypeByType(derivedFromType, model).either(
derivedFromNode -> derivedFromOperation.removeDerivedFromRelation(policyTypeId, derivedFromNode.getUniqueId(), NodeTypeEnum.PolicyType),
err -> err);
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java
index 4e4a95d2cc..48202c3ec5 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/GroupTypeOperationTest.java
@@ -145,7 +145,7 @@ public class GroupTypeOperationTest extends ModelTestBase {
assertTrue("check group type added", addGroupTypeResult.isLeft());
compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value());
- addGroupTypeResult = groupTypeOperation.getGroupTypeByTypeAndVersion("org.openecomp.groups.NetworkCollection", "1.0");
+ addGroupTypeResult = groupTypeOperation.getGroupTypeByTypeAndVersion("org.openecomp.groups.NetworkCollection", "1.0", null);
assertTrue("check group type added", addGroupTypeResult.isLeft());
compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value());
@@ -344,6 +344,7 @@ public class GroupTypeOperationTest extends ModelTestBase {
Either<GroupTypeDefinition, StorageOperationStatus> updateGroupTypeResult = groupTypeOperation.updateGroupType(newGroupTypeDefinition, addGroupTypeResult.left().value());
assertTrue(updateGroupTypeResult.isRight());
assertEquals(StorageOperationStatus.MATCH_NOT_FOUND, updateGroupTypeResult.right().value());
+
}
@Test
@@ -454,7 +455,7 @@ public class GroupTypeOperationTest extends ModelTestBase {
assertTrue("check group type added", addGroupTypeResult.isLeft());
compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value());
- addGroupTypeResult = groupTypeOperation.getGroupTypeByTypeAndVersion("org.openecomp.groups.PrivateCollection", "1.0");
+ addGroupTypeResult = groupTypeOperation.getGroupTypeByTypeAndVersion("org.openecomp.groups.PrivateCollection", "1.0", null);
assertTrue("check group type added", addGroupTypeResult.isLeft());
compareBetweenCreatedToSent(groupTypeDefinition, addGroupTypeResult.left().value());
@@ -541,12 +542,7 @@ public class GroupTypeOperationTest extends ModelTestBase {
@Test
public void testAddGroupTypeWithModel() {
- createRootGroupTypeNode();
-
- GroupTypeDefinition groupTypeDefinition = new GroupTypeDefinition();
- groupTypeDefinition.setDescription("groups l2-networks in network collection");
- groupTypeDefinition.setType("org.openecomp.groups.PrivateCollection");
- groupTypeDefinition.setVersion("1.0");
+ GroupTypeDefinition groupTypeDefinition = createGroupTypeDef();
groupTypeDefinition.setModel("testModel");
Model model = new Model("testModel");
modelOperation.createModel(model , true);
@@ -554,7 +550,7 @@ public class GroupTypeOperationTest extends ModelTestBase {
Either<GroupTypeDefinition, StorageOperationStatus> addGroupType = groupTypeOperation.addGroupType(groupTypeDefinition);
assertTrue(addGroupType.isLeft());
Either<GroupTypeDefinition, StorageOperationStatus> eitherGroupTypeFetched =
- groupTypeOperation.getLatestGroupTypeByType(groupTypeDefinition.getType(), groupTypeDefinition.getModel());
+ groupTypeOperation.getLatestGroupTypeByType(groupTypeDefinition.getType(), groupTypeDefinition.getModel());
assertTrue(eitherGroupTypeFetched.isLeft());
assertEquals(groupTypeDefinition.getModel(), eitherGroupTypeFetched.left().value().getModel());
}
@@ -712,7 +708,7 @@ public class GroupTypeOperationTest extends ModelTestBase {
updatedType.setIcon("icon");
groupTypeOperation.updateGroupType(updatedType, currGroupType.left().value());
- Either<GroupTypeDefinition, StorageOperationStatus> fetchedUpdatedType = groupTypeOperation.getLatestGroupTypeByType(createdType.getType());
+ Either<GroupTypeDefinition, StorageOperationStatus> fetchedUpdatedType = groupTypeOperation.getLatestGroupTypeByType(createdType.getType(), createdType.getModel());
GroupTypeDefinition fetchedGroupType = fetchedUpdatedType.left().value();
assertThat(fetchedGroupType.getProperties()).isEmpty();
assertThat(fetchedGroupType)
@@ -762,7 +758,7 @@ public class GroupTypeOperationTest extends ModelTestBase {
Either<GroupTypeDefinition, StorageOperationStatus> currGroupType = groupTypeOperation.addGroupType(groupType1);
groupTypeOperation.updateGroupType(updatedGroupType, currGroupType.left().value());
- Either<GroupTypeDefinition, StorageOperationStatus> latestGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType1.getType());
+ Either<GroupTypeDefinition, StorageOperationStatus> latestGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType1.getType(), groupType1.getModel());
assertThat(latestGroupType.left().value().getDerivedFrom()).isEqualTo(rootGroupType.getType());
verifyDerivedFromNodeEqualsToRootGroupType(rootGroupType, latestGroupType.left().value().getUniqueId());
}
@@ -778,7 +774,7 @@ public class GroupTypeOperationTest extends ModelTestBase {
Either<GroupTypeDefinition, StorageOperationStatus> updateGroupTypeRes = groupTypeOperation.updateGroupType(updatedGroupType, currGroupType.left().value());
assertThat(updateGroupTypeRes.right().value()).isEqualTo(StorageOperationStatus.NOT_FOUND);
- Either<GroupTypeDefinition, StorageOperationStatus> latestGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType1.getType());
+ Either<GroupTypeDefinition, StorageOperationStatus> latestGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType1.getType(), groupType1.getModel());
assertThat(latestGroupType.left().value().getDerivedFrom()).isEqualTo(rootGroupType.getType());
}
@@ -795,7 +791,7 @@ public class GroupTypeOperationTest extends ModelTestBase {
groupTypeOperation.updateGroupType(updatedGroupType, currGroupType.left().value());
- Either<GroupTypeDefinition, StorageOperationStatus> latestGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType1.getType());
+ Either<GroupTypeDefinition, StorageOperationStatus> latestGroupType = groupTypeOperation.getLatestGroupTypeByType(groupType1.getType(), groupType1.getModel());
assertThat(latestGroupType.left().value().getDerivedFrom()).isEqualTo(derivedType1.getType());
}
@@ -813,7 +809,7 @@ public class GroupTypeOperationTest extends ModelTestBase {
Either<GroupTypeDefinition, StorageOperationStatus> updateResult = groupTypeOperation.updateGroupType(updatedGroupType, currGroupType.left().value());
assertThat(updateResult.right().value()).isEqualTo(StorageOperationStatus.GENERAL_ERROR);
- Either<GroupTypeDefinition, StorageOperationStatus> latestGroupType = groupTypeOperation.getLatestGroupTypeByType(updatedGroupType.getType());
+ Either<GroupTypeDefinition, StorageOperationStatus> latestGroupType = groupTypeOperation.getLatestGroupTypeByType(updatedGroupType.getType(), updatedGroupType.getModel());
assertThat(latestGroupType.left().value().getDerivedFrom()).isEqualTo(rootGroupType.getType());
}
diff --git a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java
index e25344f8bb..d849ec647d 100644
--- a/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java
+++ b/catalog-model/src/test/java/org/openecomp/sdc/be/model/operations/impl/PolicyTypeOperationTest.java
@@ -107,7 +107,7 @@ public class PolicyTypeOperationTest extends ModelTestBase {
@Test
public void testGetLatestPolicyTypeByType() {
PolicyTypeDefinition policyTypeCreated = policyTypeOperation.addPolicyType(createPolicyTypeDef()).left().value();
- Either<PolicyTypeDefinition, StorageOperationStatus> eitherPolicyTypeFetched = policyTypeOperation.getLatestPolicyTypeByType(policyTypeCreated.getType());
+ Either<PolicyTypeDefinition, StorageOperationStatus> eitherPolicyTypeFetched = policyTypeOperation.getLatestPolicyTypeByType(policyTypeCreated.getType(), policyTypeCreated.getModel());
assertTrue(eitherPolicyTypeFetched.isLeft());
PolicyTypeDefinition policyTypeFetched = eitherPolicyTypeFetched.left().value();
assertEquals(policyTypeFetched.toString(), policyTypeCreated.toString());
@@ -134,7 +134,7 @@ public class PolicyTypeOperationTest extends ModelTestBase {
String derivedFromRootType = rootPolicyType.getType();
PolicyTypeDefinition policyType1 = createPolicyTypeDef("tosca.policies.type1", "desc1", derivedFromRootType);
policyTypeOperation.addPolicyType(policyType1);
- Either<PolicyTypeDefinition, StorageOperationStatus> eitherPolicyTypeFetched = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType());
+ Either<PolicyTypeDefinition, StorageOperationStatus> eitherPolicyTypeFetched = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), policyType1.getModel());
assertThat(eitherPolicyTypeFetched.left().value().getDerivedFrom()).isEqualTo(rootPolicyType.getType());
}
@@ -145,7 +145,7 @@ public class PolicyTypeOperationTest extends ModelTestBase {
PolicyTypeDefinition policyType1 = createPolicyTypeDef("tosca.policies.type1", null, prop1, prop2);
PolicyTypeDefinition policyType2 = createPolicyTypeDef("tosca.policies.type2", "desc3", policyType1.getType(), null);
addPolicyTypesToDB(policyType1, policyType2);
- Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType2 = policyTypeOperation.getLatestPolicyTypeByType(policyType2.getType());
+ Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType2 = policyTypeOperation.getLatestPolicyTypeByType(policyType2.getType(), policyType2.getModel());
assertThat(latestPolicyType2.isLeft()).isTrue();
assertThat(latestPolicyType2.left().value().getProperties())
.usingElementComparatorOnFields("defaultValue", "name", "type")
@@ -166,7 +166,7 @@ public class PolicyTypeOperationTest extends ModelTestBase {
addPolicyTypesToDB(rootPolicyType, policyType1, policyType2, policyType3, policyType4);
- Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType3 = policyTypeOperation.getLatestPolicyTypeByType(policyType4.getType());
+ Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType3 = policyTypeOperation.getLatestPolicyTypeByType(policyType4.getType(), policyType4.getModel());
assertThat(latestPolicyType3.isLeft()).isTrue();
assertThat(latestPolicyType3.left().value().getProperties())
.usingElementComparatorOnFields("defaultValue", "name", "type")
@@ -220,7 +220,7 @@ public class PolicyTypeOperationTest extends ModelTestBase {
Either<PolicyTypeDefinition, StorageOperationStatus> addedPolicyTypeResult = policyTypeOperation.addPolicyType(policyType1);
assertThat(addedPolicyTypeResult.isLeft()).isTrue();
- Either<PolicyTypeDefinition, StorageOperationStatus> fetchedPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType());
+ Either<PolicyTypeDefinition, StorageOperationStatus> fetchedPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), policyType1.getModel());
PolicyTypeDefinition fetchedPolicyTypeVal = fetchedPolicyType.left().value();
assertThat(fetchedPolicyTypeVal.getDerivedFrom()).isEqualTo(derivedFromRootType);
verifyDerivedFromNodeEqualsToRootPolicyType(rootPolicyType, fetchedPolicyTypeVal.getUniqueId());
@@ -245,7 +245,7 @@ public class PolicyTypeOperationTest extends ModelTestBase {
updatedType.setIcon("icon");
policyTypeOperation.updatePolicyType(updatedType, currPolicyType.left().value());
- Either<PolicyTypeDefinition, StorageOperationStatus> fetchedUpdatedType = policyTypeOperation.getLatestPolicyTypeByType(createdType.getType());
+ Either<PolicyTypeDefinition, StorageOperationStatus> fetchedUpdatedType = policyTypeOperation.getLatestPolicyTypeByType(createdType.getType(), createdType.getModel());
PolicyTypeDefinition fetchedPolicyType = fetchedUpdatedType.left().value();
assertThat(fetchedPolicyType.getProperties()).isEmpty();
assertThat(fetchedPolicyType)
@@ -266,7 +266,7 @@ public class PolicyTypeOperationTest extends ModelTestBase {
policyTypeOperation.updatePolicyType(updatedPolicyType, currPolicyType.left().value());
- Either<PolicyTypeDefinition, StorageOperationStatus> fetchedUpdatedType = policyTypeOperation.getLatestPolicyTypeByType(policyType.getType());
+ Either<PolicyTypeDefinition, StorageOperationStatus> fetchedUpdatedType = policyTypeOperation.getLatestPolicyTypeByType(policyType.getType(), policyType.getModel());
assertThat(fetchedUpdatedType.left().value().getProperties())
.usingElementComparatorOnFields("name", "defaultValue", "type")
.containsExactlyInAnyOrder(updatedProp1, prop3);
@@ -282,7 +282,7 @@ public class PolicyTypeOperationTest extends ModelTestBase {
Either<PolicyTypeDefinition, StorageOperationStatus> currPolicyType = policyTypeOperation.addPolicyType(policyType1);
policyTypeOperation.updatePolicyType(updatedPolicyType, currPolicyType.left().value());
- Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType());
+ Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), policyType1.getModel());
assertThat(latestPolicyType.left().value().getDerivedFrom()).isEqualTo(rootPolicyType.getType());
verifyDerivedFromNodeEqualsToRootPolicyType(rootPolicyType, latestPolicyType.left().value().getUniqueId());
}
@@ -297,7 +297,7 @@ public class PolicyTypeOperationTest extends ModelTestBase {
policyTypeOperation.updatePolicyType(updatedPolicyType, currPolicyType.left().value());
- Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType());
+ Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), policyType1.getModel());
assertThat(latestPolicyType.left().value().getDerivedFrom()).isNull();
verifyDerivedFromRelationDoesntExist(latestPolicyType.left().value().getUniqueId());
}
@@ -315,7 +315,7 @@ public class PolicyTypeOperationTest extends ModelTestBase {
policyTypeOperation.updatePolicyType(updatedPolicyType, currPolicyType.left().value());
- Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType());
+ Either<PolicyTypeDefinition, StorageOperationStatus> latestPolicyType = policyTypeOperation.getLatestPolicyTypeByType(policyType1.getType(), policyType1.getModel());
assertThat(latestPolicyType.left().value().getDerivedFrom()).isEqualTo(rootPolicyType.getType());
verifyDerivedFromNodeEqualsToRootPolicyType(rootPolicyType, latestPolicyType.left().value().getUniqueId());
}