Code Review
/
policy
/
engine.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Fix all bugs reported by Sonar in policy/engine
[policy/engine.git]
/
ONAP-XACML
/
src
/
main
/
java
/
org
/
onap
/
policy
/
xacml
/
std
/
pap
/
StdEngine.java
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
d43a890
..
d3dc7ae
100644
(file)
--- 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
* ================================================================================
* ============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.
* ================================================================================
* 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.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());
}
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());
}
//
throw new PAPException ("Repository is NOT writable: " + this.repository.toAbsolutePath());
}
//
@@
-180,18
+180,8
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
// We don't have the default group, create it
//
String defaultId = properties.getProperty(PROP_PAP_GROUPS_DEFAULT, PROP_PAP_GROUPS_DEFAULT_NAME);
// We don't have the default group, create it
//
String defaultId = properties.getProperty(PROP_PAP_GROUPS_DEFAULT, PROP_PAP_GROUPS_DEFAULT_NAME);
- if(defaultId == null){
- defaultId = PROP_PAP_GROUPS_DEFAULT_NAME;
- }
- 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("".equals(defaultId)){
if("".equals(defaultId)){
-
defaultId = "default"
;
+
defaultId = PROP_PAP_GROUPS_DEFAULT_NAME
;
}
logger.warn("Default group does NOT exist, creating " + defaultId);
Path defaultPath = Paths.get(this.repository.toString(), defaultId);
}
logger.warn("Default group does NOT exist, creating " + defaultId);
Path defaultPath = Paths.get(this.repository.toString(), defaultId);
@@
-320,7
+310,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
// If it exists already
//
if (Files.exists(groupPath)) {
// If it exists already
//
if (Files.exists(groupPath)) {
- logger.warn(addGroup + id + " directory exists"
+ groupPath.toString()
);
+ logger.warn(addGroup + id + " directory exists");
} else {
try {
//
} else {
try {
//
@@
-338,7
+328,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
Path policyProperties = Paths.get(groupPath.toString(), "xacml.policy.properties");
if (Files.exists(policyProperties)) {
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
"
);
} else {
Properties props = new Properties();
props.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, "");
} else {
Properties props = new Properties();
props.setProperty(XACMLProperties.PROP_REFERENCEDPOLICIES, "");
@@
-349,7
+339,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
props.store(os, "");
}
} catch (IOException e) {
props.store(os, "");
}
} catch (IOException e) {
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "StdEngine", "Failed to create
" + policyProperties
);
+ PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "StdEngine", "Failed to create
policyProperties"
);
throw new PAPException("Failed to create " + id);
}
}
throw new PAPException("Failed to create " + id);
}
}
@@
-359,7
+349,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)) {
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
."
);
} else {
try {
props = setPIPProperties(props);
} else {
try {
props = setPIPProperties(props);
@@
-368,7
+358,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
props.store(os, "");
}
} catch (IOException e) {
props.store(os, "");
}
} catch (IOException e) {
- PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdEngine", "Failed to create
" + pipProperties
);
+ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "StdEngine", "Failed to create
pipProperties"
);
throw new PAPException("Failed to create " + id);
}
throw new PAPException("Failed to create " + id);
}
@@
-467,7
+457,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
this.doSave();
} else {
PolicyLogger.error("Failed to add to new group, putting back into original group.");
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.");
}
}
PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Failed to put PDP back into original group.");
}
}
@@
-492,8
+482,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());
// 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();
}
}
this.doSave();
}
@@
-625,16
+615,16
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
List<String> ids = new ArrayList<>();
for (PDPGroup group : this.groups) {
ids.add(group.getId());
List<String> ids = new ArrayList<>();
for (PDPGroup group : this.groups) {
ids.add(group.getId());
- properties.setProperty(group.getId() + ".name",
(group.getName() == null ? "" : group.getName()
));
- properties.setProperty(group.getId() + ".description",
(group.getDescription() == null ? "" : group.getDescription()
));
+ properties.setProperty(group.getId() + ".name",
group.getName() == null ? "" : group.getName(
));
+ properties.setProperty(group.getId() + ".description",
group.getDescription() == null ? "" : group.getDescription(
));
//
// Iterate its PDPs
//
List<String> pdps = new ArrayList<>();
for (PDP pdp : group.getPdps()) {
pdps.add(pdp.getId());
//
// Iterate its PDPs
//
List<String> pdps = new ArrayList<>();
for (PDP pdp : group.getPdps()) {
pdps.add(pdp.getId());
- properties.setProperty(pdp.getId() + ".name",
(pdp.getName() == null ? "" : pdp.getName()
));
- properties.setProperty(pdp.getId() + ".description",
(pdp.getDescription() == null ? "" : pdp.getDescription()
));
+ properties.setProperty(pdp.getId() + ".name",
pdp.getName() == null ? "" : pdp.getName(
));
+ properties.setProperty(pdp.getId() + ".description",
pdp.getDescription() == null ? "" : pdp.getDescription(
));
if (pdp instanceof OnapPDP) {
properties.setProperty(pdp.getId() + ".jmxport", (((OnapPDP)pdp).getJmxPort()==0 ? "" : ((OnapPDP)pdp).getJmxPort()).toString());
}
if (pdp instanceof OnapPDP) {
properties.setProperty(pdp.getId() + ".jmxport", (((OnapPDP)pdp).getJmxPort()==0 ? "" : ((OnapPDP)pdp).getJmxPort()).toString());
}
@@
-769,9
+759,7
@@
public class StdEngine extends StdPDPItemSetChangeNotifier implements PAPPolicyE
// Save the configuration
//
this.saveConfiguration();
// 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");
}
}
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "StdEngine", "Failed to save configuration");
}
}