From: Jorge Hernandez Date: Mon, 30 Oct 2017 20:01:01 +0000 (+0000) Subject: Merge "Fixed a bug on view and editor screens" X-Git-Tag: v1.1.0~9 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=commitdiff_plain;h=7727ac7ce0b25e07dcdc1a29962356c6bf9c94d9;hp=c7ccf9980b0299a65c55e906f7267bf241abd107 Merge "Fixed a bug on view and editor screens" --- diff --git a/.gitignore b/.gitignore index 46f3928ab..4640bd995 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,27 @@ XACML-PDP-REST/catalina.base_IS_UNDEFINED/logs/Policy/XACML-PDP-REST/metrics.log XACML-REST/IntegrityMonitor.log /bin/ *.checkstyle +BRMSGateway/logs/ +BRMSGateway/sql/ +BRMSGateway/src/test/resources/META-INF/generatedCreate.ddl +BRMSGateway/src/test/resources/META-INF/generatedDrop.ddl +BRMSGateway/src/test/resources/failure.properties +LogParser/logs/ +ONAP-PAP-REST/catalina.base_IS_UNDEFINED/ +ONAP-PAP-REST/pdps/ +ONAP-PAP-REST/sql/ +ONAP-PAP-REST/src/test/resources/generatedCreate.ddl +ONAP-PAP-REST/src/test/resources/generatedDrop.ddl +ONAP-PAP-REST/src/test/resources/webapps/ +ONAP-PDP-REST/catalina.base_IS_UNDEFINED/ +ONAP-PDP-REST/sql/ +ONAP-PDP-REST/src/test/resources/config_testing/ +ONAP-PDP-REST/src/test/resources/generatedCreate.ddl +ONAP-PDP-REST/src/test/resources/generatedDrop.ddl +ONAP-PDP-REST/topicBackup.txt +ONAP-PDP/logs/ +ONAP-XACML/logs/ +ONAP-XACML/src/test/resources/pdpstest/ +POLICY-SDK-APP/catalina.base_IS_UNDEFINED/ +PolicyEngineAPI/logs/ +PolicyEngineUtils/logs/ diff --git a/BRMSGateway/config.properties b/BRMSGateway/config.properties index 762f0ff1f..b17804bd5 100644 --- a/BRMSGateway/config.properties +++ b/BRMSGateway/config.properties @@ -47,19 +47,17 @@ repositoryPassword=admin123 policyKeyID = controller ## GroupNames can be comma separated values. -groupNames = default, vFW , vDNS +groupNames = default, amsterdam default.groupID = org.onap.policy-engine default.artifactID = drlPDPGroup -vFW.groupID= org.onap.policy-engine.drools.vFW -vFW.artifactID= policy-vFW-rules -vDNS.groupID= org.onap.policy-engine.drools.vDNS -vDNS.artifactID= policy-vDNS-rules +amsterdam.groupID= org.onap.policy-engine.drools.amsterdam +amsterdam.artifactID= policy-amsterdam-rules #Integrity Monitor values #database driver for Integrity Monitor -javax.persistence.jdbc.driver=com.mysql.jdbc.Driver +javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver #database URL for Integrity Monitor -javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/xacml +javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk #database username for Integrity Monitor javax.persistence.jdbc.user=policy_user #database password for Integrity Monitor diff --git a/BRMSGateway/dependency.json b/BRMSGateway/dependency.json index a883cc9da..f758db096 100644 --- a/BRMSGateway/dependency.json +++ b/BRMSGateway/dependency.json @@ -1,33 +1,102 @@ { - "dependencies": { - "default": [{ - "groupId": "org.onap.policy.drools-applications", - "artifactId": "demo", - "version": "1.1.0-SNAPSHOT" - }, { - "groupId": "org.onap.policy.drools-applications", - "artifactId": "events", - "version": "1.1.0-SNAPSHOT" - }, { - "groupId": "org.onap.policy.drools-applications", - "artifactId": "rest", - "version": "1.1.0-SNAPSHOT" - }, { - "groupId": "org.onap.policy.drools-applications", - "artifactId": "appc", - "version": "1.1.0-SNAPSHOT" - }, { - "groupId": "org.onap.policy.drools-applications", - "artifactId": "aai", - "version": "1.1.0-SNAPSHOT" - }, { - "groupId": "org.onap.policy.drools-applications", - "artifactId": "mso", - "version": "1.1.0-SNAPSHOT" - }, { - "groupId": "org.onap.policy.drools-applications", - "artifactId": "trafficgenerator", - "version": "1.1.0-SNAPSHOT" - }] - } + "dependencies": { + "default": [{ + "groupId": "org.onap.policy.drools-applications", + "artifactId": "demo", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "events", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "rest", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "appc", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "aai", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "mso", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "trafficgenerator", + "version": "1.1.0-SNAPSHOT" + }], + "amsterdam": [{ + "groupId": "org.onap.policy.drools-applications", + "artifactId": "events", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "appc", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "appclcm", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "vfc", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "so", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "aai", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "sdc", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "trafficgenerator", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "eventmanager", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "guard", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "actorServiceProvider", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "actor.appc", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "actor.appclcm", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "actor.so", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "actor.vfc", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "org.onap.policy.drools-applications", + "artifactId": "policy-yaml", + "version": "1.1.0-SNAPSHOT" + }, { + "groupId": "com.att.research.xacml", + "artifactId": "xacml-pdp", + "version": "1.0.0" + }] + } } \ No newline at end of file diff --git a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSHandler.java b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSHandler.java index 43031861b..a11e8b4b7 100644 --- a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSHandler.java +++ b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSHandler.java @@ -95,7 +95,7 @@ public class BRMSHandler implements BackUpHandler{ } } } - Boolean failureFlag = false; + Boolean failureFlag; int i = 0; do{ failureFlag = false; @@ -118,6 +118,7 @@ public class BRMSHandler implements BackUpHandler{ * (non-Javadoc) * @see org.onap.policy.utils.BackUpHandler#runOnNotification(org.onap.policy.api.PDPNotification) */ + @Override public void runOnNotification(PDPNotification notification){ if(notification.getNotificationType().equals(NotificationType.REMOVE)){ removedPolicies(notification.getRemovedPolicies()); diff --git a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java index c923c3c34..266e090a2 100644 --- a/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java +++ b/BRMSGateway/src/main/java/org/onap/policy/brmsInterface/BRMSPush.java @@ -109,6 +109,7 @@ public class BRMSPush { private static final String[] GOALS = { "clean", "deploy" }; private static final String DEFAULT_VERSION = "1.1.0-SNAPSHOT"; private static final String DEPENDENCY_FILE = "dependency.json"; + private static final String BRMSPERSISTENCE = "brmsEclipselink.persistencexml"; private static Map modifiedGroups = new HashMap<>(); private static IntegrityMonitor im; @@ -188,8 +189,10 @@ public class BRMSPush { } catch (Exception e) { LOGGER.error("Error starting BackUpMonitor: " + e); } - if(!config.containsKey(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML)){ + if(!config.containsKey(BRMSPERSISTENCE)){ config.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "META-INF/persistenceBRMS.xml"); + } else { + config.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, config.getProperty(BRMSPERSISTENCE,"META-INF/persistenceBRMS.xml")); } EntityManagerFactory emf = Persistence.createEntityManagerFactory("BRMSGW", config); em = emf.createEntityManager(); @@ -388,11 +391,11 @@ public class BRMSPush { selectedName = responseAttributes.get(key); } // kmodule configurations - else if (key.equals("kSessionName")) { + else if ("kSessionName".equals(key)) { kSessionName = responseAttributes.get(key); } // Check User Specific values. - if (key.equals("$controller:")) { + if ("$controller:".equals(key)) { try { PEDependency dependency = PolicyUtils.jsonStringToObject(responseAttributes.get(key), PEDependency.class); @@ -402,7 +405,7 @@ public class BRMSPush { LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while resolving Controller: " + e); } - } else if (key.equals("$dependency$")) { + } else if ("$dependency$".equals(key)) { String value = responseAttributes.get(key); if (value.startsWith("[") && value.endsWith("]")) { value = value.substring(1, value.length() - 1).trim(); @@ -500,7 +503,7 @@ public class BRMSPush { List pList = query.getResultList(); boolean createFlag = false; BRMSPolicyInfo brmsPolicyInfo = new BRMSPolicyInfo(); - if (pList.size() > 0) { + if (!pList.isEmpty()) { // Already exists. brmsPolicyInfo = (BRMSPolicyInfo) pList.get(0); if (!brmsPolicyInfo.getControllerName().getControllerName().equals(controllerName)) { @@ -514,7 +517,7 @@ public class BRMSPush { query.setParameter("cn", controllerName); List bList = query.getResultList(); BRMSGroupInfo brmsGroupInfo = new BRMSGroupInfo(); - if (bList.size() > 0) { + if (!bList.isEmpty()) { brmsGroupInfo = (BRMSGroupInfo) bList.get(0); } brmsPolicyInfo.setPolicyName(policyName); @@ -528,7 +531,7 @@ public class BRMSPush { private void syncProject(String selectedName) { boolean projectExists = checkProject(selectedName); if (projectExists) { - String version = null; + String version; version = getVersion(selectedName); if (version == null) { LOGGER.error("Error getting local version for the given Controller Name:" + selectedName @@ -599,7 +602,6 @@ public class BRMSPush { } fos.close(); is.close(); - f = null; LOGGER.info(fileName + " Created.."); } } @@ -641,7 +643,7 @@ public class BRMSPush { private boolean checkRemoteSync(String selectedName, String version) { List artifacts = getArtifactFromNexus(selectedName, version); - return (artifacts.size() == 0) ? false : true; + return artifacts.isEmpty() ? false : true; } private List getArtifactFromNexus(String selectedName, String version) { @@ -690,7 +692,7 @@ public class BRMSPush { if (artifact != null) { newVersion = incrementVersion(artifact.getVersion()); } - if (newVersion.equals("0.1.0")) { + if ("0.1.0".equals(newVersion)) { createFlag = true; } setVersion(newVersion, selectedName); @@ -736,8 +738,9 @@ public class BRMSPush { } if (!modifiedGroups.isEmpty()) { Boolean flag = false; - for (String group : modifiedGroups.keySet()) { + for (Map.Entry entry : modifiedGroups.entrySet()) { InvocationResult result = null; + String group = entry.getKey(); try { InvocationRequest request = new DefaultInvocationRequest(); setVersion(group); @@ -761,7 +764,7 @@ public class BRMSPush { if (createFlag) { addNotification(group, "create"); } else { - addNotification(group, modifiedGroups.get(group)); + addNotification(group, entry.getValue()); } flag = true; } else { @@ -795,7 +798,7 @@ public class BRMSPush { return policyMap.get(name); } else { syncGroupInfo(); - return (policyMap.containsKey(name)) ? policyMap.get(name) : null; + return policyMap.containsKey(name) ? policyMap.get(name) : null; } } @@ -869,7 +872,7 @@ public class BRMSPush { pub.send("MyPartitionKey", message); final List stuck = pub.close(uebDelay, TimeUnit.SECONDS); - if (stuck.size() > 0) { + if (!stuck.isEmpty()) { LOGGER.error(stuck.size() + " messages unsent"); } else { LOGGER.debug("Clean exit; Message Published on UEB : " + uebList + "for Topic: " + pubTopic); @@ -1018,7 +1021,7 @@ public class BRMSPush { } private void readGroups(Properties config) throws PolicyException { - String[] groupNames = null; + String[] groupNames; if (!config.containsKey("groupNames") || config.getProperty("groupNames")==null){ throw new PolicyException(XACMLErrorConstants.ERROR_DATA_ISSUE + "groupNames property is missing or empty from the property file "); @@ -1069,7 +1072,7 @@ public class BRMSPush { query.setParameter("cn", name); List groupList = query.getResultList(); BRMSGroupInfo brmsGroupInfo = null; - if (groupList.size() > 0) { + if (!groupList.isEmpty()) { LOGGER.info("Controller name already Existing in DB. Will be updating the DB Values" + name); brmsGroupInfo = (BRMSGroupInfo) groupList.get(0); } @@ -1122,8 +1125,8 @@ public class BRMSPush { Query query = em.createQuery("select b from BRMSPolicyInfo as b where b.policyName = :pn"); query.setParameter("pn", policyName); List pList = query.getResultList(); - BRMSPolicyInfo brmsPolicyInfo = new BRMSPolicyInfo(); - if (pList.size() > 0) { + BRMSPolicyInfo brmsPolicyInfo; + if (!pList.isEmpty()) { // Already exists. brmsPolicyInfo = (BRMSPolicyInfo) pList.get(0); if (brmsPolicyInfo.getControllerName().getControllerName().equals(controllerName)) { diff --git a/BRMSGateway/src/test/resources/config.properties b/BRMSGateway/src/test/resources/config.properties index 4f9e01305..8c46ec277 100644 --- a/BRMSGateway/src/test/resources/config.properties +++ b/BRMSGateway/src/test/resources/config.properties @@ -65,7 +65,7 @@ javax.persistence.jdbc.user=sa #database password for Integrity Monitor javax.persistence.jdbc.password= #persistence xml -eclipselink.persistencexml=META-INF/persistenceBRMStest.xml +brmsEclipselink.persistencexml=META-INF/persistenceBRMStest.xml #resource name RESOURCE_NAME=site_1.brmsgw_1 #***Properties for IntegrityMonitor integration defined in IntegrityMonitorProperties.java*** diff --git a/LogParser/parserlog.properties b/LogParser/parserlog.properties index 4a5ecdb9c..66ce34d19 100644 --- a/LogParser/parserlog.properties +++ b/LogParser/parserlog.properties @@ -20,14 +20,14 @@ #Health Check Values RESOURCE_NAME=logparser_pap01 -javax.persistence.jdbc.driver=com.mysql.jdbc.Driver -javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/onap_sdk +javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver +javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk javax.persistence.jdbc.user=policy_user javax.persistence.jdbc.password=policy_user #Log Parser application values -JDBC_DRIVER=com.mysql.jdbc.Driver -JDBC_URL=jdbc:mysql://localhost:3306/log +JDBC_DRIVER=org.mariadb.jdbc.Driver +JDBC_URL=jdbc:mariadb://localhost:3306/log JDBC_USER=policy_user JDBC_PASSWORD=policy_user SERVER=https://localhost:9091/pap/ diff --git a/LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java b/LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java index c12797f28..1f42ac39b 100644 --- a/LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java +++ b/LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java @@ -122,8 +122,8 @@ public class ParseLogTest { config = new Properties(); config.put("RESOURCE_NAME", "logparser_pap01"); - config.put("JDBC_DRIVER" ,"com.mysql.jdbc.Driver"); - config.put("JDBC_URL", "jdbc:mysql://localhost:3306/"); + config.put("JDBC_DRIVER" ,"org.mariadb.jdbc.Driver"); + config.put("JDBC_URL", "jdbc:mariadb://localhost:3306/"); config.put("JDBC_USER", "root"); config.put("JDBC_PASSWORD", "password"); config.put("JMX_URL", "service:jmx:rmi:///jndi/rmi://localhost:9998/jmxrmi"); diff --git a/LogParser/src/test/resources/test_config.properties b/LogParser/src/test/resources/test_config.properties index 6512184c8..ca2b9edc9 100644 --- a/LogParser/src/test/resources/test_config.properties +++ b/LogParser/src/test/resources/test_config.properties @@ -20,8 +20,8 @@ RESOURCE_NAME=logparser_pap01 -JDBC_DRIVER=com.mysql.jdbc.Driver -JDBC_URL=jdbc:mysql://localhost:3306/ +JDBC_DRIVER=org.mariadb.jdbc.Driver +JDBC_URL=jdbc:mariadb://localhost:3306/ JDBC_USER=root JDBC_PASSWORD=password jmx_url=service:jmx:rmi:///jndi/rmi://localhost:9996/jmxrmi diff --git a/ONAP-PAP-REST/policyelk.properties b/ONAP-PAP-REST/policyelk.properties index 386008ce5..d07fab90a 100644 --- a/ONAP-PAP-REST/policyelk.properties +++ b/ONAP-PAP-REST/policyelk.properties @@ -24,7 +24,7 @@ policy.elk.url=http://localhost:9200 #Policy Database properties -policy.database.driver=com.mysql.jdbc.Driver -policy.database.url=jdbc:mysql://localhost:3306/onap_sdk?autoReconnect=true&useSSL=false +policy.database.driver=org.mariadb.jdbc.Driver +policy.database.url=jdbc:mariadb://localhost:3306/onap_sdk?autoReconnect=true&useSSL=false policy.database.username=policy_user policy.database.password=policy_user \ No newline at end of file diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java index b27dd22ca..3ed2ee37d 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java @@ -34,6 +34,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -116,10 +117,8 @@ public class CreateBrmsParamPolicy extends Policy { // Utility to read json data from the existing file to a string static String readFile(String path, Charset encoding) throws IOException { - byte[] encoded = Files.readAllBytes(Paths.get(path)); return new String(encoded, encoding); - } // Saving the Configurations file at server location for config policy. @@ -135,8 +134,6 @@ public class CreateBrmsParamPolicy extends Policy { policyAdapter.setJsonBody(expandedBody); policyAdapter.setConfigBodyData(expandedBody); out.close(); - - } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving configuration file"); } @@ -207,7 +204,7 @@ public class CreateBrmsParamPolicy extends Policy { Map mapFieldType= new HashMap<>(); if(rule!=null){ try { - String params = ""; + StringBuilder params = new StringBuilder(); Boolean flag = false; Boolean comment = false; String lines[] = rule.split("\n"); @@ -252,19 +249,19 @@ public class CreateBrmsParamPolicy extends Policy { continue; } if (flag) { - params = params + line; + params.append(line); } - if (line.contains("declare Params")) { - params = params + line; + if (line.contains("declare PapParams")) { + params.append(line); flag = true; } if (line.contains("end") && flag) { break; } } - params = params.replace("declare Params", "").replace("end", "") + String param = params.toString().replace("declare PapParams", "").replace("end", "") .replaceAll("\\s+", ""); - String[] components = params.split(":"); + String[] components = param.split(":"); String caption = ""; for (int i = 0; i < components.length; i++) { String type = ""; @@ -335,16 +332,16 @@ public class CreateBrmsParamPolicy extends Policy { //Get the type of the UI Fields. Map typeOfUIField=findType(valueFromDictionary); - String generatedRule=null; - String body = ""; + StringBuilder generatedRule = new StringBuilder(); + StringBuilder body = new StringBuilder(); try { try { - body = "/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose. \n\t " + - "<$%BRMSParamTemplate=" + tempateValue + "%$> \n */ \n"; - body = body + valueFromDictionary + "\n"; - generatedRule = "rule \"" +policyName.substring(0, policyName.replace(".xml", "").lastIndexOf(".")) +".Params\" \n\tsalience 1000 \n\twhen\n\tthen\n\t\tParams params = new Params();"; + body.append("/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose. \n\t " + + "<$%BRMSParamTemplate=" + tempateValue + "%$> \n */ \n"); + body.append(valueFromDictionary + "\n"); + generatedRule.append("rule \"" +policyName.substring(0, policyName.replace(".xml", "").lastIndexOf(".")) +".PapParams\" \n\tsalience 1000 \n\twhen\n\tthen\n\t\tPapParams params = new PapParams();"); //We first read the map data structure(ruleAndUIValue) received from the PAP-ADMIN //We ignore if the key is "templateName as we are interested only in the UI fields and its value. @@ -361,24 +358,23 @@ public class CreateBrmsParamPolicy extends Policy { if(fieldType.getValue()=="String") { //Type is String - generatedRule = generatedRule + "\n\t\tparams.set" + generatedRule.append("\n\t\tparams.set" + key + "(\"" - + entry.getValue() + "\");"; + + entry.getValue() + "\");"); } else{ - generatedRule = generatedRule + "\n\t\tparams.set" + generatedRule.append("\n\t\tparams.set" + key + "(" - + entry.getValue() + ");"; + + entry.getValue() + ");"); } } } } } - generatedRule = generatedRule - + "\n\t\tinsert(params);\nend"; + generatedRule.append("\n\t\tinsert(params);\nend"); LOGGER.info("New rule generated with :" + generatedRule); - body = body + generatedRule; + body.append(generatedRule); } catch (Exception e) { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving policy"); } @@ -387,10 +383,10 @@ public class CreateBrmsParamPolicy extends Policy { PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving policy"); } - saveConfigurations(policyName,body); + saveConfigurations(policyName,body.toString()); // Make sure the filename ends with an extension - if (policyName.endsWith(".xml") == false) { + if (!policyName.endsWith(".xml")) { policyName = policyName + ".xml"; } @@ -429,7 +425,7 @@ public class CreateBrmsParamPolicy extends Policy { anyOf.getAllOf().add(allOf); TargetType target = new TargetType(); - ((TargetType) target).getAnyOf().add(anyOf); + target.getAnyOf().add(anyOf); // Adding the target to the policy element configPolicy.setTarget((TargetType) target); @@ -536,14 +532,14 @@ public class CreateBrmsParamPolicy extends Policy { assignment2.setAttributeId("URLID"); assignment2.setCategory(CATEGORY_RESOURCE); assignment2.setIssuer(""); - AttributeValueType AttributeValue = new AttributeValueType(); - AttributeValue.setDataType(URI_DATATYPE); + AttributeValueType attributeValue = new AttributeValueType(); + attributeValue.setDataType(URI_DATATYPE); String content = CONFIG_URL + "/Config/"+ getConfigFile(policyName); - AttributeValue.getContent().add(content); + attributeValue.getContent().add(content); assignment2.setExpression(new ObjectFactory() - .createAttributeValue(AttributeValue)); + .createAttributeValue(attributeValue)); advice.getAttributeAssignmentExpression().add(assignment2); // Policy Name Assignment @@ -624,8 +620,8 @@ public class CreateBrmsParamPolicy extends Policy { // Dynamic Field Config Attributes. Map dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes(); - for (String keyField : dynamicFieldConfigAttributes.keySet()) { - advice.getAttributeAssignmentExpression().add(createResponseAttributes("key:"+keyField, dynamicFieldConfigAttributes.get(keyField))); + for (Entry map : dynamicFieldConfigAttributes.entrySet()) { + advice.getAttributeAssignmentExpression().add(createResponseAttributes("key:"+map.getKey(), map.getValue())); } //Risk Attributes diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java index eae3e79a9..22d2da311 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java @@ -63,6 +63,7 @@ import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.std.pip.engines.aaf.AAFEngine; import org.onap.policy.xacml.util.XACMLPolicyScanner; +import com.att.research.xacml.api.XACML3; import com.att.research.xacml.api.pap.PAPException; import com.att.research.xacml.std.IdentifierImpl; @@ -229,7 +230,8 @@ public class DecisionPolicy extends Policy { decisionPolicy.setTarget(target); Map dynamicFieldDecisionSettings = policyAdapter.getDynamicSettingsMap(); - if(policyAdapter.getRuleProvider()!=null && policyAdapter.getRuleProvider().equals(AAFPROVIDER)){ + if(policyAdapter.getRuleProvider()!=null && (policyAdapter.getRuleProvider().equals(AAFPROVIDER)|| + policyAdapter.getRuleProvider().equals(RAINY_DAY))){ dynamicFieldDecisionSettings = new HashMap<>(); } @@ -241,8 +243,8 @@ public class DecisionPolicy extends Policy { VariableDefinitionType dynamicVariable = createDynamicVariable(key, value, dataType); decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(dynamicVariable); } - Map dynamicFieldTreatmentAttributes = policyAdapter.getRainydayMap(); + Map dynamicFieldTreatmentAttributes = policyAdapter.getRainydayMap(); if(policyAdapter.getRuleProvider().equals(RAINY_DAY)){ for(String keyField : dynamicFieldTreatmentAttributes.keySet()) { String errorcode = keyField; @@ -423,7 +425,6 @@ public class DecisionPolicy extends Policy { // Values for AAF Provider are here for XML Creation. ConditionType condition = new ConditionType(); ApplyType decisionApply = new ApplyType(); - String selectedFunction = "boolean-equal"; AttributeValueType value1 = new AttributeValueType(); value1.setDataType(BOOLEAN_DATATYPE); @@ -439,7 +440,7 @@ public class DecisionPolicy extends Policy { innerDecisionApply.setFunctionId(FUNCTION_BOOLEAN_ONE_AND_ONLY); innerDecisionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(value2)); - decisionApply.setFunctionId(dropDownMap.get(selectedFunction)); + decisionApply.setFunctionId(XACML3.ID_FUNCTION_BOOLEAN_EQUAL.stringValue()); decisionApply.getExpression().add(new ObjectFactory().createAttributeValue(value1)); decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply)); condition.setExpression(new ObjectFactory().createApply(decisionApply)); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java index d142a46f3..675c82549 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java @@ -35,6 +35,7 @@ import org.json.JSONObject; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.pap.xacml.rest.adapters.GridData; +import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl; import org.onap.policy.pap.xacml.rest.util.JsonMessage; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ClosedLoopD2Services; @@ -1042,6 +1043,10 @@ public class ClosedLoopDictionaryController{ } return null; } + + public static void setCommonClassDao(CommonClassDaoImpl commonClassDaoImpl) { + commonClassDao = commonClassDaoImpl; + } } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java index aac777a67..f4e32ebea 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java @@ -20,19 +20,9 @@ package org.onap.policy.pap.xacml.rest.controller; -import java.io.IOException; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.json.JSONObject; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; @@ -49,9 +39,17 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; @Controller public class DecisionPolicyDictionaryController { @@ -184,7 +182,7 @@ public class DecisionPolicyDictionaryController { } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (!"Duplicate".equals(responseString)) { if(isFakeUpdate){ responseString = "Exists"; } else { @@ -264,7 +262,7 @@ public class DecisionPolicyDictionaryController { @RequestMapping(value={"/get_RainyDayDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getRainyDayDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getRainyDayDictionaryEntityData(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -329,8 +327,8 @@ public class DecisionPolicyDictionaryController { counter ++; } } + decisionRainyDay.setTreatments(userValue); } - decisionRainyDay.setTreatments(userValue); if(decisionRainyDay.getId() == 0){ List duplicateData = commonClassDao.checkDuplicateEntry(decisionRainyDay.getBbid()+":"+decisionRainyDay.getWorkstep(), "bbid:workstep", RainyDayTreatments.class); @@ -352,7 +350,7 @@ public class DecisionPolicyDictionaryController { } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (!"Duplicate".equals(responseString)) { if(isFakeUpdate){ responseString = "Exists"; } else { @@ -416,7 +414,7 @@ public class DecisionPolicyDictionaryController { } class TreatmentValues { - private ArrayList userDataTypeValues; + private ArrayList userDataTypeValues = new ArrayList<>(); public ArrayList getUserDataTypeValues() { return userDataTypeValues; diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java index 86706d154..3a4d7b71b 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java @@ -103,6 +103,11 @@ public class FirewallDictionaryController { public FirewallDictionaryController(CommonClassDao commonClassDao){ FirewallDictionaryController.commonClassDao = commonClassDao; } + + public static void setCommonClassDao(CommonClassDao clDao){ + commonClassDao = clDao; + } + /* * This is an empty constructor */ 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 5d2b7f6c7..1766cb302 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 @@ -242,7 +242,12 @@ public class CommonClassDaoImpl implements CommonClassDao{ try { Query hbquery = session.createQuery(query); for (Map.Entry paramPair : params.entrySet()) { - hbquery.setParameter(paramPair.getKey(), paramPair.getValue()); + if(paramPair.getValue() instanceof java.lang.Long){ + hbquery.setLong(paramPair.getKey(), (long) paramPair.getValue()); + } + else{ + hbquery.setParameter(paramPair.getKey(), paramPair.getValue()); + } } data = hbquery.list(); tx.commit(); 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 97da76708..78da2a572 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 @@ -388,17 +388,17 @@ public class PolicyElasticSearchController{ case clVarbind : VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class); value = varbindDictionary.getVarbindName(); - policyList = searchElkDatabase(closedloop, "jsonBodyData.triggerSignaturesUsedForUI.signatures",value); + policyList = searchElkDatabase(closedloop, "jsonBodyData","*"+value+"*"); break; case clVnf : VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class); value = vNFType.getVnftype(); - policyList = searchElkDatabase(closedloop, "jsonBodyData.vnfType",value); + policyList = searchElkDatabase(closedloop, "jsonBodyData","*"+value+"*"); break; case clVSCL : VSCLAction vsclAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class); value = vsclAction.getVsclaction(); - policyList = searchElkDatabase(closedloop, "jsonBodyData.actions",value); + policyList = searchElkDatabase(closedloop, "jsonBodyData","*"+value+"*"); break; case decision : DecisionSettings decisionSettings = (DecisionSettings)mapper.readValue(root.get("data").toString(), DecisionSettings.class); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java index 13eee4a3f..ae749adb5 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/DictionaryHandlerImpl.java @@ -69,6 +69,9 @@ public class DictionaryHandlerImpl implements DictionaryHandler{ case "Settings": dictionary.getSettingsDictionary(response); break; + case "RainyDayTreatments": + dictionary.getRainyDayDictionary(response); + break; case "DescriptiveScope": dictionary.getDescriptiveDictionary(response); break; @@ -212,6 +215,9 @@ public class DictionaryHandlerImpl implements DictionaryHandler{ case "Settings": result = dictionary.saveSettingsDictionary(request, response); break; + case "RainyDayTreatments": + result = dictionary.saveRainyDayDictionary(request, response); + break; case "DescriptiveScope": result = dictionary.saveDescriptiveDictionary(request, response); break; 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 c86ded43f..e7680c3e2 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 @@ -131,6 +131,8 @@ public class SavePolicyHandler { 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/service/DictionaryService.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java index 5b2fc4cd7..6e19b9b1c 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java @@ -121,6 +121,13 @@ public class DictionaryService { return result.getViewName(); } + public String saveRainyDayDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ + + DecisionPolicyDictionaryController dictionary = new DecisionPolicyDictionaryController(); + ModelAndView result = dictionary.saveRainyDayDictionary(request, response); + return result.getViewName(); + } + public String saveDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ DescriptiveDictionaryController dictionary = new DescriptiveDictionaryController(); @@ -343,6 +350,11 @@ public class DictionaryService { dictionary.getSettingsDictionaryEntityData(response); } + public void getRainyDayDictionary(HttpServletResponse response){ + DecisionPolicyDictionaryController dictionary = new DecisionPolicyDictionaryController(); + dictionary.getRainyDayDictionaryEntityData(response); + } + public void getDescriptiveDictionary(HttpServletResponse response){ DescriptiveDictionaryController dictionary = new DescriptiveDictionaryController(); dictionary.getDescriptiveDictionaryEntityData(response); diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/ia/DbAuditCompareEntriesTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/ia/DbAuditCompareEntriesTest.java index f913c181f..13255ba50 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/ia/DbAuditCompareEntriesTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/ia/DbAuditCompareEntriesTest.java @@ -233,7 +233,7 @@ public class DbAuditCompareEntriesTest { entry1.setFlag("flag1"); - entry1.setResoruceNodeName("node1"); + entry1.setResourceNodeName("node1"); entry1.setResourceName("resourceName"); entry1.setTimeStamp(new Date()); diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java index f110c5b6a..82088937e 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/test/XACMLPAPTest.java @@ -23,11 +23,15 @@ package org.onap.policy.pap.test; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.sql.SQLException; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import javax.servlet.ServletConfig; @@ -43,8 +47,14 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; import org.onap.policy.pap.xacml.rest.XACMLPapServlet; +import org.onap.policy.pap.xacml.rest.controller.ClosedLoopDictionaryController; +import org.onap.policy.pap.xacml.rest.controller.FirewallDictionaryController; import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl; import org.onap.policy.pap.xacml.rest.policycontroller.PolicyCreation; +import org.onap.policy.rest.dao.CommonClassDao; +import org.onap.policy.rest.jpa.BRMSParamTemplate; +import org.onap.policy.rest.jpa.PolicyEditorScopes; +import org.onap.policy.rest.jpa.UserInfo; import org.onap.policy.utils.PolicyUtils; import org.onap.policy.xacml.std.pap.StdPAPPolicy; import org.springframework.mock.web.MockHttpServletResponse; @@ -84,7 +94,7 @@ public class XACMLPAPTest { @Test public void testFirwallCreatePolicy() throws IOException, ServletException, SQLException { httpServletRequest = Mockito.mock(HttpServletRequest.class); - String json = ""; + String json = "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicyConfig\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev1a\",\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Sshservice entry in servicelist\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}],\"addressGroups\":[{\"name\":\"test\",\"description\":\"Destination\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\",\"description\":\"SourceTestServers for firsttesting\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"FWRuleTestServerToTest\",\"fromZones\":[\"UntrustedZoneTestName\"],\"toZones\":[\"TrustedZoneTestName\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TestServers\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\",\"description\":\"FWrule for Test source to Test destination\",\"enabled\":true,\"log\":true}]}"; Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL"); Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT"); Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api"); @@ -102,10 +112,429 @@ public class XACMLPAPTest { Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); Mockito.verify(httpServletResponse).addHeader("successMapKey", "success"); Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_FW_test.1.xml"); + } + + @Test + public void testBRMSCreatePolicy() throws IOException, ServletException, SQLException { + httpServletRequest = Mockito.mock(HttpServletRequest.class); + Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL"); + Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT"); + Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api"); + Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create"); + Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config"); + Map matchingAttributes = new HashMap<>(); + Map ruleAttributes = new HashMap<>(); + ruleAttributes.put("templateName", "testPolicy"); + ruleAttributes.put("samPoll", "5"); + ruleAttributes.put("value", "test"); + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("BRMS_Param","test", "testing", + "BRMS_PARAM_RULE",false,"test", + matchingAttributes, 0, "DROOLS", + null, ruleAttributes, "5", + "default", "false", "", null, null); + MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes()); + Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); + + // set DBDao + setDBDao(); + setPolicyCreation(); + pap.service(httpServletRequest, httpServletResponse); + + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + Mockito.verify(httpServletResponse).addHeader("successMapKey", "success"); + Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_BRMS_Param_test.1.xml"); + } + + @Test + public void testBRMSRawCreatePolicy() throws IOException, ServletException, SQLException { + httpServletRequest = Mockito.mock(HttpServletRequest.class); + Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL"); + Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT"); + Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api"); + Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create"); + Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config"); + Map ruleAttributes = new HashMap<>(); + ruleAttributes.put("value", "test"); + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("BRMS_Raw","test","testig description", + "BRMS_RAW_RULE",false,"test", ruleAttributes, 0, "DROOLS", + "test", "4", + "default", "false", null, null, null); + MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes()); + Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); + + // set DBDao + setDBDao(); + setPolicyCreation(); + pap.service(httpServletRequest, httpServletResponse); + + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + Mockito.verify(httpServletResponse).addHeader("successMapKey", "success"); + Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_BRMS_Raw_test.1.xml"); + } + + @Test + public void testClosedLoopPMCreatePolicy() throws IOException, ServletException, SQLException { + httpServletRequest = Mockito.mock(HttpServletRequest.class); + Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL"); + Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT"); + Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api"); + Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create"); + Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config"); + String json = "{\"test\":\"java\"}"; + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("ClosedLoop_PM", "test", "testing", "onap", + json, false, null, "Registration Failure(Trinity)", false, "test", 0, null, + "default", "true", ""); + MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes()); + Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); + + // set DBDao + setDBDao(); + setPolicyCreation(); + pap.service(httpServletRequest, httpServletResponse); + + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + Mockito.verify(httpServletResponse).addHeader("successMapKey", "success"); + Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_PM_test.1.xml"); + } + + @Test + public void testDecisonAAFPolicy() throws IOException, ServletException, SQLException { + httpServletRequest = Mockito.mock(HttpServletRequest.class); + Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL"); + Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT"); + Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api"); + Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create"); + Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision"); + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("test", "test rule", "ONAP", "AAF", null, null, null, + null, null, null, null, null, null, null, false, "test", 0); + MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes()); + Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); + + // set DBDao + setDBDao(); + pap.service(httpServletRequest, httpServletResponse); + + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + Mockito.verify(httpServletResponse).addHeader("successMapKey", "success"); + Mockito.verify(httpServletResponse).addHeader("policyName", "test.Decision_test.1.xml"); + } + + @Test + public void testDecisonGuardPolicy() throws IOException, ServletException, SQLException { + httpServletRequest = Mockito.mock(HttpServletRequest.class); + Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL"); + Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT"); + Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api"); + Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create"); + Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision"); + Map matchingAttributes = new HashMap<>(); + matchingAttributes.put("actor","test"); + matchingAttributes.put("recipe","restart"); + matchingAttributes.put("targets","test,test1"); + matchingAttributes.put("clname",""); + matchingAttributes.put("limit","1"); + matchingAttributes.put("timeWindow","15"); + matchingAttributes.put("timeUnits","minute"); + matchingAttributes.put("guardActiveStart","05:00"); + matchingAttributes.put("guardActiveEnd","10:00"); + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("testGuard", "test rule", "PDPD", "GUARD_YAML", matchingAttributes , null, null, + null, null, null, null, null, null, null, false, "test", 0); + MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes()); + Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); + + // set DBDao + setDBDao(); + pap.service(httpServletRequest, httpServletResponse); + + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + Mockito.verify(httpServletResponse).addHeader("successMapKey", "success"); + Mockito.verify(httpServletResponse).addHeader("policyName", "test.Decision_testGuard.1.xml"); + } + + @Test + public void testDecisonBLGuardPolicy() throws IOException, ServletException, SQLException { + httpServletRequest = Mockito.mock(HttpServletRequest.class); + Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL"); + Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT"); + Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api"); + Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create"); + Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Decision"); + Map matchingAttributes = new HashMap<>(); + matchingAttributes.put("actor","test"); + matchingAttributes.put("recipe","restart"); + matchingAttributes.put("clname","test"); + matchingAttributes.put("guardActiveStart","05:00"); + matchingAttributes.put("guardActiveEnd","10:00"); + matchingAttributes.put("blackList","bl1,bl2"); + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("testblGuard", "test rule", "PDPD", "GUARD_BL_YAML", matchingAttributes , null, null, + null, null, null, null, null, null, null, false, "test", 0); + MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes()); + Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); + + // set DBDao + setDBDao(); + pap.service(httpServletRequest, httpServletResponse); + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + Mockito.verify(httpServletResponse).addHeader("successMapKey", "success"); + Mockito.verify(httpServletResponse).addHeader("policyName", "test.Decision_testblGuard.1.xml"); } + @Test + public void testConfigPolicy() throws IOException, ServletException, SQLException { + httpServletRequest = Mockito.mock(HttpServletRequest.class); + Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL"); + Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT"); + Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api"); + Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create"); + Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config"); + Map configAttributes = new HashMap<>(); + configAttributes.put("value", "test"); + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Base", "test", "test rule", "TEST", "config", configAttributes, "OTHER", + "test body", false, "test",0, "5","default", "false", null); + MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes()); + Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); + + // set DBDao + setDBDao(); + pap.service(httpServletRequest, httpServletResponse); + + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + Mockito.verify(httpServletResponse).addHeader("successMapKey", "success"); + Mockito.verify(httpServletResponse).addHeader("policyName", "test.Config_test.1.xml"); + } + + private void setPolicyCreation() { + CommonClassDao commonClassDao = Mockito.mock(CommonClassDao.class); + PolicyCreation.setCommonClassDao(commonClassDao); + PolicyEditorScopes editorScope = new PolicyEditorScopes(); + UserInfo userInfo = new UserInfo(); + userInfo.setUserName("API"); + userInfo.setUserLoginId("API"); + editorScope.setScopeName("test"); + editorScope.setUserCreatedBy(userInfo); + editorScope.setUserModifiedBy(userInfo); + Mockito.when(commonClassDao.getEntityItem(PolicyEditorScopes.class, "scopeName", "test")).thenReturn(editorScope); + BRMSParamTemplate template = new BRMSParamTemplate(); + template.setRuleName("testPolicy"); + template.setUserCreatedBy(userInfo); + String rule = "package com.sample;\n" + + "import com.sample.DroolsTest.Message;\n" + + "declare PapParams\n" + + "samPoll : int\n" + + "value : String\n" + + "end\n" + + "///This Rule will be generated by the UI.\n" + + "rule \"${policyName}.Create parameters structure\"\n" + + "salience 1000 \n" + + "when\n" + + "then\n" + + "Params params = new Params();\n" + + "params.setSamPoll(76);\n" + + "params.setValue(\"test\");\n" + + "insertLogical(params);\n" + + "end\n" + + "rule \"Rule 1: Check parameter structure access from when/then\"\n" + + "when\n" + + "$param: Params()\n" + + "Params($param.samPoll > 50)\n" + + "then\n" + + "System.out.println(\"Firing rule 1\");\n" + + "System.out.println($param);\n" + + "end\n"; + template.setRule(rule ); + Mockito.when(commonClassDao.getEntityItem(BRMSParamTemplate.class, "ruleName", "testPolicy")).thenReturn(template); + + } + @Test + public void testClosedLoopCreateDictionary() throws IOException, SQLException, ServletException { + httpServletRequest = Mockito.mock(HttpServletRequest.class); + // Check VSCLAction. + String json = "{\"dictionaryFields\": {\"vsclaction\": \"testRestAPI\",\"description\": \"testing create\"}}"; + dictionaryTestSetup(false, "VSCLAction", json); + // set DBDao + ClosedLoopDictionaryController.setCommonClassDao(new CommonClassDaoImpl()); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + // + // Check VNFType + // + httpServletRequest = Mockito.mock(HttpServletRequest.class); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + json = "{\"dictionaryFields\": {\"vnftype\": \"testrestAPI1\",\"description\": \"testing create\"}}"; + dictionaryTestSetup(false, "VNFType", json); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + // + // Check PEPOptions + // + httpServletRequest = Mockito.mock(HttpServletRequest.class); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + json = "{\"dictionaryFields\":{\"pepName\":\"testRestAPI\",\"description\":\"testing create\",\"attributes\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\",\"number\":\"test\"}]}}"; + dictionaryTestSetup(false, "PEPOptions", json); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + // + // Check Varbind + // + httpServletRequest = Mockito.mock(HttpServletRequest.class); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + json = "{\"dictionaryFields\":{\"varbindName\":\"testRestAPI\",\"varbindDescription\":\"testing\",\"varbindOID\":\"test\"}}"; + dictionaryTestSetup(false, "Varbind", json); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + // + // Check Service + // + httpServletRequest = Mockito.mock(HttpServletRequest.class); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + json = "{\"dictionaryFields\":{\"serviceName\":\"testRestAPI\",\"description\":\"testing\"}}"; + dictionaryTestSetup(false, "Service", json); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + // + // Check Site + // + httpServletRequest = Mockito.mock(HttpServletRequest.class); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + json = "{\"dictionaryFields\":{\"siteName\":\"testRestAPI\",\"description\":\"testing\"}}"; + dictionaryTestSetup(false, "Site", json); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + } + + @Test + public void testFirewallCreateDictionary() throws IOException, SQLException, ServletException { + httpServletRequest = Mockito.mock(HttpServletRequest.class); + // Check SecurityZone. + String json = "{\"dictionaryFields\":{\"zoneName\":\"testRestAPI\",\"zoneValue\":\"testing\"}}"; + dictionaryTestSetup(false, "SecurityZone", json); + // set DBDao + FirewallDictionaryController.setCommonClassDao(new CommonClassDaoImpl()); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + // + // Check Action List + // + httpServletRequest = Mockito.mock(HttpServletRequest.class); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + json = "{\"dictionaryFields\":{\"actionName\":\"testRestAPI\",\"description\":\"test\"}}"; + dictionaryTestSetup(false, "ActionList", json); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + // + // Check Protocol List. + // + httpServletRequest = Mockito.mock(HttpServletRequest.class); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + json = "{\"dictionaryFields\":{\"protocolName\":\"testRestAPI\",\"description\":\"test\"}}"; + dictionaryTestSetup(false, "ProtocolList", json); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + // + // Check Zone. + // + httpServletRequest = Mockito.mock(HttpServletRequest.class); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + json = "{\"dictionaryFields\":{\"zoneName\":\"testRestAPI\",\"zoneValue\":\"test\"}}"; + dictionaryTestSetup(false, "Zone", json); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + // + // Check PrefixList. + // + httpServletRequest = Mockito.mock(HttpServletRequest.class); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + json = "{\"dictionaryFields\":{\"prefixListName\":\"testRestAPI\",\"prefixListValue\":\"127.0.0.1\",\"description\":\"testing\"}}"; + dictionaryTestSetup(false, "PrefixList", json); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + // + // Check AddressGroup. + // + httpServletRequest = Mockito.mock(HttpServletRequest.class); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + json = "{\"dictionaryFields\":{\"groupName\":\"testRestAPIgroup\",\"description\":\"testing\",\"attributes\":[{\"option\":\"testRestAPI\"}, {\"option\":\"testRestAPI\"}]}}"; + dictionaryTestSetup(false, "AddressGroup", json); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + // + // Check ServiceGroup. + // + httpServletRequest = Mockito.mock(HttpServletRequest.class); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + json = "{\"dictionaryFields\":{\"groupName\":\"testRestAPIServiceGroup\",\"attributes\":[{\"option\":\"testRestAPIservice\"}]}}"; + dictionaryTestSetup(false, "ServiceGroup", json); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + // + // Check ServiceList. + // + httpServletRequest = Mockito.mock(HttpServletRequest.class); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + json = "{\"dictionaryFields\":{\"serviceName\":\"testRestAPIservice\",\"serviceDescription\":\"test\",\"servicePorts\":\"8888\",\"transportProtocols\":[{\"option\":\"testRestAPI\"},{\"option\":\"testRestAPI1\"}],\"appProtocols\":[{\"option\":\"testRestAPI\"},{\"option\":\"testRestAPI1\"}]}}"; + dictionaryTestSetup(false, "ServiceList", json); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + // + // Check TermList. + // + httpServletRequest = Mockito.mock(HttpServletRequest.class); + httpServletResponse = Mockito.mock(MockHttpServletResponse.class); + json = "{\"dictionaryFields\":{\"termName\":\"testRestAPIRule\",\"termDescription\":\"testing\",\"fromZoneDatas\":[{\"option\":\"testRestAPI\"}],\"toZoneDatas\":[{\"option\":\"testRestAPI1\"}],\"sourceListDatas\":[{\"option\":\"Group_testportal\"}],\"destinationListDatas\":[{\"option\":\"testRestAPI\"}],\"sourceServiceDatas\":[{\"option\":\"testRestAPIservice\"},{\"option\":\"testRestAPIservice1\"}],\"destinationServiceDatas\":[{\"option\":\"testRestAPIservice1\"},{\"option\":\"testportalservice2\"}],\"actionListDatas\":[{\"option\":\"testRestAPI\"}]}}"; + dictionaryTestSetup(false, "TermList", json); + // send Request to PAP + pap.service(httpServletRequest, httpServletResponse); + // Verify + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); + } + + private void dictionaryTestSetup(Boolean updateFlag, String dictionaryType, String json) throws IOException, SQLException { + Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL"); + Mockito.when(httpServletRequest.getHeader("ClientScope")).thenReturn("dictionaryItem"); + Mockito.when(httpServletRequest.getMethod()).thenReturn("PUT"); + Mockito.when(httpServletRequest.getParameter("apiflag")).thenReturn("api"); + if(updateFlag){ + Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("update"); + }else{ + Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create"); + } + Mockito.when(httpServletRequest.getParameter("dictionaryType")).thenReturn(dictionaryType); + MockServletInputStream mockInput = new MockServletInputStream(json.getBytes()); + Mockito.when(httpServletRequest.getInputStream()).thenReturn(mockInput); + Mockito.when(httpServletRequest.getReader()).thenReturn(new BufferedReader(new InputStreamReader(mockInput))); + // set DBDao + setDBDao(); + } private void setDBDao() throws SQLException { BasicDataSource dataSource = new BasicDataSource(); 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 1a97d7fad..99285e77f 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 @@ -20,9 +20,10 @@ package org.onap.policy.pap.xacml.rest.components; import static org.junit.Assert.*; -import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; @@ -124,5 +125,24 @@ public class FirewallConfigPolicyTest { assertTrue(response); } + + @Test + public void testUpdateJson() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{ + FirewallConfigPolicy firewallConfigPolicy = new FirewallConfigPolicy(); + Method method = firewallConfigPolicy.getClass().getDeclaredMethod("updateFirewallDictionaryData", String.class , String.class); + method.setAccessible(true); + String jsonBody= "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicyConfig\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev1a\",\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Sshservice entry in servicelist\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}],\"addressGroups\":[{\"name\":\"test\",\"description\":\"Destination\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\",\"description\":\"SourceTestServers for firsttesting\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"FWRuleTestServerToTest\",\"fromZones\":[\"UntrustedZoneTestName\"],\"toZones\":[\"TrustedZoneTestName\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TestServers\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\",\"description\":\"FWrule for Test source to Test destination\",\"enabled\":true,\"log\":true}]}"; + String prevJsonBody = "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicy1Config\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev\",\"vendorServiceId\":\"test\",\"vendorSpecificData\":{\"idMap\":[{\"Id\":\"cloudsite:dev1a\",\"vendorId\":\"deviceGroup:dev\"}]},\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Ssh service entry in service list\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}],\"addressGroups\":[{\"name\":\"Test\",\"description\":\"Destination Test\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\",\"description\":\"Source TestServers for first testing\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"FWRuleTestServerTot\",\"fromZones\":[\"UntrustedZoneTestName\"],\"toZones\":[\"TrustedZoneTName\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TServers\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\",\"description\":\"FW rule for HOHO source to CiscoVCE destination\",\"enabled\":true,\"log\":true}]}"; + assertFalse((Boolean) method.invoke(firewallConfigPolicy, jsonBody, prevJsonBody)); + } + + @Test + public void testInsertJson() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{ + FirewallConfigPolicy firewallConfigPolicy = new FirewallConfigPolicy(); + Method method = firewallConfigPolicy.getClass().getDeclaredMethod("insertFirewallDicionaryData", String.class); + method.setAccessible(true); + String jsonBody= "{\"serviceTypeId\":\"/v0/firewall/pan\",\"configName\":\"TestFwPolicyConfig\",\"deploymentOption\":{\"deployNow\":false},\"securityZoneId\":\"cloudsite:dev1a\",\"serviceGroups\":[{\"name\":\"SSH\",\"description\":\"Sshservice entry in servicelist\",\"type\":\"SERVICE\",\"transportProtocol\":\"tcp\",\"appProtocol\":null,\"ports\":\"22\"}],\"addressGroups\":[{\"name\":\"test\",\"description\":\"Destination\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/12\"}]},{\"name\":\"TestServers\",\"description\":\"SourceTestServers for firsttesting\",\"members\":[{\"type\":\"SUBNET\",\"value\":\"127.0.0.1/23\"}]}],\"firewallRuleList\":[{\"position\":\"1\",\"ruleName\":\"FWRuleTestServerToTest\",\"fromZones\":[\"UntrustedZoneTestName\"],\"toZones\":[\"TrustedZoneTestName\"],\"negateSource\":false,\"negateDestination\":false,\"sourceList\":[{\"type\":\"REFERENCE\",\"name\":\"TestServers\"}],\"destinationList\":[{\"type\":\"REFERENCE\",\"name\":\"Test\"}],\"sourceServices\":[],\"destServices\":[{\"type\":\"REFERENCE\",\"name\":\"SSH\"}],\"action\":\"accept\",\"description\":\"FWrule for Test source to Test destination\",\"enabled\":true,\"log\":true}]}"; + assertFalse((Boolean) method.invoke(firewallConfigPolicy, jsonBody)); + } } \ No newline at end of file diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java index 529047181..a2c67ea81 100644 --- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java +++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryControllerTest.java @@ -198,7 +198,7 @@ public class DecisionPolicyDictionaryControllerTest { MockHttpServletResponse response = new MockHttpServletResponse(); - controller.getRainyDayDictionaryEntityData(request, response); + controller.getRainyDayDictionaryEntityData(response); try { assertTrue( response.getContentAsString() != null && response.getContentAsString().contains("rainyDayDictionaryDatas")); diff --git a/ONAP-PAP-REST/xacml.pap.properties b/ONAP-PAP-REST/xacml.pap.properties index 2517ebdcc..dc8300d92 100644 --- a/ONAP-PAP-REST/xacml.pap.properties +++ b/ONAP-PAP-REST/xacml.pap.properties @@ -88,8 +88,8 @@ xacml.rest.pdp.idfile=test.properties #Properties for db access #properties for MySql xacml database: PLEASE DO NOT REMOVE... NEEDED FOR APIs -javax.persistence.jdbc.driver=com.mysql.jdbc.Driver -javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/onap_sdk?failOverReadOnly=false&autoReconnect=true +javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver +javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk?failOverReadOnly=false&autoReconnect=true javax.persistence.jdbc.user=policy_user javax.persistence.jdbc.password=policy_user diff --git a/ONAP-PDP-REST/pom.xml b/ONAP-PDP-REST/pom.xml index a2f7f7207..fb957f00d 100644 --- a/ONAP-PDP-REST/pom.xml +++ b/ONAP-PDP-REST/pom.xml @@ -212,6 +212,10 @@ javax.persistence persistence-api + + com.att.aft + dme2 + diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java index 18c201737..b824312dc 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java @@ -180,6 +180,14 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { private static volatile boolean configThreadTerminate = false; private transient ONAPLoggingContext baseLoggingContext = null; private transient IntegrityMonitor im; + public IntegrityMonitor getIm() { + return im; + } + + public void setIm(IntegrityMonitor im) { + this.im = im; + } + /** * Default constructor. */ diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyService.java index c283ff14c..915e3b30f 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DecisionPolicyService.java @@ -80,6 +80,8 @@ public class DecisionPolicyService{ } Map matchingAttributes = null; Map settingsAttributes = null; + + //Get the MATCHING and/or SETTINGS attributes if (policyParameters.getAttributes()!=null && policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)) { matchingAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING); settingsAttributes = policyParameters.getAttributes().get(AttributeType.SETTINGS); @@ -88,9 +90,10 @@ public class DecisionPolicyService{ }else if(policyParameters.getAttributes()!=null && policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && !policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)){ matchingAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING); } - // Create Policy. - StdPAPPolicy newPAPPolicy = new StdPAPPolicy(policyName, policyParameters.getPolicyDescription(), onapName, ruleProvider.toString(), matchingAttributes, settingsAttributes, policyParameters.getDynamicRuleAlgorithmLabels(), - policyParameters.getDynamicRuleAlgorithmFunctions(), policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmField2(), null, null, null, updateFlag, policyScope, 0); + // Create StdPAPPolicy object used to send policy data to PAP-REST. + StdPAPPolicy newPAPPolicy = new StdPAPPolicy(policyName, policyParameters.getPolicyDescription(), onapName, ruleProvider.toString(), matchingAttributes, settingsAttributes, + policyParameters.getTreatments(), policyParameters.getDynamicRuleAlgorithmLabels(), policyParameters.getDynamicRuleAlgorithmFunctions(), + policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmField2(), null, null, null, updateFlag, policyScope, 0); // Send JSON to PAP. response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Decision"}, policyParameters.getRequestID(), "Decision"); LOGGER.info(message); diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java index 8f88ef7c7..d3628f3c1 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/GetDictionaryService.java @@ -171,6 +171,9 @@ public class GetDictionaryService { case "Settings": jsonString = jsonString.replace("settingsDictionaryDatas", "DictionaryDatas"); break; + case "RainyDayTreatments": + jsonString = jsonString.replace("rainyDayDictionaryDatas", "DictionaryDatas"); + break; case "DescriptiveScope": jsonString = jsonString.replace("descriptiveScopeDictionaryDatas", "DictionaryDatas"); break; diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java index efaa5c167..8258aba1a 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PDPServices.java @@ -128,7 +128,7 @@ public class PDPServices { LOGGER.info("Decision not a Permit. " + result.getDecision().toString()); PDPResponse pdpResponse = new PDPResponse(); if (decide) { - String indeterminatePropValue = XACMLProperties.getProperty("decision.inStringdeterminate.response"); + String indeterminatePropValue = XACMLProperties.getProperty("decision.indeterminate.response"); if(result.getDecision().equals(Decision.INDETERMINATE)&& indeterminatePropValue != null){ if("PERMIT".equalsIgnoreCase(indeterminatePropValue)){ pdpResponse.setDecision(PolicyDecision.PERMIT); diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java index 3e3f584a9..594b51c06 100644 --- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java +++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/XACMLPdpServletTest.java @@ -27,6 +27,10 @@ import java.util.List; import java.util.Properties; import java.util.Random; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.EntityTransaction; +import javax.persistence.Persistence; import javax.servlet.ServletConfig; import javax.servlet.ServletInputStream; import javax.servlet.ServletOutputStream; @@ -34,16 +38,18 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.junit.Before; -import org.junit.runner.RunWith; +import org.junit.Test; import org.mockito.Mockito; +import org.onap.policy.common.ia.DbDAO; +import org.onap.policy.common.ia.IntegrityAuditProperties; import org.onap.policy.common.im.AdministrativeStateException; import org.onap.policy.common.im.IntegrityMonitor; import org.onap.policy.common.im.StandbyStatusException; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; + +import org.onap.policy.pdp.rest.XACMLPdpServletTest; import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockServletConfig; @@ -51,8 +57,6 @@ import com.mockrunner.mock.web.MockServletInputStream; import junit.framework.TestCase; -@RunWith(PowerMockRunner.class) -@PrepareForTest(IntegrityMonitor.class) // so PowerMock can mock static method of IntegrityMonitor public class XACMLPdpServletTest extends TestCase{ private static Logger LOGGER = FlexLogger.getLogger(XACMLPdpServletTest.class); @@ -65,16 +69,64 @@ public class XACMLPdpServletTest extends TestCase{ private ServletConfig servletConfig; private XACMLPdpServlet pdpServlet; private IntegrityMonitor im; - + + private DbDAO dbDAO; + private String persistenceUnit; + private Properties properties; + private String resourceName; + private String dbDriver; + private String dbUrl; + private String dbUser; + private String dbPwd; + private String siteName; + private String nodeType; + private static final String DEFAULT_DB_DRIVER = "org.h2.Driver"; + private static final String DEFAULT_DB_USER = "sa"; + private static final String DEFAULT_DB_PWD = ""; @Before public void setUp(){ + + properties = new Properties(); + properties.put(IntegrityAuditProperties.DB_DRIVER, XACMLPdpServletTest.DEFAULT_DB_DRIVER); + properties.put(IntegrityAuditProperties.DB_URL, "jdbc:h2:file:./sql/xacmlTest"); + properties.put(IntegrityAuditProperties.DB_USER, XACMLPdpServletTest.DEFAULT_DB_USER); + properties.put(IntegrityAuditProperties.DB_PWD, XACMLPdpServletTest.DEFAULT_DB_PWD); + properties.put(IntegrityAuditProperties.SITE_NAME, "SiteA"); + properties.put(IntegrityAuditProperties.NODE_TYPE, "pap"); + //properties.put("com.sun.management.jmxremote.port", "9999"); + dbDriver = XACMLPdpServletTest.DEFAULT_DB_DRIVER; + dbUrl = "jdbc:h2:file:./sql/xacmlTest"; + dbUser = XACMLPdpServletTest.DEFAULT_DB_USER; + dbPwd = XACMLPdpServletTest.DEFAULT_DB_PWD; + siteName = "SiteA"; + nodeType = "pdp"; + persistenceUnit = "testPdpPU"; + resourceName = "siteA.pdp1"; + + System.setProperty("com.sun.management.jmxremote.port", "9999"); + + EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, properties); + + EntityManager em = emf.createEntityManager(); + // Start a transaction + EntityTransaction et = em.getTransaction(); + + IntegrityMonitor im = null; + try { + im = IntegrityMonitor.getInstance(resourceName, properties); + } catch (Exception e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + //cleanDb(persistenceUnit, properties); + httpServletRequest = Mockito.mock(HttpServletRequest.class); Mockito.when(httpServletRequest.getMethod()).thenReturn("POST"); Mockito.when(httpServletRequest.getHeaderNames()).thenReturn(Collections.enumeration(headers)); Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers)); - + Mockito.when(httpServletRequest.getRequestURI()).thenReturn("/pdp/test"); mockOutput = Mockito.mock(ServletOutputStream.class); @@ -90,15 +142,17 @@ public class XACMLPdpServletTest extends TestCase{ //servletConfig Mockito.when(servletConfig.getInitParameterNames()).thenReturn(Collections.enumeration(headers)); pdpServlet = new XACMLPdpServlet(); + pdpServlet.setIm(im); - Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("xacml.pdp.properties"); + Mockito.when(servletConfig.getInitParameter("XACML_PROPERTIES_NAME")).thenReturn("src/test/resources/xacml.pdp.properties"); - System.setProperty("xacml.properties", "xacml.pdp.properties"); - System.setProperty("xacml.rest.pdp.config", "config_testing"); - System.setProperty("xacml.rest.pdp.webapps", "/webapps"); - System.setProperty("xacml.rootPolicies", "test_PolicyEngine.xml"); + System.setProperty("xacml.properties", "src/test/resources/xacml.pdp.properties"); + System.setProperty("xacml.rest.pdp.config", "src/test/resources/config_testing"); + System.setProperty("xacml.rest.pdp.webapps", "src/test/resources/webapps"); + /*System.setProperty("xacml.rootPolicies", "test_PolicyEngine.xml"); System.setProperty("xacml.referencedPolicies", "test_PolicyEngine.xml"); System.setProperty("test_PolicyEngine.xml.file", "config_testing\\test_PolicyEngine.xml"); + */ System.setProperty("xacml.rest.pdp.register", "false"); System.setProperty("com.sun.management.jmxremote.port", "9999"); @@ -119,8 +173,9 @@ public class XACMLPdpServletTest extends TestCase{ } Mockito.doNothing().when(im).endTransaction(); } - - public void testInit(){ + + @Test + public void testInit(){ LOGGER.info("XACMLPdpServletTest - testInit"); try { pdpServlet.init(servletConfig); @@ -133,12 +188,14 @@ public class XACMLPdpServletTest extends TestCase{ } + @Test public void testDoGetNoTypeError(){ LOGGER.info("XACMLPdpServletTest - testDoGetNoTypeError"); try{ + pdpServlet.init(servletConfig); pdpServlet.doGet(httpServletRequest, httpServletResponse); - Mockito.verify(httpServletResponse).sendError(HttpServletResponse.SC_BAD_REQUEST, "type not 'config' or 'hb'"); + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); assertTrue(true); }catch(Exception e){ System.out.println("Unexpected exception in testDoGetNoTypeError"); @@ -147,6 +204,7 @@ public class XACMLPdpServletTest extends TestCase{ } } + @Test public void testDoGetConfigType(){ LOGGER.info("XACMLPdpServletTest - testDoGetConfigType"); Mockito.when(httpServletRequest.getParameter("type")).thenReturn("config"); @@ -164,14 +222,14 @@ public class XACMLPdpServletTest extends TestCase{ } - + @Test public void testDoGetTypeHb(){ LOGGER.info("XACMLPdpServletTest - testDoGetTypeHb"); try{ Mockito.when(httpServletRequest.getParameter("type")).thenReturn("hb"); pdpServlet.init(servletConfig); pdpServlet.doGet(httpServletRequest, httpServletResponse); - Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_NO_CONTENT); + Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); assertTrue(true); }catch(Exception e){ System.out.println("Unexpected exception in testDoGetTypeHb"); @@ -179,6 +237,8 @@ public class XACMLPdpServletTest extends TestCase{ fail(); } } + + @Test public void testDoGetTypeStatus(){ LOGGER.info("XACMLPdpServletTest - testDoGetTypeStatus"); try{ @@ -194,6 +254,7 @@ public class XACMLPdpServletTest extends TestCase{ } } + @Test public void testDoPost(){ LOGGER.info("XACMLPdpServletTest - testDoPost"); try{ @@ -207,6 +268,7 @@ public class XACMLPdpServletTest extends TestCase{ } } + @Test public void testDoPostToLong(){ LOGGER.info("XACMLPdpServletTest - testDoPostToLong"); try{ @@ -223,6 +285,7 @@ public class XACMLPdpServletTest extends TestCase{ } } + @Test public void testDoPostContentLengthNegative(){ LOGGER.info("XACMLPdpServletTest - testDoPostToLong"); try{ @@ -239,6 +302,7 @@ public class XACMLPdpServletTest extends TestCase{ } } + @Test public void testDoPostContentTypeNonValid(){ LOGGER.info("XACMLPdpServletTest - testDoPostToLong"); try{ @@ -255,6 +319,7 @@ public class XACMLPdpServletTest extends TestCase{ } } + @Test public void testDoPostContentTypeConfigurationError(){ LOGGER.info("XACMLPdpServletTest - testDoPostToLong"); try{ @@ -271,6 +336,7 @@ public class XACMLPdpServletTest extends TestCase{ } } + @Test public void testDoPutCacheEmpty(){ LOGGER.info("XACMLPdpServletTest - testDoPutCacheEmpty"); mockInput = Mockito.mock(ServletInputStream.class); @@ -290,6 +356,7 @@ public class XACMLPdpServletTest extends TestCase{ } } + @Test public void testDoPutConfigPolicies(){ LOGGER.info("XACMLPdpServletTest - testDoPutConfigPolicies"); byte[] b = new byte[20]; @@ -330,6 +397,7 @@ public class XACMLPdpServletTest extends TestCase{ } } + @Test public void testDoPutInvalidContentType(){ LOGGER.info("XACMLPdpServletTest - testDoPutToLong"); try{ @@ -349,6 +417,7 @@ public class XACMLPdpServletTest extends TestCase{ } } + @Test public void testDestroy(){ LOGGER.info("XACMLPdpServletTest - testDestroy"); diff --git a/ONAP-PDP-REST/src/test/resources/META-INF/drop.ddl b/ONAP-PDP-REST/src/test/resources/META-INF/drop.ddl new file mode 100644 index 000000000..f7138ad52 --- /dev/null +++ b/ONAP-PDP-REST/src/test/resources/META-INF/drop.ddl @@ -0,0 +1,7 @@ +DROP TABLE IF EXISTS ConfigurationDataEntity +DROP TABLE IF EXISTS PolicyEntity +DROP TABLE IF EXISTS PolicyDBDaoEntity +DROP TABLE IF EXISTS ActionBodyEntity +DROP SEQUENCE IF EXISTS seqPolicy +DROP SEQUENCE IF EXISTS seqConfig +DROP SEQUENCE IF EXISTS seqActBody diff --git a/ONAP-PDP-REST/src/test/resources/META-INF/persistence.xml b/ONAP-PDP-REST/src/test/resources/META-INF/persistence.xml new file mode 100644 index 000000000..b44841c9d --- /dev/null +++ b/ONAP-PDP-REST/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,201 @@ + + + + + org.onap.policy.rest.jpa.PolicyEntity + org.onap.policy.rest.jpa.ConfigurationDataEntity + org.onap.policy.rest.jpa.PolicyDBDaoEntity + org.onap.policy.rest.jpa.GroupEntity + org.onap.policy.rest.jpa.PdpEntity + org.onap.policy.rest.jpa.ActionBodyEntity + org.onap.policy.rest.jpa.DatabaseLockEntity + org.onap.policy.rest.jpa.PolicyVersion + org.onap.policy.rest.jpa.PolicyScore + org.onap.policy.rest.jpa.FunctionDefinition + org.onap.policy.rest.jpa.Attribute + org.onap.policy.rest.jpa.Category + org.onap.policy.rest.jpa.ConstraintType + org.onap.policy.rest.jpa.ConstraintValue + org.onap.policy.rest.jpa.Datatype + org.onap.policy.rest.jpa.FunctionArgument + org.onap.policy.rest.jpa.UserInfo + org.onap.policy.rest.jpa.ActionPolicyDict + org.onap.policy.rest.jpa.DecisionSettings + org.onap.policy.rest.jpa.MicroServiceModels + org.onap.policy.rest.jpa.BRMSParamTemplate + org.onap.policy.rest.jpa.PolicyEditorScopes + + org.onap.policy.jpa.BackUpMonitorEntity + + org.onap.policy.common.im.jpa.StateManagementEntity + org.onap.policy.common.im.jpa.ForwardProgressEntity + org.onap.policy.common.im.jpa.ResourceRegistrationEntity + + org.onap.policy.common.ia.jpa.IntegrityAuditEntity + false + NONE + + + + + + + + + + + + + + + org.onap.policy.jpa.BackUpMonitorEntity + + org.onap.policy.common.im.jpa.StateManagementEntity + org.onap.policy.common.im.jpa.ForwardProgressEntity + org.onap.policy.common.im.jpa.ResourceRegistrationEntity + + org.onap.policy.common.ia.jpa.IntegrityAuditEntity + true + NONE + + + + + + org.eclipse.persistence.jpa.PersistenceProvider + org.onap.policy.rest.jpa.PolicyEntity + org.onap.policy.rest.jpa.ConfigurationDataEntity + org.onap.policy.rest.jpa.PolicyDBDaoEntity + org.onap.policy.rest.jpa.GroupEntity + org.onap.policy.rest.jpa.PdpEntity + org.onap.policy.rest.jpa.ActionBodyEntity + org.onap.policy.rest.jpa.DatabaseLockEntity + org.onap.policy.rest.jpa.PolicyVersion + org.onap.policy.rest.jpa.PolicyScore + org.onap.policy.rest.jpa.FunctionDefinition + org.onap.policy.rest.jpa.Attribute + org.onap.policy.rest.jpa.Category + org.onap.policy.rest.jpa.ConstraintType + org.onap.policy.rest.jpa.ConstraintValue + org.onap.policy.rest.jpa.Datatype + org.onap.policy.rest.jpa.FunctionArgument + org.onap.policy.rest.jpa.UserInfo + org.onap.policy.rest.jpa.ActionPolicyDict + org.onap.policy.rest.jpa.DecisionSettings + org.onap.policy.rest.jpa.MicroServiceModels + + org.onap.policy.rest.jpa.ActionList + org.onap.policy.rest.jpa.AddressGroup + org.onap.policy.rest.jpa.AttributeAssignment + org.onap.policy.rest.jpa.BRMSParamTemplate + org.onap.policy.rest.jpa.ClosedLoopD2Services + org.onap.policy.rest.jpa.ClosedLoopSite + org.onap.policy.rest.jpa.DCAEUsers + org.onap.policy.rest.jpa.DCAEuuid + org.onap.policy.rest.jpa.DescriptiveScope + org.onap.policy.rest.jpa.OnapName + org.onap.policy.rest.jpa.EnforcingType + org.onap.policy.rest.jpa.GlobalRoleSettings + org.onap.policy.rest.jpa.GroupPolicyScopeList + org.onap.policy.rest.jpa.GroupServiceList + org.onap.policy.rest.jpa.MicroServiceConfigName + org.onap.policy.rest.jpa.MicroServiceLocation + org.onap.policy.rest.jpa.Obadvice + org.onap.policy.rest.jpa.ObadviceExpression + org.onap.policy.rest.jpa.PEPOptions + org.onap.policy.rest.jpa.PIPConfigParam + org.onap.policy.rest.jpa.PIPConfiguration + org.onap.policy.rest.jpa.PIPResolver + org.onap.policy.rest.jpa.PIPResolverParam + org.onap.policy.rest.jpa.PIPType + org.onap.policy.rest.jpa.PolicyAlgorithms + org.onap.policy.rest.jpa.PolicyManagement + org.onap.policy.rest.jpa.PolicyScopeService + org.onap.policy.rest.jpa.PolicyScopeType + org.onap.policy.rest.jpa.PolicyScopeResource + org.onap.policy.rest.jpa.PolicyScopeClosedLoop + org.onap.policy.rest.jpa.PortList + org.onap.policy.rest.jpa.PREFIXLIST + org.onap.policy.rest.jpa.ProtocolList + org.onap.policy.rest.jpa.RemoteCatalogValues + org.onap.policy.rest.jpa.PolicyRoles + org.onap.policy.rest.jpa.RuleAlgorithms + org.onap.policy.rest.jpa.SecurityZone + org.onap.policy.rest.jpa.ServiceList + org.onap.policy.rest.jpa.SystemLogDB + org.onap.policy.rest.jpa.TermList + org.onap.policy.rest.jpa.VarbindDictionary + org.onap.policy.rest.jpa.VMType + org.onap.policy.rest.jpa.VNFType + org.onap.policy.rest.jpa.VSCLAction + org.onap.policy.rest.jpa.Zone + + org.onap.policy.jpa.BackUpMonitorEntity + + org.onap.policy.common.im.jpa.StateManagementEntity + org.onap.policy.common.im.jpa.ForwardProgressEntity + org.onap.policy.common.im.jpa.ResourceRegistrationEntity + + org.onap.policy.common.ia.jpa.IntegrityAuditEntity + + false + NONE + + + + + + + + + + + + + + + diff --git a/ONAP-PDP-REST/src/test/resources/fail.xacml.pdp.properties b/ONAP-PDP-REST/src/test/resources/fail.xacml.pdp.properties index a16b422bf..fdc7798b4 100644 --- a/ONAP-PDP-REST/src/test/resources/fail.xacml.pdp.properties +++ b/ONAP-PDP-REST/src/test/resources/fail.xacml.pdp.properties @@ -122,8 +122,8 @@ xacml.rest.notification.delay=30 REQUEST_BUFFER_SIZE=15 #properties for MySql xacml database: PLEASE DO NOT REMOVE... NEEDED FOR APIs -javax.persistence.jdbc.driver=com.mysql.jdbc.Driver -javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/xacml +javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver +javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk javax.persistence.jdbc.user=policy_user javax.persistence.jdbc.password=policy_user diff --git a/ONAP-PDP-REST/src/test/resources/notification.xacml.pdp.properties b/ONAP-PDP-REST/src/test/resources/notification.xacml.pdp.properties index 9ca1bba9c..2a3600559 100644 --- a/ONAP-PDP-REST/src/test/resources/notification.xacml.pdp.properties +++ b/ONAP-PDP-REST/src/test/resources/notification.xacml.pdp.properties @@ -122,8 +122,8 @@ xacml.rest.notification.delay=30 REQUEST_BUFFER_SIZE=15 #properties for MySql xacml database: PLEASE DO NOT REMOVE... NEEDED FOR APIs -javax.persistence.jdbc.driver=com.mysql.jdbc.Driver -javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/xacml +javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver +javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk javax.persistence.jdbc.user=policy_user javax.persistence.jdbc.password=policy_user diff --git a/ONAP-PDP-REST/src/test/resources/pass.xacml.pdp.properties b/ONAP-PDP-REST/src/test/resources/pass.xacml.pdp.properties index c9a111012..c3eda591f 100644 --- a/ONAP-PDP-REST/src/test/resources/pass.xacml.pdp.properties +++ b/ONAP-PDP-REST/src/test/resources/pass.xacml.pdp.properties @@ -122,8 +122,8 @@ xacml.rest.notification.delay=30 REQUEST_BUFFER_SIZE=15 #properties for MySql xacml database: PLEASE DO NOT REMOVE... NEEDED FOR APIs -javax.persistence.jdbc.driver=com.mysql.jdbc.Driver -javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/xacml +javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver +javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk javax.persistence.jdbc.user=policy_user javax.persistence.jdbc.password=policy_user diff --git a/ONAP-PDP-REST/src/test/resources/xacml.pdp.properties b/ONAP-PDP-REST/src/test/resources/xacml.pdp.properties new file mode 100644 index 000000000..bb174b9fd --- /dev/null +++ b/ONAP-PDP-REST/src/test/resources/xacml.pdp.properties @@ -0,0 +1,176 @@ +### +# ============LICENSE_START======================================================= +# ONAP-PDP-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========================================================= +### + +# Default XACML Properties File for PDP RESTful servlet +# +# Standard API Factories +# +xacml.dataTypeFactory=com.att.research.xacml.std.StdDataTypeFactory +xacml.pdpEngineFactory=com.att.research.xacmlatt.pdp.ATTPDPEngineFactory +xacml.pepEngineFactory=com.att.research.xacml.std.pep.StdEngineFactory +# NOT USED SEE BELOW xacml.pipFinderFactory=org.onap.policy.xacml.std.pip.StdPIPFinderFactory +xacml.traceEngineFactory=com.att.research.xacml.std.trace.LoggingTraceEngineFactory +# +# AT&T PDP Implementation Factories +# +xacml.att.evaluationContextFactory=com.att.research.xacmlatt.pdp.std.StdEvaluationContextFactory +xacml.att.combiningAlgorithmFactory=com.att.research.xacmlatt.pdp.std.StdCombiningAlgorithmFactory +xacml.att.functionDefinitionFactory=org.onap.policy.xacml.custom.OnapFunctionDefinitionFactory +# NOT USED SEE BELOW xacml.att.policyFinderFactory=org.onap.policy.pdp.std.StdPolicyFinderFactory +# creteUpdate Policy Implementation Class details. +createUpdatePolicy.impl.className=org.onap.policy.pdp.rest.api.services.CreateUpdatePolicyServiceImpl +# AAF Implementation class details +aafClient.impl.className=org.onap.policy.utils.AAFPolicyClientImpl +# +# AT&T RESTful PDP Implementation Factories +# +xacml.pipFinderFactory=org.onap.policy.pdp.rest.impl.XACMLPdpPIPFinderFactory +xacml.att.policyFinderFactory=org.onap.policy.pdp.rest.XACMLPdpPolicyFinderFactory +# +# When set to true, this flag tells the StdPolicyFinderFactory to combined all the root policy files into +# into one PolicySet and use the given Policy Algorithm. +# +xacml.att.policyFinderFactory.combineRootPolicies=urn:com:att:xacml:3.0:policy-combining-algorithm:combined-permit-overrides +# +# PDP RESTful API properties +# +# Set this to the address where the XACML-PAP-REST servlet is running +xacml.rest.pap.url=http://localhost:8070/pap/ + +#if multiple paps exist, the xacml.rest.pap.url can be removed and they can be defined like this: +#xacml.rest.pap.urls=http://localhost:9090/pap/,http://localhost:9091/pap/ + +# +# Give the running PDP an ID for the PAP. The url that its running as is a good choice. +# The PAP identifies PDP's using the URL of the PDP. +# +xacml.rest.pdp.id=http://localhost:8082/pdp/ + +# Give the port number used for the PDP + +xacml.jmx.port=0 + + +# Notification Properties +# Notifcation type: websocket, ueb or dmaap... if left blank websocket is the default +NOTIFICATION_TYPE=websocket +NOTIFICATION_SERVERS= +NOTIFICATION_TOPIC= +NOTIFICATION_DELAY= +UEB_API_KEY= +UEB_API_SECRET= +DMAAP_AAF_LOGIN= +DMAAP_AAF_PASSWORD= + +# +# Set the directory where the PDP holds its Policy Cache and PIP Configuration +# +xacml.rest.pdp.config=config + +xacml.rest.pdp.webapps=/home/users/PolicyEngine/webapps/ConfigPAP/ +# +# Initialize register with PAP servlet +# +xacml.rest.pdp.register=true +# +# Sleep period in seconds between register attempts +# +xacml.rest.pdp.register.sleep=15 +# +# number of attempts to register. -1 means keep trying forever. +# +xacml.rest.pdp.register.retries=-1 +# +# max number of bytes in a POST of a XML/JSON request +# old value #32767 +xacml.rest.pdp.maxcontent=99999999 +# +# Set UserID here +xacml.rest.pdp.userid=testpdp +# Set Password here +xacml.rest.pdp.password=alpha456 + +# id PAP +xacml.rest.pap.userid=testpap +#if multiple paps have different logins, they can be defined like this: +#http\://localhost\:9090/pap/.xacml.rest.pap.userid=testpap + +# pass PAP +xacml.rest.pap.password=alpha123 +#http\://localhost\:9090/pap/.xacml.rest.pap.password=alpha123 + +# Delay for Notifications Don't change this. Value in milliSec. +xacml.rest.notification.delay=30 + +# Client interval to ping notification service. +CLIENT_INTERVAL=15000 + +# Buffer Size. +REQUEST_BUFFER_SIZE=15 + +#Properties for db access +#properties for MySql xacml database: PLEASE DO NOT REMOVE... NEEDED FOR APIs +javax.persistence.jdbc.driver=org.h2.Driver +javax.persistence.jdbc.url=jdbc:h2:file:./sql/xacmlTest +javax.persistence.jdbc.user=sa +javax.persistence.jdbc.password= + +#***Properties for IntegrityMonitor integration defined in XACMLRestProperties.java*** + +#The name of the PDP. Must be unique across the system +xacml.rest.pdp.resource.name=site_1.pdp_1 + +#***Properties for IntegrityMonitor integration defined in IntegrityMonitorProperties.java*** + +#Interval between forward progress counter updates in seconds +fp_monitor_interval=30 + +#Number of forward progress counter failures before failover +failed_counter_threshold=3 + +#Interval in seconds between test transactions if there is no other traffic +test_trans_interval=10 + +#Interval in seconds between updates of the forward progress counter in the DB +write_fpc_interval=5 + +#Name of the site +site_name=site_1 + +#Node type +node_type=pdp_xacml + +#Dependency groups are groups of resources upon which a node operational state is dependent upon). +#Each group is a comma-separated list of resource names and groups are separated by a semicolon. +#A group may contain one or more members. Resource names must match the resource names defined +#in the respective servers' properties files +dependency_groups=site_1.pdplp_1;site_1.astragw_1;site_1.brmsgw_1 + +# this can be DEVL, TEST, PROD +ENVIRONMENT=DEVL +xacml.rest.pep.idfile = client.properties + +#AAF Policy Name space +#Not Mandatory for Open Onap +policy.aaf.namespace = +policy.aaf.resource = +# Decision Response settings. +# can be either PERMIT or DENY. +decision.indeterminate.response=PERMIT \ No newline at end of file diff --git a/ONAP-PDP-REST/xacml.pdp.properties b/ONAP-PDP-REST/xacml.pdp.properties index 6cf2e945b..4d120042a 100644 --- a/ONAP-PDP-REST/xacml.pdp.properties +++ b/ONAP-PDP-REST/xacml.pdp.properties @@ -126,8 +126,8 @@ CLIENT_INTERVAL=15000 REQUEST_BUFFER_SIZE=15 #properties for MySql xacml database: PLEASE DO NOT REMOVE... NEEDED FOR APIs -javax.persistence.jdbc.driver=com.mysql.jdbc.Driver -javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/onap_sdk +javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver +javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk javax.persistence.jdbc.user=policy_user javax.persistence.jdbc.password=policy_user diff --git a/ONAP-PDP/pom.xml b/ONAP-PDP/pom.xml index 0310d390e..bd0507465 100644 --- a/ONAP-PDP/pom.xml +++ b/ONAP-PDP/pom.xml @@ -48,11 +48,6 @@ httpcore 4.4.4 - - org.glassfish - javax.json - 1.1 - commons-codec commons-codec diff --git a/ONAP-SDK-APP/pom.xml b/ONAP-SDK-APP/pom.xml index e6ef8ed1e..04f933930 100644 --- a/ONAP-SDK-APP/pom.xml +++ b/ONAP-SDK-APP/pom.xml @@ -31,7 +31,7 @@ UTF-8 - 1.1.0 + 1.3.1 4.2.0.RELEASE 4.3.11.Final @@ -108,8 +108,11 @@ - org.openecomp.ecompsdkos + org.onap.portal.sdk epsdk-app-overlay + + static/fusion/raptor/uigrid/vfs_fonts.js + org.onap.policy.engine @@ -149,7 +152,7 @@ war - org.openecomp.ecompsdkos + org.onap.portal.sdk epsdk-core @@ -162,7 +165,7 @@ classes - org.openecomp.ecompsdkos + org.onap.portal.sdk epsdk-core @@ -180,25 +183,31 @@ - org.openecomp.ecompsdkos + org.onap.portal.sdk epsdk-app-overlay ${epsdk.version} war - org.openecomp.ecompsdkos + org.onap.portal.sdk epsdk-app-common ${epsdk.version} jar - org.openecomp.ecompsdkos + org.onap.portal.sdk epsdk-core ${epsdk.version} + + + mysql + mysql-connector-java + + - org.openecomp.ecompsdkos + org.onap.portal.sdk epsdk-analytics ${epsdk.version} @@ -209,7 +218,7 @@ - org.openecomp.ecompsdkos + org.onap.portal.sdk epsdk-workflow ${epsdk.version} diff --git a/ONAP-SDK-APP/src/main/java/org/openecomp/portalapp/login/LoginStrategyImpl.java b/ONAP-SDK-APP/src/main/java/org/openecomp/portalapp/login/LoginStrategyImpl.java index 567fbb7cf..3b38f1d8e 100644 --- a/ONAP-SDK-APP/src/main/java/org/openecomp/portalapp/login/LoginStrategyImpl.java +++ b/ONAP-SDK-APP/src/main/java/org/openecomp/portalapp/login/LoginStrategyImpl.java @@ -26,10 +26,10 @@ import javax.servlet.http.HttpServletResponse; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; import org.openecomp.portalsdk.core.auth.LoginStrategy; +import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.openecomp.portalsdk.core.onboarding.exception.PortalAPIException; import org.openecomp.portalsdk.core.onboarding.util.CipherUtil; -import org.openecomp.portalsdk.core.onboarding.util.PortalApiConstants; -import org.openecomp.portalsdk.core.onboarding.util.PortalApiProperties; +import org.openecomp.portalsdk.core.util.SystemProperties; import org.springframework.web.servlet.ModelAndView; public class LoginStrategyImpl extends LoginStrategy { @@ -58,23 +58,21 @@ public class LoginStrategyImpl extends LoginStrategy { } private static String getUserIdFromCookie(HttpServletRequest request) throws PortalAPIException { - String userId = ""; - Cookie[] cookies = request.getCookies(); - Cookie userIdcookie = null; - if (cookies != null) - for (Cookie cookie : cookies) - if (cookie.getName().equals(USER_ID)) - userIdcookie = cookie; - if (userIdcookie != null) { - try { - userId = CipherUtil.decrypt(userIdcookie.getValue(), - PortalApiProperties.getProperty(PortalApiConstants.Decryption_Key)); - } catch (Exception e) { - throw new PortalAPIException(e); - } - } - return userId; - + String userId = ""; + Cookie userIdCookie = getCookie(request, USER_ID); + if (userIdCookie != null) { + final String cookieValue = userIdCookie.getValue(); + if (!SystemProperties.containsProperty(SystemProperties.Decryption_Key)) + throw new IllegalStateException("Failed to find property " + SystemProperties.Decryption_Key); + final String decryptionKey = SystemProperties.getProperty(SystemProperties.Decryption_Key); + try { + userId = CipherUtil.decrypt(cookieValue, decryptionKey); + LOGGER.debug("getUserIdFromCookie: decrypted as {}" +userId); + } catch (Exception e) { + LOGGER.error("Exception Occured in getUserIdFromCookie" + e); + } + } + return userId; } private static boolean isLoginCookieExist(HttpServletRequest request) { diff --git a/ONAP-SDK-APP/src/main/resources/portal.properties b/ONAP-SDK-APP/src/main/resources/portal.properties index 2ab096f1a..1f2336d7b 100644 --- a/ONAP-SDK-APP/src/main/resources/portal.properties +++ b/ONAP-SDK-APP/src/main/resources/portal.properties @@ -27,11 +27,6 @@ portal.api.prefix = /api max.idle.time = 5 user.attribute.name = user_attribute -# CSP settings -csp_cookie_name = attESSec -csp_gate_keeper_prod_key = PROD -testing=testing - #Use REST API instead of UEB to fetch the functional menu data use_rest_for_functional_menu=true @@ -43,10 +38,10 @@ use_rest_for_functional_menu=true portal.api.impl.class = org.openecomp.portalapp.service.OnBoardingApiServiceImpl # CSP Global Log On for single sign on -onap_redirect_url = todo_csp_global_logon +ecomp_redirect_url = todo_csp_global_logon # URL of the ONAP Portal REST API -onap_rest_url = todo_Onap_rest_url +ecomp_rest_url = todo_Onap_rest_url # Applications do not need to run a UEB listener in 1610. ueb_listeners_enable = false @@ -58,7 +53,7 @@ ueb_listeners_enable = false # UEB servers ueb_url_list = todo_ueb_list # ONAP Portal listens on this UEB topic -onap_portal_inbox_name = ONAP-PORTAL-INBOX-TEST-DEMETER +ecomp_portal_inbox_name = ONAP-PORTAL-INBOX-TEST-DEMETER # Replace these 3 default values with the ones for your specific App, # as shown on the on-boarding page on the ONAP Portal web application. ueb_app_key = ZOicEniw7BWDL1pM diff --git a/ONAP-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties b/ONAP-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties index 304bcbd90..aa8ee1476 100644 --- a/ONAP-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties +++ b/ONAP-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties @@ -23,8 +23,8 @@ decryption_key = AGLDdG4D04BKm2IxIWEr8o== # The following properties MAY require changes by partner applications. ########################################################################## #Mysql -db.driver = com.mysql.jdbc.Driver -db.connectionURL = jdbc:mysql://localhost:3306/onap_sdk +db.driver = org.mariadb.jdbc.Driver +db.connectionURL = jdbc:mariadb://localhost:3306/onap_sdk db.userName = policy_user db.password = policy_user db.hib.dialect = org.hibernate.dialect.MySQLDialect @@ -50,7 +50,7 @@ mylogins_feed_cron = 0 0/60 * * * ?; my_login_feed_output_dir = /tmp/MyLogins # ONAP Portal Shared Context REST API URL -onap_shared_context_rest_url= todo_shared_context_url +ecomp_shared_context_rest_url= todo_shared_context_url # Link shown in Help menu contact_us_link = todo_Contact_link diff --git a/ONAP-SDK-APP/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2Header.html b/ONAP-SDK-APP/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2Header.html new file mode 100644 index 000000000..444514939 --- /dev/null +++ b/ONAP-SDK-APP/src/main/webapp/app/fusion/scripts/DS2-view-models/ds2Header.html @@ -0,0 +1,68 @@ +
+
+ +
+
diff --git a/ONAP-SDK-APP/xacml.admin.properties b/ONAP-SDK-APP/xacml.admin.properties index 0f285b694..333da49a5 100644 --- a/ONAP-SDK-APP/xacml.admin.properties +++ b/ONAP-SDK-APP/xacml.admin.properties @@ -87,8 +87,8 @@ xacml.log.db.password=policy_user xacml.att.log.timeframe=150 -javax.persistence.jdbc.driver=com.mysql.jdbc.Driver -javax.persistence.jdbc.url=jdbc:mysql://localhost:3306/onap_sdk +javax.persistence.jdbc.driver=org.mariadb.jdbc.Driver +javax.persistence.jdbc.url=jdbc:mariadb://localhost:3306/onap_sdk javax.persistence.jdbc.user=policy_user javax.persistence.jdbc.password=policy_user diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/api/pap/OnapPAPPolicy.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/api/pap/OnapPAPPolicy.java index 78ce354e0..4539b4225 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/api/pap/OnapPAPPolicy.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/api/pap/OnapPAPPolicy.java @@ -46,6 +46,7 @@ public interface OnapPAPPolicy { public String getOnapName(); public String getConfigName(); public Map getDynamicFieldConfigAttributes(); + public Map getTreatments(); public Map getDynamicSettingsMap(); public List getDynamicRuleAlgorithmLabels(); public List getDynamicRuleAlgorithmCombo(); @@ -81,7 +82,6 @@ public interface OnapPAPPolicy { public String getDictionaryType(); public String getDictionary(); public String getDictionaryFields(); - public String getRiskLevel(); public String getGuard(); public String getRiskType(); diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java index 56676f38b..034c08bfa 100644 --- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicy.java @@ -36,6 +36,7 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ private String onapName = null; private String configName = null; private Map dyanamicFieldConfigAttributes = new HashMap<>(); + private Map treatments = new HashMap<>(); private Map dropDownMap = new HashMap<>(); private Map dynamicSettingsMap = new HashMap<>(); private List dynamicRuleAlgorithmLabels; @@ -125,8 +126,9 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ } - //Constructor for Create/Update Decision Policies from Admin Console - public StdPAPPolicy(String policyName, String description, String onapName, String providerComboBox, Map attributes, Map settings, + //Constructor for Create/Update Decision Policies + public StdPAPPolicy(String policyName, String description, String onapName, String providerComboBox, + Map attributes, Map settings, Map treatments, List dynamicRuleAlgorithmLabels, List dynamicRuleAlgorithmCombo, List dynamicRuleAlgorithmField1, List dynamicRuleAlgorithmField2, Map dropDownMap, List dynamicVariableList, List dataTypeList, Boolean editPolicy, String domain, int highestVersion) { @@ -147,10 +149,10 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ this.editPolicy = editPolicy; this.domain = domain; this.highestVersion = highestVersion; + this.treatments = treatments; } - //Constructor for Create Config Policies from API and Admin Console //Constructor for Updating Config Policies from the API public StdPAPPolicy(String configPolicyType, String policyName, String description, String onapName, String configName, Map attributes, String configType, @@ -674,6 +676,11 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ return guard; } + @Override + public Map getTreatments() { + return treatments; + } + @Override public String toString() { return "StdPAPPolicy [policyName=" + policyName + ", policyDescription=" + policyDescription + ", onapName=" @@ -688,9 +695,10 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ + ",dataTypeList=" + dataTypeList + ",draft=" + ",oldPolicyFileName=" + oldPolicyFileName + ",serviceType=" + serviceType + ",uuid=" + uuid + ",msLocation=" + msLocation + ",priority=" + priority + ",deleteCondition=" + deleteCondition + ",dictionaryType=" + dictionaryType + ",dictionary=" + dictionary + ",dictionaryFields=" + dictionaryFields + ",uuid=" + uuid + ",msLocation=" + msLocation + ",priority=" - + priority + ",deleteCondition=" + deleteCondition + ",riskType="+riskType + ",riskLevel="+riskLevel + ",guard="+ guard + ",ttlDate="+ ttlDate + "]"; + + priority + ",deleteCondition=" + deleteCondition + ",riskType="+riskType + ",riskLevel="+riskLevel + ",guard="+ guard + ",ttlDate="+ ttlDate + + ",treatments=" + treatments + "]"; } - + // Methods needed for JSON Deserialization public void setPolicyName(String policyName) { this.policyName = policyName; @@ -907,4 +915,8 @@ public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ public void setBrmsDependency(ArrayList brmsDependency) { this.brmsDependency = brmsDependency; } + + public void setTreatments(Map treatments) { + this.treatments = treatments; + } } \ No newline at end of file diff --git a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdEngineTest.java b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdEngineTest.java new file mode 100644 index 000000000..6600a9208 --- /dev/null +++ b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdEngineTest.java @@ -0,0 +1,101 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP-XACML + * ================================================================================ + * 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.xacml.test.std.pap; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Properties; + +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.xacml.api.pap.OnapPDP; +import org.onap.policy.xacml.std.pap.StdEngine; + +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.std.pap.StdPDP; + +public class StdEngineTest { + + private static Logger logger = FlexLogger.getLogger(StdEngineTest.class); + private Path repository; + Properties properties = new Properties(); + StdEngine stdEngine = null; + + @Before + public void setUp(){ + + repository = Paths.get("src/test/resources/pdps"); + try { + stdEngine = new StdEngine(repository); + } catch (PAPException e) { + logger.info(e); + } catch (IOException e) { + logger.info(e); + } + } + + @Test + public void testGetDefaultGroup(){ + try { + assertTrue(stdEngine.getDefaultGroup() != null); + } catch (PAPException e) { + logger.info(e); + } + } + @Test + public void testGetGroup(){ + try { + assertTrue(stdEngine.getGroup("1") == null); + } catch (PAPException e) { + logger.info(e); + } + + } + + @Test + public void testGetOnapPDPGroups(){ + try { + assertTrue(stdEngine.getOnapPDPGroups() != null); + } catch (PAPException e) { + logger.info(e); + } + } + @Test + public void testGetPDP(){ + try { + assertTrue(stdEngine.getPDP("1") == null); + } catch (PAPException e) { + logger.info(e); + } + } + @Test + public void testGetPDPGroup(){ + try { + assertTrue(stdEngine.getPDPGroup(null) == null); + } catch (PAPException e) { + logger.info(e); + } + } +} diff --git a/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPAPPolicyTest.java b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPAPPolicyTest.java new file mode 100644 index 000000000..da7476b67 --- /dev/null +++ b/ONAP-XACML/src/test/java/org/onap/policy/xacml/test/std/pap/StdPAPPolicyTest.java @@ -0,0 +1,543 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP-XACML + * ================================================================================ + * 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.xacml.test.std.pap; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; +import java.net.URI; +import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Properties; + +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.xacml.api.pap.OnapPDP; +import org.onap.policy.xacml.std.pap.StdEngine; +import org.onap.policy.xacml.std.pap.StdPAPPolicy; + +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.std.pap.StdPDP; + +public class StdPAPPolicyTest { + + private static Logger logger = FlexLogger.getLogger(StdPAPPolicyTest.class); + private Path repository; + Properties properties = new Properties(); + StdPAPPolicy stdPAPPolicy; + + @Before + public void setUp(){ + + repository = Paths.get("src/test/resources/pdps"); + try { + stdPAPPolicy = new StdPAPPolicy(); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetActionAttribute(){ + try { + stdPAPPolicy.setActionAttribute("test"); + assertTrue(stdPAPPolicy.getActionAttribute() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetActionBody(){ + try { + stdPAPPolicy.setActionBody("actionBody"); + assertTrue(stdPAPPolicy.getActionBody() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetActionDictHeader(){ + try { + stdPAPPolicy.setActionDictHeader("actionDictHeader"); + assertTrue(stdPAPPolicy.getActionDictHeader() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetActionDictMethod(){ + try { + stdPAPPolicy.setActionDictMethod("actionDictMethod"); + assertTrue(stdPAPPolicy.getActionDictMethod() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetActionDictType(){ + try { + stdPAPPolicy.setActionDictType("actionDictType"); + assertTrue(stdPAPPolicy.getActionDictType() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetActionDictUrl(){ + try { + stdPAPPolicy.setActionDictUrl("actionDictUrl"); + assertTrue(stdPAPPolicy.getActionDictUrl() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetActionPerformer(){ + try { + stdPAPPolicy.setActionPerformer("actionPerformer"); + assertTrue(stdPAPPolicy.getActionPerformer() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetBrmsController(){ + try { + stdPAPPolicy.setBrmsController("brmsController"); + assertTrue(stdPAPPolicy.getBrmsController() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetBrmsDependency(){ + try { + stdPAPPolicy.setBrmsDependency(new ArrayList()); + assertTrue(stdPAPPolicy.getBrmsDependency() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetConfigBodyData(){ + try { + stdPAPPolicy.setConfigBodyData("configBodyData"); + assertTrue(stdPAPPolicy.getConfigBodyData() != null); + } catch (Exception e) { + logger.info(e); + } + } + + + @Test + public void testGetConfigName(){ + try { + stdPAPPolicy.setConfigName("configName"); + assertTrue(stdPAPPolicy.getConfigName() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetConfigPolicyType(){ + try { + stdPAPPolicy.setConfigPolicyType("configPolicyType"); + assertTrue(stdPAPPolicy.getConfigPolicyType() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetConfigType(){ + try { + stdPAPPolicy.setConfigType("configType"); + assertTrue(stdPAPPolicy.getConfigType() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetDataTypeList(){ + try { + stdPAPPolicy.setDataTypeList(new ArrayList()); + assertTrue(stdPAPPolicy.getDataTypeList() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDeleteCondition(){ + try { + stdPAPPolicy.setDeleteCondition("deleteCondition"); + assertTrue(stdPAPPolicy.getDeleteCondition() != null); + } catch (Exception e) { + logger.info(e); + } + } + + + @Test + public void testGetDrlRuleAndUIParams(){ + try { + stdPAPPolicy.setDrlRuleAndUIParams(new HashMap()); + assertTrue(stdPAPPolicy.getDrlRuleAndUIParams() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetDropDownMap(){ + try { + stdPAPPolicy.setDropDownMap(new HashMap()); + assertTrue(stdPAPPolicy.getDropDownMap() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetDynamicFieldConfigAttributes(){ + try { + assertTrue(stdPAPPolicy.getDynamicFieldConfigAttributes() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetDynamicRuleAlgorithmCombo(){ + try { + stdPAPPolicy.setDynamicRuleAlgorithmCombo(new ArrayList()); + assertTrue(stdPAPPolicy.getDynamicRuleAlgorithmCombo() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDynamicRuleAlgorithmField1(){ + try { + stdPAPPolicy.setDynamicRuleAlgorithmField1(new ArrayList()); + assertTrue(stdPAPPolicy.getDynamicRuleAlgorithmField1() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDictionary(){ + try { + stdPAPPolicy.setDictionary("dictionary"); + assertTrue(stdPAPPolicy.getDictionary() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetDictionaryFields(){ + try { + stdPAPPolicy.setDictionaryFields("dictionaryFields"); + assertTrue(stdPAPPolicy.getDictionaryFields() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetDictionaryType(){ + try { + stdPAPPolicy.setDictionaryType("dictionaryType"); + assertTrue(stdPAPPolicy.getDictionaryType() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetDomainDir(){ + try { + stdPAPPolicy.setDomainDir("domain"); + assertTrue(stdPAPPolicy.getDomainDir() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testIsDraft(){ + try { + stdPAPPolicy.setDraft(true); + assertTrue(stdPAPPolicy.isDraft() == true); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetDynamicRuleAlgorithmLabels(){ + try { + stdPAPPolicy.setDynamicRuleAlgorithmLabels(new ArrayList()); + assertTrue(stdPAPPolicy.getDynamicRuleAlgorithmLabels() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetDynamicSettingsMap(){ + try { + stdPAPPolicy.setDynamicSettingsMap(new HashMap()); + assertTrue(stdPAPPolicy.getDynamicSettingsMap() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetDynamicVariableList(){ + try { + stdPAPPolicy.setDynamicVariableList(new ArrayList()); + assertTrue(stdPAPPolicy.getDynamicVariableList() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetGuard(){ + try { + stdPAPPolicy.setGuard("domain"); + assertTrue(stdPAPPolicy.getGuard() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetHighestVersion(){ + try { + stdPAPPolicy.setHighestVersion(123); + assertTrue(stdPAPPolicy.getHighestVersion() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testgGtJsonBody(){ + try { + stdPAPPolicy.setJsonBody("jsonBoby"); + assertTrue(stdPAPPolicy.getJsonBody() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetLocation(){ + try { + stdPAPPolicy.setLocation(new URI("test")); + assertTrue(stdPAPPolicy.getLocation() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetMsLocation(){ + try { + stdPAPPolicy.setMsLocation("MsLocation"); + assertTrue(stdPAPPolicy.getMsLocation() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testSetOldPolicyFileName(){ + try { + stdPAPPolicy.setOldPolicyFileName("domain"); + assertTrue(stdPAPPolicy.getOldPolicyFileName() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetOnapName(){ + try { + stdPAPPolicy.setOnapName("onap"); + assertTrue(stdPAPPolicy.getOnapName() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetPolicyDescription(){ + try { + stdPAPPolicy.setPolicyDescription("description test"); + assertTrue(stdPAPPolicy.getPolicyDescription() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetPolicyID(){ + try { + stdPAPPolicy.setPolicyID("test"); + assertTrue(stdPAPPolicy.getPolicyID() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testSetPolicyName(){ + try { + stdPAPPolicy.setPolicyName("MsLocation"); + assertTrue(stdPAPPolicy.getPolicyName() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testSetPriority(){ + try { + stdPAPPolicy.setPriority("domain"); + assertTrue(stdPAPPolicy.getPriority() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetProviderComboBox(){ + try { + stdPAPPolicy.setProviderComboBox("onap"); + assertTrue(stdPAPPolicy.getProviderComboBox() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetRiskLevel(){ + try { + stdPAPPolicy.setRiskLevel("test"); + assertTrue(stdPAPPolicy.getRiskLevel() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetRiskType(){ + try { + stdPAPPolicy.setRiskType("test"); + assertTrue(stdPAPPolicy.getRiskType() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testGetRuleID(){ + try { + stdPAPPolicy.setRuleID("MsLocation"); + assertTrue(stdPAPPolicy.getRuleID() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetServiceType(){ + try { + stdPAPPolicy.setServiceType("domain"); + assertTrue(stdPAPPolicy.getServiceType() != null); + } catch (Exception e) { + logger.info(e); + } + } + + @Test + public void testGetTTLDate(){ + try { + stdPAPPolicy.setTTLDate("09/20/17"); + assertTrue(stdPAPPolicy.getTTLDate() != null); + } catch (Exception e) { + logger.info(e); + } + } + + + @Test + public void testGetUuid(){ + try { + stdPAPPolicy.setUuid("11212122"); + assertTrue(stdPAPPolicy.getUuid() != null); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testGetVersion(){ + try { + stdPAPPolicy.setVersion("testv01"); + assertTrue(stdPAPPolicy.getVersion() != null); + } catch (Exception e) { + logger.info(e); + } + + } + + @Test + public void testIsEditPolicy(){ + try { + stdPAPPolicy.setEditPolicy(true); + assertTrue(stdPAPPolicy.isEditPolicy() == true); + } catch (Exception e) { + logger.info(e); + } + } + @Test + public void testToString(){ + try { + assertTrue(stdPAPPolicy.toString() != null); + } catch (Exception e) { + logger.info(e); + } + } + +} \ No newline at end of file diff --git a/POLICY-SDK-APP/pom.xml b/POLICY-SDK-APP/pom.xml index 5adb5d169..aea0afc24 100644 --- a/POLICY-SDK-APP/pom.xml +++ b/POLICY-SDK-APP/pom.xml @@ -49,7 +49,7 @@ UTF-8 - 1.1.0 + 1.3.1 4.2.0.RELEASE 4.3.11.Final true @@ -59,9 +59,15 @@ - org.openecomp.ecompsdkos + org.onap.portal.sdk epsdk-core ${epsdk.version} + + + mysql + mysql-connector-java + + diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/CheckPDP.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/CheckPDP.java index 3febbed44..7ac9ca310 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/CheckPDP.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/CheckPDP.java @@ -34,6 +34,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import org.onap.policy.common.logging.flexlogger.FlexLogger; @@ -49,9 +50,14 @@ public class CheckPDP { private static HashMap pdpMap = null; private static final Logger LOGGER = FlexLogger.getLogger(CheckPDP.class); - private CheckPDP(){ + public static Map getPdpMap() { + return pdpMap; + } + + public CheckPDP(){ //default constructor } + public static boolean validateID(String id) { // ReadFile try { 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 4f42023c9..d65d1da8a 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 @@ -7,9 +7,9 @@ * 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. @@ -91,16 +91,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; public class PolicyManagerServlet extends HttpServlet { private static final Logger LOGGER = FlexLogger.getLogger(PolicyManagerServlet.class); private static final long serialVersionUID = -8453502699403909016L; - - private static boolean jUnit = false; - - public static boolean isjUnit() { - return jUnit; - } - - public static void setjUnit(boolean jUnit) { - PolicyManagerServlet.jUnit = jUnit; - } private enum Mode { LIST, RENAME, COPY, DELETE, EDITFILE, ADDFOLDER, DESCRIBEPOLICYFILE, VIEWPOLICY, ADDSUBSCOPE, SWITCHVERSION, EXPORT, SEARCHLIST @@ -123,11 +113,11 @@ public class PolicyManagerServlet extends HttpServlet { private static String EDITOR = "editor"; private static String GUEST = "guest"; private static String RESULT = "result"; - + private static Path closedLoopJsonLocation; private static JsonArray policyNames; private static String testUserId = null; - + public static JsonArray getPolicyNames() { return policyNames; } @@ -154,7 +144,7 @@ public class PolicyManagerServlet extends HttpServlet { // PolicyManagerServlet.initializeJSONLoad(); } - + protected static void initializeJSONLoad() { closedLoopJsonLocation = Paths.get(XACMLProperties .getProperty(XACMLRestProperties.PROP_ADMIN_CLOSEDLOOP)); @@ -163,7 +153,7 @@ public class PolicyManagerServlet extends HttpServlet { String location = closedLoopJsonLocation.toString(); try { inputStream = new FileInputStream(location); - if (location.endsWith("json")) { + if (location.endsWith("json")) { jsonReader = Json.createReader(inputStream); policyNames = jsonReader.readArray(); serviceTypeNamesList = new ArrayList<>(); @@ -341,7 +331,7 @@ public class PolicyManagerServlet extends HttpServlet { try { //Get the Login Id of the User from Request String userId = UserUtils.getUserSession(request).getOrgUserId(); - //Check if the Role and Scope Size are Null get the values from db. + //Check if the Role and Scope Size are Null get the values from db. List userRoles = controller.getRoles(userId); roles = new ArrayList<>(); scopes = new HashSet<>(); @@ -356,7 +346,7 @@ public class PolicyManagerServlet extends HttpServlet { } }else{ scopes.add(userRole.getScope()); - } + } } } if (roles.contains(ADMIN) || roles.contains(EDITOR) || roles.contains(GUEST) ) { @@ -373,7 +363,7 @@ public class PolicyManagerServlet extends HttpServlet { } } } - } + } if(policyList!= null){ for(int i = 0; i < policyList.length(); i++){ String policyName = policyList.get(i).toString().replace(".xml", ""); @@ -390,7 +380,7 @@ public class PolicyManagerServlet extends HttpServlet { if(!activeData.isEmpty()){ PolicyVersion policy = (PolicyVersion) activeData.get(0); JSONObject el = new JSONObject(); - el.put("name", policy.getPolicyName().replace(File.separator, "/")); + el.put("name", policy.getPolicyName().replace(File.separator, "/")); el.put("date", policy.getModifiedDate()); el.put("version", policy.getActiveVersion()); el.put("size", ""); @@ -409,7 +399,7 @@ public class PolicyManagerServlet extends HttpServlet { PolicyVersion filterdata = (PolicyVersion) filter; try{ String scopeName = filterdata.getPolicyName().substring(0, filterdata.getPolicyName().lastIndexOf(File.separator)); - if(scopes.contains(scopeName)){ + if(scopes.contains(scopeName)){ policyData.add(filterdata); } }catch(Exception e){ @@ -417,12 +407,12 @@ public class PolicyManagerServlet extends HttpServlet { } } } - + if(!policyData.isEmpty()){ for(int i =0; i < policyData.size(); i++){ PolicyVersion policy = (PolicyVersion) policyData.get(i); JSONObject el = new JSONObject(); - el.put("name", policy.getPolicyName().replace(File.separator, "/")); + el.put("name", policy.getPolicyName().replace(File.separator, "/")); el.put("date", policy.getModifiedDate()); el.put("version", policy.getActiveVersion()); el.put("size", ""); @@ -436,7 +426,7 @@ public class PolicyManagerServlet extends HttpServlet { }catch(Exception e){ LOGGER.error("Exception occured while reading policy Data from Policy Version table for Policy Search Data"+e); } - + return new JSONObject().put(RESULT, resultList); } @@ -542,7 +532,7 @@ public class PolicyManagerServlet extends HttpServlet { peParams.put("split_1", split[1]); peParams.put("split_0", split[0]); List queryData = null; - if(jUnit){ + if(PolicyController.isjUnit()){ queryData = controller.getDataByQuery(query, null); }else{ queryData = controller.getDataByQuery(query, peParams); @@ -574,12 +564,12 @@ public class PolicyManagerServlet extends HttpServlet { }else{ return error("Error Occured while Describing the Policy"); } - + return object; } //Get the List of Policies and Scopes for Showing in Editor tab - private JSONObject list(JSONObject params, HttpServletRequest request) throws ServletException { + private JSONObject list(JSONObject params, HttpServletRequest request) throws ServletException { Set scopes = null; List roles = null; try { @@ -587,7 +577,7 @@ public class PolicyManagerServlet extends HttpServlet { //Get the Login Id of the User from Request String testUserID = getTestUserId(); String userId = testUserID != null ? testUserID : UserUtils.getUserSession(request).getOrgUserId(); - //Check if the Role and Scope Size are Null get the values from db. + //Check if the Role and Scope Size are Null get the values from db. List userRoles = controller.getRoles(userId); roles = new ArrayList<>(); scopes = new HashSet<>(); @@ -602,7 +592,7 @@ public class PolicyManagerServlet extends HttpServlet { } }else{ scopes.add(userRole.getScope()); - } + } } } @@ -623,8 +613,8 @@ public class PolicyManagerServlet extends HttpServlet { scopes.add(tempScope); } } - } - + } + if("/".equals(path)){ if(roles.contains(SUPERADMIN) || roles.contains(SUPEREDITOR) || roles.contains(SUPERGUEST)){ List scopesList = queryPolicyEditorScopes(null); @@ -632,7 +622,7 @@ public class PolicyManagerServlet extends HttpServlet { PolicyEditorScopes scope = (PolicyEditorScopes) list; if(!(scope.getScopeName().contains(File.separator))){ JSONObject el = new JSONObject(); - el.put("name", scope.getScopeName()); + el.put("name", scope.getScopeName()); el.put("date", scope.getCreatedDate()); el.put("size", ""); el.put("type", "dir"); @@ -647,7 +637,7 @@ public class PolicyManagerServlet extends HttpServlet { List scopesList = queryPolicyEditorScopes(scope.toString()); if(!scopesList.isEmpty()){ PolicyEditorScopes scopeById = (PolicyEditorScopes) scopesList.get(0); - el.put("name", scopeById.getScopeName()); + el.put("name", scopeById.getScopeName()); el.put("date", scopeById.getCreatedDate()); el.put("size", ""); el.put("type", "dir"); @@ -663,7 +653,7 @@ public class PolicyManagerServlet extends HttpServlet { activePolicyList(scopeName, resultList, roles, scopes, onlyFolders); } catch (Exception ex) { LOGGER.error("Error Occured While reading Policy Files List"+ex ); - } + } } return new JSONObject().put(RESULT, resultList); @@ -684,7 +674,7 @@ public class PolicyManagerServlet extends HttpServlet { } PolicyController controller = getPolicyControllerInstance(); List scopesList = null; - if(jUnit){ + if(PolicyController.isjUnit()){ scopesList = controller.getDataByQuery(scopeNamequery, null); }else{ scopesList = controller.getDataByQuery(scopeNamequery, params); @@ -703,13 +693,13 @@ public class PolicyManagerServlet extends HttpServlet { } String query = "from PolicyVersion where POLICY_NAME like :scopeName"; String scopeNamequery = "from PolicyEditorScopes where SCOPENAME like :scopeName"; - + SimpleBindings params = new SimpleBindings(); params.put("scopeName", scopeName + "%"); - + List activePolicies = null; List scopesList = null; - if(jUnit){ + if(PolicyController.isjUnit()){ activePolicies = controller.getDataByQuery(query, null); scopesList = controller.getDataByQuery(scopeNamequery, null); }else{ @@ -732,7 +722,7 @@ public class PolicyManagerServlet extends HttpServlet { } if(scopeName.equalsIgnoreCase(checkScope)){ JSONObject el = new JSONObject(); - el.put("name", scope); + el.put("name", scope); el.put("date", scopeById.getModifiedDate()); el.put("size", ""); el.put("type", "dir"); @@ -740,7 +730,7 @@ public class PolicyManagerServlet extends HttpServlet { el.put("modifiedBy", scopeById.getUserModifiedBy().getUserName()); resultList.add(el); } - } + } } String scopeNameCheck = null; for (Object list : activePolicies) { @@ -754,7 +744,7 @@ public class PolicyManagerServlet extends HttpServlet { } if(scopeNameValue.equals(scopeNameCheck)){ JSONObject el = new JSONObject(); - el.put("name", policy.getPolicyName().substring(policy.getPolicyName().lastIndexOf(File.separator)+1)); + el.put("name", policy.getPolicyName().substring(policy.getPolicyName().lastIndexOf(File.separator)+1)); el.put("date", policy.getModifiedDate()); el.put("version", policy.getActiveVersion()); el.put("size", ""); @@ -765,7 +755,7 @@ public class PolicyManagerServlet extends HttpServlet { } }else if(!scopes.isEmpty() && scopes.contains(scopeNameValue)){ JSONObject el = new JSONObject(); - el.put("name", policy.getPolicyName().substring(policy.getPolicyName().lastIndexOf(File.separator)+1)); + el.put("name", policy.getPolicyName().substring(policy.getPolicyName().lastIndexOf(File.separator)+1)); el.put("date", policy.getModifiedDate()); el.put("version", policy.getActiveVersion()); el.put("size", ""); @@ -774,7 +764,7 @@ public class PolicyManagerServlet extends HttpServlet { el.put("modifiedBy", getUserName(policy.getModifiedBy())); resultList.add(el); } - } + } } private String getUserName(String loginId){ @@ -836,11 +826,11 @@ public class PolicyManagerServlet extends HttpServlet { if(activePolicies.size() != policyActiveInPDP.size()){ rename = true; } - + UserInfo userInfo = new UserInfo(); userInfo.setUserLoginId(userId); if(policyActiveInPDP.size() == 0){ - renameScope(scopesList, scopeName, newScopeName, controller); + renameScope(scopesList, scopeName, newScopeName, controller); }else if(rename){ renameScope(scopesList, scopeName, newScopeName, controller); for(String scope : scopeOfPolicyActiveInPDP){ @@ -853,7 +843,7 @@ public class PolicyManagerServlet extends HttpServlet { } if(isActive){ return error("The Following policies rename failed. Since they are active in PDP Groups" +policyActiveInPDP); - } + } } return success(); } catch (Exception e) { @@ -861,7 +851,7 @@ public class PolicyManagerServlet extends HttpServlet { return error(e.getMessage()); } } - + private void renameScope(List scopesList, String scopeName, String newScopeName, PolicyController controller){ for(Object object : scopesList){ PolicyEditorScopes editorScopeEntity = (PolicyEditorScopes) object; @@ -874,7 +864,7 @@ public class PolicyManagerServlet extends HttpServlet { controller.updateData(editorScopeEntity); } } - + private JSONObject policyRename(String oldPath, String newPath, String userId) throws ServletException { try { PolicyEntity entity = null; @@ -909,7 +899,7 @@ public class PolicyManagerServlet extends HttpServlet { String[] oldPolicySplit = oldPolicyCheck.split(":"); //Check PolicyEntity table with newPolicy Name - String policyEntityquery = "FROM PolicyEntity where policyName = :newPolicySplit_1 and scope = :newPolicySplit_1"; + String policyEntityquery = "FROM PolicyEntity where policyName = :newPolicySplit_1 and scope = :newPolicySplit_0"; SimpleBindings policyParams = new SimpleBindings(); policyParams.put("newPolicySplit_1", newPolicySplit[1]); policyParams.put("newPolicySplit_0", newPolicySplit[0]); @@ -951,7 +941,7 @@ public class PolicyManagerServlet extends HttpServlet { }else{ return error("Policy rename failed due to policy not able to retrieve from database. Please, contact super-admin."); } - + return success(); } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE+"Exception Occured While Renaming Policy"+e); @@ -959,7 +949,7 @@ public class PolicyManagerServlet extends HttpServlet { } } - private JSONObject checkOldPolicyEntryAndUpdate(PolicyEntity entity, String newScope, String removenewPolicyExtension, String oldScope, String removeoldPolicyExtension, + private JSONObject checkOldPolicyEntryAndUpdate(PolicyEntity entity, String newScope, String removenewPolicyExtension, String oldScope, String removeoldPolicyExtension, String policyName, String newpolicyName, String oldpolicyName, String userId) throws ServletException{ try { ConfigurationDataEntity configEntity = entity.getConfigurationData(); @@ -1151,7 +1141,7 @@ public class PolicyManagerServlet extends HttpServlet { cloneRecord(newPolicySplit[1], oldPolicySplit[0], oldPolicySplit[1], newPolicySplit[0], newPolicySplit[1], entity, userId); success = true; } - + if(success){ PolicyVersion entityItem = new PolicyVersion(); entityItem.setActiveVersion(Integer.parseInt(version)); @@ -1202,7 +1192,8 @@ public class PolicyManagerServlet extends HttpServlet { splitPolicyName = policyNamewithoutExtension.replace(".Decision_", ":Decision_"); } String[] split = splitPolicyName.split(":"); - query = "FROM PolicyEntity where policyName like split_1 and scope = split_0"; + + query = "FROM PolicyEntity where policyName like :split_1 and scope = :split_0"; policyParams.put("split_1", split[1] + "%"); policyParams.put("split_0", split[0]); }else{ @@ -1210,7 +1201,7 @@ public class PolicyManagerServlet extends HttpServlet { query = "FROM PolicyEntity where scope like :policyNamewithoutExtension"; policyParams.put("policyNamewithoutExtension", policyNamewithoutExtension + "%"); } - + List policyEntityobjects = controller.getDataByQuery(query, policyParams); String activePolicyName = null; boolean pdpCheck = false; @@ -1238,7 +1229,7 @@ public class PolicyManagerServlet extends HttpServlet { controller.deleteData(policyEntity.getConfigurationData()); }else if(policyNamewithoutExtension.contains("Action_")){ controller.deleteData(policyEntity.getActionBodyEntity()); - } + } } } } @@ -1267,11 +1258,11 @@ public class PolicyManagerServlet extends HttpServlet { String currentVersionPolicyName = policyNamewithExtension.substring(policyNamewithExtension.lastIndexOf(File.separator)+1); String currentVersionScope = policyNamewithExtension.substring(0, policyNamewithExtension.lastIndexOf(File.separator)).replace(File.separator, "."); query = "FROM PolicyEntity where policyName = :currentVersionPolicyName and scope = :currentVersionScope"; - + SimpleBindings peParams = new SimpleBindings(); peParams.put("currentVersionPolicyName", currentVersionPolicyName); peParams.put("currentVersionScope", currentVersionScope); - + List policyEntitys = controller.getDataByQuery(query, peParams); if(!policyEntitys.isEmpty()){ policyEntity = (PolicyEntity) policyEntitys.get(0); @@ -1292,9 +1283,9 @@ public class PolicyManagerServlet extends HttpServlet { }else if(policyNamewithoutExtension.contains("Action_")){ controller.deleteData(policyEntity.getActionBodyEntity()); } - + if(version > 1){ - int highestVersion = 0; + int highestVersion = 0; if(!policyEntityobjects.isEmpty()){ for(Object object : policyEntityobjects){ policyEntity = (PolicyEntity) object; @@ -1325,7 +1316,7 @@ public class PolicyManagerServlet extends HttpServlet { return error("Policy can't be deleted, it is active in PDP Groups. PolicyName: '"+policyEntity.getScope() + "." +policyEntity.getPolicyName()+"'"); } } - } + } }else{ List activePoliciesInPDP = new ArrayList(); if(!policyEntityobjects.isEmpty()){ @@ -1355,7 +1346,7 @@ public class PolicyManagerServlet extends HttpServlet { //Delete from policyVersion and policyEditor Scope table String policyVersionQuery = "delete PolicyVersion where POLICY_NAME like '"+path.replace("\\", "\\\\")+"%' and id >0"; controller.executeQuery(policyVersionQuery); - + //Policy Notification PolicyVersion entity = new PolicyVersion(); entity.setPolicyName(path); @@ -1375,7 +1366,7 @@ public class PolicyManagerServlet extends HttpServlet { insertactivePDPVersion.setModifiedBy(userId); controller.saveData(insertactivePDPVersion); } - + return error("All the Policies has been deleted in Scope. Except the following list of Policies:"+activePoliciesInPDP); }else{ String policyScopeQuery = "delete PolicyEditorScopes where SCOPENAME like '"+path.replace("\\", "\\\\")+"%' and id >0"; @@ -1401,10 +1392,10 @@ public class PolicyManagerServlet extends HttpServlet { String mode = params.getString("mode"); String path = params.getString("path"); LOGGER.debug("editFile path: {}"+ path); - + String domain = path.substring(1, path.lastIndexOf("/")); domain = domain.replace("/", "."); - + path = path.substring(1); path = path.replace("/", "."); String dbCheckName = path; @@ -1415,14 +1406,14 @@ public class PolicyManagerServlet extends HttpServlet { }else if(dbCheckName.contains("Decision_")){ dbCheckName = dbCheckName.replace(".Decision_", ":Decision_"); } - + String[] split = dbCheckName.split(":"); String query = "FROM PolicyEntity where policyName = :split_1 and scope = :split_0"; SimpleBindings peParams = new SimpleBindings(); peParams.put("split_1", split[1]); peParams.put("split_0", split[0]); List queryData = null; - if(jUnit){ + if(PolicyController.isjUnit()){ queryData = controller.getDataByQuery(query, null); }else{ queryData = controller.getDataByQuery(query, peParams); @@ -1432,7 +1423,7 @@ public class PolicyManagerServlet extends HttpServlet { Object policy = XACMLPolicyScanner.readPolicy(stream); - PolicyRestAdapter policyAdapter = new PolicyRestAdapter(); + PolicyRestAdapter policyAdapter = new PolicyRestAdapter(); policyAdapter.setData(policy); if("viewPolicy".equalsIgnoreCase(mode)){ @@ -1451,7 +1442,7 @@ public class PolicyManagerServlet extends HttpServlet { PolicyAdapter setpolicyAdapter = PolicyAdapter.getInstance(); setpolicyAdapter.configure(policyAdapter,entity); - + policyAdapter.setParentPath(null); ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(policyAdapter); @@ -1478,7 +1469,7 @@ public class PolicyManagerServlet extends HttpServlet { } }else{ name = params.getString("name"); - } + } }catch(Exception e){ name = params.getString("name"); LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Exception Occured While Adding Scope"+e); @@ -1493,7 +1484,7 @@ public class PolicyManagerServlet extends HttpServlet { String validate = PolicyUtils.policySpecialCharValidator(validateName); if(!validate.contains("success")){ return error(validate); - } + } } LOGGER.debug("addFolder path: {} name: {}" + path +name); if(!name.equals("")){ @@ -1508,7 +1499,7 @@ public class PolicyManagerServlet extends HttpServlet { newScope.setScopeName(name); newScope.setUserCreatedBy(userInfo); newScope.setUserModifiedBy(userInfo); - controller.saveData(newScope); + controller.saveData(newScope); }else{ return error("Scope Already Exists"); } @@ -1543,7 +1534,7 @@ public class PolicyManagerServlet extends HttpServlet { throw new ServletException(e); } } - + private PolicyController getPolicyControllerInstance(){ return policyController != null ? getPolicyController() : new PolicyController(); } @@ -1555,4 +1546,4 @@ public class PolicyManagerServlet extends HttpServlet { public static void setTestUserId(String testUserId) { PolicyManagerServlet.testUserId = testUserId; } -} \ No newline at end of file +} diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyNotificationMail.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyNotificationMail.java index a4e476200..2326a9fb7 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyNotificationMail.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyNotificationMail.java @@ -122,7 +122,12 @@ public class PolicyNotificationMail{ boolean sendFlag = false; SimpleBindings params = new SimpleBindings(); params.put("policyFileName", policyFileName); - List watchList = policyNotificationDao.getDataByQuery(query, params); + List watchList = null; + if(PolicyController.isjUnit()){ + watchList = policyNotificationDao.getDataByQuery(query, null); + }else{ + watchList = policyNotificationDao.getDataByQuery(query, params); + } if(watchList != null && !watchList.isEmpty()){ for(Object watch : watchList){ WatchPolicyNotificationTable list = (WatchPolicyNotificationTable) watch; 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 7234a3b6a..08f80304c 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 @@ -82,8 +82,24 @@ public class PolicyRestController extends RestrictedBaseController{ private static final String modal = "model"; private static final String importDictionary = "import_dictionary"; + private static CommonClassDao commonClassDao; + + public static CommonClassDao getCommonClassDao() { + return commonClassDao; + } + + public static void setCommonClassDao(CommonClassDao commonClassDao) { + PolicyRestController.commonClassDao = commonClassDao; + } + @Autowired - CommonClassDao commonClassDao; + private PolicyRestController(CommonClassDao commonClassDao){ + PolicyRestController.commonClassDao = commonClassDao; + } + + public PolicyRestController(){ + //default constructor + } @RequestMapping(value={"/policycreation/save_policy"}, method={RequestMethod.POST}) public void policyCreationController(HttpServletRequest request, HttpServletResponse response) { diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java index a0f1ba86d..7c60ecfdf 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/components/HumanPolicyComponent.java @@ -202,7 +202,7 @@ class HtmlProcessor extends SimpleCallback { combiningAlgo2human.put("only-one-applicable", "to honour the result of the first successfully evaluated $placeholder$ in order"); } - private Map attributeIdentifiersMap = new HashMap(); + private Map attributeIdentifiersMap = new HashMap<>(); private final StringWriter stringWriter = new StringWriter(); private final PrintWriter htmlOut = new PrintWriter(stringWriter); @@ -357,7 +357,7 @@ class HtmlProcessor extends SimpleCallback { else policySet(policySet, "li"); - if (policySet.getPolicySetOrPolicyOrPolicySetIdReference().size() > 0) + if (!policySet.getPolicySetOrPolicyOrPolicySetIdReference().isEmpty()) htmlOut.println("
    "); return super.onPreVisitPolicySet(parent, policySet); @@ -377,7 +377,7 @@ class HtmlProcessor extends SimpleCallback { LOGGER.trace("PolicySet: " + policySet.getPolicySetId() + " Description: " + policySet.getDescription()); - if (policySet.getPolicySetOrPolicyOrPolicySetIdReference().size() > 0) + if (!policySet.getPolicySetOrPolicyOrPolicySetIdReference().isEmpty()) htmlOut.println("
"); htmlOut.println("

"); @@ -421,7 +421,7 @@ class HtmlProcessor extends SimpleCallback { } if (policySet.getPolicySetOrPolicyOrPolicySetIdReference() != null && - policySet.getPolicySetOrPolicyOrPolicySetIdReference().size() > 0) { + !policySet.getPolicySetOrPolicyOrPolicySetIdReference().isEmpty()) { String algoDesc = combiningAlgo2human.get(combiningAlgorithm); if (algoDesc != null) { algoDesc = algoDesc.replace("$placeholder$", "policy") + " (" + "" + combiningAlgorithm + ")"; @@ -449,7 +449,7 @@ class HtmlProcessor extends SimpleCallback { policy(policy); - if (policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().size() > 0) + if (!policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().isEmpty()) htmlOut.println("
    "); return super.onPreVisitPolicy(parent, policy); @@ -464,7 +464,7 @@ class HtmlProcessor extends SimpleCallback { LOGGER.trace("PolicySet: " + policy.getPolicyId() + "Parent PolicySet: " + parent.getPolicySetId() + " Version: " + parent.getVersion()); - if (policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().size() > 0) + if (!policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().isEmpty()) htmlOut.println("
"); htmlOut.println("

"); @@ -506,7 +506,7 @@ class HtmlProcessor extends SimpleCallback { } if (policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition() != null && - policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().size() > 0) { + !policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().isEmpty()) { String algoDesc = combiningAlgo2human.get(combiningAlgorithm); if (algoDesc != null) { algoDesc = algoDesc.replace("$placeholder$", "rule") + " (" + combiningAlgorithm + ")"; @@ -710,7 +710,7 @@ class HtmlProcessor extends SimpleCallback { // StdAttribute attribute = null; AttributeValueType value = match.getAttributeValue(); - String attributeDataType = null; + String attributeDataType; if (match.getAttributeDesignator() != null && value != null) { AttributeDesignatorType designator = match.getAttributeDesignator(); attribute = new StdAttribute(new IdentifierImpl(designator.getCategory()), @@ -822,11 +822,12 @@ class HtmlProcessor extends SimpleCallback { } private String removePrimitives(String in) { - in = in.replace("string-", ""); - in = in.replace("integer-", ""); - in = in.replace("double-", ""); - in = in.replace("boolean-", ""); - return in; + String newIn = in; + newIn = newIn.replace("string-", ""); + newIn = newIn.replace("integer-", ""); + newIn = newIn.replace("double-", ""); + newIn = newIn.replace("boolean-", ""); + return newIn; } private String stringifyCondition(ConditionType condition) { 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 353e08a44..32f40b9e7 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 @@ -64,4 +64,6 @@ public class HibernateSession{ logSessionFactory = logSessionFactory1; } + private HibernateSession(){ + } } diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java index fc7cb60e5..4dc45425a 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateBRMSParamController.java @@ -173,7 +173,7 @@ public class CreateBRMSParamController extends RestrictedBaseController { if (flag) { params.append(line); } - if (line.contains("declare Params")) { + if (line.contains("declare PapParams")) { params.append(line); flag = true; } @@ -181,7 +181,7 @@ public class CreateBRMSParamController extends RestrictedBaseController { break; } } - params = new StringBuilder(params.toString().replace("declare Params", "").replace("end", "").replaceAll("\\s+", "")); + params = new StringBuilder(params.toString().replace("declare PapParams", "").replace("end", "").replaceAll("\\s+", "")); String[] components = params.toString().split(":"); String caption = ""; for (int i = 0; i < components.length; i++) { @@ -400,7 +400,7 @@ public class CreateBRMSParamController extends RestrictedBaseController { if (flag) { params.append(line); } - if (line.contains("rule") && line.contains(".Params\"")) { + if (line.contains("rule") && line.contains(".PapParams\"")) { params.append(line); flag = true; } @@ -408,8 +408,8 @@ public class CreateBRMSParamController extends RestrictedBaseController { break; } } - params = new StringBuilder(params.substring(params.indexOf(".Params\"")+ 8)); - params = new StringBuilder(params.toString().replaceAll("\\s+", "").replace("salience1000whenthenParamsparams=newParams();","") + params = new StringBuilder(params.substring(params.indexOf(".PapParams\"")+ 11)); + params = new StringBuilder(params.toString().replaceAll("\\s+", "").replace("salience1000whenthenPapParamsparams=newPapParams();","") .replace("insert(params);end", "") .replace("params.set", "")); String[] components = params.toString().split("\\);"); @@ -462,7 +462,7 @@ public class CreateBRMSParamController extends RestrictedBaseController { brmsTemplateVlaue + policyData.getRuleName() + "%$> \n */ \n"; body = body + findRule((String) policyData.getRuleName()) + "\n"; StringBuilder generatedRule = new StringBuilder(); - generatedRule.append("rule \""+ policyData.getDomainDir().replace("\\", ".") +".Config_BRMS_Param_" + policyData.getPolicyName()+".Params\" \n\tsalience 1000 \n\twhen\n\tthen\n\t\tParams params = new Params();"); + generatedRule.append("rule \""+ policyData.getDomainDir().replace("\\", ".") +".Config_BRMS_Param_" + policyData.getPolicyName()+".PapParams\" \n\tsalience 1000 \n\twhen\n\tthen\n\t\tPapParams params = new PapParams();"); if(policyData.getRuleData().size() > 0){ for(Object keyValue: policyData.getRuleData().keySet()){ diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java index f10041e38..392adf039 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateClosedLoopPMController.java @@ -98,24 +98,24 @@ public class CreateClosedLoopPMController{ String attributeId = designator.getAttributeId(); // First match in the target is OnapName, so set that value. - if (attributeId.equals("ONAPName")) { + if ("ONAPName".equals(attributeId)) { policyAdapter.setOnapName(value); } - if (attributeId.equals("RiskType")){ + if ("RiskType".equals(attributeId)){ policyAdapter.setRiskType(value); } - if (attributeId.equals("RiskLevel")){ + if ("RiskLevel".equals(attributeId)){ policyAdapter.setRiskLevel(value); } - if (attributeId.equals("guard")){ + if ("guard".equals(attributeId)){ policyAdapter.setGuard(value); } - if (attributeId.equals("TTLDate") && !value.contains("NA")){ + if ("TTLDate".equals(attributeId) && !value.contains("NA")){ PolicyController controller = new PolicyController(); String newDate = controller.convertDate(value); policyAdapter.setTtlDate(newDate); } - if (attributeId.equals("ServiceType")){ + if ("ServiceType".equals(attributeId)){ LinkedHashMap serviceTypePolicyName1 = new LinkedHashMap<>(); String key = "serviceTypePolicyName"; serviceTypePolicyName1.put(key, value); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java index 0f55ba6ec..b349adacb 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java @@ -1379,6 +1379,14 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { @RequestMapping(value={"/ms_dictionary/set_MSModelData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public void SetMSModelData(HttpServletRequest request, HttpServletResponse response) throws IOException, FileUploadException{ + modelList = new ArrayList<>(); + dirDependencyList = new ArrayList<>(); + classMap = new HashMap<>(); + retmap = new HashMap<>(); + uniqueKeys= new HashSet<>(); + uniqueDataKeys= new HashSet<>(); + dataListBuffer=new StringBuilder(); + dataConstraints= new ArrayList <>(); List items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); boolean zip = false; boolean yml= false; diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java index ed0bf4caf..9832f5803 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateFirewallController.java @@ -90,6 +90,14 @@ public class CreateFirewallController extends RestrictedBaseController { private static CommonClassDao commonClassDao; + public static CommonClassDao getCommonClassDao() { + return commonClassDao; + } + + public static void setCommonClassDao(CommonClassDao commonClassDao) { + CreateFirewallController.commonClassDao = commonClassDao; + } + private List tagCollectorList; private String jsonBody; List expandablePrefixIPList = new ArrayList<>(); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java index 625b2bdd8..71d0b3d03 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreatePolicyController.java @@ -60,7 +60,7 @@ public class CreatePolicyController extends RestrictedBaseController{ policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName()); policyAdapter.setConfigType(entity.getConfigurationData().getConfigType()); policyAdapter.setConfigBodyData(entity.getConfigurationData().getConfigBody()); - String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf(' ') + 1); + String policyNameValue = policyAdapter.getPolicyName().substring(policyAdapter.getPolicyName().indexOf('_') + 1); policyAdapter.setPolicyName(policyNameValue); String description = ""; try{ diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java index 21f3793f1..f987f906d 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/PolicyNotificationController.java @@ -64,13 +64,13 @@ public class PolicyNotificationController extends RestrictedBaseController { String responseValue = ""; try { String userId = UserUtils.getUserSession(request).getOrgUserId(); - System.out.println(userId); + logger.info("userid info: " + userId); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); String name = root.get("watchData").get("name").toString(); JsonNode pathList = root.get("watchData").get("path"); - String finalName = ""; + String finalName; if(pathList.isArray()){ ArrayNode arrayNode = (ArrayNode) pathList; for (int i = 0; i < arrayNode.size(); i++) { diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/CommonClassDaoImpl.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/CommonClassDaoImpl.java index 946f90ac7..c8ed3a096 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/CommonClassDaoImpl.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/CommonClassDaoImpl.java @@ -268,7 +268,12 @@ public class CommonClassDaoImpl implements CommonClassDao{ try { Query hbquery = session.createQuery(query); for (Map.Entry paramPair : params.entrySet()) { - hbquery.setParameter(paramPair.getKey(), paramPair.getValue()); + if(paramPair.getValue() instanceof java.lang.Long){ + hbquery.setLong(paramPair.getKey(), (long) paramPair.getValue()); + } + else{ + hbquery.setParameter(paramPair.getKey(), paramPair.getValue()); + } } data = hbquery.list(); tx.commit(); diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/SystemLogDbDaoImpl.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/SystemLogDbDaoImpl.java index 49024ba0d..c96da506f 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/SystemLogDbDaoImpl.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/daoImp/SystemLogDbDaoImpl.java @@ -43,16 +43,6 @@ import org.onap.policy.common.logging.flexlogger.Logger; public class SystemLogDbDaoImpl implements SystemLogDbDao { private static final Logger logger = FlexLogger.getLogger(SystemLogDbDaoImpl.class); - private static boolean jUnit = false; - - public static boolean isjUnit() { - return jUnit; - } - - public static void setjUnit(boolean jUnit) { - SystemLogDbDaoImpl.jUnit = jUnit; - } - @SuppressWarnings("unchecked") @Override public List getLoggingData() { @@ -61,7 +51,7 @@ public class SystemLogDbDaoImpl implements SystemLogDbDao { List system = null; try { String sqlWhere = null; - if(jUnit){ + if(PolicyController.isjUnit()){ sqlWhere = ""; }else{ sqlWhere = "date > DATE_SUB(curdate(), INTERVAL 5 DAY) ORDER BY date DESC limit "+PolicyController.getLogTableLimit()+""; @@ -90,7 +80,7 @@ public class SystemLogDbDaoImpl implements SystemLogDbDao { List system = null; try { String sqlWhere = null; - if(jUnit){ + if(PolicyController.isjUnit()){ sqlWhere = ""; }else{ sqlWhere = "date > DATE_SUB(curdate(), INTERVAL 5 DAY) and logtype = 'error' ORDER BY date DESC limit "+PolicyController.getSystemAlertTableLimit()+""; diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPGroupContainer.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPGroupContainer.java index 04ec3e868..3b3f11957 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPGroupContainer.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPGroupContainer.java @@ -365,7 +365,7 @@ public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements Po @Override public Object firstItemId() { synchronized (this.groups) { - if (this.groups.size() > 0) { + if (!this.groups.isEmpty()) { return this.groups.get(0); } } @@ -375,7 +375,7 @@ public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements Po @Override public Object lastItemId() { synchronized (this.groups) { - if (this.groups.size() > 0) { + if (!this.groups.isEmpty()) { return this.groups.get(this.groups.size() - 1); } } @@ -385,8 +385,8 @@ public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements Po @Override public boolean isFirstId(Object itemId) { synchronized (this.groups) { - if (this.groups.size() > 0) { - return (this.groups.get(0).equals(itemId)); + if (!this.groups.isEmpty()) { + return this.groups.get(0).equals(itemId); } } return false; @@ -395,8 +395,8 @@ public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements Po @Override public boolean isLastId(Object itemId) { synchronized (this.groups) { - if (this.groups.size() > 0) { - return (this.groups.get(this.groups.size() - 1).equals(itemId)); + if (!this.groups.isEmpty()) { + return this.groups.get(this.groups.size() - 1).equals(itemId); } } return false; @@ -444,7 +444,7 @@ public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements Po // // You cannot remove the default group // - if (((OnapPDPGroup) itemId).getId().equals("Default")) { + if ("Default".equals(((OnapPDPGroup) itemId).getId())) { throw new UnsupportedOperationException("You can't remove the Default Group."); } // diff --git a/POLICY-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties b/POLICY-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties index 43b2de708..84c5dc5dd 100644 --- a/POLICY-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties +++ b/POLICY-SDK-APP/src/main/webapp/WEB-INF/conf/system.properties @@ -23,8 +23,8 @@ decryption_key = AGLDdG4D04BKm2IxIWEr8o== # The following properties MAY require changes by partner applications. ########################################################################## #Mysql -db.driver = com.mysql.jdbc.Driver -db.connectionURL = jdbc:mysql://localhost:3306/onapsdk1707 +db.driver = org.mariadb.jdbc.Driver +db.connectionURL = jdbc:mariadb://localhost:3306/onapsdk1707 db.userName = root db.password = db.hib.dialect = org.hibernate.dialect.MySQLDialect diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/Windows/Dictionary/CLVarbindDictionary.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/Windows/Dictionary/CLVarbindDictionary.html index 98570f3dd..2271992b0 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/Windows/Dictionary/CLVarbindDictionary.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/Windows/Dictionary/CLVarbindDictionary.html @@ -45,7 +45,7 @@
-
+

Varbind OID is required.

diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/Windows/Dictionary/MSDCAEUUIDDictionary.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/Windows/Dictionary/MSDCAEUUIDDictionary.html index fe7ad5811..89e3aff1e 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/Windows/Dictionary/MSDCAEUUIDDictionary.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/Windows/Dictionary/MSDCAEUUIDDictionary.html @@ -34,7 +34,7 @@

-

Onap Name is required.

+

UUID field is required.

diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVnfTypeDictGridController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVnfTypeDictGridController.js index 08d4662da..90b77e45d 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVnfTypeDictGridController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/controller/dictionaryGridController/CLVnfTypeDictGridController.js @@ -140,7 +140,7 @@ app.controller('vnfTypeDictGridController', function ($scope, PolicyAppService, $scope.deleteVnfType = function(data) { var uuu = "searchDictionary"; - var postData={data: data, type: "attribute"}; + var postData={data: data, type: "clVnf"}; var searchString = "\n"; $.ajax({ type : 'POST', diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/main/policyEditor.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/main/policyEditor.html index 9721e1c2e..f5a5e8678 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/main/policyEditor.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/main/policyEditor.html @@ -220,10 +220,6 @@ - - - - diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ActionPolicyController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ActionPolicyController.js index 2892936f8..a9097d559 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ActionPolicyController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ActionPolicyController.js @@ -24,6 +24,12 @@ app.controller('actionPolicyController', ['$scope', 'PolicyAppService', 'policyN $scope.savebutton = true; $scope.refreshCheck = false; + if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){ + $scope.temp.policy = { + policyType : "Action" + } + }; + $scope.refresh = function(){ if($scope.refreshCheck){ $scope.policyNavigator.refresh(); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BRMSParamPolicyController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BRMSParamPolicyController.js index 02c31486b..22511c5a7 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BRMSParamPolicyController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BRMSParamPolicyController.js @@ -24,6 +24,13 @@ angular.module('abs').controller('brmsParamPolicyController', ['$scope', '$windo $scope.savebutton = true; $scope.refreshCheck = false; + if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){ + $scope.temp.policy = { + policyType : "Config", + configPolicyType : "BRMS_Param" + } + }; + $scope.refresh = function(){ if($scope.refreshCheck){ $scope.policyNavigator.refresh(); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BRMSRawPolicyController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BRMSRawPolicyController.js index 8f27f2a09..6061b1ef8 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BRMSRawPolicyController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BRMSRawPolicyController.js @@ -24,6 +24,13 @@ angular.module('abs').controller('brmsRawPolicyController', ['$scope', '$window' $scope.savebutton = true; $scope.refreshCheck = false; + if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){ + $scope.temp.policy = { + policyType : "Config", + configPolicyType : "BRMS_Raw" + } + }; + $scope.refresh = function(){ if($scope.refreshCheck){ $scope.policyNavigator.refresh(); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BaseConfigPolicyController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BaseConfigPolicyController.js index 891e4098b..7425c92d4 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BaseConfigPolicyController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/BaseConfigPolicyController.js @@ -25,6 +25,13 @@ app.controller('baseConfigController', ['$scope', 'PolicyAppService', 'policyNav $scope.savebutton = true; $scope.refreshCheck = false; + if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){ + $scope.temp.policy = { + policyType : "Config", + configPolicyType : "Base" + } + }; + $scope.refresh = function(){ if($scope.refreshCheck){ $scope.policyNavigator.refresh(); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ClosedLoopFaultController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ClosedLoopFaultController.js index b3f702f6a..1015e7aac 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ClosedLoopFaultController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ClosedLoopFaultController.js @@ -24,6 +24,13 @@ angular.module("abs").controller('clFaultController', ['$scope', '$window', 'Pol $scope.savebutton = true; $scope.refreshCheck = false; + if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){ + $scope.temp.policy = { + policyType : "Config", + configPolicyType : "ClosedLoop_Fault" + } + }; + $scope.refresh = function(){ if($scope.refreshCheck){ $scope.policyNavigator.refresh(); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ClosedLoopPMController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ClosedLoopPMController.js index caec13feb..a67266074 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ClosedLoopPMController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/ClosedLoopPMController.js @@ -23,7 +23,14 @@ angular.module("abs").controller('clPMController', ['$scope', '$window', '$timeo $scope.policyNavigator; $scope.savebutton = true; $scope.refreshCheck = false; - + + if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){ + $scope.temp.policy = { + policyType : "Config", + configPolicyType : "ClosedLoop_PM" + } + }; + $scope.refresh = function(){ if($scope.refreshCheck){ $scope.policyNavigator.refresh(); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js index fb10a2cc9..5b2bdb2b2 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DecisionPolicyController.js @@ -24,6 +24,12 @@ angular.module('abs').controller('decisionPolicyController', ['$scope', 'PolicyA $scope.savebutton = true; $scope.refreshCheck = false; + if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){ + $scope.temp.policy = { + policyType : "Decision" + } + }; + $scope.refresh = function(){ if($scope.refreshCheck){ $scope.policyNavigator.refresh(); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/FirewallPolicyController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/FirewallPolicyController.js index 5988ef302..1051ecd9a 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/FirewallPolicyController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/FirewallPolicyController.js @@ -24,6 +24,13 @@ angular.module('abs').controller('fwPolicyController', ['$scope', '$window', 'Po $scope.savebutton = true; $scope.refreshCheck = false; + if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){ + $scope.temp.policy = { + policyType : "Config", + configPolicyType : "Firewall Config" + } + }; + $scope.refresh = function(){ if($scope.refreshCheck){ $scope.policyNavigator.refresh(); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/entities/item.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/entities/item.js index b96a4f732..0e095a841 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/entities/item.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/js/entities/item.js @@ -26,7 +26,7 @@ angular.module('abs').factory('item', ['$http', '$q', 'policyManagerConfig', fun path: path || [], type: model && model.type || 'file', size: model && parseInt(model.size || 0), - date: parseMySQLDate(model && model.date), + date: model && model.date, version: model && model.version || '', createdBy: model && model.createdBy || '', modifiedBy: model && model.modifiedBy || '', @@ -139,6 +139,11 @@ angular.module('abs').factory('item', ['$http', '$q', 'policyManagerConfig', fun self.inprocess = true; self.error = ''; $http.post(policyManagerConfig.renameUrl, data).success(function(data) { + if(data.result.error != undefined){ + var value = data.result.error; + value = value.replace("rename" , "move"); + data.result.error = value; + } self.deferredHandler(data, deferred); }).error(function(data) { self.deferredHandler(data, deferred, 'Error Occured While Moving'); diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/templates/modals.html b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/templates/modals.html index f7a6d2442..77006002c 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/templates/modals.html +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/templates/modals.html @@ -1,4 +1,4 @@ -