sonar blocker/critical fixes

Fixes for sonar critical and blocker issues

Issue-Id: POLICY-113
Change-Id: I33bf28abfc52bf289401c58409beaac01b5c2fa6
Signed-off-by: Tej, Tarun <tt3868@att.com>
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
index 88f6d45..4d3fe06 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java
@@ -1574,7 +1574,7 @@
 				PolicyDBDaoTransaction setDefaultGroupTransaction = policyDBDao.getNewTransaction();
 				try {
 					setDefaultGroupTransaction.changeDefaultGroup(group, "XACMLPapServlet.doACPost");
-					papEngine.SetDefaultGroup(group);
+					papEngine.setDefaultGroup(group);
 					setDefaultGroupTransaction.commitTransaction();
 				} catch (Exception e) {
 					setDefaultGroupTransaction.rollbackTransaction();
@@ -1652,7 +1652,7 @@
 	 * @throws ServletException
 	 * @throws IOException
 	 */
-	private void doACGet(HttpServletRequest request, HttpServletResponse response, String groupId, ONAPLoggingContext loggingContext) throws ServletException, IOException {
+	private void doACGet(HttpServletRequest request, HttpServletResponse response, String groupId, ONAPLoggingContext loggingContext) throws IOException {
 		try {
 			String parameterDefault = request.getParameter("default");
 			String pdpId = request.getParameter("pdpId");
@@ -1684,7 +1684,12 @@
 					if (pdpGroup == null) {
 						// Request is for the (unspecified) group containing a given PDP
 						loggingContext.setServiceName("AC:PAP.getPDP");
-						OnapPDP pdp = papEngine.getPDP(pdpId);
+						OnapPDP pdp = null;
+						try{
+						    pdp = papEngine.getPDP(pdpId);
+						}catch(PAPException e){
+						    LOGGER.error(e);
+						}
 						// convert response object to JSON and include in the response
 						mapperWriteValue(new ObjectMapper(), response,  pdp);
 						if (LOGGER.isDebugEnabled()) {
@@ -1692,7 +1697,11 @@
 						}
 						response.setStatus(HttpServletResponse.SC_OK);
 						response.setHeader("content-type", "application/json");
-						response.getOutputStream().close();
+						try{
+                            response.getOutputStream().close();
+                        } catch (IOException e){
+                            LOGGER.error(e);
+                        }
 						loggingContext.transactionEnded();
 						auditLogger.info("Success");
 						PolicyLogger.audit("Transaction Ended Successfully");
@@ -1700,8 +1709,13 @@
 					} else {
 						// Request is for the group containing a given PDP
 						loggingContext.setServiceName("AC:PAP.getGroupForPDP");
-						OnapPDP pdp = papEngine.getPDP(pdpId);
-						OnapPDPGroup group = papEngine.getPDPGroup((OnapPDP) pdp);
+						OnapPDPGroup group =null;
+						try{
+						    OnapPDP pdp = papEngine.getPDP(pdpId);
+	                        group = papEngine.getPDPGroup((OnapPDP) pdp);
+						}catch(PAPException e){
+						    LOGGER.error(e);
+						}
 						// convert response object to JSON and include in the response
 						mapperWriteValue(new ObjectMapper(), response,  group);
 						if (LOGGER.isDebugEnabled()) {
@@ -1742,7 +1756,12 @@
 				}
 			}
 			// for all other GET operations the group must exist before the operation can be done
-			OnapPDPGroup group = papEngine.getGroup(groupId);
+			OnapPDPGroup group = null;
+			try{
+			    group = papEngine.getGroup(groupId);
+			} catch(PAPException e){
+			    LOGGER.error(e);
+			}
 			if (group == null) {
 				String message = "Unknown groupId '" + groupId + "'";
 				PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message);
@@ -1810,7 +1829,7 @@
 	 * @throws ServletException
 	 * @throws IOException
 	 */
-	private void doACPut(HttpServletRequest request, HttpServletResponse response, String groupId, ONAPLoggingContext loggingContext) throws ServletException, IOException {
+	private void doACPut(HttpServletRequest request, HttpServletResponse response, String groupId, ONAPLoggingContext loggingContext) throws IOException {
 		PolicyDBDaoTransaction acPutTransaction = policyDBDao.getNewTransaction();
 		try {
 			// for PUT operations the group may or may not need to exist before the operation can be done
@@ -1846,15 +1865,14 @@
 				// get the request content into a String
 				String json = null;
 				// read the inputStream into a buffer (trick found online scans entire input looking for end-of-file)
-				Scanner scanner = null;
 				try{
-				    scanner = new Scanner(request.getInputStream());
+				    Scanner scanner = new Scanner(request.getInputStream());
+				    scanner.useDelimiter("\\A");
+	                json =  scanner.hasNext() ? scanner.next() : "";
+	                scanner.close();
 				}catch(IOException e){
 				    LOGGER.error(e);
 				}
-				scanner.useDelimiter("\\A");
-				json =  scanner.hasNext() ? scanner.next() : "";
-				scanner.close();
 				LOGGER.info("JSON request from AC: " + json);
 				// convert Object sent as JSON into local object
 				ObjectMapper mapper = new ObjectMapper();
@@ -1871,7 +1889,13 @@
 				}
 				StdPDP pdp = (StdPDP) objectFromJSON;
 				if(pdp != null){
-					if (papEngine.getPDP(pdpId) == null) {
+				    OnapPDP oPDP = null;
+				    try{
+				        oPDP = papEngine.getPDP(pdpId);
+				    }catch (PAPException e){
+				        LOGGER.error(e);
+				    }
+					if (oPDP == null) {
 						// this is a request to create a new PDP object
 						try{
 							acPutTransaction.addPdpToGroup(pdp.getId(), group.getId(), pdp.getName(), 
@@ -1940,15 +1964,14 @@
 				// get the request content into a String
 				String json = null;
 				// read the inputStream into a buffer (trick found online scans entire input looking for end-of-file)
-				Scanner scanner = null;
                 try{
-                    scanner = new Scanner(request.getInputStream());
+                    Scanner scanner = new Scanner(request.getInputStream());
+                    scanner.useDelimiter("\\A");
+                    json =  scanner.hasNext() ? scanner.next() : "";
+                    scanner.close();
                 }catch(IOException e){
                     LOGGER.error(e);
                 }
-				scanner.useDelimiter("\\A");
-				json =  scanner.hasNext() ? scanner.next() : "";
-				scanner.close();
 				LOGGER.info("JSON request from AC: " + json);
 				// convert Object sent as JSON into local object
 				ObjectMapper mapper = new ObjectMapper();
@@ -2020,7 +2043,7 @@
 	 * @throws ServletException
 	 * @throws IOException
 	 */
-	private void doACDelete(HttpServletRequest request, HttpServletResponse response, String groupId, ONAPLoggingContext loggingContext) throws ServletException, IOException {
+	private void doACDelete(HttpServletRequest request, HttpServletResponse response, String groupId, ONAPLoggingContext loggingContext) throws IOException {
 		//This code is to allow deletes to propagate to the database since delete is not implemented
 		String isDeleteNotify = request.getParameter("isDeleteNotify");
 		if(isDeleteNotify != null){
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
index bf632f1..7c46990 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
@@ -796,7 +796,7 @@
 			//set default if it should be
 			if(!localGroupClone.isDefaultGroup() && groupRecord.isDefaultGroup()){
 				try {
-					papEngine.SetDefaultGroup(localGroup);
+					papEngine.setDefaultGroup(localGroup);
 					return;
 				} catch (PAPException e) {
 					PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught PAPException trying to set default group with papEngine.SetDefaultGroup("+localGroupClone+");");
diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/api/pap/PAPPolicyEngine.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/api/pap/PAPPolicyEngine.java
index 4f1cfaf..805293e 100644
--- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/api/pap/PAPPolicyEngine.java
+++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/api/pap/PAPPolicyEngine.java
@@ -30,11 +30,11 @@
 	
 	public OnapPDPGroup getDefaultGroup() throws PAPException;
 	
-	public void						SetDefaultGroup(OnapPDPGroup group) throws PAPException;
+	public void						setDefaultGroup(OnapPDPGroup group) throws PAPException;
 	
-	public void		newPDP(String id, OnapPDPGroup group, String name, String description, int jmxport) throws PAPException, NullPointerException;
+	public void		newPDP(String id, OnapPDPGroup group, String name, String description, int jmxport) throws PAPException;
 	
-	public void						newGroup(String name, String description) throws PAPException, NullPointerException;
+	public void						newGroup(String name, String description) throws PAPException;
 	
 	public OnapPDPGroup getGroup(String id) throws PAPException;
 	
@@ -54,7 +54,7 @@
 	
 	public void						updateGroup(OnapPDPGroup group) throws PAPException;
 	
-	public void						removeGroup(OnapPDPGroup group, OnapPDPGroup newGroup) throws PAPException, NullPointerException;
+	public void						removeGroup(OnapPDPGroup group, OnapPDPGroup newGroup) throws PAPException;
 	
 public void						publishPolicy(String id, String name, boolean isRoot, InputStream policy, OnapPDPGroup group) throws PAPException;
 	
diff --git a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java
index 14d7c7f..09c5a6a 100644
--- a/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java
+++ b/ONAP-XACML/src/main/java/org/onap/policy/xacml/std/pap/StdEngine.java
@@ -810,7 +810,7 @@
 	}
 
 	@Override
-	public void SetDefaultGroup(OnapPDPGroup group) throws PAPException {
+	public void setDefaultGroup(OnapPDPGroup group) throws PAPException {
 		boolean changesMade = false;
 		for (OnapPDPGroup aGroup : groups) {
 			if (aGroup.getId().equals(group.getId())) {
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java
index d75af07..1f9372a 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java
@@ -119,7 +119,7 @@
 	}
 
 	@Override
-	public void SetDefaultGroup(OnapPDPGroup group) throws PAPException {
+	public void setDefaultGroup(OnapPDPGroup group) throws PAPException {
 		sendToPAP("POST", null, null, null, groupID + group.getId(), "default=true");
 	}
 
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPGroupContainer.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPGroupContainer.java
index c05a674..04ec3e8 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPGroupContainer.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/model/PDPGroupContainer.java
@@ -142,7 +142,7 @@
 	
 	public void makeDefault(OnapPDPGroup group) {
 		try {
-			this.papEngine.SetDefaultGroup(group);
+			this.papEngine.setDefaultGroup(group);
 		} catch (PAPException e) {
 			String message = "Unable to set Default Group on server: " + e;
 			LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + message, e);