X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fadmin%2FPolicyNotificationMail.java;h=6424465de3144352672e6cd96998b3e11d714f64;hb=7206d21ac469fefb18b5d5fe570771f2442aeedb;hp=2326a9fb762e50742533b8cb482869876ae4d16c;hpb=deb35bccd7b0d360668f393fe5b45b735b7956b2;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyNotificationMail.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyNotificationMail.java index 2326a9fb7..6424465de 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyNotificationMail.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyNotificationMail.java @@ -66,7 +66,7 @@ public class PolicyNotificationMail{ public void sendMail(PolicyVersion entityItem, String policyName, String mode, CommonClassDao policyNotificationDao) throws MessagingException { String from = PolicyController.getSmtpUsername(); - String to = ""; + String to; String subject = ""; String message = ""; DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); @@ -108,12 +108,15 @@ public class PolicyNotificationMail{ } String policyFileName = entityItem.getPolicyName(); String checkPolicyName = policyName; + if(checkPolicyName.endsWith(".xml") || checkPolicyName.contains(".")){ + checkPolicyName = checkPolicyName.substring(0, checkPolicyName.indexOf('.')); + } if(policyFileName.contains("/")){ - policyFileName = policyFileName.substring(0, policyFileName.indexOf("/")); + policyFileName = policyFileName.substring(0, policyFileName.indexOf('/')); policyFileName = policyFileName.replace("/", File.separator); } if(policyFileName.contains("\\")){ - policyFileName = policyFileName.substring(0, policyFileName.indexOf("\\")); + policyFileName = policyFileName.substring(0, policyFileName.indexOf('\\')); policyFileName = policyFileName.replace("\\", "\\\\"); } @@ -122,7 +125,7 @@ public class PolicyNotificationMail{ boolean sendFlag = false; SimpleBindings params = new SimpleBindings(); params.put("policyFileName", policyFileName); - List watchList = null; + List watchList; if(PolicyController.isjUnit()){ watchList = policyNotificationDao.getDataByQuery(query, null); }else{ @@ -140,11 +143,9 @@ public class PolicyNotificationMail{ } } if(sendFlag){ - AnnotationConfigApplicationContext ctx = null; - try { + try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) { to = list.getLoginIds()+"@"+PolicyController.getSmtpEmailExtension(); to = to.trim(); - ctx = new AnnotationConfigApplicationContext(); ctx.register(PolicyNotificationMail.class); ctx.refresh(); JavaMailSenderImpl mailSender = ctx.getBean(JavaMailSenderImpl.class); @@ -155,15 +156,11 @@ public class PolicyNotificationMail{ mailMsg.setSubject(subject); mailMsg.setText(message); mailSender.send(mimeMessage); - if(mode.equalsIgnoreCase("Rename") || mode.contains("Delete") || mode.contains("Move")){ + if("Rename".equalsIgnoreCase(mode) || mode.contains("Delete") || mode.contains("Move")){ policyNotificationDao.delete(watch); } } catch (Exception e) { policyLogger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Exception Occured in Policy Notification" +e); - }finally{ - if(ctx != null){ - ctx.close(); - } } } }