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