1 package ecar.email;
2
3
4 import java.io.IOException;
5 import java.util.ArrayList;
6 import java.util.Iterator;
7 import java.util.List;
8
9 import javax.servlet.Filter;
10 import javax.servlet.FilterChain;
11 import javax.servlet.FilterConfig;
12 import javax.servlet.ServletException;
13 import javax.servlet.ServletRequest;
14 import javax.servlet.ServletResponse;
15 import javax.servlet.http.HttpServletRequest;
16
17 import comum.util.Data;
18
19 import ecar.dao.ConfiguracaoDao;
20 import ecar.dao.UsuarioDao;
21 import ecar.pojo.ConfiguracaoCfg;
22 import ecar.pojo.UsuarioUsu;
23
24
25
26
27
28
29
30 public class AtualizadorEmail implements Filter {
31
32
33
34
35
36
37
38
39
40 public AtualizadorEmail() {
41 super();
42 }
43
44
45
46
47
48
49
50
51
52
53
54
55
56 public void init(FilterConfig arg0) throws ServletException {
57 }
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
75 try {
76 chain.doFilter(request, response);
77
78 HttpServletRequest httpRequest = (HttpServletRequest) request;
79 ConfiguracaoDao configDao = new ConfiguracaoDao(httpRequest);
80 ConfiguracaoCfg configuracao = configDao.getConfiguracao();
81 if (Data.getDataAtual().after(Data.addDias(configuracao.getIntervaloAtualizacaoEmail().intValue() ,configuracao.getUltimaAtualizacaoEmail())))
82 {
83 UsuarioDao usuDao = new UsuarioDao((HttpServletRequest)request);
84 UsuarioUsu usuario = null;
85 Iterator listaIds = usuDao.getListaIdDominio().iterator();
86 List listaUsu = new ArrayList();
87 while (listaIds.hasNext())
88 {
89 String idAtual = (String) listaIds.next();
90 usuario = usuDao.getUsuarioByIdDominio(idAtual);
91 if ((!"".equals(usuario.getEmail1UsuSent())) || (!(UsuarioDao.INFORMACAO_NAO_LOCALIZADA_SENTINELA).equals(usuario.getNomeUsu())))
92 {
93 usuario.setEmail1Usu(usuario.getEmail1UsuSent());
94 usuario.setNomeUsu(usuario.getNomeUsuSent());
95 listaUsu.add(usuario);
96 }
97 }
98 if (listaUsu.size() > 0)
99 usuDao.salvarOuAlterar(listaUsu);
100
101
102 String fullUrl;
103 fullUrl = httpRequest.getScheme() + "://" + httpRequest.getServerName();
104 if (httpRequest.getServerPort() != 80) {
105 fullUrl += ":" + httpRequest.getServerPort();
106 }
107 fullUrl += httpRequest.getContextPath();
108
109
110 configuracao.setContextPath(fullUrl);
111 configuracao.setUltimaAtualizacaoEmail(Data.getDataAtual());
112 configDao.salvarOuAlterar(configuracao);
113 }
114 } catch (Exception e) {
115 org.apache.log4j.Logger.getLogger(this.getClass()).error(e);
116 }
117 }
118
119
120
121
122
123
124
125
126
127
128
129 public void destroy() {
130 }
131
132 }