summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java
diff options
context:
space:
mode:
Diffstat (limited to 'ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java369
1 files changed, 149 insertions, 220 deletions
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 142f72b97..f3c78ffb9 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
@@ -19,10 +19,7 @@
*/
package org.onap.policy.pap.xacml.rest.controller;
- /*
- *
- *
- * */
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
@@ -36,7 +33,7 @@ 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.pap.xacml.rest.DisctionaryNames;
+import org.onap.policy.pap.xacml.rest.DictionaryNames;
import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.ActionList;
import org.onap.policy.rest.jpa.ActionPolicyDict;
@@ -68,6 +65,7 @@ import org.onap.policy.rest.jpa.Zone;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -79,8 +77,6 @@ import au.com.bytecode.opencsv.CSVReader;
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";
@@ -89,11 +85,13 @@ public class DictionaryImportController {
DictionaryImportController.commonClassDao = commonClassDao;
}
- public DictionaryImportController(){}
+ public DictionaryImportController(){
+ super();
+ }
- @RequestMapping(value={"/dictionary/import_dictionary"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
- public void ImportDictionaryData(HttpServletRequest request, HttpServletResponse response) throws IOException{
+ @RequestMapping(value={"/dictionary/import_dictionary"}, method={RequestMethod.POST})
+ 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");
@@ -109,22 +107,16 @@ public class DictionaryImportController {
// fix Fortify Path Manipulation issue
if(!isValidDictionaryName(dictionaryName)){
LOGGER.error("dictionaryName is invalid");
- response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
- response.getWriter().write("Error");
+ response.setStatus(HttpServletResponse.SC_OK);
+ response.getWriter().write("Dictionary Import failed. Hence the following dictionary doen't support import function : "+ dictionaryName);
return;
}
-
- boolean dictionaryImportExists = false;
- try{
- File file = new File(dictionaryName);
- OutputStream outputStream = new FileOutputStream(file);
+ File file = new File(dictionaryName);
+ try(OutputStream outputStream = new FileOutputStream(file); FileReader fileReader = new FileReader(file.toString())){
IOUtils.copy(request.getInputStream(), outputStream);
- outputStream.close();
- this.newFile = file.toString();
- CSVReader csvReader = new CSVReader(new FileReader(this.newFile));
+ CSVReader csvReader = new CSVReader(fileReader);
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();
@@ -133,26 +125,26 @@ public class DictionaryImportController {
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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
- if(("priority").equalsIgnoreCase(dictSheet.get(0)[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])){
+ if("datatype".equalsIgnoreCase(dictSheet.get(0)[j]) || "Data Type".equalsIgnoreCase(dictSheet.get(0)[j])){
Datatype dataType = new Datatype();
- if(("string").equalsIgnoreCase(rows[j])){
+ if("string".equalsIgnoreCase(rows[j])){
dataType.setId(26);
- }else if(("integer").equalsIgnoreCase(rows[j])){
+ }else if("integer".equalsIgnoreCase(rows[j])){
dataType.setId(12);
- }else if(("double").equalsIgnoreCase(rows[j])){
+ }else if("double".equalsIgnoreCase(rows[j])){
dataType.setId(25);
- }else if(("boolean").equalsIgnoreCase(rows[j])){
+ }else if("boolean".equalsIgnoreCase(rows[j])){
dataType.setId(18);
- }else if(("user").equalsIgnoreCase(rows[j])){
+ }else if("user".equalsIgnoreCase(rows[j])){
dataType.setId(29);
}
attribute.setDatatypeBean(dataType);
@@ -160,7 +152,7 @@ public class DictionaryImportController {
category.setId(5);
attribute.setCategoryBean(category);
}
- if(("attribute_value").equalsIgnoreCase(dictSheet.get(0)[j]) || ("Attribute Value").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("attribute_value".equalsIgnoreCase(dictSheet.get(0)[j]) || "Attribute Value".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setAttributeValue(rows[j]);
}
}
@@ -168,7 +160,6 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("ActionPolicyDictionary")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
ActionPolicyDict attribute = new ActionPolicyDict();
UserInfo userinfo = new UserInfo();
@@ -177,25 +168,25 @@ public class DictionaryImportController {
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])){
+ 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])){
+ if("body".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setBody(rows[j]);
}
- if((DESCRIPTION).equalsIgnoreCase(dictSheet.get(0)[j])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
- if(("headers").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("headers".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setHeader(rows[j]);
}
- if(("method").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("method".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setMethod(rows[j]);
}
- if(("type").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("type".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setType(rows[j]);
}
- if(("url").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("url".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setUrl(rows[j]);
}
}
@@ -203,7 +194,6 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("OnapName")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
OnapName attribute = new OnapName();
UserInfo userinfo = new UserInfo();
@@ -212,10 +202,10 @@ public class DictionaryImportController {
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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
}
@@ -224,7 +214,6 @@ public class DictionaryImportController {
}
if(dictionaryName.startsWith("MSPolicyDictionary")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
MicroServiceModels attribute = new MicroServiceModels();
UserInfo userinfo = new UserInfo();
@@ -232,28 +221,28 @@ public class DictionaryImportController {
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])){
+ 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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
- if(("dependency").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("dependency".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDependency(rows[j]);
}
- if(("attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setAttributes(rows[j]);
}
- if(("enumValues").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("enumValues".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setEnumValues(rows[j]);
}
- if(("Ref Attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("Ref Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setRef_attributes(rows[j]);
}
- if(("Sub Attributes").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("Sub Attributes".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setSub_attributes(rows[j]);
}
}
@@ -263,7 +252,6 @@ public class DictionaryImportController {
}
if(dictionaryName.startsWith("VNFType")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
VNFType attribute = new VNFType();
UserInfo userinfo = new UserInfo();
@@ -272,10 +260,10 @@ public class DictionaryImportController {
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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
}
@@ -283,7 +271,6 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("VSCLAction")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
VSCLAction attribute = new VSCLAction();
UserInfo userinfo = new UserInfo();
@@ -292,10 +279,10 @@ public class DictionaryImportController {
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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
}
@@ -303,7 +290,6 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("ClosedLoopService")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
ClosedLoopD2Services attribute = new ClosedLoopD2Services();
UserInfo userinfo = new UserInfo();
@@ -312,10 +298,10 @@ public class DictionaryImportController {
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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
}
@@ -323,7 +309,6 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("ClosedLoopSite")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
ClosedLoopSite attribute = new ClosedLoopSite();
UserInfo userinfo = new UserInfo();
@@ -332,10 +317,10 @@ public class DictionaryImportController {
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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
}
@@ -343,7 +328,6 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("PEPOptions")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
PEPOptions attribute = new PEPOptions();
UserInfo userinfo = new UserInfo();
@@ -352,13 +336,13 @@ public class DictionaryImportController {
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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
- if(("Actions").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("Actions".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setActions(rows[j]);
}
}
@@ -366,7 +350,6 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("VarbindDictionary")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
VarbindDictionary attribute = new VarbindDictionary();
UserInfo userinfo = new UserInfo();
@@ -375,13 +358,13 @@ public class DictionaryImportController {
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])){
+ 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])){
+ 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])){
+ if("varbind_oid".equalsIgnoreCase(dictSheet.get(0)[j]) || "Varbind OID".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setVarbindOID(rows[j]);
}
}
@@ -389,7 +372,6 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("BRMSParamDictionary")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
BRMSParamTemplate attribute = new BRMSParamTemplate();
UserInfo userinfo = new UserInfo();
@@ -397,13 +379,13 @@ public class DictionaryImportController {
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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
- if(("rule").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("rule".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setRule(rows[j]);
}
}
@@ -411,7 +393,6 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("BRMSControllerDictionary")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
BRMSController attribute = new BRMSController();
UserInfo userinfo = new UserInfo();
@@ -419,13 +400,13 @@ public class DictionaryImportController {
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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
- if(("controller").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("controller".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setController(rows[j]);
}
}
@@ -433,7 +414,6 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("BRMSDependencyDictionary")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
BRMSDependency attribute = new BRMSDependency();
UserInfo userinfo = new UserInfo();
@@ -441,13 +421,13 @@ public class DictionaryImportController {
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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
- if(("dependency").equalsIgnoreCase(dictSheet.get(0)[j])){
+ if("dependency".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDependency(rows[j]);
}
}
@@ -455,7 +435,6 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("Settings")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
DecisionSettings attribute = new DecisionSettings();
UserInfo userinfo = new UserInfo();
@@ -464,26 +443,26 @@ public class DictionaryImportController {
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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
- if(("priority").equalsIgnoreCase(dictSheet.get(0)[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])){
+ if("datatype".equalsIgnoreCase(dictSheet.get(0)[j]) || "Data Type".equalsIgnoreCase(dictSheet.get(0)[j])){
Datatype dataType = new Datatype();
- if(("string").equalsIgnoreCase(rows[j])){
+ if("string".equalsIgnoreCase(rows[j])){
dataType.setId(26);
- }else if(("integer").equalsIgnoreCase(rows[j])){
+ }else if("integer".equalsIgnoreCase(rows[j])){
dataType.setId(12);
- }else if(("double").equalsIgnoreCase(rows[j])){
+ }else if("double".equalsIgnoreCase(rows[j])){
dataType.setId(25);
- }else if(("boolean").equalsIgnoreCase(rows[j])){
+ }else if("boolean".equalsIgnoreCase(rows[j])){
dataType.setId(18);
- }else if(("user").equalsIgnoreCase(rows[j])){
+ }else if("user".equalsIgnoreCase(rows[j])){
dataType.setId(29);
}
attribute.setDatatypeBean(dataType);
@@ -493,18 +472,17 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("PrefixList")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
PrefixList attribute = new PrefixList();
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])){
+ 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])){
+ 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])){
+ if("prefixListValue".equalsIgnoreCase(dictSheet.get(0)[j]) || "PrefixList Value".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
}
@@ -512,15 +490,14 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("SecurityZone")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
SecurityZone attribute = new SecurityZone();
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])){
+ 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])){
+ if("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setZoneValue(rows[j]);
}
}
@@ -528,15 +505,14 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("Zone")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
Zone attribute = new Zone();
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])){
+ 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])){
+ if("zoneValue".equalsIgnoreCase(dictSheet.get(0)[j]) || "Zone Value".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setZoneValue(rows[j]);
}
}
@@ -544,27 +520,26 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("ServiceList")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
ServiceList attribute = new ServiceList();
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])){
+ 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])){
+ 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])){
+ 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])){
+ 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])){
+ 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])){
+ if("servicePorts".equalsIgnoreCase(dictSheet.get(0)[j]) || "Ports".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setServicePorts(rows[j]);
}
}
@@ -572,15 +547,14 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("ServiceGroup")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
GroupServiceList attribute = new GroupServiceList();
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])){
+ 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])){
+ if("serviceList".equalsIgnoreCase(dictSheet.get(0)[j]) || "Service List".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setServiceList(rows[j]);
}
}
@@ -588,18 +562,17 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("AddressGroup")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
AddressGroup attribute = new AddressGroup();
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])){
+ 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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
}
@@ -607,15 +580,14 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("ProtocolList")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
ProtocolList attribute = new ProtocolList();
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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
}
@@ -623,15 +595,14 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("ActionList")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
ActionList attribute = new ActionList();
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])){
+ 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])){
+ if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setDescription(rows[j]);
}
}
@@ -639,7 +610,6 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("TermList")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
TermList attribute = new TermList();
UserInfo userinfo = new UserInfo();
@@ -648,31 +618,31 @@ public class DictionaryImportController {
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])){
+ 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])){
+ 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])){
+ 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])){
+ 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])){
+ 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])){
+ 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])){
+ 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])){
+ 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])){
+ if("action".equalsIgnoreCase(dictSheet.get(0)[j]) || "Action List".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setAction(rows[j]);
}
}
@@ -680,7 +650,6 @@ public class DictionaryImportController {
}
}
if(dictionaryName.startsWith("SearchCriteria")){
- dictionaryImportExists = true;
for(int i = 1; i< dictSheet.size(); i++){
DescriptiveScope attribute = new DescriptiveScope();
UserInfo userinfo = new UserInfo();
@@ -689,13 +658,13 @@ public class DictionaryImportController {
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])){
+ 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])){
+ 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])){
+ if("search".equalsIgnoreCase(dictSheet.get(0)[j]) || "Search Criteria".equalsIgnoreCase(dictSheet.get(0)[j])){
attribute.setSearch(rows[j]);
}
}
@@ -703,97 +672,57 @@ public class DictionaryImportController {
}
}
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");
- }
+ 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");
+ }finally{
+ if(file != null && file.exists()){
+ boolean deleted = file.delete();
+ LOGGER.error("Imported File has been deleted: "+deleted);
+ }
}
}
public boolean isValidDictionaryName(String dictionaryName){
- if(dictionaryName.startsWith(DisctionaryNames.Attribute.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.ActionPolicyDictionary.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.OnapName.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.MSPolicyDictionary.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.VNFType.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.VSCLAction.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.ClosedLoopService.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.ClosedLoopSite.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.PEPOptions.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.VarbindDictionary.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.BRMSParamDictionary.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.BRMSControllerDictionary.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.BRMSDependencyDictionary.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.Settings.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.PrefixList.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.SecurityZone.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.Zone.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.ServiceList.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.ServiceGroup.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.AddressGroup.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.ProtocolList.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.ActionList.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.TermList.toString())){
- return true;
- }
- if(dictionaryName.startsWith(DisctionaryNames.SearchCriteria.toString())){
- return true;
- }
- return false;
+ String nameCheck = dictionaryName.replace(".csv", "");
+ try{
+ DictionaryNames mode = DictionaryNames.valueOf(nameCheck);
+ switch (mode){
+ case Attribute:
+ case ActionPolicyDictionary:
+ case OnapName:
+ case MSPolicyDictionary:
+ case VNFType:
+ case VSCLAction:
+ case ClosedLoopService:
+ case ClosedLoopSite:
+ case PEPOptions:
+ case VarbindDictionary:
+ case BRMSParamDictionary:
+ case BRMSControllerDictionary:
+ case BRMSDependencyDictionary:
+ case Settings:
+ case PrefixList:
+ case SecurityZone:
+ case Zone:
+ case ServiceList:
+ case ServiceGroup:
+ case AddressGroup:
+ case ProtocolList:
+ case ActionList:
+ case TermList:
+ case SearchCriteria:
+ return true;
+ default:
+ return false;
+ }
+ }catch(Exception e){
+ LOGGER.error("Dictionary not exits: " +dictionaryName +e);
+ return false;
+ }
}
} \ No newline at end of file