diff options
author | Gao, Chenfei (cg287m) <cgao@research.att.com> | 2018-02-06 12:42:50 -0500 |
---|---|---|
committer | Gao, Chenfei (cg287m) <cgao@research.att.com> | 2018-02-06 14:48:13 -0500 |
commit | cd417e811577a3efd26a57c3cad3a48d42d9e2d6 (patch) | |
tree | 3402444b5b17585db5d8e8f3bad5748168b272d3 /ONAP-XACML/src/main/java/org | |
parent | 549cafbb3b5b5c9298e8c7371835f5c58633349f (diff) |
Continue addressing technical debt for ONAP-XACML
Fix all sonar issues that do not require code refactoring
Issue-ID: POLICY-475
Change-Id: Iefa91e0048b7041c96d47bce7ec99034d6fcc427
Signed-off-by: Gao, Chenfei (cg287m) <cgao@research.att.com>
Diffstat (limited to 'ONAP-XACML/src/main/java/org')
14 files changed, 118 insertions, 153 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 3173bc16d..4399f715f 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -125,10 +125,10 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE if (Files.notExists(this.repository)) { Files.createDirectory(repository); } - if (Files.isDirectory(this.repository) == false) { + if (!Files.isDirectory(this.repository)) { throw new PAPException ("Repository is NOT a directory: " + this.repository.toAbsolutePath()); } - if (Files.isWritable(this.repository) == false) { + if (!Files.isWritable(this.repository)) { throw new PAPException ("Repository is NOT writable: " + this.repository.toAbsolutePath()); } // @@ -467,7 +467,7 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE this.doSave(); } else { PolicyLogger.error("Failed to add to new group, putting back into original group."); - if (((StdPDPGroup) currentGroup).removePDP(pdp) == false) { + if (!((StdPDPGroup) currentGroup).removePDP(pdp)) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Failed to put PDP back into original group."); } } @@ -492,8 +492,8 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE // the only things that the user can change are name and description currentPDP.setDescription(pdp.getDescription()); currentPDP.setName(pdp.getName()); - if (currentPDP instanceof OnapPDP && pdp instanceof OnapPDP) { - ((OnapPDP)currentPDP).setJmxPort(((OnapPDP)pdp).getJmxPort()); + if (currentPDP instanceof OnapPDP) { + ((OnapPDP)currentPDP).setJmxPort(pdp.getJmxPort()); } this.doSave(); } @@ -769,9 +769,7 @@ public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE // Save the configuration // this.saveConfiguration(); - } catch (IOException e) { - PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdEngine", "Failed to save configuration"); - } catch (PAPException e) { + } catch (IOException|PAPException e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdEngine", "Failed to save configuration"); } } diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngineFactory.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngineFactory.java index ee6785611..dd8a92135 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngineFactory.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngineFactory.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ public class StdEngineFactory extends ONAPPapEngineFactory { @Override public PAPPolicyEngine newEngine() throws FactoryException, PAPException { try { - return (PAPPolicyEngine) new StdEngine(); + return new StdEngine(); } catch (IOException e) { PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "StdEngineFactory", "Failed to create engine"); return null; @@ -47,7 +47,7 @@ public class StdEngineFactory extends ONAPPapEngineFactory { public PAPPolicyEngine newEngine(Properties properties) throws FactoryException, PAPException { try { - return (PAPPolicyEngine) new StdEngine(properties); + return new StdEngine(properties); } catch (IOException e) { PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "StdEngineFactory", "Failed to create engine"); return null; 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 c66d11b8c..a8c59e892 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 e059ea665..8727b8185 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -210,9 +210,6 @@ public class StdPDP extends StdPDPItemSetChangeNotifier implements OnapPDP, Comp if (o == null) { return -1; } - if ( ! (o instanceof StdPDP)) { - return -1; - } if (o.name == null) { return -1; } 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 9289c2461..bdbbf33f7 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -89,6 +89,21 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG @JsonIgnore private Integer jmxport; + public StdPDPGroup() { + // + // Methods needed for JSON deserialization + // + } + + public StdPDPGroup(OnapPDPGroup group) { + this.id = group.getId(); + this.name = group.getName(); + this.description = group.getDescription(); + this.isDefault = group.isDefaultGroup(); + this.pdps = group.getOnapPdps(); + this.policies = group.getPolicies(); + this.pipConfigs = group.getPipConfigs(); + } public StdPDPGroup(String id, Path directory) { this.id = id; @@ -333,7 +348,6 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG // to occur: 1) old default=false (don't want to fire) and // then 2) new default=true (yes fire - but we'll have to do that // elsewhere. - //this.firePDPGroupChanged(this); } @Override @@ -474,7 +488,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG logger.info("Copied " + num + " bytes for policy " + name); StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, isRoot, name, tempFile.toUri()); - if (tempRootPolicy.isValid() == false) { + if (!tempRootPolicy.isValid()) { try { Files.delete(tempFile); } catch(Exception ee) { @@ -544,7 +558,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG // policy is new to this group StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, true, name, policyFile.toUri()); - if (tempRootPolicy.isValid() == false) { + if (!tempRootPolicy.isValid()) { try { Files.delete(policyFile); } catch(Exception ee) { @@ -606,7 +620,7 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG // policy is new to this group StdPDPPolicy tempRootPolicy = new StdPDPPolicy(id, true, name, policyFile.toUri()); - if (tempRootPolicy.isValid() == false) { + if (!tempRootPolicy.isValid()) { try { Files.delete(policyFile); } catch(Exception ee) { @@ -924,23 +938,6 @@ public class StdPDPGroup extends StdPDPItemSetChangeNotifier implements OnapPDPG this.changed(); } - - public StdPDPGroup() { - // - // Methods needed for JSON deserialization - // - } - - public StdPDPGroup(OnapPDPGroup group) { - this.id = group.getId(); - this.name = group.getName(); - this.description = group.getDescription(); - this.isDefault = group.isDefaultGroup(); - this.pdps = group.getOnapPdps(); - this.policies = group.getPolicies(); - this.pipConfigs = group.getPipConfigs(); - } - public boolean isDefault() { return isDefault; } 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 ae4649e11..dd9bf0a2c 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,18 +71,30 @@ public class StdPDPGroupStatus implements PDPGroupStatus { public StdPDPGroupStatus(PDPGroupStatus stat) { this.status = stat.getStatus(); - this.failedPDPs.clear(); this.failedPDPs.addAll(stat.getFailedPDPs()); - this.failedPIPConfigs.clear(); this.failedPIPConfigs.addAll(stat.getFailedPipConfigs()); - this.failedPolicies.clear(); this.failedPolicies.addAll(stat.getFailedPolicies()); - this.inSynchPDPs.clear(); this.inSynchPDPs.addAll(stat.getInSynchPDPs()); - this.lastUpdateFailedPDPs.clear(); this.lastUpdateFailedPDPs.addAll(stat.getLastUpdateFailedPDPs()); - this.loadedPIPConfigs.clear(); this.loadedPIPConfigs.addAll(stat.getLoadedPipConfigs()); - this.loadedPolicies.clear(); this.loadedPolicies.addAll(stat.getLoadedPolicies()); - this.loadErrors.clear(); this.loadErrors.addAll(stat.getLoadErrors()); - this.loadWarnings.clear(); this.loadWarnings.addAll(stat.getLoadWarnings()); - this.outOfSynchPDPs.clear(); this.outOfSynchPDPs.addAll(stat.getOutOfSynchPDPs()); - this.unknownPDPs.clear(); this.unknownPDPs.addAll(stat.getUpdatingPDPs()); - this.updatingPDPs.clear(); this.updatingPDPs.addAll(stat.getUpdatingPDPs()); + this.failedPDPs.clear(); + this.failedPDPs.addAll(stat.getFailedPDPs()); + this.failedPIPConfigs.clear(); + this.failedPIPConfigs.addAll(stat.getFailedPipConfigs()); + this.failedPolicies.clear(); + this.failedPolicies.addAll(stat.getFailedPolicies()); + this.inSynchPDPs.clear(); + this.inSynchPDPs.addAll(stat.getInSynchPDPs()); + this.lastUpdateFailedPDPs.clear(); + this.lastUpdateFailedPDPs.addAll(stat.getLastUpdateFailedPDPs()); + this.loadedPIPConfigs.clear(); + this.loadedPIPConfigs.addAll(stat.getLoadedPipConfigs()); + this.loadedPolicies.clear(); + this.loadedPolicies.addAll(stat.getLoadedPolicies()); + this.loadErrors.clear(); + this.loadErrors.addAll(stat.getLoadErrors()); + this.loadWarnings.clear(); + this.loadWarnings.addAll(stat.getLoadWarnings()); + this.outOfSynchPDPs.clear(); + this.outOfSynchPDPs.addAll(stat.getOutOfSynchPDPs()); + this.unknownPDPs.clear(); + this.unknownPDPs.addAll(stat.getUpdatingPDPs()); + this.updatingPDPs.clear(); + this.updatingPDPs.addAll(stat.getUpdatingPDPs()); } public Set<PDPPIPConfig> getLoadedPIPConfigs() { @@ -286,16 +298,16 @@ public class StdPDPGroupStatus implements PDPGroupStatus { @Override @JsonIgnore public boolean isGroupOk() { - if (this.policiesOK() == false) { + if (!this.policiesOK()) { return false; } - if (this.pipConfigOK() == false) { + if (!this.pipConfigOK()) { return false; } - if (this.pdpsOK() == false) { + if (!this.pdpsOK()) { return false; } - if (this.loadErrors.isEmpty() == false) { + if (!this.loadErrors.isEmpty()) { return false; } return this.status == Status.OK; 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 0c832b30e..9a65d50b2 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 79e41f831..03170bdb7 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -64,7 +64,12 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { private URI location = null; - + public StdPDPPolicy() { + // + // Methods needed for JSON Deserialization + // + } + public StdPDPPolicy(String id, boolean isRoot) { this.id = id; this.isRoot = isRoot; @@ -173,7 +178,7 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { } if (this.policyId != null) { ArrayList<String> foo = Lists.newArrayList(Splitter.on(':').split(this.policyId)); - if (foo.isEmpty() == false) { + if (!foo.isEmpty()) { return foo.get(foo.size() - 1); } } @@ -337,14 +342,6 @@ public class StdPDPPolicy implements PDPPolicy, Serializable { return versionString; } - - - 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 6e1f2d62b..e42d54446 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 7c75e58d8..355a6f644 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -80,6 +80,10 @@ public class OperationHistoryEngine extends StdConfigurableEngine{ XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, new IdentifierImpl("target"), XACML.ID_DATATYPE_STRING); + + public OperationHistoryEngine() { + super(); + } private void addIntegerAttribute(StdMutablePIPResponse stdPIPResponse, Identifier category, Identifier attributeId, int value, PIPRequest pipRequest) { AttributeValue<BigInteger> attributeValue = null; @@ -93,10 +97,6 @@ public class OperationHistoryEngine extends StdConfigurableEngine{ } } - public OperationHistoryEngine() { - super(); - } - @Override public Collection<PIPRequest> attributesRequired() { return new ArrayList<>(); 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 de46d01f1..de35e0eb8 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 fd8b3c6c0..58f5a49e1 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,12 @@ package org.onap.policy.xacml.util; public class MetricsUtil { + private MetricsUtil() { + // + // private constructor to hide the implicit public one for utility class + // + } + public static class AvgLatency { private long cumLatency = 0; private long count = 0; 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 b8b19ec93..e24343704 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,7 +62,6 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeSelectorType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.IdReferenceType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionType; import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionsType; @@ -152,10 +151,8 @@ public class XACMLPolicyScanner { if (this.policyObject == null) { return null; } - if (this.callback != null) { - if (this.callback.onBeginScan(this.policyObject) == CallbackResult.STOP) { - return this.policyObject; - } + if (this.callback != null && this.callback.onBeginScan(this.policyObject) == CallbackResult.STOP) { + return this.policyObject; } if (this.policyObject instanceof PolicyType) { this.scanPolicy(null, (PolicyType) this.policyObject); @@ -186,10 +183,8 @@ public class XACMLPolicyScanner { if (logger.isTraceEnabled()) { logger.trace("scanning policy set: " + policySet.getPolicySetId() + " " + policySet.getDescription()); } - if (this.callback != null) { - if (this.callback.onPreVisitPolicySet(parent, policySet) == CallbackResult.STOP) { - return CallbackResult.STOP; - } + if (this.callback != null && this.callback.onPreVisitPolicySet(parent, policySet) == CallbackResult.STOP) { + return CallbackResult.STOP; } // // Scan its info @@ -208,28 +203,18 @@ public class XACMLPolicyScanner { // List<JAXBElement<?>> list = policySet.getPolicySetOrPolicyOrPolicySetIdReference(); for (JAXBElement<?> element: list) { - if ("PolicySet".equals(element.getName().getLocalPart())) { - if (this.scanPolicySet(policySet, (PolicySetType)element.getValue()) == CallbackResult.STOP) { - return CallbackResult.STOP; - } - } 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 ("PolicySetIdReference".equals(element.getName().getLocalPart())) { - - } else if ("PolicyIdReference".equals(element.getName().getLocalPart())) { - - } + if ("PolicySet".equals(element.getName().getLocalPart()) && + this.scanPolicySet(policySet, (PolicySetType)element.getValue()) == CallbackResult.STOP) { + return CallbackResult.STOP; + } else if ("Policy".equals(element.getName().getLocalPart()) && + this.scanPolicy(policySet, (PolicyType)element.getValue()) == CallbackResult.STOP) { + return CallbackResult.STOP; } else { logger.warn("generating policy sets found unsupported element: " + element.getName().getNamespaceURI()); } } - if (this.callback != null) { - if (this.callback.onPostVisitPolicySet(parent, policySet) == CallbackResult.STOP) { - return CallbackResult.STOP; - } + if (this.callback != null && this.callback.onPostVisitPolicySet(parent, policySet) == CallbackResult.STOP) { + return CallbackResult.STOP; } return CallbackResult.CONTINUE; } @@ -246,10 +231,8 @@ public class XACMLPolicyScanner { if (logger.isTraceEnabled()) { logger.trace("scanning policy: " + policy.getPolicyId() + " " + policy.getDescription()); } - if (this.callback != null) { - if (this.callback.onPreVisitPolicy(parent, policy) == CallbackResult.STOP) { - return CallbackResult.STOP; - } + if (this.callback != null && this.callback.onPreVisitPolicy(parent, policy) == CallbackResult.STOP) { + return CallbackResult.STOP; } // // Scan its info @@ -276,10 +259,8 @@ public class XACMLPolicyScanner { if (logger.isTraceEnabled()) { logger.trace("scanning rule: " + rule.getRuleId() + " " + rule.getDescription()); } - if (this.callback != null) { - if (this.callback.onPreVisitRule(policy, rule) == CallbackResult.STOP) { - return CallbackResult.STOP; - } + if (this.callback != null && this.callback.onPreVisitRule(policy, rule) == CallbackResult.STOP) { + return CallbackResult.STOP; } if (this.scanTarget(rule, rule.getTarget()) == CallbackResult.STOP) { return CallbackResult.STOP; @@ -293,16 +274,12 @@ public class XACMLPolicyScanner { if (this.scanAdvice(rule, rule.getAdviceExpressions()) == CallbackResult.STOP) { return CallbackResult.STOP; } - if (this.callback != null) { - if (this.callback.onPostVisitRule(policy, rule) == CallbackResult.STOP) { - return CallbackResult.STOP; - } + if (this.callback != null && this.callback.onPostVisitRule(policy, rule) == CallbackResult.STOP) { + return CallbackResult.STOP; } } else if (o instanceof VariableDefinitionType) { - if (this.callback != null) { - if (this.callback.onVariable(policy, (VariableDefinitionType) o) == CallbackResult.STOP) { - return CallbackResult.STOP; - } + if (this.callback != null && this.callback.onVariable(policy, (VariableDefinitionType) o) == CallbackResult.STOP) { + return CallbackResult.STOP; } } else { if (logger.isDebugEnabled()) { @@ -310,10 +287,8 @@ public class XACMLPolicyScanner { } } } - if (this.callback != null) { - if (this.callback.onPostVisitPolicy(parent, policy) == CallbackResult.STOP) { - return CallbackResult.STOP; - } + if (this.callback != null && this.callback.onPostVisitPolicy(parent, policy) == CallbackResult.STOP) { + return CallbackResult.STOP; } return CallbackResult.CONTINUE; } @@ -369,10 +344,8 @@ public class XACMLPolicyScanner { } else { logger.warn("NULL designator/selector or value for match."); } - if (attribute != null && this.callback != null) { - if (this.callback.onAttribute(parent, target, attribute) == CallbackResult.STOP) { - return CallbackResult.STOP; - } + if (attribute != null && this.callback != null && this.callback.onAttribute(parent, target, attribute) == CallbackResult.STOP) { + return CallbackResult.STOP; } } } @@ -417,10 +390,8 @@ public class XACMLPolicyScanner { ob.addAttributeAssignment(attribute); } } - if (this.callback != null) { - if (this.callback.onObligation(parent, expression, ob) == CallbackResult.STOP) { - return CallbackResult.STOP; - } + if (this.callback != null && this.callback.onObligation(parent, expression, ob) == CallbackResult.STOP) { + return CallbackResult.STOP; } } return CallbackResult.CONTINUE; @@ -460,10 +431,8 @@ public class XACMLPolicyScanner { ob.addAttributeAssignment(attribute); } } - if (this.callback != null) { - if (this.callback.onAdvice(parent, expression, ob) == CallbackResult.STOP) { - return CallbackResult.STOP; - } + if (this.callback != null && this.callback.onAdvice(parent, expression, ob) == CallbackResult.STOP) { + return CallbackResult.STOP; } } return CallbackResult.CONTINUE; @@ -481,12 +450,8 @@ public class XACMLPolicyScanner { return CallbackResult.CONTINUE; } for (Object o : list) { - if (o instanceof VariableDefinitionType) { - if (this.callback != null) { - if (this.callback.onVariable(policy, (VariableDefinitionType) o) == CallbackResult.STOP) { - return CallbackResult.STOP; - } - } + if (o instanceof VariableDefinitionType && this.callback != null && this.callback.onVariable(policy, (VariableDefinitionType) o) == CallbackResult.STOP) { + return CallbackResult.STOP; } } @@ -501,12 +466,8 @@ public class XACMLPolicyScanner { * @return */ protected CallbackResult scanConditions(RuleType rule, ConditionType condition) { - if (condition != null) { - if (this.callback != null) { - if (this.callback.onCondition(rule, condition) == CallbackResult.STOP) { - return CallbackResult.STOP; - } - } + if (condition != null && this.callback != null && this.callback.onCondition(rule, condition) == CallbackResult.STOP) { + return CallbackResult.STOP; } return CallbackResult.CONTINUE; } 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 0807f758b..cb3d44828 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP-XACML * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -144,10 +144,7 @@ public class XACMLPolicyWriter { Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(policyElement, byteArrayOutputStream); - ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); - - return byteArrayInputStream; - + return new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); } catch (JAXBException e) { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPolicyWriter", "writePolicyFile failed"); return null; |