Moved the string literal on the left side of the actual string comparison.
Added the "@Override" annotation for method signature
Removed the useless assignment to local variables
Issue-ID: POLICY-239
Change-Id: I5fb84bb6109c03c8c0850100b69df095d865b404
Signed-off-by: rama-huawei <rama.subba.reddy.s@huawei.com>
private static void readFile(){
String pdpFile = null;
private static void readFile(){
String pdpFile = null;
- Long newModified = null;
try{
pdpFile = XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_IDFILE);
}catch (Exception e){
try{
pdpFile = XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_IDFILE);
}catch (Exception e){
}
// Check if File is updated recently
else {
}
// Check if File is updated recently
else {
- newModified = pdpPath.toFile().lastModified();
+ Long newModified = pdpPath.toFile().lastModified();
if (!newModified.equals(oldModified)) {
// File has been updated.
readProps();
if (!newModified.equals(oldModified)) {
// File has been updated.
readProps();
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void readProps() {
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void readProps() {
- Properties pdpProp = null;
pdpProp = new Properties();
try {
InputStream in = new FileInputStream(pdpPath.toFile());
pdpProp = new Properties();
try {
InputStream in = new FileInputStream(pdpPath.toFile());
private static void loadPDPProperties(String propKey, Properties pdpProp){
if (propKey.startsWith("PDP_URL")) {
private static void loadPDPProperties(String propKey, Properties pdpProp){
if (propKey.startsWith("PDP_URL")) {
- String check_val = pdpProp.getProperty(propKey);
- if (check_val == null) {
+ String checkVal = pdpProp.getProperty(propKey);
+ if (checkVal == null) {
LOGGER.error("Properties file doesn't have the PDP_URL parameter");
}
LOGGER.error("Properties file doesn't have the PDP_URL parameter");
}
- if (check_val != null && check_val.contains(";")) {
- List<String> pdp_default = new ArrayList<>(Arrays.asList(check_val.split("\\s*;\\s*")));
+ if (checkVal != null && checkVal.contains(";")) {
+ List<String> pdpDefault = new ArrayList<>(Arrays.asList(checkVal.split("\\s*;\\s*")));
- while (pdpCount < pdp_default.size()) {
- String pdpVal = pdp_default.get(pdpCount);
+ while (pdpCount < pdpDefault.size()) {
+ String pdpVal = pdpDefault.get(pdpCount);
readPDPParam(pdpVal);
pdpCount++;
}
readPDPParam(pdpVal);
pdpCount++;
}
private static final Logger LOGGER = FlexLogger.getLogger(PolicyAdapter.class);
public void configure(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
private static final Logger LOGGER = FlexLogger.getLogger(PolicyAdapter.class);
public void configure(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
- String policyNameValue = null ;
+ String policyNameValue;
String configPolicyName = null ;
if(extendedOptions(policyAdapter, entity)){
return;
String configPolicyName = null ;
if(extendedOptions(policyAdapter, entity)){
return;
* @return
* @throws PAPException
*/
* @return
* @throws PAPException
*/
public void updateGroup(OnapPDPGroup group) throws PAPException {
try {
public void updateGroup(OnapPDPGroup group) throws PAPException {
try {
//Validate the Policy Data
public boolean validatePolicyRequest(PolicyRestAdapter policyAdapter, String policyType) throws PAPException {
//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
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);
* @return
* @throws PAPException
*/
* @return
* @throws PAPException
*/
public PDPStatus getStatus(OnapPDP pdp) throws PAPException {
return (StdPDPStatus)sendToPAP("GET", pdp, null, StdPDPStatus.class);
}
public PDPStatus getStatus(OnapPDP pdp) throws PAPException {
return (StdPDPStatus)sendToPAP("GET", pdp, null, StdPDPStatus.class);
}
String papPass = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_PASS);
Base64.Encoder encoder = Base64.getEncoder();
String encoding = encoder.encodeToString((papID+":"+papPass).getBytes(StandardCharsets.UTF_8));
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;
LOGGER.info("Encoding for the PAP is: " + encoding);
try {
String fullURL = papServletURLString;
}
// special case - Status (actually the detailed status) comes from the PDP directly, not the 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
// Adjust the url and properties appropriately
- String pdpID =((OnapPDP)content).getId();
+ String pdpID =((OnapPDP)contentObj).getId();
fullURL = pdpID + "?type=Status";
fullURL = pdpID + "?type=Status";
if(CheckPDP.validateID(pdpID)){
encoding = CheckPDP.getEncoding(pdpID);
}
if(CheckPDP.validateID(pdpID)){
encoding = CheckPDP.getEncoding(pdpID);
}
connection.setDoOutput(true);
connection.setDoInput(true);
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()) {
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);
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("copied to output, bytes="+count);
}
LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to write content in '" + method + "'", e);
}
} else {
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();
ObjectMapper mapper = new ObjectMapper();
- mapper.writeValue(connection.getOutputStream(), content);
+ mapper.writeValue(connection.getOutputStream(), contentObj);
String isValidData = connection.getHeaderField("isValidData");
String isSuccess = connection.getHeaderField("successMapKey");
Map<String, String> successMap = new HashMap<>();
String isValidData = connection.getHeaderField("isValidData");
String isSuccess = connection.getHeaderField("successMapKey");
Map<String, String> successMap = new HashMap<>();
- if (isValidData != null && isValidData.equalsIgnoreCase("true")){
+ if (isValidData != null && "true".equalsIgnoreCase(isValidData)){
LOGGER.info("Policy Data is valid.");
return true;
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;
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;
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;
LOGGER.info("There was an error while creating the policy!");
successMap.put("error", "error");
return successMap;