X-Git-Url: https://gerrit.onap.org/r/gitweb?p=policy%2Fengine.git;a=blobdiff_plain;f=ECOMP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcomponents%2FPolicyDBDao.java;h=b65557e0584f597623ca32e5ac22afe0fe5db56e;hp=51fcb3d09dcf76f5bbecbdbc99258622a70ab9b1;hb=fc5c07705edc4dcb7083b39116a43844bb6a1490;hpb=d9007d680d19734d5dc106479784c420236cca4b diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java index 51fcb3d09..b65557e05 100644 --- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java +++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java @@ -35,7 +35,6 @@ import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.Path; @@ -69,8 +68,6 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathFactory; -import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; - import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; @@ -105,6 +102,8 @@ import com.att.research.xacml.api.pap.PDP; import com.att.research.xacml.api.pap.PDPPolicy; import com.att.research.xacml.util.XACMLProperties; +import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType; + public class PolicyDBDao { private static final Logger logger = FlexLogger.getLogger(PolicyDBDao.class); private List otherServers; @@ -871,6 +870,7 @@ public class PolicyDBDao { try { policyStream.close(); } catch (IOException e) { + didUpdate = false; PolicyLogger.error(e.getMessage()); } } @@ -1031,7 +1031,7 @@ public class PolicyDBDao { String action = "unknown action"; try { - if(policy.isDeleted()){ + if(policy != null && policy.isDeleted()){ logger.debug("Deleting Policy: " + policy.getPolicyName()); action = "delete"; Path newPath = Paths.get(policyPath.toString(), policy.getPolicyName()); @@ -1098,7 +1098,7 @@ public class PolicyDBDao { } } catch (IOException e1) { - PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "Error occurred while performing [" + action + "] of Policy File: " + policy.getPolicyName()); + PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "Error occurred while performing [" + action + "] of Policy File: " + policy != null ? policy.getPolicyName() : "null"); } } @@ -1315,11 +1315,12 @@ public class PolicyDBDao { String repo = buildPolicyDirectory(); String policyScope = policy.getScope(); + if(policyScope == null){ policyScope = ""; PolicyLogger.error("buildPolicyScopeDirectory("+policy+") computed null policyScope. Using blank."); } else { - policyScope = policyScope.replace(".", FileSystems.getDefault().getSeparator()); + policyScope = policyScope.replace(".", File.separator); } if(policyScope == null){ policyScope = ""; @@ -1329,7 +1330,7 @@ public class PolicyDBDao { PolicyLogger.error("buildPolicyScopeDirectory("+policy+") received null repo. Using blank."); repo = ""; } - Path returnPath = Paths.get(repo + FileSystems.getDefault().getSeparator() + policyScope); + Path returnPath = Paths.get(repo + File.separator + policyScope); if(returnPath != null){ return returnPath.toString(); } else { @@ -1341,9 +1342,7 @@ public class PolicyDBDao { } private String buildPolicyScopeDirectory(String policyScope){ String repo = buildPolicyDirectory(); - policyScope = policyScope.replace(".", FileSystems.getDefault().getSeparator()); - return repo + FileSystems.getDefault().getSeparator() + policyScope; - + return repo + File.separator + policyScope.replace(".", File.separator); } private static String buildPolicyDirectory(){ @@ -1628,7 +1627,13 @@ public class PolicyDBDao { } catch(Exception e){ PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "auditLocalDatabase() error"); logger.error("Exception Occured"+e); - } + }finally{ + try { + Files.walk(webappsPath).close(); + } catch (IOException e) { + logger.error("Exception Occured while closing File Stream"+e); + } + } } /** @@ -1980,7 +1985,7 @@ public class PolicyDBDao { for(int j=i;j= path.length()){ + if(path != null && (gitPath.length() >= path.length())){ logger.debug("gitPath length(): " + gitPath.length() + ">= path.length(): " + path.length() + ". Returning null"); return null; } @@ -2996,6 +3001,13 @@ public class PolicyDBDao { } } } + if(policyXmlStream != null){ + try { + policyXmlStream.close(); + } catch (IOException e) { + logger.error("Exception Occured while closing input stream"+e); + } + } createPolicy(policy.policyAdapter, username, policyScope,finalName,policyDataString); }