Code Review
/
policy
/
engine.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Merge "JUnit workaround for PAP-REST, sonar bug"
[policy/engine.git]
/
POLICY-SDK-APP
/
src
/
main
/
java
/
org
/
onap
/
policy
/
admin
/
PolicyNotificationMail.java
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
a4e4762
..
6424465
100644
(file)
--- 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();
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");
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;
}
String policyFileName = entityItem.getPolicyName();
String checkPolicyName = policyName;
+ if(checkPolicyName.endsWith(".xml") || checkPolicyName.contains(".")){
+ checkPolicyName = checkPolicyName.substring(0, checkPolicyName.indexOf('.'));
+ }
if(policyFileName.contains("/")){
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.replace("/", File.separator);
}
if(policyFileName.contains("\\")){
- policyFileName = policyFileName.substring(0, policyFileName.indexOf(
"\\"
));
+ policyFileName = policyFileName.substring(0, policyFileName.indexOf(
'\\'
));
policyFileName = policyFileName.replace("\\", "\\\\");
}
policyFileName = policyFileName.replace("\\", "\\\\");
}
@@
-122,7
+125,12
@@
public class PolicyNotificationMail{
boolean sendFlag = false;
SimpleBindings params = new SimpleBindings();
params.put("policyFileName", policyFileName);
boolean sendFlag = false;
SimpleBindings params = new SimpleBindings();
params.put("policyFileName", policyFileName);
- List<Object> watchList = policyNotificationDao.getDataByQuery(query, params);
+ List<Object> watchList;
+ if(PolicyController.isjUnit()){
+ watchList = policyNotificationDao.getDataByQuery(query, null);
+ }else{
+ watchList = policyNotificationDao.getDataByQuery(query, params);
+ }
if(watchList != null && !watchList.isEmpty()){
for(Object watch : watchList){
WatchPolicyNotificationTable list = (WatchPolicyNotificationTable) watch;
if(watchList != null && !watchList.isEmpty()){
for(Object watch : watchList){
WatchPolicyNotificationTable list = (WatchPolicyNotificationTable) watch;
@@
-135,11
+143,9
@@
public class PolicyNotificationMail{
}
}
if(sendFlag){
}
}
if(sendFlag){
- AnnotationConfigApplicationContext ctx = null;
- try {
+ try (AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext()) {
to = list.getLoginIds()+"@"+PolicyController.getSmtpEmailExtension();
to = to.trim();
to = list.getLoginIds()+"@"+PolicyController.getSmtpEmailExtension();
to = to.trim();
- ctx = new AnnotationConfigApplicationContext();
ctx.register(PolicyNotificationMail.class);
ctx.refresh();
JavaMailSenderImpl mailSender = ctx.getBean(JavaMailSenderImpl.class);
ctx.register(PolicyNotificationMail.class);
ctx.refresh();
JavaMailSenderImpl mailSender = ctx.getBean(JavaMailSenderImpl.class);
@@
-150,15
+156,11
@@
public class PolicyNotificationMail{
mailMsg.setSubject(subject);
mailMsg.setText(message);
mailSender.send(mimeMessage);
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);
policyNotificationDao.delete(watch);
}
} catch (Exception e) {
policyLogger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW+"Exception Occured in Policy Notification" +e);
- }finally{
- if(ctx != null){
- ctx.close();
- }
}
}
}
}
}
}