Project

General

Profile

« Previous | Next » 

Revision 33295

Added by Nikon Gasparis over 9 years ago

added email package

View differences:

modules/uoa-validator-commons/trunk/src/main/java/gr/uoa/di/validator/email/BugReporter.java
1
package gr.uoa.di.validator.email;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import org.apache.log4j.Logger;
7

  
8

  
9
public class BugReporter {
10

  
11
	private transient Logger logger = Logger.getLogger(BugReporter.class);
12
	
13
	private String ex = null;
14

  
15
	public void report() {
16
		List<String> recipients = new ArrayList<String>();
17
		try {
18
			recipients.add("nikonas@di.uoa.gr");
19
			String message = "An exception has occurred:\n"+ex;
20
			String subject = "Automatic Bug Report";
21
//			this.getEmailer().sendMail(recipients, subject, message, false, null);
22
		} catch (Exception e) {
23
			logger.error("error sending error report", e);
24
		}
25
	}
26

  
27
	public void setEx(String ex) {
28
		this.ex = ex;
29
	}
30

  
31
	public String getEx() {
32
		return ex;
33
	}
34
	
35
	
36

  
37
}
modules/uoa-validator-commons/trunk/src/main/java/gr/uoa/di/validator/email/Emailer.java
1
package gr.uoa.di.validator.email;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import org.apache.log4j.Logger;
7

  
8
import eu.dnetlib.utils.MailLibrary;
9

  
10
public class Emailer {
11

  
12
	private static Logger logger = Logger.getLogger(Emailer.class);
13

  
14
	private List<String> specialRecipients = new ArrayList<String>();
15
	private boolean override = false, logonly = false;
16
	private String overrideEmail = null, from = null;
17

  
18
	private MailLibrary mailer = null;
19

  
20
	public void sendMail(List<String> recipients, String subject, String message, boolean sendToSpecial, List<String> repoAdminMails) throws Exception {
21

  
22
		try {
23
			if (sendToSpecial) {
24
				recipients.addAll(this.specialRecipients);
25
			}
26

  
27
			if (repoAdminMails != null)
28
				recipients.addAll(repoAdminMails);
29

  
30
			if (this.override) {
31
				recipients.clear();
32
				recipients.add(overrideEmail);
33
			}
34

  
35
			logger.debug("Sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message);
36
			if (!logonly)
37
				mailer.sendEmail(recipients.toArray(new String[] {}), subject, message);
38
		} catch (Exception e) {
39
			logger.error("Error sending mail to Recipients: " + recipients + " Subject: " + subject + " Message: " + message, e);
40
			throw new Exception(e);
41
		}
42
	}
43

  
44
	public void setSpecialRecipients(String specialRecipients) {
45
		String[] recps = specialRecipients.split(",");
46

  
47
		for (String recp : recps) {
48
			recp = recp.trim();
49

  
50
			this.specialRecipients.add(recp);
51
		}
52
	}
53

  
54
	public void setOverride(boolean override) {
55
		this.override = override;
56
	}
57

  
58
	public void setOverrideEmail(String overrideEmail) {
59
		this.overrideEmail = overrideEmail;
60
	}
61

  
62
	public void setMailer(MailLibrary mailer) {
63
		this.mailer = mailer;
64
	}
65

  
66
	public String getFrom() {
67
		return from;
68
	}
69

  
70
	public void setFrom(String from) {
71
		this.from = from;
72
	}
73

  
74
	public boolean isLogonly() {
75
		return logonly;
76
	}
77

  
78
	public void setLogonly(boolean logonly) {
79
		this.logonly = logonly;
80
	}
81

  
82
}
modules/uoa-validator-commons/trunk/src/main/resources/gr/uoa/di/validator/dao/springContext-validator-dao.xml
16 16
        http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd"
17 17
	default-autowire="no">
18 18

  
19
	<bean id="jobSubmittedDao" class="gr.uoa.di.validator.dao.JobSubmittedDAOImpl">
19
	<bean id="jobSubmittedDao" class="gr.uoa.di.validator.dao.jobs.JobSubmittedDAOImpl">
20 20
		<property name="datasource" ref="validator.dataSource" />
21 21
	</bean>
22 22
	
23
	<bean id="repositoryStoredDao" class="gr.uoa.di.validator.dao.RepositoryStoredDAOImpl">
23
	<bean id="repositoryStoredDao" class="gr.uoa.di.validator.dao.repositories.RepositoryStoredDAOImpl">
24 24
		<property name="datasource" ref="validator.dataSource" />
25 25
	</bean>
26 26

  
27
	<bean id="ruleSetDao" class="gr.uoa.di.validator.dao.RuleSetDAOimpl">
27
	<bean id="ruleSetDao" class="gr.uoa.di.validator.dao.rules.RuleSetDAOimpl">
28 28
		<property name="datasource" ref="validator.dataSource" />
29 29
	</bean>	
30 30

  
31
	<bean id="ruleStoredDao" class="gr.uoa.di.validator.dao.RuleStoredDAOimpl">
31
	<bean id="ruleStoredDao" class="gr.uoa.di.validator.dao.rules.RuleStoredDAOimpl">
32 32
		<property name="datasource" ref="validator.dataSource" />
33 33
	</bean>		
34 34
	
35
	<bean id="taskStoredDao" class="gr.uoa.di.validator.dao.TaskStoredDAOimpl">
35
	<bean id="taskStoredDao" class="gr.uoa.di.validator.dao.tasks.TaskStoredDAOimpl">
36 36
		<property name="datasource" ref="validator.dataSource" />
37 37
	</bean>		
38 38
	
39
	<bean id="userStoredDao" class="gr.uoa.di.validator.dao.UserStoredDAOimpl">
39
	<bean id="userStoredDao" class="gr.uoa.di.validator.dao.users.UserStoredDAOimpl">
40 40
		<property name="datasource" ref="validator.dataSource" />
41 41
	</bean>				
42 42
	
modules/uoa-validator-commons/trunk/src/main/resources/gr/uoa/di/validator/email/springContext-validator-emailer.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<beans xmlns="http://www.springframework.org/schema/beans"
3
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
	xmlns:context="http://www.springframework.org/schema/context"
5
	xmlns:cxf="http://cxf.apache.org/core"
6
	xmlns:jaxws="http://cxf.apache.org/jaxws"
7
	xmlns:p="http://http://www.springframework.org/schema/p"
8
	xmlns:template="http://dnetlib.eu/springbeans/template"
9
	xmlns:t="http://dnetlib.eu/springbeans/t"
10
	xmlns:tx="http://www.springframework.org/schema/tx"
11
	
12
	xsi:schemaLocation="
13
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
14
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
15
        http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
16
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
17
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
18
        http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd"
19
	default-autowire="no">
20
			
21
	<bean id="emailer" class="gr.uoa.di.validator.email.Emailer">
22
		<property name="override" value="${services.validator.mail.override}" />
23
		<property name="overrideEmail" value="${services.validator.mail.overrideEmail}" />
24
		<property name="logonly" value="${services.validator.mail.logonly}" />
25
		<property name="specialRecipients" value="${services.validator.mail.specialRecipients}" />
26
		<property name="from" value="${services.validator.mail.fromAddress}" />
27
		<property name="mailer" ref="maillib" />
28
	</bean>
29
	
30
	<bean id="maillib" class="eu.dnetlib.utils.MailLibrary" init-method="init">
31
		<property name="mailhost" value="${services.validator.mail.host}" />
32
		<property name="smtpPort" value="${services.validator.mail.port}" />
33
		<property name="authenticate" value="${services.validator.mail.authenticate}" />
34
		<property name="username" value="${services.validator.mail.username}" />
35
		<property name="password" value="${services.validator.mail.password}" />
36
		<property name="from" value="${services.validator.mail.fromAddress}" />
37
		<property name="replyTo" value="${services.validator.mail.replyToAddress}" />
38
		<property name="mode" value="${services.validator.mail.mode}" />
39
		<property name="debug" value="${services.validator.mail.debug}" />
40
	</bean>
41

  
42
</beans>
modules/uoa-validator-commons/trunk/pom.xml
15 15
	</scm>
16 16
	<dependencies>
17 17
		<dependency>
18
			<groupId>eu.dnetlib</groupId>
19
			<artifactId>uoa-utils</artifactId>
20
			<version>[1.0.0]</version>
21
		</dependency>
22
		<dependency>
18 23
			<groupId>log4j</groupId>
19 24
			<artifactId>log4j</artifactId>
20 25
			<version>[1.2.14,1.3.0)</version>
......
40 45
			<artifactId>postgresql</artifactId>
41 46
			<version>9.1-901.jdbc4</version>
42 47
		</dependency>
48
		<dependency>
49
			<groupId>javax.mail</groupId>
50
			<artifactId>mail</artifactId>
51
			<version>1.4.7</version>
52
			<exclusions>
53
				<exclusion>
54
					<groupId>javax.activation</groupId>
55
					<artifactId>activation</artifactId>
56
				</exclusion>
57
			</exclusions>
58
		</dependency>
59
		
43 60
	</dependencies>
44 61
</project>

Also available in: Unified diff