Modified the code to fix various pushPolicy issues
[policy/engine.git] / ONAP-PAP-REST / src / main / java / org / onap / policy / pap / xacml / rest / policycontroller / PolicyCreation.java
index 80657fc..2af8a6e 100644 (file)
@@ -99,7 +99,7 @@ public class PolicyCreation extends AbstractPolicyCreation{
        
        @RequestMapping(value="/policycreation/save_policy", method = RequestMethod.POST)
        @ResponseBody
-       public ResponseEntity<String> savePolicy(@RequestBody PolicyRestAdapter policyData, HttpServletResponse response) throws Exception{
+       public ResponseEntity<String> savePolicy(@RequestBody PolicyRestAdapter policyData, HttpServletResponse response){
                String body = null;
                HttpStatus status = HttpStatus.BAD_REQUEST;
                Map<String, String> successMap = new HashMap<>();
@@ -115,7 +115,7 @@ public class PolicyCreation extends AbstractPolicyCreation{
                                policyData.setTtlDate("NA");
                        }else{
                                String dateTTL = policyData.getTtlDate();
-                               String newDate = convertDate(dateTTL, false);
+                               String newDate = convertDate(dateTTL);
                                policyData.setTtlDate(newDate);
                        }
 
@@ -193,6 +193,15 @@ public class PolicyCreation extends AbstractPolicyCreation{
                                        return new ResponseEntity<String>(body, status);
                                }               
                        }else{
+                               // if policy does not exist and the request is updatePolicy return error
+                               if(policyData.isEditPolicy()){
+                                       body = "policyNotAvailableForEdit";
+                                       status = HttpStatus.NOT_FOUND;
+                                       response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+                                       response.addHeader("error", body);
+                                       response.addHeader("message", policyData.getPolicyName() + " does not exist on the PAP and cannot be updated.");
+                                       return new ResponseEntity<String>(body, status);
+                               }
                                version = 1;
                                if(userId == null){
                                        createdBy = "API";
@@ -512,13 +521,14 @@ public class PolicyCreation extends AbstractPolicyCreation{
                                        response.addHeader("error", "error");                                                   
                                }
                        }catch(Exception e){
+                               LOGGER.error("Exception Occured : ",e);
                                if(policyDBDaoTransaction != null){
                                        policyDBDaoTransaction.rollbackTransaction();
                                }
                        }
                }
                catch (Exception e){
-                       LOGGER.error("Exception Occured : "+e);
+                       LOGGER.error("Exception Occured : "+e.getMessage(),e);
                        body = "error";
                        response.addHeader("error", e.getMessage());    
                        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);