aboutsummaryrefslogtreecommitdiffstats
path: root/POLICY-SDK-APP
diff options
context:
space:
mode:
authorrb7147 <rb7147@att.com>2018-09-04 14:16:04 -0400
committerrb7147 <rb7147@att.com>2018-09-05 13:24:05 -0400
commit7fd58e9a2427a215daa6b543e901534e83d3c246 (patch)
tree196e418bee0cb53ae3af913fe9fbc93e4e9dd719 /POLICY-SDK-APP
parent2cb76b3efe8ca385da3bc5f5afc5b26a52c6fd43 (diff)
XACML Platform Enhancements
To Support Raw Policy Creation from GUI and API. GetDecision on combining algorithim with Policy Set. Issue-ID: POLICY-902 Change-Id: Ie3189f8ded2e03366bc7d65d15b95b88c89b0acd Signed-off-by: rb7147 <rb7147@att.com>
Diffstat (limited to 'POLICY-SDK-APP')
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java651
-rw-r--r--POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js644
-rw-r--r--POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html17
3 files changed, 708 insertions, 604 deletions
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java
index 5ff20b6fc..fdbee2a99 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/DecisionPolicyController.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
package org.onap.policy.controller;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -28,19 +30,19 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-
import javax.xml.bind.JAXBElement;
-
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
import org.onap.policy.rest.adapter.RainyDayParams;
import org.onap.policy.rest.adapter.YAMLParams;
import org.onap.policy.rest.jpa.PolicyEntity;
+import org.onap.policy.xacml.util.XACMLPolicyWriter;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
-
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
@@ -50,6 +52,7 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
+import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
@@ -59,308 +62,366 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableReferenceType;
@Controller
@RequestMapping("/")
public class DecisionPolicyController extends RestrictedBaseController {
- private static final Logger policyLogger = FlexLogger.getLogger(DecisionPolicyController.class);
-
- public DecisionPolicyController(){
- // This constructor is empty
- }
+ private static final Logger policyLogger = FlexLogger.getLogger(DecisionPolicyController.class);
+
+ public DecisionPolicyController() {
+ // This constructor is empty
+ }
+
+ protected PolicyRestAdapter policyAdapter = null;
+ private ArrayList<Object> attributeList;
+ private ArrayList<Object> decisionList;
+ private ArrayList<Object> ruleAlgorithmList;
+ private ArrayList<Object> treatmentList = null;
+ protected LinkedList<Integer> ruleAlgoirthmTracker;
+ public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not";
+ private static final String blEntry = "@blEntry@";
+ private static final String decisionRawType = "@#RuleProvider@#Decision_Raw@#RuleProvider@#";
+
+ public void rawXACMLPolicy(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
+ try (InputStream policyXmlStream = XACMLPolicyWriter.getXmlAsInputStream(policyAdapter.getPolicyData())) {
+ String name = StringUtils.substringAfter(entity.getPolicyName(), "Decision_");
+ policyAdapter.setPolicyName(name.substring(0, name.indexOf('.')));
+ policyAdapter.setRuleProvider("Raw");
+ policyAdapter.setRawXacmlPolicy(IOUtils.toString(policyXmlStream).replaceAll(decisionRawType, ""));
+ } catch (IOException e) {
+ policyLogger.error("Exception Occured while setting XACML Raw Object" + e);
+ }
+ }
- protected PolicyRestAdapter policyAdapter = null;
- private ArrayList<Object> attributeList;
- private ArrayList<Object> decisionList;
- private ArrayList<Object> ruleAlgorithmList;
- private ArrayList<Object> treatmentList = null;
- protected LinkedList<Integer> ruleAlgoirthmTracker;
- public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not";
+ @SuppressWarnings("unchecked")
+ public void prePopulateDecisionPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
+ attributeList = new ArrayList<>();
+ decisionList = new ArrayList<>();
+ ruleAlgorithmList = new ArrayList<>();
+ treatmentList = new ArrayList<>();
- @SuppressWarnings("unchecked")
- public void prePopulateDecisionPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
- attributeList = new ArrayList<>();
- decisionList = new ArrayList<>();
- ruleAlgorithmList = new ArrayList<>();
- treatmentList = new ArrayList<>();
-
- if (policyAdapter.getPolicyData() instanceof PolicyType) {
- RainyDayParams rainydayParams = new RainyDayParams();
- Object policyData = policyAdapter.getPolicyData();
- PolicyType policy = (PolicyType) policyData;
- policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName());
- String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf('_') + 1);
- policyAdapter.setPolicyName(policyNameValue);
- String description = "";
- try{
- description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:"));
- }catch(Exception e){
- policyLogger.info("General error", e);
- description = policy.getDescription();
- }
- policyAdapter.setPolicyDescription(description);
- // Get the target data under policy for Action.
- TargetType target = policy.getTarget();
- if (target != null) {
- // under target we have AnyOFType
- List<AnyOfType> anyOfList = target.getAnyOf();
- if (anyOfList != null) {
- Iterator<AnyOfType> iterAnyOf = anyOfList.iterator();
- while (iterAnyOf.hasNext()) {
- AnyOfType anyOf = iterAnyOf.next();
- // Under AntOfType we have AllOfType
- List<AllOfType> allOfList = anyOf.getAllOf();
- if (allOfList != null) {
- Iterator<AllOfType> iterAllOf = allOfList.iterator();
- while (iterAllOf.hasNext()) {
- AllOfType allOf = iterAllOf.next();
- // Under AllOfType we have Mathch.
- List<MatchType> matchList = allOf.getMatch();
- int index = 0;
- if (matchList != null) {
- Iterator<MatchType> iterMatch = matchList.iterator();
- while (iterMatch.hasNext()) {
- MatchType match = iterMatch.next();
- //
- // Under the match we have attributevalue and
- // attributeDesignator. So,finally down to the actual attribute.
- //
- AttributeValueType attributeValue = match.getAttributeValue();
- String value = (String) attributeValue.getContent().get(0);
- if(value!=null){
+ boolean rawPolicyCheck = false;
+ if (policyAdapter.getPolicyData() instanceof PolicySetType) {
+ rawPolicyCheck = ((PolicySetType) policyAdapter.getPolicyData()).getDescription().contains(decisionRawType);
+ } else {
+ rawPolicyCheck = ((PolicyType) policyAdapter.getPolicyData()).getDescription().contains(decisionRawType);
+ }
+
+ if (rawPolicyCheck) {
+ rawXACMLPolicy(policyAdapter, entity);
+ } else {
+ RainyDayParams rainydayParams = new RainyDayParams();
+ Object policyData = policyAdapter.getPolicyData();
+ PolicyType policy = (PolicyType) policyData;
+ policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName());
+
+ policyAdapter.setPolicyName(StringUtils.substringAfter(policyAdapter.getPolicyName(), "Decision_"));
+ String description = "";
+ String blackListEntryType = "Use Manual Entry";
+ try {
+ if (policy.getDescription().contains(blEntry)) {
+ blackListEntryType = policy.getDescription().substring(policy.getDescription().indexOf(blEntry) + 9,
+ policy.getDescription().lastIndexOf(blEntry));
+ }
+ policyAdapter.setBlackListEntryType(blackListEntryType);
+ description = policy.getDescription().substring(0, policy.getDescription().indexOf("@CreatedBy:"));
+
+ } catch (Exception e) {
+ policyLogger.info("General error", e);
+ description = policy.getDescription();
+ }
+ policyAdapter.setPolicyDescription(description);
+ // Get the target data under policy for Action.
+ TargetType target = policy.getTarget();
+ if (target != null) {
+ // under target we have AnyOFType
+ List<AnyOfType> anyOfList = target.getAnyOf();
+ if (anyOfList != null) {
+ Iterator<AnyOfType> iterAnyOf = anyOfList.iterator();
+ while (iterAnyOf.hasNext()) {
+ AnyOfType anyOf = iterAnyOf.next();
+ // Under AntOfType we have AllOfType
+ List<AllOfType> allOfList = anyOf.getAllOf();
+ if (allOfList != null) {
+ Iterator<AllOfType> iterAllOf = allOfList.iterator();
+ while (iterAllOf.hasNext()) {
+ AllOfType allOf = iterAllOf.next();
+ // Under AllOfType we have Mathch.
+ List<MatchType> matchList = allOf.getMatch();
+ int index = 0;
+ if (matchList != null) {
+ Iterator<MatchType> iterMatch = matchList.iterator();
+ while (iterMatch.hasNext()) {
+ MatchType match = iterMatch.next();
+ //
+ // Under the match we have attributevalue and
+ // attributeDesignator. So,finally down to the actual attribute.
+ //
+ AttributeValueType attributeValue = match.getAttributeValue();
+ String value = (String) attributeValue.getContent().get(0);
+ if (value != null) {
value = value.replaceAll("\\(\\?i\\)", "");
}
- AttributeDesignatorType designator = match.getAttributeDesignator();
- String attributeId = designator.getAttributeId();
- // First match in the target is OnapName, so set that value.
- if ("ONAPName".equals(attributeId)) {
- policyAdapter.setOnapName(value);
- }
- // Component attributes are saved under Target here we are fetching them back.
- // One row is default so we are not adding dynamic component at index 0.
- if (index >= 1) {
- Map<String, String> attribute = new HashMap<>();
- attribute.put("key", attributeId);
- attribute.put("value", value);
- attributeList.add(attribute);
- }
- index++;
- }
- }
- policyAdapter.setAttributes(attributeList);
- }
- }
- }
- // Setting rainy day attributes to the parameters object if they exist
- boolean rainy = false;
- if(!attributeList.isEmpty()) {
- for(int i=0; i<attributeList.size() ; i++){
- Map<String, String> map = (Map<String,String>)attributeList.get(i);
- if("WorkStep".equals(map.get("key"))){
- rainydayParams.setWorkstep(map.get("value"));
- rainy=true;
- }else if("BB_ID".equals(map.get("key"))){
- rainydayParams.setBbid(map.get("value"));
- rainy=true;
- }else if("ServiceType".equals(map.get("key"))){
- rainydayParams.setServiceType(map.get("value"));
- rainy=true;
- }else if("VNFType".equals(map.get("key"))){
- rainydayParams.setVnfType(map.get("value"));
- rainy=true;
- }
- }
- }
- if(rainy){
- policyAdapter.setRuleProvider("Rainy_Day");
- }
- }
+ AttributeDesignatorType designator = match.getAttributeDesignator();
+ String attributeId = designator.getAttributeId();
+ // First match in the target is OnapName, so set that value.
+ if ("ONAPName".equals(attributeId)) {
+ policyAdapter.setOnapName(value);
+ }
+ // Component attributes are saved under Target here we are fetching them back.
+ // One row is default so we are not adding dynamic component at index 0.
+ if (index >= 1) {
+ Map<String, String> attribute = new HashMap<>();
+ attribute.put("key", attributeId);
+ attribute.put("value", value);
+ attributeList.add(attribute);
+ }
+ index++;
+ }
+ }
+ policyAdapter.setAttributes(attributeList);
+ }
+ }
+ }
+ // Setting rainy day attributes to the parameters object if they exist
+ boolean rainy = false;
+ if (!attributeList.isEmpty()) {
+ for (int i = 0; i < attributeList.size(); i++) {
+ Map<String, String> map = (Map<String, String>) attributeList.get(i);
+ if ("WorkStep".equals(map.get("key"))) {
+ rainydayParams.setWorkstep(map.get("value"));
+ rainy = true;
+ } else if ("BB_ID".equals(map.get("key"))) {
+ rainydayParams.setBbid(map.get("value"));
+ rainy = true;
+ } else if ("ServiceType".equals(map.get("key"))) {
+ rainydayParams.setServiceType(map.get("value"));
+ rainy = true;
+ } else if ("VNFType".equals(map.get("key"))) {
+ rainydayParams.setVnfType(map.get("value"));
+ rainy = true;
+ }
+ }
+ }
+ if (rainy) {
+ policyAdapter.setRuleProvider("Rainy_Day");
+ }
+ }
+
+ List<Object> ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
+ int index = 0;
+ for (Object object : ruleList) {
+ if (object instanceof VariableDefinitionType) {
+ VariableDefinitionType variableDefinitionType = (VariableDefinitionType) object;
+ Map<String, String> settings = new HashMap<>();
+ settings.put("key", variableDefinitionType.getVariableId());
+ JAXBElement<AttributeValueType> attributeValueTypeElement =
+ (JAXBElement<AttributeValueType>) variableDefinitionType.getExpression();
+ if (attributeValueTypeElement != null) {
+ AttributeValueType attributeValueType = attributeValueTypeElement.getValue();
+ settings.put("value", attributeValueType.getContent().get(0).toString());
+ }
+ decisionList.add(settings);
+ } else if (object instanceof RuleType) {
+ // get the condition data under the rule for rule Algorithms.
+ if (((RuleType) object).getEffect().equals(EffectType.DENY)) {
+ if (((RuleType) object).getAdviceExpressions() != null) {
+ if ("AAF".equalsIgnoreCase(((RuleType) object).getAdviceExpressions()
+ .getAdviceExpression().get(0).getAdviceId())) {
+ policyAdapter.setRuleProvider("AAF");
+ break;
+ } else if ("GUARD_YAML".equalsIgnoreCase(((RuleType) object).getAdviceExpressions()
+ .getAdviceExpression().get(0).getAdviceId())) {
+ policyAdapter.setRuleProvider("GUARD_YAML");
+ } else if ("GUARD_BL_YAML".equalsIgnoreCase(((RuleType) object).getAdviceExpressions()
+ .getAdviceExpression().get(0).getAdviceId())) {
+ policyAdapter.setRuleProvider("GUARD_BL_YAML");
+ }
+ } else {
+ policyAdapter.setRuleProvider("Custom");
+ }
+ ConditionType condition = ((RuleType) object).getCondition();
+ if (condition != null) {
+ ApplyType decisionApply = (ApplyType) condition.getExpression().getValue();
+ decisionApply = (ApplyType) decisionApply.getExpression().get(0).getValue();
+ ruleAlgoirthmTracker = new LinkedList<>();
+ if (policyAdapter.getRuleProvider() != null
+ && ("GUARD_YAML".equals(policyAdapter.getRuleProvider())
+ || ("GUARD_BL_YAML".equals(policyAdapter.getRuleProvider())))) {
+ YAMLParams yamlParams = new YAMLParams();
+ for (int i = 0; i < attributeList.size(); i++) {
+ Map<String, String> map = (Map<String, String>) attributeList.get(i);
+ if ("actor".equals(map.get("key"))) {
+ yamlParams.setActor(map.get("value"));
+ } else if ("recipe".equals(map.get("key"))) {
+ yamlParams.setRecipe(map.get("value"));
+ } else if ("target".equals(map.get("key"))) {
+ yamlParams.setTargets(Arrays.asList(map.get("value").split("\\|")));
+ } else if ("clname".equals(map.get("key"))) {
+ yamlParams.setClname(map.get("value"));
+ }
+ }
+ ApplyType apply =
+ (ApplyType) ((ApplyType) decisionApply.getExpression().get(0).getValue())
+ .getExpression().get(0).getValue();
+ yamlParams.setGuardActiveStart(
+ ((AttributeValueType) apply.getExpression().get(1).getValue()).getContent()
+ .get(0).toString());
+ yamlParams.setGuardActiveEnd(
+ ((AttributeValueType) apply.getExpression().get(2).getValue()).getContent()
+ .get(0).toString());
+ if ("GUARD_BL_YAML".equals(policyAdapter.getRuleProvider())) {
+ apply = (ApplyType) ((ApplyType) ((ApplyType) decisionApply.getExpression()
+ .get(0).getValue()).getExpression().get(1).getValue()).getExpression()
+ .get(2).getValue();
+ Iterator<JAXBElement<?>> attributes = apply.getExpression().iterator();
+ List<String> blackList = new ArrayList<>();
+ while (attributes.hasNext()) {
+ blackList.add(((AttributeValueType) attributes.next().getValue())
+ .getContent().get(0).toString());
+ }
+ yamlParams.setBlackList(blackList);
+ if ("Use File Upload".equals(policyAdapter.getBlackListEntryType())) {
+ policyAdapter.setBlackListEntries(blackList);
+ }
+ } else {
+ ApplyType timeWindowSection = (ApplyType) ((ApplyType) decisionApply
+ .getExpression().get(0).getValue()).getExpression().get(1).getValue();
+ yamlParams.setLimit(((AttributeValueType) timeWindowSection.getExpression()
+ .get(1).getValue()).getContent().get(0).toString());
+ String timeWindow = ((AttributeDesignatorType) ((ApplyType) timeWindowSection
+ .getExpression().get(0).getValue()).getExpression().get(0).getValue())
+ .getIssuer();
+ yamlParams.setTimeUnits(timeWindow.substring(timeWindow.lastIndexOf(':') + 1));
+ yamlParams.setTimeWindow(timeWindow.substring(timeWindow.indexOf(":tw:") + 4,
+ timeWindow.lastIndexOf(':')));
+ }
+ policyAdapter.setYamlparams(yamlParams);
+ policyAdapter.setAttributes(new ArrayList<Object>());
+ policyAdapter.setRuleAlgorithmschoices(new ArrayList<Object>());
+ break;
+ }
+ // Populating Rule Algorithms starting from compound.
+ prePopulateDecisionCompoundRuleAlgorithm(index, decisionApply);
+ policyAdapter.setRuleAlgorithmschoices(ruleAlgorithmList);
+ }
+ } else if (policyAdapter.getRuleProvider() != null
+ && "Rainy_Day".equals(policyAdapter.getRuleProvider())
+ && ((RuleType) object).getEffect().equals(EffectType.PERMIT)) {
+
+ TargetType ruleTarget = ((RuleType) object).getTarget();
+ AdviceExpressionsType adviceExpression = ((RuleType) object).getAdviceExpressions();
+
+ String errorcode = ruleTarget.getAnyOf().get(0).getAllOf().get(0).getMatch().get(1)
+ .getAttributeValue().getContent().get(0).toString();
+ JAXBElement<AttributeValueType> tempTreatmentObj =
+ (JAXBElement<AttributeValueType>) adviceExpression.getAdviceExpression().get(0)
+ .getAttributeAssignmentExpression().get(0).getExpression();
+ String treatment = tempTreatmentObj.getValue().getContent().get(0).toString();
+
+ prePopulateRainyDayTreatments(errorcode, treatment);
+
+ }
+ }
+ }
+ }
+
+ rainydayParams.setTreatmentTableChoices(treatmentList);
+ policyAdapter.setRainyday(rainydayParams);
+ policyAdapter.setSettings(decisionList);
+ }
+
+ }
+
+ private void prePopulateRainyDayTreatments(String errorcode, String treatment) {
+ Map<String, String> ruleMap = new HashMap<>();
- List<Object> ruleList = policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
- int index = 0;
- for (Object object : ruleList) {
- if (object instanceof VariableDefinitionType) {
- VariableDefinitionType variableDefinitionType = (VariableDefinitionType) object;
- Map<String, String> settings = new HashMap<>();
- settings.put("key", variableDefinitionType.getVariableId());
- JAXBElement<AttributeValueType> attributeValueTypeElement = (JAXBElement<AttributeValueType>) variableDefinitionType.getExpression();
- if (attributeValueTypeElement != null) {
- AttributeValueType attributeValueType = attributeValueTypeElement.getValue();
- settings.put("value", attributeValueType.getContent().get(0).toString());
- }
- decisionList.add(settings);
- } else if (object instanceof RuleType) {
- // get the condition data under the rule for rule Algorithms.
- if(((RuleType) object).getEffect().equals(EffectType.DENY)) {
- if(((RuleType) object).getAdviceExpressions()!=null){
- if("AAF".equalsIgnoreCase(((RuleType) object).getAdviceExpressions().getAdviceExpression().get(0).getAdviceId())){
- policyAdapter.setRuleProvider("AAF");
- break;
- }else if("GUARD_YAML".equalsIgnoreCase(((RuleType) object).getAdviceExpressions().getAdviceExpression().get(0).getAdviceId())){
- policyAdapter.setRuleProvider("GUARD_YAML");
- }else if("GUARD_BL_YAML".equalsIgnoreCase(((RuleType) object).getAdviceExpressions().getAdviceExpression().get(0).getAdviceId())){
- policyAdapter.setRuleProvider("GUARD_BL_YAML");
- }
- }else{
- policyAdapter.setRuleProvider("Custom");
- }
- ConditionType condition = ((RuleType) object).getCondition();
- if (condition != null) {
- ApplyType decisionApply = (ApplyType) condition.getExpression().getValue();
- decisionApply = (ApplyType) decisionApply.getExpression().get(0).getValue();
- ruleAlgoirthmTracker = new LinkedList<>();
- if(policyAdapter.getRuleProvider()!=null && ("GUARD_YAML".equals(policyAdapter.getRuleProvider())||("GUARD_BL_YAML".equals(policyAdapter.getRuleProvider())))){
- YAMLParams yamlParams = new YAMLParams();
- for(int i=0; i<attributeList.size() ; i++){
- Map<String, String> map = (Map<String,String>)attributeList.get(i);
- if("actor".equals(map.get("key"))){
- yamlParams.setActor(map.get("value"));
- }else if("recipe".equals(map.get("key"))){
- yamlParams.setRecipe(map.get("value"));
- }else if("target".equals(map.get("key"))){
- yamlParams.setTargets(Arrays.asList(map.get("value").split("\\|")));
- }else if("clname".equals(map.get("key"))){
- yamlParams.setClname(map.get("value"));
- }
- }
- ApplyType apply = (ApplyType)((ApplyType)decisionApply.getExpression().get(0).getValue()).getExpression().get(0).getValue();
- yamlParams.setGuardActiveStart(((AttributeValueType)apply.getExpression().get(1).getValue()).getContent().get(0).toString());
- yamlParams.setGuardActiveEnd(((AttributeValueType)apply.getExpression().get(2).getValue()).getContent().get(0).toString());
- if("GUARD_BL_YAML".equals(policyAdapter.getRuleProvider())){
- apply = (ApplyType)((ApplyType)((ApplyType)decisionApply.getExpression().get(0).getValue()).getExpression().get(1).getValue()).getExpression().get(2).getValue();
- Iterator<JAXBElement<?>> attributes = apply.getExpression().iterator();
- List<String> blackList = new ArrayList<>();
- while(attributes.hasNext()){
- blackList.add(((AttributeValueType)attributes.next().getValue()).getContent().get(0).toString());
- }
- yamlParams.setBlackList(blackList);
- }else{
- ApplyType timeWindowSection = (ApplyType)((ApplyType)decisionApply.getExpression().get(0).getValue()).getExpression().get(1).getValue();
- yamlParams.setLimit(((AttributeValueType)timeWindowSection.getExpression().get(1).getValue()).getContent().get(0).toString());
- String timeWindow = ((AttributeDesignatorType)((ApplyType)timeWindowSection.getExpression().get(0).getValue()).getExpression().get(0).getValue()).getIssuer();
- yamlParams.setTimeUnits(timeWindow.substring(timeWindow.lastIndexOf(':')+1));
- yamlParams.setTimeWindow(timeWindow.substring(timeWindow.indexOf(":tw:")+4,timeWindow.lastIndexOf(':')));
- }
- policyAdapter.setYamlparams(yamlParams);
- policyAdapter.setAttributes(new ArrayList<Object>());
- policyAdapter.setRuleAlgorithmschoices(new ArrayList<Object>());
- break;
- }
- // Populating Rule Algorithms starting from compound.
- prePopulateDecisionCompoundRuleAlgorithm(index, decisionApply);
- policyAdapter.setRuleAlgorithmschoices(ruleAlgorithmList);
- }
- } else if(policyAdapter.getRuleProvider()!=null && "Rainy_Day".equals(policyAdapter.getRuleProvider())&& ((RuleType) object).getEffect().equals(EffectType.PERMIT)) {
-
- TargetType ruleTarget = ((RuleType) object).getTarget();
- AdviceExpressionsType adviceExpression = ((RuleType) object).getAdviceExpressions();
-
- String errorcode = ruleTarget.getAnyOf().get(0).getAllOf().get(0).getMatch().
- get(1).getAttributeValue().getContent().get(0).toString();
- JAXBElement<AttributeValueType> tempTreatmentObj = (JAXBElement<AttributeValueType>) adviceExpression.getAdviceExpression().
- get(0).getAttributeAssignmentExpression().get(0).getExpression();
- String treatment = tempTreatmentObj.getValue().getContent().get(0).toString();
-
- prePopulateRainyDayTreatments(errorcode, treatment);
+ ruleMap.put("errorcode", errorcode);
+ ruleMap.put("treatment", treatment);
+ treatmentList.add(ruleMap);
- }
- }
- }
- }
-
- rainydayParams.setTreatmentTableChoices(treatmentList);
- policyAdapter.setRainyday(rainydayParams);
- policyAdapter.setSettings(decisionList);
- }
+ }
- }
+ private void prePopulateDecisionRuleAlgorithms(int index, ApplyType decisionApply,
+ List<JAXBElement<?>> jaxbDecisionTypes) {
+ Map<String, String> ruleMap = new HashMap<>();
+ ruleMap.put("id", "A" + (index + 1));
+ Map<String, String> dropDownMap = PolicyController.getDropDownMap();
+ for (Entry<String, String> entry : dropDownMap.entrySet()) {
+ if (entry.getValue().equals(decisionApply.getFunctionId())) {
+ ruleMap.put("dynamicRuleAlgorithmCombo", entry.getKey());
+ }
+ }
+ // Populate the key and value fields
+ if ((jaxbDecisionTypes.get(0).getValue() instanceof AttributeValueType)) {
+ ApplyType innerDecisionApply = (ApplyType) jaxbDecisionTypes.get(1).getValue();
+ List<JAXBElement<?>> jaxbInnerDecisionTypes = innerDecisionApply.getExpression();
+ if (jaxbInnerDecisionTypes.get(0).getValue() instanceof AttributeDesignatorType) {
+ AttributeDesignatorType attributeDesignator =
+ (AttributeDesignatorType) jaxbInnerDecisionTypes.get(0).getValue();
+ ruleMap.put("dynamicRuleAlgorithmField1", attributeDesignator.getAttributeId());
- private void prePopulateRainyDayTreatments(String errorcode, String treatment) {
- Map<String, String> ruleMap = new HashMap<>();
-
- ruleMap.put("errorcode", errorcode);
- ruleMap.put("treatment", treatment);
- treatmentList.add(ruleMap);
-
- }
-
- private void prePopulateDecisionRuleAlgorithms(int index, ApplyType decisionApply, List<JAXBElement<?>> jaxbDecisionTypes) {
- Map<String, String> ruleMap = new HashMap<>();
- ruleMap.put("id", "A" + (index +1));
- Map<String, String> dropDownMap = PolicyController.getDropDownMap();
- for (Entry<String, String> entry : dropDownMap.entrySet()) {
- if (entry.getValue().equals(decisionApply.getFunctionId())) {
- ruleMap.put("dynamicRuleAlgorithmCombo", entry.getKey());
- }
- }
- // Populate the key and value fields
- if ((jaxbDecisionTypes.get(0).getValue() instanceof AttributeValueType)) {
- ApplyType innerDecisionApply = (ApplyType) jaxbDecisionTypes.get(1).getValue();
- List<JAXBElement<?>> jaxbInnerDecisionTypes = innerDecisionApply.getExpression();
- if (jaxbInnerDecisionTypes.get(0).getValue() instanceof AttributeDesignatorType) {
- AttributeDesignatorType attributeDesignator = (AttributeDesignatorType) jaxbInnerDecisionTypes.get(0).getValue();
- ruleMap.put("dynamicRuleAlgorithmField1", attributeDesignator.getAttributeId());
+ // Get from Attribute Value
+ AttributeValueType actionConditionAttributeValue =
+ (AttributeValueType) jaxbDecisionTypes.get(0).getValue();
+ String attributeValue = (String) actionConditionAttributeValue.getContent().get(0);
+ ruleMap.put("dynamicRuleAlgorithmField2", attributeValue);
+ }
+ } else if ((jaxbDecisionTypes.get(0).getValue()) instanceof VariableReferenceType) {
+ VariableReferenceType variableReference = (VariableReferenceType) jaxbDecisionTypes.get(0).getValue();
+ ruleMap.put("dynamicRuleAlgorithmField1", "S_" + variableReference.getVariableId());
- // Get from Attribute Value
- AttributeValueType actionConditionAttributeValue = (AttributeValueType) jaxbDecisionTypes.get(0).getValue();
- String attributeValue = (String) actionConditionAttributeValue.getContent().get(0);
- ruleMap.put("dynamicRuleAlgorithmField2", attributeValue);
- }
- } else if ((jaxbDecisionTypes.get(0).getValue()) instanceof VariableReferenceType) {
- VariableReferenceType variableReference = (VariableReferenceType) jaxbDecisionTypes.get(0).getValue();
- ruleMap.put("dynamicRuleAlgorithmField1", "S_"+ variableReference.getVariableId());
+ // Get from Attribute Value
+ AttributeValueType actionConditionAttributeValue = (AttributeValueType) jaxbDecisionTypes.get(1).getValue();
+ String attributeValue = (String) actionConditionAttributeValue.getContent().get(0);
+ ruleMap.put("dynamicRuleAlgorithmField2", attributeValue);
+ }
+ ruleAlgorithmList.add(ruleMap);
+ }
- // Get from Attribute Value
- AttributeValueType actionConditionAttributeValue = (AttributeValueType) jaxbDecisionTypes.get(1).getValue();
- String attributeValue = (String) actionConditionAttributeValue.getContent().get(0);
- ruleMap.put("dynamicRuleAlgorithmField2", attributeValue);
- }
- ruleAlgorithmList.add(ruleMap);
- }
+ private int prePopulateDecisionCompoundRuleAlgorithm(int index, ApplyType decisionApply) {
+ boolean isCompoundRule = true;
+ List<JAXBElement<?>> jaxbDecisionTypes = decisionApply.getExpression();
+ for (JAXBElement<?> jaxbElement : jaxbDecisionTypes) {
+ // If There is Attribute Value under Decision Type that means we came to the final child
+ if (policyLogger.isDebugEnabled()) {
+ policyLogger.debug("Prepopulating rule algoirthm: " + index);
+ }
+ // Check to see if Attribute Value exists, if yes then it is not a compound rule
+ if (jaxbElement.getValue() instanceof AttributeValueType) {
+ prePopulateDecisionRuleAlgorithms(index, decisionApply, jaxbDecisionTypes);
+ ruleAlgoirthmTracker.addLast(index);
+ isCompoundRule = false;
+ index++;
+ }
+ }
+ if (isCompoundRule) {
+ // As it's compound rule, Get the Apply types
+ for (JAXBElement<?> jaxbElement : jaxbDecisionTypes) {
+ ApplyType innerDecisionApply = (ApplyType) jaxbElement.getValue();
+ index = prePopulateDecisionCompoundRuleAlgorithm(index, innerDecisionApply);
+ }
+ // Populate combo box
+ if (policyLogger.isDebugEnabled()) {
+ policyLogger.debug("Prepopulating Compound rule algorithm: " + index);
+ }
+ Map<String, String> rule = new HashMap<>();
+ for (String key : PolicyController.getDropDownMap().keySet()) {
+ String keyValue = PolicyController.getDropDownMap().get(key);
+ if (keyValue.equals(decisionApply.getFunctionId())) {
+ rule.put("dynamicRuleAlgorithmCombo", key);
+ break;
+ }
+ }
- private int prePopulateDecisionCompoundRuleAlgorithm(int index, ApplyType decisionApply) {
- boolean isCompoundRule = true;
- List<JAXBElement<?>> jaxbDecisionTypes = decisionApply.getExpression();
- for (JAXBElement<?> jaxbElement : jaxbDecisionTypes) {
- // If There is Attribute Value under Decision Type that means we came to the final child
- if (policyLogger.isDebugEnabled()) {
- policyLogger.debug("Prepopulating rule algoirthm: " + index);
- }
- // Check to see if Attribute Value exists, if yes then it is not a compound rule
- if(jaxbElement.getValue() instanceof AttributeValueType) {
- prePopulateDecisionRuleAlgorithms(index, decisionApply, jaxbDecisionTypes);
- ruleAlgoirthmTracker.addLast(index);
- isCompoundRule = false;
- index++;
- }
- }
- if (isCompoundRule) {
- // As it's compound rule, Get the Apply types
- for (JAXBElement<?> jaxbElement : jaxbDecisionTypes) {
- ApplyType innerDecisionApply = (ApplyType) jaxbElement.getValue();
- index = prePopulateDecisionCompoundRuleAlgorithm(index, innerDecisionApply);
- }
- // Populate combo box
- if (policyLogger.isDebugEnabled()) {
- policyLogger.debug("Prepopulating Compound rule algorithm: " + index);
- }
- Map<String, String> rule = new HashMap<>();
- for (String key : PolicyController.getDropDownMap().keySet()) {
- String keyValue = PolicyController.getDropDownMap().get(key);
- if (keyValue.equals(decisionApply.getFunctionId())) {
- rule.put("dynamicRuleAlgorithmCombo", key);
- break;
- }
- }
+ rule.put("id", "A" + (index + 1));
+ // Populate Key and values for Compound Rule
+ rule.put("dynamicRuleAlgorithmField1", "A" + (ruleAlgoirthmTracker.getLast() + 1));
+ ruleAlgoirthmTracker.removeLast();
+ rule.put("dynamicRuleAlgorithmField2", "A" + (ruleAlgoirthmTracker.getLast() + 1));
+ ruleAlgoirthmTracker.removeLast();
+ ruleAlgoirthmTracker.addLast(index);
+ ruleAlgorithmList.add(rule);
+ index++;
+ }
- rule.put("id", "A" + (index +1));
- // Populate Key and values for Compound Rule
- rule.put("dynamicRuleAlgorithmField1", "A" + (ruleAlgoirthmTracker.getLast() + 1 ));
- ruleAlgoirthmTracker.removeLast();
- rule.put("dynamicRuleAlgorithmField2", "A" + (ruleAlgoirthmTracker.getLast() + 1));
- ruleAlgoirthmTracker.removeLast();
- ruleAlgoirthmTracker.addLast(index);
- ruleAlgorithmList.add(rule);
- index++;
- }
-
- return index;
- }
+ return index;
+ }
}
diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js
index f560f4d58..ba9e44868 100644
--- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js
+++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js
@@ -17,414 +17,444 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', '$http', function ($scope, PolicyAppService, PolicyNavigator, modalService, $modal, Notification, $http) {
- $("#dialog").hide();
-
- $scope.policyNavigator;
- $scope.savebutton = true;
- $scope.refreshCheck = false;
- $scope.disableOnCreate = false;
-
- if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
- $scope.disableOnCreate = true;
- $scope.temp.policy = {
- policyType : "Decision"
- }
- };
-
- $scope.refresh = function(){
- if($scope.refreshCheck){
- $scope.policyNavigator.refresh();
- }
- $scope.modal('createNewPolicy', true);
- $scope.temp.policy = "";
- };
-
- $scope.modal = function(id, hide) {
- return $('#' + id).modal(hide ? 'hide' : 'show');
- };
-
- if($scope.temp.policy.ruleProvider==undefined){
- $scope.temp.policy.ruleProvider="Custom";
+angular.module('abs').controller('decisionPolicyController', [ '$scope', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', '$http', function($scope, PolicyAppService, PolicyNavigator, modalService, $modal, Notification, $http) {
+ $("#dialog").hide();
+
+ $scope.policyNavigator;
+ $scope.savebutton = true;
+ $scope.refreshCheck = false;
+ $scope.disableOnCreate = false;
+ $scope.notRawPolicy = true;
+
+ if (!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly) {
+ $scope.disableOnCreate = true;
+ $scope.temp.policy = {
+ policyType : "Decision"
+ }
}
-
- if($scope.temp.policy.blackListEntryType==undefined){
- $scope.temp.policy.blackListEntryType="Use Manual Entry";
+ ;
+
+ $scope.refresh = function() {
+ if ($scope.refreshCheck) {
+ $scope.policyNavigator.refresh();
+ }
+ $scope.modal('createNewPolicy', true);
+ $scope.temp.policy = "";
+ };
+
+ $scope.modal = function(id, hide) {
+ return $('#' + id).modal(hide ? 'hide' : 'show');
+ };
+
+ if ($scope.temp.policy.ruleProvider == undefined) {
+ $scope.temp.policy.ruleProvider = "Custom";
+ }
+
+ if ($scope.temp.policy.blackListEntryType == undefined) {
+ $scope.temp.policy.blackListEntryType = "Use Manual Entry";
}
-
- PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
+
+ PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function(data) {
var j = data;
$scope.data = JSON.parse(j.data);
console.log($scope.data);
$scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
console.log($scope.onapNameDictionaryDatas);
- }, function (error) {
+ }, function(error) {
console.log("failed");
});
- PolicyAppService.getData('getDictionary/get_SettingsDictionaryDataByName').then(function (data) {
+ PolicyAppService.getData('getDictionary/get_SettingsDictionaryDataByName').then(function(data) {
var j = data;
$scope.data = JSON.parse(j.data);
console.log($scope.data);
$scope.settingsDictionaryDatas = JSON.parse($scope.data.settingsDictionaryDatas);
console.log($scope.settingsDictionaryDatas);
- }, function (error) {
+ }, function(error) {
console.log("failed");
});
- PolicyAppService.getData('get_FunctionDefinitionDataByName').then(function (data) {
+ PolicyAppService.getData('get_FunctionDefinitionDataByName').then(function(data) {
var j = data;
$scope.data = JSON.parse(j.data);
console.log($scope.data);
$scope.functionDefinitionDatas = JSON.parse($scope.data.functionDefinitionDatas);
console.log($scope.functionDefinitionDatas);
- }, function (error) {
+ }, function(error) {
console.log("failed");
});
- PolicyAppService.getData('getDictionary/get_AttributeDatabyAttributeName').then(function (data) {
+ PolicyAppService.getData('getDictionary/get_AttributeDatabyAttributeName').then(function(data) {
var j = data;
$scope.data = JSON.parse(j.data);
console.log($scope.data);
$scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
console.log($scope.attributeDictionaryDatas);
- }, function (error) {
+ }, function(error) {
console.log("failed");
});
- PolicyAppService.getData('getDictionary/get_RainyDayDictionaryDataByName').then(function (data) {
+ PolicyAppService.getData('getDictionary/get_RainyDayDictionaryDataByName').then(function(data) {
var j = data;
$scope.data = JSON.parse(j.data);
console.log($scope.data);
- $scope.rainyDayDictionaryDatas = JSON.parse($scope.data.rainyDayDictionaryDatas);
+ $scope.rainyDayDictionaryDatas = JSON.parse($scope.data.rainyDayDictionaryDatas);
console.log($scope.rainyDayDictionaryDatas);
- }, function (error) {
+ }, function(error) {
console.log("failed");
});
-
- PolicyAppService.getData('getDictionary/get_RainyDayDictionaryData').then(function (data) {
- var j = data;
- $scope.data = JSON.parse(j.data);
- console.log($scope.data);
- $scope.rainyDayDictionaryDataEntity = JSON.parse($scope.data.rainyDayDictionaryDatas);
- console.log($scope.rainyDayDictionaryDatasEntity);
- }, function (error) {
- console.log("failed");
- });
-
- function extend(obj, src) {
- for (var key in src) {
- if (src.hasOwnProperty(key)) obj[key] = src[key];
- }
- return obj;
- }
-
- $scope.saveDecisionPolicy = function(policy){
- if(policy.itemContent != undefined){
- $scope.refreshCheck = true;
- $scope.policyNavigator = policy.itemContent;
- policy.itemContent = "";
- }
- $scope.savebutton = false;
- console.log(policy);
- var uuu = "policycreation/save_policy";
- var postData={policyData: policy};
+
+ PolicyAppService.getData('getDictionary/get_RainyDayDictionaryData').then(function(data) {
+ var j = data;
+ $scope.data = JSON.parse(j.data);
+ console.log($scope.data);
+ $scope.rainyDayDictionaryDataEntity = JSON.parse($scope.data.rainyDayDictionaryDatas);
+ console.log($scope.rainyDayDictionaryDatasEntity);
+ }, function(error) {
+ console.log("failed");
+ });
+
+ function extend(obj, src) {
+ for (var key in src) {
+ if (src.hasOwnProperty(key))
+ obj[key] = src[key];
+ }
+ return obj;
+ }
+
+ $scope.saveDecisionPolicy = function(policy) {
+ if (policy.itemContent != undefined) {
+ $scope.refreshCheck = true;
+ $scope.policyNavigator = policy.itemContent;
+ policy.itemContent = "";
+ }
+ $scope.savebutton = false;
+ console.log(policy);
+ var uuu = "policycreation/save_policy";
+ var postData = {
+ policyData : policy
+ };
$.ajax({
type : 'POST',
url : uuu,
- dataType: 'json',
- contentType: 'application/json',
- data: JSON.stringify(postData),
- success : function(data){
- $scope.$apply(function(){
- $scope.data=data.policyData;
- if($scope.data == 'success'){
+ dataType : 'json',
+ contentType : 'application/json',
+ data : JSON.stringify(postData),
+ success : function(data) {
+ $scope.$apply(function() {
+ $scope.data = data.policyData;
+ if ($scope.data == 'success') {
$scope.temp.policy.readOnly = 'true';
- Notification.success("Policy Saved Successfully.");
- }else if ($scope.data == 'PolicyExists'){
+ Notification.success("Policy Saved Successfully.");
+ } else if ($scope.data == 'PolicyExists') {
$scope.savebutton = true;
Notification.error("Policy Already Exists with Same Name in Scope.");
- }
+ }
});
console.log($scope.data);
-
+
},
- error : function(data){
+ error : function(data) {
Notification.error("Error Occured while saving Policy.");
}
});
- };
-
- $scope.validatePolicy = function(policy){
- console.log(policy);
- document.getElementById("validate").innerHTML = "";
- var uuu = "policyController/validate_policy.htm";
- var postData={policyData: policy};
- $.ajax({
- type : 'POST',
- url : uuu,
- dataType: 'json',
- contentType: 'application/json',
- data: JSON.stringify(postData),
- success : function(data){
- $scope.$apply(function(){
- $scope.validateData = data.data.replace(/\"/g, "");
- $scope.data=data.data;
- if($scope.data == '"success"'){
- Notification.success("Validation Success.");
- $scope.savebutton = false;
- }else{
- Notification.error("Validation Failed.");
- document.getElementById("validate").innerHTML = $scope.validateData;
- document.getElementById("validate").style.color = "white";
- document.getElementById("validate").style.backgroundColor = "red";
- $scope.savebutton = true;
- }
-
- });
- console.log($scope.data);
- },
- error : function(data){
- Notification.error("Validation Failed.");
- $scope.savebutton = true;
- }
- });
- };
-
- if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
- $scope.temp.policy.attributes = [];
- $scope.temp.policy.settings = [];
- $scope.temp.policy.ruleAlgorithmschoices = [];
- if(!$scope.temp.policy.yamlparams){
- $scope.temp.policy.yamlparams = {};
- }
- if(!$scope.temp.policy.yamlparams.targets){
- $scope.temp.policy.yamlparams.targets = [];
- }
- if(!$scope.temp.policy.yamlparams.blackList){
- $scope.temp.policy.yamlparams.blackList = [];
- }
- if(!$scope.temp.policy.rainyday){
- $scope.temp.policy.rainyday = {};
- }
- if(!$scope.temp.policy.rainyday.treatmentTableChoices){
- $scope.temp.policy.rainyday.treatmentTableChoices = [];
- }
-
- }else if($scope.temp.policy.ruleProvider=="Custom"){
- if($scope.temp.policy.attributes.length == 0){
- $scope.temp.policy.attributes = [];
- }
- if($scope.temp.policy.settings.length == 0){
- $scope.temp.policy.settings = [];
- }
- if($scope.temp.policy.ruleAlgorithmschoices == null || $scope.temp.policy.ruleAlgorithmschoices.length == 0){
- $scope.temp.policy.ruleAlgorithmschoices = [];
- }
- }else if($scope.temp.policy.ruleProvider=="GUARD_BL_YAML"){
- if($scope.temp.policy.yamlparams.blackList == null || $scope.temp.policy.yamlparams.blackList.length==0){
- $scope.temp.policy.yamlparams.blackList = [];
- }
- if($scope.temp.policy.blackListEntries == null || $scope.temp.policy.blackListEntries.length==0){
- $scope.temp.policy.blackListEntries = [];
- }
- $scope.blackListEntries = [];
- $scope.temp.policy.appendBlackListEntries = [];
- $scope.blackListEntries = arrayUnique($scope.temp.policy.blackListEntries.concat($scope.temp.policy.yamlparams.blackList));
- }else if($scope.temp.policy.ruleProvider=="GUARD_YAML"){
- if($scope.temp.policy.yamlparams.targets.length==0){
- $scope.temp.policy.yamlparams.targets = [];
- }
- }else if($scope.temp.policy.ruleProvider=="Rainy_Day"){
- if($scope.temp.policy.rainyday.treatmentTableChoices == null || $scope.temp.policy.rainyday.treatmentTableChoices.length == 0){
- $scope.temp.policy.rainyday.treatmentTableChoices = [];
- }
- }
- $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
- $scope.addNewChoice = function() {
- var newItemNo = $scope.temp.policy.attributes.length+1;
- $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
- };
- $scope.removeChoice = function() {
- var lastItem = $scope.temp.policy.attributes.length-1;
- $scope.temp.policy.attributes.splice(lastItem);
- };
-
- $scope.settingsDatas = [{"settings" : $scope.temp.policy.settings}];
- $scope.addNewSettingsChoice = function() {
- var newItemNo = $scope.temp.policy.settings.length+1;
- $scope.temp.policy.settings.push({'id':'choice'+newItemNo});
- };
- $scope.removeSettingsChoice = function() {
- var lastItem = $scope.temp.policy.settings.length-1;
- $scope.temp.policy.settings.splice(lastItem);
- };
-
- $scope.addNewTarget = function(){
- $scope.temp.policy.yamlparams.targets.push('');
- };
- $scope.removeTarget = function(){
- var lastItem = $scope.temp.policy.yamlparams.targets.length-1;
- $scope.temp.policy.yamlparams.targets.splice(lastItem);
- };
-
- $scope.addNewBL = function() {
- $scope.temp.policy.yamlparams.blackList.push('');
- };
-
- $scope.removeBL = function(id) {
- $scope.temp.policy.yamlparams.blackList = $scope.temp.policy.yamlparams.blackList.filter(function (obj){
+ };
+
+ $scope.validatePolicy = function(policy) {
+ console.log(policy);
+ document.getElementById("validate").innerHTML = "";
+ var uuu = "policyController/validate_policy.htm";
+ var postData = {
+ policyData : policy
+ };
+ $.ajax({
+ type : 'POST',
+ url : uuu,
+ dataType : 'json',
+ contentType : 'application/json',
+ data : JSON.stringify(postData),
+ success : function(data) {
+ $scope.$apply(function() {
+ $scope.validateData = data.data.replace(/\"/g, "");
+ $scope.data = data.data;
+ if ($scope.data == '"success"') {
+ Notification.success("Validation Success.");
+ $scope.savebutton = false;
+ } else {
+ Notification.error("Validation Failed.");
+ document.getElementById("validate").innerHTML = $scope.validateData;
+ document.getElementById("validate").style.color = "white";
+ document.getElementById("validate").style.backgroundColor = "red";
+ $scope.savebutton = true;
+ }
+
+ });
+ console.log($scope.data);
+ },
+ error : function(data) {
+ Notification.error("Validation Failed.");
+ $scope.savebutton = true;
+ }
+ });
+ };
+
+ if (!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly) {
+ $scope.temp.policy.attributes = [];
+ $scope.temp.policy.settings = [];
+ $scope.temp.policy.ruleAlgorithmschoices = [];
+ if (!$scope.temp.policy.yamlparams) {
+ $scope.temp.policy.yamlparams = {};
+ }
+ if (!$scope.temp.policy.yamlparams.targets) {
+ $scope.temp.policy.yamlparams.targets = [];
+ }
+ if (!$scope.temp.policy.yamlparams.blackList) {
+ $scope.temp.policy.yamlparams.blackList = [];
+ }
+ if (!$scope.temp.policy.rainyday) {
+ $scope.temp.policy.rainyday = {};
+ }
+ if (!$scope.temp.policy.rainyday.treatmentTableChoices) {
+ $scope.temp.policy.rainyday.treatmentTableChoices = [];
+ }
+
+ } else if ($scope.temp.policy.ruleProvider == "Custom") {
+ if ($scope.temp.policy.attributes.length == 0) {
+ $scope.temp.policy.attributes = [];
+ }
+ if ($scope.temp.policy.settings.length == 0) {
+ $scope.temp.policy.settings = [];
+ }
+ if ($scope.temp.policy.ruleAlgorithmschoices == null || $scope.temp.policy.ruleAlgorithmschoices.length == 0) {
+ $scope.temp.policy.ruleAlgorithmschoices = [];
+ }
+ } else if ($scope.temp.policy.ruleProvider == "GUARD_BL_YAML") {
+ if ($scope.temp.policy.yamlparams.blackList == null || $scope.temp.policy.yamlparams.blackList.length == 0) {
+ $scope.temp.policy.yamlparams.blackList = [];
+ }
+ if ($scope.temp.policy.blackListEntries == null || $scope.temp.policy.blackListEntries.length == 0) {
+ $scope.temp.policy.blackListEntries = [];
+ }
+ $scope.blackListEntries = [];
+ $scope.temp.policy.appendBlackListEntries = [];
+ $scope.blackListEntries = arrayUnique($scope.temp.policy.blackListEntries.concat($scope.temp.policy.yamlparams.blackList));
+ } else if ($scope.temp.policy.ruleProvider == "GUARD_YAML") {
+ if ($scope.temp.policy.yamlparams.targets.length == 0) {
+ $scope.temp.policy.yamlparams.targets = [];
+ }
+ } else if ($scope.temp.policy.ruleProvider == "Rainy_Day") {
+ if ($scope.temp.policy.rainyday.treatmentTableChoices == null || $scope.temp.policy.rainyday.treatmentTableChoices.length == 0) {
+ $scope.temp.policy.rainyday.treatmentTableChoices = [];
+ }
+ }
+ $scope.attributeDatas = [ {
+ "attributes" : $scope.temp.policy.attributes
+ } ];
+ $scope.addNewChoice = function() {
+ var newItemNo = $scope.temp.policy.attributes.length + 1;
+ $scope.temp.policy.attributes.push({
+ 'id' : 'choice' + newItemNo
+ });
+ };
+ $scope.removeChoice = function() {
+ var lastItem = $scope.temp.policy.attributes.length - 1;
+ $scope.temp.policy.attributes.splice(lastItem);
+ };
+
+ $scope.settingsDatas = [ {
+ "settings" : $scope.temp.policy.settings
+ } ];
+ $scope.addNewSettingsChoice = function() {
+ var newItemNo = $scope.temp.policy.settings.length + 1;
+ $scope.temp.policy.settings.push({
+ 'id' : 'choice' + newItemNo
+ });
+ };
+ $scope.removeSettingsChoice = function() {
+ var lastItem = $scope.temp.policy.settings.length - 1;
+ $scope.temp.policy.settings.splice(lastItem);
+ };
+
+ $scope.addNewTarget = function() {
+ $scope.temp.policy.yamlparams.targets.push('');
+ };
+ $scope.removeTarget = function() {
+ var lastItem = $scope.temp.policy.yamlparams.targets.length - 1;
+ $scope.temp.policy.yamlparams.targets.splice(lastItem);
+ };
+
+ $scope.addNewBL = function() {
+ $scope.temp.policy.yamlparams.blackList.push('');
+ };
+
+ $scope.removeBL = function(id) {
+ $scope.temp.policy.yamlparams.blackList = $scope.temp.policy.yamlparams.blackList.filter(function(obj) {
return obj !== id;
});
- };
-
- $scope.treatmentDatas = [{"treatmentValues" : $scope.temp.policy.rainyday.treatmentTableChoices}];
- $scope.addNewTreatment = function() {
- $scope.temp.policy.rainyday.treatmentTableChoices.push({});
- };
- $scope.removeTreatment = function() {
- var lastItem = $scope.temp.policy.rainyday.treatmentTableChoices.length-1;
- $scope.temp.policy.rainyday.treatmentTableChoices.splice(lastItem);
- };
-
+ };
+
+ $scope.treatmentDatas = [ {
+ "treatmentValues" : $scope.temp.policy.rainyday.treatmentTableChoices
+ } ];
+ $scope.addNewTreatment = function() {
+ $scope.temp.policy.rainyday.treatmentTableChoices.push({});
+ };
+ $scope.removeTreatment = function() {
+ var lastItem = $scope.temp.policy.rainyday.treatmentTableChoices.length - 1;
+ $scope.temp.policy.rainyday.treatmentTableChoices.splice(lastItem);
+ };
+
$scope.workstepDictionaryDatas = [];
- $scope.getWorkstepValues = function(bbidValue){
+ $scope.getWorkstepValues = function(bbidValue) {
for (var i = 0; i < $scope.rainyDayDictionaryDataEntity.length; ++i) {
- var obj = $scope.rainyDayDictionaryDataEntity[i];
- if (obj.bbid == bbidValue){
- $scope.workstepDictionaryDatas.push(obj.workstep);
- }
- }
+ var obj = $scope.rainyDayDictionaryDataEntity[i];
+ if (obj.bbid == bbidValue) {
+ $scope.workstepDictionaryDatas.push(obj.workstep);
+ }
+ }
};
-
+
$scope.allowedTreatmentsDatas = [];
- $scope.getTreatmentValues = function(bbidValue, workstepValue){
+ $scope.getTreatmentValues = function(bbidValue, workstepValue) {
for (var i = 0; i < $scope.rainyDayDictionaryDataEntity.length; ++i) {
- var obj = $scope.rainyDayDictionaryDataEntity[i];
- if (obj.bbid == bbidValue && obj.workstep == workstepValue){
- var splitAlarm = obj.treatments.split(',');
- for (var j = 0; j < splitAlarm.length; ++j) {
- $scope.allowedTreatmentsDatas.push(splitAlarm[j]);
- }
- }
- }
+ var obj = $scope.rainyDayDictionaryDataEntity[i];
+ if (obj.bbid == bbidValue && obj.workstep == workstepValue) {
+ var splitAlarm = obj.treatments.split(',');
+ for (var j = 0; j < splitAlarm.length; ++j) {
+ $scope.allowedTreatmentsDatas.push(splitAlarm[j]);
+ }
+ }
+ }
+ };
+
+ $scope.ItemNo = 0;
+ $scope.ruleAlgorithmDatas = [ {
+ "ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices
+ } ];
+
+ $scope.addNewRuleAlgorithm = function() {
+ if ($scope.temp.policy.ruleAlgorithmschoices != null) {
+ var newItemNo = $scope.temp.policy.ruleAlgorithmschoices.length + 1;
+ } else {
+ var newItemNo = 1;
+ }
+ if (newItemNo > 1) {
+ var value = newItemNo - 1;
+ $scope.attributeDictionaryDatas.push('A' + value);
+ }
+ $scope.temp.policy.ruleAlgorithmschoices.push({
+ 'id' : 'A' + newItemNo
+ });
+ };
+
+ $scope.removeRuleAlgorithm = function() {
+ var lastItem = $scope.temp.policy.ruleAlgorithmschoices.length - 1;
+ $scope.temp.policy.ruleAlgorithmschoices.splice(lastItem);
+ };
+
+ $scope.providerListener = function(ruleProvider) {
+ if (ruleProvider != "Custom") {
+ $scope.temp.policy.ruleAlgorithmschoices = [];
+ $scope.temp.policy.settings = [];
+ $scope.temp.policy.attributes = [];
+ }
+ if (ruleProvider === "Raw") {
+ $scope.notRawPolicy = false;
+ }
};
-
- $scope.ItemNo = 0;
- $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices }];
-
- $scope.addNewRuleAlgorithm = function() {
- if($scope.temp.policy.ruleAlgorithmschoices != null){
- var newItemNo = $scope.temp.policy.ruleAlgorithmschoices.length+1;
- }else{
- var newItemNo = 1;
- }
- if(newItemNo > 1){
- var value = newItemNo-1;
- $scope.attributeDictionaryDatas.push('A'+value);
- }
- $scope.temp.policy.ruleAlgorithmschoices.push({'id':'A'+newItemNo});
- };
-
- $scope.removeRuleAlgorithm = function() {
- var lastItem = $scope.temp.policy.ruleAlgorithmschoices.length-1;
- $scope.temp.policy.ruleAlgorithmschoices.splice(lastItem);
- };
-
- $scope.providerListener = function(ruleProvider) {
- if (ruleProvider!="Custom"){
- $scope.temp.policy.ruleAlgorithmschoices = [];
- $scope.temp.policy.settings = [];
- $scope.temp.policy.attributes = [];
- }
- };
-
- $scope.importButton = true;
- var fd;
+
+ $scope.importButton = true;
+ var fd;
$scope.uploadBLFile = function(files) {
fd = new FormData();
fd.append("file", files[0]);
var fileExtension = files[0].name.split(".")[1];
- if(fileExtension == "xls"){
+ if (fileExtension == "xls") {
$scope.importButton = false;
$scope.$apply();
- }else{
+ } else {
Notification.error("Upload the BlackList file which extends with .xls format.");
}
};
-
+
function arrayUnique(array) {
- var a = array.concat();
- for(var i=0; i<a.length; ++i) {
- for(var j=i+1; j<a.length; ++j) {
- if(a[i] === a[j])
- a.splice(j--, 1);
- }
- }
- return a;
+ var a = array.concat();
+ for (var i = 0; i < a.length; ++i) {
+ for (var j = i + 1; j < a.length; ++j) {
+ if (a[i] === a[j])
+ a.splice(j--, 1);
+ }
+ }
+ return a;
}
-
- $scope.submitUpload = function(){
- $http.post("policycreation/importBlackListForDecisionPolicy", fd, {
- withCredentials: false,
- headers: {'Content-Type': undefined},
- transformRequest: angular.identity
- }).success(function(data){
+
+ $scope.submitUpload = function() {
+ $http.post("policycreation/importBlackListForDecisionPolicy", fd, {
+ withCredentials : false,
+ headers : {
+ 'Content-Type' : undefined
+ },
+ transformRequest : angular.identity
+ }).success(function(data) {
$scope.data = JSON.parse(data.data);
$scope.temp.policy.blackListEntries = $scope.data.blackListEntries;
- if($scope.temp.policy.blackListEntries[0] !== "error"){
+ if ($scope.temp.policy.blackListEntries[0] !== "error") {
$scope.blackListEntries = arrayUnique($scope.temp.policy.blackListEntries.concat($scope.temp.policy.yamlparams.blackList));
$scope.temp.policy.appendBlackListEntries = $scope.data.appendBlackListEntries;
- $scope.blackListEntries = $scope.blackListEntries.filter(function (obj){
+ $scope.blackListEntries = $scope.blackListEntries.filter(function(obj) {
return !$scope.temp.policy.appendBlackListEntries.includes(obj);
});
- if($scope.blackListEntries.length == 0){
+ if ($scope.blackListEntries.length == 0) {
$scope.validateButton = true;
Notification.error("Black Lists are empty. Minimum one entry required.");
- }else{
+ } else {
$scope.temp.policy.blackListEntries = $scope.blackListEntries;
Notification.success("Blacklist File Uploaded Successfully.");
$scope.validateButton = false;
$scope.importButton = true;
}
- }else{
- Notification.error("Blacklist File Upload Failed." + $scope.temp.policy.blackListEntries[1]);
+ } else {
+ Notification.error("Blacklist File Upload Failed." + $scope.temp.policy.blackListEntries[1]);
}
- }).error(function(data){
- Notification.error("Blacklist File Upload Failed.");
+ }).error(function(data) {
+ Notification.error("Blacklist File Upload Failed.");
});
};
-
- $scope.initializeBlackList = function(){
- if($scope.temp.policy.blackListEntryType === "Use File Upload"){
- $scope.validateButton = true;
+
+ $scope.initializeBlackList = function() {
+ if ($scope.temp.policy.blackListEntryType === "Use File Upload") {
+ $scope.validateButton = true;
} else {
- $scope.validateButton = false;
+ $scope.validateButton = false;
}
$("#importFile").val('');
};
-
- $scope.exportBlackListEntries = function(){
+
+ $scope.exportBlackListEntries = function() {
var uuu = "policycreation/exportDecisionBlackListEntries";
- var postData={policyData: $scope.temp.policy, date : $scope.temp.model.modifiedDate, version : $scope.temp.model.version};
+ var postData = {
+ policyData : $scope.temp.policy,
+ date : $scope.temp.model.modifiedDate,
+ version : $scope.temp.model.version
+ };
$.ajax({
type : 'POST',
url : uuu,
- dataType: 'json',
- contentType: 'application/json',
- data: JSON.stringify(postData),
- success : function(data){
- $scope.$apply(function(){
- $scope.data=data.data;
+ dataType : 'json',
+ contentType : 'application/json',
+ data : JSON.stringify(postData),
+ success : function(data) {
+ $scope.$apply(function() {
+ $scope.data = data.data;
var url = '../' + $scope.data;
window.location = url;
Notification.success("BlackList Entries Exported Successfully.");
});
console.log($scope.data);
},
- error : function(data){
+ error : function(data) {
Notification.error("Error Occured while Exporting BlackList Entries.");
}
});
- };
-}]); \ No newline at end of file
+ };
+} ]); \ No newline at end of file
diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html
index 151af152d..f27d5c619 100644
--- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html
+++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplates/DecisionPolicyTemplate.html
@@ -28,14 +28,14 @@
ng-model="temp.policy.policyName" required pattern="\S+"
title="Enter Policy Name without any spaces and special characters and will accept _." />
</div>
- <div class="form-group col-sm-6">
+ <div ng-show="notRawPolicy" class="form-group col-sm-6">
<label>Description:</label> <input type="text" class="form-control"
ng-disabled="temp.policy.readOnly"
ng-model="temp.policy.policyDescription"
title="Description field will accept any type of data." />
</div>
</div>
- <div class="form-group row">
+ <div ng-show="notRawPolicy" class="form-group row">
<div class="form-group col-sm-6">
<label>Onap Name:<sup><b>*</b></sup></label> <select
class="form-control" ng-disabled="temp.policy.readOnly"
@@ -55,10 +55,23 @@
<option>Rainy_Day</option>
<option>GUARD_YAML</option>
<option>GUARD_BL_YAML</option>
+ <option>Raw</option>
</select>
</div>
</div>
</div>
+ <div ng-if="temp.policy.ruleProvider == 'Raw'">
+ <div class="well">
+ <div class="form-group row">
+ <div class="form-group col-sm-12">
+ <label>Raw Policy:<sup><b>*</b></sup></label>
+ <textarea class="form-control" ng-disabled="temp.policy.readOnly"
+ ng-model="temp.policy.rawXacmlPolicy" style="height: 400px;"
+ required title="Enter the Raw XACML Policy."></textarea>
+ </div>
+ </div>
+ </div>
+ </div>
<div ng-if="temp.policy.ruleProvider == 'Rainy_Day'">
<div class="well">
<div class="form-group row">