summaryrefslogtreecommitdiffstats
path: root/PolicyEngineAPI/src/main/java
diff options
context:
space:
mode:
authorKrishnajinka <kris.jinka@samsung.com>2018-07-26 16:33:11 +0900
committerKrishnajinka <kris.jinka@samsung.com>2018-07-26 20:42:30 +0900
commit5a9d91a75f1a65074c71652e7f404f460390974a (patch)
treee59d1070610de9084dcb105acfcf87d4016503fb /PolicyEngineAPI/src/main/java
parent7957dd169d09ff5fcfdfc0384e8ed7d3534d3dc0 (diff)
Refactor code for nested stmts in policy std
Refactor code for nested control statements in PolicyEngineAPI policy.std package. These issues are flagged by Sonar as Major issues. Rework based on review comments Issue-ID: POLICY-1012 Change-Id: I6925dd5d56b653ef4cefe5ae64686a49f9741125 Signed-off-by: Krishnajinka <kris.jinka@samsung.com>
Diffstat (limited to 'PolicyEngineAPI/src/main/java')
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndDMAAP.java186
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java221
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java198
3 files changed, 312 insertions, 293 deletions
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 0281f6010..065f084ba 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndDMAAP.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndDMAAP.java
@@ -3,6 +3,7 @@
* PolicyEngineAPI
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,98 +34,103 @@ import org.onap.policy.utils.BusPublisher;
import org.onap.policy.xacml.api.XACMLErrorConstants;
public class ManualClientEndDMAAP {
- private static StdPDPNotification notification = null;
- private static String resultJson = null;
- private static Logger logger = FlexLogger.getLogger(ManualClientEndDMAAP.class.getName());
- private static BusConsumer dmaapConsumer = null;
- private static String uniquID = null;
- private static String topic = null;
-
- private ManualClientEndDMAAP() {
- // Empty constructor
- }
-
+ private static StdPDPNotification notification = null;
+ private static String resultJson = null;
+ private static Logger logger = FlexLogger.getLogger(ManualClientEndDMAAP.class.getName());
+ private static BusConsumer dmaapConsumer = null;
+ private static String uniquID = null;
+ private static String topic = null;
+ private static int RETRY_LIMIT = 4;
+ private ManualClientEndDMAAP() {
+ // Empty constructor
+ }
- public static PDPNotification result(NotificationScheme scheme) {
- if (resultJson == null || notification == null) {
- logger.debug("No Result" );
- 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) {
+ public static PDPNotification result(NotificationScheme scheme) {
+ if (resultJson == null || notification == null) {
+ logger.debug("No Result" );
+ 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) {
BusPublisher pub = null;
- try {
- pub = new BusPublisher.DmaapPublisherWrapper(dmaapList, topic, aafLogin, aafPassword);
- final JSONObject msg1 = new JSONObject ();
- msg1.put ( "JSON", "DMaaP Update Request UID=" + uniqueID);
- pub.send ( "MyPartitionKey", msg1.toString () );
- } catch (Exception e) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to create DMaaP Publisher: ", e);
- }
- if(pub != null){
- pub.close ();
- }
- }
+ try {
+ pub = new BusPublisher.DmaapPublisherWrapper(dmaapList, topic, aafLogin, aafPassword);
+ final JSONObject msg1 = new JSONObject ();
+ msg1.put ( "JSON", "DMaaP Update Request UID=" + uniqueID);
+ pub.send ( "MyPartitionKey", msg1.toString () );
+ } catch (Exception e) {
+ logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to create DMaaP Publisher: ", e);
+ }
+ if(pub != null){
+ pub.close ();
+ }
+ }
+
+ //NOTE: should be able to remove this for DMAAP since we will not be creating topics dynamically
+ public static void createTopic (String topic, String uniquID, List<String> dmaapList, String aafLogin, String aafPassword){
+ ManualClientEndDMAAP.topic = topic;
+ publishMessage(topic, uniquID, dmaapList, aafLogin, aafPassword);
+ }
+
+
+ public static void start(List<String> dmaapList, String topic, String aafLogin, String aafPassword, String uniqueID) {
+
+ ManualClientEndDMAAP.uniquID = uniqueID;
+ ManualClientEndDMAAP.topic = topic;
+
+ String id = "0";
+
+ try {
+ dmaapConsumer = new BusConsumer.DmaapConsumerWrapper(dmaapList, topic, aafLogin, aafPassword, "clientGroup", id, 15*1000, 1000);
+ } catch (Exception e) {
+ logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to create DMaaP Consumer: ", e);
+ }
+
+ int retries = 1;
+ boolean isSuccess = false;
+ while (retries < RETRY_LIMIT && !isSuccess) {
+ isSuccess = publishMessageAndSetNotification(dmaapList, topic, aafLogin, aafPassword);
+ retries++;
+ }
+ }
- //NOTE: should be able to remove this for DMAAP since we will not be creating topics dynamically
- public static void createTopic (String topic, String uniquID, List<String> dmaapList, String aafLogin, String aafPassword){
- ManualClientEndDMAAP.topic = topic;
- publishMessage(topic, uniquID, dmaapList, aafLogin, aafPassword);
- }
-
-
- public static void start(List<String> dmaapList, String topic, String aafLogin, String aafPassword, String uniqueID) {
-
- ManualClientEndDMAAP.uniquID = uniqueID;
- ManualClientEndDMAAP.topic = topic;
-
- String id = "0";
-
- try {
- dmaapConsumer = new BusConsumer.DmaapConsumerWrapper(dmaapList, topic, aafLogin, aafPassword, "clientGroup", id, 15*1000, 1000);
- } catch (Exception e) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to create DMaaP Consumer: ", e);
- }
-
- int count = 1;
- while (count < 4) {
- publishMessage(topic, uniquID, dmaapList, aafLogin, aafPassword);
- try {
- for ( String msg : dmaapConsumer.fetch () )
- {
- logger.debug("Manual Notification Recieved Message " + msg + " from DMaaP server : " + dmaapList.toString());
- resultJson = msg;
- if (!msg.contains("DMaaP Update")){
- notification = NotificationUnMarshal.notificationJSON(msg);
- count = 4;
- }
- }
- }catch (Exception e) {
- logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to fetch messages from DMaaP servers: ", e);
- }
- count++;
- }
- }
+ private static boolean publishMessageAndSetNotification(List<String> dmaapList, String topic, String aafLogin, String aafPassword) {
+ publishMessage(topic, uniquID, dmaapList, aafLogin, aafPassword);
+ try {
+ for ( String msg : dmaapConsumer.fetch () ) {
+ logger.debug("Manual Notification Recieved Message " + msg + " from DMaaP server : " + dmaapList.toString());
+ resultJson = msg;
+ if (!msg.contains("DMaaP Update")){
+ notification = NotificationUnMarshal.notificationJSON(msg);
+ return true;
+ }
+ }
+ }catch (Exception e) {
+ logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Unable to fetch messages from DMaaP servers: ", e);
+ }
+ return false;
+ }
}
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 c04736e86..d67e136e3 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/ManualClientEndUEB.java
@@ -3,6 +3,7 @@
* PolicyEngineAPI
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -39,123 +40,127 @@ import com.att.nsa.cambria.client.CambriaPublisher;
@SuppressWarnings("deprecation")
public class ManualClientEndUEB {
- private static StdPDPNotification notification = null;
- private static String resultJson = null;
- private static Logger logger = FlexLogger.getLogger(ManualClientEndUEB.class.getName());
- private static CambriaConsumer CConsumer = null;
- @SuppressWarnings("unused")
- private static List<String> uebURLList = null;
- @SuppressWarnings("unused")
- private static boolean messageNotReceived = false;
- @SuppressWarnings("unused")
- private static String url = null;
- private static String uniquID = null;
- private static String topic = null;
+ private static StdPDPNotification notification = null;
+ private static String resultJson = null;
+ private static Logger logger = FlexLogger.getLogger(ManualClientEndUEB.class.getName());
+ private static CambriaConsumer CConsumer = null;
+ @SuppressWarnings("unused")
+ private static List<String> uebURLList = null;
+ @SuppressWarnings("unused")
+ private static boolean messageNotReceived = false;
+ @SuppressWarnings("unused")
+ private static String url = null;
+ private static String uniquID = null;
+ private static String topic = null;
+ private static int RETRY_LIMIT = 4;
- private ManualClientEndUEB() {
- // Empty constructor
- }
+ private ManualClientEndUEB() {
+ // Empty constructor
+ }
- public static PDPNotification result(NotificationScheme scheme) {
- if (resultJson == null || notification == null) {
- logger.debug("No Result" );
- 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;
- }
+ public static PDPNotification result(NotificationScheme scheme) {
+ if (resultJson == null || notification == null) {
+ logger.debug("No Result" );
+ 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> uebURLList) {
-
- String UEBlist = uebURLList.toString();
- UEBlist = UEBlist.substring(1,UEBlist.length()-1);
+ private static void publishMessage(String pubTopic, String uniqueID , List<String> uebURLList) {
+
+ String UEBlist = uebURLList.toString();
+ UEBlist = UEBlist.substring(1,UEBlist.length()-1);
CambriaPublisher pub = null;
- try {
- pub = CambriaClientFactory.createSimplePublisher(null, UEBlist, pubTopic);
- } catch (Exception e1) {
- logger.error("Exception Occured"+e1);
- }
+ try {
+ pub = CambriaClientFactory.createSimplePublisher(null, UEBlist, pubTopic);
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ }
final JSONObject msg1 = new JSONObject ();
msg1.put ( "JSON", "UEB Update Ruest UID=" + uniqueID);
if(pub != null){
- try {
- pub.send ( "MyPartitionKey", msg1.toString () );
- pub.close ();
- } catch (IOException e) {
- logger.error("Exception Occured"+e);
- }
+ try {
+ pub.send ( "MyPartitionKey", msg1.toString () );
+ pub.close ();
+ } catch (IOException e) {
+ logger.error("Exception Occured"+e);
+ }
}
- }
+ }
+
+ public static void createTopic (String url, String uniquID, List<String> uebURLList){
+ URL aURL;
+ try {
+ aURL = new URL(url);
+ topic = aURL.getHost() + aURL.getPort();
+ } catch (MalformedURLException e) {
+ topic = url.replace("[:/]", "");
+ }
+
+ publishMessage(topic+ uniquID , uniquID, uebURLList);
- public static void createTopic (String url, String uniquID, List<String> uebURLList){
- URL aURL;
- try {
- aURL = new URL(url);
- topic = aURL.getHost() + aURL.getPort();
- } catch (MalformedURLException e) {
- topic = url.replace("[:/]", "");
- }
+ }
+ public static void start(String url, List<String> uebURLList,
+ String uniqueID) {
+ ManualClientEndUEB.uebURLList = uebURLList;
+ ManualClientEndUEB.url = url;
+ ManualClientEndUEB.uniquID = uniqueID;
+ URL aURL;
+ try {
+ aURL = new URL(url);
+ ManualClientEndUEB.topic = aURL.getHost() + aURL.getPort();
+ } catch (MalformedURLException e) {
+ ManualClientEndUEB.topic = url.replace("[:/]", "");
+ }
+ String id = "0";
+ try {
+ CConsumer = CambriaClientFactory.createConsumer ( null, uebURLList, topic + uniquID, "clientGroup", id, 15*1000, 1000 );
+ } catch (Exception e1) {
+ logger.error("Exception Occured"+e1);
+ }
+ int retries = 1;
+ boolean isSuccess = false;
+ while (retries < RETRY_LIMIT && !isSuccess) {
+ isSuccess = publishMessageAndSetNotification(uebURLList);
+ retries++;
+ }
+ }
- publishMessage(topic+ uniquID , uniquID, uebURLList);
-
- }
- public static void start(String url, List<String> uebURLList,
- String uniqueID) {
- ManualClientEndUEB.uebURLList = uebURLList;
- ManualClientEndUEB.url = url;
- ManualClientEndUEB.uniquID = uniqueID;
- URL aURL;
- try {
- aURL = new URL(url);
- ManualClientEndUEB.topic = aURL.getHost() + aURL.getPort();
- } catch (MalformedURLException e) {
- ManualClientEndUEB.topic = url.replace("[:/]", "");
- }
- String id = "0";
- try {
- CConsumer = CambriaClientFactory.createConsumer ( null, uebURLList, topic + uniquID, "clientGroup", id, 15*1000, 1000 );
- } catch (Exception e1) {
- logger.error("Exception Occured"+e1);
- }
- int count = 1;
- while (count < 4) {
- publishMessage(topic + "UpdateRequest", uniquID, uebURLList);
- try {
- for ( String msg : CConsumer.fetch () )
- {
-
- logger.debug("Manual Notification Recieved Message " + msg + " from UEB cluster : " + uebURLList.toString());
- resultJson = msg;
- if (!msg.contains("UEB Update")){
- notification = NotificationUnMarshal.notificationJSON(msg);
- count = 4;
- }
- }
- }catch (Exception e) {
- logger.error("Error in Manual CLient UEB notification ", e);
- }
- count++;
- }
- }
-
+ private static boolean publishMessageAndSetNotification(List<String> uebURLList) {
+ publishMessage(topic + "UpdateRequest", uniquID, uebURLList);
+ try {
+ for ( String msg : CConsumer.fetch () ) {
+ logger.debug("Manual Notification Recieved Message " + msg + " from UEB cluster : " + uebURLList.toString());
+ resultJson = msg;
+ if (!msg.contains("UEB Update")){
+ notification = NotificationUnMarshal.notificationJSON(msg);
+ return true;
+ }
+ }
+ }catch (Exception e) {
+ logger.error("Error in Manual CLient UEB notification ", e);
+ }
+ return false;
+ }
}
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 f09b5779c..8f3cf043a 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java
@@ -3,6 +3,7 @@
* PolicyEngineAPI
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -348,7 +349,7 @@ public class StdPolicyEngine {
return deletePolicyImpl(parameters);
}
- public PolicyChangeResponse deletePolicyImpl(final DeletePolicyParameters parameters) throws PolicyException {
+ private PolicyChangeResponse deletePolicyImpl(final DeletePolicyParameters parameters) throws PolicyException {
final StdPolicyChangeResponse response = new StdPolicyChangeResponse();
String body = null;
// Create Request.
@@ -379,7 +380,7 @@ public class StdPolicyEngine {
return getDictionaryItemImpl(parameters);
}
- public DictionaryResponse getDictionaryItemImpl(final DictionaryParameters parameters) throws PolicyException {
+ private DictionaryResponse getDictionaryItemImpl(final DictionaryParameters parameters) throws PolicyException {
final StdDictionaryResponse response = new StdDictionaryResponse();
String body = "{}";
// Create Request.
@@ -450,7 +451,7 @@ public class StdPolicyEngine {
return createUpdateDictionaryItemImpl(parameters, true);
}
- public PolicyChangeResponse createUpdateDictionaryItemImpl(final DictionaryParameters parameters,
+ private PolicyChangeResponse createUpdateDictionaryItemImpl(final DictionaryParameters parameters,
final boolean updateFlag) throws PolicyException {
final String resource = getDictionaryResouceName(updateFlag);
@@ -487,7 +488,7 @@ public class StdPolicyEngine {
return policyEngineImportImpl(importParameters);
}
- public PolicyChangeResponse policyEngineImportImpl(final ImportParameters importParameters) throws PolicyException {
+ private PolicyChangeResponse policyEngineImportImpl(final ImportParameters importParameters) throws PolicyException {
final LinkedMultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
// Create Request.
try {
@@ -530,7 +531,7 @@ public class StdPolicyEngine {
return createUpdatePolicyImpl(policyParameters, true);
}
- public PolicyChangeResponse createUpdatePolicyImpl(final PolicyParameters policyParameters,
+ private PolicyChangeResponse createUpdatePolicyImpl(final PolicyParameters policyParameters,
final boolean updateFlag) throws PolicyException {
final String resource = getPolicyResourceName(updateFlag);
String body = null;
@@ -575,7 +576,7 @@ public class StdPolicyEngine {
}
}
- public DecisionResponse getDecisionImpl(final String onapName, final Map<String, String> decisionAttributes,
+ private DecisionResponse getDecisionImpl(final String onapName, final Map<String, String> decisionAttributes,
final UUID requestID) throws PolicyDecisionException {
String body = null;
// Create Request.
@@ -604,7 +605,7 @@ public class StdPolicyEngine {
}
}
- public Collection<PolicyConfig> getConfigImpl(final ConfigRequestParameters configRequestParameters)
+ private Collection<PolicyConfig> getConfigImpl(final ConfigRequestParameters configRequestParameters)
throws PolicyConfigException {
String body = null;
// Create Request.
@@ -632,51 +633,53 @@ public class StdPolicyEngine {
private ArrayList<PolicyConfig> configResult(final APIPolicyConfigResponse[] response)
throws PolicyConfigException {
final ArrayList<PolicyConfig> result = new ArrayList<>();
- if (response != null) {
- for (final APIPolicyConfigResponse policyConfigResponse : response) {
- final StdPolicyConfig policyConfig = new StdPolicyConfig();
- policyConfig.setConfigStatus(policyConfigResponse.getPolicyConfigMessage());
- policyConfig.setMatchingConditions(policyConfigResponse.getMatchingConditions());
- policyConfig.setPolicyConfigStatus(policyConfigResponse.getPolicyConfigStatus());
- policyConfig.setPolicyName(policyConfigResponse.getPolicyName());
- policyConfig.setPolicyType(policyConfigResponse.getType());
- policyConfig.setPolicyVersion(policyConfigResponse.getPolicyVersion());
- policyConfig.setPolicyType(policyConfigResponse.getPolicyType());
- policyConfig.setResponseAttributes(policyConfigResponse.getResponseAttributes());
- setMatches(policyConfig.getMatchingConditions());
- if (policyConfigResponse.getType() != null) {
- try {
- switch (policyConfigResponse.getType()) {
- case JSON:
- final StringReader reader = new StringReader(policyConfigResponse.getConfig());
- try (final JsonReader jsonReader = Json.createReader(reader)) {
- final JsonObject object = jsonReader.readObject();
- policyConfig.setJsonObject(object);
- }
- break;
- case OTHER:
- policyConfig.setOther(policyConfigResponse.getConfig());
- break;
- case PROPERTIES:
- final Properties props = new Properties();
- props.putAll(policyConfigResponse.getProperty());
- policyConfig.setProperties(props);
- break;
- case XML:
- final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- final DocumentBuilder builder = factory.newDocumentBuilder();
- final StringReader stringReader = new StringReader(policyConfigResponse.getConfig());
- policyConfig.setDocument(builder.parse(new InputSource(stringReader)));
- break;
- }
- } catch (final Exception exception) {
- LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + exception);
- throw new PolicyConfigException(
- XACMLErrorConstants.ERROR_SCHEMA_INVALID + "Unable to parse the config", exception);
+ if (response == null) {
+ return result;
+ }
+
+ for (final APIPolicyConfigResponse policyConfigResponse : response) {
+ final StdPolicyConfig policyConfig = new StdPolicyConfig();
+ policyConfig.setConfigStatus(policyConfigResponse.getPolicyConfigMessage());
+ policyConfig.setMatchingConditions(policyConfigResponse.getMatchingConditions());
+ policyConfig.setPolicyConfigStatus(policyConfigResponse.getPolicyConfigStatus());
+ policyConfig.setPolicyName(policyConfigResponse.getPolicyName());
+ policyConfig.setPolicyType(policyConfigResponse.getType());
+ policyConfig.setPolicyVersion(policyConfigResponse.getPolicyVersion());
+ policyConfig.setPolicyType(policyConfigResponse.getPolicyType());
+ policyConfig.setResponseAttributes(policyConfigResponse.getResponseAttributes());
+ setMatches(policyConfig.getMatchingConditions());
+ if (policyConfigResponse.getType() != null) {
+ try {
+ switch (policyConfigResponse.getType()) {
+ case JSON:
+ final StringReader reader = new StringReader(policyConfigResponse.getConfig());
+ try (final JsonReader jsonReader = Json.createReader(reader)) {
+ final JsonObject object = jsonReader.readObject();
+ policyConfig.setJsonObject(object);
+ }
+ break;
+ case OTHER:
+ policyConfig.setOther(policyConfigResponse.getConfig());
+ break;
+ case PROPERTIES:
+ final Properties props = new Properties();
+ props.putAll(policyConfigResponse.getProperty());
+ policyConfig.setProperties(props);
+ break;
+ case XML:
+ final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ final DocumentBuilder builder = factory.newDocumentBuilder();
+ final StringReader stringReader = new StringReader(policyConfigResponse.getConfig());
+ policyConfig.setDocument(builder.parse(new InputSource(stringReader)));
+ break;
}
+ } catch (final Exception exception) {
+ LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + exception);
+ throw new PolicyConfigException(
+ XACMLErrorConstants.ERROR_SCHEMA_INVALID + "Unable to parse the config", exception);
}
- result.add(policyConfig);
}
+ result.add(policyConfig);
}
return result;
}
@@ -774,7 +777,7 @@ public class StdPolicyEngine {
clientEncoding = encoder.encodeToString((userName + ":" + pass).getBytes(StandardCharsets.UTF_8));
}
- public Collection<String> listConfigImpl(final ConfigRequestParameters listRequestParameters)
+ private Collection<String> listConfigImpl(final ConfigRequestParameters listRequestParameters)
throws PolicyConfigException {
final Collection<String> policyList = new ArrayList<>();
if (junit) {
@@ -792,7 +795,7 @@ public class StdPolicyEngine {
return policyList;
}
- public Collection<PolicyResponse> sendEventImpl(final Map<String, String> eventAttributes, final UUID requestID)
+ private Collection<PolicyResponse> sendEventImpl(final Map<String, String> eventAttributes, final UUID requestID)
throws PolicyEventException {
String body = null;
// Create Request.
@@ -864,7 +867,7 @@ public class StdPolicyEngine {
apiKey = properties.getProperty(UEB_API_KEY_PROP_NAME);
apiSecret = properties.getProperty(UEB_API_SECRET_PROP_NAME);
- setNotificationType(notificationTypeValue, DEFAULT_NOTIFICATION);
+ setNotificationType(notificationTypeValue);
if (serverList == null) {
notificationType.clear();
@@ -872,7 +875,7 @@ public class StdPolicyEngine {
LOGGER.info(
"Properties file doesn't have the NOTIFICATION_SERVERS parameter system will use defualt websockets");
} else {
- notificationURLList = getPropertyValueAsList(serverList.trim(), COMMA);
+ notificationURLList = getPropertyValueAsList(serverList.trim());
}
if (topic != null) {
@@ -907,19 +910,7 @@ public class StdPolicyEngine {
// Check the Keys for PDP_URLs
for (final String propertyKey : prop.stringPropertyNames()) {
if (propertyKey.startsWith(PDP_URL_PROP_NAME)) {
- final String propertyValue = prop.getProperty(propertyKey);
- if (propertyValue == null) {
- throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
- + "Properties file doesn't have the PDP_URL parameter");
- }
- if (propertyValue.contains(SEMICOLLON)) {
- final List<String> pdpDefault = Arrays.asList(propertyValue.split(REGEX));
- for (final String pdpVal : pdpDefault) {
- readPDPParam(pdpVal);
- }
- } else {
- readPDPParam(propertyValue);
- }
+ readPDPPropertyURL(prop, propertyKey);
}
}
if (pdps == null || pdps.isEmpty()) {
@@ -928,13 +919,29 @@ public class StdPolicyEngine {
}
}
- private void setNotificationType(final String propertyValue, final String defaultValue) {
+ private void readPDPPropertyURL(Properties prop, String propertyKey) throws PolicyEngineException {
+ final String propertyValue = prop.getProperty(propertyKey);
+ if (propertyValue == null) {
+ throw new PolicyEngineException(XACMLErrorConstants.ERROR_DATA_ISSUE
+ + "Properties file doesn't have the PDP_URL parameter");
+ }
+ if (propertyValue.contains(SEMICOLLON)) {
+ final List<String> pdpDefault = Arrays.asList(propertyValue.split(REGEX));
+ for (final String pdpVal : pdpDefault) {
+ readPDPParam(pdpVal);
+ }
+ } else {
+ readPDPParam(propertyValue);
+ }
+ }
+
+ private void setNotificationType(final String propertyValue) {
if (propertyValue == null) {
- notificationType.add(defaultValue);
+ notificationType.add(DEFAULT_NOTIFICATION);
LOGGER.info(
"Properties file doesn't have the NOTIFICATION_TYPE parameter system will use defualt websockets");
} else {
- notificationType = getPropertyValueAsList(propertyValue.trim(), COMMA);
+ notificationType = getPropertyValueAsList(propertyValue.trim());
}
}
@@ -992,9 +999,9 @@ public class StdPolicyEngine {
}
}
- private List<String> getPropertyValueAsList(final String propertyValue, final String split) {
- if (propertyValue.contains(split)) {
- return Arrays.asList(propertyValue.split(split));
+ private List<String> getPropertyValueAsList(final String propertyValue) {
+ if (propertyValue.contains(COMMA)) {
+ return Arrays.asList(propertyValue.split(COMMA));
}
final List<String> valuesList = new ArrayList<>();
valuesList.add(propertyValue);
@@ -1087,28 +1094,29 @@ public class StdPolicyEngine {
if (junit) {
return;
}
+ if (pdps == null) {
+ return;
+ }
- if (pdps != null) {
- 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);
- this.registerUEBThread.start();
- this.uebThread = true;
- } else if (notificationType.get(0).equals(DMAAP) && !this.dmaapThread) {
- this.dmaapClientThread = new AutoClientDMAAP(notificationURLList, topic, userName, pass);
- AutoClientDMAAP.setAuto(scheme, handler);
- this.registerDMAAPThread = new Thread(this.dmaapClientThread);
- this.registerDMAAPThread.start();
- this.dmaapThread = true;
- } else {
- if (pdps.get(0) != null) {
- if (AutoClientEnd.getUrl() == null) {
- AutoClientEnd.start(pdps.get(0));
- } else {
- AutoClientEnd.stop();
- AutoClientEnd.start(pdps.get(0));
- }
+ 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);
+ this.registerUEBThread.start();
+ this.uebThread = true;
+ } else if (notificationType.get(0).equals(DMAAP) && !this.dmaapThread) {
+ this.dmaapClientThread = new AutoClientDMAAP(notificationURLList, topic, userName, pass);
+ AutoClientDMAAP.setAuto(scheme, handler);
+ this.registerDMAAPThread = new Thread(this.dmaapClientThread);
+ this.registerDMAAPThread.start();
+ this.dmaapThread = true;
+ } else {
+ if (pdps.get(0) != null) {
+ if (AutoClientEnd.getUrl() == null) {
+ AutoClientEnd.start(pdps.get(0));
+ } else {
+ AutoClientEnd.stop();
+ AutoClientEnd.start(pdps.get(0));
}
}
}
@@ -1227,7 +1235,7 @@ public class StdPolicyEngine {
/*
* Create Config Policy API Implementation
*/
- public String createUpdateConfigPolicyImpl(final String policyName, final String policyDescription,
+ private String createUpdateConfigPolicyImpl(final String policyName, final String policyDescription,
final String onapName, final String configName, final Map<String, String> configAttributes,
final String configType, final String body, final String policyScope, final UUID requestID,
final String riskLevel, final String riskType, final String guard, final String ttlDate,
@@ -1276,7 +1284,7 @@ public class StdPolicyEngine {
/*
* Create Update Config Firewall Policy API implementation
*/
- public String createUpdateConfigFirewallPolicyImpl(final String policyName, final JsonObject firewallJson,
+ private String createUpdateConfigFirewallPolicyImpl(final String policyName, final JsonObject firewallJson,
final String policyScope, final UUID requestID, final String riskLevel, final String riskType,
final String guard, final String ttlDate, final boolean updateFlag) throws PolicyException {
validateParameters(policyName, policyScope);