X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fadmin%2FRESTfulPAPEngine.java;h=234d28f1061630bb80a3277da795f74768bbb2b1;hb=refs%2Fchanges%2F45%2F27645%2F2;hp=d75af075d4a4743ed15664f78b3dd8e342327f37;hpb=073cc188efe9abb4c010cf674e34e2cf46ef1c52;p=policy%2Fengine.git 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 d75af075d..234d28f10 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 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP } @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"); } @@ -160,6 +160,7 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP * @return * @throws PAPException */ + @Override public void updateGroup(OnapPDPGroup group) throws PAPException { try { @@ -242,12 +243,10 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP //Validate the Policy Data public boolean validatePolicyRequest(PolicyRestAdapter policyAdapter, String policyType) throws PAPException { - Boolean isValidData = false; StdPAPPolicy newPAPPolicy = new StdPAPPolicy(policyAdapter.getPolicyName(), policyAdapter.getConfigBodyData(), policyAdapter.getConfigType(), "Base"); //send JSON object to PAP - isValidData = (Boolean) sendToPAP("PUT", newPAPPolicy, null, null, "operation=validate", "apiflag=admin", "policyType=" + policyType); - return isValidData; + return (Boolean) sendToPAP("PUT", newPAPPolicy, null, null, "operation=validate", "apiflag=admin", "policyType=" + policyType); } @@ -321,7 +320,7 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP * @return * @throws PAPException */ - + @Override public PDPStatus getStatus(OnapPDP pdp) throws PAPException { return (StdPDPStatus)sendToPAP("GET", pdp, null, StdPDPStatus.class); } @@ -355,6 +354,7 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP String papPass = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS); Base64.Encoder encoder = Base64.getEncoder(); String encoding = encoder.encodeToString((papID+":"+papPass).getBytes(StandardCharsets.UTF_8)); + Object contentObj = content; LOGGER.info("Encoding for the PAP is: " + encoding); try { String fullURL = papServletURLString; @@ -367,11 +367,11 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP } // special case - Status (actually the detailed status) comes from the PDP directly, not the PAP - if (method.equals("GET") && (content instanceof OnapPDP) && responseContentClass == StdPDPStatus.class) { + if ("GET".equals(method) && (contentObj instanceof OnapPDP) && responseContentClass == StdPDPStatus.class) { // Adjust the url and properties appropriately - String pdpID =((OnapPDP)content).getId(); + String pdpID =((OnapPDP)contentObj).getId(); fullURL = pdpID + "?type=Status"; - content = null; + contentObj = null; if(CheckPDP.validateID(pdpID)){ encoding = CheckPDP.getEncoding(pdpID); } @@ -401,14 +401,14 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP connection.setDoOutput(true); connection.setDoInput(true); - if (content != null) { - if (content instanceof InputStream) { + if (contentObj != null) { + if (contentObj instanceof InputStream) { try { // // Send our current policy configuration // try (OutputStream os = connection.getOutputStream()) { - int count = IOUtils.copy((InputStream)content, os); + int count = IOUtils.copy((InputStream)contentObj, os); if (LOGGER.isDebugEnabled()) { LOGGER.debug("copied to output, bytes="+count); } @@ -417,9 +417,9 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to write content in '" + method + "'", e); } } else { - // The content is an object to be encoded in JSON + // The contentObj is an object to be encoded in JSON ObjectMapper mapper = new ObjectMapper(); - mapper.writeValue(connection.getOutputStream(), content); + mapper.writeValue(connection.getOutputStream(), contentObj); } } // @@ -434,18 +434,18 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP String isValidData = connection.getHeaderField("isValidData"); String isSuccess = connection.getHeaderField("successMapKey"); Map successMap = new HashMap<>(); - if (isValidData != null && isValidData.equalsIgnoreCase("true")){ + if (isValidData != null && "true".equalsIgnoreCase(isValidData)){ LOGGER.info("Policy Data is valid."); return true; - } else if (isValidData != null && isValidData.equalsIgnoreCase("false")) { + } else if (isValidData != null && "false".equalsIgnoreCase(isValidData)) { LOGGER.info("Policy Data is invalid."); return false; - } else if (isSuccess != null && isSuccess.equalsIgnoreCase("success")) { + } else if (isSuccess != null && "success".equalsIgnoreCase(isSuccess)) { LOGGER.info("Policy Created Successfully!" ); String finalPolicyPath = connection.getHeaderField("finalPolicyPath"); successMap.put("success", finalPolicyPath); return successMap; - } else if (isSuccess != null && isSuccess.equalsIgnoreCase("error")) { + } else if (isSuccess != null && "error".equalsIgnoreCase(isSuccess)) { LOGGER.info("There was an error while creating the policy!"); successMap.put("error", "error"); return successMap; @@ -467,12 +467,10 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP final CollectionType javaType = mapper.getTypeFactory().constructCollectionType(collectionTypeClass, responseContentClass); - Object objectFromJSON = mapper.readValue(json, javaType); - return objectFromJSON; + return (Object)mapper.readValue(json, javaType); } else { // single value object expected - Object objectFromJSON = mapper.readValue(json, responseContentClass); - return objectFromJSON; + return (Object)mapper.readValue(json, responseContentClass); } }