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=1fccfda7815dab8ed683d1cdd4cd12936ee88b55;hb=84540cb5794753f9ade18149238ccde443edac35;hp=da73613fce76a722c9be9fb0c6b6b22cb8094eae;hpb=dea7a9791960ac2f913e2ab4c70491706ab9e2a0;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 da73613fc..1fccfda78 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 @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd. + * Modifications Copyright (C) 2019 Bell Canada * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +25,11 @@ package org.onap.policy.admin; import java.io.File; import java.text.DateFormat; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Properties; -import javax.mail.MessagingException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import javax.script.SimpleBindings; @@ -56,6 +57,7 @@ public class PolicyNotificationMail{ private static final String ACTIVE_VERSION = "Active Version : "; private static final String SCOPE_POLICY_NAME = "Scope + Policy Name : "; private static final String DELETED_TIME = "Deleted Time : "; + private static final String DELETED_BY = "Deleted By : "; private static Logger policyLogger = FlexLogger.getLogger(PolicyNotificationMail.class); @Bean @@ -81,9 +83,8 @@ public class PolicyNotificationMail{ * @param policyName Name of the policy for which notification is to be sent * @param mode kind of operation done on the policy * @param policyNotificationDao database access object for policy - * @throws MessagingException */ - public void sendMail(PolicyVersion entityItem, String policyName, String mode, CommonClassDao policyNotificationDao) throws MessagingException { + public void sendMail(PolicyVersion entityItem, String policyName, String mode, CommonClassDao policyNotificationDao) { String subject = ""; String message = ""; @@ -102,17 +103,17 @@ public class PolicyNotificationMail{ if("DeleteAll".equalsIgnoreCase(mode)){ subject = "Policy has been Deleted : "+entityItem.getPolicyName(); message = POLICY_WATCHING_MESSAGE + PolicyController.getSmtpApplicationName() + " has been Deleted with All Versions" + '\n' + '\n' + '\n'+ SCOPE_POLICY_NAME + policyName + '\n' - + '\n' + '\n' + "Deleted By : " +entityItem.getModifiedBy() + '\n' + DELETED_TIME +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + EMAIL_MESSAGE_POSTSCRIPT; + + '\n' + '\n' + DELETED_BY +entityItem.getModifiedBy() + '\n' + DELETED_TIME +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + EMAIL_MESSAGE_POSTSCRIPT; } if("DeleteOne".equalsIgnoreCase(mode)){ subject = "Policy has been Deleted : "+entityItem.getPolicyName(); message = POLICY_WATCHING_MESSAGE + PolicyController.getSmtpApplicationName() + " has been Deleted" + '\n' + '\n' + '\n'+ SCOPE_POLICY_NAME + policyName + '\n' +"Policy Version : " +entityItem.getActiveVersion() - + '\n' + '\n' + "Deleted By : " +entityItem.getModifiedBy() + '\n' + DELETED_TIME +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + EMAIL_MESSAGE_POSTSCRIPT; + + '\n' + '\n' + DELETED_BY +entityItem.getModifiedBy() + '\n' + DELETED_TIME +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + EMAIL_MESSAGE_POSTSCRIPT; } if("DeleteScope".equalsIgnoreCase(mode)){ subject = "Scope has been Deleted : "+entityItem.getPolicyName(); message = "The Scope Which you are watching in " + PolicyController.getSmtpApplicationName() + " has been Deleted" + '\n' + '\n' + '\n'+ "Scope + Scope Name : " + policyName + '\n' - + '\n' + '\n' + "Deleted By : " +entityItem.getModifiedBy() + '\n' + DELETED_TIME +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + EMAIL_MESSAGE_POSTSCRIPT; + + '\n' + '\n' + DELETED_BY +entityItem.getModifiedBy() + '\n' + DELETED_TIME +dateFormat.format(date) + '\n' + '\n' + '\n' + '\n' + EMAIL_MESSAGE_POSTSCRIPT; } if("SwitchVersion".equalsIgnoreCase(mode)){ subject = "Policy has been SwitchedVersion : "+entityItem.getPolicyName(); @@ -129,24 +130,25 @@ public class PolicyNotificationMail{ String policyFileName = findPolicyFileName(entityItem); String query = "from WatchPolicyNotificationTable where policyName like:policyFileName"; List watchList = findWatchList(policyNotificationDao, policyFileName, query); - if (watchList == null) return; - - composeAndSendMail(mode, policyNotificationDao, subject, message, checkPolicyName, watchList); + if (!watchList.isEmpty()) { + composeAndSendMail(mode, policyNotificationDao, subject, message, checkPolicyName, watchList); + } } private List findWatchList(CommonClassDao policyNotificationDao, String policyFileName, String query) { SimpleBindings params = new SimpleBindings(); params.put("policyFileName", policyFileName); List watchList; - if(PolicyController.isjUnit()){ + if (PolicyController.isjUnit()) { watchList = policyNotificationDao.getDataByQuery(query, null); - }else{ + } else { watchList = policyNotificationDao.getDataByQuery(query, params); } - if(watchList == null || watchList.isEmpty()) { - policyLogger.debug("List of policy being watched is either null or empty, hence return without sending mail"); - return null; + if (watchList == null || watchList.isEmpty()) { + policyLogger + .debug("List of policy being watched is either null or empty, hence return without sending mail"); + watchList = new ArrayList<>(); } return watchList; }