1 | /** |
---|
2 | * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. |
---|
3 | * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior |
---|
4 | * |
---|
5 | * This program is free software: you can redistribute it and/or modify |
---|
6 | * it under the terms of the GNU Affero General Public License as |
---|
7 | * published by the Free Software Foundation, either version 3 of the |
---|
8 | * License, or (at your option) any later version. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | * GNU Affero General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU Affero General Public License |
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | */ |
---|
18 | |
---|
19 | /******************************************************************************\ |
---|
20 | * |
---|
21 | * This product was developed by |
---|
22 | * |
---|
23 | * SERVIÃO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), |
---|
24 | * |
---|
25 | * a government company established under Brazilian law (5.615/70), |
---|
26 | * at Department of Development of Porto Alegre. |
---|
27 | * |
---|
28 | \******************************************************************************/ |
---|
29 | |
---|
30 | package serpro.mailarchiver.util.bshcommands; |
---|
31 | |
---|
32 | import java.nio.file.Files; |
---|
33 | import java.nio.file.Path; |
---|
34 | import java.sql.SQLException; |
---|
35 | import java.text.DecimalFormat; |
---|
36 | import java.text.SimpleDateFormat; |
---|
37 | import java.util.ArrayList; |
---|
38 | import java.util.Date; |
---|
39 | import java.util.HashMap; |
---|
40 | import java.util.HashSet; |
---|
41 | import java.util.Iterator; |
---|
42 | import java.util.LinkedList; |
---|
43 | import java.util.List; |
---|
44 | import java.util.Map; |
---|
45 | import java.util.Set; |
---|
46 | |
---|
47 | import bsh.CallStack; |
---|
48 | import bsh.Interpreter; |
---|
49 | |
---|
50 | import org.springframework.beans.factory.annotation.Autowired; |
---|
51 | import org.springframework.beans.factory.annotation.Configurable; |
---|
52 | |
---|
53 | import com.vaadin.data.Property; |
---|
54 | import com.vaadin.data.Property.ValueChangeEvent; |
---|
55 | import com.vaadin.ui.Button; |
---|
56 | import com.vaadin.ui.Button.ClickEvent; |
---|
57 | import com.vaadin.ui.CheckBox; |
---|
58 | import com.vaadin.ui.HorizontalLayout; |
---|
59 | import com.vaadin.ui.Label; |
---|
60 | import com.vaadin.ui.OptionGroup; |
---|
61 | import com.vaadin.ui.Panel; |
---|
62 | import com.vaadin.ui.PasswordField; |
---|
63 | import com.vaadin.ui.ProgressIndicator; |
---|
64 | import com.vaadin.ui.TextField; |
---|
65 | import com.vaadin.ui.VerticalLayout; |
---|
66 | import com.vaadin.ui.Window; |
---|
67 | |
---|
68 | import com.vaadin.ui.Window.Notification; |
---|
69 | import serpro.mailarchiver.service.Settings; |
---|
70 | import serpro.mailarchiver.service.dto.TFolder; |
---|
71 | import serpro.mailarchiver.service.dto.TMessage; |
---|
72 | import serpro.mailarchiver.service.web.ArchiveServices; |
---|
73 | import serpro.mailarchiver.service.web.ServiceFault; |
---|
74 | import serpro.mailarchiver.util.Browser; |
---|
75 | import serpro.mailarchiver.util.GearsUtil; |
---|
76 | import serpro.mailarchiver.util.Logger; |
---|
77 | import serpro.mailarchiver.util.Sqlite; |
---|
78 | import serpro.mailarchiver.util.SystemAccount; |
---|
79 | import serpro.mailarchiver.util.SystemAuthenticator; |
---|
80 | import serpro.mailarchiver.view.admin.AdminConsoleApp; |
---|
81 | |
---|
82 | @Configurable |
---|
83 | public class importGears { |
---|
84 | |
---|
85 | private static final Logger log = Logger.getLocalLogger(); |
---|
86 | |
---|
87 | @Autowired private SystemAuthenticator sysAuth; |
---|
88 | @Autowired private Settings settings; |
---|
89 | @Autowired private ArchiveServices archiveServices; |
---|
90 | |
---|
91 | private Window window = new Window("MailArchiver ImportGears"); |
---|
92 | private GearsArchive gearsArchive = null; |
---|
93 | private LoginPanel loginPanel; |
---|
94 | private PanelWindow1 panel1; |
---|
95 | private PanelWindow2 panel2; |
---|
96 | private PanelWindow3 panel3; |
---|
97 | private PanelWindow4 panel4; |
---|
98 | private PanelWindow5 panel5; |
---|
99 | private PanelWindow6 panel6; |
---|
100 | private PanelWindow7 panel7; |
---|
101 | private ThreadSearch search; |
---|
102 | private ThreadValidateWindow validate; |
---|
103 | private ThreadArchiverWindow archiverWindow; |
---|
104 | private ThreadArchiverProcess archiverProcess; |
---|
105 | private ThreadValidateProcess archiverValidateProcess; |
---|
106 | private boolean reImporter = false; |
---|
107 | |
---|
108 | public static void invoke(final Interpreter interpreter, final CallStack callstack) { |
---|
109 | |
---|
110 | // System.out.println("importGears.invoke sendo executado... "); |
---|
111 | log.debug("importGears.invoke sendo executado... "); |
---|
112 | |
---|
113 | new importGears().init(); |
---|
114 | } |
---|
115 | |
---|
116 | private void init() { |
---|
117 | |
---|
118 | gearsArchive = new GearsArchive(); |
---|
119 | |
---|
120 | //apenas para inicializar a tela principal |
---|
121 | panel1 = new PanelWindow1(); |
---|
122 | |
---|
123 | |
---|
124 | window.setHeight("300px"); |
---|
125 | window.setWidth("600px"); |
---|
126 | window.setPositionY(110); |
---|
127 | |
---|
128 | final VerticalLayout layout = (VerticalLayout) window.getContent(); |
---|
129 | |
---|
130 | //painel que representa a tela inicial do aplicativo |
---|
131 | layout.addComponent(panel1.getPanel()); |
---|
132 | |
---|
133 | AdminConsoleApp.getInstance().getMainWindow().addWindow(window); |
---|
134 | } |
---|
135 | |
---|
136 | //classe para manipulação de arquivamentos do google gears |
---|
137 | public class GearsArchive { |
---|
138 | |
---|
139 | private String userId = null; |
---|
140 | private String sessionId = null; |
---|
141 | private boolean inProcess = true; |
---|
142 | private boolean validate = true; |
---|
143 | private String currentInportMessageSubject = new String(); |
---|
144 | private Integer currentValidInportMessageNumber = 0; |
---|
145 | private Integer totalMessages = 0; |
---|
146 | private Integer totalValidMessages = 0; |
---|
147 | private Integer totalFailMessages = 1; |
---|
148 | private Double percentProgress = new Double("00.00"); |
---|
149 | private List<String> listGearsBrowserArchives = new ArrayList<String>(); |
---|
150 | private Map<String, List<String>> validDatabasePaths = new HashMap<String, List<String>>(); |
---|
151 | private Set<String> listSelectedGearsBrowserArchives = new HashSet(); |
---|
152 | private String mailArchiveId = null; |
---|
153 | private SystemAccount account = null; |
---|
154 | |
---|
155 | public List<String> getListGearsBrowserArchives() { |
---|
156 | return listGearsBrowserArchives; |
---|
157 | } |
---|
158 | |
---|
159 | public void setListGearsBrowserArchives(List<String> listGearsBrowserArchives) { |
---|
160 | this.listGearsBrowserArchives = listGearsBrowserArchives; |
---|
161 | } |
---|
162 | |
---|
163 | public Set<String> getListSelectedGearsBrowserArchives() { |
---|
164 | return listSelectedGearsBrowserArchives; |
---|
165 | } |
---|
166 | |
---|
167 | public void setListSelectedGearsBrowserArchives(Set<String> listSelectedGearsBrowserArchives) { |
---|
168 | this.listSelectedGearsBrowserArchives = listSelectedGearsBrowserArchives; |
---|
169 | } |
---|
170 | |
---|
171 | public Map<String, List<String>> getValidDatabasePaths() { |
---|
172 | return validDatabasePaths; |
---|
173 | } |
---|
174 | |
---|
175 | public void setValidDatabasePaths(Map<String, List<String>> validDatabasePaths) { |
---|
176 | this.validDatabasePaths = validDatabasePaths; |
---|
177 | } |
---|
178 | |
---|
179 | public GearsArchive() { |
---|
180 | |
---|
181 | //id do destino de importação |
---|
182 | mailArchiveId = settings.get("dbid"); |
---|
183 | |
---|
184 | //carrega o sessionId |
---|
185 | sessionId = AdminConsoleApp.getInstance().getSession().getSessionId(); |
---|
186 | |
---|
187 | //carrega user logado ao mailarchiver |
---|
188 | userId = AdminConsoleApp.getInstance().getSession().getUserId().substring(0, 9); |
---|
189 | } |
---|
190 | |
---|
191 | |
---|
192 | private boolean authenticateUserOs(String userOs, String passwdOs, String domain){ |
---|
193 | |
---|
194 | account = sysAuth.authenticate(userOs, passwdOs); |
---|
195 | |
---|
196 | if(account != null) { |
---|
197 | return true; |
---|
198 | } |
---|
199 | return false; |
---|
200 | } |
---|
201 | |
---|
202 | private void configureGearsPaths() { |
---|
203 | |
---|
204 | //listagem dos arquivamentos válidos encontrados |
---|
205 | // System.out.println("importGears.configureGearsPaths sendo executado... "); |
---|
206 | |
---|
207 | log.debug("importGears.configureGearsPaths sendo executado... "); |
---|
208 | |
---|
209 | //armazena os arquivamentos descobertos localmente por browser |
---|
210 | List<String> browserArchivePaths = new ArrayList<String>(); |
---|
211 | |
---|
212 | try{ |
---|
213 | Path chromeGearsPath = account.getGearsPath(Browser.Chrome); |
---|
214 | if((chromeGearsPath != null) && (Files.isReadable(chromeGearsPath))) { |
---|
215 | browserArchivePaths.add(chromeGearsPath.toString()); |
---|
216 | } |
---|
217 | else { |
---|
218 | // log.warn("O diretório padrão do Google Gears para o navegador Chrome não existe ou o MailArchive não tem permissões sobre a localização do mesmo."); |
---|
219 | } |
---|
220 | |
---|
221 | Path firefoxGearsPath = account.getGearsPath(Browser.Firefox); |
---|
222 | if((firefoxGearsPath != null) && (Files.isReadable(firefoxGearsPath))) { |
---|
223 | browserArchivePaths.add(firefoxGearsPath.toString()); |
---|
224 | } |
---|
225 | else { |
---|
226 | log.warn("O diretório padrão do Google Gears para o navegador Firefox não existe ou o MailArchive não tem permissões sobre a localização do mesmo."); |
---|
227 | } |
---|
228 | |
---|
229 | Path internetExplorerGearsPath = account.getGearsPath(Browser.InternetExplorer); |
---|
230 | if((internetExplorerGearsPath != null) && (Files.isReadable(internetExplorerGearsPath))) { |
---|
231 | browserArchivePaths.add(internetExplorerGearsPath.toString()); |
---|
232 | } |
---|
233 | else { |
---|
234 | log.warn("O diretório padrão do Google Gears para o navegador Internet Explorer não existe ou o MailArchive não tem permissões sobre a localização do mesmo."); |
---|
235 | } |
---|
236 | } |
---|
237 | catch (Exception e) { |
---|
238 | log.error("Falha na identificação do perfil do usuário junto ao navegador: diretório de dados do Gears não localizado para as credencias de sistema informados!"); |
---|
239 | } |
---|
240 | finally{ |
---|
241 | for(String pathStr : browserArchivePaths) { |
---|
242 | validateDatabasePaths(pathStr); |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | log.debug("importGears.configureGearsPaths sendo finalizado... "); |
---|
247 | } |
---|
248 | |
---|
249 | // valida as estruturas de arquivamento por browser a adiciona aos validDatabasePaths |
---|
250 | // valida a permissão de acesso do usuário logado ao expresso |
---|
251 | private void validateDatabasePaths(String browserArchivePath) { |
---|
252 | List<String> databaseFilePaths = new ArrayList<String>(); |
---|
253 | |
---|
254 | Sqlite.getInstance().setBrowserArchiverPath(browserArchivePath); |
---|
255 | |
---|
256 | Iterator databasePaths = Sqlite.getInstance().listDatabasePaths().values().iterator(); |
---|
257 | |
---|
258 | while(databasePaths.hasNext()) { |
---|
259 | List<String> databasePathValues = (List<String>) databasePaths.next(); |
---|
260 | |
---|
261 | for(String databasePath : databasePathValues) { |
---|
262 | if(databasePath != null && !databasePath.isEmpty()) { |
---|
263 | // testa a permissão de usuário |
---|
264 | if(Sqlite.getInstance().isExpressoDatabase(databasePath) |
---|
265 | && Sqlite.getInstance().isUserDatabase(databasePath, userId)) { |
---|
266 | databaseFilePaths.add(databasePath); |
---|
267 | //para listagem da tela |
---|
268 | listGearsBrowserArchives.add(browserArchivePath); |
---|
269 | } |
---|
270 | } |
---|
271 | } |
---|
272 | } |
---|
273 | //armazena os database válidos por raiz de arquivamento gears |
---|
274 | validDatabasePaths.put(browserArchivePath, databaseFilePaths); |
---|
275 | } |
---|
276 | |
---|
277 | // contabiliza o número total de emails passÃveis de importação pelo MailArchiver |
---|
278 | // a contagem será efetuada após a seleção de arquivamentos pelo usr |
---|
279 | public void setTotalMessages() { |
---|
280 | |
---|
281 | totalMessages = 0; |
---|
282 | |
---|
283 | Iterator validPaths = validDatabasePaths.keySet().iterator(); |
---|
284 | |
---|
285 | while(validPaths.hasNext()) { |
---|
286 | String browserArchivePath = validPaths.next().toString(); |
---|
287 | |
---|
288 | if(listSelectedGearsBrowserArchives.contains(browserArchivePath)) { |
---|
289 | List<String> databaseFilePaths = validDatabasePaths.get(browserArchivePath); |
---|
290 | // contabiliza email para o databasePath corrente |
---|
291 | for(String databasePath : databaseFilePaths) { |
---|
292 | totalMessages += Sqlite.getInstance().getTotalMessages(databasePath, mailArchiveId, userId); |
---|
293 | |
---|
294 | // System.out.println("Número de mensagens encontradas..: " + totalMessages); |
---|
295 | |
---|
296 | log.debug("Número de mensagens encontradas..: " + totalMessages); |
---|
297 | } |
---|
298 | } |
---|
299 | } |
---|
300 | } |
---|
301 | |
---|
302 | // grava dados de msgs aptas a importação pelo mailarchiver na table archive_importer |
---|
303 | // o método ArchiveServices.archive utilizará as informações salvas nesta tabela |
---|
304 | private void preArchiveMessages() { |
---|
305 | // System.out.println("importGears.preArchiveMessages sendo executado... "); |
---|
306 | |
---|
307 | log.debug("importGears.preArchiveMessages sendo executado... "); |
---|
308 | |
---|
309 | Date startArchiverDate = new Date(); |
---|
310 | |
---|
311 | Integer currentMessageNumber = 0; |
---|
312 | |
---|
313 | System.out.println("PROCESSO DE ARQUIVAMENTO GEARS INICIANDO EM..: " |
---|
314 | + new SimpleDateFormat("dd-MMMM-yyyy HH:mm:ss").format(startArchiverDate)); |
---|
315 | |
---|
316 | System.out.println("USUÃRIO LOGADO..: " + userId); |
---|
317 | |
---|
318 | log.debug("PROCESSO DE ARQUIVAMENTO GEARS INICIANDO EM..: " |
---|
319 | + new SimpleDateFormat("dd-MMMM-yyyy HH:mm:ss").format(startArchiverDate)); |
---|
320 | log.debug("USUÃRIO LOGADO..: " + userId); |
---|
321 | |
---|
322 | //contabiliza o total de msgs a serem analisadas para posteior importação pelo MailArchiver |
---|
323 | setTotalMessages(); |
---|
324 | |
---|
325 | Iterator selectedArchivePaths = listSelectedGearsBrowserArchives.iterator(); |
---|
326 | |
---|
327 | while(selectedArchivePaths.hasNext() && validate) { |
---|
328 | String browserSelectedArchivePath = selectedArchivePaths.next().toString(); |
---|
329 | |
---|
330 | Sqlite.getInstance().setBrowserArchiverPath(browserSelectedArchivePath); |
---|
331 | |
---|
332 | if(validDatabasePaths.containsKey(browserSelectedArchivePath)) { |
---|
333 | Iterator databasePaths = validDatabasePaths.get(browserSelectedArchivePath).iterator(); |
---|
334 | |
---|
335 | // começa o pré-arquivamento por databasePath |
---|
336 | while(databasePaths.hasNext() && validate) { |
---|
337 | |
---|
338 | String databasePath = databasePaths.next().toString(); |
---|
339 | |
---|
340 | if(reImporter) { |
---|
341 | //atualiza tabela de controle para possibilitar re-importação do databasePath corrente |
---|
342 | // System.out.println("Atualizando tabela de controle para re-importação."); |
---|
343 | try { |
---|
344 | Sqlite.getInstance().deleteMessageParameters(databasePath, mailArchiveId, userId); |
---|
345 | |
---|
346 | //re-contabiliza as msgs a serem analisadas |
---|
347 | setTotalMessages(); |
---|
348 | |
---|
349 | } |
---|
350 | catch(SQLException ex) { |
---|
351 | log.error("Falha no processo de deleção de parâmetros de mensagens referente ao MailArChiveId..: " |
---|
352 | + mailArchiveId, null, ex); |
---|
353 | } |
---|
354 | } |
---|
355 | // carrega listagem de folders |
---|
356 | Iterator folders = Sqlite.getInstance().listFolders(databasePath, userId).iterator(); |
---|
357 | |
---|
358 | while(folders.hasNext() && validate) { |
---|
359 | String folder = (String) folders.next(); |
---|
360 | |
---|
361 | // carrega as mensagens que ainda não foram importadas - teste pelo mailArchiveId |
---|
362 | // a chave é o mail id e o value eh um map com subject de chave e mail serializado como value |
---|
363 | Map<String, Map<String, String>> messages = Sqlite.getInstance().listMessages(databasePath, folder, mailArchiveId, userId); |
---|
364 | |
---|
365 | // caso 1 - primeiro arquivamento |
---|
366 | // executa pre-archiver |
---|
367 | if(!messages.isEmpty()) { |
---|
368 | |
---|
369 | Iterator messagesIds = messages.keySet().iterator(); |
---|
370 | |
---|
371 | while(messagesIds.hasNext() && validate) { |
---|
372 | String messageId = messagesIds.next().toString(); |
---|
373 | |
---|
374 | currentMessageNumber++; //contador de mensagens passÃveis de importação |
---|
375 | |
---|
376 | Map<String, String> messageValues = messages.get(messageId); |
---|
377 | |
---|
378 | Iterator messageValuesIterator = messageValues.keySet().iterator(); |
---|
379 | |
---|
380 | while(messageValuesIterator.hasNext()) { |
---|
381 | |
---|
382 | // parametro carregado apenas para identificação de mensagem não importada na log |
---|
383 | String messageSubject = messageValuesIterator.next().toString(); |
---|
384 | |
---|
385 | String urlExportFile = GearsUtil.unserializeUrlEntries(messageValues.get(messageSubject).toString()); |
---|
386 | |
---|
387 | String urlFilePath = null; |
---|
388 | try { |
---|
389 | |
---|
390 | urlFilePath = Sqlite.getInstance().getResponseBodiesFilePath(urlExportFile); |
---|
391 | |
---|
392 | } |
---|
393 | catch(SQLException ex) { |
---|
394 | // grava ocorrência de mensagem com erro no log de usuário |
---|
395 | GearsUtil.writeInUserLogFile("FolderName..: " + folder + " Message Subject..: " + messageSubject, totalFailMessages++); |
---|
396 | |
---|
397 | log.error("FolderName..: " + folder); |
---|
398 | |
---|
399 | log.error("Message subject.: " + messageSubject); |
---|
400 | |
---|
401 | log.error("Não foram encontradas ocorrências de filePath para a url " + urlExportFile |
---|
402 | + " na table localserver.entries", ex); |
---|
403 | } |
---|
404 | |
---|
405 | if(urlFilePath != null) { |
---|
406 | |
---|
407 | // System.out.println("UrlFilePath..: " + urlFilePath); |
---|
408 | |
---|
409 | log.debug("UrlFilePath..: " + urlFilePath); |
---|
410 | |
---|
411 | String messageFilePath = GearsUtil.loadFilePaths(browserSelectedArchivePath, urlFilePath); |
---|
412 | |
---|
413 | // System.out.println("MessageFilePath..: " + messageFilePath); |
---|
414 | |
---|
415 | log.debug("MessageFilePath..: " + messageFilePath); |
---|
416 | |
---|
417 | if(messageFilePath != null) { |
---|
418 | try { |
---|
419 | |
---|
420 | Sqlite.getInstance().insertMessageParameters(databasePath, folder, messageId, mailArchiveId, messageFilePath, userId); |
---|
421 | |
---|
422 | currentValidInportMessageNumber++; |
---|
423 | |
---|
424 | } |
---|
425 | catch(SQLException ex) { |
---|
426 | // grava ocorrência de mensagem com erro no log de usuário |
---|
427 | GearsUtil.writeInUserLogFile("FolderName..: " + folder + " Message Subject..: " + messageSubject, totalFailMessages++); |
---|
428 | |
---|
429 | log.error("FolderName..: " + folder); |
---|
430 | |
---|
431 | log.error("Message subject.: " + messageSubject); |
---|
432 | |
---|
433 | log.error("Falha na inserção do registro de controle referente a mensagem de mailId.: " + messageId, ex); |
---|
434 | } |
---|
435 | } |
---|
436 | else {//loga informações a respeito da mensagam não validada |
---|
437 | // grava ocorrência de mensagem com erro no log de usuário |
---|
438 | GearsUtil.writeInUserLogFile("FolderName..: " + folder + " Message Subject..: " + messageSubject, totalFailMessages++); |
---|
439 | |
---|
440 | log.error("FolderName..: " + folder); |
---|
441 | |
---|
442 | log.error("Message subject.: " + messageSubject); |
---|
443 | |
---|
444 | log.error("Não foi encontrado fonte para a mensagem: " + messageId + " e não inserida na estrututura de meta-arquivamento(h2)"); |
---|
445 | } |
---|
446 | } |
---|
447 | } |
---|
448 | // totalizar percentual de mensagens analisadas |
---|
449 | percentProgress = (currentMessageNumber.doubleValue() / totalMessages) * 100; |
---|
450 | } |
---|
451 | } |
---|
452 | } |
---|
453 | } |
---|
454 | } |
---|
455 | } |
---|
456 | validate = false; |
---|
457 | |
---|
458 | // System.out.println("importGears.preArchiveMessages sendo finalizado... "); |
---|
459 | |
---|
460 | log.debug("importGears.preArchiveMessages sendo finalizado... "); |
---|
461 | |
---|
462 | } |
---|
463 | |
---|
464 | // contabiliza o total de mensagens a serem importadas pelo mailarchiver para todos os arquivamentos encontrados |
---|
465 | // utiliza os registros já validados da tabela archive_importer |
---|
466 | private void setTotalValidMessages() { |
---|
467 | totalValidMessages = 0; |
---|
468 | |
---|
469 | Iterator database = validDatabasePaths.values().iterator(); |
---|
470 | |
---|
471 | while(database.hasNext()) { |
---|
472 | List<String> databasePaths = (List<String>) database.next(); |
---|
473 | |
---|
474 | for(String databasePath : databasePaths) { |
---|
475 | totalValidMessages += Sqlite.getInstance().getTotalValidMessages(databasePath, mailArchiveId, userId); |
---|
476 | } |
---|
477 | } |
---|
478 | |
---|
479 | // System.out.println("TOTAL DE MENSAGENS VÃLIDAS A SEREM IMPORTADAS PELO MAILARCHIVER..: " + totalValidMessages); |
---|
480 | |
---|
481 | log.debug("TOTAL DE MENSAGENS VÃLIDAS A SEREM IMPORTADAS PELO MAILARCHIVER..: " + totalValidMessages); |
---|
482 | |
---|
483 | } |
---|
484 | |
---|
485 | private void archiveMessages() { |
---|
486 | // System.out.println("importGears.archiveMessages sendo executado... "); |
---|
487 | |
---|
488 | log.debug("importGears.archiveMessages sendo executado... "); |
---|
489 | |
---|
490 | // carrega o numero total de mensagens validadas na fase de pré-arquivamento |
---|
491 | // o número diz respeito a todos databasePaths encontrados |
---|
492 | if(inProcess) { |
---|
493 | setTotalValidMessages(); |
---|
494 | } |
---|
495 | |
---|
496 | if(totalValidMessages > 0) { |
---|
497 | |
---|
498 | currentValidInportMessageNumber = 0; //re-inicializa contador |
---|
499 | |
---|
500 | Iterator browserArchivePaths = validDatabasePaths.keySet().iterator(); |
---|
501 | |
---|
502 | while(browserArchivePaths.hasNext() && inProcess) { |
---|
503 | Iterator databasePaths = validDatabasePaths.get(browserArchivePaths.next()).iterator(); |
---|
504 | |
---|
505 | while(databasePaths.hasNext() && inProcess) { |
---|
506 | String databasePath = databasePaths.next().toString(); |
---|
507 | |
---|
508 | // lê os dados de email aptos a importação da table archive_importer (imported=false) |
---|
509 | LinkedList<String[]> messageParameters = Sqlite.getInstance().listMessageParameters(databasePath, mailArchiveId, userId); |
---|
510 | |
---|
511 | Set<String> archivedFolders = new HashSet<String>(); |
---|
512 | |
---|
513 | Iterator parameters = messageParameters.iterator(); |
---|
514 | |
---|
515 | TFolder archiveFolder = null; |
---|
516 | |
---|
517 | while(parameters.hasNext() && inProcess) { |
---|
518 | String[] parameter = (String[]) parameters.next(); |
---|
519 | |
---|
520 | String folderName = parameter[0]; |
---|
521 | |
---|
522 | String mailId = parameter[1]; |
---|
523 | |
---|
524 | String messageFilePath = parameter[2]; |
---|
525 | |
---|
526 | String messageHeader = parameter[3]; |
---|
527 | |
---|
528 | String unseen = parameter[4]; |
---|
529 | |
---|
530 | try { |
---|
531 | // cria folder no meta-arquivamento a partir do parametro folder |
---|
532 | if(!archivedFolders.contains(folderName)) { |
---|
533 | archiveFolder = archiveServices.createAbsoluteFolder(sessionId, folderName); |
---|
534 | } |
---|
535 | } |
---|
536 | catch(ServiceFault ex) { |
---|
537 | log.error("Falha na criação do Folder " + folderName, ex); |
---|
538 | } |
---|
539 | |
---|
540 | if(archiveFolder != null) { |
---|
541 | //adiciona ao set de controle de folders arquivados no mailarchiver |
---|
542 | archivedFolders.add(archiveFolder.getName()); |
---|
543 | |
---|
544 | //ler os dados da mensagem do filesystem de usr a partir do parametro messagefilepath |
---|
545 | String messageContent = GearsUtil.getMessageRFC822(messageFilePath); |
---|
546 | |
---|
547 | if(messageContent != null && messageContent.length() > 0) { |
---|
548 | //cria mensagem no meta-arquivamento |
---|
549 | TMessage message = null; |
---|
550 | |
---|
551 | try { |
---|
552 | //TMessage archive(String sessionId, String folderId, String message) throws ServiceFault; |
---|
553 | message = archiveServices.archive(sessionId, archiveFolder.getId(), messageContent); |
---|
554 | } |
---|
555 | catch(ServiceFault ex) { |
---|
556 | // grava ocorrência de mensagem com erro no log de usuário |
---|
557 | GearsUtil.writeInUserLogFile("FolderName..: " + archiveFolder.getName() |
---|
558 | + " MessageFilePath..: " + messageFilePath, totalFailMessages++); |
---|
559 | |
---|
560 | log.error("FolderName..: " + folderName); |
---|
561 | |
---|
562 | log.error("MessageFilepath..: " + messageFilePath, ex); |
---|
563 | |
---|
564 | // log.error("Conteúdo da mensagem..: " + "\n" + messageContent, ex); |
---|
565 | } |
---|
566 | |
---|
567 | if(message != null && message.getSize() > 0) { |
---|
568 | try { |
---|
569 | // atualiza registro na tabela de controle a partir do parametro mailid |
---|
570 | Sqlite.getInstance().updateMessageParameters(databasePath, mailId, mailArchiveId, userId); |
---|
571 | try { |
---|
572 | //aplica as tags lidas da column mail.header |
---|
573 | String xmlQueryConfig = GearsUtil.writeQueryConfigHeaders(message.getId(), messageHeader, unseen); |
---|
574 | |
---|
575 | if(xmlQueryConfig != null) { |
---|
576 | archiveServices.tagMessages(sessionId, xmlQueryConfig); |
---|
577 | } |
---|
578 | } |
---|
579 | catch(ServiceFault ex) { |
---|
580 | log.error(ex); |
---|
581 | } |
---|
582 | |
---|
583 | currentInportMessageSubject = message.getSubject(); |
---|
584 | |
---|
585 | currentValidInportMessageNumber++; |
---|
586 | |
---|
587 | // System.out.println("Inserindo mensagem..: " + currentValidInportMessageNumber + " de" + totalValidMessages); |
---|
588 | |
---|
589 | } |
---|
590 | catch(SQLException ex) { |
---|
591 | // grava ocorrência de mensagem com erro no log de usuário |
---|
592 | GearsUtil.writeInUserLogFile("FolderName..: " + archiveFolder.getName() + " Message Subject..: " + message.getSubject(), totalFailMessages++); |
---|
593 | |
---|
594 | log.error("FolderName..: " + folderName); |
---|
595 | |
---|
596 | log.error("Message subject.: " + message.getSubject()); |
---|
597 | |
---|
598 | log.error("Falha na atualização da tabela archive_importer para o mailId..: " + mailId, ex); |
---|
599 | } |
---|
600 | |
---|
601 | } |
---|
602 | else { |
---|
603 | // grava ocorrência de mensagem com erro no log de usuário |
---|
604 | GearsUtil.writeInUserLogFile("FolderName..: " + archiveFolder.getName() |
---|
605 | + " MessageFilePath..: " + messageFilePath, totalFailMessages++); |
---|
606 | |
---|
607 | log.error("Falha na criação da mensagem ao invocar ArchiveServices.archive()!!"); |
---|
608 | |
---|
609 | log.error("FolderName..: " + folderName); |
---|
610 | |
---|
611 | log.error("MessageFilepath..: " + messageFilePath); |
---|
612 | } |
---|
613 | } |
---|
614 | } |
---|
615 | else { |
---|
616 | log.error("Folder não inserido na estrututura de meta-arquivamento(h2)..: " + folderName); |
---|
617 | } |
---|
618 | } |
---|
619 | } |
---|
620 | } |
---|
621 | inProcess = false; |
---|
622 | } |
---|
623 | |
---|
624 | Date finishArchiverDate = new Date(); |
---|
625 | |
---|
626 | System.out.println("PROCESSO DE ARQUIVAMENTO GEARS FINALIZADO EM..: " |
---|
627 | + new SimpleDateFormat("dd-MMMM-yyyy HH:mm:ss").format(finishArchiverDate)); |
---|
628 | |
---|
629 | log.debug("PROCESSO DE ARQUIVAMENTO GEARS FINALIZADO EM..: " |
---|
630 | + new SimpleDateFormat("dd-MMMM-yyyy HH:mm:ss").format(finishArchiverDate)); |
---|
631 | |
---|
632 | log.debug("Foram inseridas " + currentValidInportMessageNumber + " mensagens na estrututura de meta-arquivamento(h2)!"); |
---|
633 | |
---|
634 | // System.out.println("importGears.archiveMessages sendo finalizado... "); |
---|
635 | |
---|
636 | log.debug("importGears.archiveMessages sendo finalizado... "); |
---|
637 | } |
---|
638 | } |
---|
639 | |
---|
640 | // login - será chamado após painel1 de boas vindas |
---|
641 | public class LoginPanel extends VerticalLayout{ |
---|
642 | private final TextField username; |
---|
643 | |
---|
644 | private final TextField domain; |
---|
645 | |
---|
646 | private final PasswordField password; |
---|
647 | |
---|
648 | private Panel panel; |
---|
649 | |
---|
650 | public Panel getPanel() { |
---|
651 | return panel; |
---|
652 | } |
---|
653 | |
---|
654 | public LoginPanel(){ |
---|
655 | |
---|
656 | panel = new Panel("Painel de autenticação da aplicação! "); |
---|
657 | |
---|
658 | |
---|
659 | panel.addComponent(new Label("Informe os dados referentes a conta do sistema operacional.")); |
---|
660 | |
---|
661 | |
---|
662 | setSizeUndefined(); // let content 'push' size |
---|
663 | |
---|
664 | setSpacing(true); |
---|
665 | |
---|
666 | // Username |
---|
667 | username = new TextField("Nome do Usuário"); |
---|
668 | |
---|
669 | panel.addComponent(username); |
---|
670 | |
---|
671 | // Password |
---|
672 | password = new PasswordField("Senha"); |
---|
673 | |
---|
674 | panel.addComponent(password); |
---|
675 | |
---|
676 | // Domain |
---|
677 | domain = new TextField("DomÃnio"); |
---|
678 | |
---|
679 | // panel.addComponent(domain ); |
---|
680 | |
---|
681 | |
---|
682 | HorizontalLayout footer = new HorizontalLayout(); |
---|
683 | |
---|
684 | footer.setSpacing(true); |
---|
685 | |
---|
686 | footer.setMargin(true); |
---|
687 | |
---|
688 | // Login button |
---|
689 | Button loginButton = new Button("Validar", new Button.ClickListener() { |
---|
690 | // inline click listener |
---|
691 | public void buttonClick(ClickEvent event) { |
---|
692 | try{ |
---|
693 | if(gearsArchive.authenticateUserOs( |
---|
694 | username.getValue().toString(), |
---|
695 | password.getValue().toString(), |
---|
696 | domain.getValue().toString())){ |
---|
697 | |
---|
698 | panel.setVisible(false); |
---|
699 | |
---|
700 | panel2 = new PanelWindow2(); |
---|
701 | |
---|
702 | window.getContent().addComponent(panel2.getPanel()); |
---|
703 | |
---|
704 | panel2.getPanel().setVisible(true); |
---|
705 | |
---|
706 | search = new ThreadSearch(); |
---|
707 | |
---|
708 | search.setName("ARCHIVE-IMPORTGEARS-SEARCH-THREAD"); |
---|
709 | |
---|
710 | search.start(); |
---|
711 | |
---|
712 | panel2.getProgress().setEnabled(true); |
---|
713 | |
---|
714 | panel2.getProgress().setVisible(true); |
---|
715 | |
---|
716 | } else { // informa mensagem ao usuário |
---|
717 | panel.getApplication().getMainWindow(). |
---|
718 | showNotification("Validação local falhou, verifique os dados informados!", Notification.TYPE_ERROR_MESSAGE); |
---|
719 | } |
---|
720 | }catch(Exception e){ |
---|
721 | panel.getApplication().getMainWindow(). |
---|
722 | showNotification("Validação local falhou, verifique os dados informados!", Notification.TYPE_ERROR_MESSAGE); |
---|
723 | } |
---|
724 | } |
---|
725 | }); |
---|
726 | |
---|
727 | footer.addComponent(loginButton); |
---|
728 | |
---|
729 | Button exit = new Button("Sair"); |
---|
730 | |
---|
731 | exit.addListener(new Button.ClickListener() { |
---|
732 | |
---|
733 | @Override |
---|
734 | public void buttonClick(Button.ClickEvent event) { |
---|
735 | panel.getApplication().getMainWindow().removeWindow(window); |
---|
736 | } |
---|
737 | }); |
---|
738 | |
---|
739 | footer.addComponent(exit); |
---|
740 | |
---|
741 | panel.addComponent(footer); |
---|
742 | |
---|
743 | addComponent(panel); |
---|
744 | |
---|
745 | // setComponentAlignment(loginButton, Alignment.TOP_RIGHT); |
---|
746 | } |
---|
747 | } |
---|
748 | |
---|
749 | public class PanelWindow1 extends VerticalLayout { |
---|
750 | |
---|
751 | private Panel panel; |
---|
752 | |
---|
753 | public Panel getPanel() { |
---|
754 | return panel; |
---|
755 | } |
---|
756 | |
---|
757 | public PanelWindow1() { |
---|
758 | panel = new Panel("Painel de abertura da aplicação! "); |
---|
759 | |
---|
760 | setMargin(true); |
---|
761 | |
---|
762 | setSpacing(true); |
---|
763 | |
---|
764 | panel.addComponent(new Label("Assistente de importação Gears/MailArchiver.")); |
---|
765 | |
---|
766 | HorizontalLayout footer = new HorizontalLayout(); |
---|
767 | |
---|
768 | footer.setSpacing(true); |
---|
769 | |
---|
770 | footer.setMargin(true); |
---|
771 | |
---|
772 | Button next = new Button("Avançar"); |
---|
773 | |
---|
774 | next.setDescription("Iniciar processo de importação de emails"); |
---|
775 | |
---|
776 | Button exit = new Button("Sair"); |
---|
777 | |
---|
778 | next.addListener(new Button.ClickListener() { |
---|
779 | |
---|
780 | @Override |
---|
781 | public void buttonClick(Button.ClickEvent event) { |
---|
782 | panel.setVisible(false); |
---|
783 | |
---|
784 | loginPanel = new LoginPanel(); |
---|
785 | |
---|
786 | window.getContent().addComponent(loginPanel.getPanel()); |
---|
787 | |
---|
788 | loginPanel.getPanel().setVisible(true); |
---|
789 | |
---|
790 | } |
---|
791 | }); |
---|
792 | |
---|
793 | exit.addListener(new Button.ClickListener() { |
---|
794 | |
---|
795 | @Override |
---|
796 | public void buttonClick(Button.ClickEvent event) { |
---|
797 | panel.getApplication().getMainWindow().removeWindow(window); |
---|
798 | } |
---|
799 | }); |
---|
800 | |
---|
801 | footer.addComponent(next); |
---|
802 | |
---|
803 | footer.addComponent(exit); |
---|
804 | |
---|
805 | panel.addComponent(footer); |
---|
806 | |
---|
807 | addComponent(panel); |
---|
808 | } |
---|
809 | } |
---|
810 | |
---|
811 | public class PanelWindow2 extends VerticalLayout { |
---|
812 | |
---|
813 | private Panel panel; |
---|
814 | private ProgressIndicator progress; |
---|
815 | |
---|
816 | public Panel getPanel() { |
---|
817 | return panel; |
---|
818 | } |
---|
819 | |
---|
820 | public ProgressIndicator getProgress() { |
---|
821 | return progress; |
---|
822 | } |
---|
823 | |
---|
824 | public PanelWindow2() { |
---|
825 | panel = new Panel("Painel de pesquisa de arquivamentos! "); |
---|
826 | |
---|
827 | setMargin(true); |
---|
828 | |
---|
829 | setSpacing(true); |
---|
830 | |
---|
831 | panel.addComponent(new Label("Procurando arquivamentos válidos... ")); |
---|
832 | |
---|
833 | progress = new ProgressIndicator(); |
---|
834 | |
---|
835 | progress.setIndeterminate(true); |
---|
836 | |
---|
837 | progress.setPollingInterval(1000); |
---|
838 | |
---|
839 | progress.setEnabled(false); |
---|
840 | |
---|
841 | panel.addComponent(progress); |
---|
842 | |
---|
843 | Button cancel = new Button("Cancelar "); |
---|
844 | |
---|
845 | cancel.addListener(new Button.ClickListener() { |
---|
846 | |
---|
847 | @Override |
---|
848 | public void buttonClick(Button.ClickEvent event) { |
---|
849 | panel.getApplication().getMainWindow().removeWindow(window); |
---|
850 | } |
---|
851 | }); |
---|
852 | panel.addComponent(cancel); |
---|
853 | |
---|
854 | addComponent(panel); |
---|
855 | } |
---|
856 | } |
---|
857 | |
---|
858 | public class PanelWindow3 extends VerticalLayout { |
---|
859 | |
---|
860 | Panel panel; |
---|
861 | |
---|
862 | public Panel getPanel() { |
---|
863 | return panel; |
---|
864 | } |
---|
865 | |
---|
866 | public PanelWindow3() { |
---|
867 | panel = new Panel("Painel de listagem de arquivamentos válidos! "); |
---|
868 | |
---|
869 | setMargin(true); |
---|
870 | |
---|
871 | setSpacing(true); |
---|
872 | |
---|
873 | HorizontalLayout footer = new HorizontalLayout(); |
---|
874 | |
---|
875 | footer.setSpacing(true); |
---|
876 | |
---|
877 | footer.setMargin(true); |
---|
878 | |
---|
879 | OptionGroup gearsSelectPath = null; |
---|
880 | |
---|
881 | Button next = new Button("Avançar"); |
---|
882 | |
---|
883 | next.setDescription("Iniciar processo de importação de emails"); |
---|
884 | |
---|
885 | Button cancel = new Button("Cancelar"); |
---|
886 | |
---|
887 | cancel.addListener(new Button.ClickListener() { |
---|
888 | |
---|
889 | @Override |
---|
890 | public void buttonClick(Button.ClickEvent event) { |
---|
891 | // System.out.println("Aplicação encerrada pelo usuário!"); |
---|
892 | panel.getApplication().getMainWindow().removeWindow(window); |
---|
893 | log.error("Aplicação encerrada pelo usuário!"); |
---|
894 | } |
---|
895 | }); |
---|
896 | |
---|
897 | footer.addComponent(cancel); |
---|
898 | |
---|
899 | //carrega a listagem de arquivamentos default válidos encontrados |
---|
900 | gearsArchive.configureGearsPaths(); |
---|
901 | |
---|
902 | // só habilitará o OptionGroup e Next se existirem arquivamentos válidos |
---|
903 | if(!gearsArchive.getListGearsBrowserArchives().isEmpty()) { |
---|
904 | gearsSelectPath = new OptionGroup("Selecione os arquivamentos desejados.... ", |
---|
905 | gearsArchive.getListGearsBrowserArchives()); |
---|
906 | |
---|
907 | gearsSelectPath.setMultiSelect(true); |
---|
908 | |
---|
909 | gearsSelectPath.setImmediate(true); |
---|
910 | |
---|
911 | gearsSelectPath.addListener(new Property.ValueChangeListener() { |
---|
912 | |
---|
913 | @Override |
---|
914 | public void valueChange(ValueChangeEvent event) { |
---|
915 | gearsArchive.getListSelectedGearsBrowserArchives().addAll((Set) event.getProperty().getValue()); |
---|
916 | } |
---|
917 | }); |
---|
918 | panel.addComponent(gearsSelectPath); |
---|
919 | |
---|
920 | next.addListener(new Button.ClickListener() { |
---|
921 | |
---|
922 | @Override |
---|
923 | public void buttonClick(Button.ClickEvent event) { |
---|
924 | if(gearsArchive.getListSelectedGearsBrowserArchives().size() > 0) { |
---|
925 | |
---|
926 | panel.setVisible(false); |
---|
927 | |
---|
928 | panel4 = new PanelWindow4(); |
---|
929 | |
---|
930 | window.getContent().addComponent(panel4.getPanel()); |
---|
931 | |
---|
932 | panel4.getPanel().setVisible(true); |
---|
933 | } |
---|
934 | } |
---|
935 | }); |
---|
936 | |
---|
937 | footer.addComponent(next); |
---|
938 | |
---|
939 | } |
---|
940 | else { // informa mensagem ao usuário |
---|
941 | // panel.getApplication().getMainWindow().showNotification("Dados de login incorretos!", Notification.TYPE_ERROR_MESSAGE); |
---|
942 | panel.addComponent(new Label("Não foram encontradas mensagens a serem importadas!")); |
---|
943 | } |
---|
944 | |
---|
945 | panel.addComponent(footer); |
---|
946 | |
---|
947 | addComponent(panel); |
---|
948 | } |
---|
949 | } |
---|
950 | |
---|
951 | public class PanelWindow4 extends VerticalLayout { |
---|
952 | |
---|
953 | private Panel panel; |
---|
954 | |
---|
955 | public Panel getPanel() { |
---|
956 | return panel; |
---|
957 | } |
---|
958 | |
---|
959 | public PanelWindow4() { |
---|
960 | panel = new Panel("Painel de confirmação de importação de arquivamentos!"); |
---|
961 | |
---|
962 | setMargin(true); |
---|
963 | |
---|
964 | setSpacing(true); |
---|
965 | |
---|
966 | panel.addComponent(new Label("Arquivamentos a serem importados..: ")); |
---|
967 | |
---|
968 | // System.out.println("Número de arquivamentos selecionados(Raiz)..: " + gearsArchive.getListSelectedGearsBrowserArchives().size()); |
---|
969 | |
---|
970 | if(gearsArchive.getListSelectedGearsBrowserArchives().size() > 0) { |
---|
971 | Iterator paths = gearsArchive.getListSelectedGearsBrowserArchives().iterator(); |
---|
972 | |
---|
973 | while(paths.hasNext()) { |
---|
974 | String path = paths.next().toString(); |
---|
975 | |
---|
976 | if(path.contains(Browser.Chrome.name().toLowerCase())) { |
---|
977 | panel.addComponent(new Label("Google Chrome")); |
---|
978 | } |
---|
979 | |
---|
980 | if(path.contains(Browser.InternetExplorer.name().toLowerCase())) { |
---|
981 | panel.addComponent(new Label("Internet Explorer")); |
---|
982 | } |
---|
983 | |
---|
984 | if(path.contains(Browser.Firefox.name().toLowerCase())) { |
---|
985 | panel.addComponent(new Label("Mozilla Firefox")); |
---|
986 | } |
---|
987 | } |
---|
988 | } |
---|
989 | |
---|
990 | CheckBox reImport = new CheckBox("Re-importação de emails.."); |
---|
991 | |
---|
992 | reImport.setValue(false); |
---|
993 | |
---|
994 | reImport.setDescription("Re-importação de mails...."); |
---|
995 | |
---|
996 | reImport.addListener(new Button.ClickListener() { |
---|
997 | |
---|
998 | @Override |
---|
999 | public void buttonClick(Button.ClickEvent event) { |
---|
1000 | reImporter = event.getButton().booleanValue(); |
---|
1001 | } |
---|
1002 | }); |
---|
1003 | |
---|
1004 | reImport.setImmediate(true); |
---|
1005 | |
---|
1006 | panel.addComponent(reImport); |
---|
1007 | |
---|
1008 | HorizontalLayout footer = new HorizontalLayout(); |
---|
1009 | |
---|
1010 | footer.setSpacing(true); |
---|
1011 | |
---|
1012 | footer.setMargin(true); |
---|
1013 | |
---|
1014 | Button next = new Button("Avançar"); |
---|
1015 | |
---|
1016 | next.setDescription("Arquivar mensagens."); |
---|
1017 | |
---|
1018 | next.addListener(new Button.ClickListener() { |
---|
1019 | |
---|
1020 | @Override |
---|
1021 | public void buttonClick(Button.ClickEvent event) { |
---|
1022 | panel.setVisible(false); |
---|
1023 | |
---|
1024 | panel5 = new PanelWindow5(); |
---|
1025 | |
---|
1026 | window.getContent().addComponent(panel5.getPanel()); |
---|
1027 | |
---|
1028 | panel5.getPanel().setVisible(true); |
---|
1029 | |
---|
1030 | validate = new ThreadValidateWindow(); |
---|
1031 | |
---|
1032 | validate.setName("ARCHIVE-IMPORTGEARS-VALIDATE-WINDOW-THREAD"); |
---|
1033 | |
---|
1034 | validate.start(); |
---|
1035 | |
---|
1036 | archiverValidateProcess = new ThreadValidateProcess(); |
---|
1037 | |
---|
1038 | archiverValidateProcess.setName("ARCHIVE-IMPORTGEARS-VALIDATE-THREAD"); |
---|
1039 | |
---|
1040 | archiverValidateProcess.start(); |
---|
1041 | |
---|
1042 | panel5.getProgress().setEnabled(true); |
---|
1043 | |
---|
1044 | panel5.getProgress().setVisible(true); |
---|
1045 | } |
---|
1046 | }); |
---|
1047 | |
---|
1048 | Button cancel = new Button("Cancelar"); |
---|
1049 | |
---|
1050 | cancel.addListener(new Button.ClickListener() { |
---|
1051 | |
---|
1052 | @Override |
---|
1053 | public void buttonClick(Button.ClickEvent event) { |
---|
1054 | panel.getApplication().getMainWindow().removeWindow(window); |
---|
1055 | } |
---|
1056 | }); |
---|
1057 | |
---|
1058 | Button back = new Button("Voltar"); |
---|
1059 | |
---|
1060 | back.setDescription("Voltar para seleção de arquivamentos."); |
---|
1061 | |
---|
1062 | back.addListener(new Button.ClickListener() { |
---|
1063 | |
---|
1064 | @Override |
---|
1065 | public void buttonClick(Button.ClickEvent event) { |
---|
1066 | |
---|
1067 | panel.setVisible(false); |
---|
1068 | |
---|
1069 | window.getContent().addComponent(panel3.getPanel()); |
---|
1070 | |
---|
1071 | panel3.getPanel().setVisible(true); |
---|
1072 | } |
---|
1073 | }); |
---|
1074 | |
---|
1075 | footer.addComponent(cancel); |
---|
1076 | |
---|
1077 | footer.addComponent(next); |
---|
1078 | |
---|
1079 | footer.addComponent(back); |
---|
1080 | |
---|
1081 | panel.addComponent(footer); |
---|
1082 | |
---|
1083 | addComponent(panel); |
---|
1084 | } |
---|
1085 | } |
---|
1086 | |
---|
1087 | public class PanelWindow5 extends VerticalLayout { |
---|
1088 | |
---|
1089 | private Panel panel; |
---|
1090 | private ProgressIndicator progress; |
---|
1091 | private Label messageCounter = new Label(); |
---|
1092 | |
---|
1093 | public Panel getPanel() { |
---|
1094 | return panel; |
---|
1095 | } |
---|
1096 | |
---|
1097 | public ProgressIndicator getProgress() { |
---|
1098 | return progress; |
---|
1099 | } |
---|
1100 | |
---|
1101 | public Label getMessageCounter() { |
---|
1102 | return messageCounter; |
---|
1103 | } |
---|
1104 | |
---|
1105 | public PanelWindow5() { |
---|
1106 | panel = new Panel("Painel de validação de emails para arquivamento! "); |
---|
1107 | |
---|
1108 | setMargin(true); |
---|
1109 | |
---|
1110 | setSpacing(true); |
---|
1111 | |
---|
1112 | panel.addComponent(new Label("Aguarde! Analisando emails arquivados pelo Google Gears.")); |
---|
1113 | |
---|
1114 | panel.addComponent(new Label("Esta operação poderá levar vários minutos!")); |
---|
1115 | |
---|
1116 | progress = new ProgressIndicator(); |
---|
1117 | |
---|
1118 | progress.setIndeterminate(true); |
---|
1119 | |
---|
1120 | // progress.setPollingInterval(1); |
---|
1121 | |
---|
1122 | progress.setEnabled(false); |
---|
1123 | |
---|
1124 | panel.addComponent(progress); |
---|
1125 | |
---|
1126 | Button cancel = new Button("Cancelar "); |
---|
1127 | |
---|
1128 | cancel.addListener(new Button.ClickListener() { |
---|
1129 | |
---|
1130 | @Override |
---|
1131 | public void buttonClick(Button.ClickEvent event) { |
---|
1132 | gearsArchive.validate = false; |
---|
1133 | gearsArchive.inProcess = false; |
---|
1134 | panel.getApplication().getMainWindow().removeWindow(window); |
---|
1135 | } |
---|
1136 | }); |
---|
1137 | |
---|
1138 | panel.addComponent(messageCounter); // exibe um totalizador de mensagens validadas |
---|
1139 | |
---|
1140 | panel.addComponent(cancel); |
---|
1141 | |
---|
1142 | addComponent(panel); |
---|
1143 | } |
---|
1144 | } |
---|
1145 | |
---|
1146 | public class PanelWindow6 extends VerticalLayout { |
---|
1147 | |
---|
1148 | private Panel panel; |
---|
1149 | private ProgressIndicator progress; |
---|
1150 | private Label message = new Label(); |
---|
1151 | private Label messageCounter = new Label(); |
---|
1152 | |
---|
1153 | public Panel getPanel() { |
---|
1154 | return panel; |
---|
1155 | } |
---|
1156 | |
---|
1157 | public ProgressIndicator getProgress() { |
---|
1158 | return progress; |
---|
1159 | } |
---|
1160 | |
---|
1161 | public Label getMessage() { |
---|
1162 | return message; |
---|
1163 | } |
---|
1164 | |
---|
1165 | public Label getMessageCounter() { |
---|
1166 | return messageCounter; |
---|
1167 | } |
---|
1168 | |
---|
1169 | public PanelWindow6() { |
---|
1170 | panel = new Panel("Painel de andamento do processo de arquivamento! "); |
---|
1171 | |
---|
1172 | setMargin(true); |
---|
1173 | |
---|
1174 | setSpacing(true); |
---|
1175 | |
---|
1176 | panel.addComponent(new Label("Andamento do processo..: ")); |
---|
1177 | |
---|
1178 | progress = new ProgressIndicator(); |
---|
1179 | |
---|
1180 | progress.setIndeterminate(true); |
---|
1181 | |
---|
1182 | // progress.setPollingInterval(1);//atualiza a tela via ProgressIndicator |
---|
1183 | |
---|
1184 | progress.setEnabled(false); |
---|
1185 | |
---|
1186 | panel.addComponent(progress); |
---|
1187 | |
---|
1188 | Button cancel = new Button("Cancelar "); |
---|
1189 | |
---|
1190 | cancel.addListener(new Button.ClickListener() { |
---|
1191 | |
---|
1192 | @Override |
---|
1193 | public void buttonClick(Button.ClickEvent event) { |
---|
1194 | panel.setVisible(false); |
---|
1195 | |
---|
1196 | gearsArchive.inProcess = false;//termina arquivamento |
---|
1197 | |
---|
1198 | panel7 = new PanelWindow7(); |
---|
1199 | |
---|
1200 | window.getContent().addComponent(panel7.getPanel()); |
---|
1201 | |
---|
1202 | panel7.getPanel().setVisible(true); |
---|
1203 | } |
---|
1204 | }); |
---|
1205 | panel.addComponent(cancel); |
---|
1206 | |
---|
1207 | panel.addComponent(message); // exibe os filePaths das mensagens sendo importadas |
---|
1208 | |
---|
1209 | panel.addComponent(messageCounter); // exibe um totalizador de mensagens importadas |
---|
1210 | |
---|
1211 | addComponent(panel); |
---|
1212 | } |
---|
1213 | } |
---|
1214 | |
---|
1215 | public class PanelWindow7 extends VerticalLayout { |
---|
1216 | |
---|
1217 | private Panel panel; |
---|
1218 | |
---|
1219 | public Panel getPanel() { |
---|
1220 | return panel; |
---|
1221 | } |
---|
1222 | |
---|
1223 | public PanelWindow7() { |
---|
1224 | panel = new Panel("Painel de resumo do processo de importação! "); |
---|
1225 | |
---|
1226 | setMargin(true); |
---|
1227 | |
---|
1228 | setSpacing(true); |
---|
1229 | |
---|
1230 | panel.addComponent(new Label("Importação ConcluÃda!")); |
---|
1231 | |
---|
1232 | panel.addComponent(new Label("Mensagens Arquivadas..: " + gearsArchive.currentValidInportMessageNumber)); |
---|
1233 | |
---|
1234 | Button ok = new Button("ok"); |
---|
1235 | |
---|
1236 | ok.setDescription("Terminar o aplicativo!"); |
---|
1237 | |
---|
1238 | ok.addListener(new Button.ClickListener() { |
---|
1239 | |
---|
1240 | @Override |
---|
1241 | public void buttonClick(Button.ClickEvent event) { |
---|
1242 | panel.getApplication().getMainWindow().removeWindow(window); |
---|
1243 | } |
---|
1244 | }); |
---|
1245 | panel.addComponent(ok); |
---|
1246 | |
---|
1247 | addComponent(panel); |
---|
1248 | } |
---|
1249 | } |
---|
1250 | |
---|
1251 | public class ThreadSearch extends Thread { |
---|
1252 | |
---|
1253 | @Override |
---|
1254 | public void run() { |
---|
1255 | // System.out.println("ThreadSearch.run sendo executado... "); |
---|
1256 | try { |
---|
1257 | Thread.sleep(1000); |
---|
1258 | } |
---|
1259 | catch(InterruptedException e) { |
---|
1260 | log.error(e); |
---|
1261 | } |
---|
1262 | synchronized(window.getApplication()) { |
---|
1263 | panel2.getPanel().setVisible(false); |
---|
1264 | |
---|
1265 | panel3 = new PanelWindow3(); |
---|
1266 | |
---|
1267 | window.getContent().addComponent(panel3.getPanel()); |
---|
1268 | |
---|
1269 | panel3.getPanel().setVisible(true); |
---|
1270 | } |
---|
1271 | // System.out.println("ThreadSearch.run sendo finalizado... "); |
---|
1272 | } |
---|
1273 | } |
---|
1274 | |
---|
1275 | public class ThreadValidateWindow extends Thread { |
---|
1276 | |
---|
1277 | @Override |
---|
1278 | public void run() { |
---|
1279 | // System.out.println("ThreadValidateWindow.run sendo executado... "); |
---|
1280 | |
---|
1281 | boolean condition = true; |
---|
1282 | |
---|
1283 | DecimalFormat decimalFormat = new DecimalFormat("0.00"); |
---|
1284 | |
---|
1285 | while(condition) { |
---|
1286 | |
---|
1287 | synchronized(window.getApplication()) { |
---|
1288 | |
---|
1289 | panel5.getMessageCounter().setCaption(decimalFormat.format(gearsArchive.percentProgress) + "% Mensagens analisadas... "); |
---|
1290 | |
---|
1291 | log.debug(decimalFormat.format(gearsArchive.percentProgress) + "% Mensagens analisadas... "); |
---|
1292 | |
---|
1293 | // panel5.getMessageCounter().setEnabled(false); |
---|
1294 | |
---|
1295 | if(gearsArchive.totalMessages > 0) { |
---|
1296 | panel5.getMessageCounter().setVisible(true); |
---|
1297 | } |
---|
1298 | |
---|
1299 | if(!gearsArchive.validate) { |
---|
1300 | panel5.getPanel().setVisible(false); |
---|
1301 | |
---|
1302 | panel6 = new PanelWindow6(); |
---|
1303 | |
---|
1304 | window.getContent().addComponent(panel6.getPanel()); |
---|
1305 | |
---|
1306 | panel6.getPanel().setVisible(true); |
---|
1307 | |
---|
1308 | panel6.getProgress().setEnabled(true); |
---|
1309 | |
---|
1310 | panel6.getProgress().setVisible(true); |
---|
1311 | |
---|
1312 | condition = false; |
---|
1313 | } |
---|
1314 | } |
---|
1315 | } |
---|
1316 | // inicializa o processo de arquivamento no h2 |
---|
1317 | archiverWindow = new ThreadArchiverWindow(); |
---|
1318 | |
---|
1319 | archiverWindow.setName("ARCHIVE-IMPORTGEARS-WINDOW-THREAD"); |
---|
1320 | |
---|
1321 | archiverWindow.start(); |
---|
1322 | |
---|
1323 | archiverProcess = new ThreadArchiverProcess(); |
---|
1324 | |
---|
1325 | archiverProcess.setName("ARCHIVE-IMPORTGEARS-THREAD"); |
---|
1326 | |
---|
1327 | archiverProcess.start(); |
---|
1328 | |
---|
1329 | // System.out.println("ThreadValidateWindow.run sendo finalizado... "); |
---|
1330 | } |
---|
1331 | } |
---|
1332 | |
---|
1333 | // dispara o pré-arquivamento de mensagens |
---|
1334 | public class ThreadValidateProcess extends Thread { |
---|
1335 | |
---|
1336 | @Override |
---|
1337 | public void run() { |
---|
1338 | // System.out.println("ThreadArchiverValidateProcess.run sendo executado... "); |
---|
1339 | |
---|
1340 | //efetua a carga previa nos dados para posterior importação pelo mailarchiver |
---|
1341 | gearsArchive.preArchiveMessages(); |
---|
1342 | |
---|
1343 | // System.out.println("ThreadArchiverValidateProcess.run sendo finalizado... "); |
---|
1344 | } |
---|
1345 | } |
---|
1346 | |
---|
1347 | //controla as atualizações de tela enquanto o arquivamento é processado |
---|
1348 | public class ThreadArchiverWindow extends Thread { |
---|
1349 | |
---|
1350 | @Override |
---|
1351 | public void run() { |
---|
1352 | // System.out.println("ThreadArchiverWindow.run sendo executado... "); |
---|
1353 | |
---|
1354 | while(gearsArchive.inProcess) { |
---|
1355 | synchronized(window.getApplication()) { |
---|
1356 | panel6.getMessage().setCaption("Arquivando a mensagem..: " + gearsArchive.currentInportMessageSubject); |
---|
1357 | |
---|
1358 | panel6.getMessageCounter().setCaption(gearsArchive.currentValidInportMessageNumber + " de " + gearsArchive.totalValidMessages); |
---|
1359 | |
---|
1360 | panel6.getMessage().setEnabled(false); |
---|
1361 | |
---|
1362 | panel6.getMessageCounter().setEnabled(false); |
---|
1363 | |
---|
1364 | panel6.getMessage().setVisible(true); |
---|
1365 | |
---|
1366 | panel6.getMessageCounter().setVisible(true); |
---|
1367 | } |
---|
1368 | } |
---|
1369 | panel6.getPanel().setVisible(false); |
---|
1370 | |
---|
1371 | panel7 = new PanelWindow7(); |
---|
1372 | |
---|
1373 | window.getContent().addComponent(panel7.getPanel()); |
---|
1374 | |
---|
1375 | panel7.getPanel().setVisible(true); |
---|
1376 | |
---|
1377 | // System.out.println("ThreadArchiverWindow.run sendo finalizado... "); |
---|
1378 | } |
---|
1379 | } |
---|
1380 | |
---|
1381 | //dispara a importação de mensagens para o h2 |
---|
1382 | public class ThreadArchiverProcess extends Thread { |
---|
1383 | |
---|
1384 | @Override |
---|
1385 | public void run() { |
---|
1386 | // System.out.println("ThreadArchiverProcess.run sendo executado... "); |
---|
1387 | // |
---|
1388 | // System.out.println("ThreadSearch --> "+ search.getState()); |
---|
1389 | // |
---|
1390 | // System.out.println("ThreadValidateWindow --> "+ validate.getState()); |
---|
1391 | // |
---|
1392 | // System.out.println("ThreadValidateProcess --> "+ archiverValidateProcess.getState()); |
---|
1393 | |
---|
1394 | gearsArchive.archiveMessages(); |
---|
1395 | |
---|
1396 | gearsArchive.inProcess = false; |
---|
1397 | |
---|
1398 | // System.out.println("ThreadArchiverProcess.run sendo finalizado... "); |
---|
1399 | } |
---|
1400 | } |
---|
1401 | } |
---|