Convert tabs to space in ONAP PAP REST1 99/58699/1
authorKrishnajinka <kris.jinka@samsung.com>
Thu, 2 Aug 2018 11:55:10 +0000 (20:55 +0900)
committerKrishnajinka <kris.jinka@samsung.com>
Thu, 2 Aug 2018 11:55:23 +0000 (20:55 +0900)
Modify tabs to space for checkstyle issue fix in ONAP PAP REST
module. It helps future reviews and refactoring

Issue-ID: POLICY-1014
Change-Id: Idcf45689565f039c76a3ef0f40ad9a46b41bd8d6
Signed-off-by: Krishnajinka <kris.jinka@samsung.com>
29 files changed:
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/adapters/GridData.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/adapters/SearchData.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/adapters/UpdateObjectData.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ActionPolicy.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ClosedLoopPolicy.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBRMSRuleTemplate.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsParamPolicy.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateBrmsRawPolicy.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateClosedLoopPerformanceMetrics.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewOptimizationModel.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/DecisionPolicy.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/FirewallConfigPolicy.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/OptimizationConfigPolicy.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDaoTransaction.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/SafePolicyBuilder.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryController.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryController.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryImportController.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/OptimizationDictionaryController.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java
ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyController.java

index 7e05efc..24f4fef 100644 (file)
@@ -23,40 +23,40 @@ package org.onap.policy.pap.xacml.rest.adapters;
 import java.util.List;
 
 public class GridData {
-       private List<Object> attributes;
-       private List<Object> alAttributes;
-       private List<Object> transportProtocols;
-       private List<Object> appProtocols;
-
-       public List<Object> getAttributes() {
-               return attributes;
-       }
-
-       public void setAttributes(List<Object> attributes) {
-               this.attributes = attributes;
-       }
-
-       public List<Object> getAlAttributes() {
-               return alAttributes;
-       }
-
-       public void setAlAttributes(List<Object> alAttributes) {
-               this.alAttributes = alAttributes;
-       }
-
-       public List<Object> getAppProtocols() {
-               return appProtocols;
-       }
-
-       public void setAppProtocols(List<Object> appProtocols) {
-               this.appProtocols = appProtocols;
-       }
-
-       public List<Object> getTransportProtocols() {
-               return transportProtocols;
-       }
-
-       public void setTransportProtocols(List<Object> transportProtocols) {
-               this.transportProtocols = transportProtocols;
-       }
+    private List<Object> attributes;
+    private List<Object> alAttributes;
+    private List<Object> transportProtocols;
+    private List<Object> appProtocols;
+
+    public List<Object> getAttributes() {
+        return attributes;
+    }
+
+    public void setAttributes(List<Object> attributes) {
+        this.attributes = attributes;
+    }
+
+    public List<Object> getAlAttributes() {
+        return alAttributes;
+    }
+
+    public void setAlAttributes(List<Object> alAttributes) {
+        this.alAttributes = alAttributes;
+    }
+
+    public List<Object> getAppProtocols() {
+        return appProtocols;
+    }
+
+    public void setAppProtocols(List<Object> appProtocols) {
+        this.appProtocols = appProtocols;
+    }
+
+    public List<Object> getTransportProtocols() {
+        return transportProtocols;
+    }
+
+    public void setTransportProtocols(List<Object> transportProtocols) {
+        this.transportProtocols = transportProtocols;
+    }
 }
index 44e3403..45c46cb 100644 (file)
 package org.onap.policy.pap.xacml.rest.adapters;
 
 public class SearchData {
-       private String query;
-       private String policyType;
-       private String descriptiveScope;
-       private String closedLooppolicyType;
-       private String onapName;
-       private String d2Service;
-       private String vnfType;
-       private String policyStatus;
-       private String vproAction;
-       private String serviceType;
-       private String bindTextSearch;
-       public String getQuery() {
-               return query;
-       }
-       public void setQuery(String query) {
-               this.query = query;
-       }
-       public String getPolicyType() {
-               return policyType;
-       }
-       public void setPolicyType(String policyType) {
-               this.policyType = policyType;
-       }
-       public String getDescriptiveScope() {
-               return descriptiveScope;
-       }
-       public void setDescriptiveScope(String descriptiveScope) {
-               this.descriptiveScope = descriptiveScope;
-       }
-       public String getClosedLooppolicyType() {
-               return closedLooppolicyType;
-       }
-       public void setClosedLooppolicyType(String closedLooppolicyType) {
-               this.closedLooppolicyType = closedLooppolicyType;
-       }
-       public String getOnapName() {
-               return onapName;
-       }
-       public void setOnapName(String onapName) {
-               this.onapName = onapName;
-       }
-       public String getD2Service() {
-               return d2Service;
-       }
-       public void setD2Service(String d2Service) {
-               this.d2Service = d2Service;
-       }
-       public String getVnfType() {
-               return vnfType;
-       }
-       public void setVnfType(String vnfType) {
-               this.vnfType = vnfType;
-       }
-       public String getPolicyStatus() {
-               return policyStatus;
-       }
-       public void setPolicyStatus(String policyStatus) {
-               this.policyStatus = policyStatus;
-       }
-       public String getVproAction() {
-               return vproAction;
-       }
-       public void setVproAction(String vproAction) {
-               this.vproAction = vproAction;
-       }
-       public String getServiceType() {
-               return serviceType;
-       }
-       public void setServiceType(String serviceType) {
-               this.serviceType = serviceType;
-       }
-       public String getBindTextSearch() {
-               return bindTextSearch;
-       }
-       public void setBindTextSearch(String bindTextSearch) {
-               this.bindTextSearch = bindTextSearch;
-       }
+    private String query;
+    private String policyType;
+    private String descriptiveScope;
+    private String closedLooppolicyType;
+    private String onapName;
+    private String d2Service;
+    private String vnfType;
+    private String policyStatus;
+    private String vproAction;
+    private String serviceType;
+    private String bindTextSearch;
+    public String getQuery() {
+        return query;
+    }
+    public void setQuery(String query) {
+        this.query = query;
+    }
+    public String getPolicyType() {
+        return policyType;
+    }
+    public void setPolicyType(String policyType) {
+        this.policyType = policyType;
+    }
+    public String getDescriptiveScope() {
+        return descriptiveScope;
+    }
+    public void setDescriptiveScope(String descriptiveScope) {
+        this.descriptiveScope = descriptiveScope;
+    }
+    public String getClosedLooppolicyType() {
+        return closedLooppolicyType;
+    }
+    public void setClosedLooppolicyType(String closedLooppolicyType) {
+        this.closedLooppolicyType = closedLooppolicyType;
+    }
+    public String getOnapName() {
+        return onapName;
+    }
+    public void setOnapName(String onapName) {
+        this.onapName = onapName;
+    }
+    public String getD2Service() {
+        return d2Service;
+    }
+    public void setD2Service(String d2Service) {
+        this.d2Service = d2Service;
+    }
+    public String getVnfType() {
+        return vnfType;
+    }
+    public void setVnfType(String vnfType) {
+        this.vnfType = vnfType;
+    }
+    public String getPolicyStatus() {
+        return policyStatus;
+    }
+    public void setPolicyStatus(String policyStatus) {
+        this.policyStatus = policyStatus;
+    }
+    public String getVproAction() {
+        return vproAction;
+    }
+    public void setVproAction(String vproAction) {
+        this.vproAction = vproAction;
+    }
+    public String getServiceType() {
+        return serviceType;
+    }
+    public void setServiceType(String serviceType) {
+        this.serviceType = serviceType;
+    }
+    public String getBindTextSearch() {
+        return bindTextSearch;
+    }
+    public void setBindTextSearch(String bindTextSearch) {
+        this.bindTextSearch = bindTextSearch;
+    }
 }
\ No newline at end of file
index 04006f3..aa59868 100644 (file)
 package org.onap.policy.pap.xacml.rest.adapters;
 
 public class UpdateObjectData {
-       private String oldPolicyName;
-       private String newPolicyName;
-       private String action;
-       
-       public String getOldPolicyName() {
-               return oldPolicyName;
-       }
-       
-       public void setOldPolicyName(String oldPolicyName) {
-               this.oldPolicyName = oldPolicyName;
-       }
-       
-       public String getNewPolicyName() {
-               return newPolicyName;
-       }
-       
-       public void setNewPolicyName(String newPolicyName) {
-               this.newPolicyName = newPolicyName;
-       }
-       
-       public String getAction() {
-               return action;
-       }
-       
-       public void setAction(String action) {
-               this.action = action;
-       }
+    private String oldPolicyName;
+    private String newPolicyName;
+    private String action;
+
+    public String getOldPolicyName() {
+        return oldPolicyName;
+    }
+
+    public void setOldPolicyName(String oldPolicyName) {
+        this.oldPolicyName = oldPolicyName;
+    }
+
+    public String getNewPolicyName() {
+        return newPolicyName;
+    }
+
+    public void setNewPolicyName(String newPolicyName) {
+        this.newPolicyName = newPolicyName;
+    }
+
+    public String getAction() {
+        return action;
+    }
+
+    public void setAction(String action) {
+        this.action = action;
+    }
 }
index 43eb434..9f84a4e 100644 (file)
@@ -106,7 +106,7 @@ public class ActionPolicy extends Policy {
         this.commonClassDao = commonClassDao;
     }
 
-       @Override
+    @Override
     public Map<String, String> savePolicies() throws PAPException {
         
         Map<String, String> successMap = new HashMap<>();
@@ -260,7 +260,7 @@ public class ActionPolicy extends Policy {
                 policyName = policyName.replace(".xml", "");
             }
             File file = new File(ACTION_HOME+ File.separator + policyName + ".json");
-                       try(BufferedWriter bw = new BufferedWriter(new FileWriter(file.getAbsoluteFile()))) {
+            try(BufferedWriter bw = new BufferedWriter(new FileWriter(file.getAbsoluteFile()))) {
             bw.write(actionBodyData);
             if (LOGGER.isInfoEnabled()) {
                 LOGGER.info("Action Body is succesfully saved at " + file.getAbsolutePath());
@@ -488,11 +488,11 @@ public class ActionPolicy extends Policy {
     }
     
     public String getFunctionDefinitionId(String key){
-       FunctionDefinition object = (FunctionDefinition) commonClassDao.getDataById(FunctionDefinition.class, "short_name", key);
-       if(object != null){
-               return object.getXacmlid();
-       }
-       return null;
+        FunctionDefinition object = (FunctionDefinition) commonClassDao.getDataById(FunctionDefinition.class, "short_name", key);
+        if(object != null){
+            return object.getXacmlid();
+        }
+        return null;
     }
 
 }
\ No newline at end of file
index 7c05a31..e446c2a 100644 (file)
@@ -58,345 +58,345 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
 
 public class ClosedLoopPolicy extends Policy {
 
-       private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopPolicy.class);
-
-       public ClosedLoopPolicy() {
-               super();
-       }
-       
-       public ClosedLoopPolicy(PolicyRestAdapter policyAdapter){
-               this.policyAdapter = policyAdapter;
-       }
-       
-       //save configuration of the policy based on the policyname
-       private void saveConfigurations(String policyName, String jsonBody) {
-           
-               if(policyName.endsWith(".xml")){
-                   policyName = policyName.replace(".xml", "");
-               }
-               try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator+ policyName +".json")){
-                       String body = jsonBody;
-                       //Remove the trapMaxAge in Verification Signature
-                       body = body.replace(",\"trapMaxAge\":null", "");
-                       this.policyAdapter.setJsonBody(body);
-                       out.println(body);
-               } catch (Exception e) {
-                       LOGGER.error("Exception Occured while writing Configuration Data"+e);
-               } 
-       }
-       
-       //Utility to read json data from the existing file to a string
-       static String readFile(String path, Charset encoding) throws IOException {
-               
-               byte[] encoded = Files.readAllBytes(Paths.get(path));
-               return new String(encoded, encoding);
-               
-       }
-       
-       //create the configuration file based on the policy name on adding the extension as .json 
-       private String getConfigFile(String filename) {
-               filename = FilenameUtils.removeExtension(filename);
-               if (filename.endsWith(".xml")) {
-                       filename = filename.substring(0, filename.length() - 4);
-               }
-               filename = filename + ".json";
-               return filename;
-       }
-
-       @Override
-       public Map<String, String> savePolicies() throws PAPException {
-               
-               Map<String, String> successMap = new HashMap<>();
-               if(isPolicyExists()){
-                       successMap.put("EXISTS", "This Policy already exist on the PAP");
-                       return successMap;
-               }
-               
-               if(!isPreparedToSave()){
-                       prepareToSave();
-               }
-               
-               // Until here we prepared the data and here calling the method to create xml.
-               Path newPolicyPath = null;
-               newPolicyPath = Paths.get(policyAdapter.getNewFileName());
-
-               successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());  
-               return successMap;              
-       }
-
-       //This is the method for preparing the policy for saving.  We have broken it out
-       //separately because the fully configured policy is used for multiple things
-       @Override
-       public boolean prepareToSave() throws PAPException{
-               
-               if(isPreparedToSave()){
-                       //we have already done this
-                       return true;
-               }
-               
-               int version = 0;
-               String policyID = policyAdapter.getPolicyID();
-               version = policyAdapter.getHighestVersion();
-               
-               // Create the Instance for pojo, PolicyType object is used in marshalling.
-               if (policyAdapter.getPolicyType().equals("Config")) {
-                       PolicyType policyConfig = new PolicyType();
-
-                       policyConfig.setVersion(Integer.toString(version));
-                       policyConfig.setPolicyId(policyID);
-                       policyConfig.setTarget(new TargetType());
-                       policyAdapter.setData(policyConfig);
-               }
-               policyName = policyAdapter.getNewFileName();
-               if (policyAdapter.getData() != null) {
-                       // Save the Configurations file with the policy name with extention based on selection.
-                       String jsonBody = policyAdapter.getJsonBody();
-                       saveConfigurations(policyName, jsonBody);
-                       
-                       // Make sure the filename ends with an extension
-                       if (policyName.endsWith(".xml") == false) {
-                               policyName = policyName + ".xml";
-                       }
-                       
-                       PolicyType faultPolicy = (PolicyType) policyAdapter.getData();
-                       
-                       faultPolicy.setDescription(policyAdapter.getPolicyDescription());
-
-                       faultPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
-                       
-                       AllOfType allOfOne = new AllOfType();
-                       String fileName = policyAdapter.getNewFileName();
-                       String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
-                       if ((name == null) || (name.equals(""))) {
-                               name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
-                       }
-                       allOfOne.getMatch().add(createMatch("PolicyName", name));
-                       AllOfType allOf = new AllOfType();
-                       // Adding the matches to AllOfType element
-                       // Match for Onap
-                       allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
-                       // Match for riskType
-                       allOf.getMatch().add(
-                                       createDynamicMatch("RiskType", policyAdapter.getRiskType()));
-                       // Match for riskLevel
-                       allOf.getMatch().add(
-                                       createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
-                       // Match for riskguard
-                       allOf.getMatch().add(
-                                       createDynamicMatch("guard", policyAdapter.getGuard()));
-                       // Match for ttlDate
-                       allOf.getMatch().add(
-                                       createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
-                       
-                       AnyOfType anyOf = new AnyOfType();
-                       anyOf.getAllOf().add(allOfOne);
-                       anyOf.getAllOf().add(allOf);
-
-                       TargetType target = new TargetType();
-                       ((TargetType) target).getAnyOf().add(anyOf);
-                       // Adding the target to the policy element
-                       faultPolicy.setTarget((TargetType) target);
-
-                       RuleType rule = new RuleType();
-                       rule.setRuleId(policyAdapter.getRuleID());
-                       rule.setEffect(EffectType.PERMIT);
-                       
-                       // Create Target in Rule
-                       AllOfType allOfInRule = new AllOfType();
-
-                       // Creating match for ACCESS in rule target
-                       MatchType accessMatch = new MatchType();
-                       AttributeValueType accessAttributeValue = new AttributeValueType();
-                       accessAttributeValue.setDataType(STRING_DATATYPE);
-                       accessAttributeValue.getContent().add("ACCESS");
-                       accessMatch.setAttributeValue(accessAttributeValue);
-                       AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
-                       URI accessURI = null;
-                       try {
-                               accessURI = new URI(ACTION_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "CreateClosedLoopPolicy", "Exception creating ACCESS URI");
-                       }
-                       accessAttributeDesignator.setCategory(CATEGORY_ACTION);
-                       accessAttributeDesignator.setDataType(STRING_DATATYPE);
-                       accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
-                       accessMatch.setAttributeDesignator(accessAttributeDesignator);
-                       accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       // Creating Config Match in rule Target
-                       MatchType closedMatch = new MatchType();
-                       AttributeValueType closedAttributeValue = new AttributeValueType();
-                       closedAttributeValue.setDataType(STRING_DATATYPE);
-                       closedAttributeValue.getContent().add("Config");
-                       closedMatch.setAttributeValue(closedAttributeValue);
-                       AttributeDesignatorType closedAttributeDesignator = new AttributeDesignatorType();
-                       URI closedURI = null;
-                       try {
-                               closedURI = new URI(RESOURCE_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "CreateClosedLoopPolicy", "Exception creating closed URI");
-                       }
-                       closedAttributeDesignator.setCategory(CATEGORY_RESOURCE);
-                       closedAttributeDesignator.setDataType(STRING_DATATYPE);
-                       closedAttributeDesignator.setAttributeId(new IdentifierImpl(closedURI).stringValue());
-                       closedMatch.setAttributeDesignator(closedAttributeDesignator);
-                       closedMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       allOfInRule.getMatch().add(accessMatch);
-                       allOfInRule.getMatch().add(closedMatch);
-
-                       AnyOfType anyOfInRule = new AnyOfType();
-                       anyOfInRule.getAllOf().add(allOfInRule);
-
-                       TargetType targetInRule = new TargetType();
-                       targetInRule.getAnyOf().add(anyOfInRule);
-
-                       rule.setTarget(targetInRule);
-                       rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
-
-                       faultPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
-                       policyAdapter.setPolicyData(faultPolicy);
-
-               } else {
-                       PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
-               }
-
-               setPreparedToSave(true);
-               return true;
-       }
-
-       // Data required for Advice part is setting here.
-       private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
-               AdviceExpressionsType advices = new AdviceExpressionsType();
-               AdviceExpressionType advice = new AdviceExpressionType();
-               advice.setAdviceId("faultID");
-               advice.setAppliesTo(EffectType.PERMIT);
-               // For Configuration
-               AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
-               assignment1.setAttributeId("type");
-               assignment1.setCategory(CATEGORY_RESOURCE);
-               assignment1.setIssuer("");
-
-               AttributeValueType configNameAttributeValue = new AttributeValueType();
-               configNameAttributeValue.setDataType(STRING_DATATYPE);
-               configNameAttributeValue.getContent().add("Configuration");
-               assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
-
-               advice.getAttributeAssignmentExpression().add(assignment1);
-               // For Config file Url if configurations are provided.
-               AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
-               assignment2.setAttributeId("URLID");
-               assignment2.setCategory(CATEGORY_RESOURCE);
-               assignment2.setIssuer("");
-
-               AttributeValueType AttributeValue = new AttributeValueType();
-               AttributeValue.setDataType(URI_DATATYPE);
-               String content = CONFIG_URL +"/Config/" + getConfigFile(policyName);
-               System.out.println("URL value :" + content);
-               AttributeValue.getContent().add(content);
-               assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue));
-
-               advice.getAttributeAssignmentExpression().add(assignment2);
-               AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
-               assignment3.setAttributeId("PolicyName");
-               assignment3.setCategory(CATEGORY_RESOURCE);
-               assignment3.setIssuer("");
-
-               AttributeValueType attributeValue3 = new AttributeValueType();
-               attributeValue3.setDataType(STRING_DATATYPE);
-               fileName = FilenameUtils.removeExtension(fileName);
-               fileName = fileName + ".xml";
-               String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
-               if ((name == null) || (name.equals(""))) {
-                       name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
-               }
-               attributeValue3.getContent().add(name);
-               assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
-               advice.getAttributeAssignmentExpression().add(assignment3);
-
-               AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
-               assignment4.setAttributeId("VersionNumber");
-               assignment4.setCategory(CATEGORY_RESOURCE);
-               assignment4.setIssuer("");
-
-               AttributeValueType configNameAttributeValue4 = new AttributeValueType();
-               configNameAttributeValue4.setDataType(STRING_DATATYPE);
-               configNameAttributeValue4.getContent().add(Integer.toString(version));
-               assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
-
-               advice.getAttributeAssignmentExpression().add(assignment4);
-
-               AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
-               assignment5.setAttributeId("matching:" + ONAPID);
-               assignment5.setCategory(CATEGORY_RESOURCE);
-               assignment5.setIssuer("");
-
-               AttributeValueType configNameAttributeValue5 = new AttributeValueType();
-               configNameAttributeValue5.setDataType(STRING_DATATYPE);
-               configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
-               assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
-
-               advice.getAttributeAssignmentExpression().add(assignment5);
-               
-               //Risk Attributes
-               AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
-               assignment6.setAttributeId("RiskType");
-               assignment6.setCategory(CATEGORY_RESOURCE);
-               assignment6.setIssuer("");
-
-               AttributeValueType configNameAttributeValue6 = new AttributeValueType();
-               configNameAttributeValue6.setDataType(STRING_DATATYPE);
-               configNameAttributeValue6.getContent().add(policyAdapter.getRiskType());
-               assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
-
-               advice.getAttributeAssignmentExpression().add(assignment6);
-               
-               AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
-               assignment7.setAttributeId("RiskLevel");
-               assignment7.setCategory(CATEGORY_RESOURCE);
-               assignment7.setIssuer("");
-
-               AttributeValueType configNameAttributeValue7 = new AttributeValueType();
-               configNameAttributeValue7.setDataType(STRING_DATATYPE);
-               configNameAttributeValue7.getContent().add(policyAdapter.getRiskLevel());
-               assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
-
-               advice.getAttributeAssignmentExpression().add(assignment7);     
-
-               AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
-               assignment8.setAttributeId("guard");
-               assignment8.setCategory(CATEGORY_RESOURCE);
-               assignment8.setIssuer("");
-
-               AttributeValueType configNameAttributeValue8 = new AttributeValueType();
-               configNameAttributeValue8.setDataType(STRING_DATATYPE);
-               configNameAttributeValue8.getContent().add(policyAdapter.getGuard());
-               assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
-
-               advice.getAttributeAssignmentExpression().add(assignment8);
-               
-               AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
-               assignment9.setAttributeId("TTLDate");
-               assignment9.setCategory(CATEGORY_RESOURCE);
-               assignment9.setIssuer("");
-
-               AttributeValueType configNameAttributeValue9 = new AttributeValueType();
-               configNameAttributeValue9.setDataType(STRING_DATATYPE);
-               configNameAttributeValue9.getContent().add(policyAdapter.getTtlDate());
-               assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
-
-               advice.getAttributeAssignmentExpression().add(assignment9);
-
-
-               
-               advices.getAdviceExpression().add(advice);
-               return advices;
-       }
-
-       @Override
-       public Object getCorrectPolicyDataObject() {
-               return policyAdapter.getPolicyData();
-       }
+    private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopPolicy.class);
+
+    public ClosedLoopPolicy() {
+        super();
+    }
+
+    public ClosedLoopPolicy(PolicyRestAdapter policyAdapter){
+        this.policyAdapter = policyAdapter;
+    }
+
+    //save configuration of the policy based on the policyname
+    private void saveConfigurations(String policyName, String jsonBody) {
+
+            if(policyName.endsWith(".xml")){
+                policyName = policyName.replace(".xml", "");
+            }
+        try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator+ policyName +".json")){
+            String body = jsonBody;
+            //Remove the trapMaxAge in Verification Signature
+            body = body.replace(",\"trapMaxAge\":null", "");
+            this.policyAdapter.setJsonBody(body);
+            out.println(body);
+        } catch (Exception e) {
+            LOGGER.error("Exception Occured while writing Configuration Data"+e);
+        }
+    }
+
+    //Utility to read json data from the existing file to a string
+    static String readFile(String path, Charset encoding) throws IOException {
+
+        byte[] encoded = Files.readAllBytes(Paths.get(path));
+        return new String(encoded, encoding);
+
+    }
+
+    //create the configuration file based on the policy name on adding the extension as .json
+    private String getConfigFile(String filename) {
+        filename = FilenameUtils.removeExtension(filename);
+        if (filename.endsWith(".xml")) {
+            filename = filename.substring(0, filename.length() - 4);
+        }
+        filename = filename + ".json";
+        return filename;
+    }
+
+    @Override
+    public Map<String, String> savePolicies() throws PAPException {
+
+        Map<String, String> successMap = new HashMap<>();
+        if(isPolicyExists()){
+            successMap.put("EXISTS", "This Policy already exist on the PAP");
+            return successMap;
+        }
+
+        if(!isPreparedToSave()){
+            prepareToSave();
+        }
+
+        // Until here we prepared the data and here calling the method to create xml.
+        Path newPolicyPath = null;
+        newPolicyPath = Paths.get(policyAdapter.getNewFileName());
+
+        successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());
+        return successMap;
+    }
+
+    //This is the method for preparing the policy for saving.  We have broken it out
+    //separately because the fully configured policy is used for multiple things
+    @Override
+    public boolean prepareToSave() throws PAPException{
+
+        if(isPreparedToSave()){
+            //we have already done this
+            return true;
+        }
+
+        int version = 0;
+        String policyID = policyAdapter.getPolicyID();
+        version = policyAdapter.getHighestVersion();
+
+        // Create the Instance for pojo, PolicyType object is used in marshalling.
+        if (policyAdapter.getPolicyType().equals("Config")) {
+            PolicyType policyConfig = new PolicyType();
+
+            policyConfig.setVersion(Integer.toString(version));
+            policyConfig.setPolicyId(policyID);
+            policyConfig.setTarget(new TargetType());
+            policyAdapter.setData(policyConfig);
+        }
+        policyName = policyAdapter.getNewFileName();
+        if (policyAdapter.getData() != null) {
+            // Save the Configurations file with the policy name with extention based on selection.
+            String jsonBody = policyAdapter.getJsonBody();
+            saveConfigurations(policyName, jsonBody);
+
+            // Make sure the filename ends with an extension
+            if (policyName.endsWith(".xml") == false) {
+                policyName = policyName + ".xml";
+            }
+
+            PolicyType faultPolicy = (PolicyType) policyAdapter.getData();
+
+            faultPolicy.setDescription(policyAdapter.getPolicyDescription());
+
+            faultPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
+
+            AllOfType allOfOne = new AllOfType();
+            String fileName = policyAdapter.getNewFileName();
+            String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
+            if ((name == null) || (name.equals(""))) {
+                name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
+            }
+            allOfOne.getMatch().add(createMatch("PolicyName", name));
+            AllOfType allOf = new AllOfType();
+            // Adding the matches to AllOfType element
+            // Match for Onap
+            allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
+            // Match for riskType
+            allOf.getMatch().add(
+                    createDynamicMatch("RiskType", policyAdapter.getRiskType()));
+            // Match for riskLevel
+            allOf.getMatch().add(
+                    createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
+            // Match for riskguard
+            allOf.getMatch().add(
+                    createDynamicMatch("guard", policyAdapter.getGuard()));
+            // Match for ttlDate
+            allOf.getMatch().add(
+                    createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
+
+            AnyOfType anyOf = new AnyOfType();
+            anyOf.getAllOf().add(allOfOne);
+            anyOf.getAllOf().add(allOf);
+
+            TargetType target = new TargetType();
+            ((TargetType) target).getAnyOf().add(anyOf);
+            // Adding the target to the policy element
+            faultPolicy.setTarget((TargetType) target);
+
+            RuleType rule = new RuleType();
+            rule.setRuleId(policyAdapter.getRuleID());
+            rule.setEffect(EffectType.PERMIT);
+
+            // Create Target in Rule
+            AllOfType allOfInRule = new AllOfType();
+
+            // Creating match for ACCESS in rule target
+            MatchType accessMatch = new MatchType();
+            AttributeValueType accessAttributeValue = new AttributeValueType();
+            accessAttributeValue.setDataType(STRING_DATATYPE);
+            accessAttributeValue.getContent().add("ACCESS");
+            accessMatch.setAttributeValue(accessAttributeValue);
+            AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
+            URI accessURI = null;
+            try {
+                accessURI = new URI(ACTION_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "CreateClosedLoopPolicy", "Exception creating ACCESS URI");
+            }
+            accessAttributeDesignator.setCategory(CATEGORY_ACTION);
+            accessAttributeDesignator.setDataType(STRING_DATATYPE);
+            accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
+            accessMatch.setAttributeDesignator(accessAttributeDesignator);
+            accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            // Creating Config Match in rule Target
+            MatchType closedMatch = new MatchType();
+            AttributeValueType closedAttributeValue = new AttributeValueType();
+            closedAttributeValue.setDataType(STRING_DATATYPE);
+            closedAttributeValue.getContent().add("Config");
+            closedMatch.setAttributeValue(closedAttributeValue);
+            AttributeDesignatorType closedAttributeDesignator = new AttributeDesignatorType();
+            URI closedURI = null;
+            try {
+                closedURI = new URI(RESOURCE_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "CreateClosedLoopPolicy", "Exception creating closed URI");
+            }
+            closedAttributeDesignator.setCategory(CATEGORY_RESOURCE);
+            closedAttributeDesignator.setDataType(STRING_DATATYPE);
+            closedAttributeDesignator.setAttributeId(new IdentifierImpl(closedURI).stringValue());
+            closedMatch.setAttributeDesignator(closedAttributeDesignator);
+            closedMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            allOfInRule.getMatch().add(accessMatch);
+            allOfInRule.getMatch().add(closedMatch);
+
+            AnyOfType anyOfInRule = new AnyOfType();
+            anyOfInRule.getAllOf().add(allOfInRule);
+
+            TargetType targetInRule = new TargetType();
+            targetInRule.getAnyOf().add(anyOfInRule);
+
+            rule.setTarget(targetInRule);
+            rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
+
+            faultPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
+            policyAdapter.setPolicyData(faultPolicy);
+
+        } else {
+            PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
+        }
+
+        setPreparedToSave(true);
+        return true;
+    }
+
+    // Data required for Advice part is setting here.
+    private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
+        AdviceExpressionsType advices = new AdviceExpressionsType();
+        AdviceExpressionType advice = new AdviceExpressionType();
+        advice.setAdviceId("faultID");
+        advice.setAppliesTo(EffectType.PERMIT);
+        // For Configuration
+        AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
+        assignment1.setAttributeId("type");
+        assignment1.setCategory(CATEGORY_RESOURCE);
+        assignment1.setIssuer("");
+
+        AttributeValueType configNameAttributeValue = new AttributeValueType();
+        configNameAttributeValue.setDataType(STRING_DATATYPE);
+        configNameAttributeValue.getContent().add("Configuration");
+        assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
+
+        advice.getAttributeAssignmentExpression().add(assignment1);
+        // For Config file Url if configurations are provided.
+        AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
+        assignment2.setAttributeId("URLID");
+        assignment2.setCategory(CATEGORY_RESOURCE);
+        assignment2.setIssuer("");
+
+        AttributeValueType AttributeValue = new AttributeValueType();
+        AttributeValue.setDataType(URI_DATATYPE);
+        String content = CONFIG_URL +"/Config/" + getConfigFile(policyName);
+        System.out.println("URL value :" + content);
+        AttributeValue.getContent().add(content);
+        assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue));
+
+        advice.getAttributeAssignmentExpression().add(assignment2);
+        AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
+        assignment3.setAttributeId("PolicyName");
+        assignment3.setCategory(CATEGORY_RESOURCE);
+        assignment3.setIssuer("");
+
+        AttributeValueType attributeValue3 = new AttributeValueType();
+        attributeValue3.setDataType(STRING_DATATYPE);
+        fileName = FilenameUtils.removeExtension(fileName);
+        fileName = fileName + ".xml";
+        String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
+        if ((name == null) || (name.equals(""))) {
+            name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
+        }
+        attributeValue3.getContent().add(name);
+        assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
+        advice.getAttributeAssignmentExpression().add(assignment3);
+
+        AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
+        assignment4.setAttributeId("VersionNumber");
+        assignment4.setCategory(CATEGORY_RESOURCE);
+        assignment4.setIssuer("");
+
+        AttributeValueType configNameAttributeValue4 = new AttributeValueType();
+        configNameAttributeValue4.setDataType(STRING_DATATYPE);
+        configNameAttributeValue4.getContent().add(Integer.toString(version));
+        assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
+
+        advice.getAttributeAssignmentExpression().add(assignment4);
+
+        AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
+        assignment5.setAttributeId("matching:" + ONAPID);
+        assignment5.setCategory(CATEGORY_RESOURCE);
+        assignment5.setIssuer("");
+
+        AttributeValueType configNameAttributeValue5 = new AttributeValueType();
+        configNameAttributeValue5.setDataType(STRING_DATATYPE);
+        configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
+        assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
+
+        advice.getAttributeAssignmentExpression().add(assignment5);
+
+        //Risk Attributes
+        AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
+        assignment6.setAttributeId("RiskType");
+        assignment6.setCategory(CATEGORY_RESOURCE);
+        assignment6.setIssuer("");
+
+        AttributeValueType configNameAttributeValue6 = new AttributeValueType();
+        configNameAttributeValue6.setDataType(STRING_DATATYPE);
+        configNameAttributeValue6.getContent().add(policyAdapter.getRiskType());
+        assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
+
+        advice.getAttributeAssignmentExpression().add(assignment6);
+
+        AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
+        assignment7.setAttributeId("RiskLevel");
+        assignment7.setCategory(CATEGORY_RESOURCE);
+        assignment7.setIssuer("");
+
+        AttributeValueType configNameAttributeValue7 = new AttributeValueType();
+        configNameAttributeValue7.setDataType(STRING_DATATYPE);
+        configNameAttributeValue7.getContent().add(policyAdapter.getRiskLevel());
+        assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
+
+        advice.getAttributeAssignmentExpression().add(assignment7);
+
+        AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
+        assignment8.setAttributeId("guard");
+        assignment8.setCategory(CATEGORY_RESOURCE);
+        assignment8.setIssuer("");
+
+        AttributeValueType configNameAttributeValue8 = new AttributeValueType();
+        configNameAttributeValue8.setDataType(STRING_DATATYPE);
+        configNameAttributeValue8.getContent().add(policyAdapter.getGuard());
+        assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
+
+        advice.getAttributeAssignmentExpression().add(assignment8);
+
+        AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
+        assignment9.setAttributeId("TTLDate");
+        assignment9.setCategory(CATEGORY_RESOURCE);
+        assignment9.setIssuer("");
+
+        AttributeValueType configNameAttributeValue9 = new AttributeValueType();
+        configNameAttributeValue9.setDataType(STRING_DATATYPE);
+        configNameAttributeValue9.getContent().add(policyAdapter.getTtlDate());
+        assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
+
+        advice.getAttributeAssignmentExpression().add(assignment9);
+
+
+
+        advices.getAdviceExpression().add(advice);
+        return advices;
+    }
+
+    @Override
+    public Object getCorrectPolicyDataObject() {
+        return policyAdapter.getPolicyData();
+    }
 
 
 }
index 45080ce..9809ad4 100644 (file)
@@ -34,50 +34,50 @@ import org.springframework.stereotype.Service;
 
 @Service
 public class CreateBRMSRuleTemplate {
-       private static final Logger LOGGER  = FlexLogger.getLogger(CreateBRMSRuleTemplate.class);
-       private static CommonClassDao commonClassDao;
-       
-       @Autowired
-       public CreateBRMSRuleTemplate(CommonClassDao commonClassDao){
-               CreateBRMSRuleTemplate.commonClassDao = commonClassDao;
-       }
-       
-       public CreateBRMSRuleTemplate() {}
+    private static final Logger LOGGER  = FlexLogger.getLogger(CreateBRMSRuleTemplate.class);
+    private static CommonClassDao commonClassDao;
 
-       public Map<String, String> addRule(String rule, String ruleName, String description, String userID) {
-               Map<String,String> responseMap = new HashMap<>();
-               if(rule!=null && !PolicyUtils.brmsRawValidate(rule).contains("[ERR")){
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(ruleName, "ruleName", BRMSParamTemplate.class);
-                       if(duplicateData!=null && !duplicateData.isEmpty()){
-                               LOGGER.error("Import new service failed.  Service already exists");
-                               responseMap.put("DBError", "EXISTS");
-                               return responseMap;
-                       }else{
-                               BRMSParamTemplate brmsParamTemplate = new BRMSParamTemplate();
-                               brmsParamTemplate.setDescription(description);
-                               brmsParamTemplate.setRuleName(ruleName);
-                               brmsParamTemplate.setRule(rule);
-                               UserInfo userCreatedBy = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", userID);
-                               brmsParamTemplate.setUserCreatedBy(userCreatedBy);
-                               commonClassDao.save(brmsParamTemplate);
-                               LOGGER.info("Template created with " + ruleName + " by " + userID);
-                       }
-                       responseMap.put("success", "success");
-               }else{
-                       LOGGER.debug("Error during validating the rule for creating record for BRMS Param Template");
-                       responseMap.put("error", "VALIDATION");
-               }
-               return responseMap;
-       }
-       
-       public static boolean validateRuleParams(String rule) {
-               CreateBrmsParamPolicy policy = new CreateBrmsParamPolicy();
-               Map<String, String> paramValues = policy.findType(rule);
-               for(String key : paramValues.keySet()) {
-                       if(!PolicyUtils.SUCCESS.equals(PolicyUtils.policySpecialCharValidator(key))){
-                               return false;
-                       }
-               }
-               return true;
-       }
+    @Autowired
+    public CreateBRMSRuleTemplate(CommonClassDao commonClassDao){
+        CreateBRMSRuleTemplate.commonClassDao = commonClassDao;
+    }
+
+    public CreateBRMSRuleTemplate() {}
+
+    public Map<String, String> addRule(String rule, String ruleName, String description, String userID) {
+        Map<String,String> responseMap = new HashMap<>();
+        if(rule!=null && !PolicyUtils.brmsRawValidate(rule).contains("[ERR")){
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(ruleName, "ruleName", BRMSParamTemplate.class);
+            if(duplicateData!=null && !duplicateData.isEmpty()){
+                LOGGER.error("Import new service failed.  Service already exists");
+                responseMap.put("DBError", "EXISTS");
+                return responseMap;
+            }else{
+                BRMSParamTemplate brmsParamTemplate = new BRMSParamTemplate();
+                brmsParamTemplate.setDescription(description);
+                brmsParamTemplate.setRuleName(ruleName);
+                brmsParamTemplate.setRule(rule);
+                UserInfo userCreatedBy = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", userID);
+                brmsParamTemplate.setUserCreatedBy(userCreatedBy);
+                commonClassDao.save(brmsParamTemplate);
+                LOGGER.info("Template created with " + ruleName + " by " + userID);
+            }
+            responseMap.put("success", "success");
+        }else{
+            LOGGER.debug("Error during validating the rule for creating record for BRMS Param Template");
+            responseMap.put("error", "VALIDATION");
+        }
+        return responseMap;
+    }
+
+    public static boolean validateRuleParams(String rule) {
+        CreateBrmsParamPolicy policy = new CreateBrmsParamPolicy();
+        Map<String, String> paramValues = policy.findType(rule);
+        for(String key : paramValues.keySet()) {
+            if(!PolicyUtils.SUCCESS.equals(PolicyUtils.policySpecialCharValidator(key))){
+                return false;
+            }
+        }
+        return true;
+    }
 }
index 2a13fb0..3d9a779 100644 (file)
@@ -69,496 +69,496 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; 
 
 public class CreateBrmsParamPolicy extends Policy {
-       
-       private static final Logger LOGGER = FlexLogger.getLogger(CreateBrmsParamPolicy.class);
-
-       public CreateBrmsParamPolicy() {
-               super();
-       }
-
-       public CreateBrmsParamPolicy(PolicyRestAdapter policyAdapter) {
-               this.policyAdapter = policyAdapter;
-               this.policyAdapter.setConfigType(policyAdapter.getConfigType());
-
-       }
-       
-       public String expandConfigBody(String ruleContents, Map<String, String> brmsParamBody) {
-
-               Map<String,String> copyMap=new HashMap<>();
-               copyMap.putAll(brmsParamBody);
-               copyMap.put("policyName", policyName.substring(0, policyName.replace(".xml", "").lastIndexOf('.')));
-               copyMap.put("policyScope", policyAdapter.getDomainDir());
-               copyMap.put("policyVersion",policyAdapter.getHighestVersion().toString());
-               copyMap.put("unique", ("p"+policyName+UUID.randomUUID().toString()).replaceAll("[^A-Za-z0-9]", ""));
-
-               //Finding all the keys in the Map data-structure.
-               Iterator<String> iterator = copyMap.keySet().iterator(); 
-               Pattern p;
-               Matcher m;
-               while(iterator.hasNext()) {
-                       //Converting the first character of the key into a lower case. 
-                       String input= iterator.next();
-                       String output  = Character.toLowerCase(input.charAt(0)) +
-                                       (input.length() > 1 ? input.substring(1) : "");
-                       //Searching for a pattern in the String using the key. 
-                       p=Pattern.compile("\\$\\{"+output+"\\}");       
-                       m=p.matcher(ruleContents);
-                       //Replacing the value with the inputs provided by the user in the editor. 
-                       String finalInput = copyMap.get(input);
-                       if(finalInput.contains("$")){
-                               finalInput = finalInput.replace("$", "\\$");
-                       }
-                       ruleContents=m.replaceAll(finalInput);
-               }
-               return ruleContents; 
-       } 
-                        
+
+    private static final Logger LOGGER = FlexLogger.getLogger(CreateBrmsParamPolicy.class);
+
+    public CreateBrmsParamPolicy() {
+        super();
+    }
+
+    public CreateBrmsParamPolicy(PolicyRestAdapter policyAdapter) {
+        this.policyAdapter = policyAdapter;
+        this.policyAdapter.setConfigType(policyAdapter.getConfigType());
+
+    }
+
+    public String expandConfigBody(String ruleContents, Map<String, String> brmsParamBody) {
+
+        Map<String,String> copyMap=new HashMap<>();
+        copyMap.putAll(brmsParamBody);
+        copyMap.put("policyName", policyName.substring(0, policyName.replace(".xml", "").lastIndexOf('.')));
+        copyMap.put("policyScope", policyAdapter.getDomainDir());
+        copyMap.put("policyVersion",policyAdapter.getHighestVersion().toString());
+        copyMap.put("unique", ("p"+policyName+UUID.randomUUID().toString()).replaceAll("[^A-Za-z0-9]", ""));
+
+        //Finding all the keys in the Map data-structure.
+        Iterator<String> iterator = copyMap.keySet().iterator();
+        Pattern p;
+        Matcher m;
+        while(iterator.hasNext()) {
+            //Converting the first character of the key into a lower case.
+            String input= iterator.next();
+            String output  = Character.toLowerCase(input.charAt(0)) +
+                    (input.length() > 1 ? input.substring(1) : "");
+            //Searching for a pattern in the String using the key.
+            p=Pattern.compile("\\$\\{"+output+"\\}");
+            m=p.matcher(ruleContents);
+            //Replacing the value with the inputs provided by the user in the editor.
+            String finalInput = copyMap.get(input);
+            if(finalInput.contains("$")){
+                finalInput = finalInput.replace("$", "\\$");
+            }
+            ruleContents=m.replaceAll(finalInput);
+        }
+        return ruleContents;
+    }
+
 
     
-       // Utility to read json data from the existing file to a string
-       static String readFile(String path, Charset encoding) throws IOException {
-               byte[] encoded = Files.readAllBytes(Paths.get(path));
-               return new String(encoded, encoding);
-       }
-       
-       // Saving the Configurations file at server location for config policy.
-       protected void saveConfigurations(String policyName, String ruleBody) {
-           if (policyName.endsWith(".xml")) {
+    // Utility to read json data from the existing file to a string
+    static String readFile(String path, Charset encoding) throws IOException {
+        byte[] encoded = Files.readAllBytes(Paths.get(path));
+        return new String(encoded, encoding);
+    }
+
+    // Saving the Configurations file at server location for config policy.
+    protected void saveConfigurations(String policyName, String ruleBody) {
+        if (policyName.endsWith(".xml")) {
             policyName = policyName.substring(0, policyName.lastIndexOf(".xml"));
         }
-               try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName + ".txt")) {
-                       String expandedBody=expandConfigBody(ruleBody,policyAdapter.getBrmsParamBody());
-                       out.println(expandedBody);
-                       policyAdapter.setJsonBody(expandedBody);
-                       policyAdapter.setConfigBodyData(expandedBody);
-                       out.close();
-               } catch (Exception e) {
-                       PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving configuration file");
-               }
-       }
-
-
-       // Here we are adding the extension for the configurations file based on the
-       // config type selection for saving.
-       private String getConfigFile(String filename) {
-               filename = FilenameUtils.removeExtension(filename);
-               if (filename.endsWith(".txt")) {
-                       filename = filename.substring(0, filename.length() - 3);
-               }
-
-               filename = filename + ".txt";
-               return filename;
-       }
-
-       // Validations for Config form
-       public boolean validateConfigForm() {
-
-               // Validating mandatory Fields.
-               isValidForm = true;
-               return isValidForm;
-
-       }
-
-       @Override
-       public Map<String, String> savePolicies() throws PAPException {
-               
-               Map<String, String> successMap = new HashMap<>();
-               if(isPolicyExists()){
-                       successMap.put("EXISTS", "This Policy already exist on the PAP");
-                       return successMap;
-               }
-               
-               if (!isPreparedToSave()) {
-                       prepareToSave();
-               }
-               // Until here we prepared the data and here calling the method to create
-               // xml.
-               Path newPolicyPath = null;
-               newPolicyPath = Paths.get(policyAdapter.getNewFileName());
-               successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());
-               if(successMap == null){
-                       successMap = new HashMap<>();
-                       PolicyLogger.error("Failed to Update the Database Dictionary Tables.");
-                       successMap.put("error", "DB UPDATE");
-               }
-               return successMap;
-       }
-       
-       private String getValueFromDictionary(String templateName){
-               String ruleTemplate = null;
-               CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
-               String queryString="from BRMSParamTemplate where param_template_name= :templateName";
-               SimpleBindings params = new SimpleBindings();
-               params.put("templateName", templateName);
-               List<Object> result = dbConnection.getDataByQuery(queryString, params);
-               if(!result.isEmpty()){
-                       BRMSParamTemplate template = (BRMSParamTemplate) result.get(0);
-                       ruleTemplate = template.getRule();
-               }
-               return ruleTemplate;
-       }
-       
-       protected Map<String, String> findType(String rule) {
-               Map<String, String> mapFieldType= new HashMap<>();
-               if(rule!=null){
-                       try {
-                               StringBuilder params = new StringBuilder();
-                               Boolean flag = false;
-                               Boolean comment = false;
-                               String lines[] = rule.split("\n");
-                               for(String line : lines){
-                                       if (line.isEmpty() || line.startsWith("//")) {
-                                               continue;
-                                       }
-                                       if (line.startsWith("/*")) {
-                                               comment = true;
-                                               continue;
-                                       }
-                                       if (line.contains("//") && !(line.contains("http://") || line.contains("https://"))){
-                                                       line = line.split("\\/\\/")[0];
-                                       }
-                                       if (line.contains("/*")) {
-                                               comment = true;
-                                               if (line.contains("*/")) {
-                                                       try {
-                                                               comment = false;
-                                                               line = line.split("\\/\\*")[0]
-                                                                               + line.split("\\*\\/")[1].replace("*/", "");
-                                                       } catch (Exception e) {
-                                                               LOGGER.debug(e);
-                                                               line = line.split("\\/\\*")[0];
-                                                       }
-                                               } else {
-                                                       line = line.split("\\/\\*")[0];
-                                               }
-                                       }
-                                       if (line.contains("*/")) {
-                                               comment = false;
-                                               try {
-                                                       line = line.split("\\*\\/")[1].replace("*/", "");
-                                               } catch (Exception e) {
-                                                       LOGGER.debug(e);
-                                                       line = "";
-                                               }
-                                       }
-                                       if (comment) {
-                                               continue;
-                                       }
-                                       if (flag) {
-                                               params.append(line);
-                                       }
-                                       if (line.contains("declare Params")) {
-                                               params.append(line);
-                                               flag = true;
-                                       }
-                                       if (line.contains("end") && flag) {
-                                               break;
-                                       }
-                               }
-                               String param = params.toString().replace("declare Params", "").replace("end", "")
-                                               .replaceAll("\\s+", "");
-                               String[] components = param.split(":");
-                               String caption = "";
-                               for (int i = 0; i < components.length; i++) {
-                                       String type = "";
-                                       if (i == 0) {
-                                               caption = components[i];
-                                       }
-                                       if(caption.equals("")){
-                                               break;
-                                       }
-                                       String nextComponent = "";
-                                       try {
-                                               nextComponent = components[i + 1];
-                                       } catch (Exception e) {
-                                               LOGGER.debug(e);
-                                               nextComponent = components[i];
-                                       }
-                                       //If the type is of type String then we add the UI Item and type to the map. 
-                                       if (nextComponent.startsWith("String")) {
-                                               type = "String";
-                                               mapFieldType.put(caption, type);
-                                               caption = nextComponent.replace("String", "");
-                                       } else if (nextComponent.startsWith("int")) {
-                                               type = "int";
-                                               mapFieldType.put(caption, type);
-                                               caption = nextComponent.replace("int", "");
-                                       }
-                               }
-                       } catch (Exception e) {
-                               PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CreateBrmsParamPolicy", "Exception parsing file in findType");
-                       }
-               }
-               return mapFieldType;
-       }
-       
-       // This is the method for preparing the policy for saving. We have broken it
-       // out
-       // separately because the fully configured policy is used for multiple
-       // things
-       @Override
-       public boolean prepareToSave() throws PAPException {
-               
-               if (isPreparedToSave()) {
-                       // we have already done this
-                       return true;
-               }
-
-               int version = 0;
-               String policyID = policyAdapter.getPolicyID();
-               version = policyAdapter.getHighestVersion();
-
-               // Create the Instance for pojo, PolicyType object is used in
-               // marshalling.
-               if (policyAdapter.getPolicyType().equals("Config")) {
-                       PolicyType policyConfig = new PolicyType();
-
-                       policyConfig.setVersion(Integer.toString(version));
-                       policyConfig.setPolicyId(policyID);
-                       policyConfig.setTarget(new TargetType());
-                       policyAdapter.setData(policyConfig);
-               }
-
-               policyName = policyAdapter.getNewFileName();
-               
-               if (policyAdapter.getData() != null) {  
-                       Map<String,String> ruleAndUIValue= policyAdapter.getBrmsParamBody();
-                       String templateValue= ruleAndUIValue.get("templateName");
-                       String valueFromDictionary= getValueFromDictionary(templateValue);
-                       
-                       StringBuilder body = new StringBuilder();
-                       
-                       try {
-                           body.append("/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose. \n\t " +
-                                   "<$%BRMSParamTemplate=" + templateValue + "%$> \n");
-                           body.append("<%$Values=");
-                           for (Map.Entry<String, String> entry : ruleAndUIValue.entrySet()) {
-                               String uiKey = entry.getKey();
-                               if(!"templateName".equals(uiKey)) {
-                                   body.append(uiKey+":-:"+entry.getValue()+":|:");
-                               }
-                           }
-                           body.append("$%> \n*/ \n");
-                           body.append(valueFromDictionary + "\n");
-                       }
-                       catch (Exception e) {
-                           PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving policy");
-                       }
-                       
-                       saveConfigurations(policyName,body.toString());
-                       
-                       // Make sure the filename ends with an extension
-                       if (!policyName.endsWith(".xml")) {
-                               policyName = policyName + ".xml";
-                       }
-
-                       PolicyType configPolicy = (PolicyType) policyAdapter.getData();
-
-                       configPolicy.setDescription(policyAdapter.getPolicyDescription());
-
-                       configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
-
-                       AllOfType allOfOne = new AllOfType();
-
-                       String fileName = policyAdapter.getNewFileName();
-                       String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
-                       if ((name == null) || (name.equals(""))) {
-                               name = fileName.substring(fileName.lastIndexOf("/") + 1,
-                                               fileName.length());
-                       }
-                       allOfOne.getMatch().add(createMatch("PolicyName", name));
-                       
-                       
-                       AllOfType allOf = new AllOfType();
-
-                       // Match for ONAPName
-                       allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
-                       allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
-                       // Match for riskType
-                       allOf.getMatch().add(createDynamicMatch("RiskType", policyAdapter.getRiskType()));
-                       // Match for riskLevel
-                       allOf.getMatch().add(createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
-                       // Match for riskguard
-                       allOf.getMatch().add(createDynamicMatch("guard", policyAdapter.getGuard()));
-                       // Match for ttlDate
-                       allOf.getMatch().add(createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
-                       AnyOfType anyOf = new AnyOfType();
-                       anyOf.getAllOf().add(allOfOne);
-                       anyOf.getAllOf().add(allOf);
-
-                       TargetType target = new TargetType();
-                       target.getAnyOf().add(anyOf);
-
-                       // Adding the target to the policy element
-                       configPolicy.setTarget((TargetType) target);
-
-                       RuleType rule = new RuleType();
-                       rule.setRuleId(policyAdapter.getRuleID());
-
-                       rule.setEffect(EffectType.PERMIT);
-
-                       // Create Target in Rule
-                       AllOfType allOfInRule = new AllOfType();
-
-                       // Creating match for ACCESS in rule target
-                       MatchType accessMatch = new MatchType();
-                       AttributeValueType accessAttributeValue = new AttributeValueType();
-                       accessAttributeValue.setDataType(STRING_DATATYPE);
-                       accessAttributeValue.getContent().add("ACCESS");
-                       accessMatch.setAttributeValue(accessAttributeValue);
-                       AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
-                       URI accessURI = null;
-                       try {
-                               accessURI = new URI(ACTION_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy", "Exception creating ACCESS URI");
-                       }
-                       accessAttributeDesignator.setCategory(CATEGORY_ACTION);
-                       accessAttributeDesignator.setDataType(STRING_DATATYPE);
-                       accessAttributeDesignator.setAttributeId(new IdentifierImpl(
-                                       accessURI).stringValue());
-                       accessMatch.setAttributeDesignator(accessAttributeDesignator);
-                       accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       // Creating Config Match in rule Target
-                       MatchType configMatch = new MatchType();
-                       AttributeValueType configAttributeValue = new AttributeValueType();
-                       configAttributeValue.setDataType(STRING_DATATYPE);
-
-                       configAttributeValue.getContent().add("Config");
-
-                       configMatch.setAttributeValue(configAttributeValue);
-                       AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
-                       URI configURI = null;
-                       try {
-                               configURI = new URI(RESOURCE_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy", "Exception creating Config URI");
-                       }
-
-                       configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
-                       configAttributeDesignator.setDataType(STRING_DATATYPE);
-                       configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
-                       configMatch.setAttributeDesignator(configAttributeDesignator);
-                       configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       allOfInRule.getMatch().add(accessMatch);
-                       allOfInRule.getMatch().add(configMatch);
-
-                       AnyOfType anyOfInRule = new AnyOfType();
-                       anyOfInRule.getAllOf().add(allOfInRule);
-
-                       TargetType targetInRule = new TargetType();
-                       targetInRule.getAnyOf().add(anyOfInRule);
-
-                       rule.setTarget(targetInRule);
-                       rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
-
-                       configPolicy
-                                       .getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()
-                                       .add(rule);
-                       policyAdapter.setPolicyData(configPolicy);
-
-               } else {
-                       PolicyLogger.error("Unsupported data object."
-                                       + policyAdapter.getData().getClass().getCanonicalName());
-               }
-               setPreparedToSave(true);
-               return true;
-       }
-
-       // Data required for Advice part is setting here.
-       private AdviceExpressionsType getAdviceExpressions(int version,
-                       String fileName) {
-
-               //Policy Config ID Assignment
-               AdviceExpressionsType advices = new AdviceExpressionsType();
-               AdviceExpressionType advice = new AdviceExpressionType();
-               advice.setAdviceId("BRMSPARAMID");
-               advice.setAppliesTo(EffectType.PERMIT);
-               // For Configuration
-               AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
-               assignment1.setAttributeId("type");
-               assignment1.setCategory(CATEGORY_RESOURCE);
-               assignment1.setIssuer("");
-               AttributeValueType configNameAttributeValue = new AttributeValueType();
-               configNameAttributeValue.setDataType(STRING_DATATYPE);
-               configNameAttributeValue.getContent().add("Configuration");
-               assignment1.setExpression(new ObjectFactory()
-                               .createAttributeValue(configNameAttributeValue));
-               advice.getAttributeAssignmentExpression().add(assignment1);
-
-               // For Config file Url if configurations are provided.
-               // URL ID Assignment
-               AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
-               assignment2.setAttributeId("URLID");
-               assignment2.setCategory(CATEGORY_RESOURCE);
-               assignment2.setIssuer("");
-               AttributeValueType attributeValue = new AttributeValueType();
-               attributeValue.setDataType(URI_DATATYPE);
-
-               String content = CONFIG_URL + "/Config/"+ getConfigFile(policyName);
-
-               attributeValue.getContent().add(content);
-               assignment2.setExpression(new ObjectFactory()
-                               .createAttributeValue(attributeValue));
-               advice.getAttributeAssignmentExpression().add(assignment2);
-
-               // Policy Name Assignment
-               AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
-               assignment3.setAttributeId("PolicyName");
-               assignment3.setCategory(CATEGORY_RESOURCE);
-               assignment3.setIssuer("");
-               AttributeValueType attributeValue3 = new AttributeValueType();
-               attributeValue3.setDataType(STRING_DATATYPE);
-               fileName = FilenameUtils.removeExtension(fileName);
-               fileName = fileName + ".xml";
-               String name = fileName.substring(fileName.lastIndexOf("\\") + 1,
-                               fileName.length());
-               if ((name == null) || (name.equals(""))) {
-                       name = fileName.substring(fileName.lastIndexOf("/") + 1,
-                                       fileName.length());
-               }
-               attributeValue3.getContent().add(name);
-               assignment3.setExpression(new ObjectFactory()
-                               .createAttributeValue(attributeValue3));
-               advice.getAttributeAssignmentExpression().add(assignment3);
-
-               // Version Number Assignment
-               AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
-               assignment4.setAttributeId("VersionNumber");
-               assignment4.setCategory(CATEGORY_RESOURCE);
-               assignment4.setIssuer("");
-               AttributeValueType configNameAttributeValue4 = new AttributeValueType();
-               configNameAttributeValue4.setDataType(STRING_DATATYPE);
-               configNameAttributeValue4.getContent().add(Integer.toString(version));
-               assignment4.setExpression(new ObjectFactory()
-                               .createAttributeValue(configNameAttributeValue4));
-               advice.getAttributeAssignmentExpression().add(assignment4);
-
-               // Onap Name Assignment
-               AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
-               assignment5.setAttributeId("matching:" + ONAPID);
-               assignment5.setCategory(CATEGORY_RESOURCE);
-               assignment5.setIssuer("");
-               AttributeValueType configNameAttributeValue5 = new AttributeValueType();
-               configNameAttributeValue5.setDataType(STRING_DATATYPE);
-               configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
-               assignment5.setExpression(new ObjectFactory()
-                               .createAttributeValue(configNameAttributeValue5));
-               advice.getAttributeAssignmentExpression().add(assignment5);
-               
-               
-               //Config Name Assignment
-               AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
-               assignment6.setAttributeId("matching:" +CONFIGID);
-               assignment6.setCategory(CATEGORY_RESOURCE);
-               assignment6.setIssuer("");
-               AttributeValueType configNameAttributeValue6 = new AttributeValueType();
-               configNameAttributeValue6.setDataType(STRING_DATATYPE);
-               configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
-               assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
-               advice.getAttributeAssignmentExpression().add(assignment6);
+        try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName + ".txt")) {
+            String expandedBody=expandConfigBody(ruleBody,policyAdapter.getBrmsParamBody());
+            out.println(expandedBody);
+            policyAdapter.setJsonBody(expandedBody);
+            policyAdapter.setConfigBodyData(expandedBody);
+            out.close();
+        } catch (Exception e) {
+            PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving configuration file");
+        }
+    }
+
+
+    // Here we are adding the extension for the configurations file based on the
+    // config type selection for saving.
+    private String getConfigFile(String filename) {
+        filename = FilenameUtils.removeExtension(filename);
+        if (filename.endsWith(".txt")) {
+            filename = filename.substring(0, filename.length() - 3);
+        }
+
+        filename = filename + ".txt";
+        return filename;
+    }
+
+    // Validations for Config form
+    public boolean validateConfigForm() {
+
+        // Validating mandatory Fields.
+        isValidForm = true;
+        return isValidForm;
+
+    }
+
+    @Override
+    public Map<String, String> savePolicies() throws PAPException {
+
+        Map<String, String> successMap = new HashMap<>();
+        if(isPolicyExists()){
+            successMap.put("EXISTS", "This Policy already exist on the PAP");
+            return successMap;
+        }
+
+        if (!isPreparedToSave()) {
+            prepareToSave();
+        }
+        // Until here we prepared the data and here calling the method to create
+        // xml.
+        Path newPolicyPath = null;
+        newPolicyPath = Paths.get(policyAdapter.getNewFileName());
+        successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());
+        if(successMap == null){
+            successMap = new HashMap<>();
+            PolicyLogger.error("Failed to Update the Database Dictionary Tables.");
+            successMap.put("error", "DB UPDATE");
+        }
+        return successMap;
+    }
+
+    private String getValueFromDictionary(String templateName){
+        String ruleTemplate = null;
+        CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
+        String queryString="from BRMSParamTemplate where param_template_name= :templateName";
+        SimpleBindings params = new SimpleBindings();
+        params.put("templateName", templateName);
+        List<Object> result = dbConnection.getDataByQuery(queryString, params);
+        if(!result.isEmpty()){
+            BRMSParamTemplate template = (BRMSParamTemplate) result.get(0);
+            ruleTemplate = template.getRule();
+        }
+        return ruleTemplate;
+    }
+
+    protected Map<String, String> findType(String rule) {
+        Map<String, String> mapFieldType= new HashMap<>();
+        if(rule!=null){
+            try {
+                StringBuilder params = new StringBuilder();
+                Boolean flag = false;
+                Boolean comment = false;
+                String lines[] = rule.split("\n");
+                for(String line : lines){
+                    if (line.isEmpty() || line.startsWith("//")) {
+                        continue;
+                    }
+                    if (line.startsWith("/*")) {
+                        comment = true;
+                        continue;
+                    }
+                    if (line.contains("//") && !(line.contains("http://") || line.contains("https://"))){
+                            line = line.split("\\/\\/")[0];
+                    }
+                    if (line.contains("/*")) {
+                        comment = true;
+                        if (line.contains("*/")) {
+                            try {
+                                comment = false;
+                                line = line.split("\\/\\*")[0]
+                                        + line.split("\\*\\/")[1].replace("*/", "");
+                            } catch (Exception e) {
+                                LOGGER.debug(e);
+                                line = line.split("\\/\\*")[0];
+                            }
+                        } else {
+                            line = line.split("\\/\\*")[0];
+                        }
+                    }
+                    if (line.contains("*/")) {
+                        comment = false;
+                        try {
+                            line = line.split("\\*\\/")[1].replace("*/", "");
+                        } catch (Exception e) {
+                            LOGGER.debug(e);
+                            line = "";
+                        }
+                    }
+                    if (comment) {
+                        continue;
+                    }
+                    if (flag) {
+                        params.append(line);
+                    }
+                    if (line.contains("declare Params")) {
+                        params.append(line);
+                        flag = true;
+                    }
+                    if (line.contains("end") && flag) {
+                        break;
+                    }
+                }
+                String param = params.toString().replace("declare Params", "").replace("end", "")
+                        .replaceAll("\\s+", "");
+                String[] components = param.split(":");
+                String caption = "";
+                for (int i = 0; i < components.length; i++) {
+                    String type = "";
+                    if (i == 0) {
+                        caption = components[i];
+                    }
+                    if(caption.equals("")){
+                        break;
+                    }
+                    String nextComponent = "";
+                    try {
+                        nextComponent = components[i + 1];
+                    } catch (Exception e) {
+                        LOGGER.debug(e);
+                        nextComponent = components[i];
+                    }
+                    //If the type is of type String then we add the UI Item and type to the map.
+                    if (nextComponent.startsWith("String")) {
+                        type = "String";
+                        mapFieldType.put(caption, type);
+                        caption = nextComponent.replace("String", "");
+                    } else if (nextComponent.startsWith("int")) {
+                        type = "int";
+                        mapFieldType.put(caption, type);
+                        caption = nextComponent.replace("int", "");
+                    }
+                }
+            } catch (Exception e) {
+                PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "CreateBrmsParamPolicy", "Exception parsing file in findType");
+            }
+        }
+        return mapFieldType;
+    }
+
+    // This is the method for preparing the policy for saving. We have broken it
+    // out
+    // separately because the fully configured policy is used for multiple
+    // things
+    @Override
+    public boolean prepareToSave() throws PAPException {
+
+        if (isPreparedToSave()) {
+            // we have already done this
+            return true;
+        }
+
+        int version = 0;
+        String policyID = policyAdapter.getPolicyID();
+        version = policyAdapter.getHighestVersion();
+
+        // Create the Instance for pojo, PolicyType object is used in
+        // marshalling.
+        if (policyAdapter.getPolicyType().equals("Config")) {
+            PolicyType policyConfig = new PolicyType();
+
+            policyConfig.setVersion(Integer.toString(version));
+            policyConfig.setPolicyId(policyID);
+            policyConfig.setTarget(new TargetType());
+            policyAdapter.setData(policyConfig);
+        }
+
+        policyName = policyAdapter.getNewFileName();
+
+        if (policyAdapter.getData() != null) {
+            Map<String,String> ruleAndUIValue= policyAdapter.getBrmsParamBody();
+            String templateValue= ruleAndUIValue.get("templateName");
+            String valueFromDictionary= getValueFromDictionary(templateValue);
+
+            StringBuilder body = new StringBuilder();
+
+            try {
+                body.append("/* Autogenerated Code Please Don't change/remove this comment section. This is for the UI purpose. \n\t " +
+                        "<$%BRMSParamTemplate=" + templateValue + "%$> \n");
+                body.append("<%$Values=");
+                for (Map.Entry<String, String> entry : ruleAndUIValue.entrySet()) {
+                    String uiKey = entry.getKey();
+                    if(!"templateName".equals(uiKey)) {
+                        body.append(uiKey+":-:"+entry.getValue()+":|:");
+                    }
+                }
+                body.append("$%> \n*/ \n");
+                body.append(valueFromDictionary + "\n");
+            }
+            catch (Exception e) {
+                PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsParamPolicy", "Exception saving policy");
+            }
+
+            saveConfigurations(policyName,body.toString());
+
+            // Make sure the filename ends with an extension
+            if (!policyName.endsWith(".xml")) {
+                policyName = policyName + ".xml";
+            }
+
+            PolicyType configPolicy = (PolicyType) policyAdapter.getData();
+
+            configPolicy.setDescription(policyAdapter.getPolicyDescription());
+
+            configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
+
+            AllOfType allOfOne = new AllOfType();
+
+            String fileName = policyAdapter.getNewFileName();
+            String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
+            if ((name == null) || (name.equals(""))) {
+                name = fileName.substring(fileName.lastIndexOf("/") + 1,
+                        fileName.length());
+            }
+            allOfOne.getMatch().add(createMatch("PolicyName", name));
+
+
+            AllOfType allOf = new AllOfType();
+
+            // Match for ONAPName
+            allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
+            allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
+            // Match for riskType
+            allOf.getMatch().add(createDynamicMatch("RiskType", policyAdapter.getRiskType()));
+            // Match for riskLevel
+            allOf.getMatch().add(createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
+            // Match for riskguard
+            allOf.getMatch().add(createDynamicMatch("guard", policyAdapter.getGuard()));
+            // Match for ttlDate
+            allOf.getMatch().add(createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
+            AnyOfType anyOf = new AnyOfType();
+            anyOf.getAllOf().add(allOfOne);
+            anyOf.getAllOf().add(allOf);
+
+            TargetType target = new TargetType();
+            target.getAnyOf().add(anyOf);
+
+            // Adding the target to the policy element
+            configPolicy.setTarget((TargetType) target);
+
+            RuleType rule = new RuleType();
+            rule.setRuleId(policyAdapter.getRuleID());
+
+            rule.setEffect(EffectType.PERMIT);
+
+            // Create Target in Rule
+            AllOfType allOfInRule = new AllOfType();
+
+            // Creating match for ACCESS in rule target
+            MatchType accessMatch = new MatchType();
+            AttributeValueType accessAttributeValue = new AttributeValueType();
+            accessAttributeValue.setDataType(STRING_DATATYPE);
+            accessAttributeValue.getContent().add("ACCESS");
+            accessMatch.setAttributeValue(accessAttributeValue);
+            AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
+            URI accessURI = null;
+            try {
+                accessURI = new URI(ACTION_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy", "Exception creating ACCESS URI");
+            }
+            accessAttributeDesignator.setCategory(CATEGORY_ACTION);
+            accessAttributeDesignator.setDataType(STRING_DATATYPE);
+            accessAttributeDesignator.setAttributeId(new IdentifierImpl(
+                    accessURI).stringValue());
+            accessMatch.setAttributeDesignator(accessAttributeDesignator);
+            accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            // Creating Config Match in rule Target
+            MatchType configMatch = new MatchType();
+            AttributeValueType configAttributeValue = new AttributeValueType();
+            configAttributeValue.setDataType(STRING_DATATYPE);
+
+            configAttributeValue.getContent().add("Config");
+
+            configMatch.setAttributeValue(configAttributeValue);
+            AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
+            URI configURI = null;
+            try {
+                configURI = new URI(RESOURCE_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsParamPolicy", "Exception creating Config URI");
+            }
+
+            configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
+            configAttributeDesignator.setDataType(STRING_DATATYPE);
+            configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
+            configMatch.setAttributeDesignator(configAttributeDesignator);
+            configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            allOfInRule.getMatch().add(accessMatch);
+            allOfInRule.getMatch().add(configMatch);
+
+            AnyOfType anyOfInRule = new AnyOfType();
+            anyOfInRule.getAllOf().add(allOfInRule);
+
+            TargetType targetInRule = new TargetType();
+            targetInRule.getAnyOf().add(anyOfInRule);
+
+            rule.setTarget(targetInRule);
+            rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
+
+            configPolicy
+                    .getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()
+                    .add(rule);
+            policyAdapter.setPolicyData(configPolicy);
+
+        } else {
+            PolicyLogger.error("Unsupported data object."
+                    + policyAdapter.getData().getClass().getCanonicalName());
+        }
+        setPreparedToSave(true);
+        return true;
+    }
+
+    // Data required for Advice part is setting here.
+    private AdviceExpressionsType getAdviceExpressions(int version,
+            String fileName) {
+
+        //Policy Config ID Assignment
+        AdviceExpressionsType advices = new AdviceExpressionsType();
+        AdviceExpressionType advice = new AdviceExpressionType();
+        advice.setAdviceId("BRMSPARAMID");
+        advice.setAppliesTo(EffectType.PERMIT);
+        // For Configuration
+        AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
+        assignment1.setAttributeId("type");
+        assignment1.setCategory(CATEGORY_RESOURCE);
+        assignment1.setIssuer("");
+        AttributeValueType configNameAttributeValue = new AttributeValueType();
+        configNameAttributeValue.setDataType(STRING_DATATYPE);
+        configNameAttributeValue.getContent().add("Configuration");
+        assignment1.setExpression(new ObjectFactory()
+                .createAttributeValue(configNameAttributeValue));
+        advice.getAttributeAssignmentExpression().add(assignment1);
+
+        // For Config file Url if configurations are provided.
+        // URL ID Assignment
+        AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
+        assignment2.setAttributeId("URLID");
+        assignment2.setCategory(CATEGORY_RESOURCE);
+        assignment2.setIssuer("");
+        AttributeValueType attributeValue = new AttributeValueType();
+        attributeValue.setDataType(URI_DATATYPE);
+
+        String content = CONFIG_URL + "/Config/"+ getConfigFile(policyName);
+
+        attributeValue.getContent().add(content);
+        assignment2.setExpression(new ObjectFactory()
+                .createAttributeValue(attributeValue));
+        advice.getAttributeAssignmentExpression().add(assignment2);
+
+        // Policy Name Assignment
+        AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
+        assignment3.setAttributeId("PolicyName");
+        assignment3.setCategory(CATEGORY_RESOURCE);
+        assignment3.setIssuer("");
+        AttributeValueType attributeValue3 = new AttributeValueType();
+        attributeValue3.setDataType(STRING_DATATYPE);
+        fileName = FilenameUtils.removeExtension(fileName);
+        fileName = fileName + ".xml";
+        String name = fileName.substring(fileName.lastIndexOf("\\") + 1,
+                fileName.length());
+        if ((name == null) || (name.equals(""))) {
+            name = fileName.substring(fileName.lastIndexOf("/") + 1,
+                    fileName.length());
+        }
+        attributeValue3.getContent().add(name);
+        assignment3.setExpression(new ObjectFactory()
+                .createAttributeValue(attributeValue3));
+        advice.getAttributeAssignmentExpression().add(assignment3);
+
+        // Version Number Assignment
+        AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
+        assignment4.setAttributeId("VersionNumber");
+        assignment4.setCategory(CATEGORY_RESOURCE);
+        assignment4.setIssuer("");
+        AttributeValueType configNameAttributeValue4 = new AttributeValueType();
+        configNameAttributeValue4.setDataType(STRING_DATATYPE);
+        configNameAttributeValue4.getContent().add(Integer.toString(version));
+        assignment4.setExpression(new ObjectFactory()
+                .createAttributeValue(configNameAttributeValue4));
+        advice.getAttributeAssignmentExpression().add(assignment4);
+
+        // Onap Name Assignment
+        AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
+        assignment5.setAttributeId("matching:" + ONAPID);
+        assignment5.setCategory(CATEGORY_RESOURCE);
+        assignment5.setIssuer("");
+        AttributeValueType configNameAttributeValue5 = new AttributeValueType();
+        configNameAttributeValue5.setDataType(STRING_DATATYPE);
+        configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
+        assignment5.setExpression(new ObjectFactory()
+                .createAttributeValue(configNameAttributeValue5));
+        advice.getAttributeAssignmentExpression().add(assignment5);
+
+
+        //Config Name Assignment
+        AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
+        assignment6.setAttributeId("matching:" +CONFIGID);
+        assignment6.setCategory(CATEGORY_RESOURCE);
+        assignment6.setIssuer("");
+        AttributeValueType configNameAttributeValue6 = new AttributeValueType();
+        configNameAttributeValue6.setDataType(STRING_DATATYPE);
+        configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
+        assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
+        advice.getAttributeAssignmentExpression().add(assignment6);
         // Adding Controller Information. 
         if(policyAdapter.getBrmsController()!=null){
             BRMSDictionaryController brmsDicitonaryController = new BRMSDictionaryController();
@@ -581,69 +581,69 @@ public class CreateBrmsParamPolicy extends Policy {
         }
         
         // Dynamic Field Config Attributes. 
-               Map<String, String> dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes();
-               for (Entry<String, String> map : dynamicFieldConfigAttributes.entrySet()) {
-                       advice.getAttributeAssignmentExpression().add(createResponseAttributes("key:"+map.getKey(), map.getValue()));
-               }
-               
-               //Risk Attributes
-               AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
-               assignment8.setAttributeId("RiskType");
-               assignment8.setCategory(CATEGORY_RESOURCE);
-               assignment8.setIssuer("");
-
-               AttributeValueType configNameAttributeValue8 = new AttributeValueType();
-               configNameAttributeValue8.setDataType(STRING_DATATYPE);
-               configNameAttributeValue8.getContent().add(policyAdapter.getRiskType());
-               assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
-
-               advice.getAttributeAssignmentExpression().add(assignment8);
-               
-               AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
-               assignment9.setAttributeId("RiskLevel");
-               assignment9.setCategory(CATEGORY_RESOURCE);
-               assignment9.setIssuer("");
-
-               AttributeValueType configNameAttributeValue9 = new AttributeValueType();
-               configNameAttributeValue9.setDataType(STRING_DATATYPE);
-               configNameAttributeValue9.getContent().add(policyAdapter.getRiskLevel());
-               assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
-
-               advice.getAttributeAssignmentExpression().add(assignment9);     
-
-               AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
-               assignment10.setAttributeId("guard");
-               assignment10.setCategory(CATEGORY_RESOURCE);
-               assignment10.setIssuer("");
-
-               AttributeValueType configNameAttributeValue10 = new AttributeValueType();
-               configNameAttributeValue10.setDataType(STRING_DATATYPE);
-               configNameAttributeValue10.getContent().add(policyAdapter.getGuard());
-               assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
-
-               advice.getAttributeAssignmentExpression().add(assignment10);
-
-               AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
-               assignment11.setAttributeId("TTLDate");
-               assignment11.setCategory(CATEGORY_RESOURCE);
-               assignment11.setIssuer("");
-
-               AttributeValueType configNameAttributeValue11 = new AttributeValueType();
-               configNameAttributeValue11.setDataType(STRING_DATATYPE);
-               configNameAttributeValue11.getContent().add(policyAdapter.getTtlDate());
-               assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
-
-               advice.getAttributeAssignmentExpression().add(assignment11);
-
-               advices.getAdviceExpression().add(advice);
-               return advices;
-       }
-
-       @Override
-       public Object getCorrectPolicyDataObject() {            
-               return policyAdapter.getData();
-       }
-       
+        Map<String, String> dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes();
+        for (Entry<String, String> map : dynamicFieldConfigAttributes.entrySet()) {
+            advice.getAttributeAssignmentExpression().add(createResponseAttributes("key:"+map.getKey(), map.getValue()));
+        }
+
+        //Risk Attributes
+        AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
+        assignment8.setAttributeId("RiskType");
+        assignment8.setCategory(CATEGORY_RESOURCE);
+        assignment8.setIssuer("");
+
+        AttributeValueType configNameAttributeValue8 = new AttributeValueType();
+        configNameAttributeValue8.setDataType(STRING_DATATYPE);
+        configNameAttributeValue8.getContent().add(policyAdapter.getRiskType());
+        assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
+
+        advice.getAttributeAssignmentExpression().add(assignment8);
+
+        AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
+        assignment9.setAttributeId("RiskLevel");
+        assignment9.setCategory(CATEGORY_RESOURCE);
+        assignment9.setIssuer("");
+
+        AttributeValueType configNameAttributeValue9 = new AttributeValueType();
+        configNameAttributeValue9.setDataType(STRING_DATATYPE);
+        configNameAttributeValue9.getContent().add(policyAdapter.getRiskLevel());
+        assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
+
+        advice.getAttributeAssignmentExpression().add(assignment9);
+
+        AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
+        assignment10.setAttributeId("guard");
+        assignment10.setCategory(CATEGORY_RESOURCE);
+        assignment10.setIssuer("");
+
+        AttributeValueType configNameAttributeValue10 = new AttributeValueType();
+        configNameAttributeValue10.setDataType(STRING_DATATYPE);
+        configNameAttributeValue10.getContent().add(policyAdapter.getGuard());
+        assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
+
+        advice.getAttributeAssignmentExpression().add(assignment10);
+
+        AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
+        assignment11.setAttributeId("TTLDate");
+        assignment11.setCategory(CATEGORY_RESOURCE);
+        assignment11.setIssuer("");
+
+        AttributeValueType configNameAttributeValue11 = new AttributeValueType();
+        configNameAttributeValue11.setDataType(STRING_DATATYPE);
+        configNameAttributeValue11.getContent().add(policyAdapter.getTtlDate());
+        assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
+
+        advice.getAttributeAssignmentExpression().add(assignment11);
+
+        advices.getAdviceExpression().add(advice);
+        return advices;
+    }
+
+    @Override
+    public Object getCorrectPolicyDataObject() {
+        return policyAdapter.getData();
+    }
+
     private AttributeAssignmentExpressionType  createResponseAttributes(String key, String value){
         AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
         assignment7.setAttributeId(key);
index 0bac0e0..7290f4c 100644 (file)
@@ -59,336 +59,336 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
 
 
 public class CreateBrmsRawPolicy extends Policy {
-       
-       public CreateBrmsRawPolicy() {
-               super();
-       }
-
-       public CreateBrmsRawPolicy(PolicyRestAdapter policyAdapter) {
-               this.policyAdapter = policyAdapter;
-               this.policyAdapter.setConfigType(policyAdapter.getConfigType());
-
-       }
-
-       // Saving the Configurations file at server location for CreateBrmsRawPolicy policy.
-       protected void saveConfigurations(String policyName, String jsonBody) {         
-           
-               if (policyName.endsWith(".xml")) {
-                   policyName = policyName.substring(0,
-                               policyName.lastIndexOf(".xml"));
-               }
-               try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName + ".txt")){
-                       out.println(jsonBody);
-               } catch (Exception e) {
-                       PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsRawPolicy", "Exception saving configurations file");
-               }
-       }
-
-       // Utility to read json data from the existing file to a string
-       static String readFile(String path, Charset encoding) throws IOException {
-
-               byte[] encoded = Files.readAllBytes(Paths.get(path));
-               return new String(encoded, encoding);
-
-       }
-
-       // Here we are adding the extension for the configurations file based on the
-       // config type selection for saving.
-       private String getConfigFile(String filename) {
-               filename = FilenameUtils.removeExtension(filename);
-               if (filename.endsWith(".txt")) {
-                       filename = filename.substring(0, filename.length() - 3);
-               }
-
-               filename = filename + ".txt";
-               return filename;
-       }
-
-       // Validations for Config form
-       public boolean validateConfigForm() {
-
-               // Validating mandatory Fields.
-               isValidForm = true;
-               return isValidForm;
-
-       }
-
-       @Override
-       public Map<String, String> savePolicies() throws PAPException {
-               
-               Map<String, String> successMap = new HashMap<>();
-               if(isPolicyExists()){
-                       successMap.put("EXISTS", "This Policy already exist on the PAP");
-                       return successMap;
-               }
-               
-               if (!isPreparedToSave()) {
-                       prepareToSave();
-               }
-               // Until here we prepared the data and here calling the method to create
-               // xml.
-               Path newPolicyPath = null;
-               newPolicyPath = Paths.get(policyAdapter.getNewFileName());
-               
-               successMap = createPolicy(newPolicyPath, getCorrectPolicyDataObject());
-               if (successMap == null) {
-                       successMap = new HashMap<>();
-                       PolicyLogger.error("Failed to Update the Database Dictionary Tables.");
-                       successMap.put("error", "DB UPDATE");
-               }
-
-               return successMap;
-       }
-
-       // This is the method for preparing the policy for saving. We have broken it
-       // out
-       // separately because the fully configured policy is used for multiple
-       // things
-       @Override
-       public boolean prepareToSave() throws PAPException {
-
-               if (isPreparedToSave()) {
-                       // we have already done this
-                       return true;
-               }
-
-               int version = 0;
-               String policyID = policyAdapter.getPolicyID();
-               version = policyAdapter.getHighestVersion();
-
-               // Create the Instance for pojo, PolicyType object is used in
-               // marshalling.
-               if (policyAdapter.getPolicyType().equals("Config")) {
-                       PolicyType policyConfig = new PolicyType();
-
-                       policyConfig.setVersion(Integer.toString(version));
-                       policyConfig.setPolicyId(policyID);
-                       policyConfig.setTarget(new TargetType());
-                       policyAdapter.setData(policyConfig);
-               }
-
-               policyName = policyAdapter.getNewFileName();
-               
-               if (policyAdapter.getData() != null) {
-                       //String jsonBody = policyAdapter.getJsonBody();
-                       String configBody=policyAdapter.getConfigBodyData();
-                       saveConfigurations(policyName, configBody);
-
-                       // Make sure the filename ends with an extension
-                       if (policyName.endsWith(".xml") == false) {
-                               policyName = policyName + ".xml";
-                       }
-
-                       PolicyType configPolicy = (PolicyType) policyAdapter.getData();
-
-                       configPolicy.setDescription(policyAdapter.getPolicyDescription());
-
-                       configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
-
-                       AllOfType allOfOne = new AllOfType();
-                       String fileName = policyAdapter.getNewFileName();
-                       String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
-                       if ((name == null) || (name.equals(""))) {
-                               name = fileName.substring(fileName.lastIndexOf("/") + 1,
-                                               fileName.length());
-                       }
-                       allOfOne.getMatch().add(createMatch("PolicyName", name));
-                       
-                       
-                       AllOfType allOf = new AllOfType();
-
-                       // Match for ONAPName
-                       allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
-                       allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
-                       // Match for riskType
-                       allOf.getMatch().add(createDynamicMatch("RiskType", policyAdapter.getRiskType()));
-                       // Match for riskLevel
-                       allOf.getMatch().add(createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
-                       // Match for riskguard
-                       allOf.getMatch().add(createDynamicMatch("guard", policyAdapter.getGuard()));
-                       // Match for ttlDate
-                       allOf.getMatch().add(createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
-                       AnyOfType anyOf = new AnyOfType();
-                       anyOf.getAllOf().add(allOfOne);
-                       anyOf.getAllOf().add(allOf);
-
-                       TargetType target = new TargetType();
-                       ((TargetType) target).getAnyOf().add(anyOf);
-
-                       // Adding the target to the policy element
-                       configPolicy.setTarget((TargetType) target);
-
-                       RuleType rule = new RuleType();
-                       rule.setRuleId(policyAdapter.getRuleID());
-
-                       rule.setEffect(EffectType.PERMIT);
-
-                       // Create Target in Rule
-                       AllOfType allOfInRule = new AllOfType();
-
-                       // Creating match for ACCESS in rule target
-                       MatchType accessMatch = new MatchType();
-                       AttributeValueType accessAttributeValue = new AttributeValueType();
-                       accessAttributeValue.setDataType(STRING_DATATYPE);
-                       accessAttributeValue.getContent().add("ACCESS");
-                       accessMatch.setAttributeValue(accessAttributeValue);
-                       AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
-                       URI accessURI = null;
-                       try {
-                               accessURI = new URI(ACTION_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsRawPolicy", "Exception creating ACCESS URI");
-                       }
-                       accessAttributeDesignator.setCategory(CATEGORY_ACTION);
-                       accessAttributeDesignator.setDataType(STRING_DATATYPE);
-                       accessAttributeDesignator.setAttributeId(new IdentifierImpl(
-                                       accessURI).stringValue());
-                       accessMatch.setAttributeDesignator(accessAttributeDesignator);
-                       accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       // Creating Config Match in rule Target
-                       MatchType configMatch = new MatchType();
-                       AttributeValueType configAttributeValue = new AttributeValueType();
-                       configAttributeValue.setDataType(STRING_DATATYPE);
-
-                       configAttributeValue.getContent().add("Config");
-
-                       configMatch.setAttributeValue(configAttributeValue);
-                       AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
-                       URI configURI = null;
-                       try {
-                               configURI = new URI(RESOURCE_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsRawPolicy", "Exception creating Config URI");
-                       }
-
-                       configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
-                       configAttributeDesignator.setDataType(STRING_DATATYPE);
-                       configAttributeDesignator.setAttributeId(new IdentifierImpl(
-                                       configURI).stringValue());
-                       configMatch.setAttributeDesignator(configAttributeDesignator);
-                       configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       allOfInRule.getMatch().add(accessMatch);
-                       allOfInRule.getMatch().add(configMatch);
-
-                       AnyOfType anyOfInRule = new AnyOfType();
-                       anyOfInRule.getAllOf().add(allOfInRule);
-
-                       TargetType targetInRule = new TargetType();
-                       targetInRule.getAnyOf().add(anyOfInRule);
-
-                       rule.setTarget(targetInRule);
-                       rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
-
-                       configPolicy
-                                       .getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()
-                                       .add(rule);
-                       policyAdapter.setPolicyData(configPolicy);
-
-               } else {
-                       PolicyLogger.error("Unsupported data object."
-                                       + policyAdapter.getData().getClass().getCanonicalName());
-               }
-               setPreparedToSave(true);
-               return true;
-       }
-
-       // Data required for Advice part is setting here.
-       private AdviceExpressionsType getAdviceExpressions(int version,
-                       String fileName) {
-
-               // Policy Config ID Assignment
-               AdviceExpressionsType advices = new AdviceExpressionsType();
-               AdviceExpressionType advice = new AdviceExpressionType();
-               advice.setAdviceId("BRMSRAWID");
-               advice.setAppliesTo(EffectType.PERMIT);
-               // For Configuration
-               AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
-               assignment1.setAttributeId("type");
-               assignment1.setCategory(CATEGORY_RESOURCE);
-               assignment1.setIssuer("");
-               AttributeValueType configNameAttributeValue = new AttributeValueType();
-               configNameAttributeValue.setDataType(STRING_DATATYPE);
-               configNameAttributeValue.getContent().add("Configuration");
-               assignment1.setExpression(new ObjectFactory()
-                               .createAttributeValue(configNameAttributeValue));
-               advice.getAttributeAssignmentExpression().add(assignment1);
-
-               // For Config file Url if configurations are provided.
-               // URL ID Assignment
-               AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
-               assignment2.setAttributeId("URLID");
-               assignment2.setCategory(CATEGORY_RESOURCE);
-               assignment2.setIssuer("");
-               AttributeValueType AttributeValue = new AttributeValueType();
-               AttributeValue.setDataType(URI_DATATYPE);
-
-               String content = CONFIG_URL + "/Config/" + getConfigFile(policyName);
-
-               AttributeValue.getContent().add(content);
-               assignment2.setExpression(new ObjectFactory()
-                               .createAttributeValue(AttributeValue));
-               advice.getAttributeAssignmentExpression().add(assignment2);
-
-               // Policy Name Assignment
-               AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
-               assignment3.setAttributeId("PolicyName");
-               assignment3.setCategory(CATEGORY_RESOURCE);
-               assignment3.setIssuer("");
-               AttributeValueType attributeValue3 = new AttributeValueType();
-               attributeValue3.setDataType(STRING_DATATYPE);
-               fileName = FilenameUtils.removeExtension(fileName);
-               fileName = fileName + ".xml";
-               System.out.println(fileName);
-               String name = fileName.substring(fileName.lastIndexOf("\\") + 1,
-                               fileName.length());
-               if ((name == null) || (name.equals(""))) {
-                       name = fileName.substring(fileName.lastIndexOf("/") + 1,
-                                       fileName.length());
-               }
-               System.out.println(name);
-               attributeValue3.getContent().add(name);
-               assignment3.setExpression(new ObjectFactory()
-                               .createAttributeValue(attributeValue3));
-               advice.getAttributeAssignmentExpression().add(assignment3);
-
-               // Version Number Assignment
-               AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
-               assignment4.setAttributeId("VersionNumber");
-               assignment4.setCategory(CATEGORY_RESOURCE);
-               assignment4.setIssuer("");
-               AttributeValueType configNameAttributeValue4 = new AttributeValueType();
-               configNameAttributeValue4.setDataType(STRING_DATATYPE);
-               configNameAttributeValue4.getContent().add(Integer.toString(version));
-               assignment4.setExpression(new ObjectFactory()
-                               .createAttributeValue(configNameAttributeValue4));
-               advice.getAttributeAssignmentExpression().add(assignment4);
-
-               // Onap Name Assignment
-               AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
-               assignment5.setAttributeId("matching:" + ONAPID);
-               assignment5.setCategory(CATEGORY_RESOURCE);
-               assignment5.setIssuer("");
-               AttributeValueType configNameAttributeValue5 = new AttributeValueType();
-               configNameAttributeValue5.setDataType(STRING_DATATYPE);
-               configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
-               assignment5.setExpression(new ObjectFactory()
-                               .createAttributeValue(configNameAttributeValue5));
-               advice.getAttributeAssignmentExpression().add(assignment5);
-               
-               
-               //Config Name Assignment
-               AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
-               assignment6.setAttributeId("matching:" + CONFIGID);
-               assignment6.setCategory(CATEGORY_RESOURCE);
-               assignment6.setIssuer("");
-               AttributeValueType configNameAttributeValue6 = new AttributeValueType();
-               configNameAttributeValue6.setDataType(STRING_DATATYPE);
-               configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
-               assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
-               advice.getAttributeAssignmentExpression().add(assignment6);
-               
+
+    public CreateBrmsRawPolicy() {
+        super();
+    }
+
+    public CreateBrmsRawPolicy(PolicyRestAdapter policyAdapter) {
+        this.policyAdapter = policyAdapter;
+        this.policyAdapter.setConfigType(policyAdapter.getConfigType());
+
+    }
+
+    // Saving the Configurations file at server location for CreateBrmsRawPolicy policy.
+    protected void saveConfigurations(String policyName, String jsonBody) {
+
+            if (policyName.endsWith(".xml")) {
+                policyName = policyName.substring(0,
+                            policyName.lastIndexOf(".xml"));
+            }
+        try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName + ".txt")){
+            out.println(jsonBody);
+        } catch (Exception e) {
+            PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "CreateBrmsRawPolicy", "Exception saving configurations file");
+        }
+    }
+
+    // Utility to read json data from the existing file to a string
+    static String readFile(String path, Charset encoding) throws IOException {
+
+        byte[] encoded = Files.readAllBytes(Paths.get(path));
+        return new String(encoded, encoding);
+
+    }
+
+    // Here we are adding the extension for the configurations file based on the
+    // config type selection for saving.
+    private String getConfigFile(String filename) {
+        filename = FilenameUtils.removeExtension(filename);
+        if (filename.endsWith(".txt")) {
+            filename = filename.substring(0, filename.length() - 3);
+        }
+
+        filename = filename + ".txt";
+        return filename;
+    }
+
+    // Validations for Config form
+    public boolean validateConfigForm() {
+
+        // Validating mandatory Fields.
+        isValidForm = true;
+        return isValidForm;
+
+    }
+
+    @Override
+    public Map<String, String> savePolicies() throws PAPException {
+
+        Map<String, String> successMap = new HashMap<>();
+        if(isPolicyExists()){
+            successMap.put("EXISTS", "This Policy already exist on the PAP");
+            return successMap;
+        }
+
+        if (!isPreparedToSave()) {
+            prepareToSave();
+        }
+        // Until here we prepared the data and here calling the method to create
+        // xml.
+        Path newPolicyPath = null;
+        newPolicyPath = Paths.get(policyAdapter.getNewFileName());
+
+        successMap = createPolicy(newPolicyPath, getCorrectPolicyDataObject());
+        if (successMap == null) {
+            successMap = new HashMap<>();
+            PolicyLogger.error("Failed to Update the Database Dictionary Tables.");
+            successMap.put("error", "DB UPDATE");
+        }
+
+        return successMap;
+    }
+
+    // This is the method for preparing the policy for saving. We have broken it
+    // out
+    // separately because the fully configured policy is used for multiple
+    // things
+    @Override
+    public boolean prepareToSave() throws PAPException {
+
+        if (isPreparedToSave()) {
+            // we have already done this
+            return true;
+        }
+
+        int version = 0;
+        String policyID = policyAdapter.getPolicyID();
+        version = policyAdapter.getHighestVersion();
+
+        // Create the Instance for pojo, PolicyType object is used in
+        // marshalling.
+        if (policyAdapter.getPolicyType().equals("Config")) {
+            PolicyType policyConfig = new PolicyType();
+
+            policyConfig.setVersion(Integer.toString(version));
+            policyConfig.setPolicyId(policyID);
+            policyConfig.setTarget(new TargetType());
+            policyAdapter.setData(policyConfig);
+        }
+
+        policyName = policyAdapter.getNewFileName();
+
+        if (policyAdapter.getData() != null) {
+            //String jsonBody = policyAdapter.getJsonBody();
+            String configBody=policyAdapter.getConfigBodyData();
+            saveConfigurations(policyName, configBody);
+
+            // Make sure the filename ends with an extension
+            if (policyName.endsWith(".xml") == false) {
+                policyName = policyName + ".xml";
+            }
+
+            PolicyType configPolicy = (PolicyType) policyAdapter.getData();
+
+            configPolicy.setDescription(policyAdapter.getPolicyDescription());
+
+            configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
+
+            AllOfType allOfOne = new AllOfType();
+            String fileName = policyAdapter.getNewFileName();
+            String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
+            if ((name == null) || (name.equals(""))) {
+                name = fileName.substring(fileName.lastIndexOf("/") + 1,
+                        fileName.length());
+            }
+            allOfOne.getMatch().add(createMatch("PolicyName", name));
+
+
+            AllOfType allOf = new AllOfType();
+
+            // Match for ONAPName
+            allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
+            allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
+            // Match for riskType
+            allOf.getMatch().add(createDynamicMatch("RiskType", policyAdapter.getRiskType()));
+            // Match for riskLevel
+            allOf.getMatch().add(createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
+            // Match for riskguard
+            allOf.getMatch().add(createDynamicMatch("guard", policyAdapter.getGuard()));
+            // Match for ttlDate
+            allOf.getMatch().add(createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
+            AnyOfType anyOf = new AnyOfType();
+            anyOf.getAllOf().add(allOfOne);
+            anyOf.getAllOf().add(allOf);
+
+            TargetType target = new TargetType();
+            ((TargetType) target).getAnyOf().add(anyOf);
+
+            // Adding the target to the policy element
+            configPolicy.setTarget((TargetType) target);
+
+            RuleType rule = new RuleType();
+            rule.setRuleId(policyAdapter.getRuleID());
+
+            rule.setEffect(EffectType.PERMIT);
+
+            // Create Target in Rule
+            AllOfType allOfInRule = new AllOfType();
+
+            // Creating match for ACCESS in rule target
+            MatchType accessMatch = new MatchType();
+            AttributeValueType accessAttributeValue = new AttributeValueType();
+            accessAttributeValue.setDataType(STRING_DATATYPE);
+            accessAttributeValue.getContent().add("ACCESS");
+            accessMatch.setAttributeValue(accessAttributeValue);
+            AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
+            URI accessURI = null;
+            try {
+                accessURI = new URI(ACTION_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsRawPolicy", "Exception creating ACCESS URI");
+            }
+            accessAttributeDesignator.setCategory(CATEGORY_ACTION);
+            accessAttributeDesignator.setDataType(STRING_DATATYPE);
+            accessAttributeDesignator.setAttributeId(new IdentifierImpl(
+                    accessURI).stringValue());
+            accessMatch.setAttributeDesignator(accessAttributeDesignator);
+            accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            // Creating Config Match in rule Target
+            MatchType configMatch = new MatchType();
+            AttributeValueType configAttributeValue = new AttributeValueType();
+            configAttributeValue.setDataType(STRING_DATATYPE);
+
+            configAttributeValue.getContent().add("Config");
+
+            configMatch.setAttributeValue(configAttributeValue);
+            AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
+            URI configURI = null;
+            try {
+                configURI = new URI(RESOURCE_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateBrmsRawPolicy", "Exception creating Config URI");
+            }
+
+            configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
+            configAttributeDesignator.setDataType(STRING_DATATYPE);
+            configAttributeDesignator.setAttributeId(new IdentifierImpl(
+                    configURI).stringValue());
+            configMatch.setAttributeDesignator(configAttributeDesignator);
+            configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            allOfInRule.getMatch().add(accessMatch);
+            allOfInRule.getMatch().add(configMatch);
+
+            AnyOfType anyOfInRule = new AnyOfType();
+            anyOfInRule.getAllOf().add(allOfInRule);
+
+            TargetType targetInRule = new TargetType();
+            targetInRule.getAnyOf().add(anyOfInRule);
+
+            rule.setTarget(targetInRule);
+            rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
+
+            configPolicy
+                    .getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()
+                    .add(rule);
+            policyAdapter.setPolicyData(configPolicy);
+
+        } else {
+            PolicyLogger.error("Unsupported data object."
+                    + policyAdapter.getData().getClass().getCanonicalName());
+        }
+        setPreparedToSave(true);
+        return true;
+    }
+
+    // Data required for Advice part is setting here.
+    private AdviceExpressionsType getAdviceExpressions(int version,
+            String fileName) {
+
+        // Policy Config ID Assignment
+        AdviceExpressionsType advices = new AdviceExpressionsType();
+        AdviceExpressionType advice = new AdviceExpressionType();
+        advice.setAdviceId("BRMSRAWID");
+        advice.setAppliesTo(EffectType.PERMIT);
+        // For Configuration
+        AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
+        assignment1.setAttributeId("type");
+        assignment1.setCategory(CATEGORY_RESOURCE);
+        assignment1.setIssuer("");
+        AttributeValueType configNameAttributeValue = new AttributeValueType();
+        configNameAttributeValue.setDataType(STRING_DATATYPE);
+        configNameAttributeValue.getContent().add("Configuration");
+        assignment1.setExpression(new ObjectFactory()
+                .createAttributeValue(configNameAttributeValue));
+        advice.getAttributeAssignmentExpression().add(assignment1);
+
+        // For Config file Url if configurations are provided.
+        // URL ID Assignment
+        AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
+        assignment2.setAttributeId("URLID");
+        assignment2.setCategory(CATEGORY_RESOURCE);
+        assignment2.setIssuer("");
+        AttributeValueType AttributeValue = new AttributeValueType();
+        AttributeValue.setDataType(URI_DATATYPE);
+
+        String content = CONFIG_URL + "/Config/" + getConfigFile(policyName);
+
+        AttributeValue.getContent().add(content);
+        assignment2.setExpression(new ObjectFactory()
+                .createAttributeValue(AttributeValue));
+        advice.getAttributeAssignmentExpression().add(assignment2);
+
+        // Policy Name Assignment
+        AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
+        assignment3.setAttributeId("PolicyName");
+        assignment3.setCategory(CATEGORY_RESOURCE);
+        assignment3.setIssuer("");
+        AttributeValueType attributeValue3 = new AttributeValueType();
+        attributeValue3.setDataType(STRING_DATATYPE);
+        fileName = FilenameUtils.removeExtension(fileName);
+        fileName = fileName + ".xml";
+        System.out.println(fileName);
+        String name = fileName.substring(fileName.lastIndexOf("\\") + 1,
+                fileName.length());
+        if ((name == null) || (name.equals(""))) {
+            name = fileName.substring(fileName.lastIndexOf("/") + 1,
+                    fileName.length());
+        }
+        System.out.println(name);
+        attributeValue3.getContent().add(name);
+        assignment3.setExpression(new ObjectFactory()
+                .createAttributeValue(attributeValue3));
+        advice.getAttributeAssignmentExpression().add(assignment3);
+
+        // Version Number Assignment
+        AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
+        assignment4.setAttributeId("VersionNumber");
+        assignment4.setCategory(CATEGORY_RESOURCE);
+        assignment4.setIssuer("");
+        AttributeValueType configNameAttributeValue4 = new AttributeValueType();
+        configNameAttributeValue4.setDataType(STRING_DATATYPE);
+        configNameAttributeValue4.getContent().add(Integer.toString(version));
+        assignment4.setExpression(new ObjectFactory()
+                .createAttributeValue(configNameAttributeValue4));
+        advice.getAttributeAssignmentExpression().add(assignment4);
+
+        // Onap Name Assignment
+        AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
+        assignment5.setAttributeId("matching:" + ONAPID);
+        assignment5.setCategory(CATEGORY_RESOURCE);
+        assignment5.setIssuer("");
+        AttributeValueType configNameAttributeValue5 = new AttributeValueType();
+        configNameAttributeValue5.setDataType(STRING_DATATYPE);
+        configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
+        assignment5.setExpression(new ObjectFactory()
+                .createAttributeValue(configNameAttributeValue5));
+        advice.getAttributeAssignmentExpression().add(assignment5);
+
+
+        //Config Name Assignment
+        AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
+        assignment6.setAttributeId("matching:" + CONFIGID);
+        assignment6.setCategory(CATEGORY_RESOURCE);
+        assignment6.setIssuer("");
+        AttributeValueType configNameAttributeValue6 = new AttributeValueType();
+        configNameAttributeValue6.setDataType(STRING_DATATYPE);
+        configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
+        assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
+        advice.getAttributeAssignmentExpression().add(assignment6);
+
         // Adding Controller Information. 
         if(policyAdapter.getBrmsController()!=null){
             BRMSDictionaryController brmsDicitonaryController = new BRMSDictionaryController();
@@ -411,69 +411,69 @@ public class CreateBrmsRawPolicy extends Policy {
         }
         
         // Dynamic Field Config Attributes. 
-               Map<String, String> dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes();
-               for (String keyField : dynamicFieldConfigAttributes.keySet()) {
-                       advice.getAttributeAssignmentExpression().add(createResponseAttributes("key:"+keyField, dynamicFieldConfigAttributes.get(keyField)));
-               }
-               
-               //Risk Attributes
-               AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
-               assignment8.setAttributeId("RiskType");
-               assignment8.setCategory(CATEGORY_RESOURCE);
-               assignment8.setIssuer("");
-
-               AttributeValueType configNameAttributeValue8 = new AttributeValueType();
-               configNameAttributeValue8.setDataType(STRING_DATATYPE);
-               configNameAttributeValue8.getContent().add(policyAdapter.getRiskType());
-               assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
-
-               advice.getAttributeAssignmentExpression().add(assignment8);
-               
-               AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
-               assignment9.setAttributeId("RiskLevel");
-               assignment9.setCategory(CATEGORY_RESOURCE);
-               assignment9.setIssuer("");
-
-               AttributeValueType configNameAttributeValue9 = new AttributeValueType();
-               configNameAttributeValue9.setDataType(STRING_DATATYPE);
-               configNameAttributeValue9.getContent().add(policyAdapter.getRiskLevel());
-               assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
-
-               advice.getAttributeAssignmentExpression().add(assignment9);     
-
-               AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
-               assignment10.setAttributeId("guard");
-               assignment10.setCategory(CATEGORY_RESOURCE);
-               assignment10.setIssuer("");
-
-               AttributeValueType configNameAttributeValue10 = new AttributeValueType();
-               configNameAttributeValue10.setDataType(STRING_DATATYPE);
-               configNameAttributeValue10.getContent().add(policyAdapter.getGuard());
-               assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
-
-               advice.getAttributeAssignmentExpression().add(assignment10);
-
-               AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
-               assignment11.setAttributeId("TTLDate");
-               assignment11.setCategory(CATEGORY_RESOURCE);
-               assignment11.setIssuer("");
-
-               AttributeValueType configNameAttributeValue11 = new AttributeValueType();
-               configNameAttributeValue11.setDataType(STRING_DATATYPE);
-               configNameAttributeValue11.getContent().add(policyAdapter.getTtlDate());
-               assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
-
-               advice.getAttributeAssignmentExpression().add(assignment11);
-
-               advices.getAdviceExpression().add(advice);
-               return advices;
-       }
-
-       @Override
-       public Object getCorrectPolicyDataObject() {
-               return policyAdapter.getData();
-       }
-       
+        Map<String, String> dynamicFieldConfigAttributes = policyAdapter.getDynamicFieldConfigAttributes();
+        for (String keyField : dynamicFieldConfigAttributes.keySet()) {
+            advice.getAttributeAssignmentExpression().add(createResponseAttributes("key:"+keyField, dynamicFieldConfigAttributes.get(keyField)));
+        }
+
+        //Risk Attributes
+        AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
+        assignment8.setAttributeId("RiskType");
+        assignment8.setCategory(CATEGORY_RESOURCE);
+        assignment8.setIssuer("");
+
+        AttributeValueType configNameAttributeValue8 = new AttributeValueType();
+        configNameAttributeValue8.setDataType(STRING_DATATYPE);
+        configNameAttributeValue8.getContent().add(policyAdapter.getRiskType());
+        assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
+
+        advice.getAttributeAssignmentExpression().add(assignment8);
+
+        AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
+        assignment9.setAttributeId("RiskLevel");
+        assignment9.setCategory(CATEGORY_RESOURCE);
+        assignment9.setIssuer("");
+
+        AttributeValueType configNameAttributeValue9 = new AttributeValueType();
+        configNameAttributeValue9.setDataType(STRING_DATATYPE);
+        configNameAttributeValue9.getContent().add(policyAdapter.getRiskLevel());
+        assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
+
+        advice.getAttributeAssignmentExpression().add(assignment9);
+
+        AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
+        assignment10.setAttributeId("guard");
+        assignment10.setCategory(CATEGORY_RESOURCE);
+        assignment10.setIssuer("");
+
+        AttributeValueType configNameAttributeValue10 = new AttributeValueType();
+        configNameAttributeValue10.setDataType(STRING_DATATYPE);
+        configNameAttributeValue10.getContent().add(policyAdapter.getGuard());
+        assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
+
+        advice.getAttributeAssignmentExpression().add(assignment10);
+
+        AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
+        assignment11.setAttributeId("TTLDate");
+        assignment11.setCategory(CATEGORY_RESOURCE);
+        assignment11.setIssuer("");
+
+        AttributeValueType configNameAttributeValue11 = new AttributeValueType();
+        configNameAttributeValue11.setDataType(STRING_DATATYPE);
+        configNameAttributeValue11.getContent().add(policyAdapter.getTtlDate());
+        assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
+
+        advice.getAttributeAssignmentExpression().add(assignment11);
+
+        advices.getAdviceExpression().add(advice);
+        return advices;
+    }
+
+    @Override
+    public Object getCorrectPolicyDataObject() {
+        return policyAdapter.getData();
+    }
+
     private AttributeAssignmentExpressionType  createResponseAttributes(String key, String value){
         AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
         assignment7.setAttributeId(key);
index 456924a..e74cc33 100644 (file)
@@ -55,351 +55,351 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
 
 public class CreateClosedLoopPerformanceMetrics extends Policy {
-       
-       private static final Logger LOGGER      = FlexLogger.getLogger(CreateClosedLoopPerformanceMetrics.class);
-       
-       public CreateClosedLoopPerformanceMetrics() {
-               super();
-       }
-       
-       public CreateClosedLoopPerformanceMetrics(PolicyRestAdapter policyAdapter){
-               this.policyAdapter = policyAdapter;
-       }
-
-       //save configuration of the policy based on the policyname
-       private void saveConfigurations(String policyName, final String jsonBody) {
-           
-               if(policyName.endsWith(".xml")){
-                   policyName   = policyName.substring(0, policyName.lastIndexOf(".xml"));
-               }
-               try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + "."+ policyName +".json")){
-                       out.println(jsonBody);
-                       policyAdapter.setJsonBody(jsonBody);
-                       policyAdapter.setConfigBodyData(jsonBody);
-               } catch (Exception e) {
-                       LOGGER.error("Exception Occured"+e);
-               }
-       }
-       
-       //getting the policy name and setting to configuration on adding .json
-       private String getConfigFile(String filename) {
-               filename = FilenameUtils.removeExtension(filename);
-               if (filename.endsWith(".xml")) {
-                       filename = filename.substring(0, filename.length() - 4);
-               }
-               filename = filename +".json";
-               return filename;
-       }
-       
-       @Override
-       public Map<String, String> savePolicies() throws PAPException {
-
-               Map<String, String> successMap = new HashMap<>();
-               if(isPolicyExists()){
-                       successMap.put("EXISTS", "This Policy already exist on the PAP");
-                       return successMap;
-               }
-
-               if(!isPreparedToSave()){
-                       //Prep and configure the policy for saving
-                       prepareToSave();
-               }
-
-               // Until here we prepared the data and here calling the method to create xml.
-               Path newPolicyPath = null;
-               newPolicyPath = Paths.get(policyAdapter.getNewFileName());
-
-               successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());  
-               
-               return successMap;              
-       }
-       
-       //This is the method for preparing the policy for saving.  We have broken it out
-       //separately because the fully configured policy is used for multiple things
-       @Override
-       public boolean prepareToSave() throws PAPException{
-
-               if(isPreparedToSave()){
-                       //we have already done this
-                       return true;
-               }
-               
-               int version = 0;
-               String policyID = policyAdapter.getPolicyID();
-               version = policyAdapter.getHighestVersion();
-               
-               // Create the Instance for pojo, PolicyType object is used in marshalling.
-               if (policyAdapter.getPolicyType().equals("Config")) {
-                       PolicyType policyConfig = new PolicyType();
-
-                       policyConfig.setVersion(Integer.toString(version));
-                       policyConfig.setPolicyId(policyID);
-                       policyConfig.setTarget(new TargetType());
-                       policyAdapter.setData(policyConfig);
-               }
-               policyName = policyAdapter.getNewFileName();
-               if (policyAdapter.getData() != null) {
-                       // Save the Configurations file with the policy name with extention based on selection.
-                       String jsonBody = policyAdapter.getJsonBody();
-                       saveConfigurations(policyName, jsonBody);
-                       
-                       // Make sure the filename ends with an extension
-                       if (policyName.endsWith(".xml") == false) {
-                               policyName = policyName + ".xml";
-                       }
-                       
-       
-                       PolicyType configPolicy = (PolicyType) policyAdapter.getData();
-                       
-                       configPolicy.setDescription(policyAdapter.getPolicyDescription());
-
-                       configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
-                       
-                       AllOfType allOfOne = new AllOfType();
-                       String fileName = policyAdapter.getNewFileName();
-                       String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
-                       if ((name == null) || (name.equals(""))) {
-                               name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
-                       }
-                       allOfOne.getMatch().add(createMatch("PolicyName", name));
-                       AllOfType allOf = new AllOfType();
-                       
-                       // Adding the matches to AllOfType element Match for Onap
-                       allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
-                       // Match for riskType
-                       allOf.getMatch().add(
-                                       createDynamicMatch("RiskType", policyAdapter.getRiskType()));
-                       // Match for riskLevel
-                       allOf.getMatch().add(
-                                       createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
-                       // Match for riskguard
-                       allOf.getMatch().add(
-                                       createDynamicMatch("guard", policyAdapter.getGuard()));
-                       // Match for ttlDate
-                       allOf.getMatch().add(
-                                       createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
-                       // Match for ServiceType
-                       allOf.getMatch().add(createMatch("ServiceType", policyAdapter.getServiceType()));
-
-                       AnyOfType anyOf = new AnyOfType();
-                       anyOf.getAllOf().add(allOfOne);
-                       anyOf.getAllOf().add(allOf);
-
-                       TargetType target = new TargetType();
-                       ((TargetType) target).getAnyOf().add(anyOf);
-                       
-                       // Adding the target to the policy element
-                       configPolicy.setTarget((TargetType) target);
-
-                       RuleType rule = new RuleType();
-                       rule.setRuleId(policyAdapter.getRuleID());
-                       
-                       rule.setEffect(EffectType.PERMIT);
-                       
-                       // Create Target in Rule
-                       AllOfType allOfInRule = new AllOfType();
-
-                       // Creating match for ACCESS in rule target
-                       MatchType accessMatch = new MatchType();
-                       AttributeValueType accessAttributeValue = new AttributeValueType();
-                       accessAttributeValue.setDataType(STRING_DATATYPE);
-                       accessAttributeValue.getContent().add("ACCESS");
-                       accessMatch.setAttributeValue(accessAttributeValue);
-                       AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
-                       URI accessURI = null;
-                       try {
-                               accessURI = new URI(ACTION_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateClosedLoopPerformanceMetrics", "Exception creating ACCESS URI");
-                       }
-                       accessAttributeDesignator.setCategory(CATEGORY_ACTION);
-                       accessAttributeDesignator.setDataType(STRING_DATATYPE);
-                       accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
-                       accessMatch.setAttributeDesignator(accessAttributeDesignator);
-                       accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       // Creating Config Match in rule Target
-                       MatchType configMatch = new MatchType();
-                       AttributeValueType configAttributeValue = new AttributeValueType();
-                       configAttributeValue.setDataType(STRING_DATATYPE);
-                       configAttributeValue.getContent().add("Config");
-                       configMatch.setAttributeValue(configAttributeValue);
-                       AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
-                       URI configURI = null;
-                       try {
-                               configURI = new URI(RESOURCE_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateClosedLoopPerformanceMetrics", "Exception creating Config URI");
-                       }
-                       configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
-                       configAttributeDesignator.setDataType(STRING_DATATYPE);
-                       configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
-                       configMatch.setAttributeDesignator(configAttributeDesignator);
-                       configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       allOfInRule.getMatch().add(accessMatch);
-                       allOfInRule.getMatch().add(configMatch);
-
-                       AnyOfType anyOfInRule = new AnyOfType();
-                       anyOfInRule.getAllOf().add(allOfInRule);
-
-                       TargetType targetInRule = new TargetType();
-                       targetInRule.getAnyOf().add(anyOfInRule);
-
-                       rule.setTarget(targetInRule);
-                       rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
-
-                       configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
-                       policyAdapter.setPolicyData(configPolicy);
-
-               } else {
-                       PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
-               }
-               setPreparedToSave(true);
-               return true;
-       }
-       
-       // Data required for Advice part is setting here.
-       @SuppressWarnings("static-access")
-       private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
-               AdviceExpressionsType advices = new AdviceExpressionsType();
-               AdviceExpressionType advice = new AdviceExpressionType();
-               advice.setAdviceId("PMID");
-               advice.setAppliesTo(EffectType.PERMIT);
-               // For Configuration
-               AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
-               assignment1.setAttributeId("type");
-               assignment1.setCategory(CATEGORY_RESOURCE);
-               assignment1.setIssuer("");
-
-               AttributeValueType configNameAttributeValue = new AttributeValueType();
-               configNameAttributeValue.setDataType(STRING_DATATYPE);
-               configNameAttributeValue.getContent().add("Configuration");
-               assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
-
-               advice.getAttributeAssignmentExpression().add(assignment1);
-               // For Config file Url if configurations are provided.
-               AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
-               assignment2.setAttributeId("URLID");
-               assignment2.setCategory(CATEGORY_RESOURCE);
-               assignment2.setIssuer("");
-
-               AttributeValueType AttributeValue = new AttributeValueType();
-               AttributeValue.setDataType(URI_DATATYPE);
-               String content = CONFIG_URL +"/Config/"+ getConfigFile(policyName);
-               AttributeValue.getContent().add(content);
-               assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue));
-
-               advice.getAttributeAssignmentExpression().add(assignment2);
-               AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
-               assignment3.setAttributeId("PolicyName");
-               assignment3.setCategory(CATEGORY_RESOURCE);
-               assignment3.setIssuer("");
-
-               AttributeValueType attributeValue3 = new AttributeValueType();
-               attributeValue3.setDataType(STRING_DATATYPE);
-               fileName = FilenameUtils.removeExtension(fileName);
-               fileName = fileName + ".xml";
-               String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
-               if ((name == null) || (name.equals(""))) {
-                       name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
-               }
-               attributeValue3.getContent().add(name);
-               assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
-               advice.getAttributeAssignmentExpression().add(assignment3);
-
-               AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
-               assignment4.setAttributeId("VersionNumber");
-               assignment4.setCategory(CATEGORY_RESOURCE);
-               assignment4.setIssuer("");
-
-               AttributeValueType configNameAttributeValue4 = new AttributeValueType();
-               configNameAttributeValue4.setDataType(STRING_DATATYPE);
-               configNameAttributeValue4.getContent().add(Integer.toString(version));
-               assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
-
-               advice.getAttributeAssignmentExpression().add(assignment4);
-
-               AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
-               assignment5.setAttributeId("matching:" + this.ONAPID);
-               assignment5.setCategory(CATEGORY_RESOURCE);
-               assignment5.setIssuer("");
-
-               AttributeValueType configNameAttributeValue5 = new AttributeValueType();
-               configNameAttributeValue5.setDataType(STRING_DATATYPE);
-               configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
-               assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
-
-               advice.getAttributeAssignmentExpression().add(assignment5);
-
-               AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
-               assignment6.setAttributeId("matching:" + this.CLOSEDLOOPID);
-               assignment6.setCategory(CATEGORY_RESOURCE);
-               assignment6.setIssuer("");
-
-               AttributeValueType configNameAttributeValue6 = new AttributeValueType();
-               configNameAttributeValue6.setDataType(STRING_DATATYPE);
-               configNameAttributeValue6.getContent().add(policyAdapter.getServiceType());
-               assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
-
-               advice.getAttributeAssignmentExpression().add(assignment6);
-               
-               //Risk Attributes
-               AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
-               assignment7.setAttributeId("RiskType");
-               assignment7.setCategory(CATEGORY_RESOURCE);
-               assignment7.setIssuer("");
-
-               AttributeValueType configNameAttributeValue7 = new AttributeValueType();
-               configNameAttributeValue7.setDataType(STRING_DATATYPE);
-               configNameAttributeValue7.getContent().add(policyAdapter.getRiskType());
-               assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
-
-               advice.getAttributeAssignmentExpression().add(assignment7);
-               
-               AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
-               assignment8.setAttributeId("RiskLevel");
-               assignment8.setCategory(CATEGORY_RESOURCE);
-               assignment8.setIssuer("");
-
-               AttributeValueType configNameAttributeValue8 = new AttributeValueType();
-               configNameAttributeValue8.setDataType(STRING_DATATYPE);
-               configNameAttributeValue8.getContent().add(policyAdapter.getRiskLevel());
-               assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
-
-               advice.getAttributeAssignmentExpression().add(assignment8);     
-
-               AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
-               assignment9.setAttributeId("guard");
-               assignment9.setCategory(CATEGORY_RESOURCE);
-               assignment9.setIssuer("");
-
-               AttributeValueType configNameAttributeValue9 = new AttributeValueType();
-               configNameAttributeValue9.setDataType(STRING_DATATYPE);
-               configNameAttributeValue9.getContent().add(policyAdapter.getGuard());
-               assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
-
-               advice.getAttributeAssignmentExpression().add(assignment9);
-               
-               AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
-               assignment10.setAttributeId("TTLDate");
-               assignment10.setCategory(CATEGORY_RESOURCE);
-               assignment10.setIssuer("");
-
-               AttributeValueType configNameAttributeValue10 = new AttributeValueType();
-               configNameAttributeValue10.setDataType(STRING_DATATYPE);
-               configNameAttributeValue10.getContent().add(policyAdapter.getTtlDate());
-               assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
-
-               advice.getAttributeAssignmentExpression().add(assignment10);
-
-               advices.getAdviceExpression().add(advice);
-               return advices;
-       }
-
-       @Override
-       public Object getCorrectPolicyDataObject() {
-               return policyAdapter.getPolicyData();
-       }       
+
+    private static final Logger LOGGER = FlexLogger.getLogger(CreateClosedLoopPerformanceMetrics.class);
+
+    public CreateClosedLoopPerformanceMetrics() {
+        super();
+    }
+
+    public CreateClosedLoopPerformanceMetrics(PolicyRestAdapter policyAdapter){
+        this.policyAdapter = policyAdapter;
+    }
+
+    //save configuration of the policy based on the policyname
+    private void saveConfigurations(String policyName, final String jsonBody) {
+
+            if(policyName.endsWith(".xml")){
+                policyName   = policyName.substring(0, policyName.lastIndexOf(".xml"));
+            }
+        try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + "."+ policyName +".json")){
+            out.println(jsonBody);
+            policyAdapter.setJsonBody(jsonBody);
+            policyAdapter.setConfigBodyData(jsonBody);
+        } catch (Exception e) {
+            LOGGER.error("Exception Occured"+e);
+        }
+    }
+
+    //getting the policy name and setting to configuration on adding .json
+    private String getConfigFile(String filename) {
+        filename = FilenameUtils.removeExtension(filename);
+        if (filename.endsWith(".xml")) {
+            filename = filename.substring(0, filename.length() - 4);
+        }
+        filename = filename +".json";
+        return filename;
+    }
+
+    @Override
+    public Map<String, String> savePolicies() throws PAPException {
+
+        Map<String, String> successMap = new HashMap<>();
+        if(isPolicyExists()){
+            successMap.put("EXISTS", "This Policy already exist on the PAP");
+            return successMap;
+        }
+
+        if(!isPreparedToSave()){
+            //Prep and configure the policy for saving
+            prepareToSave();
+        }
+
+        // Until here we prepared the data and here calling the method to create xml.
+        Path newPolicyPath = null;
+        newPolicyPath = Paths.get(policyAdapter.getNewFileName());
+
+        successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());
+
+        return successMap;
+    }
+
+    //This is the method for preparing the policy for saving.  We have broken it out
+    //separately because the fully configured policy is used for multiple things
+    @Override
+    public boolean prepareToSave() throws PAPException{
+
+        if(isPreparedToSave()){
+            //we have already done this
+            return true;
+        }
+
+        int version = 0;
+        String policyID = policyAdapter.getPolicyID();
+        version = policyAdapter.getHighestVersion();
+
+        // Create the Instance for pojo, PolicyType object is used in marshalling.
+        if (policyAdapter.getPolicyType().equals("Config")) {
+            PolicyType policyConfig = new PolicyType();
+
+            policyConfig.setVersion(Integer.toString(version));
+            policyConfig.setPolicyId(policyID);
+            policyConfig.setTarget(new TargetType());
+            policyAdapter.setData(policyConfig);
+        }
+        policyName = policyAdapter.getNewFileName();
+        if (policyAdapter.getData() != null) {
+            // Save the Configurations file with the policy name with extention based on selection.
+            String jsonBody = policyAdapter.getJsonBody();
+            saveConfigurations(policyName, jsonBody);
+
+            // Make sure the filename ends with an extension
+            if (policyName.endsWith(".xml") == false) {
+                policyName = policyName + ".xml";
+            }
+
+
+            PolicyType configPolicy = (PolicyType) policyAdapter.getData();
+
+            configPolicy.setDescription(policyAdapter.getPolicyDescription());
+
+            configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
+
+            AllOfType allOfOne = new AllOfType();
+            String fileName = policyAdapter.getNewFileName();
+            String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
+            if ((name == null) || (name.equals(""))) {
+                name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
+            }
+            allOfOne.getMatch().add(createMatch("PolicyName", name));
+            AllOfType allOf = new AllOfType();
+
+            // Adding the matches to AllOfType element Match for Onap
+            allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
+            // Match for riskType
+            allOf.getMatch().add(
+                    createDynamicMatch("RiskType", policyAdapter.getRiskType()));
+            // Match for riskLevel
+            allOf.getMatch().add(
+                    createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
+            // Match for riskguard
+            allOf.getMatch().add(
+                    createDynamicMatch("guard", policyAdapter.getGuard()));
+            // Match for ttlDate
+            allOf.getMatch().add(
+                    createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
+            // Match for ServiceType
+            allOf.getMatch().add(createMatch("ServiceType", policyAdapter.getServiceType()));
+
+            AnyOfType anyOf = new AnyOfType();
+            anyOf.getAllOf().add(allOfOne);
+            anyOf.getAllOf().add(allOf);
+
+            TargetType target = new TargetType();
+            ((TargetType) target).getAnyOf().add(anyOf);
+
+            // Adding the target to the policy element
+            configPolicy.setTarget((TargetType) target);
+
+            RuleType rule = new RuleType();
+            rule.setRuleId(policyAdapter.getRuleID());
+
+            rule.setEffect(EffectType.PERMIT);
+
+            // Create Target in Rule
+            AllOfType allOfInRule = new AllOfType();
+
+            // Creating match for ACCESS in rule target
+            MatchType accessMatch = new MatchType();
+            AttributeValueType accessAttributeValue = new AttributeValueType();
+            accessAttributeValue.setDataType(STRING_DATATYPE);
+            accessAttributeValue.getContent().add("ACCESS");
+            accessMatch.setAttributeValue(accessAttributeValue);
+            AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
+            URI accessURI = null;
+            try {
+                accessURI = new URI(ACTION_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateClosedLoopPerformanceMetrics", "Exception creating ACCESS URI");
+            }
+            accessAttributeDesignator.setCategory(CATEGORY_ACTION);
+            accessAttributeDesignator.setDataType(STRING_DATATYPE);
+            accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
+            accessMatch.setAttributeDesignator(accessAttributeDesignator);
+            accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            // Creating Config Match in rule Target
+            MatchType configMatch = new MatchType();
+            AttributeValueType configAttributeValue = new AttributeValueType();
+            configAttributeValue.setDataType(STRING_DATATYPE);
+            configAttributeValue.getContent().add("Config");
+            configMatch.setAttributeValue(configAttributeValue);
+            AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
+            URI configURI = null;
+            try {
+                configURI = new URI(RESOURCE_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "CreateClosedLoopPerformanceMetrics", "Exception creating Config URI");
+            }
+            configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
+            configAttributeDesignator.setDataType(STRING_DATATYPE);
+            configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
+            configMatch.setAttributeDesignator(configAttributeDesignator);
+            configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            allOfInRule.getMatch().add(accessMatch);
+            allOfInRule.getMatch().add(configMatch);
+
+            AnyOfType anyOfInRule = new AnyOfType();
+            anyOfInRule.getAllOf().add(allOfInRule);
+
+            TargetType targetInRule = new TargetType();
+            targetInRule.getAnyOf().add(anyOfInRule);
+
+            rule.setTarget(targetInRule);
+            rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
+
+            configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
+            policyAdapter.setPolicyData(configPolicy);
+
+        } else {
+            PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
+        }
+        setPreparedToSave(true);
+        return true;
+    }
+
+    // Data required for Advice part is setting here.
+    @SuppressWarnings("static-access")
+    private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
+        AdviceExpressionsType advices = new AdviceExpressionsType();
+        AdviceExpressionType advice = new AdviceExpressionType();
+        advice.setAdviceId("PMID");
+        advice.setAppliesTo(EffectType.PERMIT);
+        // For Configuration
+        AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
+        assignment1.setAttributeId("type");
+        assignment1.setCategory(CATEGORY_RESOURCE);
+        assignment1.setIssuer("");
+
+        AttributeValueType configNameAttributeValue = new AttributeValueType();
+        configNameAttributeValue.setDataType(STRING_DATATYPE);
+        configNameAttributeValue.getContent().add("Configuration");
+        assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
+
+        advice.getAttributeAssignmentExpression().add(assignment1);
+        // For Config file Url if configurations are provided.
+        AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
+        assignment2.setAttributeId("URLID");
+        assignment2.setCategory(CATEGORY_RESOURCE);
+        assignment2.setIssuer("");
+
+        AttributeValueType AttributeValue = new AttributeValueType();
+        AttributeValue.setDataType(URI_DATATYPE);
+        String content = CONFIG_URL +"/Config/"+ getConfigFile(policyName);
+        AttributeValue.getContent().add(content);
+        assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue));
+
+        advice.getAttributeAssignmentExpression().add(assignment2);
+        AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
+        assignment3.setAttributeId("PolicyName");
+        assignment3.setCategory(CATEGORY_RESOURCE);
+        assignment3.setIssuer("");
+
+        AttributeValueType attributeValue3 = new AttributeValueType();
+        attributeValue3.setDataType(STRING_DATATYPE);
+        fileName = FilenameUtils.removeExtension(fileName);
+        fileName = fileName + ".xml";
+        String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
+        if ((name == null) || (name.equals(""))) {
+            name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
+        }
+        attributeValue3.getContent().add(name);
+        assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
+        advice.getAttributeAssignmentExpression().add(assignment3);
+
+        AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
+        assignment4.setAttributeId("VersionNumber");
+        assignment4.setCategory(CATEGORY_RESOURCE);
+        assignment4.setIssuer("");
+
+        AttributeValueType configNameAttributeValue4 = new AttributeValueType();
+        configNameAttributeValue4.setDataType(STRING_DATATYPE);
+        configNameAttributeValue4.getContent().add(Integer.toString(version));
+        assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
+
+        advice.getAttributeAssignmentExpression().add(assignment4);
+
+        AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
+        assignment5.setAttributeId("matching:" + this.ONAPID);
+        assignment5.setCategory(CATEGORY_RESOURCE);
+        assignment5.setIssuer("");
+
+        AttributeValueType configNameAttributeValue5 = new AttributeValueType();
+        configNameAttributeValue5.setDataType(STRING_DATATYPE);
+        configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
+        assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
+
+        advice.getAttributeAssignmentExpression().add(assignment5);
+
+        AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
+        assignment6.setAttributeId("matching:" + this.CLOSEDLOOPID);
+        assignment6.setCategory(CATEGORY_RESOURCE);
+        assignment6.setIssuer("");
+
+        AttributeValueType configNameAttributeValue6 = new AttributeValueType();
+        configNameAttributeValue6.setDataType(STRING_DATATYPE);
+        configNameAttributeValue6.getContent().add(policyAdapter.getServiceType());
+        assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
+
+        advice.getAttributeAssignmentExpression().add(assignment6);
+
+        //Risk Attributes
+        AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
+        assignment7.setAttributeId("RiskType");
+        assignment7.setCategory(CATEGORY_RESOURCE);
+        assignment7.setIssuer("");
+
+        AttributeValueType configNameAttributeValue7 = new AttributeValueType();
+        configNameAttributeValue7.setDataType(STRING_DATATYPE);
+        configNameAttributeValue7.getContent().add(policyAdapter.getRiskType());
+        assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
+
+        advice.getAttributeAssignmentExpression().add(assignment7);
+
+        AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
+        assignment8.setAttributeId("RiskLevel");
+        assignment8.setCategory(CATEGORY_RESOURCE);
+        assignment8.setIssuer("");
+
+        AttributeValueType configNameAttributeValue8 = new AttributeValueType();
+        configNameAttributeValue8.setDataType(STRING_DATATYPE);
+        configNameAttributeValue8.getContent().add(policyAdapter.getRiskLevel());
+        assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
+
+        advice.getAttributeAssignmentExpression().add(assignment8);
+
+        AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
+        assignment9.setAttributeId("guard");
+        assignment9.setCategory(CATEGORY_RESOURCE);
+        assignment9.setIssuer("");
+
+        AttributeValueType configNameAttributeValue9 = new AttributeValueType();
+        configNameAttributeValue9.setDataType(STRING_DATATYPE);
+        configNameAttributeValue9.getContent().add(policyAdapter.getGuard());
+        assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
+
+        advice.getAttributeAssignmentExpression().add(assignment9);
+
+        AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
+        assignment10.setAttributeId("TTLDate");
+        assignment10.setCategory(CATEGORY_RESOURCE);
+        assignment10.setIssuer("");
+
+        AttributeValueType configNameAttributeValue10 = new AttributeValueType();
+        configNameAttributeValue10.setDataType(STRING_DATATYPE);
+        configNameAttributeValue10.getContent().add(policyAdapter.getTtlDate());
+        assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
+
+        advice.getAttributeAssignmentExpression().add(assignment10);
+
+        advices.getAdviceExpression().add(advice);
+        return advices;
+    }
+
+    @Override
+    public Object getCorrectPolicyDataObject() {
+        return policyAdapter.getPolicyData();
+    }
 
 }
index c4de9a0..87c9f91 100644 (file)
@@ -50,243 +50,243 @@ import org.onap.policy.rest.util.MSModelUtils.MODEL_TYPE;
 import com.google.gson.Gson;
 
 public class CreateNewOptimizationModel {
-       private static final Logger logger = FlexLogger.getLogger(CreateNewOptimizationModel.class);
-       private OptimizationModels newModel = null;
-       private HashMap<String,MSAttributeObject > classMap = new HashMap<>();
-       
-       private static final String EXTRACTDIR = "ExtractDir";
-       private static final String SUCCESS = "success";
-
-       
-       MSModelUtils utils = new MSModelUtils(XACMLPapServlet.getMsOnapName(), XACMLPapServlet.getMsPolicyName());
-
-       public CreateNewOptimizationModel() {
-               super();
-       }
-
-       public CreateNewOptimizationModel(String importFile, String  modelName, String description, String version, String randomID) {
-       
-               this.newModel = new OptimizationModels();
-               this.newModel.setVersion(version);
-               this.newModel.setModelName(modelName);
-               this.newModel.setDescription(description);
-               UserInfo userInfo = new UserInfo();
-               userInfo.setUserLoginId("API");
-               this.newModel.setUserCreatedBy(userInfo);
-               String cleanUpFile = null;
-       
-           Map<String, MSAttributeObject> tempMap = new HashMap<>();
-           //Need to delete the file
-           if (importFile.contains(".zip")){
-               extractFolder(randomID + ".zip");
-               File directory = new File(EXTRACTDIR + File.separator + randomID);
-               List<File> fileList = listModelFiles(directory.toString());
-               //get all the files from a director
-               for (File file : fileList){
-                   if (file.isFile()){
-                       processYmlModel(file.toString(), modelName);
-                   }
-               }
-               cleanUpFile = EXTRACTDIR + File.separator + randomID + ".zip";
-               try {
-                               FileUtils.deleteDirectory(new File(EXTRACTDIR + File.separator + randomID));
-                               FileUtils.deleteDirectory(new File(randomID));
-                               File deleteFile = new File(cleanUpFile); 
-                               FileUtils.forceDelete(deleteFile);
-                       } catch (IOException e) {
-                               logger.error("Failed to unzip model file " + randomID, e);
-                       }
-           }else {
-               if(importFile.contains(".yml")){
-                       
-                               processYmlModel(EXTRACTDIR + File.separator + randomID+".yml", modelName);
-                           cleanUpFile = EXTRACTDIR + File.separator + randomID+".yml";
-                       
-               }else{
-                           tempMap = utils.processEpackage(EXTRACTDIR + File.separator + randomID+".xmi", MODEL_TYPE.XMI);
-                           classMap.putAll(tempMap);
-                           cleanUpFile = EXTRACTDIR + File.separator + randomID+".xmi";
-               }
-                   File deleteFile = new File(cleanUpFile); 
-                       deleteFile.delete();
-           }
-       }
-       
-       private void processYmlModel(String fileName, String  modelName){
-
-               try {
-                       
-                       utils.parseTosca(fileName);
-                       
-                       MSAttributeObject msAttributes= new MSAttributeObject();
-                       msAttributes.setClassName(modelName);
-                       
-                       LinkedHashMap<String, String> returnAttributeList =new LinkedHashMap<>();
-                       returnAttributeList.put(modelName, utils.getAttributeString());
-                       msAttributes.setAttribute(returnAttributeList);
-                       
-                       msAttributes.setSubClass(utils.getRetmap());
-                       
-                       msAttributes.setMatchingSet(utils.getMatchableValues());
-                       
-                       LinkedHashMap<String, String> returnReferenceList =new LinkedHashMap<>();
-
-                       returnReferenceList.put(modelName, utils.getReferenceAttributes());
-                       msAttributes.setRefAttribute(returnReferenceList);
-                       
-                       if(!"".equals(utils.getListConstraints())){
-                               LinkedHashMap<String, String> enumList =new LinkedHashMap<>();
-                               String[] listArray=utils.getListConstraints().split("#");
+    private static final Logger logger = FlexLogger.getLogger(CreateNewOptimizationModel.class);
+    private OptimizationModels newModel = null;
+    private HashMap<String,MSAttributeObject > classMap = new HashMap<>();
+
+    private static final String EXTRACTDIR = "ExtractDir";
+    private static final String SUCCESS = "success";
+
+
+    MSModelUtils utils = new MSModelUtils(XACMLPapServlet.getMsOnapName(), XACMLPapServlet.getMsPolicyName());
+
+    public CreateNewOptimizationModel() {
+        super();
+    }
+
+    public CreateNewOptimizationModel(String importFile, String  modelName, String description, String version, String randomID) {
+
+        this.newModel = new OptimizationModels();
+        this.newModel.setVersion(version);
+        this.newModel.setModelName(modelName);
+        this.newModel.setDescription(description);
+        UserInfo userInfo = new UserInfo();
+        userInfo.setUserLoginId("API");
+        this.newModel.setUserCreatedBy(userInfo);
+        String cleanUpFile = null;
+
+        Map<String, MSAttributeObject> tempMap = new HashMap<>();
+        //Need to delete the file
+        if (importFile.contains(".zip")){
+            extractFolder(randomID + ".zip");
+            File directory = new File(EXTRACTDIR + File.separator + randomID);
+            List<File> fileList = listModelFiles(directory.toString());
+            //get all the files from a director
+            for (File file : fileList){
+                if (file.isFile()){
+                    processYmlModel(file.toString(), modelName);
+                }
+            }
+            cleanUpFile = EXTRACTDIR + File.separator + randomID + ".zip";
+            try {
+                FileUtils.deleteDirectory(new File(EXTRACTDIR + File.separator + randomID));
+                FileUtils.deleteDirectory(new File(randomID));
+                File deleteFile = new File(cleanUpFile);
+                FileUtils.forceDelete(deleteFile);
+            } catch (IOException e) {
+                logger.error("Failed to unzip model file " + randomID, e);
+            }
+        }else {
+            if(importFile.contains(".yml")){
+
+                processYmlModel(EXTRACTDIR + File.separator + randomID+".yml", modelName);
+                cleanUpFile = EXTRACTDIR + File.separator + randomID+".yml";
+
+            }else{
+                tempMap = utils.processEpackage(EXTRACTDIR + File.separator + randomID+".xmi", MODEL_TYPE.XMI);
+                classMap.putAll(tempMap);
+                cleanUpFile = EXTRACTDIR + File.separator + randomID+".xmi";
+            }
+            File deleteFile = new File(cleanUpFile);
+            deleteFile.delete();
+        }
+    }
+
+    private void processYmlModel(String fileName, String  modelName){
+
+        try {
+
+            utils.parseTosca(fileName);
+
+            MSAttributeObject msAttributes= new MSAttributeObject();
+            msAttributes.setClassName(modelName);
+
+            LinkedHashMap<String, String> returnAttributeList =new LinkedHashMap<>();
+            returnAttributeList.put(modelName, utils.getAttributeString());
+            msAttributes.setAttribute(returnAttributeList);
+
+            msAttributes.setSubClass(utils.getRetmap());
+
+            msAttributes.setMatchingSet(utils.getMatchableValues());
+
+            LinkedHashMap<String, String> returnReferenceList =new LinkedHashMap<>();
+
+            returnReferenceList.put(modelName, utils.getReferenceAttributes());
+            msAttributes.setRefAttribute(returnReferenceList);
+
+            if(!"".equals(utils.getListConstraints())){
+                LinkedHashMap<String, String> enumList =new LinkedHashMap<>();
+                String[] listArray=utils.getListConstraints().split("#");
                 for(String str:listArray){
                     String[] strArr= str.split("=");
                     if(strArr.length>1){
                         enumList.put(strArr[0], strArr[1]);
                     }
                 }
-                               msAttributes.setEnumType(enumList);
-                       }
-                       
-                       classMap=new LinkedHashMap<>();
-                       classMap.put(modelName, msAttributes);
-                       
-               } catch (Exception e) {
-                       logger.error("Failed to process yml model" + e);
-               }
-       
-       }
-       
-       private List<File> listModelFiles(String directoryName) {
-               File directory = new File(directoryName);
-               List<File> resultList = new ArrayList<>();
-               File[] fList = directory.listFiles();
-               for (File file : fList) {
-                       if (file.isFile()) {
-                               resultList.add(file);
-                       } else if (file.isDirectory()) {
-                               resultList.addAll(listModelFiles(file.getAbsolutePath()));
-                       }
-               }
-               return resultList;
-       }
-
-       @SuppressWarnings("rawtypes")
-       private void extractFolder(String zipFile) {
-           int buffer = 2048;
-           File file = new File(zipFile);
-
-               try(ZipFile zip = new ZipFile(EXTRACTDIR + File.separator +file);){
-                   String newPath =  zipFile.substring(0, zipFile.length() - 4);
-                   new File(newPath).mkdir();
-                   Enumeration zipFileEntries = zip.entries();
-       
-                   // Process each entry
-                   while (zipFileEntries.hasMoreElements()){
-                       // grab a zip file entry
-                       ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
-                       String currentEntry = entry.getName();
-                       File destFile = new File(EXTRACTDIR + File.separator + newPath + File.separator + currentEntry);
-                       File destinationParent = destFile.getParentFile();
-       
-                       destinationParent.mkdirs();
-       
-                       if (!entry.isDirectory()){
-                           int currentByte;
-
-                           byte[] data = new byte[buffer];
-                                       try(FileOutputStream fos = new FileOutputStream(destFile);
-                                                       BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
-                                                               BufferedOutputStream dest = new BufferedOutputStream(fos, buffer)) {
-
-                                               while ((currentByte = is.read(data, 0, buffer)) != -1) {
-                                                       dest.write(data, 0, currentByte);
-                                               }
-                                               dest.flush();
-                                       }
-                       }
-       
-                       if (currentEntry.endsWith(".zip")){
-                           extractFolder(destFile.getAbsolutePath());
-                       }
-                   }
-           } catch (IOException e) {
-                       logger.error("Failed to unzip model file " + zipFile + e);
-               }
-       }
-
-       public Map<String, String> addValuesToNewModel() {
-               
-               Map<String, String> successMap = new HashMap<>();
-               MSAttributeObject mainClass;
-               
-               if (!classMap.containsKey(this.newModel.getModelName())){
-                       logger.error("Model Provided does not contain the service name provided in request. Unable to import new model");
-                       PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "AddValuesToNewModel", "Unable to pull out required values, file missing service name provided in request");
-                       successMap.put("error", "MISSING");
-                       return successMap;
-               }
-               mainClass = classMap.get(this.newModel.getModelName());
-               newModel.setDependency("[]");
-               if(mainClass.getSubClass() != null){
-                  String value = new Gson().toJson(mainClass.getSubClass());
-                  newModel.setSubattributes(value);
-               }
-               
-               if(mainClass.getAttribute() != null){
-                       String attributes= mainClass.getAttribute().toString().replace("{", "").replace("}", "");
-                       int equalsIndexForAttributes= attributes.indexOf('=');
-                       String atttributesAfterFirstEquals= attributes.substring(equalsIndexForAttributes+1);
-                       this.newModel.setAttributes(atttributesAfterFirstEquals);
-               }
-               
-               if(mainClass.getRefAttribute() != null){
-                       String refAttributes= mainClass.getRefAttribute().toString().replace("{", "").replace("}", "");
-                       int equalsIndex= refAttributes.indexOf('=');
-                       String refAttributesAfterFirstEquals= refAttributes.substring(equalsIndex+1);
-                       this.newModel.setRefattributes(refAttributesAfterFirstEquals);
-               }
-               
-               if(mainClass.getEnumType() != null){
-                   this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
-               }
-               
-               if(mainClass.getMatchingSet() != null){
-                   this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
-               }
-               
-               successMap.put(SUCCESS, SUCCESS);
-               return successMap;
-               
-       }
-       
-       public Map<String, String> saveImportService(){
-               String modelName = this.newModel.getModelName();
-               String importedBy = "API";
-               String version = this.newModel.getVersion();
-               Map<String, String> successMap = new HashMap<>();
-               CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
-               List<Object> result = dbConnection.getDataById(OptimizationModels.class, "modelName:version", modelName+":"+version);
-               if(result.isEmpty()){
-                       OptimizationModels model = new OptimizationModels();
-                       model.setModelName(modelName);
-                       model.setVersion(version);
-                       model.setAttributes(this.newModel.getAttributes());
-                       model.setAnnotation(this.newModel.getAnnotation());
-                       model.setDependency(this.newModel.getDependency());
-                       model.setDescription(this.newModel.getDescription());
-                       model.setEnumValues(this.newModel.getEnumValues());
-                       model.setRefattributes(this.newModel.getRefattributes());
-                       model.setSubattributes(this.newModel.getSubattributes());
-                       model.setDataOrderInfo(this.newModel.getDataOrderInfo());
-                       UserInfo userInfo = new UserInfo();
-                       userInfo.setUserLoginId(importedBy);
-                       userInfo.setUserName(importedBy);
-                       model.setUserCreatedBy(userInfo);
-                       dbConnection.save(model);
-                       successMap.put(SUCCESS, SUCCESS);
-               }else{
-                       successMap.put("DBError", "EXISTS");
-                       logger.error("Import new service failed.  Service already exists");
-               }               
-               return successMap;
-       }
+                msAttributes.setEnumType(enumList);
+            }
+
+            classMap=new LinkedHashMap<>();
+            classMap.put(modelName, msAttributes);
+
+        } catch (Exception e) {
+            logger.error("Failed to process yml model" + e);
+        }
+
+    }
+
+    private List<File> listModelFiles(String directoryName) {
+        File directory = new File(directoryName);
+        List<File> resultList = new ArrayList<>();
+        File[] fList = directory.listFiles();
+        for (File file : fList) {
+            if (file.isFile()) {
+                resultList.add(file);
+            } else if (file.isDirectory()) {
+                resultList.addAll(listModelFiles(file.getAbsolutePath()));
+            }
+        }
+        return resultList;
+    }
+
+    @SuppressWarnings("rawtypes")
+    private void extractFolder(String zipFile) {
+        int buffer = 2048;
+        File file = new File(zipFile);
+
+        try(ZipFile zip = new ZipFile(EXTRACTDIR + File.separator +file);){
+            String newPath =  zipFile.substring(0, zipFile.length() - 4);
+            new File(newPath).mkdir();
+            Enumeration zipFileEntries = zip.entries();
+
+            // Process each entry
+            while (zipFileEntries.hasMoreElements()){
+                // grab a zip file entry
+                ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
+                String currentEntry = entry.getName();
+                File destFile = new File(EXTRACTDIR + File.separator + newPath + File.separator + currentEntry);
+                File destinationParent = destFile.getParentFile();
+
+                destinationParent.mkdirs();
+
+                if (!entry.isDirectory()){
+                    int currentByte;
+
+                    byte[] data = new byte[buffer];
+                    try(FileOutputStream fos = new FileOutputStream(destFile);
+                            BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry));
+                                BufferedOutputStream dest = new BufferedOutputStream(fos, buffer)) {
+
+                        while ((currentByte = is.read(data, 0, buffer)) != -1) {
+                            dest.write(data, 0, currentByte);
+                        }
+                        dest.flush();
+                    }
+                }
+
+                if (currentEntry.endsWith(".zip")){
+                    extractFolder(destFile.getAbsolutePath());
+                }
+            }
+        } catch (IOException e) {
+            logger.error("Failed to unzip model file " + zipFile + e);
+        }
+    }
+
+    public Map<String, String> addValuesToNewModel() {
+
+        Map<String, String> successMap = new HashMap<>();
+        MSAttributeObject mainClass;
+
+        if (!classMap.containsKey(this.newModel.getModelName())){
+            logger.error("Model Provided does not contain the service name provided in request. Unable to import new model");
+            PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "AddValuesToNewModel", "Unable to pull out required values, file missing service name provided in request");
+            successMap.put("error", "MISSING");
+            return successMap;
+        }
+        mainClass = classMap.get(this.newModel.getModelName());
+        newModel.setDependency("[]");
+        if(mainClass.getSubClass() != null){
+           String value = new Gson().toJson(mainClass.getSubClass());
+           newModel.setSubattributes(value);
+        }
+
+        if(mainClass.getAttribute() != null){
+            String attributes= mainClass.getAttribute().toString().replace("{", "").replace("}", "");
+            int equalsIndexForAttributes= attributes.indexOf('=');
+            String atttributesAfterFirstEquals= attributes.substring(equalsIndexForAttributes+1);
+            this.newModel.setAttributes(atttributesAfterFirstEquals);
+        }
+
+        if(mainClass.getRefAttribute() != null){
+            String refAttributes= mainClass.getRefAttribute().toString().replace("{", "").replace("}", "");
+            int equalsIndex= refAttributes.indexOf('=');
+            String refAttributesAfterFirstEquals= refAttributes.substring(equalsIndex+1);
+            this.newModel.setRefattributes(refAttributesAfterFirstEquals);
+        }
+
+        if(mainClass.getEnumType() != null){
+            this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
+        }
+
+        if(mainClass.getMatchingSet() != null){
+            this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
+        }
+
+        successMap.put(SUCCESS, SUCCESS);
+        return successMap;
+
+    }
+
+    public Map<String, String> saveImportService(){
+        String modelName = this.newModel.getModelName();
+        String importedBy = "API";
+        String version = this.newModel.getVersion();
+        Map<String, String> successMap = new HashMap<>();
+        CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
+        List<Object> result = dbConnection.getDataById(OptimizationModels.class, "modelName:version", modelName+":"+version);
+        if(result.isEmpty()){
+            OptimizationModels model = new OptimizationModels();
+            model.setModelName(modelName);
+            model.setVersion(version);
+            model.setAttributes(this.newModel.getAttributes());
+            model.setAnnotation(this.newModel.getAnnotation());
+            model.setDependency(this.newModel.getDependency());
+            model.setDescription(this.newModel.getDescription());
+            model.setEnumValues(this.newModel.getEnumValues());
+            model.setRefattributes(this.newModel.getRefattributes());
+            model.setSubattributes(this.newModel.getSubattributes());
+            model.setDataOrderInfo(this.newModel.getDataOrderInfo());
+            UserInfo userInfo = new UserInfo();
+            userInfo.setUserLoginId(importedBy);
+            userInfo.setUserName(importedBy);
+            model.setUserCreatedBy(userInfo);
+            dbConnection.save(model);
+            successMap.put(SUCCESS, SUCCESS);
+        }else{
+            successMap.put("DBError", "EXISTS");
+            logger.error("Import new service failed.  Service already exists");
+        }
+        return successMap;
+    }
 }
index c8c540c..eece6c0 100644 (file)
@@ -85,101 +85,101 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableDefinitionType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableReferenceType;
 
 public class DecisionPolicy extends Policy {
-       
-       private static final Logger LOGGER      = FlexLogger.getLogger(DecisionPolicy.class);
-       
-       public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not";
-       private static final String AAFPROVIDER = "AAF";
-       public static final String GUARD_YAML = "GUARD_YAML";
+
+    private static final Logger LOGGER = FlexLogger.getLogger(DecisionPolicy.class);
+
+    public static final String FUNCTION_NOT = "urn:oasis:names:tc:xacml:1.0:function:not";
+    private static final String AAFPROVIDER = "AAF";
+    public static final String GUARD_YAML = "GUARD_YAML";
     public static final String GUARD_BL_YAML = "GUARD_BL_YAML";
     public static final String RAINY_DAY = "Rainy_Day";
     private static final String XACML_GUARD_TEMPLATE = "Decision_GuardPolicyTemplate.xml";
     private static final String XACML_BLGUARD_TEMPLATE = "Decision_GuardBLPolicyTemplate.xml";
 
-       private static final String ONAPNAME = "ONAPName";
-       private static final String POLICY_NAME = "PolicyName";
-       private static final String DESCRIPTION = "description";
-
-       
-       List<String> dynamicLabelRuleAlgorithms = new LinkedList<>();
-       List<String> dynamicFieldComboRuleAlgorithms = new LinkedList<>();
-       List<String> dynamicFieldOneRuleAlgorithms = new LinkedList<>();
-       List<String> dynamicFieldTwoRuleAlgorithms = new LinkedList<>();
-       List<String> dataTypeList = new LinkedList<>();
-       
-       private CommonClassDao commonClassDao;
-       
-       public DecisionPolicy() {
-               super();
-       }
-       
-       public DecisionPolicy(PolicyRestAdapter policyAdapter, CommonClassDao commonClassDao){
-               this.policyAdapter = policyAdapter;
-               this.commonClassDao = commonClassDao;
-       }
-       
-       @Override
-       public Map<String, String> savePolicies() throws PAPException {
-
-               Map<String, String> successMap = new HashMap<>();
-               if(isPolicyExists()){
-                       successMap.put("EXISTS", "This Policy already exist on the PAP");
-                       return successMap;
-               }
-
-               if(!isPreparedToSave()){
-                       //Prep and configure the policy for saving
-                       prepareToSave();
-               }
-
-               // Until here we prepared the data and here calling the method to create xml.
-               Path newPolicyPath = null;
-               newPolicyPath = Paths.get(policyAdapter.getNewFileName());
-
-               successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());  
-               return successMap;              
-       }
-       
-       //This is the method for preparing the policy for saving.  We have broken it out
-       //separately because the fully configured policy is used for multiple things
-       @Override
-       public boolean prepareToSave() throws PAPException{
-
-               if(isPreparedToSave()){
-                       //we have already done this
-                       return true;
-               }
-               
-               int version = 0;
-               String policyID = policyAdapter.getPolicyID();
-               version = policyAdapter.getHighestVersion();
-               
-               // Create the Instance for pojo, PolicyType object is used in marshalling.
-               if ("Decision".equals(policyAdapter.getPolicyType())) {
-                       PolicyType policyConfig = new PolicyType();
-
-                       policyConfig.setVersion(Integer.toString(version));
-                       policyConfig.setPolicyId(policyID);
-                       policyConfig.setTarget(new TargetType());
-                       policyAdapter.setData(policyConfig);
-               }
-               policyName = policyAdapter.getNewFileName();
-               
-               if(policyAdapter.getRuleProvider().equals(GUARD_YAML) || policyAdapter.getRuleProvider().equals(GUARD_BL_YAML)){
-                       Map<String, String> yamlParams = new HashMap<>();
-                       String blackListEntryType = policyAdapter.getBlackListEntryType() !=null ? policyAdapter.getBlackListEntryType(): "Use Manual Entry";
-                       String description = policyAdapter.getPolicyDescription() != null? policyAdapter.getPolicyDescription(): "YAML Guard Policy";
-                       yamlParams.put(DESCRIPTION, description + "@blEntry@" + blackListEntryType + "@blEntry@");
-                       String fileName = policyAdapter.getNewFileName();
-                       String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length());
-                       if ((name == null) || ("".equals(name))) {
-                               name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
-                       }
-                       yamlParams.put(POLICY_NAME, name);
-                       yamlParams.put(ONAPNAME, policyAdapter.getOnapName());
-                       Map<String, String> params = policyAdapter.getDynamicFieldConfigAttributes();
-                       yamlParams.putAll(params);
-                       // Call YAML to XACML
+    private static final String ONAPNAME = "ONAPName";
+    private static final String POLICY_NAME = "PolicyName";
+    private static final String DESCRIPTION = "description";
+
+
+    List<String> dynamicLabelRuleAlgorithms = new LinkedList<>();
+    List<String> dynamicFieldComboRuleAlgorithms = new LinkedList<>();
+    List<String> dynamicFieldOneRuleAlgorithms = new LinkedList<>();
+    List<String> dynamicFieldTwoRuleAlgorithms = new LinkedList<>();
+    List<String> dataTypeList = new LinkedList<>();
+
+    private CommonClassDao commonClassDao;
+
+    public DecisionPolicy() {
+        super();
+    }
+
+    public DecisionPolicy(PolicyRestAdapter policyAdapter, CommonClassDao commonClassDao){
+        this.policyAdapter = policyAdapter;
+        this.commonClassDao = commonClassDao;
+    }
+
+    @Override
+    public Map<String, String> savePolicies() throws PAPException {
+
+        Map<String, String> successMap = new HashMap<>();
+        if(isPolicyExists()){
+            successMap.put("EXISTS", "This Policy already exist on the PAP");
+            return successMap;
+        }
+
+        if(!isPreparedToSave()){
+            //Prep and configure the policy for saving
+            prepareToSave();
+        }
+
+        // Until here we prepared the data and here calling the method to create xml.
+        Path newPolicyPath = null;
+        newPolicyPath = Paths.get(policyAdapter.getNewFileName());
+
+        successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());
+        return successMap;
+    }
+
+    //This is the method for preparing the policy for saving.  We have broken it out
+    //separately because the fully configured policy is used for multiple things
+    @Override
+    public boolean prepareToSave() throws PAPException{
+
+        if(isPreparedToSave()){
+            //we have already done this
+            return true;
+        }
+
+        int version = 0;
+        String policyID = policyAdapter.getPolicyID();
+        version = policyAdapter.getHighestVersion();
+
+        // Create the Instance for pojo, PolicyType object is used in marshalling.
+        if ("Decision".equals(policyAdapter.getPolicyType())) {
+            PolicyType policyConfig = new PolicyType();
+
+            policyConfig.setVersion(Integer.toString(version));
+            policyConfig.setPolicyId(policyID);
+            policyConfig.setTarget(new TargetType());
+            policyAdapter.setData(policyConfig);
+        }
+        policyName = policyAdapter.getNewFileName();
+
+        if(policyAdapter.getRuleProvider().equals(GUARD_YAML) || policyAdapter.getRuleProvider().equals(GUARD_BL_YAML)){
+            Map<String, String> yamlParams = new HashMap<>();
+            String blackListEntryType = policyAdapter.getBlackListEntryType() !=null ? policyAdapter.getBlackListEntryType(): "Use Manual Entry";
+            String description = policyAdapter.getPolicyDescription() != null? policyAdapter.getPolicyDescription(): "YAML Guard Policy";
+            yamlParams.put(DESCRIPTION, description + "@blEntry@" + blackListEntryType + "@blEntry@");
+            String fileName = policyAdapter.getNewFileName();
+            String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length());
+            if ((name == null) || ("".equals(name))) {
+                name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
+            }
+            yamlParams.put(POLICY_NAME, name);
+            yamlParams.put(ONAPNAME, policyAdapter.getOnapName());
+            Map<String, String> params = policyAdapter.getDynamicFieldConfigAttributes();
+            yamlParams.putAll(params);
+            // Call YAML to XACML
             try {
                 PolicyType decisionPolicy = getGuardPolicy(yamlParams, policyAdapter.getRuleProvider());
                 decisionPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
@@ -190,614 +190,614 @@ public class DecisionPolicy extends Policy {
                 LOGGER.error(e);
                 throw new PAPException(e);
             }
-               }else if (policyAdapter.getData() != null) {
-                       PolicyType decisionPolicy = (PolicyType)  policyAdapter.getData();
-                       
-                       decisionPolicy.setDescription(policyAdapter.getPolicyDescription());
-                       
-                       decisionPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
-                       AllOfType allOfOne = new AllOfType();
-                       String fileName = policyAdapter.getNewFileName();
-                       String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length());
-                       if ((name == null) || ("".equals(name))) {
-                               name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
-                       }
-                       allOfOne.getMatch().add(createMatch(POLICY_NAME, name));
-                       
-                       AllOfType allOf = new AllOfType();
-                       
-                       // Match for Onap
-                       allOf.getMatch().add(createMatch(ONAPNAME, (policyAdapter.getOnapName())));
-                       
-                       Map<String, String> dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes();
-                       if(policyAdapter.getRuleProvider()!=null && policyAdapter.getRuleProvider().equals(AAFPROVIDER)){
-                               dynamicFieldComponentAttributes = new HashMap<>();
-                       }
-                       
-                       // If there is any dynamic field attributes create the matches here
-                       for (String keyField : dynamicFieldComponentAttributes.keySet()) {
-                               String key = keyField;
-                               String value = dynamicFieldComponentAttributes.get(key);
-                               MatchType dynamicMatch = createDynamicMatch(key, value);
-                               allOf.getMatch().add(dynamicMatch);
-                       }
-
-                       AnyOfType anyOf = new AnyOfType();
-                       anyOf.getAllOf().add(allOfOne);
-                       anyOf.getAllOf().add(allOf);
-
-                       TargetType target = new TargetType();
-                       target.getAnyOf().add(anyOf);
-                       decisionPolicy.setTarget(target);
-
-                       Map<String, String> dynamicFieldDecisionSettings = policyAdapter.getDynamicSettingsMap();
-                       if(policyAdapter.getRuleProvider()!=null && (policyAdapter.getRuleProvider().equals(AAFPROVIDER)||
-                                       policyAdapter.getRuleProvider().equals(RAINY_DAY))){
-                               dynamicFieldDecisionSettings = new HashMap<>();
-                       }
-                       
-                       // settings are dynamic so check how many rows are added and add all
-                       for (String keyField : dynamicFieldDecisionSettings.keySet()) {
-                               String key = keyField;
-                               String value = dynamicFieldDecisionSettings.get(key);
-                               String dataType = getDataType(key);
-                               VariableDefinitionType dynamicVariable = createDynamicVariable(key, value, dataType);
-                               decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(dynamicVariable);
-                       }
-                       
-                       Map<String, String> dynamicFieldTreatmentAttributes = policyAdapter.getRainydayMap();
-                       if(policyAdapter.getRuleProvider().equals(RAINY_DAY)){
-                               for(String keyField : dynamicFieldTreatmentAttributes.keySet()) {
-                                       String errorcode = keyField;
-                                       String treatment = dynamicFieldTreatmentAttributes.get(errorcode);
-                                       createRainydayRule(decisionPolicy, errorcode, treatment, true);
-                               }
-                       } else {
-                               createRule(decisionPolicy, true);
-                               createRule(decisionPolicy, false);
-                       }
-
-               }
-               setPreparedToSave(true);
-               return true;
-       }
-       
-       public PolicyType getGuardPolicy(Map<String, String> yamlParams, String ruleProvider) throws BuilderException{
-               try {
-                       ControlLoopGuardBuilder builder = ControlLoopGuardBuilder.Factory.buildControlLoopGuard(new Guard());
-                       MatchParameters matchParameters = new MatchParameters(yamlParams.get("actor"), yamlParams.get("recipe"));
-                       matchParameters.setControlLoopName(yamlParams.get("clname"));
-                       if(yamlParams.containsKey("targets")){
-                               String targetString = yamlParams.get("targets");
-                               List<String> targets = null;
-                               if(targetString!=null && !targetString.isEmpty()){
-                                       if (targetString.contains(",")){
-                                               targets = Arrays.asList(targetString.split(","));
-                                       }
-                                       else{
-                                               targets = new ArrayList<>();
-                                               targets.add(targetString);
-                                       }       
-                               }
-                               matchParameters.setTargets(targets);
-                       }
-                       GuardPolicy policy1 = new GuardPolicy((policyAdapter.getUuid()!=null? policyAdapter.getUuid(): UUID.randomUUID().toString()) ,yamlParams.get(POLICY_NAME), yamlParams.get(DESCRIPTION), matchParameters);
-                       builder = builder.addGuardPolicy(policy1);
+        }else if (policyAdapter.getData() != null) {
+            PolicyType decisionPolicy = (PolicyType)  policyAdapter.getData();
+
+            decisionPolicy.setDescription(policyAdapter.getPolicyDescription());
+
+            decisionPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
+            AllOfType allOfOne = new AllOfType();
+            String fileName = policyAdapter.getNewFileName();
+            String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length());
+            if ((name == null) || ("".equals(name))) {
+                name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
+            }
+            allOfOne.getMatch().add(createMatch(POLICY_NAME, name));
+
+            AllOfType allOf = new AllOfType();
+
+            // Match for Onap
+            allOf.getMatch().add(createMatch(ONAPNAME, (policyAdapter.getOnapName())));
+
+            Map<String, String> dynamicFieldComponentAttributes = policyAdapter.getDynamicFieldConfigAttributes();
+            if(policyAdapter.getRuleProvider()!=null && policyAdapter.getRuleProvider().equals(AAFPROVIDER)){
+                dynamicFieldComponentAttributes = new HashMap<>();
+            }
+
+            // If there is any dynamic field attributes create the matches here
+            for (String keyField : dynamicFieldComponentAttributes.keySet()) {
+                String key = keyField;
+                String value = dynamicFieldComponentAttributes.get(key);
+                MatchType dynamicMatch = createDynamicMatch(key, value);
+                allOf.getMatch().add(dynamicMatch);
+            }
+
+            AnyOfType anyOf = new AnyOfType();
+            anyOf.getAllOf().add(allOfOne);
+            anyOf.getAllOf().add(allOf);
+
+            TargetType target = new TargetType();
+            target.getAnyOf().add(anyOf);
+            decisionPolicy.setTarget(target);
+
+            Map<String, String> dynamicFieldDecisionSettings = policyAdapter.getDynamicSettingsMap();
+            if(policyAdapter.getRuleProvider()!=null && (policyAdapter.getRuleProvider().equals(AAFPROVIDER)||
+                    policyAdapter.getRuleProvider().equals(RAINY_DAY))){
+                dynamicFieldDecisionSettings = new HashMap<>();
+            }
+
+            // settings are dynamic so check how many rows are added and add all
+            for (String keyField : dynamicFieldDecisionSettings.keySet()) {
+                String key = keyField;
+                String value = dynamicFieldDecisionSettings.get(key);
+                String dataType = getDataType(key);
+                VariableDefinitionType dynamicVariable = createDynamicVariable(key, value, dataType);
+                decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(dynamicVariable);
+            }
+
+            Map<String, String> dynamicFieldTreatmentAttributes = policyAdapter.getRainydayMap();
+            if(policyAdapter.getRuleProvider().equals(RAINY_DAY)){
+                for(String keyField : dynamicFieldTreatmentAttributes.keySet()) {
+                    String errorcode = keyField;
+                    String treatment = dynamicFieldTreatmentAttributes.get(errorcode);
+                    createRainydayRule(decisionPolicy, errorcode, treatment, true);
+                }
+            } else {
+                createRule(decisionPolicy, true);
+                createRule(decisionPolicy, false);
+            }
+
+        }
+        setPreparedToSave(true);
+        return true;
+    }
+
+    public PolicyType getGuardPolicy(Map<String, String> yamlParams, String ruleProvider) throws BuilderException{
+        try {
+            ControlLoopGuardBuilder builder = ControlLoopGuardBuilder.Factory.buildControlLoopGuard(new Guard());
+            MatchParameters matchParameters = new MatchParameters(yamlParams.get("actor"), yamlParams.get("recipe"));
+            matchParameters.setControlLoopName(yamlParams.get("clname"));
+            if(yamlParams.containsKey("targets")){
+                String targetString = yamlParams.get("targets");
+                List<String> targets = null;
+                if(targetString!=null && !targetString.isEmpty()){
+                    if (targetString.contains(",")){
+                        targets = Arrays.asList(targetString.split(","));
+                    }
+                    else{
+                        targets = new ArrayList<>();
+                        targets.add(targetString);
+                    }
+                }
+                matchParameters.setTargets(targets);
+            }
+            GuardPolicy policy1 = new GuardPolicy((policyAdapter.getUuid()!=null? policyAdapter.getUuid(): UUID.randomUUID().toString()) ,yamlParams.get(POLICY_NAME), yamlParams.get(DESCRIPTION), matchParameters);
+            builder = builder.addGuardPolicy(policy1);
             Map<String, String> activeTimeRange = new HashMap<>();
             activeTimeRange.put("start", yamlParams.get("guardActiveStart"));
             activeTimeRange.put("end", yamlParams.get("guardActiveEnd"));
-                       String blackListString = yamlParams.get("blackList");
-                       List<String> blackList = null;
+            String blackListString = yamlParams.get("blackList");
+            List<String> blackList = null;
             if(blackListString!=null && !blackListString.trim().isEmpty()){
-                               if (blackListString.contains(",")){
-                                       blackList = Arrays.asList(blackListString.split(","));                                                          
-                               }
-                               else{
-                                       blackList = new ArrayList<>();
-                                       blackList.add(blackListString);
-                               }       
-                       }
+                if (blackListString.contains(",")){
+                    blackList = Arrays.asList(blackListString.split(","));
+                }
+                else{
+                    blackList = new ArrayList<>();
+                    blackList.add(blackListString);
+                }
+            }
             if(yamlParams.containsKey("appendBlackList")){
-               String appendBlackListString = yamlParams.get("appendBlackList");
+                String appendBlackListString = yamlParams.get("appendBlackList");
                 List<String> appendBlackList = null;
                 if(appendBlackListString!=null && !appendBlackListString.trim().isEmpty()){
-                       appendBlackList = Arrays.asList(appendBlackListString.split(","));      
-                       for(int i=0; i<appendBlackList.size();i++){
-                               blackList.remove(appendBlackList.get(i));
-                       }
+                    appendBlackList = Arrays.asList(appendBlackListString.split(","));
+                    for(int i=0; i<appendBlackList.size();i++){
+                        blackList.remove(appendBlackList.get(i));
+                    }
                 }
             }
-                       File templateFile;
-                       Path xacmlTemplatePath;
-                       ClassLoader classLoader = getClass().getClassLoader();
-                       Constraint cons = new Constraint();
-                       switch (ruleProvider){
-                       case GUARD_BL_YAML:
-                               templateFile = new File(classLoader.getResource(XACML_BLGUARD_TEMPLATE).getFile());
-                               xacmlTemplatePath = templateFile.toPath();
+            File templateFile;
+            Path xacmlTemplatePath;
+            ClassLoader classLoader = getClass().getClassLoader();
+            Constraint cons = new Constraint();
+            switch (ruleProvider){
+            case GUARD_BL_YAML:
+                templateFile = new File(classLoader.getResource(XACML_BLGUARD_TEMPLATE).getFile());
+                xacmlTemplatePath = templateFile.toPath();
                 cons.setActive_time_range(activeTimeRange);
                 if(blackList==null || blackList.isEmpty()){
                     throw new BuilderException("blackList is required");
                 }
                 cons.setBlacklist(blackList);
-                               break;
-                       default:
-                               templateFile = new File(classLoader.getResource(XACML_GUARD_TEMPLATE).getFile());
-                               xacmlTemplatePath = templateFile.toPath();
-                               Map<String,String> timeWindow = new HashMap<>();
-                               if(!PolicyUtils.isInteger(yamlParams.get("timeWindow"))){
-                                       throw new BuilderException("time window is not in Integer format.");
-                               }
-                               String timeUnits = yamlParams.get("timeUnits");
-                               if(timeUnits==null || !(timeUnits.equalsIgnoreCase("minute") || timeUnits.equalsIgnoreCase("hour") || timeUnits.equalsIgnoreCase("day") 
-                                               || timeUnits.equalsIgnoreCase("week") || timeUnits.equalsIgnoreCase("month")||timeUnits.equalsIgnoreCase("year"))){
-                                       throw new BuilderException("time Units is not in proper format.");
-                               }
-                               timeWindow.put("value", yamlParams.get("timeWindow"));
-                               timeWindow.put("units", yamlParams.get("timeUnits"));
-                               cons = new Constraint(Integer.parseInt(yamlParams.get("limit")),timeWindow,activeTimeRange);
-                               break;
-                       }
-                       builder = builder.addLimitConstraint(policy1.getId(), cons);
-                       // Build the specification
-                       Results results = builder.buildSpecification();
-                       // YAML TO XACML 
-                       ControlLoopGuard yamlGuardObject = SafePolicyBuilder.loadYamlGuard(results.getSpecification());
-               String xacmlTemplateContent;
-               try {
-                               xacmlTemplateContent = new String(Files.readAllBytes(xacmlTemplatePath));
-                               HashMap<String, String> yamlSpecs = new HashMap<>();
-                               yamlSpecs.put(POLICY_NAME, yamlParams.get(POLICY_NAME));
-                               yamlSpecs.put(DESCRIPTION, yamlParams.get(DESCRIPTION));
-                               yamlSpecs.put(ONAPNAME, yamlParams.get(ONAPNAME));
-                               yamlSpecs.put("actor", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getActor());
-                               yamlSpecs.put("recipe", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getRecipe());
-                               yamlSpecs.put("clname", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getControlLoopName());
-                               if(yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getFreq_limit_per_target()!=null){
-                                       yamlSpecs.put("limit", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getFreq_limit_per_target().toString());
-                               }
-                               if(yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window()!=null){
-                                       yamlSpecs.put("twValue", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window().get("value"));
-                                       yamlSpecs.put("twUnits", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window().get("units"));
-                               }
-                               yamlSpecs.put("guardActiveStart", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getActive_time_range().get("start"));
-                               yamlSpecs.put("guardActiveEnd", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getActive_time_range().get("end"));
-                       String xacmlPolicyContent = SafePolicyBuilder.generateXacmlGuard(xacmlTemplateContent,yamlSpecs, yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getBlacklist(), yamlGuardObject.getGuards().getFirst().getMatch_parameters().getTargets());
-                      // Convert the  Policy into Stream input to Policy Adapter. 
-                       Object policy = XACMLPolicyScanner.readPolicy(new ByteArrayInputStream(xacmlPolicyContent.getBytes(StandardCharsets.UTF_8)));
-                               return (PolicyType) policy;
-                       } catch (IOException e) {
-                               LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error while creating the policy " + e.getMessage() , e);
-                       }
-               } catch (BuilderException e) {
-                       LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error while creating the policy " + e.getMessage() ,e);
-                       throw e;
-               }
-               return null;
-       }
-       
-       private DecisionSettings findDecisionSettingsBySettingId(String settingId) {
-               DecisionSettings decisionSetting = null;
-               
-               EntityManager em = XACMLPapServlet.getEmf().createEntityManager();
-               Query getDecisionSettings = em.createNamedQuery("DecisionSettings.findAll");
-               List<?> decisionSettingsList = getDecisionSettings.getResultList();
-               
-               for (Object id : decisionSettingsList) {
-                       decisionSetting = (DecisionSettings) id;
-                       if (decisionSetting.getXacmlId().equals(settingId)) {
-                               break;
-                       }
-               }
-               return decisionSetting;
-       }
-       
-       private void createRule(PolicyType decisionPolicy, boolean permitRule) {
-               RuleType rule = new RuleType();
-                       
-               rule.setRuleId(policyAdapter.getRuleID());
-                       
-               if (permitRule) {
-                       rule.setEffect(EffectType.PERMIT);
-               } else {
-                       rule.setEffect(EffectType.DENY);
-               }
-               rule.setTarget(new TargetType());
-
-               // Create Target in Rule
-               AllOfType allOfInRule = new AllOfType();
-
-               // Creating match for ACCESS in rule target
-               MatchType accessMatch = new MatchType();
-               AttributeValueType accessAttributeValue = new AttributeValueType();
-               accessAttributeValue.setDataType(STRING_DATATYPE);
-               accessAttributeValue.getContent().add("DECIDE");
-               accessMatch.setAttributeValue(accessAttributeValue);
-               AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
-               URI accessURI = null;
-               try {
-                       accessURI = new URI(ACTION_ID);
-               } catch (URISyntaxException e) {
-                       PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "DecisionPolicy", "Exception creating ACCESS URI");
-               }
-               accessAttributeDesignator.setCategory(CATEGORY_ACTION);
-               accessAttributeDesignator.setDataType(STRING_DATATYPE);
-               accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
-               accessMatch.setAttributeDesignator(accessAttributeDesignator);
-               accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-               
-               dynamicLabelRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmLabels();
-               dynamicFieldComboRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo();
-               dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1();
-               dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2();
-               
-               if(policyAdapter.getRuleProvider()!=null && policyAdapter.getRuleProvider().equals(AAFPROVIDER)){
-                       // Values for AAF Provider are here for XML Creation. 
-                       ConditionType condition = new ConditionType();
-                       ApplyType decisionApply = new ApplyType();
-                       
-                       AttributeValueType value1 = new AttributeValueType();
-                       value1.setDataType(BOOLEAN_DATATYPE);
-                       value1.getContent().add("true");
-                       
-                       AttributeDesignatorType value2 = new AttributeDesignatorType();
-                       value2.setAttributeId(AAFEngine.AAF_RESULT);
-                       value2.setCategory(CATEGORY_RESOURCE);
-                       value2.setDataType(BOOLEAN_DATATYPE);
-                       value2.setMustBePresent(false);
-                       
-                       ApplyType innerDecisionApply = new ApplyType();
-                       innerDecisionApply.setFunctionId(FUNCTION_BOOLEAN_ONE_AND_ONLY);
-                       innerDecisionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(value2));
-                       
-                       decisionApply.setFunctionId(XACML3.ID_FUNCTION_BOOLEAN_EQUAL.stringValue());
-                       decisionApply.getExpression().add(new ObjectFactory().createAttributeValue(value1));
-                       decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply));
-                       condition.setExpression(new ObjectFactory().createApply(decisionApply));
-                       if (!permitRule) {
-                               ApplyType notOuterApply = new ApplyType();
-                               notOuterApply.setFunctionId(FUNCTION_NOT);
-                               notOuterApply.getExpression().add(condition.getExpression());
-                               condition.setExpression(new ObjectFactory().createApply(notOuterApply));
-                       }
-                       rule.setCondition(condition);
-                       allOfInRule.getMatch().add(accessMatch);
-
-                       AnyOfType anyOfInRule = new AnyOfType();
-                       anyOfInRule.getAllOf().add(allOfInRule);
-
-                       TargetType targetInRule = new TargetType();
-                       targetInRule.getAnyOf().add(anyOfInRule);
-
-                       rule.setTarget(targetInRule);
-                       if(!permitRule){
-                               AdviceExpressionsType adviceExpressions = new AdviceExpressionsType();
-                               AdviceExpressionType adviceExpression = new AdviceExpressionType();
-                               adviceExpression.setAdviceId(AAFPROVIDER);
-                               adviceExpression.setAppliesTo(EffectType.DENY);
-                               AttributeAssignmentExpressionType assignment = new AttributeAssignmentExpressionType();
-                               assignment.setAttributeId("aaf.response");
-                               assignment.setCategory(CATEGORY_RESOURCE);
-                               AttributeDesignatorType value = new AttributeDesignatorType();
-                               value.setAttributeId(AAFEngine.AAF_RESPONSE);
-                               value.setCategory(CATEGORY_RESOURCE);
-                               value.setDataType(STRING_DATATYPE);
-                               value.setMustBePresent(false);
-                               assignment.setExpression(new ObjectFactory().createAttributeDesignator(value));
-                               adviceExpression.getAttributeAssignmentExpression().add(assignment);
-                               adviceExpressions.getAdviceExpression().add(adviceExpression);
-                               rule.setAdviceExpressions(adviceExpressions);
-                       }
-                       decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
-                       policyAdapter.setPolicyData(decisionPolicy);
-                       
-               }else if (dynamicLabelRuleAlgorithms != null && !dynamicLabelRuleAlgorithms.isEmpty()) {
-                       boolean isCompound = false;
-                       ConditionType condition = new ConditionType();
-                       int index = dynamicFieldOneRuleAlgorithms.size() - 1;
-                       
-                       for (String labelAttr : dynamicLabelRuleAlgorithms) {
-                               // if the rule algorithm as a label means it is a compound
-                               if (dynamicFieldOneRuleAlgorithms.get(index).equals(labelAttr)) {
-                                       ApplyType decisionApply = new ApplyType();
-
-                                       String selectedFunction = dynamicFieldComboRuleAlgorithms.get(index);
-                                       String value1 = dynamicFieldOneRuleAlgorithms.get(index);
-                                       String value2 = dynamicFieldTwoRuleAlgorithms.get(index);
-                                       decisionApply.setFunctionId(getFunctionDefinitionId(selectedFunction));
-                                       decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value1)));
-                                       decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value2)));
-                                       condition.setExpression(new ObjectFactory().createApply(decisionApply));
-                                       isCompound = true;
-                               }
-
-                               // if rule algorithm not a compound
-                               if (!isCompound) {
-                                       condition.setExpression(new ObjectFactory().createApply(getInnerDecisionApply(dynamicLabelRuleAlgorithms.get(index))));
-                               }
-                       }
-                       if (!permitRule) {
-                               ApplyType notOuterApply = new ApplyType();
-                               notOuterApply.setFunctionId(FUNCTION_NOT);
-                               notOuterApply.getExpression().add(condition.getExpression());
-                               condition.setExpression(new ObjectFactory().createApply(notOuterApply));
-                       }
-                       rule.setCondition(condition);
-                       allOfInRule.getMatch().add(accessMatch);
-
-                       AnyOfType anyOfInRule = new AnyOfType();
-                       anyOfInRule.getAllOf().add(allOfInRule);
-
-                       TargetType targetInRule = new TargetType();
-                       targetInRule.getAnyOf().add(anyOfInRule);
-
-                       rule.setTarget(targetInRule);
-
-                       decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
-                       policyAdapter.setPolicyData(decisionPolicy);
-                       
-               } else {
-                       PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object."+ policyAdapter.getData().getClass().getCanonicalName());
-               }
-
-       }
-       
-       private void createRainydayRule(PolicyType decisionPolicy, String errorcode, String treatment, boolean permitRule) {
-               RuleType rule = new RuleType();
-               
-               rule.setRuleId(UUID.randomUUID().toString());
-                       
-               if (permitRule) {
-                       rule.setEffect(EffectType.PERMIT);
-               } else {
-                       rule.setEffect(EffectType.DENY);
-               }
-               rule.setTarget(new TargetType());
-
-               // Create Target in Rule
-               AllOfType allOfInRule = new AllOfType();
-
-               // Creating match for DECIDE in rule target
-               MatchType accessMatch = new MatchType();
-               AttributeValueType accessAttributeValue = new AttributeValueType();
-               accessAttributeValue.setDataType(STRING_DATATYPE);
-               accessAttributeValue.getContent().add("DECIDE");
-               accessMatch.setAttributeValue(accessAttributeValue);
-               AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
-               URI accessURI = null;
-               try {
-                       accessURI = new URI(ACTION_ID);
-               } catch (URISyntaxException e) {
-                       PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "DecisionPolicy", "Exception creating ACCESS URI");
-               }
-               accessAttributeDesignator.setCategory(CATEGORY_ACTION);
-               accessAttributeDesignator.setDataType(STRING_DATATYPE);
-               accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
-               accessMatch.setAttributeDesignator(accessAttributeDesignator);
-               accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-               
-               allOfInRule.getMatch().add(accessMatch);
-               
-               // Creating match for ErrorCode in rule target
-               MatchType errorcodeMatch = new MatchType();
-               AttributeValueType errorcodeAttributeValue = new AttributeValueType();
-               errorcodeAttributeValue.setDataType(STRING_DATATYPE);
-               errorcodeAttributeValue.getContent().add(errorcode);
-               errorcodeMatch.setAttributeValue(errorcodeAttributeValue);
-               AttributeDesignatorType errorcodeAttributeDesignator = new AttributeDesignatorType();
-               errorcodeAttributeDesignator.setCategory(CATEGORY_RESOURCE);
-               errorcodeAttributeDesignator.setDataType(STRING_DATATYPE);
-               errorcodeAttributeDesignator.setAttributeId("ErrorCode");
-               errorcodeMatch.setAttributeDesignator(errorcodeAttributeDesignator);
-               errorcodeMatch.setMatchId(FUNCTION_STRING_REGEXP_MATCH);
-               
-               allOfInRule.getMatch().add(errorcodeMatch);
-               
-               AnyOfType anyOfInRule = new AnyOfType();
-               anyOfInRule.getAllOf().add(allOfInRule);
-               
-               TargetType targetInRule = new TargetType();
-               targetInRule.getAnyOf().add(anyOfInRule);
-               
-               rule.setTarget(targetInRule);
-               
-               AdviceExpressionsType adviceExpressions = new AdviceExpressionsType();
-               AdviceExpressionType adviceExpression = new AdviceExpressionType();             
-               adviceExpression.setAdviceId(RAINY_DAY);
-               adviceExpression.setAppliesTo(EffectType.PERMIT);
-               
-               AttributeAssignmentExpressionType assignment = new AttributeAssignmentExpressionType();
-               assignment.setAttributeId("treatment");
-               assignment.setCategory(CATEGORY_RESOURCE);
-               
-               AttributeValueType treatmentAttributeValue = new AttributeValueType();
-               treatmentAttributeValue.setDataType(STRING_DATATYPE);
-               treatmentAttributeValue.getContent().add(treatment);
-               assignment.setExpression(new ObjectFactory().createAttributeValue(treatmentAttributeValue));
-               
-               adviceExpression.getAttributeAssignmentExpression().add(assignment);
-               adviceExpressions.getAdviceExpression().add(adviceExpression);
-               rule.setAdviceExpressions(adviceExpressions);
-               decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
-               policyAdapter.setPolicyData(decisionPolicy);
-               
-       }
-       
-       // if compound setting the inner apply here
-       protected ApplyType getInnerDecisionApply(String value1Label) {
-               ApplyType decisionApply = new ApplyType();
-               int index = 0;
-               // check the index for the label.
-               for (String labelAttr : dynamicLabelRuleAlgorithms) {
-                       if (labelAttr.equals(value1Label)) {
-                               String value1 = dynamicFieldOneRuleAlgorithms.get(index);
-                               populateDataTypeList(value1);
-
-                               // check if the row contains label again
-                               for (String labelValue : dynamicLabelRuleAlgorithms) {
-                                       if (labelValue.equals(value1)) {
-                                               return getCompoundDecisionApply(index);
-                                       }
-                               }
-
-                               // Getting the values from the form.
-                               String functionKey = dynamicFieldComboRuleAlgorithms.get(index);
-                               String value2 = dynamicFieldTwoRuleAlgorithms.get(index);
-                               decisionApply.setFunctionId(getFunctionDefinitionId(functionKey));
-                               // if two text field are rule attributes.
-                               if ((value1.contains(RULE_VARIABLE)) && (value2.contains(RULE_VARIABLE))) {
-                                       ApplyType innerDecisionApply1 = new ApplyType();
-                                       ApplyType       innerDecisionApply2      = new  ApplyType();                                                      
-                                       AttributeDesignatorType  attributeDesignator1     = new AttributeDesignatorType();                                                               
-                                       AttributeDesignatorType  attributeDesignator2     = new AttributeDesignatorType();                                                                                       
-                                       //If selected function is Integer function set integer functionID
-                                       if(functionKey.toLowerCase().contains("integer")){
-                                               innerDecisionApply1.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY );
-                                               innerDecisionApply2.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
-                                               attributeDesignator1.setDataType(INTEGER_DATATYPE);
-                                               attributeDesignator2.setDataType(INTEGER_DATATYPE);
-                                       } else{
-                                               //If selected function is not a Integer function set String functionID
-                                               innerDecisionApply1.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
-                                               innerDecisionApply2.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
-                                               attributeDesignator1.setDataType(STRING_DATATYPE);
-                                               attributeDesignator2.setDataType(STRING_DATATYPE);
-                                       }
-                                       attributeDesignator1.setCategory(CATEGORY_RESOURCE);
-                                       attributeDesignator2.setCategory(CATEGORY_RESOURCE);
-                                       //Here set actual field values
-                                       attributeDesignator1.setAttributeId(value1.  contains("resource:")?value1.substring( 9):value1.substring(8));
-                                       attributeDesignator2.setAttributeId(value1.  contains("resource:")?value1.substring( 9):value1.substring(8));                                                    
-                                       innerDecisionApply1.getExpression().add(new ObjectFactory().createAttributeDesignator( attributeDesignator1));
-                                       innerDecisionApply2.getExpression().add(new ObjectFactory().createAttributeDesignator( attributeDesignator2));                                                    
-                                       decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply1));
-                                       decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply2));                                                          
-                               } else {
-                                       // if either of one text field is rule attribute.
-                                       if (!value1.startsWith("S_")) {
-                                               ApplyType innerDecisionApply = new ApplyType();
-                                               AttributeDesignatorType attributeDesignator = new AttributeDesignatorType();
-                                               AttributeValueType decisionConditionAttributeValue = new AttributeValueType();
-
-                                               if (functionKey.toLowerCase().contains("integer")) {
-                                                       innerDecisionApply.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
-                                                       decisionConditionAttributeValue.setDataType(INTEGER_DATATYPE);
-                                                       attributeDesignator.setDataType(INTEGER_DATATYPE);
-                                               } else {
-                                                       innerDecisionApply.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
-                                                       decisionConditionAttributeValue.setDataType(STRING_DATATYPE);
-                                                       attributeDesignator.setDataType(STRING_DATATYPE);
-                                               }
-
-                                               String attributeId = null;
-                                               String attributeValue = null;
-
-                                               // Find which textField has rule attribute and set it as
-                                               // attributeId and the other as attributeValue.
-                                               attributeId = value1;
-                                               attributeValue = value2;
-                       
-                                               if (attributeId != null) {
-                                                       attributeDesignator.setCategory(CATEGORY_RESOURCE);
-                                                       attributeDesignator.setAttributeId(attributeId);
-                                               }
-                                               decisionConditionAttributeValue.getContent().add(attributeValue);
-                                               innerDecisionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator));
-                                               decisionApply.getExpression().add(new ObjectFactory().createAttributeValue(decisionConditionAttributeValue));
-                                               decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply));
-                                       } else {
-                                               value1 = value1.substring(2, value1.length());
-                                               VariableReferenceType variableReferenceType = new VariableReferenceType();
-                                               variableReferenceType.setVariableId(value1);
-                                               
-                                               String dataType = dataTypeList.get(index);
-
-                                               AttributeValueType decisionConditionAttributeValue = new AttributeValueType();
-                                               decisionConditionAttributeValue.setDataType(dataType);
-                                               decisionConditionAttributeValue.getContent().add(value2);
-                                               decisionApply.getExpression().add(new ObjectFactory().createVariableReference(variableReferenceType));
-                                               decisionApply.getExpression().add(new ObjectFactory().createAttributeValue(decisionConditionAttributeValue));
-                                       }
-                               }
-                       }
-                       index++;
-               }
-               return decisionApply;
-       }
-
-       // if the rule algorithm is multiple compound one setting the apply
-       protected ApplyType getCompoundDecisionApply(int index) {
-               ApplyType decisionApply = new ApplyType();
-               String selectedFunction = dynamicFieldComboRuleAlgorithms.get(index);
-               String value1 = dynamicFieldOneRuleAlgorithms.get(index);
-               String value2 = dynamicFieldTwoRuleAlgorithms.get(index);
-               decisionApply.setFunctionId(getFunctionDefinitionId(selectedFunction));
-               decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value1)));
-               decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value2)));
-               return decisionApply;
-       }
-       
-       private VariableDefinitionType createDynamicVariable(String key, String value, String dataType) {
-               VariableDefinitionType dynamicVariable = new VariableDefinitionType();
-               AttributeValueType dynamicAttributeValue = new AttributeValueType();
-
-               dynamicAttributeValue.setDataType(dataType);
-               dynamicAttributeValue.getContent().add(value);
-
-               dynamicVariable.setVariableId(key);
-               dynamicVariable.setExpression(new ObjectFactory().createAttributeValue(dynamicAttributeValue));
-
-               return dynamicVariable;
-
-       }       
-       
-       private void populateDataTypeList(String value1) {
-               String dataType = null;
-               if(value1.contains("S_")) {
-                       value1 = value1.substring(2, value1.length());
-                       DecisionSettings decisionSettings = findDecisionSettingsBySettingId(value1.substring(2, value1.length()));
-                       if (decisionSettings != null && "string".equals(decisionSettings.getDatatypeBean().getShortName())) {
-                               dataType = STRING_DATATYPE;
-                       } else if (decisionSettings != null && "boolean".equals(decisionSettings.getDatatypeBean().getShortName())) {
-                               dataType = BOOLEAN_DATATYPE;
-                       } else {
-                               dataType = INTEGER_DATATYPE;
-                       }
-               } else {
-                       dataType = "OTHER";
-               }
-
-               dataTypeList.add(dataType);
-       }
-       
-       
-       private String getDataType(String key) {
-               
-               DecisionSettings decisionSettings = findDecisionSettingsBySettingId(key);
-               String dataType = null;
-               
-               if (decisionSettings != null && "string".equals(decisionSettings.getDatatypeBean().getShortName())) {
-                       dataType = STRING_DATATYPE;
-               } else if (decisionSettings != null && "boolean".equals(decisionSettings.getDatatypeBean().getShortName())) {
-                       dataType = BOOLEAN_DATATYPE;
-               } else {
-                       dataType = INTEGER_DATATYPE;
-               }
-               
-               return dataType;
-       }
-
-       @Override
-       public Object getCorrectPolicyDataObject() {
-               return policyAdapter.getData();
-       }
-       
-       public String getFunctionDefinitionId(String key){
-       FunctionDefinition object = (FunctionDefinition) commonClassDao.getDataById(FunctionDefinition.class, "shortname", key);
-       if(object != null){
-               return object.getXacmlid();
-       }
-       return null;
+                break;
+            default:
+                templateFile = new File(classLoader.getResource(XACML_GUARD_TEMPLATE).getFile());
+                xacmlTemplatePath = templateFile.toPath();
+                Map<String,String> timeWindow = new HashMap<>();
+                if(!PolicyUtils.isInteger(yamlParams.get("timeWindow"))){
+                    throw new BuilderException("time window is not in Integer format.");
+                }
+                String timeUnits = yamlParams.get("timeUnits");
+                if(timeUnits==null || !(timeUnits.equalsIgnoreCase("minute") || timeUnits.equalsIgnoreCase("hour") || timeUnits.equalsIgnoreCase("day")
+                        || timeUnits.equalsIgnoreCase("week") || timeUnits.equalsIgnoreCase("month")||timeUnits.equalsIgnoreCase("year"))){
+                    throw new BuilderException("time Units is not in proper format.");
+                }
+                timeWindow.put("value", yamlParams.get("timeWindow"));
+                timeWindow.put("units", yamlParams.get("timeUnits"));
+                cons = new Constraint(Integer.parseInt(yamlParams.get("limit")),timeWindow,activeTimeRange);
+                break;
+            }
+            builder = builder.addLimitConstraint(policy1.getId(), cons);
+            // Build the specification
+            Results results = builder.buildSpecification();
+            // YAML TO XACML
+            ControlLoopGuard yamlGuardObject = SafePolicyBuilder.loadYamlGuard(results.getSpecification());
+            String xacmlTemplateContent;
+            try {
+                xacmlTemplateContent = new String(Files.readAllBytes(xacmlTemplatePath));
+                HashMap<String, String> yamlSpecs = new HashMap<>();
+                yamlSpecs.put(POLICY_NAME, yamlParams.get(POLICY_NAME));
+                yamlSpecs.put(DESCRIPTION, yamlParams.get(DESCRIPTION));
+                yamlSpecs.put(ONAPNAME, yamlParams.get(ONAPNAME));
+                yamlSpecs.put("actor", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getActor());
+                yamlSpecs.put("recipe", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getRecipe());
+                yamlSpecs.put("clname", yamlGuardObject.getGuards().getFirst().getMatch_parameters().getControlLoopName());
+                if(yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getFreq_limit_per_target()!=null){
+                    yamlSpecs.put("limit", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getFreq_limit_per_target().toString());
+                }
+                if(yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window()!=null){
+                    yamlSpecs.put("twValue", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window().get("value"));
+                    yamlSpecs.put("twUnits", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getTime_window().get("units"));
+                }
+                yamlSpecs.put("guardActiveStart", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getActive_time_range().get("start"));
+                yamlSpecs.put("guardActiveEnd", yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getActive_time_range().get("end"));
+                String xacmlPolicyContent = SafePolicyBuilder.generateXacmlGuard(xacmlTemplateContent,yamlSpecs, yamlGuardObject.getGuards().getFirst().getLimit_constraints().getFirst().getBlacklist(), yamlGuardObject.getGuards().getFirst().getMatch_parameters().getTargets());
+               // Convert the  Policy into Stream input to Policy Adapter.
+                Object policy = XACMLPolicyScanner.readPolicy(new ByteArrayInputStream(xacmlPolicyContent.getBytes(StandardCharsets.UTF_8)));
+                return (PolicyType) policy;
+            } catch (IOException e) {
+                LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error while creating the policy " + e.getMessage() , e);
+            }
+        } catch (BuilderException e) {
+            LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Error while creating the policy " + e.getMessage() ,e);
+            throw e;
+        }
+        return null;
+    }
+
+    private DecisionSettings findDecisionSettingsBySettingId(String settingId) {
+        DecisionSettings decisionSetting = null;
+
+        EntityManager em = XACMLPapServlet.getEmf().createEntityManager();
+        Query getDecisionSettings = em.createNamedQuery("DecisionSettings.findAll");
+        List<?> decisionSettingsList = getDecisionSettings.getResultList();
+
+        for (Object id : decisionSettingsList) {
+            decisionSetting = (DecisionSettings) id;
+            if (decisionSetting.getXacmlId().equals(settingId)) {
+                break;
+            }
+        }
+        return decisionSetting;
+    }
+
+    private void createRule(PolicyType decisionPolicy, boolean permitRule) {
+        RuleType rule = new RuleType();
+
+        rule.setRuleId(policyAdapter.getRuleID());
+
+        if (permitRule) {
+            rule.setEffect(EffectType.PERMIT);
+        } else {
+            rule.setEffect(EffectType.DENY);
+        }
+        rule.setTarget(new TargetType());
+
+        // Create Target in Rule
+        AllOfType allOfInRule = new AllOfType();
+
+        // Creating match for ACCESS in rule target
+        MatchType accessMatch = new MatchType();
+        AttributeValueType accessAttributeValue = new AttributeValueType();
+        accessAttributeValue.setDataType(STRING_DATATYPE);
+        accessAttributeValue.getContent().add("DECIDE");
+        accessMatch.setAttributeValue(accessAttributeValue);
+        AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
+        URI accessURI = null;
+        try {
+            accessURI = new URI(ACTION_ID);
+        } catch (URISyntaxException e) {
+            PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "DecisionPolicy", "Exception creating ACCESS URI");
+        }
+        accessAttributeDesignator.setCategory(CATEGORY_ACTION);
+        accessAttributeDesignator.setDataType(STRING_DATATYPE);
+        accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
+        accessMatch.setAttributeDesignator(accessAttributeDesignator);
+        accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+        dynamicLabelRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmLabels();
+        dynamicFieldComboRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmCombo();
+        dynamicFieldOneRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField1();
+        dynamicFieldTwoRuleAlgorithms = policyAdapter.getDynamicRuleAlgorithmField2();
+
+        if(policyAdapter.getRuleProvider()!=null && policyAdapter.getRuleProvider().equals(AAFPROVIDER)){
+            // Values for AAF Provider are here for XML Creation.
+            ConditionType condition = new ConditionType();
+            ApplyType decisionApply = new ApplyType();
+
+            AttributeValueType value1 = new AttributeValueType();
+            value1.setDataType(BOOLEAN_DATATYPE);
+            value1.getContent().add("true");
+
+            AttributeDesignatorType value2 = new AttributeDesignatorType();
+            value2.setAttributeId(AAFEngine.AAF_RESULT);
+            value2.setCategory(CATEGORY_RESOURCE);
+            value2.setDataType(BOOLEAN_DATATYPE);
+            value2.setMustBePresent(false);
+
+            ApplyType innerDecisionApply = new ApplyType();
+            innerDecisionApply.setFunctionId(FUNCTION_BOOLEAN_ONE_AND_ONLY);
+            innerDecisionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(value2));
+
+            decisionApply.setFunctionId(XACML3.ID_FUNCTION_BOOLEAN_EQUAL.stringValue());
+            decisionApply.getExpression().add(new ObjectFactory().createAttributeValue(value1));
+            decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply));
+            condition.setExpression(new ObjectFactory().createApply(decisionApply));
+            if (!permitRule) {
+                ApplyType notOuterApply = new ApplyType();
+                notOuterApply.setFunctionId(FUNCTION_NOT);
+                notOuterApply.getExpression().add(condition.getExpression());
+                condition.setExpression(new ObjectFactory().createApply(notOuterApply));
+            }
+            rule.setCondition(condition);
+            allOfInRule.getMatch().add(accessMatch);
+
+            AnyOfType anyOfInRule = new AnyOfType();
+            anyOfInRule.getAllOf().add(allOfInRule);
+
+            TargetType targetInRule = new TargetType();
+            targetInRule.getAnyOf().add(anyOfInRule);
+
+            rule.setTarget(targetInRule);
+            if(!permitRule){
+                AdviceExpressionsType adviceExpressions = new AdviceExpressionsType();
+                AdviceExpressionType adviceExpression = new AdviceExpressionType();
+                adviceExpression.setAdviceId(AAFPROVIDER);
+                adviceExpression.setAppliesTo(EffectType.DENY);
+                AttributeAssignmentExpressionType assignment = new AttributeAssignmentExpressionType();
+                assignment.setAttributeId("aaf.response");
+                assignment.setCategory(CATEGORY_RESOURCE);
+                AttributeDesignatorType value = new AttributeDesignatorType();
+                value.setAttributeId(AAFEngine.AAF_RESPONSE);
+                value.setCategory(CATEGORY_RESOURCE);
+                value.setDataType(STRING_DATATYPE);
+                value.setMustBePresent(false);
+                assignment.setExpression(new ObjectFactory().createAttributeDesignator(value));
+                adviceExpression.getAttributeAssignmentExpression().add(assignment);
+                adviceExpressions.getAdviceExpression().add(adviceExpression);
+                rule.setAdviceExpressions(adviceExpressions);
+            }
+            decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
+            policyAdapter.setPolicyData(decisionPolicy);
+
+        }else if (dynamicLabelRuleAlgorithms != null && !dynamicLabelRuleAlgorithms.isEmpty()) {
+            boolean isCompound = false;
+            ConditionType condition = new ConditionType();
+            int index = dynamicFieldOneRuleAlgorithms.size() - 1;
+
+            for (String labelAttr : dynamicLabelRuleAlgorithms) {
+                // if the rule algorithm as a label means it is a compound
+                if (dynamicFieldOneRuleAlgorithms.get(index).equals(labelAttr)) {
+                    ApplyType decisionApply = new ApplyType();
+
+                    String selectedFunction = dynamicFieldComboRuleAlgorithms.get(index);
+                    String value1 = dynamicFieldOneRuleAlgorithms.get(index);
+                    String value2 = dynamicFieldTwoRuleAlgorithms.get(index);
+                    decisionApply.setFunctionId(getFunctionDefinitionId(selectedFunction));
+                    decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value1)));
+                    decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value2)));
+                    condition.setExpression(new ObjectFactory().createApply(decisionApply));
+                    isCompound = true;
+                }
+
+                // if rule algorithm not a compound
+                if (!isCompound) {
+                    condition.setExpression(new ObjectFactory().createApply(getInnerDecisionApply(dynamicLabelRuleAlgorithms.get(index))));
+                }
+            }
+            if (!permitRule) {
+                ApplyType notOuterApply = new ApplyType();
+                notOuterApply.setFunctionId(FUNCTION_NOT);
+                notOuterApply.getExpression().add(condition.getExpression());
+                condition.setExpression(new ObjectFactory().createApply(notOuterApply));
+            }
+            rule.setCondition(condition);
+            allOfInRule.getMatch().add(accessMatch);
+
+            AnyOfType anyOfInRule = new AnyOfType();
+            anyOfInRule.getAllOf().add(allOfInRule);
+
+            TargetType targetInRule = new TargetType();
+            targetInRule.getAnyOf().add(anyOfInRule);
+
+            rule.setTarget(targetInRule);
+
+            decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
+            policyAdapter.setPolicyData(decisionPolicy);
+
+        } else {
+            PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + "Unsupported data object."+ policyAdapter.getData().getClass().getCanonicalName());
+        }
+
     }
-       
+
+    private void createRainydayRule(PolicyType decisionPolicy, String errorcode, String treatment, boolean permitRule) {
+        RuleType rule = new RuleType();
+
+        rule.setRuleId(UUID.randomUUID().toString());
+
+        if (permitRule) {
+            rule.setEffect(EffectType.PERMIT);
+        } else {
+            rule.setEffect(EffectType.DENY);
+        }
+        rule.setTarget(new TargetType());
+
+        // Create Target in Rule
+        AllOfType allOfInRule = new AllOfType();
+
+        // Creating match for DECIDE in rule target
+        MatchType accessMatch = new MatchType();
+        AttributeValueType accessAttributeValue = new AttributeValueType();
+        accessAttributeValue.setDataType(STRING_DATATYPE);
+        accessAttributeValue.getContent().add("DECIDE");
+        accessMatch.setAttributeValue(accessAttributeValue);
+        AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
+        URI accessURI = null;
+        try {
+            accessURI = new URI(ACTION_ID);
+        } catch (URISyntaxException e) {
+            PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "DecisionPolicy", "Exception creating ACCESS URI");
+        }
+        accessAttributeDesignator.setCategory(CATEGORY_ACTION);
+        accessAttributeDesignator.setDataType(STRING_DATATYPE);
+        accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
+        accessMatch.setAttributeDesignator(accessAttributeDesignator);
+        accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+        allOfInRule.getMatch().add(accessMatch);
+
+        // Creating match for ErrorCode in rule target
+        MatchType errorcodeMatch = new MatchType();
+        AttributeValueType errorcodeAttributeValue = new AttributeValueType();
+        errorcodeAttributeValue.setDataType(STRING_DATATYPE);
+        errorcodeAttributeValue.getContent().add(errorcode);
+        errorcodeMatch.setAttributeValue(errorcodeAttributeValue);
+        AttributeDesignatorType errorcodeAttributeDesignator = new AttributeDesignatorType();
+        errorcodeAttributeDesignator.setCategory(CATEGORY_RESOURCE);
+        errorcodeAttributeDesignator.setDataType(STRING_DATATYPE);
+        errorcodeAttributeDesignator.setAttributeId("ErrorCode");
+        errorcodeMatch.setAttributeDesignator(errorcodeAttributeDesignator);
+        errorcodeMatch.setMatchId(FUNCTION_STRING_REGEXP_MATCH);
+
+        allOfInRule.getMatch().add(errorcodeMatch);
+
+        AnyOfType anyOfInRule = new AnyOfType();
+        anyOfInRule.getAllOf().add(allOfInRule);
+
+        TargetType targetInRule = new TargetType();
+        targetInRule.getAnyOf().add(anyOfInRule);
+
+        rule.setTarget(targetInRule);
+
+        AdviceExpressionsType adviceExpressions = new AdviceExpressionsType();
+        AdviceExpressionType adviceExpression = new AdviceExpressionType();
+        adviceExpression.setAdviceId(RAINY_DAY);
+        adviceExpression.setAppliesTo(EffectType.PERMIT);
+
+        AttributeAssignmentExpressionType assignment = new AttributeAssignmentExpressionType();
+        assignment.setAttributeId("treatment");
+        assignment.setCategory(CATEGORY_RESOURCE);
+
+        AttributeValueType treatmentAttributeValue = new AttributeValueType();
+        treatmentAttributeValue.setDataType(STRING_DATATYPE);
+        treatmentAttributeValue.getContent().add(treatment);
+        assignment.setExpression(new ObjectFactory().createAttributeValue(treatmentAttributeValue));
+
+        adviceExpression.getAttributeAssignmentExpression().add(assignment);
+        adviceExpressions.getAdviceExpression().add(adviceExpression);
+        rule.setAdviceExpressions(adviceExpressions);
+        decisionPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
+        policyAdapter.setPolicyData(decisionPolicy);
+
+    }
+
+    // if compound setting the inner apply here
+    protected ApplyType getInnerDecisionApply(String value1Label) {
+        ApplyType decisionApply = new ApplyType();
+        int index = 0;
+        // check the index for the label.
+        for (String labelAttr : dynamicLabelRuleAlgorithms) {
+            if (labelAttr.equals(value1Label)) {
+                String value1 = dynamicFieldOneRuleAlgorithms.get(index);
+                populateDataTypeList(value1);
+
+                // check if the row contains label again
+                for (String labelValue : dynamicLabelRuleAlgorithms) {
+                    if (labelValue.equals(value1)) {
+                        return getCompoundDecisionApply(index);
+                    }
+                }
+
+                // Getting the values from the form.
+                String functionKey = dynamicFieldComboRuleAlgorithms.get(index);
+                String value2 = dynamicFieldTwoRuleAlgorithms.get(index);
+                decisionApply.setFunctionId(getFunctionDefinitionId(functionKey));
+                // if two text field are rule attributes.
+                if ((value1.contains(RULE_VARIABLE)) && (value2.contains(RULE_VARIABLE))) {
+                    ApplyType innerDecisionApply1 = new ApplyType();
+                    ApplyType  innerDecisionApply2      = new  ApplyType();
+                    AttributeDesignatorType  attributeDesignator1        = new AttributeDesignatorType();
+                    AttributeDesignatorType  attributeDesignator2        = new AttributeDesignatorType();
+                    //If selected function is Integer function set integer functionID
+                    if(functionKey.toLowerCase().contains("integer")){
+                        innerDecisionApply1.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY );
+                        innerDecisionApply2.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
+                        attributeDesignator1.setDataType(INTEGER_DATATYPE);
+                        attributeDesignator2.setDataType(INTEGER_DATATYPE);
+                    } else{
+                        //If selected function is not a Integer function set String functionID
+                        innerDecisionApply1.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
+                        innerDecisionApply2.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
+                        attributeDesignator1.setDataType(STRING_DATATYPE);
+                        attributeDesignator2.setDataType(STRING_DATATYPE);
+                    }
+                    attributeDesignator1.setCategory(CATEGORY_RESOURCE);
+                    attributeDesignator2.setCategory(CATEGORY_RESOURCE);
+                    //Here set actual field values
+                    attributeDesignator1.setAttributeId(value1.  contains("resource:")?value1.substring( 9):value1.substring(8));
+                    attributeDesignator2.setAttributeId(value1.  contains("resource:")?value1.substring( 9):value1.substring(8));
+                    innerDecisionApply1.getExpression().add(new ObjectFactory().createAttributeDesignator( attributeDesignator1));
+                    innerDecisionApply2.getExpression().add(new ObjectFactory().createAttributeDesignator( attributeDesignator2));
+                    decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply1));
+                    decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply2));
+                } else {
+                    // if either of one text field is rule attribute.
+                    if (!value1.startsWith("S_")) {
+                        ApplyType innerDecisionApply = new ApplyType();
+                        AttributeDesignatorType attributeDesignator = new AttributeDesignatorType();
+                        AttributeValueType decisionConditionAttributeValue = new AttributeValueType();
+
+                        if (functionKey.toLowerCase().contains("integer")) {
+                            innerDecisionApply.setFunctionId(FUNTION_INTEGER_ONE_AND_ONLY);
+                            decisionConditionAttributeValue.setDataType(INTEGER_DATATYPE);
+                            attributeDesignator.setDataType(INTEGER_DATATYPE);
+                        } else {
+                            innerDecisionApply.setFunctionId(FUNCTION_STRING_ONE_AND_ONLY);
+                            decisionConditionAttributeValue.setDataType(STRING_DATATYPE);
+                            attributeDesignator.setDataType(STRING_DATATYPE);
+                        }
+
+                        String attributeId = null;
+                        String attributeValue = null;
+
+                        // Find which textField has rule attribute and set it as
+                        // attributeId and the other as attributeValue.
+                        attributeId = value1;
+                        attributeValue = value2;
+
+                        if (attributeId != null) {
+                            attributeDesignator.setCategory(CATEGORY_RESOURCE);
+                            attributeDesignator.setAttributeId(attributeId);
+                        }
+                        decisionConditionAttributeValue.getContent().add(attributeValue);
+                        innerDecisionApply.getExpression().add(new ObjectFactory().createAttributeDesignator(attributeDesignator));
+                        decisionApply.getExpression().add(new ObjectFactory().createAttributeValue(decisionConditionAttributeValue));
+                        decisionApply.getExpression().add(new ObjectFactory().createApply(innerDecisionApply));
+                    } else {
+                        value1 = value1.substring(2, value1.length());
+                        VariableReferenceType variableReferenceType = new VariableReferenceType();
+                        variableReferenceType.setVariableId(value1);
+
+                        String dataType = dataTypeList.get(index);
+
+                        AttributeValueType decisionConditionAttributeValue = new AttributeValueType();
+                        decisionConditionAttributeValue.setDataType(dataType);
+                        decisionConditionAttributeValue.getContent().add(value2);
+                        decisionApply.getExpression().add(new ObjectFactory().createVariableReference(variableReferenceType));
+                        decisionApply.getExpression().add(new ObjectFactory().createAttributeValue(decisionConditionAttributeValue));
+                    }
+                }
+            }
+            index++;
+        }
+        return decisionApply;
+    }
+
+    // if the rule algorithm is multiple compound one setting the apply
+    protected ApplyType getCompoundDecisionApply(int index) {
+        ApplyType decisionApply = new ApplyType();
+        String selectedFunction = dynamicFieldComboRuleAlgorithms.get(index);
+        String value1 = dynamicFieldOneRuleAlgorithms.get(index);
+        String value2 = dynamicFieldTwoRuleAlgorithms.get(index);
+        decisionApply.setFunctionId(getFunctionDefinitionId(selectedFunction));
+        decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value1)));
+        decisionApply.getExpression().add(new ObjectFactory().createApply(getInnerDecisionApply(value2)));
+        return decisionApply;
+    }
+
+    private VariableDefinitionType createDynamicVariable(String key, String value, String dataType) {
+        VariableDefinitionType dynamicVariable = new VariableDefinitionType();
+        AttributeValueType dynamicAttributeValue = new AttributeValueType();
+
+        dynamicAttributeValue.setDataType(dataType);
+        dynamicAttributeValue.getContent().add(value);
+
+        dynamicVariable.setVariableId(key);
+        dynamicVariable.setExpression(new ObjectFactory().createAttributeValue(dynamicAttributeValue));
+
+        return dynamicVariable;
+
+    }
+
+    private void populateDataTypeList(String value1) {
+        String dataType = null;
+        if(value1.contains("S_")) {
+            value1 = value1.substring(2, value1.length());
+            DecisionSettings decisionSettings = findDecisionSettingsBySettingId(value1.substring(2, value1.length()));
+            if (decisionSettings != null && "string".equals(decisionSettings.getDatatypeBean().getShortName())) {
+                dataType = STRING_DATATYPE;
+            } else if (decisionSettings != null && "boolean".equals(decisionSettings.getDatatypeBean().getShortName())) {
+                dataType = BOOLEAN_DATATYPE;
+            } else {
+                dataType = INTEGER_DATATYPE;
+            }
+        } else {
+            dataType = "OTHER";
+        }
+
+        dataTypeList.add(dataType);
+    }
+
+
+    private String getDataType(String key) {
+
+        DecisionSettings decisionSettings = findDecisionSettingsBySettingId(key);
+        String dataType = null;
+
+        if (decisionSettings != null && "string".equals(decisionSettings.getDatatypeBean().getShortName())) {
+            dataType = STRING_DATATYPE;
+        } else if (decisionSettings != null && "boolean".equals(decisionSettings.getDatatypeBean().getShortName())) {
+            dataType = BOOLEAN_DATATYPE;
+        } else {
+            dataType = INTEGER_DATATYPE;
+        }
+
+        return dataType;
+    }
+
+    @Override
+    public Object getCorrectPolicyDataObject() {
+        return policyAdapter.getData();
+    }
+
+    public String getFunctionDefinitionId(String key){
+        FunctionDefinition object = (FunctionDefinition) commonClassDao.getDataById(FunctionDefinition.class, "shortname", key);
+        if(object != null){
+            return object.getXacmlid();
+        }
+        return null;
+    }
+
 }
index e747edb..6cadc77 100644 (file)
@@ -84,1211 +84,1211 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
 
 public class FirewallConfigPolicy extends Policy {
 
-       private static final Logger LOGGER = FlexLogger.getLogger(FirewallConfigPolicy.class);
+    private static final Logger LOGGER = FlexLogger.getLogger(FirewallConfigPolicy.class);
 
-       public FirewallConfigPolicy() {
-               super();
-       }
+    public FirewallConfigPolicy() {
+        super();
+    }
 
-       public FirewallConfigPolicy(PolicyRestAdapter policyAdapter) {
-               this.policyAdapter = policyAdapter;
-               this.policyAdapter.setConfigType(policyAdapter.getConfigType());
-       }
+    public FirewallConfigPolicy(PolicyRestAdapter policyAdapter) {
+        this.policyAdapter = policyAdapter;
+        this.policyAdapter.setConfigType(policyAdapter.getConfigType());
+    }
 
-       // Saving the Configurations file at server location for config policy.
-       protected void saveConfigurations(String policyName, String jsonBody) {
-               String configurationName = policyName;
-               if(configurationName.endsWith(".xml")){
+    // Saving the Configurations file at server location for config policy.
+    protected void saveConfigurations(String policyName, String jsonBody) {
+        String configurationName = policyName;
+        if(configurationName.endsWith(".xml")){
             configurationName = configurationName.replace(".xml", "");
-               }
+        }
         String fileName = CONFIG_HOME + File.separator + configurationName + ".json";
-               try(BufferedWriter bw = new BufferedWriter(new FileWriter(fileName))){
-                   bw.write(jsonBody);
-                       if (LOGGER.isDebugEnabled()) {
-                               LOGGER.debug("Configuration is succesfully saved");
-                       }
-               } catch (IOException e) {
-                       LOGGER.error("Save of configuration to file" +fileName+ "failed",e);
-               }
-       }
-       
+        try(BufferedWriter bw = new BufferedWriter(new FileWriter(fileName))){
+            bw.write(jsonBody);
+            if (LOGGER.isDebugEnabled()) {
+                LOGGER.debug("Configuration is succesfully saved");
+            }
+        } catch (IOException e) {
+            LOGGER.error("Save of configuration to file" +fileName+ "failed",e);
+        }
+    }
+
    //Utility to read json data from the existing file to a string
-       static String readFile(String path, Charset encoding) throws IOException {
-               byte[] encoded = Files.readAllBytes(Paths.get(path));
-               return new String(encoded, encoding);
-       }
-
-       @Override
-       public Map<String, String> savePolicies() throws PAPException {
-               Map<String, String> successMap = new HashMap<>();
-               if(isPolicyExists()){
-                       successMap.put("EXISTS", "This Policy already exist on the PAP");
-                       return successMap;
-               }
-               if(!isPreparedToSave()){
-                       prepareToSave();
-               }
-
-               // Until here we prepared the data and here calling the method to create xml.
-               Path newPolicyPath = null;
-               newPolicyPath = Paths.get(policyAdapter.getNewFileName());
-               Boolean dbIsUpdated = false;
-               if (policyAdapter.getApiflag() != null && "admin".equalsIgnoreCase(policyAdapter.getApiflag())){
-                       if (policyAdapter.isEditPolicy()) {
-                               dbIsUpdated = updateFirewallDictionaryData(policyAdapter.getJsonBody(), policyAdapter.getPrevJsonBody());
-                       } else {
-                               try {
+    static String readFile(String path, Charset encoding) throws IOException {
+        byte[] encoded = Files.readAllBytes(Paths.get(path));
+        return new String(encoded, encoding);
+    }
+
+    @Override
+    public Map<String, String> savePolicies() throws PAPException {
+        Map<String, String> successMap = new HashMap<>();
+        if(isPolicyExists()){
+            successMap.put("EXISTS", "This Policy already exist on the PAP");
+            return successMap;
+        }
+        if(!isPreparedToSave()){
+            prepareToSave();
+        }
+
+        // Until here we prepared the data and here calling the method to create xml.
+        Path newPolicyPath = null;
+        newPolicyPath = Paths.get(policyAdapter.getNewFileName());
+        Boolean dbIsUpdated = false;
+        if (policyAdapter.getApiflag() != null && "admin".equalsIgnoreCase(policyAdapter.getApiflag())){
+            if (policyAdapter.isEditPolicy()) {
+                dbIsUpdated = updateFirewallDictionaryData(policyAdapter.getJsonBody(), policyAdapter.getPrevJsonBody());
+            } else {
+                try {
                     dbIsUpdated = insertFirewallDicionaryData(policyAdapter.getJsonBody());
                 } catch (SQLException e) {
                     throw new PAPException(e);
                 }
-                       }
-               } else {
-                       dbIsUpdated = true;
-               }
-
-               if(dbIsUpdated) {
-                       successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());  
-               } else {
-                       PolicyLogger.error("Failed to Update the Database Dictionary Tables.");
-
-                       //remove the new json file 
-                       String jsonBody = policyAdapter.getPrevJsonBody();
-                       if (jsonBody!=null){
-                               saveConfigurations(policyName, jsonBody);
-                       } else {
-                               saveConfigurations(policyName, "");
-                       }
-                       successMap.put("fwdberror", "DB UPDATE");
-               }
-
-               return successMap;              
-       }
-
-       //This is the method for preparing the policy for saving.  We have broken it out
-       //separately because the fully configured policy is used for multiple things
-       @Override
-       public boolean prepareToSave() throws PAPException{
-
-               if(isPreparedToSave()){
-                       //we have already done this
-                       return true;
-               }
-
-               int version = 0;
-               String policyID = policyAdapter.getPolicyID();
-               version = policyAdapter.getHighestVersion();
-
-               // Create the Instance for pojo, PolicyType object is used in marshaling.
-               if ("Config".equals(policyAdapter.getPolicyType())) {
-                       PolicyType policyConfig = new PolicyType();
-
-                       policyConfig.setVersion(Integer.toString(version));
-                       policyConfig.setPolicyId(policyID);
-                       policyConfig.setTarget(new TargetType());
-                       policyAdapter.setData(policyConfig);
-               }
-               policyName = policyAdapter.getNewFileName();
-
-               //String oldPolicyName = policyName.replace(".xml", "");
-               String scope = policyName.substring(0, policyName.indexOf('.'));
-               String dbPolicyName = policyName.substring(policyName.indexOf('.')+1).replace(".xml", "");
-
-               int oldversion = Integer.parseInt(dbPolicyName.substring(dbPolicyName.lastIndexOf('.')+1));
-               dbPolicyName = dbPolicyName.substring(0, dbPolicyName.lastIndexOf('.')+1);
-               if(oldversion > 1){
-                       oldversion = oldversion - 1; 
-                       dbPolicyName = dbPolicyName + oldversion + ".xml";
-               }
-               EntityManager em = XACMLPapServlet.getEmf().createEntityManager();
-               Query createPolicyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:policyName");                     
-               createPolicyQuery.setParameter("scope", scope);
-               createPolicyQuery.setParameter("policyName", dbPolicyName);
-               List<?> createPolicyQueryList = createPolicyQuery.getResultList();
-               if(!createPolicyQueryList.isEmpty()){
-                       PolicyEntity entitydata = (PolicyEntity) createPolicyQueryList.get(0);
-                       policyAdapter.setPrevJsonBody(entitydata.getConfigurationData().getConfigBody());
-               }
-               em.close();
-               if (policyAdapter.getData() != null) {
-                       String jsonBody = policyAdapter.getJsonBody();
-                       saveConfigurations(policyName, jsonBody);
-
-                       // Make sure the filename ends with an extension
-                       if (!policyName.endsWith(".xml")) {
-                               policyName = policyName + ".xml";
-                       }
-
-                       PolicyType configPolicy = (PolicyType) policyAdapter.getData();
-
-                       configPolicy.setDescription(policyAdapter.getPolicyDescription());
-
-                       configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
-
-                       AllOfType allOfOne = new AllOfType();
-                       String fileName = policyAdapter.getNewFileName();
-                       String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length());
-                       if ((name == null) || (name.equals(""))) {
-                               name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
-                       }
-                       allOfOne.getMatch().add(createMatch("PolicyName", name));
-                       AllOfType allOf = new AllOfType();
-
-                       // Match for ConfigName
-                       allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
-                       // Match for riskType
-                       allOf.getMatch().add(createDynamicMatch("RiskType", policyAdapter.getRiskType()));
-                       // Match for riskLevel
-                       allOf.getMatch().add(createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
-                       // Match for riskguard
-                       allOf.getMatch().add(createDynamicMatch("guard", policyAdapter.getGuard()));
-                       // Match for ttlDate
-                       allOf.getMatch().add(createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
-                       AnyOfType anyOf = new AnyOfType();
-                       anyOf.getAllOf().add(allOfOne);
-                       anyOf.getAllOf().add(allOf);
-
-                       TargetType target = new TargetType();
-                       target.getAnyOf().add(anyOf);
-
-                       // Adding the target to the policy element
-                       configPolicy.setTarget((TargetType) target);
-
-                       RuleType rule = new RuleType();
-                       rule.setRuleId(policyAdapter.getRuleID());
-                       rule.setEffect(EffectType.PERMIT);
-
-                       // Create Target in Rule
-                       AllOfType allOfInRule = new AllOfType();
-
-                       // Creating match for ACCESS in rule target
-                       MatchType accessMatch = new MatchType();
-                       AttributeValueType accessAttributeValue = new AttributeValueType();
-                       accessAttributeValue.setDataType(STRING_DATATYPE);
-                       accessAttributeValue.getContent().add("ACCESS");
-                       accessMatch.setAttributeValue(accessAttributeValue);
-                       AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
-                       URI accessURI = null;
-                       try {
-                               accessURI = new URI(ACTION_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "FirewallConfigPolicy", "Exception creating ACCESS URI");
-                       }
-                       accessAttributeDesignator.setCategory(CATEGORY_ACTION);
-                       accessAttributeDesignator.setDataType(STRING_DATATYPE);
-                       accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
-                       accessMatch.setAttributeDesignator(accessAttributeDesignator);
-                       accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       // Creating Config Match in rule Target
-                       MatchType configMatch = new MatchType();
-                       AttributeValueType configAttributeValue = new AttributeValueType();
-                       configAttributeValue.setDataType(STRING_DATATYPE);
-
-                       configAttributeValue.getContent().add("Config");
-
-                       configMatch.setAttributeValue(configAttributeValue);
-                       AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
-                       URI configURI = null;
-                       try {
-                               configURI = new URI(RESOURCE_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "FirewallConfigPolicy", "Exception creating Config URI");
-                       }
-
-                       configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
-                       configAttributeDesignator.setDataType(STRING_DATATYPE);
-                       configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
-                       configMatch.setAttributeDesignator(configAttributeDesignator);
-                       configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       allOfInRule.getMatch().add(accessMatch);
-                       allOfInRule.getMatch().add(configMatch);
-
-                       AnyOfType anyOfInRule = new AnyOfType();
-                       anyOfInRule.getAllOf().add(allOfInRule);
-
-                       TargetType targetInRule = new TargetType();
-                       targetInRule.getAnyOf().add(anyOfInRule);
-
-                       rule.setTarget(targetInRule);
-                       rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
-
-                       configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
-                       policyAdapter.setPolicyData(configPolicy);
-
-               } else {
-                       PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
-               }
-               setPreparedToSave(true);
-               return true;
-       }
-
-       // Data required for Advice part is setting here.
-       private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
-
-               //Firewall Config ID Assignment
-               AdviceExpressionsType advices = new AdviceExpressionsType();
-               AdviceExpressionType advice = new AdviceExpressionType();
-               advice.setAdviceId("firewallConfigID");
-               advice.setAppliesTo(EffectType.PERMIT);
-               // For Configuration
-               AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
-               assignment1.setAttributeId("type");
-               assignment1.setCategory(CATEGORY_RESOURCE);
-               assignment1.setIssuer("");
-               AttributeValueType configNameAttributeValue = new AttributeValueType();
-               configNameAttributeValue.setDataType(STRING_DATATYPE);
-               configNameAttributeValue.getContent().add("Configuration");
-               assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
-               advice.getAttributeAssignmentExpression().add(assignment1);
-
-               // For Config file Url if configurations are provided.
-               //URL ID Assignment
-               AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
-               assignment2.setAttributeId("URLID");
-               assignment2.setCategory(CATEGORY_RESOURCE);
-               assignment2.setIssuer("");
-               AttributeValueType AttributeValue = new AttributeValueType();
-               AttributeValue.setDataType(URI_DATATYPE);
-               if (policyName.endsWith(".xml")) {
-                       policyName = policyName.substring(0, policyName.lastIndexOf(".xml"));
-               }
-               String content = CONFIG_URL + "/Config/" + policyName + ".json";
-
-               AttributeValue.getContent().add(content);
-               assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue));
-               advice.getAttributeAssignmentExpression().add(assignment2);
-
-               //Policy Name Assignment
-               AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
-               assignment3.setAttributeId("PolicyName");
-               assignment3.setCategory(CATEGORY_RESOURCE);
-               assignment3.setIssuer("");
-               AttributeValueType attributeValue3 = new AttributeValueType();
-               attributeValue3.setDataType(STRING_DATATYPE);
-               fileName = FilenameUtils.removeExtension(fileName);
-               fileName = fileName + ".xml";
-               String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
-               if ((name == null) || (name.equals(""))) {
-                       name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
-               }
-               attributeValue3.getContent().add(name);
-               assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
-               advice.getAttributeAssignmentExpression().add(assignment3);
-
-               //Version Number Assignment
-               AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
-               assignment4.setAttributeId("VersionNumber");
-               assignment4.setCategory(CATEGORY_RESOURCE);
-               assignment4.setIssuer("");
-               AttributeValueType configNameAttributeValue4 = new AttributeValueType();
-               configNameAttributeValue4.setDataType(STRING_DATATYPE);
-               configNameAttributeValue4.getContent().add(Integer.toString(version));
-               assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
-               advice.getAttributeAssignmentExpression().add(assignment4);
-
-               //Onap Name Assignment
-               AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
-               assignment5.setAttributeId("matching:" + ONAPID);
-               assignment5.setCategory(CATEGORY_RESOURCE);
-               assignment5.setIssuer("");
-               AttributeValueType configNameAttributeValue5 = new AttributeValueType();
-               configNameAttributeValue5.setDataType(STRING_DATATYPE);
-               assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
-               advice.getAttributeAssignmentExpression().add(assignment5);
-
-               //Config Name Assignment
-               AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
-               assignment6.setAttributeId("matching:" + CONFIGID);
-               assignment6.setCategory(CATEGORY_RESOURCE);
-               assignment6.setIssuer("");
-               AttributeValueType configNameAttributeValue6 = new AttributeValueType();
-               configNameAttributeValue6.setDataType(STRING_DATATYPE);
-               configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
-               assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
-               advice.getAttributeAssignmentExpression().add(assignment6);
-
-               //Risk Attributes
-               AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
-               assignment7.setAttributeId("RiskType");
-               assignment7.setCategory(CATEGORY_RESOURCE);
-               assignment7.setIssuer("");
-
-               AttributeValueType configNameAttributeValue7 = new AttributeValueType();
-               configNameAttributeValue7.setDataType(STRING_DATATYPE);
-               configNameAttributeValue7.getContent().add(policyAdapter.getRiskType());
-               assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
-
-               advice.getAttributeAssignmentExpression().add(assignment7);
-
-               AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
-               assignment8.setAttributeId("RiskLevel");
-               assignment8.setCategory(CATEGORY_RESOURCE);
-               assignment8.setIssuer("");
-
-               AttributeValueType configNameAttributeValue8 = new AttributeValueType();
-               configNameAttributeValue8.setDataType(STRING_DATATYPE);
-               configNameAttributeValue8.getContent().add(policyAdapter.getRiskLevel());
-               assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
-
-               advice.getAttributeAssignmentExpression().add(assignment8);     
-
-               AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
-               assignment9.setAttributeId("guard");
-               assignment9.setCategory(CATEGORY_RESOURCE);
-               assignment9.setIssuer("");
-
-               AttributeValueType configNameAttributeValue9 = new AttributeValueType();
-               configNameAttributeValue9.setDataType(STRING_DATATYPE);
-               configNameAttributeValue9.getContent().add(policyAdapter.getGuard());
-               assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
-
-               advice.getAttributeAssignmentExpression().add(assignment9);
-
-               AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
-               assignment10.setAttributeId("TTLDate");
-               assignment10.setCategory(CATEGORY_RESOURCE);
-               assignment10.setIssuer("");
-
-               AttributeValueType configNameAttributeValue10 = new AttributeValueType();
-               configNameAttributeValue10.setDataType(STRING_DATATYPE);
-               configNameAttributeValue10.getContent().add(policyAdapter.getTtlDate());
-               assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
-
-               advice.getAttributeAssignmentExpression().add(assignment10);
-               advices.getAdviceExpression().add(advice);
-               return advices;
-       }
-
-
-       private Boolean insertFirewallDicionaryData (String jsonBody) throws SQLException {
-               CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
-               JsonObject json = null;
-               if (jsonBody != null) {
-
-                       //Read jsonBody to JsonObject
-                       json = stringToJson(jsonBody);
-
-                       JsonArray firewallRules = null;
-                       JsonArray serviceGroup = null;
-                       JsonArray addressGroup = null;
-                       //insert data into tables
-                       try {
-                               firewallRules = json.getJsonArray("firewallRuleList");
-                               serviceGroup = json.getJsonArray("serviceGroups");
-                               addressGroup = json.getJsonArray("addressGroups");      
-                               /*
-                                * Inserting firewallRuleList data into the Terms, SecurityZone, and Action tables
-                                */
-                               if (firewallRules != null) {
-                                       for(int i = 0;i<firewallRules.size();i++) {
-                                               /*
-                                                * Populate ArrayLists with values from the JSON
-                                                */
-                                               //create the JSON object from the JSON Array for each iteration through the for loop
-                                               JsonObject ruleListobj = firewallRules.getJsonObject(i);
-
-                                               //get values from JSON fields of firewallRulesList Array
-                                               String ruleName = ruleListobj.get("ruleName").toString();
-                                               String action = ruleListobj.get("action").toString();
-                                               String description = ruleListobj.get("description").toString();
-                                               List<Object> result = dbConnection.getDataById(TermList.class, "termName", ruleName);
-                                               if(result != null && !result.isEmpty()){
-                                                       TermList termEntry = (TermList) result.get(0);
-                                                       dbConnection.delete(termEntry);
-                                               }
-                                               
-                                               //getting fromZone Array field from the firewallRulesList
-                                               JsonArray fromZoneArray = ruleListobj.getJsonArray("fromZones");
-                                               String fromZoneString = null;
-
-                                               for (int fromZoneIndex = 0;fromZoneIndex<fromZoneArray.size(); fromZoneIndex++) {
-                                                       String value = fromZoneArray.get(fromZoneIndex).toString();
-                                                       value = value.replace("\"", "");
-                                                       if (fromZoneString != null) {
-                                                               fromZoneString = fromZoneString.concat(",").concat(value);
-                                                       } else {
-                                                               fromZoneString = value;
-                                                       }
-                                               }
-                                               String fromZoneInsert = "'"+fromZoneString+"'";
-
-                                               //getting toZone Array field from the firewallRulesList
-                                               JsonArray toZoneArray = ruleListobj.getJsonArray("toZones");
-                                               String toZoneString = null;
-                                               for (int toZoneIndex = 0; toZoneIndex<toZoneArray.size(); toZoneIndex++) {
-                                                       String value = toZoneArray.get(toZoneIndex).toString();
-                                                       value = value.replace("\"", "");
-                                                       if (toZoneString != null) {
-                                                               toZoneString = toZoneString.concat(",").concat(value);
-                                                       } else {
-                                                               toZoneString = value;
-                                                       }
-                                               }
-                                               String toZoneInsert = "'"+toZoneString+"'";
-
-                                               //getting sourceList Array fields from the firewallRulesList
-                                               JsonArray srcListArray = ruleListobj.getJsonArray("sourceList");
-                                               String srcListString = null;
-                                               for (int srcListIndex = 0; srcListIndex< srcListArray.size(); srcListIndex++) {
-                                                       JsonObject srcListObj = srcListArray.getJsonObject(srcListIndex);
-                                                       String type = srcListObj.get("type").toString().replace("\"", "");
-
-                                                       String value = null;
-                                                       if(type.equals("REFERENCE")||type.equals("GROUP")){
-                                                               value = srcListObj.get("name").toString();
-                                                       } else if (type.equalsIgnoreCase("ANY")){
-                                                               value = null;
-                                                       } else {
-                                                               value = srcListObj.get("value").toString();
-                                                       }
-
-                                                       if (value!=null){
-                                                               value = value.replace("\"", "");
-                                                       }
-
-                                                       if (srcListString != null) {
-                                                               srcListString = srcListString.concat(",").concat(value);
-
-                                                       } else {
-                                                               srcListString = value;
-                                                       }
-
-                                               }
-                                               String srcListInsert = "'"+srcListString+"'";
-
-                                               //getting destinationList Array fields from the firewallRulesList
-                                               JsonArray destListArray = ruleListobj.getJsonArray("destinationList");
-                                               String destListString = null;
-                                               for (int destListIndex = 0; destListIndex <destListArray.size(); destListIndex++) {
-                                                       JsonObject destListObj = destListArray.getJsonObject(destListIndex);
-                                                       String type = destListObj.get("type").toString().replace("\"", "");
-
-                                                       String value = null;
-                                                       if(type.equals("REFERENCE")||type.equals("GROUP")){
-                                                               value = destListObj.get("name").toString();
-                                                       } else if (type.equalsIgnoreCase("ANY")){
-                                                               value = null;
-                                                       } else {
-                                                               value = destListObj.get("value").toString();
-                                                       }
-
-                                                       if (value!=null){
-                                                               value = value.replace("\"", "");
-                                                       }
-
-                                                       if (destListString != null) {
-                                                               destListString = destListString.concat(",").concat(value);
-                                                       } else {
-                                                               destListString = value;
-                                                       }
-                                               }
-                                               String destListInsert = "'"+destListString+"'";
-
-                                               //getting destServices Array fields from the firewallRulesList
-                                               JsonArray destServicesArray = ruleListobj.getJsonArray("destServices");
-                                               String destPortListString = null;
-                                               for (int destPortListIndex = 0; destPortListIndex < destServicesArray.size(); destPortListIndex++) {
-                                                       JsonObject destServicesObj = destServicesArray.getJsonObject(destPortListIndex);
-                                                       String type = destServicesObj.get("type").toString().replace("\"", "");
-
-                                                       String value = null;
-                                                       if(type.equals("REFERENCE")||type.equals("GROUP")){
-                                                               value = destServicesObj.get("name").toString();
-                                                       } else if (type.equalsIgnoreCase("ANY")){
-                                                               value = null;
-                                                       } else {
-                                                               value = destServicesObj.get("value").toString();
-                                                       }
-
-                                                       if (value!=null){
-                                                               value = value.replace("\"", "");
-                                                       }
-
-                                                       if (destPortListString != null) {
-                                                               destPortListString = destPortListString.concat(",").concat(value);
-                                                       } else {
-                                                               destPortListString = value;
-                                                       }
-                                               }
-                                               String destPortListInsert = "'"+destPortListString+"'";                                 
-
-                                               /*
-                                                * Create Queries to INSERT data into database tables and execute 
-                                                */     
-                                               UserInfo userInfo = new UserInfo();
-                                               userInfo.setUserLoginId("API");
-                                               userInfo.setUserName("API");
-                                               
-                                               TermList termEntry = new TermList();
-                                               termEntry.setTermName(ruleName);
-                                               termEntry.setSrcIPList(srcListInsert);
-                                               termEntry.setDestIPList(destListInsert);
-                                               termEntry.setProtocolList("null");
-                                               termEntry.setPortList("null");
-                                               termEntry.setSrcPortList("null");
-                                               termEntry.setDestPortList(destPortListInsert);
-                                               termEntry.setAction(action);
-                                               termEntry.setDescription(description);
-                                               termEntry.setFromZones(fromZoneInsert);
-                                               termEntry.setToZones(toZoneInsert);
-                                               termEntry.setUserCreatedBy(userInfo);
-                                               dbConnection.save(termEntry);
-                                               
-                                               ActionList actionEntry = new ActionList();
-                                               actionEntry.setActionName(action);
-                                               actionEntry.setDescription(action);
-                                               dbConnection.save(actionEntry);
-                                       }
-                               }
-
-                               /*
-                                * Inserting serviceGroups data into the ServiceGroup, ServiceList, ProtocolList, and PortList tables
-                                */
-                               if (serviceGroup != null) {
-                                       for(int i = 0; i < serviceGroup.size() ; i++) {
-                                               /*
-                                                * Populate ArrayLists with values from the JSON
-                                                */
-                                               //create the JSON object from the JSON Array for each iteration through the for loop
-                                               JsonObject svcGroupListobj = serviceGroup.getJsonObject(i);
-
-                                               String serviceListName = svcGroupListobj.get("name").toString();
-                                               String description = null;
-                                               if (svcGroupListobj.containsKey("description")){
-                                                       description = svcGroupListobj.get("description").toString();
-                                               }
-
-                                               //getting members Array from the serviceGroup
-                                               JsonArray membersArray = svcGroupListobj.getJsonArray("members");
-
-                                               //String type = svcGroupListobj.get("type").toString();
-                                               Boolean isServiceGroup = false;
-                                               if (membersArray!=null){
-                                                       String membersType = membersArray.getJsonObject(0).get("type").toString();
-                                                       if (membersType.contains("REFERENCE")) {
-                                                               isServiceGroup = true;
-                                                       }
-                                               }
-
-                                               //Insert values into GROUPSERVICELIST table if name begins with Group 
-                                               if (isServiceGroup) {
-                                                       String name = null;
-                                                       for (int membersIndex = 0; membersIndex< membersArray.size(); membersIndex++) {
-                                                               JsonObject membersObj = membersArray.getJsonObject(membersIndex);
-                                                               //String value = membersObj.get("name").toString();
-                                                               String type = membersObj.get("type").toString().replace("\"", "");
-
-                                                               String value = null;
-                                                               if(type.equals("REFERENCE")||type.equals("GROUP")||type.equals("SERVICE")){
-                                                                       value = membersObj.get("name").toString();
-                                                               } else if (type.equalsIgnoreCase("ANY")){
-                                                                       value = null;
-                                                               } else {
-                                                                       value = membersObj.get("value").toString();
-                                                               }
-
-                                                               if(value != null){
-                                                                       value = value.replace("\"", "");
-                                                               }
-
-                                                               if (name != null) {
-                                                                       name = name.concat(",").concat(value);
-                                                               } else {
-                                                                       name = value;
-                                                               }
-                                                       }
-                                                       String nameInsert = "'"+name+"'";               
-                                                       GroupServiceList groupServiceEntry = new GroupServiceList();
-                                                       groupServiceEntry.setGroupName(serviceListName);
-                                                       groupServiceEntry.setServiceList(nameInsert);
-                                                       dbConnection.save(groupServiceEntry);
-                                               } else { //Insert JSON data serviceList table, protollist table, and portlist table
-                                                       String type = svcGroupListobj.get("type").toString();
-                                                       String transportProtocol = svcGroupListobj.get("transportProtocol").toString();
-                                                       String ports = svcGroupListobj.get("ports").toString();
-
-                                                       /*
-                                                        * Create Queries to INSERT data into database table and execute 
-                                                        */
-                                                       ServiceList serviceListEntry = new ServiceList();
-                                                       serviceListEntry.setServiceName(serviceListName);
-                                                       serviceListEntry.setServiceDescription(description);
-                                                       serviceListEntry.setServiceType(type);
-                                                       serviceListEntry.setServiceTransProtocol(transportProtocol);
-                                                       serviceListEntry.setServiceAppProtocol("null");
-                                                       serviceListEntry.setServicePorts(ports);
-                                                       dbConnection.save(serviceListEntry);
-                                                       
-                                                       ProtocolList protocolEntry = new ProtocolList();
-                                                       protocolEntry.setProtocolName(transportProtocol);
-                                                       protocolEntry.setDescription(transportProtocol);
-                                                       dbConnection.save(protocolEntry);
-                                                       
-                                                       PortList portListEntry = new PortList();
-                                                       portListEntry.setPortName(ports);
-                                                       portListEntry.setDescription(ports);
-                                                       dbConnection.save(portListEntry);
-                                               }
-                                       }
-                               }
-
-                               /*
-                                * Inserting addressGroup data into the ADDRESSGROUP table
-                                */
-                               if (addressGroup != null) {
-                                       for(int i = 0; i < addressGroup.size(); i++) {
-                                               /*
-                                                * Populate ArrayLists with values from the JSON
-                                                */
-                                               //create the JSON object from the JSON Array for each iteration through the for loop
-                                               JsonObject addressGroupObj = addressGroup.getJsonObject(i);
-
-                                               //create JSON array for members
-                                               JsonArray membersArray = addressGroupObj.getJsonArray("members");
-                                               String addressGroupName = addressGroupObj.get("name").toString();
-
-                                               String description = null;
-                                               if (addressGroupObj.containsKey("description")){
-                                                       description = addressGroupObj.get("description").toString();
-                                               }
-
-                                               String prefixIP = null;
-                                               String type = null;
-                                               for (int membersIndex = 0; membersIndex < membersArray.size(); membersIndex++) {
-                                                       JsonObject membersObj = membersArray.getJsonObject(membersIndex);
-                                                       //String value = membersObj.get("value").toString();
-                                                       type = membersObj.get("type").toString().replace("\"", "");
-
-                                                       String value = null;
-                                                       if(type.equals("REFERENCE")||type.equals("GROUP")||type.equals("SERVICE")){
-                                                               value = membersObj.get("name").toString();
-                                                       } else if (type.equalsIgnoreCase("ANY")){
-                                                               value = null;
-                                                       } else {
-                                                               value = membersObj.get("value").toString();
-                                                       }
-
-                                                       if(value != null){
-                                                               value = value.replace("\"", "");
-                                                       }
-
-                                                       if (prefixIP != null) {
-                                                               prefixIP = prefixIP.concat(",").concat(value);
-                                                       } else {
-                                                               prefixIP = value;
-                                                       }
-                                               }
-                                               String prefixList = "'"+prefixIP+"'";
-
-                                               Boolean isAddressGroup = type.contains("REFERENCE");
-
-                                               if (isAddressGroup) {                                                           
-                                                       AddressGroup addressGroupEntry = new AddressGroup();
-                                                       addressGroupEntry.setGroupName(addressGroupName);
-                                                       addressGroupEntry.setDescription(description);
-                                                       addressGroupEntry.setServiceList(prefixList);
-                                                       dbConnection.save(addressGroupEntry);
-                                               } else {
-                                                       PrefixList prefixListEntry = new PrefixList();
-                                                       prefixListEntry.setPrefixListName(addressGroupName);
-                                                       prefixListEntry.setDescription(description);
-                                                       prefixListEntry.setPrefixListValue(prefixList);
-                                                       dbConnection.save(prefixListEntry);
-                                               }
-                                       }
-                               }
-
-                               /*
-                                * Remove duplicate values from 'lookup' dictionary tables
-                                */
-                               //ProtocolList Table
-                               String protoDelete = "DELETE FROM protocollist USING protocollist, protocollist p1 "
-                                               + "WHERE protocollist.id > p1.id AND protocollist.protocolname = p1.protocolname;";
-                               dbConnection.updateQuery(protoDelete);
-
-                               //PortList Table
-                               String portListDelete = "DELETE FROM portlist USING portlist, portlist p1 "
-                                               + "WHERE portlist.id > p1.id AND portlist.portname = p1.portname; ";
-                               dbConnection.updateQuery(portListDelete);
-
-                               //PrefixList Table
-                               String prefixListDelete = "DELETE FROM prefixlist USING prefixlist, prefixlist p1 "
-                                               + "WHERE prefixlist.id > p1.id AND prefixlist.pl_name = p1.pl_name AND "
-                                               + "prefixlist.pl_value = p1.pl_value AND prefixlist.description = p1.description; ";
-                               dbConnection.updateQuery(prefixListDelete);
-
-                               //GroupServiceList
-                               String groupServiceDelete = "DELETE FROM groupservicelist USING groupservicelist, groupservicelist g1 "
-                                               + "WHERE groupservicelist.id > g1.id AND groupservicelist.name = g1.name AND "
-                                               + "groupservicelist.serviceList = g1.serviceList; ";
-                               dbConnection.updateQuery(groupServiceDelete);
-                       }catch (Exception e) {
-                               PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "FirewallConfigPolicy", "Exception getting Json values");
-                               return false;
-                       } 
-                       return true;
-
-               } else {
-                       return false;
-               }
-
-       }
-
-
-       private Boolean updateFirewallDictionaryData(String jsonBody, String prevJsonBody) {
-               CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
-               JsonObject oldJson = null;
-               JsonObject newJson = null;
-
-               if (jsonBody != null || prevJsonBody != null) {
-
-                       oldJson = stringToJson(prevJsonBody);
-                       newJson = stringToJson(jsonBody);
-
-                       //if no changes to the json then return true
-                       if (oldJson != null && oldJson.equals(newJson)) {
-                               return true;
-                       }
-
-                       JsonArray firewallRules = null;
-                       JsonArray serviceGroup = null;
-                       JsonArray addressGroup = null;
-
-                       firewallRules = newJson.getJsonArray("firewallRuleList");
-                       serviceGroup = newJson.getJsonArray("serviceGroups");
-                       addressGroup = newJson.getJsonArray("addressGroups");   
-
-                       //insert data into tables
-                       try {
-                               JsonNode jsonDiff = createPatch(jsonBody, prevJsonBody);
-
-                               for (int i = 0; i<jsonDiff.size(); i++) {
-                                       //String path = jsonDiff.get(i).asText();
-                                       String jsonpatch = jsonDiff.get(i).toString();
-
-                                       JsonObject patchObj = stringToJson(jsonpatch);
-
-                                       String path = patchObj.get("path").toString().replace('"', ' ').trim();
-
-                                       if (path.contains("firewallRuleList")) {
-                                               /*
-                                                * Inserting firewallRuleList data into the Terms, SecurityZone, and Action tables
-                                                */
-                                               for(int ri = 0; ri < firewallRules.size(); ri++) {
-                                                       /*
-                                                        * Populate ArrayLists with values from the JSON
-                                                        */
-                                                       //create the JSON object from the JSON Array for each iteration through the for loop
-                                                       JsonObject ruleListobj = firewallRules.getJsonObject(ri);
-
-                                                       //get values from JSON fields of firewallRulesList Array
-                                                       String ruleName = ruleListobj.get("ruleName").toString().replace('"', '\'');
-                                                       String action = ruleListobj.get("action").toString().replace('"', '\'');
-                                                       String description = ruleListobj.get("description").toString().replace('"', '\'');
-
-                                                       List<Object> result = dbConnection.getDataById(TermList.class, "termName", ruleName);
-                                                       if(result != null && !result.isEmpty()){
-                                                               TermList termEntry = (TermList) result.get(0);
-                                                               dbConnection.delete(termEntry);
-                                                       }
-
-                                                       //getting fromZone Array field from the firewallRulesList
-                                                       JsonArray fromZoneArray = ruleListobj.getJsonArray("fromZones");
-                                                       String fromZoneString = null;
-
-                                                       for (int fromZoneIndex = 0; fromZoneIndex<fromZoneArray.size() ; fromZoneIndex++) {
-                                                               String value = fromZoneArray.get(fromZoneIndex).toString();
-                                                               value = value.replace("\"", "");
-
-                                                               if (fromZoneString != null) {
-                                                                       fromZoneString = fromZoneString.concat(",").concat(value);
-
-                                                               } else {
-                                                                       fromZoneString = value;
-                                                               }
-
-                                                       }
-                                                       String fromZoneInsert = "'"+fromZoneString+"'";
-
-                                                       //getting toZone Array field from the firewallRulesList
-                                                       JsonArray toZoneArray = ruleListobj.getJsonArray("toZones");
-                                                       String toZoneString = null;
-
-
-                                                       for (int toZoneIndex = 0; toZoneIndex < toZoneArray.size(); toZoneIndex++) {
-                                                               String value = toZoneArray.get(toZoneIndex).toString();
-                                                               value = value.replace("\"", "");
-
-                                                               if (toZoneString != null) {
-                                                                       toZoneString = toZoneString.concat(",").concat(value);
-
-                                                               } else {
-                                                                       toZoneString = value;
-                                                               }
-
-                                                       }
-                                                       String toZoneInsert = "'"+toZoneString+"'";
-                                                       //getting sourceList Array fields from the firewallRulesList
-                                                       JsonArray srcListArray = ruleListobj.getJsonArray("sourceList");
-                                                       String srcListString = null;
-                                                       for (int srcListIndex = 0; srcListIndex<srcListArray.size(); srcListIndex++) {
-                                                               JsonObject srcListObj = srcListArray.getJsonObject(srcListIndex);
-                                                               String type = srcListObj.get("type").toString().replace("\"", "");
-
-                                                               String value = null;
-                                                               if(type.equals("REFERENCE")||type.equals("GROUP")){
-                                                                       value = srcListObj.get("name").toString();
-                                                               } else if (type.equalsIgnoreCase("ANY")){
-                                                                       value = null;
-                                                               } else {
-                                                                       value = srcListObj.get("value").toString();
-                                                               }
-
-                                                               if(value != null){
-                                                                       value = value.replace("\"", "");
-                                                               }
-
-                                                               if (srcListString != null) {
-                                                                       srcListString = srcListString.concat(",").concat(value);
-
-                                                               } else {
-                                                                       srcListString = value;
-                                                               }
-
-                                                       }
-                                                       String srcListInsert = "'"+srcListString+"'";
-
-                                                       //getting destinationList Array fields from the firewallRulesList
-                                                       JsonArray destListArray = ruleListobj.getJsonArray("destinationList");
-                                                       String destListString = null;
-                                                       for (int destListIndex = 0; destListIndex<destListArray.size(); destListIndex ++) {
-                                                               JsonObject destListObj = destListArray.getJsonObject(destListIndex);
-                                                               String type = destListObj.get("type").toString().replace("\"", "");
-
-                                                               String value = null;
-                                                               if(type.equals("REFERENCE")||type.equals("GROUP")){
-                                                                       value = destListObj.get("name").toString();
-                                                               } else if (type.equalsIgnoreCase("ANY")){
-                                                                       value = null;
-                                                               } else {
-                                                                       value = destListObj.get("value").toString();
-                                                               }
-
-                                                               if(value != null){
-                                                                       value = value.replace("\"", "");
-                                                               }
-
-                                                               if (destListString != null) {
-                                                                       destListString = destListString.concat(",").concat(value);
-                                                               } else {
-                                                                       destListString = value;
-                                                               }
-                                                       }
-                                                       String destListInsert = "'"+destListString+"'";
-
-                                                       //getting destServices Array fields from the firewallRulesList
-                                                       JsonArray destServicesArray = ruleListobj.getJsonArray("destServices");
-                                                       String destPortListString = null;
-                                                       for (int destPortListIndex = 0; destPortListIndex < destServicesArray.size(); destPortListIndex++) {
-                                                               JsonObject destServicesObj = destServicesArray.getJsonObject(destPortListIndex);
-                                                               String type = destServicesObj.get("type").toString().replace("\"", "");
-
-                                                               String value = null;
-                                                               if(type.equals("REFERENCE")||type.equals("GROUP")){
-                                                                       value = destServicesObj.get("name").toString();
-                                                               } else if (type.equalsIgnoreCase("ANY")){
-                                                                       value = null;
-                                                               } else {
-                                                                       value = destServicesObj.get("value").toString();
-                                                               }
-
-                                                               if(value != null){
-                                                                       value = value.replace("\"", "");
-                                                               }
-
-                                                               if (destPortListString != null) {
-                                                                       destPortListString = destPortListString.concat(",").concat(value);
-                                                               } else {
-                                                                       destPortListString = value;
-                                                               }
-                                                       }
-                                                       String destPortListInsert = "'"+destPortListString+"'";                                 
-
-                                                       /*
-                                                        * Create Queries to INSERT data into database tables and execute 
-                                                        */
-                                                       UserInfo userInfo = new UserInfo();
-                                                       userInfo.setUserLoginId("API");
-                                                       userInfo.setUserName("API");
-                                                       
-                                                       TermList termEntry = new TermList();
-                                                       termEntry.setTermName(ruleName);
-                                                       termEntry.setSrcIPList(srcListInsert);
-                                                       termEntry.setDestIPList(destListInsert);
-                                                       termEntry.setProtocolList("null");
-                                                       termEntry.setPortList("null");
-                                                       termEntry.setSrcPortList("null");
-                                                       termEntry.setDestPortList(destPortListInsert);
-                                                       termEntry.setAction(action);
-                                                       termEntry.setDescription(description);
-                                                       termEntry.setFromZones(fromZoneInsert);
-                                                       termEntry.setToZones(toZoneInsert);
-                                                       termEntry.setUserCreatedBy(userInfo);
-                                                       dbConnection.save(termEntry);
-                                                       
-                                                       List<Object> actionResult = dbConnection.getDataById(ActionList.class, "actionName", action);
-                                                       if(actionResult == null || actionResult.isEmpty()){
-                                                               ActionList actionEntry = new ActionList();
-                                                               actionEntry.setActionName(action);
-                                                               actionEntry.setDescription(action);
-                                                               dbConnection.save(actionEntry); 
-                                                       }
-                                               }
-                                       }
-
-                                       if (path.contains("serviceGroups")) {
-                                               /*
-                                                * Inserting serviceGroups data into the ServiceGroup, ServiceList, ProtocolList, and PortList tables
-                                                */
-                                               for(int si = 0; si < serviceGroup.size(); si++) {
-                                                       /*
-                                                        * Populate ArrayLists with values from the JSON
-                                                        */
-                                                       //create the JSON object from the JSON Array for each iteration through the for loop
-                                                       JsonObject svcGroupListobj = serviceGroup.getJsonObject(si);
-
-                                                       String groupName = svcGroupListobj.get("name").toString().replace('"', '\''); 
-
-                                                       String description = null;
-                                                       if (svcGroupListobj.containsKey("description")){
-                                                               description = svcGroupListobj.get("description").toString().replace('"', '\'');
-                                                       }
-
-                                                       JsonArray membersArray = svcGroupListobj.getJsonArray("members");
-
-                                                       Boolean isServiceGroup = false;
-                                                       if (membersArray!=null){
-                                                               String membersType = membersArray.getJsonObject(0).get("type").toString();
-                                                               if (membersType.contains("REFERENCE")) {
-                                                                       isServiceGroup = true;
-                                                               }
-                                                       }
-
-                                                       //Insert values into GROUPSERVICELIST table if name begins with Group 
-                                                       if (isServiceGroup) {
-                                                               List<Object> result = dbConnection.getDataById(GroupServiceList.class, "name", groupName);
-                                                               if(result != null && !result.isEmpty()){
-                                                                       GroupServiceList groupEntry = (GroupServiceList) result.get(0);
-                                                                       dbConnection.delete(groupEntry);
-                                                               }
-                       
-                                                               String name = null;
-                                                               for (int membersIndex = 0; membersIndex < membersArray.size(); membersIndex++) {
-                                                                       JsonObject membersObj = membersArray.getJsonObject(membersIndex);
-                                                                       String type = membersObj.get("type").toString().replace("\"", "");
-
-                                                                       String value = null;
-                                                                       if(type.equals("REFERENCE")||type.equals("GROUP")||type.equals("SERVICE")){
-                                                                               value = membersObj.get("name").toString();
-                                                                       } else if (type.equalsIgnoreCase("ANY")){
-                                                                               value = null;
-                                                                       } else {
-                                                                               value = membersObj.get("value").toString();
-                                                                       }
-
-                                                                       if(value != null){
-                                                                               value = value.replace("\"", "");
-                                                                       }
-
-                                                                       if (name != null) {
-                                                                               name = name.concat(",").concat(value);
-                                                                       } else {
-                                                                               name = value;
-                                                                       }
-                                                               }
-                                                               String nameInsert = "'"+name+"'";       
-                                                               GroupServiceList groupServiceEntry = new GroupServiceList();
-                                                               groupServiceEntry.setGroupName(groupName);
-                                                               groupServiceEntry.setServiceList(nameInsert);
-                                                               dbConnection.save(groupServiceEntry);
-                                                       } else { //Insert JSON data serviceGroup table, protocollist table, and portlist table
-                                                               String type = svcGroupListobj.get("type").toString().replace('"', '\'');
-                                                               String transportProtocol = svcGroupListobj.get("transportProtocol").toString().replace('"', '\'');
-                                                               String ports = svcGroupListobj.get("ports").toString().replace('"', '\'');
-                                                               
-                                                               List<Object> result = dbConnection.getDataById(ServiceList.class, "name", groupName);
-                                                               if(result != null && !result.isEmpty()){
-                                                                       ServiceList serviceEntry = (ServiceList) result.get(0);
-                                                                       dbConnection.delete(serviceEntry);
-                                                               }
-                                                               
-                                                               ServiceList serviceListEntry = new ServiceList();
-                                                               serviceListEntry.setServiceName(groupName);
-                                                               serviceListEntry.setServiceDescription(description);
-                                                               serviceListEntry.setServiceType(type);
-                                                               serviceListEntry.setServiceTransProtocol(transportProtocol);
-                                                               serviceListEntry.setServiceAppProtocol("null");
-                                                               serviceListEntry.setServicePorts(ports);
-                                                               dbConnection.save(serviceListEntry);
-                                                               
-                                                               List<Object> protocolResult = dbConnection.getDataById(ProtocolList.class, "protocolName", transportProtocol);
-                                                               if(protocolResult == null || protocolResult.isEmpty()){
-                                                                       ProtocolList protocolEntry = new ProtocolList();
-                                                                       protocolEntry.setProtocolName(transportProtocol);
-                                                                       protocolEntry.setDescription(transportProtocol);
-                                                                       dbConnection.save(protocolEntry);
-                                                               }
-                                                               
-                                                               List<Object> portResult = dbConnection.getDataById(PortList.class, "portName", ports);
-                                                               if(portResult == null || portResult.isEmpty()){
-                                                                       PortList portEntry = new PortList();
-                                                                       portEntry.setPortName(ports);
-                                                                       portEntry.setDescription(ports);
-                                                                       dbConnection.save(portEntry);
-                                                               }
-                                                       }
-                                               }
-                                       }
-
-                                       if (path.contains("addressGroups")) {
-                                               /*
-                                                * Inserting addressGroup data into the ADDRESSGROUP table
-                                                */
-                                               for(int ai=0; ai < addressGroup.size() ; ai++) {
-
-                                                       /*
-                                                        * Populate ArrayLists with values from the JSON
-                                                        */
-                                                       //create the JSON object from the JSON Array for each iteration through the for loop
-                                                       JsonObject addressGroupObj = addressGroup.getJsonObject(ai);
-
-                                                       //create JSON array for members
-                                                       JsonArray membersArray = addressGroupObj.getJsonArray("members");
-                                                       String addressGroupName = addressGroupObj.get("name").toString().replace('"', '\'');
-
-                                                       String description = null;
-                                                       if (addressGroupObj.containsKey("description")){
-                                                               description = addressGroupObj.get("description").toString().replace('"', '\'');
-                                                       }
-
-                                                       String prefixIP = null;
-                                                       String type = null;
-                                                       for (int membersIndex=0; membersIndex < membersArray.size(); membersIndex++) {
-                                                               JsonObject membersObj = membersArray.getJsonObject(membersIndex);
-                                                               type = membersObj.get("type").toString().replace("\"", "");
-
-                                                               String value = null;
-                                                               if(type.equals("REFERENCE")||type.equals("GROUP")||type.equals("SERVICE")){
-                                                                       value = membersObj.get("name").toString();
-                                                               } else if (type.equalsIgnoreCase("ANY")){
-                                                                       value = null;
-                                                               } else {
-                                                                       value = membersObj.get("value").toString();
-                                                               }
-
-                                                               if(value != null){
-                                                                       value = value.replace("\"", "");
-                                                               }
-
-                                                               if (prefixIP != null) {
-                                                                       prefixIP = prefixIP.concat(",").concat(value);
-                                                               } else {
-                                                                       prefixIP = value;
-                                                               }
-                                                       }
-                                                       
-                                                       String prefixList = "'"+prefixIP+"'";
-                                                       Boolean isAddressGroup = type.contains("REFERENCE");
-
-                                                       if (isAddressGroup) {   
-                                                               List<Object> result = dbConnection.getDataById(AddressGroup.class, "name", addressGroupName);
-                                                               if(result != null && !result.isEmpty()){
-                                                                       AddressGroup addressGroupEntry = (AddressGroup) result.get(0);
-                                                                       dbConnection.delete(addressGroupEntry);
-                                                               }
-                                                               AddressGroup newAddressGroup = new AddressGroup();
-                                                               newAddressGroup.setGroupName(addressGroupName);
-                                                               newAddressGroup.setDescription(description);
-                                                               newAddressGroup.setServiceList(prefixList);
-                                                               dbConnection.save(newAddressGroup);
-                                                       } else {
-                                                               List<Object> result = dbConnection.getDataById(PrefixList.class, "prefixListName", addressGroupName);
-                                                               if(result != null && !result.isEmpty()){
-                                                                       PrefixList prefixListEntry = (PrefixList) result.get(0);
-                                                                       dbConnection.delete(prefixListEntry);
-                                                               }
-                                                               PrefixList newPrefixList = new PrefixList();
-                                                               newPrefixList.setPrefixListName(addressGroupName);
-                                                               newPrefixList.setDescription(description);
-                                                               newPrefixList.setPrefixListValue(prefixList);
-                                                               dbConnection.save(newPrefixList);
-                                                       }
-                                               }                                               
-                                       }
-                               }
-
-                               /*
-                                * Remove duplicate values from 'lookup' dictionary tables
-                                */
-                               //ProtocolList Table
-                               String protoDelete = "DELETE FROM protocollist USING protocollist, protocollist p1 "
-                                               + "WHERE protocollist.id > p1.id AND protocollist.protocolname = p1.protocolname;";
-                               dbConnection.updateQuery(protoDelete);
-
-                               //PortList Table
-                               String portListDelete = "DELETE FROM portlist USING portlist, portlist p1 "
-                                               + "WHERE portlist.id > p1.id AND portlist.portname = p1.portname; ";
-                               dbConnection.updateQuery(portListDelete);
-
-                               //PrefixList Table
-                               String prefixListDelete = "DELETE FROM prefixlist USING prefixlist, prefixlist p1 "
-                                               + "WHERE prefixlist.id > p1.id AND prefixlist.pl_name = p1.pl_name AND "
-                                               + "prefixlist.pl_value = p1.pl_value AND prefixlist.description = p1.description; ";
-                               dbConnection.updateQuery(prefixListDelete);
-
-                               //GroupServiceList
-                               String groupServiceDelete = "DELETE FROM groupservicelist USING groupservicelist, groupservicelist g1 "
-                                               + "WHERE groupservicelist.id > g1.id AND groupservicelist.name = g1.name AND "
-                                               + "groupservicelist.serviceList = g1.serviceList; ";
-                               dbConnection.updateQuery(groupServiceDelete);
-                       }catch (Exception e) {
-                               PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "FirewallConfigPolicy", "Exception executing Firewall queries");
-                               return false;
-                       }
-                       return true;
-               } else {
-                       return false;
-               }
-
-       }
-
-       private JsonObject stringToJson(String jsonString) {
-               //Read jsonBody to JsonObject
-               StringReader in = new StringReader(jsonString);
-               JsonReader jsonReader = Json.createReader(in);
-               JsonObject json = jsonReader.readObject();
-               jsonReader.close();
-               return json;
-       }
-
-       private JsonNode createPatch(String json, String oldJson) {
-               JsonNode oldJason = null;
-               JsonNode updatedJason = null;
-
-               try {
-                       oldJason = JsonLoader.fromString(oldJson);
-                       updatedJason = JsonLoader.fromString(json);
-               } catch (IOException e) {
-                       LOGGER.error("Exception Occured"+e);
-               }
-               return JsonDiff.asJson(oldJason, updatedJason);
-       }
-
-       @Override
-       public Object getCorrectPolicyDataObject() {
-               return policyAdapter.getPolicyData();
-       }
+            }
+        } else {
+            dbIsUpdated = true;
+        }
+
+        if(dbIsUpdated) {
+            successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());
+        } else {
+            PolicyLogger.error("Failed to Update the Database Dictionary Tables.");
+
+            //remove the new json file
+            String jsonBody = policyAdapter.getPrevJsonBody();
+            if (jsonBody!=null){
+                saveConfigurations(policyName, jsonBody);
+            } else {
+                saveConfigurations(policyName, "");
+            }
+            successMap.put("fwdberror", "DB UPDATE");
+        }
+
+        return successMap;
+    }
+
+    //This is the method for preparing the policy for saving.  We have broken it out
+    //separately because the fully configured policy is used for multiple things
+    @Override
+    public boolean prepareToSave() throws PAPException{
+
+        if(isPreparedToSave()){
+            //we have already done this
+            return true;
+        }
+
+        int version = 0;
+        String policyID = policyAdapter.getPolicyID();
+        version = policyAdapter.getHighestVersion();
+
+        // Create the Instance for pojo, PolicyType object is used in marshaling.
+        if ("Config".equals(policyAdapter.getPolicyType())) {
+            PolicyType policyConfig = new PolicyType();
+
+            policyConfig.setVersion(Integer.toString(version));
+            policyConfig.setPolicyId(policyID);
+            policyConfig.setTarget(new TargetType());
+            policyAdapter.setData(policyConfig);
+        }
+        policyName = policyAdapter.getNewFileName();
+
+        //String oldPolicyName = policyName.replace(".xml", "");
+        String scope = policyName.substring(0, policyName.indexOf('.'));
+        String dbPolicyName = policyName.substring(policyName.indexOf('.')+1).replace(".xml", "");
+
+        int oldversion = Integer.parseInt(dbPolicyName.substring(dbPolicyName.lastIndexOf('.')+1));
+        dbPolicyName = dbPolicyName.substring(0, dbPolicyName.lastIndexOf('.')+1);
+        if(oldversion > 1){
+            oldversion = oldversion - 1;
+            dbPolicyName = dbPolicyName + oldversion + ".xml";
+        }
+        EntityManager em = XACMLPapServlet.getEmf().createEntityManager();
+        Query createPolicyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:policyName");
+        createPolicyQuery.setParameter("scope", scope);
+        createPolicyQuery.setParameter("policyName", dbPolicyName);
+        List<?> createPolicyQueryList = createPolicyQuery.getResultList();
+        if(!createPolicyQueryList.isEmpty()){
+            PolicyEntity entitydata = (PolicyEntity) createPolicyQueryList.get(0);
+            policyAdapter.setPrevJsonBody(entitydata.getConfigurationData().getConfigBody());
+        }
+        em.close();
+        if (policyAdapter.getData() != null) {
+            String jsonBody = policyAdapter.getJsonBody();
+            saveConfigurations(policyName, jsonBody);
+
+            // Make sure the filename ends with an extension
+            if (!policyName.endsWith(".xml")) {
+                policyName = policyName + ".xml";
+            }
+
+            PolicyType configPolicy = (PolicyType) policyAdapter.getData();
+
+            configPolicy.setDescription(policyAdapter.getPolicyDescription());
+
+            configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
+
+            AllOfType allOfOne = new AllOfType();
+            String fileName = policyAdapter.getNewFileName();
+            String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length());
+            if ((name == null) || (name.equals(""))) {
+                name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
+            }
+            allOfOne.getMatch().add(createMatch("PolicyName", name));
+            AllOfType allOf = new AllOfType();
+
+            // Match for ConfigName
+            allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
+            // Match for riskType
+            allOf.getMatch().add(createDynamicMatch("RiskType", policyAdapter.getRiskType()));
+            // Match for riskLevel
+            allOf.getMatch().add(createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
+            // Match for riskguard
+            allOf.getMatch().add(createDynamicMatch("guard", policyAdapter.getGuard()));
+            // Match for ttlDate
+            allOf.getMatch().add(createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
+            AnyOfType anyOf = new AnyOfType();
+            anyOf.getAllOf().add(allOfOne);
+            anyOf.getAllOf().add(allOf);
+
+            TargetType target = new TargetType();
+            target.getAnyOf().add(anyOf);
+
+            // Adding the target to the policy element
+            configPolicy.setTarget((TargetType) target);
+
+            RuleType rule = new RuleType();
+            rule.setRuleId(policyAdapter.getRuleID());
+            rule.setEffect(EffectType.PERMIT);
+
+            // Create Target in Rule
+            AllOfType allOfInRule = new AllOfType();
+
+            // Creating match for ACCESS in rule target
+            MatchType accessMatch = new MatchType();
+            AttributeValueType accessAttributeValue = new AttributeValueType();
+            accessAttributeValue.setDataType(STRING_DATATYPE);
+            accessAttributeValue.getContent().add("ACCESS");
+            accessMatch.setAttributeValue(accessAttributeValue);
+            AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
+            URI accessURI = null;
+            try {
+                accessURI = new URI(ACTION_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "FirewallConfigPolicy", "Exception creating ACCESS URI");
+            }
+            accessAttributeDesignator.setCategory(CATEGORY_ACTION);
+            accessAttributeDesignator.setDataType(STRING_DATATYPE);
+            accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
+            accessMatch.setAttributeDesignator(accessAttributeDesignator);
+            accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            // Creating Config Match in rule Target
+            MatchType configMatch = new MatchType();
+            AttributeValueType configAttributeValue = new AttributeValueType();
+            configAttributeValue.setDataType(STRING_DATATYPE);
+
+            configAttributeValue.getContent().add("Config");
+
+            configMatch.setAttributeValue(configAttributeValue);
+            AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
+            URI configURI = null;
+            try {
+                configURI = new URI(RESOURCE_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "FirewallConfigPolicy", "Exception creating Config URI");
+            }
+
+            configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
+            configAttributeDesignator.setDataType(STRING_DATATYPE);
+            configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
+            configMatch.setAttributeDesignator(configAttributeDesignator);
+            configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            allOfInRule.getMatch().add(accessMatch);
+            allOfInRule.getMatch().add(configMatch);
+
+            AnyOfType anyOfInRule = new AnyOfType();
+            anyOfInRule.getAllOf().add(allOfInRule);
+
+            TargetType targetInRule = new TargetType();
+            targetInRule.getAnyOf().add(anyOfInRule);
+
+            rule.setTarget(targetInRule);
+            rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
+
+            configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
+            policyAdapter.setPolicyData(configPolicy);
+
+        } else {
+            PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
+        }
+        setPreparedToSave(true);
+        return true;
+    }
+
+    // Data required for Advice part is setting here.
+    private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
+
+        //Firewall Config ID Assignment
+        AdviceExpressionsType advices = new AdviceExpressionsType();
+        AdviceExpressionType advice = new AdviceExpressionType();
+        advice.setAdviceId("firewallConfigID");
+        advice.setAppliesTo(EffectType.PERMIT);
+        // For Configuration
+        AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
+        assignment1.setAttributeId("type");
+        assignment1.setCategory(CATEGORY_RESOURCE);
+        assignment1.setIssuer("");
+        AttributeValueType configNameAttributeValue = new AttributeValueType();
+        configNameAttributeValue.setDataType(STRING_DATATYPE);
+        configNameAttributeValue.getContent().add("Configuration");
+        assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
+        advice.getAttributeAssignmentExpression().add(assignment1);
+
+        // For Config file Url if configurations are provided.
+        //URL ID Assignment
+        AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
+        assignment2.setAttributeId("URLID");
+        assignment2.setCategory(CATEGORY_RESOURCE);
+        assignment2.setIssuer("");
+        AttributeValueType AttributeValue = new AttributeValueType();
+        AttributeValue.setDataType(URI_DATATYPE);
+        if (policyName.endsWith(".xml")) {
+            policyName = policyName.substring(0, policyName.lastIndexOf(".xml"));
+        }
+        String content = CONFIG_URL + "/Config/" + policyName + ".json";
+
+        AttributeValue.getContent().add(content);
+        assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue));
+        advice.getAttributeAssignmentExpression().add(assignment2);
+
+        //Policy Name Assignment
+        AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
+        assignment3.setAttributeId("PolicyName");
+        assignment3.setCategory(CATEGORY_RESOURCE);
+        assignment3.setIssuer("");
+        AttributeValueType attributeValue3 = new AttributeValueType();
+        attributeValue3.setDataType(STRING_DATATYPE);
+        fileName = FilenameUtils.removeExtension(fileName);
+        fileName = fileName + ".xml";
+        String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
+        if ((name == null) || (name.equals(""))) {
+            name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
+        }
+        attributeValue3.getContent().add(name);
+        assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
+        advice.getAttributeAssignmentExpression().add(assignment3);
+
+        //Version Number Assignment
+        AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
+        assignment4.setAttributeId("VersionNumber");
+        assignment4.setCategory(CATEGORY_RESOURCE);
+        assignment4.setIssuer("");
+        AttributeValueType configNameAttributeValue4 = new AttributeValueType();
+        configNameAttributeValue4.setDataType(STRING_DATATYPE);
+        configNameAttributeValue4.getContent().add(Integer.toString(version));
+        assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
+        advice.getAttributeAssignmentExpression().add(assignment4);
+
+        //Onap Name Assignment
+        AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
+        assignment5.setAttributeId("matching:" + ONAPID);
+        assignment5.setCategory(CATEGORY_RESOURCE);
+        assignment5.setIssuer("");
+        AttributeValueType configNameAttributeValue5 = new AttributeValueType();
+        configNameAttributeValue5.setDataType(STRING_DATATYPE);
+        assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
+        advice.getAttributeAssignmentExpression().add(assignment5);
+
+        //Config Name Assignment
+        AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
+        assignment6.setAttributeId("matching:" + CONFIGID);
+        assignment6.setCategory(CATEGORY_RESOURCE);
+        assignment6.setIssuer("");
+        AttributeValueType configNameAttributeValue6 = new AttributeValueType();
+        configNameAttributeValue6.setDataType(STRING_DATATYPE);
+        configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
+        assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
+        advice.getAttributeAssignmentExpression().add(assignment6);
+
+        //Risk Attributes
+        AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
+        assignment7.setAttributeId("RiskType");
+        assignment7.setCategory(CATEGORY_RESOURCE);
+        assignment7.setIssuer("");
+
+        AttributeValueType configNameAttributeValue7 = new AttributeValueType();
+        configNameAttributeValue7.setDataType(STRING_DATATYPE);
+        configNameAttributeValue7.getContent().add(policyAdapter.getRiskType());
+        assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
+
+        advice.getAttributeAssignmentExpression().add(assignment7);
+
+        AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
+        assignment8.setAttributeId("RiskLevel");
+        assignment8.setCategory(CATEGORY_RESOURCE);
+        assignment8.setIssuer("");
+
+        AttributeValueType configNameAttributeValue8 = new AttributeValueType();
+        configNameAttributeValue8.setDataType(STRING_DATATYPE);
+        configNameAttributeValue8.getContent().add(policyAdapter.getRiskLevel());
+        assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
+
+        advice.getAttributeAssignmentExpression().add(assignment8);
+
+        AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
+        assignment9.setAttributeId("guard");
+        assignment9.setCategory(CATEGORY_RESOURCE);
+        assignment9.setIssuer("");
+
+        AttributeValueType configNameAttributeValue9 = new AttributeValueType();
+        configNameAttributeValue9.setDataType(STRING_DATATYPE);
+        configNameAttributeValue9.getContent().add(policyAdapter.getGuard());
+        assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
+
+        advice.getAttributeAssignmentExpression().add(assignment9);
+
+        AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
+        assignment10.setAttributeId("TTLDate");
+        assignment10.setCategory(CATEGORY_RESOURCE);
+        assignment10.setIssuer("");
+
+        AttributeValueType configNameAttributeValue10 = new AttributeValueType();
+        configNameAttributeValue10.setDataType(STRING_DATATYPE);
+        configNameAttributeValue10.getContent().add(policyAdapter.getTtlDate());
+        assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
+
+        advice.getAttributeAssignmentExpression().add(assignment10);
+        advices.getAdviceExpression().add(advice);
+        return advices;
+    }
+
+
+    private Boolean insertFirewallDicionaryData (String jsonBody) throws SQLException {
+        CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
+        JsonObject json = null;
+        if (jsonBody != null) {
+
+            //Read jsonBody to JsonObject
+            json = stringToJson(jsonBody);
+
+            JsonArray firewallRules = null;
+            JsonArray serviceGroup = null;
+            JsonArray addressGroup = null;
+            //insert data into tables
+            try {
+                firewallRules = json.getJsonArray("firewallRuleList");
+                serviceGroup = json.getJsonArray("serviceGroups");
+                addressGroup = json.getJsonArray("addressGroups");
+                /*
+                 * Inserting firewallRuleList data into the Terms, SecurityZone, and Action tables
+                 */
+                if (firewallRules != null) {
+                    for(int i = 0;i<firewallRules.size();i++) {
+                        /*
+                         * Populate ArrayLists with values from the JSON
+                         */
+                        //create the JSON object from the JSON Array for each iteration through the for loop
+                        JsonObject ruleListobj = firewallRules.getJsonObject(i);
+
+                        //get values from JSON fields of firewallRulesList Array
+                        String ruleName = ruleListobj.get("ruleName").toString();
+                        String action = ruleListobj.get("action").toString();
+                        String description = ruleListobj.get("description").toString();
+                        List<Object> result = dbConnection.getDataById(TermList.class, "termName", ruleName);
+                        if(result != null && !result.isEmpty()){
+                            TermList termEntry = (TermList) result.get(0);
+                            dbConnection.delete(termEntry);
+                        }
+
+                        //getting fromZone Array field from the firewallRulesList
+                        JsonArray fromZoneArray = ruleListobj.getJsonArray("fromZones");
+                        String fromZoneString = null;
+
+                        for (int fromZoneIndex = 0;fromZoneIndex<fromZoneArray.size(); fromZoneIndex++) {
+                            String value = fromZoneArray.get(fromZoneIndex).toString();
+                            value = value.replace("\"", "");
+                            if (fromZoneString != null) {
+                                fromZoneString = fromZoneString.concat(",").concat(value);
+                            } else {
+                                fromZoneString = value;
+                            }
+                        }
+                        String fromZoneInsert = "'"+fromZoneString+"'";
+
+                        //getting toZone Array field from the firewallRulesList
+                        JsonArray toZoneArray = ruleListobj.getJsonArray("toZones");
+                        String toZoneString = null;
+                        for (int toZoneIndex = 0; toZoneIndex<toZoneArray.size(); toZoneIndex++) {
+                            String value = toZoneArray.get(toZoneIndex).toString();
+                            value = value.replace("\"", "");
+                            if (toZoneString != null) {
+                                toZoneString = toZoneString.concat(",").concat(value);
+                            } else {
+                                toZoneString = value;
+                            }
+                        }
+                        String toZoneInsert = "'"+toZoneString+"'";
+
+                        //getting sourceList Array fields from the firewallRulesList
+                        JsonArray srcListArray = ruleListobj.getJsonArray("sourceList");
+                        String srcListString = null;
+                        for (int srcListIndex = 0; srcListIndex< srcListArray.size(); srcListIndex++) {
+                            JsonObject srcListObj = srcListArray.getJsonObject(srcListIndex);
+                            String type = srcListObj.get("type").toString().replace("\"", "");
+
+                            String value = null;
+                            if(type.equals("REFERENCE")||type.equals("GROUP")){
+                                value = srcListObj.get("name").toString();
+                            } else if (type.equalsIgnoreCase("ANY")){
+                                value = null;
+                            } else {
+                                value = srcListObj.get("value").toString();
+                            }
+
+                            if (value!=null){
+                                value = value.replace("\"", "");
+                            }
+
+                            if (srcListString != null) {
+                                srcListString = srcListString.concat(",").concat(value);
+
+                            } else {
+                                srcListString = value;
+                            }
+
+                        }
+                        String srcListInsert = "'"+srcListString+"'";
+
+                        //getting destinationList Array fields from the firewallRulesList
+                        JsonArray destListArray = ruleListobj.getJsonArray("destinationList");
+                        String destListString = null;
+                        for (int destListIndex = 0; destListIndex <destListArray.size(); destListIndex++) {
+                            JsonObject destListObj = destListArray.getJsonObject(destListIndex);
+                            String type = destListObj.get("type").toString().replace("\"", "");
+
+                            String value = null;
+                            if(type.equals("REFERENCE")||type.equals("GROUP")){
+                                value = destListObj.get("name").toString();
+                            } else if (type.equalsIgnoreCase("ANY")){
+                                value = null;
+                            } else {
+                                value = destListObj.get("value").toString();
+                            }
+
+                            if (value!=null){
+                                value = value.replace("\"", "");
+                            }
+
+                            if (destListString != null) {
+                                destListString = destListString.concat(",").concat(value);
+                            } else {
+                                destListString = value;
+                            }
+                        }
+                        String destListInsert = "'"+destListString+"'";
+
+                        //getting destServices Array fields from the firewallRulesList
+                        JsonArray destServicesArray = ruleListobj.getJsonArray("destServices");
+                        String destPortListString = null;
+                        for (int destPortListIndex = 0; destPortListIndex < destServicesArray.size(); destPortListIndex++) {
+                            JsonObject destServicesObj = destServicesArray.getJsonObject(destPortListIndex);
+                            String type = destServicesObj.get("type").toString().replace("\"", "");
+
+                            String value = null;
+                            if(type.equals("REFERENCE")||type.equals("GROUP")){
+                                value = destServicesObj.get("name").toString();
+                            } else if (type.equalsIgnoreCase("ANY")){
+                                value = null;
+                            } else {
+                                value = destServicesObj.get("value").toString();
+                            }
+
+                            if (value!=null){
+                                value = value.replace("\"", "");
+                            }
+
+                            if (destPortListString != null) {
+                                destPortListString = destPortListString.concat(",").concat(value);
+                            } else {
+                                destPortListString = value;
+                            }
+                        }
+                        String destPortListInsert = "'"+destPortListString+"'";
+
+                        /*
+                         * Create Queries to INSERT data into database tables and execute
+                         */
+                        UserInfo userInfo = new UserInfo();
+                        userInfo.setUserLoginId("API");
+                        userInfo.setUserName("API");
+
+                        TermList termEntry = new TermList();
+                        termEntry.setTermName(ruleName);
+                        termEntry.setSrcIPList(srcListInsert);
+                        termEntry.setDestIPList(destListInsert);
+                        termEntry.setProtocolList("null");
+                        termEntry.setPortList("null");
+                        termEntry.setSrcPortList("null");
+                        termEntry.setDestPortList(destPortListInsert);
+                        termEntry.setAction(action);
+                        termEntry.setDescription(description);
+                        termEntry.setFromZones(fromZoneInsert);
+                        termEntry.setToZones(toZoneInsert);
+                        termEntry.setUserCreatedBy(userInfo);
+                        dbConnection.save(termEntry);
+
+                        ActionList actionEntry = new ActionList();
+                        actionEntry.setActionName(action);
+                        actionEntry.setDescription(action);
+                        dbConnection.save(actionEntry);
+                    }
+                }
+
+                /*
+                 * Inserting serviceGroups data into the ServiceGroup, ServiceList, ProtocolList, and PortList tables
+                 */
+                if (serviceGroup != null) {
+                    for(int i = 0; i < serviceGroup.size() ; i++) {
+                        /*
+                         * Populate ArrayLists with values from the JSON
+                         */
+                        //create the JSON object from the JSON Array for each iteration through the for loop
+                        JsonObject svcGroupListobj = serviceGroup.getJsonObject(i);
+
+                        String serviceListName = svcGroupListobj.get("name").toString();
+                        String description = null;
+                        if (svcGroupListobj.containsKey("description")){
+                            description = svcGroupListobj.get("description").toString();
+                        }
+
+                        //getting members Array from the serviceGroup
+                        JsonArray membersArray = svcGroupListobj.getJsonArray("members");
+
+                        //String type = svcGroupListobj.get("type").toString();
+                        Boolean isServiceGroup = false;
+                        if (membersArray!=null){
+                            String membersType = membersArray.getJsonObject(0).get("type").toString();
+                            if (membersType.contains("REFERENCE")) {
+                                isServiceGroup = true;
+                            }
+                        }
+
+                        //Insert values into GROUPSERVICELIST table if name begins with Group
+                        if (isServiceGroup) {
+                            String name = null;
+                            for (int membersIndex = 0; membersIndex< membersArray.size(); membersIndex++) {
+                                JsonObject membersObj = membersArray.getJsonObject(membersIndex);
+                                //String value = membersObj.get("name").toString();
+                                String type = membersObj.get("type").toString().replace("\"", "");
+
+                                String value = null;
+                                if(type.equals("REFERENCE")||type.equals("GROUP")||type.equals("SERVICE")){
+                                    value = membersObj.get("name").toString();
+                                } else if (type.equalsIgnoreCase("ANY")){
+                                    value = null;
+                                } else {
+                                    value = membersObj.get("value").toString();
+                                }
+
+                                if(value != null){
+                                    value = value.replace("\"", "");
+                                }
+
+                                if (name != null) {
+                                    name = name.concat(",").concat(value);
+                                } else {
+                                    name = value;
+                                }
+                            }
+                            String nameInsert = "'"+name+"'";
+                            GroupServiceList groupServiceEntry = new GroupServiceList();
+                            groupServiceEntry.setGroupName(serviceListName);
+                            groupServiceEntry.setServiceList(nameInsert);
+                            dbConnection.save(groupServiceEntry);
+                        } else { //Insert JSON data serviceList table, protollist table, and portlist table
+                            String type = svcGroupListobj.get("type").toString();
+                            String transportProtocol = svcGroupListobj.get("transportProtocol").toString();
+                            String ports = svcGroupListobj.get("ports").toString();
+
+                            /*
+                             * Create Queries to INSERT data into database table and execute
+                             */
+                            ServiceList serviceListEntry = new ServiceList();
+                            serviceListEntry.setServiceName(serviceListName);
+                            serviceListEntry.setServiceDescription(description);
+                            serviceListEntry.setServiceType(type);
+                            serviceListEntry.setServiceTransProtocol(transportProtocol);
+                            serviceListEntry.setServiceAppProtocol("null");
+                            serviceListEntry.setServicePorts(ports);
+                            dbConnection.save(serviceListEntry);
+
+                            ProtocolList protocolEntry = new ProtocolList();
+                            protocolEntry.setProtocolName(transportProtocol);
+                            protocolEntry.setDescription(transportProtocol);
+                            dbConnection.save(protocolEntry);
+
+                            PortList portListEntry = new PortList();
+                            portListEntry.setPortName(ports);
+                            portListEntry.setDescription(ports);
+                            dbConnection.save(portListEntry);
+                        }
+                    }
+                }
+
+                /*
+                 * Inserting addressGroup data into the ADDRESSGROUP table
+                 */
+                if (addressGroup != null) {
+                    for(int i = 0; i < addressGroup.size(); i++) {
+                        /*
+                         * Populate ArrayLists with values from the JSON
+                         */
+                        //create the JSON object from the JSON Array for each iteration through the for loop
+                        JsonObject addressGroupObj = addressGroup.getJsonObject(i);
+
+                        //create JSON array for members
+                        JsonArray membersArray = addressGroupObj.getJsonArray("members");
+                        String addressGroupName = addressGroupObj.get("name").toString();
+
+                        String description = null;
+                        if (addressGroupObj.containsKey("description")){
+                            description = addressGroupObj.get("description").toString();
+                        }
+
+                        String prefixIP = null;
+                        String type = null;
+                        for (int membersIndex = 0; membersIndex < membersArray.size(); membersIndex++) {
+                            JsonObject membersObj = membersArray.getJsonObject(membersIndex);
+                            //String value = membersObj.get("value").toString();
+                            type = membersObj.get("type").toString().replace("\"", "");
+
+                            String value = null;
+                            if(type.equals("REFERENCE")||type.equals("GROUP")||type.equals("SERVICE")){
+                                value = membersObj.get("name").toString();
+                            } else if (type.equalsIgnoreCase("ANY")){
+                                value = null;
+                            } else {
+                                value = membersObj.get("value").toString();
+                            }
+
+                            if(value != null){
+                                value = value.replace("\"", "");
+                            }
+
+                            if (prefixIP != null) {
+                                prefixIP = prefixIP.concat(",").concat(value);
+                            } else {
+                                prefixIP = value;
+                            }
+                        }
+                        String prefixList = "'"+prefixIP+"'";
+
+                        Boolean isAddressGroup = type.contains("REFERENCE");
+
+                        if (isAddressGroup) {
+                            AddressGroup addressGroupEntry = new AddressGroup();
+                            addressGroupEntry.setGroupName(addressGroupName);
+                            addressGroupEntry.setDescription(description);
+                            addressGroupEntry.setServiceList(prefixList);
+                            dbConnection.save(addressGroupEntry);
+                        } else {
+                            PrefixList prefixListEntry = new PrefixList();
+                            prefixListEntry.setPrefixListName(addressGroupName);
+                            prefixListEntry.setDescription(description);
+                            prefixListEntry.setPrefixListValue(prefixList);
+                            dbConnection.save(prefixListEntry);
+                        }
+                    }
+                }
+
+                /*
+                 * Remove duplicate values from 'lookup' dictionary tables
+                 */
+                //ProtocolList Table
+                String protoDelete = "DELETE FROM protocollist USING protocollist, protocollist p1 "
+                        + "WHERE protocollist.id > p1.id AND protocollist.protocolname = p1.protocolname;";
+                dbConnection.updateQuery(protoDelete);
+
+                //PortList Table
+                String portListDelete = "DELETE FROM portlist USING portlist, portlist p1 "
+                        + "WHERE portlist.id > p1.id AND portlist.portname = p1.portname; ";
+                dbConnection.updateQuery(portListDelete);
+
+                //PrefixList Table
+                String prefixListDelete = "DELETE FROM prefixlist USING prefixlist, prefixlist p1 "
+                        + "WHERE prefixlist.id > p1.id AND prefixlist.pl_name = p1.pl_name AND "
+                        + "prefixlist.pl_value = p1.pl_value AND prefixlist.description = p1.description; ";
+                dbConnection.updateQuery(prefixListDelete);
+
+                //GroupServiceList
+                String groupServiceDelete = "DELETE FROM groupservicelist USING groupservicelist, groupservicelist g1 "
+                        + "WHERE groupservicelist.id > g1.id AND groupservicelist.name = g1.name AND "
+                        + "groupservicelist.serviceList = g1.serviceList; ";
+                dbConnection.updateQuery(groupServiceDelete);
+            }catch (Exception e) {
+                PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "FirewallConfigPolicy", "Exception getting Json values");
+                return false;
+            }
+            return true;
+
+        } else {
+            return false;
+        }
+
+    }
+
+
+    private Boolean updateFirewallDictionaryData(String jsonBody, String prevJsonBody) {
+        CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
+        JsonObject oldJson = null;
+        JsonObject newJson = null;
+
+        if (jsonBody != null || prevJsonBody != null) {
+
+            oldJson = stringToJson(prevJsonBody);
+            newJson = stringToJson(jsonBody);
+
+            //if no changes to the json then return true
+            if (oldJson != null && oldJson.equals(newJson)) {
+                return true;
+            }
+
+            JsonArray firewallRules = null;
+            JsonArray serviceGroup = null;
+            JsonArray addressGroup = null;
+
+            firewallRules = newJson.getJsonArray("firewallRuleList");
+            serviceGroup = newJson.getJsonArray("serviceGroups");
+            addressGroup = newJson.getJsonArray("addressGroups");
+
+            //insert data into tables
+            try {
+                JsonNode jsonDiff = createPatch(jsonBody, prevJsonBody);
+
+                for (int i = 0; i<jsonDiff.size(); i++) {
+                    //String path = jsonDiff.get(i).asText();
+                    String jsonpatch = jsonDiff.get(i).toString();
+
+                    JsonObject patchObj = stringToJson(jsonpatch);
+
+                    String path = patchObj.get("path").toString().replace('"', ' ').trim();
+
+                    if (path.contains("firewallRuleList")) {
+                        /*
+                         * Inserting firewallRuleList data into the Terms, SecurityZone, and Action tables
+                         */
+                        for(int ri = 0; ri < firewallRules.size(); ri++) {
+                            /*
+                             * Populate ArrayLists with values from the JSON
+                             */
+                            //create the JSON object from the JSON Array for each iteration through the for loop
+                            JsonObject ruleListobj = firewallRules.getJsonObject(ri);
+
+                            //get values from JSON fields of firewallRulesList Array
+                            String ruleName = ruleListobj.get("ruleName").toString().replace('"', '\'');
+                            String action = ruleListobj.get("action").toString().replace('"', '\'');
+                            String description = ruleListobj.get("description").toString().replace('"', '\'');
+
+                            List<Object> result = dbConnection.getDataById(TermList.class, "termName", ruleName);
+                            if(result != null && !result.isEmpty()){
+                                TermList termEntry = (TermList) result.get(0);
+                                dbConnection.delete(termEntry);
+                            }
+
+                            //getting fromZone Array field from the firewallRulesList
+                            JsonArray fromZoneArray = ruleListobj.getJsonArray("fromZones");
+                            String fromZoneString = null;
+
+                            for (int fromZoneIndex = 0; fromZoneIndex<fromZoneArray.size() ; fromZoneIndex++) {
+                                String value = fromZoneArray.get(fromZoneIndex).toString();
+                                value = value.replace("\"", "");
+
+                                if (fromZoneString != null) {
+                                    fromZoneString = fromZoneString.concat(",").concat(value);
+
+                                } else {
+                                    fromZoneString = value;
+                                }
+
+                            }
+                            String fromZoneInsert = "'"+fromZoneString+"'";
+
+                            //getting toZone Array field from the firewallRulesList
+                            JsonArray toZoneArray = ruleListobj.getJsonArray("toZones");
+                            String toZoneString = null;
+
+
+                            for (int toZoneIndex = 0; toZoneIndex < toZoneArray.size(); toZoneIndex++) {
+                                String value = toZoneArray.get(toZoneIndex).toString();
+                                value = value.replace("\"", "");
+
+                                if (toZoneString != null) {
+                                    toZoneString = toZoneString.concat(",").concat(value);
+
+                                } else {
+                                    toZoneString = value;
+                                }
+
+                            }
+                            String toZoneInsert = "'"+toZoneString+"'";
+                            //getting sourceList Array fields from the firewallRulesList
+                            JsonArray srcListArray = ruleListobj.getJsonArray("sourceList");
+                            String srcListString = null;
+                            for (int srcListIndex = 0; srcListIndex<srcListArray.size(); srcListIndex++) {
+                                JsonObject srcListObj = srcListArray.getJsonObject(srcListIndex);
+                                String type = srcListObj.get("type").toString().replace("\"", "");
+
+                                String value = null;
+                                if(type.equals("REFERENCE")||type.equals("GROUP")){
+                                    value = srcListObj.get("name").toString();
+                                } else if (type.equalsIgnoreCase("ANY")){
+                                    value = null;
+                                } else {
+                                    value = srcListObj.get("value").toString();
+                                }
+
+                                if(value != null){
+                                    value = value.replace("\"", "");
+                                }
+
+                                if (srcListString != null) {
+                                    srcListString = srcListString.concat(",").concat(value);
+
+                                } else {
+                                    srcListString = value;
+                                }
+
+                            }
+                            String srcListInsert = "'"+srcListString+"'";
+
+                            //getting destinationList Array fields from the firewallRulesList
+                            JsonArray destListArray = ruleListobj.getJsonArray("destinationList");
+                            String destListString = null;
+                            for (int destListIndex = 0; destListIndex<destListArray.size(); destListIndex ++) {
+                                JsonObject destListObj = destListArray.getJsonObject(destListIndex);
+                                String type = destListObj.get("type").toString().replace("\"", "");
+
+                                String value = null;
+                                if(type.equals("REFERENCE")||type.equals("GROUP")){
+                                    value = destListObj.get("name").toString();
+                                } else if (type.equalsIgnoreCase("ANY")){
+                                    value = null;
+                                } else {
+                                    value = destListObj.get("value").toString();
+                                }
+
+                                if(value != null){
+                                    value = value.replace("\"", "");
+                                }
+
+                                if (destListString != null) {
+                                    destListString = destListString.concat(",").concat(value);
+                                } else {
+                                    destListString = value;
+                                }
+                            }
+                            String destListInsert = "'"+destListString+"'";
+
+                            //getting destServices Array fields from the firewallRulesList
+                            JsonArray destServicesArray = ruleListobj.getJsonArray("destServices");
+                            String destPortListString = null;
+                            for (int destPortListIndex = 0; destPortListIndex < destServicesArray.size(); destPortListIndex++) {
+                                JsonObject destServicesObj = destServicesArray.getJsonObject(destPortListIndex);
+                                String type = destServicesObj.get("type").toString().replace("\"", "");
+
+                                String value = null;
+                                if(type.equals("REFERENCE")||type.equals("GROUP")){
+                                    value = destServicesObj.get("name").toString();
+                                } else if (type.equalsIgnoreCase("ANY")){
+                                    value = null;
+                                } else {
+                                    value = destServicesObj.get("value").toString();
+                                }
+
+                                if(value != null){
+                                    value = value.replace("\"", "");
+                                }
+
+                                if (destPortListString != null) {
+                                    destPortListString = destPortListString.concat(",").concat(value);
+                                } else {
+                                    destPortListString = value;
+                                }
+                            }
+                            String destPortListInsert = "'"+destPortListString+"'";
+
+                            /*
+                             * Create Queries to INSERT data into database tables and execute
+                             */
+                            UserInfo userInfo = new UserInfo();
+                            userInfo.setUserLoginId("API");
+                            userInfo.setUserName("API");
+
+                            TermList termEntry = new TermList();
+                            termEntry.setTermName(ruleName);
+                            termEntry.setSrcIPList(srcListInsert);
+                            termEntry.setDestIPList(destListInsert);
+                            termEntry.setProtocolList("null");
+                            termEntry.setPortList("null");
+                            termEntry.setSrcPortList("null");
+                            termEntry.setDestPortList(destPortListInsert);
+                            termEntry.setAction(action);
+                            termEntry.setDescription(description);
+                            termEntry.setFromZones(fromZoneInsert);
+                            termEntry.setToZones(toZoneInsert);
+                            termEntry.setUserCreatedBy(userInfo);
+                            dbConnection.save(termEntry);
+
+                            List<Object> actionResult = dbConnection.getDataById(ActionList.class, "actionName", action);
+                            if(actionResult == null || actionResult.isEmpty()){
+                                ActionList actionEntry = new ActionList();
+                                actionEntry.setActionName(action);
+                                actionEntry.setDescription(action);
+                                dbConnection.save(actionEntry);
+                            }
+                        }
+                    }
+
+                    if (path.contains("serviceGroups")) {
+                        /*
+                         * Inserting serviceGroups data into the ServiceGroup, ServiceList, ProtocolList, and PortList tables
+                         */
+                        for(int si = 0; si < serviceGroup.size(); si++) {
+                            /*
+                             * Populate ArrayLists with values from the JSON
+                             */
+                            //create the JSON object from the JSON Array for each iteration through the for loop
+                            JsonObject svcGroupListobj = serviceGroup.getJsonObject(si);
+
+                            String groupName = svcGroupListobj.get("name").toString().replace('"', '\'');
+
+                            String description = null;
+                            if (svcGroupListobj.containsKey("description")){
+                                description = svcGroupListobj.get("description").toString().replace('"', '\'');
+                            }
+
+                            JsonArray membersArray = svcGroupListobj.getJsonArray("members");
+
+                            Boolean isServiceGroup = false;
+                            if (membersArray!=null){
+                                String membersType = membersArray.getJsonObject(0).get("type").toString();
+                                if (membersType.contains("REFERENCE")) {
+                                    isServiceGroup = true;
+                                }
+                            }
+
+                            //Insert values into GROUPSERVICELIST table if name begins with Group
+                            if (isServiceGroup) {
+                                List<Object> result = dbConnection.getDataById(GroupServiceList.class, "name", groupName);
+                                if(result != null && !result.isEmpty()){
+                                    GroupServiceList groupEntry = (GroupServiceList) result.get(0);
+                                    dbConnection.delete(groupEntry);
+                                }
+
+                                String name = null;
+                                for (int membersIndex = 0; membersIndex < membersArray.size(); membersIndex++) {
+                                    JsonObject membersObj = membersArray.getJsonObject(membersIndex);
+                                    String type = membersObj.get("type").toString().replace("\"", "");
+
+                                    String value = null;
+                                    if(type.equals("REFERENCE")||type.equals("GROUP")||type.equals("SERVICE")){
+                                        value = membersObj.get("name").toString();
+                                    } else if (type.equalsIgnoreCase("ANY")){
+                                        value = null;
+                                    } else {
+                                        value = membersObj.get("value").toString();
+                                    }
+
+                                    if(value != null){
+                                        value = value.replace("\"", "");
+                                    }
+
+                                    if (name != null) {
+                                        name = name.concat(",").concat(value);
+                                    } else {
+                                        name = value;
+                                    }
+                                }
+                                String nameInsert = "'"+name+"'";
+                                GroupServiceList groupServiceEntry = new GroupServiceList();
+                                groupServiceEntry.setGroupName(groupName);
+                                groupServiceEntry.setServiceList(nameInsert);
+                                dbConnection.save(groupServiceEntry);
+                            } else { //Insert JSON data serviceGroup table, protocollist table, and portlist table
+                                String type = svcGroupListobj.get("type").toString().replace('"', '\'');
+                                String transportProtocol = svcGroupListobj.get("transportProtocol").toString().replace('"', '\'');
+                                String ports = svcGroupListobj.get("ports").toString().replace('"', '\'');
+
+                                List<Object> result = dbConnection.getDataById(ServiceList.class, "name", groupName);
+                                if(result != null && !result.isEmpty()){
+                                    ServiceList serviceEntry = (ServiceList) result.get(0);
+                                    dbConnection.delete(serviceEntry);
+                                }
+
+                                ServiceList serviceListEntry = new ServiceList();
+                                serviceListEntry.setServiceName(groupName);
+                                serviceListEntry.setServiceDescription(description);
+                                serviceListEntry.setServiceType(type);
+                                serviceListEntry.setServiceTransProtocol(transportProtocol);
+                                serviceListEntry.setServiceAppProtocol("null");
+                                serviceListEntry.setServicePorts(ports);
+                                dbConnection.save(serviceListEntry);
+
+                                List<Object> protocolResult = dbConnection.getDataById(ProtocolList.class, "protocolName", transportProtocol);
+                                if(protocolResult == null || protocolResult.isEmpty()){
+                                    ProtocolList protocolEntry = new ProtocolList();
+                                    protocolEntry.setProtocolName(transportProtocol);
+                                    protocolEntry.setDescription(transportProtocol);
+                                    dbConnection.save(protocolEntry);
+                                }
+
+                                List<Object> portResult = dbConnection.getDataById(PortList.class, "portName", ports);
+                                if(portResult == null || portResult.isEmpty()){
+                                    PortList portEntry = new PortList();
+                                    portEntry.setPortName(ports);
+                                    portEntry.setDescription(ports);
+                                    dbConnection.save(portEntry);
+                                }
+                            }
+                        }
+                    }
+
+                    if (path.contains("addressGroups")) {
+                        /*
+                         * Inserting addressGroup data into the ADDRESSGROUP table
+                         */
+                        for(int ai=0; ai < addressGroup.size() ; ai++) {
+
+                            /*
+                             * Populate ArrayLists with values from the JSON
+                             */
+                            //create the JSON object from the JSON Array for each iteration through the for loop
+                            JsonObject addressGroupObj = addressGroup.getJsonObject(ai);
+
+                            //create JSON array for members
+                            JsonArray membersArray = addressGroupObj.getJsonArray("members");
+                            String addressGroupName = addressGroupObj.get("name").toString().replace('"', '\'');
+
+                            String description = null;
+                            if (addressGroupObj.containsKey("description")){
+                                description = addressGroupObj.get("description").toString().replace('"', '\'');
+                            }
+
+                            String prefixIP = null;
+                            String type = null;
+                            for (int membersIndex=0; membersIndex < membersArray.size(); membersIndex++) {
+                                JsonObject membersObj = membersArray.getJsonObject(membersIndex);
+                                type = membersObj.get("type").toString().replace("\"", "");
+
+                                String value = null;
+                                if(type.equals("REFERENCE")||type.equals("GROUP")||type.equals("SERVICE")){
+                                    value = membersObj.get("name").toString();
+                                } else if (type.equalsIgnoreCase("ANY")){
+                                    value = null;
+                                } else {
+                                    value = membersObj.get("value").toString();
+                                }
+
+                                if(value != null){
+                                    value = value.replace("\"", "");
+                                }
+
+                                if (prefixIP != null) {
+                                    prefixIP = prefixIP.concat(",").concat(value);
+                                } else {
+                                    prefixIP = value;
+                                }
+                            }
+
+                            String prefixList = "'"+prefixIP+"'";
+                            Boolean isAddressGroup = type.contains("REFERENCE");
+
+                            if (isAddressGroup) {
+                                List<Object> result = dbConnection.getDataById(AddressGroup.class, "name", addressGroupName);
+                                if(result != null && !result.isEmpty()){
+                                    AddressGroup addressGroupEntry = (AddressGroup) result.get(0);
+                                    dbConnection.delete(addressGroupEntry);
+                                }
+                                AddressGroup newAddressGroup = new AddressGroup();
+                                newAddressGroup.setGroupName(addressGroupName);
+                                newAddressGroup.setDescription(description);
+                                newAddressGroup.setServiceList(prefixList);
+                                dbConnection.save(newAddressGroup);
+                            } else {
+                                List<Object> result = dbConnection.getDataById(PrefixList.class, "prefixListName", addressGroupName);
+                                if(result != null && !result.isEmpty()){
+                                    PrefixList prefixListEntry = (PrefixList) result.get(0);
+                                    dbConnection.delete(prefixListEntry);
+                                }
+                                PrefixList newPrefixList = new PrefixList();
+                                newPrefixList.setPrefixListName(addressGroupName);
+                                newPrefixList.setDescription(description);
+                                newPrefixList.setPrefixListValue(prefixList);
+                                dbConnection.save(newPrefixList);
+                            }
+                        }
+                    }
+                }
+
+                /*
+                 * Remove duplicate values from 'lookup' dictionary tables
+                 */
+                //ProtocolList Table
+                String protoDelete = "DELETE FROM protocollist USING protocollist, protocollist p1 "
+                        + "WHERE protocollist.id > p1.id AND protocollist.protocolname = p1.protocolname;";
+                dbConnection.updateQuery(protoDelete);
+
+                //PortList Table
+                String portListDelete = "DELETE FROM portlist USING portlist, portlist p1 "
+                        + "WHERE portlist.id > p1.id AND portlist.portname = p1.portname; ";
+                dbConnection.updateQuery(portListDelete);
+
+                //PrefixList Table
+                String prefixListDelete = "DELETE FROM prefixlist USING prefixlist, prefixlist p1 "
+                        + "WHERE prefixlist.id > p1.id AND prefixlist.pl_name = p1.pl_name AND "
+                        + "prefixlist.pl_value = p1.pl_value AND prefixlist.description = p1.description; ";
+                dbConnection.updateQuery(prefixListDelete);
+
+                //GroupServiceList
+                String groupServiceDelete = "DELETE FROM groupservicelist USING groupservicelist, groupservicelist g1 "
+                        + "WHERE groupservicelist.id > g1.id AND groupservicelist.name = g1.name AND "
+                        + "groupservicelist.serviceList = g1.serviceList; ";
+                dbConnection.updateQuery(groupServiceDelete);
+            }catch (Exception e) {
+                PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "FirewallConfigPolicy", "Exception executing Firewall queries");
+                return false;
+            }
+            return true;
+        } else {
+            return false;
+        }
+
+    }
+
+    private JsonObject stringToJson(String jsonString) {
+        //Read jsonBody to JsonObject
+        StringReader in = new StringReader(jsonString);
+        JsonReader jsonReader = Json.createReader(in);
+        JsonObject json = jsonReader.readObject();
+        jsonReader.close();
+        return json;
+    }
+
+    private JsonNode createPatch(String json, String oldJson) {
+        JsonNode oldJason = null;
+        JsonNode updatedJason = null;
+
+        try {
+            oldJason = JsonLoader.fromString(oldJson);
+            updatedJason = JsonLoader.fromString(json);
+        } catch (IOException e) {
+            LOGGER.error("Exception Occured"+e);
+        }
+        return JsonDiff.asJson(oldJason, updatedJason);
+    }
+
+    @Override
+    public Object getCorrectPolicyDataObject() {
+        return policyAdapter.getPolicyData();
+    }
 
 }
\ No newline at end of file
index e021211..26c7ed8 100644 (file)
@@ -64,112 +64,112 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; 
 
 public class MicroServiceConfigPolicy extends Policy {
-       
-       private static final Logger LOGGER = FlexLogger.getLogger(MicroServiceConfigPolicy.class);
-       
+
+    private static final Logger LOGGER = FlexLogger.getLogger(MicroServiceConfigPolicy.class);
+
     private static Map<String, String> mapAttribute = new HashMap<>();
     private static Map<String, String> mapMatch = new HashMap<>();
 
-       private static synchronized Map<String, String> getMatchMap () {
-               return mapMatch;
-       }
-
-       private static synchronized void setMatchMap(Map<String, String> mm) {
-               mapMatch = mm;
-       }
-
-       public MicroServiceConfigPolicy() {
-               super();
-       }
-       
-       public MicroServiceConfigPolicy(PolicyRestAdapter policyAdapter){
-               this.policyAdapter = policyAdapter;
-       }
-
-       //save configuration of the policy based on the policyname
-       private void saveConfigurations(String policyName, String jsonBody) {
-               if(policyName.endsWith(".xml")){
-                   policyName = policyName.replace(".xml", "");
-               }
-               try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName +".json")){
-                       out.println(jsonBody);
-               } catch (Exception e) {
-                       LOGGER.error("Exception Occured While writing Configuration data"+e);
-               } 
-       }
-       
-       
-       @Override
-       public Map<String, String> savePolicies() throws PAPException {
-
-               Map<String, String> successMap = new HashMap<>();
-               if(isPolicyExists()){
-                       successMap.put("EXISTS", "This Policy already exist on the PAP");
-                       return successMap;
-               }
-
-               if(!isPreparedToSave()){
-                       //Prep and configure the policy for saving
-                       prepareToSave();
-               }
-
-               // Until here we prepared the data and here calling the method to create xml.
-               Path newPolicyPath = null;
-               newPolicyPath = Paths.get(policyAdapter.getNewFileName());
-
-               successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());  
-       
-               return successMap;              
-       }
-       
-       //This is the method for preparing the policy for saving.  We have broken it out
-       //separately because the fully configured policy is used for multiple things
-       @Override
-       public boolean prepareToSave() throws PAPException{
-
-               if(isPreparedToSave()){
-                       //we have already done this
-                       return true;
-               }
-               
-               int version = 0;
-               String policyID = policyAdapter.getPolicyID();
-               version = policyAdapter.getHighestVersion();
-               
-               // Create the Instance for pojo, PolicyType object is used in marshalling.
-               if (policyAdapter.getPolicyType().equals("Config")) {
-                       PolicyType policyConfig = new PolicyType();
-
-                       policyConfig.setVersion(Integer.toString(version));
-                       policyConfig.setPolicyId(policyID);
-                       policyConfig.setTarget(new TargetType());
-                       policyAdapter.setData(policyConfig);
-               }
-               policyName = policyAdapter.getNewFileName();
-               if (policyAdapter.getData() != null) {
-                       // Save the Configurations file with the policy name with extention based on selection.
-                       String jsonBody = policyAdapter.getJsonBody();
-                       saveConfigurations(policyName, jsonBody);
-                       
-                       // Make sure the filename ends with an extension
-                       if (policyName.endsWith(".xml") == false) {
-                               policyName = policyName + ".xml";
-                       }
-                       
-       
-                       PolicyType configPolicy = (PolicyType) policyAdapter.getData();
-                       
-                       configPolicy.setDescription(policyAdapter.getPolicyDescription());
-
-                       configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
-                       
-                       AllOfType allOfOne = new AllOfType();
-                       String fileName = policyAdapter.getNewFileName();
-                       String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
-                       if ((name == null) || (name.equals(""))) {
-                               name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
-                       }
-                       
+    private static synchronized Map<String, String> getMatchMap () {
+        return mapMatch;
+    }
+
+    private static synchronized void setMatchMap(Map<String, String> mm) {
+        mapMatch = mm;
+    }
+
+    public MicroServiceConfigPolicy() {
+        super();
+    }
+
+    public MicroServiceConfigPolicy(PolicyRestAdapter policyAdapter){
+        this.policyAdapter = policyAdapter;
+    }
+
+    //save configuration of the policy based on the policyname
+    private void saveConfigurations(String policyName, String jsonBody) {
+            if(policyName.endsWith(".xml")){
+                policyName = policyName.replace(".xml", "");
+            }
+        try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName +".json")){
+            out.println(jsonBody);
+        } catch (Exception e) {
+            LOGGER.error("Exception Occured While writing Configuration data"+e);
+        }
+    }
+
+
+    @Override
+    public Map<String, String> savePolicies() throws PAPException {
+
+        Map<String, String> successMap = new HashMap<>();
+        if(isPolicyExists()){
+            successMap.put("EXISTS", "This Policy already exist on the PAP");
+            return successMap;
+        }
+
+        if(!isPreparedToSave()){
+            //Prep and configure the policy for saving
+            prepareToSave();
+        }
+
+        // Until here we prepared the data and here calling the method to create xml.
+        Path newPolicyPath = null;
+        newPolicyPath = Paths.get(policyAdapter.getNewFileName());
+
+        successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());
+
+        return successMap;
+    }
+
+    //This is the method for preparing the policy for saving.  We have broken it out
+    //separately because the fully configured policy is used for multiple things
+    @Override
+    public boolean prepareToSave() throws PAPException{
+
+        if(isPreparedToSave()){
+            //we have already done this
+            return true;
+        }
+
+        int version = 0;
+        String policyID = policyAdapter.getPolicyID();
+        version = policyAdapter.getHighestVersion();
+
+        // Create the Instance for pojo, PolicyType object is used in marshalling.
+        if (policyAdapter.getPolicyType().equals("Config")) {
+            PolicyType policyConfig = new PolicyType();
+
+            policyConfig.setVersion(Integer.toString(version));
+            policyConfig.setPolicyId(policyID);
+            policyConfig.setTarget(new TargetType());
+            policyAdapter.setData(policyConfig);
+        }
+        policyName = policyAdapter.getNewFileName();
+        if (policyAdapter.getData() != null) {
+            // Save the Configurations file with the policy name with extention based on selection.
+            String jsonBody = policyAdapter.getJsonBody();
+            saveConfigurations(policyName, jsonBody);
+
+            // Make sure the filename ends with an extension
+            if (policyName.endsWith(".xml") == false) {
+                policyName = policyName + ".xml";
+            }
+
+
+            PolicyType configPolicy = (PolicyType) policyAdapter.getData();
+
+            configPolicy.setDescription(policyAdapter.getPolicyDescription());
+
+            configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
+
+            AllOfType allOfOne = new AllOfType();
+            String fileName = policyAdapter.getNewFileName();
+            String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
+            if ((name == null) || (name.equals(""))) {
+                name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
+            }
+
             //setup values for pulling out matching attributes
             ObjectMapper mapper = new ObjectMapper();
             String matching = null;
@@ -196,124 +196,124 @@ public class MicroServiceConfigPolicy extends Policy {
                 throw new PAPException(e1);
             }
             
-                       // Match for policyName
-                       allOfOne.getMatch().add(createMatch("PolicyName", name));
-                       
-                       AllOfType allOf = new AllOfType();
-               
-                       // Adding the matches to AllOfType element Match for Onap
-                       allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
-                       if (matchMap==null || matchMap.isEmpty()){
-                               // Match for ConfigName
-                               allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
-                               // Match for Service
-                               allOf.getMatch().add(createDynamicMatch("service", policyAdapter.getServiceType()));
-                               // Match for uuid
-                               allOf.getMatch().add(createDynamicMatch("uuid", policyAdapter.getUuid()));
-                               // Match for location
-                               allOf.getMatch().add(createDynamicMatch("location", policyAdapter.getLocation()));
-                       }else {
-                               for (Entry<String, String> matchValue : matchMap.entrySet()){
-                                       String value = matchValue.getValue();
-                                       String key = matchValue.getKey().trim();
-                                       if (value.contains("matching-true")){
-                                               if (mapAttribute.containsKey(key)){
-                                                       allOf.getMatch().add(createDynamicMatch(key, mapAttribute.get(key)));
-                                               }
-                                       }
-                               }
-                       }
-                       // Match for riskType
-                       allOf.getMatch().add(
-                                       createDynamicMatch("RiskType", policyAdapter.getRiskType()));
-                       // Match for riskLevel
-                       allOf.getMatch().add(
-                                       createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
-                       // Match for riskguard
-                       allOf.getMatch().add(
-                                       createDynamicMatch("guard", policyAdapter.getGuard()));
-                       // Match for ttlDate
-                       allOf.getMatch().add(
-                                       createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
-
-                       AnyOfType anyOf = new AnyOfType();
-                       anyOf.getAllOf().add(allOfOne);
-                       anyOf.getAllOf().add(allOf);
-
-                       TargetType target = new TargetType();
-                       ((TargetType) target).getAnyOf().add(anyOf);
-                       
-                       // Adding the target to the policy element
-                       configPolicy.setTarget((TargetType) target);
-
-                       RuleType rule = new RuleType();
-                       rule.setRuleId(policyAdapter.getRuleID());
-                       
-                       rule.setEffect(EffectType.PERMIT);
-                       
-                       // Create Target in Rule
-                       AllOfType allOfInRule = new AllOfType();
-
-                       // Creating match for ACCESS in rule target
-                       MatchType accessMatch = new MatchType();
-                       AttributeValueType accessAttributeValue = new AttributeValueType();
-                       accessAttributeValue.setDataType(STRING_DATATYPE);
-                       accessAttributeValue.getContent().add("ACCESS");
-                       accessMatch.setAttributeValue(accessAttributeValue);
-                       AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
-                       URI accessURI = null;
-                       try {
-                               accessURI = new URI(ACTION_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy", "Exception creating ACCESS URI");
-                       }
-                       accessAttributeDesignator.setCategory(CATEGORY_ACTION);
-                       accessAttributeDesignator.setDataType(STRING_DATATYPE);
-                       accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
-                       accessMatch.setAttributeDesignator(accessAttributeDesignator);
-                       accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       // Creating Config Match in rule Target
-                       MatchType configMatch = new MatchType();
-                       AttributeValueType configAttributeValue = new AttributeValueType();
-                       configAttributeValue.setDataType(STRING_DATATYPE);
-                       configAttributeValue.getContent().add("Config");
-                       configMatch.setAttributeValue(configAttributeValue);
-                       AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
-                       URI configURI = null;
-                       try {
-                               configURI = new URI(RESOURCE_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy", "Exception creating Config URI");
-                       }
-                       configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
-                       configAttributeDesignator.setDataType(STRING_DATATYPE);
-                       configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
-                       configMatch.setAttributeDesignator(configAttributeDesignator);
-                       configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       allOfInRule.getMatch().add(accessMatch);
-                       allOfInRule.getMatch().add(configMatch);
-
-                       AnyOfType anyOfInRule = new AnyOfType();
-                       anyOfInRule.getAllOf().add(allOfInRule);
-
-                       TargetType targetInRule = new TargetType();
-                       targetInRule.getAnyOf().add(anyOfInRule);
-
-                       rule.setTarget(targetInRule);
-                       rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
-
-                       configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
-                       policyAdapter.setPolicyData(configPolicy);
-
-               } else {
-                       PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
-               }
-               setPreparedToSave(true);
-               return true;
-       }
-       
+            // Match for policyName
+            allOfOne.getMatch().add(createMatch("PolicyName", name));
+
+            AllOfType allOf = new AllOfType();
+
+            // Adding the matches to AllOfType element Match for Onap
+            allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
+            if (matchMap==null || matchMap.isEmpty()){
+                // Match for ConfigName
+                allOf.getMatch().add(createMatch("ConfigName", policyAdapter.getConfigName()));
+                // Match for Service
+                allOf.getMatch().add(createDynamicMatch("service", policyAdapter.getServiceType()));
+                // Match for uuid
+                allOf.getMatch().add(createDynamicMatch("uuid", policyAdapter.getUuid()));
+                // Match for location
+                allOf.getMatch().add(createDynamicMatch("location", policyAdapter.getLocation()));
+            }else {
+                for (Entry<String, String> matchValue : matchMap.entrySet()){
+                    String value = matchValue.getValue();
+                    String key = matchValue.getKey().trim();
+                    if (value.contains("matching-true")){
+                        if (mapAttribute.containsKey(key)){
+                            allOf.getMatch().add(createDynamicMatch(key, mapAttribute.get(key)));
+                        }
+                    }
+                }
+            }
+            // Match for riskType
+            allOf.getMatch().add(
+                    createDynamicMatch("RiskType", policyAdapter.getRiskType()));
+            // Match for riskLevel
+            allOf.getMatch().add(
+                    createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
+            // Match for riskguard
+            allOf.getMatch().add(
+                    createDynamicMatch("guard", policyAdapter.getGuard()));
+            // Match for ttlDate
+            allOf.getMatch().add(
+                    createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
+
+            AnyOfType anyOf = new AnyOfType();
+            anyOf.getAllOf().add(allOfOne);
+            anyOf.getAllOf().add(allOf);
+
+            TargetType target = new TargetType();
+            ((TargetType) target).getAnyOf().add(anyOf);
+
+            // Adding the target to the policy element
+            configPolicy.setTarget((TargetType) target);
+
+            RuleType rule = new RuleType();
+            rule.setRuleId(policyAdapter.getRuleID());
+
+            rule.setEffect(EffectType.PERMIT);
+
+            // Create Target in Rule
+            AllOfType allOfInRule = new AllOfType();
+
+            // Creating match for ACCESS in rule target
+            MatchType accessMatch = new MatchType();
+            AttributeValueType accessAttributeValue = new AttributeValueType();
+            accessAttributeValue.setDataType(STRING_DATATYPE);
+            accessAttributeValue.getContent().add("ACCESS");
+            accessMatch.setAttributeValue(accessAttributeValue);
+            AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
+            URI accessURI = null;
+            try {
+                accessURI = new URI(ACTION_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy", "Exception creating ACCESS URI");
+            }
+            accessAttributeDesignator.setCategory(CATEGORY_ACTION);
+            accessAttributeDesignator.setDataType(STRING_DATATYPE);
+            accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
+            accessMatch.setAttributeDesignator(accessAttributeDesignator);
+            accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            // Creating Config Match in rule Target
+            MatchType configMatch = new MatchType();
+            AttributeValueType configAttributeValue = new AttributeValueType();
+            configAttributeValue.setDataType(STRING_DATATYPE);
+            configAttributeValue.getContent().add("Config");
+            configMatch.setAttributeValue(configAttributeValue);
+            AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
+            URI configURI = null;
+            try {
+                configURI = new URI(RESOURCE_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "MicroServiceConfigPolicy", "Exception creating Config URI");
+            }
+            configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
+            configAttributeDesignator.setDataType(STRING_DATATYPE);
+            configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
+            configMatch.setAttributeDesignator(configAttributeDesignator);
+            configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            allOfInRule.getMatch().add(accessMatch);
+            allOfInRule.getMatch().add(configMatch);
+
+            AnyOfType anyOfInRule = new AnyOfType();
+            anyOfInRule.getAllOf().add(allOfInRule);
+
+            TargetType targetInRule = new TargetType();
+            targetInRule.getAnyOf().add(anyOfInRule);
+
+            rule.setTarget(targetInRule);
+            rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
+
+            configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
+            policyAdapter.setPolicyData(configPolicy);
+
+        } else {
+            PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
+        }
+        setPreparedToSave(true);
+        return true;
+    }
+
     private void pullMatchValue(JsonNode rootNode) {
         Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields();
         String newValue = null;
@@ -339,89 +339,89 @@ public class MicroServiceConfigPolicy extends Policy {
        CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
        List<Object> result = dbConnection.getDataById(MicroServiceModels.class, "modelName:version", modelName+":"+modelVersion);
        if(result != null && !result.isEmpty()){
-          MicroServiceModels model = (MicroServiceModels) result.get(0);
-          ruleTemplate = model.getAnnotation();
+           MicroServiceModels model = (MicroServiceModels) result.get(0);
+           ruleTemplate = model.getAnnotation();
        }
        return ruleTemplate;
    }
    
-       // Data required for Advice part is setting here.
-       private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
-               AdviceExpressionsType advices = new AdviceExpressionsType();
-               AdviceExpressionType advice = new AdviceExpressionType();
-               advice.setAdviceId("MSID");
-               advice.setAppliesTo(EffectType.PERMIT);
-               // For Configuration
-               AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
-               assignment1.setAttributeId("type");
-               assignment1.setCategory(CATEGORY_RESOURCE);
-               assignment1.setIssuer("");
-
-               AttributeValueType configNameAttributeValue = new AttributeValueType();
-               configNameAttributeValue.setDataType(STRING_DATATYPE);
-               configNameAttributeValue.getContent().add("Configuration");
-               assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
-
-               advice.getAttributeAssignmentExpression().add(assignment1);
-               // For Config file Url if configurations are provided.
-               AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
-               assignment2.setAttributeId("URLID");
-               assignment2.setCategory(CATEGORY_RESOURCE);
-               assignment2.setIssuer("");
-
-               AttributeValueType AttributeValue = new AttributeValueType();
-               AttributeValue.setDataType(URI_DATATYPE);
-               String configName;
-               if(policyName.endsWith(".xml")){
-                       configName = policyName.replace(".xml", "");
-               }else{
-                       configName = policyName;
-               }
-               String content = CONFIG_URL +"/Config/" + configName + ".json";
-               AttributeValue.getContent().add(content);
-               assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue));
-
-               advice.getAttributeAssignmentExpression().add(assignment2);
-               AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
-               assignment3.setAttributeId("PolicyName");
-               assignment3.setCategory(CATEGORY_RESOURCE);
-               assignment3.setIssuer("");
-
-               AttributeValueType attributeValue3 = new AttributeValueType();
-               attributeValue3.setDataType(STRING_DATATYPE);
-               fileName = FilenameUtils.removeExtension(fileName);
-               fileName = fileName + ".xml";
-               String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
-               if ((name == null) || (name.equals(""))) {
-                       name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
-               }
-               attributeValue3.getContent().add(name);
-               assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
-               advice.getAttributeAssignmentExpression().add(assignment3);
-
-               AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
-               assignment4.setAttributeId("VersionNumber");
-               assignment4.setCategory(CATEGORY_RESOURCE);
-               assignment4.setIssuer("");
-
-               AttributeValueType configNameAttributeValue4 = new AttributeValueType();
-               configNameAttributeValue4.setDataType(STRING_DATATYPE);
-               configNameAttributeValue4.getContent().add(Integer.toString(version));
-               assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
-
-               advice.getAttributeAssignmentExpression().add(assignment4);
-
-               AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
-               assignment5.setAttributeId("matching:" + ONAPID);
-               assignment5.setCategory(CATEGORY_RESOURCE);
-               assignment5.setIssuer("");
-
-               AttributeValueType configNameAttributeValue5 = new AttributeValueType();
-               configNameAttributeValue5.setDataType(STRING_DATATYPE);
-               configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
-               assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
-
-               advice.getAttributeAssignmentExpression().add(assignment5);
+    // Data required for Advice part is setting here.
+    private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
+        AdviceExpressionsType advices = new AdviceExpressionsType();
+        AdviceExpressionType advice = new AdviceExpressionType();
+        advice.setAdviceId("MSID");
+        advice.setAppliesTo(EffectType.PERMIT);
+        // For Configuration
+        AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
+        assignment1.setAttributeId("type");
+        assignment1.setCategory(CATEGORY_RESOURCE);
+        assignment1.setIssuer("");
+
+        AttributeValueType configNameAttributeValue = new AttributeValueType();
+        configNameAttributeValue.setDataType(STRING_DATATYPE);
+        configNameAttributeValue.getContent().add("Configuration");
+        assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
+
+        advice.getAttributeAssignmentExpression().add(assignment1);
+        // For Config file Url if configurations are provided.
+        AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
+        assignment2.setAttributeId("URLID");
+        assignment2.setCategory(CATEGORY_RESOURCE);
+        assignment2.setIssuer("");
+
+        AttributeValueType AttributeValue = new AttributeValueType();
+        AttributeValue.setDataType(URI_DATATYPE);
+        String configName;
+        if(policyName.endsWith(".xml")){
+            configName = policyName.replace(".xml", "");
+        }else{
+            configName = policyName;
+        }
+        String content = CONFIG_URL +"/Config/" + configName + ".json";
+        AttributeValue.getContent().add(content);
+        assignment2.setExpression(new ObjectFactory().createAttributeValue(AttributeValue));
+
+        advice.getAttributeAssignmentExpression().add(assignment2);
+        AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
+        assignment3.setAttributeId("PolicyName");
+        assignment3.setCategory(CATEGORY_RESOURCE);
+        assignment3.setIssuer("");
+
+        AttributeValueType attributeValue3 = new AttributeValueType();
+        attributeValue3.setDataType(STRING_DATATYPE);
+        fileName = FilenameUtils.removeExtension(fileName);
+        fileName = fileName + ".xml";
+        String name = fileName.substring(fileName.lastIndexOf("\\") + 1, fileName.length());
+        if ((name == null) || (name.equals(""))) {
+            name = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length());
+        }
+        attributeValue3.getContent().add(name);
+        assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
+        advice.getAttributeAssignmentExpression().add(assignment3);
+
+        AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
+        assignment4.setAttributeId("VersionNumber");
+        assignment4.setCategory(CATEGORY_RESOURCE);
+        assignment4.setIssuer("");
+
+        AttributeValueType configNameAttributeValue4 = new AttributeValueType();
+        configNameAttributeValue4.setDataType(STRING_DATATYPE);
+        configNameAttributeValue4.getContent().add(Integer.toString(version));
+        assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
+
+        advice.getAttributeAssignmentExpression().add(assignment4);
+
+        AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
+        assignment5.setAttributeId("matching:" + ONAPID);
+        assignment5.setCategory(CATEGORY_RESOURCE);
+        assignment5.setIssuer("");
+
+        AttributeValueType configNameAttributeValue5 = new AttributeValueType();
+        configNameAttributeValue5.setDataType(STRING_DATATYPE);
+        configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
+        assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
+
+        advice.getAttributeAssignmentExpression().add(assignment5);
 
         AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
         assignment7.setAttributeId("matching:service");
@@ -437,42 +437,42 @@ public class MicroServiceConfigPolicy extends Policy {
 
         Map<String, String> matchMap = getMatchMap();
         if (matchMap==null || matchMap.isEmpty()){
-               AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
-               assignment6.setAttributeId("matching:" + CONFIGID);
-               assignment6.setCategory(CATEGORY_RESOURCE);
-               assignment6.setIssuer("");
+            AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
+            assignment6.setAttributeId("matching:" + CONFIGID);
+            assignment6.setCategory(CATEGORY_RESOURCE);
+            assignment6.setIssuer("");
 
-               AttributeValueType configNameAttributeValue6 = new AttributeValueType();
-               configNameAttributeValue6.setDataType(STRING_DATATYPE);
-               configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
-               assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
+            AttributeValueType configNameAttributeValue6 = new AttributeValueType();
+            configNameAttributeValue6.setDataType(STRING_DATATYPE);
+            configNameAttributeValue6.getContent().add(policyAdapter.getConfigName());
+            assignment6.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue6));
 
-               advice.getAttributeAssignmentExpression().add(assignment6);
+            advice.getAttributeAssignmentExpression().add(assignment6);
 
 
-               AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
-               assignment8.setAttributeId("matching:uuid");
-               assignment8.setCategory(CATEGORY_RESOURCE);
-               assignment8.setIssuer("");
+            AttributeAssignmentExpressionType assignment8 = new AttributeAssignmentExpressionType();
+            assignment8.setAttributeId("matching:uuid");
+            assignment8.setCategory(CATEGORY_RESOURCE);
+            assignment8.setIssuer("");
 
-               AttributeValueType configNameAttributeValue8 = new AttributeValueType();
-               configNameAttributeValue8.setDataType(STRING_DATATYPE);
-               configNameAttributeValue8.getContent().add(policyAdapter.getUuid());
-               assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
+            AttributeValueType configNameAttributeValue8 = new AttributeValueType();
+            configNameAttributeValue8.setDataType(STRING_DATATYPE);
+            configNameAttributeValue8.getContent().add(policyAdapter.getUuid());
+            assignment8.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue8));
 
-               advice.getAttributeAssignmentExpression().add(assignment8);
+            advice.getAttributeAssignmentExpression().add(assignment8);
 
-               AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
-               assignment9.setAttributeId("matching:Location");
-               assignment9.setCategory(CATEGORY_RESOURCE);
-               assignment9.setIssuer("");
+            AttributeAssignmentExpressionType assignment9 = new AttributeAssignmentExpressionType();
+            assignment9.setAttributeId("matching:Location");
+            assignment9.setCategory(CATEGORY_RESOURCE);
+            assignment9.setIssuer("");
 
-               AttributeValueType configNameAttributeValue9 = new AttributeValueType();
-               configNameAttributeValue9.setDataType(STRING_DATATYPE);
-               configNameAttributeValue9.getContent().add(policyAdapter.getLocation());
-               assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
+            AttributeValueType configNameAttributeValue9 = new AttributeValueType();
+            configNameAttributeValue9.setDataType(STRING_DATATYPE);
+            configNameAttributeValue9.getContent().add(policyAdapter.getLocation());
+            assignment9.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue9));
 
-               advice.getAttributeAssignmentExpression().add(assignment9);
+            advice.getAttributeAssignmentExpression().add(assignment9);
         } else {
             for (Entry<String, String> matchValue : matchMap.entrySet()){
                 String value = matchValue.getValue();
@@ -496,73 +496,73 @@ public class MicroServiceConfigPolicy extends Policy {
             }
         }
         
-               AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
-               assignment10.setAttributeId("Priority");
-               assignment10.setCategory(CATEGORY_RESOURCE);
-               assignment10.setIssuer("");
-
-               AttributeValueType configNameAttributeValue10 = new AttributeValueType();
-               configNameAttributeValue10.setDataType(STRING_DATATYPE);
-               configNameAttributeValue10.getContent().add(policyAdapter.getPriority());
-               assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
-
-               advice.getAttributeAssignmentExpression().add(assignment10);
-               
-               //Risk Attributes
-               AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
-               assignment11.setAttributeId("RiskType");
-               assignment11.setCategory(CATEGORY_RESOURCE);
-               assignment11.setIssuer("");
-
-               AttributeValueType configNameAttributeValue11 = new AttributeValueType();
-               configNameAttributeValue11.setDataType(STRING_DATATYPE);
-               configNameAttributeValue11.getContent().add(policyAdapter.getRiskType());
-               assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
-
-               advice.getAttributeAssignmentExpression().add(assignment11);
-               
-               AttributeAssignmentExpressionType assignment12 = new AttributeAssignmentExpressionType();
-               assignment12.setAttributeId("RiskLevel");
-               assignment12.setCategory(CATEGORY_RESOURCE);
-               assignment12.setIssuer("");
-
-               AttributeValueType configNameAttributeValue12 = new AttributeValueType();
-               configNameAttributeValue12.setDataType(STRING_DATATYPE);
-               configNameAttributeValue12.getContent().add(policyAdapter.getRiskLevel());
-               assignment12.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue12));
-
-               advice.getAttributeAssignmentExpression().add(assignment12);    
-
-               AttributeAssignmentExpressionType assignment13 = new AttributeAssignmentExpressionType();
-               assignment13.setAttributeId("guard");
-               assignment13.setCategory(CATEGORY_RESOURCE);
-               assignment13.setIssuer("");
-
-               AttributeValueType configNameAttributeValue13 = new AttributeValueType();
-               configNameAttributeValue13.setDataType(STRING_DATATYPE);
-               configNameAttributeValue13.getContent().add(policyAdapter.getGuard());
-               assignment13.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue13));
-
-               advice.getAttributeAssignmentExpression().add(assignment13);
-               
-               AttributeAssignmentExpressionType assignment14 = new AttributeAssignmentExpressionType();
-               assignment14.setAttributeId("TTLDate");
-               assignment14.setCategory(CATEGORY_RESOURCE);
-               assignment14.setIssuer("");
-
-               AttributeValueType configNameAttributeValue14 = new AttributeValueType();
-               configNameAttributeValue14.setDataType(STRING_DATATYPE);
-               configNameAttributeValue14.getContent().add(policyAdapter.getTtlDate());
-               assignment14.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue14));
-
-               advice.getAttributeAssignmentExpression().add(assignment14);
-
-               advices.getAdviceExpression().add(advice);
-               return advices;
-       }
-
-       @Override
-       public Object getCorrectPolicyDataObject() {
-               return policyAdapter.getPolicyData();
-       }       
+        AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
+        assignment10.setAttributeId("Priority");
+        assignment10.setCategory(CATEGORY_RESOURCE);
+        assignment10.setIssuer("");
+
+        AttributeValueType configNameAttributeValue10 = new AttributeValueType();
+        configNameAttributeValue10.setDataType(STRING_DATATYPE);
+        configNameAttributeValue10.getContent().add(policyAdapter.getPriority());
+        assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
+
+        advice.getAttributeAssignmentExpression().add(assignment10);
+
+        //Risk Attributes
+        AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
+        assignment11.setAttributeId("RiskType");
+        assignment11.setCategory(CATEGORY_RESOURCE);
+        assignment11.setIssuer("");
+
+        AttributeValueType configNameAttributeValue11 = new AttributeValueType();
+        configNameAttributeValue11.setDataType(STRING_DATATYPE);
+        configNameAttributeValue11.getContent().add(policyAdapter.getRiskType());
+        assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
+
+        advice.getAttributeAssignmentExpression().add(assignment11);
+
+        AttributeAssignmentExpressionType assignment12 = new AttributeAssignmentExpressionType();
+        assignment12.setAttributeId("RiskLevel");
+        assignment12.setCategory(CATEGORY_RESOURCE);
+        assignment12.setIssuer("");
+
+        AttributeValueType configNameAttributeValue12 = new AttributeValueType();
+        configNameAttributeValue12.setDataType(STRING_DATATYPE);
+        configNameAttributeValue12.getContent().add(policyAdapter.getRiskLevel());
+        assignment12.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue12));
+
+        advice.getAttributeAssignmentExpression().add(assignment12);
+
+        AttributeAssignmentExpressionType assignment13 = new AttributeAssignmentExpressionType();
+        assignment13.setAttributeId("guard");
+        assignment13.setCategory(CATEGORY_RESOURCE);
+        assignment13.setIssuer("");
+
+        AttributeValueType configNameAttributeValue13 = new AttributeValueType();
+        configNameAttributeValue13.setDataType(STRING_DATATYPE);
+        configNameAttributeValue13.getContent().add(policyAdapter.getGuard());
+        assignment13.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue13));
+
+        advice.getAttributeAssignmentExpression().add(assignment13);
+
+        AttributeAssignmentExpressionType assignment14 = new AttributeAssignmentExpressionType();
+        assignment14.setAttributeId("TTLDate");
+        assignment14.setCategory(CATEGORY_RESOURCE);
+        assignment14.setIssuer("");
+
+        AttributeValueType configNameAttributeValue14 = new AttributeValueType();
+        configNameAttributeValue14.setDataType(STRING_DATATYPE);
+        configNameAttributeValue14.getContent().add(policyAdapter.getTtlDate());
+        assignment14.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue14));
+
+        advice.getAttributeAssignmentExpression().add(assignment14);
+
+        advices.getAdviceExpression().add(advice);
+        return advices;
+    }
+
+    @Override
+    public Object getCorrectPolicyDataObject() {
+        return policyAdapter.getPolicyData();
+    }
 }
index 18d588c..2719a15 100644 (file)
@@ -64,114 +64,114 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType; 
 
 public class OptimizationConfigPolicy extends Policy {
-       
-       private static final Logger LOGGER = FlexLogger.getLogger(OptimizationConfigPolicy.class);
-       
+
+    private static final Logger LOGGER = FlexLogger.getLogger(OptimizationConfigPolicy.class);
+
     private static Map<String, String> mapAttribute = new HashMap<>();
     private static Map<String, String> mapMatch = new HashMap<>();
 
-       private static synchronized Map<String, String> getMatchMap () {
-               return mapMatch;
-       }
-
-       private static synchronized void setMatchMap(Map<String, String> mm) {
-               mapMatch = mm;
-       }
-
-       public OptimizationConfigPolicy() {
-               super();
-       }
-       
-       public OptimizationConfigPolicy(PolicyRestAdapter policyAdapter){
-               this.policyAdapter = policyAdapter;
-       }
-
-       //save configuration of the policy based on the policyname
-       private void saveConfigurations(String policyName, String jsonBody) {
-               
-               if(policyName.endsWith(".xml")){
-                       policyName = policyName.replace(".xml", "");
-               }
-               
-               try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName +".json");){
-                       out.println(jsonBody);
-               } catch (Exception e) {
-                       LOGGER.error("Exception Occured While writing Configuration data"+e);
-               } 
-       }
-       
-       
-       @Override
-       public Map<String, String> savePolicies() throws PAPException {
-
-               Map<String, String> successMap = new HashMap<>();
-               if(isPolicyExists()){
-                       successMap.put("EXISTS", "This Policy already exist on the PAP");
-                       return successMap;
-               }
-
-               if(!isPreparedToSave()){
-                       //Prep and configure the policy for saving
-                       prepareToSave();
-               }
-
-               // Until here we prepared the data and here calling the method to create xml.
-               Path newPolicyPath = null;
-               newPolicyPath = Paths.get(policyAdapter.getNewFileName());
-
-               successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());  
-       
-               return successMap;              
-       }
-       
-       //This is the method for preparing the policy for saving.  We have broken it out
-       //separately because the fully configured policy is used for multiple things
-       @Override
-       public boolean prepareToSave() throws PAPException{
-
-               if(isPreparedToSave()){
-                       //we have already done this
-                       return true;
-               }
-               
-               int version = 0;
-               String policyID = policyAdapter.getPolicyID();
-               version = policyAdapter.getHighestVersion();
-               
-               // Create the Instance for pojo, PolicyType object is used in marshalling.
-               if (policyAdapter.getPolicyType().equals("Config")) {
-                       PolicyType policyConfig = new PolicyType();
-
-                       policyConfig.setVersion(Integer.toString(version));
-                       policyConfig.setPolicyId(policyID);
-                       policyConfig.setTarget(new TargetType());
-                       policyAdapter.setData(policyConfig);
-               }
-               policyName = policyAdapter.getNewFileName();
-               if (policyAdapter.getData() != null) {
-                       // Save the Configurations file with the policy name with extention based on selection.
-                       String jsonBody = policyAdapter.getJsonBody();
-                       saveConfigurations(policyName, jsonBody);
-                       
-                       // Make sure the filename ends with an extension
-                       if (!policyName.endsWith(".xml")) {
-                               policyName = policyName + ".xml";
-                       }
-                       
-       
-                       PolicyType configPolicy = (PolicyType) policyAdapter.getData();
-                       
-                       configPolicy.setDescription(policyAdapter.getPolicyDescription());
-
-                       configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
-                       
-                       AllOfType allOfOne = new AllOfType();
-                       String fileName = policyAdapter.getNewFileName();
-                       String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length());
-                       if ((name == null) || (name.equals(""))) {
-                               name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
-                       }
-                       
+    private static synchronized Map<String, String> getMatchMap () {
+        return mapMatch;
+    }
+
+    private static synchronized void setMatchMap(Map<String, String> mm) {
+        mapMatch = mm;
+    }
+
+    public OptimizationConfigPolicy() {
+        super();
+    }
+
+    public OptimizationConfigPolicy(PolicyRestAdapter policyAdapter){
+        this.policyAdapter = policyAdapter;
+    }
+
+    //save configuration of the policy based on the policyname
+    private void saveConfigurations(String policyName, String jsonBody) {
+
+        if(policyName.endsWith(".xml")){
+            policyName = policyName.replace(".xml", "");
+        }
+
+        try (PrintWriter out = new PrintWriter(CONFIG_HOME + File.separator + policyName +".json");){
+            out.println(jsonBody);
+        } catch (Exception e) {
+            LOGGER.error("Exception Occured While writing Configuration data"+e);
+        }
+    }
+
+
+    @Override
+    public Map<String, String> savePolicies() throws PAPException {
+
+        Map<String, String> successMap = new HashMap<>();
+        if(isPolicyExists()){
+            successMap.put("EXISTS", "This Policy already exist on the PAP");
+            return successMap;
+        }
+
+        if(!isPreparedToSave()){
+            //Prep and configure the policy for saving
+            prepareToSave();
+        }
+
+        // Until here we prepared the data and here calling the method to create xml.
+        Path newPolicyPath = null;
+        newPolicyPath = Paths.get(policyAdapter.getNewFileName());
+
+        successMap = createPolicy(newPolicyPath,getCorrectPolicyDataObject());
+
+        return successMap;
+    }
+
+    //This is the method for preparing the policy for saving.  We have broken it out
+    //separately because the fully configured policy is used for multiple things
+    @Override
+    public boolean prepareToSave() throws PAPException{
+
+        if(isPreparedToSave()){
+            //we have already done this
+            return true;
+        }
+
+        int version = 0;
+        String policyID = policyAdapter.getPolicyID();
+        version = policyAdapter.getHighestVersion();
+
+        // Create the Instance for pojo, PolicyType object is used in marshalling.
+        if (policyAdapter.getPolicyType().equals("Config")) {
+            PolicyType policyConfig = new PolicyType();
+
+            policyConfig.setVersion(Integer.toString(version));
+            policyConfig.setPolicyId(policyID);
+            policyConfig.setTarget(new TargetType());
+            policyAdapter.setData(policyConfig);
+        }
+        policyName = policyAdapter.getNewFileName();
+        if (policyAdapter.getData() != null) {
+            // Save the Configurations file with the policy name with extention based on selection.
+            String jsonBody = policyAdapter.getJsonBody();
+            saveConfigurations(policyName, jsonBody);
+
+            // Make sure the filename ends with an extension
+            if (!policyName.endsWith(".xml")) {
+                policyName = policyName + ".xml";
+            }
+
+
+            PolicyType configPolicy = (PolicyType) policyAdapter.getData();
+
+            configPolicy.setDescription(policyAdapter.getPolicyDescription());
+
+            configPolicy.setRuleCombiningAlgId(policyAdapter.getRuleCombiningAlgId());
+
+            AllOfType allOfOne = new AllOfType();
+            String fileName = policyAdapter.getNewFileName();
+            String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length());
+            if ((name == null) || (name.equals(""))) {
+                name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
+            }
+
             //setup values for pulling out matching attributes
             ObjectMapper mapper = new ObjectMapper();
             String matching = null;
@@ -198,114 +198,114 @@ public class OptimizationConfigPolicy extends Policy {
                 throw new PAPException(e1);
             }
             
-                       // Match for policyName
-                       allOfOne.getMatch().add(createMatch("PolicyName", name));
-                       
-                       AllOfType allOf = new AllOfType();
-               
-                       // Adding the matches to AllOfType element Match for Onap
-                       allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
-                       if (matchMap!=null && !matchMap.isEmpty()) {
-                               for (Entry<String, String> matchValue : matchMap.entrySet()){
-                                       String value = matchValue.getValue();
-                                       String key = matchValue.getKey().trim();
-                                       if (value.contains("matching-true") && mapAttribute.containsKey(key)){
-                                               allOf.getMatch().add(createDynamicMatch(key, mapAttribute.get(key)));
-                                       }
-                               }
-                       }
-                       
-                       // Match for riskType
-                       allOf.getMatch().add(
-                                       createDynamicMatch("RiskType", policyAdapter.getRiskType()));
-                       // Match for riskLevel
-                       allOf.getMatch().add(
-                                       createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
-                       // Match for riskguard
-                       allOf.getMatch().add(
-                                       createDynamicMatch("guard", policyAdapter.getGuard()));
-                       // Match for ttlDate
-                       allOf.getMatch().add(
-                                       createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
-
-                       AnyOfType anyOf = new AnyOfType();
-                       anyOf.getAllOf().add(allOfOne);
-                       anyOf.getAllOf().add(allOf);
-
-                       TargetType target = new TargetType();
-                       target.getAnyOf().add(anyOf);
-                       
-                       // Adding the target to the policy element
-                       configPolicy.setTarget((TargetType) target);
-
-                       RuleType rule = new RuleType();
-                       rule.setRuleId(policyAdapter.getRuleID());
-                       
-                       rule.setEffect(EffectType.PERMIT);
-                       
-                       // Create Target in Rule
-                       AllOfType allOfInRule = new AllOfType();
-
-                       // Creating match for ACCESS in rule target
-                       MatchType accessMatch = new MatchType();
-                       AttributeValueType accessAttributeValue = new AttributeValueType();
-                       accessAttributeValue.setDataType(STRING_DATATYPE);
-                       accessAttributeValue.getContent().add("ACCESS");
-                       accessMatch.setAttributeValue(accessAttributeValue);
-                       AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
-                       URI accessURI = null;
-                       try {
-                               accessURI = new URI(ACTION_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "OptimizationConfigPolicy", "Exception creating ACCESS URI");
-                       }
-                       accessAttributeDesignator.setCategory(CATEGORY_ACTION);
-                       accessAttributeDesignator.setDataType(STRING_DATATYPE);
-                       accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
-                       accessMatch.setAttributeDesignator(accessAttributeDesignator);
-                       accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       // Creating Config Match in rule Target
-                       MatchType configMatch = new MatchType();
-                       AttributeValueType configAttributeValue = new AttributeValueType();
-                       configAttributeValue.setDataType(STRING_DATATYPE);
-                       configAttributeValue.getContent().add("Config");
-                       configMatch.setAttributeValue(configAttributeValue);
-                       AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
-                       URI configURI = null;
-                       try {
-                               configURI = new URI(RESOURCE_ID);
-                       } catch (URISyntaxException e) {
-                               PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "OptimizationConfigPolicy", "Exception creating Config URI");
-                       }
-                       configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
-                       configAttributeDesignator.setDataType(STRING_DATATYPE);
-                       configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
-                       configMatch.setAttributeDesignator(configAttributeDesignator);
-                       configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
-
-                       allOfInRule.getMatch().add(accessMatch);
-                       allOfInRule.getMatch().add(configMatch);
-
-                       AnyOfType anyOfInRule = new AnyOfType();
-                       anyOfInRule.getAllOf().add(allOfInRule);
-
-                       TargetType targetInRule = new TargetType();
-                       targetInRule.getAnyOf().add(anyOfInRule);
-
-                       rule.setTarget(targetInRule);
-                       rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
-
-                       configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
-                       policyAdapter.setPolicyData(configPolicy);
-
-               } else {
-                       PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
-               }
-               setPreparedToSave(true);
-               return true;
-       }
-       
+            // Match for policyName
+            allOfOne.getMatch().add(createMatch("PolicyName", name));
+
+            AllOfType allOf = new AllOfType();
+
+            // Adding the matches to AllOfType element Match for Onap
+            allOf.getMatch().add(createMatch("ONAPName", policyAdapter.getOnapName()));
+            if (matchMap!=null && !matchMap.isEmpty()) {
+                for (Entry<String, String> matchValue : matchMap.entrySet()){
+                    String value = matchValue.getValue();
+                    String key = matchValue.getKey().trim();
+                    if (value.contains("matching-true") && mapAttribute.containsKey(key)){
+                        allOf.getMatch().add(createDynamicMatch(key, mapAttribute.get(key)));
+                    }
+                }
+            }
+
+            // Match for riskType
+            allOf.getMatch().add(
+                    createDynamicMatch("RiskType", policyAdapter.getRiskType()));
+            // Match for riskLevel
+            allOf.getMatch().add(
+                    createDynamicMatch("RiskLevel", String.valueOf(policyAdapter.getRiskLevel())));
+            // Match for riskguard
+            allOf.getMatch().add(
+                    createDynamicMatch("guard", policyAdapter.getGuard()));
+            // Match for ttlDate
+            allOf.getMatch().add(
+                    createDynamicMatch("TTLDate", policyAdapter.getTtlDate()));
+
+            AnyOfType anyOf = new AnyOfType();
+            anyOf.getAllOf().add(allOfOne);
+            anyOf.getAllOf().add(allOf);
+
+            TargetType target = new TargetType();
+            target.getAnyOf().add(anyOf);
+
+            // Adding the target to the policy element
+            configPolicy.setTarget((TargetType) target);
+
+            RuleType rule = new RuleType();
+            rule.setRuleId(policyAdapter.getRuleID());
+
+            rule.setEffect(EffectType.PERMIT);
+
+            // Create Target in Rule
+            AllOfType allOfInRule = new AllOfType();
+
+            // Creating match for ACCESS in rule target
+            MatchType accessMatch = new MatchType();
+            AttributeValueType accessAttributeValue = new AttributeValueType();
+            accessAttributeValue.setDataType(STRING_DATATYPE);
+            accessAttributeValue.getContent().add("ACCESS");
+            accessMatch.setAttributeValue(accessAttributeValue);
+            AttributeDesignatorType accessAttributeDesignator = new AttributeDesignatorType();
+            URI accessURI = null;
+            try {
+                accessURI = new URI(ACTION_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "OptimizationConfigPolicy", "Exception creating ACCESS URI");
+            }
+            accessAttributeDesignator.setCategory(CATEGORY_ACTION);
+            accessAttributeDesignator.setDataType(STRING_DATATYPE);
+            accessAttributeDesignator.setAttributeId(new IdentifierImpl(accessURI).stringValue());
+            accessMatch.setAttributeDesignator(accessAttributeDesignator);
+            accessMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            // Creating Config Match in rule Target
+            MatchType configMatch = new MatchType();
+            AttributeValueType configAttributeValue = new AttributeValueType();
+            configAttributeValue.setDataType(STRING_DATATYPE);
+            configAttributeValue.getContent().add("Config");
+            configMatch.setAttributeValue(configAttributeValue);
+            AttributeDesignatorType configAttributeDesignator = new AttributeDesignatorType();
+            URI configURI = null;
+            try {
+                configURI = new URI(RESOURCE_ID);
+            } catch (URISyntaxException e) {
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "OptimizationConfigPolicy", "Exception creating Config URI");
+            }
+            configAttributeDesignator.setCategory(CATEGORY_RESOURCE);
+            configAttributeDesignator.setDataType(STRING_DATATYPE);
+            configAttributeDesignator.setAttributeId(new IdentifierImpl(configURI).stringValue());
+            configMatch.setAttributeDesignator(configAttributeDesignator);
+            configMatch.setMatchId(FUNCTION_STRING_EQUAL_IGNORE);
+
+            allOfInRule.getMatch().add(accessMatch);
+            allOfInRule.getMatch().add(configMatch);
+
+            AnyOfType anyOfInRule = new AnyOfType();
+            anyOfInRule.getAllOf().add(allOfInRule);
+
+            TargetType targetInRule = new TargetType();
+            targetInRule.getAnyOf().add(anyOfInRule);
+
+            rule.setTarget(targetInRule);
+            rule.setAdviceExpressions(getAdviceExpressions(version, policyName));
+
+            configPolicy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
+            policyAdapter.setPolicyData(configPolicy);
+
+        } else {
+            PolicyLogger.error("Unsupported data object." + policyAdapter.getData().getClass().getCanonicalName());
+        }
+        setPreparedToSave(true);
+        return true;
+    }
+
     private void pullMatchValue(JsonNode rootNode) {
         Iterator<Map.Entry<String, JsonNode>> fieldsIterator = rootNode.fields();
         String newValue = null;
@@ -331,97 +331,97 @@ public class OptimizationConfigPolicy extends Policy {
        CommonClassDaoImpl dbConnection = new CommonClassDaoImpl();
        List<Object> result = dbConnection.getDataById(OptimizationModels.class, "modelName:version", modelName+":"+modelVersion);
        if(result != null && !result.isEmpty()){
-          OptimizationModels model = (OptimizationModels) result.get(0);
-          ruleTemplate = model.getAnnotation();
+           OptimizationModels model = (OptimizationModels) result.get(0);
+           ruleTemplate = model.getAnnotation();
        }
        return ruleTemplate;
    }
    
-       // Data required for Advice part is setting here.
-       private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
-               AdviceExpressionsType advices = new AdviceExpressionsType();
-               AdviceExpressionType advice = new AdviceExpressionType();
-               advice.setAdviceId("OptimizationID");
-               advice.setAppliesTo(EffectType.PERMIT);
-               
-               // For Configuration
-               AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
-               assignment1.setAttributeId("type");
-               assignment1.setCategory(CATEGORY_RESOURCE);
-               assignment1.setIssuer("");
-
-               AttributeValueType configNameAttributeValue = new AttributeValueType();
-               configNameAttributeValue.setDataType(STRING_DATATYPE);
-               configNameAttributeValue.getContent().add("Configuration");
-               assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
-
-               advice.getAttributeAssignmentExpression().add(assignment1);
-               
-               // For Config file Url if configurations are provided.
-               AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
-               assignment2.setAttributeId("URLID");
-               assignment2.setCategory(CATEGORY_RESOURCE);
-               assignment2.setIssuer("");
-
-               AttributeValueType attributeValue = new AttributeValueType();
-               attributeValue.setDataType(URI_DATATYPE);
-               String configName;
-               if(policyName.endsWith(".xml")){
-                       configName = policyName.replace(".xml", "");
-               }else{
-                       configName = policyName;
-               }
-               String content = CONFIG_URL +"/Config/" + configName + ".json";
-               attributeValue.getContent().add(content);
-               assignment2.setExpression(new ObjectFactory().createAttributeValue(attributeValue));
-
-               advice.getAttributeAssignmentExpression().add(assignment2);
-               
-               //PolicyName Attribute Assignment
-               AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
-               assignment3.setAttributeId("PolicyName");
-               assignment3.setCategory(CATEGORY_RESOURCE);
-               assignment3.setIssuer("");
-
-               AttributeValueType attributeValue3 = new AttributeValueType();
-               attributeValue3.setDataType(STRING_DATATYPE);
-               fileName = FilenameUtils.removeExtension(fileName);
-               fileName = fileName + ".xml";
-               String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length());
-               if ((name == null) || (name.equals(""))) {
-                       name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
-               }
-               attributeValue3.getContent().add(name);
-               assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
-               advice.getAttributeAssignmentExpression().add(assignment3);
-
-               //VersionNumber Attribute Assignment
-               AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
-               assignment4.setAttributeId("VersionNumber");
-               assignment4.setCategory(CATEGORY_RESOURCE);
-               assignment4.setIssuer("");
-
-               AttributeValueType configNameAttributeValue4 = new AttributeValueType();
-               configNameAttributeValue4.setDataType(STRING_DATATYPE);
-               configNameAttributeValue4.getContent().add(Integer.toString(version));
-               assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
-
-               advice.getAttributeAssignmentExpression().add(assignment4);
-
-               //OnapName Attribute Assignment
-               AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
-               assignment5.setAttributeId("matching:" + ONAPID);
-               assignment5.setCategory(CATEGORY_RESOURCE);
-               assignment5.setIssuer("");
-
-               AttributeValueType configNameAttributeValue5 = new AttributeValueType();
-               configNameAttributeValue5.setDataType(STRING_DATATYPE);
-               configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
-               assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
-
-               advice.getAttributeAssignmentExpression().add(assignment5);
-               
-               //ServiceType Attribute Assignment
+    // Data required for Advice part is setting here.
+    private AdviceExpressionsType getAdviceExpressions(int version, String fileName) {
+        AdviceExpressionsType advices = new AdviceExpressionsType();
+        AdviceExpressionType advice = new AdviceExpressionType();
+        advice.setAdviceId("OptimizationID");
+        advice.setAppliesTo(EffectType.PERMIT);
+
+        // For Configuration
+        AttributeAssignmentExpressionType assignment1 = new AttributeAssignmentExpressionType();
+        assignment1.setAttributeId("type");
+        assignment1.setCategory(CATEGORY_RESOURCE);
+        assignment1.setIssuer("");
+
+        AttributeValueType configNameAttributeValue = new AttributeValueType();
+        configNameAttributeValue.setDataType(STRING_DATATYPE);
+        configNameAttributeValue.getContent().add("Configuration");
+        assignment1.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue));
+
+        advice.getAttributeAssignmentExpression().add(assignment1);
+
+        // For Config file Url if configurations are provided.
+        AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
+        assignment2.setAttributeId("URLID");
+        assignment2.setCategory(CATEGORY_RESOURCE);
+        assignment2.setIssuer("");
+
+        AttributeValueType attributeValue = new AttributeValueType();
+        attributeValue.setDataType(URI_DATATYPE);
+        String configName;
+        if(policyName.endsWith(".xml")){
+            configName = policyName.replace(".xml", "");
+        }else{
+            configName = policyName;
+        }
+        String content = CONFIG_URL +"/Config/" + configName + ".json";
+        attributeValue.getContent().add(content);
+        assignment2.setExpression(new ObjectFactory().createAttributeValue(attributeValue));
+
+        advice.getAttributeAssignmentExpression().add(assignment2);
+
+        //PolicyName Attribute Assignment
+        AttributeAssignmentExpressionType assignment3 = new AttributeAssignmentExpressionType();
+        assignment3.setAttributeId("PolicyName");
+        assignment3.setCategory(CATEGORY_RESOURCE);
+        assignment3.setIssuer("");
+
+        AttributeValueType attributeValue3 = new AttributeValueType();
+        attributeValue3.setDataType(STRING_DATATYPE);
+        fileName = FilenameUtils.removeExtension(fileName);
+        fileName = fileName + ".xml";
+        String name = fileName.substring(fileName.lastIndexOf('\\') + 1, fileName.length());
+        if ((name == null) || (name.equals(""))) {
+            name = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length());
+        }
+        attributeValue3.getContent().add(name);
+        assignment3.setExpression(new ObjectFactory().createAttributeValue(attributeValue3));
+        advice.getAttributeAssignmentExpression().add(assignment3);
+
+        //VersionNumber Attribute Assignment
+        AttributeAssignmentExpressionType assignment4 = new AttributeAssignmentExpressionType();
+        assignment4.setAttributeId("VersionNumber");
+        assignment4.setCategory(CATEGORY_RESOURCE);
+        assignment4.setIssuer("");
+
+        AttributeValueType configNameAttributeValue4 = new AttributeValueType();
+        configNameAttributeValue4.setDataType(STRING_DATATYPE);
+        configNameAttributeValue4.getContent().add(Integer.toString(version));
+        assignment4.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue4));
+
+        advice.getAttributeAssignmentExpression().add(assignment4);
+
+        //OnapName Attribute Assignment
+        AttributeAssignmentExpressionType assignment5 = new AttributeAssignmentExpressionType();
+        assignment5.setAttributeId("matching:" + ONAPID);
+        assignment5.setCategory(CATEGORY_RESOURCE);
+        assignment5.setIssuer("");
+
+        AttributeValueType configNameAttributeValue5 = new AttributeValueType();
+        configNameAttributeValue5.setDataType(STRING_DATATYPE);
+        configNameAttributeValue5.getContent().add(policyAdapter.getOnapName());
+        assignment5.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue5));
+
+        advice.getAttributeAssignmentExpression().add(assignment5);
+
+        //ServiceType Attribute Assignment
         AttributeAssignmentExpressionType assignment7 = new AttributeAssignmentExpressionType();
         assignment7.setAttributeId("matching:service");
         assignment7.setCategory(CATEGORY_RESOURCE);
@@ -437,7 +437,7 @@ public class OptimizationConfigPolicy extends Policy {
         // Add matching attribute assignments if exist
         Map<String, String> matchMap = getMatchMap();
         if (matchMap!=null && !matchMap.isEmpty()) {
-               for (Entry<String, String> matchValue : matchMap.entrySet()){
+            for (Entry<String, String> matchValue : matchMap.entrySet()){
                 String value = matchValue.getValue();
                 String key = matchValue.getKey().trim();
                 if (value.contains("matching-true") && mapAttribute.containsKey(key)){
@@ -457,76 +457,76 @@ public class OptimizationConfigPolicy extends Policy {
         }
         
         // Priority Attribute Assignment
-               AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
-               assignment10.setAttributeId("Priority");
-               assignment10.setCategory(CATEGORY_RESOURCE);
-               assignment10.setIssuer("");
-
-               AttributeValueType configNameAttributeValue10 = new AttributeValueType();
-               configNameAttributeValue10.setDataType(STRING_DATATYPE);
-               configNameAttributeValue10.getContent().add(policyAdapter.getPriority());
-               assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
-
-               advice.getAttributeAssignmentExpression().add(assignment10);
-               
-               //RiskType Attribute Assignment
-               AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
-               assignment11.setAttributeId("RiskType");
-               assignment11.setCategory(CATEGORY_RESOURCE);
-               assignment11.setIssuer("");
-
-               AttributeValueType configNameAttributeValue11 = new AttributeValueType();
-               configNameAttributeValue11.setDataType(STRING_DATATYPE);
-               configNameAttributeValue11.getContent().add(policyAdapter.getRiskType());
-               assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
-
-               advice.getAttributeAssignmentExpression().add(assignment11);
-               
-               //RiskLevel Attribute Assignment
-               AttributeAssignmentExpressionType assignment12 = new AttributeAssignmentExpressionType();
-               assignment12.setAttributeId("RiskLevel");
-               assignment12.setCategory(CATEGORY_RESOURCE);
-               assignment12.setIssuer("");
-
-               AttributeValueType configNameAttributeValue12 = new AttributeValueType();
-               configNameAttributeValue12.setDataType(STRING_DATATYPE);
-               configNameAttributeValue12.getContent().add(policyAdapter.getRiskLevel());
-               assignment12.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue12));
-
-               advice.getAttributeAssignmentExpression().add(assignment12);    
-               
-               //Guard Attribute Assignment
-               AttributeAssignmentExpressionType assignment13 = new AttributeAssignmentExpressionType();
-               assignment13.setAttributeId("guard");
-               assignment13.setCategory(CATEGORY_RESOURCE);
-               assignment13.setIssuer("");
-
-               AttributeValueType configNameAttributeValue13 = new AttributeValueType();
-               configNameAttributeValue13.setDataType(STRING_DATATYPE);
-               configNameAttributeValue13.getContent().add(policyAdapter.getGuard());
-               assignment13.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue13));
-
-               advice.getAttributeAssignmentExpression().add(assignment13);
-               
-               //TTLDate Attribute Assignment
-               AttributeAssignmentExpressionType assignment14 = new AttributeAssignmentExpressionType();
-               assignment14.setAttributeId("TTLDate");
-               assignment14.setCategory(CATEGORY_RESOURCE);
-               assignment14.setIssuer("");
-
-               AttributeValueType configNameAttributeValue14 = new AttributeValueType();
-               configNameAttributeValue14.setDataType(STRING_DATATYPE);
-               configNameAttributeValue14.getContent().add(policyAdapter.getTtlDate());
-               assignment14.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue14));
-
-               advice.getAttributeAssignmentExpression().add(assignment14);
-
-               advices.getAdviceExpression().add(advice);
-               return advices;
-       }
-
-       @Override
-       public Object getCorrectPolicyDataObject() {
-               return policyAdapter.getPolicyData();
-       }       
+        AttributeAssignmentExpressionType assignment10 = new AttributeAssignmentExpressionType();
+        assignment10.setAttributeId("Priority");
+        assignment10.setCategory(CATEGORY_RESOURCE);
+        assignment10.setIssuer("");
+
+        AttributeValueType configNameAttributeValue10 = new AttributeValueType();
+        configNameAttributeValue10.setDataType(STRING_DATATYPE);
+        configNameAttributeValue10.getContent().add(policyAdapter.getPriority());
+        assignment10.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue10));
+
+        advice.getAttributeAssignmentExpression().add(assignment10);
+
+        //RiskType Attribute Assignment
+        AttributeAssignmentExpressionType assignment11 = new AttributeAssignmentExpressionType();
+        assignment11.setAttributeId("RiskType");
+        assignment11.setCategory(CATEGORY_RESOURCE);
+        assignment11.setIssuer("");
+
+        AttributeValueType configNameAttributeValue11 = new AttributeValueType();
+        configNameAttributeValue11.setDataType(STRING_DATATYPE);
+        configNameAttributeValue11.getContent().add(policyAdapter.getRiskType());
+        assignment11.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue11));
+
+        advice.getAttributeAssignmentExpression().add(assignment11);
+
+        //RiskLevel Attribute Assignment
+        AttributeAssignmentExpressionType assignment12 = new AttributeAssignmentExpressionType();
+        assignment12.setAttributeId("RiskLevel");
+        assignment12.setCategory(CATEGORY_RESOURCE);
+        assignment12.setIssuer("");
+
+        AttributeValueType configNameAttributeValue12 = new AttributeValueType();
+        configNameAttributeValue12.setDataType(STRING_DATATYPE);
+        configNameAttributeValue12.getContent().add(policyAdapter.getRiskLevel());
+        assignment12.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue12));
+
+        advice.getAttributeAssignmentExpression().add(assignment12);
+
+        //Guard Attribute Assignment
+        AttributeAssignmentExpressionType assignment13 = new AttributeAssignmentExpressionType();
+        assignment13.setAttributeId("guard");
+        assignment13.setCategory(CATEGORY_RESOURCE);
+        assignment13.setIssuer("");
+
+        AttributeValueType configNameAttributeValue13 = new AttributeValueType();
+        configNameAttributeValue13.setDataType(STRING_DATATYPE);
+        configNameAttributeValue13.getContent().add(policyAdapter.getGuard());
+        assignment13.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue13));
+
+        advice.getAttributeAssignmentExpression().add(assignment13);
+
+        //TTLDate Attribute Assignment
+        AttributeAssignmentExpressionType assignment14 = new AttributeAssignmentExpressionType();
+        assignment14.setAttributeId("TTLDate");
+        assignment14.setCategory(CATEGORY_RESOURCE);
+        assignment14.setIssuer("");
+
+        AttributeValueType configNameAttributeValue14 = new AttributeValueType();
+        configNameAttributeValue14.setDataType(STRING_DATATYPE);
+        configNameAttributeValue14.getContent().add(policyAdapter.getTtlDate());
+        assignment14.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue14));
+
+        advice.getAttributeAssignmentExpression().add(assignment14);
+
+        advices.getAdviceExpression().add(advice);
+        return advices;
+    }
+
+    @Override
+    public Object getCorrectPolicyDataObject() {
+        return policyAdapter.getPolicyData();
+    }
 }
index 8bfcab9..d6ace7c 100644 (file)
@@ -35,142 +35,142 @@ import com.att.research.xacml.api.pap.PAPException;
 
 public interface PolicyDBDaoTransaction {
 
-       /**
-        * Commits (makes permanent) the current transaction. Also, notifies other PolicyDBDao instances on other PAP servers of the update.
-        * @throws IllegalStateException if the PolicyDBDao transaction has not been used or has been committed already.
-        * @throws PersistenceException if the commit fails for some reason
-        */
-       public void commitTransaction();
-       
-       /**
-        * Create or update a policy
-        * @param policy A Policy object representing the policy to store or update
-        * @param username A string of the username you want to be stored for doing this operation
-        * @throws IllegalStateException If a transaction is open that has not yet been committed
-        * @throws PersistenceException If a database error occurs
-        * @throws IllegalArgumentException If the Policy's PolicyRestAdapter contains incorrect data.
-        */
-       public void createPolicy(Policy policy, String username) throws PolicyDBException;
-       
-       /**
-        * Check if the PolicyDBDaoTransaction is currently open
-        * @return False if the PolicyDBDao transaction has not been used or has been committed already, true if it is open.
-        */
-       public boolean isTransactionOpen();
-       
-       /**
-        * Rollback (undo) the current transaction.
-        */
-       public void rollbackTransaction();
-       
-       /**
-        * Close the PolicyDBDaoTransaction without rolling back or doing anything. Just used to close the EntityManager
-        */
-       public void close();
-       
-       
-       /**
-        * Create a new PDP group in the database
-        * @param groupID The ID to name the new group (use PolicyDBDao.createNewPDPGroupId)
-        * @param groupName The name to use for the new group
-        * @param groupDescription Description of the new group (optional)
-        * @param username Username of the user performing the operation
-        * @throws IllegalArgumentException If non-optional parameters are null or empty strings
-        * @throws IllegalStateException If a transaction is already open
-        * @throws PersistenceException If a database error occurs
-        */
-       public void createGroup(String groupID, String groupName, String groupDescription, String username) throws PolicyDBException;
-       
-       /**
-        * Updates a group in the database with a new name of description
-        * @param group The group with updated information. The id must match an existing group, but the name and description can be changed.
-        * @param username Username of the user performing the operation
-        * @throws IllegalArgumentException If non-optional parameters are null or empty strings
-        * @throws IllegalStateException If a transaction is already open
-        * @throws PersistenceException If a database error occurs or if the group can not be found
-        */
-       public void updateGroup(OnapPDPGroup group, String username) throws PolicyDBException;
-       
-       /**
-        * Updates a PDP in the database with new information
-        * @param pdp The PDP to update
-        * @param username Username of the user performing the operation
-        * @throws IllegalArgumentException If non-optional parameters are null or empty strings
-        * @throws IllegalStateException If a transaction is already open
-        * @throws PersistenceException If a database error occurs or if the pdp can not be found
-        */
-       public void updatePdp(OnapPDP pdp, String username) throws PolicyDBException;
-       
-       /**
-        * Change the default group in the database to the group provided.
-        * @param group The new group which should be set as default in the database
-        * @param username Username of the user performing the operation
-        * @throws IllegalArgumentException If non-optional parameters are null or empty strings
-        * @throws IllegalStateException If a transaction is already open
-        * @throws PersistenceException If a database error occurs
-        */
-       public void changeDefaultGroup(OnapPDPGroup group, String username) throws PolicyDBException;
-       
-       /**
-        * Moves a PDP to a new group.
-        * @param pdp The PDP which is to be moved to a new group
-        * @param group The new group which the PDP should be added to
-        * @param username Username of the user performing the operation
-        * @throws IllegalArgumentException If non-optional parameters are null or empty strings
-        * @throws IllegalStateException If a transaction is already open
-        * @throws PersistenceException If a database error occurs
-        */
-       public void movePdp(OnapPDP pdp, OnapPDPGroup group, String username) throws PolicyDBException;
-       
-       /**
-        * Add a new PDP to an existing group
-        * @param pdpID The ID to name the new PDP
-        * @param groupID The ID of the existing group to add the PDP to
-        * @param pdpName The name to use for the new PDP
-        * @param pdpDescription Description of the new PDP (optional)
-        * @param pdpJmxPort
-        * @param username Username of the user performing the operation
-        * @throws IllegalArgumentException If non-optional parameters are null or empty strings
-        * @throws IllegalStateException If a transaction is already open
-        * @throws PersistenceException If a database error occurs
-        */
-       public void addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int pdpJmxPort, String username) throws PolicyDBException;
-       
-       /**
-        * Add an existing policy to an existing group
-        * @param group The ID of the existing group to add the policy to
-        * @param policyID The ID of an existing policy
-        * @return 
-        * @throws IllegalArgumentException If non-optional parameters are null or empty strings
-        * @throws IllegalStateException If a transaction is already open
-        * @throws PersistenceException If a database error occurs
-        * @throws PolicyDBException 
-        */
-       public StdPDPGroup addPolicyToGroup(String group, String policyID, String username) throws PolicyDBException;
-       
-       
-       /**
-        * Delete an existing PDP groupPolicyDBException
-        * @param group A PDPGroup object representing the group to delete
-        * @param moveToGroup A PDPGroup object representing another existing group which PDPs in the group being deleted should be moved to
-        * @throws IllegalArgumentException If non-optional parameters are null or empty strings
-        * @throws IllegalStateException If a transaction is already open
-        * @throws PersistenceException If a database error occurs
-        * @throws PAPException If an error relating to how groups are handled occurs
-        */
-       public void deleteGroup(OnapPDPGroup group, OnapPDPGroup moveToGroup, String username)throws PolicyDBException;
-       
-       /**
-        * Removes an existing PDP from its group and deletes it.
-        * @param pdpID The ID of the existing PDP which should be deleted
-        * @throws IllegalArgumentException If non-optional parameters are null or empty strings
-        * @throws IllegalStateException If a transaction is already open
-        * @throws PersistenceException If a database error occurs
-        */
-       public void removePdpFromGroup(String pdpID, String username) throws PolicyDBException;
-       
-       public GroupEntity getGroup(long groupKey);
-       public GroupEntity getGroup(String groupId);
-       public List<?> getPdpsInGroup(long groupKey);
-       public PdpEntity getPdp(long pdpKey);
+    /**
+     * Commits (makes permanent) the current transaction. Also, notifies other PolicyDBDao instances on other PAP servers of the update.
+     * @throws IllegalStateException if the PolicyDBDao transaction has not been used or has been committed already.
+     * @throws PersistenceException if the commit fails for some reason
+     */
+    public void commitTransaction();
+
+    /**
+     * Create or update a policy
+     * @param policy A Policy object representing the policy to store or update
+     * @param username A string of the username you want to be stored for doing this operation
+     * @throws IllegalStateException If a transaction is open that has not yet been committed
+     * @throws PersistenceException If a database error occurs
+     * @throws IllegalArgumentException If the Policy's PolicyRestAdapter contains incorrect data.
+     */
+    public void createPolicy(Policy policy, String username) throws PolicyDBException;
+
+    /**
+     * Check if the PolicyDBDaoTransaction is currently open
+     * @return False if the PolicyDBDao transaction has not been used or has been committed already, true if it is open.
+     */
+    public boolean isTransactionOpen();
+
+    /**
+     * Rollback (undo) the current transaction.
+     */
+    public void rollbackTransaction();
+
+    /**
+     * Close the PolicyDBDaoTransaction without rolling back or doing anything. Just used to close the EntityManager
+     */
+    public void close();
+
+
+    /**
+     * Create a new PDP group in the database
+     * @param groupID The ID to name the new group (use PolicyDBDao.createNewPDPGroupId)
+     * @param groupName The name to use for the new group
+     * @param groupDescription Description of the new group (optional)
+     * @param username Username of the user performing the operation
+     * @throws IllegalArgumentException If non-optional parameters are null or empty strings
+     * @throws IllegalStateException If a transaction is already open
+     * @throws PersistenceException If a database error occurs
+     */
+    public void createGroup(String groupID, String groupName, String groupDescription, String username) throws PolicyDBException;
+
+    /**
+     * Updates a group in the database with a new name of description
+     * @param group The group with updated information. The id must match an existing group, but the name and description can be changed.
+     * @param username Username of the user performing the operation
+     * @throws IllegalArgumentException If non-optional parameters are null or empty strings
+     * @throws IllegalStateException If a transaction is already open
+     * @throws PersistenceException If a database error occurs or if the group can not be found
+     */
+    public void updateGroup(OnapPDPGroup group, String username) throws PolicyDBException;
+
+    /**
+     * Updates a PDP in the database with new information
+     * @param pdp The PDP to update
+     * @param username Username of the user performing the operation
+     * @throws IllegalArgumentException If non-optional parameters are null or empty strings
+     * @throws IllegalStateException If a transaction is already open
+     * @throws PersistenceException If a database error occurs or if the pdp can not be found
+     */
+    public void updatePdp(OnapPDP pdp, String username) throws PolicyDBException;
+
+    /**
+     * Change the default group in the database to the group provided.
+     * @param group The new group which should be set as default in the database
+     * @param username Username of the user performing the operation
+     * @throws IllegalArgumentException If non-optional parameters are null or empty strings
+     * @throws IllegalStateException If a transaction is already open
+     * @throws PersistenceException If a database error occurs
+     */
+    public void changeDefaultGroup(OnapPDPGroup group, String username) throws PolicyDBException;
+
+    /**
+     * Moves a PDP to a new group.
+     * @param pdp The PDP which is to be moved to a new group
+     * @param group The new group which the PDP should be added to
+     * @param username Username of the user performing the operation
+     * @throws IllegalArgumentException If non-optional parameters are null or empty strings
+     * @throws IllegalStateException If a transaction is already open
+     * @throws PersistenceException If a database error occurs
+     */
+    public void movePdp(OnapPDP pdp, OnapPDPGroup group, String username) throws PolicyDBException;
+
+    /**
+     * Add a new PDP to an existing group
+     * @param pdpID The ID to name the new PDP
+     * @param groupID The ID of the existing group to add the PDP to
+     * @param pdpName The name to use for the new PDP
+     * @param pdpDescription Description of the new PDP (optional)
+     * @param pdpJmxPort
+     * @param username Username of the user performing the operation
+     * @throws IllegalArgumentException If non-optional parameters are null or empty strings
+     * @throws IllegalStateException If a transaction is already open
+     * @throws PersistenceException If a database error occurs
+     */
+    public void addPdpToGroup(String pdpID, String groupID, String pdpName, String pdpDescription, int pdpJmxPort, String username) throws PolicyDBException;
+
+    /**
+     * Add an existing policy to an existing group
+     * @param group The ID of the existing group to add the policy to
+     * @param policyID The ID of an existing policy
+     * @return
+     * @throws IllegalArgumentException If non-optional parameters are null or empty strings
+     * @throws IllegalStateException If a transaction is already open
+     * @throws PersistenceException If a database error occurs
+     * @throws PolicyDBException
+     */
+    public StdPDPGroup addPolicyToGroup(String group, String policyID, String username) throws PolicyDBException;
+
+
+    /**
+     * Delete an existing PDP groupPolicyDBException
+     * @param group A PDPGroup object representing the group to delete
+     * @param moveToGroup A PDPGroup object representing another existing group which PDPs in the group being deleted should be moved to
+     * @throws IllegalArgumentException If non-optional parameters are null or empty strings
+     * @throws IllegalStateException If a transaction is already open
+     * @throws PersistenceException If a database error occurs
+     * @throws PAPException If an error relating to how groups are handled occurs
+     */
+    public void deleteGroup(OnapPDPGroup group, OnapPDPGroup moveToGroup, String username)throws PolicyDBException;
+
+    /**
+     * Removes an existing PDP from its group and deletes it.
+     * @param pdpID The ID of the existing PDP which should be deleted
+     * @throws IllegalArgumentException If non-optional parameters are null or empty strings
+     * @throws IllegalStateException If a transaction is already open
+     * @throws PersistenceException If a database error occurs
+     */
+    public void removePdpFromGroup(String pdpID, String username) throws PolicyDBException;
+
+    public GroupEntity getGroup(long groupKey);
+    public GroupEntity getGroup(String groupId);
+    public List<?> getPdpsInGroup(long groupKey);
+    public PdpEntity getPdp(long pdpKey);
 }
index ba5b002..7a0f708 100644 (file)
@@ -30,57 +30,57 @@ import org.yaml.snakeyaml.Yaml;
 import org.yaml.snakeyaml.constructor.Constructor;
 
 public class SafePolicyBuilder {
-       
-       private SafePolicyBuilder(){
-               //Private Constructor. 
-       }
 
-       public static ControlLoopGuard loadYamlGuard(String specification) {
-               //
-               // Read the yaml into our Java Object
-               //
-               PolicyLogger.info("Requested YAML to convert : " + specification);
-               Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class));
-               Object obj = yaml.load(specification);
-               return (ControlLoopGuard) obj;
-       }
-       
-       public static String generateXacmlGuard(String xacmlFileContent,Map<String, String> generateMap, List<String> blacklist, List<String> targets) {
-               //Setup default values and Targets. 
-               StringBuilder targetRegex= new StringBuilder(".*|");
-               if(targets!=null && !targets.isEmpty()){
-                       targetRegex = new StringBuilder();
+    private SafePolicyBuilder(){
+        //Private Constructor.
+    }
+
+    public static ControlLoopGuard loadYamlGuard(String specification) {
+        //
+        // Read the yaml into our Java Object
+        //
+        PolicyLogger.info("Requested YAML to convert : " + specification);
+        Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class));
+        Object obj = yaml.load(specification);
+        return (ControlLoopGuard) obj;
+    }
+
+    public static String generateXacmlGuard(String xacmlFileContent,Map<String, String> generateMap, List<String> blacklist, List<String> targets) {
+        //Setup default values and Targets.
+        StringBuilder targetRegex= new StringBuilder(".*|");
+        if(targets!=null && !targets.isEmpty()){
+            targetRegex = new StringBuilder();
             for(String t : targets){
-               targetRegex.append(t + "|");
+                targetRegex.append(t + "|");
+            }
+        }
+        if(generateMap.get("clname")==null|| generateMap.get("clname").isEmpty()){
+            generateMap.put("clname",".*");
+        }
+        generateMap.put("targets", targetRegex.toString().substring(0, targetRegex.length()-1));
+        // Replace values.
+        for(Map.Entry<String,String> map: generateMap.entrySet()){
+            Pattern p = Pattern.compile("\\$\\{" +map.getKey() +"\\}");
+            Matcher m = p.matcher(xacmlFileContent);
+            String finalInput = map.getValue();
+            if(finalInput.contains("$")){
+                finalInput = finalInput.replace("$", "\\$");
+            }
+            xacmlFileContent=m.replaceAll(finalInput);
+        }
+        if(blacklist!=null && !blacklist.isEmpty()){
+            StringBuilder rule = new StringBuilder();
+            for(String blackListName : blacklist){
+                if(blackListName.contains("$")){
+                    blackListName = blackListName.replace("$", "\\$");
+                }
+                rule.append("<AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">"+blackListName+"</AttributeValue>");
             }
-               }
-               if(generateMap.get("clname")==null|| generateMap.get("clname").isEmpty()){
-                       generateMap.put("clname",".*");
-               }
-               generateMap.put("targets", targetRegex.toString().substring(0, targetRegex.length()-1));
-               // Replace values. 
-               for(Map.Entry<String,String> map: generateMap.entrySet()){
-                       Pattern p = Pattern.compile("\\$\\{" +map.getKey() +"\\}");
-                       Matcher m = p.matcher(xacmlFileContent);
-                       String finalInput = map.getValue();
-                       if(finalInput.contains("$")){
-                               finalInput = finalInput.replace("$", "\\$");
-                       }
-                       xacmlFileContent=m.replaceAll(finalInput);
-               }
-               if(blacklist!=null && !blacklist.isEmpty()){
-                       StringBuilder rule = new StringBuilder();
-                       for(String blackListName : blacklist){
-                               if(blackListName.contains("$")){
-                                       blackListName = blackListName.replace("$", "\\$");
-                               }
-                               rule.append("<AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">"+blackListName+"</AttributeValue>");
-                       }
-                       Pattern p = Pattern.compile("\\$\\{blackListElement\\}");
-                       Matcher m = p.matcher(xacmlFileContent);
-                       xacmlFileContent=m.replaceAll(rule.toString());
-               }
-               PolicyLogger.info("Generated XACML from the YAML Spec: \n" + xacmlFileContent);
-               return xacmlFileContent;
-       }
+            Pattern p = Pattern.compile("\\$\\{blackListElement\\}");
+            Matcher m = p.matcher(xacmlFileContent);
+            xacmlFileContent=m.replaceAll(rule.toString());
+        }
+        PolicyLogger.info("Generated XACML from the YAML Spec: \n" + xacmlFileContent);
+        return xacmlFileContent;
+    }
 }
index 59a7ed3..8e62040 100644 (file)
@@ -44,116 +44,116 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 
 @Controller
 public class ActionPolicyDictionaryController {
-       
-       private static CommonClassDao commonClassDao;
-       private static String operation = "operation";
-       private static String attributeName = "attributeName";
-       private static String actionDatas = "actionPolicyDictionaryDatas";
-       
-       @Autowired
-       public ActionPolicyDictionaryController(CommonClassDao commonClassDao){
-               ActionPolicyDictionaryController.commonClassDao = commonClassDao;
-       }
-       
-       public void setCommonClassDao(CommonClassDao commonClassDao){
-               ActionPolicyDictionaryController.commonClassDao = commonClassDao;
-       }
-               
-       public ActionPolicyDictionaryController(){
-               super();
-       }
-
-       private DictionaryUtils getDictionaryUtilsInstance(){
-               return DictionaryUtils.getDictionaryUtils();
-       }
-       
-       @RequestMapping(value={"/get_ActionPolicyDictDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getActionEntitybyName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, actionDatas, attributeName, ActionPolicyDict.class);
-       }
-
-       @RequestMapping(value={"/get_ActionPolicyDictData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getActionPolicyDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, actionDatas, ActionPolicyDict.class);
-       }
-
-       @RequestMapping(value={"/action_dictionary/save_ActionDict"}, method={RequestMethod.POST})
-       public ModelAndView saveActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       ActionPolicyDict actionPolicyDict = null;
-                       ActionAdapter adapter = null;
-                       String userId = null;
-                       if(fromAPI){
-                               actionPolicyDict = mapper.readValue(root.get("dictionaryFields").toString(), ActionPolicyDict.class);
-                               adapter = mapper.readValue(root.get("dictionaryFields").toString(), ActionAdapter.class);
-                               userId = "API";
-                       }else{
-                               actionPolicyDict = mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionPolicyDict.class);
-                               adapter = mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionAdapter.class);
-                               userId = root.get("userid").textValue();
-                       }
-                       UserInfo userInfo = utils.getUserInfo(userId);
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(actionPolicyDict.getAttributeName(), attributeName, ActionPolicyDict.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               ActionPolicyDict data = (ActionPolicyDict) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       actionPolicyDict.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != actionPolicyDict.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       actionPolicyDict.setHeader(utils.appendKeyValue(adapter.getHeaders(), ":", "="));
-                       
-                       String responseString = null;
-                       if(!duplicateflag){
-                               actionPolicyDict.setUserModifiedBy(userInfo);
-                               if(actionPolicyDict.getId() == 0){
-                                       actionPolicyDict.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(actionPolicyDict);
-                               }else{
-                                       actionPolicyDict.setModifiedDate(new Date());
-                                       commonClassDao.update(actionPolicyDict); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(ActionPolicyDict.class));
-                       }else{
-                               responseString = "Duplicate";
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, actionDatas, responseString);
-                       }
-               }catch(Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/action_dictionary/remove_actionPolicyDict"}, method={RequestMethod.POST})
-       public void removeActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, actionDatas, ActionPolicyDict.class);
-       }
+
+    private static CommonClassDao commonClassDao;
+    private static String operation = "operation";
+    private static String attributeName = "attributeName";
+    private static String actionDatas = "actionPolicyDictionaryDatas";
+
+    @Autowired
+    public ActionPolicyDictionaryController(CommonClassDao commonClassDao){
+        ActionPolicyDictionaryController.commonClassDao = commonClassDao;
+    }
+
+    public void setCommonClassDao(CommonClassDao commonClassDao){
+        ActionPolicyDictionaryController.commonClassDao = commonClassDao;
+    }
+
+    public ActionPolicyDictionaryController(){
+        super();
+    }
+
+    private DictionaryUtils getDictionaryUtilsInstance(){
+        return DictionaryUtils.getDictionaryUtils();
+    }
+
+    @RequestMapping(value={"/get_ActionPolicyDictDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getActionEntitybyName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, actionDatas, attributeName, ActionPolicyDict.class);
+    }
+
+    @RequestMapping(value={"/get_ActionPolicyDictData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getActionPolicyDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, actionDatas, ActionPolicyDict.class);
+    }
+
+    @RequestMapping(value={"/action_dictionary/save_ActionDict"}, method={RequestMethod.POST})
+    public ModelAndView saveActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            ActionPolicyDict actionPolicyDict = null;
+            ActionAdapter adapter = null;
+            String userId = null;
+            if(fromAPI){
+                actionPolicyDict = mapper.readValue(root.get("dictionaryFields").toString(), ActionPolicyDict.class);
+                adapter = mapper.readValue(root.get("dictionaryFields").toString(), ActionAdapter.class);
+                userId = "API";
+            }else{
+                actionPolicyDict = mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionPolicyDict.class);
+                adapter = mapper.readValue(root.get("actionPolicyDictionaryData").toString(), ActionAdapter.class);
+                userId = root.get("userid").textValue();
+            }
+            UserInfo userInfo = utils.getUserInfo(userId);
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(actionPolicyDict.getAttributeName(), attributeName, ActionPolicyDict.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                ActionPolicyDict data = (ActionPolicyDict) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    actionPolicyDict.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != actionPolicyDict.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            actionPolicyDict.setHeader(utils.appendKeyValue(adapter.getHeaders(), ":", "="));
+
+            String responseString = null;
+            if(!duplicateflag){
+                actionPolicyDict.setUserModifiedBy(userInfo);
+                if(actionPolicyDict.getId() == 0){
+                    actionPolicyDict.setUserCreatedBy(userInfo);
+                    commonClassDao.save(actionPolicyDict);
+                }else{
+                    actionPolicyDict.setModifiedDate(new Date());
+                    commonClassDao.update(actionPolicyDict);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(ActionPolicyDict.class));
+            }else{
+                responseString = "Duplicate";
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, actionDatas, responseString);
+            }
+        }catch(Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/action_dictionary/remove_actionPolicyDict"}, method={RequestMethod.POST})
+    public void removeActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, actionDatas, ActionPolicyDict.class);
+    }
 }
 
 class ActionAdapter{
-       private List<Object> headers;
+    private List<Object> headers;
 
-       public List<Object> getHeaders() {
-               return headers;
-       }
+    public List<Object> getHeaders() {
+        return headers;
+    }
 
-       public void setHeaders(List<Object> headers) {
-               this.headers = headers;
-       }
+    public void setHeaders(List<Object> headers) {
+        this.headers = headers;
+    }
 }
index 0ab5cf9..a0044d2 100644 (file)
@@ -57,321 +57,321 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 
 @Controller
 public class BRMSDictionaryController{
-       
-       private static final Logger LOGGER  = FlexLogger.getLogger(BRMSDictionaryController.class);
 
-       private static final String VALIDATIONRESPONSE = "Validation";
+    private static final Logger LOGGER  = FlexLogger.getLogger(BRMSDictionaryController.class);
 
-       private static CommonClassDao commonClassDao;
-       private static String rule;
-       private static String successMsg = "Success";
-       private static String duplicateResponseString = "Duplicate";
-       private static String ruleName = "ruleName";
-       private static String errorMessage      = "Error";
-       private static String operation = "operation";
-       private static String dictionaryFields ="dictionaryFields";
-       private static String userid = "userid";
-       private static String dependencyName = "dependencyName";
-       private static String controllerName = "controllerName";
-       private static String brmsParamDatas = "brmsParamDictionaryDatas";
-       private static String brmsDependencyDatas = "brmsDependencyDictionaryDatas";
-       private static String brmsControllerDatas = "brmsControllerDictionaryDatas";
-       
-       @Autowired
-       public BRMSDictionaryController(CommonClassDao commonClassDao){
-               BRMSDictionaryController.commonClassDao = commonClassDao;
-       }
-       
-       public static void setCommonClassDao(CommonClassDao commonClassDao2) {
-               BRMSDictionaryController.commonClassDao = commonClassDao2;      
-       }
+    private static final String VALIDATIONRESPONSE = "Validation";
 
-       public BRMSDictionaryController() {
-               super();
-       }
-       
-       private DictionaryUtils getDictionaryUtilsInstance(){
-               return DictionaryUtils.getDictionaryUtils();
-       }
+    private static CommonClassDao commonClassDao;
+    private static String rule;
+    private static String successMsg = "Success";
+    private static String duplicateResponseString = "Duplicate";
+    private static String ruleName = "ruleName";
+    private static String errorMessage = "Error";
+    private static String operation = "operation";
+    private static String dictionaryFields ="dictionaryFields";
+    private static String userid = "userid";
+    private static String dependencyName = "dependencyName";
+    private static String controllerName = "controllerName";
+    private static String brmsParamDatas = "brmsParamDictionaryDatas";
+    private static String brmsDependencyDatas = "brmsDependencyDictionaryDatas";
+    private static String brmsControllerDatas = "brmsControllerDictionaryDatas";
+
+    @Autowired
+    public BRMSDictionaryController(CommonClassDao commonClassDao){
+        BRMSDictionaryController.commonClassDao = commonClassDao;
+    }
+
+    public static void setCommonClassDao(CommonClassDao commonClassDao2) {
+        BRMSDictionaryController.commonClassDao = commonClassDao2;
+    }
+
+    public BRMSDictionaryController() {
+        super();
+    }
+
+    private DictionaryUtils getDictionaryUtilsInstance(){
+        return DictionaryUtils.getDictionaryUtils();
+    }
+
+    @RequestMapping(value={"/get_BRMSParamDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getBRMSParamDictionaryByNameEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, brmsParamDatas, ruleName, BRMSParamTemplate.class);
+    }
+
+    @RequestMapping(value={"/get_BRMSParamData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getBRMSParamDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, brmsParamDatas, BRMSParamTemplate.class);
+    }
+
+    @RequestMapping(value={"/brms_dictionary/set_BRMSParamData"}, method={RequestMethod.POST})
+    public static void setRuleData(HttpServletRequest request) throws IOException{
+        StringWriter writer = new StringWriter();
+        IOUtils.copy(request.getInputStream() , writer, StandardCharsets.UTF_8);
+        String cleanStreamBoundary =  writer.toString().replaceFirst("------(.*)(?s).*octet-stream", "");
+        rule = cleanStreamBoundary.substring(0, cleanStreamBoundary.lastIndexOf("end")+4);
+    }
+
+    @RequestMapping(value={"/brms_dictionary/save_BRMSParam"}, method={RequestMethod.POST})
+    public ModelAndView saveBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
 
-       @RequestMapping(value={"/get_BRMSParamDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getBRMSParamDictionaryByNameEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, brmsParamDatas, ruleName, BRMSParamTemplate.class);
-       }
-       
-       @RequestMapping(value={"/get_BRMSParamData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getBRMSParamDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, brmsParamDatas, BRMSParamTemplate.class);
-       }
-       
-       @RequestMapping(value={"/brms_dictionary/set_BRMSParamData"}, method={RequestMethod.POST})
-       public static void setRuleData(HttpServletRequest request) throws IOException{
-               StringWriter writer = new StringWriter();
-               IOUtils.copy(request.getInputStream() , writer, StandardCharsets.UTF_8);
-               String cleanStreamBoundary =  writer.toString().replaceFirst("------(.*)(?s).*octet-stream", "");
-               rule = cleanStreamBoundary.substring(0, cleanStreamBoundary.lastIndexOf("end")+4);
-       }
-       
-       @RequestMapping(value={"/brms_dictionary/save_BRMSParam"}, method={RequestMethod.POST})
-       public ModelAndView saveBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       
             BRMSParamTemplate bRMSParamTemplateData;
             String userId = null;
             if(fromAPI){
-               bRMSParamTemplateData = mapper.readValue(root.get(dictionaryFields).toString(), BRMSParamTemplate.class);
-                               userId = "API";
-                       }else{
-                               bRMSParamTemplateData = mapper.readValue(root.get("brmsParamDictionaryData").toString(), BRMSParamTemplate.class);
-                               userId = root.get(userid).textValue();
-                       }
-                       UserInfo userInfo = utils.getUserInfo(userId);
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(bRMSParamTemplateData.getRuleName(), ruleName, BRMSParamTemplate.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               BRMSParamTemplate data = (BRMSParamTemplate) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       bRMSParamTemplateData.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != bRMSParamTemplateData.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
+                bRMSParamTemplateData = mapper.readValue(root.get(dictionaryFields).toString(), BRMSParamTemplate.class);
+                userId = "API";
+            }else{
+                bRMSParamTemplateData = mapper.readValue(root.get("brmsParamDictionaryData").toString(), BRMSParamTemplate.class);
+                userId = root.get(userid).textValue();
+            }
+            UserInfo userInfo = utils.getUserInfo(userId);
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(bRMSParamTemplateData.getRuleName(), ruleName, BRMSParamTemplate.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                BRMSParamTemplate data = (BRMSParamTemplate) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    bRMSParamTemplateData.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != bRMSParamTemplateData.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
             boolean validation = false;
             if(rule != null && CreateBRMSRuleTemplate.validateRuleParams(rule)){
-                       bRMSParamTemplateData.setRule(rule);
-                       validation = true;
-                       if(!duplicateflag){
-                               if(bRMSParamTemplateData.getId() == 0){
-                                       bRMSParamTemplateData.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(bRMSParamTemplateData);
-                               }else{
-                                       commonClassDao.update(bRMSParamTemplateData); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(BRMSParamTemplate.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
+                bRMSParamTemplateData.setRule(rule);
+                validation = true;
+                if(!duplicateflag){
+                    if(bRMSParamTemplateData.getId() == 0){
+                        bRMSParamTemplateData.setUserCreatedBy(userInfo);
+                        commonClassDao.save(bRMSParamTemplateData);
+                    }else{
+                        commonClassDao.update(bRMSParamTemplateData);
+                    }
+                    responseString = mapper.writeValueAsString(commonClassDao.getData(BRMSParamTemplate.class));
+                }else{
+                    responseString = duplicateResponseString;
+                }
+            }
+
+            if(!validation){
+                responseString = VALIDATIONRESPONSE;
             }
-                               
-                       if(!validation){
-                               responseString = VALIDATIONRESPONSE;
-                       }
-                       if(fromAPI){
-                               if (responseString!=null && !(duplicateResponseString).equals(responseString) && !VALIDATIONRESPONSE.equals(responseString)) {
+            if(fromAPI){
+                if (responseString!=null && !(duplicateResponseString).equals(responseString) && !VALIDATIONRESPONSE.equals(responseString)) {
                     responseString = successMsg;
                 }
                 ModelAndView result = new ModelAndView();
                 result.setViewName(responseString);
                 return result;
-                       }else{
-                               utils.setResponseData(response, brmsParamDatas, responseString);
-                       }
-               }catch(Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
+            }else{
+                utils.setResponseData(response, brmsParamDatas, responseString);
+            }
+        }catch(Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/brms_dictionary/remove_brmsParam"}, method={RequestMethod.POST})
+    public void removeBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response)throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, brmsParamDatas, BRMSParamTemplate.class);
+    }
 
-       @RequestMapping(value={"/brms_dictionary/remove_brmsParam"}, method={RequestMethod.POST})
-       public void removeBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response)throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, brmsParamDatas, BRMSParamTemplate.class);
-       }
-       
     @RequestMapping(value={"/get_BRMSDependencyDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getBRMSDependencyDictionaryByNameEntityData(HttpServletResponse response){
-       DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, brmsDependencyDatas, dependencyName, BRMSDependency.class);
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, brmsDependencyDatas, dependencyName, BRMSDependency.class);
     }
     
     @RequestMapping(value={"/get_BRMSDependencyData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getBRMSDependencyDictionaryEntityData(HttpServletResponse response){
-       DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, brmsDependencyDatas, BRMSDependency.class);
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, brmsDependencyDatas, BRMSDependency.class);
     }
     
     @RequestMapping(value={"/brms_dictionary/save_BRMSDependencyData"}, method={RequestMethod.POST})
     public ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-       DictionaryUtils utils = getDictionaryUtilsInstance();
-       try {
-               LOGGER.debug("DictionaryController:  saveBRMSDependencyDictionary() is called");
-               boolean fromAPI = utils.isRequestFromAPI(request);
-               ObjectMapper mapper = new ObjectMapper();
-               mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-               JsonNode root = mapper.readTree(request.getReader());
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            LOGGER.debug("DictionaryController:  saveBRMSDependencyDictionary() is called");
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
 
-               BRMSDependency brmsDependency;
-               String userId = null;
-               if(fromAPI){
-                       brmsDependency = mapper.readValue(root.get(dictionaryFields).toString(), BRMSDependency.class);
-                       userId = "API";
-               }else{
-                       brmsDependency = mapper.readValue(root.get("brmsDependencyDictionaryData").toString(), BRMSDependency.class);
-                       userId = root.get(userid).textValue();
-               }
-               UserInfo userInfo = utils.getUserInfo(userId);
+            BRMSDependency brmsDependency;
+            String userId = null;
+            if(fromAPI){
+                brmsDependency = mapper.readValue(root.get(dictionaryFields).toString(), BRMSDependency.class);
+                userId = "API";
+            }else{
+                brmsDependency = mapper.readValue(root.get("brmsDependencyDictionaryData").toString(), BRMSDependency.class);
+                userId = root.get(userid).textValue();
+            }
+            UserInfo userInfo = utils.getUserInfo(userId);
 
-               List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), dependencyName, BRMSDependency.class);
-               boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               BRMSDependency data = (BRMSDependency) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       brmsDependency.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != brmsDependency.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-               LOGGER.audit("the userId from the onap portal is: " + userId);
-               String responseString = null;
-               if(brmsDependency.getDependency()!=null && !("").equals(brmsDependency.getDependency().trim())){
-                       PEDependency dependency = null;
-                       try{
-                               dependency = PolicyUtils.jsonStringToObject(brmsDependency.getDependency(), PEDependency.class);
-                       }catch(Exception e){
-                               LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS PEDependency Dictionary : " + brmsDependency.getDependency(),e);
-                       }
-                       if(dependency==null){
-                               responseString = errorMessage;
-                       }else{
-                               if(!duplicateflag){
-                                       brmsDependency.setUserModifiedBy(userInfo);
-                                       if(brmsDependency.getId() == 0){
-                                               brmsDependency.setUserCreatedBy(userInfo);
-                                               commonClassDao.save(brmsDependency);
-                                       }else{
-                                               brmsDependency.setModifiedDate(new Date());
-                                               commonClassDao.update(brmsDependency); 
-                                       } 
-                                       responseString = mapper.writeValueAsString(commonClassDao.getData(BRMSDependency.class));
-                               }else{
-                                       responseString = duplicateResponseString;
-                               }
-                       }
-               }
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), dependencyName, BRMSDependency.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                BRMSDependency data = (BRMSDependency) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    brmsDependency.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != brmsDependency.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            LOGGER.audit("the userId from the onap portal is: " + userId);
+            String responseString = null;
+            if(brmsDependency.getDependency()!=null && !("").equals(brmsDependency.getDependency().trim())){
+                PEDependency dependency = null;
+                try{
+                    dependency = PolicyUtils.jsonStringToObject(brmsDependency.getDependency(), PEDependency.class);
+                }catch(Exception e){
+                    LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS PEDependency Dictionary : " + brmsDependency.getDependency(),e);
+                }
+                if(dependency==null){
+                    responseString = errorMessage;
+                }else{
+                    if(!duplicateflag){
+                        brmsDependency.setUserModifiedBy(userInfo);
+                        if(brmsDependency.getId() == 0){
+                            brmsDependency.setUserCreatedBy(userInfo);
+                            commonClassDao.save(brmsDependency);
+                        }else{
+                            brmsDependency.setModifiedDate(new Date());
+                            commonClassDao.update(brmsDependency);
+                        }
+                        responseString = mapper.writeValueAsString(commonClassDao.getData(BRMSDependency.class));
+                    }else{
+                        responseString = duplicateResponseString;
+                    }
+                }
+            }
 
-               if(fromAPI){
-                       if(responseString!=null && !duplicateResponseString.equals(responseString) && !errorMessage.equals(responseString)){
-                               responseString = successMsg;
-                       }
-                       ModelAndView result = new ModelAndView();
-                       result.setViewName(responseString);
-                       return result;
-               }else{
-                       utils.setResponseData(response, brmsDependencyDatas, responseString);
-               }
-       } catch (Exception e){
-               utils.setErrorResponseData(response, e);
-       }
-       return null;
+            if(fromAPI){
+                if(responseString!=null && !duplicateResponseString.equals(responseString) && !errorMessage.equals(responseString)){
+                    responseString = successMsg;
+                }
+                ModelAndView result = new ModelAndView();
+                result.setViewName(responseString);
+                return result;
+            }else{
+                utils.setResponseData(response, brmsDependencyDatas, responseString);
+            }
+        } catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
     }
  
     @RequestMapping(value={"/brms_dictionary/remove_brmsDependency"}, method={RequestMethod.POST})
     public void removeBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-       DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, brmsDependencyDatas, BRMSDependency.class);
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, brmsDependencyDatas, BRMSDependency.class);
     }
     
     
     @RequestMapping(value={"/get_BRMSControllerDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getBRMSControllerDictionaryByNameEntityData(HttpServletResponse response){
-       DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, brmsControllerDatas, controllerName, BRMSController.class);
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, brmsControllerDatas, controllerName, BRMSController.class);
     }
     
     @RequestMapping(value={"/get_BRMSControllerData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getBRMSControllerDictionaryEntityData(HttpServletResponse response){
-       DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, brmsControllerDatas, BRMSController.class);
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, brmsControllerDatas, BRMSController.class);
     }
     
     @RequestMapping(value={"/brms_dictionary/save_BRMSControllerData"}, method={RequestMethod.POST})
     public ModelAndView saveBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-       DictionaryUtils utils = getDictionaryUtilsInstance();
-       try {
-               LOGGER.debug("DictionaryController:  saveBRMSControllerDictionary() is called");
-               boolean fromAPI = utils.isRequestFromAPI(request);
-               ObjectMapper mapper = new ObjectMapper();
-               mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-               JsonNode root = mapper.readTree(request.getReader());
-               BRMSController brmsController;
-               String userId = null;
-               if(fromAPI){
-                       brmsController = mapper.readValue(root.get(dictionaryFields).toString(), BRMSController.class);
-                       userId = "API";
-               }else{
-                       brmsController = mapper.readValue(root.get("brmsControllerDictionaryData").toString(), BRMSController.class);
-                       userId = root.get(userid).textValue();
-               }
-               UserInfo userInfo = utils.getUserInfo(userId);
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            LOGGER.debug("DictionaryController:  saveBRMSControllerDictionary() is called");
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            BRMSController brmsController;
+            String userId = null;
+            if(fromAPI){
+                brmsController = mapper.readValue(root.get(dictionaryFields).toString(), BRMSController.class);
+                userId = "API";
+            }else{
+                brmsController = mapper.readValue(root.get("brmsControllerDictionaryData").toString(), BRMSController.class);
+                userId = root.get(userid).textValue();
+            }
+            UserInfo userInfo = utils.getUserInfo(userId);
 
-               List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(brmsController.getControllerName(), controllerName, BRMSController.class);
-               boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               BRMSController data = (BRMSController) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       brmsController.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != brmsController.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-               String responseString = null;
-               if(brmsController.getController()!=null && !("").equals(brmsController.getController().trim())){
-                       PEDependency dependency = null;
-                       try{
-                               dependency = PolicyUtils.jsonStringToObject(brmsController.getController(), PEDependency.class);
-                       }catch(Exception e){
-                               LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS Controller Dictionary : " + brmsController.getController(),e);
-                       }
-                       if(dependency==null){
-                               responseString = errorMessage;
-                       }else{
-                               if(!duplicateflag){
-                                       brmsController.setUserModifiedBy(userInfo);
-                                       if(brmsController.getId() == 0){
-                                               brmsController.setUserCreatedBy(userInfo);
-                                               commonClassDao.save(brmsController);
-                                       }else{
-                                               brmsController.setModifiedDate(new Date());
-                                               commonClassDao.update(brmsController); 
-                                       } 
-                                       responseString = mapper.writeValueAsString(commonClassDao.getData(OnapName.class));
-                               }else{
-                                       responseString = duplicateResponseString;
-                               }
-                       }
-               }
-               if(fromAPI){
-                       if (responseString!=null && !(duplicateResponseString).equals(responseString) && !(errorMessage).equals(responseString)) {
-                               responseString = successMsg;
-                       }
-                       ModelAndView result = new ModelAndView();
-                       result.setViewName(responseString);
-                       return result;
-               }else{
-                       utils.setResponseData(response, brmsControllerDatas, responseString);
-               }
-       } catch (Exception e){
-               utils.setErrorResponseData(response, e);
-       }
-       return null;
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(brmsController.getControllerName(), controllerName, BRMSController.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                BRMSController data = (BRMSController) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    brmsController.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != brmsController.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(brmsController.getController()!=null && !("").equals(brmsController.getController().trim())){
+                PEDependency dependency = null;
+                try{
+                    dependency = PolicyUtils.jsonStringToObject(brmsController.getController(), PEDependency.class);
+                }catch(Exception e){
+                    LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS Controller Dictionary : " + brmsController.getController(),e);
+                }
+                if(dependency==null){
+                    responseString = errorMessage;
+                }else{
+                    if(!duplicateflag){
+                        brmsController.setUserModifiedBy(userInfo);
+                        if(brmsController.getId() == 0){
+                            brmsController.setUserCreatedBy(userInfo);
+                            commonClassDao.save(brmsController);
+                        }else{
+                            brmsController.setModifiedDate(new Date());
+                            commonClassDao.update(brmsController);
+                        }
+                        responseString = mapper.writeValueAsString(commonClassDao.getData(OnapName.class));
+                    }else{
+                        responseString = duplicateResponseString;
+                    }
+                }
+            }
+            if(fromAPI){
+                if (responseString!=null && !(duplicateResponseString).equals(responseString) && !(errorMessage).equals(responseString)) {
+                    responseString = successMsg;
+                }
+                ModelAndView result = new ModelAndView();
+                result.setViewName(responseString);
+                return result;
+            }else{
+                utils.setResponseData(response, brmsControllerDatas, responseString);
+            }
+        } catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
     }
  
     @RequestMapping(value={"/brms_dictionary/remove_brmsController"}, method={RequestMethod.POST})
     public void removeBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-       DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, brmsControllerDatas, BRMSController.class);
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, brmsControllerDatas, BRMSController.class);
     }
     
     public BRMSDependency getDependencyDataByID(String dependencyName){
index 5d28c82..5e7113a 100644 (file)
@@ -53,250 +53,250 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 @Controller
 public class ClosedLoopDictionaryController{
 
-       private static CommonClassDao commonClassDao;
-       private static String vsclaction = "vsclaction";
-       private static String operation = "operation";
-       private static String vnftype = "vnftype";
-       private static String pepName = "pepName";
-       private static String varbindName = "varbindName";
-       private static String serviceName = "serviceName";
-       private static String siteName = "siteName";
-       private static String dictionaryFields = "dictionaryFields";
-       private static String duplicateResponseString = "Duplicate";
-       private static String userid = "userid";
-       private static String vsclActionDatas = "vsclActionDictionaryDatas";
-       private static String vnfTypeDatas = "vnfTypeDictionaryDatas";
-       private static String pepOptionDatas = "pepOptionsDictionaryDatas";
-       private static String varbindDatas = "varbindDictionaryDatas";
-       private static String closedLoopDatas = "closedLoopServiceDictionaryDatas";
-       private static String closedLoopSiteDatas = "closedLoopSiteDictionaryDatas";
-       
-       @Autowired
-       public ClosedLoopDictionaryController(CommonClassDao commonClassDao){
-               ClosedLoopDictionaryController.commonClassDao = commonClassDao;
-       }
-       
-       public void setCommonClassDao(CommonClassDao commonClassDao){
-               ClosedLoopDictionaryController.commonClassDao = commonClassDao;
-       }
-
-       public static void setCommonClassDao(CommonClassDaoImpl commonClassDaoImpl) {
+    private static CommonClassDao commonClassDao;
+    private static String vsclaction = "vsclaction";
+    private static String operation = "operation";
+    private static String vnftype = "vnftype";
+    private static String pepName = "pepName";
+    private static String varbindName = "varbindName";
+    private static String serviceName = "serviceName";
+    private static String siteName = "siteName";
+    private static String dictionaryFields = "dictionaryFields";
+    private static String duplicateResponseString = "Duplicate";
+    private static String userid = "userid";
+    private static String vsclActionDatas = "vsclActionDictionaryDatas";
+    private static String vnfTypeDatas = "vnfTypeDictionaryDatas";
+    private static String pepOptionDatas = "pepOptionsDictionaryDatas";
+    private static String varbindDatas = "varbindDictionaryDatas";
+    private static String closedLoopDatas = "closedLoopServiceDictionaryDatas";
+    private static String closedLoopSiteDatas = "closedLoopSiteDictionaryDatas";
+
+    @Autowired
+    public ClosedLoopDictionaryController(CommonClassDao commonClassDao){
+        ClosedLoopDictionaryController.commonClassDao = commonClassDao;
+    }
+
+    public void setCommonClassDao(CommonClassDao commonClassDao){
+        ClosedLoopDictionaryController.commonClassDao = commonClassDao;
+    }
+
+    public static void setCommonClassDao(CommonClassDaoImpl commonClassDaoImpl) {
         commonClassDao = commonClassDaoImpl;
     }
-       
-       public ClosedLoopDictionaryController(){
-               super();
-       }
-
-       private DictionaryUtils getDictionaryUtilsInstance(){
-               return DictionaryUtils.getDictionaryUtils();
-       }
-       
-       @RequestMapping(value={"/get_VSCLActionDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, vsclActionDatas, vsclaction, VSCLAction.class);
-       }
-
-
-       @RequestMapping(value={"/get_VSCLActionData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getVSCLActionDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, vsclActionDatas, VSCLAction.class);
-       }
-
-       @RequestMapping(value={"/get_VNFTypeDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, vnfTypeDatas, vnftype, VNFType.class);
-       }
-
-       @RequestMapping(value={"/get_VNFTypeData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getVNFTypeDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, vnfTypeDatas, VNFType.class);
-       }
-
-       @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, pepOptionDatas, pepName, PEPOptions.class);
-       }
-
-       @RequestMapping(value={"/get_PEPOptionsData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getPEPOptionsDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, pepOptionDatas, PEPOptions.class);
-       }
-
-       @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getVarbindDictionaryByNameEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, varbindDatas, varbindName, VarbindDictionary.class);
-       }
-
-       @RequestMapping(value={"/get_VarbindDictionaryData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getVarbindDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, varbindDatas, VarbindDictionary.class);
-       }
-
-       @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, closedLoopDatas, serviceName, ClosedLoopD2Services.class);
-       }
-
-       @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, closedLoopDatas, ClosedLoopD2Services.class);
-       }
-
-       @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, closedLoopSiteDatas, siteName, ClosedLoopSite.class);
-       }
-
-       @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, closedLoopSiteDatas, ClosedLoopSite.class);
-       }
-
-       @RequestMapping(value={"/cl_dictionary/save_vsclAction"}, method={RequestMethod.POST})
-       public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response)throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       VSCLAction vSCLAction;
-                       String userId = null;
-                       if (fromAPI) {
-                               vSCLAction = mapper.readValue(root.get(dictionaryFields).toString(), VSCLAction.class);
-                               userId = "API";
-                       } else {
-                               vSCLAction = mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class);
-                               userId = root.get(userid).textValue();
-                       }
-                       UserInfo userInfo = utils.getUserInfo(userId);
-
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               VSCLAction data = (VSCLAction) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       vSCLAction.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != vSCLAction.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               vSCLAction.setUserModifiedBy(userInfo);
-                               if(vSCLAction.getId() == 0){
-                                       vSCLAction.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(vSCLAction);
-                               }else{
-                                       vSCLAction.setModifiedDate(new Date());
-                                       commonClassDao.update(vSCLAction); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, vsclActionDatas, responseString);
-                       }
-               }catch(Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/cl_dictionary/remove_VsclAction"}, method={RequestMethod.POST})
-       public void removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, vsclActionDatas, OnapName.class);
-       }
-
-       @RequestMapping(value={"/cl_dictionary/save_vnfType"}, method={RequestMethod.POST})
-       public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       VNFType vNFType;
-                       String userId = null;
-                       if (fromAPI) {
-                               vNFType = mapper.readValue(root.get(dictionaryFields).toString(), VNFType.class);
-                               userId = "API";
-                       } else {
-                               vNFType = mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class);
-                               userId = root.get(userid).textValue();
-                       }
-                       UserInfo userInfo = utils.getUserInfo(userId);
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               VNFType data = (VNFType) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       vNFType.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != vNFType.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               vNFType.setUserModifiedBy(userInfo);
-                               if(vNFType.getId() == 0){
-                                       vNFType.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(vNFType);
-                               }else{
-                                       vNFType.setModifiedDate(new Date());
-                                       commonClassDao.update(vNFType); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-        
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, vnfTypeDatas, responseString);
-                       }
-               }catch(Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/cl_dictionary/remove_vnfType"}, method={RequestMethod.POST})
-       public void removeVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, vnfTypeDatas, VNFType.class);
-       }
-
-       @RequestMapping(value={"/cl_dictionary/save_pepOptions"}, method={RequestMethod.POST})
-       public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
+
+    public ClosedLoopDictionaryController(){
+        super();
+    }
+
+    private DictionaryUtils getDictionaryUtilsInstance(){
+        return DictionaryUtils.getDictionaryUtils();
+    }
+
+    @RequestMapping(value={"/get_VSCLActionDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, vsclActionDatas, vsclaction, VSCLAction.class);
+    }
+
+
+    @RequestMapping(value={"/get_VSCLActionData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getVSCLActionDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, vsclActionDatas, VSCLAction.class);
+    }
+
+    @RequestMapping(value={"/get_VNFTypeDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, vnfTypeDatas, vnftype, VNFType.class);
+    }
+
+    @RequestMapping(value={"/get_VNFTypeData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getVNFTypeDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, vnfTypeDatas, VNFType.class);
+    }
+
+    @RequestMapping(value={"/get_PEPOptionsDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, pepOptionDatas, pepName, PEPOptions.class);
+    }
+
+    @RequestMapping(value={"/get_PEPOptionsData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getPEPOptionsDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, pepOptionDatas, PEPOptions.class);
+    }
+
+    @RequestMapping(value={"/get_VarbindDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getVarbindDictionaryByNameEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, varbindDatas, varbindName, VarbindDictionary.class);
+    }
+
+    @RequestMapping(value={"/get_VarbindDictionaryData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getVarbindDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, varbindDatas, VarbindDictionary.class);
+    }
+
+    @RequestMapping(value={"/get_ClosedLoopServicesDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, closedLoopDatas, serviceName, ClosedLoopD2Services.class);
+    }
+
+    @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, closedLoopDatas, ClosedLoopD2Services.class);
+    }
+
+    @RequestMapping(value={"/get_ClosedLoopSiteDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, closedLoopSiteDatas, siteName, ClosedLoopSite.class);
+    }
+
+    @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, closedLoopSiteDatas, ClosedLoopSite.class);
+    }
+
+    @RequestMapping(value={"/cl_dictionary/save_vsclAction"}, method={RequestMethod.POST})
+    public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response)throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            VSCLAction vSCLAction;
+            String userId = null;
+            if (fromAPI) {
+                vSCLAction = mapper.readValue(root.get(dictionaryFields).toString(), VSCLAction.class);
+                userId = "API";
+            } else {
+                vSCLAction = mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class);
+                userId = root.get(userid).textValue();
+            }
+            UserInfo userInfo = utils.getUserInfo(userId);
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                VSCLAction data = (VSCLAction) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    vSCLAction.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != vSCLAction.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                vSCLAction.setUserModifiedBy(userInfo);
+                if(vSCLAction.getId() == 0){
+                    vSCLAction.setUserCreatedBy(userInfo);
+                    commonClassDao.save(vSCLAction);
+                }else{
+                    vSCLAction.setModifiedDate(new Date());
+                    commonClassDao.update(vSCLAction);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, vsclActionDatas, responseString);
+            }
+        }catch(Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/cl_dictionary/remove_VsclAction"}, method={RequestMethod.POST})
+    public void removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, vsclActionDatas, OnapName.class);
+    }
+
+    @RequestMapping(value={"/cl_dictionary/save_vnfType"}, method={RequestMethod.POST})
+    public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            VNFType vNFType;
+            String userId = null;
+            if (fromAPI) {
+                vNFType = mapper.readValue(root.get(dictionaryFields).toString(), VNFType.class);
+                userId = "API";
+            } else {
+                vNFType = mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class);
+                userId = root.get(userid).textValue();
+            }
+            UserInfo userInfo = utils.getUserInfo(userId);
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                VNFType data = (VNFType) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    vNFType.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != vNFType.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                vNFType.setUserModifiedBy(userInfo);
+                if(vNFType.getId() == 0){
+                    vNFType.setUserCreatedBy(userInfo);
+                    commonClassDao.save(vNFType);
+                }else{
+                    vNFType.setModifiedDate(new Date());
+                    commonClassDao.update(vNFType);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, vnfTypeDatas, responseString);
+            }
+        }catch(Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/cl_dictionary/remove_vnfType"}, method={RequestMethod.POST})
+    public void removeVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, vnfTypeDatas, VNFType.class);
+    }
+
+    @RequestMapping(value={"/cl_dictionary/save_pepOptions"}, method={RequestMethod.POST})
+    public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
             PEPOptions pEPOptions;
             GridData gridData;
             String userId = null;
@@ -305,240 +305,240 @@ public class ClosedLoopDictionaryController{
                 gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
                 userId = "API";
             }else{
-               pEPOptions = mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class);
-               gridData = mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class);
-               userId = root.get(userid).textValue();
+                pEPOptions = mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class);
+                gridData = mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class);
+                userId = root.get(userid).textValue();
             }
             UserInfo userInfo = utils.getUserInfo(userId);
             
-                       if(!gridData.getAttributes().isEmpty()){
-                               pEPOptions.setActions(utils.appendKeyValue(gridData.getAttributes(), ":#@", "=#@"));
-                       }
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               PEPOptions data = (PEPOptions) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       pEPOptions.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != pEPOptions.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               pEPOptions.setUserModifiedBy(userInfo);
-                               if(pEPOptions.getId() == 0){
-                                       pEPOptions.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(pEPOptions);
-                               }else{
-                                       pEPOptions.setModifiedDate(new Date());
-                                       commonClassDao.update(pEPOptions); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, pepOptionDatas, responseString);
-                       }
+            if(!gridData.getAttributes().isEmpty()){
+                pEPOptions.setActions(utils.appendKeyValue(gridData.getAttributes(), ":#@", "=#@"));
+            }
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                PEPOptions data = (PEPOptions) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    pEPOptions.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != pEPOptions.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                pEPOptions.setUserModifiedBy(userInfo);
+                if(pEPOptions.getId() == 0){
+                    pEPOptions.setUserCreatedBy(userInfo);
+                    commonClassDao.save(pEPOptions);
+                }else{
+                    pEPOptions.setModifiedDate(new Date());
+                    commonClassDao.update(pEPOptions);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, pepOptionDatas, responseString);
+            }
         }catch(Exception e){
-               utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/cl_dictionary/remove_pepOptions"}, method={RequestMethod.POST})
-       public void removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, pepOptionDatas, VNFType.class);
-       }
-
-       @RequestMapping(value={"/cl_dictionary/save_service"}, method={RequestMethod.POST})
-       public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/cl_dictionary/remove_pepOptions"}, method={RequestMethod.POST})
+    public void removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, pepOptionDatas, VNFType.class);
+    }
+
+    @RequestMapping(value={"/cl_dictionary/save_service"}, method={RequestMethod.POST})
+    public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
             ClosedLoopD2Services serviceData;
             String userId = null;
             if(fromAPI){
                 serviceData = mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.class);
                 userId = "API";
             } else {
-               serviceData = mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class);
-               userId = root.get(userid).textValue();
+                serviceData = mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class);
+                userId = root.get(userid).textValue();
             }
             UserInfo userInfo = utils.getUserInfo(userId);
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       serviceData.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != serviceData.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               serviceData.setUserModifiedBy(userInfo);
-                               if(serviceData.getId() == 0){
-                                       serviceData.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(serviceData);
-                               }else{
-                                       serviceData.setModifiedDate(new Date());
-                                       commonClassDao.update(serviceData); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    serviceData.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != serviceData.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                serviceData.setUserModifiedBy(userInfo);
+                if(serviceData.getId() == 0){
+                    serviceData.setUserCreatedBy(userInfo);
+                    commonClassDao.save(serviceData);
+                }else{
+                    serviceData.setModifiedDate(new Date());
+                    commonClassDao.update(serviceData);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
             if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, closedLoopDatas, responseString);
-                       }
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, closedLoopDatas, responseString);
+            }
         }catch(Exception e){
-               utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/cl_dictionary/remove_Service"}, method={RequestMethod.POST})
-       public void removeServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, closedLoopDatas, VNFType.class);
-       }
-
-       @RequestMapping(value={"/cl_dictionary/save_siteName"}, method={RequestMethod.POST})
-       public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/cl_dictionary/remove_Service"}, method={RequestMethod.POST})
+    public void removeServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, closedLoopDatas, VNFType.class);
+    }
+
+    @RequestMapping(value={"/cl_dictionary/save_siteName"}, method={RequestMethod.POST})
+    public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
             ClosedLoopSite siteData;
             String userId = null;
             if(fromAPI){
                 siteData = mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopSite.class);
                 userId = "API";
             }else{
-               siteData = mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class);
-               userId = root.get(userid).textValue();
+                siteData = mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class);
+                userId = root.get(userid).textValue();
             }
             UserInfo userInfo = utils.getUserInfo(userId);
             
             List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               ClosedLoopSite data = (ClosedLoopSite) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       siteData.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != siteData.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                ClosedLoopSite data = (ClosedLoopSite) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    siteData.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != siteData.getId()))){
+                    duplicateflag = true;
+                }
+            }
             String responseString = null;
-                       if(!duplicateflag){
-                               siteData.setUserModifiedBy(userInfo);
-                               if(siteData.getId() == 0){
-                                       siteData.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(siteData);
-                               }else{
-                                       siteData.setModifiedDate(new Date());
-                                       commonClassDao.update(siteData); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
+            if(!duplicateflag){
+                siteData.setUserModifiedBy(userInfo);
+                if(siteData.getId() == 0){
+                    siteData.setUserCreatedBy(userInfo);
+                    commonClassDao.save(siteData);
+                }else{
+                    siteData.setModifiedDate(new Date());
+                    commonClassDao.update(siteData);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
             if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, closedLoopSiteDatas, responseString);
-                       }
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, closedLoopSiteDatas, responseString);
+            }
         }catch (Exception e){
-               utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/cl_dictionary/remove_site"}, method={RequestMethod.POST})
-       public void removeSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, closedLoopSiteDatas, VNFType.class);
-       }
-
-       @RequestMapping(value={"/cl_dictionary/save_varbind"}, method={RequestMethod.POST})
-       public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/cl_dictionary/remove_site"}, method={RequestMethod.POST})
+    public void removeSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, closedLoopSiteDatas, VNFType.class);
+    }
+
+    @RequestMapping(value={"/cl_dictionary/save_varbind"}, method={RequestMethod.POST})
+    public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
             VarbindDictionary varbindDictionary;
             String userId = null;
             if(fromAPI){
                 varbindDictionary = mapper.readValue(root.get(dictionaryFields).toString(), VarbindDictionary.class);
                 userId = "API";
             }else{
-               varbindDictionary = mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class);
-               userId = root.get(userid).textValue();
+                varbindDictionary = mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class);
+                userId = root.get(userid).textValue();
             }
             UserInfo userInfo = utils.getUserInfo(userId);
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               VarbindDictionary data = (VarbindDictionary) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       varbindDictionary.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != varbindDictionary.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       
-                       String responseString = null;
-                       if(!duplicateflag){
-                               varbindDictionary.setUserModifiedBy(userInfo);
-                               if(varbindDictionary.getId() == 0){
-                                       varbindDictionary.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(varbindDictionary);
-                               }else{
-                                       varbindDictionary.setModifiedDate(new Date());
-                                       commonClassDao.update(varbindDictionary); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }            
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                VarbindDictionary data = (VarbindDictionary) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    varbindDictionary.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != varbindDictionary.getId()))){
+                    duplicateflag = true;
+                }
+            }
+
+            String responseString = null;
+            if(!duplicateflag){
+                varbindDictionary.setUserModifiedBy(userInfo);
+                if(varbindDictionary.getId() == 0){
+                    varbindDictionary.setUserCreatedBy(userInfo);
+                    commonClassDao.save(varbindDictionary);
+                }else{
+                    varbindDictionary.setModifiedDate(new Date());
+                    commonClassDao.update(varbindDictionary);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
             if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, varbindDatas, responseString);
-                       }
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, varbindDatas, responseString);
+            }
         }catch (Exception e){
-               utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/cl_dictionary/remove_varbindDict"}, method={RequestMethod.POST})
-       public void removeVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, varbindDatas, VNFType.class);
-       }
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/cl_dictionary/remove_varbindDict"}, method={RequestMethod.POST})
+    public void removeVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, varbindDatas, VNFType.class);
+    }
 }
\ No newline at end of file
index 6e68d78..738a808 100644 (file)
@@ -46,187 +46,187 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 
 @Controller
 public class DecisionPolicyDictionaryController {
-       
-       private static CommonClassDao commonClassDao;
-       private static String xacmlId = "xacmlId";
-       private static String bbID = "bbid";
-       private static String operation = "operation";
-       private static String duplicateResponseString = "Duplicate";
-       private static String settingDatas = "settingsDictionaryDatas";
-       private static String rainDayDatas = "rainyDayDictionaryDatas";
-       private static String dictionaryFields ="dictionaryFields";
-       
-       @Autowired
-       public DecisionPolicyDictionaryController(CommonClassDao commonClassDao){
-               DecisionPolicyDictionaryController.commonClassDao = commonClassDao;
-       }
-       
-       public DecisionPolicyDictionaryController(){
-               super();
-       }
-       
-       private DictionaryUtils getDictionaryUtilsInstance(){
-               return DictionaryUtils.getDictionaryUtils();
-       }
-       
-       @RequestMapping(value={"/get_SettingsDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getSettingsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, settingDatas, xacmlId, DecisionSettings.class);
-       }
-
-       
-       @RequestMapping(value={"/get_SettingsDictionaryData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getSettingsDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, settingDatas, DecisionSettings.class);
-       }
-       
-       @RequestMapping(value={"/decision_dictionary/save_Settings"}, method={RequestMethod.POST})
-       public ModelAndView saveSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       DecisionSettings decisionSettings;
-                       String userId = null;
-
-                       if(fromAPI){
-                               decisionSettings = mapper.readValue(root.get(dictionaryFields).toString(), DecisionSettings.class);
-                               userId = "API";
-                       }else{
-                               decisionSettings = mapper.readValue(root.get("settingsDictionaryData").toString(), DecisionSettings.class);
-                               userId = root.get("userid").textValue();
-                       }
-                       UserInfo userInfo = utils.getUserInfo(userId);
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(decisionSettings.getXacmlId(), xacmlId, DecisionSettings.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               DecisionSettings data = (DecisionSettings) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       decisionSettings.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != decisionSettings.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       if(decisionSettings.getDatatypeBean().getShortName() != null){
-                               String datatype = decisionSettings.getDatatypeBean().getShortName();
-                               decisionSettings.setDatatypeBean(utils.getDataType(datatype));
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               decisionSettings.setUserModifiedBy(userInfo);
-                               if(decisionSettings.getId() == 0){
-                                       decisionSettings.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(decisionSettings);
-                               }else{
-                                       decisionSettings.setModifiedDate(new Date());
-                                       commonClassDao.update(decisionSettings); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, settingDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/settings_dictionary/remove_settings"}, method={RequestMethod.POST})
-       public void removeSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, settingDatas, DecisionSettings.class);
-       }
-       
-       @RequestMapping(value={"/get_RainyDayDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getRainyDayDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, rainDayDatas, bbID, RainyDayTreatments.class);
-       }
-
-       @RequestMapping(value={"/get_RainyDayDictionaryData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getRainyDayDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, rainDayDatas, RainyDayTreatments.class);
-       }
-       
-       @RequestMapping(value={"/decision_dictionary/save_RainyDay"}, method={RequestMethod.POST})
-       public ModelAndView saveRainyDayDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       RainyDayTreatments decisionRainyDay;
+
+    private static CommonClassDao commonClassDao;
+    private static String xacmlId = "xacmlId";
+    private static String bbID = "bbid";
+    private static String operation = "operation";
+    private static String duplicateResponseString = "Duplicate";
+    private static String settingDatas = "settingsDictionaryDatas";
+    private static String rainDayDatas = "rainyDayDictionaryDatas";
+    private static String dictionaryFields ="dictionaryFields";
+
+    @Autowired
+    public DecisionPolicyDictionaryController(CommonClassDao commonClassDao){
+        DecisionPolicyDictionaryController.commonClassDao = commonClassDao;
+    }
+
+    public DecisionPolicyDictionaryController(){
+        super();
+    }
+
+    private DictionaryUtils getDictionaryUtilsInstance(){
+        return DictionaryUtils.getDictionaryUtils();
+    }
+
+    @RequestMapping(value={"/get_SettingsDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getSettingsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, settingDatas, xacmlId, DecisionSettings.class);
+    }
+
+
+    @RequestMapping(value={"/get_SettingsDictionaryData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getSettingsDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, settingDatas, DecisionSettings.class);
+    }
+
+    @RequestMapping(value={"/decision_dictionary/save_Settings"}, method={RequestMethod.POST})
+    public ModelAndView saveSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            DecisionSettings decisionSettings;
+            String userId = null;
+
+            if(fromAPI){
+                decisionSettings = mapper.readValue(root.get(dictionaryFields).toString(), DecisionSettings.class);
+                userId = "API";
+            }else{
+                decisionSettings = mapper.readValue(root.get("settingsDictionaryData").toString(), DecisionSettings.class);
+                userId = root.get("userid").textValue();
+            }
+            UserInfo userInfo = utils.getUserInfo(userId);
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(decisionSettings.getXacmlId(), xacmlId, DecisionSettings.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                DecisionSettings data = (DecisionSettings) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    decisionSettings.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != decisionSettings.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            if(decisionSettings.getDatatypeBean().getShortName() != null){
+                String datatype = decisionSettings.getDatatypeBean().getShortName();
+                decisionSettings.setDatatypeBean(utils.getDataType(datatype));
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                decisionSettings.setUserModifiedBy(userInfo);
+                if(decisionSettings.getId() == 0){
+                    decisionSettings.setUserCreatedBy(userInfo);
+                    commonClassDao.save(decisionSettings);
+                }else{
+                    decisionSettings.setModifiedDate(new Date());
+                    commonClassDao.update(decisionSettings);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, settingDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/settings_dictionary/remove_settings"}, method={RequestMethod.POST})
+    public void removeSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, settingDatas, DecisionSettings.class);
+    }
+
+    @RequestMapping(value={"/get_RainyDayDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getRainyDayDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, rainDayDatas, bbID, RainyDayTreatments.class);
+    }
+
+    @RequestMapping(value={"/get_RainyDayDictionaryData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getRainyDayDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, rainDayDatas, RainyDayTreatments.class);
+    }
+
+    @RequestMapping(value={"/decision_dictionary/save_RainyDay"}, method={RequestMethod.POST})
+    public ModelAndView saveRainyDayDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            RainyDayTreatments decisionRainyDay;
             TreatmentValues treatmentsData = null;
             if(fromAPI){
-               decisionRainyDay = mapper.readValue(root.get(dictionaryFields).toString(), RainyDayTreatments.class);
-               treatmentsData = mapper.readValue(root.get(dictionaryFields).toString(), TreatmentValues.class);
+                decisionRainyDay = mapper.readValue(root.get(dictionaryFields).toString(), RainyDayTreatments.class);
+                treatmentsData = mapper.readValue(root.get(dictionaryFields).toString(), TreatmentValues.class);
+            }else{
+                decisionRainyDay = mapper.readValue(root.get("rainyDayDictionaryData").toString(), RainyDayTreatments.class);
+                treatmentsData = mapper.readValue(root.get("rainyDayDictionaryData").toString(), TreatmentValues.class);
+            }
+            decisionRainyDay.setTreatments(utils.appendKey(treatmentsData.getUserDataTypeValues(), "treatment", ","));
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(decisionRainyDay.getBbid()+":"+decisionRainyDay.getWorkstep(), "bbid:workstep", RainyDayTreatments.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                RainyDayTreatments data = (RainyDayTreatments) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    decisionRainyDay.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != decisionRainyDay.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(decisionRainyDay.getId() == 0){
+                    commonClassDao.save(decisionRainyDay);
+                }else{
+                    commonClassDao.update(decisionRainyDay);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(RainyDayTreatments.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
             }else{
-               decisionRainyDay = mapper.readValue(root.get("rainyDayDictionaryData").toString(), RainyDayTreatments.class);
-               treatmentsData = mapper.readValue(root.get("rainyDayDictionaryData").toString(), TreatmentValues.class);
+                utils.setResponseData(response, rainDayDatas, responseString);
             }
-                       decisionRainyDay.setTreatments(utils.appendKey(treatmentsData.getUserDataTypeValues(), "treatment", ","));
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(decisionRainyDay.getBbid()+":"+decisionRainyDay.getWorkstep(), "bbid:workstep", RainyDayTreatments.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               RainyDayTreatments data = (RainyDayTreatments) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       decisionRainyDay.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != decisionRainyDay.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(decisionRainyDay.getId() == 0){
-                                       commonClassDao.save(decisionRainyDay);
-                               }else{
-                                       commonClassDao.update(decisionRainyDay); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(RainyDayTreatments.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, rainDayDatas, responseString);
-                       }
         }catch (Exception e){
-               utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/decision_dictionary/remove_rainyDay"}, method={RequestMethod.POST})
-       public void removeRainyDayDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, rainDayDatas, RainyDayTreatments.class);
-       }
-       
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/decision_dictionary/remove_rainyDay"}, method={RequestMethod.POST})
+    public void removeRainyDayDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, rainDayDatas, RainyDayTreatments.class);
+    }
+
 }
 
 class TreatmentValues { 
-       private List<Object> userDataTypeValues = new ArrayList<>();
+    private List<Object> userDataTypeValues = new ArrayList<>();
 
-       public List<Object> getUserDataTypeValues() {
-               return userDataTypeValues;
-       }
+    public List<Object> getUserDataTypeValues() {
+        return userDataTypeValues;
+    }
 
-       public void setUserDataTypeValues(List<Object> userDataTypeValues) {
-               this.userDataTypeValues = userDataTypeValues;
-       }
+    public void setUserDataTypeValues(List<Object> userDataTypeValues) {
+        this.userDataTypeValues = userDataTypeValues;
+    }
 }
index db71096..a1d1bc8 100644 (file)
@@ -45,102 +45,102 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 
 @Controller
 public class DescriptiveDictionaryController {
-       
-       private static CommonClassDao commonClassDao;
-       private static String operation = "operation";
-       private static String dScopeName = "descriptiveScopeName";
-       private static String descriptiveDatas = "descriptiveScopeDictionaryDatas";
-       
-       @Autowired
-       public DescriptiveDictionaryController(CommonClassDao commonClassDao){
-               DescriptiveDictionaryController.commonClassDao = commonClassDao;
-       }
-       
-       public void setCommonClassDao(CommonClassDao commonClassDao){
-               DescriptiveDictionaryController.commonClassDao = commonClassDao;
-       }
-       
-       public DescriptiveDictionaryController(){
-               super();
-       }
 
-       private DictionaryUtils getDictionaryUtilsInstance(){
-               return DictionaryUtils.getDictionaryUtils();
-       }
-       
-       @RequestMapping(value={"/get_DescriptiveScopeByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getDescriptiveDictionaryByNameEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, descriptiveDatas, dScopeName, DescriptiveScope.class);
-       }
-       
-       @RequestMapping(value={"/get_DescriptiveScope"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getDescriptiveDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, descriptiveDatas, DescriptiveScope.class);
-       }
-       
-       @RequestMapping(value={"/descriptive_dictionary/save_descriptive"}, method={RequestMethod.POST})
-       public ModelAndView saveDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response)throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       DescriptiveScope descriptiveScope;
-                       GridData data;
-                       String userId = null;
-                       if(fromAPI){
-                               descriptiveScope = mapper.readValue(root.get("dictionaryFields").toString(), DescriptiveScope.class);
-                               data = mapper.readValue(root.get("dictionaryFields").toString(), GridData.class);
-                               userId = "API";
-                       }else{
-                               descriptiveScope = mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), DescriptiveScope.class);
-                               data = mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), GridData.class);
-                               userId = root.get("userid").textValue();
-                       }
-                       descriptiveScope.setSearch(utils.appendKeyValue(data.getAttributes(), "AND", ":"));
-                       UserInfo userInfo = utils.getUserInfo(userId);
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(descriptiveScope.getScopeName(), dScopeName, DescriptiveScope.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               DescriptiveScope data1 = (DescriptiveScope) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       descriptiveScope.setId(data1.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data1.getId() != descriptiveScope.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               descriptiveScope.setUserModifiedBy(userInfo);
-                               if(descriptiveScope.getId() == 0){
-                                       descriptiveScope.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(descriptiveScope);
-                               }else{
-                                       descriptiveScope.setModifiedDate(new Date());
-                                       commonClassDao.update(descriptiveScope); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(DescriptiveScope.class));
-                       }else{
-                               responseString = "Duplicate";
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, descriptiveDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
+    private static CommonClassDao commonClassDao;
+    private static String operation = "operation";
+    private static String dScopeName = "descriptiveScopeName";
+    private static String descriptiveDatas = "descriptiveScopeDictionaryDatas";
 
-       @RequestMapping(value={"/descriptive_dictionary/remove_descriptiveScope"}, method={RequestMethod.POST})
-       public void removeDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, descriptiveDatas, DescriptiveScope.class);
-       }
+    @Autowired
+    public DescriptiveDictionaryController(CommonClassDao commonClassDao){
+        DescriptiveDictionaryController.commonClassDao = commonClassDao;
+    }
+
+    public void setCommonClassDao(CommonClassDao commonClassDao){
+        DescriptiveDictionaryController.commonClassDao = commonClassDao;
+    }
+
+    public DescriptiveDictionaryController(){
+        super();
+    }
+
+    private DictionaryUtils getDictionaryUtilsInstance(){
+        return DictionaryUtils.getDictionaryUtils();
+    }
+
+    @RequestMapping(value={"/get_DescriptiveScopeByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getDescriptiveDictionaryByNameEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, descriptiveDatas, dScopeName, DescriptiveScope.class);
+    }
+
+    @RequestMapping(value={"/get_DescriptiveScope"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getDescriptiveDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, descriptiveDatas, DescriptiveScope.class);
+    }
+
+    @RequestMapping(value={"/descriptive_dictionary/save_descriptive"}, method={RequestMethod.POST})
+    public ModelAndView saveDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response)throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            DescriptiveScope descriptiveScope;
+            GridData data;
+            String userId = null;
+            if(fromAPI){
+                descriptiveScope = mapper.readValue(root.get("dictionaryFields").toString(), DescriptiveScope.class);
+                data = mapper.readValue(root.get("dictionaryFields").toString(), GridData.class);
+                userId = "API";
+            }else{
+                descriptiveScope = mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), DescriptiveScope.class);
+                data = mapper.readValue(root.get("descriptiveScopeDictionaryData").toString(), GridData.class);
+                userId = root.get("userid").textValue();
+            }
+            descriptiveScope.setSearch(utils.appendKeyValue(data.getAttributes(), "AND", ":"));
+            UserInfo userInfo = utils.getUserInfo(userId);
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(descriptiveScope.getScopeName(), dScopeName, DescriptiveScope.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                DescriptiveScope data1 = (DescriptiveScope) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    descriptiveScope.setId(data1.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data1.getId() != descriptiveScope.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                descriptiveScope.setUserModifiedBy(userInfo);
+                if(descriptiveScope.getId() == 0){
+                    descriptiveScope.setUserCreatedBy(userInfo);
+                    commonClassDao.save(descriptiveScope);
+                }else{
+                    descriptiveScope.setModifiedDate(new Date());
+                    commonClassDao.update(descriptiveScope);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(DescriptiveScope.class));
+            }else{
+                responseString = "Duplicate";
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, descriptiveDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/descriptive_dictionary/remove_descriptiveScope"}, method={RequestMethod.POST})
+    public void removeDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, descriptiveDatas, DescriptiveScope.class);
+    }
 }
\ No newline at end of file
index 0b7693c..7253988 100644 (file)
@@ -47,201 +47,201 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 
 @Controller
 public class DictionaryController {
-       
-       private static final Log LOGGER = LogFactory.getLog(DictionaryController.class);
-
-       private static CommonClassDao commonClassDao;
-       private static String xacmlId = "xacmlId";
-       private static String operation = "operation";
-       private static String dictionaryFields ="dictionaryFields";
-       private static String duplicateResponseString = "Duplicate";
-       private static String onapName = "onapName";
-       private static String attributeDatas = "attributeDictionaryDatas";
-       private static String onapNameDatas = "onapNameDictionaryDatas";
-       
-       @Autowired
-       public DictionaryController(CommonClassDao commonClassDao){
-               DictionaryController.commonClassDao = commonClassDao;
-       }
-
-       public DictionaryController(){
-               super();
-       }
-       
-       private DictionaryUtils getDictionaryUtilsInstance(){
-               return DictionaryUtils.getDictionaryUtils();
-       }
-       
-       @RequestMapping(value={"/get_AttributeDatabyAttributeName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getAttributeDictionaryEntityDatabyAttributeName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, attributeDatas, xacmlId, Attribute.class);
-       }
-       
-       //Attribute Dictionary
-       @RequestMapping(value="/get_AttributeData", method= RequestMethod.GET , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getAttributeDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, attributeDatas, Attribute.class);
-       }
-       
-       @RequestMapping(value={"/attribute_dictionary/save_attribute"}, method={RequestMethod.POST})
-       public ModelAndView saveAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       Attribute attributeData = null;
-                       AttributeValues attributeValueData = null;
-                       String userId = null;
-                       if(fromAPI){
-                               attributeData = mapper.readValue(root.get(dictionaryFields).toString(), Attribute.class);
-                               attributeValueData = mapper.readValue(root.get(dictionaryFields).toString(), AttributeValues.class);
-                               userId = "API";
-                       }else{
-                               attributeData = mapper.readValue(root.get("attributeDictionaryData").toString(), Attribute.class);
-                               attributeValueData = mapper.readValue(root.get("attributeDictionaryData").toString(), AttributeValues.class);
-                               userId = root.get("userid").textValue();
-                       }
-                       UserInfo userInfo = utils.getUserInfo(userId);
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(attributeData.getXacmlId(), xacmlId, Attribute.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               Attribute data = (Attribute) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       attributeData.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != attributeData.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       if(attributeValueData.getUserDataTypeValues() != null && !attributeValueData.getUserDataTypeValues().isEmpty()){
-                               attributeData.setAttributeValue(utils.appendKey(attributeValueData.getUserDataTypeValues(), "attributeValues", ","));
-                       }
-                       
-                       if(attributeData.getDatatypeBean().getShortName() != null){
-                               String datatype = attributeData.getDatatypeBean().getShortName();       
-                               attributeData.setDatatypeBean(utils.getDataType(datatype));
-                       }
-
-                       String responseString = null;
-                       if(!duplicateflag){
-                               attributeData.setUserModifiedBy(userInfo);
-                               if(attributeData.getId() == 0){
-                                       attributeData.setCategoryBean(utils.getCategory());
-                                       attributeData.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(attributeData);
-                               }else{
-                                       attributeData.setModifiedDate(new Date());
-                                       commonClassDao.update(attributeData); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(Attribute.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, attributeDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/attribute_dictionary/remove_attribute"}, method={RequestMethod.POST})
-       public void removeAttributeDictionary(HttpServletRequest request, HttpServletResponse response)throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, attributeDatas, Attribute.class);
-       }
-       
-       //OnapName Dictionary
-       @RequestMapping(value={"/get_OnapNameDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getOnapNameDictionaryByNameEntityData(HttpServletResponse response){
-               LOGGER.info("get_OnapNameDataByName is called");
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, onapNameDatas, onapName, OnapName.class);
-       }
-       
-       @RequestMapping(value={"/get_OnapNameData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getOnapNameDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, onapNameDatas, OnapName.class);
-       }
-
-       @RequestMapping(value={"/onap_dictionary/save_onapName"}, method={RequestMethod.POST})
-       public ModelAndView saveOnapDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       OnapName onapData;
-                       String userId = null;
-                       if(fromAPI){
-                               onapData = mapper.readValue(root.get(dictionaryFields).toString(), OnapName.class);
-                               userId = "API";
-                       }else{
-                               onapData = mapper.readValue(root.get("onapNameDictionaryData").toString(), OnapName.class);
-                               userId = root.get("userid").textValue();
-                       }
-                       UserInfo userInfo = utils.getUserInfo(userId);
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getOnapName(), onapName, OnapName.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               OnapName data = (OnapName) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       onapData.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               onapData.setUserModifiedBy(userInfo);
-                               if(onapData.getId() == 0){
-                                       onapData.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(onapData);
-                               }else{
-                                       onapData.setModifiedDate(new Date());
-                                       commonClassDao.update(onapData); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(OnapName.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, onapNameDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/onap_dictionary/remove_onap"}, method={RequestMethod.POST})
-       public void removeOnapDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, onapNameDatas, OnapName.class);
-       }
+
+    private static final Log LOGGER    = LogFactory.getLog(DictionaryController.class);
+
+    private static CommonClassDao commonClassDao;
+    private static String xacmlId = "xacmlId";
+    private static String operation = "operation";
+    private static String dictionaryFields ="dictionaryFields";
+    private static String duplicateResponseString = "Duplicate";
+    private static String onapName = "onapName";
+    private static String attributeDatas = "attributeDictionaryDatas";
+    private static String onapNameDatas = "onapNameDictionaryDatas";
+
+    @Autowired
+    public DictionaryController(CommonClassDao commonClassDao){
+        DictionaryController.commonClassDao = commonClassDao;
+    }
+
+    public DictionaryController(){
+        super();
+    }
+
+    private DictionaryUtils getDictionaryUtilsInstance(){
+        return DictionaryUtils.getDictionaryUtils();
+    }
+
+    @RequestMapping(value={"/get_AttributeDatabyAttributeName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getAttributeDictionaryEntityDatabyAttributeName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, attributeDatas, xacmlId, Attribute.class);
+    }
+
+    //Attribute Dictionary
+    @RequestMapping(value="/get_AttributeData", method= RequestMethod.GET , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getAttributeDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, attributeDatas, Attribute.class);
+    }
+
+    @RequestMapping(value={"/attribute_dictionary/save_attribute"}, method={RequestMethod.POST})
+    public ModelAndView saveAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            Attribute attributeData = null;
+            AttributeValues attributeValueData = null;
+            String userId = null;
+            if(fromAPI){
+                attributeData = mapper.readValue(root.get(dictionaryFields).toString(), Attribute.class);
+                attributeValueData = mapper.readValue(root.get(dictionaryFields).toString(), AttributeValues.class);
+                userId = "API";
+            }else{
+                attributeData = mapper.readValue(root.get("attributeDictionaryData").toString(), Attribute.class);
+                attributeValueData = mapper.readValue(root.get("attributeDictionaryData").toString(), AttributeValues.class);
+                userId = root.get("userid").textValue();
+            }
+            UserInfo userInfo = utils.getUserInfo(userId);
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(attributeData.getXacmlId(), xacmlId, Attribute.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                Attribute data = (Attribute) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    attributeData.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != attributeData.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            if(attributeValueData.getUserDataTypeValues() != null && !attributeValueData.getUserDataTypeValues().isEmpty()){
+                attributeData.setAttributeValue(utils.appendKey(attributeValueData.getUserDataTypeValues(), "attributeValues", ","));
+            }
+
+            if(attributeData.getDatatypeBean().getShortName() != null){
+                String datatype = attributeData.getDatatypeBean().getShortName();
+                attributeData.setDatatypeBean(utils.getDataType(datatype));
+            }
+
+            String responseString = null;
+            if(!duplicateflag){
+                attributeData.setUserModifiedBy(userInfo);
+                if(attributeData.getId() == 0){
+                    attributeData.setCategoryBean(utils.getCategory());
+                    attributeData.setUserCreatedBy(userInfo);
+                    commonClassDao.save(attributeData);
+                }else{
+                    attributeData.setModifiedDate(new Date());
+                    commonClassDao.update(attributeData);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(Attribute.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, attributeDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/attribute_dictionary/remove_attribute"}, method={RequestMethod.POST})
+    public void removeAttributeDictionary(HttpServletRequest request, HttpServletResponse response)throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, attributeDatas, Attribute.class);
+    }
+
+    //OnapName Dictionary
+    @RequestMapping(value={"/get_OnapNameDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getOnapNameDictionaryByNameEntityData(HttpServletResponse response){
+        LOGGER.info("get_OnapNameDataByName is called");
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, onapNameDatas, onapName, OnapName.class);
+    }
+
+    @RequestMapping(value={"/get_OnapNameData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getOnapNameDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, onapNameDatas, OnapName.class);
+    }
+
+    @RequestMapping(value={"/onap_dictionary/save_onapName"}, method={RequestMethod.POST})
+    public ModelAndView saveOnapDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            OnapName onapData;
+            String userId = null;
+            if(fromAPI){
+                onapData = mapper.readValue(root.get(dictionaryFields).toString(), OnapName.class);
+                userId = "API";
+            }else{
+                onapData = mapper.readValue(root.get("onapNameDictionaryData").toString(), OnapName.class);
+                userId = root.get("userid").textValue();
+            }
+            UserInfo userInfo = utils.getUserInfo(userId);
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getOnapName(), onapName, OnapName.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                OnapName data = (OnapName) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    onapData.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                onapData.setUserModifiedBy(userInfo);
+                if(onapData.getId() == 0){
+                    onapData.setUserCreatedBy(userInfo);
+                    commonClassDao.save(onapData);
+                }else{
+                    onapData.setModifiedDate(new Date());
+                    commonClassDao.update(onapData);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(OnapName.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, onapNameDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/onap_dictionary/remove_onap"}, method={RequestMethod.POST})
+    public void removeOnapDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, onapNameDatas, OnapName.class);
+    }
 }
 
 class AttributeValues{
-       private List<Object> userDataTypeValues;
+    private List<Object> userDataTypeValues;
 
-       public List<Object> getUserDataTypeValues() {
-               return userDataTypeValues;
-       }
+    public List<Object> getUserDataTypeValues() {
+        return userDataTypeValues;
+    }
 
-       public void setUserDataTypeValues(List<Object> userDataTypeValues) {
-               this.userDataTypeValues = userDataTypeValues;
-       }
+    public void setUserDataTypeValues(List<Object> userDataTypeValues) {
+        this.userDataTypeValues = userDataTypeValues;
+    }
 }
\ No newline at end of file
index 9423017..7093cd5 100644 (file)
@@ -75,704 +75,704 @@ import au.com.bytecode.opencsv.CSVReader;
 
 @Controller
 public class DictionaryImportController {
-       private static final Logger LOGGER  = FlexLogger.getLogger(DictionaryImportController.class);
-       
-       private static CommonClassDao commonClassDao;
-       private static final String DESCRIPTION= "description";
-       private static final String ERROR= "Error";
-       private static final String DEPENDENCY= "dependency";
-       
-       @Autowired
-       public DictionaryImportController(CommonClassDao commonClassDao){
-               setCommonClassDao(commonClassDao);
-       }
-       
-       public static void setCommonClassDao(CommonClassDao commonClassDao) {
-               DictionaryImportController.commonClassDao = commonClassDao;
-       }
-       
-       public DictionaryImportController(){
-               super();        
-       }
+    private static final Logger LOGGER  = FlexLogger.getLogger(DictionaryImportController.class);
 
-       @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");
-               String dictionaryName = request.getParameter("dictionaryName");
-               
-               if(dictionaryName == null || dictionaryName.isEmpty()){
-                       LOGGER.error("dictionaryName is null/empty");
-                       response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
-                       response.getWriter().write(ERROR);
-                       return;
-               }
-               
-               // fix Fortify Path Manipulation issue
-               if(!isValidDictionaryName(dictionaryName)){
-                       LOGGER.error("dictionaryName is invalid");
-                       response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
-                       response.getWriter().write(ERROR);
-                       return;                 
-               }
-               File file = new File(dictionaryName);   
-               try(OutputStream outputStream = new FileOutputStream(file); FileReader fileReader = new FileReader(file.toString())){
-                       IOUtils.copy(request.getInputStream(), outputStream);
-                       CSVReader csvReader = new CSVReader(fileReader);
-                       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]);
-                                               }
-                                       }
-                                       commonClassDao.save(attribute);
-                               }
-                       }
-                       if(dictionaryName.startsWith("ActionPolicyDictionary")){
-                               for(int i = 1; i< dictSheet.size(); i++){
-                                       ActionPolicyDict attribute = new ActionPolicyDict();
-                                       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);
-                               }
-                       }
-                       if(dictionaryName.startsWith("OnapName")){
-                               for(int i = 1; i< dictSheet.size(); i++){
-                                       OnapName attribute = new OnapName();
-                                       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);
-                               }
-                       }
+    private static CommonClassDao commonClassDao;
+    private static final String DESCRIPTION= "description";
+    private static final String ERROR= "Error";
+    private static final String DEPENDENCY= "dependency";
 
-                       if(dictionaryName.startsWith("MSPolicyDictionary")){
-                               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("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) {
-                                                       attribute.setAnnotation(rows[j]);
-                                               }
-                                       }
+    @Autowired
+    public DictionaryImportController(CommonClassDao commonClassDao){
+        setCommonClassDao(commonClassDao);
+    }
 
-                                       commonClassDao.save(attribute);
-                               }
-                       }               
+    public static void setCommonClassDao(CommonClassDao commonClassDao) {
+        DictionaryImportController.commonClassDao = commonClassDao;
+    }
 
-                       if(dictionaryName.startsWith("OptimizationPolicyDictionary")){
-                               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]) || "Optimization 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("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) {
-                                                       attribute.setAnnotation(rows[j]);
-                                               }
-                                       }
+    public DictionaryImportController(){
+        super();
+    }
 
-                                       commonClassDao.save(attribute);
-                               }
-                       }               
+    @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");
+        String dictionaryName = request.getParameter("dictionaryName");
 
-                       if(dictionaryName.startsWith("VNFType")){
-                               for(int i = 1; i< dictSheet.size(); i++){
-                                       VNFType attribute = new VNFType();
-                                       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);
-                               }
-                       }
-                       if(dictionaryName.startsWith("VSCLAction")){
-                               for(int i = 1; i< dictSheet.size(); i++){
-                                       VSCLAction attribute = new VSCLAction();
-                                       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);
-                               }
-                       }
-                       if(dictionaryName.startsWith("ClosedLoopService")){
-                               for(int i = 1; i< dictSheet.size(); i++){
-                                       ClosedLoopD2Services attribute = new ClosedLoopD2Services();
-                                       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);
-                               }
-                       }
-                       if(dictionaryName.startsWith("ClosedLoopSite")){
-                               for(int i = 1; i< dictSheet.size(); i++){
-                                       ClosedLoopSite attribute = new ClosedLoopSite();
-                                       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);
-                               }
-                       }
-                       if(dictionaryName.startsWith("PEPOptions")){
-                               for(int i = 1; i< dictSheet.size(); i++){
-                                       PEPOptions attribute = new PEPOptions();
-                                       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);
-                               }
-                       }
-                       if(dictionaryName.startsWith("VarbindDictionary")){
-                               for(int i = 1; i< dictSheet.size(); i++){
-                                       VarbindDictionary attribute = new VarbindDictionary();
-                                       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);
-                               }
-                       }
-                       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])){
-                                                       attribute.setDescription(rows[j]);
-                                               }
-                                               if("rule".equalsIgnoreCase(dictSheet.get(0)[j])){
-                                                       attribute.setRule(rows[j]);
-                                               }
-                                       }
-                                       commonClassDao.save(attribute);
-                               }
-                       }
-                       if(dictionaryName.startsWith("BRMSControllerDictionary")){
-                               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);
-                               }
-                       }
-                       if(dictionaryName.startsWith("BRMSDependencyDictionary")){
-                               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);
-                               }
-                       }
-                       if(dictionaryName.startsWith("Settings")){
-                               for(int i = 1; i< dictSheet.size(); i++){
-                                       DecisionSettings attribute = new DecisionSettings();
-                                       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);
-                               }
-                       }
-                       if(dictionaryName.startsWith("PrefixList")){
-                               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])){
-                                                       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);
-                               }
-                       }
-                       if(dictionaryName.startsWith("SecurityZone")){
-                               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])){
-                                                       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);
-                               }
-                       }
-                       if(dictionaryName.startsWith("Zone")){
-                               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])){
-                                                       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);
-                               }
-                       }
-                       if(dictionaryName.startsWith("ServiceList")){
-                               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])){
-                                                       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);
-                               }
-                       }
-                       if(dictionaryName.startsWith("ServiceGroup")){
-                               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])){
-                                                       attribute.setGroupName(rows[j]);
-                                               }
-                                               if("serviceList".equalsIgnoreCase(dictSheet.get(0)[j])  || "Service List".equalsIgnoreCase(dictSheet.get(0)[j])){
-                                                       attribute.setServiceList(rows[j]);
-                                               }
-                                       }
-                                       commonClassDao.save(attribute);
-                               }
-                       }
-                       if(dictionaryName.startsWith("AddressGroup")){
-                               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])){
-                                                       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]);
-                                               }
-                                       }
-                                       commonClassDao.save(attribute);
-                               }
-                       }
-                       if(dictionaryName.startsWith("ProtocolList")){
-                               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])){
-                                                       attribute.setProtocolName(rows[j]);
-                                               }
-                                               if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
-                                                       attribute.setDescription(rows[j]);
-                                               }
-                                       }
-                                       commonClassDao.save(attribute);
-                               }
-                       }
-                       if(dictionaryName.startsWith("ActionList")){
-                               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])){
-                                                       attribute.setActionName(rows[j]);
-                                               }
-                                               if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
-                                                       attribute.setDescription(rows[j]);
-                                               }
-                                       }
-                                       commonClassDao.save(attribute);
-                               }
-                       }
-                       if(dictionaryName.startsWith("TermList")){
-                               for(int i = 1; i< dictSheet.size(); i++){
-                                       TermList attribute = new TermList();
-                                       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]);
-                                               }
-                                       }
-                                       commonClassDao.save(attribute);
-                               }
-                       }
-                       if(dictionaryName.startsWith("SearchCriteria")){
-                               for(int i = 1; i< dictSheet.size(); i++){
-                                       DescriptiveScope attribute = new DescriptiveScope();
-                                       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);
-                               }
-                       }
-                       csvReader.close();
-                       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){
-               
-               String nameCheck = dictionaryName.replace(".csv", "");
-               try{
-                       DictionaryNames mode = DictionaryNames.valueOf(nameCheck);
-                       switch (mode){
-                               case Attribute:
-                               case ActionPolicyDictionary:
-                               case OnapName:
-                               case MSPolicyDictionary:
-                               case OptimizationPolicyDictionary:
-                               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;
-               }       
-       }
+        if(dictionaryName == null || dictionaryName.isEmpty()){
+            LOGGER.error("dictionaryName is null/empty");
+            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+            response.getWriter().write(ERROR);
+            return;
+        }
+
+        // fix Fortify Path Manipulation issue
+        if(!isValidDictionaryName(dictionaryName)){
+            LOGGER.error("dictionaryName is invalid");
+            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+            response.getWriter().write(ERROR);
+            return;
+        }
+        File file = new File(dictionaryName);
+        try(OutputStream outputStream = new FileOutputStream(file); FileReader fileReader = new FileReader(file.toString())){
+            IOUtils.copy(request.getInputStream(), outputStream);
+            CSVReader csvReader = new CSVReader(fileReader);
+            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]);
+                        }
+                    }
+                    commonClassDao.save(attribute);
+                }
+            }
+            if(dictionaryName.startsWith("ActionPolicyDictionary")){
+                for(int i = 1; i< dictSheet.size(); i++){
+                    ActionPolicyDict attribute = new ActionPolicyDict();
+                    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);
+                }
+            }
+            if(dictionaryName.startsWith("OnapName")){
+                for(int i = 1; i< dictSheet.size(); i++){
+                    OnapName attribute = new OnapName();
+                    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);
+                }
+            }
+
+            if(dictionaryName.startsWith("MSPolicyDictionary")){
+                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("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) {
+                            attribute.setAnnotation(rows[j]);
+                        }
+                    }
+
+                    commonClassDao.save(attribute);
+                }
+            }
+
+            if(dictionaryName.startsWith("OptimizationPolicyDictionary")){
+                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]) || "Optimization 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("annotations".equalsIgnoreCase(dictSheet.get(0)[j])) {
+                            attribute.setAnnotation(rows[j]);
+                        }
+                    }
+
+                    commonClassDao.save(attribute);
+                }
+            }
+
+            if(dictionaryName.startsWith("VNFType")){
+                for(int i = 1; i< dictSheet.size(); i++){
+                    VNFType attribute = new VNFType();
+                    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);
+                }
+            }
+            if(dictionaryName.startsWith("VSCLAction")){
+                for(int i = 1; i< dictSheet.size(); i++){
+                    VSCLAction attribute = new VSCLAction();
+                    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);
+                }
+            }
+            if(dictionaryName.startsWith("ClosedLoopService")){
+                for(int i = 1; i< dictSheet.size(); i++){
+                    ClosedLoopD2Services attribute = new ClosedLoopD2Services();
+                    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);
+                }
+            }
+            if(dictionaryName.startsWith("ClosedLoopSite")){
+                for(int i = 1; i< dictSheet.size(); i++){
+                    ClosedLoopSite attribute = new ClosedLoopSite();
+                    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);
+                }
+            }
+            if(dictionaryName.startsWith("PEPOptions")){
+                for(int i = 1; i< dictSheet.size(); i++){
+                    PEPOptions attribute = new PEPOptions();
+                    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);
+                }
+            }
+            if(dictionaryName.startsWith("VarbindDictionary")){
+                for(int i = 1; i< dictSheet.size(); i++){
+                    VarbindDictionary attribute = new VarbindDictionary();
+                    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);
+                }
+            }
+            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])){
+                            attribute.setDescription(rows[j]);
+                        }
+                        if("rule".equalsIgnoreCase(dictSheet.get(0)[j])){
+                            attribute.setRule(rows[j]);
+                        }
+                    }
+                    commonClassDao.save(attribute);
+                }
+            }
+            if(dictionaryName.startsWith("BRMSControllerDictionary")){
+                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);
+                }
+            }
+            if(dictionaryName.startsWith("BRMSDependencyDictionary")){
+                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);
+                }
+            }
+            if(dictionaryName.startsWith("Settings")){
+                for(int i = 1; i< dictSheet.size(); i++){
+                    DecisionSettings attribute = new DecisionSettings();
+                    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);
+                }
+            }
+            if(dictionaryName.startsWith("PrefixList")){
+                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])){
+                            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);
+                }
+            }
+            if(dictionaryName.startsWith("SecurityZone")){
+                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])){
+                            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);
+                }
+            }
+            if(dictionaryName.startsWith("Zone")){
+                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])){
+                            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);
+                }
+            }
+            if(dictionaryName.startsWith("ServiceList")){
+                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])){
+                            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);
+                }
+            }
+            if(dictionaryName.startsWith("ServiceGroup")){
+                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])){
+                            attribute.setGroupName(rows[j]);
+                        }
+                        if("serviceList".equalsIgnoreCase(dictSheet.get(0)[j])  || "Service List".equalsIgnoreCase(dictSheet.get(0)[j])){
+                            attribute.setServiceList(rows[j]);
+                        }
+                    }
+                    commonClassDao.save(attribute);
+                }
+            }
+            if(dictionaryName.startsWith("AddressGroup")){
+                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])){
+                            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]);
+                        }
+                    }
+                    commonClassDao.save(attribute);
+                }
+            }
+            if(dictionaryName.startsWith("ProtocolList")){
+                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])){
+                            attribute.setProtocolName(rows[j]);
+                        }
+                        if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
+                            attribute.setDescription(rows[j]);
+                        }
+                    }
+                    commonClassDao.save(attribute);
+                }
+            }
+            if(dictionaryName.startsWith("ActionList")){
+                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])){
+                            attribute.setActionName(rows[j]);
+                        }
+                        if(DESCRIPTION.equalsIgnoreCase(dictSheet.get(0)[j])){
+                            attribute.setDescription(rows[j]);
+                        }
+                    }
+                    commonClassDao.save(attribute);
+                }
+            }
+            if(dictionaryName.startsWith("TermList")){
+                for(int i = 1; i< dictSheet.size(); i++){
+                    TermList attribute = new TermList();
+                    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]);
+                        }
+                    }
+                    commonClassDao.save(attribute);
+                }
+            }
+            if(dictionaryName.startsWith("SearchCriteria")){
+                for(int i = 1; i< dictSheet.size(); i++){
+                    DescriptiveScope attribute = new DescriptiveScope();
+                    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);
+                }
+            }
+            csvReader.close();
+            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){
+
+        String nameCheck = dictionaryName.replace(".csv", "");
+        try{
+            DictionaryNames mode = DictionaryNames.valueOf(nameCheck);
+            switch (mode){
+                case Attribute:
+                case ActionPolicyDictionary:
+                case OnapName:
+                case MSPolicyDictionary:
+                case OptimizationPolicyDictionary:
+                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
index 4cf9a71..891787f 100644 (file)
@@ -65,1078 +65,1078 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 @Controller
 public class FirewallDictionaryController {
 
-       private static final Logger LOGGER  = FlexLogger.getLogger(FirewallDictionaryController.class);
-
-       private static CommonClassDao commonClassDao;
-       private static String prefixListName = "prefixListName";
-       private static String successMessage = "success";
-       private static String operation = "operation";
-       private static String errorMsg  = "error";
-       private static String dictionaryFields ="dictionaryFields";
-       private static String duplicateResponseString = "Duplicate";
-       private static String utf8 = "UTF-8";
-       private static String applicationJsonContentType = "application / json";
-       private static String protocolName = "protocolName";
-       private static String groupNameStart = "Group_";
-       private static String option = "option";
-       private static String zoneName =  "zoneName";
-       private static String serviceName = "serviceName";
-       private static String termName = "termName";
-       private static String userid = "userid";
-       private static String tagPickerName = "tagPickerName";
-       private static String pfListDatas = "prefixListDictionaryDatas";
-       private static String portListDatas = "portListDictionaryDatas";
-       private static String protocolListDatas = "protocolListDictionaryDatas";
-       private static String addressGroupDatas = "addressGroupDictionaryDatas";
-       private static String actionListDatas = "actionListDictionaryDatas";
-       private static String serviceGroupDatas = "serviceGroupDictionaryDatas";
-       private static String securityZoneDatas = "securityZoneDictionaryDatas";
-       private static String serviceListDatas = "serviceListDictionaryDatas";
-       private static String zoneDatas = "zoneDictionaryDatas";
-       private static String termListDictDatas = "termListDictionaryDatas";
-       private static String fwDictListDatas = "fwDictListDictionaryDatas";
-       private static String fwTagPickerDatas = "fwTagPickerDictionaryDatas";
-       private static String fwTagDatas = "fwTagDictionaryDatas";
-       
-       
-       @Autowired
-       public FirewallDictionaryController(CommonClassDao commonClassDao){
-               FirewallDictionaryController.commonClassDao = commonClassDao;
-       }
-       
-       public static void setCommonClassDao(CommonClassDao clDao){
-           commonClassDao = clDao;
-       }
-       
-       public FirewallDictionaryController(){
-               super();
-       }       
-
-       private DictionaryUtils getDictionaryUtilsInstance(){
-               return DictionaryUtils.getDictionaryUtils();
-       }
-       
-       @RequestMapping(value={"/get_PrefixListDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getPrefixListDictionaryEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, pfListDatas, prefixListName, PrefixList.class);
-       }
-
-       @RequestMapping(value={"/get_PrefixListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getPrefixListDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, pfListDatas, PrefixList.class);
-       }
-
-       @RequestMapping(value={"/fw_dictionary/save_prefixList"}, method={RequestMethod.POST})
-       public ModelAndView savePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       PrefixList prefixList;
-                       if (fromAPI) {
-                               prefixList = mapper.readValue(root.get(dictionaryFields).toString(), PrefixList.class);
-                       } else {
-                               prefixList = mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class);
-                       }
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), prefixListName, PrefixList.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               PrefixList data = (PrefixList) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       prefixList.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != prefixList.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(prefixList.getId() == 0){
-                                       commonClassDao.save(prefixList);
-                               }else{
-                                       commonClassDao.update(prefixList); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, pfListDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/fw_dictionary/remove_PrefixList"}, method={RequestMethod.POST})
-       public void removePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, pfListDatas, PrefixList.class);
-       }
-
-       @RequestMapping(value={"/fw_dictionary/validate_prefixList"}, method={RequestMethod.POST})
-       public void validatePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       PrefixList prefixList = mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class);
-                       String responseValidation = successMessage;
-                       try{
-                               CIDR.newCIDR(prefixList.getPrefixListValue());
-                       }catch(UnknownHostException e){
-                               LOGGER.error(e);
-                               responseValidation = errorMsg;
-                       }               
-                       response.setCharacterEncoding(utf8);
-                       response.setContentType(applicationJsonContentType);
-                       request.setCharacterEncoding(utf8);
-
-                       PrintWriter out = response.getWriter();
-                       JSONObject j = new JSONObject("{result: " + responseValidation + "}");
-                       out.write(j.toString());
-               }
-               catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-       }
-
-       @RequestMapping(value={"/get_PortListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getPortListDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, portListDatas, PortList.class);
-       }
-
-       @RequestMapping(value={"/fw_dictionary/save_portName"}, method={RequestMethod.POST})
-       public ModelAndView savePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       PortList portList;
-                       if(fromAPI){
-                               portList = mapper.readValue(root.get(dictionaryFields).toString(), PortList.class);
-                       }else{
-                               portList = mapper.readValue(root.get("portListDictionaryData").toString(), PortList.class);
-                       }
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(portList.getPortName(), "portName", PortList.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               PortList data = (PortList) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       portList.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != portList.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(portList.getId() == 0){
-                                       commonClassDao.save(portList);
-                               }else{
-                                       commonClassDao.update(portList); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, portListDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/fw_dictionary/remove_PortList"}, method={RequestMethod.POST})
-       public void removePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, portListDatas, PortList.class);
-       }
-
-       @RequestMapping(value={"/get_ProtocolListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getProtocolListDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, protocolListDatas, ProtocolList.class);
-       }
-
-       @RequestMapping(value={"/get_ProtocolListDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getProtocolListDictionaryEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, protocolListDatas, protocolName, ProtocolList.class);
-       }
-
-       @RequestMapping(value={"/fw_dictionary/save_protocolList"}, method={RequestMethod.POST})
-       public ModelAndView saveProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       ProtocolList protocolList;
-                       if(fromAPI){
-                               protocolList = mapper.readValue(root.get(dictionaryFields).toString(), ProtocolList.class);
-                       }else{
-                               protocolList = mapper.readValue(root.get("protocolListDictionaryData").toString(), ProtocolList.class);
-                       }
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), protocolName, ProtocolList.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               ProtocolList data = (ProtocolList) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       protocolList.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != protocolList.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(protocolList.getId() == 0){
-                                       commonClassDao.save(protocolList);
-                               }else{
-                                       commonClassDao.update(protocolList); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, protocolListDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/fw_dictionary/remove_protocol"}, method={RequestMethod.POST})
-       public void removeProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, protocolListDatas, ProtocolList.class);
-       }
-
-       @RequestMapping(value={"/get_AddressGroupDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getAddressGroupDictionaryEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, addressGroupDatas, "name", AddressGroup.class);
-       }
-
-       @RequestMapping(value={"/get_AddressGroupData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getAddressGroupDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, addressGroupDatas, AddressGroup.class);
-       }
-
-       @RequestMapping(value={"/fw_dictionary/save_addressGroup"}, method={RequestMethod.POST})
-       public ModelAndView saveAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       AddressGroup addressGroup;
-                       GridData gridData;
-                       if(fromAPI){
-                               addressGroup = mapper.readValue(root.get(dictionaryFields).toString(), AddressGroup.class);
-                               gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
-                       }else{
-                               addressGroup = mapper.readValue(root.get("addressGroupDictionaryData").toString(), AddressGroup.class);
-                               gridData = mapper.readValue(root.get("addressGroupDictionaryData").toString(), GridData.class);
-                       }
-                       if(!addressGroup.getGroupName().startsWith(groupNameStart)){
-                               String groupName = groupNameStart+addressGroup.getGroupName();
-                               addressGroup.setGroupName(groupName);
-                       }
-                       addressGroup.setServiceList(utils.appendKey(gridData.getAttributes(), option, ","));
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               AddressGroup data = (AddressGroup) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       addressGroup.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != addressGroup.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(addressGroup.getId() == 0){
-                                       commonClassDao.save(addressGroup);
-                               }else{
-                                       commonClassDao.update(addressGroup); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, addressGroupDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/fw_dictionary/remove_AddressGroup"}, method={RequestMethod.POST})
-       public void removeAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, addressGroupDatas, AddressGroup.class);
-       }
-
-       @RequestMapping(value={"/get_ActionListDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getActionListDictionaryEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, actionListDatas, "actionName", ActionList.class);
-       }
-
-       @RequestMapping(value={"/get_ActionListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getActionListDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, actionListDatas, ActionList.class);
-       }
-
-       @RequestMapping(value={"/fw_dictionary/save_ActionList"}, method={RequestMethod.POST})
-       public ModelAndView saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       ActionList actionList;
-                       if (fromAPI) {
-                               actionList = mapper.readValue(root.get(dictionaryFields).toString(), ActionList.class);
-                       } else {
-                               actionList = mapper.readValue(root.get("actionListDictionaryData").toString(), ActionList.class);
-                       }
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               ActionList data = (ActionList) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       actionList.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != actionList.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(actionList.getId() == 0){
-                                       commonClassDao.save(actionList);
-                               }else{
-                                       commonClassDao.update(actionList); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(ActionList.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, actionListDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/fw_dictionary/remove_ActionList"}, method={RequestMethod.POST})
-       public void removeActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, actionListDatas, ActionList.class);
-       }
-
-       @RequestMapping(value={"/get_ServiceGroupData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getServiceGroupDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, serviceGroupDatas, GroupServiceList.class);
-       }
-
-       @RequestMapping(value={"/get_ServiceGroupDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getServiceGroupDictionaryEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, serviceGroupDatas, "name", GroupServiceList.class);
-       }
-
-       @RequestMapping(value={"/fw_dictionary/save_serviceGroup"}, method={RequestMethod.POST})
-       public ModelAndView saveServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       GroupServiceList groupServiceList;
-                       GridData gridData;
-                       if(fromAPI){
-                               groupServiceList = mapper.readValue(root.get(dictionaryFields).toString(), GroupServiceList.class);
-                               gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
-                       }else{
-                               groupServiceList = mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GroupServiceList.class);
-                               gridData = mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GridData.class);
-                       }
-                       if(!groupServiceList.getGroupName().startsWith(groupNameStart)){
-                               String groupName = groupNameStart+groupServiceList.getGroupName();
-                               groupServiceList.setGroupName(groupName);
-                       }
-                       groupServiceList.setServiceList(utils.appendKey(gridData.getAttributes(), option, ","));
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               GroupServiceList data = (GroupServiceList) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       groupServiceList.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != groupServiceList.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(groupServiceList.getId() == 0){
-                                       commonClassDao.save(groupServiceList);
-                               }else{
-                                       commonClassDao.update(groupServiceList); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, serviceGroupDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/fw_dictionary/remove_serviceGroup"}, method={RequestMethod.POST})
-       public void removeServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, serviceGroupDatas, GroupServiceList.class);
-       }
-
-       @RequestMapping(value={"/get_SecurityZoneDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getSecurityZoneDictionaryEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, securityZoneDatas, zoneName, SecurityZone.class);
-       }
-
-       @RequestMapping(value={"/get_SecurityZoneData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getSecurityZoneDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, securityZoneDatas, SecurityZone.class);
-       }
-
-       @RequestMapping(value={"/fw_dictionary/save_securityZone"}, method={RequestMethod.POST})
-       public ModelAndView saveSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       SecurityZone securityZone;
-                       if(fromAPI){
-                               securityZone = mapper.readValue(root.get(dictionaryFields).toString(), SecurityZone.class);
-                       }else{
-                               securityZone = mapper.readValue(root.get("securityZoneDictionaryData").toString(), SecurityZone.class);
-                       }
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), zoneName, SecurityZone.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               SecurityZone data = (SecurityZone) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       securityZone.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != securityZone.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(securityZone.getId() == 0){
-                                       commonClassDao.save(securityZone);
-                               }else{
-                                       commonClassDao.update(securityZone); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, securityZoneDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/fw_dictionary/remove_securityZone"}, method={RequestMethod.POST})
-       public void removeSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, securityZoneDatas, SecurityZone.class);
-       }
-
-
-       @RequestMapping(value={"/get_ServiceListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getServiceListDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, serviceListDatas, ServiceList.class);
-       }
-
-       @RequestMapping(value={"/get_ServiceListDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getServiceListDictionaryEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, serviceListDatas, serviceName, ServiceList.class);
-       }
-
-       @RequestMapping(value={"/fw_dictionary/save_serviceList"}, method={RequestMethod.POST})
-       public ModelAndView saveServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       ServiceList serviceList;
-                       GridData serviceListGridData;
-                       if(fromAPI){
-                               serviceList = mapper.readValue(root.get(dictionaryFields).toString(), ServiceList.class);
-                               serviceListGridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
-                       }else{
-                               serviceList = mapper.readValue(root.get("serviceListDictionaryData").toString(), ServiceList.class);
-                               serviceListGridData = mapper.readValue(root.get("serviceListDictionaryData").toString(), GridData.class);
-                       }
-                       serviceList.setServiceTransProtocol(utils.appendKey(serviceListGridData.getTransportProtocols(), option, ","));
-                       serviceList.setServiceAppProtocol(utils.appendKey(serviceListGridData.getAppProtocols(), option, ","));
-                       serviceList.setServiceType("SERVICE");
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), serviceName, ServiceList.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               ServiceList data = (ServiceList) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       serviceList.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != serviceList.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(serviceList.getId() == 0){
-                                       commonClassDao.save(serviceList);
-                               }else{
-                                       commonClassDao.update(serviceList); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(ServiceList.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, serviceListDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/fw_dictionary/remove_serviceList"}, method={RequestMethod.POST})
-       public void removeServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, serviceListDatas, ServiceList.class);
-       }
-
-       @RequestMapping(value={"/get_ZoneData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getZoneDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, zoneDatas, Zone.class);
-       }
-
-       @RequestMapping(value={"/get_ZoneDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getZoneDictionaryEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, zoneDatas, zoneName, Zone.class);
-       }
-
-       @RequestMapping(value={"/fw_dictionary/save_zoneName"}, method={RequestMethod.POST})
-       public ModelAndView saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       Zone zone;
-                       if (fromAPI) {
-                               zone = mapper.readValue(root.get(dictionaryFields).toString(), Zone.class);
-                       } else {
-                               zone = mapper.readValue(root.get("zoneDictionaryData").toString(), Zone.class);
-                       }
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(zone.getZoneName(), zoneName, Zone.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               Zone data = (Zone) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       zone.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != zone.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(zone.getId() == 0){
-                                       commonClassDao.save(zone);
-                               }else{
-                                       commonClassDao.update(zone); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(Zone.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, zoneDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/fw_dictionary/remove_zone"}, method={RequestMethod.POST})
-       public void removeZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, zoneDatas, Zone.class);
-       }
-
-       @RequestMapping(value={"/get_TermListDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getTermListDictionaryEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, termListDictDatas, termName, TermList.class);
-       }
-
-       @RequestMapping(value={"/get_TermListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getTermListDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, termListDictDatas, TermList.class);
-       }
-
-       @RequestMapping(value={"/fw_dictionary/save_termList"}, method={RequestMethod.POST})
-       public ModelAndView saveTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       TermList termList;
-                       TermListData termListDatas;
-                       String userId = null;
-                       if(fromAPI){
-                               termList = mapper.readValue(root.get(dictionaryFields).toString(), TermList.class);
-                               termListDatas = mapper.readValue(root.get(dictionaryFields).toString(), TermListData.class);
-                               userId = "API";
-                       }else{
-                               termList = mapper.readValue(root.get("termListDictionaryData").toString(), TermList.class);
-                               termListDatas = mapper.readValue(root.get("termListDictionaryData").toString(), TermListData.class);
-                               userId = root.get(userid).textValue();
-                       }
-                       
-                       termList.setFromZones(utils.appendKey(termListDatas.getFromZoneDatas(), option, ","));
-                       termList.setToZones(utils.appendKey(termListDatas.getToZoneDatas(), option, ","));
-                       termList.setSrcIPList(utils.appendKey(termListDatas.getSourceListDatas(), option, ","));
-                       termList.setDestIPList(utils.appendKey(termListDatas.getDestinationListDatas(), option, ","));
-                       termList.setSrcPortList(utils.appendKey(termListDatas.getSourceServiceDatas(), option, ","));
-                       termList.setDestPortList(utils.appendKey(termListDatas.getDestinationServiceDatas(), option, ","));
-                       termList.setAction(utils.appendKey(termListDatas.getActionListDatas(), option, ","));
-                       
-                       UserInfo userInfo = utils.getUserInfo(userId);
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(termList.getTermName(), termName, TermList.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               TermList data = (TermList) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       termList.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != termList.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               termList.setUserModifiedBy(userInfo);
-                               if(termList.getId() == 0){
-                                       termList.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(termList);
-                               }else{
-                                       termList.setModifiedDate(new Date());
-                                       commonClassDao.update(termList); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(TermList.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, termListDictDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/fw_dictionary/remove_termList"}, method={RequestMethod.POST})
-       public void removeTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, termListDictDatas, TermList.class);
-       }
-       
-       //ParentList Dictionary Data
-       @RequestMapping(value={"/get_FWDictionaryListDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getFWDictListDictionaryEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, fwDictListDatas, "parentItemName", FirewallDictionaryList.class);
-       }
-
-       @RequestMapping(value={"/get_FWDictionaryListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getFWDictionaryListEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, fwDictListDatas, FirewallDictionaryList.class);
-       }
-
-       @RequestMapping(value={"/fw_dictionary/save_FWDictionaryList"}, method={RequestMethod.POST})
-       public ModelAndView saveFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       FirewallDictionaryList fwDictList;
-                       GridData gridData;
-                       if (fromAPI) {
-                               fwDictList = mapper.readValue(root.get(dictionaryFields).toString(), FirewallDictionaryList.class);
-                               gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
-                       } else {
-                               fwDictList = mapper.readValue(root.get("fwDictListDictionaryData").toString(), FirewallDictionaryList.class);
-                               gridData = mapper.readValue(root.get("fwDictListDictionaryData").toString(), GridData.class);
-                       }
-                       
-                       fwDictList.setServiceList(utils.appendKey(gridData.getAttributes(), option, ","));
-                       fwDictList.setAddressList(utils.appendKey(gridData.getAlAttributes(), option, ","));
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(fwDictList.getParentItemName(), "parentItemName", FirewallDictionaryList.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               FirewallDictionaryList data = (FirewallDictionaryList) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       fwDictList.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != fwDictList.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(fwDictList.getId() == 0){
-                                       commonClassDao.save(fwDictList);
-                               }else{
-                                       commonClassDao.update(fwDictList); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, fwDictListDatas, responseString);
-                       }
-               }
-               catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/fw_dictionary/remove_FWDictionaryList"}, method={RequestMethod.POST})
-       public void removeFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, fwDictListDatas, FirewallDictionaryList.class);
-       }
-
-
-       @RequestMapping(value={"/get_TagPickerNameByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getTagPickerNameEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, fwTagPickerDatas, tagPickerName, FWTagPicker.class);
-       }
-
-       @RequestMapping(value={"/get_TagPickerListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getTagPickerDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, fwTagPickerDatas, FWTagPicker.class);
-       }
-
-       @RequestMapping(value={"/fw_dictionary/save_fwTagPicker"}, method={RequestMethod.POST})
-       public ModelAndView saveFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       FWTagPicker fwTagPicker;
-                       TagGridValues data;
-                       String userId = "";
-                       if (fromAPI) {
-                               fwTagPicker = mapper.readValue(root.get(dictionaryFields).toString(), FWTagPicker.class);
-                               data = mapper.readValue(root.get(dictionaryFields).toString(), TagGridValues.class);
-                               userId = "API";
-                       } else {
-                               fwTagPicker = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class);
-                               data = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class);
-                               userId = root.get(userid).textValue();
-                       }
-                       fwTagPicker.setTagValues(utils.appendKeyValue(data.getTags(), "#", ":"));
-                       
-                       UserInfo userInfo = utils.getUserInfo(userId);
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), tagPickerName, FWTagPicker.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               FWTagPicker data1 = (FWTagPicker) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       fwTagPicker.setId(data1.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data1.getId() != fwTagPicker.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               fwTagPicker.setUserModifiedBy(userInfo);
-                               if(fwTagPicker.getId() == 0){
-                                       fwTagPicker.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(fwTagPicker);
-                               }else{
-                                       fwTagPicker.setModifiedDate(new Date());
-                                       commonClassDao.update(fwTagPicker); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, fwTagPickerDatas, responseString);
-                       }
-               }
-               catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/fw_dictionary/remove_tagPicker"}, method={RequestMethod.POST})
-       public void removeFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, fwTagPickerDatas, FWTagPicker.class);
-       }
-
-       @RequestMapping(value={"/get_TagListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getTagDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, fwTagDatas, FWTag.class);
-       }
-       
-       @RequestMapping(value={"/get_TagNameByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getTagNameEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, fwTagDatas, "fwTagName", FWTag.class);
-       }
-
-
-       @RequestMapping(value={"/fw_dictionary/save_fwTag"}, method={RequestMethod.POST})
-       public ModelAndView saveFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       FWTag fwTag;
-                       TagGridValues tagGridValues;
-                       String userId="";
-                       if(fromAPI){
-                               fwTag = mapper.readValue(root.get(dictionaryFields).toString(), FWTag.class);
-                               tagGridValues = mapper.readValue(root.get(dictionaryFields).toString(), TagGridValues.class);
-                               userId = "API";
-                       }else{
-                               fwTag = mapper.readValue(root.get("fwTagDictionaryData").toString(), FWTag.class);
-                               tagGridValues = mapper.readValue(root.get("fwTagDictionaryData").toString(), TagGridValues.class);
-                               userId = root.get(userid).textValue();
-                       }
-                       fwTag.setTagValues(utils.appendKey(tagGridValues.getTags(), "tags", ","));
-                       
-                       UserInfo userInfo = utils.getUserInfo(userId);
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "fwTagName", FWTag.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               FWTag data = (FWTag) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       fwTag.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != fwTag.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               fwTag.setUserModifiedBy(userInfo);
-                               if(fwTag.getId() == 0){
-                                       fwTag.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(fwTag);
-                               }else{
-                                       fwTag.setModifiedDate(new Date());
-                                       commonClassDao.update(fwTag); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, fwTagDatas, responseString);
-                       }
-               }
-               catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/fw_dictionary/remove_tagList"}, method={RequestMethod.POST})
-       public void removeFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, fwTagDatas, FWTag.class);
-       }
+    private static final Logger LOGGER  = FlexLogger.getLogger(FirewallDictionaryController.class);
+
+    private static CommonClassDao commonClassDao;
+    private static String prefixListName = "prefixListName";
+    private static String successMessage = "success";
+    private static String operation = "operation";
+    private static String errorMsg     = "error";
+    private static String dictionaryFields ="dictionaryFields";
+    private static String duplicateResponseString = "Duplicate";
+    private static String utf8 = "UTF-8";
+    private static String applicationJsonContentType = "application / json";
+    private static String protocolName = "protocolName";
+    private static String groupNameStart = "Group_";
+    private static String option = "option";
+    private static String zoneName =  "zoneName";
+    private static String serviceName = "serviceName";
+    private static String termName = "termName";
+    private static String userid = "userid";
+    private static String tagPickerName = "tagPickerName";
+    private static String pfListDatas = "prefixListDictionaryDatas";
+    private static String portListDatas = "portListDictionaryDatas";
+    private static String protocolListDatas = "protocolListDictionaryDatas";
+    private static String addressGroupDatas = "addressGroupDictionaryDatas";
+    private static String actionListDatas = "actionListDictionaryDatas";
+    private static String serviceGroupDatas = "serviceGroupDictionaryDatas";
+    private static String securityZoneDatas = "securityZoneDictionaryDatas";
+    private static String serviceListDatas = "serviceListDictionaryDatas";
+    private static String zoneDatas = "zoneDictionaryDatas";
+    private static String termListDictDatas = "termListDictionaryDatas";
+    private static String fwDictListDatas = "fwDictListDictionaryDatas";
+    private static String fwTagPickerDatas = "fwTagPickerDictionaryDatas";
+    private static String fwTagDatas = "fwTagDictionaryDatas";
+
+
+    @Autowired
+    public FirewallDictionaryController(CommonClassDao commonClassDao){
+        FirewallDictionaryController.commonClassDao = commonClassDao;
+    }
+
+    public static void setCommonClassDao(CommonClassDao clDao){
+        commonClassDao = clDao;
+    }
+
+    public FirewallDictionaryController(){
+        super();
+    }
+
+    private DictionaryUtils getDictionaryUtilsInstance(){
+        return DictionaryUtils.getDictionaryUtils();
+    }
+
+    @RequestMapping(value={"/get_PrefixListDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getPrefixListDictionaryEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, pfListDatas, prefixListName, PrefixList.class);
+    }
+
+    @RequestMapping(value={"/get_PrefixListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getPrefixListDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, pfListDatas, PrefixList.class);
+    }
+
+    @RequestMapping(value={"/fw_dictionary/save_prefixList"}, method={RequestMethod.POST})
+    public ModelAndView savePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            PrefixList prefixList;
+            if (fromAPI) {
+                prefixList = mapper.readValue(root.get(dictionaryFields).toString(), PrefixList.class);
+            } else {
+                prefixList = mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class);
+            }
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), prefixListName, PrefixList.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                PrefixList data = (PrefixList) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    prefixList.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != prefixList.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(prefixList.getId() == 0){
+                    commonClassDao.save(prefixList);
+                }else{
+                    commonClassDao.update(prefixList);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, pfListDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/fw_dictionary/remove_PrefixList"}, method={RequestMethod.POST})
+    public void removePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, pfListDatas, PrefixList.class);
+    }
+
+    @RequestMapping(value={"/fw_dictionary/validate_prefixList"}, method={RequestMethod.POST})
+    public void validatePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            PrefixList prefixList = mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class);
+            String responseValidation = successMessage;
+            try{
+                CIDR.newCIDR(prefixList.getPrefixListValue());
+            }catch(UnknownHostException e){
+                LOGGER.error(e);
+                responseValidation = errorMsg;
+            }
+            response.setCharacterEncoding(utf8);
+            response.setContentType(applicationJsonContentType);
+            request.setCharacterEncoding(utf8);
+
+            PrintWriter out = response.getWriter();
+            JSONObject j = new JSONObject("{result: " + responseValidation + "}");
+            out.write(j.toString());
+        }
+        catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+    }
+
+    @RequestMapping(value={"/get_PortListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getPortListDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, portListDatas, PortList.class);
+    }
+
+    @RequestMapping(value={"/fw_dictionary/save_portName"}, method={RequestMethod.POST})
+    public ModelAndView savePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            PortList portList;
+            if(fromAPI){
+                portList = mapper.readValue(root.get(dictionaryFields).toString(), PortList.class);
+            }else{
+                portList = mapper.readValue(root.get("portListDictionaryData").toString(), PortList.class);
+            }
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(portList.getPortName(), "portName", PortList.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                PortList data = (PortList) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    portList.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != portList.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(portList.getId() == 0){
+                    commonClassDao.save(portList);
+                }else{
+                    commonClassDao.update(portList);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, portListDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/fw_dictionary/remove_PortList"}, method={RequestMethod.POST})
+    public void removePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, portListDatas, PortList.class);
+    }
+
+    @RequestMapping(value={"/get_ProtocolListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getProtocolListDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, protocolListDatas, ProtocolList.class);
+    }
+
+    @RequestMapping(value={"/get_ProtocolListDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getProtocolListDictionaryEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, protocolListDatas, protocolName, ProtocolList.class);
+    }
+
+    @RequestMapping(value={"/fw_dictionary/save_protocolList"}, method={RequestMethod.POST})
+    public ModelAndView saveProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            ProtocolList protocolList;
+            if(fromAPI){
+                protocolList = mapper.readValue(root.get(dictionaryFields).toString(), ProtocolList.class);
+            }else{
+                protocolList = mapper.readValue(root.get("protocolListDictionaryData").toString(), ProtocolList.class);
+            }
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), protocolName, ProtocolList.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                ProtocolList data = (ProtocolList) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    protocolList.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != protocolList.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(protocolList.getId() == 0){
+                    commonClassDao.save(protocolList);
+                }else{
+                    commonClassDao.update(protocolList);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, protocolListDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/fw_dictionary/remove_protocol"}, method={RequestMethod.POST})
+    public void removeProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, protocolListDatas, ProtocolList.class);
+    }
+
+    @RequestMapping(value={"/get_AddressGroupDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getAddressGroupDictionaryEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, addressGroupDatas, "name", AddressGroup.class);
+    }
+
+    @RequestMapping(value={"/get_AddressGroupData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getAddressGroupDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, addressGroupDatas, AddressGroup.class);
+    }
+
+    @RequestMapping(value={"/fw_dictionary/save_addressGroup"}, method={RequestMethod.POST})
+    public ModelAndView saveAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            AddressGroup addressGroup;
+            GridData gridData;
+            if(fromAPI){
+                addressGroup = mapper.readValue(root.get(dictionaryFields).toString(), AddressGroup.class);
+                gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
+            }else{
+                addressGroup = mapper.readValue(root.get("addressGroupDictionaryData").toString(), AddressGroup.class);
+                gridData = mapper.readValue(root.get("addressGroupDictionaryData").toString(), GridData.class);
+            }
+            if(!addressGroup.getGroupName().startsWith(groupNameStart)){
+                String groupName = groupNameStart+addressGroup.getGroupName();
+                addressGroup.setGroupName(groupName);
+            }
+            addressGroup.setServiceList(utils.appendKey(gridData.getAttributes(), option, ","));
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                AddressGroup data = (AddressGroup) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    addressGroup.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != addressGroup.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(addressGroup.getId() == 0){
+                    commonClassDao.save(addressGroup);
+                }else{
+                    commonClassDao.update(addressGroup);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, addressGroupDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/fw_dictionary/remove_AddressGroup"}, method={RequestMethod.POST})
+    public void removeAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, addressGroupDatas, AddressGroup.class);
+    }
+
+    @RequestMapping(value={"/get_ActionListDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getActionListDictionaryEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, actionListDatas, "actionName", ActionList.class);
+    }
+
+    @RequestMapping(value={"/get_ActionListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getActionListDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, actionListDatas, ActionList.class);
+    }
+
+    @RequestMapping(value={"/fw_dictionary/save_ActionList"}, method={RequestMethod.POST})
+    public ModelAndView saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            ActionList actionList;
+            if (fromAPI) {
+                actionList = mapper.readValue(root.get(dictionaryFields).toString(), ActionList.class);
+            } else {
+                actionList = mapper.readValue(root.get("actionListDictionaryData").toString(), ActionList.class);
+            }
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                ActionList data = (ActionList) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    actionList.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != actionList.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(actionList.getId() == 0){
+                    commonClassDao.save(actionList);
+                }else{
+                    commonClassDao.update(actionList);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(ActionList.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, actionListDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/fw_dictionary/remove_ActionList"}, method={RequestMethod.POST})
+    public void removeActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, actionListDatas, ActionList.class);
+    }
+
+    @RequestMapping(value={"/get_ServiceGroupData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getServiceGroupDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, serviceGroupDatas, GroupServiceList.class);
+    }
+
+    @RequestMapping(value={"/get_ServiceGroupDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getServiceGroupDictionaryEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, serviceGroupDatas, "name", GroupServiceList.class);
+    }
+
+    @RequestMapping(value={"/fw_dictionary/save_serviceGroup"}, method={RequestMethod.POST})
+    public ModelAndView saveServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            GroupServiceList groupServiceList;
+            GridData gridData;
+            if(fromAPI){
+                groupServiceList = mapper.readValue(root.get(dictionaryFields).toString(), GroupServiceList.class);
+                gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
+            }else{
+                groupServiceList = mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GroupServiceList.class);
+                gridData = mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GridData.class);
+            }
+            if(!groupServiceList.getGroupName().startsWith(groupNameStart)){
+                String groupName = groupNameStart+groupServiceList.getGroupName();
+                groupServiceList.setGroupName(groupName);
+            }
+            groupServiceList.setServiceList(utils.appendKey(gridData.getAttributes(), option, ","));
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                GroupServiceList data = (GroupServiceList) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    groupServiceList.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != groupServiceList.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(groupServiceList.getId() == 0){
+                    commonClassDao.save(groupServiceList);
+                }else{
+                    commonClassDao.update(groupServiceList);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, serviceGroupDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/fw_dictionary/remove_serviceGroup"}, method={RequestMethod.POST})
+    public void removeServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, serviceGroupDatas, GroupServiceList.class);
+    }
+
+    @RequestMapping(value={"/get_SecurityZoneDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getSecurityZoneDictionaryEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, securityZoneDatas, zoneName, SecurityZone.class);
+    }
+
+    @RequestMapping(value={"/get_SecurityZoneData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getSecurityZoneDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, securityZoneDatas, SecurityZone.class);
+    }
+
+    @RequestMapping(value={"/fw_dictionary/save_securityZone"}, method={RequestMethod.POST})
+    public ModelAndView saveSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            SecurityZone securityZone;
+            if(fromAPI){
+                securityZone = mapper.readValue(root.get(dictionaryFields).toString(), SecurityZone.class);
+            }else{
+                securityZone = mapper.readValue(root.get("securityZoneDictionaryData").toString(), SecurityZone.class);
+            }
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), zoneName, SecurityZone.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                SecurityZone data = (SecurityZone) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    securityZone.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != securityZone.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(securityZone.getId() == 0){
+                    commonClassDao.save(securityZone);
+                }else{
+                    commonClassDao.update(securityZone);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, securityZoneDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/fw_dictionary/remove_securityZone"}, method={RequestMethod.POST})
+    public void removeSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, securityZoneDatas, SecurityZone.class);
+    }
+
+
+    @RequestMapping(value={"/get_ServiceListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getServiceListDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, serviceListDatas, ServiceList.class);
+    }
+
+    @RequestMapping(value={"/get_ServiceListDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getServiceListDictionaryEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, serviceListDatas, serviceName, ServiceList.class);
+    }
+
+    @RequestMapping(value={"/fw_dictionary/save_serviceList"}, method={RequestMethod.POST})
+    public ModelAndView saveServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            ServiceList serviceList;
+            GridData serviceListGridData;
+            if(fromAPI){
+                serviceList = mapper.readValue(root.get(dictionaryFields).toString(), ServiceList.class);
+                serviceListGridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
+            }else{
+                serviceList = mapper.readValue(root.get("serviceListDictionaryData").toString(), ServiceList.class);
+                serviceListGridData = mapper.readValue(root.get("serviceListDictionaryData").toString(), GridData.class);
+            }
+            serviceList.setServiceTransProtocol(utils.appendKey(serviceListGridData.getTransportProtocols(), option, ","));
+            serviceList.setServiceAppProtocol(utils.appendKey(serviceListGridData.getAppProtocols(), option, ","));
+            serviceList.setServiceType("SERVICE");
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), serviceName, ServiceList.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                ServiceList data = (ServiceList) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    serviceList.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != serviceList.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(serviceList.getId() == 0){
+                    commonClassDao.save(serviceList);
+                }else{
+                    commonClassDao.update(serviceList);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(ServiceList.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, serviceListDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/fw_dictionary/remove_serviceList"}, method={RequestMethod.POST})
+    public void removeServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, serviceListDatas, ServiceList.class);
+    }
+
+    @RequestMapping(value={"/get_ZoneData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getZoneDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, zoneDatas, Zone.class);
+    }
+
+    @RequestMapping(value={"/get_ZoneDictionaryDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getZoneDictionaryEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, zoneDatas, zoneName, Zone.class);
+    }
+
+    @RequestMapping(value={"/fw_dictionary/save_zoneName"}, method={RequestMethod.POST})
+    public ModelAndView saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            Zone zone;
+            if (fromAPI) {
+                zone = mapper.readValue(root.get(dictionaryFields).toString(), Zone.class);
+            } else {
+                zone = mapper.readValue(root.get("zoneDictionaryData").toString(), Zone.class);
+            }
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(zone.getZoneName(), zoneName, Zone.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                Zone data = (Zone) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    zone.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != zone.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(zone.getId() == 0){
+                    commonClassDao.save(zone);
+                }else{
+                    commonClassDao.update(zone);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(Zone.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, zoneDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/fw_dictionary/remove_zone"}, method={RequestMethod.POST})
+    public void removeZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, zoneDatas, Zone.class);
+    }
+
+    @RequestMapping(value={"/get_TermListDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getTermListDictionaryEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, termListDictDatas, termName, TermList.class);
+    }
+
+    @RequestMapping(value={"/get_TermListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getTermListDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, termListDictDatas, TermList.class);
+    }
+
+    @RequestMapping(value={"/fw_dictionary/save_termList"}, method={RequestMethod.POST})
+    public ModelAndView saveTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            TermList termList;
+            TermListData termListDatas;
+            String userId = null;
+            if(fromAPI){
+                termList = mapper.readValue(root.get(dictionaryFields).toString(), TermList.class);
+                termListDatas = mapper.readValue(root.get(dictionaryFields).toString(), TermListData.class);
+                userId = "API";
+            }else{
+                termList = mapper.readValue(root.get("termListDictionaryData").toString(), TermList.class);
+                termListDatas = mapper.readValue(root.get("termListDictionaryData").toString(), TermListData.class);
+                userId = root.get(userid).textValue();
+            }
+
+            termList.setFromZones(utils.appendKey(termListDatas.getFromZoneDatas(), option, ","));
+            termList.setToZones(utils.appendKey(termListDatas.getToZoneDatas(), option, ","));
+            termList.setSrcIPList(utils.appendKey(termListDatas.getSourceListDatas(), option, ","));
+            termList.setDestIPList(utils.appendKey(termListDatas.getDestinationListDatas(), option, ","));
+            termList.setSrcPortList(utils.appendKey(termListDatas.getSourceServiceDatas(), option, ","));
+            termList.setDestPortList(utils.appendKey(termListDatas.getDestinationServiceDatas(), option, ","));
+            termList.setAction(utils.appendKey(termListDatas.getActionListDatas(), option, ","));
+
+            UserInfo userInfo = utils.getUserInfo(userId);
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(termList.getTermName(), termName, TermList.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                TermList data = (TermList) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    termList.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != termList.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                termList.setUserModifiedBy(userInfo);
+                if(termList.getId() == 0){
+                    termList.setUserCreatedBy(userInfo);
+                    commonClassDao.save(termList);
+                }else{
+                    termList.setModifiedDate(new Date());
+                    commonClassDao.update(termList);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(TermList.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, termListDictDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/fw_dictionary/remove_termList"}, method={RequestMethod.POST})
+    public void removeTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, termListDictDatas, TermList.class);
+    }
+
+    //ParentList Dictionary Data
+    @RequestMapping(value={"/get_FWDictionaryListDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getFWDictListDictionaryEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, fwDictListDatas, "parentItemName", FirewallDictionaryList.class);
+    }
+
+    @RequestMapping(value={"/get_FWDictionaryListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getFWDictionaryListEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, fwDictListDatas, FirewallDictionaryList.class);
+    }
+
+    @RequestMapping(value={"/fw_dictionary/save_FWDictionaryList"}, method={RequestMethod.POST})
+    public ModelAndView saveFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            FirewallDictionaryList fwDictList;
+            GridData gridData;
+            if (fromAPI) {
+                fwDictList = mapper.readValue(root.get(dictionaryFields).toString(), FirewallDictionaryList.class);
+                gridData = mapper.readValue(root.get(dictionaryFields).toString(), GridData.class);
+            } else {
+                fwDictList = mapper.readValue(root.get("fwDictListDictionaryData").toString(), FirewallDictionaryList.class);
+                gridData = mapper.readValue(root.get("fwDictListDictionaryData").toString(), GridData.class);
+            }
+
+            fwDictList.setServiceList(utils.appendKey(gridData.getAttributes(), option, ","));
+            fwDictList.setAddressList(utils.appendKey(gridData.getAlAttributes(), option, ","));
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(fwDictList.getParentItemName(), "parentItemName", FirewallDictionaryList.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                FirewallDictionaryList data = (FirewallDictionaryList) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    fwDictList.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != fwDictList.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(fwDictList.getId() == 0){
+                    commonClassDao.save(fwDictList);
+                }else{
+                    commonClassDao.update(fwDictList);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, fwDictListDatas, responseString);
+            }
+        }
+        catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/fw_dictionary/remove_FWDictionaryList"}, method={RequestMethod.POST})
+    public void removeFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, fwDictListDatas, FirewallDictionaryList.class);
+    }
+
+
+    @RequestMapping(value={"/get_TagPickerNameByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getTagPickerNameEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, fwTagPickerDatas, tagPickerName, FWTagPicker.class);
+    }
+
+    @RequestMapping(value={"/get_TagPickerListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getTagPickerDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, fwTagPickerDatas, FWTagPicker.class);
+    }
+
+    @RequestMapping(value={"/fw_dictionary/save_fwTagPicker"}, method={RequestMethod.POST})
+    public ModelAndView saveFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            FWTagPicker fwTagPicker;
+            TagGridValues data;
+            String userId = "";
+            if (fromAPI) {
+                fwTagPicker = mapper.readValue(root.get(dictionaryFields).toString(), FWTagPicker.class);
+                data = mapper.readValue(root.get(dictionaryFields).toString(), TagGridValues.class);
+                userId = "API";
+            } else {
+                fwTagPicker = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class);
+                data = mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class);
+                userId = root.get(userid).textValue();
+            }
+            fwTagPicker.setTagValues(utils.appendKeyValue(data.getTags(), "#", ":"));
+
+            UserInfo userInfo = utils.getUserInfo(userId);
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), tagPickerName, FWTagPicker.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                FWTagPicker data1 = (FWTagPicker) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    fwTagPicker.setId(data1.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data1.getId() != fwTagPicker.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                fwTagPicker.setUserModifiedBy(userInfo);
+                if(fwTagPicker.getId() == 0){
+                    fwTagPicker.setUserCreatedBy(userInfo);
+                    commonClassDao.save(fwTagPicker);
+                }else{
+                    fwTagPicker.setModifiedDate(new Date());
+                    commonClassDao.update(fwTagPicker);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, fwTagPickerDatas, responseString);
+            }
+        }
+        catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/fw_dictionary/remove_tagPicker"}, method={RequestMethod.POST})
+    public void removeFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, fwTagPickerDatas, FWTagPicker.class);
+    }
+
+    @RequestMapping(value={"/get_TagListData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getTagDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, fwTagDatas, FWTag.class);
+    }
+
+    @RequestMapping(value={"/get_TagNameByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getTagNameEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, fwTagDatas, "fwTagName", FWTag.class);
+    }
+
+
+    @RequestMapping(value={"/fw_dictionary/save_fwTag"}, method={RequestMethod.POST})
+    public ModelAndView saveFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            FWTag fwTag;
+            TagGridValues tagGridValues;
+            String userId="";
+            if(fromAPI){
+                fwTag = mapper.readValue(root.get(dictionaryFields).toString(), FWTag.class);
+                tagGridValues = mapper.readValue(root.get(dictionaryFields).toString(), TagGridValues.class);
+                userId = "API";
+            }else{
+                fwTag = mapper.readValue(root.get("fwTagDictionaryData").toString(), FWTag.class);
+                tagGridValues = mapper.readValue(root.get("fwTagDictionaryData").toString(), TagGridValues.class);
+                userId = root.get(userid).textValue();
+            }
+            fwTag.setTagValues(utils.appendKey(tagGridValues.getTags(), "tags", ","));
+
+            UserInfo userInfo = utils.getUserInfo(userId);
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "fwTagName", FWTag.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                FWTag data = (FWTag) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    fwTag.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != fwTag.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                fwTag.setUserModifiedBy(userInfo);
+                if(fwTag.getId() == 0){
+                    fwTag.setUserCreatedBy(userInfo);
+                    commonClassDao.save(fwTag);
+                }else{
+                    fwTag.setModifiedDate(new Date());
+                    commonClassDao.update(fwTag);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, fwTagDatas, responseString);
+            }
+        }
+        catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/fw_dictionary/remove_tagList"}, method={RequestMethod.POST})
+    public void removeFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, fwTagDatas, FWTag.class);
+    }
 }
 
 class TagGridValues{
-       private List<Object> tags;
+    private List<Object> tags;
 
-       public List<Object> getTags() {
-               return tags;
-       }
+    public List<Object> getTags() {
+        return tags;
+    }
 
-       public void setTags(List<Object> tags) {
-               this.tags = tags;
-       }
+    public void setTags(List<Object> tags) {
+        this.tags = tags;
+    }
 }
 
 class AGGridData{
-       private List<Object> attributes;
+    private List<Object> attributes;
 
-       public List<Object> getAttributes() {
-               return attributes;
-       }
+    public List<Object> getAttributes() {
+        return attributes;
+    }
 
-       public void setAttributes(List<Object> attributes) {
-               this.attributes = attributes;
-       }
+    public void setAttributes(List<Object> attributes) {
+        this.attributes = attributes;
+    }
 }
 
 class TermListData{
-       private List<Object> fromZoneDatas;
-       private List<Object> toZoneDatas;
-       private List<Object> sourceListDatas;
-       private List<Object> destinationListDatas;
-       private List<Object> sourceServiceDatas;
-       private List<Object> destinationServiceDatas;
-       private List<Object> actionListDatas;
-       public List<Object> getFromZoneDatas() {
-               return fromZoneDatas;
-       }
-       public void setFromZoneDatas(List<Object> fromZoneDatas) {
-               this.fromZoneDatas = fromZoneDatas;
-       }
-       public List<Object> getToZoneDatas() {
-               return toZoneDatas;
-       }
-       public void setToZoneDatas(List<Object> toZoneDatas) {
-               this.toZoneDatas = toZoneDatas;
-       }
-       public List<Object> getSourceListDatas() {
-               return sourceListDatas;
-       }
-       public void setSourceListDatas(List<Object> sourceListDatas) {
-               this.sourceListDatas = sourceListDatas;
-       }
-       public List<Object> getDestinationListDatas() {
-               return destinationListDatas;
-       }
-       public void setDestinationListDatas(List<Object> destinationListDatas) {
-               this.destinationListDatas = destinationListDatas;
-       }
-       public List<Object> getSourceServiceDatas() {
-               return sourceServiceDatas;
-       }
-       public void setSourceServiceDatas(List<Object> sourceServiceDatas) {
-               this.sourceServiceDatas = sourceServiceDatas;
-       }
-       public List<Object> getDestinationServiceDatas() {
-               return destinationServiceDatas;
-       }
-       public void setDestinationServiceDatas(List<Object> destinationServiceDatas) {
-               this.destinationServiceDatas = destinationServiceDatas;
-       }
-       public List<Object> getActionListDatas() {
-               return actionListDatas;
-       }
-       public void setActionListDatas(List<Object> actionListDatas) {
-               this.actionListDatas = actionListDatas;
-       }
+    private List<Object> fromZoneDatas;
+    private List<Object> toZoneDatas;
+    private List<Object> sourceListDatas;
+    private List<Object> destinationListDatas;
+    private List<Object> sourceServiceDatas;
+    private List<Object> destinationServiceDatas;
+    private List<Object> actionListDatas;
+    public List<Object> getFromZoneDatas() {
+        return fromZoneDatas;
+    }
+    public void setFromZoneDatas(List<Object> fromZoneDatas) {
+        this.fromZoneDatas = fromZoneDatas;
+    }
+    public List<Object> getToZoneDatas() {
+        return toZoneDatas;
+    }
+    public void setToZoneDatas(List<Object> toZoneDatas) {
+        this.toZoneDatas = toZoneDatas;
+    }
+    public List<Object> getSourceListDatas() {
+        return sourceListDatas;
+    }
+    public void setSourceListDatas(List<Object> sourceListDatas) {
+        this.sourceListDatas = sourceListDatas;
+    }
+    public List<Object> getDestinationListDatas() {
+        return destinationListDatas;
+    }
+    public void setDestinationListDatas(List<Object> destinationListDatas) {
+        this.destinationListDatas = destinationListDatas;
+    }
+    public List<Object> getSourceServiceDatas() {
+        return sourceServiceDatas;
+    }
+    public void setSourceServiceDatas(List<Object> sourceServiceDatas) {
+        this.sourceServiceDatas = sourceServiceDatas;
+    }
+    public List<Object> getDestinationServiceDatas() {
+        return destinationServiceDatas;
+    }
+    public void setDestinationServiceDatas(List<Object> destinationServiceDatas) {
+        this.destinationServiceDatas = destinationServiceDatas;
+    }
+    public List<Object> getActionListDatas() {
+        return actionListDatas;
+    }
+    public void setActionListDatas(List<Object> actionListDatas) {
+        this.actionListDatas = actionListDatas;
+    }
 }
\ No newline at end of file
index 6acae3f..1f1eca5 100644 (file)
@@ -64,10 +64,10 @@ import com.google.gson.Gson;
 
 @Controller
 public class MicroServiceDictionaryController {
-       private static final Logger LOGGER  = FlexLogger.getLogger(MicroServiceDictionaryController.class);
+    private static final Logger LOGGER  = FlexLogger.getLogger(MicroServiceDictionaryController.class);
+
+    private static CommonClassDao commonClassDao;
 
-       private static CommonClassDao commonClassDao;
-       
     private static String successMapKey= "successMapKey";
     private static String successMsg = "success";
     private static String operation = "operation";
@@ -77,255 +77,255 @@ public class MicroServiceDictionaryController {
     private LinkedHashMap<String,MSAttributeObject > classMap;
     private List<String> modelList = new ArrayList<>();
     private static String apiflag = "apiflag";
-       private static String dictionaryFields ="dictionaryFields";
-       private static String update = "update";
-       private static String duplicateResponseString = "Duplicate";
-       private static String microServiceModelsDictionaryDatas = "microServiceModelsDictionaryDatas";
-       private static String modelName = "modelName";
-       private static String microServiceModelsDictionaryData = "microServiceModelsDictionaryData";
-       private static String description = "description";
-       private static String version = "version";
-       private static String classMapData = "classMap";
-       private static String dcaeUUIDDatas = "dcaeUUIDDictionaryDatas";
-       private static String microServiceConfigNameDatas = "microServiceConfigNameDictionaryDatas";
-       private static String microServiceLocationDatas = "microServiceLocationDictionaryDatas";
-       private static String microServiceAttributeDatas = "microServiceAttributeDictionaryDatas";
-       private static String microServiceHeaderDefaultDatas = "microServiceHeaderDefaultDatas";
+    private static String dictionaryFields ="dictionaryFields";
+    private static String update = "update";
+    private static String duplicateResponseString = "Duplicate";
+    private static String microServiceModelsDictionaryDatas = "microServiceModelsDictionaryDatas";
+    private static String modelName = "modelName";
+    private static String microServiceModelsDictionaryData = "microServiceModelsDictionaryData";
+    private static String description = "description";
+    private static String version = "version";
+    private static String classMapData = "classMap";
+    private static String dcaeUUIDDatas = "dcaeUUIDDictionaryDatas";
+    private static String microServiceConfigNameDatas = "microServiceConfigNameDictionaryDatas";
+    private static String microServiceLocationDatas = "microServiceLocationDictionaryDatas";
+    private static String microServiceAttributeDatas = "microServiceAttributeDictionaryDatas";
+    private static String microServiceHeaderDefaultDatas = "microServiceHeaderDefaultDatas";
 
     public MicroServiceDictionaryController(){
-       super();
+        super();
     }  
-       
+
     private DictionaryUtils getDictionaryUtilsInstance(){
-               return DictionaryUtils.getDictionaryUtils();
-       }
+        return DictionaryUtils.getDictionaryUtils();
+    }
     
-       @Autowired
-       public MicroServiceDictionaryController(CommonClassDao commonClassDao){
-               MicroServiceDictionaryController.commonClassDao = commonClassDao;
-       }
-       public static void setCommonClassDao(CommonClassDao commonClassDao) {
-               MicroServiceDictionaryController.commonClassDao = commonClassDao;
-       }
-
-       MSModelUtils utils = new MSModelUtils(XACMLPapServlet.getMsOnapName(), XACMLPapServlet.getMsPolicyName());
-       
-       private MicroServiceModels newModel;
-       
-       @RequestMapping(value={"/get_DCAEUUIDDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getDCAEUUIDDictionaryByNameEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, dcaeUUIDDatas, "name", DCAEuuid.class);
-       }
-
-       @RequestMapping(value={"/get_DCAEUUIDData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getDCAEUUIDDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, dcaeUUIDDatas, DCAEuuid.class);
-       }
-       
-       @RequestMapping(value={"/ms_dictionary/save_dcaeUUID"}, method={RequestMethod.POST})
-       public ModelAndView saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
+    @Autowired
+    public MicroServiceDictionaryController(CommonClassDao commonClassDao){
+        MicroServiceDictionaryController.commonClassDao = commonClassDao;
+    }
+    public static void setCommonClassDao(CommonClassDao commonClassDao) {
+        MicroServiceDictionaryController.commonClassDao = commonClassDao;
+    }
+
+    MSModelUtils utils = new MSModelUtils(XACMLPapServlet.getMsOnapName(), XACMLPapServlet.getMsPolicyName());
+
+    private MicroServiceModels newModel;
+
+    @RequestMapping(value={"/get_DCAEUUIDDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getDCAEUUIDDictionaryByNameEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, dcaeUUIDDatas, "name", DCAEuuid.class);
+    }
+
+    @RequestMapping(value={"/get_DCAEUUIDData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getDCAEUUIDDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, dcaeUUIDDatas, DCAEuuid.class);
+    }
+
+    @RequestMapping(value={"/ms_dictionary/save_dcaeUUID"}, method={RequestMethod.POST})
+    public ModelAndView saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
             DCAEuuid dCAEuuid;
             if(fromAPI){
                 dCAEuuid = mapper.readValue(root.get(dictionaryFields).toString(), DCAEuuid.class);
             }else{
-               dCAEuuid = mapper.readValue(root.get("dcaeUUIDDictionaryData").toString(), DCAEuuid.class);
+                dCAEuuid = mapper.readValue(root.get("dcaeUUIDDictionaryData").toString(), DCAEuuid.class);
             }
             
             List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(dCAEuuid.getName(), "name", DCAEuuid.class);
-                       boolean duplicateflag = false;
-                       if(duplicateData != null && !duplicateData.isEmpty()){
-                               DCAEuuid data = (DCAEuuid) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       dCAEuuid.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != dCAEuuid.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(dCAEuuid.getId() == 0){
-                                       commonClassDao.save(dCAEuuid);
-                               }else{
-                                       commonClassDao.update(dCAEuuid); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, dcaeUUIDDatas, responseString);
-                       }
+            boolean duplicateflag = false;
+            if(duplicateData != null && !duplicateData.isEmpty()){
+                DCAEuuid data = (DCAEuuid) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    dCAEuuid.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != dCAEuuid.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(dCAEuuid.getId() == 0){
+                    commonClassDao.save(dCAEuuid);
+                }else{
+                    commonClassDao.update(dCAEuuid);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, dcaeUUIDDatas, responseString);
+            }
         }catch (Exception e){
-               utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/ms_dictionary/remove_dcaeuuid"}, method={RequestMethod.POST})
-       public void removeDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, dcaeUUIDDatas, DCAEuuid.class);
-       }
-       
-       @RequestMapping(value={"/get_MicroServiceConfigNameDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, microServiceConfigNameDatas, "name", MicroServiceConfigName.class);
-       }
-       
-       @RequestMapping(value={"/get_MicroServiceConfigNameData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getMicroServiceConfigNameDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, microServiceConfigNameDatas, MicroServiceConfigName.class);
-       }
-       
-       @RequestMapping(value={"/ms_dictionary/save_configName"}, method={RequestMethod.POST})
-       public ModelAndView saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/ms_dictionary/remove_dcaeuuid"}, method={RequestMethod.POST})
+    public void removeDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, dcaeUUIDDatas, DCAEuuid.class);
+    }
+
+    @RequestMapping(value={"/get_MicroServiceConfigNameDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, microServiceConfigNameDatas, "name", MicroServiceConfigName.class);
+    }
+
+    @RequestMapping(value={"/get_MicroServiceConfigNameData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getMicroServiceConfigNameDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, microServiceConfigNameDatas, MicroServiceConfigName.class);
+    }
+
+    @RequestMapping(value={"/ms_dictionary/save_configName"}, method={RequestMethod.POST})
+    public ModelAndView saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
             MicroServiceConfigName microServiceConfigName;
             if(fromAPI){
                 microServiceConfigName = mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceConfigName.class);
             }else{
-               microServiceConfigName = mapper.readValue(root.get("microServiceConfigNameDictionaryData").toString(), MicroServiceConfigName.class);
+                microServiceConfigName = mapper.readValue(root.get("microServiceConfigNameDictionaryData").toString(), MicroServiceConfigName.class);
             }
             List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(microServiceConfigName.getName(), "name", MicroServiceConfigName.class);
-                       boolean duplicateflag = false;
-                       if(duplicateData != null && !duplicateData.isEmpty()){
-                               MicroServiceConfigName data = (MicroServiceConfigName) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       microServiceConfigName.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != microServiceConfigName.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(microServiceConfigName.getId() == 0){
-                                       commonClassDao.save(microServiceConfigName);
-                               }else{
-                                       commonClassDao.update(microServiceConfigName); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, microServiceConfigNameDatas, responseString);
-                       }
+            boolean duplicateflag = false;
+            if(duplicateData != null && !duplicateData.isEmpty()){
+                MicroServiceConfigName data = (MicroServiceConfigName) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    microServiceConfigName.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != microServiceConfigName.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(microServiceConfigName.getId() == 0){
+                    commonClassDao.save(microServiceConfigName);
+                }else{
+                    commonClassDao.update(microServiceConfigName);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, microServiceConfigNameDatas, responseString);
+            }
         }catch (Exception e){
-               utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/ms_dictionary/remove_msConfigName"}, method={RequestMethod.POST})
-       public void removeMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, microServiceConfigNameDatas, MicroServiceConfigName.class);
-       }
-       
-       @RequestMapping(value={"/get_MicroServiceLocationDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getMicroServiceLocationByNameDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, microServiceLocationDatas, "name", MicroServiceLocation.class);
-       }
-       
-       @RequestMapping(value={"/get_MicroServiceLocationData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getMicroServiceLocationDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, microServiceLocationDatas, MicroServiceLocation.class);
-       }
-       
-       @RequestMapping(value={"/ms_dictionary/save_location"}, method={RequestMethod.POST})
-       public ModelAndView saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response)throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/ms_dictionary/remove_msConfigName"}, method={RequestMethod.POST})
+    public void removeMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, microServiceConfigNameDatas, MicroServiceConfigName.class);
+    }
+
+    @RequestMapping(value={"/get_MicroServiceLocationDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getMicroServiceLocationByNameDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, microServiceLocationDatas, "name", MicroServiceLocation.class);
+    }
+
+    @RequestMapping(value={"/get_MicroServiceLocationData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getMicroServiceLocationDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, microServiceLocationDatas, MicroServiceLocation.class);
+    }
+
+    @RequestMapping(value={"/ms_dictionary/save_location"}, method={RequestMethod.POST})
+    public ModelAndView saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response)throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
             MicroServiceLocation microServiceLocation;
             if(fromAPI){
                 microServiceLocation = mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceLocation.class);
             }else{
-               microServiceLocation = mapper.readValue(root.get("microServiceLocationDictionaryData").toString(), MicroServiceLocation.class);
+                microServiceLocation = mapper.readValue(root.get("microServiceLocationDictionaryData").toString(), MicroServiceLocation.class);
             }
             
             List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(microServiceLocation.getName(), "name", MicroServiceLocation.class);
-                       boolean duplicateflag = false;
-                       if(duplicateData != null && !duplicateData.isEmpty()){
-                               MicroServiceLocation data = (MicroServiceLocation) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       microServiceLocation.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != microServiceLocation.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(microServiceLocation.getId() == 0){
-                                       commonClassDao.save(microServiceLocation);
-                               }else{
-                                       commonClassDao.update(microServiceLocation); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, microServiceLocationDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/ms_dictionary/remove_msLocation"}, method={RequestMethod.POST})
-       public void removeMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, microServiceLocationDatas, MicroServiceLocation.class);
-       }
-       
+            boolean duplicateflag = false;
+            if(duplicateData != null && !duplicateData.isEmpty()){
+                MicroServiceLocation data = (MicroServiceLocation) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    microServiceLocation.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != microServiceLocation.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(microServiceLocation.getId() == 0){
+                    commonClassDao.save(microServiceLocation);
+                }else{
+                    commonClassDao.update(microServiceLocation);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, microServiceLocationDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/ms_dictionary/remove_msLocation"}, method={RequestMethod.POST})
+    public void removeMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, microServiceLocationDatas, MicroServiceLocation.class);
+    }
+
     @RequestMapping(value={"/get_MicroServiceAttributeDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getMicroServiceAttributeByNameDictionaryEntityData(HttpServletResponse response){
-       DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, microServiceAttributeDatas, "name", MicroServiceAttribute.class);
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, microServiceAttributeDatas, "name", MicroServiceAttribute.class);
     }
     
     @RequestMapping(value={"/get_MicroServiceAttributeData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getMicroServiceAttributeDictionaryEntityData(HttpServletResponse response){
-       DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, microServiceAttributeDatas, MicroServiceAttribute.class);
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, microServiceAttributeDatas, MicroServiceAttribute.class);
     }
     
     @RequestMapping(value={"/ms_dictionary/save_modelAttribute"}, method={RequestMethod.POST})
     public ModelAndView saveMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-       DictionaryUtils utils = getDictionaryUtilsInstance();
+        DictionaryUtils utils = getDictionaryUtilsInstance();
         try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
+            boolean fromAPI = utils.isRequestFromAPI(request);
             ObjectMapper mapper = new ObjectMapper();
             mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
             JsonNode root = mapper.readTree(request.getReader());
@@ -339,52 +339,52 @@ public class MicroServiceDictionaryController {
             }
             checkValue = microServiceAttribute.getName() + ":" + microServiceAttribute.getValue() + ":" + microServiceAttribute.getModelName();
             List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(checkValue, "name:value:modelName", MicroServiceAttribute.class);
-                       boolean duplicateflag = false;
-                       if(duplicateData != null && !duplicateData.isEmpty()){
-                               MicroServiceAttribute data = (MicroServiceAttribute) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       microServiceAttribute.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != microServiceAttribute.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(microServiceAttribute.getId() == 0){
-                                       commonClassDao.save(microServiceAttribute);
-                               }else{
-                                       commonClassDao.update(microServiceAttribute); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, microServiceAttributeDatas, responseString);
-                       }
+            boolean duplicateflag = false;
+            if(duplicateData != null && !duplicateData.isEmpty()){
+                MicroServiceAttribute data = (MicroServiceAttribute) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    microServiceAttribute.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != microServiceAttribute.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(microServiceAttribute.getId() == 0){
+                    commonClassDao.save(microServiceAttribute);
+                }else{
+                    commonClassDao.update(microServiceAttribute);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, microServiceAttributeDatas, responseString);
+            }
         }
         catch (Exception e){
-               utils.setErrorResponseData(response, e);
+            utils.setErrorResponseData(response, e);
         }
         return null;
     }
  
     @RequestMapping(value={"/ms_dictionary/remove_modelAttribute"}, method={RequestMethod.POST})
     public void removeMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-       DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, microServiceAttributeDatas, MicroServiceAttribute.class);
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, microServiceAttributeDatas, MicroServiceAttribute.class);
     }
  
-       
-       @RequestMapping(value={"/get_MicroServiceModelsDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getMicroServiceModelsDictionaryByNameEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, microServiceModelsDictionaryDatas, modelName, MicroServiceModels.class);
-       }
-       
+
+    @RequestMapping(value={"/get_MicroServiceModelsDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getMicroServiceModelsDictionaryByNameEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, microServiceModelsDictionaryDatas, modelName, MicroServiceModels.class);
+    }
+
     @RequestMapping(value={"/get_MicroServiceModelsDataByVersion"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getMicroServiceModelsDictionaryByVersionEntityData(HttpServletRequest request, HttpServletResponse response){
         try{
@@ -409,12 +409,12 @@ public class MicroServiceDictionaryController {
         }
     }
     
-       @RequestMapping(value={"/get_MicroServiceModelsData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getMicroServiceModelsDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, microServiceModelsDictionaryDatas, MicroServiceModels.class);
-       }
-       
+    @RequestMapping(value={"/get_MicroServiceModelsData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getMicroServiceModelsDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, microServiceModelsDictionaryDatas, MicroServiceModels.class);
+    }
+
     @RequestMapping(value={"/get_MicroServiceModelsDataServiceVersion"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getMicroServiceModelsDictionaryEntityDataServiceVersion(HttpServletResponse response){
         try{
@@ -423,9 +423,9 @@ public class MicroServiceDictionaryController {
             List<String> data = new ArrayList<>();
             List<Object> datas = commonClassDao.getData(MicroServiceModels.class);
             for(int i = 0; i < datas.size(); i++){
-               MicroServiceModels msmodel = (MicroServiceModels) datas.get(i);
+                MicroServiceModels msmodel = (MicroServiceModels) datas.get(i);
                 if (!data.contains(msmodel.getModelName())){
-                       data.add(msmodel.getModelName() + "-v" + msmodel.getVersion());
+                    data.add(msmodel.getModelName() + "-v" + msmodel.getVersion());
                 }
             }
             model.put(microServiceModelsDictionaryDatas, mapper.writeValueAsString(data));
@@ -463,287 +463,287 @@ public class MicroServiceDictionaryController {
         }
     }
     
-       @RequestMapping(value={"/ms_dictionary/save_model"}, method={RequestMethod.POST})
-       public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       this.newModel = new MicroServiceModels();
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       MicroServiceModels microServiceModels = new MicroServiceModels();
-                       String userId = null;
-                       
-                       String dataOrderInfo = null;
-                       if(root.has("dataOrderInfo")){
-                               dataOrderInfo = root.get("dataOrderInfo").toString();
-                       }
-
-                       if(root.has("modelType")){
-                               JsonNode dataType = root.get("modelType");
-                               String modelType= dataType.toString();
-                               if(modelType.contains("yml")){
-                                       if (root.has(microServiceModelsDictionaryData)){
-                                               if (root.get(microServiceModelsDictionaryData).has(description)){
-                                                       microServiceModels.setDescription(root.get(microServiceModelsDictionaryData).get(description).asText().replace("\"", ""));
-                                               }
-                                               if (root.get(microServiceModelsDictionaryData).has(modelName)){
-                                                       microServiceModels.setModelName(root.get(microServiceModelsDictionaryData).get(modelName).asText().replace("\"", ""));
-                                                       this.newModel.setModelName(microServiceModels.getModelName());
-                                               }
-                                               if (root.get(microServiceModelsDictionaryData).has(version)){
-                                                       microServiceModels.setVersion(root.get(microServiceModelsDictionaryData).get(version).asText().replace("\"", ""));
-                                                       this.newModel.setVersion(microServiceModels.getVersion());
-                                               }
-                                       }
-
-                                       classMap = new LinkedHashMap<>();
-                                       JsonNode data = root.get(classMapData);
-                                       ObjectMapper mapper1 = new ObjectMapper();
-                                       String data1 = data.toString().substring(1, data.toString().length()-1);
-                                       data1 = data1.replace("\\", "");
-                                       data1=data1.replace("\"{","{");
-                                       data1=data1.replace("}\"","}");
-                                       JSONObject jsonObject = new JSONObject(data1);
-                                       Set<String> keys = jsonObject.keySet();
-                                       for(String key : keys){
-                                               String value = jsonObject.get(key).toString();
-                                               MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
-                                               classMap.put(key, msAttributeObject);
-                                       }
-
-                                       userId = root.get("userid").textValue();
-                                       MSAttributeObject mainClass = classMap.get(this.newModel.getModelName());
-                                       this.newModel.setDependency("[]");
-                                       String value = new Gson().toJson(mainClass.getSubClass());
-                                       this.newModel.setSub_attributes(value);
-                                       String attributes= mainClass.getAttribute().toString().replace("{", "").replace("}", "");
-                                       int equalsIndexForAttributes= attributes.indexOf('=');
-                                       String atttributesAfterFirstEquals= attributes.substring(equalsIndexForAttributes+1);
-                                       this.newModel.setAttributes(atttributesAfterFirstEquals);
-                                       String refAttributes= mainClass.getRefAttribute().toString().replace("{", "").replace("}", "");
-                                       int equalsIndex= refAttributes.indexOf("=");
-                                       String refAttributesAfterFirstEquals= refAttributes.substring(equalsIndex+1);
-                                       this.newModel.setRef_attributes(refAttributesAfterFirstEquals);
-                                       this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
-                                       this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
-
-                               }else{
-                                       if (fromAPI) {
-                                               microServiceModels = mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceModels.class);
-                                               userId = "API";
-                                       } else {
-                                               if (root.has(microServiceModelsDictionaryData)){
-                                                       if (root.get(microServiceModelsDictionaryData).has(description)){
-                                                               microServiceModels.setDescription(root.get(microServiceModelsDictionaryData).get(description).asText().replace("\"", ""));
-                                                       }
-                                                       if (root.get(microServiceModelsDictionaryData).has(modelName)){
-                                                               microServiceModels.setModelName(root.get(microServiceModelsDictionaryData).get(modelName).asText().replace("\"", ""));
-                                                               this.newModel.setModelName(microServiceModels.getModelName());
-                                                       }
-                                                       if (root.get(microServiceModelsDictionaryData).has(version)){
-                                                               microServiceModels.setVersion(root.get(microServiceModelsDictionaryData).get(version).asText().replace("\"", ""));
-                                                               this.newModel.setVersion(microServiceModels.getVersion());
-                                                       }
-                                               }
-                                               if(root.has(classMapData)){
-                                                       classMap = new LinkedHashMap<>();
-                                                       JsonNode data = root.get(classMapData);
-                                                       ObjectMapper mapper1 = new ObjectMapper();
-                                                       String data1 = data.toString().substring(1, data.toString().length()-1);
-                                                       data1 = data1.replace("\\", "");
-                                                       JSONObject jsonObject = new JSONObject(data1);
-                                                       Set<String> keys = jsonObject.keySet();
-                                                       for(String key : keys){
-                                                               String value = jsonObject.get(key).toString();
-                                                               MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
-                                                               classMap.put(key, msAttributeObject);
-                                                       }
-                                               }
-                                               userId = root.get("userid").textValue();
-                                               addValuesToNewModel(classMap);
-                                       }
-                               }               
-                       }
-                       microServiceModels.setAttributes(this.newModel.getAttributes());
-                       microServiceModels.setRef_attributes(this.newModel.getRef_attributes());
-                       microServiceModels.setDependency(this.newModel.getDependency());
-                       microServiceModels.setModelName(this.newModel.getModelName());
-                       microServiceModels.setSub_attributes(this.newModel.getSub_attributes());
-                       microServiceModels.setVersion(this.newModel.getVersion());
-                       microServiceModels.setEnumValues(this.newModel.getEnumValues());
-                       microServiceModels.setAnnotation(this.newModel.getAnnotation());
-                       if(dataOrderInfo != null){
-                                microServiceModels.setDataOrderInfo(dataOrderInfo);
-                       }
-                       String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion();
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class);
-                       boolean duplicateflag = false;
-                       if(duplicateData != null && !duplicateData.isEmpty()){
-                               MicroServiceModels data = (MicroServiceModels) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       microServiceModels.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != microServiceModels.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       UserInfo userInfo = utils.getUserInfo(userId);
-                       
-                       String responseString = null;
-                       if(!duplicateflag){
-                               microServiceModels.setUserCreatedBy(userInfo);
-                               if(microServiceModels.getId() == 0){
-                                       commonClassDao.save(microServiceModels);
-                               }else{
-                                       commonClassDao.update(microServiceModels); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, microServiceModelsDictionaryDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/ms_dictionary/remove_msModel"}, method={RequestMethod.POST})
-       public void removeMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, microServiceModelsDictionaryDatas, MicroServiceModels.class);
-       }
-               
-       private void addValuesToNewModel(HashMap<String,MSAttributeObject > classMap) {
-               //Loop  through the classmap and pull out the required info for the new file.
-               String subAttribute = null;
-               
-               MSAttributeObject mainClass = classMap.get(this.newModel.getModelName());
-               
-               if (mainClass !=null){
-                       String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
-                       ArrayList<String> dependency = new ArrayList<>(Arrays.asList(dependTemp.split(",")));   
-                       dependency = getFullDependencyList(dependency);
-                       for (String element : dependency){
-                               MSAttributeObject temp = classMap.get(element);
-                               if (temp!=null){
-                                       mainClass.addAllRefAttribute(temp.getRefAttribute());
-                                       mainClass.addAllAttribute(temp.getAttribute());
-                               }
-                       }
-                       subAttribute = utils.createSubAttributes(dependency, classMap, this.newModel.getModelName());
-               }else{
-                       subAttribute = "{}";
-                       this.newModel.setDependency("");
-               }
-
-               if (mainClass != null && mainClass.getDependency()==null){
-                       mainClass.setDependency("");
-               }
-               if(mainClass != null){
-                       this.newModel.setDependency(mainClass.getDependency());
-                       this.newModel.setSub_attributes(subAttribute);
-                       this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", ""));
-                       this.newModel.setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", ""));
-                       this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
-                       this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
-               }
-       } 
-       
-       private ArrayList<String> getFullDependencyList(ArrayList<String> dependency) {
-               ArrayList<String> returnList = new ArrayList<>();
-               ArrayList<String> workingList = new ArrayList<>();
-               returnList.addAll(dependency);
-               for (String element : dependency ){
-                       if (classMap.containsKey(element)){
-                               MSAttributeObject value = classMap.get(element);                        
-                               String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""});
-                               workingList = new ArrayList<>(Arrays.asList(rawValue.split(",")));      
-                               for(String depend : workingList){
-                                       if (!returnList.contains(depend) && !depend.isEmpty()){
-                                               returnList.add(depend.trim());
-                                               //getFullDepedency(workingList)
-                                       }
-                               }
-                       }
-               }
-               
-               return returnList;
-       }
-       
-       @RequestMapping(value={"/get_MicroServiceHeaderDefaultsDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getMicroServiceHeaderDefaultsEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, microServiceHeaderDefaultDatas, "modelName", MicroserviceHeaderdeFaults.class);
-       }
-       
+    @RequestMapping(value={"/ms_dictionary/save_model"}, method={RequestMethod.POST})
+    public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            this.newModel = new MicroServiceModels();
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            MicroServiceModels microServiceModels = new MicroServiceModels();
+            String userId = null;
+
+            String dataOrderInfo = null;
+            if(root.has("dataOrderInfo")){
+                dataOrderInfo = root.get("dataOrderInfo").toString();
+            }
+
+            if(root.has("modelType")){
+                JsonNode dataType = root.get("modelType");
+                String modelType= dataType.toString();
+                if(modelType.contains("yml")){
+                    if (root.has(microServiceModelsDictionaryData)){
+                        if (root.get(microServiceModelsDictionaryData).has(description)){
+                            microServiceModels.setDescription(root.get(microServiceModelsDictionaryData).get(description).asText().replace("\"", ""));
+                        }
+                        if (root.get(microServiceModelsDictionaryData).has(modelName)){
+                            microServiceModels.setModelName(root.get(microServiceModelsDictionaryData).get(modelName).asText().replace("\"", ""));
+                            this.newModel.setModelName(microServiceModels.getModelName());
+                        }
+                        if (root.get(microServiceModelsDictionaryData).has(version)){
+                            microServiceModels.setVersion(root.get(microServiceModelsDictionaryData).get(version).asText().replace("\"", ""));
+                            this.newModel.setVersion(microServiceModels.getVersion());
+                        }
+                    }
+
+                    classMap = new LinkedHashMap<>();
+                    JsonNode data = root.get(classMapData);
+                    ObjectMapper mapper1 = new ObjectMapper();
+                    String data1 = data.toString().substring(1, data.toString().length()-1);
+                    data1 = data1.replace("\\", "");
+                    data1=data1.replace("\"{","{");
+                    data1=data1.replace("}\"","}");
+                    JSONObject jsonObject = new JSONObject(data1);
+                    Set<String> keys = jsonObject.keySet();
+                    for(String key : keys){
+                        String value = jsonObject.get(key).toString();
+                        MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
+                        classMap.put(key, msAttributeObject);
+                    }
+
+                    userId = root.get("userid").textValue();
+                    MSAttributeObject mainClass = classMap.get(this.newModel.getModelName());
+                    this.newModel.setDependency("[]");
+                    String value = new Gson().toJson(mainClass.getSubClass());
+                    this.newModel.setSub_attributes(value);
+                    String attributes= mainClass.getAttribute().toString().replace("{", "").replace("}", "");
+                    int equalsIndexForAttributes= attributes.indexOf('=');
+                    String atttributesAfterFirstEquals= attributes.substring(equalsIndexForAttributes+1);
+                    this.newModel.setAttributes(atttributesAfterFirstEquals);
+                    String refAttributes= mainClass.getRefAttribute().toString().replace("{", "").replace("}", "");
+                    int equalsIndex= refAttributes.indexOf("=");
+                    String refAttributesAfterFirstEquals= refAttributes.substring(equalsIndex+1);
+                    this.newModel.setRef_attributes(refAttributesAfterFirstEquals);
+                    this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
+                    this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
+
+                }else{
+                    if (fromAPI) {
+                        microServiceModels = mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceModels.class);
+                        userId = "API";
+                    } else {
+                        if (root.has(microServiceModelsDictionaryData)){
+                            if (root.get(microServiceModelsDictionaryData).has(description)){
+                                microServiceModels.setDescription(root.get(microServiceModelsDictionaryData).get(description).asText().replace("\"", ""));
+                            }
+                            if (root.get(microServiceModelsDictionaryData).has(modelName)){
+                                microServiceModels.setModelName(root.get(microServiceModelsDictionaryData).get(modelName).asText().replace("\"", ""));
+                                this.newModel.setModelName(microServiceModels.getModelName());
+                            }
+                            if (root.get(microServiceModelsDictionaryData).has(version)){
+                                microServiceModels.setVersion(root.get(microServiceModelsDictionaryData).get(version).asText().replace("\"", ""));
+                                this.newModel.setVersion(microServiceModels.getVersion());
+                            }
+                        }
+                        if(root.has(classMapData)){
+                            classMap = new LinkedHashMap<>();
+                            JsonNode data = root.get(classMapData);
+                            ObjectMapper mapper1 = new ObjectMapper();
+                            String data1 = data.toString().substring(1, data.toString().length()-1);
+                            data1 = data1.replace("\\", "");
+                            JSONObject jsonObject = new JSONObject(data1);
+                            Set<String> keys = jsonObject.keySet();
+                            for(String key : keys){
+                                String value = jsonObject.get(key).toString();
+                                MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
+                                classMap.put(key, msAttributeObject);
+                            }
+                        }
+                        userId = root.get("userid").textValue();
+                        addValuesToNewModel(classMap);
+                    }
+                }
+            }
+            microServiceModels.setAttributes(this.newModel.getAttributes());
+            microServiceModels.setRef_attributes(this.newModel.getRef_attributes());
+            microServiceModels.setDependency(this.newModel.getDependency());
+            microServiceModels.setModelName(this.newModel.getModelName());
+            microServiceModels.setSub_attributes(this.newModel.getSub_attributes());
+            microServiceModels.setVersion(this.newModel.getVersion());
+            microServiceModels.setEnumValues(this.newModel.getEnumValues());
+            microServiceModels.setAnnotation(this.newModel.getAnnotation());
+            if(dataOrderInfo != null){
+                 microServiceModels.setDataOrderInfo(dataOrderInfo);
+            }
+            String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion();
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class);
+            boolean duplicateflag = false;
+            if(duplicateData != null && !duplicateData.isEmpty()){
+                MicroServiceModels data = (MicroServiceModels) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    microServiceModels.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != microServiceModels.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            UserInfo userInfo = utils.getUserInfo(userId);
+
+            String responseString = null;
+            if(!duplicateflag){
+                microServiceModels.setUserCreatedBy(userInfo);
+                if(microServiceModels.getId() == 0){
+                    commonClassDao.save(microServiceModels);
+                }else{
+                    commonClassDao.update(microServiceModels);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, microServiceModelsDictionaryDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/ms_dictionary/remove_msModel"}, method={RequestMethod.POST})
+    public void removeMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, microServiceModelsDictionaryDatas, MicroServiceModels.class);
+    }
+
+    private void addValuesToNewModel(HashMap<String,MSAttributeObject > classMap) {
+        //Loop  through the classmap and pull out the required info for the new file.
+        String subAttribute = null;
+
+        MSAttributeObject mainClass = classMap.get(this.newModel.getModelName());
+
+        if (mainClass !=null){
+            String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
+            ArrayList<String> dependency = new ArrayList<>(Arrays.asList(dependTemp.split(",")));
+            dependency = getFullDependencyList(dependency);
+            for (String element : dependency){
+                MSAttributeObject temp = classMap.get(element);
+                if (temp!=null){
+                    mainClass.addAllRefAttribute(temp.getRefAttribute());
+                    mainClass.addAllAttribute(temp.getAttribute());
+                }
+            }
+            subAttribute = utils.createSubAttributes(dependency, classMap, this.newModel.getModelName());
+        }else{
+            subAttribute = "{}";
+            this.newModel.setDependency("");
+        }
+
+        if (mainClass != null && mainClass.getDependency()==null){
+            mainClass.setDependency("");
+        }
+        if(mainClass != null){
+            this.newModel.setDependency(mainClass.getDependency());
+            this.newModel.setSub_attributes(subAttribute);
+            this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", ""));
+            this.newModel.setRef_attributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", ""));
+            this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
+            this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
+        }
+    }
+
+    private ArrayList<String> getFullDependencyList(ArrayList<String> dependency) {
+        ArrayList<String> returnList = new ArrayList<>();
+        ArrayList<String> workingList = new ArrayList<>();
+        returnList.addAll(dependency);
+        for (String element : dependency ){
+            if (classMap.containsKey(element)){
+                MSAttributeObject value = classMap.get(element);
+                String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""});
+                workingList = new ArrayList<>(Arrays.asList(rawValue.split(",")));
+                for(String depend : workingList){
+                    if (!returnList.contains(depend) && !depend.isEmpty()){
+                        returnList.add(depend.trim());
+                        //getFullDepedency(workingList)
+                    }
+                }
+            }
+        }
+
+        return returnList;
+    }
+
+    @RequestMapping(value={"/get_MicroServiceHeaderDefaultsDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getMicroServiceHeaderDefaultsEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, microServiceHeaderDefaultDatas, "modelName", MicroserviceHeaderdeFaults.class);
+    }
+
     @RequestMapping(value={"/get_MicroServiceHeaderDefaultsData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
     public void getMicroServiceHeaderDefaultsEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, microServiceHeaderDefaultDatas, MicroserviceHeaderdeFaults.class);
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, microServiceHeaderDefaultDatas, MicroserviceHeaderdeFaults.class);
     }
     
     
     @RequestMapping(value={"/ms_dictionary/save_headerDefaults"}, method={RequestMethod.POST})
     public ModelAndView saveMicroServiceHeaderDefaultValues(HttpServletRequest request, HttpServletResponse response) throws IOException{
-       DictionaryUtils utils = getDictionaryUtilsInstance();
+        DictionaryUtils utils = getDictionaryUtilsInstance();
         try {
-               boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
             
             MicroserviceHeaderdeFaults msHeaderdeFaults;
             if(fromAPI){
-               msHeaderdeFaults = mapper.readValue(root.get(dictionaryFields).toString(), MicroserviceHeaderdeFaults.class);
+                msHeaderdeFaults = mapper.readValue(root.get(dictionaryFields).toString(), MicroserviceHeaderdeFaults.class);
             }else{
-               msHeaderdeFaults = mapper.readValue(root.get("modelAttributeDictionaryData").toString(), MicroserviceHeaderdeFaults.class);
+                msHeaderdeFaults = mapper.readValue(root.get("modelAttributeDictionaryData").toString(), MicroserviceHeaderdeFaults.class);
             }
             
             List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(msHeaderdeFaults.getModelName(), "modelName", MicroserviceHeaderdeFaults.class);
-                       boolean duplicateflag = false;
-                       if(duplicateData != null && !duplicateData.isEmpty()){
-                               MicroserviceHeaderdeFaults data = (MicroserviceHeaderdeFaults) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       msHeaderdeFaults.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != msHeaderdeFaults.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
+            boolean duplicateflag = false;
+            if(duplicateData != null && !duplicateData.isEmpty()){
+                MicroserviceHeaderdeFaults data = (MicroserviceHeaderdeFaults) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    msHeaderdeFaults.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != msHeaderdeFaults.getId()))){
+                    duplicateflag = true;
+                }
+            }
             
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(msHeaderdeFaults.getId() == 0){
-                                       commonClassDao.save(msHeaderdeFaults);
-                               }else{
-                                       commonClassDao.update(msHeaderdeFaults); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(MicroserviceHeaderdeFaults.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, microServiceHeaderDefaultDatas, responseString);
-                       }
+            String responseString = null;
+            if(!duplicateflag){
+                if(msHeaderdeFaults.getId() == 0){
+                    commonClassDao.save(msHeaderdeFaults);
+                }else{
+                    commonClassDao.update(msHeaderdeFaults);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(MicroserviceHeaderdeFaults.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, microServiceHeaderDefaultDatas, responseString);
+            }
         }
         catch (Exception e){
-               utils.setErrorResponseData(response, e);
+            utils.setErrorResponseData(response, e);
         }
         return null;
     }
     
     @RequestMapping(value={"/ms_dictionary/remove_headerDefaults"}, method={RequestMethod.POST})
     public void removeMicroServiceHeaderDefaults(HttpServletRequest request, HttpServletResponse response) throws IOException{
-       DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, microServiceHeaderDefaultDatas, MicroserviceHeaderdeFaults.class);
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, microServiceHeaderDefaultDatas, MicroserviceHeaderdeFaults.class);
     }
 }
\ No newline at end of file
index acb5a2a..3d1dba9 100644 (file)
@@ -53,266 +53,266 @@ import com.google.gson.Gson;
 
 @Controller
 public class OptimizationDictionaryController {
-       private static CommonClassDao commonClassDao;
-       
+    private static CommonClassDao commonClassDao;
+
     private static String operation = "operation";
     private LinkedHashMap<String,MSAttributeObject > classMap;
-       private static String dictionaryFields ="dictionaryFields";
-       private static String duplicateResponseString = "Duplicate";
-       private static String optimizationModelsDictionaryDatas = "optimizationModelsDictionaryDatas";
-       private static String modelName = "modelName";
-       private static String optimizationModelsDictionaryData = "optimizationModelsDictionaryData";
-       private static String description = "description";
-       private static String version = "version";
-       private static String classMapData = "classMap";
-       private static final String UPDATE = "update";
+    private static String dictionaryFields ="dictionaryFields";
+    private static String duplicateResponseString = "Duplicate";
+    private static String optimizationModelsDictionaryDatas = "optimizationModelsDictionaryDatas";
+    private static String modelName = "modelName";
+    private static String optimizationModelsDictionaryData = "optimizationModelsDictionaryData";
+    private static String description = "description";
+    private static String version = "version";
+    private static String classMapData = "classMap";
+    private static final String UPDATE = "update";
 
 
     public OptimizationDictionaryController(){
-       super();
+        super();
     }  
-       
+
     private DictionaryUtils getDictionaryUtilsInstance(){
-               return DictionaryUtils.getDictionaryUtils();
-       }
+        return DictionaryUtils.getDictionaryUtils();
+    }
     
-       @Autowired
-       public OptimizationDictionaryController(CommonClassDao commonClassDao){
-               setCommonClassDao(commonClassDao);
-       }
-       public static void setCommonClassDao(CommonClassDao commonClassDao) {
-               OptimizationDictionaryController.commonClassDao = commonClassDao;
-       }
+    @Autowired
+    public OptimizationDictionaryController(CommonClassDao commonClassDao){
+        setCommonClassDao(commonClassDao);
+    }
+    public static void setCommonClassDao(CommonClassDao commonClassDao) {
+        OptimizationDictionaryController.commonClassDao = commonClassDao;
+    }
+
+    MSModelUtils utils = new MSModelUtils(XACMLPapServlet.getMsOnapName(), XACMLPapServlet.getMsPolicyName());
+
+    private OptimizationModels newModel;
+
+    @RequestMapping(value={"/get_OptimizationModelsData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getOptimizationModelsDictionaryEntityData(HttpServletResponse response){
+        DictionaryUtils dUtils = getDictionaryUtilsInstance();
+        dUtils.getData(response, optimizationModelsDictionaryDatas, OptimizationModels.class);
+    }
+
+    @RequestMapping(value={"/get_OptimizationModelsDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getOptimizationModelsDictionaryByNameEntityData(HttpServletResponse response){
+        DictionaryUtils dUtils = getDictionaryUtilsInstance();
+        dUtils.getDataByEntity(response, optimizationModelsDictionaryDatas, modelName, OptimizationModels.class);
+    }
+
+    @RequestMapping(value={"/oof_dictionary/save_model"}, method={RequestMethod.POST})
+    public ModelAndView saveOptimizationModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils dUtils = getDictionaryUtilsInstance();
+        try {
+            this.newModel = new OptimizationModels();
+            boolean fromAPI = dUtils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            OptimizationModels optimizationModels = new OptimizationModels();
+            String userId = null;
+
+            String dataOrderInfo = null;
+            if(root.has("dataOrderInfo")){
+                dataOrderInfo = root.get("dataOrderInfo").toString();
+            }
+
+            if(root.has("modelType")){
+                JsonNode dataType = root.get("modelType");
+                String modelType= dataType.toString();
+                if(modelType.contains("yml")){
+                    if (root.has(optimizationModelsDictionaryData)){
+                        if (root.get(optimizationModelsDictionaryData).has(description)){
+                            optimizationModels.setDescription(root.get(optimizationModelsDictionaryData).get(description).asText().replace("\"", ""));
+                        }
+                        if (root.get(optimizationModelsDictionaryData).has(modelName)){
+                            optimizationModels.setModelName(root.get(optimizationModelsDictionaryData).get(modelName).asText().replace("\"", ""));
+                            this.newModel.setModelName(optimizationModels.getModelName());
+                        }
+                        if (root.get(optimizationModelsDictionaryData).has(version)){
+                            optimizationModels.setVersion(root.get(optimizationModelsDictionaryData).get(version).asText().replace("\"", ""));
+                            this.newModel.setVersion(optimizationModels.getVersion());
+                        }
+                    }
+
+                    classMap = new LinkedHashMap<>();
+                    JsonNode data = root.get(classMapData);
+                    ObjectMapper mapper1 = new ObjectMapper();
+                    String data1 = data.toString().substring(1, data.toString().length()-1);
+                    data1 = data1.replace("\\", "");
+                    data1=data1.replace("\"{","{");
+                    data1=data1.replace("}\"","}");
+                    JSONObject jsonObject = new JSONObject(data1);
+                    Set<String> keys = jsonObject.keySet();
+                    for(String key : keys){
+                        String value = jsonObject.get(key).toString();
+                        MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
+                        classMap.put(key, msAttributeObject);
+                    }
+
+                    userId = root.get("userid").textValue();
+                    MSAttributeObject mainClass = classMap.get(this.newModel.getModelName());
+                    this.newModel.setDependency("[]");
+                    String value = new Gson().toJson(mainClass.getSubClass());
+                    this.newModel.setSubattributes(value);
+                    String attributes= mainClass.getAttribute().toString().replace("{", "").replace("}", "");
+                    int equalsIndexForAttributes= attributes.indexOf('=');
+                    String atttributesAfterFirstEquals= attributes.substring(equalsIndexForAttributes+1, attributes.length()-1);
+                    this.newModel.setAttributes(atttributesAfterFirstEquals);
+                    String refAttributes= mainClass.getRefAttribute().toString().replace("{", "").replace("}", "");
+                    int equalsIndex= refAttributes.indexOf('=');
+                    String refAttributesAfterFirstEquals= refAttributes.substring(equalsIndex+1, refAttributes.length()-1);
+                    this.newModel.setRefattributes(refAttributesAfterFirstEquals);
+                    this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
+                    this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
+
+                }else{
+                    if (fromAPI) {
+                        optimizationModels = mapper.readValue(root.get(dictionaryFields).toString(), OptimizationModels.class);
+                        userId = "API";
+                    } else {
+                        if (root.has(optimizationModelsDictionaryData)){
+                            if (root.get(optimizationModelsDictionaryData).has(description)){
+                                optimizationModels.setDescription(root.get(optimizationModelsDictionaryData).get(description).asText().replace("\"", ""));
+                            }
+                            if (root.get(optimizationModelsDictionaryData).has(modelName)){
+                                optimizationModels.setModelName(root.get(optimizationModelsDictionaryData).get(modelName).asText().replace("\"", ""));
+                                this.newModel.setModelName(optimizationModels.getModelName());
+                            }
+                            if (root.get(optimizationModelsDictionaryData).has(version)){
+                                optimizationModels.setVersion(root.get(optimizationModelsDictionaryData).get(version).asText().replace("\"", ""));
+                                this.newModel.setVersion(optimizationModels.getVersion());
+                            }
+                        }
+                        if(root.has(classMapData)){
+                            classMap = new LinkedHashMap<>();
+                            JsonNode data = root.get(classMapData);
+                            ObjectMapper mapper1 = new ObjectMapper();
+                            String data1 = data.toString().substring(1, data.toString().length()-1);
+                            data1 = data1.replace("\\", "");
+                            JSONObject jsonObject = new JSONObject(data1);
+                            Set<String> keys = jsonObject.keySet();
+                            for(String key : keys){
+                                String value = jsonObject.get(key).toString();
+                                MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
+                                classMap.put(key, msAttributeObject);
+                            }
+                        }
+                        userId = root.get("userid").textValue();
+                        addValuesToNewModel(classMap);
+                    }
+                }
+            }
+            optimizationModels.setAttributes(this.newModel.getAttributes());
+            optimizationModels.setRefattributes(this.newModel.getRefattributes());
+            optimizationModels.setDependency(this.newModel.getDependency());
+            optimizationModels.setModelName(this.newModel.getModelName());
+            optimizationModels.setSubattributes(this.newModel.getSubattributes());
+            optimizationModels.setVersion(this.newModel.getVersion());
+            optimizationModels.setEnumValues(this.newModel.getEnumValues());
+            optimizationModels.setAnnotation(this.newModel.getAnnotation());
+
+            if(dataOrderInfo != null){
+                optimizationModels.setDataOrderInfo(dataOrderInfo);
+            }
+
+            String checkName = optimizationModels.getModelName() + ":" + optimizationModels.getVersion();
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(checkName, "modelName:version", OptimizationModels.class);
+            boolean duplicateflag = false;
+            if(duplicateData!=null && !duplicateData.isEmpty()){
+                OptimizationModels data = (OptimizationModels) duplicateData.get(0);
+                if(request.getParameter(operation) != null && UPDATE.equals(request.getParameter(operation))){
+                    optimizationModels.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !UPDATE.equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != optimizationModels.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            UserInfo userInfo = dUtils.getUserInfo(userId);
+
+            String responseString = null;
+            if(!duplicateflag){
+                optimizationModels.setUserCreatedBy(userInfo);
+                if(optimizationModels.getId() == 0){
+                    commonClassDao.save(optimizationModels);
+                }else{
+                    commonClassDao.update(optimizationModels);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(OptimizationModels.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return dUtils.getResultForApi(responseString);
+            }else{
+                dUtils.setResponseData(response, optimizationModelsDictionaryDatas, responseString);
+            }
+        }catch (Exception e){
+            dUtils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
 
-       MSModelUtils utils = new MSModelUtils(XACMLPapServlet.getMsOnapName(), XACMLPapServlet.getMsPolicyName());
-       
-       private OptimizationModels newModel;
-       
-       @RequestMapping(value={"/get_OptimizationModelsData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getOptimizationModelsDictionaryEntityData(HttpServletResponse response){
-               DictionaryUtils dUtils = getDictionaryUtilsInstance();
-               dUtils.getData(response, optimizationModelsDictionaryDatas, OptimizationModels.class);
-       }
-       
-       @RequestMapping(value={"/get_OptimizationModelsDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getOptimizationModelsDictionaryByNameEntityData(HttpServletResponse response){
-               DictionaryUtils dUtils = getDictionaryUtilsInstance();
-               dUtils.getDataByEntity(response, optimizationModelsDictionaryDatas, modelName, OptimizationModels.class);
-       }
-       
-       @RequestMapping(value={"/oof_dictionary/save_model"}, method={RequestMethod.POST})
-       public ModelAndView saveOptimizationModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils dUtils = getDictionaryUtilsInstance();
-               try {
-                       this.newModel = new OptimizationModels();
-                       boolean fromAPI = dUtils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       OptimizationModels optimizationModels = new OptimizationModels();
-                       String userId = null;
-                       
-                       String dataOrderInfo = null;
-                       if(root.has("dataOrderInfo")){
-                               dataOrderInfo = root.get("dataOrderInfo").toString();
-                       }
+    @RequestMapping(value={"/oof_dictionary/remove_model"}, method={RequestMethod.POST})
+    public void removeOptimizationModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils dUtils = getDictionaryUtilsInstance();
+        dUtils.removeData(request, response, optimizationModelsDictionaryDatas, OptimizationModels.class);
+    }
 
-                       if(root.has("modelType")){
-                               JsonNode dataType = root.get("modelType");
-                               String modelType= dataType.toString();
-                               if(modelType.contains("yml")){
-                                       if (root.has(optimizationModelsDictionaryData)){
-                                               if (root.get(optimizationModelsDictionaryData).has(description)){
-                                                       optimizationModels.setDescription(root.get(optimizationModelsDictionaryData).get(description).asText().replace("\"", ""));
-                                               }
-                                               if (root.get(optimizationModelsDictionaryData).has(modelName)){
-                                                       optimizationModels.setModelName(root.get(optimizationModelsDictionaryData).get(modelName).asText().replace("\"", ""));
-                                                       this.newModel.setModelName(optimizationModels.getModelName());
-                                               }
-                                               if (root.get(optimizationModelsDictionaryData).has(version)){
-                                                       optimizationModels.setVersion(root.get(optimizationModelsDictionaryData).get(version).asText().replace("\"", ""));
-                                                       this.newModel.setVersion(optimizationModels.getVersion());
-                                               }
-                                       }
+    private void addValuesToNewModel(HashMap<String,MSAttributeObject > classMap) {
+        //Loop  through the classmap and pull out the required info for the new file.
+        String subAttribute = null;
 
-                                       classMap = new LinkedHashMap<>();
-                                       JsonNode data = root.get(classMapData);
-                                       ObjectMapper mapper1 = new ObjectMapper();
-                                       String data1 = data.toString().substring(1, data.toString().length()-1);
-                                       data1 = data1.replace("\\", "");
-                                       data1=data1.replace("\"{","{");
-                                       data1=data1.replace("}\"","}");
-                                       JSONObject jsonObject = new JSONObject(data1);
-                                       Set<String> keys = jsonObject.keySet();
-                                       for(String key : keys){
-                                               String value = jsonObject.get(key).toString();
-                                               MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
-                                               classMap.put(key, msAttributeObject);
-                                       }
+        MSAttributeObject mainClass = classMap.get(this.newModel.getModelName());
 
-                                       userId = root.get("userid").textValue();
-                                       MSAttributeObject mainClass = classMap.get(this.newModel.getModelName());
-                                       this.newModel.setDependency("[]");
-                                       String value = new Gson().toJson(mainClass.getSubClass());
-                                       this.newModel.setSubattributes(value);
-                                       String attributes= mainClass.getAttribute().toString().replace("{", "").replace("}", "");
-                                       int equalsIndexForAttributes= attributes.indexOf('=');
-                                       String atttributesAfterFirstEquals= attributes.substring(equalsIndexForAttributes+1, attributes.length()-1);
-                                       this.newModel.setAttributes(atttributesAfterFirstEquals);
-                                       String refAttributes= mainClass.getRefAttribute().toString().replace("{", "").replace("}", "");
-                                       int equalsIndex= refAttributes.indexOf('=');
-                                       String refAttributesAfterFirstEquals= refAttributes.substring(equalsIndex+1, refAttributes.length()-1);
-                                       this.newModel.setRefattributes(refAttributesAfterFirstEquals);
-                                       this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
-                                       this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
+        if (mainClass !=null){
+            String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
+            ArrayList<String> dependency = new ArrayList<>(Arrays.asList(dependTemp.split(",")));
+            dependency = getFullDependencyList(dependency);
+            for (String element : dependency){
+                MSAttributeObject temp = classMap.get(element);
+                if (temp!=null){
+                    mainClass.addAllRefAttribute(temp.getRefAttribute());
+                    mainClass.addAllAttribute(temp.getAttribute());
+                }
+            }
+            subAttribute = utils.createSubAttributes(dependency, classMap, this.newModel.getModelName());
+        }else{
+            subAttribute = "{}";
+            this.newModel.setDependency("");
+        }
 
-                               }else{
-                                       if (fromAPI) {
-                                               optimizationModels = mapper.readValue(root.get(dictionaryFields).toString(), OptimizationModels.class);
-                                               userId = "API";
-                                       } else {
-                                               if (root.has(optimizationModelsDictionaryData)){
-                                                       if (root.get(optimizationModelsDictionaryData).has(description)){
-                                                               optimizationModels.setDescription(root.get(optimizationModelsDictionaryData).get(description).asText().replace("\"", ""));
-                                                       }
-                                                       if (root.get(optimizationModelsDictionaryData).has(modelName)){
-                                                               optimizationModels.setModelName(root.get(optimizationModelsDictionaryData).get(modelName).asText().replace("\"", ""));
-                                                               this.newModel.setModelName(optimizationModels.getModelName());
-                                                       }
-                                                       if (root.get(optimizationModelsDictionaryData).has(version)){
-                                                               optimizationModels.setVersion(root.get(optimizationModelsDictionaryData).get(version).asText().replace("\"", ""));
-                                                               this.newModel.setVersion(optimizationModels.getVersion());
-                                                       }
-                                               }
-                                               if(root.has(classMapData)){
-                                                       classMap = new LinkedHashMap<>();
-                                                       JsonNode data = root.get(classMapData);
-                                                       ObjectMapper mapper1 = new ObjectMapper();
-                                                       String data1 = data.toString().substring(1, data.toString().length()-1);
-                                                       data1 = data1.replace("\\", "");
-                                                       JSONObject jsonObject = new JSONObject(data1);
-                                                       Set<String> keys = jsonObject.keySet();
-                                                       for(String key : keys){
-                                                               String value = jsonObject.get(key).toString();
-                                                               MSAttributeObject msAttributeObject = mapper1.readValue(value, MSAttributeObject.class);
-                                                               classMap.put(key, msAttributeObject);
-                                                       }
-                                               }
-                                               userId = root.get("userid").textValue();
-                                               addValuesToNewModel(classMap);
-                                       }
-                               }               
-                       }
-                       optimizationModels.setAttributes(this.newModel.getAttributes());
-                       optimizationModels.setRefattributes(this.newModel.getRefattributes());
-                       optimizationModels.setDependency(this.newModel.getDependency());
-                       optimizationModels.setModelName(this.newModel.getModelName());
-                       optimizationModels.setSubattributes(this.newModel.getSubattributes());
-                       optimizationModels.setVersion(this.newModel.getVersion());
-                       optimizationModels.setEnumValues(this.newModel.getEnumValues());
-                       optimizationModels.setAnnotation(this.newModel.getAnnotation());
-                       
-                       if(dataOrderInfo != null){
-                               optimizationModels.setDataOrderInfo(dataOrderInfo);
-                       }
-                       
-                       String checkName = optimizationModels.getModelName() + ":" + optimizationModels.getVersion();
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(checkName, "modelName:version", OptimizationModels.class);
-                       boolean duplicateflag = false;
-                       if(duplicateData!=null && !duplicateData.isEmpty()){
-                               OptimizationModels data = (OptimizationModels) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && UPDATE.equals(request.getParameter(operation))){
-                                       optimizationModels.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !UPDATE.equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != optimizationModels.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       UserInfo userInfo = dUtils.getUserInfo(userId);
-                       
-                       String responseString = null;
-                       if(!duplicateflag){
-                               optimizationModels.setUserCreatedBy(userInfo);
-                               if(optimizationModels.getId() == 0){
-                                       commonClassDao.save(optimizationModels);
-                               }else{
-                                       commonClassDao.update(optimizationModels); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(OptimizationModels.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return dUtils.getResultForApi(responseString);
-                       }else{
-                               dUtils.setResponseData(response, optimizationModelsDictionaryDatas, responseString);
-                       }
-               }catch (Exception e){
-                       dUtils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
+        if (mainClass != null && mainClass.getDependency()==null){
+            mainClass.setDependency("");
+        }
+        if(mainClass != null){
+            this.newModel.setDependency(mainClass.getDependency());
+            this.newModel.setSubattributes(subAttribute);
+            this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", ""));
+            this.newModel.setRefattributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", ""));
+            this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
+            this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
+        }
+    }
 
-       @RequestMapping(value={"/oof_dictionary/remove_model"}, method={RequestMethod.POST})
-       public void removeOptimizationModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils dUtils = getDictionaryUtilsInstance();
-               dUtils.removeData(request, response, optimizationModelsDictionaryDatas, OptimizationModels.class);
-       }
-               
-       private void addValuesToNewModel(HashMap<String,MSAttributeObject > classMap) {
-               //Loop  through the classmap and pull out the required info for the new file.
-               String subAttribute = null;
-               
-               MSAttributeObject mainClass = classMap.get(this.newModel.getModelName());
-               
-               if (mainClass !=null){
-                       String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
-                       ArrayList<String> dependency = new ArrayList<>(Arrays.asList(dependTemp.split(",")));   
-                       dependency = getFullDependencyList(dependency);
-                       for (String element : dependency){
-                               MSAttributeObject temp = classMap.get(element);
-                               if (temp!=null){
-                                       mainClass.addAllRefAttribute(temp.getRefAttribute());
-                                       mainClass.addAllAttribute(temp.getAttribute());
-                               }
-                       }
-                       subAttribute = utils.createSubAttributes(dependency, classMap, this.newModel.getModelName());
-               }else{
-                       subAttribute = "{}";
-                       this.newModel.setDependency("");
-               }
+    private ArrayList<String> getFullDependencyList(ArrayList<String> dependency) {
+        ArrayList<String> returnList = new ArrayList<>();
+        ArrayList<String> workingList;
+        returnList.addAll(dependency);
+        for (String element : dependency ){
+            if (classMap.containsKey(element)){
+                MSAttributeObject value = classMap.get(element);
+                String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""});
+                workingList = new ArrayList<>(Arrays.asList(rawValue.split(",")));
+                for(String depend : workingList){
+                    if (!returnList.contains(depend) && !depend.isEmpty()){
+                        returnList.add(depend.trim());
+                    }
+                }
+            }
+        }
 
-               if (mainClass != null && mainClass.getDependency()==null){
-                       mainClass.setDependency("");
-               }
-               if(mainClass != null){
-                       this.newModel.setDependency(mainClass.getDependency());
-                       this.newModel.setSubattributes(subAttribute);
-                       this.newModel.setAttributes(mainClass.getAttribute().toString().replace("{", "").replace("}", ""));
-                       this.newModel.setRefattributes(mainClass.getRefAttribute().toString().replace("{", "").replace("}", ""));
-                       this.newModel.setEnumValues(mainClass.getEnumType().toString().replace("{", "").replace("}", ""));
-                       this.newModel.setAnnotation(mainClass.getMatchingSet().toString().replace("{", "").replace("}", ""));
-               }
-       } 
-       
-       private ArrayList<String> getFullDependencyList(ArrayList<String> dependency) {
-               ArrayList<String> returnList = new ArrayList<>();
-               ArrayList<String> workingList;
-               returnList.addAll(dependency);
-               for (String element : dependency ){
-                       if (classMap.containsKey(element)){
-                               MSAttributeObject value = classMap.get(element);                        
-                               String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""});
-                               workingList = new ArrayList<>(Arrays.asList(rawValue.split(",")));      
-                               for(String depend : workingList){
-                                       if (!returnList.contains(depend) && !depend.isEmpty()){
-                                               returnList.add(depend.trim());
-                                       }
-                               }
-                       }
-               }
-               
-               return returnList;
-       }
+        return returnList;
+    }
 
 }
index fd3d2f6..965235c 100644 (file)
@@ -52,441 +52,441 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 @Controller
 public class PolicyScopeDictionaryController {
 
-       private static final Logger LOGGER  = FlexLogger.getLogger(PolicyScopeDictionaryController.class);
-
-       private static CommonClassDao commonClassDao;
-       private static String operation = "operation";
-       private static String groupPolicyScopeListData1 = "groupPolicyScopeListData1";
-       private static String policyScope= "PolicyScope";
-       private static String duplicateResponseString = "Duplicate";
-       private static String groupPolicyScopeDatas = "groupPolicyScopeListDatas";
-       private static String dictionaryFields = "dictionaryFields";
-       private static String psCLDatas = "psClosedLoopDictionaryDatas";
-       private static String psServiceDatas = "psServiceDictionaryDatas";
-       private static String psTypeDatas = "psTypeDictionaryDatas";
-       private static String psResourceDatas = "psResourceDictionaryDatas";
-
-       public PolicyScopeDictionaryController(){
-               super();
-       }       
-
-       private DictionaryUtils getDictionaryUtilsInstance(){
-               return DictionaryUtils.getDictionaryUtils();
-       }
-       
-       @Autowired
-       public PolicyScopeDictionaryController(CommonClassDao commonClassDao){
-               PolicyScopeDictionaryController.commonClassDao = commonClassDao;
-       }
-       
-       public void setCommonClassDao(CommonClassDao commonClassDao){
-               PolicyScopeDictionaryController.commonClassDao = commonClassDao;
-       }
-       
-       @RequestMapping(value={"/get_GroupPolicyScopeDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getGroupPolicyScopeEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, groupPolicyScopeDatas, "name", GroupPolicyScopeList.class);
-       }
-
-       @RequestMapping(value={"/get_GroupPolicyScopeData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getGroupPolicyScopeEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, groupPolicyScopeDatas, GroupPolicyScopeList.class);
-       }
-
-       @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope"}, method={RequestMethod.POST})
-       public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       GroupPolicyScopeList gpdata = null;
-                       GroupPolicyScope groupData = null;
-                       boolean duplicateGroupFlag = false;
-                       if (fromAPI) {
-                               gpdata = mapper.readValue(root.get(dictionaryFields).toString(), GroupPolicyScopeList.class);
-                               try{
-                                       groupData = mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class);
-                               }catch(Exception e){
-                                       groupData = new GroupPolicyScope();
-                                       groupData.setResource(root.get(dictionaryFields).get("resource").toString().replace("\"", ""));
-                                       groupData.setClosedloop(root.get(dictionaryFields).get("closedloop").toString().replace("\"", ""));
-                                       groupData.setService(root.get(dictionaryFields).get("service").toString().replace("\"", ""));
-                                       groupData.setType(root.get(dictionaryFields).get("type").toString().replace("\"", ""));
-                                       LOGGER.error(e);
-                               }
-                       } else {
-                               gpdata = mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class);
-                               try{
-                                       groupData = mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class);
-                               }catch(Exception e){
-                                       LOGGER.error(e);
-                                       groupData = new GroupPolicyScope();
-                                       groupData.setResource(root.get(groupPolicyScopeListData1).get("resource").toString().replace("\"", ""));
-                                       groupData.setClosedloop(root.get(groupPolicyScopeListData1).get("closedloop").toString().replace("\"", ""));
-                                       groupData.setService(root.get(groupPolicyScopeListData1).get("service").toString().replace("\"", ""));
-                                       groupData.setType(root.get(groupPolicyScopeListData1).get("type").toString().replace("\"", ""));
-                               }
-                       }
-                       if(!gpdata.getGroupName().startsWith(policyScope)){
-                               String name = "PolicyScope_" + gpdata.getGroupName();
-                               gpdata.setGroupName(name);
-                       }
-                       ArrayList<String> valueList = new ArrayList<>();
-                       String resourceValue = groupData.getResource();
-                       String typeValue = groupData.getType();
-                       String serviceValue = groupData.getService();
-                       String closedLoopValue = groupData.getClosedloop();
-                       valueList.add("resource=" + resourceValue);
-                       valueList.add("service=" + serviceValue);
-                       valueList.add("type=" + typeValue);
-                       valueList.add("closedLoopControlName="  + closedLoopValue);
-                       String list = StringUtils.replaceEach(valueList.toString(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
-                       gpdata.setGroupList(list);
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class);
-                       if(duplicateData.isEmpty()){
-                               duplicateData =  commonClassDao.checkDuplicateEntry(gpdata.getGroupList(), "groupList", GroupPolicyScopeList.class);
-                               if(duplicateData.isEmpty()){
-                                       duplicateGroupFlag = true;
-                               }
-                       } 
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               GroupPolicyScopeList data = (GroupPolicyScopeList) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       gpdata.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != gpdata.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag && !duplicateGroupFlag){
-                               if(gpdata.getId() == 0){
-                                       commonClassDao.save(gpdata);
-                               }else{
-                                       commonClassDao.update(gpdata); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class));
-                       }else if(duplicateGroupFlag){
-                               responseString = "DuplicateGroup";
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, groupPolicyScopeDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope"}, method={RequestMethod.POST})
-       public void removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, groupPolicyScopeDatas, GroupPolicyScopeList.class);
-       }
-
-       @RequestMapping(value={"/get_PSClosedLoopDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getPSClosedLoopEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, psCLDatas, "name", OnapName.class);
-       }
-
-       @RequestMapping(value={"/get_PSClosedLoopData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getPSClosedLoopEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, psCLDatas, PolicyScopeClosedLoop.class);
-       }
-
-       @RequestMapping(value={"/ps_dictionary/save_psClosedLoop"}, method={RequestMethod.POST})
-       public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       PolicyScopeClosedLoop onapData;
-                       if(fromAPI){
-                               onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeClosedLoop.class);
-                       }else{
-                               onapData = mapper.readValue(root.get("psClosedLoopDictionaryData").toString(), PolicyScopeClosedLoop.class);
-                       }
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeClosedLoop.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               PolicyScopeClosedLoop data = (PolicyScopeClosedLoop) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       onapData.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(onapData.getId() == 0){
-                                       commonClassDao.save(onapData);
-                               }else{
-                                       commonClassDao.update(onapData); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, psCLDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop"}, method={RequestMethod.POST})
-       public void removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, psCLDatas, PolicyScopeClosedLoop.class);
-       }
-
-       @RequestMapping(value={"/get_PSServiceDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getPSServiceEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, psServiceDatas, "name", PolicyScopeService.class);
-       }
-
-       @RequestMapping(value={"/get_PSServiceData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getPSServiceEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, psServiceDatas, PolicyScopeService.class);
-       }
-
-       @RequestMapping(value={"/ps_dictionary/save_psService"}, method={RequestMethod.POST})
-       public ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       PolicyScopeService onapData;
-                       if (fromAPI) {
-                               onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeService.class);
-                       } else {
-                               onapData = mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class);
-                       }
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               PolicyScopeService data = (PolicyScopeService) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       onapData.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(onapData.getId() == 0){
-                                       commonClassDao.save(onapData);
-                               }else{
-                                       commonClassDao.update(onapData); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, psServiceDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/ps_dictionary/remove_PSService"}, method={RequestMethod.POST})
-       public void removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, psServiceDatas, PolicyScopeService.class);
-       }
-
-       @RequestMapping(value={"/get_PSTypeDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getPSTypeEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, psTypeDatas, "name", PolicyScopeType.class);
-       }
-
-       @RequestMapping(value={"/get_PSTypeData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getPSTypeEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, psTypeDatas, PolicyScopeType.class);
-       }
-
-       @RequestMapping(value={"/ps_dictionary/save_psType"}, method={RequestMethod.POST})
-       public ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       PolicyScopeType onapData;
-                       if(fromAPI){
-                               onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeType.class);
-                       }else{
-                               onapData = mapper.readValue(root.get("psTypeDictionaryData").toString(), PolicyScopeType.class);
-                       }
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeType.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               PolicyScopeType data = (PolicyScopeType) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       onapData.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(onapData.getId() == 0){
-                                       commonClassDao.save(onapData);
-                               }else{
-                                       commonClassDao.update(onapData); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, psTypeDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/ps_dictionary/remove_PSType"}, method={RequestMethod.POST})
-       public void removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, psTypeDatas, PolicyScopeType.class);
-       }
-
-       @RequestMapping(value={"/get_PSResourceDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getPSResourceEntityDataByName(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, psResourceDatas, "name", PolicyScopeResource.class);
-       }
-
-       @RequestMapping(value={"/get_PSResourceData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
-       public void getPSResourceEntityData(HttpServletResponse response){
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, psResourceDatas, PolicyScopeResource.class);
-       }
-
-       @RequestMapping(value={"/ps_dictionary/save_psResource"}, method={RequestMethod.POST})
-       public ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       PolicyScopeResource onapData;
-                       if (fromAPI) {
-                               onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeResource.class);
-                       } else {
-                               onapData = mapper.readValue(root.get("psResourceDictionaryData").toString(), PolicyScopeResource.class);
-                       }
-                       
-                       List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeResource.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               PolicyScopeResource data = (PolicyScopeResource) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       onapData.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(onapData.getId() == 0){
-                                       commonClassDao.save(onapData);
-                               }else{
-                                       commonClassDao.update(onapData); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, psResourceDatas, responseString);
-                       }
-               }catch (Exception e){
-                       utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value={"/ps_dictionary/remove_PSResource"}, method={RequestMethod.POST})
-       public void removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, psResourceDatas, PolicyScopeResource.class);
-       }
+    private static final Logger LOGGER  = FlexLogger.getLogger(PolicyScopeDictionaryController.class);
+
+    private static CommonClassDao commonClassDao;
+    private static String operation = "operation";
+    private static String groupPolicyScopeListData1 = "groupPolicyScopeListData1";
+    private static String policyScope= "PolicyScope";
+    private static String duplicateResponseString = "Duplicate";
+    private static String groupPolicyScopeDatas = "groupPolicyScopeListDatas";
+    private static String dictionaryFields = "dictionaryFields";
+    private static String psCLDatas = "psClosedLoopDictionaryDatas";
+    private static String psServiceDatas = "psServiceDictionaryDatas";
+    private static String psTypeDatas = "psTypeDictionaryDatas";
+    private static String psResourceDatas = "psResourceDictionaryDatas";
+
+    public PolicyScopeDictionaryController(){
+        super();
+    }
+
+    private DictionaryUtils getDictionaryUtilsInstance(){
+        return DictionaryUtils.getDictionaryUtils();
+    }
+
+    @Autowired
+    public PolicyScopeDictionaryController(CommonClassDao commonClassDao){
+        PolicyScopeDictionaryController.commonClassDao = commonClassDao;
+    }
+
+    public void setCommonClassDao(CommonClassDao commonClassDao){
+        PolicyScopeDictionaryController.commonClassDao = commonClassDao;
+    }
+
+    @RequestMapping(value={"/get_GroupPolicyScopeDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getGroupPolicyScopeEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, groupPolicyScopeDatas, "name", GroupPolicyScopeList.class);
+    }
+
+    @RequestMapping(value={"/get_GroupPolicyScopeData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getGroupPolicyScopeEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, groupPolicyScopeDatas, GroupPolicyScopeList.class);
+    }
+
+    @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope"}, method={RequestMethod.POST})
+    public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            GroupPolicyScopeList gpdata = null;
+            GroupPolicyScope groupData = null;
+            boolean duplicateGroupFlag = false;
+            if (fromAPI) {
+                gpdata = mapper.readValue(root.get(dictionaryFields).toString(), GroupPolicyScopeList.class);
+                try{
+                    groupData = mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class);
+                }catch(Exception e){
+                    groupData = new GroupPolicyScope();
+                    groupData.setResource(root.get(dictionaryFields).get("resource").toString().replace("\"", ""));
+                    groupData.setClosedloop(root.get(dictionaryFields).get("closedloop").toString().replace("\"", ""));
+                    groupData.setService(root.get(dictionaryFields).get("service").toString().replace("\"", ""));
+                    groupData.setType(root.get(dictionaryFields).get("type").toString().replace("\"", ""));
+                    LOGGER.error(e);
+                }
+            } else {
+                gpdata = mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class);
+                try{
+                    groupData = mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class);
+                }catch(Exception e){
+                    LOGGER.error(e);
+                    groupData = new GroupPolicyScope();
+                    groupData.setResource(root.get(groupPolicyScopeListData1).get("resource").toString().replace("\"", ""));
+                    groupData.setClosedloop(root.get(groupPolicyScopeListData1).get("closedloop").toString().replace("\"", ""));
+                    groupData.setService(root.get(groupPolicyScopeListData1).get("service").toString().replace("\"", ""));
+                    groupData.setType(root.get(groupPolicyScopeListData1).get("type").toString().replace("\"", ""));
+                }
+            }
+            if(!gpdata.getGroupName().startsWith(policyScope)){
+                String name = "PolicyScope_" + gpdata.getGroupName();
+                gpdata.setGroupName(name);
+            }
+            ArrayList<String> valueList = new ArrayList<>();
+            String resourceValue = groupData.getResource();
+            String typeValue = groupData.getType();
+            String serviceValue = groupData.getService();
+            String closedLoopValue = groupData.getClosedloop();
+            valueList.add("resource=" + resourceValue);
+            valueList.add("service=" + serviceValue);
+            valueList.add("type=" + typeValue);
+            valueList.add("closedLoopControlName="  + closedLoopValue);
+            String list = StringUtils.replaceEach(valueList.toString(), new String[]{"[", "]", " "}, new String[]{"", "", ""});
+            gpdata.setGroupList(list);
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class);
+            if(duplicateData.isEmpty()){
+                duplicateData =  commonClassDao.checkDuplicateEntry(gpdata.getGroupList(), "groupList", GroupPolicyScopeList.class);
+                if(duplicateData.isEmpty()){
+                    duplicateGroupFlag = true;
+                }
+            }
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                GroupPolicyScopeList data = (GroupPolicyScopeList) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    gpdata.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != gpdata.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag && !duplicateGroupFlag){
+                if(gpdata.getId() == 0){
+                    commonClassDao.save(gpdata);
+                }else{
+                    commonClassDao.update(gpdata);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.class));
+            }else if(duplicateGroupFlag){
+                responseString = "DuplicateGroup";
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, groupPolicyScopeDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope"}, method={RequestMethod.POST})
+    public void removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, groupPolicyScopeDatas, GroupPolicyScopeList.class);
+    }
+
+    @RequestMapping(value={"/get_PSClosedLoopDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getPSClosedLoopEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, psCLDatas, "name", OnapName.class);
+    }
+
+    @RequestMapping(value={"/get_PSClosedLoopData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getPSClosedLoopEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, psCLDatas, PolicyScopeClosedLoop.class);
+    }
+
+    @RequestMapping(value={"/ps_dictionary/save_psClosedLoop"}, method={RequestMethod.POST})
+    public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            PolicyScopeClosedLoop onapData;
+            if(fromAPI){
+                onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeClosedLoop.class);
+            }else{
+                onapData = mapper.readValue(root.get("psClosedLoopDictionaryData").toString(), PolicyScopeClosedLoop.class);
+            }
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeClosedLoop.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                PolicyScopeClosedLoop data = (PolicyScopeClosedLoop) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    onapData.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(onapData.getId() == 0){
+                    commonClassDao.save(onapData);
+                }else{
+                    commonClassDao.update(onapData);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, psCLDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop"}, method={RequestMethod.POST})
+    public void removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, psCLDatas, PolicyScopeClosedLoop.class);
+    }
+
+    @RequestMapping(value={"/get_PSServiceDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getPSServiceEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, psServiceDatas, "name", PolicyScopeService.class);
+    }
+
+    @RequestMapping(value={"/get_PSServiceData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getPSServiceEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, psServiceDatas, PolicyScopeService.class);
+    }
+
+    @RequestMapping(value={"/ps_dictionary/save_psService"}, method={RequestMethod.POST})
+    public ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            PolicyScopeService onapData;
+            if (fromAPI) {
+                onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeService.class);
+            } else {
+                onapData = mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class);
+            }
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                PolicyScopeService data = (PolicyScopeService) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    onapData.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(onapData.getId() == 0){
+                    commonClassDao.save(onapData);
+                }else{
+                    commonClassDao.update(onapData);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, psServiceDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/ps_dictionary/remove_PSService"}, method={RequestMethod.POST})
+    public void removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, psServiceDatas, PolicyScopeService.class);
+    }
+
+    @RequestMapping(value={"/get_PSTypeDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getPSTypeEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, psTypeDatas, "name", PolicyScopeType.class);
+    }
+
+    @RequestMapping(value={"/get_PSTypeData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getPSTypeEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, psTypeDatas, PolicyScopeType.class);
+    }
+
+    @RequestMapping(value={"/ps_dictionary/save_psType"}, method={RequestMethod.POST})
+    public ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            PolicyScopeType onapData;
+            if(fromAPI){
+                onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeType.class);
+            }else{
+                onapData = mapper.readValue(root.get("psTypeDictionaryData").toString(), PolicyScopeType.class);
+            }
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeType.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                PolicyScopeType data = (PolicyScopeType) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    onapData.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(onapData.getId() == 0){
+                    commonClassDao.save(onapData);
+                }else{
+                    commonClassDao.update(onapData);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, psTypeDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/ps_dictionary/remove_PSType"}, method={RequestMethod.POST})
+    public void removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, psTypeDatas, PolicyScopeType.class);
+    }
+
+    @RequestMapping(value={"/get_PSResourceDataByName"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getPSResourceEntityDataByName(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, psResourceDatas, "name", PolicyScopeResource.class);
+    }
+
+    @RequestMapping(value={"/get_PSResourceData"}, method={RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE)
+    public void getPSResourceEntityData(HttpServletResponse response){
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, psResourceDatas, PolicyScopeResource.class);
+    }
+
+    @RequestMapping(value={"/ps_dictionary/save_psResource"}, method={RequestMethod.POST})
+    public ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            PolicyScopeResource onapData;
+            if (fromAPI) {
+                onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeResource.class);
+            } else {
+                onapData = mapper.readValue(root.get("psResourceDictionaryData").toString(), PolicyScopeResource.class);
+            }
+
+            List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeResource.class);
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                PolicyScopeResource data = (PolicyScopeResource) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    onapData.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != onapData.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(onapData.getId() == 0){
+                    commonClassDao.save(onapData);
+                }else{
+                    commonClassDao.update(onapData);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, psResourceDatas, responseString);
+            }
+        }catch (Exception e){
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value={"/ps_dictionary/remove_PSResource"}, method={RequestMethod.POST})
+    public void removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, psResourceDatas, PolicyScopeResource.class);
+    }
 }
 
 class GroupPolicyScope{
-       String resource;
-       String type;
-       String service;
-       String closedloop;
-       public String getResource() {
-               return resource;
-       }
-       public void setResource(String resource) {
-               this.resource = resource;
-       }
-       public String getType() {
-               return type;
-       }
-       public void setType(String type) {
-               this.type = type;
-       }
-       public String getService() {
-               return service;
-       }
-       public void setService(String service) {
-               this.service = service;
-       }
-       public String getClosedloop() {
-               return closedloop;
-       }
-       public void setClosedloop(String closedloop) {
-               this.closedloop = closedloop;
-       }
+    String resource;
+    String type;
+    String service;
+    String closedloop;
+    public String getResource() {
+        return resource;
+    }
+    public void setResource(String resource) {
+        this.resource = resource;
+    }
+    public String getType() {
+        return type;
+    }
+    public void setType(String type) {
+        this.type = type;
+    }
+    public String getService() {
+        return service;
+    }
+    public void setService(String service) {
+        this.service = service;
+    }
+    public String getClosedloop() {
+        return closedloop;
+    }
+    public void setClosedloop(String closedloop) {
+        this.closedloop = closedloop;
+    }
 
 }
index 397904f..227be1b 100644 (file)
@@ -55,134 +55,134 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 
 @Controller
 public class PushPolicyController {
-       private static final Logger LOGGER  = FlexLogger.getLogger(PushPolicyController.class);
-       
-       private static CommonClassDao commonClassDao;
-       private static String policyNames = "policyName";
-       private static String errorMsg  = "error";
-       private static String operation = "operation";
-       private static String messageContent = "message";
-       
-       private static final String REGEX = "[0-9a-zA-Z._ ]*";
-       
-       @Autowired
-       public PushPolicyController(CommonClassDao commonClassDao){
-               PushPolicyController.commonClassDao = commonClassDao;
-       }
-       
-       public void setCommonClassDao(CommonClassDao commonClassDao){
-               PushPolicyController.commonClassDao = commonClassDao;
-       }
-       /*
-        * This is an empty constructor
-        */
-       public PushPolicyController(){}
-       
-       @RequestMapping(value="/pushPolicy", method=RequestMethod.POST)
-       public void pushPolicy(HttpServletRequest request, HttpServletResponse response){
-               ObjectMapper mapper = new ObjectMapper();
-               mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-               try {
-                       JsonNode root = mapper.readTree(request.getInputStream());
-                       String policyScope = root.get("policyScope").asText();
-                       String filePrefix = root.get("filePrefix").asText();
-                       String policyName = root.get(policyNames).asText();
-                       String pdpGroup = root.get("pdpGroup").asText();
-                       String requestID = request.getHeader("X-ECOMP-RequestID");
-                       if(requestID==null){
-                               requestID = UUID.randomUUID().toString();
+    private static final Logger LOGGER  = FlexLogger.getLogger(PushPolicyController.class);
+
+    private static CommonClassDao commonClassDao;
+    private static String policyNames = "policyName";
+    private static String errorMsg     = "error";
+    private static String operation = "operation";
+    private static String messageContent = "message";
+
+    private static final String REGEX = "[0-9a-zA-Z._ ]*";
+
+    @Autowired
+    public PushPolicyController(CommonClassDao commonClassDao){
+        PushPolicyController.commonClassDao = commonClassDao;
+    }
+
+    public void setCommonClassDao(CommonClassDao commonClassDao){
+        PushPolicyController.commonClassDao = commonClassDao;
+    }
+    /*
+     * This is an empty constructor
+     */
+    public PushPolicyController(){}
+
+    @RequestMapping(value="/pushPolicy", method=RequestMethod.POST)
+    public void pushPolicy(HttpServletRequest request, HttpServletResponse response){
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+        try {
+            JsonNode root = mapper.readTree(request.getInputStream());
+            String policyScope = root.get("policyScope").asText();
+            String filePrefix = root.get("filePrefix").asText();
+            String policyName = root.get(policyNames).asText();
+            String pdpGroup = root.get("pdpGroup").asText();
+            String requestID = request.getHeader("X-ECOMP-RequestID");
+            if(requestID==null){
+                requestID = UUID.randomUUID().toString();
                 LOGGER.info("No request ID provided, sending generated ID: " + requestID);
-                       }
-                       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);
-                       if(policyVersionObject!=null){
-                               PolicyVersion policyVersion = (PolicyVersion) policyVersionObject.get(0);
-                               String policyID = policyVersionName.replace(File.separator, "."); // This is before adding version.
-                               policyVersionName += "." + policyVersion.getActiveVersion() + ".xml";
-                               addPolicyToGroup(policyScope, policyID, policyVersionName.replace(File.separator, "."), pdpGroup, response);
-                       }else{
-                               String message = "Unknown Policy '" + policyName + "'";
-                               PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
-                               response.addHeader(errorMsg, "unknownPolicy");
-                               response.addHeader(operation, "push");
-                               response.addHeader(messageContent, message);
-                               response.setStatus(HttpServletResponse.SC_NOT_FOUND);
-                               return;
-                       }
-               } catch (NullPointerException | IOException e) {
-                       LOGGER.error(e);
-                       response.setStatus(HttpServletResponse.SC_NOT_FOUND);
-                       response.addHeader(errorMsg, "unknown");
-                       response.addHeader(operation, "push");
-                       return;
-               }
-       }
+            }
+            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);
+            if(policyVersionObject!=null){
+                PolicyVersion policyVersion = (PolicyVersion) policyVersionObject.get(0);
+                String policyID = policyVersionName.replace(File.separator, "."); // This is before adding version.
+                policyVersionName += "." + policyVersion.getActiveVersion() + ".xml";
+                addPolicyToGroup(policyScope, policyID, policyVersionName.replace(File.separator, "."), pdpGroup, response);
+            }else{
+                String message = "Unknown Policy '" + policyName + "'";
+                PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
+                response.addHeader(errorMsg, "unknownPolicy");
+                response.addHeader(operation, "push");
+                response.addHeader(messageContent, message);
+                response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                return;
+            }
+        } catch (NullPointerException | IOException e) {
+            LOGGER.error(e);
+            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+            response.addHeader(errorMsg, "unknown");
+            response.addHeader(operation, "push");
+            return;
+        }
+    }
 
-       private void addPolicyToGroup(String policyScope, String policyID, String policyName, String pdpGroup, HttpServletResponse response) {
-               StdPDPGroup selectedPDPGroup = null;
-               StdPDPPolicy selectedPolicy = null;
-               //Get the selected PDP Group to push the policy
-               try {
-                       selectedPDPGroup = (StdPDPGroup) XACMLPapServlet.getPAPEngine().getGroup(pdpGroup);
-               } catch (PAPException e1) {
-                       PolicyLogger.error(e1);
-               }
-               if(selectedPDPGroup==null){
-                       String message = "Unknown groupId '" + selectedPDPGroup + "'";
-                       if(!message.matches(REGEX) ){
-                               message = "Unknown groupId";
-                       }
-                       PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
-                       response.addHeader(errorMsg, "unknownGroupId");
-                       response.addHeader(operation, "push");
-                       response.addHeader(messageContent, message);
-                       response.setStatus(HttpServletResponse.SC_NOT_FOUND);
-                       return;
-               }
-               //Get PolicyEntity from DB;
-               EntityManager em = XACMLPapServlet.getEmf().createEntityManager();
-               Query createPolicyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:policyName");                     
-               createPolicyQuery.setParameter("scope", policyScope);
-               createPolicyQuery.setParameter(policyNames, policyName.substring(policyScope.length()+1));
-               List<?> createPolicyQueryList = createPolicyQuery.getResultList();
-               PolicyEntity policyEntity = null;
-               if(!createPolicyQueryList.isEmpty()){
-                       policyEntity = (PolicyEntity)createPolicyQueryList.get(0);
-               }else{
-                       PolicyLogger.error("Somehow, more than one policy with the same scope, name, and deleted status were found in the database");
-                       String message = "Unknown Policy '" + policyName + "'";
-                       PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
-                       response.addHeader(errorMsg, "unknownPolicy");
-                       response.addHeader(operation, "push");
-                       response.addHeader(messageContent, message);
-                       response.setStatus(HttpServletResponse.SC_NOT_FOUND);
-                       return;
-               }
-               File temp = new File(policyName);
-               try (BufferedWriter bw = new BufferedWriter(new FileWriter(temp))){
-                       bw.write(policyEntity.getPolicyData());
-                       URI selectedURI = temp.toURI();
-                       // Create the policy Object
-                       selectedPolicy = new StdPDPPolicy(policyName, true, policyID, selectedURI);
-               } catch (IOException e) {
-                       LOGGER.error("Unable to get policy '" + policyName + "': "+ e.getMessage(),e);
-               } 
-               try {
-                       new ObjectOutputStream(response.getOutputStream()).writeObject(selectedPolicy);
-               } catch (IOException e) {
-                       LOGGER.error(e);
-                       response.addHeader(errorMsg, "policyCopyError");
-                       response.addHeader(messageContent, e.getMessage());
-                       response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-                       return;
-               }
-               response.addHeader("Content-Type","application/json");
-               response.setStatus(HttpServletResponse.SC_ACCEPTED);
-               response.addHeader(operation, "push");
-               response.addHeader("policyId", policyName);
-               return;
-               // TODO : Check point to push policies within PAP. 
-       }
+    private void addPolicyToGroup(String policyScope, String policyID, String policyName, String pdpGroup, HttpServletResponse response) {
+        StdPDPGroup selectedPDPGroup = null;
+        StdPDPPolicy selectedPolicy = null;
+        //Get the selected PDP Group to push the policy
+        try {
+            selectedPDPGroup = (StdPDPGroup) XACMLPapServlet.getPAPEngine().getGroup(pdpGroup);
+        } catch (PAPException e1) {
+            PolicyLogger.error(e1);
+        }
+        if(selectedPDPGroup==null){
+            String message = "Unknown groupId '" + selectedPDPGroup + "'";
+            if(!message.matches(REGEX) ){
+                message = "Unknown groupId";
+            }
+            PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
+            response.addHeader(errorMsg, "unknownGroupId");
+            response.addHeader(operation, "push");
+            response.addHeader(messageContent, message);
+            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+        //Get PolicyEntity from DB;
+        EntityManager em = XACMLPapServlet.getEmf().createEntityManager();
+        Query createPolicyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:policyName");
+        createPolicyQuery.setParameter("scope", policyScope);
+        createPolicyQuery.setParameter(policyNames, policyName.substring(policyScope.length()+1));
+        List<?> createPolicyQueryList = createPolicyQuery.getResultList();
+        PolicyEntity policyEntity = null;
+        if(!createPolicyQueryList.isEmpty()){
+            policyEntity = (PolicyEntity)createPolicyQueryList.get(0);
+        }else{
+            PolicyLogger.error("Somehow, more than one policy with the same scope, name, and deleted status were found in the database");
+            String message = "Unknown Policy '" + policyName + "'";
+            PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
+            response.addHeader(errorMsg, "unknownPolicy");
+            response.addHeader(operation, "push");
+            response.addHeader(messageContent, message);
+            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+        File temp = new File(policyName);
+        try (BufferedWriter bw = new BufferedWriter(new FileWriter(temp))){
+            bw.write(policyEntity.getPolicyData());
+            URI selectedURI = temp.toURI();
+            // Create the policy Object
+            selectedPolicy = new StdPDPPolicy(policyName, true, policyID, selectedURI);
+        } catch (IOException e) {
+            LOGGER.error("Unable to get policy '" + policyName + "': "+ e.getMessage(),e);
+        }
+        try {
+            new ObjectOutputStream(response.getOutputStream()).writeObject(selectedPolicy);
+        } catch (IOException e) {
+            LOGGER.error(e);
+            response.addHeader(errorMsg, "policyCopyError");
+            response.addHeader(messageContent, e.getMessage());
+            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            return;
+        }
+        response.addHeader("Content-Type","application/json");
+        response.setStatus(HttpServletResponse.SC_ACCEPTED);
+        response.addHeader(operation, "push");
+        response.addHeader("policyId", policyName);
+        return;
+        // TODO : Check point to push policies within PAP.
+    }
 }
index 209ba4f..fe49e34 100644 (file)
@@ -46,165 +46,165 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 @Controller
 public class SafePolicyController {
 
-       private static CommonClassDao commonClassDao;
-       private static String duplicateResponseString = "Duplicate";
-       private static String operation = "operation";
-       private static String riskTypeDatas = "riskTypeDictionaryDatas";
-       private static String safePolicyWarningDatas = "safePolicyWarningDatas";
-
-       @Autowired
-       public SafePolicyController(CommonClassDao commonClassDao){
-               SafePolicyController.commonClassDao = commonClassDao;
-       }
-       
-       public void setCommonClassDao(CommonClassDao commonClassDao){
-               SafePolicyController.commonClassDao = commonClassDao;
-       }
-       
-       public SafePolicyController(){
-               super();
-       }       
-       
-       private DictionaryUtils getDictionaryUtilsInstance(){
-               return DictionaryUtils.getDictionaryUtils();
-       }
-       
-       @RequestMapping(value = { "/get_RiskTypeDataByName" }, method = {RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE)
-       public void getRiskTypeDictionaryByNameEntityData(HttpServletResponse response) {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, riskTypeDatas, "name", RiskType.class);
-       }
-
-       @RequestMapping(value = { "/get_RiskTypeData" }, method = {RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE)
-       public void getRiskTypeDictionaryEntityData(HttpServletResponse response) {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, riskTypeDatas, RiskType.class);
-       }
-
-       @RequestMapping(value = { "/sp_dictionary/save_riskType" }, method = {RequestMethod.POST })
-       public ModelAndView saveRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
+    private static CommonClassDao commonClassDao;
+    private static String duplicateResponseString = "Duplicate";
+    private static String operation = "operation";
+    private static String riskTypeDatas = "riskTypeDictionaryDatas";
+    private static String safePolicyWarningDatas = "safePolicyWarningDatas";
+
+    @Autowired
+    public SafePolicyController(CommonClassDao commonClassDao){
+        SafePolicyController.commonClassDao = commonClassDao;
+    }
+
+    public void setCommonClassDao(CommonClassDao commonClassDao){
+        SafePolicyController.commonClassDao = commonClassDao;
+    }
+
+    public SafePolicyController(){
+        super();
+    }
+
+    private DictionaryUtils getDictionaryUtilsInstance(){
+        return DictionaryUtils.getDictionaryUtils();
+    }
+
+    @RequestMapping(value = { "/get_RiskTypeDataByName" }, method = {RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE)
+    public void getRiskTypeDictionaryByNameEntityData(HttpServletResponse response) {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, riskTypeDatas, "name", RiskType.class);
+    }
+
+    @RequestMapping(value = { "/get_RiskTypeData" }, method = {RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE)
+    public void getRiskTypeDictionaryEntityData(HttpServletResponse response) {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, riskTypeDatas, RiskType.class);
+    }
+
+    @RequestMapping(value = { "/sp_dictionary/save_riskType" }, method = {RequestMethod.POST })
+    public ModelAndView saveRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
             RiskType riskTypeData;
             String userId = null;
             if (fromAPI) {
                 riskTypeData = mapper.readValue(root.get("dictionaryFields").toString(), RiskType.class);
                 userId = "API";
             } else {
-               riskTypeData = mapper.readValue(root.get("riskTypeDictionaryData").toString(), RiskType.class);
-               userId = root.get("userid").textValue();
+                riskTypeData = mapper.readValue(root.get("riskTypeDictionaryData").toString(), RiskType.class);
+                userId = root.get("userid").textValue();
             }
             UserInfo userInfo = utils.getUserInfo(userId);
             List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(riskTypeData.getRiskName(), "name", RiskType.class);
-                       boolean duplicateflag = false;
+            boolean duplicateflag = false;
             if(!duplicateData.isEmpty()){
-               RiskType data = (RiskType) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       riskTypeData.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != riskTypeData.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
+                RiskType data = (RiskType) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    riskTypeData.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != riskTypeData.getId()))){
+                    duplicateflag = true;
+                }
+            }
             String responseString = null;
-                       if(!duplicateflag){
-                               riskTypeData.setUserModifiedBy(userInfo);
-                               if(riskTypeData.getId() == 0){
-                                       riskTypeData.setUserCreatedBy(userInfo);
-                                       commonClassDao.save(riskTypeData);
-                               }else{
-                                       riskTypeData.setModifiedDate(new Date());
-                                       commonClassDao.update(riskTypeData); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(RiskType.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, riskTypeDatas, responseString);
-                       }
+            if(!duplicateflag){
+                riskTypeData.setUserModifiedBy(userInfo);
+                if(riskTypeData.getId() == 0){
+                    riskTypeData.setUserCreatedBy(userInfo);
+                    commonClassDao.save(riskTypeData);
+                }else{
+                    riskTypeData.setModifiedDate(new Date());
+                    commonClassDao.update(riskTypeData);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(RiskType.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, riskTypeDatas, responseString);
+            }
         }catch (Exception e) {
-               utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value = { "/sp_dictionary/remove_riskType" }, method = {RequestMethod.POST })
-       public void removeRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, riskTypeDatas, RiskType.class);
-       }
-       
-       @RequestMapping(value = { "/get_SafePolicyWarningDataByName" }, method = {RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE)
-       public void getSafePolicyWarningEntityDataByName(HttpServletResponse response) {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getDataByEntity(response, safePolicyWarningDatas, "name", SafePolicyWarning.class);
-       }
-
-       @RequestMapping(value = { "/get_SafePolicyWarningData" }, method = {RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE)
-       public void getSafePolicyWarningeEntityData(HttpServletResponse response) {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.getData(response, safePolicyWarningDatas, SafePolicyWarning.class);
-       }
-
-       @RequestMapping(value = { "/sp_dictionary/save_safePolicyWarning" }, method = {RequestMethod.POST })
-       public ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               try {
-                       boolean fromAPI = utils.isRequestFromAPI(request);
-                       ObjectMapper mapper = new ObjectMapper();
-                       mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-                       JsonNode root = mapper.readTree(request.getReader());
-                       SafePolicyWarning safePolicyWarning;
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value = { "/sp_dictionary/remove_riskType" }, method = {RequestMethod.POST })
+    public void removeRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, riskTypeDatas, RiskType.class);
+    }
+
+    @RequestMapping(value = { "/get_SafePolicyWarningDataByName" }, method = {RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE)
+    public void getSafePolicyWarningEntityDataByName(HttpServletResponse response) {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getDataByEntity(response, safePolicyWarningDatas, "name", SafePolicyWarning.class);
+    }
+
+    @RequestMapping(value = { "/get_SafePolicyWarningData" }, method = {RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE)
+    public void getSafePolicyWarningeEntityData(HttpServletResponse response) {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.getData(response, safePolicyWarningDatas, SafePolicyWarning.class);
+    }
+
+    @RequestMapping(value = { "/sp_dictionary/save_safePolicyWarning" }, method = {RequestMethod.POST })
+    public ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        try {
+            boolean fromAPI = utils.isRequestFromAPI(request);
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+            JsonNode root = mapper.readTree(request.getReader());
+            SafePolicyWarning safePolicyWarning;
             if (fromAPI) {
                 safePolicyWarning = mapper.readValue(root.get("dictionaryFields").toString(), SafePolicyWarning.class);
             } else {
-               safePolicyWarning = mapper.readValue(root.get("safePolicyWarningData").toString(), SafePolicyWarning.class);
+                safePolicyWarning = mapper.readValue(root.get("safePolicyWarningData").toString(), SafePolicyWarning.class);
             }
 
             List<Object> duplicateData =  commonClassDao.checkDuplicateEntry(safePolicyWarning.getName(), "name", SafePolicyWarning.class);
-                       boolean duplicateflag = false;
-                       if(!duplicateData.isEmpty()){
-                               SafePolicyWarning data = (SafePolicyWarning) duplicateData.get(0);
-                               if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
-                                       safePolicyWarning.setId(data.getId());
-                               }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || 
-                                               (request.getParameter(operation) == null && (data.getId() != safePolicyWarning.getId()))){
-                                       duplicateflag = true;
-                               }
-                       }
-                       String responseString = null;
-                       if(!duplicateflag){
-                               if(safePolicyWarning.getId() == 0){
-                                       commonClassDao.save(safePolicyWarning);
-                               }else{
-                                       commonClassDao.update(safePolicyWarning); 
-                               } 
-                               responseString = mapper.writeValueAsString(commonClassDao.getData(SafePolicyWarning.class));
-                       }else{
-                               responseString = duplicateResponseString;
-                       }
-                       if(fromAPI){
-                               return utils.getResultForApi(responseString);
-                       }else{
-                               utils.setResponseData(response, safePolicyWarningDatas, responseString);
-                       }
+            boolean duplicateflag = false;
+            if(!duplicateData.isEmpty()){
+                SafePolicyWarning data = (SafePolicyWarning) duplicateData.get(0);
+                if(request.getParameter(operation) != null && "update".equals(request.getParameter(operation))){
+                    safePolicyWarning.setId(data.getId());
+                }else if((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) ||
+                        (request.getParameter(operation) == null && (data.getId() != safePolicyWarning.getId()))){
+                    duplicateflag = true;
+                }
+            }
+            String responseString = null;
+            if(!duplicateflag){
+                if(safePolicyWarning.getId() == 0){
+                    commonClassDao.save(safePolicyWarning);
+                }else{
+                    commonClassDao.update(safePolicyWarning);
+                }
+                responseString = mapper.writeValueAsString(commonClassDao.getData(SafePolicyWarning.class));
+            }else{
+                responseString = duplicateResponseString;
+            }
+            if(fromAPI){
+                return utils.getResultForApi(responseString);
+            }else{
+                utils.setResponseData(response, safePolicyWarningDatas, responseString);
+            }
         }catch (Exception e) {
-               utils.setErrorResponseData(response, e);
-               }
-               return null;
-       }
-
-       @RequestMapping(value = { "/sp_dictionary/remove_SafePolicyWarning" }, method = {RequestMethod.POST })
-       public void removeSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
-               DictionaryUtils utils = getDictionaryUtilsInstance();
-               utils.removeData(request, response, safePolicyWarningDatas, SafePolicyWarning.class);
-       }
+            utils.setErrorResponseData(response, e);
+        }
+        return null;
+    }
+
+    @RequestMapping(value = { "/sp_dictionary/remove_SafePolicyWarning" }, method = {RequestMethod.POST })
+    public void removeSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        DictionaryUtils utils = getDictionaryUtilsInstance();
+        utils.removeData(request, response, safePolicyWarningDatas, SafePolicyWarning.class);
+    }
 
 }