diff options
Diffstat (limited to 'ONAP-XACML/src/main/java')
13 files changed, 137 insertions, 142 deletions
diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java index f046a3c45..d43a89000 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java @@ -66,8 +66,10 @@ import com.google.common.collect.Sets; */ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyEngine { public static final String pipPropertyFile = "pip.properties"; + + private static final String addGroup = "addGroup "; - private static Log logger = LogFactory.getLog(StdEngine.class); + private static Log logger = LogFactory.getLog(StdEngine.class); public static final String PROP_PAP_REPO = "xacml.pap.pdps"; public static final String PROP_PAP_GROUPS = "xacml.pap.groups"; @@ -181,14 +183,14 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE if(defaultId == null){ defaultId = PROP_PAP_GROUPS_DEFAULT_NAME; } - if(defaultId.equals("")){ + if("".equals(defaultId)){ defaultId = PROP_PAP_GROUPS_DEFAULT_NAME; } //we're going to check one more time in case the PROP_PAP_GROUPS_DEFAULT_NAME doesn't exist if(defaultId == null){ defaultId = "default"; } - if(defaultId.equals("")){ + if("".equals(defaultId)){ defaultId = "default"; } logger.warn("Default group does NOT exist, creating " + defaultId); @@ -318,7 +320,7 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE // If it exists already // if (Files.exists(groupPath)) { - logger.warn("addGroup " + id + " directory exists" + groupPath.toString()); + logger.warn(addGroup + id + " directory exists" + groupPath.toString()); } else { try { // @@ -336,7 +338,7 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE Path policyProperties = Paths.get(groupPath.toString(), "xacml.policy.properties"); if (Files.exists(policyProperties)) { - logger.warn("addGroup " + id + " file exists: " + policyProperties.toString()); + logger.warn(addGroup + id + " file exists: " + policyProperties.toString()); } else { Properties props = new Properties(); props.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, ""); @@ -357,7 +359,7 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE Path pipProperties = Paths.get(groupPath.toString(), "xacml.pip.properties"); Properties props = new Properties(); if (Files.exists(pipProperties)) { - logger.warn("addGroup " + id + " file exists: " + pipProperties.toString()); + logger.warn(addGroup + id + " file exists: " + pipProperties.toString()); } else { try { props = setPIPProperties(props); @@ -536,10 +538,13 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE throw new PAPException("Unknown PDP Group: " + group.getId()); } - // Currently not used on the PAP side. This is done by ((StdPDPGroup) group).copyPolicyToFile + @Override public void copyPolicy(PDPPolicy policy, OnapPDPGroup group) throws PAPException { + // + // Currently not used on the PAP side. This is done by ((StdPDPGroup) group).copyPolicyToFile + // } @@ -562,7 +567,7 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE // private Set<StdPDPGroup> readProperties(Path repository, Properties properties) throws PAPException { - Set<StdPDPGroup> groups = new HashSet<>(); + Set<StdPDPGroup> pdpGroups = new HashSet<>(); // // See if there is a groups property // @@ -589,15 +594,15 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE // // Add it in // - groups.add(g); + pdpGroups.add(g); } // // Dump what we got // if (logger.isDebugEnabled()) { - logger.debug("PDP Group List: " + groups.toString()); + logger.debug("PDP Group List: " + pdpGroups.toString()); } - return groups; + return pdpGroups; } private void saveConfiguration() throws PAPException, IOException { @@ -693,15 +698,17 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE inList = true; } } - if (inList == false) { + if (!inList) { Set<String> grps = Sets.newHashSet(groups); grps.add(group.getId()); - String newGroupList = "";; + String newGroupList; if (grps.size() == 1) { newGroupList = grps.iterator().next(); } else if (grps.size() > 1) { newGroupList = Joiner.on(',').skipNulls().join(grps); - } + } else { + newGroupList = ""; + } logger.info("New Group List: " + newGroupList); properties.setProperty(PROP_PAP_GROUPS, newGroupList); } @@ -713,7 +720,7 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE // // Set its PDP list // - if (group.getPdps().size() > 0) { + if (!group.getPdps().isEmpty()) { String pdpList = ""; if (group.getPdps().size() == 1) { pdpList = group.getPdps().iterator().next().getId(); @@ -785,7 +792,7 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE } catch (IOException e) { PolicyLogger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "can not load the pip properties from file" +e); } - props = prop; + props = prop; } return props; } @@ -849,7 +856,7 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE if (group == null) { throw new PAPException("You must specify which group the PDP will belong to."); } - if (this.groups.contains(group) == false) { + if (!this.groups.contains(group)) { throw new PAPException("Unknown group, not in our list."); } for (OnapPDP p : group.getOnapPdps()) { @@ -953,7 +960,7 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE // // Does this group exist? // - if (this.groups.contains(group) == false) { + if (!this.groups.contains(group)) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "This group doesn't exist."); throw new PAPException("The group '" + group.getId() + "' does not exist"); } @@ -967,13 +974,13 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE // // Are there PDPs? If so, then we need a target group // - if (pdps.isEmpty() == false && newGroup == null) { + if (!pdps.isEmpty() && newGroup == null) { throw new NullPointerException("Group targeted for deletion has PDPs, you must provide a new group for them."); } // // Move the PDPs // - if (pdps.isEmpty() == false) { + if (!pdps.isEmpty()) { if (! (newGroup instanceof StdPDPGroup)) { throw new PAPException("Unexpected class for newGroup: " + newGroup.getClass().getCanonicalName()); } diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java index 034c08bfa..21381c1a2 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java @@ -49,7 +49,7 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ private String policyID = null; private String ruleID = null; private String brmsController; - private ArrayList<String> brmsDependency; + private List<String> brmsDependency; private String configType = null; private Boolean editPolicy = false; private Boolean draft = false; @@ -83,7 +83,9 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ public StdPAPPolicy() { - + // + // Default empty constructor + // } //Constructor for sending location when pushing policies @@ -249,7 +251,7 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ public StdPAPPolicy (String configPolicyType, String policyName, String description, String configName, Boolean editPolicy, String domain, Map<String,String> dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, - String configBodyData, String riskLevel, String riskType, String guard, String ttlDate, String brmsController, ArrayList<String> brmsDependency) { + String configBodyData, String riskLevel, String riskType, String guard, String ttlDate, String brmsController, List<String> brmsDependency) { this.configPolicyType = configPolicyType; this.policyName = policyName; @@ -273,7 +275,7 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ public StdPAPPolicy (String configPolicyType, String policyName, String description, String configName, Boolean editPolicy, String domain, Map<String,String> dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, - String configBodyData,Map<String,String> drlRuleAndUIParams, String riskLevel, String riskType, String guard, String ttlDate, String brmsController, ArrayList<String> brmsDependency) { + String configBodyData,Map<String,String> drlRuleAndUIParams, String riskLevel, String riskType, String guard, String ttlDate, String brmsController, List<String> brmsDependency) { this.configPolicyType = configPolicyType; this.policyName = policyName; @@ -908,15 +910,15 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ this.brmsController = brmsController; } - public ArrayList<String> getBrmsDependency() { + public List<String> getBrmsDependency() { return brmsDependency; } - public void setBrmsDependency(ArrayList<String> brmsDependency) { + public void setBrmsDependency(List<String> brmsDependency) { this.brmsDependency = brmsDependency; } public void setTreatments(Map<String, String> treatments) { this.treatments = treatments; } -}
\ No newline at end of file +} diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDP.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDP.java index 4c1f4aadc..e059ea665 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDP.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDP.java @@ -52,7 +52,9 @@ public class StdPDP extends StdPDPItemSetChangeNotifier implements OnapPDP, Comp private transient Set<PDPPIPConfig> pipConfigs = new HashSet<>(); public StdPDP() { - + // + // Default constructor + // } public StdPDP(String id, Integer jmxport) { @@ -158,6 +160,8 @@ public class StdPDP extends StdPDPItemSetChangeNotifier implements OnapPDP, Comp public void setPipConfigs(Set<PDPPIPConfig> pipConfigs) { this.pipConfigs = pipConfigs; } + + @Override public void setJmxPort(Integer jmxport) { this.jmxport = jmxport; } @@ -209,13 +213,13 @@ public class StdPDP extends StdPDPItemSetChangeNotifier implements OnapPDP, Comp if ( ! (o instanceof StdPDP)) { return -1; } - if (((StdPDP)o).name == null) { + if (o.name == null) { return -1; } if (name == null) { return 1; } - return name.compareTo(((StdPDP)o).name); + return name.compareTo(o.name); } } diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroup.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroup.java index 9cdb4521d..745a43dca 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroup.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroup.java @@ -59,7 +59,9 @@ import com.google.common.base.Splitter; import com.google.common.io.ByteStreams; public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPGroup, StdItemSetChangeListener, Comparable<Object>, Serializable { + private static final long serialVersionUID = 1L; + private static final String groupNotExist= "Group directory does NOT exist"; private static Log logger = LogFactory.getLog(StdPDPGroup.class); private String id; @@ -137,8 +139,8 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } else if (key.toString().endsWith(".pdps")) { String pdpList = properties.getProperty(key.toString()); if (pdpList != null && pdpList.length() > 0) { - for (String id : Splitter.on(',').omitEmptyStrings().trimResults().split(pdpList)) { - StdPDP pdp = new StdPDP(id, properties); + for (String pdpId : Splitter.on(',').omitEmptyStrings().trimResults().split(pdpList)) { + StdPDP pdp = new StdPDP(pdpId, properties); pdp.addItemSetChangeListener(this); this.pdps.add(pdp); } @@ -157,10 +159,10 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG logger.warn("Group directory does NOT exist: " + directory.toString()); try { Files.createDirectory(directory); - this.status.addLoadWarning("Group directory does NOT exist"); + this.status.addLoadWarning(groupNotExist); } catch (IOException e) { - PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", "Group directory does NOT exist"); - this.status.addLoadError("Group directory does NOT exist"); + PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdPDPGroup", groupNotExist); + this.status.addLoadError(groupNotExist); this.status.setStatus(PDPGroupStatus.Status.LOAD_ERRORS); } } @@ -229,7 +231,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } //Even if we create a new pip file, we still need to parse and load the properties try{ - this.readPIPProperties(directory, pipProperties); + this.readPIPProperties(pipProperties); }catch(Exception e){ throw new PAPException("Failed to load the new pip properties file", e); } @@ -243,7 +245,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } // For all old PIP config's modify to the new PIP Configuration. // If PIP is empty add the new values and save it. - if(pipProperties.get(XACMLProperties.PROP_PIP_ENGINES).toString().trim().equals("")){ + if("".equals(pipProperties.get(XACMLProperties.PROP_PIP_ENGINES).toString().trim())){ pipProperties = setPIPProperties(pipProperties); try (OutputStream os = Files.newOutputStream(file)) { pipProperties.store(os, ""); @@ -252,7 +254,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG // // Parse the pips // - this.readPIPProperties(directory, pipProperties); + this.readPIPProperties(pipProperties); } catch (IOException e) { logger.warn("Failed to open group PIP Config properties file: " + file, e); this.status.addLoadError("Not PIP config properties defined"); @@ -264,20 +266,6 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } public void resetStatus() { -// // -// // If we are updating, don't allow reset -// // -// if (this.status.getStatus() == Status.UPDATING_CONFIGURATION) { -// logger.warn("We are updating, chill."); -// return; -// } -// // -// // Load errors take precedence -// // -// if (this.status.getStatus() == Status.LOAD_ERRORS) { -// logger.warn("We had load errors."); -// return; -// } // // Reset our status object // @@ -312,13 +300,13 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } // priority is worst-cast to best case - if (this.status.getUnknownPDPs().size() > 0) { + if (!this.status.getUnknownPDPs().isEmpty()) { this.status.setStatus(Status.UNKNOWN); - } else if (this.status.getFailedPDPs().size() > 0 || this.status.getLastUpdateFailedPDPs().size() > 0) { + } else if (!this.status.getFailedPDPs().isEmpty() || !this.status.getLastUpdateFailedPDPs().isEmpty()) { this.status.setStatus(Status.LOAD_ERRORS); - } else if (this.status.getOutOfSynchPDPs().size() > 0) { + } else if (!this.status.getOutOfSynchPDPs().isEmpty()) { this.status.setStatus(Status.OUT_OF_SYNCH); - } else if (this.status.getUpdatingPDPs().size() > 0) { + } else if (!this.status.getUpdatingPDPs().isEmpty()) { this.status.setStatus(Status.UPDATING_CONFIGURATION); } else { this.status.setStatus(Status.OK); @@ -404,6 +392,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG this.pdps = pdps; } + @Override public Set<OnapPDP> getOnapPdps(){ return Collections.unmodifiableSet(pdps); } @@ -430,7 +419,8 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } return null; } - + + @Override public Properties getPolicyProperties() { Properties properties = new Properties(){ @@ -442,9 +432,9 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG public synchronized Enumeration<Object> keys() { return Collections.enumeration(new TreeSet<Object>(super.keySet())); } - };; - List<String> roots = new ArrayList<String>(); - List<String> refs = new ArrayList<String>(); + }; + List<String> roots = new ArrayList<>(); + List<String> refs = new ArrayList<>(); for (PDPPolicy policy : this.policies) { // for all policies need to tell PDP the "name", which is the base name for the file id @@ -718,9 +708,10 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG this.firePDPGroupChanged(this); } + @Override public Properties getPipConfigProperties() { Properties properties = new Properties(); - List<String> configs = new ArrayList<String>(); + List<String> configs = new ArrayList<>(); for (PDPPIPConfig config : this.pipConfigs) { configs.add(config.getId()); @@ -820,11 +811,11 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG isRoot = false; continue; } - for (String id : policyList) { + for (String policyId : policyList) { // // Construct the policy filename // - Path policyPath = Paths.get(directory.toString(), id ); + Path policyPath = Paths.get(directory.toString(), policyId ); // // Create the Policy Object // @@ -854,13 +845,13 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } } - private void readPIPProperties(Path directory, Properties properties) { + private void readPIPProperties(Properties properties) { String list = properties.getProperty(XACMLProperties.PROP_PIP_ENGINES); if (list == null || list.length() == 0) { return; } - for (String id : list.split("[,]")) { - StdPDPPIPConfig config = new StdPDPPIPConfig(id, properties); + for (String pipId : list.split("[,]")) { + StdPDPPIPConfig config = new StdPDPPIPConfig(pipId, properties); if (config.isConfigured()) { this.pipConfigs.add(config); this.status.addLoadedPipConfig(config); @@ -935,11 +926,10 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG } - // - // Methods needed for JSON deserialization - // public StdPDPGroup() { - + // + // Methods needed for JSON deserialization + // } public StdPDPGroup(OnapPDPGroup group) { @@ -955,9 +945,9 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG public boolean isDefault() { return isDefault; } - public void setDefault(boolean isDefault) { - this.isDefault = isDefault; - } + public void setDefault(boolean isDefault) { + this.isDefault = isDefault; + } public void setStatus(PDPGroupStatus status) { this.status = new StdPDPGroupStatus(status); } diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroupStatus.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroupStatus.java index 296f738f4..ae4649e11 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroupStatus.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPGroupStatus.java @@ -58,9 +58,11 @@ public class StdPDPGroupStatus implements PDPGroupStatus { private Set<PDP> unknownPDPs = new HashSet<>(); - // Constructor needed for JSON deserialization + public StdPDPGroupStatus() { - + // + // Constructor needed for JSON deserialization + // } public StdPDPGroupStatus(Status status) { @@ -177,7 +179,7 @@ public class StdPDPGroupStatus implements PDPGroupStatus { @Override public boolean policiesOK() { - if (this.failedPolicies.size() > 0) { + if (!this.failedPolicies.isEmpty()) { return false; } return true; @@ -203,7 +205,7 @@ public class StdPDPGroupStatus implements PDPGroupStatus { @Override public boolean pipConfigOK() { - if (this.failedPIPConfigs.size() > 0) { + if (!this.failedPIPConfigs.isEmpty()) { return false; } return true; @@ -266,16 +268,16 @@ public class StdPDPGroupStatus implements PDPGroupStatus { @Override public boolean pdpsOK() { - if (this.outOfSynchPDPs.size() > 0) { + if (!this.outOfSynchPDPs.isEmpty()) { return false; } - if (this.failedPDPs.size() > 0) { + if (!this.failedPDPs.isEmpty()) { return false; } - if (this.lastUpdateFailedPDPs.size() > 0) { + if (!this.lastUpdateFailedPDPs.isEmpty()) { return false; } - if (this.unknownPDPs.size() > 0) { + if (!this.unknownPDPs.isEmpty()) { return false; } return true; @@ -296,7 +298,7 @@ public class StdPDPGroupStatus implements PDPGroupStatus { if (this.loadErrors.isEmpty() == false) { return false; } - return (this.status == Status.OK); + return this.status == Status.OK; } public void reset() { diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPPIPConfig.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPPIPConfig.java index f04384620..0c832b30e 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPPIPConfig.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPPIPConfig.java @@ -45,7 +45,9 @@ public class StdPDPPIPConfig implements PDPPIPConfig, Serializable { private Map<String,String> config = new HashMap<>(); public StdPDPPIPConfig() { - + // + // Default constructor + // } public StdPDPPIPConfig(String id) { diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPPolicy.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPPolicy.java index 892211a4c..79e41f831 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPPolicy.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPPolicy.java @@ -329,9 +329,9 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { } String versionString = ""; if (array.length > 0) { - versionString = "" + array[0]; + versionString = "" + Integer.toString(array[0]); for (int i = 1; i < array.length; i++) { - versionString += "." + array[i]; + versionString += "." + Integer.toString(array[i]); } } return versionString; @@ -339,10 +339,11 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { - // - // Methods needed for JSON Deserialization - // - public StdPDPPolicy() {} + public StdPDPPolicy() { + // + // Methods needed for JSON Deserialization + // + } public void setPolicyId(String policyId) { this.policyId = policyId; diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPStatus.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPStatus.java index 5349f8340..6e1f2d62b 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPStatus.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPDPStatus.java @@ -49,6 +49,9 @@ public class StdPDPStatus implements Serializable, PDPStatus { private transient Set<PDPPIPConfig> failedPIPConfigs = new HashSet<>(); public StdPDPStatus() { + // + // Default constructor + // } public void set(StdPDPStatus newStatus) { @@ -151,7 +154,7 @@ public class StdPDPStatus implements Serializable, PDPStatus { @Override public boolean policiesOK() { - if (this.failedPolicies.size() > 0) { + if (!this.failedPolicies.isEmpty()) { return false; } return true; @@ -185,7 +188,7 @@ public class StdPDPStatus implements Serializable, PDPStatus { @Override public boolean pipConfigOK() { - if (this.failedPIPConfigs.size() > 0) { + if (!this.failedPIPConfigs.isEmpty()) { return false; } return true; @@ -194,13 +197,13 @@ public class StdPDPStatus implements Serializable, PDPStatus { @Override @JsonIgnore public boolean isOk() { - if (this.policiesOK() == false) { + if (!this.policiesOK()) { return false; } - if (this.pipConfigOK() == false) { + if (!this.pipConfigOK()) { return false; } - return (this.status == Status.UP_TO_DATE); + return this.status == Status.UP_TO_DATE; } @Override diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pip/engines/OperationHistoryEngine.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pip/engines/OperationHistoryEngine.java index d393d7edb..7c75e58d8 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pip/engines/OperationHistoryEngine.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pip/engines/OperationHistoryEngine.java @@ -290,8 +290,8 @@ public class OperationHistoryEngine extends StdConfigurableEngine{ // Validating Time Units to prevent SQL Injection. private static boolean validTimeUnits(String timeUnits) { - return (timeUnits.equalsIgnoreCase("minute") || timeUnits.equalsIgnoreCase("hour") || timeUnits.equalsIgnoreCase("day") - || timeUnits.equalsIgnoreCase("week") || timeUnits.equalsIgnoreCase("month")||timeUnits.equalsIgnoreCase("year"))? + return ("minute".equalsIgnoreCase(timeUnits) || "hour".equalsIgnoreCase(timeUnits) || "day".equalsIgnoreCase(timeUnits) + || "week".equalsIgnoreCase(timeUnits) || "month".equalsIgnoreCase(timeUnits)|| "year".equalsIgnoreCase(timeUnits))? true: false; } } diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pip/engines/aaf/AAFEngine.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pip/engines/aaf/AAFEngine.java index ee75c5f8e..de46d01f1 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pip/engines/aaf/AAFEngine.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pip/engines/aaf/AAFEngine.java @@ -224,7 +224,7 @@ public class AAFEngine extends StdConfigurableEngine { /* * Drop the issuer and see if the request matches any of our supported queries */ - PIPRequest pipRequestSupported = (pipRequest.getIssuer() == null ? pipRequest : new StdPIPRequest(pipRequest.getCategory(), pipRequest.getAttributeId(), pipRequest.getDataTypeId())); + PIPRequest pipRequestSupported = pipRequest.getIssuer() == null ? pipRequest : new StdPIPRequest(pipRequest.getCategory(), pipRequest.getAttributeId(), pipRequest.getDataTypeId()); if (!mapSupportedAttributes.containsKey(pipRequestSupported)) { this.logger.debug("Requested attribute '" + pipRequest.toString() + "' is not supported"); return StdPIPResponse.PIP_RESPONSE_EMPTY; diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/MetricsUtil.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/MetricsUtil.java index 91e99b88b..fd8b3c6c0 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/MetricsUtil.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/MetricsUtil.java @@ -34,7 +34,7 @@ public class MetricsUtil { if (count == 0) return 0; - return (cumLatency / count); + return cumLatency / count; } public void reset() { diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyScanner.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyScanner.java index b43299e4e..b8b19ec93 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyScanner.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyScanner.java @@ -208,18 +208,18 @@ public class XACMLPolicyScanner { // List<JAXBElement<?>> list = policySet.getPolicySetOrPolicyOrPolicySetIdReference(); for (JAXBElement<?> element: list) { - if (element.getName().getLocalPart().equals("PolicySet")) { + if ("PolicySet".equals(element.getName().getLocalPart())) { if (this.scanPolicySet(policySet, (PolicySetType)element.getValue()) == CallbackResult.STOP) { return CallbackResult.STOP; } - } else if (element.getName().getLocalPart().equals("Policy")) { + } else if ("Policy".equals(element.getName().getLocalPart())) { if (this.scanPolicy(policySet, (PolicyType)element.getValue()) == CallbackResult.STOP) { return CallbackResult.STOP; } } else if (element.getValue() instanceof IdReferenceType) { - if (element.getName().getLocalPart().equals("PolicySetIdReference")) { + if ("PolicySetIdReference".equals(element.getName().getLocalPart())) { - } else if (element.getName().getLocalPart().equals("PolicyIdReference")) { + } else if ("PolicyIdReference".equals(element.getName().getLocalPart())) { } } else { @@ -395,7 +395,7 @@ public class XACMLPolicyScanner { return CallbackResult.CONTINUE; } List<ObligationExpressionType> expressions = obligationExpressionsType.getObligationExpression(); - if (expressions == null || expressions.size() == 0) { + if (expressions == null || expressions.isEmpty()) { return CallbackResult.CONTINUE; } for (ObligationExpressionType expression : expressions) { @@ -439,7 +439,7 @@ public class XACMLPolicyScanner { return CallbackResult.CONTINUE; } List<AdviceExpressionType> expressions = adviceExpressionstype.getAdviceExpression(); - if (expressions == null || expressions.size() == 0) { + if (expressions == null || expressions.isEmpty()) { return CallbackResult.CONTINUE; } for (AdviceExpressionType expression : expressions) { @@ -658,13 +658,12 @@ public class XACMLPolicyScanner { // NodeList nodes = doc.getChildNodes(); Node node = nodes.item(0); - Element e = null; if (node.getNodeType() == Node.ELEMENT_NODE) { - e = (Element) node; + Element e = (Element) node; // // Is it a 3.0 policy? // - if (e.getNamespaceURI().equals("urn:oasis:names:tc:xacml:3.0:core:schema:wd-17")) { + if ("urn:oasis:names:tc:xacml:3.0:core:schema:wd-17".equals(e.getNamespaceURI())) { // // A policyset or policy could be the root // diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyWriter.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyWriter.java index 14c8ffde0..5e60e3730 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyWriter.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/util/XACMLPolicyWriter.java @@ -173,16 +173,15 @@ public class XACMLPolicyWriter { @SuppressWarnings({ "unchecked", "rawtypes" }) public static String changeFileNameInXmlWhenRenamePolicy(Path filename) { - PolicyType policyType = null; String extension = ""; String domain = null; String repository = "repository"; if(filename.toString().contains("Config_")){ - domain = filename.toString().substring(filename.toString().indexOf(repository) + (repository.toString().length()+1), filename.toString().indexOf("Config_")); + domain = filename.toString().substring(filename.toString().indexOf(repository) + (repository.length()+1), filename.toString().indexOf("Config_")); }else if(filename.toString().contains("Action_")){ - domain = filename.toString().substring(filename.toString().indexOf(repository) + (repository.toString().length()+1), filename.toString().indexOf("Action_")); + domain = filename.toString().substring(filename.toString().indexOf(repository) + (repository.length()+1), filename.toString().indexOf("Action_")); }else if(filename.toString().contains("Decision_")){ - domain = filename.toString().substring(filename.toString().indexOf(repository) + (repository.toString().length()+1), filename.toString().indexOf("Decision_")); + domain = filename.toString().substring(filename.toString().indexOf(repository) + (repository.length()+1), filename.toString().indexOf("Decision_")); } if(domain.contains(File.separator)){ domain = domain.replace(File.separator, "."); @@ -191,7 +190,7 @@ public class XACMLPolicyWriter { JAXBContext context = JAXBContext.newInstance(PolicyType.class); Unmarshaller m = context.createUnmarshaller(); JAXBElement<PolicyType> policyElement = (JAXBElement<PolicyType>) m.unmarshal(filename.toFile()); - policyType = policyElement.getValue(); + PolicyType policyType = policyElement.getValue(); if (policyType != null) { TargetType targetType = policyType.getTarget(); List<AnyOfType> anyOfTypes = targetType.getAnyOf(); @@ -203,19 +202,10 @@ public class XACMLPolicyWriter { List<MatchType> match = allOfType.getMatch(); for( Iterator matchIte = match.iterator(); matchIte.hasNext();) { MatchType matchType = (MatchType) matchIte.next(); - if(matchType.getAttributeDesignator().getAttributeId().equals("PolicyName")){ + if("PolicyName".equals(matchType.getAttributeDesignator().getAttributeId())){ AttributeValueType attributeValueType = matchType.getAttributeValue(); List<Object> contents = attributeValueType.getContent(); - if (contents != null && contents.size() > 0) { - String value = (String) contents.get(0); - String version = value; - version = version.substring(0, version.lastIndexOf(".")); - version = version.substring(version.lastIndexOf(".")); - if(filename.toString().contains("Config_")){ - value = value.substring(0, value.indexOf("Config_")); - }else{ - value = value.substring(0, value.indexOf("Decision_")); - } + if (contents != null && !contents.isEmpty()) { String tmp = filename.getFileName()+""; String newName = tmp.substring(0, tmp.lastIndexOf(".")); attributeValueType.getContent().clear(); @@ -227,30 +217,30 @@ public class XACMLPolicyWriter { } if(filename.toString().contains("Config_") || filename.toString().contains("Action_")){ List<Object> objects = policyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); - if (objects != null && objects.size() > 0) { + if (objects != null && !objects.isEmpty()) { for (Iterator ite = objects.iterator(); ite.hasNext();) { RuleType ruleType = (RuleType ) ite.next(); AdviceExpressionsType adviceExpressionsType = ruleType.getAdviceExpressions(); if (adviceExpressionsType != null) { List<AdviceExpressionType> adviceExpressionTypes = adviceExpressionsType.getAdviceExpression(); - if (adviceExpressionTypes != null && adviceExpressionTypes.size() > 0) { + if (adviceExpressionTypes != null && !adviceExpressionTypes.isEmpty()) { for (Iterator iterator = adviceExpressionTypes .iterator(); iterator.hasNext();) { AdviceExpressionType adviceExpressionType = (AdviceExpressionType) iterator .next(); - if (adviceExpressionType.getAdviceId() != null && !adviceExpressionType.getAdviceId().equals("") && (adviceExpressionType.getAdviceId().equals("configID") - || adviceExpressionType.getAdviceId().equals("faultID") || adviceExpressionType.getAdviceId().equals("PMID")||adviceExpressionType.getAdviceId().equals("firewallConfigID") - || adviceExpressionType.getAdviceId().equals("MSID")) || adviceExpressionType.getAdviceId().equals("GocID")||adviceExpressionType.getAdviceId().equals("GocHPID")||adviceExpressionType.getAdviceId().equals("BRMSRAWID") - ||adviceExpressionType.getAdviceId().equals("BRMSPARAMID")|| adviceExpressionType.getAdviceId().equals("HPSuppID") || adviceExpressionType.getAdviceId().equals("HPFlapID") || adviceExpressionType.getAdviceId().equals("HPOverID")) + if (adviceExpressionType.getAdviceId() != null && !"".equals(adviceExpressionType.getAdviceId()) && ("configID".equals(adviceExpressionType.getAdviceId()) + || "faultID".equals(adviceExpressionType.getAdviceId()) || "PMID".equals(adviceExpressionType.getAdviceId())||"firewallConfigID".equals(adviceExpressionType.getAdviceId()) + || "MSID".equals(adviceExpressionType.getAdviceId())) || "GocID".equals(adviceExpressionType.getAdviceId())||"GocHPID".equals(adviceExpressionType.getAdviceId())||"BRMSRAWID".equals(adviceExpressionType.getAdviceId()) + || "BRMSPARAMID".equals(adviceExpressionType.getAdviceId())|| "HPSuppID".equals(adviceExpressionType.getAdviceId()) || "HPFlapID".equals(adviceExpressionType.getAdviceId()) || "HPOverID".equals(adviceExpressionType.getAdviceId())) { List<AttributeAssignmentExpressionType> attributeAssignmentExpressionTypes = adviceExpressionType.getAttributeAssignmentExpression(); - if (attributeAssignmentExpressionTypes != null && attributeAssignmentExpressionTypes.size() > 0) { + if (attributeAssignmentExpressionTypes != null && !attributeAssignmentExpressionTypes.isEmpty()) { for (Iterator iterator2 = attributeAssignmentExpressionTypes .iterator(); iterator2.hasNext();) { AttributeAssignmentExpressionType attributeAssignmentExpressionType = (AttributeAssignmentExpressionType) iterator2 .next(); - if (attributeAssignmentExpressionType.getAttributeId().equals("URLID")) { + if ("URLID".equals(attributeAssignmentExpressionType.getAttributeId())) { JAXBElement<AttributeValueType> attributeValueType = (JAXBElement<AttributeValueType>) attributeAssignmentExpressionType.getExpression(); AttributeValueType attributeValueType1 = attributeValueType.getValue(); String configUrl = "$URL"; @@ -266,12 +256,7 @@ public class XACMLPolicyWriter { JAXBElement<AttributeValueType> attributeValueType = (JAXBElement<AttributeValueType>) attributeAssignmentExpressionType.getExpression(); AttributeValueType attributeValueType1 = attributeValueType.getValue(); List<Object> contents = attributeValueType1.getContent(); - if (contents != null && contents.size() > 0) { - String value = (String) contents.get(0); - String version = value; - version = version.substring(0, version.lastIndexOf(".")); - version = version.substring(version.lastIndexOf(".")); - value = value.substring(0, value.indexOf("Config_")); + if (contents != null && !contents.isEmpty()) { String tmp = filename.getFileName()+""; String newName = tmp.substring(0, tmp.lastIndexOf(".")); attributeValueType1.getContent().clear(); @@ -287,26 +272,26 @@ public class XACMLPolicyWriter { } } } - if (objects != null && objects.size() > 0) { + if (objects != null && !objects.isEmpty()) { for (Iterator ite1 = objects.iterator(); ite1.hasNext();) { RuleType ruleType1 = (RuleType ) ite1.next(); ObligationExpressionsType obligationExpressionsType = ruleType1.getObligationExpressions(); if (obligationExpressionsType != null) { List<ObligationExpressionType> obligationExpressionType = obligationExpressionsType.getObligationExpression(); - if (obligationExpressionType != null && obligationExpressionType.size() > 0) { + if (obligationExpressionType != null && !obligationExpressionType.isEmpty()) { for (Iterator iterator = obligationExpressionType .iterator(); iterator.hasNext();) { ObligationExpressionType obligationExpressionTypes = (ObligationExpressionType) iterator .next(); - if (obligationExpressionTypes.getObligationId() != null && !obligationExpressionTypes.getObligationId().equals("")) { + if (obligationExpressionTypes.getObligationId() != null && !"".equals(obligationExpressionTypes.getObligationId())) { List<AttributeAssignmentExpressionType> attributeAssignmentExpressionTypes = obligationExpressionTypes.getAttributeAssignmentExpression(); - if (attributeAssignmentExpressionTypes != null && attributeAssignmentExpressionTypes.size() > 0) { + if (attributeAssignmentExpressionTypes != null && !attributeAssignmentExpressionTypes.isEmpty()) { for (Iterator iterator2 = attributeAssignmentExpressionTypes .iterator(); iterator2.hasNext();) { AttributeAssignmentExpressionType attributeAssignmentExpressionType = (AttributeAssignmentExpressionType) iterator2 .next(); - if (attributeAssignmentExpressionType.getAttributeId().equals("body")) { + if ("body".equals(attributeAssignmentExpressionType.getAttributeId())) { JAXBElement<AttributeValueType> attributeValueType = (JAXBElement<AttributeValueType>) attributeAssignmentExpressionType.getExpression(); AttributeValueType attributeValueType1 = attributeValueType.getValue(); String configUrl = "$URL"; |