From 6ed1731fa2ce340d745dc2d39ffc6a066f50fbc2 Mon Sep 17 00:00:00 2001 From: krishnajinka Date: Thu, 9 Aug 2018 07:35:57 +0900 Subject: [PATCH] Add PAP Policy parameter builder xacml policy Fix Sonar flagged major issue about 14 params instead of 9 in the constructor of std pap policy class. Commit5 for modify constrctor.fix test Issue-ID: POLICY-1016 Change-Id: I79c8482b7fc4e203cb18402ba2b5a68a120c57b1 Signed-off-by: krisjinka --- .../org/onap/policy/pap/test/XACMLPAPTest.java | 300 ++-- .../pdp/rest/api/services/ActionPolicyService.java | 139 +- .../rest/api/services/BRMSParamPolicyService.java | 118 +- .../rest/api/services/BRMSRawPolicyService.java | 136 +- .../api/services/ClosedLoopFaultPolicyService.java | 174 +- .../api/services/ClosedLoopPMPolicyService.java | 176 +- .../pdp/rest/api/services/ConfigPolicyService.java | 199 ++- .../rest/api/services/DecisionPolicyService.java | 142 +- .../rest/api/services/FirewallPolicyService.java | 153 +- .../api/services/MicroServicesPolicyService.java | 154 +- .../api/services/OptimizationPolicyService.java | 123 +- .../pdp/rest/api/services/PAPServicesTest.java | 71 +- .../onap/policy/xacml/std/pap/StdPAPPolicy.java | 1810 ++++++++++---------- .../policy/xacml/std/pap/StdPAPPolicyParams.java | 193 +++ .../xacml/test/std/pap/StdPAPPolicyTest.java | 161 +- 15 files changed, 2235 insertions(+), 1814 deletions(-) create mode 100644 ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicyParams.java 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 717266264..80772e212 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 @@ -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. @@ -74,6 +74,7 @@ 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.onap.policy.xacml.std.pap.StdPAPPolicyParams; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockServletConfig; import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder; @@ -115,7 +116,7 @@ public class XACMLPAPTest { logger.info("setUpDB: Exiting"); } - public void cleanDb(String persistenceUnit, Properties properties){ + public void cleanDb(String persistenceUnit, Properties properties) { logger.debug("cleanDb: enter"); EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceUnit, properties); @@ -152,32 +153,49 @@ public class XACMLPAPTest { commonClassDao = Mockito.mock(CommonClassDao.class); new DictionaryUtils(commonClassDao); DictionaryUtils.setDictionaryUtils(new DictionaryUtils()); - Mockito.mock(DictionaryUtils.class); + Mockito.mock(DictionaryUtils.class); } - + @Test public void testFirwallCreatePolicy() throws IOException, ServletException, SQLException { httpServletRequest = Mockito.mock(HttpServletRequest.class); - 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}]}"; + 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"); Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create"); Mockito.when(httpServletRequest.getParameter("policyType")).thenReturn("Config"); - StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Firewall Config", "test", "testDescription", "Test", false, "test", json, 0, - "5","default", "false", ""); - MockServletInputStream mockInput = new MockServletInputStream(PolicyUtils.objectToJsonString(newPAPPolicy).getBytes()); + StdPAPPolicy newPAPPolicy = + new StdPAPPolicy("Firewall Config", "test", "testDescription", "Test", false, "test", json, 0, + "5", "default", "false", ""); + 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_FW_test.1.xml"); } - + @Test public void testBRMSCreatePolicy() throws IOException, ServletException, SQLException { httpServletRequest = Mockito.mock(HttpServletRequest.class); @@ -191,24 +209,25 @@ public class XACMLPAPTest { 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", + 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()); + 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); @@ -219,23 +238,24 @@ public class XACMLPAPTest { 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", + 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()); + "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); @@ -245,22 +265,23 @@ public class XACMLPAPTest { 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", + 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()); + "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); @@ -269,20 +290,21 @@ public class XACMLPAPTest { 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, + 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()); + 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); @@ -292,29 +314,31 @@ public class XACMLPAPTest { 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()); + 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); @@ -324,26 +348,28 @@ public class XACMLPAPTest { 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()); + 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); @@ -354,20 +380,35 @@ public class XACMLPAPTest { 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()); + StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder() + .configPolicyType("Base") + .policyName("test") + .description("test rule") + .onapName("TEST") + .configName("config") + .attributes(configAttributes) + .configType("OTHER") + .configBodyData("test body") + .editPolicy(false) + .domain("test") + .highestVersion(0) + .riskLevel("5") + .riskType("default") + .guard("false") + .ttlDate(null).build()); + 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); @@ -378,7 +419,8 @@ public class XACMLPAPTest { editorScope.setScopeName("test"); editorScope.setUserCreatedBy(userInfo); editorScope.setUserModifiedBy(userInfo); - Mockito.when(commonClassDao.getEntityItem(PolicyEditorScopes.class, "scopeName", "test")).thenReturn(editorScope); + Mockito.when(commonClassDao.getEntityItem(PolicyEditorScopes.class, "scopeName", "test")) + .thenReturn(editorScope); BRMSParamTemplate template = new BRMSParamTemplate(); template.setRuleName("testPolicy"); template.setUserCreatedBy(userInfo); @@ -406,11 +448,12 @@ public class XACMLPAPTest { + "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); - + 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); @@ -439,7 +482,10 @@ public class XACMLPAPTest { // 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\"}]}}"; + 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); @@ -450,7 +496,9 @@ public class XACMLPAPTest { // httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = Mockito.mock(MockHttpServletResponse.class); - json = "{\"dictionaryFields\":{\"varbindName\":\"testRestAPI\",\"varbindDescription\":\"testing\",\"varbindOID\":\"test\"}}"; + json = + "{\"dictionaryFields\":{\"varbindName\":\"testRestAPI\",\"varbindDescription\":\"testing\"," + + "\"varbindOID\":\"test\"}}"; dictionaryTestSetup(false, "Varbind", json); // send Request to PAP pap.service(httpServletRequest, httpServletResponse); @@ -530,7 +578,9 @@ public class XACMLPAPTest { // httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = Mockito.mock(MockHttpServletResponse.class); - json = "{\"dictionaryFields\":{\"prefixListName\":\"testRestAPI\",\"prefixListValue\":\"127.0.0.1\",\"description\":\"testing\"}}"; + json = + "{\"dictionaryFields\":{\"prefixListName\":\"testRestAPI\",\"prefixListValue\":\"127.0.0.1\"," + + "\"description\":\"testing\"}}"; dictionaryTestSetup(false, "PrefixList", json); // send Request to PAP pap.service(httpServletRequest, httpServletResponse); @@ -541,7 +591,9 @@ public class XACMLPAPTest { // httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = Mockito.mock(MockHttpServletResponse.class); - json = "{\"dictionaryFields\":{\"groupName\":\"testRestAPIgroup\",\"description\":\"testing\",\"attributes\":[{\"option\":\"testRestAPI\"}, {\"option\":\"testRestAPI\"}]}}"; + json = + "{\"dictionaryFields\":{\"groupName\":\"testRestAPIgroup\",\"description\":\"testing\"," + + "\"attributes\":[{\"option\":\"testRestAPI\"}, {\"option\":\"testRestAPI\"}]}}"; dictionaryTestSetup(false, "AddressGroup", json); // send Request to PAP pap.service(httpServletRequest, httpServletResponse); @@ -552,7 +604,9 @@ public class XACMLPAPTest { // httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = Mockito.mock(MockHttpServletResponse.class); - json = "{\"dictionaryFields\":{\"groupName\":\"testRestAPIServiceGroup\",\"attributes\":[{\"option\":\"testRestAPIservice\"}]}}"; + json = + "{\"dictionaryFields\":{\"groupName\":\"testRestAPIServiceGroup\"," + + "\"attributes\":[{\"option\":\"testRestAPIservice\"}]}}"; dictionaryTestSetup(false, "ServiceGroup", json); // send Request to PAP pap.service(httpServletRequest, httpServletResponse); @@ -563,7 +617,11 @@ public class XACMLPAPTest { // 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\"}]}}"; + 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); @@ -574,14 +632,23 @@ public class XACMLPAPTest { // 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\"}]}}"; + 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); } - + @Test public void testCommonCreateDictionary() throws IOException, SQLException, ServletException { new DictionaryController(commonClassDao); @@ -593,7 +660,9 @@ public class XACMLPAPTest { when(commonClassDao.getDataById(Category.class, "shortName", "resource")).thenReturn(object); httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = Mockito.mock(MockHttpServletResponse.class); - String json = "{\"dictionaryFields\": {\"onapName\": \"testMMRestAPI1\",\"description\": \"testing update response message\"}}"; + String json = + "{\"dictionaryFields\": {\"onapName\": \"testMMRestAPI1\",\"description\": \"testing update response " + + "message\"}}"; dictionaryTestSetup(false, "OnapName", json); // send Request to PAP pap.service(httpServletRequest, httpServletResponse); @@ -602,7 +671,11 @@ public class XACMLPAPTest { httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = Mockito.mock(MockHttpServletResponse.class); - json = "{\"dictionaryFields\": {\"xacmlId\": \"testMMRestAPI1\",\"datatypeBean\": {\"shortName\": \"string\"}, \"description\": \"testing update\",\"priority\": \"High\",\"userDataTypeValues\": [{\"attributeValues\": \"testAttr\"}, {\"attributeValues\": \"testAttr2\"}, {\"attributeValues\": \"testAttr3\"}]}}"; + json = + "{\"dictionaryFields\": {\"xacmlId\": \"testMMRestAPI1\",\"datatypeBean\": {\"shortName\": " + + "\"string\"}, \"description\": \"testing update\",\"priority\": \"High\"," + + "\"userDataTypeValues\": [{\"attributeValues\": \"testAttr\"}, {\"attributeValues\": " + + "\"testAttr2\"}, {\"attributeValues\": \"testAttr3\"}]}}"; dictionaryTestSetup(false, "Attribute", json); // send Request to PAP pap.service(httpServletRequest, httpServletResponse); @@ -612,7 +685,11 @@ public class XACMLPAPTest { httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = Mockito.mock(MockHttpServletResponse.class); - json = "{\"dictionaryFields\":{\"attributeName\":\"TestMMrestAPI1\",\"type\":\"REST\",\"url\":\"testsomeurl.com\",\"method\":\"GET\",\"description\":\"test create\",\"body\":\"Testing Create\",\"headers\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\",\"number\":\"test\"}]}}"; + json = + "{\"dictionaryFields\":{\"attributeName\":\"TestMMrestAPI1\",\"type\":\"REST\",\"url\":\"testsomeurl" + + ".com\",\"method\":\"GET\",\"description\":\"test create\",\"body\":\"Testing Create\"," + + "\"headers\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\"," + + "\"number\":\"test\"}]}}"; dictionaryTestSetup(false, "Action", json); // send Request to PAP pap.service(httpServletRequest, httpServletResponse); @@ -621,7 +698,10 @@ public class XACMLPAPTest { httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = Mockito.mock(MockHttpServletResponse.class); - json = "{\"dictionaryFields\":{\"scopeName\":\"testMMRestAPI1\",\"description\":\"test\",\"attributes\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\",\"number\":\"test\"}]}}"; + json = + "{\"dictionaryFields\":{\"scopeName\":\"testMMRestAPI1\",\"description\":\"test\"," + + "\"attributes\":[{\"option\":\"test1\",\"number\":\"test\"},{\"option\":\"test2\"," + + "\"number\":\"test\"}]}}"; dictionaryTestSetup(false, "DescriptiveScope", json); // send Request to PAP pap.service(httpServletRequest, httpServletResponse); @@ -639,20 +719,24 @@ public class XACMLPAPTest { httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = Mockito.mock(MockHttpServletResponse.class); - json = "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"message\":\"test\",\"riskType\":\"testMMrestAPI1\"}}"; + json = + "{\"dictionaryFields\":{\"name\":\"testMMrestAPI1\",\"message\":\"test\"," + + "\"riskType\":\"testMMrestAPI1\"}}"; dictionaryTestSetup(false, "SafePolicyWarning", json); // send Request to PAP pap.service(httpServletRequest, httpServletResponse); // Verify Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); } - + @Test public void testDecisionCreateDictionary() throws IOException, SQLException, ServletException { new DecisionPolicyDictionaryController(commonClassDao); httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = Mockito.mock(MockHttpServletResponse.class); - String json = "{\"dictionaryFields\":{\"xacmlId\":\"testMMRestAPI1\",\"datatypeBean\":{\"shortName\":\"string\"},\"description\":\"test\",\"priority\":\"High\"}}"; + String json = + "{\"dictionaryFields\":{\"xacmlId\":\"testMMRestAPI1\",\"datatypeBean\":{\"shortName\":\"string\"}," + + "\"description\":\"test\",\"priority\":\"High\"}}"; dictionaryTestSetup(false, "Settings", json); // send Request to PAP pap.service(httpServletRequest, httpServletResponse); @@ -661,14 +745,16 @@ public class XACMLPAPTest { httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = Mockito.mock(MockHttpServletResponse.class); - json = "{\"dictionaryFields\":{\"bbid\":\"BB1\",\"workstep\":\"1\",\"treatments\":\"Manual Handling,Abort,Retry\"}}"; + json = + "{\"dictionaryFields\":{\"bbid\":\"BB1\",\"workstep\":\"1\",\"treatments\":\"Manual Handling,Abort," + + "Retry\"}}"; dictionaryTestSetup(false, "RainyDayTreatments", json); // send Request to PAP pap.service(httpServletRequest, httpServletResponse); // Verify Mockito.verify(httpServletResponse).setStatus(HttpServletResponse.SC_OK); } - + @Test public void testMSCreateDictionary() throws IOException, SQLException, ServletException { new MicroServiceDictionaryController(commonClassDao); @@ -738,22 +824,26 @@ public class XACMLPAPTest { httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = Mockito.mock(MockHttpServletResponse.class); - json = "{\"dictionaryFields\":{\"groupName\":\"testMMrestAPI1\",\"description\":\"testing\"},\"groupPolicyScopeListData1\":{\"resource\":\"ANY\",\"type\":\"ANY\",\"service\":\"ANY\",\"closedloop\":\"ANY\"}}"; + json = + "{\"dictionaryFields\":{\"groupName\":\"testMMrestAPI1\",\"description\":\"testing\"}," + + "\"groupPolicyScopeListData1\":{\"resource\":\"ANY\",\"type\":\"ANY\",\"service\":\"ANY\"," + + "\"closedloop\":\"ANY\"}}"; dictionaryTestSetup(false, "GroupPolicyScopeList", 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 { + + 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){ + if (updateFlag) { Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("update"); - }else{ + } else { Mockito.when(httpServletRequest.getParameter("operation")).thenReturn("create"); } Mockito.when(httpServletRequest.getParameter("dictionaryType")).thenReturn(dictionaryType); @@ -789,15 +879,15 @@ public class XACMLPAPTest { } @Test - public void getDictionary() throws ServletException, IOException{ - String[] dictionarys = new String[]{"Attribute", "OnapName", "Action", "BRMSParamTemplate","VSCLAction" - ,"VNFType","PEPOptions","Varbind","Service","Site", "Settings", "RainyDayTreatments", + public void getDictionary() throws ServletException, IOException { + String[] dictionarys = new String[]{"Attribute", "OnapName", "Action", "BRMSParamTemplate", "VSCLAction" + , "VNFType", "PEPOptions", "Varbind", "Service", "Site", "Settings", "RainyDayTreatments", "DescriptiveScope", "ActionList", "ProtocolList", "Zone", "SecurityZone", "PrefixList", "AddressGroup", "ServiceGroup", "ServiceList", "TermList", "MicroServiceLocation", "MicroServiceConfigName", "DCAEUUID", "MicroServiceModels", "PolicyScopeService", "PolicyScopeResource", "PolicyScopeType", "PolicyScopeClosedLoop", "GroupPolicyScopeList", "RiskType", "SafePolicyWarning", "MicroServiceDictionary"}; - for(String dictionary : dictionarys){ + for (String dictionary : dictionarys) { httpServletRequest = Mockito.mock(HttpServletRequest.class); httpServletResponse = new MockHttpServletResponse(); Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn("DEVL"); @@ -808,7 +898,7 @@ public class XACMLPAPTest { assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus()); } } - + @Test public void testDummy() throws ServletException, IOException { @@ -828,10 +918,10 @@ public class XACMLPAPTest { fail(); } } - + @After - public void destroy(){ - if(sessionFactory!=null){ + public void destroy() { + if (sessionFactory != null) { sessionFactory.close(); } pap.destroy(); diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ActionPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ActionPolicyService.java index 66920e0db..5016e0690 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ActionPolicyService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ActionPolicyService.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. @@ -30,76 +30,79 @@ import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.std.pap.StdPAPPolicy; /** - * Action Policy Implementation. - * + * Action Policy Implementation. + * * @version 0.1 */ public class ActionPolicyService { - private static final Logger LOGGER = FlexLogger.getLogger(ActionPolicyService.class.getName()); - private PAPServices papServices = null; - - private PolicyParameters policyParameters = null; - private String message = null; - private String policyName = null; - private String policyScope = null; - private Map componentAttributes = null; - private String actionAttribute = null; - private String actionPerformer = null; - - public ActionPolicyService(String policyScope, String policyName, - PolicyParameters policyParameters) { - this.policyParameters = policyParameters; - this.policyName = policyName; - this.policyScope = policyScope; - papServices = new PAPServices(); - } + private static final Logger LOGGER = FlexLogger.getLogger(ActionPolicyService.class.getName()); + private PAPServices papServices = null; - public Boolean getValidation() { - if(policyParameters.getAttributes()==null || policyParameters.getAttributes().isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Component Attributes given."; - return false; - } - componentAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING); - if (componentAttributes==null||componentAttributes.isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Component Attributes given."; - return false; - } - actionAttribute = policyParameters.getActionAttribute(); - if (actionAttribute==null||actionAttribute.trim().isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Action Attribute given."; - return false; - } - actionPerformer = policyParameters.getActionPerformer(); - if (actionPerformer==null||actionPerformer.trim().isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Action Performer given."; - return false; - } - if(!"PEP".equalsIgnoreCase(actionPerformer)&& !"PDP".equalsIgnoreCase(actionPerformer)){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Action Performer given."; - return false; - } - return true; - } + private PolicyParameters policyParameters = null; + private String message = null; + private String policyName = null; + private String policyScope = null; + private Map componentAttributes = null; + private String actionAttribute = null; + private String actionPerformer = null; - public String getMessage() { - return message; - } + public ActionPolicyService(String policyScope, String policyName, + PolicyParameters policyParameters) { + this.policyParameters = policyParameters; + this.policyName = policyName; + this.policyScope = policyScope; + papServices = new PAPServices(); + } - public String getResult(boolean updateFlag) throws PolicyException { - String response = null; - String operation = null; - if (updateFlag){ - operation = "update"; - } else { - operation = "create"; - } - // Create Policy - StdPAPPolicy newPAPPolicy = new StdPAPPolicy(policyName, policyParameters.getPolicyDescription(), - componentAttributes, policyParameters.getDynamicRuleAlgorithmLabels(), policyParameters.getDynamicRuleAlgorithmFunctions(), - policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmField2(), actionPerformer, actionAttribute, updateFlag, policyScope, 0); - // send Json to PAP - response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Action"}, policyParameters.getRequestID(), "Action"); - LOGGER.info(response); - return response; - } + public Boolean getValidation() { + if (policyParameters.getAttributes() == null || policyParameters.getAttributes().isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Component Attributes given."; + return false; + } + componentAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING); + if (componentAttributes == null || componentAttributes.isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Component Attributes given."; + return false; + } + actionAttribute = policyParameters.getActionAttribute(); + if (actionAttribute == null || actionAttribute.trim().isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Action Attribute given."; + return false; + } + actionPerformer = policyParameters.getActionPerformer(); + if (actionPerformer == null || actionPerformer.trim().isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Action Performer given."; + return false; + } + if (!"PEP".equalsIgnoreCase(actionPerformer) && !"PDP".equalsIgnoreCase(actionPerformer)) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Action Performer given."; + return false; + } + return true; + } + + public String getMessage() { + return message; + } + + public String getResult(boolean updateFlag) throws PolicyException { + String response = null; + String operation = null; + if (updateFlag) { + operation = "update"; + } else { + operation = "create"; + } + // Create Policy + StdPAPPolicy newPAPPolicy = new StdPAPPolicy(policyName, policyParameters.getPolicyDescription(), + componentAttributes, policyParameters.getDynamicRuleAlgorithmLabels(), + policyParameters.getDynamicRuleAlgorithmFunctions(), + policyParameters.getDynamicRuleAlgorithmField1(), policyParameters.getDynamicRuleAlgorithmField2(), + actionPerformer, actionAttribute, updateFlag, policyScope, 0); + // send Json to PAP + response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api", + "policyType=Action"}, policyParameters.getRequestID(), "Action"); + LOGGER.info(response); + return response; + } } diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyService.java index dd2bd452e..29b181238 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/BRMSParamPolicyService.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. @@ -31,66 +31,68 @@ import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.std.pap.StdPAPPolicy; /** - * BRMS Param Policy Implementation. - * + * BRMS Param Policy Implementation. + * * @version 0.1 */ -public class BRMSParamPolicyService{ - private static final Logger LOGGER = FlexLogger.getLogger(BRMSParamPolicyService.class.getName()); - private PAPServices papServices = null; - - private PolicyParameters policyParameters = null; - private String message = null; - private String policyName = null; - private String policyScope = null; - private String date = null; - private Map> drlRuleAndUIParams = null; - - public BRMSParamPolicyService(String policyName, String policyScope, - PolicyParameters policyParameters, String date) { - this.policyParameters = policyParameters; - this.policyName = policyName; - this.policyScope = policyScope; - this.date = date; - papServices = new PAPServices(); - } +public class BRMSParamPolicyService { + private static final Logger LOGGER = FlexLogger.getLogger(BRMSParamPolicyService.class.getName()); + private PAPServices papServices = null; - public Boolean getValidation() { - boolean levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); - if(!levelCheck){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; - return false; - } - drlRuleAndUIParams = policyParameters.getAttributes(); - if(drlRuleAndUIParams==null || drlRuleAndUIParams.isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Rule Attributes given."; - return false; - } - return true; - } + private PolicyParameters policyParameters = null; + private String message = null; + private String policyName = null; + private String policyScope = null; + private String date = null; + private Map> drlRuleAndUIParams = null; - public String getMessage() { - return message; - } + public BRMSParamPolicyService(String policyName, String policyScope, + PolicyParameters policyParameters, String date) { + this.policyParameters = policyParameters; + this.policyName = policyName; + this.policyScope = policyScope; + this.date = date; + papServices = new PAPServices(); + } - public String getResult(boolean updateFlag) throws PolicyException { - String response = null; - String operation = null; - if (updateFlag){ - operation = "update"; - } else { - operation = "create"; - } - // Create Policy - StdPAPPolicy newPAPPolicy = new StdPAPPolicy("BRMS_Param",policyName, policyParameters.getPolicyDescription(), - "BRMS_PARAM_RULE",updateFlag,policyScope, - drlRuleAndUIParams.get(AttributeType.MATCHING), 0, "DROOLS", - null, drlRuleAndUIParams.get(AttributeType.RULE), policyParameters.getRiskLevel(), - policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date, policyParameters.getControllerName(), policyParameters.getDependencyNames()); - // Send JSON to PAP - response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, policyParameters.getRequestID(), "ConfigBrmsParam"); - LOGGER.info(response); - return response; - } + public Boolean getValidation() { + boolean levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); + if (!levelCheck) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + return false; + } + drlRuleAndUIParams = policyParameters.getAttributes(); + if (drlRuleAndUIParams == null || drlRuleAndUIParams.isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Rule Attributes given."; + return false; + } + return true; + } + + public String getMessage() { + return message; + } + + public String getResult(boolean updateFlag) throws PolicyException { + String response = null; + String operation = null; + if (updateFlag) { + operation = "update"; + } else { + operation = "create"; + } + // Create Policy + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("BRMS_Param", policyName, policyParameters.getPolicyDescription(), + "BRMS_PARAM_RULE", updateFlag, policyScope, + drlRuleAndUIParams.get(AttributeType.MATCHING), 0, "DROOLS", + null, drlRuleAndUIParams.get(AttributeType.RULE), policyParameters.getRiskLevel(), + policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date, + policyParameters.getControllerName(), policyParameters.getDependencyNames()); + // Send JSON to PAP + response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api", + "policyType=Config"}, policyParameters.getRequestID(), "ConfigBrmsParam"); + LOGGER.info(response); + return response; + } } \ No newline at end of file diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyService.java index ea17529ba..df3f0356f 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/BRMSRawPolicyService.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. @@ -32,75 +32,77 @@ import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.std.pap.StdPAPPolicy; /** - * BRMS RAW Policy Implementation. - * + * BRMS RAW Policy Implementation. + * * @version 0.1 */ -public class BRMSRawPolicyService{ - private static Logger LOGGER = FlexLogger.getLogger(BRMSRawPolicyService.class.getName()); - private static PAPServices papServices = null; - - private PolicyParameters policyParameters = null; - private String message = null; - private String policyName = null; - private String policyScope = null; - private String date = null; - private boolean levelCheck = false; - private String brmsRawBody = null; - - public BRMSRawPolicyService(String policyName, String policyScope, - PolicyParameters policyParameters, String date) { - this.policyParameters = policyParameters; - this.policyName = policyName; - this.policyScope = policyScope; - this.date = date; - papServices = new PAPServices(); - } +public class BRMSRawPolicyService { + private static Logger LOGGER = FlexLogger.getLogger(BRMSRawPolicyService.class.getName()); + private static PAPServices papServices = null; - public Boolean getValidation() { - brmsRawBody = policyParameters.getConfigBody(); - if(brmsRawBody==null || brmsRawBody.trim().isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " No Rule Body given"; - return false; - } - message = PolicyUtils.brmsRawValidate(brmsRawBody); - if(message.contains("[ERR")){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Raw rule given is invalid" +message; - return false; - } - levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); - if(!levelCheck){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; - return false; - } - return true; - } + private PolicyParameters policyParameters = null; + private String message = null; + private String policyName = null; + private String policyScope = null; + private String date = null; + private boolean levelCheck = false; + private String brmsRawBody = null; - public String getMessage() { - return message; - } + public BRMSRawPolicyService(String policyName, String policyScope, + PolicyParameters policyParameters, String date) { + this.policyParameters = policyParameters; + this.policyName = policyName; + this.policyScope = policyScope; + this.date = date; + papServices = new PAPServices(); + } - public String getResult(boolean updateFlag) throws PolicyException { - String response = null; - String operation = null; - if (updateFlag){ - operation = "update"; - } else { - operation = "create"; - } - Map ruleAttributes = null; - if(policyParameters.getAttributes()!=null){ - ruleAttributes = policyParameters.getAttributes().get(AttributeType.RULE); - } - // Create Policy - StdPAPPolicy newPAPPolicy = new StdPAPPolicy("BRMS_Raw",policyName,policyParameters.getPolicyDescription(), - "BRMS_RAW_RULE",updateFlag,policyScope, ruleAttributes, 0, "DROOLS", - brmsRawBody, policyParameters.getRiskLevel(), - policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date, policyParameters.getControllerName(), policyParameters.getDependencyNames()); - // Send JSON to PAP - response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, policyParameters.getRequestID(), "ConfigBrmsRaw"); - LOGGER.info(response); - return response; - } + public Boolean getValidation() { + brmsRawBody = policyParameters.getConfigBody(); + if (brmsRawBody == null || brmsRawBody.trim().isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + " No Rule Body given"; + return false; + } + message = PolicyUtils.brmsRawValidate(brmsRawBody); + if (message.contains("[ERR")) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Raw rule given is invalid" + message; + return false; + } + levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); + if (!levelCheck) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + return false; + } + return true; + } + + public String getMessage() { + return message; + } + + public String getResult(boolean updateFlag) throws PolicyException { + String response = null; + String operation = null; + if (updateFlag) { + operation = "update"; + } else { + operation = "create"; + } + Map ruleAttributes = null; + if (policyParameters.getAttributes() != null) { + ruleAttributes = policyParameters.getAttributes().get(AttributeType.RULE); + } + // Create Policy + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("BRMS_Raw", policyName, policyParameters.getPolicyDescription(), + "BRMS_RAW_RULE", updateFlag, policyScope, ruleAttributes, 0, "DROOLS", + brmsRawBody, policyParameters.getRiskLevel(), + policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date, + policyParameters.getControllerName(), policyParameters.getDependencyNames()); + // Send JSON to PAP + response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api", + "policyType=Config"}, policyParameters.getRequestID(), "ConfigBrmsRaw"); + LOGGER.info(response); + return response; + } } diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyService.java index 5817d7410..6879b6e2f 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ClosedLoopFaultPolicyService.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. @@ -31,91 +31,97 @@ import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.std.pap.StdPAPPolicy; /** - * Closed Loop Fault Policy Implementation. - * - * @version 0.1 + * Closed Loop Fault Policy Implementation. + * + * @version 0.1 */ -public class ClosedLoopFaultPolicyService{ - private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopFaultPolicyService.class.getName()); - private PAPServices papServices = null; - - private PolicyParameters policyParameters = null; - private String message = null; - private String policyName = null; - private String policyScope = null; - private String date = null; - private JsonObject configBody = null; - - public ClosedLoopFaultPolicyService(String policyName, String policyScope, - PolicyParameters policyParameters, String date) { - this.policyParameters = policyParameters; - this.policyName = policyName; - this.policyScope = policyScope; - this.date = date; - papServices = new PAPServices(); - } +public class ClosedLoopFaultPolicyService { + private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopFaultPolicyService.class.getName()); + private PAPServices papServices = null; - public Boolean getValidation() { - if(policyParameters.getConfigBody()==null){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " No Config Body Present"; - return false; - } - if(!PolicyApiUtils.validateNONASCIICharactersAndAllowSpaces(policyParameters.getConfigBody())){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); - return false; - } - try{ - configBody = PolicyApiUtils.stringToJsonObject(policyParameters.getConfigBody()); - } catch(JsonException| IllegalStateException e){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); - LOGGER.error("Json Parse Exception.", e); - return false; - } - return true; - } + private PolicyParameters policyParameters = null; + private String message = null; + private String policyName = null; + private String policyScope = null; + private String date = null; + private JsonObject configBody = null; - public String getMessage() { - return message; - } + public ClosedLoopFaultPolicyService(String policyName, String policyScope, + PolicyParameters policyParameters, String date) { + this.policyParameters = policyParameters; + this.policyName = policyName; + this.policyScope = policyScope; + this.date = date; + papServices = new PAPServices(); + } - public String getResult(boolean updateFlag) throws PolicyException { - String response = null; - String operation = null; - String oldPolicyName = null; - if (updateFlag){ - operation = "update"; - if (policyName.endsWith("_Draft")) { - oldPolicyName = policyName + "_Draft.1"; - } - } else { - operation = "create"; - } - // get values and attributes from the JsonObject - if(!configBody.containsKey("onapname")){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given."; - LOGGER.error(message); - return message; - } - String onapName = configBody.get("onapname").toString().trim().replace("\"", ""); - if (onapName==null||onapName.trim().isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given."; - LOGGER.error(message); - return message; - } - boolean levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); - if (!levelCheck){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; - LOGGER.error(message); - return message; - } - String jsonBody = configBody.toString(); - // Create Policy. - StdPAPPolicy newPAPPolicy = new StdPAPPolicy("ClosedLoop_Fault", policyName, policyParameters.getPolicyDescription(), onapName, - jsonBody, false, oldPolicyName, null, updateFlag, policyScope, 0, policyParameters.getRiskLevel(), - policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date); - //send JSON object to PAP - response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, policyParameters.getRequestID(), "ConfigClosedLoop"); - return response; - } + public Boolean getValidation() { + if (policyParameters.getConfigBody() == null) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + " No Config Body Present"; + return false; + } + if (!PolicyApiUtils.validateNONASCIICharactersAndAllowSpaces(policyParameters.getConfigBody())) { + message = + XACMLErrorConstants.ERROR_DATA_ISSUE + " improper JSON object : " + + policyParameters.getConfigBody(); + return false; + } + try { + configBody = PolicyApiUtils.stringToJsonObject(policyParameters.getConfigBody()); + } catch (JsonException | IllegalStateException e) { + message = + XACMLErrorConstants.ERROR_DATA_ISSUE + " improper JSON object : " + + policyParameters.getConfigBody(); + LOGGER.error("Json Parse Exception.", e); + return false; + } + return true; + } + + public String getMessage() { + return message; + } + + public String getResult(boolean updateFlag) throws PolicyException { + String response = null; + String operation = null; + String oldPolicyName = null; + if (updateFlag) { + operation = "update"; + if (policyName.endsWith("_Draft")) { + oldPolicyName = policyName + "_Draft.1"; + } + } else { + operation = "create"; + } + // get values and attributes from the JsonObject + if (!configBody.containsKey("onapname")) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given."; + LOGGER.error(message); + return message; + } + String onapName = configBody.get("onapname").toString().trim().replace("\"", ""); + if (onapName == null || onapName.trim().isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given."; + LOGGER.error(message); + return message; + } + boolean levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); + if (!levelCheck) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + LOGGER.error(message); + return message; + } + String jsonBody = configBody.toString(); + // Create Policy. + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("ClosedLoop_Fault", policyName, + policyParameters.getPolicyDescription(), onapName, + jsonBody, false, oldPolicyName, null, updateFlag, policyScope, 0, policyParameters.getRiskLevel(), + policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date); + //send JSON object to PAP + response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api", + "policyType=Config"}, policyParameters.getRequestID(), "ConfigClosedLoop"); + return response; + } } diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyService.java index 74c4bd71d..3f0416492 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ClosedLoopPMPolicyService.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. @@ -31,92 +31,98 @@ import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.std.pap.StdPAPPolicy; /** - * Closed Loop PM policy Implementation. - * + * Closed Loop PM policy Implementation. + * * @version 0.1 */ -public class ClosedLoopPMPolicyService{ - private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopPMPolicyService.class.getName()); - - private PAPServices papServices = null; - private PolicyParameters policyParameters = null; - private String message = null; - private String policyName = null; - private String policyScope = null; - private String date = null; - private JsonObject configBody = null; - - public ClosedLoopPMPolicyService(String policyName, String policyScope, - PolicyParameters policyParameters, String date) { - this.policyParameters = policyParameters; - this.policyName = policyName; - this.policyScope = policyScope; - this.date = date; - papServices = new PAPServices(); - } +public class ClosedLoopPMPolicyService { + private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopPMPolicyService.class.getName()); - public Boolean getValidation() { - if(policyParameters.getConfigBody()==null){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " No Config Body Present"; - return false; - } - if(!PolicyApiUtils.validateNONASCIICharactersAndAllowSpaces(policyParameters.getConfigBody())){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); - return false; - } - try{ - configBody = PolicyApiUtils.stringToJsonObject(policyParameters.getConfigBody()); - } catch(JsonException| IllegalStateException e){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); - LOGGER.error("Error during parsing JSON config body for Closed loop PM policy " , e); - return false; - } - return true; - } + private PAPServices papServices = null; + private PolicyParameters policyParameters = null; + private String message = null; + private String policyName = null; + private String policyScope = null; + private String date = null; + private JsonObject configBody = null; - public String getMessage() { - return message; - } + public ClosedLoopPMPolicyService(String policyName, String policyScope, + PolicyParameters policyParameters, String date) { + this.policyParameters = policyParameters; + this.policyName = policyName; + this.policyScope = policyScope; + this.date = date; + papServices = new PAPServices(); + } - public String getResult(boolean updateFlag) throws PolicyException{ - String response = null; - String operation = null; - if (updateFlag){ - operation = "update"; - } else { - operation = "create"; - } - // get values and attributes from the JsonObject - if(!configBody.containsKey("onapname")){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given."; - LOGGER.error(message); - return message; - } - if(!configBody.containsKey("serviceTypePolicyName")){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Service Type Policy Name given."; - LOGGER.error(message); - return message; - } - String onapName = configBody.get("onapname").toString().trim().replace("\"", ""); - if (onapName==null||onapName.trim().isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given."; - LOGGER.error(message); - return message; - } - boolean levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); - if (!levelCheck){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; - LOGGER.error(message); - return message; - } - String jsonBody = configBody.toString(); - String serviceType = configBody.get("serviceTypePolicyName").toString().replace("\"", ""); - // Create Policy. - StdPAPPolicy newPAPPolicy = new StdPAPPolicy("ClosedLoop_PM", policyName, policyParameters.getPolicyDescription(), onapName, - jsonBody, false, null, serviceType, updateFlag, policyScope, 0, policyParameters.getRiskLevel(), - policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date); - //send JSON object to PAP - response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, policyParameters.getRequestID(), "ConfigClosedLoop"); - return response; - } + public Boolean getValidation() { + if (policyParameters.getConfigBody() == null) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + " No Config Body Present"; + return false; + } + if (!PolicyApiUtils.validateNONASCIICharactersAndAllowSpaces(policyParameters.getConfigBody())) { + message = + XACMLErrorConstants.ERROR_DATA_ISSUE + " improper JSON object : " + + policyParameters.getConfigBody(); + return false; + } + try { + configBody = PolicyApiUtils.stringToJsonObject(policyParameters.getConfigBody()); + } catch (JsonException | IllegalStateException e) { + message = + XACMLErrorConstants.ERROR_DATA_ISSUE + " improper JSON object : " + + policyParameters.getConfigBody(); + LOGGER.error("Error during parsing JSON config body for Closed loop PM policy ", e); + return false; + } + return true; + } + + public String getMessage() { + return message; + } + + public String getResult(boolean updateFlag) throws PolicyException { + String response = null; + String operation = null; + if (updateFlag) { + operation = "update"; + } else { + operation = "create"; + } + // get values and attributes from the JsonObject + if (!configBody.containsKey("onapname")) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given."; + LOGGER.error(message); + return message; + } + if (!configBody.containsKey("serviceTypePolicyName")) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Service Type Policy Name given."; + LOGGER.error(message); + return message; + } + String onapName = configBody.get("onapname").toString().trim().replace("\"", ""); + if (onapName == null || onapName.trim().isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given."; + LOGGER.error(message); + return message; + } + boolean levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); + if (!levelCheck) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + LOGGER.error(message); + return message; + } + String jsonBody = configBody.toString(); + String serviceType = configBody.get("serviceTypePolicyName").toString().replace("\"", ""); + // Create Policy. + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("ClosedLoop_PM", policyName, + policyParameters.getPolicyDescription(), onapName, + jsonBody, false, null, serviceType, updateFlag, policyScope, 0, policyParameters.getRiskLevel(), + policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date); + //send JSON object to PAP + response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api", + "policyType=Config"}, policyParameters.getRequestID(), "ConfigClosedLoop"); + return response; + } } diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyService.java index 690e94a5e..46f968aac 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/ConfigPolicyService.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. @@ -30,107 +30,124 @@ import org.onap.policy.pdp.rest.api.utils.PolicyApiUtils; import org.onap.policy.utils.PolicyUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.std.pap.StdPAPPolicy; +import org.onap.policy.xacml.std.pap.StdPAPPolicyParams; /** - * Config Base Policy Implementation. - * + * Config Base Policy Implementation. + * * @version 0.1 */ public class ConfigPolicyService { - private static final Logger LOGGER = FlexLogger.getLogger(ConfigPolicyService.class.getName()); - private PAPServices papServices = null; - - private PolicyParameters policyParameters = null; - private String message = null; - private String policyName = null; - private String policyScope = null; - private String date = null; - private String onapName = null; - private String configName = null; - - public ConfigPolicyService(String policyName, String policyScope, - PolicyParameters policyParameters, String date) { - this.policyParameters = policyParameters; - this.policyName = policyName; - this.policyScope = policyScope; - this.date = date; - papServices = new PAPServices(); - } + private static final Logger LOGGER = FlexLogger.getLogger(ConfigPolicyService.class.getName()); + private PAPServices papServices = null; - public Boolean getValidation() { - if(policyParameters.getConfigBody()==null || policyParameters.getConfigBody().trim().isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ "No Config Body given."; - return false; - } - if(policyParameters.getConfigBodyType()==null){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ "No Config Body Type given."; - return false; - } - boolean levelCheck = false; - levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); - if (!levelCheck){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; - return false; - } - onapName = policyParameters.getOnapName(); - configName = policyParameters.getConfigName(); - if(onapName==null || onapName.trim().isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No ONAP Name given."; - return false; - } - if(configName==null || configName.trim().isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Config Name given."; - return false; - } - message = PolicyUtils.policySpecialCharValidator(onapName); - if(!message.contains("success")){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ message; + private PolicyParameters policyParameters = null; + private String message = null; + private String policyName = null; + private String policyScope = null; + private String date = null; + private String onapName = null; + private String configName = null; + + public ConfigPolicyService(String policyName, String policyScope, + PolicyParameters policyParameters, String date) { + this.policyParameters = policyParameters; + this.policyName = policyName; + this.policyScope = policyScope; + this.date = date; + papServices = new PAPServices(); + } + + public Boolean getValidation() { + if (policyParameters.getConfigBody() == null || policyParameters.getConfigBody().trim().isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Config Body given."; + return false; + } + if (policyParameters.getConfigBodyType() == null) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Config Body Type given."; + return false; + } + boolean levelCheck = false; + levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); + if (!levelCheck) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + return false; + } + onapName = policyParameters.getOnapName(); + configName = policyParameters.getConfigName(); + if (onapName == null || onapName.trim().isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No ONAP Name given."; + return false; + } + if (configName == null || configName.trim().isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Config Name given."; + return false; + } + message = PolicyUtils.policySpecialCharValidator(onapName); + if (!message.contains("success")) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + message; return false; } message = PolicyUtils.policySpecialCharValidator(configName); - if(!message.contains("success")){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ message; + if (!message.contains("success")) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + message; return false; } - return true; - } + return true; + } - public String getMessage() { - return message; - } + public String getMessage() { + return message; + } - public String getResult(boolean updateFlag) throws PolicyException { - String response = null; - String operation = null; - if (updateFlag){ - operation = "update"; - } else { - operation = "create"; - } - String configType = policyParameters.getConfigBodyType().toString(); - String body = policyParameters.getConfigBody(); - String configBody = null; - //check body for JSON form and remove single quotes if present - if ("JSON".equalsIgnoreCase(configType)) { - if (body.contains("'")) { - configBody = body.replace("'", "\""); - } else { - configBody = body; - } - } else { - configBody = body; - } - Map configAttributes = null; - if(policyParameters.getAttributes()!=null){ - configAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING); - } - // create Policy. - StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Base", policyName, policyParameters.getPolicyDescription(), onapName, configName, configAttributes, configType, - configBody, updateFlag, policyScope,0, policyParameters.getRiskLevel(),policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date); - // Send Json to PAP. - response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, policyParameters.getRequestID(), "Config"); - LOGGER.info(response); - return response; - } + public String getResult(boolean updateFlag) throws PolicyException { + String response = null; + String operation = null; + if (updateFlag) { + operation = "update"; + } else { + operation = "create"; + } + String configType = policyParameters.getConfigBodyType().toString(); + String body = policyParameters.getConfigBody(); + String configBody = null; + //check body for JSON form and remove single quotes if present + if ("JSON".equalsIgnoreCase(configType)) { + if (body.contains("'")) { + configBody = body.replace("'", "\""); + } else { + configBody = body; + } + } else { + configBody = body; + } + Map configAttributes = null; + if (policyParameters.getAttributes() != null) { + configAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING); + } + // create Policy. + StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder() + .configPolicyType("Base") + .policyName(policyName) + .description(policyParameters.getPolicyDescription()) + .onapName(onapName) + .configName(configName) + .attributes(configAttributes) + .configType(configType) + .configBodyData(configBody) + .editPolicy(updateFlag) + .domain(policyScope) + .highestVersion(0) + .riskLevel(policyParameters.getRiskLevel()) + .riskType(policyParameters.getRiskType()) + .guard(String.valueOf(policyParameters.getGuard())) + .ttlDate(date) + .build()); + // Send Json to PAP. + response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api", + "policyType=Config"}, policyParameters.getRequestID(), "Config"); + LOGGER.info(response); + return response; + } } 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 915e3b30f..7bdf1dc71 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 @@ -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. @@ -31,73 +31,83 @@ import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.std.pap.StdPAPPolicy; /** - * Decision Policy Implementation - * - * @version 0.1 + * Decision Policy Implementation + * + * @version 0.1 */ -public class DecisionPolicyService{ - private static Logger LOGGER = FlexLogger.getLogger(DecisionPolicyService.class.getName()); - private static PAPServices papServices = null; - - private String message = null; - private String policyScope = null; - private String policyName = null; - private PolicyParameters policyParameters = null; - private String onapName = null; - - public DecisionPolicyService(String policyScope, String policyName, - PolicyParameters policyParameters) { - this.policyScope = policyScope; - this.policyName = policyName; - this.policyParameters = policyParameters; - papServices = new PAPServices(); - } +public class DecisionPolicyService { + private static Logger LOGGER = FlexLogger.getLogger(DecisionPolicyService.class.getName()); + private static PAPServices papServices = null; - public Boolean getValidation() { - onapName = policyParameters.getOnapName(); - if (onapName==null||onapName.trim().isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No ONAP Name given."; - return false; - } - return true; - } + private String message = null; + private String policyScope = null; + private String policyName = null; + private PolicyParameters policyParameters = null; + private String onapName = null; - public String getMessage() { - return message; - } + public DecisionPolicyService(String policyScope, String policyName, + PolicyParameters policyParameters) { + this.policyScope = policyScope; + this.policyName = policyName; + this.policyParameters = policyParameters; + papServices = new PAPServices(); + } - public String getResult(boolean updateFlag) throws PolicyException { - String response = null; - String operation = null; - if (updateFlag){ - operation = "update"; - } else { - operation = "create"; - } - RuleProvider ruleProvider = policyParameters.getRuleProvider(); - if (ruleProvider==null) { - ruleProvider = RuleProvider.CUSTOM ; - } - 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); - }else if(policyParameters.getAttributes()!=null && !policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)){ - settingsAttributes = policyParameters.getAttributes().get(AttributeType.SETTINGS); - }else if(policyParameters.getAttributes()!=null && policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && !policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)){ - matchingAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING); - } - // 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); - return response; - } + public Boolean getValidation() { + onapName = policyParameters.getOnapName(); + if (onapName == null || onapName.trim().isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No ONAP Name given."; + return false; + } + return true; + } + + public String getMessage() { + return message; + } + + public String getResult(boolean updateFlag) throws PolicyException { + String response = null; + String operation = null; + if (updateFlag) { + operation = "update"; + } else { + operation = "create"; + } + RuleProvider ruleProvider = policyParameters.getRuleProvider(); + if (ruleProvider == null) { + ruleProvider = RuleProvider.CUSTOM; + } + 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); + } else if (policyParameters.getAttributes() != null && + !policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && + policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)) { + settingsAttributes = policyParameters.getAttributes().get(AttributeType.SETTINGS); + } else if (policyParameters.getAttributes() != null && + policyParameters.getAttributes().containsKey(AttributeType.MATCHING) && + !policyParameters.getAttributes().containsKey(AttributeType.SETTINGS)) { + matchingAttributes = policyParameters.getAttributes().get(AttributeType.MATCHING); + } + // 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); + return response; + } } diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyService.java index 8f4ba9a79..45deeb49f 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/FirewallPolicyService.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. @@ -31,83 +31,88 @@ import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.std.pap.StdPAPPolicy; /** - * Firewall Policy Implementation. - * + * Firewall Policy Implementation. + * * @version 0.1 */ public class FirewallPolicyService { - private static final Logger LOGGER = FlexLogger.getLogger(FirewallPolicyService.class.getName()); - - private PAPServices papServices = null; - private PolicyParameters policyParameters = null; - private String message = null; - private String policyName = null; - private String policyScope = null; - private String date = null; - private JsonObject firewallJson = null; - - public FirewallPolicyService(String policyName, String policyScope, - PolicyParameters policyParameters, String date) { - this.policyParameters = policyParameters; - this.policyName = policyName; - this.policyScope = policyScope; - this.date = date; - papServices = new PAPServices(); - } + private static final Logger LOGGER = FlexLogger.getLogger(FirewallPolicyService.class.getName()); - public Boolean getValidation() { - if(policyParameters.getConfigBody()==null){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ "No Config Body given."; - return false; - } - try{ - firewallJson = PolicyApiUtils.stringToJsonObject(policyParameters.getConfigBody()); - } catch(JsonException| IllegalStateException e){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); - LOGGER.error("Error while parsing JSON body for creating Firewall Policy " , e); - return false; - } - if(firewallJson==null|| firewallJson.isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Config-Body given."; - return false; - } - boolean levelCheck = false; - levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); - if (!levelCheck){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; - return false; - } - return true; - } + private PAPServices papServices = null; + private PolicyParameters policyParameters = null; + private String message = null; + private String policyName = null; + private String policyScope = null; + private String date = null; + private JsonObject firewallJson = null; - public String getMessage() { - return message; - } + public FirewallPolicyService(String policyName, String policyScope, + PolicyParameters policyParameters, String date) { + this.policyParameters = policyParameters; + this.policyName = policyName; + this.policyScope = policyScope; + this.date = date; + papServices = new PAPServices(); + } - public String getResult(boolean updateFlag) throws PolicyException { - String response = null; - String operation = null; - if (updateFlag){ - operation = "update"; - } else { - operation = "create"; - } - //set values for basic policy information - if(!firewallJson.containsKey("configName")){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No configName given in firwall JSON."; - LOGGER.error(message); - return message; - } - String configName = firewallJson.get("configName").toString(); - String configDescription = ""; - String json = firewallJson.toString(); - // Create Policy. - StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Firewall Config", policyName, configDescription, configName, updateFlag, policyScope, json, 0, - policyParameters.getRiskLevel(),policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date); - // Send Json to PAP. - response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, policyParameters.getRequestID(), "ConfigFirewall"); - LOGGER.info(response); - return response; - } + public Boolean getValidation() { + if (policyParameters.getConfigBody() == null) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Config Body given."; + return false; + } + try { + firewallJson = PolicyApiUtils.stringToJsonObject(policyParameters.getConfigBody()); + } catch (JsonException | IllegalStateException e) { + message = + XACMLErrorConstants.ERROR_DATA_ISSUE + " improper JSON object : " + + policyParameters.getConfigBody(); + LOGGER.error("Error while parsing JSON body for creating Firewall Policy ", e); + return false; + } + if (firewallJson == null || firewallJson.isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Config-Body given."; + return false; + } + boolean levelCheck = false; + levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); + if (!levelCheck) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + return false; + } + return true; + } + + public String getMessage() { + return message; + } + + public String getResult(boolean updateFlag) throws PolicyException { + String response = null; + String operation = null; + if (updateFlag) { + operation = "update"; + } else { + operation = "create"; + } + //set values for basic policy information + if (!firewallJson.containsKey("configName")) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No configName given in firwall JSON."; + LOGGER.error(message); + return message; + } + String configName = firewallJson.get("configName").toString(); + String configDescription = ""; + String json = firewallJson.toString(); + // Create Policy. + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Firewall Config", policyName, configDescription, configName, + updateFlag, policyScope, json, 0, + policyParameters.getRiskLevel(), policyParameters.getRiskType(), + String.valueOf(policyParameters.getGuard()), date); + // Send Json to PAP. + response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api", + "policyType=Config"}, policyParameters.getRequestID(), "ConfigFirewall"); + LOGGER.info(response); + return response; + } } diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyService.java index 44740391e..9ca149240 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/MicroServicesPolicyService.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. @@ -31,64 +31,67 @@ import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.std.pap.StdPAPPolicy; /** - * MicroServices Policy implementation. - * + * MicroServices Policy implementation. + * * @version 0.1 */ -public class MicroServicesPolicyService{ - private static final Logger LOGGER = FlexLogger.getLogger(MicroServicesPolicyService.class.getName()); - - private PAPServices papServices = null; - private PolicyParameters policyParameters = null; - private String message = null; - private String policyName = null; - private String policyScope = null; - private String date = null; - private String onapName = null; - private JsonObject microServiceAttributes = null; - - public MicroServicesPolicyService(String policyName, String policyScope, PolicyParameters policyParameters, String date) { - this.policyParameters = policyParameters; - this.policyName = policyName; - this.policyScope = policyScope; - this.date = date; - papServices = new PAPServices(); - } +public class MicroServicesPolicyService { + private static final Logger LOGGER = FlexLogger.getLogger(MicroServicesPolicyService.class.getName()); - public Boolean getValidation() { - if(policyParameters.getConfigBody()==null){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " No Micro Service or Attributes Config Body Present"; - return false; - } - try{ - microServiceAttributes = PolicyApiUtils.stringToJsonObject(policyParameters.getConfigBody()); - } catch(JsonException| IllegalStateException e){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); - LOGGER.error("Error while parsing JSON body for MicroService Policy creation. ", e); - return false; - } - onapName = policyParameters.getOnapName(); - if (onapName==null||onapName.trim().isEmpty()){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given."; - return false; - } - boolean levelCheck = false; - levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); - if (!levelCheck){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; - return false; - } - return true; - } + private PAPServices papServices = null; + private PolicyParameters policyParameters = null; + private String message = null; + private String policyName = null; + private String policyScope = null; + private String date = null; + private String onapName = null; + private JsonObject microServiceAttributes = null; - public String getMessage() { - return message; - } - - public String getResult(boolean updateFlag) throws PolicyException{ - String response = null; + public MicroServicesPolicyService(String policyName, String policyScope, PolicyParameters policyParameters, + String date) { + this.policyParameters = policyParameters; + this.policyName = policyName; + this.policyScope = policyScope; + this.date = date; + papServices = new PAPServices(); + } + + public Boolean getValidation() { + if (policyParameters.getConfigBody() == null) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + " No Micro Service or Attributes Config Body Present"; + return false; + } + try { + microServiceAttributes = PolicyApiUtils.stringToJsonObject(policyParameters.getConfigBody()); + } catch (JsonException | IllegalStateException e) { + message = + XACMLErrorConstants.ERROR_DATA_ISSUE + " improper JSON object : " + + policyParameters.getConfigBody(); + LOGGER.error("Error while parsing JSON body for MicroService Policy creation. ", e); + return false; + } + onapName = policyParameters.getOnapName(); + if (onapName == null || onapName.trim().isEmpty()) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Onap Name given."; + return false; + } + boolean levelCheck = false; + levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel()); + if (!levelCheck) { + message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given."; + return false; + } + return true; + } + + public String getMessage() { + return message; + } + + public String getResult(boolean updateFlag) throws PolicyException { + String response = null; String operation = null; - if (updateFlag){ + if (updateFlag) { operation = "update"; } else { operation = "create"; @@ -98,39 +101,40 @@ public class MicroServicesPolicyService{ String msLocation = null; String configName = null; String microService = null; - String policyDescription=null; - String priority=null; - String version=null; - - if (microServiceAttributes.get("service")!=null){ - microService = microServiceAttributes.get("service").toString().replace("\"", ""); + String policyDescription = null; + String priority = null; + String version = null; + + if (microServiceAttributes.get("service") != null) { + microService = microServiceAttributes.get("service").toString().replace("\"", ""); } - if (microServiceAttributes.get("uuid")!=null){ + if (microServiceAttributes.get("uuid") != null) { uuid = microServiceAttributes.get("uuid").toString().replace("\"", ""); } - if (microServiceAttributes.get("location")!=null){ + if (microServiceAttributes.get("location") != null) { msLocation = microServiceAttributes.get("location").toString().replace("\"", ""); } - if (microServiceAttributes.get("configName")!=null){ + if (microServiceAttributes.get("configName") != null) { configName = microServiceAttributes.get("configName").toString().replace("\"", ""); } - if(microServiceAttributes.containsKey("description")){ - policyDescription = microServiceAttributes.get("description").toString().replace("\"", ""); + if (microServiceAttributes.containsKey("description")) { + policyDescription = microServiceAttributes.get("description").toString().replace("\"", ""); } - if(microServiceAttributes.containsKey("priority")){ - priority = microServiceAttributes.get("priority").toString().replace("\"", ""); + if (microServiceAttributes.containsKey("priority")) { + priority = microServiceAttributes.get("priority").toString().replace("\"", ""); } - if(microServiceAttributes.containsKey("version")){ - version = microServiceAttributes.get("version").toString().replace("\"", ""); + if (microServiceAttributes.containsKey("version")) { + version = microServiceAttributes.get("version").toString().replace("\"", ""); } // Create Policy. - StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Micro Service", policyName, policyDescription, onapName, - configName, microService, uuid, msLocation, microServiceAttributes.toString(), priority, + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Micro Service", policyName, policyDescription, onapName, + configName, microService, uuid, msLocation, microServiceAttributes.toString(), priority, version, updateFlag, policyScope, 0, policyParameters.getRiskLevel(), - policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date); + policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date); // Send JSON Object to PAP. - response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, policyParameters.getRequestID(), "ConfigMS"); + response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api", + "policyType=Config"}, policyParameters.getRequestID(), "ConfigMS"); LOGGER.info("Policy MS created Response: " + response); return response; - } + } } diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyService.java index 61038d955..7df90ed8b 100644 --- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyService.java +++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/OptimizationPolicyService.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. @@ -21,6 +21,7 @@ package org.onap.policy.pdp.rest.api.services; import javax.json.JsonException; import javax.json.JsonObject; + import org.onap.policy.api.PolicyException; import org.onap.policy.api.PolicyParameters; import org.onap.policy.common.logging.flexlogger.FlexLogger; @@ -30,81 +31,85 @@ import org.onap.policy.xacml.api.XACMLErrorConstants; import org.onap.policy.xacml.std.pap.StdPAPPolicy; /** - * Optimization Policy implementation. - * + * Optimization Policy implementation. + * * @version 0.1 */ -public class OptimizationPolicyService{ - private static final Logger LOGGER = FlexLogger.getLogger(OptimizationPolicyService.class.getName()); - - private PAPServices papServices = null; - private PolicyParameters policyParameters = null; - private String message = null; - private String policyName = null; - private String policyScope = null; - private String date = null; +public class OptimizationPolicyService { + private static final Logger LOGGER = FlexLogger.getLogger(OptimizationPolicyService.class.getName()); + + private PAPServices papServices = null; + private PolicyParameters policyParameters = null; + private String message = null; + private String policyName = null; + private String policyScope = null; + private String date = null; + + public OptimizationPolicyService(String policyName, String policyScope, PolicyParameters policyParameters, + String date) { + this.policyParameters = policyParameters; + this.policyName = policyName; + this.policyScope = policyScope; + this.date = date; + papServices = new PAPServices(); + } - public OptimizationPolicyService(String policyName, String policyScope, PolicyParameters policyParameters, String date) { - this.policyParameters = policyParameters; - this.policyName = policyName; - this.policyScope = policyScope; - this.date = date; - papServices = new PAPServices(); - } + public String getMessage() { + return message; + } - public String getMessage() { - return message; - } - - public String getResult(boolean updateFlag) throws PolicyException{ - String response = null; + public String getResult(boolean updateFlag) throws PolicyException { + String response = null; String operation = null; - - if (updateFlag){ + + if (updateFlag) { operation = "update"; } else { operation = "create"; } - + // get values and attributes from the JsonObject String servicModel = null; - String policyDescription=null; - String priority=null; - String version=null; - - String onapName = policyParameters.getOnapName(); - JsonObject optimizationAttributes = null; - try{ - optimizationAttributes = PolicyApiUtils.stringToJsonObject(policyParameters.getConfigBody()); - } catch(JsonException| IllegalStateException e){ - message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody(); - LOGGER.error("Error while parsing JSON body for MicroService Policy creation. ", e); - return null; - } - - if (optimizationAttributes.get("service")!=null){ - servicModel = optimizationAttributes.get("service").toString().replace("\"", ""); + String policyDescription = null; + String priority = null; + String version = null; + + String onapName = policyParameters.getOnapName(); + JsonObject optimizationAttributes = null; + try { + optimizationAttributes = PolicyApiUtils.stringToJsonObject(policyParameters.getConfigBody()); + } catch (JsonException | IllegalStateException e) { + message = + XACMLErrorConstants.ERROR_DATA_ISSUE + " improper JSON object : " + + policyParameters.getConfigBody(); + LOGGER.error("Error while parsing JSON body for MicroService Policy creation. ", e); + return null; + } + + if (optimizationAttributes.get("service") != null) { + servicModel = optimizationAttributes.get("service").toString().replace("\"", ""); } - if(optimizationAttributes.containsKey("description")){ - policyDescription = optimizationAttributes.get("description").toString().replace("\"", ""); + if (optimizationAttributes.containsKey("description")) { + policyDescription = optimizationAttributes.get("description").toString().replace("\"", ""); } - if(optimizationAttributes.containsKey("priority")){ - priority = optimizationAttributes.get("priority").toString().replace("\"", ""); + if (optimizationAttributes.containsKey("priority")) { + priority = optimizationAttributes.get("priority").toString().replace("\"", ""); } - if(optimizationAttributes.containsKey("version")){ - version = optimizationAttributes.get("version").toString().replace("\"", ""); + if (optimizationAttributes.containsKey("version")) { + version = optimizationAttributes.get("version").toString().replace("\"", ""); } - + // Create Policy Object - StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Optimization", policyName, policyDescription, onapName, - null, servicModel, null, null, optimizationAttributes.toString(), priority, + StdPAPPolicy newPAPPolicy = new StdPAPPolicy("Optimization", policyName, policyDescription, onapName, + null, servicModel, null, null, optimizationAttributes.toString(), priority, version, updateFlag, policyScope, 0, policyParameters.getRiskLevel(), - policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date); - + policyParameters.getRiskType(), String.valueOf(policyParameters.getGuard()), date); + // Send JSON Object to PAP - response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation="+operation, "apiflag=api", "policyType=Config"}, - policyParameters.getRequestID(), "ConfigOptimization"); + response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api", + "policyType=Config"}, + policyParameters.getRequestID(), "ConfigOptimization"); LOGGER.info("Response: " + response); return response; - } + } } diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.java index 93fde841d..09014cc3d 100644 --- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.java +++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/services/PAPServicesTest.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. @@ -36,44 +36,47 @@ import org.onap.policy.xacml.std.pap.StdPDPPolicy; public class PAPServicesTest { - PAPServices papServices = null; + PAPServices papServices = null; - @Before - public void setUp() throws Exception { - PAPServices.setJunit(true); - Properties prop = new Properties(); - prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties")); - String succeeded = prop.getProperty("xacml.rest.pap.url"); - List paps = Arrays.asList(succeeded.split(",")); - PAPServices.setPaps(paps); - papServices = new PAPServices(); + @Before + public void setUp() throws Exception { + PAPServices.setJunit(true); + Properties prop = new Properties(); + prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties")); + String succeeded = prop.getProperty("xacml.rest.pap.url"); + List paps = Arrays.asList(succeeded.split(",")); + PAPServices.setPaps(paps); + papServices = new PAPServices(); - } + } - @After - public void tearDown() throws Exception { - PAPServices.setPaps(null); - PAPServices.setJunit(false); - } + @After + public void tearDown() throws Exception { + PAPServices.setPaps(null); + PAPServices.setJunit(false); + } - @Test - public final void testCallPAP() throws PolicyException { - StdPAPPolicy newPAPPolicy = new StdPAPPolicy(); - String response = null; - response = (String) papServices.callPAP(newPAPPolicy, new String[] {"operation=create", "apiflag=api", "policyType=Config"}, UUID.randomUUID(), "Config"); - assertEquals("success",response); - } + @Test + public final void testCallPAP() throws PolicyException { + StdPAPPolicy newPAPPolicy = new StdPAPPolicy(); + String response = null; + response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=create", "apiflag=api", + "policyType=Config"}, UUID.randomUUID(), "Config"); + assertEquals("success", response); + } - @Test - public final void testGetActiveVersion() { - String activeVersion = papServices.getActiveVersion("test", "Config_", "test.testpolicy", "Config", UUID.randomUUID()); - assertNull(activeVersion); - } + @Test + public final void testGetActiveVersion() { + String activeVersion = papServices.getActiveVersion("test", "Config_", "test.testpolicy", "Config", + UUID.randomUUID()); + assertNull(activeVersion); + } - @Test - public final void testPushPolicy() throws PolicyException { - StdPDPPolicy selectedPolicy = papServices.pushPolicy("test", "Config_", "test.testpolicy", "Config", "default", UUID.randomUUID()); + @Test + public final void testPushPolicy() throws PolicyException { + StdPDPPolicy selectedPolicy = papServices.pushPolicy("test", "Config_", "test.testpolicy", "Config", "default" + , UUID.randomUUID()); assertNull(selectedPolicy); - } + } } 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 5974883ee..264b2b784 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 @@ -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. @@ -24,900 +24,924 @@ import java.net.URI; import java.util.HashMap; import java.util.List; import java.util.Map; + import org.onap.policy.xacml.api.pap.OnapPAPPolicy; -public class StdPAPPolicy implements OnapPAPPolicy, Serializable{ - private static final long serialVersionUID = 5260230629397322000L; - - private String policyName = null; - private String oldPolicyFileName = null; - private String policyDescription = null; - 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; - private List dynamicRuleAlgorithmCombo; - private List dynamicRuleAlgorithmField1; - private List dynamicRuleAlgorithmField2; - private transient List dynamicVariableList; - private List dataTypeList; - private String configBodyData = null; - private String policyID = null; - private String ruleID = null; - private String brmsController; - private List brmsDependency; - private String configType = null; - private Boolean editPolicy = false; - private Boolean draft = false; - private String version = null; - private String domain = null; - private String configPolicyType = null; - private String jsonBody = null; - private String serviceType = null; - private Integer highestVersion = null; - private URI location = null; - private String actionPerformer = null; - private String actionAttribute = null; - private String actionBody = null; - private String actionDictHeader = null; - private String actionDictType = null; - private String actionDictUrl = null; - private String actionDictMethod = null; - private String uuid = null; - private String msLocation = null; - private String priority = null; - private transient Map drlRuleAndUIParams=null; - private String deleteCondition = null; - private String dictionaryType = null; - private String dictionary = null; - private String dictionaryFields = null; - private String providerComboBox = null; - private String riskType = null; - private String guard = null; - private String riskLevel; - private String ttlDate = null; - - - public StdPAPPolicy() { - // - // Default empty constructor - // - } - - //Constructor for sending location when pushing policies - public StdPAPPolicy(URI location) { - this.location = location; - } - - //Constructor for Validating Config Policies - public StdPAPPolicy(String policyName, String body, String configType, String configPolicyType) { - this.policyName = policyName; - this.configBodyData = body; - this.configType = configType; - this.configPolicyType = configPolicyType; - } - - //convenience constructor - public StdPAPPolicy(String configPolicyType, String policyName, String description, String onapName, String configName, Map attributes, String configType, - String body, Boolean editPolicy, String domain, String riskLevel, String riskType, String guard, String ttlDate){ - this(configPolicyType, policyName, description, onapName, configName, attributes, configType, - body, editPolicy, domain, 1, riskLevel, riskType, guard, ttlDate); - } - - //Constructor for Create/Update Action Policies from API - public StdPAPPolicy(String policyName, String description, Map attributes, List dynamicRuleAlgorithmLabels, List dynamicRuleAlgorithmCombo, - List dynamicRuleAlgorithmField1, List dynamicRuleAlgorithmField2, String actionPerformer,String actionAttribute, Boolean editPolicy, - String domain, int highestVersion) { - - this.policyName = policyName; - this.policyDescription = description; - this.dyanamicFieldConfigAttributes = attributes; - this.dynamicRuleAlgorithmLabels = dynamicRuleAlgorithmLabels; - this.dynamicRuleAlgorithmCombo = dynamicRuleAlgorithmCombo; - this.dynamicRuleAlgorithmField1 = dynamicRuleAlgorithmField1; - this.dynamicRuleAlgorithmField2 = dynamicRuleAlgorithmField2; - this.actionPerformer = actionPerformer; - this.actionAttribute = actionAttribute; - this.editPolicy = editPolicy; - this.domain = domain; - this.highestVersion = highestVersion; - - } - - //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) { - - this.policyName = policyName; - this.policyDescription = description; - this.onapName = onapName; - this.setProviderComboBox(providerComboBox); - this.dyanamicFieldConfigAttributes = attributes; - this.dynamicSettingsMap = settings; - this.dynamicRuleAlgorithmLabels = dynamicRuleAlgorithmLabels; - this.dynamicRuleAlgorithmCombo = dynamicRuleAlgorithmCombo; - this.dynamicRuleAlgorithmField1 = dynamicRuleAlgorithmField1; - this.dynamicRuleAlgorithmField2 = dynamicRuleAlgorithmField2; - this.dynamicVariableList = dynamicVariableList; - this.dataTypeList = dataTypeList; - this.dropDownMap = dropDownMap; - 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, - String body, Boolean editPolicy, String domain, int highestVersion, String riskLevel, String riskType, String guard, String ttlDate) { - - this.configPolicyType = configPolicyType; - this.policyName = policyName; - this.policyDescription = description; - this.onapName = onapName; - this.configName = configName; - this.dyanamicFieldConfigAttributes = attributes; - this.configType = configType; - this.configBodyData = body; - this.editPolicy = editPolicy; - this.domain = domain; - this.highestVersion = highestVersion; - this.riskLevel = riskLevel; - this.riskType = riskType; - this.guard = guard; - this.ttlDate = ttlDate; - } - - //convenience constructor - public StdPAPPolicy (String configPolicyType, String policyName, String description, String onapName, String configName, Map attributes, String body, String policyID, - String ruleID, String configType, Boolean editPolicy, String version, String domain, String riskLevel, String riskType, String guard, String ttlDate) { - this (configPolicyType, policyName, description, onapName, configName, attributes, body, policyID, - ruleID, configType, editPolicy, version, domain, 1, riskLevel, riskType, guard, ttlDate); - } - - //Constructor for Updating Config Policies from Admin Console - public StdPAPPolicy (String configPolicyType, String policyName, String description, String onapName, String configName, Map attributes, String body, String policyID, - String ruleID, String configType, Boolean editPolicy, String version, String domain, int highestVersion, String riskLevel, String riskType, String guard, String ttlDate) { - - this.configPolicyType = configPolicyType; - this.policyName = policyName; - this.policyDescription = description; - this.onapName = onapName; - this.configName = configName; - this.dyanamicFieldConfigAttributes = attributes; - this.configBodyData = body; - this.policyID = policyID; - this.ruleID = ruleID; - this.configType = configType; - this.editPolicy = editPolicy; - this.version = version; - this.domain = domain; - this.highestVersion = highestVersion; - this.riskLevel = riskLevel; - this.riskType = riskType; - this.guard = guard; - this.ttlDate = ttlDate; - } - - - //Constructor for Creating Config Firewall Policies - public StdPAPPolicy (String configPolicyType, String policyName, String description, String configName, - Boolean editPolicy, String domain, String jsonBody, Integer highestVersion, String riskLevel, String riskType, String guard, String ttlDate) { - - this.configPolicyType = configPolicyType; - this.policyName = policyName; - this.policyDescription = description; - this.configName = configName; - this.editPolicy = editPolicy; - this.domain = domain; - this.jsonBody = jsonBody; - this.highestVersion = highestVersion; - this.riskLevel = riskLevel; - this.riskType = riskType; - this.guard = guard; - this.ttlDate = ttlDate; - - } - - //Constructor for Creating Goc Policies - public StdPAPPolicy (String configPolicyType, String policyName, String description, String configName, - Boolean editPolicy, String domain, String jsonBody, Integer highestVersion, String eCompName, String riskLevel, String riskType, String guard, String ttlDate) { - - this.configPolicyType = configPolicyType; - this.policyName = policyName; - this.policyDescription = description; - this.configName = configName; - this.editPolicy = editPolicy; - this.domain = domain; - this.jsonBody = jsonBody; - this.highestVersion = highestVersion; - this.onapName=eCompName; - this.riskLevel = riskLevel; - this.riskType = riskType; - this.guard = guard; - this.ttlDate = ttlDate; - } - - //Constructor for Creating BRMS Policies from the Admin Console - public StdPAPPolicy (String configPolicyType, String policyName, String description, - String configName, Boolean editPolicy, String domain, - Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, - String configBodyData, String riskLevel, String riskType, String guard, String ttlDate, String brmsController, List brmsDependency) { - - this.configPolicyType = configPolicyType; - this.policyName = policyName; - this.policyDescription = description; - this.configName = configName; - this.editPolicy = editPolicy; - this.domain = domain; - this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; - this.highestVersion = highestVersion; - this.onapName=eCompName; - this.configBodyData=configBodyData; - this.riskLevel = riskLevel; - this.riskType = riskType; - this.guard = guard; - this.ttlDate = ttlDate; - this.brmsController = brmsController; - this.brmsDependency = brmsDependency; - } - - //Constructor for Creating BRMS Param Policies from the Admin Console - public StdPAPPolicy (String configPolicyType, String policyName, String description, - String configName, Boolean editPolicy, String domain, - Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, - String configBodyData,Map drlRuleAndUIParams, String riskLevel, String riskType, String guard, String ttlDate, String brmsController, List brmsDependency) { - - this.configPolicyType = configPolicyType; - this.policyName = policyName; - this.policyDescription = description; - this.configName = configName; - this.editPolicy = editPolicy; - this.domain = domain; - this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; - this.highestVersion = highestVersion; - this.onapName=eCompName; - this.configBodyData=configBodyData; - this.drlRuleAndUIParams=drlRuleAndUIParams; - this.riskLevel = riskLevel; - this.riskType = riskType; - this.guard = guard; - this.ttlDate = ttlDate; - this.brmsController = brmsController; - this.brmsDependency = brmsDependency; - } - - //Constructor for Creating CloseLoop_Fault and Performance Metric Policies - public StdPAPPolicy (String configPolicyType, String policyName, String description, String onapName, - String jsonBody, Boolean draft, String oldPolicyFileName, String serviceType, Boolean editPolicy, - String domain, Integer highestVersion, String riskLevel, String riskType, String guard, String ttlDate) { - - this.configPolicyType = configPolicyType; - this.policyName = policyName; - this.policyDescription = description; - this.onapName = onapName; - this.jsonBody = jsonBody; - this.draft = draft; - this.oldPolicyFileName = oldPolicyFileName; - this.serviceType = serviceType; - this.editPolicy = editPolicy; - this.domain = domain; - this.highestVersion = highestVersion; - this.riskLevel = riskLevel; - this.riskType = riskType; - this.guard = guard; - this.ttlDate = ttlDate; - } - - //Constructor for Updating Config Firewall Policies from the Admin Console - public StdPAPPolicy (String configPolicyType, String policyName, String description, String configName, Boolean editPolicy, String domain, String policyID, - String ruleID, String version, String jsonBody, Integer highestVersion, String riskLevel, String riskType, String guard, String ttlDate) { - - this.configPolicyType = configPolicyType; - this.policyName = policyName; - this.policyDescription = description; - this.configName = configName; - this.editPolicy = editPolicy; - this.domain = domain; - this.policyID = policyID; - this.ruleID = ruleID; - this.version = version; - this.jsonBody = jsonBody; - this.highestVersion = highestVersion; - this.riskLevel = riskLevel; - this.riskType = riskType; - this.guard = guard; - this.ttlDate = ttlDate; - } - - //Constructor for Micro Service Creating/Updating Policies from the Admin Console - public StdPAPPolicy(String configPolicyType, String policyName, String description, String onapName, String configName, String serviceType, String uuid, - String msLocation, String jsonBody, String priority, String version, Boolean editPolicy, String domain, int highestVersion, String riskLevel, - String riskType, String guard, String ttlDate) { - - this.configPolicyType = configPolicyType; - this.policyName = policyName; - this.policyDescription = description; - this.onapName = onapName; - this.configName = configName; - this.serviceType = serviceType; - this.uuid = uuid; - this.msLocation = msLocation; - this.priority = priority; - this.version = version; - this.jsonBody = jsonBody; - this.editPolicy = editPolicy; - this.domain = domain; - this.highestVersion = highestVersion; - this.riskLevel = riskLevel; - this.riskType = riskType; - this.guard = guard; - this.ttlDate = ttlDate; - } - - //Constructor for Updating Goc Policies from the Admin Console - public StdPAPPolicy (String configPolicyType, String policyName, String description, - String configName, Boolean editPolicy, String domain, - String policyID, String ruleID, String version, - String jsonBody, Integer highestVersion, String eCompName,String riskLevel, String riskType, String guard, String ttlDate) { - - this.configPolicyType = configPolicyType; - this.policyName = policyName; - this.policyDescription = description; - this.configName = configName; - this.editPolicy = editPolicy; - this.domain = domain; - this.policyID = policyID; - this.ruleID = ruleID; - this.version = version; - this.jsonBody = jsonBody; - this.highestVersion = highestVersion; - this.onapName=eCompName; - this.riskLevel = riskLevel; - this.riskType = riskType; - this.guard = guard; - this.ttlDate = ttlDate; - } - - //Constructor for Updating Brms Policies from the Admin Console - public StdPAPPolicy (String configPolicyType, String policyName, String description, - String configName, Boolean editPolicy, String domain, - String policyID, String ruleID, String version, - Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, - String configBodyData , String riskLevel, String riskType, String guard, String ttlDate - ) { - this.configPolicyType = configPolicyType; - this.policyName = policyName; - this.policyDescription = description; - this.configName = configName; - this.editPolicy = editPolicy; - this.domain = domain; - this.policyID = policyID; - this.ruleID = ruleID; - this.version = version; - this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; - this.highestVersion = highestVersion; - this.onapName=eCompName; - this.configBodyData=configBodyData; - this.riskLevel = riskLevel; - this.riskType = riskType; - this.guard = guard; - this.ttlDate = ttlDate; - } - - //Constructor for Updating Brms Param Policies from the Admin Console - public StdPAPPolicy (String configPolicyType, String policyName, String description, - String configName, Boolean editPolicy, String domain, - String policyID, String ruleID, String version, - Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, - Map drlRuleAndUIParams, String riskLevel, String riskType, String guard, String ttlDate - ) { - this.configPolicyType = configPolicyType; - this.policyName = policyName; - this.policyDescription = description; - this.configName = configName; - this.editPolicy = editPolicy; - this.domain = domain; - this.policyID = policyID; - this.ruleID = ruleID; - this.version = version; - this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; - this.highestVersion = highestVersion; - this.onapName=eCompName; - this.drlRuleAndUIParams=drlRuleAndUIParams; - this.riskLevel = riskLevel; - this.riskType = riskType; - this.guard = guard; - this.ttlDate = ttlDate; - } - - // Constructor for deleting policies from the API - public StdPAPPolicy(String policyName, String deleteCondition) { - this.policyName = policyName; - this.deleteCondition = deleteCondition; - } - - // Constructor for creating dictionary items from the API> - public StdPAPPolicy(String dictionaryType, String dictionary, String dictionaryFields) { - this.dictionaryType = dictionaryType; - this.dictionary = dictionary; - this.dictionaryFields = dictionaryFields; - } - - @Override - public String getPolicyName() { - return policyName; - } - - @Override - public String getPolicyDescription() { - return policyDescription; - } - - @Override - public String getOnapName() { - return onapName; - } - - @Override - public String getConfigName() { - return configName; - } - - @Override - public Map getDynamicFieldConfigAttributes() { - return dyanamicFieldConfigAttributes; - } - - @Override - public String getConfigBodyData() { - return configBodyData; - } - - @Override - public String getPolicyID() { - return policyID; - } - - @Override - public String getRuleID() { - return ruleID; - } - - @Override - public String getConfigType() { - return configType; - } - - @Override - public Boolean isEditPolicy() { - return editPolicy; - } - - @Override - public Boolean isDraft() { - return draft; - } - - @Override - public String getVersion() { - return version; - } - - @Override - public String getDomainDir() { - return domain; - } - - @Override - public String getConfigPolicyType() { - return configPolicyType; - } - - @Override - public String getJsonBody() { - return jsonBody; - } - - @Override - public Integer getHighestVersion() { - return highestVersion; - } - - @Override - public URI getLocation() { - return location; - } - - @Override - public List getDynamicRuleAlgorithmLabels() { - return dynamicRuleAlgorithmLabels; - } - - @Override - public List getDynamicRuleAlgorithmCombo() { - return dynamicRuleAlgorithmCombo; - } - - @Override - public List getDynamicRuleAlgorithmField1() { - return dynamicRuleAlgorithmField1; - } - - @Override - public List getDynamicRuleAlgorithmField2() { - return dynamicRuleAlgorithmField2; - } - - @Override - public String getActionPerformer() { - return actionPerformer; - } - - @Override - public String getActionAttribute() { - return actionAttribute; - } - - @Override - public String getActionBody() { - return actionBody; - } - - @Override - public Map getDropDownMap() { - return dropDownMap; - } - - @Override - public String getActionDictHeader() { - return actionDictHeader; - } - - @Override - public String getActionDictType() { - return actionDictType; - } - - @Override - public String getActionDictUrl() { - return actionDictUrl; - } - - @Override - public String getActionDictMethod() { - return actionDictMethod; - } - - @Override - public Map getDynamicSettingsMap() { - return dynamicSettingsMap; - } - - @Override - public List getDynamicVariableList() { - return dynamicVariableList; - } - - @Override - public List getDataTypeList() { - return dataTypeList; - } - - @Override - public String getOldPolicyFileName() { - return oldPolicyFileName; - } - - @Override - public String getServiceType() { - return serviceType; - } - - @Override - public String getUuid() { - return uuid; - } - - @Override - public String getMsLocation() { - return msLocation; - } - - @Override - public String getPriority() { - return priority; - } - - @Override - public String getDeleteCondition() { - return deleteCondition; - } - - @Override - public String getDictionaryType() { - return dictionaryType; - } - - @Override - public String getDictionary() { - return dictionary; - } - - @Override - public String getTTLDate(){ - return ttlDate; - } - - @Override - public String getDictionaryFields() { - return dictionaryFields; - } - - @Override - public String getRiskType() { - return riskType; - } - - @Override - public String getRiskLevel() { - return riskLevel; - } - - @Override - public String getGuard() { - return guard; - } - - @Override - public Map getTreatments() { - return treatments; - } - - @Override - public String toString() { - return "StdPAPPolicy [policyName=" + policyName + ", policyDescription=" + policyDescription + ", onapName=" - + onapName + ", configName=" + configName + ", dyanamicFieldConfigAttributes=" + dyanamicFieldConfigAttributes + ", configBodyData=" + configBodyData - + ", policyID=" + policyID + ", ruleID=" + ruleID + ", configType=" + configType + ", editPolicy=" + ", version=" + ", domain=" + domain - + ", configPolicyType=" + configPolicyType + ", jsonBody=" + jsonBody + ", highestVersion=" + highestVersion + ", location=" + location - + ",dynamicRuleAlgorithmLabels=" + dynamicRuleAlgorithmLabels + ",dynamicRuleAlgorithmCombo=" + dynamicRuleAlgorithmCombo - + ",dynamicRuleAlgorithmField1=" + dynamicRuleAlgorithmField1 + ",dynamicRuleAlgorithmField2=" + dynamicRuleAlgorithmField2 - + ",actionPerformer=" + actionPerformer + ",actionAttribute=" + actionAttribute + ",actionBody=" + actionBody + ",dropDownMap=" + dropDownMap - + ",actionDictHeader=" + actionDictHeader + ",actionDictType=" + actionDictType + ",actionDictUrl=" + actionDictUrl - + ",actionDictMethod=" + actionDictMethod + ",dynamicSettingsMap=" + dynamicSettingsMap + ",dynamicVariableList=" + dynamicVariableList + ",providerComboBox=" + providerComboBox - + ",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 - + ",treatments=" + treatments + "]"; - } - - // Methods needed for JSON Deserialization - public void setPolicyName(String policyName) { - this.policyName = policyName; - } - - public void setPolicyDescription(String policyDescription) { - this.policyDescription = policyDescription; - } - - public void setOnapName(String onapName) { - this.onapName = onapName; - } - - public void setConfigName(String configName) { - this.configName = configName; - } - - public void setDyanamicFieldConfigAttributes( - Map dyanamicFieldConfigAttributes) { - this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; - } - - public void setConfigBodyData(String configBodyData) { - this.configBodyData = configBodyData; - } - - public void setPolicyID(String policyID) { - this.policyID = policyID; - } - - public void setRuleID(String ruleID) { - this.ruleID = ruleID; - } - - public void setConfigType(String configType) { - this.configType = configType; - } - - public void setEditPolicy(Boolean editPolicy) { - this.editPolicy = editPolicy; - } - - public void setVersion(String version) { - this.version = version; - } - - public void setDomainDir(String domain) { - this.domain = domain; - } - - public void setConfigPolicyType(String configPolicyType) { - this.configPolicyType = configPolicyType; - } - - public void setJsonBody(String jsonBody) { - this.jsonBody = jsonBody; - } - - public void setHighestVersion(Integer highestVersion) { - this.highestVersion = highestVersion; - } - - public void setLocation (URI location) { - this.location = location; - } - - public void setDynamicRuleAlgorithmLabels( - List dynamicRuleAlgorithmLabels) { - this.dynamicRuleAlgorithmLabels = dynamicRuleAlgorithmLabels; - } - - public void setDynamicRuleAlgorithmCombo(List dynamicRuleAlgorithmCombo) { - this.dynamicRuleAlgorithmCombo = dynamicRuleAlgorithmCombo; - } - - public void setDynamicRuleAlgorithmField1( - List dynamicRuleAlgorithmField1) { - this.dynamicRuleAlgorithmField1 = dynamicRuleAlgorithmField1; - } - - public void setDynamicRuleAlgorithmField2( - List dynamicRuleAlgorithmField2) { - this.dynamicRuleAlgorithmField2 = dynamicRuleAlgorithmField2; - } - - public void setActionPerformer(String actionPerformer) { - this.actionPerformer = actionPerformer; - } - - public void setActionAttribute(String actionAttribute) { - this.actionAttribute = actionAttribute; - } - - public void setActionBody(String actionBody) { - this.actionBody = actionBody; - } - - public void setDropDownMap(Map dropDownMap) { - this.dropDownMap = dropDownMap; - } - - public void setActionDictHeader(String actionDictHeader) { - this.actionDictHeader = actionDictHeader; - } +public class StdPAPPolicy implements OnapPAPPolicy, Serializable { + private static final long serialVersionUID = 5260230629397322000L; + + private String policyName = null; + private String oldPolicyFileName = null; + private String policyDescription = null; + 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; + private List dynamicRuleAlgorithmCombo; + private List dynamicRuleAlgorithmField1; + private List dynamicRuleAlgorithmField2; + private transient List dynamicVariableList; + private List dataTypeList; + private String configBodyData = null; + private String policyID = null; + private String ruleID = null; + private String brmsController; + private List brmsDependency; + private String configType = null; + private Boolean editPolicy = false; + private Boolean draft = false; + private String version = null; + private String domain = null; + private String configPolicyType = null; + private String jsonBody = null; + private String serviceType = null; + private Integer highestVersion = null; + private URI location = null; + private String actionPerformer = null; + private String actionAttribute = null; + private String actionBody = null; + private String actionDictHeader = null; + private String actionDictType = null; + private String actionDictUrl = null; + private String actionDictMethod = null; + private String uuid = null; + private String msLocation = null; + private String priority = null; + private transient Map drlRuleAndUIParams = null; + private String deleteCondition = null; + private String dictionaryType = null; + private String dictionary = null; + private String dictionaryFields = null; + private String providerComboBox = null; + private String riskType = null; + private String guard = null; + private String riskLevel; + private String ttlDate = null; + + + public StdPAPPolicy() { + // + // Default empty constructor + // + } + + //Constructor for sending location when pushing policies + public StdPAPPolicy(URI location) { + this.location = location; + } + + //Constructor for Validating Config Policies + public StdPAPPolicy(String policyName, String body, String configType, String configPolicyType) { + this.policyName = policyName; + this.configBodyData = body; + this.configType = configType; + this.configPolicyType = configPolicyType; + } + + //Constructor for Create Config Policies from API and Admin Console + //Constructor for Updating Config Policies from the API + //convenience constructor + public StdPAPPolicy(StdPAPPolicyParams stdPAPPolicyParams) { + this.configPolicyType=stdPAPPolicyParams.getConfigPolicyType(); + this.policyName = stdPAPPolicyParams.getPolicyName(); + this.policyDescription = stdPAPPolicyParams.getDescription(); + this.onapName = stdPAPPolicyParams.getOnapName(); + this.configName = stdPAPPolicyParams.getConfigName(); + this.dyanamicFieldConfigAttributes = stdPAPPolicyParams.getAttributes(); + this.configType = stdPAPPolicyParams.getConfigType(); + this.configBodyData = stdPAPPolicyParams.getConfigBodyData(); + this.editPolicy = stdPAPPolicyParams.getEditPolicy(); + this.domain = stdPAPPolicyParams.getDomain(); + this.highestVersion = stdPAPPolicyParams.getHighestVersion(); + this.riskLevel = stdPAPPolicyParams.getRiskLevel(); + this.riskType = stdPAPPolicyParams.getRiskType(); + this.guard = stdPAPPolicyParams.getGuard(); + this.ttlDate = stdPAPPolicyParams.getTtlDate(); + } + + //Constructor for Create/Update Action Policies from API + public StdPAPPolicy(String policyName, String description, Map attributes, + List dynamicRuleAlgorithmLabels, List dynamicRuleAlgorithmCombo, + List dynamicRuleAlgorithmField1, List dynamicRuleAlgorithmField2, + String actionPerformer, String actionAttribute, Boolean editPolicy, + String domain, int highestVersion) { + + this.policyName = policyName; + this.policyDescription = description; + this.dyanamicFieldConfigAttributes = attributes; + this.dynamicRuleAlgorithmLabels = dynamicRuleAlgorithmLabels; + this.dynamicRuleAlgorithmCombo = dynamicRuleAlgorithmCombo; + this.dynamicRuleAlgorithmField1 = dynamicRuleAlgorithmField1; + this.dynamicRuleAlgorithmField2 = dynamicRuleAlgorithmField2; + this.actionPerformer = actionPerformer; + this.actionAttribute = actionAttribute; + this.editPolicy = editPolicy; + this.domain = domain; + this.highestVersion = highestVersion; + + } + + //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) { + this.policyName = policyName; + this.policyDescription = description; + this.onapName = onapName; + this.setProviderComboBox(providerComboBox); + this.dyanamicFieldConfigAttributes = attributes; + this.dynamicSettingsMap = settings; + this.dynamicRuleAlgorithmLabels = dynamicRuleAlgorithmLabels; + this.dynamicRuleAlgorithmCombo = dynamicRuleAlgorithmCombo; + this.dynamicRuleAlgorithmField1 = dynamicRuleAlgorithmField1; + this.dynamicRuleAlgorithmField2 = dynamicRuleAlgorithmField2; + this.dynamicVariableList = dynamicVariableList; + this.dataTypeList = dataTypeList; + this.dropDownMap = dropDownMap; + this.editPolicy = editPolicy; + this.domain = domain; + this.highestVersion = highestVersion; + this.treatments = treatments; + } + + //convenience constructor + public StdPAPPolicy(String configPolicyType, String policyName, String description, String onapName, + String configName, Map attributes, String body, String policyID, + String ruleID, String configType, Boolean editPolicy, String version, String domain, + String riskLevel, String riskType, String guard, String ttlDate) { + this(configPolicyType, policyName, description, onapName, configName, attributes, body, policyID, + ruleID, configType, editPolicy, version, domain, 1, riskLevel, riskType, guard, ttlDate); + } + + //Constructor for Updating Config Policies from Admin Console + public StdPAPPolicy(String configPolicyType, String policyName, String description, String onapName, + String configName, Map attributes, String body, String policyID, + String ruleID, String configType, Boolean editPolicy, String version, String domain, + int highestVersion, String riskLevel, String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.onapName = onapName; + this.configName = configName; + this.dyanamicFieldConfigAttributes = attributes; + this.configBodyData = body; + this.policyID = policyID; + this.ruleID = ruleID; + this.configType = configType; + this.editPolicy = editPolicy; + this.version = version; + this.domain = domain; + this.highestVersion = highestVersion; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + + //Constructor for Creating Config Firewall Policies + public StdPAPPolicy(String configPolicyType, String policyName, String description, String configName, + Boolean editPolicy, String domain, String jsonBody, Integer highestVersion, String riskLevel, + String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.jsonBody = jsonBody; + this.highestVersion = highestVersion; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + + } + + //Constructor for Creating Goc Policies + public StdPAPPolicy(String configPolicyType, String policyName, String description, String configName, + Boolean editPolicy, String domain, String jsonBody, Integer highestVersion, String eCompName, + String riskLevel, String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.jsonBody = jsonBody; + this.highestVersion = highestVersion; + this.onapName = eCompName; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Creating BRMS Policies from the Admin Console + public StdPAPPolicy(String configPolicyType, String policyName, String description, + String configName, Boolean editPolicy, String domain, + Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, + String configBodyData, String riskLevel, String riskType, String guard, String ttlDate, + String brmsController, List brmsDependency) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; + this.highestVersion = highestVersion; + this.onapName = eCompName; + this.configBodyData = configBodyData; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + this.brmsController = brmsController; + this.brmsDependency = brmsDependency; + } + + //Constructor for Creating BRMS Param Policies from the Admin Console + public StdPAPPolicy(String configPolicyType, String policyName, String description, + String configName, Boolean editPolicy, String domain, + Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, + String configBodyData, Map drlRuleAndUIParams, String riskLevel, + String riskType, String guard, String ttlDate, String brmsController, + List brmsDependency) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; + this.highestVersion = highestVersion; + this.onapName = eCompName; + this.configBodyData = configBodyData; + this.drlRuleAndUIParams = drlRuleAndUIParams; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + this.brmsController = brmsController; + this.brmsDependency = brmsDependency; + } + + //Constructor for Creating CloseLoop_Fault and Performance Metric Policies + public StdPAPPolicy(String configPolicyType, String policyName, String description, String onapName, + String jsonBody, Boolean draft, String oldPolicyFileName, String serviceType, + Boolean editPolicy, + String domain, Integer highestVersion, String riskLevel, String riskType, String guard, + String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.onapName = onapName; + this.jsonBody = jsonBody; + this.draft = draft; + this.oldPolicyFileName = oldPolicyFileName; + this.serviceType = serviceType; + this.editPolicy = editPolicy; + this.domain = domain; + this.highestVersion = highestVersion; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Updating Config Firewall Policies from the Admin Console + public StdPAPPolicy(String configPolicyType, String policyName, String description, String configName, + Boolean editPolicy, String domain, String policyID, + String ruleID, String version, String jsonBody, Integer highestVersion, String riskLevel, + String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.policyID = policyID; + this.ruleID = ruleID; + this.version = version; + this.jsonBody = jsonBody; + this.highestVersion = highestVersion; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Micro Service Creating/Updating Policies from the Admin Console + public StdPAPPolicy(String configPolicyType, String policyName, String description, String onapName, + String configName, String serviceType, String uuid, + String msLocation, String jsonBody, String priority, String version, Boolean editPolicy, + String domain, int highestVersion, String riskLevel, + String riskType, String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.onapName = onapName; + this.configName = configName; + this.serviceType = serviceType; + this.uuid = uuid; + this.msLocation = msLocation; + this.priority = priority; + this.version = version; + this.jsonBody = jsonBody; + this.editPolicy = editPolicy; + this.domain = domain; + this.highestVersion = highestVersion; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Updating Goc Policies from the Admin Console + public StdPAPPolicy(String configPolicyType, String policyName, String description, + String configName, Boolean editPolicy, String domain, + String policyID, String ruleID, String version, + String jsonBody, Integer highestVersion, String eCompName, String riskLevel, String riskType, + String guard, String ttlDate) { + + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.policyID = policyID; + this.ruleID = ruleID; + this.version = version; + this.jsonBody = jsonBody; + this.highestVersion = highestVersion; + this.onapName = eCompName; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Updating Brms Policies from the Admin Console + public StdPAPPolicy(String configPolicyType, String policyName, String description, + String configName, Boolean editPolicy, String domain, + String policyID, String ruleID, String version, + Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, + String configBodyData, String riskLevel, String riskType, String guard, String ttlDate + ) { + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.policyID = policyID; + this.ruleID = ruleID; + this.version = version; + this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; + this.highestVersion = highestVersion; + this.onapName = eCompName; + this.configBodyData = configBodyData; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + //Constructor for Updating Brms Param Policies from the Admin Console + public StdPAPPolicy(String configPolicyType, String policyName, String description, + String configName, Boolean editPolicy, String domain, + String policyID, String ruleID, String version, + Map dyanamicFieldConfigAttributes, Integer highestVersion, String eCompName, + Map drlRuleAndUIParams, String riskLevel, String riskType, String guard, + String ttlDate + ) { + this.configPolicyType = configPolicyType; + this.policyName = policyName; + this.policyDescription = description; + this.configName = configName; + this.editPolicy = editPolicy; + this.domain = domain; + this.policyID = policyID; + this.ruleID = ruleID; + this.version = version; + this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; + this.highestVersion = highestVersion; + this.onapName = eCompName; + this.drlRuleAndUIParams = drlRuleAndUIParams; + this.riskLevel = riskLevel; + this.riskType = riskType; + this.guard = guard; + this.ttlDate = ttlDate; + } + + // Constructor for deleting policies from the API + public StdPAPPolicy(String policyName, String deleteCondition) { + this.policyName = policyName; + this.deleteCondition = deleteCondition; + } + + // Constructor for creating dictionary items from the API> + public StdPAPPolicy(String dictionaryType, String dictionary, String dictionaryFields) { + this.dictionaryType = dictionaryType; + this.dictionary = dictionary; + this.dictionaryFields = dictionaryFields; + } + + @Override + public String getPolicyName() { + return policyName; + } + + @Override + public String getPolicyDescription() { + return policyDescription; + } + + @Override + public String getOnapName() { + return onapName; + } + + @Override + public String getConfigName() { + return configName; + } + + @Override + public Map getDynamicFieldConfigAttributes() { + return dyanamicFieldConfigAttributes; + } + + @Override + public String getConfigBodyData() { + return configBodyData; + } + + @Override + public String getPolicyID() { + return policyID; + } + + @Override + public String getRuleID() { + return ruleID; + } + + @Override + public String getConfigType() { + return configType; + } + + @Override + public Boolean isEditPolicy() { + return editPolicy; + } + + @Override + public Boolean isDraft() { + return draft; + } + + @Override + public String getVersion() { + return version; + } + + @Override + public String getDomainDir() { + return domain; + } + + @Override + public String getConfigPolicyType() { + return configPolicyType; + } + + @Override + public String getJsonBody() { + return jsonBody; + } + + @Override + public Integer getHighestVersion() { + return highestVersion; + } + + @Override + public URI getLocation() { + return location; + } + + @Override + public List getDynamicRuleAlgorithmLabels() { + return dynamicRuleAlgorithmLabels; + } + + @Override + public List getDynamicRuleAlgorithmCombo() { + return dynamicRuleAlgorithmCombo; + } + + @Override + public List getDynamicRuleAlgorithmField1() { + return dynamicRuleAlgorithmField1; + } + + @Override + public List getDynamicRuleAlgorithmField2() { + return dynamicRuleAlgorithmField2; + } + + @Override + public String getActionPerformer() { + return actionPerformer; + } + + @Override + public String getActionAttribute() { + return actionAttribute; + } + + @Override + public String getActionBody() { + return actionBody; + } + + @Override + public Map getDropDownMap() { + return dropDownMap; + } + + @Override + public String getActionDictHeader() { + return actionDictHeader; + } + + @Override + public String getActionDictType() { + return actionDictType; + } + + @Override + public String getActionDictUrl() { + return actionDictUrl; + } + + @Override + public String getActionDictMethod() { + return actionDictMethod; + } + + @Override + public Map getDynamicSettingsMap() { + return dynamicSettingsMap; + } + + @Override + public List getDynamicVariableList() { + return dynamicVariableList; + } + + @Override + public List getDataTypeList() { + return dataTypeList; + } + + @Override + public String getOldPolicyFileName() { + return oldPolicyFileName; + } + + @Override + public String getServiceType() { + return serviceType; + } + + @Override + public String getUuid() { + return uuid; + } + + @Override + public String getMsLocation() { + return msLocation; + } + + @Override + public String getPriority() { + return priority; + } + + @Override + public String getDeleteCondition() { + return deleteCondition; + } + + @Override + public String getDictionaryType() { + return dictionaryType; + } + + @Override + public String getDictionary() { + return dictionary; + } + + @Override + public String getTTLDate() { + return ttlDate; + } + + @Override + public String getDictionaryFields() { + return dictionaryFields; + } + + @Override + public String getRiskType() { + return riskType; + } + + @Override + public String getRiskLevel() { + return riskLevel; + } + + @Override + public String getGuard() { + return guard; + } + + @Override + public Map getTreatments() { + return treatments; + } + + @Override + public String toString() { + return "StdPAPPolicy [policyName=" + policyName + ", policyDescription=" + policyDescription + ", onapName=" + + onapName + ", configName=" + configName + ", dyanamicFieldConfigAttributes=" + + dyanamicFieldConfigAttributes + ", configBodyData=" + configBodyData + + ", policyID=" + policyID + ", ruleID=" + ruleID + ", configType=" + configType + ", editPolicy=" + + ", version=" + ", domain=" + domain + + ", configPolicyType=" + configPolicyType + ", jsonBody=" + jsonBody + ", highestVersion=" + + highestVersion + ", location=" + location + + ",dynamicRuleAlgorithmLabels=" + dynamicRuleAlgorithmLabels + ",dynamicRuleAlgorithmCombo=" + + dynamicRuleAlgorithmCombo + + ",dynamicRuleAlgorithmField1=" + dynamicRuleAlgorithmField1 + ",dynamicRuleAlgorithmField2=" + + dynamicRuleAlgorithmField2 + + ",actionPerformer=" + actionPerformer + ",actionAttribute=" + actionAttribute + ",actionBody=" + + actionBody + ",dropDownMap=" + dropDownMap + + ",actionDictHeader=" + actionDictHeader + ",actionDictType=" + actionDictType + ",actionDictUrl=" + + actionDictUrl + + ",actionDictMethod=" + actionDictMethod + ",dynamicSettingsMap=" + dynamicSettingsMap + "," + + "dynamicVariableList=" + dynamicVariableList + ",providerComboBox=" + providerComboBox + + ",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 + + ",treatments=" + treatments + "]"; + } + + // Methods needed for JSON Deserialization + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public void setPolicyDescription(String policyDescription) { + this.policyDescription = policyDescription; + } + + public void setOnapName(String onapName) { + this.onapName = onapName; + } + + public void setConfigName(String configName) { + this.configName = configName; + } + + public void setDyanamicFieldConfigAttributes( + Map dyanamicFieldConfigAttributes) { + this.dyanamicFieldConfigAttributes = dyanamicFieldConfigAttributes; + } + + public void setConfigBodyData(String configBodyData) { + this.configBodyData = configBodyData; + } + + public void setPolicyID(String policyID) { + this.policyID = policyID; + } + + public void setRuleID(String ruleID) { + this.ruleID = ruleID; + } + + public void setConfigType(String configType) { + this.configType = configType; + } + + public void setEditPolicy(Boolean editPolicy) { + this.editPolicy = editPolicy; + } + + public void setVersion(String version) { + this.version = version; + } + + public void setDomainDir(String domain) { + this.domain = domain; + } + + public void setConfigPolicyType(String configPolicyType) { + this.configPolicyType = configPolicyType; + } + + public void setJsonBody(String jsonBody) { + this.jsonBody = jsonBody; + } + + public void setHighestVersion(Integer highestVersion) { + this.highestVersion = highestVersion; + } + + public void setLocation(URI location) { + this.location = location; + } + + public void setDynamicRuleAlgorithmLabels( + List dynamicRuleAlgorithmLabels) { + this.dynamicRuleAlgorithmLabels = dynamicRuleAlgorithmLabels; + } + + public void setDynamicRuleAlgorithmCombo(List dynamicRuleAlgorithmCombo) { + this.dynamicRuleAlgorithmCombo = dynamicRuleAlgorithmCombo; + } + + public void setDynamicRuleAlgorithmField1( + List dynamicRuleAlgorithmField1) { + this.dynamicRuleAlgorithmField1 = dynamicRuleAlgorithmField1; + } + + public void setDynamicRuleAlgorithmField2( + List dynamicRuleAlgorithmField2) { + this.dynamicRuleAlgorithmField2 = dynamicRuleAlgorithmField2; + } + + public void setActionPerformer(String actionPerformer) { + this.actionPerformer = actionPerformer; + } + + public void setActionAttribute(String actionAttribute) { + this.actionAttribute = actionAttribute; + } + + public void setActionBody(String actionBody) { + this.actionBody = actionBody; + } + + public void setDropDownMap(Map dropDownMap) { + this.dropDownMap = dropDownMap; + } + + public void setActionDictHeader(String actionDictHeader) { + this.actionDictHeader = actionDictHeader; + } + + public void setActionDictType(String actionDictType) { + this.actionDictType = actionDictType; + } + + public void setActionDictUrl(String actionDictUrl) { + this.actionDictUrl = actionDictUrl; + } + + public void setActionDictMethod(String actionDictMethod) { + this.actionDictMethod = actionDictMethod; + } + + public void setDynamicSettingsMap(Map dynamicSettingsMap) { + this.dynamicSettingsMap = dynamicSettingsMap; + } + + public void setDynamicVariableList(List dynamicVariableList) { + this.dynamicVariableList = dynamicVariableList; + } + + public void setDataTypeList(List dataTypeList) { + this.dataTypeList = dataTypeList; + } + + public void setDraft(Boolean draft) { + this.draft = draft; + } + + public void setOldPolicyFileName(String oldPolicyFileName) { + this.oldPolicyFileName = oldPolicyFileName; + } + + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + public Map getDrlRuleAndUIParams() { + return drlRuleAndUIParams; + } + + public void setDrlRuleAndUIParams(Map drlRuleAndUIParams) { + this.drlRuleAndUIParams = drlRuleAndUIParams; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public void setMsLocation(String msLocation) { + this.msLocation = msLocation; + } + + public void setPriority(String priority) { + this.priority = priority; + } + + public void setDeleteCondition(String deleteCondition) { + this.deleteCondition = deleteCondition; + } + + public void setDictionaryType(String dictionaryType) { + this.dictionaryType = dictionaryType; + } + + public void setDictionary(String dictionary) { + this.dictionary = dictionary; + } + + public void setDictionaryFields(String dictionaryFields) { + this.dictionaryFields = dictionaryFields; + } + + public String getProviderComboBox() { + return providerComboBox; + } + + public void setProviderComboBox(String providerComboBox) { + this.providerComboBox = providerComboBox; + } + + public void setRiskType(String riskType) { + this.riskType = riskType; + } + + public void setRiskLevel(String riskLevel) { + this.riskLevel = riskLevel; + } + + public void setGuard(String guard) { + this.guard = guard; + } + + public void setTTLDate(String ttlDate) { + this.ttlDate = ttlDate; + } + + public String getBrmsController() { + return brmsController; + } + + public void setBrmsController(String brmsController) { + this.brmsController = brmsController; + } - public void setActionDictType(String actionDictType) { - this.actionDictType = actionDictType; - } + public List getBrmsDependency() { + return brmsDependency; + } - public void setActionDictUrl(String actionDictUrl) { - this.actionDictUrl = actionDictUrl; - } + public void setBrmsDependency(List brmsDependency) { + this.brmsDependency = brmsDependency; + } - public void setActionDictMethod(String actionDictMethod) { - this.actionDictMethod = actionDictMethod; - } - - public void setDynamicSettingsMap(Map dynamicSettingsMap) { - this.dynamicSettingsMap = dynamicSettingsMap; - } - - public void setDynamicVariableList(List dynamicVariableList) { - this.dynamicVariableList = dynamicVariableList; - } - - public void setDataTypeList(List dataTypeList) { - this.dataTypeList = dataTypeList; - } - - public void setDraft(Boolean draft) { - this.draft = draft; - } - - public void setOldPolicyFileName(String oldPolicyFileName) { - this.oldPolicyFileName = oldPolicyFileName; - } - - public void setServiceType(String serviceType) { - this.serviceType = serviceType; - } - - public Map getDrlRuleAndUIParams() { - return drlRuleAndUIParams; - } - - public void setDrlRuleAndUIParams(Map drlRuleAndUIParams) { - this.drlRuleAndUIParams = drlRuleAndUIParams; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public void setMsLocation(String msLocation) { - this.msLocation = msLocation; - } - - public void setPriority(String priority) { - this.priority = priority; - } - - public void setDeleteCondition(String deleteCondition) { - this.deleteCondition = deleteCondition; - } - - public void setDictionaryType(String dictionaryType) { - this.dictionaryType = dictionaryType; - } - - public void setDictionary(String dictionary) { - this.dictionary = dictionary; - } - - public void setDictionaryFields(String dictionaryFields) { - this.dictionaryFields = dictionaryFields; - } - - public String getProviderComboBox() { - return providerComboBox; - } - - public void setProviderComboBox(String providerComboBox) { - this.providerComboBox = providerComboBox; - } - - public void setRiskType(String riskType){ - this.riskType = riskType; - } - - public void setRiskLevel(String riskLevel){ - this.riskLevel = riskLevel; - } - - public void setGuard(String guard){ - this.guard = guard; - } - - public void setTTLDate(String ttlDate){ - this.ttlDate = ttlDate; - } - - public String getBrmsController() { - return brmsController; - } - - public void setBrmsController(String brmsController) { - this.brmsController = brmsController; - } - - public List getBrmsDependency() { - return brmsDependency; - } - - public void setBrmsDependency(List brmsDependency) { - this.brmsDependency = brmsDependency; - } - - public void setTreatments(Map treatments) { - this.treatments = treatments; - } + public void setTreatments(Map treatments) { + this.treatments = treatments; + } } diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicyParams.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicyParams.java new file mode 100644 index 000000000..a9daa9e97 --- /dev/null +++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdPAPPolicyParams.java @@ -0,0 +1,193 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP-XACML + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics Co., Ltd. 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.std.pap; + +import java.util.Map; + +public class StdPAPPolicyParams { + private String configPolicyType; + private String policyName; + private String description; + private String onapName; + private String configName; + private Map attributes; + private String configType; + private String configBodyData; + private Boolean editPolicy; + private String domain; + private String riskLevel; + private String riskType; + private String guard; + private String ttlDate; + private int highestVersion; + + private StdPAPPolicyParams() { + super(); + } + + public int getHighestVersion() { + return highestVersion; + } + + public static StdPAPPolicyParamsBuilder builder() { + return new StdPAPPolicyParamsBuilder(); + } + + public String getConfigPolicyType() { + return configPolicyType; + } + + public String getPolicyName() { + return policyName; + } + + public String getDescription() { + return description; + } + + public String getOnapName() { + return onapName; + } + + public String getConfigName() { + return configName; + } + + public Map getAttributes() { + return attributes; + } + + public String getConfigType() { + return configType; + } + + public String getConfigBodyData() { + return configBodyData; + } + + public Boolean getEditPolicy() { + return editPolicy; + } + + public String getDomain() { + return domain; + } + + public String getRiskLevel() { + return riskLevel; + } + + public String getRiskType() { + return riskType; + } + + public String getGuard() { + return guard; + } + + public String getTtlDate() { + return ttlDate; + } + + public static class StdPAPPolicyParamsBuilder { + StdPAPPolicyParams m = new StdPAPPolicyParams(); + + public StdPAPPolicyParams build() { + return m; + } + + public StdPAPPolicyParamsBuilder configPolicyType(String configPolicyType) { + m.configPolicyType = configPolicyType; + return this; + } + + + public StdPAPPolicyParamsBuilder policyName(String policyName) { + m.policyName = policyName; + return this; + } + + public StdPAPPolicyParamsBuilder description(String description) { + m.description = description; + return this; + } + + public StdPAPPolicyParamsBuilder onapName(String onapName) { + m.onapName = onapName; + return this; + } + + public StdPAPPolicyParamsBuilder configName(String configName) { + m.configName = configName; + return this; + } + + public StdPAPPolicyParamsBuilder attributes(Map attributes) { + m.attributes = attributes; + return this; + } + + public StdPAPPolicyParamsBuilder configType(String configType) { + m.configType = configType; + return this; + } + + public StdPAPPolicyParamsBuilder configBodyData(String body) { + m.configBodyData = body; + return this; + } + + public StdPAPPolicyParamsBuilder editPolicy(boolean editPolicy) { + m.editPolicy = editPolicy; + return this; + } + + public StdPAPPolicyParamsBuilder domain(String domain) { + m.domain = domain; + return this; + } + + public StdPAPPolicyParamsBuilder riskLevel(String riskLevel) { + m.riskLevel = riskLevel; + return this; + } + + public StdPAPPolicyParamsBuilder riskType(String riskType) { + m.riskType = riskType; + return this; + } + + public StdPAPPolicyParamsBuilder guard(String guard) { + m.guard = guard; + return this; + } + + public StdPAPPolicyParamsBuilder ttlDate(String ttlDate) { + m.ttlDate = ttlDate; + return this; + } + + public StdPAPPolicyParamsBuilder highestVersion(int highVer) { + m.highestVersion = highVer; + return this; + } + } +} 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 index 42fa87288..aa57c27f0 100644 --- 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 @@ -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. @@ -21,6 +21,7 @@ package org.onap.policy.xacml.test.std.pap; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; + import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Paths; @@ -29,11 +30,13 @@ import java.util.HashMap; import java.util.List; import java.util.Map; 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.std.pap.StdPAPPolicy; +import org.onap.policy.xacml.std.pap.StdPAPPolicyParams; public class StdPAPPolicyTest { @@ -569,13 +572,30 @@ public class StdPAPPolicyTest { assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); } - + @Test - public void testConstructorStringStringStringStringStringMapStringStringStringStringBooleanStringStringStringStringString() throws URISyntaxException { + public void testConstructorStringStringStringStringStringMapStringStringStringStringBooleanStringStringStringStringString() + throws URISyntaxException { Map attributes = new HashMap<>(); attributes.put("aKey", "aValue"); - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "onapName", "configName", attributes, - "configType", "body", true, "domain", "riskLevel", "riskType", "guard", "ttlDate"); + + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy( + StdPAPPolicyParams.builder() + .configPolicyType("configTypePolicy") + .policyName("policyName") + .description("description") + .onapName("onapName") + .configName("configName") + .attributes(attributes) + .configType("configType") + .configBodyData("body") + .editPolicy(true) + .domain("domain") + .highestVersion(1) + .riskLevel("riskLevel") + .riskType("riskType") + .guard("guard") + .ttlDate("ttlDate").build()); assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); assertEquals("policyName", stdPAPPolicy.getPolicyName()); assertEquals("description", stdPAPPolicy.getPolicyDescription()); @@ -591,9 +611,9 @@ public class StdPAPPolicyTest { assertEquals("guard", stdPAPPolicy.getGuard()); assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); } - + @Test - public void testConstructorStringStringMapStringStringListStringListStringListStringListStringStringStringBooleanStringint(){ + public void testConstructorStringStringMapStringStringListStringListStringListStringListStringStringStringBooleanStringint() { Map attributes = new HashMap<>(); attributes.put("aKey", "aValue"); List dynamicRuleAlgorithmLabels = new ArrayList<>(); @@ -604,7 +624,9 @@ public class StdPAPPolicyTest { dynamicRuleAlgorithmField1.add("dynamicRuleAlgorithmField1"); List dynamicRuleAlgorithmField2 = new ArrayList<>(); dynamicRuleAlgorithmField2.add("dynamicRuleAlgorithmField2"); - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("policyName", "description", attributes, dynamicRuleAlgorithmLabels, dynamicRuleAlgorithmCombo, dynamicRuleAlgorithmField1, dynamicRuleAlgorithmField2, + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("policyName", "description", attributes, + dynamicRuleAlgorithmLabels, dynamicRuleAlgorithmCombo, dynamicRuleAlgorithmField1, + dynamicRuleAlgorithmField2, "actionPerformer", "actionAttribute", true, "domain", 1); assertEquals("policyName", stdPAPPolicy.getPolicyName()); assertEquals("description", stdPAPPolicy.getPolicyDescription()); @@ -619,9 +641,9 @@ public class StdPAPPolicyTest { assertEquals("domain", stdPAPPolicy.getDomainDir()); assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); } - + @Test - public void testConstructorStringStringStringStringMapStringStringMapStringStringMapStringStringListStringListStringListStringListStringMapStringStringListObjectListStringBooleanStringint(){ + public void testConstructorStringStringStringStringMapStringStringMapStringStringMapStringStringListStringListStringListStringListStringMapStringStringListObjectListStringBooleanStringint() { Map attributes = new HashMap<>(); attributes.put("aKey1", "aValue1"); Map settings = new HashMap<>(); @@ -642,8 +664,10 @@ public class StdPAPPolicyTest { dynamicVariableList.add("dynamicVariableList"); List dataTypeList = new ArrayList<>(); dataTypeList.add("dataTypeList"); - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("policyName", "description", "onapName", "providerComboBox", attributes, settings, treatments, dynamicRuleAlgorithmLabels, dynamicRuleAlgorithmCombo, - dynamicRuleAlgorithmField1, dynamicRuleAlgorithmField2, dropDownMap, dynamicVariableList, dataTypeList, true, "domain", 1); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("policyName", "description", "onapName", "providerComboBox", + attributes, settings, treatments, dynamicRuleAlgorithmLabels, dynamicRuleAlgorithmCombo, + dynamicRuleAlgorithmField1, dynamicRuleAlgorithmField2, dropDownMap, dynamicVariableList, + dataTypeList, true, "domain", 1); assertEquals("policyName", stdPAPPolicy.getPolicyName()); assertEquals("description", stdPAPPolicy.getPolicyDescription()); assertEquals("onapName", stdPAPPolicy.getOnapName()); @@ -662,13 +686,16 @@ public class StdPAPPolicyTest { assertEquals("domain", stdPAPPolicy.getDomainDir()); assertEquals(Integer.valueOf(1), stdPAPPolicy.getHighestVersion()); } - + @Test - public void testConstructorStringStringStringStringStringMapStringStringStringStringStringStringBooleanStringStringintStringStringStringString() throws URISyntaxException { + public void testConstructorStringStringStringStringStringMapStringStringStringStringStringStringBooleanStringStringintStringStringStringString() + throws URISyntaxException { Map attributes = new HashMap<>(); attributes.put("aKey", "aValue"); - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "onapName", "configName", attributes, - "body", "policyId", "ruleId", "configType", true, "version", "domain", 1, "riskLevel", "riskType", "guard", "ttlDate"); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "onapName", + "configName", attributes, + "body", "policyId", "ruleId", "configType", true, "version", "domain", 1, "riskLevel", "riskType", + "guard", "ttlDate"); assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); assertEquals("policyName", stdPAPPolicy.getPolicyName()); assertEquals("description", stdPAPPolicy.getPolicyDescription()); @@ -688,10 +715,12 @@ public class StdPAPPolicyTest { assertEquals("guard", stdPAPPolicy.getGuard()); assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); } - + @Test - public void testConstructorStringStringStringStringBooleanStringStringIntegerStringStringStringString() throws URISyntaxException { - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, + public void testConstructorStringStringStringStringBooleanStringStringIntegerStringStringStringString() + throws URISyntaxException { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", + true, "domain", "jasonBody", 1, "riskLevel", "riskType", "guard", "ttlDate"); assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); assertEquals("policyName", stdPAPPolicy.getPolicyName()); @@ -706,10 +735,12 @@ public class StdPAPPolicyTest { assertEquals("guard", stdPAPPolicy.getGuard()); assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); } - + @Test - public void testConstructorStringStringStringStringBooleanStringStringIntegerStringStringStringStringString() throws URISyntaxException { - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, + public void testConstructorStringStringStringStringBooleanStringStringIntegerStringStringStringStringString() + throws URISyntaxException { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", + true, "domain", "jasonBody", 1, "eCompName", "riskLevel", "riskType", "guard", "ttlDate"); assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); assertEquals("policyName", stdPAPPolicy.getPolicyName()); @@ -725,15 +756,18 @@ public class StdPAPPolicyTest { assertEquals("guard", stdPAPPolicy.getGuard()); assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); } - + @Test - public void testConstructorMapStringStringIntegerStringStringStringStringStringStringStringArrayListString() throws URISyntaxException { + public void testConstructorMapStringStringIntegerStringStringStringStringStringStringStringArrayListString() + throws URISyntaxException { Map dyanamicFieldConfigAttributes = new HashMap<>(); dyanamicFieldConfigAttributes.put("aKey", "aValue"); ArrayList brmsDependency = new ArrayList<>(); brmsDependency.add("brmsDependency"); - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, - "domain", dyanamicFieldConfigAttributes, 1, "eCompName", "configBodyData", "riskLevel", "riskType", "guard", "ttlDate", "brmsController", brmsDependency); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", + true, + "domain", dyanamicFieldConfigAttributes, 1, "eCompName", "configBodyData", "riskLevel", "riskType", + "guard", "ttlDate", "brmsController", brmsDependency); assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); assertEquals("policyName", stdPAPPolicy.getPolicyName()); assertEquals("description", stdPAPPolicy.getPolicyDescription()); @@ -751,17 +785,20 @@ public class StdPAPPolicyTest { assertEquals("brmsController", stdPAPPolicy.getBrmsController()); assertEquals(brmsDependency, stdPAPPolicy.getBrmsDependency()); } - + @Test - public void testConstructorMapStringStringIntegerStringStringMapStringStringStringStringStringStringStringArrayListString() throws URISyntaxException { + public void testConstructorMapStringStringIntegerStringStringMapStringStringStringStringStringStringStringArrayListString() + throws URISyntaxException { Map dyanamicFieldConfigAttributes = new HashMap<>(); dyanamicFieldConfigAttributes.put("aKey", "aValue"); Map drlRuleAndUIParams = new HashMap<>(); drlRuleAndUIParams.put("aDrlRuleKey", "aDrlRuleValue"); ArrayList brmsDependency = new ArrayList<>(); brmsDependency.add("brmsDependency"); - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, - "domain", dyanamicFieldConfigAttributes, 1, "eCompName", "configBodyData", drlRuleAndUIParams, "riskLevel", "riskType", "guard", "ttlDate", "brmsController", brmsDependency); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", + true, + "domain", dyanamicFieldConfigAttributes, 1, "eCompName", "configBodyData", drlRuleAndUIParams, + "riskLevel", "riskType", "guard", "ttlDate", "brmsController", brmsDependency); assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); assertEquals("policyName", stdPAPPolicy.getPolicyName()); assertEquals("description", stdPAPPolicy.getPolicyDescription()); @@ -780,10 +817,12 @@ public class StdPAPPolicyTest { assertEquals("brmsController", stdPAPPolicy.getBrmsController()); assertEquals(brmsDependency, stdPAPPolicy.getBrmsDependency()); } - + @Test - public void testConstructorStringStringStringStringStringBooleanStringStringBooleanStringIntegerStringStringStringString() throws URISyntaxException { - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "onapName", "jasonBody", true, + public void testConstructorStringStringStringStringStringBooleanStringStringBooleanStringIntegerStringStringStringString() + throws URISyntaxException { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "onapName", + "jasonBody", true, "oldPolicyFileName", "serviceType", true, "domain", 1, "riskLevel", "riskType", "guard", "ttlDate"); assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); assertEquals("policyName", stdPAPPolicy.getPolicyName()); @@ -801,10 +840,12 @@ public class StdPAPPolicyTest { assertEquals("guard", stdPAPPolicy.getGuard()); assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); } - + @Test - public void testConstructorStringStringStringStringBooleanStringStringStringStringStringIntegerStringStringStringString() throws URISyntaxException { - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, "domain", "policyId", "ruleId", + public void testConstructorStringStringStringStringBooleanStringStringStringStringStringIntegerStringStringStringString() + throws URISyntaxException { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", + true, "domain", "policyId", "ruleId", "version", "jasonBody", 1, "riskLevel", "riskType", "guard", "ttlDate"); assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); assertEquals("policyName", stdPAPPolicy.getPolicyName()); @@ -822,11 +863,13 @@ public class StdPAPPolicyTest { assertEquals("guard", stdPAPPolicy.getGuard()); assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); } - + @Test - public void testConstructorStringStringStringStringStringStringStringStringStringStringStringBooleanStringintStringStringStringString() throws URISyntaxException { - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "onapName", "configName", "serviceType", - "uuid", "msLocation", "jasonBody", "priority" , "version", true, "domain", + public void testConstructorStringStringStringStringStringStringStringStringStringStringStringBooleanStringintStringStringStringString() + throws URISyntaxException { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "onapName", + "configName", "serviceType", + "uuid", "msLocation", "jasonBody", "priority", "version", true, "domain", 1, "riskLevel", "riskType", "guard", "ttlDate"); assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); assertEquals("policyName", stdPAPPolicy.getPolicyName()); @@ -847,10 +890,12 @@ public class StdPAPPolicyTest { assertEquals("guard", stdPAPPolicy.getGuard()); assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); } - + @Test - public void testConstructorStringStringStringStringBooleanStringStringStringStringStringIntegerStringStringStringStringString() throws URISyntaxException { - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, "domain", "policyId", "ruleId", "version", + public void testConstructorStringStringStringStringBooleanStringStringStringStringStringIntegerStringStringStringStringString() + throws URISyntaxException { + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", + true, "domain", "policyId", "ruleId", "version", "jasonBody", 1, "ecompName", "riskLevel", "riskType", "guard", "ttlDate"); assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); assertEquals("policyName", stdPAPPolicy.getPolicyName()); @@ -869,13 +914,16 @@ public class StdPAPPolicyTest { assertEquals("guard", stdPAPPolicy.getGuard()); assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); } - + @Test - public void testConstructorStringStringStringStringBooleanStringStringStringStringMapStringStringIntegerStringStringStringStringString() throws URISyntaxException { + public void testConstructorStringStringStringStringBooleanStringStringStringStringMapStringStringIntegerStringStringStringStringString() + throws URISyntaxException { Map dyanamicFieldConfigAttributes = new HashMap<>(); dyanamicFieldConfigAttributes.put("aKey", "aValue"); - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, - "domain", "policyId", "ruleId", "version", dyanamicFieldConfigAttributes, 1, "eCompName", "configBodyData", "riskLevel", "riskType", "guard", "ttlDate"); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", + true, + "domain", "policyId", "ruleId", "version", dyanamicFieldConfigAttributes, 1, "eCompName", + "configBodyData", "riskLevel", "riskType", "guard", "ttlDate"); assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); assertEquals("policyName", stdPAPPolicy.getPolicyName()); assertEquals("description", stdPAPPolicy.getPolicyDescription()); @@ -894,15 +942,18 @@ public class StdPAPPolicyTest { assertEquals("guard", stdPAPPolicy.getGuard()); assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); } - + @Test - public void testConstructorStringStringStringStringBooleanStringStringStringStringMapStringStringIntegerStringMapStringStringStringStringStringString() throws URISyntaxException { + public void testConstructorStringStringStringStringBooleanStringStringStringStringMapStringStringIntegerStringMapStringStringStringStringStringString() + throws URISyntaxException { Map dyanamicFieldConfigAttributes = new HashMap<>(); dyanamicFieldConfigAttributes.put("aKey", "aValue"); Map drlRuleAndUIParams = new HashMap<>(); drlRuleAndUIParams.put("aDrlRuleKey", "aDrlRuleValue"); - StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", true, - "domain", "policyId", "ruleId", "version", dyanamicFieldConfigAttributes, 1, "eCompName", drlRuleAndUIParams, "riskLevel", "riskType", "guard", "ttlDate"); + StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("configTypePolicy", "policyName", "description", "configName", + true, + "domain", "policyId", "ruleId", "version", dyanamicFieldConfigAttributes, 1, "eCompName", + drlRuleAndUIParams, "riskLevel", "riskType", "guard", "ttlDate"); assertEquals("configTypePolicy", stdPAPPolicy.getConfigPolicyType()); assertEquals("policyName", stdPAPPolicy.getPolicyName()); assertEquals("description", stdPAPPolicy.getPolicyDescription()); @@ -921,19 +972,19 @@ public class StdPAPPolicyTest { assertEquals("guard", stdPAPPolicy.getGuard()); assertEquals("ttlDate", stdPAPPolicy.getTTLDate()); } - + @Test public void testConstructorStringString() { StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("policyName", "deleteCondition"); assertEquals("policyName", stdPAPPolicy.getPolicyName()); assertEquals("deleteCondition", stdPAPPolicy.getDeleteCondition()); } - + @Test public void testConstructorStringStringString() { StdPAPPolicy stdPAPPolicy = new StdPAPPolicy("dictionaryType", "dictionary", "dictionaryFields"); assertEquals("dictionaryType", stdPAPPolicy.getDictionaryType()); assertEquals("dictionary", stdPAPPolicy.getDictionary()); assertEquals("dictionaryFields", stdPAPPolicy.getDictionaryFields()); - } + } } -- 2.16.6