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=895adbe417e609b993a9d091cf2eb75f819e635e;hb=cac5ee759fee5db51a32838c7e25b878468a27e0;hp=67d9c8813b40de170bdaeb1d713f81274d4a0768;hpb=aa9e865ccf191e814b50b8b4b51d516fc359d948;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 67d9c8813..895adbe41 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 @@ -109,14 +109,14 @@ public class PolicyNotificationMail{ String policyFileName = entityItem.getPolicyName(); String checkPolicyName = policyName; if(checkPolicyName.endsWith(".xml") || checkPolicyName.contains(".")){ - checkPolicyName = checkPolicyName.substring(0, checkPolicyName.indexOf(".")); + 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("\\", "\\\\"); } @@ -143,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); @@ -158,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(); - } } } }