r519 - in trunk: faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin
Author: echatellier Date: 2014-08-11 18:17:56 +0200 (Mon, 11 Aug 2014) New Revision: 519 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/519 Log: refs-70 #5559: Import csv des archives existantes Added: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ImportArchiveAction.java trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/import-archive-input.jsp Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java 2014-08-11 14:46:33 UTC (rev 518) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailService.java 2014-08-11 16:17:56 UTC (rev 519) @@ -104,6 +104,13 @@ AttachmentFile getEmailDetailAsAttachment(Email email); /** + * Retourne le nombre de mail archivé. + * + * @return le nombre de mail archivé + */ + long getArchivedMailCount(); + + /** * Import archive from input stream. * * @param is input stream of csv file Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java 2014-08-11 14:46:33 UTC (rev 518) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/EmailServiceImpl.java 2014-08-11 16:17:56 UTC (rev 519) @@ -1296,4 +1296,11 @@ IOUtils.closeQuietly(inputStream); } } + + @Override + public long getArchivedMailCount() { + EmailTopiaDao emailDao = getPersistenceContext().getEmailDao(); + long result = emailDao.forDemandStatusEquals(DemandStatus.ARCHIVED).count(); + return result; + } } Added: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ImportArchiveAction.java =================================================================== --- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ImportArchiveAction.java (rev 0) +++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ImportArchiveAction.java 2014-08-11 16:17:56 UTC (rev 519) @@ -0,0 +1,116 @@ +package com.franciaflex.faxtomail.web.action.admin; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts2.convention.annotation.Action; +import org.apache.struts2.convention.annotation.InterceptorRef; +import org.apache.struts2.convention.annotation.InterceptorRefs; +import org.apache.struts2.convention.annotation.Result; + +import com.franciaflex.faxtomail.services.service.EmailService; +import com.franciaflex.faxtomail.web.FaxToMailActionSupport; +import com.opensymphony.xwork2.Preparable; + +/** + * Action de reprise des archives. + * + * @author Eric Chatellier + */ +@InterceptorRefs({ + @InterceptorRef("faxToMailInterceptor"), + @InterceptorRef("loginInterceptor"), + @InterceptorRef("paramsPrepareParamsStack") +}) +public class ImportArchiveAction extends FaxToMailActionSupport implements Preparable { + + private static final Log log = LogFactory.getLog(ImportArchiveAction.class); + + protected String attachmentBase; + + protected File archiveFile; + + protected EmailService emailService; + + protected boolean disabledImport; + + public void setEmailService(EmailService emailService) { + this.emailService = emailService; + } + + public void setArchiveFile(File archiveFile) { + this.archiveFile = archiveFile; + } + + public void setAttachmentBase(String attachmentBase) { + this.attachmentBase = attachmentBase; + } + + public boolean isDisabledImport() { + return disabledImport; + } + + @Override + public void prepare() throws Exception { + // check authorization + if (!getSession().isAdmin()) { + throw new RuntimeException("Not authorized"); + } + } + + @Override + @Action("import-archive-input") + public String input() throws Exception { + checkDisabled(); + return super.input(); + } + + protected boolean checkDisabled() { + + // pour eviter les erreurs, on considere que si 1000 mails archivés sont présents, il + // proviennent de la reprise des archives + if (emailService.getArchivedMailCount() > 1000) { + disabledImport = true; + } + return disabledImport; + } + + @Override + public void validate() { + if (StringUtils.isEmpty(attachmentBase)) { + addActionError("Le répertoire de base des pièces jointes est obligatoire !"); + } + else if (!new File(attachmentBase).isDirectory()) { + addActionError("Le répertoire de base des pièces jointes n'est pas un répertoire lisible !"); + } + if (archiveFile == null) { + addActionError("Le fichier d'archive est obligatoire !"); + } + + checkDisabled(); + } + + @Action(results = {@Result(type = "redirectAction", params = {"actionName", "import-archive-input"})}) + @Override + public String execute() throws Exception { + String result = INPUT; + + if (!checkDisabled()) { + try (InputStream is = new FileInputStream(archiveFile)) { + File file = new File(attachmentBase); + emailService.importArchive(is, file); + result = SUCCESS; + } catch (Exception ex) { + if (log.isErrorEnabled()) { + log.error("Can't import archive file", ex); + } + addActionError("Can't import archive " + ex.getMessage()); + } + } + return result; + } +} Property changes on: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/action/admin/ImportArchiveAction.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/import-archive-input.jsp =================================================================== --- trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/import-archive-input.jsp (rev 0) +++ trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/import-archive-input.jsp 2014-08-11 16:17:56 UTC (rev 519) @@ -0,0 +1,66 @@ +<%-- + #%L + FaxToMail :: Web + $Id$ + $HeadURL$ + %% + Copyright (C) 2014 Franciaflex, Code Lutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public + License along with this program. If not, see + <http://www.gnu.org/licenses/gpl-3.0.html>. + #L% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<!DOCTYPE html> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + <head> + <title>Reprise des archives</title> + </head> + + <body> + + <div id="main-container" class="container"> + + <h1 class="page-header">Reprise des archives</h1> + + <s:if test="disabledImport"> + <em>L'import des archives a déjà été effectué, il n'est plus disponible</em> + </s:if> + <s:else> + <s:form id="main_form" action="import-archive" method="post" enctype="multipart/form-data"> + + <s:actionmessage/> + <s:actionerror/> + + <div class="form-group"> + <label for="archiveFile" class="control-label">Fichier d'archive :</label> + <input type="file" id="archiveFile" name="archiveFile" class="form-control"> + <p class="help-block">Format du fichier csv : <code>receptionDate;projectReference;sender;fax;recipient;object;archiveDate;companyReference;originalEmail;comment;etatAttente;demandType;priority;mailFolder;client-code;client-brand;attachments</code><br /> + Encodage du fichier csv : <code>${applicationConfig.importFileEncoding}</code></p> + </div> + <div class="form-group"> + <label for="attachmentBase" class="control-label">Répertoire de base des pièces jointes :</label> + <input type="text" id="attachmentBase" name="attachmentBase" class="form-control"> + <p class="help-block">Dossier contenant les pièces jointes référencées dans le fichier d'archive</p> + </div> + <button type="submit" class="btn btn-primary navbar-btn">Valider</button> + <hr /> + + </s:form> + </s:else> + </div> + </body> +</html> Property changes on: trunk/faxtomail-ui-web/src/main/webapp/WEB-INF/content/admin/import-archive-input.jsp ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native
participants (1)
-
echatellier@users.forge.codelutin.com