Policy 1707 commit to LF
[policy/engine.git] / ECOMP-PAP-REST / src / main / java / org / openecomp / policy / pap / xacml / rest / policycontroller / PolicyCreation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP-PAP-REST
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.openecomp.policy.pap.xacml.rest.policycontroller;
21
22 import java.io.File;
23 import java.util.HashMap;
24 import java.util.LinkedHashMap;
25 import java.util.LinkedList;
26 import java.util.List;
27 import java.util.Map;
28
29 import javax.servlet.http.HttpServletRequest;
30 import javax.servlet.http.HttpServletResponse;
31
32 import org.openecomp.policy.common.logging.eelf.PolicyLogger;
33 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
34 import org.openecomp.policy.common.logging.flexlogger.Logger;
35 import org.openecomp.policy.pap.xacml.rest.XACMLPapServlet;
36 import org.openecomp.policy.pap.xacml.rest.components.ActionPolicy;
37 import org.openecomp.policy.pap.xacml.rest.components.ClosedLoopPolicy;
38 import org.openecomp.policy.pap.xacml.rest.components.ConfigPolicy;
39 import org.openecomp.policy.pap.xacml.rest.components.CreateBrmsParamPolicy;
40 import org.openecomp.policy.pap.xacml.rest.components.CreateBrmsRawPolicy;
41 import org.openecomp.policy.pap.xacml.rest.components.CreateClosedLoopPerformanceMetrics;
42 import org.openecomp.policy.pap.xacml.rest.components.DecisionPolicy;
43 import org.openecomp.policy.pap.xacml.rest.components.FirewallConfigPolicy;
44 import org.openecomp.policy.pap.xacml.rest.components.MicroServiceConfigPolicy;
45 import org.openecomp.policy.pap.xacml.rest.components.Policy;
46 import org.openecomp.policy.pap.xacml.rest.components.PolicyDBDao;
47 import org.openecomp.policy.pap.xacml.rest.components.PolicyDBDaoTransaction;
48 import org.openecomp.policy.pap.xacml.rest.elk.client.PolicyElasticSearchController;
49 import org.openecomp.policy.pap.xacml.rest.util.AbstractPolicyCreation;
50 import org.openecomp.policy.rest.adapter.PolicyRestAdapter;
51 import org.openecomp.policy.rest.dao.CommonClassDao;
52 import org.openecomp.policy.rest.jpa.ActionPolicyDict;
53 import org.openecomp.policy.rest.jpa.BRMSParamTemplate;
54 import org.openecomp.policy.rest.jpa.PolicyEditorScopes;
55 import org.openecomp.policy.rest.jpa.PolicyVersion;
56 import org.openecomp.policy.rest.jpa.UserInfo;
57 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
58 import org.springframework.beans.factory.annotation.Autowired;
59 import org.springframework.http.HttpStatus;
60 import org.springframework.http.ResponseEntity;
61 import org.springframework.http.converter.HttpMessageNotReadableException;
62 import org.springframework.web.bind.annotation.ExceptionHandler;
63 import org.springframework.web.bind.annotation.RequestBody;
64 import org.springframework.web.bind.annotation.RequestMapping;
65 import org.springframework.web.bind.annotation.RequestMethod;
66 import org.springframework.web.bind.annotation.ResponseBody;
67 import org.springframework.web.bind.annotation.RestController;
68
69 import com.fasterxml.jackson.databind.ObjectMapper;
70
71
72 @RestController
73 @RequestMapping("/")
74 public class PolicyCreation extends AbstractPolicyCreation{
75
76         private static final Logger LOGGER      = FlexLogger.getLogger(PolicyCreation.class);
77
78         private String ruleID = "";
79         private PolicyDBDao policyDBDao;
80         String CLName = null;
81         
82         private static CommonClassDao commonClassDao;
83         
84         @Autowired
85         public PolicyCreation(CommonClassDao commonClassDao){
86                 PolicyCreation.commonClassDao = commonClassDao;
87         }
88
89         public PolicyCreation(){}
90         
91         @RequestMapping(value="/policycreation/save_policy", method = RequestMethod.POST)
92         @ResponseBody
93         public ResponseEntity<String> savePolicy(@RequestBody PolicyRestAdapter policyData, HttpServletResponse response) throws Exception{
94                 String body = null;
95                 HttpStatus status = HttpStatus.BAD_REQUEST;
96                 Map<String, String> successMap = new HashMap<String, String>();
97                 Map<String, String> attributeMap = new HashMap<String, String>();
98                 PolicyVersion policyVersionDao;
99                 try {
100                 
101                         Policy newPolicy = null;
102                         String policyConfigType = null;
103                         String userId = policyData.getUserId();
104
105                         if (policyData.getTtlDate()==null){
106                                 policyData.setTtlDate("NA");
107                         }else{
108                                 String dateTTL = policyData.getTtlDate();
109                                 String newDate = convertDate(dateTTL, false);
110                                 policyData.setTtlDate(newDate);
111                         }
112
113                         String policyType = policyData.getPolicyType();
114
115                         String filePrefix = null;
116                         if (policyType.equalsIgnoreCase("Config")) {
117                                 policyConfigType = policyData.getConfigPolicyType();
118                                 if (policyConfigType.equalsIgnoreCase("Firewall Config")) {
119                                         filePrefix = "Config_FW_";
120                                 }else if (policyConfigType.equalsIgnoreCase("ClosedLoop_Fault")) {
121                                         filePrefix = "Config_Fault_";
122                                 }else if (policyConfigType.equalsIgnoreCase("ClosedLoop_PM")) {
123                                         filePrefix = "Config_PM_";
124                                 }else if (policyConfigType.equalsIgnoreCase("Micro Service")) {
125                                         filePrefix = "Config_MS_";
126                                 }else if (policyConfigType.equalsIgnoreCase("BRMS_Raw")) {
127                                         filePrefix = "Config_BRMS_Raw_";
128                                 }else if (policyConfigType.equalsIgnoreCase("BRMS_Param")) {
129                                         filePrefix = "Config_BRMS_Param_";
130                                 }else {
131                                         filePrefix = "Config_"; 
132                                 }
133                         } else if (policyType.equalsIgnoreCase("Action")) {
134                                 filePrefix = "Action_";
135                         } else if (policyType.equalsIgnoreCase("Decision")) {
136                                 filePrefix = "Decision_";
137                         }
138
139                         int version = 0;
140                         int highestVersion = 0;
141                         String createdBy = "";
142                         String modifiedBy = userId;
143                         String scopeCheck = policyData.getDomainDir().replace(".", File.separator);
144                         PolicyEditorScopes policyEditorScope = (PolicyEditorScopes) commonClassDao.getEntityItem(PolicyEditorScopes.class, "scopeName", scopeCheck);
145                         if(policyEditorScope == null){
146                                 UserInfo userInfo = new UserInfo();
147                                 userInfo.setUserName("API");
148                                 userInfo.setUserLoginId("API");
149                                 PolicyEditorScopes editorScope = new PolicyEditorScopes();
150                                 editorScope.setScopeName(scopeCheck);
151                                 editorScope.setUserCreatedBy(userInfo);
152                                 editorScope.setUserModifiedBy(userInfo);
153                                 commonClassDao.save(editorScope);
154                         }
155                         //get the highest version of policy from policy version table.
156                         String dbCheckPolicyName = policyData.getDomainDir() + File.separator + filePrefix + policyData.getPolicyName();
157                         PolicyVersion policyVersion = getPolicyVersionData(dbCheckPolicyName);  
158                         if(policyVersion == null){
159                                 highestVersion = 0;
160                         }else{
161                                 highestVersion = policyVersion.getHigherVersion();
162                         }
163                         
164                         if(highestVersion != 0){
165                                 if(policyData.isEditPolicy){
166                                         version = highestVersion +1;
167                                         if(userId ==null){
168                                                 modifiedBy = "API";
169                                         }else{
170                                                 modifiedBy = userId;
171                                         }
172                                         policyData.setUserId("API");
173                                         createdBy = policyVersion.getCreatedBy();
174                                         policyVersionDao = policyVersion;
175                                         policyVersionDao.setActiveVersion(version);
176                                         policyVersionDao.setHigherVersion(version);
177                                         policyVersionDao.setModifiedBy(modifiedBy);
178                                 }else{
179                                         body = "policyExists";
180                                         status = HttpStatus.CONFLICT;
181                                         response.setStatus(HttpServletResponse.SC_CONFLICT);
182                                         response.addHeader("error", "policyExists");
183                                         response.addHeader("policyName", policyData.getPolicyName());
184                                         return new ResponseEntity<String>(body, status);
185                                 }               
186                         }else{
187                                 version = 1;
188                                 if(userId == null){
189                                         createdBy = "API";
190                                         modifiedBy = "API";
191                                         policyData.setUserId("API");
192                                 }else{
193                                         createdBy = userId;
194                                         modifiedBy = userId;
195                                         policyData.setUserId("API");
196                                 }
197                                 policyVersionDao = new PolicyVersion();
198                                 policyVersionDao.setPolicyName(dbCheckPolicyName);
199                                 policyVersionDao.setActiveVersion(version);
200                                 policyVersionDao.setHigherVersion(version);
201                                 policyVersionDao.setCreatedBy(createdBy);
202                                 policyVersionDao.setModifiedBy(modifiedBy);
203                         }
204                         
205                         policyData.setPolicyID(newPolicyID());
206                         policyData.setRuleID(ruleID);
207         
208                         String policyFileName = dbCheckPolicyName.replace(File.separator, ".")+ "." + version + ".xml";
209                         policyData.setNewFileName(policyFileName);
210                         policyData.setPolicyDescription(policyData.getPolicyDescription()+ "@CreatedBy:" +createdBy + "@CreatedBy:" + "@ModifiedBy:" +modifiedBy + "@ModifiedBy:");
211                         policyData.setRuleCombiningAlgId("urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-overrides");
212                         if(policyData.getApiflag() == null){
213                                 //set the Rule Combining Algorithm Id to be sent to PAP-REST via JSON   
214                                 if(policyData.getAttributes() != null){
215                                         if(policyData.getAttributes().size() > 0){
216                                                 for(Object attribute : policyData.getAttributes()){
217                                                         if(attribute instanceof LinkedHashMap<?, ?>){
218                                                                 String key = ((LinkedHashMap<?, ?>) attribute).get("key").toString();
219                                                                 String value = ((LinkedHashMap<?, ?>) attribute).get("value").toString();
220                                                                 attributeMap.put(key, value);   
221                                                         }
222                                                 }
223                                         }
224                                 }
225                                 policyData.setDynamicFieldConfigAttributes(attributeMap);
226                         }
227                         
228                         policyData.setVersion(String.valueOf(version));
229                         policyData.setHighestVersion(version);
230
231                         // Calling Component class per policy type
232                         if (policyType.equalsIgnoreCase("Config")) {
233                                 if (policyConfigType.equalsIgnoreCase("Firewall Config")) {
234                                         newPolicy = new FirewallConfigPolicy(policyData);
235                                 }else if (policyConfigType.equalsIgnoreCase("BRMS_Raw")) { 
236                                         policyData.setEcompName("DROOLS");
237                                         policyData.setConfigName("BRMS_RAW_RULE");
238                                         newPolicy = new CreateBrmsRawPolicy(policyData);
239                                 }else if (policyConfigType.equalsIgnoreCase("BRMS_Param")) {
240                                         policyData.setEcompName("DROOLS");
241                                         policyData.setConfigName("BRMS_PARAM_RULE");
242                                         Map<String, String> drlRuleAndUIParams = new HashMap<String, String>();
243                                         if(policyData.getApiflag() == null){
244                                                 // If there is any dynamic field create the matches here
245                                                 String key="templateName";
246                                                 String value=(String) policyData.getRuleName();
247                                                 drlRuleAndUIParams.put(key, value);
248                                                 if(policyData.getRuleData().size() > 0){
249                                                         for(Object keyValue: policyData.getRuleData().keySet()){
250                                                                 drlRuleAndUIParams.put(keyValue.toString(), policyData.getRuleData().get(keyValue).toString());
251                                                         }
252                                                 }
253                                                 policyData.setBrmsParamBody(drlRuleAndUIParams);
254                                         }else{
255                                 drlRuleAndUIParams=policyData.getBrmsParamBody();
256                                 String modelName= drlRuleAndUIParams.get("templateName");
257                                 PolicyLogger.info("Template name from API is: "+modelName);
258                                 
259                                 BRMSParamTemplate template = (BRMSParamTemplate) commonClassDao.getEntityItem(BRMSParamTemplate.class, "ruleName", modelName);
260                                 if(template == null){
261                                         String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Template.  The template name, " 
262                                             + modelName + " was not found in the dictionary.";
263                                         body = message;
264                                         status = HttpStatus.BAD_REQUEST;
265                                     response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
266                                     response.addHeader("error", message);
267                                     response.addHeader("modelName", modelName);
268                                     return new ResponseEntity<String>(body, status);
269                                 }
270                                         }               
271                                         newPolicy = new CreateBrmsParamPolicy(policyData);
272                                 }else if (policyConfigType.equalsIgnoreCase("Base")) {
273                                         newPolicy =  new ConfigPolicy(policyData);
274                                 }else if (policyConfigType.equalsIgnoreCase("ClosedLoop_Fault")) {
275                                         newPolicy = new ClosedLoopPolicy(policyData);
276                                 }else if (policyConfigType.equalsIgnoreCase("ClosedLoop_PM")) {
277                                         if(policyData.getApiflag() == null){
278                                                 policyData.setServiceType(policyData.getServiceTypePolicyName().get("serviceTypePolicyName").toString());
279                                                 ObjectMapper jsonMapper = new ObjectMapper();
280                                                 String jsonBody = jsonMapper.writeValueAsString(policyData.getJsonBodyData());
281                                                 jsonBody = jsonBody.replaceFirst("\\{", "\\{\"serviceTypePolicyName\": \"serviceTypeFieldValue\",");
282                                                 jsonBody = jsonBody.replace("serviceTypeFieldValue", policyData.getServiceType());
283                                                 policyData.setJsonBody(jsonBody);
284                                         }
285                                         newPolicy = new CreateClosedLoopPerformanceMetrics(policyData);
286                                 }else if (policyConfigType.equalsIgnoreCase("Micro Service")) {
287                                         newPolicy = new MicroServiceConfigPolicy(policyData);
288                                 }
289                         }else if(policyType.equalsIgnoreCase("Action")) {
290                                 if(policyData.getApiflag() == null){
291                                         List<String> dynamicRuleAlgorithmLabels = new LinkedList<String>();
292                                         List<String> dynamicRuleAlgorithmCombo = new LinkedList<String>();
293                                         List<String> dynamicRuleAlgorithmField1 = new LinkedList<String>();
294                                         List<String> dynamicRuleAlgorithmField2 = new LinkedList<String>();
295
296
297                                         if(policyData.getRuleAlgorithmschoices().size() > 0){
298                                                 for(Object attribute : policyData.getRuleAlgorithmschoices()){
299                                                         if(attribute instanceof LinkedHashMap<?, ?>){
300                                                                 String label = ((LinkedHashMap<?, ?>) attribute).get("id").toString();
301                                                                 String key = ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmField1").toString();
302                                                                 String rule = ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmCombo").toString();
303                                                                 String value = ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmField2").toString();
304                                                                 dynamicRuleAlgorithmLabels.add(label);
305                                                                 dynamicRuleAlgorithmField1.add(key);
306                                                                 dynamicRuleAlgorithmCombo.add(rule);
307                                                                 dynamicRuleAlgorithmField2.add(value);
308                                                         }
309                                                 }
310                                         }
311
312                                         String actionDictValue = policyData.getActionAttributeValue();
313                                         ActionPolicyDict jsonData = ((ActionPolicyDict) commonClassDao.getEntityItem(ActionPolicyDict.class, "attributeName", actionDictValue));
314                                         String actionBodyString = jsonData.getBody();
315                                         String actionDictHeader = jsonData.getHeader();
316                                         String actionDictType = jsonData.getType();
317                                         String actionDictUrl = jsonData.getUrl();
318                                         String actionDictMethod = jsonData.getMethod();
319                                         policyData.setActionDictHeader(actionDictHeader);
320                                         policyData.setActionDictType(actionDictType);
321                                         policyData.setActionDictUrl(actionDictUrl);
322                                         policyData.setActionDictMethod(actionDictMethod);
323                                         policyData.setActionAttribute(actionDictValue);
324                                         policyData.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
325                                         policyData.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
326                                         policyData.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
327                                         policyData.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
328                                         if (actionBodyString != null) {
329                                                 policyData.setActionBody(actionBodyString);
330                                         }
331                                 }
332                                 newPolicy = new ActionPolicy(policyData);
333                         } else if (policyType.equalsIgnoreCase("Decision")) {
334                                 if(policyData.getApiflag() == null){
335                                         Map<String, String> settingsMap = new HashMap<String, String>();
336                                         List<String> dynamicRuleAlgorithmLabels = new LinkedList<String>();
337                                         List<String> dynamicRuleAlgorithmCombo = new LinkedList<String>();
338                                         List<String> dynamicRuleAlgorithmField1 = new LinkedList<String>();
339                                         List<String> dynamicRuleAlgorithmField2 = new LinkedList<String>();
340                                         List<Object> dynamicVariableList = new LinkedList<Object>();
341                                         List<String> dataTypeList = new LinkedList<String>();
342
343                                         if(policyData.getSettings().size() > 0){
344                                                 for(Object settingsData : policyData.getSettings()){
345                                                         if(settingsData instanceof LinkedHashMap<?, ?>){
346                                                                 String key = ((LinkedHashMap<?, ?>) settingsData).get("key").toString();
347                                                                 String value = ((LinkedHashMap<?, ?>) settingsData).get("value").toString();
348                                                                 settingsMap.put(key, value);    
349                                                         }
350                                                 }
351                                         }
352                                         if(policyData.getRuleAlgorithmschoices().size() > 0){
353                                                 for(Object attribute : policyData.getRuleAlgorithmschoices()){
354                                                         if(attribute instanceof LinkedHashMap<?, ?>){
355                                                                 String label = ((LinkedHashMap<?, ?>) attribute).get("id").toString();
356                                                                 String key = ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmField1").toString();
357                                                                 String rule = ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmCombo").toString();
358                                                                 String value = ((LinkedHashMap<?, ?>) attribute).get("dynamicRuleAlgorithmField2").toString();
359                                                                 dynamicRuleAlgorithmLabels.add(label);
360                                                                 dynamicRuleAlgorithmField1.add(key);
361                                                                 dynamicRuleAlgorithmCombo.add(rule);
362                                                                 dynamicRuleAlgorithmField2.add(value);
363                                                         }
364                                                 }
365                                         }
366
367                                         policyData.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
368                                         policyData.setDynamicRuleAlgorithmCombo(dynamicRuleAlgorithmCombo);
369                                         policyData.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
370                                         policyData.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
371                                         policyData.setDynamicVariableList(dynamicVariableList);
372                                         policyData.setDynamicSettingsMap(settingsMap);
373                                         policyData.setDynamicFieldConfigAttributes(attributeMap);
374                                         policyData.setDataTypeList(dataTypeList);
375                                 }
376                                 newPolicy = new DecisionPolicy(policyData);
377                         }
378
379                         newPolicy.prepareToSave();
380                         
381                         PolicyDBDaoTransaction policyDBDaoTransaction = null;
382                         try{
383                                 policyDBDao = PolicyDBDao.getPolicyDBDaoInstance(XACMLPapServlet.getEmf());
384                                 policyDBDaoTransaction = policyDBDao.getNewTransaction();
385                                 policyDBDaoTransaction.createPolicy(newPolicy, policyData.getUserId());
386                                 successMap = newPolicy.savePolicies();
387                                 if(successMap.containsKey("success")){
388                                         policyDBDaoTransaction.commitTransaction();
389                                         if(policyData.isEditPolicy){
390                                                 commonClassDao.update(policyVersionDao);
391                                         }else{
392                                                 commonClassDao.save(policyVersionDao);
393                                         }
394                                         try{
395                                                 PolicyElasticSearchController search= new PolicyElasticSearchController();
396                                                 search.updateElk(policyData);
397                                         }catch(Exception e){
398                                                 LOGGER.error("Error Occured while saving policy to Elastic Database"+e);
399                                         }
400                                         body = "success";
401                                         status = HttpStatus.OK;
402                                         response.setStatus(HttpServletResponse.SC_OK);                                                          
403                                         response.addHeader("successMapKey", "success");                                                         
404                                         response.addHeader("policyName", policyData.getNewFileName());
405                                         
406                     //get message from the SafetyCheckerResults if present
407                     String safetyCheckerResponse = policyData.getClWarning();
408                     String existingCLName = policyData.getExistingCLName();
409
410                     //if safetyCheckerResponse is not null add a header to send back with response
411                     if(safetyCheckerResponse!=null) {
412                         PolicyLogger.info("SafetyCheckerResponse message: " + safetyCheckerResponse);
413                         response.addHeader("safetyChecker", safetyCheckerResponse);
414                         response.addHeader("newCLName", CLName);
415                         response.addHeader("conflictCLName", existingCLName);
416                     } else {
417                         PolicyLogger.info("SafetyCheckerResponse was empty or null.");
418                     }
419                     
420                                 }else if (successMap.containsKey("invalidAttribute")) {
421                                         String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Invalid Action Attribute";
422                                         LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + "Could not fine " + policyData.getActionAttribute() + " in the ActionPolicyDict table.");
423                                         body = "invalidAttribute";
424                                         status = HttpStatus.BAD_REQUEST;
425                                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);                                                         
426                                         response.addHeader("invalidAttribute", policyData.getActionAttribute());
427                                         response.addHeader("error", message);
428                                         response.addHeader("policyName", policyData.getPolicyName());
429                                 }else if (successMap.containsKey("fwdberror")) {
430                                         policyDBDaoTransaction.rollbackTransaction();
431                                         body = "fwdberror";
432                                         status = HttpStatus.BAD_REQUEST;
433                                         String message = XACMLErrorConstants.ERROR_DATA_ISSUE
434                             + "Error when inserting Firewall ConfigBody data into the database.";
435                                 PolicyLogger.error(message);
436                                         response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
437                                         response.addHeader("error", message);
438                                         response.addHeader("policyName", policyData.getPolicyName());
439                                 } else if (successMap.get("error").equals("Validation Failed")) {
440                     policyDBDaoTransaction.rollbackTransaction();
441                     String message = XACMLErrorConstants.ERROR_DATA_ISSUE
442                                         + "Error Validating the Policy on the PAP.";
443                     PolicyLogger.error(message);
444                     body = "Validation";
445                                         status = HttpStatus.BAD_REQUEST;
446                     response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
447                     response.addHeader("error", message);
448                     response.addHeader("policyName", policyData.getPolicyName());
449                 }else {                                         
450                                         policyDBDaoTransaction.rollbackTransaction();
451                                         body = "error";
452                                         status = HttpStatus.INTERNAL_SERVER_ERROR;
453                                         response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);                                                               
454                                         response.addHeader("error", "error");                                                   
455                                 }
456                         }catch(Exception e){
457                                 policyDBDaoTransaction.rollbackTransaction();
458                         }
459
460                 }
461                 catch (Exception e){
462                         e.printStackTrace();
463                 }
464                 return new ResponseEntity<String>(body, status);
465         }
466
467         @ExceptionHandler({ HttpMessageNotReadableException.class })
468         public ResponseEntity<String> messageNotReadableExceptionHandler(HttpServletRequest req, HttpMessageNotReadableException exception) {
469                 LOGGER.error("Request not readable: {}", exception);
470                 StringBuilder message = new StringBuilder();
471                 message.append(exception.getMessage());
472                 if (exception.getCause() != null) {
473                         message.append(" Reason Caused: "
474                                         + exception.getCause().getMessage());
475                 }
476                 return new ResponseEntity<>(message.toString(), HttpStatus.BAD_REQUEST);
477         }
478
479         public PolicyVersion getPolicyVersionData(String dbCheckPolicyName){
480                 PolicyVersion entityItem = (PolicyVersion) commonClassDao.getEntityItem(PolicyVersion.class, "policyName", dbCheckPolicyName);
481                 if (entityItem != null) {               
482                         if(entityItem.getPolicyName().equals(dbCheckPolicyName)){
483                                 return entityItem;
484                         }
485                 }       
486                 return entityItem;
487         }
488 }