X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=applications%2Fcommon%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpdp%2Fxacml%2Fapplication%2Fcommon%2Fstd%2FStdOnapPip.java;h=c511a9adbc4b1dc15bf8a8836b840d30ae78920b;hb=0ae998fcb08390a0d4a2dd2b98116be280c299d5;hp=70d4941848da5bf453f762f94938e90f26767082;hpb=fca3dd7b4bdc33b579750004c9d3bc163d20a2a7;p=policy%2Fxacml-pdp.git diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java index 70d49418..c511a9ad 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java @@ -22,6 +22,7 @@ package org.onap.policy.pdp.xacml.application.common.std; import com.att.research.xacml.api.Attribute; import com.att.research.xacml.api.AttributeValue; +import com.att.research.xacml.api.DataTypeException; import com.att.research.xacml.api.Identifier; import com.att.research.xacml.api.XACML3; import com.att.research.xacml.api.pip.PIPException; @@ -35,7 +36,6 @@ import com.att.research.xacml.std.pip.StdPIPRequest; import com.att.research.xacml.std.pip.engines.StdConfigurableEngine; import java.math.BigInteger; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Iterator; @@ -81,7 +81,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine { @Override public void configure(String id, Properties properties) throws PIPException { super.configure(id, properties); - logger.debug("Configuring historyDb PIP {}", properties); + logger.info("Configuring historyDb PIP {}", properties); this.properties = properties; } @@ -105,16 +105,12 @@ public abstract class StdOnapPip extends StdConfigurableEngine { try { pipResponse = pipFinder.getMatchingAttributes(pipRequest, this); if (pipResponse.getStatus() != null && !pipResponse.getStatus().isOk()) { - if (logger.isInfoEnabled()) { - logger.info("get attribute error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), - pipResponse.getStatus()); - } + logger.info("get attribute error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), + pipResponse.getStatus()); pipResponse = null; } if (pipResponse != null && pipResponse.getAttributes().isEmpty()) { - if (logger.isInfoEnabled()) { - logger.info("No value for {}", pipRequest.getAttributeId().stringValue()); - } + logger.info("No value for {}", pipRequest.getAttributeId().stringValue()); pipResponse = null; } } catch (PIPException ex) { @@ -126,12 +122,10 @@ public abstract class StdOnapPip extends StdConfigurableEngine { protected String findFirstAttributeValue(PIPResponse pipResponse) { for (Attribute attribute: pipResponse.getAttributes()) { Iterator> iterAttributeValues = attribute.findValues(DataTypes.DT_STRING); - if (iterAttributeValues != null) { - while (iterAttributeValues.hasNext()) { - String value = iterAttributeValues.next().getValue(); - if (value != null) { - return value; - } + while (iterAttributeValues.hasNext()) { + String value = iterAttributeValues.next().getValue(); + if (value != null) { + return value; } } } @@ -142,7 +136,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine { Identifier attributeId, int value, PIPRequest pipRequest) { AttributeValue attributeValue = null; try { - attributeValue = DataTypes.DT_INTEGER.createAttributeValue(value); + attributeValue = makeInteger(value); } catch (Exception e) { logger.error("Failed to convert {} to integer {}", value, e); } @@ -156,7 +150,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine { Identifier attributeId, long value, PIPRequest pipRequest) { AttributeValue attributeValue = null; try { - attributeValue = DataTypes.DT_INTEGER.createAttributeValue(value); + attributeValue = makeLong(value); } catch (Exception e) { logger.error("Failed to convert {} to long {}", value, e); } @@ -170,7 +164,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine { String value, PIPRequest pipRequest) { AttributeValue attributeValue = null; try { - attributeValue = DataTypes.DT_STRING.createAttributeValue(value); + attributeValue = makeString(value); } catch (Exception ex) { logger.error("Failed to convert {} to an AttributeValue", value, ex); } @@ -180,4 +174,18 @@ public abstract class StdOnapPip extends StdConfigurableEngine { } } + // these may be overridden by junit tests + + protected AttributeValue makeInteger(int value) throws DataTypeException { + return DataTypes.DT_INTEGER.createAttributeValue(value); + } + + protected AttributeValue makeLong(long value) throws DataTypeException { + return DataTypes.DT_INTEGER.createAttributeValue(value); + } + + protected AttributeValue makeString(String value) throws DataTypeException { + return DataTypes.DT_STRING.createAttributeValue(value); + } + }