X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fcomponents%2FHumanPolicyComponent.java;h=de1c551fc9602002e14e92d69bb770a3fed453ba;hb=cac5ee759fee5db51a32838c7e25b878468a27e0;hp=7c60ecfdf834c6509183e34ce80c184bc06f663c;hpb=42f82aadb12d017378ac9fa5cb11722191a548f0;p=policy%2Fengine.git
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java
index 7c60ecfdf..de1c551fc 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java
@@ -24,7 +24,6 @@ package org.onap.policy.components;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Path;
@@ -131,13 +130,11 @@ public class HumanPolicyComponent{
return null;
}
- private static String processPolicy() throws IllegalArgumentException {
- if (LOGGER.isTraceEnabled())
+ private static String processPolicy() {
+ if (LOGGER.isTraceEnabled()) {
LOGGER.trace("ENTER");
-
- FileInputStream pIS = null;
- try {
- pIS = new FileInputStream(policyFile);
+ }
+ try (FileInputStream pIS = new FileInputStream(policyFile)){
Object policy = XACMLPolicyScanner.readPolicy(pIS);
if (policy == null)
throw new IllegalArgumentException("Policy File " + policyFile.getName() +
@@ -160,14 +157,6 @@ public class HumanPolicyComponent{
": " + e.getMessage();
LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + msg, e);
throw new IllegalArgumentException(msg);
- } finally {
- if (pIS != null) {
- try {
- pIS.close();
- } catch (IOException e) {
- LOGGER.warn(e.getMessage(), e);
- }
- }
}
}
@@ -209,8 +198,7 @@ class HtmlProcessor extends SimpleCallback {
private final String policyName;
private final Object rootPolicyObject;
- public HtmlProcessor(File policyFile, Object policyObject)
- throws IllegalArgumentException {
+ public HtmlProcessor(File policyFile, Object policyObject) {
if (LOGGER.isTraceEnabled())
LOGGER.trace("ENTER");
@@ -409,7 +397,7 @@ class HtmlProcessor extends SimpleCallback {
if (policySet.getTarget() == null ||
policySet.getTarget().getAnyOf() == null ||
- policySet.getTarget().getAnyOf().size() <= 0) {
+ policySet.getTarget().getAnyOf().isEmpty()) {
htmlOut.println("
This policy set applies to all requests.
");
} else {
htmlOut.print("");
@@ -494,7 +482,7 @@ class HtmlProcessor extends SimpleCallback {
if (policy.getTarget() == null ||
policy.getTarget().getAnyOf() == null ||
- policy.getTarget().getAnyOf().size() <= 0) {
+ policy.getTarget().getAnyOf().isEmpty()) {
htmlOut.println("
This policy applies to all requests.
");
} else {
htmlOut.print("");
@@ -566,7 +554,7 @@ class HtmlProcessor extends SimpleCallback {
if (rule.getTarget() == null ||
rule.getTarget().getAnyOf() == null ||
- rule.getTarget().getAnyOf().size() <= 0) {
+ rule.getTarget().getAnyOf().isEmpty()) {
htmlOut.print(" for all requests");
} else {
List anyOf_s = rule.getTarget().getAnyOf();
@@ -690,7 +678,7 @@ class HtmlProcessor extends SimpleCallback {
if (anyOfList != null) {
Iterator iterAnyOf = anyOfList.iterator();
- String targetInHuman = "";
+ StringBuilder targetInHuman = new StringBuilder();
while (iterAnyOf.hasNext()) {
AnyOfType anyOf = iterAnyOf.next();
List allOfList = anyOf.getAllOf();
@@ -702,7 +690,7 @@ class HtmlProcessor extends SimpleCallback {
if (matchList != null) {
Iterator iterMatch = matchList.iterator();
if (matchList.size() > 1)
- targetInHuman += "(";
+ targetInHuman.append("(");
while (iterMatch.hasNext()) {
MatchType match = iterMatch.next();
//
@@ -741,7 +729,7 @@ class HtmlProcessor extends SimpleCallback {
attribute.getAttributeId().stringValue());
this.attributeIdentifiersMap.put(succintIdentifier,ai);
- targetInHuman += "" + succintIdentifier + " " + functionName + " ";
+ targetInHuman.append("" + succintIdentifier + " " + functionName + " ");
int numAttributes = attribute.getValues().size();
int count = 0;
@@ -753,38 +741,39 @@ class HtmlProcessor extends SimpleCallback {
int countValues = 0;
for (Object o : value_s) {
countValues++;
- targetInHuman += " " + o + "";
+ targetInHuman.append(" " + o + "");
if (countValues < numValues) {
- targetInHuman += ", or";
+ targetInHuman.append(", or");
}
}
} else {
- targetInHuman += " " + v.getValue() + "";
+ targetInHuman.append(" " + v.getValue() + "");
if (count < numAttributes) {
- targetInHuman += ", or ";
+ targetInHuman.append(", or ");
}
}
}
}
if (iterMatch.hasNext()) {
- targetInHuman += " and ";
+ targetInHuman.append(" and ");
}
} // end iterMatch
if (matchList.size() > 1) {
- targetInHuman += ")";
+ targetInHuman.append(")");
}
}
if (iterAllOf.hasNext()) {
- targetInHuman += " or ";
+ targetInHuman.append(" or ");
}
} // end iterAllOf
}
if (iterAnyOf.hasNext()) {
- targetInHuman = "(" + targetInHuman + ")" + " or ";
+ targetInHuman = new StringBuilder();
+ targetInHuman.append("(" + targetInHuman + ")" + " or ");
} else {
if (anyOfList.size() > 1) {
- targetInHuman += ")";
+ targetInHuman.append(")");
}
}
} // end iterAnyOf
@@ -855,21 +844,20 @@ class HtmlProcessor extends SimpleCallback {
}
List> exps = apply.getExpression();
- if (exps == null || exps.size() == 0)
+ if (exps == null || exps.isEmpty())
return "";
else {
- String forResult = "";
+ StringBuilder forResult = new StringBuilder();
for (JAXBElement> e : exps) {
Object v = e.getValue();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("one-and-only children: " + v);
}
if (v != null) {
- // C: return stringifyExpression(v, result);
- forResult += stringifyExpression(v);
+ forResult.append(stringifyExpression(v));
}
}
- return forResult;
+ return forResult.toString();
}
}
@@ -884,20 +872,20 @@ class HtmlProcessor extends SimpleCallback {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(functionName + " 1 expression: " + numExpr);
}
- String applySubresult = "";
+ StringBuilder applySubresult = new StringBuilder();
for (JAXBElement> e : apply.getExpression()) {
Object v = e.getValue();
if (v != null) {
- applySubresult += this.stringifyExpression(e.getValue());
+ applySubresult.append(this.stringifyExpression(e.getValue()));
}
}
- return " " + removePrimitives(functionName) + " (" + applySubresult + ")";
+ return " " + removePrimitives(functionName) + " (" + applySubresult.toString() + ")";
} else {
// > 1 arguments
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(functionName + " > 1 expressions: " + numExpr);
}
- String applySubresult = "";
+ StringBuilder applySubresult = new StringBuilder();
int exprCount = 0;
for (JAXBElement> e : apply.getExpression()) {
exprCount++;
@@ -905,20 +893,20 @@ class HtmlProcessor extends SimpleCallback {
if (ev != null) {
if (ev instanceof ApplyType) {
if (((ApplyType) ev).getFunctionId().contains("one-and-only")) {
- applySubresult += this.stringifyExpression(e.getValue());
+ applySubresult.append(this.stringifyExpression(e.getValue()));
} else {
- applySubresult += "(" + this.stringifyExpression(e.getValue()) + ")";
+ applySubresult.append("(" + this.stringifyExpression(e.getValue()) + ")");
}
} else {
- applySubresult += this.stringifyExpression(e.getValue());
+ applySubresult.append(this.stringifyExpression(e.getValue()));
}
if (exprCount < numExpr) {
- applySubresult += " " + removePrimitives(functionName) + " ";
+ applySubresult.append(" " + removePrimitives(functionName) + " ");
}
}
}
- return applySubresult;
+ return applySubresult.toString();
}
}
if (expression instanceof AttributeDesignatorType) {
@@ -953,11 +941,11 @@ class HtmlProcessor extends SimpleCallback {
if (expression instanceof AttributeValueType) {
AttributeValueType avt = (AttributeValueType) expression;
List