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");
boolean sendFlag = false;
SimpleBindings params = new SimpleBindings();
params.put("policyFileName", policyFileName);
- List<Object> watchList = null;
+ List<Object> watchList;
if(PolicyController.isjUnit()){
watchList = policyNotificationDao.getDataByQuery(query, null);
}else{
}
}
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);
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();
- }
}
}
}