X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcomponents%2FCreateBrmsParamPolicy.java;fp=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcomponents%2FCreateBrmsParamPolicy.java;h=ffb902bc4b2a49cecd8e0221e1f4c1b5c9942879;hp=c728f3bffac42a7f20f6f07f81590c425bdde311;hb=577b34e9bdad94d0b1559a9917af3283124aeeda;hpb=0c20d1c294fe146e1018f14b07a8d861c29fe527 diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java index c728f3bff..ffb902bc4 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java @@ -22,7 +22,7 @@ package org.onap.policy.pap.xacml.rest.components; import com.att.research.xacml.api.pap.PAPException; import com.att.research.xacml.std.IdentifierImpl; - +import com.google.common.annotations.VisibleForTesting; import java.io.File; import java.io.IOException; import java.io.PrintWriter; @@ -41,9 +41,7 @@ import java.util.Map.Entry; import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; - import javax.script.SimpleBindings; - import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType; @@ -57,7 +55,6 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObjectFactory; 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; - import org.apache.commons.io.FilenameUtils; import org.onap.policy.common.logging.eelf.MessageCodes; import org.onap.policy.common.logging.eelf.PolicyLogger; @@ -131,7 +128,7 @@ public class CreateBrmsParamPolicy extends Policy { out.close(); } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", - "Exception saving configuration file"); + "Exception saving configuration file"); } } @@ -148,6 +145,7 @@ public class CreateBrmsParamPolicy extends Policy { } // Validations for Config form + @Override public boolean validateConfigForm() { // Validating mandatory Fields. @@ -252,7 +250,7 @@ public class CreateBrmsParamPolicy extends Policy { } } String param = - params.toString().replace("declare Params", "").replace("end", "").replaceAll("\\s+", ""); + params.toString().replace("declare Params", "").replace("end", "").replaceAll("\\s+", ""); String[] components = param.split(":"); String caption = ""; for (int i = 0; i < components.length; i++) { @@ -283,7 +281,7 @@ public class CreateBrmsParamPolicy extends Policy { } } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CreateBrmsParamPolicy", - "Exception parsing file in findType"); + "Exception parsing file in findType"); } } return mapFieldType; @@ -327,7 +325,7 @@ public class CreateBrmsParamPolicy extends Policy { try { body.append("/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI " - + "purpose. \n\t " + "<$%BRMSParamTemplate=" + templateValue + "%$> \n"); + + "purpose. \n\t " + "<$%BRMSParamTemplate=" + templateValue + "%$> \n"); body.append("<%$Values="); for (Map.Entry entry : ruleAndUIValue.entrySet()) { String uiKey = entry.getKey(); @@ -339,7 +337,7 @@ public class CreateBrmsParamPolicy extends Policy { body.append(valueFromDictionary + "\n"); } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", - "Exception saving policy"); + "Exception saving policy"); } saveConfigurations(policyName, body.toString()); @@ -407,7 +405,7 @@ public class CreateBrmsParamPolicy extends Policy { accessURI = new URI(ACTION_ID); } catch (URISyntaxException e) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy", - "Exception creating ACCESS URI"); + "Exception creating ACCESS URI"); } accessAttributeDesignator.setCategory(CATEGORY_ACTION); accessAttributeDesignator.setDataType(STRING_DATATYPE); @@ -429,7 +427,7 @@ public class CreateBrmsParamPolicy extends Policy { configURI = new URI(RESOURCE_ID); } catch (URISyntaxException e) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy", - "Exception creating Config URI"); + "Exception creating Config URI"); } configAttributeDesignator.setCategory(CATEGORY_RESOURCE); @@ -461,7 +459,8 @@ public class CreateBrmsParamPolicy extends Policy { } // Data required for Advice part is setting here. - private AdviceExpressionsType getAdviceExpressions(int version, String fileName) { + @VisibleForTesting + protected AdviceExpressionsType getAdviceExpressions(int version, String fileName) { // Policy Config ID Assignment AdviceExpressionsType advices = new AdviceExpressionsType(); @@ -546,8 +545,8 @@ public class CreateBrmsParamPolicy extends Policy { // Adding Controller Information. if (policyAdapter.getBrmsController() != null) { BRMSDictionaryController brmsDicitonaryController = new BRMSDictionaryController(); - advice.getAttributeAssignmentExpression().add(createResponseAttributes( - "controller:" + policyAdapter.getBrmsController(), + advice.getAttributeAssignmentExpression() + .add(createResponseAttributes("controller:" + policyAdapter.getBrmsController(), brmsDicitonaryController.getControllerDataByID(policyAdapter.getBrmsController()).getController())); } @@ -561,14 +560,14 @@ public class CreateBrmsParamPolicy extends Policy { key.append(dependencyName + ","); } advice.getAttributeAssignmentExpression() - .add(createResponseAttributes("dependencies:" + key.toString(), dependencies.toString())); + .add(createResponseAttributes("dependencies:" + key.toString(), dependencies.toString())); } // Dynamic Field Config Attributes. Map dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes(); for (Entry map : dynamicFieldConfigAttributes.entrySet()) { advice.getAttributeAssignmentExpression() - .add(createResponseAttributes("key:" + map.getKey(), map.getValue())); + .add(createResponseAttributes("key:" + map.getKey(), map.getValue())); } // Risk Attributes