aboutsummaryrefslogtreecommitdiffstats
path: root/PolicyEngineAPI/src/main
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2018-02-01 12:22:30 -0500
committerPamela Dragosh <pdragosh@research.att.com>2018-02-01 12:37:59 -0500
commit06f456d8d06840a21f48531b0bd35b1a429b10f9 (patch)
treea72db2dbec1a520589e98809d03424cf81c6aab1 /PolicyEngineAPI/src/main
parent066fc4529f36d210a4a4700e8dbfd2cb42f4dc66 (diff)
Reduce technical debt and add JUnit
* Addressed some very simple cyclic complexity * Added simple JUnit tests and finished others * Removed useless assignments Issue-ID: POLICY-477 Change-Id: Ic919bbf78ad2732a430c32f1feb3c88678be710d Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
Diffstat (limited to 'PolicyEngineAPI/src/main')
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/api/DecisionRequestParameters.java1
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/api/EventRequestParameters.java1
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfigException.java1
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyDecisionException.java1
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEventException.java1
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyException.java1
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyParameters.java6
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/api/PushPolicyParameters.java1
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java9
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientDMAAP.java102
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientEnd.java152
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientUEB.java74
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndDMAAP.java45
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java45
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/MatchStore.java14
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java53
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyConfig.java2
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java302
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java8
19 files changed, 432 insertions, 387 deletions
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/DecisionRequestParameters.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/DecisionRequestParameters.java
index 5cf9d641d..2163bf555 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/DecisionRequestParameters.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/DecisionRequestParameters.java
@@ -38,6 +38,7 @@ public class DecisionRequestParameters {
* Constructor with no Parameters
*/
public DecisionRequestParameters(){
+ // Empty constructor
}
/**
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/EventRequestParameters.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/EventRequestParameters.java
index 6e4bbbd51..c3aa50378 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/EventRequestParameters.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/EventRequestParameters.java
@@ -37,6 +37,7 @@ public class EventRequestParameters {
* Constructor with no Parameters
*/
public EventRequestParameters(){
+ // Empty constructor
}
/**
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfigException.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfigException.java
index b42d8b280..5d370da08 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfigException.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfigException.java
@@ -29,6 +29,7 @@ public class PolicyConfigException extends Exception{
private static final long serialVersionUID = -188355220060684215L;
public PolicyConfigException() {
+ // Empty constructor
}
public PolicyConfigException(String message) {
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyDecisionException.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyDecisionException.java
index 38081de7e..c705566ad 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyDecisionException.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyDecisionException.java
@@ -30,6 +30,7 @@ public class PolicyDecisionException extends Exception {
private static final long serialVersionUID = -2080072039363261175L;
public PolicyDecisionException() {
+ // Empty constructor
}
public PolicyDecisionException(String message) {
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEventException.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEventException.java
index 335c4905b..e9d9852d1 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEventException.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyEventException.java
@@ -29,6 +29,7 @@ public class PolicyEventException extends Exception {
private static final long serialVersionUID = -1477625011320634608L;
public PolicyEventException() {
+ // Empty constructor
}
public PolicyEventException(String message) {
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyException.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyException.java
index 5d8555d38..cee1342ff 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyException.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyException.java
@@ -29,6 +29,7 @@ public class PolicyException extends Exception {
private static final long serialVersionUID = -5006203722296799708L;
public PolicyException() {
+ // Empty constructor
}
public PolicyException(String message) {
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyParameters.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyParameters.java
index ae9ba8a88..cb51e481d 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyParameters.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyParameters.java
@@ -53,7 +53,7 @@ public class PolicyParameters {
private String priority;
private RuleProvider ruleProvider;
private String controllerName;
- private ArrayList<String> dependencyNames;
+ private List<String> dependencyNames;
private Date ttlDate;
private boolean guard = false;
private String riskLevel = "5";
@@ -548,7 +548,7 @@ public class PolicyParameters {
*
* @return ArrayList of String(s) format of dependency names.
*/
- public ArrayList<String> getDependencyNames() {
+ public List<String> getDependencyNames() {
return dependencyNames;
}
@@ -557,7 +557,7 @@ public class PolicyParameters {
*
* @param dependencyNames ArrayList of String(s).
*/
- public void setDependencyNames(ArrayList<String> dependencyNames) {
+ public void setDependencyNames(List<String> dependencyNames) {
this.dependencyNames = dependencyNames;
}
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PushPolicyParameters.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PushPolicyParameters.java
index 211be7e65..a55cd6ed3 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PushPolicyParameters.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PushPolicyParameters.java
@@ -38,6 +38,7 @@ public class PushPolicyParameters {
* Constructor with no Parameters.
*/
public PushPolicyParameters(){
+ // Empty constructor
}
/**
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java b/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java
index be363c24f..e65413f50 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java
@@ -36,48 +36,57 @@ public class APIPolicyConfigResponse implements APIConfigResponse {
private Map<String, String> matchingConditions;
private Map<String, String> responseAttributes;
private Map<String, String> property;
+
+ @Override
public String getConfig() {
return config;
}
public void setConfig(String config) {
this.config = config;
}
+ @Override
public PolicyType getType() {
return type;
}
public void setType(PolicyType type) {
this.type = type;
}
+ @Override
public PolicyConfigStatus getPolicyConfigStatus() {
return policyConfigStatus;
}
public void setPolicyConfigStatus(PolicyConfigStatus policyConfigStatus) {
this.policyConfigStatus = policyConfigStatus;
}
+ @Override
public String getPolicyConfigMessage() {
return policyConfigMessage;
}
public void setPolicyConfigMessage(String policyConfigMessage) {
this.policyConfigMessage = policyConfigMessage;
}
+ @Override
public Map<String, String> getProperty() {
return property;
}
public void setProperty(Map<String, String> property) {
this.property = property;
}
+ @Override
public String getPolicyName(){
return policyName;
}
public void setPolicyName(String policyName){
this.policyName = policyName;
}
+ @Override
public String getPolicyVersion(){
return policyVersion;
}
public void setPolicyVersion(String policyVersion){
this.policyVersion = policyVersion;
}
+ @Override
public Map<String, String> getMatchingConditions(){
return matchingConditions;
}
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientDMAAP.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientDMAAP.java
index 97f60b0dc..2fa408810 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientDMAAP.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientDMAAP.java
@@ -90,36 +90,36 @@ public class AutoClientDMAAP implements Runnable {
}
String group = UUID.randomUUID().toString();
String id = "0";
+
+ if (scheme == null || handler == null ||
+ ! (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) ||
+ scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) ) {
+ logger.info("no stop/start required");
+ return;
+ }
- // Stop and Start needs to be done.
- if (scheme != null && handler != null) {
- if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)
- || scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) {
-
- // create a loop to listen for messages from DMaaP server
- try {
- setDmaapCosumer(new BusConsumer.DmaapConsumerWrapper(dmaapList, topic, aafLogin, aafPassword, group,
- id, 15 * 1000, 1000));
- } catch (Exception e) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to create DMaaP Consumer: ", e);
- }
-
- while (this.isRunning()) {
- try {
- for (String msg : dmaapConsumer.fetch()) {
- logger.debug("Auto Notification Recieved Message " + msg + " from DMAAP server : "
- + dmaapList.toString());
- setNotification(NotificationUnMarshal.notificationJSON(msg));
- callHandler();
- }
- } catch (Exception e) {
- logger.debug("Error in processing DMAAP message", e);
- }
+ // create a loop to listen for messages from DMaaP server
+ try {
+ setDmaapCosumer(new BusConsumer.DmaapConsumerWrapper(dmaapList, topic, aafLogin, aafPassword, group,
+ id, 15 * 1000, 1000));
+ } catch (Exception e) {
+ logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to create DMaaP Consumer: ", e);
+ }
+ while (this.isRunning()) {
+ try {
+ for (String msg : dmaapConsumer.fetch()) {
+ logger.debug("Auto Notification Recieved Message " + msg + " from DMAAP server : "
+ + dmaapList.toString());
+ setNotification(NotificationUnMarshal.notificationJSON(msg));
+ callHandler();
}
- logger.debug("Stopping DMAAP Consumer loop will no longer fetch messages from the servers");
+ } catch (Exception e) {
+ logger.debug("Error in processing DMAAP message", e);
}
+
}
+ logger.debug("Stopping DMAAP Consumer loop will no longer fetch messages from the servers");
}
private static void setNotification(StdPDPNotification notificationJSON) {
@@ -131,30 +131,34 @@ public class AutoClientDMAAP implements Runnable {
}
private static void callHandler() {
- if (handler != null && scheme != null) {
- if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)) {
- boolean removed = false, updated = false;
- if (notification.getRemovedPolicies() != null && !notification.getRemovedPolicies().isEmpty()) {
- removed = true;
- }
- if (notification.getLoadedPolicies() != null && !notification.getLoadedPolicies().isEmpty()) {
- updated = true;
- }
- if (removed && updated) {
- notification.setNotificationType(NotificationType.BOTH);
- } else if (removed) {
- notification.setNotificationType(NotificationType.REMOVE);
- } else if (updated) {
- notification.setNotificationType(NotificationType.UPDATE);
- }
- handler.notificationReceived(notification);
- } else if (scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) {
- PDPNotification newNotification = MatchStore.checkMatch(notification);
- if (newNotification.getNotificationType() != null) {
- handler.notificationReceived(newNotification);
- }
- }
- }
+
+ if (handler == null || scheme == null) {
+ logger.info("handler does not need to do anything");
+ return;
+ }
+ if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)) {
+ boolean removed = false;
+ boolean updated = false;
+ if (notification.getRemovedPolicies() != null && !notification.getRemovedPolicies().isEmpty()) {
+ removed = true;
+ }
+ if (notification.getLoadedPolicies() != null && !notification.getLoadedPolicies().isEmpty()) {
+ updated = true;
+ }
+ if (removed && updated) {
+ notification.setNotificationType(NotificationType.BOTH);
+ } else if (removed) {
+ notification.setNotificationType(NotificationType.REMOVE);
+ } else if (updated) {
+ notification.setNotificationType(NotificationType.UPDATE);
+ }
+ handler.notificationReceived(notification);
+ } else if (scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) {
+ PDPNotification newNotification = MatchStore.checkMatch(notification);
+ if (newNotification.getNotificationType() != null) {
+ handler.notificationReceived(newNotification);
+ }
+ }
}
}
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientEnd.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientEnd.java
index f0d99d09e..ec021a43e 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientEnd.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientEnd.java
@@ -56,6 +56,10 @@ public class AutoClientEnd {
private static boolean error = false;
private static Logger logger = FlexLogger.getLogger(AutoClientEnd.class.getName());
+ private AutoClientEnd() {
+ // Empty constructor
+ }
+
public static void setAuto(NotificationScheme scheme,
NotificationHandler handler) {
AutoClientEnd.scheme = scheme;
@@ -76,40 +80,42 @@ public class AutoClientEnd {
public static void start(String url) {
AutoClientEnd.url = url;
+
+ if (scheme == null || handler == null ||
+ ! (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) &&
+ scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS) ) ||
+ AutoClientEnd.client == null) {
+ return;
+ }
+
// Stop and Start needs to be done.
- if (scheme != null && handler!=null) {
- if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) || scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) {
- if (AutoClientEnd.client == null) {
- client = ClientManager.createClient();
- if(url.contains("https")){
- url = url.replaceAll("https", "wss");
- }else {
- url = url.replaceAll("http", "ws");
- }
- try {
- logger.info("Starting Auto Notification with the PDP server : " + url);
- client.connectToServer(AutoClientEnd.class, new URI(url + "notifications"));
- status = true;
- if(error){
- // The URL's will be in Sync according to design Spec.
- ManualClientEnd.start(AutoClientEnd.url);
- StdPDPNotification notification = NotificationStore.getDeltaNotification((StdPDPNotification)ManualClientEnd.result(NotificationScheme.MANUAL_ALL_NOTIFICATIONS));
- if(notification.getNotificationType()!=null&&oldNotification!=notification){
- oldNotification= notification;
- AutoClientEnd.notification = notification;
- callHandler();
- }
- error = false;
- }
- //
- } catch (DeploymentException | IOException | URISyntaxException e) {
- logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
- client = null;
- status = false;
- changeURL();
- }
+ client = ClientManager.createClient();
+ if(url.contains("https")){
+ url = url.replaceAll("https", "wss");
+ }else {
+ url = url.replaceAll("http", "ws");
+ }
+ try {
+ logger.info("Starting Auto Notification with the PDP server : " + url);
+ client.connectToServer(AutoClientEnd.class, new URI(url + "notifications"));
+ status = true;
+ if(error){
+ // The URL's will be in Sync according to design Spec.
+ ManualClientEnd.start(AutoClientEnd.url);
+ StdPDPNotification notification = NotificationStore.getDeltaNotification((StdPDPNotification)ManualClientEnd.result(NotificationScheme.MANUAL_ALL_NOTIFICATIONS));
+ if(notification.getNotificationType()!=null&&oldNotification!=notification){
+ oldNotification= notification;
+ AutoClientEnd.notification = notification;
+ callHandler();
}
+ error = false;
}
+ //
+ } catch (DeploymentException | IOException | URISyntaxException e) {
+ logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
+ client = null;
+ status = false;
+ changeURL();
}
}
@@ -120,56 +126,58 @@ public class AutoClientEnd {
}
public static void stop() {
- if (client != null) {
- client.shutdown();
- if(session!=null){
- try {
- stop = true;
- logger.info("\n Closing Auto Notification WebSocket Connection.. ");
- session.close();
- session = null;
- } catch (IOException e) {
- logger.error("Error closing websocket connection", e);
- }
+ if (client == null) {
+ return;
+ }
+ client.shutdown();
+ if(session!=null){
+ try {
+ stop = true;
+ logger.info("\n Closing Auto Notification WebSocket Connection.. ");
+ session.close();
+ session = null;
+ } catch (IOException e) {
+ logger.error("Error closing websocket connection", e);
}
- client = null;
- status = false;
- stop = false;
}
+ client = null;
+ status = false;
+ stop = false;
}
private static void callHandler() {
- if (handler != null && scheme != null) {
- if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)) {
- boolean removed = false;
- boolean updated = false;
- if (notification.getRemovedPolicies() != null && !notification.getRemovedPolicies().isEmpty()) {
- removed = true;
- }
- if (notification.getLoadedPolicies() != null && !notification.getLoadedPolicies().isEmpty()) {
- updated = true;
- }
- if (removed && updated) {
- notification.setNotificationType(NotificationType.BOTH);
- } else if (removed) {
- notification.setNotificationType(NotificationType.REMOVE);
- } else if (updated) {
- notification.setNotificationType(NotificationType.UPDATE);
- }
+ if (handler == null || scheme == null) {
+ return;
+ }
+ if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)) {
+ boolean removed = false;
+ boolean updated = false;
+ if (notification.getRemovedPolicies() != null && !notification.getRemovedPolicies().isEmpty()) {
+ removed = true;
+ }
+ if (notification.getLoadedPolicies() != null && !notification.getLoadedPolicies().isEmpty()) {
+ updated = true;
+ }
+ if (removed && updated) {
+ notification.setNotificationType(NotificationType.BOTH);
+ } else if (removed) {
+ notification.setNotificationType(NotificationType.REMOVE);
+ } else if (updated) {
+ notification.setNotificationType(NotificationType.UPDATE);
+ }
+ try{
+ handler.notificationReceived(notification);
+ }catch (Exception e){
+ logger.error("Error in Clients Handler Object : ", e);
+ }
+ } else if (scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) {
+ PDPNotification newNotification = MatchStore.checkMatch(notification);
+ if (newNotification.getNotificationType() != null) {
try{
- handler.notificationReceived(notification);
+ handler.notificationReceived(newNotification);
}catch (Exception e){
logger.error("Error in Clients Handler Object : ", e);
}
- } else if (scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) {
- PDPNotification newNotification = MatchStore.checkMatch(notification);
- if (newNotification.getNotificationType() != null) {
- try{
- handler.notificationReceived(newNotification);
- }catch (Exception e){
- logger.error("Error in Clients Handler Object : ", e);
- }
- }
}
}
}
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientUEB.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientUEB.java
index f84568aba..6bfcd2c7a 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientUEB.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/AutoClientUEB.java
@@ -103,44 +103,44 @@ public class AutoClientUEB implements Runnable {
String group = UUID.randomUUID ().toString ();
String id = "0";
// Stop and Start needs to be done.
- if (scheme != null && handler!=null) {
- if (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) || scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) {
- URL aURL;
- try {
- aURL = new URL(AutoClientUEB.topic);
- setTopic(aURL.getHost() + aURL.getPort());
- } catch (MalformedURLException e) {
- setTopic(AutoClientUEB.url.replace("[:/]", ""));
- }
- try {
- ConsumerBuilder builder = new CambriaClientBuilders.ConsumerBuilder();
- builder.knownAs(group, id)
- .usingHosts(uebURLList)
- .onTopic(topic)
- .waitAtServer(15*1000)
- .receivingAtMost(1000)
- .authenticatedBy(apiKey, apiSecret);
- setConsumer(builder.build());
- } catch (Exception e1) {
- logger.error("Exception Occured" + e1);
- }
- while (this.isRunning()) {
- try {
- for (String msg : cConsumer.fetch()) {
- logger.debug("Auto Notification Recieved Message " + msg + " from UEB cluster : "
- + uebURLList.toString());
- setNotification(NotificationUnMarshal.notificationJSON(msg));
- callHandler();
- }
- } catch (Exception e) {
- logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Error in processing UEB message"
- + e.getMessage(), e);
- }
-
- }
- logger.debug("Stopping UEB Consumer loop will not logger fetch messages from the cluster");
- }
+ if (scheme == null || handler == null ||
+ ! (scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS) || scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS)) ) {
+ return;
}
+ URL aURL;
+ try {
+ aURL = new URL(AutoClientUEB.topic);
+ setTopic(aURL.getHost() + aURL.getPort());
+ } catch (MalformedURLException e) {
+ setTopic(AutoClientUEB.url.replace("[:/]", ""));
+ }
+ try {
+ ConsumerBuilder builder = new CambriaClientBuilders.ConsumerBuilder();
+ builder.knownAs(group, id)
+ .usingHosts(uebURLList)
+ .onTopic(topic)
+ .waitAtServer(15*1000)
+ .receivingAtMost(1000)
+ .authenticatedBy(apiKey, apiSecret);
+ setConsumer(builder.build());
+ } catch (Exception e1) {
+ logger.error("Exception Occured" + e1);
+ }
+ while (this.isRunning()) {
+ try {
+ for (String msg : cConsumer.fetch()) {
+ logger.debug("Auto Notification Recieved Message " + msg + " from UEB cluster : "
+ + uebURLList.toString());
+ setNotification(NotificationUnMarshal.notificationJSON(msg));
+ callHandler();
+ }
+ } catch (Exception e) {
+ logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Error in processing UEB message"
+ + e.getMessage(), e);
+ }
+
+ }
+ logger.debug("Stopping UEB Consumer loop will not logger fetch messages from the cluster");
}
private static void setNotification(StdPDPNotification notificationJSON) {
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndDMAAP.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndDMAAP.java
index 025bd2128..0281f6010 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndDMAAP.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndDMAAP.java
@@ -40,34 +40,37 @@ public class ManualClientEndDMAAP {
private static String uniquID = null;
private static String topic = null;
+ private ManualClientEndDMAAP() {
+ // Empty constructor
+ }
+
public static PDPNotification result(NotificationScheme scheme) {
if (resultJson == null || notification == null) {
logger.debug("No Result" );
return null;
- } else {
- if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
- boolean removed = false, updated = false;
- if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){
- removed = true;
- }
- if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){
- updated = true;
- }
- if(removed && updated) {
- notification.setNotificationType(NotificationType.BOTH);
- }else if(removed){
- notification.setNotificationType(NotificationType.REMOVE);
- }else if(updated){
- notification.setNotificationType(NotificationType.UPDATE);
- }
- return notification;
- }else if(scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) {
- return MatchStore.checkMatch(notification);
- }else {
- return null;
+ }
+ if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
+ boolean removed = false;
+ boolean updated = false;
+ if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){
+ removed = true;
+ }
+ if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){
+ updated = true;
+ }
+ if(removed && updated) {
+ notification.setNotificationType(NotificationType.BOTH);
+ }else if(removed){
+ notification.setNotificationType(NotificationType.REMOVE);
+ }else if(updated){
+ notification.setNotificationType(NotificationType.UPDATE);
}
+ return notification;
+ }else if(scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) {
+ return MatchStore.checkMatch(notification);
}
+ return null;
}
private static void publishMessage(String pubTopic, String uniqueID, List<String> dmaapList, String aafLogin, String aafPassword) {
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java
index 29c85a2ad..8590f6a5b 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java
@@ -51,35 +51,36 @@ public class ManualClientEndUEB {
private static String url = null;
private static String uniquID = null;
private static String topic = null;
-
+
+ private ManualClientEndUEB() {
+ // Empty constructor
+ }
public static PDPNotification result(NotificationScheme scheme) {
if (resultJson == null || notification == null) {
logger.debug("No Result" );
return null;
- } else {
- if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
- boolean removed = false, updated = false;
- if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){
- removed = true;
- }
- if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){
- updated = true;
- }
- if(removed && updated) {
- notification.setNotificationType(NotificationType.BOTH);
- }else if(removed){
- notification.setNotificationType(NotificationType.REMOVE);
- }else if(updated){
- notification.setNotificationType(NotificationType.UPDATE);
- }
- return notification;
- }else if(scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) {
- return MatchStore.checkMatch(notification);
- }else {
- return null;
+ }
+ if(scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
+ boolean removed = false, updated = false;
+ if(notification.getRemovedPolicies()!=null && !notification.getRemovedPolicies().isEmpty()){
+ removed = true;
+ }
+ if(notification.getLoadedPolicies()!=null && !notification.getLoadedPolicies().isEmpty()){
+ updated = true;
+ }
+ if(removed && updated) {
+ notification.setNotificationType(NotificationType.BOTH);
+ }else if(removed){
+ notification.setNotificationType(NotificationType.REMOVE);
+ }else if(updated){
+ notification.setNotificationType(NotificationType.UPDATE);
}
+ return notification;
+ }else if(scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) {
+ return MatchStore.checkMatch(notification);
}
+ return null;
}
private static void publishMessage(String pubTopic, String uniqueID , List<String> uebURLList) {
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/MatchStore.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/MatchStore.java
index a243c1fc1..ecdafe43c 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/MatchStore.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/MatchStore.java
@@ -37,6 +37,10 @@ public class MatchStore {
private static HashSet<Matches> matchStore = new HashSet<>();
private static Logger logger = FlexLogger.getLogger(MatchStore.class.getName());
+ private MatchStore() {
+ // Empty Constructor
+ }
+
public static HashSet<Matches> getMatchStore() {
return matchStore;
}
@@ -103,14 +107,14 @@ public class MatchStore {
//Logic changes for Requested Policies notifications..
public static PDPNotification checkMatch(PDPNotification oldNotification) {
- boolean removed = false, updated = false;
+ boolean removed = false;
+ boolean updated = false;
if(oldNotification==null){
return null;
}
StdPDPNotification newNotification = new StdPDPNotification();
if(matchStore.isEmpty()) {
logger.debug("No Success Config Calls made yet.. ");
- System.out.println("No success Config calls made yet. ");
return null;
}
if(oldNotification.getRemovedPolicies()!=null && !oldNotification.getRemovedPolicies().isEmpty()){
@@ -132,7 +136,7 @@ public class MatchStore {
for(LoadedPolicy updatedPolicy: oldNotification.getLoadedPolicies()){
// if it is config policies check their matches..
if(updatedPolicy.getMatches()!=null && !updatedPolicy.getMatches().isEmpty()){
- boolean matched = false;
+ boolean matched;
for(Matches match : matchStore){
matched = false;
// Again Better way would be comparing sizes first.
@@ -144,14 +148,14 @@ public class MatchStore {
// Comparing both the values..
boolean matchAttributes = false;
for(String newKey: updatedPolicy.getMatches().keySet()){
- if(newKey.equals("ONAPName")){
+ if("ONAPName".equals(newKey)){
if(updatedPolicy.getMatches().get(newKey).equals(match.getOnapName())){
matchAttributes = true;
}else {
matchAttributes = false;
break;
}
- }else if(newKey.equals("ConfigName")) {
+ }else if("ConfigName".equals(newKey)) {
if(updatedPolicy.getMatches().get(newKey).equals(match.getConfigName())){
matchAttributes = true;
}else{
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java
index 447e7cb26..6772f5a9b 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/NotificationUnMarshal.java
@@ -32,34 +32,39 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class NotificationUnMarshal {
+ private NotificationUnMarshal() {
+ // Empty constructor
+ }
+
public static StdPDPNotification notificationJSON(String json) throws IOException{
ObjectMapper mapper = new ObjectMapper();
StdPDPNotification notification = mapper.readValue(json, StdPDPNotification.class);
- if(notification!=null&&notification.getLoadedPolicies()!=null){
- Collection<StdLoadedPolicy> stdLoadedPolicies = new ArrayList<>();
- for(LoadedPolicy loadedPolicy: notification.getLoadedPolicies()){
- StdLoadedPolicy stdLoadedPolicy = (StdLoadedPolicy) loadedPolicy;
- if(notification.getRemovedPolicies()!=null){
- Boolean updated = false;
- for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){
- String regex = ".(\\d)*.xml";
- if(removedPolicy.getPolicyName().replaceAll(regex, "").equals(stdLoadedPolicy.getPolicyName().replaceAll(regex, ""))){
- updated = true;
- break;
- }
- }
- if(updated){
- stdLoadedPolicy.setUpdateType(UpdateType.UPDATE);
- }else{
- stdLoadedPolicy.setUpdateType(UpdateType.NEW);
- }
- }else{
- stdLoadedPolicy.setUpdateType(UpdateType.NEW);
- }
- stdLoadedPolicies.add(stdLoadedPolicy);
- }
- notification.setLoadedPolicies(stdLoadedPolicies);
+ if(notification == null || notification.getLoadedPolicies() == null){
+ return notification;
}
+ Collection<StdLoadedPolicy> stdLoadedPolicies = new ArrayList<>();
+ for(LoadedPolicy loadedPolicy: notification.getLoadedPolicies()){
+ StdLoadedPolicy stdLoadedPolicy = (StdLoadedPolicy) loadedPolicy;
+ if(notification.getRemovedPolicies()!=null){
+ Boolean updated = false;
+ for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){
+ String regex = ".(\\d)*.xml";
+ if(removedPolicy.getPolicyName().replaceAll(regex, "").equals(stdLoadedPolicy.getPolicyName().replaceAll(regex, ""))){
+ updated = true;
+ break;
+ }
+ }
+ if(updated){
+ stdLoadedPolicy.setUpdateType(UpdateType.UPDATE);
+ }else{
+ stdLoadedPolicy.setUpdateType(UpdateType.NEW);
+ }
+ }else{
+ stdLoadedPolicy.setUpdateType(UpdateType.NEW);
+ }
+ stdLoadedPolicies.add(stdLoadedPolicy);
+ }
+ notification.setLoadedPolicies(stdLoadedPolicies);
return notification;
}
}
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyConfig.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyConfig.java
index 62db64491..b5c1a4c8f 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyConfig.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyConfig.java
@@ -91,7 +91,7 @@ public class StdPolicyConfig implements PolicyConfig{
@Override
public String getPolicyName() {
if(policyName!=null && policyName.contains(".xml")){
- return (policyName.substring(0, policyName.substring(0, policyName.lastIndexOf('.')).lastIndexOf('.')));
+ return policyName.substring(0, policyName.substring(0, policyName.lastIndexOf('.')).lastIndexOf('.'));
}
return policyName;
}
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java
index 6c74dde89..d08ea29f9 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java
@@ -537,7 +537,7 @@ public class StdPolicyEngine {
public DecisionResponse getDecisionImpl(String onapName, Map<String, String> decisionAttributes, UUID requestID)
throws PolicyDecisionException {
String resource = "getDecision";
- StdDecisionResponse response = new StdDecisionResponse();
+ StdDecisionResponse response;
String body = null;
// Create Request.
try {
@@ -579,7 +579,7 @@ public class StdPolicyEngine {
public Collection<PolicyConfig> getConfigImpl(ConfigRequestParameters configRequestParameters)
throws PolicyConfigException {
String resource = "getConfig";
- ArrayList<PolicyConfig> response = null;
+ ArrayList<PolicyConfig> response;
String body = null;
// Create Request.
try {
@@ -671,9 +671,9 @@ public class StdPolicyEngine {
HashMap<String, String> configAttributes = new HashMap<>();
try {
for (Map.Entry<String,String> entry : matchingConditions.entrySet()) {
- if (entry.getKey().equalsIgnoreCase("ONAPName")) {
+ if ("ONAPName".equalsIgnoreCase(entry.getKey())) {
match.setOnapName(entry.getValue());
- } else if (entry.getKey().equalsIgnoreCase("ConfigName")) {
+ } else if ("ConfigName".equalsIgnoreCase(entry.getKey())) {
match.setConfigName(entry.getValue());
} else {
configAttributes.put(entry.getKey(), entry.getValue());
@@ -716,31 +716,31 @@ public class StdPolicyEngine {
break;
}
}
- if (exception != null && exception.getStatusCode() != null) {
- if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
- String message = XACMLErrorConstants.ERROR_PERMISSIONS + ":" + exception.getStatusCode() + ":"
- + ERROR_AUTH_GET_PERM + resource;
- LOGGER.error(message);
- throw new PolicyException(message, exception);
- }
- if (exception.getStatusCode().equals(HttpStatus.BAD_REQUEST)) {
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ":" + exception.getStatusCode() + ":"
- + exception.getResponseBodyAsString();
- LOGGER.error(message);
- throw new PolicyException(message, exception);
- }
- if (exception.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
- String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_WHILE_CONNECTING + pdps
- + exception;
- LOGGER.error(message);
- throw new PolicyException(message, exception);
- }
- String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + exception.getStatusCode() + ":"
+ if (exception == null || exception.getStatusCode() == null) {
+ return result;
+ }
+ if (exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED)) {
+ String message = XACMLErrorConstants.ERROR_PERMISSIONS + ":" + exception.getStatusCode() + ":"
+ + ERROR_AUTH_GET_PERM + resource;
+ LOGGER.error(message);
+ throw new PolicyException(message, exception);
+ }
+ if (exception.getStatusCode().equals(HttpStatus.BAD_REQUEST)) {
+ String message = XACMLErrorConstants.ERROR_DATA_ISSUE + ":" + exception.getStatusCode() + ":"
+ exception.getResponseBodyAsString();
LOGGER.error(message);
throw new PolicyException(message, exception);
}
- return result;
+ if (exception.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
+ String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ERROR_WHILE_CONNECTING + pdps
+ + exception;
+ LOGGER.error(message);
+ throw new PolicyException(message, exception);
+ }
+ String message = XACMLErrorConstants.ERROR_PROCESS_FLOW + ":" + exception.getStatusCode() + ":"
+ + exception.getResponseBodyAsString();
+ LOGGER.error(message);
+ throw new PolicyException(message, exception);
}
private HttpHeaders getHeaders() {
@@ -782,7 +782,7 @@ public class StdPolicyEngine {
public Collection<PolicyResponse> sendEventImpl(Map<String, String> eventAttributes, UUID requestID)
throws PolicyEventException {
String resource = "sendEvent";
- ArrayList<PolicyResponse> response = null;
+ ArrayList<PolicyResponse> response;
String body = null;
// Create Request.
try {
@@ -835,140 +835,140 @@ public class StdPolicyEngine {
if (propertyFilePath == null) {
throw new PolicyEngineException(
XACMLErrorConstants.ERROR_DATA_ISSUE + "Error NO PropertyFile Path provided");
+ }
+
+ // Adding logic for remote Properties file.
+ Properties prop = new Properties();
+ if (propertyFilePath.startsWith("http")) {
+ URL configURL;
+ try {
+ configURL = new URL(propertyFilePath);
+ URLConnection connection;
+ connection = configURL.openConnection();
+ prop.load(connection.getInputStream());
+ } catch (IOException e) {
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e);
+ throw new PolicyEngineException(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "Maformed property URL " + e.getMessage());
+ }
} else {
- // Adding logic for remote Properties file.
- Properties prop = new Properties();
- if (propertyFilePath.startsWith("http")) {
- URL configURL;
+ Path file = Paths.get(propertyFilePath);
+ if (!file.toFile().exists()) {
+ throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
+ + "File doesn't exist in the specified Path " + file.toString());
+ }
+ if (file.toString().endsWith(".properties")) {
+ InputStream in;
+ prop = new Properties();
try {
- configURL = new URL(propertyFilePath);
- URLConnection connection = null;
- connection = configURL.openConnection();
- prop.load(connection.getInputStream());
+ in = new FileInputStream(file.toFile());
+ prop.load(in);
} catch (IOException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e);
+ LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
throw new PolicyEngineException(
- XACMLErrorConstants.ERROR_DATA_ISSUE + "Maformed property URL " + e.getMessage());
+ XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Load the Properties file", e);
}
} else {
- Path file = Paths.get(propertyFilePath);
- if (!file.toFile().exists()) {
- throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
- + "File doesn't exist in the specified Path " + file.toString());
- }
- if (file.toString().endsWith(".properties")) {
- InputStream in;
- prop = new Properties();
- try {
- in = new FileInputStream(file.toFile());
- prop.load(in);
- } catch (IOException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + e);
- throw new PolicyEngineException(
- XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Cannot Load the Properties file", e);
- }
- } else {
- LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + propertyFilePath);
- throw new PolicyEngineException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file");
- }
+ LOGGER.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file " + propertyFilePath);
+ throw new PolicyEngineException(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Not a .properties file");
}
- // UEB and DMAAP Settings
- String checkType = prop.getProperty("NOTIFICATION_TYPE");
- String serverList = prop.getProperty("NOTIFICATION_SERVERS");
- topic = prop.getProperty("NOTIFICATION_TOPIC");
- apiKey = prop.getProperty("UEB_API_KEY");
- apiSecret = prop.getProperty("UEB_API_SECRET");
-
- if (checkType == null) {
- notificationType.add(DEFAULT_NOTIFICATION);
- LOGGER.info(
- "Properties file doesn't have the NOTIFICATION_TYPE parameter system will use defualt websockets");
+ }
+ // UEB and DMAAP Settings
+ String checkType = prop.getProperty("NOTIFICATION_TYPE");
+ String serverList = prop.getProperty("NOTIFICATION_SERVERS");
+ topic = prop.getProperty("NOTIFICATION_TOPIC");
+ apiKey = prop.getProperty("UEB_API_KEY");
+ apiSecret = prop.getProperty("UEB_API_SECRET");
+
+ if (checkType == null) {
+ notificationType.add(DEFAULT_NOTIFICATION);
+ LOGGER.info(
+ "Properties file doesn't have the NOTIFICATION_TYPE parameter system will use defualt websockets");
+ } else {
+ checkType = checkType.trim();
+ if (checkType.contains(",")) {
+ notificationType = new ArrayList<>(Arrays.asList(prop.getProperty("NOTIFICATION_TYPE").split(",")));
} else {
- checkType = checkType.trim();
- if (checkType.contains(",")) {
- notificationType = new ArrayList<>(Arrays.asList(prop.getProperty("NOTIFICATION_TYPE").split(",")));
- } else {
- notificationType = new ArrayList<>();
- notificationType.add(checkType);
- }
+ notificationType = new ArrayList<>();
+ notificationType.add(checkType);
}
- if (serverList == null) {
- notificationType.clear();
- notificationType.add(DEFAULT_NOTIFICATION);
- LOGGER.info(
- "Properties file doesn't have the NOTIFICATION_SERVERS parameter system will use defualt websockets");
+ }
+ if (serverList == null) {
+ notificationType.clear();
+ notificationType.add(DEFAULT_NOTIFICATION);
+ LOGGER.info(
+ "Properties file doesn't have the NOTIFICATION_SERVERS parameter system will use defualt websockets");
+ } else {
+ serverList = serverList.trim();
+ if (serverList.contains(",")) {
+ notificationURLList = new ArrayList<>(Arrays.asList(serverList.split(",")));
} else {
- serverList = serverList.trim();
- if (serverList.contains(",")) {
- notificationURLList = new ArrayList<>(Arrays.asList(serverList.split(",")));
- } else {
- notificationURLList = new ArrayList<>();
- notificationURLList.add(serverList);
- }
+ notificationURLList = new ArrayList<>();
+ notificationURLList.add(serverList);
}
+ }
- if (topic != null) {
- topic = topic.trim();
- } else {
- LOGGER.error("Properties file doesn't have the NOTIFICATION_TOPIC parameter.");
- }
+ if (topic != null) {
+ topic = topic.trim();
+ } else {
+ LOGGER.error("Properties file doesn't have the NOTIFICATION_TOPIC parameter.");
+ }
- // Client ID Authorization Settings.
- String clientID = prop.getProperty("CLIENT_ID");
- if (clientKey == null) {
- clientKey = prop.getProperty("CLIENT_KEY");
- try {
- clientKey = PolicyUtils.decode(clientKey);
- } catch (UnsupportedEncodingException | IllegalArgumentException e) {
- LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS
- + " Cannot Decode the given Password Proceeding with given Password!!", e);
- }
- }
- if (clientID == null || clientKey == null || clientID.isEmpty() || clientKey.isEmpty()) {
+ // Client ID Authorization Settings.
+ String clientID = prop.getProperty("CLIENT_ID");
+ if (clientKey == null) {
+ clientKey = prop.getProperty("CLIENT_KEY");
+ try {
+ clientKey = PolicyUtils.decode(clientKey);
+ } catch (UnsupportedEncodingException | IllegalArgumentException e) {
LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS
- + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!");
- throw new PolicyEngineException(XACMLErrorConstants.ERROR_PERMISSIONS
- + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!");
- } else {
- setClientId(clientID.trim());
- setClientKey(clientKey.trim());
+ + " Cannot Decode the given Password Proceeding with given Password!!", e);
}
- setEnvironment(prop);
- // Initializing the values.
- init();
- // Check the Keys for PDP_URLs
- Collection<Object> unsorted = prop.keySet();
- @SuppressWarnings({ "rawtypes", "unchecked" })
- List<String> sorted = new ArrayList(unsorted);
- Collections.sort(sorted);
- for (String propKey : sorted) {
- if (propKey.startsWith("PDP_URL")) {
- String checkVal = prop.getProperty(propKey);
- if (checkVal == null) {
- throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
- + "Properties file doesn't have the PDP_URL parameter");
- }
- if (checkVal.contains(";")) {
- List<String> pdpDefault = new ArrayList<>(Arrays.asList(checkVal.split("\\s*;\\s*")));
- int pdpCount = 0;
- while (pdpCount < pdpDefault.size()) {
- String pdpVal = pdpDefault.get(pdpCount);
- readPDPParam(pdpVal);
- pdpCount++;
- }
- } else {
- readPDPParam(checkVal);
+ }
+ if (clientID == null || clientKey == null || clientID.isEmpty() || clientKey.isEmpty()) {
+ LOGGER.error(XACMLErrorConstants.ERROR_PERMISSIONS
+ + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!");
+ throw new PolicyEngineException(XACMLErrorConstants.ERROR_PERMISSIONS
+ + " Cannot proceed without the CLIENT_KEY and CLIENT_ID values !!");
+ } else {
+ setClientId(clientID.trim());
+ setClientKey(clientKey.trim());
+ }
+ setEnvironment(prop);
+ // Initializing the values.
+ init();
+ // Check the Keys for PDP_URLs
+ Collection<Object> unsorted = prop.keySet();
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ List<String> sorted = new ArrayList(unsorted);
+ Collections.sort(sorted);
+ for (String propKey : sorted) {
+ if (propKey.startsWith("PDP_URL")) {
+ String checkVal = prop.getProperty(propKey);
+ if (checkVal == null) {
+ throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
+ + "Properties file doesn't have the PDP_URL parameter");
+ }
+ if (checkVal.contains(";")) {
+ List<String> pdpDefault = new ArrayList<>(Arrays.asList(checkVal.split("\\s*;\\s*")));
+ int pdpCount = 0;
+ while (pdpCount < pdpDefault.size()) {
+ String pdpVal = pdpDefault.get(pdpCount);
+ readPDPParam(pdpVal);
+ pdpCount++;
}
+ } else {
+ readPDPParam(checkVal);
}
}
- if (pdps == null || pdps.isEmpty()) {
- LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs");
- throw new PolicyEngineException(
- XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs");
- }
- // Get JUNIT property from properties file when running tests
- checkJunit(prop);
}
+ if (pdps == null || pdps.isEmpty()) {
+ LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs");
+ throw new PolicyEngineException(
+ XACMLErrorConstants.ERROR_DATA_ISSUE + "Cannot Proceed without PDP_URLs");
+ }
+ // Get JUNIT property from properties file when running tests
+ checkJunit(prop);
}
private static void checkJunit(Properties prop) {
@@ -976,7 +976,7 @@ public class StdPolicyEngine {
if (junitFlag == null || junitFlag.isEmpty()) {
LOGGER.info("No JUNIT property provided, this will not be executed as a test.");
} else {
- if (junitFlag.equalsIgnoreCase("test")) {
+ if ("test".equalsIgnoreCase(junitFlag)) {
StdPolicyEngine.junit = true;
} else {
StdPolicyEngine.junit = false;
@@ -1040,7 +1040,7 @@ public class StdPolicyEngine {
LOGGER.debug("Scheme is : " + scheme.toString());
LOGGER.debug("Handler is : " + handler.getClass().getName());
- if (notificationType.get(0).equals("ueb")) {
+ if ("ueb".equals(notificationType.get(0))) {
if (this.uebThread) {
AutoClientUEB.setAuto(scheme, handler);
this.uebThread = registerUEBThread.isAlive();
@@ -1059,7 +1059,7 @@ public class StdPolicyEngine {
}
if (pdps != null) {
- if (notificationType.get(0).equals("ueb") && !this.uebThread) {
+ if ("ueb".equals(notificationType.get(0)) && !this.uebThread) {
this.uebClientThread = new AutoClientUEB(pdps.get(0), notificationURLList, apiKey, apiSecret);
AutoClientUEB.setAuto(scheme, handler);
this.registerUEBThread = new Thread(this.uebClientThread);
@@ -1089,7 +1089,7 @@ public class StdPolicyEngine {
*/
public PDPNotification getNotification() {
// Check if there is proper scheme..
- PDPNotification notification = null;
+ PDPNotification notification;
if (this.scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)
|| this.scheme.equals(NotificationScheme.MANUAL_NOTIFICATIONS)) {
if (notificationType.get(0).equals("ueb")) {
@@ -1106,12 +1106,10 @@ public class StdPolicyEngine {
if (notification == null) {
LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "No Notification yet..");
return null;
- } else {
- return notification;
}
- } else {
- return null;
+ return notification;
}
+ return null;
}
/*
@@ -1119,7 +1117,7 @@ public class StdPolicyEngine {
*/
public void setScheme(NotificationScheme scheme) {
this.scheme = scheme;
- if (notificationType.get(0).equals("ueb")) {
+ if ("ueb".equals(notificationType.get(0))) {
AutoClientUEB.setScheme(this.scheme);
if (this.scheme.equals(NotificationScheme.MANUAL_ALL_NOTIFICATIONS)) {
ManualClientEndUEB.createTopic(pdps.get(0), UNIQUEID, notificationURLList);
@@ -1155,7 +1153,7 @@ public class StdPolicyEngine {
if (this.scheme != null && this.handler != null && (this.scheme.equals(NotificationScheme.AUTO_ALL_NOTIFICATIONS)
|| this.scheme.equals(NotificationScheme.AUTO_NOTIFICATIONS))) {
LOGGER.info("Clear Notification called.. ");
- if (notificationType.get(0).equals("ueb")) {
+ if ("ueb".equals(notificationType.get(0))) {
this.uebClientThread.terminate();
this.uebThread = false;
} else if (notificationType.get(0).equals(DMAAP)) {
@@ -1222,7 +1220,7 @@ public class StdPolicyEngine {
policyParameters.setPolicyDescription(policyDescription);
policyParameters.setOnapName(onapName);
policyParameters.setConfigName(configName);
- Map<AttributeType, Map<String, String>> attributes = new HashMap<AttributeType, Map<String, String>>();
+ Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
attributes.put(AttributeType.MATCHING, configAttributes);
policyParameters.setAttributes(attributes);
policyParameters.setConfigBodyType(PolicyType.valueOf(configType));
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java
index fc854b077..b1b60dbd8 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java
@@ -88,26 +88,32 @@ public class StdStatus extends StdPolicyResponse implements PolicyConfig, Policy
return policyResponseMessage;
}
+ @Override
public void setPolicyResponseStatus(PolicyResponseStatus policyResponseStatus) {
this.policyResponseStatus = policyResponseStatus;
}
+ @Override
public void setActionAdvised(Map<String, String> actionAdvised) {
this.actionAdvised = actionAdvised;
}
+ @Override
public void setActionTaken(Map<String, String> actionTaken) {
this.actionTaken = actionTaken;
}
+ @Override
public void setRequestAttributes(Map<String, String> requestAttributes) {
this.requestAttributes = requestAttributes;
}
+ @Override
public void setPolicyResponseMessage(String policyResponseMessage) {
this.policyResponseMessage = policyResponseMessage;
}
+ @Override
public void setPolicyResponseStatus(String policyResponseMessage, PolicyResponseStatus policyResponseStatus) {
this.policyResponseMessage = policyResponseMessage;
this.policyResponseStatus = policyResponseStatus;
@@ -146,7 +152,7 @@ public class StdStatus extends StdPolicyResponse implements PolicyConfig, Policy
@Override
public String getPolicyName() {
if(policyName!=null && policyName.contains(".xml")){
- return (policyName.substring(0, policyName.substring(0, policyName.lastIndexOf(".")).lastIndexOf(".")));
+ return (policyName.substring(0, policyName.substring(0, policyName.lastIndexOf('.')).lastIndexOf('.')));
}
return policyName;
}