1
|
package eu.dnetlib.goldoa.service.utils;
|
2
|
|
3
|
import org.aspectj.lang.ProceedingJoinPoint;
|
4
|
import org.aspectj.lang.annotation.Around;
|
5
|
import org.aspectj.lang.annotation.Aspect;
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
7
|
import org.springframework.beans.factory.annotation.Value;
|
8
|
import org.springframework.stereotype.Component;
|
9
|
|
10
|
import javax.mail.MessagingException;
|
11
|
import java.io.PrintWriter;
|
12
|
import java.io.StringWriter;
|
13
|
|
14
|
/**
|
15
|
* Created by antleb on 5/6/15.
|
16
|
*/
|
17
|
@Component
|
18
|
@Aspect
|
19
|
public class EmailUtilsLogger {
|
20
|
@Autowired
|
21
|
private MailLibrary mailLibrary;
|
22
|
|
23
|
private
|
24
|
@Value("#{cascadingPropertyLoader.properties['goldoa.debugemails']}")
|
25
|
boolean sendEmails = false;
|
26
|
|
27
|
@Around("execution(public void eu.dnetlib.goldoa.service.utils.EmailUtils.send* (..))")
|
28
|
public Object logErrors(ProceedingJoinPoint joinPoint) throws Throwable {
|
29
|
if (sendEmails) {
|
30
|
try {
|
31
|
mailLibrary.sendEmail("antleb@di.uoa.gr", "sending email: " + joinPoint.getSignature().getName(), "");
|
32
|
|
33
|
return joinPoint.proceed();
|
34
|
} catch (Throwable throwable) {
|
35
|
StringWriter sw = new StringWriter();
|
36
|
PrintWriter pw = new PrintWriter(sw);
|
37
|
|
38
|
throwable.printStackTrace(pw);
|
39
|
pw.close();
|
40
|
|
41
|
try {
|
42
|
mailLibrary.sendEmail("antleb@di.uoa.gr", "Exception in mails", sw.toString());
|
43
|
} catch (MessagingException e) {
|
44
|
e.printStackTrace();
|
45
|
}
|
46
|
|
47
|
throw throwable;
|
48
|
}
|
49
|
} else {
|
50
|
return joinPoint.proceed();
|
51
|
}
|
52
|
}
|
53
|
}
|