X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fpolicy%2Fcomponents%2FHumanPolicyComponent.java;h=5b4fdeb0227a04b232c89e915e58e0abfedaa962;hb=685ed1545ed28b777a3ba6e7d315b78f355154cb;hp=f788fb67398f04753e47dbdc1f63be2a1874f920;hpb=87c95be02a8a4d77e165dede90777e811b59dcae;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java index f788fb673..5b4fdeb02 100644 --- a/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java +++ b/POLICY-SDK-APP/src/main/java/org/openecomp/policy/components/HumanPolicyComponent.java @@ -27,8 +27,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; -import java.nio.file.FileSystems; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -37,6 +37,23 @@ import java.util.Map; import javax.xml.bind.JAXBElement; +import org.apache.commons.io.FilenameUtils; +import org.json.JSONObject; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; +import org.openecomp.policy.controller.PolicyController; +import org.openecomp.policy.rest.jpa.FunctionDefinition; +import org.openecomp.policy.utils.XACMLPolicyWriterWithPapNotify; +import org.openecomp.policy.xacml.api.XACMLErrorConstants; +import org.openecomp.policy.xacml.util.XACMLPolicyScanner; + +import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.std.IdentifierImpl; +import com.att.research.xacml.std.StdAttribute; +import com.att.research.xacml.std.StdAttributeValue; +import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult; +import com.att.research.xacml.util.XACMLPolicyScanner.SimpleCallback; + 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; @@ -55,24 +72,6 @@ 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.VariableReferenceType; -import org.apache.commons.io.FilenameUtils; -import org.json.JSONObject; -import org.openecomp.policy.controller.PolicyController; -import org.openecomp.policy.rest.jpa.FunctionDefinition; -import org.openecomp.policy.utils.XACMLPolicyWriterWithPapNotify; - -import com.att.research.xacml.api.AttributeValue; -import org.openecomp.policy.xacml.api.XACMLErrorConstants; -import com.att.research.xacml.std.IdentifierImpl; -import com.att.research.xacml.std.StdAttribute; -import com.att.research.xacml.std.StdAttributeValue; -import org.openecomp.policy.xacml.util.XACMLPolicyScanner; -import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult; -import com.att.research.xacml.util.XACMLPolicyScanner.SimpleCallback; - -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; - public class HumanPolicyComponent{ @@ -103,6 +102,10 @@ public class HumanPolicyComponent{ private static File policyFile; + private HumanPolicyComponent(){ + //Default Constructor + } + public static JSONObject DescribePolicy(final File policyFile) { if (LOGGER.isTraceEnabled()) LOGGER.trace("ENTER"); @@ -143,7 +146,7 @@ public class HumanPolicyComponent{ HumanPolicyComponent.htmlProcessor = new HtmlProcessor(HumanPolicyComponent.policyFile, policy); - Path policyPath = FileSystems.getDefault().getPath(policyFile.getAbsolutePath()); + Path policyPath = Paths.get(policyFile.getAbsolutePath()); XACMLPolicyScanner xacmlScanner = new XACMLPolicyScanner(policyPath, htmlProcessor); xacmlScanner.scan(); String html = htmlProcessor.html(); @@ -298,7 +301,7 @@ class HtmlProcessor extends SimpleCallback { AttributeIdentifiers value = entry.getValue(); htmlOut.println(""); htmlOut.print("" + value.category + ""); - htmlOut.print("" + value.type + ""); + htmlOut.print("" + value.getType() + ""); htmlOut.print("" + value.id + ""); htmlOut.println(""); } @@ -654,7 +657,7 @@ class HtmlProcessor extends SimpleCallback { if (assignmentObject instanceof AttributeValueType) { AttributeValueType avt = (AttributeValueType) assignmentObject; if (attributeIdentifiers != null) { - attributeIdentifiers.type = avt.getDataType(); + attributeIdentifiers.setType(avt.getDataType()); } int numContent = avt.getContent().size(); int countContent = 0; @@ -730,35 +733,36 @@ class HtmlProcessor extends SimpleCallback { } String functionName = getHumanFunction(match.getMatchId()); - - String succintIdentifier = extractLastIdentifier(attribute.getCategory().stringValue(), ":") + - ":" + extractLastIdentifier(attribute.getAttributeId().stringValue(), ":"); - AttributeIdentifiers ai = new AttributeIdentifiers(attribute.getCategory().stringValue(), - attributeDataType, - attribute.getAttributeId().stringValue()); - this.attributeIdentifiersMap.put(succintIdentifier,ai); - - targetInHuman += "" + succintIdentifier + " " + functionName + " "; - - int numAttributes = attribute.getValues().size(); - int count = 0; - for (AttributeValue v: attribute.getValues()) { - count++; - if (v.getValue() instanceof Collection) { - Collection value_s = (Collection) v.getValue(); - int numValues = value_s.size(); - int countValues = 0; - for (Object o : value_s) { - countValues++; - targetInHuman += " " + o + ""; - if (countValues < numValues) { - targetInHuman += ", or"; + if(attribute != null){ + String succintIdentifier = extractLastIdentifier(attribute.getCategory().stringValue(), ":") + + ":" + extractLastIdentifier(attribute.getAttributeId().stringValue(), ":"); + AttributeIdentifiers ai = new AttributeIdentifiers(attribute.getCategory().stringValue(), + attributeDataType, + attribute.getAttributeId().stringValue()); + this.attributeIdentifiersMap.put(succintIdentifier,ai); + + targetInHuman += "" + succintIdentifier + " " + functionName + " "; + + int numAttributes = attribute.getValues().size(); + int count = 0; + for (AttributeValue v: attribute.getValues()) { + count++; + if (v.getValue() instanceof Collection) { + Collection value_s = (Collection) v.getValue(); + int numValues = value_s.size(); + int countValues = 0; + for (Object o : value_s) { + countValues++; + targetInHuman += " " + o + ""; + if (countValues < numValues) { + targetInHuman += ", or"; + } + } + } else { + targetInHuman += " " + v.getValue() + ""; + if (count < numAttributes) { + targetInHuman += ", or "; } - } - } else { - targetInHuman += " " + v.getValue() + ""; - if (count < numAttributes) { - targetInHuman += ", or "; } } } @@ -968,12 +972,20 @@ class HtmlProcessor extends SimpleCallback { class AttributeIdentifiers { public final String category; - public String type; + private String type; public final String id; public AttributeIdentifiers(String category, String type, String id) { this.category = category; - this.type = type; + this.setType(type); this.id = id; } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } }