summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java26
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java2
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java1
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java21
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java11
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java2
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java12
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java1
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java2
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ActionPolicyTest.java3
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicyTest.java3
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java3
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorImplTest.java100
-rw-r--r--ONAP-PAP-REST/src/test/resources/xacml.pap.properties2
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/models/PolicyConfig.java8
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java20
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java36
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java2
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/utils/PolicyApiUtils.java7
-rw-r--r--ONAP-REST/pom.xml5
-rw-r--r--ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ClosedLoopFaultBody.java16
-rw-r--r--ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java553
-rw-r--r--ONAP-REST/src/main/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImpl.java56
-rw-r--r--ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java171
-rw-r--r--ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java95
-rw-r--r--ONAP-REST/src/test/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImplTest.java441
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java2
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java20
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java6
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/conf/HibernateSession.java10
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ActionPolicyController.java2
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java8
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfig.java7
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java8
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyConfig.java14
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java1
-rw-r--r--PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java10
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigBasePolicyClient.java5
-rw-r--r--packages/base/src/files/install/elk/config/elasticsearch.yml5
39 files changed, 1146 insertions, 551 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
index 85d79f74a..d6c298731 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
@@ -40,7 +40,6 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Scanner;
@@ -88,7 +87,6 @@ import org.onap.policy.xacml.api.pap.ONAPPapEngineFactory;
import org.onap.policy.xacml.api.pap.OnapPDP;
import org.onap.policy.xacml.api.pap.OnapPDPGroup;
import org.onap.policy.xacml.api.pap.PAPPolicyEngine;
-import org.onap.policy.xacml.std.pap.StdPAPPolicy;
import org.onap.policy.xacml.std.pap.StdPDP;
import org.onap.policy.xacml.std.pap.StdPDPGroup;
import org.onap.policy.xacml.std.pap.StdPDPItemSetChangeNotifier.StdItemSetChangeListener;
@@ -1421,12 +1419,10 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
//If the selected policy is in the group we must remove the old version of it
LOGGER.info("Removing old version of the policy");
for(PDPPolicy existingPolicy : currentPoliciesInGroup) {
- if (existingPolicy.getName().equals(policy.getName())){
- if (!existingPolicy.getId().equals(policy.getId())) {
- group.removePolicy(existingPolicy);
- LOGGER.info("Removing policy: " + existingPolicy);
- break;
- }
+ if (existingPolicy.getName().equals(policy.getName()) && !existingPolicy.getId().equals(policy.getId())){
+ group.removePolicy(existingPolicy);
+ LOGGER.info("Removing policy: " + existingPolicy);
+ break;
}
}
@@ -1620,12 +1616,10 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
*/
if(apiflag != null){
- // get the request content into a String
- String json = null;
// read the inputStream into a buffer
java.util.Scanner scanner = new java.util.Scanner(request.getInputStream());
scanner.useDelimiter("\\A");
- json = scanner.hasNext() ? scanner.next() : "";
+ String json = scanner.hasNext() ? scanner.next() : "";
scanner.close();
LOGGER.info("PushPolicy API request: " + json);
@@ -1673,7 +1667,9 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
//delete temporary policy file from the bin directory
- Files.deleteIfExists(Paths.get(policy.getId()));
+ if(policy != null) {
+ Files.deleteIfExists(Paths.get(policy.getId()));
+ }
}
} catch (Exception e) {
@@ -2624,10 +2620,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
public UpdatePDPThread(OnapPDP pdp, ONAPLoggingContext loggingContext) {
this.pdp = pdp;
- if (!(loggingContext == null)) {
- if (!(loggingContext.getRequestID() == null) || (loggingContext.getRequestID() == "")) {
+ if ((loggingContext != null) && (loggingContext.getRequestID() != null || loggingContext.getRequestID() == "")) {
this.requestId = loggingContext.getRequestID();
- }
}
this.loggingContext = loggingContext;
}
@@ -2637,7 +2631,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
HttpURLConnection connection = null;
// get a new logging context for the thread
try {
- if (this.loggingContext.equals(null)) {
+ if (this.loggingContext == null) {
loggingContext = new ONAPLoggingContext(baseLoggingContext);
}
} catch (Exception e) {
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
index cf183114c..70745b9b3 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
@@ -69,7 +69,6 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.onap.policy.common.logging.eelf.MessageCodes;
@@ -93,7 +92,6 @@ import org.onap.policy.xacml.api.pap.OnapPDPGroup;
import org.onap.policy.xacml.api.pap.PAPPolicyEngine;
import org.onap.policy.xacml.std.pap.StdPDPGroup;
import org.onap.policy.xacml.std.pap.StdPDPPolicy;
-import org.onap.policy.xacml.util.XACMLPolicyScanner;
import org.onap.policy.xacml.util.XACMLPolicyWriter;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java
index c7148213d..c8b8c6a05 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/daoimpl/CommonClassDaoImpl.java
@@ -45,7 +45,6 @@ import org.onap.policy.rest.jpa.PolicyRoles;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
-import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Service("CommonClassDao")
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java
index ee6fd0568..430f9cd65 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElasticSearchPolicyUpdate.java
@@ -177,13 +177,10 @@ public class ElasticSearchPolicyUpdate {
while(configResult.next()){
String configBody = configResult.getString("configbody");
String configType = configResult.getString("configtype");
- if("JSON".equalsIgnoreCase(configType)){
- policyDataString.append("\"jsonBodyData\":"+configBody+",\"configType\":\""+configType+"\",");
- }else if("OTHER".equalsIgnoreCase(configType)){
- if(configBody!=null){
- configBody= configBody.replaceAll("\"", "");
- policyDataString.append("\"jsonBodyData\":\""+configBody+"\",\"configType\":\""+configType+"\",");
- }
+ if(configBody!=null){
+ configBody = configBody.replace("null", "\"\"");
+ configBody= configBody.replace("\"", "\\\"");
+ policyDataString.append("\"jsonBodyData\":\""+configBody+"\",\"configType\":\""+configType+"\",");
}
}
configResult.close();
@@ -197,7 +194,9 @@ public class ElasticSearchPolicyUpdate {
ResultSet actionResult = pstmt.executeQuery();
while(actionResult.next()){
String actionBody = actionResult.getString("actionbody");
- policyDataString.append("\"jsonBodyData\":"+actionBody+",");
+ actionBody = actionBody.replace("null", "\"\"");
+ actionBody = actionBody.replace("\"", "\\\"");
+ policyDataString.append("\"jsonBodyData\":\""+actionBody+"\",");
}
actionResult.close();
}
@@ -205,13 +204,11 @@ public class ElasticSearchPolicyUpdate {
String _id = policyWithScopeName;
- policyDataString.append(constructPolicyData(policyData, policyDataString));
-
- String dataString = policyDataString.toString();
+ String dataString = constructPolicyData(policyData, policyDataString);
dataString = dataString.substring(0, dataString.length()-1);
dataString = dataString.trim().replace(System.getProperty("line.separator"), "") + "}";
dataString = dataString.replace("null", "\"\"");
- dataString = dataString.replaceAll(" ", "").replaceAll("\n", "");
+ dataString = dataString.replaceAll("\n", "");
try{
Gson gson = new Gson();
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java
index 88f9e2c87..9091d79ed 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/ElkConnectorImpl.java
@@ -101,6 +101,9 @@ public class ElkConnectorImpl implements ElkConnector{
throw e;
}
}
+ private boolean isAlphaNumeric(String query){
+ return query.matches("[a-zA-Z_0-9]+");
+ }
@Override
public JestResult search(PolicyIndexType type, String text) throws IllegalStateException, IllegalArgumentException {
@@ -112,6 +115,10 @@ public class ElkConnectorImpl implements ElkConnector{
throw new IllegalArgumentException("No search string provided");
}
+ if(!isAlphaNumeric(text)){
+ throw new IllegalArgumentException("Search must be alpha numeric");
+ }
+
QueryStringQueryBuilder mQ = QueryBuilders.queryStringQuery("*"+text+"*");
SearchSourceBuilder searchSourceBuilder =
new SearchSourceBuilder().query(mQ);
@@ -198,6 +205,10 @@ public class ElkConnectorImpl implements ElkConnector{
return search(type, text);
}
+ if(!isAlphaNumeric(text)){
+ throw new IllegalArgumentException("Search must be alpha numeric");
+ }
+
String matches_s = "";
matches_s = "{\n" +
" \"size\" : "+ ElkConnectorImpl.QUERY_MAXRECORDS + ",\n" +
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java
index 3e065ff05..b624f3bf0 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticData.java
@@ -113,7 +113,7 @@ public class PolicyElasticData {
private YAMLParams yamlparams;
public PolicyElasticData(PolicyRestAdapter policyData) {
- this.scope = policyData.getDomain();
+ this.scope = policyData.getDomainDir();
this.policyType = policyData.getPolicyType();
this.configPolicyType = policyData.getConfigPolicyType();
this.configBodyData = policyData.getConfigBodyData();
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java
index 78da2a572..77e45e30d 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/elk/client/PolicyElasticSearchController.java
@@ -231,7 +231,7 @@ public class PolicyElasticSearchController{
if(searchData.getPolicyType() != null && "closedLoop".equals(searchData.getPolicyType())){
searchKeyValue.put("jsonBodyData", "*" +entry[1] +"*");
}else{
- searchKeyValue.put(entry[0], entry[1]);
+ searchText = entry[1];
}
}
}
@@ -265,13 +265,13 @@ public class PolicyElasticSearchController{
searchKeyValue.put("jsonBodyData."+d2Service+"", "true");
}
if(searchData.getVnfType() != null){
- searchKeyValue.put("jsonBodyData", "*" +searchData.getVnfType() +"*");
+ searchKeyValue.put("jsonBodyData", "*"+searchData.getVnfType()+"*");
}
if(searchData.getPolicyStatus() != null){
- searchKeyValue.put("jsonBodyData", "*" +searchData.getPolicyStatus()+"*");
+ searchKeyValue.put("jsonBodyData", "*"+searchData.getPolicyStatus()+"*");
}
if(searchData.getVproAction() != null){
- searchKeyValue.put("jsonBodyData", "*" +searchData.getVproAction()+"*");
+ searchKeyValue.put("jsonBodyData", "*"+searchData.getVproAction()+"*");
}
if(searchData.getServiceType() != null){
searchKeyValue.put("serviceType", searchData.getServiceType());
@@ -288,8 +288,10 @@ public class PolicyElasticSearchController{
type = ElkConnector.PolicyIndexType.decision;
}else if(policyType.equalsIgnoreCase("config")){
type = ElkConnector.PolicyIndexType.config;
- }else {
+ }else if(policyType.equalsIgnoreCase("closedloop")){
type = ElkConnector.PolicyIndexType.closedloop;
+ }else{
+ type = ElkConnector.PolicyIndexType.all;
}
}else{
type = ElkConnector.PolicyIndexType.all;
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java
index e7680c3e2..9be4b0342 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/SavePolicyHandler.java
@@ -130,7 +130,6 @@ public class SavePolicyHandler {
policyAdapter.setDynamicSettingsMap(policy.getDynamicSettingsMap());
policyAdapter.setRuleProvider(policy.getProviderComboBox());
policyAdapter.setDomainDir(policyAdapter.getPolicyScope());
- policyAdapter.setDomain(policyAdapter.getPolicyScope());
policyAdapter.setRainydayMap(policy.getTreatments());
return policyAdapter;
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
index 2af8a6ee1..76fe4ae5d 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java
@@ -200,7 +200,7 @@ public class PolicyCreation extends AbstractPolicyCreation{
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.addHeader("error", body);
response.addHeader("message", policyData.getPolicyName() + " does not exist on the PAP and cannot be updated.");
- return new ResponseEntity<String>(body, status);
+ return new ResponseEntity<>(body, status);
}
version = 1;
if(userId == null){
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ActionPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ActionPolicyTest.java
index b93cca36d..55879ca53 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ActionPolicyTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/ActionPolicyTest.java
@@ -69,8 +69,7 @@ public class ActionPolicyTest {
policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
policyAdapter.setPolicyType("Action");
policyAdapter.setEditPolicy(false);
- policyAdapter.setDomainDir("src/test/resources/client.properties");
- policyAdapter.setDomain("Test");
+ policyAdapter.setDomainDir("Test");
policyAdapter.setNewFileName("Test.Action_junitTest.1.xml");
policyAdapter.setHighestVersion(1);
policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicyTest.java
index 3854ab984..caa5707cc 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicyTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicyTest.java
@@ -72,8 +72,7 @@ public class DecisionPolicyTest {
policyAdapter.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
policyAdapter.setPolicyType("Decision");
policyAdapter.setEditPolicy(false);
- policyAdapter.setDomainDir("src/test/resources/client.properties");
- policyAdapter.setDomain("Test");
+ policyAdapter.setDomainDir("Test");
policyAdapter.setNewFileName("/src/test/resources/Test/client.properties");
policyAdapter.setHighestVersion(1);
policyAdapter.setPolicyID("urn:xacml:policy:id:"+UUID.randomUUID());
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java
index 99285e77f..a2c6ddf4e 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicyTest.java
@@ -63,8 +63,7 @@ public class FirewallConfigPolicyTest {
policyAdapter.setPolicyType("Config");
policyAdapter.setConfigPolicyType("Firewall Config");
policyAdapter.setEditPolicy(false);
- policyAdapter.setDomainDir("src/test/resources/client.properties");
- policyAdapter.setDomain("Test");
+ policyAdapter.setDomainDir("Test");
policyAdapter.setNewFileName("Test.Config_FW_junitTest.1.xml");
policyAdapter.setHighestVersion(1);
policyAdapter.setVersion(String.valueOf(1));
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorImplTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorImplTest.java
new file mode 100644
index 000000000..c0f59273c
--- /dev/null
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/elk/ElkConnectorImplTest.java
@@ -0,0 +1,100 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PAP-REST
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.pap.xacml.rest.elk;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import io.searchbox.client.JestResult;
+
+import java.lang.reflect.Method;
+
+import org.junit.Test;
+import org.onap.policy.pap.xacml.rest.elk.client.ElkConnector.PolicyIndexType;
+import org.onap.policy.pap.xacml.rest.elk.client.ElkConnectorImpl;
+
+public class ElkConnectorImplTest {
+
+ @Test
+ public void isAlphaNumericTest() {
+ try {
+ Method method = ElkConnectorImpl.class.getDeclaredMethod("isAlphaNumeric", String.class);
+ method.setAccessible(true);
+ assertTrue((boolean) method.invoke(new ElkConnectorImpl(), "abc123"));
+ assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123*"));
+ assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123{}"));
+ assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123\n"));
+ assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123<"));
+ assertFalse((boolean) method.invoke(new ElkConnectorImpl(), "abc123:"));
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ @Test
+ public void searchTest(){
+ JestResult r1=null, r2=null, r3=null, r4=null;
+
+ // Should always work if the above test passes and ELK server is up
+ try{
+ r1 = new ElkConnectorImpl().search(PolicyIndexType.decision, "abc123");
+ } catch (Exception e) {
+ // ELK server is down. Don't continue the test
+ if(e instanceof IllegalStateException){
+ return;
+ }
+ fail();
+ }
+
+ // Should always work
+ try{
+ r2 = new ElkConnectorImpl().search(PolicyIndexType.decision, "The_quick_brown_fox_jumps_over_the_lazy_dog");
+ } catch (Exception e) {
+ fail();
+ }
+
+ // Should throw exception
+ try{
+ r3 = new ElkConnectorImpl().search(PolicyIndexType.decision, "abc123{}");
+ } catch (Exception e) {
+ if(! (e instanceof IllegalArgumentException)){
+ fail();
+ }
+ }
+
+ // Should throw exception
+ try{
+ r4 = new ElkConnectorImpl().search(PolicyIndexType.decision, "The quick brown fox jumps over the lazy dog");
+ } catch (Exception e) {
+ if(! (e instanceof IllegalArgumentException)){
+ fail();
+ }
+ }
+
+ assertNotNull(r1);
+ assertNotNull(r2);
+ assertNull(r3);
+ assertNull(r4);
+ }
+
+}
diff --git a/ONAP-PAP-REST/src/test/resources/xacml.pap.properties b/ONAP-PAP-REST/src/test/resources/xacml.pap.properties
index f886435bf..c523d39ab 100644
--- a/ONAP-PAP-REST/src/test/resources/xacml.pap.properties
+++ b/ONAP-PAP-REST/src/test/resources/xacml.pap.properties
@@ -71,7 +71,7 @@ xacml.rest.config.webapps=src/test/resources/webapps/
#xacml.rest.pap.run.audit.flag=true
#Turn the audit off to not synchronize the DB/file system
#xacml.rest.pap.run.audit.flag=false
-xacml.rest.pap.run.audit.flag=true
+xacml.rest.pap.run.audit.flag=false
#Audit will synchronize the file system to match the contents of the DB
#xacml.rest.pap.filesystem.audit=true
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/models/PolicyConfig.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/models/PolicyConfig.java
index 391ef6c8a..3614bac08 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/models/PolicyConfig.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/models/PolicyConfig.java
@@ -24,6 +24,7 @@ import io.swagger.annotations.ApiModel;
import java.util.Map;
import org.onap.policy.api.PolicyConfigStatus;
+import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.api.PolicyType;
import org.onap.policy.models.APIConfigResponse;
@@ -34,6 +35,7 @@ public class PolicyConfig implements APIConfigResponse{
private PolicyType type;
private String config;
private String policyName;
+ private PolicyConfigType policyType;
private String policyVersion;
private Map<String, String> matchingConditions;
private Map<String, String> responseAttributes;
@@ -92,4 +94,10 @@ public class PolicyConfig implements APIConfigResponse{
public Map<String,String> getResponseAttributes(){
return responseAttributes;
}
+ public PolicyConfigType getPolicyType() {
+ return policyType;
+ }
+ public void setPolicyType(PolicyConfigType policyType) {
+ this.policyType = policyType;
+ }
}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java
index 483e13c23..f91f6e2f2 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java
@@ -23,7 +23,6 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
-import org.glassfish.jersey.spi.Contract;
import org.onap.policy.api.PolicyException;
import org.onap.policy.api.PolicyParameters;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
@@ -34,7 +33,6 @@ import org.onap.policy.rest.util.PolicyValidation;
import org.onap.policy.rest.util.PolicyValidationRequestWrapper;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.springframework.http.HttpStatus;
-import org.springframework.stereotype.Controller;
import com.google.common.base.Strings;
@@ -244,17 +242,13 @@ public class CreateUpdatePolicyServiceImpl implements CreateUpdatePolicyService
return false;
}
- if(policyParameters.getPolicyClass() != null){
- if ("Config".equals(policyParameters.getPolicyClass().toString())){
- String policyConfigType = policyParameters.getPolicyConfigType().toString();
- if(!"BRMS_Param".equalsIgnoreCase(policyConfigType)){
- if(Strings.isNullOrEmpty(policyParameters.getConfigBody())){
- message = XACMLErrorConstants.ERROR_DATA_ISSUE + "ConfigBody: No Config Body given";
- LOGGER.error("Common validation did not return success: " + message);
- return false;
- }
- }
- }
+ if(policyParameters.getPolicyClass() != null && "Config".equals(policyParameters.getPolicyClass().toString())){
+ String policyConfigType = policyParameters.getPolicyConfigType().toString();
+ if(!"BRMS_Param".equalsIgnoreCase(policyConfigType) && Strings.isNullOrEmpty(policyParameters.getConfigBody())){
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE + "ConfigBody: No Config Body given";
+ LOGGER.error("Common validation did not return success: " + message);
+ return false;
+ }
}
try {
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java
index 58d5c8f31..6e6badf6a 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetConfigService.java
@@ -36,6 +36,7 @@ import javax.json.JsonObjectBuilder;
import org.onap.policy.api.ConfigRequestParameters;
import org.onap.policy.api.PolicyConfigException;
import org.onap.policy.api.PolicyConfigStatus;
+import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.pdp.rest.api.models.PDPResponse;
@@ -143,11 +144,46 @@ public class GetConfigService {
policyConfig.setProperty(stdStatus.getProperty());
policyConfig.setResponseAttributes(stdStatus.getResponseAttributes());
policyConfig.setType(stdStatus.getType());
+ policyConfig.setPolicyType(getPolicyType(stdStatus.getPolicyName()));
result.add(policyConfig);
}
}
return result;
}
+
+ // Returns PolicyConfigType based on policyName.
+ private PolicyConfigType getPolicyType(String policyName) {
+ if(policyName != null) {
+ String name = policyName;
+ if(name.endsWith(".xml")){
+ name = name.substring(0, name.substring(0, name.lastIndexOf('.')).lastIndexOf('.'));
+ }
+ name = name.substring(name.lastIndexOf('.')+1);
+ PolicyConfigType extType = extendedServices(name);
+ if(extType != null) return extType;
+ if (name.startsWith("Config_BRMS_Param_")) {
+ return PolicyConfigType.BRMS_PARAM;
+ } else if(name.startsWith("Config_BRMS_Raw_")) {
+ return PolicyConfigType.BRMS_RAW;
+ } else if(name.startsWith("Config_Fault_")) {
+ return PolicyConfigType.ClosedLoop_Fault;
+ } else if(name.startsWith("Config_FW_")) {
+ return PolicyConfigType.Firewall;
+ } else if(name.startsWith("Config_PM_")) {
+ return PolicyConfigType.ClosedLoop_PM;
+ } else if(name.startsWith("Config_MS_")) {
+ return PolicyConfigType.MicroService;
+ } else if(name.startsWith("Config_")) {
+ return PolicyConfigType.Base;
+ }
+ }
+ return null;
+ }
+
+ public PolicyConfigType extendedServices(String policyName) {
+ // For extended services policyName will be required.
+ return null;
+ }
// Filter logic required for results comparing with requests.
private Collection<PolicyConfig> filterResults(
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java
index 773f0d86a..a3d18b3e6 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PushPolicyService.java
@@ -26,12 +26,10 @@ import org.onap.policy.api.PushPolicyParameters;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
import org.onap.policy.xacml.api.XACMLErrorConstants;
-import org.onap.policy.xacml.std.pap.StdPAPPolicy;
import org.onap.policy.xacml.std.pap.StdPDPPolicy;
import org.springframework.http.HttpStatus;
import com.att.research.xacml.api.pap.PAPException;
-import com.att.research.xacml.api.pap.PDPPolicy;
public class PushPolicyService {
private static final Logger LOGGER = FlexLogger.getLogger(PushPolicyService.class.getName());
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/utils/PolicyApiUtils.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/utils/PolicyApiUtils.java
index 472d3aa95..197db26c1 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/utils/PolicyApiUtils.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/utils/PolicyApiUtils.java
@@ -62,8 +62,7 @@ public class PolicyApiUtils {
public static String formatResponse(StringBuilder responseString){
LOGGER.info("Formatting response message from Policy Validator");
- String response = null;
- response = responseString.toString().replace("<br>", " | ");
+ String response = responseString.toString().replace("<br>", " | ");
response = response.replaceAll("(<b>|<\\/b>|<br>|<i>|<\\/i>|@#)", "");
return response;
@@ -126,8 +125,8 @@ public class PolicyApiUtils {
|| "PUT".equals(json.getString("method").trim())
|| "POST".equals(json.getString("method").trim())){
- message = SUCCESS;
-
+ //Successful Validation
+
}else{
message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Method value.";
return message;
diff --git a/ONAP-REST/pom.xml b/ONAP-REST/pom.xml
index 325308178..499ec195f 100644
--- a/ONAP-REST/pom.xml
+++ b/ONAP-REST/pom.xml
@@ -136,6 +136,11 @@
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>${springframework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.version}</version>
</dependency>
diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ClosedLoopFaultBody.java b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ClosedLoopFaultBody.java
index 3d85f9f93..73909d923 100644
--- a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ClosedLoopFaultBody.java
+++ b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ClosedLoopFaultBody.java
@@ -221,22 +221,6 @@ public class ClosedLoopFaultBody {
this.verificationSignatures = verificationSignatures;
}
- /*public ArrayList<String> getD2Services() {
- return d2Services;
- }
-
- public void setD2Services(ArrayList<String> d2Services) {
- this.d2Services = d2Services;
- }
-
- public ArrayList<String> getSiteNames() {
- return siteNames;
- }
-
- public void setSiteNames(ArrayList<String> siteNames) {
- this.siteNames = siteNames;
- }*/
-
public boolean isvDNS() {
return vDNS;
}
diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java
index 6de0c9b78..de424683d 100644
--- a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java
+++ b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java
@@ -342,12 +342,6 @@ public class PolicyRestAdapter {
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}
- public String getUserGitPath() {
- return gitPath;
- }
- public void setUserGitPath(String gitPath) {
- this.gitPath = gitPath;
- }
public boolean isValidData() {
return isValidData;
}
@@ -629,281 +623,274 @@ public class PolicyRestAdapter {
public void setNewFileName(String newFileName) {
this.newFileName = newFileName;
}
-
- public String getDomain() {
- return domain;
- }
- public void setDomain(String domain) {
- this.domain = domain;
- }
- public OnapName getOnapNameField() {
- return onapNameField;
- }
- public void setOnapNameField(OnapName onapNameField) {
- this.onapNameField = onapNameField;
- }
- public Object getJsonBodyData() {
- return jsonBodyData;
- }
- public void setJsonBodyData(Object jsonBodyData) {
- this.jsonBodyData = jsonBodyData;
- }
- public String getDirPath() {
- return dirPath;
- }
- public void setDirPath(String dirPath) {
- this.dirPath = dirPath;
- }
- public String getConfigBodyPath() {
- return configBodyPath;
- }
- public void setConfigBodyPath(String configBodyPath) {
- this.configBodyPath = configBodyPath;
- }
- public ArrayList<Object> getAttributes() {
- return attributes;
- }
- public void setAttributes(ArrayList<Object> attributes) {
- this.attributes = attributes;
- }
- public ArrayList<Object> getSettings() {
- return settings;
- }
- public void setSettings(ArrayList<Object> settings) {
- this.settings = settings;
- }
- public ArrayList<Object> getRuleAlgorithmschoices() {
- return ruleAlgorithmschoices;
- }
- public void setRuleAlgorithmschoices(ArrayList<Object> ruleAlgorithmschoices) {
- this.ruleAlgorithmschoices = ruleAlgorithmschoices;
- }
- public LinkedHashMap<?, ?> getServiceTypePolicyName() {
- return serviceTypePolicyName;
- }
- public void setServiceTypePolicyName(LinkedHashMap<?, ?> serviceTypePolicyName) {
- this.serviceTypePolicyName = serviceTypePolicyName;
- }
- public LinkedHashMap<?, ?> getVerticaMetrics() {
- return verticaMetrics;
- }
- public void setVerticaMetrics(LinkedHashMap<?, ?> verticaMetrics) {
- this.verticaMetrics = verticaMetrics;
- }
- public LinkedHashMap<?, ?> getDescription() {
- return description;
- }
- public void setDescription(LinkedHashMap<?, ?> description) {
- this.description = description;
- }
- public LinkedHashMap<?, ?> getAttributeFields() {
- return attributeFields;
- }
- public void setAttributeFields(LinkedHashMap<?, ?> attributeFields) {
- this.attributeFields = attributeFields;
- }
- public String getClearTimeOut() {
- return clearTimeOut;
- }
- public void setClearTimeOut(String clearTimeOut) {
- this.clearTimeOut = clearTimeOut;
- }
- public String getTrapMaxAge() {
- return trapMaxAge;
- }
- public void setTrapMaxAge(String trapMaxAge) {
- this.trapMaxAge = trapMaxAge;
- }
- public String getVerificationclearTimeOut() {
- return verificationclearTimeOut;
- }
- public void setVerificationclearTimeOut(String verificationclearTimeOut) {
- this.verificationclearTimeOut = verificationclearTimeOut;
- }
- public Map<String, String> getDynamicLayoutMap() {
- return dynamicLayoutMap;
- }
- public void setDynamicLayoutMap(Map<String, String> dynamicLayoutMap) {
- this.dynamicLayoutMap = dynamicLayoutMap;
- }
- public String getFwPolicyType() {
- return fwPolicyType;
- }
- public void setFwPolicyType(String fwPolicyType) {
- this.fwPolicyType = fwPolicyType;
- }
- public ArrayList<Object> getFwattributes() {
- return fwattributes;
- }
- public void setFwattributes(ArrayList<Object> fwattributes) {
- this.fwattributes = fwattributes;
- }
- public String getParentForChild() {
- return parentForChild;
- }
- public void setParentForChild(String parentForChild) {
- this.parentForChild = parentForChild;
- }
- public String getRuleName() {
- return ruleName;
- }
- public void setRuleName(String ruleName) {
- this.ruleName = ruleName;
- }
- public LinkedHashMap<?, ?> getRuleData() {
- return ruleData;
- }
- public void setRuleData(LinkedHashMap<?, ?> ruleData) {
- this.ruleData = ruleData;
- }
- public LinkedHashMap<?, ?> getRuleListData() {
- return ruleListData;
- }
- public void setRuleListData(LinkedHashMap<?, ?> ruleListData) {
- this.ruleListData = ruleListData;
- }
- public String getSecurityZone() {
- return securityZone;
- }
- public void setSecurityZone(String securityZone) {
- this.securityZone = securityZone;
- }
- public String getActionAttributeValue() {
- return actionAttributeValue;
- }
- public void setActionAttributeValue(String actionAttributeValue) {
- this.actionAttributeValue = actionAttributeValue;
- }
- public String getRuleProvider() {
- return ruleProvider;
- }
- public void setRuleProvider(String ruleProvider) {
- this.ruleProvider = ruleProvider;
- }
- public String getMsLocation() {
- return msLocation;
- }
- public void setMsLocation(String msLocation) {
- this.msLocation = msLocation;
- }
- public Map<String,String> getDrlRuleAndUIParams() {
- return drlRuleAndUIParams;
- }
- public void setDrlRuleAndUIParams(Map<String,String> drlRuleAndUIParams) {
- this.drlRuleAndUIParams = drlRuleAndUIParams;
- }
- public String getActionBody() {
- return actionBody;
- }
- public void setActionBody(String actionBody) {
- this.actionBody = actionBody;
- }
- public String getActionDictHeader() {
- return actionDictHeader;
- }
- public void setActionDictHeader(String actionDictHeader) {
- this.actionDictHeader = actionDictHeader;
- }
- public String getActionDictType() {
- return actionDictType;
- }
- public void setActionDictType(String actionDictType) {
- this.actionDictType = actionDictType;
- }
- public String getActionDictUrl() {
- return actionDictUrl;
- }
- public void setActionDictUrl(String actionDictUrl) {
- this.actionDictUrl = actionDictUrl;
- }
- public String getActionDictMethod() {
- return actionDictMethod;
- }
- public void setActionDictMethod(String actionDictMethod) {
- this.actionDictMethod = actionDictMethod;
- }
- public String getClWarning() {
- return clWarning;
- }
- public void setClWarning(String clWarning) {
- this.clWarning = clWarning;
- }
- public String getNewCLName() {
- return newCLName;
- }
- public void setNewCLName(String newCLName) {
- this.newCLName = newCLName;
- }
- public String getExistingCLName() {
- return existingCLName;
- }
- public void setExistingCLName(String existingCLName) {
- this.existingCLName = existingCLName;
- }
- public YAMLParams getYamlparams() {
- return yamlparams;
- }
- public void setYamlparams(YAMLParams yamlparams) {
- this.yamlparams = yamlparams;
- }
- /**
- * @return the rainyday
- */
- public RainyDayParams getRainyday() {
- return rainyday;
- }
- /**
- * @param rainyday the rainyday to set
- */
- public void setRainyday(RainyDayParams rainyday) {
- this.rainyday = rainyday;
- }
- /**
- * @return the errorCodeList
- */
- public List<String> getErrorCodeList() {
- return errorCodeList;
- }
- /**
- * @param errorCodeList the errorCodeList to set
- */
- public void setErrorCodeList(List<String> errorCodeList) {
- this.errorCodeList = errorCodeList;
- }
- /**
- * @return the treatmentList
- */
- public List<String> getTreatmentList() {
- return treatmentList;
- }
- /**
- * @param treatmentList the treatmentList to set
- */
- public void setTreatmentList(List<String> treatmentList) {
- this.treatmentList = treatmentList;
- }
- /**
- * @return the rainydayMap
- */
- public Map<String,String> getRainydayMap() {
- return rainydayMap;
- }
- /**
- * @param rainydayMap the rainydayMap to set
- */
- public void setRainydayMap(Map<String,String> rainydayMap) {
- this.rainydayMap = rainydayMap;
- }
- /**
- * @return the policyJSON
- */
- public Object getPolicyJSON() {
- return policyJSON;
- }
- /**
- * @param policyJSON the policyJSON to set
- */
- public void setPolicyJSON(Object policyJSON) {
- this.policyJSON = policyJSON;
- }
+ public OnapName getOnapNameField() {
+ return onapNameField;
+ }
+ public void setOnapNameField(OnapName onapNameField) {
+ this.onapNameField = onapNameField;
+ }
+ public Object getJsonBodyData() {
+ return jsonBodyData;
+ }
+ public void setJsonBodyData(Object jsonBodyData) {
+ this.jsonBodyData = jsonBodyData;
+ }
+ public String getDirPath() {
+ return dirPath;
+ }
+ public void setDirPath(String dirPath) {
+ this.dirPath = dirPath;
+ }
+ public String getConfigBodyPath() {
+ return configBodyPath;
+ }
+ public void setConfigBodyPath(String configBodyPath) {
+ this.configBodyPath = configBodyPath;
+ }
+ public ArrayList<Object> getAttributes() {
+ return attributes;
+ }
+ public void setAttributes(ArrayList<Object> attributes) {
+ this.attributes = attributes;
+ }
+ public ArrayList<Object> getSettings() {
+ return settings;
+ }
+ public void setSettings(ArrayList<Object> settings) {
+ this.settings = settings;
+ }
+ public ArrayList<Object> getRuleAlgorithmschoices() {
+ return ruleAlgorithmschoices;
+ }
+ public void setRuleAlgorithmschoices(ArrayList<Object> ruleAlgorithmschoices) {
+ this.ruleAlgorithmschoices = ruleAlgorithmschoices;
+ }
+ public LinkedHashMap<?, ?> getServiceTypePolicyName() {
+ return serviceTypePolicyName;
+ }
+ public void setServiceTypePolicyName(LinkedHashMap<?, ?> serviceTypePolicyName) {
+ this.serviceTypePolicyName = serviceTypePolicyName;
+ }
+ public LinkedHashMap<?, ?> getVerticaMetrics() {
+ return verticaMetrics;
+ }
+ public void setVerticaMetrics(LinkedHashMap<?, ?> verticaMetrics) {
+ this.verticaMetrics = verticaMetrics;
+ }
+ public LinkedHashMap<?, ?> getDescription() {
+ return description;
+ }
+ public void setDescription(LinkedHashMap<?, ?> description) {
+ this.description = description;
+ }
+ public LinkedHashMap<?, ?> getAttributeFields() {
+ return attributeFields;
+ }
+ public void setAttributeFields(LinkedHashMap<?, ?> attributeFields) {
+ this.attributeFields = attributeFields;
+ }
+ public String getClearTimeOut() {
+ return clearTimeOut;
+ }
+ public void setClearTimeOut(String clearTimeOut) {
+ this.clearTimeOut = clearTimeOut;
+ }
+ public String getTrapMaxAge() {
+ return trapMaxAge;
+ }
+ public void setTrapMaxAge(String trapMaxAge) {
+ this.trapMaxAge = trapMaxAge;
+ }
+ public String getVerificationclearTimeOut() {
+ return verificationclearTimeOut;
+ }
+ public void setVerificationclearTimeOut(String verificationclearTimeOut) {
+ this.verificationclearTimeOut = verificationclearTimeOut;
+ }
+ public Map<String, String> getDynamicLayoutMap() {
+ return dynamicLayoutMap;
+ }
+ public void setDynamicLayoutMap(Map<String, String> dynamicLayoutMap) {
+ this.dynamicLayoutMap = dynamicLayoutMap;
+ }
+ public String getFwPolicyType() {
+ return fwPolicyType;
+ }
+ public void setFwPolicyType(String fwPolicyType) {
+ this.fwPolicyType = fwPolicyType;
+ }
+ public ArrayList<Object> getFwattributes() {
+ return fwattributes;
+ }
+ public void setFwattributes(ArrayList<Object> fwattributes) {
+ this.fwattributes = fwattributes;
+ }
+ public String getParentForChild() {
+ return parentForChild;
+ }
+ public void setParentForChild(String parentForChild) {
+ this.parentForChild = parentForChild;
+ }
+ public String getRuleName() {
+ return ruleName;
+ }
+ public void setRuleName(String ruleName) {
+ this.ruleName = ruleName;
+ }
+ public LinkedHashMap<?, ?> getRuleData() {
+ return ruleData;
+ }
+ public void setRuleData(LinkedHashMap<?, ?> ruleData) {
+ this.ruleData = ruleData;
+ }
+ public LinkedHashMap<?, ?> getRuleListData() {
+ return ruleListData;
+ }
+ public void setRuleListData(LinkedHashMap<?, ?> ruleListData) {
+ this.ruleListData = ruleListData;
+ }
+ public String getSecurityZone() {
+ return securityZone;
+ }
+ public void setSecurityZone(String securityZone) {
+ this.securityZone = securityZone;
+ }
+ public String getActionAttributeValue() {
+ return actionAttributeValue;
+ }
+ public void setActionAttributeValue(String actionAttributeValue) {
+ this.actionAttributeValue = actionAttributeValue;
+ }
+ public String getRuleProvider() {
+ return ruleProvider;
+ }
+ public void setRuleProvider(String ruleProvider) {
+ this.ruleProvider = ruleProvider;
+ }
+ public String getMsLocation() {
+ return msLocation;
+ }
+ public void setMsLocation(String msLocation) {
+ this.msLocation = msLocation;
+ }
+ public Map<String,String> getDrlRuleAndUIParams() {
+ return drlRuleAndUIParams;
+ }
+ public void setDrlRuleAndUIParams(Map<String,String> drlRuleAndUIParams) {
+ this.drlRuleAndUIParams = drlRuleAndUIParams;
+ }
+ public String getActionBody() {
+ return actionBody;
+ }
+ public void setActionBody(String actionBody) {
+ this.actionBody = actionBody;
+ }
+ public String getActionDictHeader() {
+ return actionDictHeader;
+ }
+ public void setActionDictHeader(String actionDictHeader) {
+ this.actionDictHeader = actionDictHeader;
+ }
+ public String getActionDictType() {
+ return actionDictType;
+ }
+ public void setActionDictType(String actionDictType) {
+ this.actionDictType = actionDictType;
+ }
+ public String getActionDictUrl() {
+ return actionDictUrl;
+ }
+ public void setActionDictUrl(String actionDictUrl) {
+ this.actionDictUrl = actionDictUrl;
+ }
+ public String getActionDictMethod() {
+ return actionDictMethod;
+ }
+ public void setActionDictMethod(String actionDictMethod) {
+ this.actionDictMethod = actionDictMethod;
+ }
+ public String getClWarning() {
+ return clWarning;
+ }
+ public void setClWarning(String clWarning) {
+ this.clWarning = clWarning;
+ }
+ public String getNewCLName() {
+ return newCLName;
+ }
+ public void setNewCLName(String newCLName) {
+ this.newCLName = newCLName;
+ }
+ public String getExistingCLName() {
+ return existingCLName;
+ }
+ public void setExistingCLName(String existingCLName) {
+ this.existingCLName = existingCLName;
+ }
+ public YAMLParams getYamlparams() {
+ return yamlparams;
+ }
+ public void setYamlparams(YAMLParams yamlparams) {
+ this.yamlparams = yamlparams;
+ }
+ /**
+ * @return the rainyday
+ */
+ public RainyDayParams getRainyday() {
+ return rainyday;
+ }
+ /**
+ * @param rainyday the rainyday to set
+ */
+ public void setRainyday(RainyDayParams rainyday) {
+ this.rainyday = rainyday;
+ }
+ /**
+ * @return the errorCodeList
+ */
+ public List<String> getErrorCodeList() {
+ return errorCodeList;
+ }
+ /**
+ * @param errorCodeList the errorCodeList to set
+ */
+ public void setErrorCodeList(List<String> errorCodeList) {
+ this.errorCodeList = errorCodeList;
+ }
+ /**
+ * @return the treatmentList
+ */
+ public List<String> getTreatmentList() {
+ return treatmentList;
+ }
+ /**
+ * @param treatmentList the treatmentList to set
+ */
+ public void setTreatmentList(List<String> treatmentList) {
+ this.treatmentList = treatmentList;
+ }
+ /**
+ * @return the rainydayMap
+ */
+ public Map<String,String> getRainydayMap() {
+ return rainydayMap;
+ }
+ /**
+ * @param rainydayMap the rainydayMap to set
+ */
+ public void setRainydayMap(Map<String,String> rainydayMap) {
+ this.rainydayMap = rainydayMap;
+ }
+ /**
+ * @return the policyJSON
+ */
+ public Object getPolicyJSON() {
+ return policyJSON;
+ }
+ /**
+ * @param policyJSON the policyJSON to set
+ */
+ public void setPolicyJSON(Object policyJSON) {
+ this.policyJSON = policyJSON;
+ }
}
diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImpl.java b/ONAP-REST/src/main/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImpl.java
index f6682eb40..8aa04356f 100644
--- a/ONAP-REST/src/main/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImpl.java
+++ b/ONAP-REST/src/main/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImpl.java
@@ -20,6 +20,7 @@
package org.onap.policy.rest.daoimpl;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -42,12 +43,13 @@ import org.onap.policy.rest.jpa.PolicyRoles;
import org.onap.policy.xacml.api.XACMLErrorConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import org.springframework.stereotype.Service;
@Component
public class PolicyValidationDaoImpl implements CommonClassDao{
private static final Logger LOGGER = FlexLogger.getLogger(PolicyValidationDaoImpl.class);
+ private static final String DB_CONNECTION_CLOSING_ERROR = "Error While Closing Connection/Statement";
+ private static final String DBTABLE_QUERY_ERROR = "Error While Querying Table";
private static SessionFactory sessionfactory;
public static SessionFactory getSessionfactory() {
@@ -76,12 +78,12 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
Criteria cr = session.createCriteria(className);
data = cr.list();
}catch(Exception e){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Table"+e);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DBTABLE_QUERY_ERROR + e);
}finally{
try{
session.close();
}catch(Exception e){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR+e);
}
}
return data;
@@ -106,12 +108,12 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
}
data = cr.list();
} catch (Exception e) {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Table"+e);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DBTABLE_QUERY_ERROR + e);
}finally{
try{
session.close();
}catch(Exception e1){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1);
}
}
return data;
@@ -125,12 +127,12 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
session.persist(entity);
tx.commit();
}catch(Exception e){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving data to Table"+e);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Saving data to Table"+e);
}finally{
try{
session.close();
}catch(Exception e1){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1);
}
}
@@ -149,7 +151,7 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
try{
session.close();
}catch(Exception e1){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1);
}
}
@@ -169,7 +171,7 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
try{
session.close();
}catch(Exception e1){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1);
}
}
@@ -207,7 +209,7 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
try{
session.close();
}catch(Exception e1){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1);
}
}
return data;
@@ -240,7 +242,7 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
try{
session.close();
}catch(Exception e1){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1);
}
}
return rolesData;
@@ -249,12 +251,14 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
@Override
public List<Object> checkExistingGroupListforUpdate(String arg0, String arg1) {
- return null;
+ return Collections.emptyList();
}
@Override
- public void deleteAll() {}
+ public void deleteAll() {
+ // Do nothing because this method is not used and is a placeholder to avoid 'Unimplemented Method' error
+ }
@SuppressWarnings("unchecked")
@@ -276,13 +280,13 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
data = hbquery.list();
tx.commit();
} catch (Exception e) {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Database Table"+e);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DBTABLE_QUERY_ERROR + e);
throw e;
}finally{
try{
session.close();
}catch(HibernateException e1){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1);
}
}
return data;
@@ -309,12 +313,12 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
data = cr.list().get(0);
tx.commit();
} catch (Exception e) {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Database Table"+e);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DBTABLE_QUERY_ERROR + e);
}finally{
try{
session.close();
}catch(Exception e1){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1);
}
}
return data;
@@ -322,11 +326,15 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
@Override
- public void updateClAlarms(String arg0, String arg1) {}
+ public void updateClAlarms(String arg0, String arg1) {
+ // Do nothing because this method is not used and is a placeholder to avoid 'Unimplemented Method' error
+ }
@Override
- public void updateClYaml(String arg0, String arg1) {}
+ public void updateClYaml(String arg0, String arg1) {
+ // Do nothing because this method is not used and is a placeholder to avoid 'Unimplemented Method' error
+ }
@Override
@@ -343,7 +351,7 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
try{
session.close();
}catch(Exception e1){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1);
}
}
@@ -360,12 +368,12 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
cr.setProjection(Projections.property(columnName));
data = cr.list();
}catch(Exception e){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Table"+e);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DBTABLE_QUERY_ERROR + e);
}finally{
try{
session.close();
}catch(Exception e){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e);
}
}
return data;
@@ -396,12 +404,12 @@ public class PolicyValidationDaoImpl implements CommonClassDao{
entityData = cr.add(disjunction).list();
tx.commit();
} catch (Exception e) {
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Querying Table" +className +e);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DBTABLE_QUERY_ERROR + className + e);
}finally{
try{
session.close();
}catch(Exception e1){
- LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error While Closing Connection/Statement"+e1);
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + DB_CONNECTION_CLOSING_ERROR + e1);
}
}
return entityData;
diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java
index 223381afe..e98a41f9e 100644
--- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java
+++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java
@@ -60,6 +60,9 @@ public class PolicyValidation {
public static final String ENFORCER_CONFIG_POLICY= "Enforcer Config";
public static final String MICROSERVICES="Micro Service";
public static final String FIREWALL="Firewall Config";
+ public static final String HTML_ITALICS_LNBREAK = "</i><br>";
+ public static final String SUCCESS = "success";
+ public static final String EMPTY_COMPONENT_ATTR = "Component Attributes: One or more Fields in Component Attributes is Empty.";
private static Map<String, String> mapAttribute = new HashMap<>();
@@ -84,7 +87,7 @@ public class PolicyValidation {
if(policyData.getPolicyName() != null){
String policyNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getPolicyName());
- if(!policyNameValidate.contains("success")){
+ if(!policyNameValidate.contains(SUCCESS)){
responseString.append("PolicyName:" + policyNameValidate + "<br>");
valid = false;
};
@@ -94,7 +97,7 @@ public class PolicyValidation {
}
if(policyData.getPolicyDescription() != null){
String descriptionValidate = PolicyUtils.descriptionValidator(policyData.getPolicyDescription());
- if(!descriptionValidate.contains("success")){
+ if(!descriptionValidate.contains(SUCCESS)){
responseString.append("Description:" + descriptionValidate + "<br>");
valid = false;
}
@@ -107,7 +110,7 @@ public class PolicyValidation {
if(!Strings.isNullOrEmpty(policyData.getOnapName())) {
String onapNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getOnapName());
- if(!onapNameValidate.contains("success")){
+ if(!onapNameValidate.contains(SUCCESS)){
responseString.append("OnapName:" + onapNameValidate + "<br>");
valid = false;
}
@@ -119,7 +122,7 @@ public class PolicyValidation {
if(!Strings.isNullOrEmpty(policyData.getRiskType())) {
String riskTypeValidate = PolicyUtils.policySpecialCharValidator(policyData.getRiskType());
- if(!riskTypeValidate.contains("success")){
+ if(!riskTypeValidate.contains(SUCCESS)){
responseString.append("RiskType:" + riskTypeValidate + "<br>");
valid = false;
}
@@ -130,7 +133,7 @@ public class PolicyValidation {
if(!Strings.isNullOrEmpty(policyData.getRiskLevel())) {
String validateRiskLevel = PolicyUtils.policySpecialCharValidator(policyData.getRiskLevel());
- if(!validateRiskLevel.contains("success")){
+ if(!validateRiskLevel.contains(SUCCESS)){
responseString.append("RiskLevel:" + validateRiskLevel + "<br>");
valid = false;
}
@@ -141,7 +144,7 @@ public class PolicyValidation {
if(!Strings.isNullOrEmpty(policyData.getGuard())) {
String validateGuard = PolicyUtils.policySpecialCharValidator(policyData.getGuard());
- if(!validateGuard.contains("success")){
+ if(!validateGuard.contains(SUCCESS)){
responseString.append("Guard:" + validateGuard + "<br>");
valid = false;
}
@@ -153,7 +156,7 @@ public class PolicyValidation {
if("Base".equalsIgnoreCase(policyData.getConfigPolicyType())){
if(!Strings.isNullOrEmpty(policyData.getConfigName())) {
String configNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getConfigName());
- if(!configNameValidate.contains("success")){
+ if(!configNameValidate.contains(SUCCESS)){
responseString.append("ConfigName:" + configNameValidate + "<br>");
valid = false;
}
@@ -163,7 +166,7 @@ public class PolicyValidation {
}
if(!Strings.isNullOrEmpty(policyData.getConfigType())) {
String configTypeValidate = PolicyUtils.policySpecialCharValidator(policyData.getConfigType());
- if(!configTypeValidate.contains("success")){
+ if(!configTypeValidate.contains(SUCCESS)){
responseString.append("ConfigType:" + configTypeValidate + "<br>");
valid = false;
}
@@ -190,11 +193,9 @@ public class PolicyValidation {
responseString.append("Config Body: Property data is not valid" + "<br>");
valid = false;
}
- } else if (configType.equals("OTHER")) {
- if (configBodyData.equals("")) {
- responseString.append("Config Body: Config Body Should not be Empty" + "<br>");
- valid = false;
- }
+ } else if ("OTHER".equals(configType) && ("".equals(configBodyData))) {
+ responseString.append("Config Body: Config Body Should not be Empty" + "<br>");
+ valid = false;
}
}
}else{
@@ -203,27 +204,25 @@ public class PolicyValidation {
}
}
- if("Firewall Config".equalsIgnoreCase(policyData.getConfigPolicyType())){
+ if(FIREWALL.equalsIgnoreCase(policyData.getConfigPolicyType())){
if(policyData.getConfigName() != null && !policyData.getConfigName().isEmpty()){
String configNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getConfigName());
- if(!configNameValidate.contains("success")){
- responseString.append("<b>ConfigName</b>:<i>" + configNameValidate + "</i><br>");
+ if(!configNameValidate.contains(SUCCESS)){
+ responseString.append("<b>ConfigName</b>:<i>" + configNameValidate + HTML_ITALICS_LNBREAK);
valid = false;
}
}else{
- responseString.append("<b>Config Name</b>:<i> Config Name is required" + "</i><br>");
+ responseString.append("<b>Config Name</b>:<i> Config Name is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(policyData.getSecurityZone() == null || policyData.getSecurityZone().isEmpty()){
- responseString.append("<b>Security Zone</b>:<i> Security Zone is required" + "</i><br>");
+ responseString.append("<b>Security Zone</b>:<i> Security Zone is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
- if("BRMS_Param".equalsIgnoreCase(policyData.getConfigPolicyType())){
- if(policyData.getRuleName() == null || policyData.getRuleName().isEmpty()){
- responseString.append("<b>BRMS Template</b>:<i>BRMS Template is required</i><br>");
- valid = false;
- }
+ if("BRMS_Param".equalsIgnoreCase(policyData.getConfigPolicyType()) && Strings.isNullOrEmpty(policyData.getRuleName())){
+ responseString.append("<b>BRMS Template</b>:<i>BRMS Template is required" + HTML_ITALICS_LNBREAK);
+ valid = false;
}
if("BRMS_Raw".equalsIgnoreCase(policyData.getConfigPolicyType())){
if(policyData.getConfigBodyData() != null && !policyData.getConfigBodyData().isEmpty()){
@@ -231,44 +230,45 @@ public class PolicyValidation {
// If there are any error other than Annotations then this is not Valid
if(message.contains("[ERR")){
- responseString.append("<b>Raw Rule Validate</b>:<i>Raw Rule has error"+ message +"</i><br>");
+ responseString.append("<b>Raw Rule Validate</b>:<i>Raw Rule has error"+ message + HTML_ITALICS_LNBREAK);
valid = false;
}
}else{
- responseString.append("<b>Raw Rule</b>:<i>Raw Rule is required</i><br>");
+ responseString.append("<b>Raw Rule</b>:<i>Raw Rule is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
- if("ClosedLoop_PM".equalsIgnoreCase(policyData.getConfigPolicyType())){
+ if(CLOSEDLOOP_PM.equalsIgnoreCase(policyData.getConfigPolicyType())){
try{
if(Strings.isNullOrEmpty(policyData.getServiceTypePolicyName().get("serviceTypePolicyName").toString())){
- responseString.append("<b>ServiceType PolicyName</b>:<i>ServiceType PolicyName is required</i><br>");
+ responseString.append("<b>ServiceType PolicyName</b>:<i>ServiceType PolicyName is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}catch(Exception e){
LOGGER.error("ERROR in ClosedLoop_PM PolicyName" , e);
- responseString.append("<b>ServiceType PolicyName</b>:<i>ServiceType PolicyName is required</i><br>");
+ responseString.append("<b>ServiceType PolicyName</b>:<i>ServiceType PolicyName is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(policyData.getJsonBody() != null){
- ClosedLoopPMBody pmBody = (ClosedLoopPMBody)mapper.readValue(policyData.getJsonBody(), ClosedLoopPMBody.class);
+
+ ClosedLoopPMBody pmBody = mapper.readValue(policyData.getJsonBody(), ClosedLoopPMBody.class);
if(pmBody.getEmailAddress() != null){
String result = emailValidation(pmBody.getEmailAddress(), responseString.toString());
- if(result != "success"){
+ if(result != SUCCESS){
responseString.append(result + "<br>");
valid = false;
}
}
if((pmBody.isGamma() || pmBody.isMcr() || pmBody.isTrinity() || pmBody.isvDNS() || pmBody.isvUSP()) != true){
- responseString.append("<b>D2/Virtualized Services</b>: <i>Select at least one D2/Virtualized Services</i><br>");
+ responseString.append("<b>D2/Virtualized Services</b>: <i>Select at least one D2/Virtualized Services" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(pmBody.getGeoLink() != null && !pmBody.getGeoLink().isEmpty()){
String result = PolicyUtils.policySpecialCharValidator(pmBody.getGeoLink());
- if(!result.contains("success")){
- responseString.append("<b>GeoLink</b>:<i>" + result + "</i><br>");
+ if(!result.contains(SUCCESS)){
+ responseString.append("<b>GeoLink</b>:<i>" + result + HTML_ITALICS_LNBREAK);
valid = false;
};
}
@@ -278,19 +278,19 @@ public class PolicyValidation {
String value = entry.getValue();
if(!key.contains("Message")){
String attributeValidate = PolicyUtils.policySpecialCharValidator(value);
- if(!attributeValidate.contains("success")){
- responseString.append("<b>Attributes</b>:<i>" + key + " : value has spaces or invalid characters</i><br>");
+ if(!attributeValidate.contains(SUCCESS)){
+ responseString.append("<b>Attributes</b>:<i>" + key + " : value has spaces or invalid characters" + HTML_ITALICS_LNBREAK);
valid = false;
};
}
}
}
}else{
- responseString.append("<b>D2/Virtualized Services</b>:<i>Select atleast one D2/Virtualized Services</i><br>");
+ responseString.append("<b>D2/Virtualized Services</b>:<i>Select atleast one D2/Virtualized Services" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
- if("ClosedLoop_Fault".equalsIgnoreCase(policyData.getConfigPolicyType())){
+ if(CLOSEDLOOP_POLICY.equalsIgnoreCase(policyData.getConfigPolicyType())){
if(policyData.getJsonBody() != null){
// For API we need to get the conditions key from the Json request and check it before deserializing to POJO due to the enum
@@ -299,11 +299,11 @@ public class PolicyValidation {
if(!json.isNull("conditions")){
String apiCondition = (String) json.get("conditions");
if(Strings.isNullOrEmpty(apiCondition)){
- responseString.append("<b>Conditions</b>: <i>Select At least one Condition</i><br>");
+ responseString.append("<b>Conditions</b>: <i>Select At least one Condition" + HTML_ITALICS_LNBREAK);
return responseString;
}
} else {
- responseString.append("<b>Conditions</b>: <i>There were no conditions provided in configBody json</i><br>");
+ responseString.append("<b>Conditions</b>: <i>There were no conditions provided in configBody json" + HTML_ITALICS_LNBREAK);
return responseString;
}
}
@@ -311,79 +311,79 @@ public class PolicyValidation {
ClosedLoopFaultBody faultBody = mapper.readValue(policyData.getJsonBody(), ClosedLoopFaultBody.class);
if(faultBody.getEmailAddress() != null && !faultBody.getEmailAddress().isEmpty()){
String result = emailValidation(faultBody.getEmailAddress(), responseString.toString());
- if(result != "success"){
+ if(result != SUCCESS){
responseString.append(result+ "<br>");
valid = false;
}
}
if((faultBody.isGamma() || faultBody.isMcr() || faultBody.isTrinity() || faultBody.isvDNS() || faultBody.isvUSP()) != true){
- responseString.append("<b>D2/Virtualized Services</b>: <i>Select at least one D2/Virtualized Services</i><br>");
+ responseString.append("<b>D2/Virtualized Services</b>: <i>Select at least one D2/Virtualized Services" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(faultBody.getActions() == null || faultBody.getActions().isEmpty()){
- responseString.append("<b>vPRO Actions</b>: <i>vPRO Actions is required</i><br>");
+ responseString.append("<b>vPRO Actions</b>: <i>vPRO Actions is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(faultBody.getClosedLoopPolicyStatus() == null || faultBody.getClosedLoopPolicyStatus().isEmpty()){
- responseString.append("<b>Policy Status</b>: <i>Policy Status is required</i><br>");
+ responseString.append("<b>Policy Status</b>: <i>Policy Status is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(faultBody.getConditions() == null){
- responseString.append("<b>Conditions</b>: <i>Select At least one Condition</i><br>");
+ responseString.append("<b>Conditions</b>: <i>Select At least one Condition" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(faultBody.getGeoLink() != null && !faultBody.getGeoLink().isEmpty()){
String result = PolicyUtils.policySpecialCharWithSpaceValidator(faultBody.getGeoLink());
- if(!result.contains("success")){
- responseString.append("<b>GeoLink</b>:<i>" + result + "</i><br>");
+ if(!result.contains(SUCCESS)){
+ responseString.append("<b>GeoLink</b>:<i>" + result + HTML_ITALICS_LNBREAK);
valid = false;
}
}
if(faultBody.getAgingWindow() == 0){
- responseString.append("<b>Aging Window</b>: <i>Aging Window is required</i><br>");
+ responseString.append("<b>Aging Window</b>: <i>Aging Window is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(faultBody.getTimeInterval() == 0){
- responseString.append("<b>Time Interval</b>: <i>Time Interval is required</i><br>");
+ responseString.append("<b>Time Interval</b>: <i>Time Interval is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(faultBody.getRetrys() == 0){
- responseString.append("<b>Number of Retries</b>: <i>Number of Retries is required</i><br>");
+ responseString.append("<b>Number of Retries</b>: <i>Number of Retries is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(faultBody.getTimeOutvPRO() == 0){
- responseString.append("<b>APP-C Timeout</b>: <i>APP-C Timeout is required</i><br>");
+ responseString.append("<b>APP-C Timeout</b>: <i>APP-C Timeout is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(faultBody.getTimeOutRuby() == 0){
- responseString.append("<b>TimeOutRuby</b>: <i>TimeOutRuby is required</i><br>");
+ responseString.append("<b>TimeOutRuby</b>: <i>TimeOutRuby is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(faultBody.getVnfType() == null || faultBody.getVnfType().isEmpty()){
- responseString.append("<b>Vnf Type</b>: <i>Vnf Type is required</i><br>");
+ responseString.append("<b>Vnf Type</b>: <i>Vnf Type is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}else{
- responseString.append("<b>D2/Virtualized Services</b>: <i>Select atleast one D2/Virtualized Services</i><br>");
- responseString.append("<b>vPRO Actions</b>: <i>vPRO Actions is required</i><br>");
- responseString.append("<b>Aging Window</b>: <i>Aging Window is required</i><br>");
- responseString.append("<b>Policy Status</b>: <i>Policy Status is required</i><br>");
- responseString.append("<b>Conditions</b>: <i>Select Atleast one Condition</i><br>");
- responseString.append("<b>PEP Name</b>: <i>PEP Name is required</i><br>");
- responseString.append("<b>PEP Action</b>: <i>PEP Action is required</i><br>");
- responseString.append("<b>Time Interval</b>: <i>Time Interval is required</i><br>");
- responseString.append("<b>Number of Retries</b>: <i>Number of Retries is required</i><br>");
- responseString.append("<b>APP-C Timeout</b>: <i>APP-C Timeout is required</i><br>");
- responseString.append("<b>TimeOutRuby</b>: <i>TimeOutRuby is required</i><br>");
- responseString.append("<b>Vnf Type</b>: <i>Vnf Type is required</i><br>");
+ responseString.append("<b>D2/Virtualized Services</b>: <i>Select atleast one D2/Virtualized Services" + HTML_ITALICS_LNBREAK);
+ responseString.append("<b>vPRO Actions</b>: <i>vPRO Actions is required" + HTML_ITALICS_LNBREAK);
+ responseString.append("<b>Aging Window</b>: <i>Aging Window is required" + HTML_ITALICS_LNBREAK);
+ responseString.append("<b>Policy Status</b>: <i>Policy Status is required" + HTML_ITALICS_LNBREAK);
+ responseString.append("<b>Conditions</b>: <i>Select Atleast one Condition" + HTML_ITALICS_LNBREAK);
+ responseString.append("<b>PEP Name</b>: <i>PEP Name is required" + HTML_ITALICS_LNBREAK);
+ responseString.append("<b>PEP Action</b>: <i>PEP Action is required" + HTML_ITALICS_LNBREAK);
+ responseString.append("<b>Time Interval</b>: <i>Time Interval is required" + HTML_ITALICS_LNBREAK);
+ responseString.append("<b>Number of Retries</b>: <i>Number of Retries is required" + HTML_ITALICS_LNBREAK);
+ responseString.append("<b>APP-C Timeout</b>: <i>APP-C Timeout is required" + HTML_ITALICS_LNBREAK);
+ responseString.append("<b>TimeOutRuby</b>: <i>TimeOutRuby is required" + HTML_ITALICS_LNBREAK);
+ responseString.append("<b>Vnf Type</b>: <i>Vnf Type is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
- if ("Micro Service".equals(policyData.getConfigPolicyType())){
+ if (MICROSERVICES.equals(policyData.getConfigPolicyType())){
if(!Strings.isNullOrEmpty(policyData.getServiceType())){
pullJsonKeyPairs((JsonNode) policyData.getPolicyJSON());
- MicroServiceModels returnModel = new MicroServiceModels();
+
String service = null;
String version = null;
if (policyData.getServiceType().contains("-v")){
@@ -395,13 +395,12 @@ public class PolicyValidation {
}
if(!Strings.isNullOrEmpty(version)) {
- returnModel = getAttributeObject(service, version);
+ MicroServiceModels returnModel = getAttributeObject(service, version);
if(returnModel != null) {
String annotation = returnModel.getAnnotation();
if (!Strings.isNullOrEmpty(annotation)){
- Map<String, String> rangeMap = new HashMap<>();
- rangeMap = Splitter.on(",").withKeyValueSeparator("=").split(annotation);
+ Map<String, String> rangeMap = Splitter.on(",").withKeyValueSeparator("=").split(annotation);
for (Entry<String, String> rMap : rangeMap.entrySet()){
if (rMap.getValue().contains("range::")){
String value = mapAttribute.get(rMap.getKey().trim());
@@ -424,7 +423,7 @@ public class PolicyValidation {
}
} else {
responseString.append("<b>"+rMap.getKey()+"</b>:<i>" + rMap.getKey()
- + " is required for the MicroService model " + service + "</i><br>");
+ + " is required for the MicroService model " + service + HTML_ITALICS_LNBREAK);
valid = false;
}
@@ -433,20 +432,20 @@ public class PolicyValidation {
}
} else {
responseString.append("<b>Micro Service Model</b>:<i> Invalid Model. The model name, " + service +
- " of version, " + version + " was not found in the dictionary</i><br>");
+ " of version, " + version + " was not found in the dictionary" + HTML_ITALICS_LNBREAK);
valid = false;
}
} else {
- responseString.append("<b>Micro Version</b>:<i> Micro Service Version is required" + "</i><br>");
+ responseString.append("<b>Micro Version</b>:<i> Micro Service Version is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
} else {
- responseString.append("<b>Micro Service</b>:<i> Micro Service is required" + "</i><br>");
+ responseString.append("<b>Micro Service</b>:<i> Micro Service is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
if(Strings.isNullOrEmpty(policyData.getPriority())){
- responseString.append("<b>Priority</b>:<i> Priority is required" + "</i><br>");
+ responseString.append("<b>Priority</b>:<i> Priority is required" + HTML_ITALICS_LNBREAK);
valid = false;
}
}
@@ -454,7 +453,7 @@ public class PolicyValidation {
if (DECISION_POLICY.equalsIgnoreCase(policyData.getPolicyType())){
if(!Strings.isNullOrEmpty(policyData.getOnapName())){
String onapNameValidate = PolicyUtils.policySpecialCharValidator(policyData.getOnapName());
- if(!onapNameValidate.contains("success")){
+ if(!onapNameValidate.contains(SUCCESS)){
responseString.append("OnapName:" + onapNameValidate + "<br>");
valid = false;
}
@@ -570,7 +569,7 @@ public class PolicyValidation {
valid = false;
}else{
for(String blackList: policyData.getYamlparams().getBlackList()){
- if(blackList==null || !("success".equals(PolicyUtils.policySpecialCharValidator(blackList)))){
+ if(blackList==null || !(SUCCESS.equals(PolicyUtils.policySpecialCharValidator(blackList)))){
responseString.append(" Guard Params <b>BlackList</b> Should be valid String" + "<br>");
valid = false;
break;
@@ -585,7 +584,7 @@ public class PolicyValidation {
if(ACTION_POLICY.equalsIgnoreCase(policyData.getPolicyType())){
if(!Strings.isNullOrEmpty(policyData.getActionPerformer())){
String actionPerformer = PolicyUtils.policySpecialCharValidator(policyData.getActionPerformer());
- if(!actionPerformer.contains("success")){
+ if(!actionPerformer.contains(SUCCESS)){
responseString.append("ActionPerformer:" + actionPerformer + "<br>");
valid = false;
}
@@ -601,25 +600,25 @@ public class PolicyValidation {
String key = ((LinkedHashMap<?, ?>) attribute).get("key").toString();
String value = ((LinkedHashMap<?, ?>) attribute).get("value").toString();
if("".equals(key) || "".equals(value)){
- responseString.append("Component Attributes: One or more Fields in Component Attributes is Empty." + "<br>");
+ responseString.append(EMPTY_COMPONENT_ATTR + "<br>");
valid = false;
break;
}
}catch(Exception e){
LOGGER.error("This is a Policy Validation check" +e);
- responseString.append("Component Attributes: One or more Fields in Component Attributes is Empty." + "<br>");
+ responseString.append(EMPTY_COMPONENT_ATTR + "<br>");
valid = false;
break;
}
}
}
}else{
- responseString.append("Component Attributes: One or more Fields in Component Attributes is Empty." + "<br>");
+ responseString.append(EMPTY_COMPONENT_ATTR + "<br>");
valid = false;
}
if(!Strings.isNullOrEmpty(policyData.getActionAttributeValue())){
String actionAttribute = PolicyUtils.policySpecialCharValidator(policyData.getActionAttributeValue());
- if(!actionAttribute.contains("success")){
+ if(!actionAttribute.contains(SUCCESS)){
responseString.append("ActionAttribute:" + actionAttribute + "<br>");
valid = false;
};
@@ -662,11 +661,11 @@ public class PolicyValidation {
value = "Message:" + safePolicyWarningData.getMessage();
}
}
- responseString.append("success" + "@#"+ value);
+ responseString.append(SUCCESS + "@#"+ value);
}
}else{
if(valid){
- responseString.append("success");
+ responseString.append(SUCCESS);
}
}
@@ -681,10 +680,10 @@ public class PolicyValidation {
protected String emailValidation(String email, String response){
if(email != null){
String validateEmail = PolicyUtils.validateEmailAddress(email.replace("\"", ""));
- if(!validateEmail.contains("success")){
- response += "<b>Email</b>:<i>" + validateEmail+ "</i><br>";
+ if(!validateEmail.contains(SUCCESS)){
+ response += "<b>Email</b>:<i>" + validateEmail + HTML_ITALICS_LNBREAK;
}else{
- return "success";
+ return SUCCESS;
}
}
return response;
diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java
index 072462297..03c1fb0c7 100644
--- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java
+++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidationRequestWrapper.java
@@ -63,16 +63,14 @@ public class PolicyValidationRequestWrapper {
policyData = mapper.readValue(root.get("policyData").toString(), PolicyRestAdapter.class);
JsonObject json = null;
- if(root != null){
- json = stringToJsonObject(root.toString());
-
- if(json != null){
- if(json.containsKey("policyJSON")){
- policyData.setPolicyJSON(root.get("policyJSON"));
- }else{
- String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString();
- policyData.setJsonBody(jsonBodyData);
- }
+ json = stringToJsonObject(root.toString());
+
+ if(json != null){
+ if(json.containsKey("policyJSON")){
+ policyData.setPolicyJSON(root.get("policyJSON"));
+ }else{
+ String jsonBodyData = json.getJsonObject("policyData").get("jsonBodyData").toString();
+ policyData.setJsonBody(jsonBodyData);
}
}
@@ -127,13 +125,13 @@ public class PolicyValidationRequestWrapper {
// Set Matching attributes in RainyDayParams in adapter
RainyDayParams rainyday = new RainyDayParams();
- rainyday.setServiceType(matching.get("ServiceType"));
- rainyday.setVnfType(matching.get("VNFType"));
- rainyday.setBbid(matching.get("BB_ID"));
- rainyday.setWorkstep(matching.get("WorkStep"));
-
-
-
+ if(matching != null) {
+ rainyday.setServiceType(matching.get("ServiceType"));
+ rainyday.setVnfType(matching.get("VNFType"));
+ rainyday.setBbid(matching.get("BB_ID"));
+ rainyday.setWorkstep(matching.get("WorkStep"));
+ }
+
Map<String, String> treatments = parameters.getTreatments();
ArrayList<Object> treatmentsTableChoices = new ArrayList<>();
@@ -153,32 +151,32 @@ public class PolicyValidationRequestWrapper {
// Set Matching attributes in YAMLParams in adapter
YAMLParams yamlparams = new YAMLParams();
- yamlparams.setActor(matching.get("actor"));
- yamlparams.setRecipe(matching.get("recipe"));
- yamlparams.setGuardActiveStart(matching.get("guardActiveStart"));
- yamlparams.setGuardActiveEnd(matching.get("guardActiveEnd"));
-
- if("GUARD_YAML".equals(ruleProvider)){
- yamlparams.setLimit(matching.get("limit"));
- yamlparams.setTimeWindow(matching.get("timeWindow"));
- yamlparams.setTimeUnits(matching.get("timeUnits"));
- }else{
+ if (matching != null) {
+ yamlparams.setActor(matching.get("actor"));
+ yamlparams.setRecipe(matching.get("recipe"));
+ yamlparams.setGuardActiveStart(matching.get("guardActiveStart"));
+ yamlparams.setGuardActiveEnd(matching.get("guardActiveEnd"));
- List<String> blackList = new ArrayList<>();
+ if("GUARD_YAML".equals(ruleProvider)){
+ yamlparams.setLimit(matching.get("limit"));
+ yamlparams.setTimeWindow(matching.get("timeWindow"));
+ yamlparams.setTimeUnits(matching.get("timeUnits"));
+ }else{
+
+ List<String> blackList = new ArrayList<>();
- if(!Strings.isNullOrEmpty(matching.get("blackList"))){
- String[] blackListArray = matching.get("blackList").split(",");
- for(String element : blackListArray){
- blackList.add(element);
- }
- }
-
- yamlparams.setBlackList(blackList);
+ if(!Strings.isNullOrEmpty(matching.get("blackList"))){
+ String[] blackListArray = matching.get("blackList").split(",");
+ for(String element : blackListArray){
+ blackList.add(element);
+ }
+ }
+
+ yamlparams.setBlackList(blackList);
- }
-
+ }
+ }
policyData.setYamlparams(yamlparams);
-;
}
} else if("Action".equals(parameters.getPolicyClass().toString())){
@@ -216,15 +214,16 @@ public class PolicyValidationRequestWrapper {
policyData.setRuleAlgorithmschoices(ruleAlgorithmChoices);
ArrayList<Object> attributeList = new ArrayList<>();
-
- for (String keyField : matching.keySet()) {
- LinkedHashMap<String, String> attributeMap = new LinkedHashMap<>();
- String key = keyField;
- String value = matching.get(keyField);
- attributeMap.put("key", key);
- attributeMap.put("value", value);
- attributeList.add(attributeMap);
- }
+ if (matching != null) {
+ for (String keyField : matching.keySet()) {
+ LinkedHashMap<String, String> attributeMap = new LinkedHashMap<>();
+ String key = keyField;
+ String value = matching.get(keyField);
+ attributeMap.put("key", key);
+ attributeMap.put("value", value);
+ attributeList.add(attributeMap);
+ }
+ }
policyData.setAttributes(attributeList);
policyData.setActionAttributeValue(parameters.getActionAttribute());
diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImplTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImplTest.java
new file mode 100644
index 000000000..7467d4dfe
--- /dev/null
+++ b/ONAP-REST/src/test/java/org/onap/policy/rest/daoimpl/PolicyValidationDaoImplTest.java
@@ -0,0 +1,441 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-REST
+ * ================================================================================
+ * Copyright (C) 2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.policy.rest.daoimpl;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Properties;
+
+import javax.script.SimpleBindings;
+
+import org.apache.tomcat.dbcp.dbcp2.BasicDataSource;
+import org.h2.tools.Server;
+import org.hibernate.SessionFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.logging.flexlogger.FlexLogger;
+import org.onap.policy.common.logging.flexlogger.Logger;
+//import org.onap.policy.conf.HibernateSession;
+//import org.onap.policy.controller.PolicyController;
+import org.onap.policy.rest.jpa.OnapName;
+import org.onap.policy.rest.jpa.PolicyEntity;
+import org.onap.policy.rest.jpa.PolicyRoles;
+import org.onap.policy.rest.jpa.PolicyVersion;
+import org.onap.policy.rest.jpa.SystemLogDB;
+import org.onap.policy.rest.jpa.UserInfo;
+import org.onap.policy.rest.jpa.WatchPolicyNotificationTable;
+import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.test.annotation.Rollback;
+
+
+public class PolicyValidationDaoImplTest {
+
+ private static Logger logger = FlexLogger.getLogger(PolicyValidationDaoImplTest.class);
+
+ SessionFactory sessionFactory;
+ Server server;
+ PolicyValidationDaoImpl commonClassDao;
+
+ @Before
+ public void setUp() throws Exception{
+ try{
+ BasicDataSource dataSource = new BasicDataSource();
+ dataSource.setDriverClassName("org.h2.Driver");
+ // In-memory DB for testing
+ dataSource.setUrl("jdbc:h2:mem:test");
+ dataSource.setUsername("sa");
+ dataSource.setPassword("");
+ LocalSessionFactoryBuilder sessionBuilder = new LocalSessionFactoryBuilder(dataSource);
+ sessionBuilder.scanPackages("org.onap.*", "com.*");
+
+ Properties properties = new Properties();
+ properties.put("hibernate.show_sql", "false");
+ properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
+ properties.put("hibernate.hbm2ddl.auto", "drop");
+ properties.put("hibernate.hbm2ddl.auto", "create");
+
+ sessionBuilder.addProperties(properties);
+ sessionFactory = sessionBuilder.buildSessionFactory();
+
+ // Set up dao with SessionFactory
+ commonClassDao = new PolicyValidationDaoImpl();
+ PolicyValidationDaoImpl.setSessionfactory(sessionFactory);
+ //PolicyController.setLogTableLimit("1");
+ //HibernateSession.setSession(sessionFactory);
+ SystemLogDB data1 = new SystemLogDB();
+ data1.setDate(new Date());
+ data1.setLogtype("INFO");
+ data1.setRemote("Test");
+ data1.setSystem("Test");
+ data1.setType("Test");
+ SystemLogDB data2 = new SystemLogDB();
+ data2.setDate(new Date());
+ data2.setLogtype("error");
+ data2.setRemote("Test");
+ data2.setSystem("Test");
+ data2.setType("Test");
+ //HibernateSession.getSession().save(data1);
+ //HibernateSession.getSession().save(data2);
+
+ // Create TCP server for troubleshooting
+ server = Server.createTcpServer("-tcpAllowOthers").start();
+ System.out.println("URL: jdbc:h2:" + server.getURL() + "/mem:test");
+
+ }catch(Exception e){
+ System.err.println(e);
+ fail();
+ }
+ }
+
+ @Test
+ @Transactional
+ @Rollback(true)
+ public void testDB(){
+ try{
+ // Add data
+ UserInfo userinfo = new UserInfo();
+ userinfo.setUserLoginId("Test");
+ userinfo.setUserName("Test");
+ commonClassDao.save(userinfo);
+ OnapName onapName = new OnapName();
+ onapName.setOnapName("Test");
+ onapName.setUserCreatedBy(userinfo);
+ onapName.setUserModifiedBy(userinfo);
+ onapName.setModifiedDate(new Date());
+ commonClassDao.save(onapName);
+
+
+ List<Object> list = commonClassDao.getData(OnapName.class);
+ assertTrue(list.size() == 1);
+ logger.debug(list.size());
+ logger.debug(list.get(0));
+ }catch(Exception e){
+ logger.debug("Exception Occured"+e);
+ fail();
+ }
+ }
+
+ @Test
+ @Transactional
+ @Rollback(true)
+ public void testUser(){
+ try{
+ // Add data
+ UserInfo userinfo = new UserInfo();
+ String loginId_userName = "Test";
+ userinfo.setUserLoginId(loginId_userName);
+ userinfo.setUserName(loginId_userName);
+ commonClassDao.save(userinfo);
+
+
+ List<Object> dataCur = commonClassDao.getDataByQuery("from UserInfo", new SimpleBindings());
+
+ assertEquals(1, dataCur.size());
+ UserInfo cur = (UserInfo) dataCur.get(0);
+ assertEquals(loginId_userName, cur.getUserLoginId());
+ assertEquals(loginId_userName, cur.getUserName());
+
+ assertFalse(dataCur.isEmpty());
+
+ }catch(Exception e){
+ logger.debug("Exception Occured"+e);
+ fail();
+ }
+ }
+
+ @Test
+ @Transactional
+ @Rollback(true)
+ public void getDataByQuery_DashboardController(){
+ try{
+ // Add data
+ PolicyEntity pe = new PolicyEntity();
+ String name = "TestPolicy";
+ pe.setPolicyName(name);
+ pe.setPolicyData("dummyData");
+ pe.prePersist();
+ pe.setScope("dummyScope");
+ pe.setDescription("descr");
+ pe.setDeleted(false);
+ pe.setCreatedBy("Test");
+ commonClassDao.save(pe);
+
+ List<Object> dataCur = commonClassDao.getDataByQuery("from PolicyEntity", new SimpleBindings());
+
+ assertTrue(1 == dataCur.size());
+ assertTrue( dataCur.get(0) instanceof PolicyEntity);
+ assertEquals( name, ((PolicyEntity)dataCur.get(0)).getPolicyName());
+ assertEquals( pe, ((PolicyEntity)dataCur.get(0)));
+
+
+ }catch(Exception e){
+ logger.debug("Exception Occured"+e);
+ fail();
+ }
+ }
+
+ @Test
+ @Transactional
+ @Rollback(true)
+ public void getDataByQuery_AutoPushController(){
+ try{
+ // Add data
+ PolicyVersion pv = new PolicyVersion();
+ pv.setActiveVersion(2);
+ pv.setPolicyName("myPname");
+ pv.prePersist();
+ pv.setCreatedBy("Test");
+ pv.setModifiedBy("Test");
+
+ PolicyVersion pv2 = new PolicyVersion();
+ pv2.setActiveVersion(1);
+ pv2.setPolicyName("test");
+ pv2.prePersist();
+ pv2.setCreatedBy("Test");
+ pv2.setModifiedBy("Test");
+
+ commonClassDao.save(pv);
+ commonClassDao.save(pv2);
+
+ String scope = "my";
+ scope += "%";
+ String query = "From PolicyVersion where policy_name like :scope and id > 0";
+ SimpleBindings params = new SimpleBindings();
+ params.put("scope", scope);
+ List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
+
+
+ assertTrue(1 == dataCur.size());
+ assertEquals(pv, (PolicyVersion) dataCur.get(0));
+
+ }catch(Exception e){
+ logger.debug("Exception Occured"+e);
+ fail();
+ }
+ }
+
+ @Test
+ @Transactional
+ @Rollback(true)
+ public void getDataByQuery_PolicyNotificationMail(){
+ try{
+ // Add data
+ WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
+ String policyFileName = "banana";
+ watch.setLoginIds("Test");
+ watch.setPolicyName("bananaWatch");
+ commonClassDao.save(watch);
+
+ if(policyFileName.contains("/")){
+ policyFileName = policyFileName.substring(0, policyFileName.indexOf("/"));
+ policyFileName = policyFileName.replace("/", File.separator);
+ }
+ if(policyFileName.contains("\\")){
+ policyFileName = policyFileName.substring(0, policyFileName.indexOf("\\"));
+ policyFileName = policyFileName.replace("\\", "\\\\");
+ }
+
+
+ // Current Implementation
+ policyFileName += "%";
+ String query = "from WatchPolicyNotificationTable where policyName like:policyFileName";
+ SimpleBindings params = new SimpleBindings();
+ params.put("policyFileName", policyFileName);
+ List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
+
+ // Assertions
+ assertTrue(dataCur.size() == 1);
+ assertTrue(dataCur.get(0) instanceof WatchPolicyNotificationTable);
+ assertEquals(watch, (WatchPolicyNotificationTable) dataCur.get(0));
+
+ }catch(Exception e){
+ logger.debug("Exception Occured"+e);
+ fail();
+ }
+ }
+
+
+ @Test
+ @Transactional
+ @Rollback(true)
+ public void getDataByQuery_PolicyController(){
+ try{
+ // Add data
+ PolicyEntity pe = new PolicyEntity();
+ String name = "actionDummy";
+ pe.setPolicyName(name);
+ pe.setPolicyData("dummyData");
+ pe.prePersist();
+ pe.setScope("dummyScope");
+ pe.setDescription("descr");
+ pe.setDeleted(false);
+ pe.setCreatedBy("Test");
+ commonClassDao.save(pe);
+
+ String dbCheckName = "dummyScope:action";
+ String[] splitDBCheckName = dbCheckName.split(":");
+
+
+ // Current Implementation
+ String query = "FROM PolicyEntity where policyName like :splitDBCheckName1 and scope = :splitDBCheckName0";
+ SimpleBindings params = new SimpleBindings();
+ params.put("splitDBCheckName1", splitDBCheckName[1] + "%");
+ params.put("splitDBCheckName0", splitDBCheckName[0]);
+ List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
+
+ // Assertions
+ assertTrue(dataCur.size() == 1);
+ assertTrue(dataCur.get(0) instanceof PolicyEntity);
+ assertEquals(pe, (PolicyEntity) dataCur.get(0));
+
+ }catch(Exception e){
+ logger.debug("Exception Occured"+e);
+ fail();
+ }
+ }
+
+ @Test
+ @Transactional
+ @Rollback(true)
+ public void getDataByQuery_PolicyNotificationController(){
+ try{
+ // Add data
+ WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
+ String finalName = "banana"; // Policy File Name
+ String userId = "Test";
+ watch.setLoginIds(userId);
+ watch.setPolicyName(finalName);
+ commonClassDao.save(watch);
+
+
+ // Current Implementation
+ String query = "from WatchPolicyNotificationTable where POLICYNAME = :finalName and LOGINIDS = :userId";
+ SimpleBindings params = new SimpleBindings();
+ params.put("finalName", finalName);
+ params.put("userId", userId);
+ List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
+
+ // Assertions
+ assertTrue(dataCur.size() == 1);
+ assertTrue(dataCur.get(0) instanceof WatchPolicyNotificationTable);
+ assertEquals(watch, (WatchPolicyNotificationTable) dataCur.get(0) );
+
+ }catch(Exception e){
+ logger.debug("Exception Occured"+e);
+ fail();
+ }
+ }
+
+
+ /* Test for SQL Injection Protection
+ */
+
+ @Test
+ @Transactional
+ @Rollback(true)
+ public void getDataByQuery_PolicyNotificationController_Injection(){
+ try{
+ // Add data
+ WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
+ String userId = "Test";
+ watch.setLoginIds(userId);
+ watch.setPolicyName("banana");
+ commonClassDao.save(watch);
+
+ WatchPolicyNotificationTable watch2 = new WatchPolicyNotificationTable();
+ watch2.setLoginIds(userId);
+ watch2.setPolicyName("banana2");
+ commonClassDao.save(watch2);
+
+ // SQL Injection attempt
+ String finalName = "banana' OR '1'='1";
+
+
+ // Current Implementation
+ String query = "from WatchPolicyNotificationTable where POLICYNAME = :finalName and LOGINIDS = :userId";
+ SimpleBindings params = new SimpleBindings();
+ params.put("finalName", finalName);
+ params.put("userId", userId);
+ List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
+
+ // Assertions
+ assertTrue(dataCur.size() <= 1);
+
+ if(dataCur.size() >= 1){
+ assertTrue(dataCur.get(0) instanceof WatchPolicyNotificationTable);
+ assertFalse(watch.equals((WatchPolicyNotificationTable) dataCur.get(0)));
+ assertFalse(watch.equals((WatchPolicyNotificationTable) dataCur.get(0)));
+ }
+ }catch(Exception e){
+ logger.debug("Exception Occured"+e);
+ fail();
+ }
+ }
+
+ @Test
+ public void testCommonClassDaoImplMethods(){
+ try{
+ UserInfo userInfo = new UserInfo();
+ userInfo.setUserLoginId("TestID");
+ userInfo.setUserName("Test");
+ commonClassDao.save(userInfo);
+ List<Object> data = commonClassDao.getDataById(UserInfo.class, "userLoginId:userName", "TestID:Test");
+ assertTrue(data.size() == 1);
+ UserInfo userInfoUpdate = (UserInfo) data.get(0);
+ userInfoUpdate.setUserName("Test1");
+ commonClassDao.update(userInfoUpdate);
+ List<String> data1 = commonClassDao.getDataByColumn(UserInfo.class, "userLoginId");
+ assertTrue(data1.size() == 1);
+ UserInfo data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName", "TestID:Test1");
+ assertTrue("TestID".equals(data2.getUserLoginId()));
+ List<Object> data3 = commonClassDao.checkDuplicateEntry("TestID:Test1", "userLoginId:userName", UserInfo.class);
+ assertTrue(data3.size() == 1);
+ PolicyRoles roles = new PolicyRoles();
+ roles.setRole("admin");
+ roles.setLoginId(userInfo);
+ roles.setScope("test");
+ commonClassDao.save(roles);
+ List<PolicyRoles> roles1 = commonClassDao.getUserRoles();
+ assertTrue(roles1.size() == 1);
+ List<String> multipleData = new ArrayList<>();
+ multipleData.add("TestID:Test1");
+ List<Object> data4 = commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName", multipleData);
+ assertTrue(data4.size() == 1);
+ commonClassDao.delete(data2);
+ }catch(Exception e){
+ logger.debug("Exception Occured"+e);
+ fail();
+ }
+ }
+
+ @After
+ public void deleteDB(){
+ sessionFactory.close();
+ server.stop();
+
+ }
+
+}
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java
index cb373a1bd..151d36a33 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyManagerServlet.java
@@ -1448,7 +1448,7 @@ public class PolicyManagerServlet extends HttpServlet {
policyAdapter.setReadOnly(false);
policyAdapter.setEditPolicy(true);
}
- policyAdapter.setDomain(domain);
+
policyAdapter.setDomainDir(domain);
policyAdapter.setPolicyData(policy);
String policyName = path.replace(".xml", "");
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java
index f38f3e266..64b88134b 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java
@@ -84,23 +84,25 @@ public class PolicyRestController extends RestrictedBaseController{
private static CommonClassDao commonClassDao;
- public static CommonClassDao getCommonClassDao() {
- return commonClassDao;
+ public PolicyRestController(){
+ //default constructor
}
- public static void setCommonClassDao(CommonClassDao commonClassDao) {
- PolicyRestController.commonClassDao = commonClassDao;
- }
-
@Autowired
private PolicyRestController(CommonClassDao commonClassDao){
PolicyRestController.commonClassDao = commonClassDao;
}
- public PolicyRestController(){
- //default constructor
+ public static CommonClassDao getCommonClassDao() {
+ return commonClassDao;
}
+ public static void setCommonClassDao(CommonClassDao commonClassDao) {
+ PolicyRestController.commonClassDao = commonClassDao;
+ }
+
+
+
@RequestMapping(value={"/policycreation/save_policy"}, method={RequestMethod.POST})
public void policyCreationController(HttpServletRequest request, HttpServletResponse response) {
String userId = UserUtils.getUserSession(request).getOrgUserId();
@@ -492,4 +494,4 @@ public class PolicyRestController extends RestrictedBaseController{
callPAP(null, "POST", uri.trim());
}
-} \ No newline at end of file
+}
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java
index e48b0cb19..234d28f10 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java
@@ -467,12 +467,10 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP
final CollectionType javaType =
mapper.getTypeFactory().constructCollectionType(collectionTypeClass, responseContentClass);
- Object objectFromJSON = mapper.readValue(json, javaType);
- return objectFromJSON;
+ return (Object)mapper.readValue(json, javaType);
} else {
// single value object expected
- Object objectFromJSON = mapper.readValue(json, responseContentClass);
- return objectFromJSON;
+ return (Object)mapper.readValue(json, responseContentClass);
}
}
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/conf/HibernateSession.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/conf/HibernateSession.java
index 32f40b9e7..0e1be9349 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/conf/HibernateSession.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/conf/HibernateSession.java
@@ -56,6 +56,13 @@ public class HibernateSession{
LOGGER.error("Exception Occured while creating Log database Hibernate session"+ex);
}
}
+
+ private HibernateSession(){
+ /**
+ empty implementation
+ */
+ }
+
public static Session getSession(){
return logSessionFactory.openSession();
}
@@ -64,6 +71,5 @@ public class HibernateSession{
logSessionFactory = logSessionFactory1;
}
- private HibernateSession(){
- }
+
}
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ActionPolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ActionPolicyController.java
index 0f66a45e6..2f3c91476 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ActionPolicyController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/ActionPolicyController.java
@@ -257,7 +257,7 @@ public class ActionPolicyController extends RestrictedBaseController {
ruleMap.put("dynamicRuleAlgorithmField2", attributeValue);
}
// Rule Attribute added as value
- else if (((jaxbActionTypes.get(0).getValue()) instanceof AttributeValueType)) {
+ else if ((jaxbActionTypes.get(0).getValue()) instanceof AttributeValueType) {
AttributeValueType actionConditionAttributeValue = (AttributeValueType) jaxbActionTypes.get(0).getValue();
String attributeValue = (String) actionConditionAttributeValue.getContent().get(0);
ruleMap.put("dynamicRuleAlgorithmField2", attributeValue);
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java
index 9a1aac1b5..ed32f2904 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyValidationController.java
@@ -46,14 +46,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class PolicyValidationController extends RestrictedBaseController {
private static final Logger LOGGER = FlexLogger.getLogger(PolicyValidationController.class);
-
- public static final String CONFIG_POLICY = "Config";
- public static final String ACTION_POLICY = "Action";
- public static final String DECISION_POLICY = "Decision";
- public static final String CLOSEDLOOP_POLICY = "ClosedLoop_Fault";
- public static final String CLOSEDLOOP_PM = "ClosedLoop_PM";
- public static final String ENFORCER_CONFIG_POLICY= "Enforcer Config";
- public static final String MICROSERVICES="Micro Service";
@RequestMapping(value={"/policyController/validate_policy.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
public ModelAndView validatePolicy(HttpServletRequest request, HttpServletResponse response) throws IOException{
diff --git a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfig.java b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfig.java
index 652fd4da3..aa5ee1304 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfig.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/api/PolicyConfig.java
@@ -111,6 +111,13 @@ public interface PolicyConfig {
* @return <code>Map</code> of <code>String, String</code> which consists of the Response Attributes of the Policy retrieved.
*/
public Map<String,String> getResponseAttributes();
+
+ /**
+ * Gets the {@link PolicyConfigType} of the policy that has been retrieved.
+ *
+ * @return the <code>PolicyConfigType</code> of the policy that has been retrieved.
+ */
+ public PolicyConfigType getPolicyType();
/**
* Returns the <code>String</code> version of the <code>PolicyConfig</code> object.
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 7efee00b8..be363c24f 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/models/APIPolicyConfigResponse.java
@@ -22,12 +22,14 @@ package org.onap.policy.models;
import java.util.Map;
import org.onap.policy.api.PolicyConfigStatus;
+import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.api.PolicyType;
public class APIPolicyConfigResponse implements APIConfigResponse {
private String policyConfigMessage;
private PolicyConfigStatus policyConfigStatus;
private PolicyType type;
+ private PolicyConfigType policyType;
private String config;
private String policyName;
private String policyVersion;
@@ -88,4 +90,10 @@ public class APIPolicyConfigResponse implements APIConfigResponse {
public Map<String,String> getResponseAttributes(){
return responseAttributes;
}
+ public PolicyConfigType getPolicyType() {
+ return policyType;
+ }
+ public void setPolicyType(PolicyConfigType policyType) {
+ this.policyType = policyType;
+ }
}
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 8a9b0a0b4..62db64491 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyConfig.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyConfig.java
@@ -28,6 +28,7 @@ import javax.json.JsonObject;
import org.onap.policy.api.PolicyConfig;
import org.onap.policy.api.PolicyConfigStatus;
+import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.api.PolicyType;
import org.w3c.dom.Document;
@@ -48,6 +49,7 @@ public class StdPolicyConfig implements PolicyConfig{
private String configStatus;
private String policyName;
private String policyVersion;
+ private PolicyConfigType type;
private Map<String,String> matchingConditions;
private Map<String,String> responseAttributes;
@@ -89,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;
}
@@ -158,7 +160,17 @@ public class StdPolicyConfig implements PolicyConfig{
this.responseAttributes = responseAttributes;
}
+
+ public void setPolicyType(PolicyConfigType policyType) {
+ this.type = policyType;
+ }
+
@Override
+ public PolicyConfigType getPolicyType(){
+ return this.type;
+ }
+
+ @Override
public String toString() {
return "PolicyConfig [ policyConfigStatus=" + policyConfigStatus + ", policyConfigMessage=" + configStatus + ", policyName=" + 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 bef964174..6c74dde89 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdPolicyEngine.java
@@ -625,6 +625,7 @@ public class StdPolicyEngine {
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) {
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 798cbde37..fc854b077 100644
--- a/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java
+++ b/PolicyEngineAPI/src/main/java/org/onap/policy/std/StdStatus.java
@@ -29,6 +29,7 @@ import javax.json.JsonObject;
import org.onap.policy.api.DecisionResponse;
import org.onap.policy.api.PolicyConfig;
import org.onap.policy.api.PolicyConfigStatus;
+import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.api.PolicyDecision;
import org.onap.policy.api.PolicyResponse;
import org.onap.policy.api.PolicyResponseStatus;
@@ -39,6 +40,7 @@ public class StdStatus extends StdPolicyResponse implements PolicyConfig, Policy
private PolicyType policyType;
private Properties properties;
private JsonObject jsonObject;
+ private PolicyConfigType type;
private Document document;
private String other;
private PolicyConfigStatus policyConfigStatus;
@@ -232,4 +234,12 @@ public class StdStatus extends StdPolicyResponse implements PolicyConfig, Policy
public String getDetails(){
return details;
}
+
+ public PolicyConfigType getPolicyType() {
+ return type;
+ }
+
+ public void setPolicyType(PolicyConfigType policyType) {
+ this.type = policyType;
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigBasePolicyClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigBasePolicyClient.java
index b8dfdc1f6..cfcc1460b 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigBasePolicyClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigBasePolicyClient.java
@@ -1,4 +1,4 @@
-/*-
+ /*-
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
@@ -47,8 +47,7 @@ public class ConfigBasePolicyClient{
policyParameters.setConfigName("testBase"); //required
policyParameters.setConfigBodyType(PolicyType.OTHER); //required
policyParameters.setConfigBody("testing"); //required
- //policyParameters.setPolicyScope("MikeConsole"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI
-
+
//Set the Config Attributes... These are Optional
Map<String, String> configAttributes = new HashMap<>();
configAttributes.put("Template", "SampleTemplate");
diff --git a/packages/base/src/files/install/elk/config/elasticsearch.yml b/packages/base/src/files/install/elk/config/elasticsearch.yml
index ec6def080..ef32b08d0 100644
--- a/packages/base/src/files/install/elk/config/elasticsearch.yml
+++ b/packages/base/src/files/install/elk/config/elasticsearch.yml
@@ -89,3 +89,8 @@ network.bind_host: ["_local_"]
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
+#--------------------------------- Scripting -----------------------------------
+# These will be removed in v6.0
+script.inline: false
+script.stored: false
+script.file: false