From 95524c8ef8be0d41de8bb2b918f320e464ebb897 Mon Sep 17 00:00:00 2001 From: rb7147 Date: Wed, 18 Jul 2018 12:50:06 -0400 Subject: Decision BlackList Guard Enhancements While creating a decision Bl Guard Policy we are allowing to add Blacklist entries through file upload for bulk from GUI. Issue-ID: POLICY-901 Change-Id: I4031fd4a96937b9facc330cecf72777d701d4678 Signed-off-by: rb7147 --- .../policy/rest/adapter/PolicyRestAdapter.java | 21 +++++++++ .../onap/policy/rest/adapter/ReturnBlackList.java | 51 ++++++++++++++++++++++ .../onap/policy/rest/util/PolicyValidation.java | 33 ++++++++------ .../policy/rest/adapter/ReturnBlackListTest.java | 41 +++++++++++++++++ 4 files changed, 132 insertions(+), 14 deletions(-) create mode 100644 ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ReturnBlackList.java create mode 100644 ONAP-REST/src/test/java/org/onap/policy/rest/adapter/ReturnBlackListTest.java (limited to 'ONAP-REST/src') diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java index a9daf1732..e815fe2b9 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/PolicyRestAdapter.java @@ -127,6 +127,9 @@ public class PolicyRestAdapter { private String actionDictUrl = null; private String actionDictMethod = null; private YAMLParams yamlparams; + private List blackListEntries; + private List appendBlackListEntries; + private String blackListEntryType; //Rainy Day Decision private RainyDayParams rainyday; @@ -907,4 +910,22 @@ public class PolicyRestAdapter { public void setFaultDatas(ClosedLoopFaultTrapDatas faultDatas) { this.faultDatas = faultDatas; } + public List getAppendBlackListEntries() { + return appendBlackListEntries; + } + public void setAppendBlackListEntries(List appendBlackListEntries) { + this.appendBlackListEntries = appendBlackListEntries; + } + public List getBlackListEntries() { + return blackListEntries; + } + public void setBlackListEntries(List blackListEntries) { + this.blackListEntries = blackListEntries; + } + public String getBlackListEntryType() { + return blackListEntryType; + } + public void setBlackListEntryType(String blackListEntryType) { + this.blackListEntryType = blackListEntryType; + } } diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ReturnBlackList.java b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ReturnBlackList.java new file mode 100644 index 000000000..6ecf1b5e4 --- /dev/null +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/adapter/ReturnBlackList.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.rest.adapter; + +public class ReturnBlackList { + private boolean entryCheck; + private int actionValue; + private String entryValue; + + public boolean isEntryCheck() { + return entryCheck; + } + + public void setEntryCheck(boolean entryCheck) { + this.entryCheck = entryCheck; + } + + public int getActionValue() { + return actionValue; + } + + public void setActionValue(int actionValue) { + this.actionValue = actionValue; + } + + public String getEntryValue() { + return entryValue; + } + + public void setEntryValue(String entryValue) { + this.entryValue = entryValue; + } +} diff --git a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java index 50985b12d..0478f5f95 100644 --- a/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java +++ b/ONAP-REST/src/main/java/org/onap/policy/rest/util/PolicyValidation.java @@ -940,20 +940,25 @@ public class PolicyValidation { responseString.append("Guard Params Time Units is Required" + HTML_ITALICS_LNBREAK); valid = false; } - }else if("GUARD_BL_YAML".equals(policyData.getRuleProvider())){ - if(policyData.getYamlparams().getBlackList()==null || policyData.getYamlparams().getBlackList().isEmpty()){ - responseString.append(" Guard Params BlackList is Required " + HTML_ITALICS_LNBREAK); - valid = false; - }else{ - for(String blackList: policyData.getYamlparams().getBlackList()){ - if(blackList==null || !(SUCCESS.equals(PolicyUtils.policySpecialCharValidator(blackList)))){ - responseString.append(" Guard Params BlackList Should be valid String" + HTML_ITALICS_LNBREAK); - valid = false; - break; - } - } - } - } + } else if ("GUARD_BL_YAML".equals(policyData.getRuleProvider()) + && "Use Manual Entry".equals(policyData.getBlackListEntryType())) { + if (policyData.getYamlparams().getBlackList() == null + || policyData.getYamlparams().getBlackList().isEmpty()) { + responseString + .append(" Guard Params BlackList is Required " + HTML_ITALICS_LNBREAK); + valid = false; + } else { + for (String blackList : policyData.getYamlparams().getBlackList()) { + if (blackList == null + || !(SUCCESS.equals(PolicyUtils.policySpecialCharValidator(blackList)))) { + responseString.append(" Guard Params BlackList Should be valid String" + + HTML_ITALICS_LNBREAK); + valid = false; + break; + } + } + } + } } } } diff --git a/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/ReturnBlackListTest.java b/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/ReturnBlackListTest.java new file mode 100644 index 000000000..e8f6684b1 --- /dev/null +++ b/ONAP-REST/src/test/java/org/onap/policy/rest/adapter/ReturnBlackListTest.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.rest.adapter; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class ReturnBlackListTest { + + @Test + public void testReturnBlackList() { + ReturnBlackList list = new ReturnBlackList(); + list.setActionValue(1); + list.setEntryCheck(true); + list.setEntryValue("Test"); + + assertTrue(1 == list.getActionValue()); + assertTrue(list.isEntryCheck()); + assertTrue("Test".equals(list.getEntryValue())); + } + +} -- cgit 1.2.3-korg