aboutsummaryrefslogtreecommitdiffstats
path: root/applications/common/src
diff options
context:
space:
mode:
Diffstat (limited to 'applications/common/src')
-rw-r--r--applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java64
-rw-r--r--applications/common/src/test/resources/matchable/onap.policies.Test-1.0.0.yaml50
-rw-r--r--applications/common/src/test/resources/matchable/test.policies.input.tosca.yaml50
3 files changed, 135 insertions, 29 deletions
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java
index addb0df3..ae09ec10 100644
--- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java
+++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java
@@ -332,20 +332,60 @@ public class StdMatchableTranslator extends StdBaseTranslator {
//
// Iterate the properties
//
+ int totalWeight = findMatchableFromMap(properties, policyTypes, targetType);
+ LOGGER.info("Total weight is {}", totalWeight);
+ return Pair.of(targetType, totalWeight);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected int findMatchableFromList(List<Object> listProperties, Collection<ToscaPolicyType> policyTypes,
+ TargetType targetType) {
+ LOGGER.info("findMatchableFromList {}", listProperties);
+ int totalWeight = 0;
+ for (Object property : listProperties) {
+ if (property instanceof List) {
+ totalWeight += findMatchableFromList((List<Object>) property, policyTypes, targetType);
+ } else if (property instanceof Map) {
+ totalWeight += findMatchableFromMap((Map<String, Object>) property, policyTypes, targetType);
+ }
+ }
+ return totalWeight;
+ }
+
+ protected int findMatchableFromMap(Map<String, Object> properties, Collection<ToscaPolicyType> policyTypes,
+ TargetType targetType) {
+ LOGGER.info("findMatchableFromMap {}", properties);
int totalWeight = 0;
for (Entry<String, Object> entrySet : properties.entrySet()) {
//
- // Find matchable properties
+ // Is this a matchable property?
//
if (isMatchable(entrySet.getKey(), policyTypes)) {
LOGGER.info("Found matchable property {}", entrySet.getKey());
int weight = generateMatchable(targetType, entrySet.getKey(), entrySet.getValue());
LOGGER.info("Weight is {}", weight);
totalWeight += weight;
+ } else {
+ //
+ // Check if we need to search deeper
+ //
+ totalWeight += checkDeeperForMatchable(entrySet.getValue(), policyTypes, targetType);
}
}
- LOGGER.info("Total weight is {}", totalWeight);
- return Pair.of(targetType, totalWeight);
+ return totalWeight;
+ }
+
+ @SuppressWarnings("unchecked")
+ protected int checkDeeperForMatchable(Object property, Collection<ToscaPolicyType> policyTypes,
+ TargetType targetType) {
+ if (property instanceof List) {
+ return findMatchableFromList((List<Object>) property, policyTypes, targetType);
+ } else if (property instanceof Map) {
+ return findMatchableFromMap((Map<String, Object>) property, policyTypes,
+ targetType);
+ }
+ LOGGER.info("checkDeeperForMatchable not necessary for {}", property);
+ return 0;
}
/**
@@ -362,11 +402,28 @@ public class StdMatchableTranslator extends StdBaseTranslator {
if (checkIsMatchableProperty(propertyName, propertiesEntry)) {
return true;
}
+ //
+ // Check if its a list or map
+ //
+ if (isListOrMap(propertiesEntry.getValue().getType())
+ && ! isYamlType(propertiesEntry.getValue().getEntrySchema().getType())) {
+ LOGGER.info("need to search list or map");
+ }
}
}
+ LOGGER.info("isMatchable false for {}", propertyName);
return false;
}
+ private boolean isListOrMap(String type) {
+ return "list".equalsIgnoreCase(type) || "map".equalsIgnoreCase(type);
+ }
+
+ private boolean isYamlType(String type) {
+ return "string".equalsIgnoreCase(type) || "integer".equalsIgnoreCase(type) || "float".equalsIgnoreCase(type)
+ || "boolean".equalsIgnoreCase(type) || "timestamp".equalsIgnoreCase(type);
+ }
+
/**
* checkIsMatchableProperty - checks the policy contents for matchable field. If the metadata doesn't exist,
* then definitely not. If the property doesn't exist, then definitely not. Otherwise need to have a metadata
@@ -665,6 +722,7 @@ public class StdMatchableTranslator extends StdBaseTranslator {
LOGGER.error("parameters: {} ", this.apiRestParameters);
return null;
}
+ LOGGER.info("Successfully pulled {}", policyTypeId);
//
// Store it locally
//
diff --git a/applications/common/src/test/resources/matchable/onap.policies.Test-1.0.0.yaml b/applications/common/src/test/resources/matchable/onap.policies.Test-1.0.0.yaml
index 089aad66..f44a3061 100644
--- a/applications/common/src/test/resources/matchable/onap.policies.Test-1.0.0.yaml
+++ b/applications/common/src/test/resources/matchable/onap.policies.Test-1.0.0.yaml
@@ -18,10 +18,10 @@ policy_types:
type: integer
metadata:
matchable: true
- nonmatachableDouble:
- type: double
- matchableDouble:
- type: double
+ nonmatachableFloat:
+ type: float
+ matchableFloat:
+ type: float
metadata:
matchable: true
nonmatachableBoolean:
@@ -35,4 +35,44 @@ policy_types:
metadata:
matchable: true
entry_schema:
- type: string \ No newline at end of file
+ type: string
+ propertyOneMap:
+ type: map
+ entry_schema:
+ type: onap.datatype.level1
+data_types:
+ onap.datatype.one:
+ derived_from: tosca.datatypes.Root
+ properties:
+ oneString:
+ type: string
+ oneStringMatchable:
+ type: string
+ metadata:
+ matachable: true
+ propertyTwoList:
+ type: list
+ entry_schema:
+ type: onap.datatype.two
+ onap.datatype.two:
+ derived_from: tosca.datatypes.Root
+ properties:
+ twoString:
+ type: string
+ twoStringMatchable:
+ type: string
+ metadata:
+ matachable: true
+ propertyThreeMap:
+ type: map
+ entry_schema:
+ type: onap.datatype.three
+ onap.datatype.three:
+ derived_from: tosca.datatypes.Root
+ properties:
+ threeString:
+ type: string
+ threeStringMatchable:
+ type: string
+ metadata:
+ matachable: true \ No newline at end of file
diff --git a/applications/common/src/test/resources/matchable/test.policies.input.tosca.yaml b/applications/common/src/test/resources/matchable/test.policies.input.tosca.yaml
index 434f7a97..9a68d488 100644
--- a/applications/common/src/test/resources/matchable/test.policies.input.tosca.yaml
+++ b/applications/common/src/test/resources/matchable/test.policies.input.tosca.yaml
@@ -1,23 +1,31 @@
tosca_definitions_version: tosca_simple_yaml_1_0_0
topology_template:
- policies:
- -
- Test.policy:
- type: onap.policies.Test
- type_version: 1.0.0
- version: 1.0.0
- metadata:
- policy-id: Test.policy
- policy-version: 1
- properties:
- nonmatachableString: "I am NON matchable"
- matchableString: "I should be matched"
- nonmatachableInteger: 0
- matachableInteger: 1000
- nonmatachableDouble: 0.0
- matchableDouble: 1.1
- nonmatachableBoolean: false
- matachableBoolean: true
- matchableListString:
- - match A
- - match B \ No newline at end of file
+ policies:
+ - Test.policy:
+ type: onap.policies.Test
+ type_version: 1.0.0
+ version: 1.0.0
+ metadata:
+ policy-id: Test.policy
+ policy-version: 1
+ properties:
+ nonmatachableString: I am NON matchable
+ matchableString: I should be matched
+ nonmatachableInteger: 0
+ matachableInteger: 1000
+ nonmatachableFloat: 0.0
+ matchableFloat: 1.1
+ nonmatachableBoolean: false
+ matachableBoolean: true
+ matchableListString:
+ - match A
+ - match B
+ propertyOneMap:
+ oneString: One is NOT matchable
+ oneStringMatchable: One should be matched
+ propertyTwoList:
+ - twoString: Two is NOT matchable
+ twoStringMatachable: Two should be matched
+ propertyThreeMap:
+ threeString: Three is NOT matchable
+ threeStringMatchable: Three should be matched \ No newline at end of file