summaryrefslogtreecommitdiffstats
path: root/ECOMP-PAP-REST/src
diff options
context:
space:
mode:
authorrb7147 <rb7147@att.com>2017-06-15 09:42:41 -0400
committerrb7147 <rb7147@att.com>2017-06-15 13:27:54 -0400
commita084c4de015521f842a3fef0d7f1f7c340237bc3 (patch)
tree0a3ca8266ee4f91cf246268d6b8b22722899c0ec /ECOMP-PAP-REST/src
parent685ed1545ed28b777a3ba6e7d315b78f355154cb (diff)
[Policy-8 ,Policy-23] Updated Matchid for policies
Commit includes Resolved Sonar blokcers Included the 1707 database scripts. Change-Id: I2ffdfce57e6dee0892b272b23283bf246204599a Signed-off-by: rb7147 <rb7147@att.com>
Diffstat (limited to 'ECOMP-PAP-REST/src')
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java8
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/components/PolicyDBDao.java153
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/ImportService.java7
3 files changed, 83 insertions, 85 deletions
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java
index 4ceae062b..c681c9325 100644
--- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java
+++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java
@@ -1495,6 +1495,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
try{
doACPostTransaction.movePdp(pdp, group, "XACMLPapServlet.doACPost");
}catch(Exception e){
+ doACPostTransaction.rollbackTransaction();
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet",
" Error while moving pdp in the database: "
+"pdp="+pdp.getId()+",to group="+group.getId());
@@ -1520,9 +1521,6 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
return;
}
} catch (PAPException e) {
- if(doACPostTransaction != null){
- doACPostTransaction.rollbackTransaction();
- }
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " AC POST exception");
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
@@ -1748,11 +1746,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
if (papEngine.getPDP(pdpId) == null) {
// this is a request to create a new PDP object
try{
- acPutTransaction.addPdpToGroup(pdp == null ? "PDP is null" : pdp.getId(), group.getId(), pdp.getName(),
+ acPutTransaction.addPdpToGroup(pdp.getId(), group.getId(), pdp.getName(),
pdp.getDescription(), pdp.getJmxPort(),"XACMLPapServlet.doACPut");
} catch(Exception e){
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while adding pdp to group in the database: "
- +"pdp="+ (pdp == null ? "PDP is null" : pdp.getId()) +",to group="+group.getId());
+ +"pdp="+ (pdp.getId()) +",to group="+group.getId());
throw new PAPException(e.getMessage());
}
papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort());
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 8bf5ad6c9..2297413e8 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
@@ -978,6 +978,7 @@ public class PolicyDBDao {
//call command to update
}
private void handleIncomingPolicyChange(String url, String policyId,String oldPathString){
+ String policyName = null;
EntityManager em = emf.createEntityManager();
Query getPolicyEntityQuery = em.createNamedQuery("PolicyEntity.FindById");
getPolicyEntityQuery.setParameter("id", Long.valueOf(policyId));
@@ -991,6 +992,7 @@ public class PolicyDBDao {
String action = "unknown action";
try {
if(policy != null){
+ policyName = policy.getPolicyName();
logger.debug("Deleting Policy: " + policy.getPolicyName());
action = "delete";
Path subFile = null;
@@ -1011,7 +1013,6 @@ public class PolicyDBDao {
}
}
} catch (IOException e1) {
- String policyName = policy.getPolicyName();
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e1, "PolicyDBDao", "Error occurred while performing [" + action + "] of Policy File: " + policyName);
}
}
@@ -2103,89 +2104,93 @@ public class PolicyDBDao {
@Override
public void createPolicy(Policy policy, String username){
- logger.debug("createPolicy(PolicyRestAdapter policy, String username) as createPolicy("+policy+","+username+") called");
- String policyScope = policy.policyAdapter.getDomainDir().replace(File.separator, ".");
- //Does not need to be XACMLPolicyWriterWithPapNotify since it is already in the PAP
- //and this transaction is intercepted up stream.
- InputStream policyXmlStream = XACMLPolicyWriter.getXmlAsInputStream((PolicyType)policy.getCorrectPolicyDataObject());
- String policyDataString;
- try {
- policyDataString = IOUtils.toString(policyXmlStream);
- } catch (IOException e) {
- policyDataString = "could not read";
- PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught IOException on IOUtils.toString("+policyXmlStream+")");
- throw new IllegalArgumentException("Cannot parse the policy xml from the PolicyRestAdapter.");
- }
- IOUtils.closeQuietly(policyXmlStream);
- String configPath = "";
- if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Config")) {
- configPath = evaluateXPath("/Policy/Rule/AdviceExpressions/AdviceExpression[contains(@AdviceId,'ID')]/AttributeAssignmentExpression[@AttributeId='URLID']/AttributeValue/text()", policyDataString);
- } else if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Action")) {
- configPath = evaluateXPath("/Policy/Rule/ObligationExpressions/ObligationExpression[contains(@ObligationId, " +policy.policyAdapter.getActionAttribute()+ ")]/AttributeAssignmentExpression[@AttributeId='body']/AttributeValue/text()", policyDataString);
- }
-
- String prefix = null;
- if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Config")) {
-
- prefix = configPath.substring(configPath.indexOf(policyScope+".")+policyScope.concat(".").length(), configPath.indexOf(policy.policyAdapter.getPolicyName()));
- if(isNullOrEmpty(policy.policyAdapter.getConfigBodyData())){
- String configData = "";
- try{
- String newConfigPath = configPath;
+ InputStream policyXmlStream = null;
+ try{
+ logger.debug("createPolicy(PolicyRestAdapter policy, String username) as createPolicy("+policy+","+username+") called");
+ String policyScope = policy.policyAdapter.getDomainDir().replace(File.separator, ".");
+ //Does not need to be XACMLPolicyWriterWithPapNotify since it is already in the PAP
+ //and this transaction is intercepted up stream.
+ String policyDataString;
+ try {
+ policyXmlStream = XACMLPolicyWriter.getXmlAsInputStream((PolicyType)policy.getCorrectPolicyDataObject());
+ policyDataString = IOUtils.toString(policyXmlStream);
+ } catch (IOException e) {
+ policyDataString = "could not read";
+ PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught IOException on IOUtils.toString("+policyXmlStream+")");
+ throw new IllegalArgumentException("Cannot parse the policy xml from the PolicyRestAdapter.");
+ }
+ IOUtils.closeQuietly(policyXmlStream);
+ String configPath = "";
+ if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Config")) {
+ configPath = evaluateXPath("/Policy/Rule/AdviceExpressions/AdviceExpression[contains(@AdviceId,'ID')]/AttributeAssignmentExpression[@AttributeId='URLID']/AttributeValue/text()", policyDataString);
+ } else if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Action")) {
+ configPath = evaluateXPath("/Policy/Rule/ObligationExpressions/ObligationExpression[contains(@ObligationId, " +policy.policyAdapter.getActionAttribute()+ ")]/AttributeAssignmentExpression[@AttributeId='body']/AttributeValue/text()", policyDataString);
+ }
+
+ String prefix = null;
+ if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Config")) {
+
+ prefix = configPath.substring(configPath.indexOf(policyScope+".")+policyScope.concat(".").length(), configPath.indexOf(policy.policyAdapter.getPolicyName()));
+ if(isNullOrEmpty(policy.policyAdapter.getConfigBodyData())){
+ String configData = "";
try{
- newConfigPath = processConfigPath(newConfigPath);
- }catch(Exception e2){
- logger.error("Could not process config path: "+newConfigPath,e2);
+ String newConfigPath = configPath;
+ try{
+ newConfigPath = processConfigPath(newConfigPath);
+ }catch(Exception e2){
+ logger.error("Could not process config path: "+newConfigPath,e2);
+ }
+ configData = readConfigFile(newConfigPath);
+ }catch(Exception e){
+ logger.error("Could not read config body data for "+configPath,e);
}
- configData = readConfigFile(newConfigPath);
- }catch(Exception e){
- logger.error("Could not read config body data for "+configPath,e);
+ policy.policyAdapter.setConfigBodyData(configData);
}
- policy.policyAdapter.setConfigBodyData(configData);
- }
- } else if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Action")) {
- prefix = "Action_";
- } else if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Decision")) {
- prefix = "Decision_";
- }
-
- if(!(policy.policyAdapter.getData() instanceof PolicyType)){
- PolicyLogger.error("The data field is not an instance of PolicyType");
- throw new IllegalArgumentException("The data field is not an instance of PolicyType");
- }
- String finalName = policyScope + "." + prefix+policy.policyAdapter.getPolicyName()+"."+((PolicyType)policy.policyAdapter.getData()).getVersion()+".xml";
- if(policy.policyAdapter.getConfigType() == null || policy.policyAdapter.getConfigType().equals("")){
- //get the config file extension
- String ext = "";
- if (configPath != null) {
- if (!configPath.equalsIgnoreCase("")) {
- ext = configPath.substring(configPath.lastIndexOf('.'), configPath.length());;
+ } else if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Action")) {
+ prefix = "Action_";
+ } else if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Decision")) {
+ prefix = "Decision_";
+ }
+
+ if(!(policy.policyAdapter.getData() instanceof PolicyType)){
+ PolicyLogger.error("The data field is not an instance of PolicyType");
+ throw new IllegalArgumentException("The data field is not an instance of PolicyType");
+ }
+ String finalName = policyScope + "." + prefix+policy.policyAdapter.getPolicyName()+"."+((PolicyType)policy.policyAdapter.getData()).getVersion()+".xml";
+ if(policy.policyAdapter.getConfigType() == null || policy.policyAdapter.getConfigType().equals("")){
+ //get the config file extension
+ String ext = "";
+ if (configPath != null) {
+ if (!configPath.equalsIgnoreCase("")) {
+ ext = configPath.substring(configPath.lastIndexOf('.'), configPath.length());;
+ }
}
- }
- if(ext.contains("txt")){
- policy.policyAdapter.setConfigType(OTHER_CONFIG);
- } else if(ext.contains("json")){
- policy.policyAdapter.setConfigType(JSON_CONFIG);
- } else if(ext.contains("xml")){
- policy.policyAdapter.setConfigType(XML_CONFIG);
- } else if(ext.contains("properties")){
- policy.policyAdapter.setConfigType(PROPERTIES_CONFIG);
- } else {
- if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Action")){
+ if(ext.contains("txt")){
+ policy.policyAdapter.setConfigType(OTHER_CONFIG);
+ } else if(ext.contains("json")){
policy.policyAdapter.setConfigType(JSON_CONFIG);
+ } else if(ext.contains("xml")){
+ policy.policyAdapter.setConfigType(XML_CONFIG);
+ } else if(ext.contains("properties")){
+ policy.policyAdapter.setConfigType(PROPERTIES_CONFIG);
+ } else {
+ if (policy.policyAdapter.getPolicyType().equalsIgnoreCase("Action")){
+ policy.policyAdapter.setConfigType(JSON_CONFIG);
+ }
}
}
- }
- 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);
+ }finally{
+ 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);
-
}
@Override
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/ImportService.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/ImportService.java
index d70332edf..0b3e313d6 100644
--- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/ImportService.java
+++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/service/ImportService.java
@@ -95,10 +95,8 @@ public class ImportService {
}
}else{
InputStream inputStream = null;
- FileOutputStream outputStream = null;
- try {
+ try(FileOutputStream outputStream = new FileOutputStream("ExtractDir" + File.separator + randomID+".zip")) {
inputStream = request.getInputStream();
- outputStream = new FileOutputStream("ExtractDir" + File.separator + randomID+".zip");
byte[] buffer = new byte[4096];
int bytesRead = -1 ;
while ((bytesRead = inputStream.read(buffer)) != -1) {
@@ -112,9 +110,6 @@ public class ImportService {
if(inputStream != null){
inputStream.close();
}
- if(outputStream != null){
- outputStream.close();
- }
} catch (IOException e) {
PolicyLogger.error("Exception Occured while closing the input/output stream"+e);
}