diff options
Diffstat (limited to 'ONAP-PAP-REST/src/main/java/org/onap')
12 files changed, 761 insertions, 558 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java index b5a3b45e8..5c9b2b883 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java @@ -38,6 +38,7 @@ import org.onap.policy.pap.xacml.rest.util.JsonMessage; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ActionPolicyDict; import org.onap.policy.rest.jpa.UserInfo; +import org.onap.policy.utils.PolicyUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -215,7 +216,7 @@ public class ActionPolicyDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java index 675c82549..f359ca2cb 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java @@ -45,6 +45,7 @@ import org.onap.policy.rest.jpa.UserInfo; import org.onap.policy.rest.jpa.VNFType; import org.onap.policy.rest.jpa.VSCLAction; import org.onap.policy.rest.jpa.VarbindDictionary; +import org.onap.policy.utils.PolicyUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -392,7 +393,7 @@ public class ClosedLoopDictionaryController{ response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -422,7 +423,7 @@ public class ClosedLoopDictionaryController{ response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -513,7 +514,7 @@ public class ClosedLoopDictionaryController{ response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -543,7 +544,7 @@ public class ClosedLoopDictionaryController{ response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -653,7 +654,7 @@ public class ClosedLoopDictionaryController{ response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -683,7 +684,7 @@ public class ClosedLoopDictionaryController{ response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -771,7 +772,7 @@ public class ClosedLoopDictionaryController{ response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -801,7 +802,7 @@ public class ClosedLoopDictionaryController{ response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -890,7 +891,7 @@ public class ClosedLoopDictionaryController{ response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -920,7 +921,7 @@ public class ClosedLoopDictionaryController{ response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -1009,7 +1010,7 @@ public class ClosedLoopDictionaryController{ response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -1039,7 +1040,7 @@ public class ClosedLoopDictionaryController{ response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java index f4e32ebea..5792cba81 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java @@ -23,6 +23,7 @@ package org.onap.policy.pap.xacml.rest.controller; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; + import org.json.JSONObject; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; @@ -32,6 +33,7 @@ import org.onap.policy.rest.jpa.Datatype; import org.onap.policy.rest.jpa.DecisionSettings; import org.onap.policy.rest.jpa.RainyDayTreatments; import org.onap.policy.rest.jpa.UserInfo; +import org.onap.policy.utils.PolicyUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -41,6 +43,7 @@ import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; @@ -208,7 +211,7 @@ public class DecisionPolicyDictionaryController { response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -238,7 +241,7 @@ public class DecisionPolicyDictionaryController { response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -376,7 +379,7 @@ public class DecisionPolicyDictionaryController { response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -406,7 +409,7 @@ public class DecisionPolicyDictionaryController { response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java index 40b0b5d62..a12f17b50 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java @@ -40,6 +40,7 @@ import org.onap.policy.pap.xacml.rest.util.JsonMessage; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.DescriptiveScope; import org.onap.policy.rest.jpa.UserInfo; +import org.onap.policy.utils.PolicyUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -210,7 +211,7 @@ public class DescriptiveDictionaryController { response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -240,7 +241,7 @@ public class DescriptiveDictionaryController { response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java index aee05da45..0b487010c 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java @@ -31,19 +31,27 @@ import java.io.OutputStream; import java.util.List; import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import org.apache.commons.compress.utils.IOUtils; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.ActionList; import org.onap.policy.rest.jpa.ActionPolicyDict; import org.onap.policy.rest.jpa.AddressGroup; import org.onap.policy.rest.jpa.Attribute; +import org.onap.policy.rest.jpa.BRMSController; +import org.onap.policy.rest.jpa.BRMSDependency; import org.onap.policy.rest.jpa.BRMSParamTemplate; import org.onap.policy.rest.jpa.Category; +import org.onap.policy.rest.jpa.ClosedLoopD2Services; +import org.onap.policy.rest.jpa.ClosedLoopSite; import org.onap.policy.rest.jpa.Datatype; import org.onap.policy.rest.jpa.DecisionSettings; import org.onap.policy.rest.jpa.DescriptiveScope; import org.onap.policy.rest.jpa.GroupServiceList; +import org.onap.policy.rest.jpa.MicroServiceModels; import org.onap.policy.rest.jpa.OnapName; import org.onap.policy.rest.jpa.PEPOptions; import org.onap.policy.rest.jpa.PrefixList; @@ -68,9 +76,12 @@ import au.com.bytecode.opencsv.CSVReader; @Controller public class DictionaryImportController { + private static final Logger LOGGER = FlexLogger.getLogger(DictionaryImportController.class); + private String newFile; private static CommonClassDao commonClassDao; + private static final String DESCRIPTION= "description"; @Autowired public DictionaryImportController(CommonClassDao commonClassDao){ @@ -81,458 +92,622 @@ public class DictionaryImportController { @RequestMapping(value={"/dictionary/import_dictionary"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public void ImportDictionaryData(HttpServletRequest request) throws IOException{ + public void ImportDictionaryData(HttpServletRequest request, HttpServletResponse response) throws IOException{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); String userId = request.getParameter("userId"); String dictionaryName = request.getParameter("dictionaryName"); - - File file = new File(dictionaryName); - OutputStream outputStream = new FileOutputStream(file); - IOUtils.copy(request.getInputStream(), outputStream); - outputStream.close(); - this.newFile = file.toString(); - CSVReader csvReader = new CSVReader(new FileReader(this.newFile)); - List<String[]> dictSheet = csvReader.readAll(); - if(dictionaryName.startsWith("Attribute")){ - for(int i = 1; i< dictSheet.size(); i++){ - Attribute attribute = new Attribute(""); - UserInfo userinfo = new UserInfo(); - userinfo.setUserLoginId(userId); - attribute.setUserCreatedBy(userinfo); - attribute.setUserModifiedBy(userinfo); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("xacml_id").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute ID").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setXacmlId(rows[j]); - } - if(("description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); - } - if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setPriority(rows[j]); - } - if(("datatype").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Data Type").equalsIgnoreCase(dictSheet.get(0)[j])){ - Datatype dataType = new Datatype(); - if(("string").equalsIgnoreCase(rows[j])){ - dataType.setId(26); - }else if(("integer").equalsIgnoreCase(rows[j])){ - dataType.setId(12); - }else if(("double").equalsIgnoreCase(rows[j])){ - dataType.setId(25); - }else if(("boolean").equalsIgnoreCase(rows[j])){ - dataType.setId(18); - }else if(("user").equalsIgnoreCase(rows[j])){ - dataType.setId(29); - } - attribute.setDatatypeBean(dataType); - Category category = new Category(); - category.setId(5); - attribute.setCategoryBean(category); - } - if(("attribute_value").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute Value").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setAttributeValue(rows[j]); + + if(dictionaryName == null || dictionaryName.isEmpty()){ + LOGGER.error("dictionaryName is null/empty"); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + response.getWriter().write("Error"); + return; + } + + boolean dictionaryImportExists = false; + try{ + File file = new File(dictionaryName); + OutputStream outputStream = new FileOutputStream(file); + IOUtils.copy(request.getInputStream(), outputStream); + outputStream.close(); + this.newFile = file.toString(); + CSVReader csvReader = new CSVReader(new FileReader(this.newFile)); + List<String[]> dictSheet = csvReader.readAll(); + if(dictionaryName.startsWith("Attribute")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + Attribute attribute = new Attribute(""); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("xacml_id").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute ID").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setXacmlId(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } + if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setPriority(rows[j]); + } + if(("datatype").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Data Type").equalsIgnoreCase(dictSheet.get(0)[j])){ + Datatype dataType = new Datatype(); + if(("string").equalsIgnoreCase(rows[j])){ + dataType.setId(26); + }else if(("integer").equalsIgnoreCase(rows[j])){ + dataType.setId(12); + }else if(("double").equalsIgnoreCase(rows[j])){ + dataType.setId(25); + }else if(("boolean").equalsIgnoreCase(rows[j])){ + dataType.setId(18); + }else if(("user").equalsIgnoreCase(rows[j])){ + dataType.setId(29); + } + attribute.setDatatypeBean(dataType); + Category category = new Category(); + category.setId(5); + attribute.setCategoryBean(category); + } + if(("attribute_value").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute Value").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setAttributeValue(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("ActionPolicyDictionary")){ - for(int i = 1; i< dictSheet.size(); i++){ - ActionPolicyDict attribute = new ActionPolicyDict("", userId); - UserInfo userinfo = new UserInfo(); - userinfo.setUserLoginId(userId); - attribute.setUserCreatedBy(userinfo); - attribute.setUserModifiedBy(userinfo); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("attribute_name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setAttributeName(rows[j]); - } - if(("body").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setBody(rows[j]); - } - if(("description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); - } - if(("headers").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setHeader(rows[j]); - } - if(("method").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setMethod(rows[j]); - } - if(("type").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setMethod(rows[j]); - } - if(("url").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setMethod(rows[j]); + if(dictionaryName.startsWith("ActionPolicyDictionary")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + ActionPolicyDict attribute = new ActionPolicyDict("", userId); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("attribute_name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setAttributeName(rows[j]); + } + if(("body").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setBody(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } + if(("headers").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setHeader(rows[j]); + } + if(("method").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setMethod(rows[j]); + } + if(("type").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setType(rows[j]); + } + if(("url").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setUrl(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("OnapName")){ - for(int i = 1; i< dictSheet.size(); i++){ - OnapName attribute = new OnapName("", userId); - UserInfo userinfo = new UserInfo(); - userinfo.setUserLoginId(userId); - attribute.setUserCreatedBy(userinfo); - attribute.setUserModifiedBy(userinfo); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("onap_name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Onap Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setOnapName(rows[j]); - } - if(("description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); + if(dictionaryName.startsWith("OnapName")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + OnapName attribute = new OnapName("", userId); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("onap_name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Onap Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setOnapName(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("VNFType")){ - for(int i = 1; i< dictSheet.size(); i++){ - VNFType attribute = new VNFType("", userId); - UserInfo userinfo = new UserInfo(); - userinfo.setUserLoginId(userId); - attribute.setUserCreatedBy(userinfo); - attribute.setUserModifiedBy(userinfo); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("vnf_type").equalsIgnoreCase(dictSheet.get(0)[j]) || ("VNF Type").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setVnftype(rows[j]); + + if(dictionaryName.startsWith("MSPolicyDictionary")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + MicroServiceModels attribute = new MicroServiceModels(); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("modelName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Micro Service Model").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setModelName(rows[j]); + } + if(("version").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Model Version").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setVersion(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } + if(("dependency").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDependency(rows[j]); + } + if(("attributes").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setAttributes(rows[j]); + } + if(("enumValues").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setEnumValues(rows[j]); + } + if(("Ref Attributes").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setRef_attributes(rows[j]); + } + if(("Sub Attributes").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setSub_attributes(rows[j]); + } } - if(("description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); + + commonClassDao.save(attribute); + } + } + + if(dictionaryName.startsWith("VNFType")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + VNFType attribute = new VNFType("", userId); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("vnf_type").equalsIgnoreCase(dictSheet.get(0)[j]) || ("VNF Type").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setVnftype(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("VSCLAction")){ - for(int i = 1; i< dictSheet.size(); i++){ - VSCLAction attribute = new VSCLAction("", userId); - UserInfo userinfo = new UserInfo(); - userinfo.setUserLoginId(userId); - attribute.setUserCreatedBy(userinfo); - attribute.setUserModifiedBy(userinfo); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("vscl_action").equalsIgnoreCase(dictSheet.get(0)[j]) || ("VSCL Action").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setVsclaction(rows[j]); - } - if(("description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); + if(dictionaryName.startsWith("VSCLAction")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + VSCLAction attribute = new VSCLAction("", userId); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("vscl_action").equalsIgnoreCase(dictSheet.get(0)[j]) || ("VSCL Action").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setVsclaction(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("PEPOptions")){ - for(int i = 1; i< dictSheet.size(); i++){ - PEPOptions attribute = new PEPOptions("", userId); - UserInfo userinfo = new UserInfo(); - userinfo.setUserLoginId(userId); - attribute.setUserCreatedBy(userinfo); - attribute.setUserModifiedBy(userinfo); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("PEP_NAME").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PEP Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setPepName(rows[j]); - } - if(("description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); - } - if(("Actions").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setActions(rows[j]); + if(dictionaryName.startsWith("ClosedLoopService")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + ClosedLoopD2Services attribute = new ClosedLoopD2Services("", userId); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("serviceName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setServiceName(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("VarbindDictionary")){ - for(int i = 1; i< dictSheet.size(); i++){ - VarbindDictionary attribute = new VarbindDictionary("", userId); - UserInfo userinfo = new UserInfo(); - userinfo.setUserLoginId(userId); - attribute.setUserCreatedBy(userinfo); - attribute.setUserModifiedBy(userinfo); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("varbind_Name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setVarbindName(rows[j]); - } - if(("varbind_Description").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind Description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setVarbindDescription(rows[j]); - } - if(("varbind_oid").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind OID").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setVarbindOID(rows[j]); + if(dictionaryName.startsWith("ClosedLoopSite")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + ClosedLoopSite attribute = new ClosedLoopSite("", userId); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("siteName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Site Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setSiteName(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("BRMSParamDictionary")){ - for(int i = 1; i< dictSheet.size(); i++){ - BRMSParamTemplate attribute = new BRMSParamTemplate(); - UserInfo userinfo = new UserInfo(); - userinfo.setUserLoginId(userId); - attribute.setUserCreatedBy(userinfo); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("param_template_name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Rule Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setRuleName(rows[j]); - } - if(("DESCRIPTION").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); - } - if(("rule").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setRule(rows[j]); + if(dictionaryName.startsWith("PEPOptions")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + PEPOptions attribute = new PEPOptions("", userId); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("PEP_NAME").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PEP Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setPepName(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } + if(("Actions").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setActions(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("Settings")){ - for(int i = 1; i< dictSheet.size(); i++){ - DecisionSettings attribute = new DecisionSettings("", userId); - UserInfo userinfo = new UserInfo(); - userinfo.setUserLoginId(userId); - attribute.setUserCreatedBy(userinfo); - attribute.setUserModifiedBy(userinfo); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("xacml_id").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Settings ID").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setXacmlId(rows[j]); - } - if(("description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); - } - if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setPriority(rows[j]); - } - if(("datatype").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Data Type").equalsIgnoreCase(dictSheet.get(0)[j])){ - Datatype dataType = new Datatype(); - if(("string").equalsIgnoreCase(rows[j])){ - dataType.setId(26); - }else if(("integer").equalsIgnoreCase(rows[j])){ - dataType.setId(12); - }else if(("double").equalsIgnoreCase(rows[j])){ - dataType.setId(25); - }else if(("boolean").equalsIgnoreCase(rows[j])){ - dataType.setId(18); - }else if(("user").equalsIgnoreCase(rows[j])){ - dataType.setId(29); - } - attribute.setDatatypeBean(dataType); + if(dictionaryName.startsWith("VarbindDictionary")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + VarbindDictionary attribute = new VarbindDictionary("", userId); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("varbind_Name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setVarbindName(rows[j]); + } + if(("varbind_Description").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind Description").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setVarbindDescription(rows[j]); + } + if(("varbind_oid").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Varbind OID").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setVarbindOID(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("PrefixList")){ - for(int i = 1; i< dictSheet.size(); i++){ - PrefixList attribute = new PrefixList("", userId); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("prefixListName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PrefixList Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setPrefixListName(rows[j]); - } - if(("description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setPrefixListValue(rows[j]); - } - if(("prefixListValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PrefixList Value").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); + if(dictionaryName.startsWith("BRMSParamDictionary")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + BRMSParamTemplate attribute = new BRMSParamTemplate(); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("param_template_name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Rule Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setRuleName(rows[j]); + } + if(("Description").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } + if(("rule").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setRule(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("SecurityZone")){ - for(int i = 1; i< dictSheet.size(); i++){ - SecurityZone attribute = new SecurityZone("", userId); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("zoneName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setZoneName(rows[j]); - } - if(("zoneValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Value").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setZoneValue(rows[j]); + if(dictionaryName.startsWith("BRMSControllerDictionary")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + BRMSController attribute = new BRMSController(); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("controllerName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Controller Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setControllerName(rows[j]); + } + if(("DESCRIPTION").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } + if(("controller").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setController(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("Zone")){ - for(int i = 1; i< dictSheet.size(); i++){ - Zone attribute = new Zone("", userId); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("zoneName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setZoneName(rows[j]); - } - if(("zoneValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Value").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setZoneValue(rows[j]); + if(dictionaryName.startsWith("BRMSDependencyDictionary")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + BRMSDependency attribute = new BRMSDependency(); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("dependencyName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Dependency Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDependencyName(rows[j]); + } + if(("DESCRIPTION").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } + if(("dependency").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDependency(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("ServiceList")){ - for(int i = 1; i< dictSheet.size(); i++){ - ServiceList attribute = new ServiceList("", userId); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("serviceName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setServiceName(rows[j]); - } - if(("serviceDesc").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setServiceDescription(rows[j]); - } - if(("serviceType").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service Type").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setServiceType(rows[j]); - } - if(("serviceTrasProtocol").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Transport Protocol").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setServiceTransProtocol(rows[j]); - } - if(("serviceAppProtocol").equalsIgnoreCase(dictSheet.get(0)[j]) || ("APP Protocol").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setServiceAppProtocol(rows[j]); - } - if(("servicePorts").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Ports").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setServicePorts(rows[j]); + if(dictionaryName.startsWith("Settings")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + DecisionSettings attribute = new DecisionSettings("", userId); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("xacml_id").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Settings ID").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setXacmlId(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } + if(("priority").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setPriority(rows[j]); + } + if(("datatype").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Data Type").equalsIgnoreCase(dictSheet.get(0)[j])){ + Datatype dataType = new Datatype(); + if(("string").equalsIgnoreCase(rows[j])){ + dataType.setId(26); + }else if(("integer").equalsIgnoreCase(rows[j])){ + dataType.setId(12); + }else if(("double").equalsIgnoreCase(rows[j])){ + dataType.setId(25); + }else if(("boolean").equalsIgnoreCase(rows[j])){ + dataType.setId(18); + }else if(("user").equalsIgnoreCase(rows[j])){ + dataType.setId(29); + } + attribute.setDatatypeBean(dataType); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("ServiceGroup")){ - for(int i = 1; i< dictSheet.size(); i++){ - GroupServiceList attribute = new GroupServiceList("", userId); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Group Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setGroupName(rows[j]); - } - if(("serviceList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service List").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setServiceList(rows[j]); + if(dictionaryName.startsWith("PrefixList")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + PrefixList attribute = new PrefixList("", userId); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("prefixListName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PrefixList Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setPrefixListName(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setPrefixListValue(rows[j]); + } + if(("prefixListValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("PrefixList Value").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("AddressGroup")){ - for(int i = 1; i< dictSheet.size(); i++){ - AddressGroup attribute = new AddressGroup("", userId); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Group Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setGroupName(rows[j]); - } - if(("serviceList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Prefix List").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setServiceList(rows[j]); - } - if(("description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); + if(dictionaryName.startsWith("SecurityZone")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + SecurityZone attribute = new SecurityZone("", userId); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("zoneName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setZoneName(rows[j]); + } + if(("zoneValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Value").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setZoneValue(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("ProtocolList")){ - for(int i = 1; i< dictSheet.size(); i++){ - ProtocolList attribute = new ProtocolList("", userId); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("protocolName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Protocol Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setProtocolName(rows[j]); - } - if(("description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); + if(dictionaryName.startsWith("Zone")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + Zone attribute = new Zone("", userId); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("zoneName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setZoneName(rows[j]); + } + if(("zoneValue").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Zone Value").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setZoneValue(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("ActionList")){ - for(int i = 1; i< dictSheet.size(); i++){ - ActionList attribute = new ActionList("", userId); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("actionName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Action Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setActionName(rows[j]); - } - if(("description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); + if(dictionaryName.startsWith("ServiceList")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + ServiceList attribute = new ServiceList("", userId); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("serviceName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setServiceName(rows[j]); + } + if(("serviceDesc").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Description").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setServiceDescription(rows[j]); + } + if(("serviceType").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service Type").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setServiceType(rows[j]); + } + if(("serviceTrasProtocol").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Transport Protocol").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setServiceTransProtocol(rows[j]); + } + if(("serviceAppProtocol").equalsIgnoreCase(dictSheet.get(0)[j]) || ("APP Protocol").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setServiceAppProtocol(rows[j]); + } + if(("servicePorts").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Ports").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setServicePorts(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("TermList")){ - for(int i = 1; i< dictSheet.size(); i++){ - TermList attribute = new TermList("", userId); - UserInfo userinfo = new UserInfo(); - userinfo.setUserLoginId(userId); - attribute.setUserCreatedBy(userinfo); - attribute.setUserModifiedBy(userinfo); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("termName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Term-Name").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setTermName(rows[j]); - } - if(("Term-Description").equalsIgnoreCase(dictSheet.get(0)[j]) || ("termDescription").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); - } - if(("fromZone").equalsIgnoreCase(dictSheet.get(0)[j]) || ("From Zone").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setFromZones(rows[j]); - } - if(("toZone").equalsIgnoreCase(dictSheet.get(0)[j]) || ("To Zone").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setToZones(rows[j]); - } - if(("srcIPList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Source-IP-List").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setSrcIPList(rows[j]); - } - if(("destIPList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Destination-IP-List").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDestIPList(rows[j]); - } - if(("srcPortList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Source-Port-List").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setSrcPortList(rows[j]); + if(dictionaryName.startsWith("ServiceGroup")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + GroupServiceList attribute = new GroupServiceList("", userId); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Group Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setGroupName(rows[j]); + } + if(("serviceList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Service List").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setServiceList(rows[j]); + } } - if(("destPortList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Destination-Port-List").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDestPortList(rows[j]); + commonClassDao.save(attribute); + } + } + if(dictionaryName.startsWith("AddressGroup")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + AddressGroup attribute = new AddressGroup("", userId); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("name").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Group Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setGroupName(rows[j]); + } + if(("serviceList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Prefix List").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setServiceList(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } } - if(("action").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Action List").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setAction(rows[j]); + commonClassDao.save(attribute); + } + } + if(dictionaryName.startsWith("ProtocolList")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + ProtocolList attribute = new ProtocolList("", userId); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("protocolName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Protocol Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setProtocolName(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - if(dictionaryName.startsWith("SearchCriteria")){ - for(int i = 1; i< dictSheet.size(); i++){ - DescriptiveScope attribute = new DescriptiveScope("", userId); - UserInfo userinfo = new UserInfo(); - userinfo.setUserLoginId(userId); - attribute.setUserCreatedBy(userinfo); - attribute.setUserModifiedBy(userinfo); - String[] rows = dictSheet.get(i); - for (int j=0 ; j<rows.length; j++ ){ - if(("descriptiveScopeName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Descriptive ScopeName").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setScopeName(rows[j]); + if(dictionaryName.startsWith("ActionList")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + ActionList attribute = new ActionList("", userId); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("actionName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Action Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setActionName(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } } - if(("description").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setDescription(rows[j]); + commonClassDao.save(attribute); + } + } + if(dictionaryName.startsWith("TermList")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + TermList attribute = new TermList("", userId); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("termName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Term-Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setTermName(rows[j]); + } + if(("Term-Description").equalsIgnoreCase(dictSheet.get(0)[j]) || ("termDescription").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } + if(("fromZone").equalsIgnoreCase(dictSheet.get(0)[j]) || ("From Zone").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setFromZones(rows[j]); + } + if(("toZone").equalsIgnoreCase(dictSheet.get(0)[j]) || ("To Zone").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setToZones(rows[j]); + } + if(("srcIPList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Source-IP-List").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setSrcIPList(rows[j]); + } + if(("destIPList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Destination-IP-List").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDestIPList(rows[j]); + } + if(("srcPortList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Source-Port-List").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setSrcPortList(rows[j]); + } + if(("destPortList").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Destination-Port-List").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDestPortList(rows[j]); + } + if(("action").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Action List").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setAction(rows[j]); + } } - if(("search").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Search Criteria").equalsIgnoreCase(dictSheet.get(0)[j])){ - attribute.setSearch(rows[j]); + commonClassDao.save(attribute); + } + } + if(dictionaryName.startsWith("SearchCriteria")){ + dictionaryImportExists = true; + for(int i = 1; i< dictSheet.size(); i++){ + DescriptiveScope attribute = new DescriptiveScope("", userId); + UserInfo userinfo = new UserInfo(); + userinfo.setUserLoginId(userId); + attribute.setUserCreatedBy(userinfo); + attribute.setUserModifiedBy(userinfo); + String[] rows = dictSheet.get(i); + for (int j=0 ; j<rows.length; j++ ){ + if(("descriptiveScopeName").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Descriptive Scope Name").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setScopeName(rows[j]); + } + if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setDescription(rows[j]); + } + if(("search").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Search Criteria").equalsIgnoreCase(dictSheet.get(0)[j])){ + attribute.setSearch(rows[j]); + } } + commonClassDao.save(attribute); } - commonClassDao.save(attribute); } - } - csvReader.close(); - if(file.exists()){ - file.delete(); + csvReader.close(); + if(file.exists()){ + file.delete(); + } + if(!dictionaryImportExists){ + response.setStatus(HttpServletResponse.SC_OK); + response.getWriter().write("Dictionary Import failed. Hence the following dictionary doen't support import function : "+ dictionaryName); + }else{ + response.setStatus(HttpServletResponse.SC_OK); + response.getWriter().write("Success"); + } + }catch(Exception e){ + LOGGER.error("Exception Occured while importing dictionary"+e); + response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); + response.getWriter().write("Error"); } } -} +}
\ No newline at end of file diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java index cd4c1a435..9e248bf62 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java @@ -37,6 +37,7 @@ import org.onap.policy.common.logging.flexlogger.Logger; import org.onap.policy.pap.xacml.rest.util.JsonMessage; import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.EnforcingType; +import org.onap.policy.utils.PolicyUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -104,7 +105,7 @@ public class EnforcerDictionaryController { response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); LOGGER.error(e); } return null; @@ -135,7 +136,7 @@ public class EnforcerDictionaryController { response.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java index 3a4d7b71b..6b60c586a 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java @@ -54,6 +54,7 @@ import org.onap.policy.rest.jpa.ServiceList; import org.onap.policy.rest.jpa.TermList; import org.onap.policy.rest.jpa.UserInfo; import org.onap.policy.rest.jpa.Zone; +import org.onap.policy.utils.PolicyUtils; import org.onap.policy.xacml.api.XACMLErrorConstants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -228,7 +229,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -256,7 +257,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -289,7 +290,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -353,7 +354,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -381,7 +382,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -496,7 +497,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -525,7 +526,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -666,7 +667,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -695,7 +696,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -816,7 +817,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -844,7 +845,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -986,7 +987,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -1016,7 +1017,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -1132,7 +1133,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -1162,7 +1163,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -1312,7 +1313,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; @@ -1343,7 +1344,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -1456,7 +1457,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -1486,7 +1487,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -1682,11 +1683,13 @@ public class FirewallDictionaryController { }else{ termList.setUserCreatedBy(this.getUserInfo(userId)); termList.setUserModifiedBy(this.getUserInfo(userId)); + termList.setCreatedDate(new Date()); commonClassDao.save(termList); } }else{ if(!isFakeUpdate) { termList.setUserModifiedBy(this.getUserInfo(userId)); + termList.setModifiedDate(new Date()); commonClassDao.update(termList); } } @@ -1723,7 +1726,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -1753,7 +1756,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -1863,7 +1866,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -1893,7 +1896,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -1922,6 +1925,8 @@ public class FirewallDictionaryController { model.put("fwTagPickerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader(successMapKey, successMessage); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ @@ -1933,58 +1938,55 @@ public class FirewallDictionaryController { public ModelAndView saveFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; + boolean isFakeUpdate = false; boolean fromAPI = false; - if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) { + if (request.getParameter("apiflag")!=null && ("api").equalsIgnoreCase (request.getParameter("apiflag"))) { fromAPI = true; } - ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); - - FWTagPicker fwTagPicker; - TagGridValues data; - String userId = null; + + String userId = ""; if (fromAPI) { - fwTagPicker = (FWTagPicker)mapper.readValue(root.get(fwTagPickerDictionaryData).toString(), FWTagPicker.class); - data = (TagGridValues)mapper.readValue(root.get(fwTagPickerDictionaryData).toString(), TagGridValues.class); + fwTagPicker = (FWTagPicker)mapper.readValue(root.get("dictionaryFields").toString(), FWTagPicker.class); userId = "API"; - //check if update operation or create, get id for data to be updated and update attributeData - if ((update).equals(request.getParameter(operation))) { - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), tagPickerName, FWTagPicker.class); + if (("update").equals(request.getParameter("operation"))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), "tagPickerName", FWTagPicker.class); + int id = 0; FWTagPicker dbdata = (FWTagPicker) duplicateData.get(0); - int id = dbdata.getId(); + id = dbdata.getId(); fwTagPicker.setId(id); fwTagPicker.setUserCreatedBy(this.getUserInfo(userId)); } } else { - - fwTagPicker = (FWTagPicker)mapper.readValue(root.get(fwTagPickerDictionaryData).toString(), FWTagPicker.class); - data = (TagGridValues)mapper.readValue(root.get(fwTagPickerDictionaryData).toString(), TagGridValues.class); - userId = root.get(userid).textValue(); - } - - String header = ""; - int counter = 0; - if(!data.getTags().isEmpty()){ - for(Object attribute : data.getTags()){ - if(attribute instanceof LinkedHashMap<?, ?>){ - String key = ((LinkedHashMap<?, ?>) attribute).get(option).toString(); - String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString(); - if(counter>0){ - header = header + "#"; + TagGridValues data; + fwTagPicker = (FWTagPicker)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class); + data = (TagGridValues)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class); + userId = root.get("userid").textValue(); + + StringBuilder header = new StringBuilder(); + int counter = 0; + if(!data.getTags().isEmpty()){ + for(Object attribute : data.getTags()){ + if(attribute instanceof LinkedHashMap<?, ?>){ + String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString(); + String value = ((LinkedHashMap<?, ?>) attribute).get("number").toString(); + if(counter>0){ + header.append("#"); + } + header.append(key+":"+value); + counter ++; } - header = header + key + ":"; - header = header + value; - counter ++; } } + fwTagPicker.setTagValues(header.toString()); } - fwTagPicker.setTagValues(header); + if(fwTagPicker.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), tagPickerName, FWTagPicker.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), "tagPickerName", FWTagPicker.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -1997,7 +1999,6 @@ public class FirewallDictionaryController { fwTagPicker.setModifiedDate(new Date()); commonClassDao.update(fwTagPicker); } - String responseString = ""; if(duplicateflag){ responseString = duplicateResponseString; @@ -2028,7 +2029,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -2056,33 +2057,34 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } - - @RequestMapping(value={"/get_TagNameByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTagNameEntityDataByName(HttpServletResponse response){ + @RequestMapping(value={"/get_TagListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getTagDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put(fwTagDictionaryDatas, mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTag.class, "fwTagName"))); + model.put(fwTagDictionaryDatas, mapper.writeValueAsString(commonClassDao.getData(FWTag.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); + response.addHeader(successMapKey, successMessage); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); } } - - @RequestMapping(value={"/get_TagListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTagDictionaryEntityData(HttpServletResponse response){ + + @RequestMapping(value={"/get_TagNameByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) + public void getTagNameEntityDataByName(HttpServletRequest request, HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put(fwTagDictionaryDatas, mapper.writeValueAsString(commonClassDao.getData(FWTag.class))); + model.put("fwTagDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTag.class, "fwTagName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -2092,6 +2094,7 @@ public class FirewallDictionaryController { } } + @RequestMapping(value={"/fw_dictionary/save_fwTag"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) public ModelAndView saveFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { @@ -2100,50 +2103,47 @@ public class FirewallDictionaryController { if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) { fromAPI = true; } - ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); - - FWTag fwTag; - TagGridValues tagGridValues; - String userId = null; + + String userId=""; if (fromAPI) { - fwTag = (FWTag)mapper.readValue(root.get(fwTagDictionaryDatas).toString(), FWTag.class); - tagGridValues = (TagGridValues)mapper.readValue(root.get(fwTagDictionaryDatas).toString(), TagGridValues.class); + fwTag = mapper.readValue(root.get("dictionaryFields").toString(), FWTag.class); userId = "API"; - //check if update operation or create, get id for data to be updated and update attributeData - if ((update).equals(request.getParameter(operation))) { - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "tagName", FWTag.class); + if ("update".equals(request.getParameter("operation"))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "fwTagName", FWTag.class); + int id = 0; FWTag data = (FWTag) duplicateData.get(0); - int id = data.getId(); + id = data.getId(); fwTag.setId(id); fwTag.setUserCreatedBy(this.getUserInfo(userId)); - } } else { - fwTag = (FWTag)mapper.readValue(root.get("fwTagDictionaryData").toString(), FWTag.class); - tagGridValues = (TagGridValues)mapper.readValue(root.get("fwTagDictionaryData").toString(), TagGridValues.class); - userId = root.get(userid).textValue(); - } - - String userValue = ""; - int counter = 0; - if(!tagGridValues.getTags().isEmpty()){ - for(Object attribute : tagGridValues.getTags()){ - if(attribute instanceof LinkedHashMap<?, ?>){ - String key = ((LinkedHashMap<?, ?>) attribute).get("tags").toString(); - if(counter>0){ - userValue = userValue + ","; + TagGridValues tagGridValues; + fwTag = mapper.readValue(root.get("fwTagDictionaryData").toString(), FWTag.class); + tagGridValues = mapper.readValue(root.get("fwTagDictionaryData").toString(), TagGridValues.class); + userId = root.get("userid").textValue(); + + StringBuilder userValue = new StringBuilder(); + int counter = 0; + if(!tagGridValues.getTags().isEmpty()){ + for(Object attribute : tagGridValues.getTags()){ + if(attribute instanceof LinkedHashMap<?, ?>){ + String key = ((LinkedHashMap<?, ?>) attribute).get("tags").toString(); + if(counter>0){ + userValue.append(","); + } + userValue.append(key); + counter ++; } - userValue = userValue + key ; - counter ++; } } + fwTag.setTagValues(userValue.toString()); } - fwTag.setTagValues(userValue); + if(fwTag.getId() == 0){ List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "fwTagName", FWTag.class); if(!duplicateData.isEmpty()){ @@ -2151,20 +2151,22 @@ public class FirewallDictionaryController { }else{ fwTag.setUserCreatedBy(this.getUserInfo(userId)); fwTag.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.save(fwTag); - } + } }else{ - fwTag.setUserModifiedBy(this.getUserInfo(userId)); - fwTag.setModifiedDate(new Date()); - commonClassDao.update(fwTag); + + fwTag.setUserModifiedBy(this.getUserInfo(userId)); + commonClassDao.update(fwTag); + } - String responseString = ""; if(duplicateflag){ - responseString = duplicateResponseString; + responseString = "Duplicate"; }else{ - responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class)); + responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class)); } + if (fromAPI) { if (responseString!=null && !(duplicateResponseString).equals(responseString)) { responseString = successMsg; @@ -2189,7 +2191,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -2219,7 +2221,7 @@ public class FirewallDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java index 0170a71e0..2eca73ea5 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java @@ -47,6 +47,7 @@ import org.onap.policy.rest.jpa.MicroServiceModels; import org.onap.policy.rest.jpa.UserInfo; import org.onap.policy.rest.util.MSAttributeObject; import org.onap.policy.rest.util.MSModelUtils; +import org.onap.policy.utils.PolicyUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -216,7 +217,7 @@ public class MicroServiceDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); LOGGER.error(e); } return null; @@ -247,7 +248,7 @@ public class MicroServiceDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -365,7 +366,7 @@ public class MicroServiceDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); LOGGER.error(e); } return null; @@ -396,7 +397,7 @@ public class MicroServiceDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -511,7 +512,7 @@ public class MicroServiceDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); LOGGER.error(e); } return null; @@ -542,7 +543,7 @@ public class MicroServiceDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -657,7 +658,7 @@ public class MicroServiceDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); LOGGER.error(e); } return null; @@ -688,7 +689,7 @@ public class MicroServiceDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -965,7 +966,7 @@ public class MicroServiceDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); LOGGER.error(e); } return null; @@ -996,7 +997,7 @@ public class MicroServiceDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java index 2715d581b..4b2f299a5 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java @@ -42,6 +42,7 @@ import org.onap.policy.rest.jpa.PolicyScopeResource; import org.onap.policy.rest.jpa.PolicyScopeService; import org.onap.policy.rest.jpa.PolicyScopeType; import org.onap.policy.rest.jpa.UserInfo; +import org.onap.policy.utils.PolicyUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -268,7 +269,7 @@ public class PolicyScopeDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -298,7 +299,7 @@ public class PolicyScopeDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -420,7 +421,7 @@ public class PolicyScopeDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); LOGGER.error(e); } return null; @@ -451,7 +452,7 @@ public class PolicyScopeDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -570,7 +571,7 @@ public class PolicyScopeDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); LOGGER.error(e); } return null; @@ -601,7 +602,7 @@ public class PolicyScopeDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -726,7 +727,7 @@ public class PolicyScopeDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); LOGGER.error(e); } return null; @@ -757,7 +758,7 @@ public class PolicyScopeDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -880,7 +881,7 @@ public class PolicyScopeDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -910,7 +911,7 @@ public class PolicyScopeDictionaryController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java index 885a6117f..a695ec389 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java @@ -86,7 +86,7 @@ public class PushPolicyController { requestID = UUID.randomUUID().toString(); LOGGER.info("No request ID provided, sending generated ID: " + requestID); } - LOGGER.info("Push policy Request : " + root.asText()); + LOGGER.info("Push policy Request to get the selectedPolicy : " + root.asText()); String policyVersionName = policyScope.replace(".", File.separator) + File.separator + filePrefix + policyName; List<?> policyVersionObject = commonClassDao.getDataById(PolicyVersion.class, policyNames, policyVersionName); @@ -116,7 +116,7 @@ public class PushPolicyController { private void addPolicyToGroup(String policyScope, String policyID, String policyName, String pdpGroup, HttpServletResponse response) { StdPDPGroup selectedPDPGroup = null; StdPDPPolicy selectedPolicy = null; - //Get the current policies from the Group and Add the new one + //Get the selected PDP Group to push the policy try { selectedPDPGroup = (StdPDPGroup) XACMLPapServlet.getPAPEngine().getGroup(pdpGroup); } catch (PAPException e1) { @@ -127,6 +127,9 @@ public class PushPolicyController { PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); response.addHeader(errorMsg, "unknownGroupId"); response.addHeader(operation, "push"); + //for fixing Header Manipulation of Fortify issue + message = message.replace("\n", ""); + message = message.replace("\r", ""); response.addHeader(messageContent, message); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; @@ -159,7 +162,7 @@ public class PushPolicyController { // Create the policy Object selectedPolicy = new StdPDPPolicy(policyName, true, policyID, selectedURI); } catch (IOException e) { - LOGGER.error("Unable to create policy '" + policyName + "': "+ e.getMessage(),e); + LOGGER.error("Unable to get policy '" + policyName + "': "+ e.getMessage(),e); } try { new ObjectOutputStream(response.getOutputStream()).writeObject(selectedPolicy); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyController.java index 1ad304cc7..02d53c6b4 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyController.java @@ -38,6 +38,7 @@ import org.onap.policy.rest.dao.CommonClassDao; import org.onap.policy.rest.jpa.RiskType; import org.onap.policy.rest.jpa.SafePolicyWarning; import org.onap.policy.rest.jpa.UserInfo; +import org.onap.policy.utils.PolicyUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; @@ -195,7 +196,7 @@ public class SafePolicyController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -226,7 +227,7 @@ public class SafePolicyController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -349,7 +350,7 @@ public class SafePolicyController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } @@ -381,7 +382,7 @@ public class SafePolicyController { response.setCharacterEncoding(utf8); request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); - out.write(e.getMessage()); + out.write(PolicyUtils.CATCH_EXCEPTION); } return null; } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java index 76fe4ae5d..415c7792d 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/policycontroller/PolicyCreation.java @@ -20,6 +20,7 @@ package org.onap.policy.pap.xacml.rest.policycontroller; import java.io.File; +import java.util.Date; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; @@ -184,6 +185,7 @@ public class PolicyCreation extends AbstractPolicyCreation{ policyVersionDao.setActiveVersion(version); policyVersionDao.setHigherVersion(version); policyVersionDao.setModifiedBy(modifiedBy); + policyVersionDao.setModifiedDate(new Date()); }else{ body = "policyExists"; status = HttpStatus.CONFLICT; @@ -229,14 +231,12 @@ public class PolicyCreation extends AbstractPolicyCreation{ policyData.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides"); if(policyData.getApiflag() == null){ //set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON - if(policyData.getAttributes() != null){ - if(policyData.getAttributes().size() > 0){ - for(Object attribute : policyData.getAttributes()){ - if(attribute instanceof LinkedHashMap<?, ?>){ - String key = ((LinkedHashMap<?, ?>) attribute).get("key").toString(); - String value = ((LinkedHashMap<?, ?>) attribute).get("value").toString(); - attributeMap.put(key, value); - } + if(policyData.getAttributes() != null && !policyData.getAttributes().isEmpty()){ + for(Object attribute : policyData.getAttributes()){ + if(attribute instanceof LinkedHashMap<?, ?>){ + String key = ((LinkedHashMap<?, ?>) attribute).get("key").toString(); + String value = ((LinkedHashMap<?, ?>) attribute).get("value").toString(); + attributeMap.put(key, value); } } } @@ -312,7 +312,7 @@ public class PolicyCreation extends AbstractPolicyCreation{ List<String> dynamicRuleAlgorithmField2 = new LinkedList<>(); - if(policyData.getRuleAlgorithmschoices().size() > 0){ + if(!policyData.getRuleAlgorithmschoices().isEmpty()){ for(Object attribute : policyData.getRuleAlgorithmschoices()){ if(attribute instanceof LinkedHashMap<?, ?>){ String label = ((LinkedHashMap<?, ?>) attribute).get("id").toString(); @@ -329,22 +329,35 @@ public class PolicyCreation extends AbstractPolicyCreation{ String actionDictValue = policyData.getActionAttributeValue(); ActionPolicyDict jsonData = ((ActionPolicyDict) commonClassDao.getEntityItem(ActionPolicyDict.class, "attributeName", actionDictValue)); - String actionBodyString = jsonData.getBody(); - String actionDictHeader = jsonData.getHeader(); - String actionDictType = jsonData.getType(); - String actionDictUrl = jsonData.getUrl(); - String actionDictMethod = jsonData.getMethod(); - policyData.setActionDictHeader(actionDictHeader); - policyData.setActionDictType(actionDictType); - policyData.setActionDictUrl(actionDictUrl); - policyData.setActionDictMethod(actionDictMethod); + if(jsonData!=null){ + String actionBodyString = jsonData.getBody(); + String actionDictHeader = jsonData.getHeader(); + String actionDictType = jsonData.getType(); + String actionDictUrl = jsonData.getUrl(); + String actionDictMethod = jsonData.getMethod(); + policyData.setActionDictHeader(actionDictHeader); + policyData.setActionDictType(actionDictType); + policyData.setActionDictUrl(actionDictUrl); + policyData.setActionDictMethod(actionDictMethod); + if (actionBodyString != null) { + policyData.setActionBody(actionBodyString); + } + } policyData.setActionAttribute(actionDictValue); policyData.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels); policyData.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo); policyData.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1); policyData.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2); - if (actionBodyString != null) { - policyData.setActionBody(actionBodyString); + }else{ + // API request. + String comboDictValue = policyData.getActionAttribute(); + ActionPolicyDict jsonData = ((ActionPolicyDict) commonClassDao.getEntityItem(ActionPolicyDict.class, "attributeName", comboDictValue)); + if(jsonData!=null){ + policyData.setActionBody(jsonData.getBody()); + policyData.setActionDictHeader(jsonData.getHeader()); + policyData.setActionDictType(jsonData.getType()); + policyData.setActionDictUrl(jsonData.getUrl()); + policyData.setActionDictMethod(jsonData.getMethod()); } } newPolicy = new ActionPolicy(policyData); |