aboutsummaryrefslogtreecommitdiffstats
path: root/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components
diff options
context:
space:
mode:
authorMichael Mokry <mm117s@att.com>2017-07-07 16:00:59 -0500
committerMichael Mokry <mm117s@att.com>2017-07-10 18:58:00 +0000
commiteb654437ee2815028602daa943d0a939a5bee3cd (patch)
tree77ad3b26bcf60a80cbbf87dbd1b06f60de976c39 /ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components
parentbb927b5325d7b82cdc65bf25aa217ad7c56a46b3 (diff)
[POLICY-67] Add new Rainy Day Decision Policy
Change-Id: I8fb730e4363c885ccbe3a05ae971c5de5608d70c Signed-off-by: Michael Mokry <mm117s@att.com>
Diffstat (limited to 'ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components')
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java100
1 files changed, 97 insertions, 3 deletions
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java
index 02ea630a6..180b989e7 100644
--- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java
+++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/DecisionPolicy.java
@@ -88,7 +88,8 @@ public class DecisionPolicy extends Policy {
public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not";
private static final String AAFProvider = "AAF";
public static final String GUARD_YAML = "GUARD_YAML";
- public static final String GUARD_BL_YAML = "GUARD_BL_YAML";
+ public static final String GUARD_BL_YAML = "GUARD_BL_YAML";
+ public static final String RAINY_DAY = "Rainy_Day";
private static final String XACML_GUARD_TEMPLATE = "Decision_GuardPolicyTemplate.xml";
private static final String XACML_BLGUARD_TEMPLATE = "Decision_GuardBLPolicyTemplate.xml";
@@ -235,9 +236,21 @@ public class DecisionPolicy extends Policy {
VariableDefinitionType dynamicVariable = createDynamicVariable(key, value, dataType);
decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(dynamicVariable);
}
+
+
+ Map<String, String> dynamicFieldTreatmentAttributes = policyAdapter.getRainydayMap();
+
+ if(policyAdapter.getRuleProvider().equals(RAINY_DAY)){
+ for(String keyField : dynamicFieldTreatmentAttributes.keySet()) {
+ String errorcode = keyField;
+ String treatment = dynamicFieldTreatmentAttributes.get(errorcode);
+ createRainydayRule(decisionPolicy, errorcode, treatment, true);
+ }
+ } else {
+ createRule(decisionPolicy, true);
+ createRule(decisionPolicy, false);
+ }
- createRule(decisionPolicy, true);
- createRule(decisionPolicy, false);
}
setPreparedToSave(true);
@@ -483,6 +496,87 @@ public class DecisionPolicy extends Policy {
}
+ private void createRainydayRule(PolicyType decisionPolicy, String errorcode, String treatment, boolean permitRule) {
+ RuleType rule = new RuleType();
+
+ rule.setRuleId(UUID.randomUUID().toString());
+
+ if (permitRule) {
+ rule.setEffect(EffectType.PERMIT);
+ } else {
+ rule.setEffect(EffectType.DENY);
+ }
+ rule.setTarget(new TargetType());
+
+ // Create Target in Rule
+ AllOfType allOfInRule = new AllOfType();
+
+ // Creating match for ACCESS in rule target
+ MatchType accessMatch = new MatchType();
+ AttributeValueType accessAttributeValue = new AttributeValueType();
+ accessAttributeValue.setDataType(STRING_DATATYPE);
+ accessAttributeValue.getContent().add("DECIDE");
+ accessMatch.setAttributeValue(accessAttributeValue);
+ AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
+ URI accessURI = null;
+ try {
+ accessURI = new URI(ACTION_ID);
+ } catch (URISyntaxException e) {
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "DecisionPolicy", "Exception creating ACCESS URI");
+ }
+ accessAttributeDesignator.setCategory(CATEGORY_ACTION);
+ accessAttributeDesignator.setDataType(STRING_DATATYPE);
+ accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
+ accessMatch.setAttributeDesignator(accessAttributeDesignator);
+ accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+ allOfInRule.getMatch().add(accessMatch);
+
+ // Creating match for ErrorCode in rule target
+ MatchType errorcodeMatch = new MatchType();
+ AttributeValueType errorcodeAttributeValue = new AttributeValueType();
+ errorcodeAttributeValue.setDataType(STRING_DATATYPE);
+ errorcodeAttributeValue.getContent().add(errorcode);
+ errorcodeMatch.setAttributeValue(errorcodeAttributeValue);
+ AttributeDesignatorType errorcodeAttributeDesignator = new AttributeDesignatorType();
+ errorcodeAttributeDesignator.setCategory(CATEGORY_ACTION);
+ errorcodeAttributeDesignator.setDataType(STRING_DATATYPE);
+ errorcodeAttributeDesignator.setAttributeId("ErrorCode");
+ errorcodeMatch.setAttributeDesignator(errorcodeAttributeDesignator);
+ errorcodeMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+ allOfInRule.getMatch().add(errorcodeMatch);
+
+ AnyOfType anyOfInRule = new AnyOfType();
+ anyOfInRule.getAllOf().add(allOfInRule);
+
+ TargetType targetInRule = new TargetType();
+ targetInRule.getAnyOf().add(anyOfInRule);
+
+ rule.setTarget(targetInRule);
+
+ AdviceExpressionsType adviceExpressions = new AdviceExpressionsType();
+ AdviceExpressionType adviceExpression = new AdviceExpressionType();
+ adviceExpression.setAdviceId(RAINY_DAY);
+ adviceExpression.setAppliesTo(EffectType.PERMIT);
+
+ AttributeAssignmentExpressionType assignment = new AttributeAssignmentExpressionType();
+ assignment.setAttributeId("treatment");
+ assignment.setCategory(CATEGORY_RESOURCE);
+
+ AttributeValueType treatmentAttributeValue = new AttributeValueType();
+ treatmentAttributeValue.setDataType(STRING_DATATYPE);
+ treatmentAttributeValue.getContent().add(treatment);
+ assignment.setExpression(new ObjectFactory().createAttributeValue(treatmentAttributeValue));
+
+ adviceExpression.getAttributeAssignmentExpression().add(assignment);
+ adviceExpressions.getAdviceExpression().add(adviceExpression);
+ rule.setAdviceExpressions(adviceExpressions);
+ decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
+ policyAdapter.setPolicyData(decisionPolicy);
+
+ }
+
// if compound setting the inner apply here
protected ApplyType getInnerDecisionApply(String value1Label) {
ApplyType decisionApply = new ApplyType();