r35 - in trunk: . faxtomail-persistence/src/main/java/com/franciaflex/faxtomail faxtomail-persistence/src/main/resources/i18n faxtomail-persistence/src/main/xmi faxtomail-service faxtomail-service/src/main/java/com/franciaflex/faxtomail/services faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports faxtomail-service/src/main/resources/i18n faxtomail-service/src/test/java faxtomail-serv
Author: kmorin Date: 2014-04-14 18:33:11 +0200 (Mon, 14 Apr 2014) New Revision: 35 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/35 Log: refs #4653 [TECH] Gestion des mails / fax entrants Added: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailAccountImportModel.java trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailFilterImportModel.java trunk/faxtomail-service/src/test/java/com/ trunk/faxtomail-service/src/test/java/com/franciaflex/ trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/ trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/ trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/ trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/AbstractFaxToMailServiceTest.java trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/MailFolderServiceTest.java Modified: trunk/README.txt trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationProvider.java trunk/faxtomail-persistence/src/main/resources/i18n/faxtomail-persistence_en_GB.properties trunk/faxtomail-persistence/src/main/resources/i18n/faxtomail-persistence_fr_FR.properties trunk/faxtomail-persistence/src/main/xmi/faxtomail.zargo trunk/faxtomail-service/pom.xml trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/DecoratorService.java trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailDecorator.java trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/InitFaxToMailService.java trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderService.java trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ReferentielService.java trunk/faxtomail-service/src/main/resources/i18n/faxtomail-service_en_GB.properties trunk/faxtomail-service/src/main/resources/i18n/faxtomail-service_fr_FR.properties trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/MailFilterJob.java Modified: trunk/README.txt =================================================================== --- trunk/README.txt 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/README.txt 2014-04-14 16:33:11 UTC (rev 35) @@ -1,30 +0,0 @@ -Faire une nouvelle version mineure ----------------------------------- - -Cette release va juste déployer sur le dépot nexus les artifacts + mettre à jour -le fichier de mises à jour sur http://appup.forge.codelutin.com/tutti. - -mvn release:prepare -mvn release:perform - -Faire une nouvelle version majeure ----------------------------------- - -Cette release va en plus générer et deployer sur forge.codelutin.com les zip -incluant la jre + l'application. - -mvn release:prepare -Darguments="-DperformFullRelease" -mvn release:perform -Darguments="-DperformFullRelease" - -Historique des versions de base -------------------------------- - -+---------------------+------------+---------------------------+ -| Application version | Db version | Allegro db schema version | -+=====================+============+===========================+ -+ 2.3 + 2013.06.04 + 3.2.1.01 + -+---------------------+------------+---------------------------+ -+ 2.4 + 2013.06.04 + 3.2.3 + -+---------------------+------------+---------------------------+ -+ 2.8.1 + 2013.08.22 + 3.2.3 + -+---------------------+------------+---------------------------+ Modified: trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java =================================================================== --- trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java 2014-04-14 16:33:11 UTC (rev 35) @@ -190,7 +190,7 @@ applicationConfig.save(file, false, optionKeyToNotSave); } catch (IOException e) { throw new ApplicationTechnicalException( - t("tutti.config.save.error", file), e); + t("faxtomail.config.save.error", file), e); } } Modified: trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationProvider.java =================================================================== --- trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationProvider.java 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationProvider.java 2014-04-14 16:33:11 UTC (rev 35) @@ -1,29 +1,5 @@ package com.franciaflex.faxtomail; -/* - * #%L - * Tutti :: Persistence - * $Id: TuttiConfigurationProvider.java 1566 2014-02-04 08:31:02Z tchemit $ - * $HeadURL: http://svn.forge.codelutin.com/svn/tutti/trunk/tutti-persistence/src/main/ja... $ - * %% - * Copyright (C) 2012 - 2013 Ifremer - * %% - * 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% - */ - import org.nuiton.config.ApplicationConfigProvider; import org.nuiton.config.ConfigActionDef; import org.nuiton.config.ConfigOptionDef; Modified: trunk/faxtomail-persistence/src/main/resources/i18n/faxtomail-persistence_en_GB.properties =================================================================== --- trunk/faxtomail-persistence/src/main/resources/i18n/faxtomail-persistence_en_GB.properties 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/faxtomail-persistence/src/main/resources/i18n/faxtomail-persistence_en_GB.properties 2014-04-14 16:33:11 UTC (rev 35) @@ -20,6 +20,7 @@ faxtomail.config.option.ui.showNumberEditorButton.description= faxtomail.config.option.version.description= faxtomail.config.parse.error= +faxtomail.config.save.error= faxtomail.demandStatus.archive= faxtomail.demandStatus.inProgress= faxtomail.demandStatus.qualified= @@ -39,4 +40,3 @@ faxtomail.persistence.mkDir.error= faxtomail.service.config.deleteTempDirectory.error= faxtomail.service.mkDir.error= -tutti.config.save.error= Modified: trunk/faxtomail-persistence/src/main/resources/i18n/faxtomail-persistence_fr_FR.properties =================================================================== --- trunk/faxtomail-persistence/src/main/resources/i18n/faxtomail-persistence_fr_FR.properties 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/faxtomail-persistence/src/main/resources/i18n/faxtomail-persistence_fr_FR.properties 2014-04-14 16:33:11 UTC (rev 35) @@ -20,6 +20,7 @@ faxtomail.config.option.ui.showNumberEditorButton.description= faxtomail.config.option.version.description= faxtomail.config.parse.error= +faxtomail.config.save.error= faxtomail.demandStatus.archive=Archive faxtomail.demandStatus.inProgress=En cours faxtomail.demandStatus.qualified=Qualifié @@ -38,4 +39,3 @@ faxtomail.persistence.mkDir.error= faxtomail.service.config.deleteTempDirectory.error= faxtomail.service.mkDir.error= -tutti.config.save.error= Modified: trunk/faxtomail-persistence/src/main/xmi/faxtomail.zargo =================================================================== (Binary files differ) Modified: trunk/faxtomail-service/pom.xml =================================================================== --- trunk/faxtomail-service/pom.xml 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/faxtomail-service/pom.xml 2014-04-14 16:33:11 UTC (rev 35) @@ -126,24 +126,29 @@ <artifactId>junit</artifactId> </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + </dependencies> <build> - <pluginManagement> - <plugins> - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <properties> - <property> - <name>listener</name> - <value>fr.ifremer.tutti.persistence.test.TuttiRunListener</value> - </property> - </properties> - </configuration> - </plugin> - </plugins> - </pluginManagement> + <!--<pluginManagement>--> + <!--<plugins>--> + <!--<plugin>--> + <!--<artifactId>maven-surefire-plugin</artifactId>--> + <!--<configuration>--> + <!--<properties>--> + <!--<property>--> + <!--<name>listener</name>--> + <!--<value>fr.ifremer.tutti.persistence.test.TuttiRunListener</value>--> + <!--</property>--> + <!--</properties>--> + <!--</configuration>--> + <!--</plugin>--> + <!--</plugins>--> + <!--</pluginManagement>--> <plugins> <plugin> Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/DecoratorService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/DecoratorService.java 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/DecoratorService.java 2014-04-14 16:33:11 UTC (rev 35) @@ -1,29 +1,5 @@ package com.franciaflex.faxtomail.services; -/* - * #%L - * Tutti :: Application - * $Id: DecoratorService.java 1566 2014-02-04 08:31:02Z tchemit $ - * $HeadURL: http://svn.forge.codelutin.com/svn/tutti/trunk/tutti-service/src/main/java/f... $ - * %% - * Copyright (C) 2012 Ifremer - * %% - * 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% - */ - import com.franciaflex.faxtomail.persistence.entities.Attachment; import com.franciaflex.faxtomail.persistence.entities.FaxToMailUser; import com.franciaflex.faxtomail.persistence.entities.HasLabel; @@ -34,7 +10,7 @@ import java.util.Date; /** - * Tutti decorator service. + * FaxToMail decorator service. * * @author tchemit <chemit@codelutin.com> * @since 0.1 Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailDecorator.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailDecorator.java 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/FaxToMailDecorator.java 2014-04-14 16:33:11 UTC (rev 35) @@ -95,7 +95,7 @@ int i = 0; for (Context<O> OContext : contexts) { - OContext.setComparator(new TuttiDecoratorComparator<O>(getProperty(i++))); + OContext.setComparator(new FaxToMailDecoratorComparator<O>(getProperty(i++))); } this.cache = CacheBuilder.newBuilder().build(new CacheLoader<O, String>() { @@ -137,8 +137,8 @@ this.sortOnlyOnSelectedContextTokens = sortOnlyOnSelectedContextTokens; } - public TuttiDecoratorComparator<O> getCurrentComparator() { - return (TuttiDecoratorComparator<O>) context.getComparator(0); + public FaxToMailDecoratorComparator<O> getCurrentComparator() { + return (FaxToMailDecoratorComparator<O>) context.getComparator(0); } @Override @@ -216,13 +216,13 @@ return super.clone(); } - public static class TuttiDecoratorComparator<O> extends JXPathComparator<O> implements Serializable, Cloneable { + public static class FaxToMailDecoratorComparator<O> extends JXPathComparator<O> implements Serializable, Cloneable { private static final long serialVersionUID = 1L; protected String expression; - public TuttiDecoratorComparator(String expression) { + public FaxToMailDecoratorComparator(String expression) { super(expression); this.expression = expression; } @@ -230,31 +230,31 @@ @Override public void init(JXPathDecorator<O> decorator, List<O> datas) { clear(); - FaxToMailDecorator<O> tuttiDecorator = (FaxToMailDecorator<O>) decorator; + FaxToMailDecorator<O> faxToMailDecorator = (FaxToMailDecorator<O>) decorator; String token = decorator.getTokens()[0]; boolean sortOnlyOnSelectedContext = - tuttiDecorator.isSortOnlyOnSelectedContext() && - tuttiDecorator.getSortOnlyOnSelectedContextTokens() != null && - tuttiDecorator.getSortOnlyOnSelectedContextTokens().contains(token); + faxToMailDecorator.isSortOnlyOnSelectedContext() && + faxToMailDecorator.getSortOnlyOnSelectedContextTokens() != null && + faxToMailDecorator.getSortOnlyOnSelectedContextTokens().contains(token); for (O data : datas) { if (sortOnlyOnSelectedContext) { - Object tokenValue = tuttiDecorator.getValue(data, token); + Object tokenValue = faxToMailDecorator.getValue(data, token); valueCache.put(data, (Comparable) tokenValue); } else if (data instanceof Number) { valueCache.put(data, (Comparable) data); } else { - Comparable key = tuttiDecorator.toString(data); + Comparable key = faxToMailDecorator.toString(data); valueCache.put(data, key); } } } @Override - public TuttiDecoratorComparator<O> clone() { - TuttiDecoratorComparator<O> result = - new TuttiDecoratorComparator<O>(expression); + public FaxToMailDecoratorComparator<O> clone() { + FaxToMailDecoratorComparator<O> result = + new FaxToMailDecoratorComparator<O>(expression); return result; } Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/InitFaxToMailService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/InitFaxToMailService.java 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/InitFaxToMailService.java 2014-04-14 16:33:11 UTC (rev 35) @@ -45,6 +45,7 @@ import com.franciaflex.faxtomail.persistence.entities.History; import com.franciaflex.faxtomail.persistence.entities.HistoryTopiaDao; import com.franciaflex.faxtomail.persistence.entities.HistoryType; +import com.franciaflex.faxtomail.persistence.entities.MailFilter; import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.persistence.entities.MailFolderTopiaDao; import com.franciaflex.faxtomail.persistence.entities.Priority; @@ -67,12 +68,15 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URISyntaxException; import java.net.URL; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.Random; @@ -223,7 +227,7 @@ FaxToMailUser.PROPERTY_TRIGRAPH, "JBO"); MailFolderTopiaDao folderDao = getPersistenceContext().getMailFolderDao(); - List<MailFolder> folders = new ArrayList<>(); + Map<String, MailFolder> folders = new HashMap<>(); Random random = new Random(); EmailTopiaDao emailDao = getPersistenceContext().getEmailDao(); @@ -232,79 +236,100 @@ int etatAttenteSize = etatAttentes.size(); + // root folders MailFolder chargesClientelle = folderDao.create(MailFolder.PROPERTY_NAME, "Chargés de clientèle"); - folders.add(chargesClientelle); + folders.put("Chargés de clientèle", chargesClientelle); Collections.shuffle(etatAttentes); + MailFolder sav = folderDao.create(MailFolder.PROPERTY_NAME, "SAV", + MailFolder.PROPERTY_ETAT_ATTENTE, etatAttentes.subList(0, random.nextInt(etatAttenteSize - 8) + 2)); + folders.put("SAV", sav); + + // companies + CompanyTopiaDao companyTopiaDao = getPersistenceContext().getCompanyDao(); + ConfigurationTopiaDao configurationTopiaDao = getPersistenceContext().getConfigurationDao(); + Company fx = companyTopiaDao.create(Company.PROPERTY_NAME, "Franciaflex", + Company.PROPERTY_CONFIGURATION, configurationTopiaDao.create(), + Company.PROPERTY_MAIL_FOLDER, folders.values()); + companyTopiaDao.create(Company.PROPERTY_NAME, "Faber", Company.PROPERTY_CONFIGURATION, configurationTopiaDao.create()); + companyTopiaDao.create(Company.PROPERTY_NAME, "France Fermeture", Company.PROPERTY_CONFIGURATION, configurationTopiaDao.create()); + + // user folders + Collections.shuffle(etatAttentes); MailFolder cyrilFolder = folderDao.create(MailFolder.PROPERTY_NAME, "Cyril", MailFolder.PROPERTY_PARENT, chargesClientelle, MailFolder.PROPERTY_ETAT_ATTENTE, etatAttentes.subList(0, random.nextInt(etatAttenteSize - 8) + 2)); chargesClientelle.addChildren(cyrilFolder); + folders.put("Cyril", cyrilFolder); MailFolder claireFolder = folderDao.create(MailFolder.PROPERTY_NAME, "Claire", MailFolder.PROPERTY_PARENT, chargesClientelle); chargesClientelle.addChildren(claireFolder); + folders.put("Claire", claireFolder); Collections.shuffle(etatAttentes); MailFolder agatheFolder = folderDao.create(MailFolder.PROPERTY_NAME, "Agathe", MailFolder.PROPERTY_PARENT, chargesClientelle, MailFolder.PROPERTY_ETAT_ATTENTE, etatAttentes.subList(0, random.nextInt(etatAttenteSize - 8) + 2)); chargesClientelle.addChildren(agatheFolder); + folders.put("Agathe", agatheFolder); - MailFolder sav = folderDao.create(MailFolder.PROPERTY_NAME, "SAV", - MailFolder.PROPERTY_ETAT_ATTENTE, etatAttentes.subList(0, random.nextInt(etatAttenteSize - 8) + 2)); - folders.add(sav); - MailFolder marcFolder = folderDao.create(MailFolder.PROPERTY_NAME, "Marc", MailFolder.PROPERTY_PARENT, sav); sav.addChildren(marcFolder); + folders.put("Marc", marcFolder); MailFolder fredericFolder = folderDao.create(MailFolder.PROPERTY_NAME, "Frédéric", MailFolder.PROPERTY_PARENT, sav); sav.addChildren(fredericFolder); + folders.put("Frédéric", fredericFolder); MailFolder jeanneFolder = folderDao.create(MailFolder.PROPERTY_NAME, "Jeanne", MailFolder.PROPERTY_PARENT, sav); sav.addChildren(jeanneFolder); + folders.put("Jeanne", jeanneFolder); - // companies - CompanyTopiaDao companyTopiaDao = getPersistenceContext().getCompanyDao(); - ConfigurationTopiaDao configurationTopiaDao = getPersistenceContext().getConfigurationDao(); - Company fx = companyTopiaDao.create(Company.PROPERTY_NAME, "Franciaflex", Company.PROPERTY_CONFIGURATION, configurationTopiaDao.create(), Company.PROPERTY_MAIL_FOLDER, folders); - companyTopiaDao.create(Company.PROPERTY_NAME, "Faber", Company.PROPERTY_CONFIGURATION, configurationTopiaDao.create()); - companyTopiaDao.create(Company.PROPERTY_NAME, "France Fermeture", Company.PROPERTY_CONFIGURATION, configurationTopiaDao.create()); - + // email accounts try { - URL mailAccountsPropertiesURL = ClassLoader.getSystemResource("mail_accounts.properties"); - if (mailAccountsPropertiesURL != null) { - InputStream mailAccountStream = new FileInputStream(mailAccountsPropertiesURL.getPath()); - Properties properties = new Properties(); - properties.load(mailAccountStream); - String protocol = (String) properties.get("mail.protocol"); - String host = (String) properties.get("mail.host"); - String user = (String) properties.get("mail.user"); - String password = (String) properties.get("mail.password"); + URL emailAccountsPropertiesURL = ClassLoader.getSystemResource("email_accounts.csv"); + if (emailAccountsPropertiesURL != null) { + File emailAccountFile = new File(emailAccountsPropertiesURL.toURI()); - EmailAccountTopiaDao emailAccountTopiaDao = getPersistenceContext().getEmailAccountDao(); - EmailAccount emailAccount = emailAccountTopiaDao.create(EmailAccount.PROPERTY_PROTOCOL, protocol, - EmailAccount.PROPERTY_HOST, host, - EmailAccount.PROPERTY_USER, user, - EmailAccount.PROPERTY_PASSWORD, password); - fx.addEmailAccount(emailAccount); + List<EmailAccount> emailAccounts = getReferentielService().importEmailAccounts(emailAccountFile); + + fx.addAllEmailAccount(emailAccounts); companyTopiaDao.update(fx); } - } catch(IOException e) { + } catch(Exception e) { log.error("error getting the email accounts", e); - return; } + // email filters + + try { + URL emailFiltersPropertiesURL = ClassLoader.getSystemResource("email_filters.csv"); + if (emailFiltersPropertiesURL != null) { + File emailFilterFile = new File(emailFiltersPropertiesURL.toURI()); + + List<MailFilter> mailFilters = getReferentielService().importEmailFilters(emailFilterFile, folders); + + fx.addAllMailFilter(mailFilters); + companyTopiaDao.update(fx); + } + + } catch(Exception e) { + log.error("error getting the email filters", e); + } + + // user groups FaxToMailUserGroupTopiaDao userGroupDao = getPersistenceContext().getFaxToMailUserGroupDao(); userGroupDao.create(FaxToMailUserGroup.PROPERTY_NAME, "Chargés de clientèle"); userGroupDao.create(FaxToMailUserGroup.PROPERTY_NAME, "Commerciaux"); userGroupDao.create(FaxToMailUserGroup.PROPERTY_NAME, "SAV"); userGroupDao.create(FaxToMailUserGroup.PROPERTY_NAME, "Administrateurs"); + // clients and emails try { URL fxClientsURL = ClassLoader.getSystemResource("fx_clients.csv"); if (fxClientsURL != null) { Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderService.java 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/MailFolderService.java 2014-04-14 16:33:11 UTC (rev 35) @@ -2,6 +2,8 @@ import com.franciaflex.faxtomail.persistence.entities.Email; import com.franciaflex.faxtomail.persistence.entities.EtatAttente; +import com.franciaflex.faxtomail.persistence.entities.MailFilter; +import com.franciaflex.faxtomail.persistence.entities.MailFilterTopiaDao; import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.persistence.entities.MailFolderTopiaDao; import com.franciaflex.faxtomail.services.FaxToMailServiceSupport; @@ -11,11 +13,14 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.topia.persistence.TopiaIdFactory; +import org.nuiton.topia.persistence.pager.TopiaPagerBean; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; /** * @author kmorin <kmorin@codelutin.com> @@ -26,8 +31,25 @@ private static final Log log = LogFactory.getLog(MailFolderService.class); - public MailFolder getRandomFolder() { - return getPersistenceContext().getMailFolderDao().forParentEquals(null).findAny(); + public MailFolder getFolderForRecipient(String recipient) { + MailFilterTopiaDao filterTopiaDao = getPersistenceContext().getMailFilterDao(); + + TopiaPagerBean tpb = new TopiaPagerBean(); + tpb.setSortColumn(MailFilter.PROPERTY_POSITION); + tpb.setSortAscendant(true); + + String query = "FROM " + MailFilter.class.getCanonicalName() + " WHERE :recipient LIKE " + MailFilter.PROPERTY_EXPRESSION; + Map<String, Object> params = new HashMap<>(); + params.put("recipient", recipient); + + Collection<MailFilter> filters = filterTopiaDao.find(query, params, tpb); + MailFolder result; + if (CollectionUtils.isNotEmpty(filters)) { + result = filters.iterator().next().getMailFolder(); + } else { + result = null; + } + return result; } public List<MailFolder> getAllMailFolders() { Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ReferentielService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ReferentielService.java 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ReferentielService.java 2014-04-14 16:33:11 UTC (rev 35) @@ -4,14 +4,21 @@ import com.franciaflex.faxtomail.persistence.entities.ClientTopiaDao; import com.franciaflex.faxtomail.persistence.entities.DemandType; import com.franciaflex.faxtomail.persistence.entities.DemandTypeTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.EmailAccount; +import com.franciaflex.faxtomail.persistence.entities.EmailAccountTopiaDao; import com.franciaflex.faxtomail.persistence.entities.EtatAttente; import com.franciaflex.faxtomail.persistence.entities.EtatAttenteTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.MailFilter; +import com.franciaflex.faxtomail.persistence.entities.MailFilterTopiaDao; +import com.franciaflex.faxtomail.persistence.entities.MailFolder; import com.franciaflex.faxtomail.persistence.entities.Priority; import com.franciaflex.faxtomail.persistence.entities.PriorityTopiaDao; import com.franciaflex.faxtomail.persistence.entities.Range; import com.franciaflex.faxtomail.persistence.entities.RangeTopiaDao; import com.franciaflex.faxtomail.services.FaxToMailServiceSupport; import com.franciaflex.faxtomail.services.service.imports.ClientImportModel; +import com.franciaflex.faxtomail.services.service.imports.EmailAccountImportModel; +import com.franciaflex.faxtomail.services.service.imports.EmailFilterImportModel; import com.google.common.base.Charsets; import com.google.common.io.Files; import org.apache.commons.io.IOUtils; @@ -24,6 +31,7 @@ import java.io.Reader; import java.util.ArrayList; import java.util.List; +import java.util.Map; import static org.nuiton.i18n.I18n.t; @@ -94,4 +102,78 @@ } return result; } + + public List<EmailAccount> importEmailAccounts(File csvFile) throws IOException { + List<EmailAccount> result = new ArrayList<>(); + EmailAccountTopiaDao dao = getPersistenceContext().getEmailAccountDao(); + + Reader reader = Files.newReader(csvFile, Charsets.UTF_8); + EmailAccountImportModel emailAccountImportModel = new EmailAccountImportModel(';'); + try { + Import<EmailAccount> importer = Import.newImport(emailAccountImportModel, reader); + try { + for (EmailAccount emailAccount : importer) { + result.add(dao.create(emailAccount)); + } + getPersistenceContext().commit(); + + } finally { + IOUtils.closeQuietly(importer); + } + reader.close(); + + } catch (IOException e) { + throw new IOException(t("faxtomail.service.referential.import.emailAccount.error", csvFile), e); + + } catch (ImportRuntimeException e) { + String message; + if (e.getCause() != null) { + message = e.getCause().getMessage(); + } else { + message = e.getMessage(); + } + throw new ApplicationTechnicalException(message, e); + + } finally { + IOUtils.closeQuietly(reader); + } + return result; + } + + public List<MailFilter> importEmailFilters(File csvFile, Map<String, MailFolder> foldersByName) throws IOException { + List<MailFilter> result = new ArrayList<>(); + MailFilterTopiaDao dao = getPersistenceContext().getMailFilterDao(); + + Reader reader = Files.newReader(csvFile, Charsets.UTF_8); + EmailFilterImportModel emailFilterImportModel = new EmailFilterImportModel(';', foldersByName); + try { + Import<MailFilter> importer = Import.newImport(emailFilterImportModel, reader); + try { + for (MailFilter emailFilter : importer) { + result.add(dao.create(emailFilter)); + } + getPersistenceContext().commit(); + + } finally { + IOUtils.closeQuietly(importer); + } + reader.close(); + + } catch (IOException e) { + throw new IOException(t("faxtomail.service.referential.import.emailFilter.error", csvFile), e); + + } catch (ImportRuntimeException e) { + String message; + if (e.getCause() != null) { + message = e.getCause().getMessage(); + } else { + message = e.getMessage(); + } + throw new ApplicationTechnicalException(message, e); + + } finally { + IOUtils.closeQuietly(reader); + } + return result; + } } Added: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailAccountImportModel.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailAccountImportModel.java (rev 0) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailAccountImportModel.java 2014-04-14 16:33:11 UTC (rev 35) @@ -0,0 +1,29 @@ +package com.franciaflex.faxtomail.services.service.imports; + +import com.franciaflex.faxtomail.persistence.entities.EmailAccount; +import com.franciaflex.faxtomail.persistence.entities.EmailAccountImpl; +import org.nuiton.csv.ValueParser; +import org.nuiton.csv.ext.AbstractImportModel; + +import java.text.ParseException; + +/** + * @author Kevin Morin (Code Lutin) + * @since x.x + */ +public class EmailAccountImportModel extends AbstractImportModel<EmailAccount> { + + public EmailAccountImportModel(char separator) { + super(separator); + + newMandatoryColumn("protocol", EmailAccount.PROPERTY_PROTOCOL); + newMandatoryColumn("host", EmailAccount.PROPERTY_HOST); + newMandatoryColumn("user", EmailAccount.PROPERTY_USER); + newMandatoryColumn("password", EmailAccount.PROPERTY_PASSWORD); + } + + @Override + public EmailAccount newEmptyInstance() { + return new EmailAccountImpl(); + } +} Added: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailFilterImportModel.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailFilterImportModel.java (rev 0) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/imports/EmailFilterImportModel.java 2014-04-14 16:33:11 UTC (rev 35) @@ -0,0 +1,42 @@ +package com.franciaflex.faxtomail.services.service.imports; + +import com.franciaflex.faxtomail.persistence.entities.EmailAccount; +import com.franciaflex.faxtomail.persistence.entities.EmailAccountImpl; +import com.franciaflex.faxtomail.persistence.entities.MailFilter; +import com.franciaflex.faxtomail.persistence.entities.MailFilterImpl; +import com.franciaflex.faxtomail.persistence.entities.MailFolder; +import org.nuiton.csv.ValueParser; +import org.nuiton.csv.ext.AbstractImportModel; + +import java.text.ParseException; +import java.util.Map; + +/** + * @author Kevin Morin (Code Lutin) + * @since x.x + */ +public class EmailFilterImportModel extends AbstractImportModel<MailFilter> { + + public EmailFilterImportModel(char separator, final Map<String, MailFolder> foldersByName) { + super(separator); + + newMandatoryColumn("recipient", MailFilter.PROPERTY_EXPRESSION); + newMandatoryColumn("folder", MailFilter.PROPERTY_MAIL_FOLDER, new ValueParser<Object>() { + @Override + public Object parse(String value) throws ParseException { + return foldersByName.get(value); + } + }); + newMandatoryColumn("position", MailFilter.PROPERTY_POSITION, new ValueParser<Object>() { + @Override + public Object parse(String value) throws ParseException { + return Integer.parseInt(value); + } + }); + } + + @Override + public MailFilter newEmptyInstance() { + return new MailFilterImpl(); + } +} Modified: trunk/faxtomail-service/src/main/resources/i18n/faxtomail-service_en_GB.properties =================================================================== --- trunk/faxtomail-service/src/main/resources/i18n/faxtomail-service_en_GB.properties 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/faxtomail-service/src/main/resources/i18n/faxtomail-service_en_GB.properties 2014-04-14 16:33:11 UTC (rev 35) @@ -1,67 +0,0 @@ -faxtomail.config.option.basedir.description= -faxtomail.config.option.csv.separator.description= -faxtomail.config.option.data.directory.description= -faxtomail.config.option.inceptionYear.description= -faxtomail.config.option.organizationName.description= -faxtomail.config.option.site.url.description= -faxtomail.config.option.tmp.directory.description= -faxtomail.config.option.version.description= -faxtomail.config.service= -faxtomail.email.projectReference.default= -faxtomail.service.compressZipFile.error= -faxtomail.service.config.deleteTempDirectory.error= -faxtomail.service.mkDir.error= -faxtomail.service.referential.import.clients.error= -faxtomail.validator.error.email.clientCode.required= -faxtomail.validator.error.email.demandType.required= -faxtomail.validator.error.email.projectReference.required= -tutti.config.option.basedir.description= -tutti.config.option.csv.separator.description= -tutti.config.option.inceptionYear.description= -tutti.config.option.organizationName.description= -tutti.config.option.site.url.description= -tutti.config.option.tmp.directory.description= -tutti.config.option.version.description= -tutti.property.attachment= -tutti.property.caracteristic= -tutti.property.country= -tutti.property.cruise= -tutti.property.date= -tutti.property.department= -tutti.property.firstName= -tutti.property.fishingOperation= -tutti.property.fishingOperationLocation= -tutti.property.fishingOperationNumber= -tutti.property.fractionName= -tutti.property.gear= -tutti.property.gearShootingStartDate= -tutti.property.genusSpecies= -tutti.property.internationalRegistrationCode= -tutti.property.label= -tutti.property.lastName= -tutti.property.marineLitterCategory= -tutti.property.matrixName= -tutti.property.methodName= -tutti.property.multirigAggregation= -tutti.property.name= -tutti.property.parameterName= -tutti.property.person= -tutti.property.program= -tutti.property.protocol= -tutti.property.rankOrder= -tutti.property.refTaxCode= -tutti.property.sortedUnsortedCategory= -tutti.property.species= -tutti.property.stationNumber= -tutti.property.strata= -tutti.property.surveyCode= -tutti.property.tuttiLocation= -tutti.property.user= -tutti.property.vessel= -tutti.property.zone= -tutti.propety.no.species.speciesCode= -tutti.propety.no.vessel.name= -tutti.propety.no.zone= -tutti.propety.vessel.nation.registrationCode= -tutti.service.compressZipFile.error= -tutti.service.context.serviceInstanciation.error= Modified: trunk/faxtomail-service/src/main/resources/i18n/faxtomail-service_fr_FR.properties =================================================================== --- trunk/faxtomail-service/src/main/resources/i18n/faxtomail-service_fr_FR.properties 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/faxtomail-service/src/main/resources/i18n/faxtomail-service_fr_FR.properties 2014-04-14 16:33:11 UTC (rev 35) @@ -1,5 +1,7 @@ faxtomail.email.projectReference.default=Votre demande du %s faxtomail.service.referential.import.clients.error= +faxtomail.service.referential.import.emailAccount.error= +faxtomail.service.referential.import.emailFilter.error= faxtomail.validator.error.email.clientCode.required= faxtomail.validator.error.email.demandType.required= faxtomail.validator.error.email.projectReference.required= Added: trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/AbstractFaxToMailServiceTest.java =================================================================== --- trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/AbstractFaxToMailServiceTest.java (rev 0) +++ trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/AbstractFaxToMailServiceTest.java 2014-04-14 16:33:11 UTC (rev 35) @@ -0,0 +1,277 @@ +package com.franciaflex.faxtomail.services.service; + +/* + * #%L + * Extranet ENC-AHI :: Services + * $Id: AbstractExtranetEncAhiServiceTest.java 1134 2014-02-17 08:47:05Z sbavencoff $ + * $HeadURL: http://svn.forge.codelutin.com/svn/extranet-enc-ahi/trunk/extranet-services/... $ + * %% + * Copyright (C) 2013 Ministère des Affaires sociales et de la Santé + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.franciaflex.faxtomail.FaxToMailConfiguration; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailTopiaApplicationContext; +import com.franciaflex.faxtomail.persistence.entities.FaxToMailTopiaPersistenceContext; +import com.franciaflex.faxtomail.services.FaxToMailService; +import com.franciaflex.faxtomail.services.FaxToMailServiceContext; +import org.apache.commons.lang3.SystemUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.cfg.Environment; +import org.junit.After; +import org.nuiton.util.FileUtil; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +public class AbstractFaxToMailServiceTest { + + private static final Log log = LogFactory.getLog(AbstractFaxToMailServiceTest.class); + + protected static final String DATABASE_REF = "DataBaseRef"; + + protected static FaxToMailConfiguration applicationConfig; + + protected FaxToMailServiceContext serviceContext; + + protected FaxToMailTopiaApplicationContext applicationContext; + + protected List<FaxToMailTopiaPersistenceContext> openedTransactions = new LinkedList<>(); + + protected FaxToMailTopiaApplicationContext newApplicationContext(String dataBase) { + + Map<String, String> hibernateH2Config = new HashMap<String, String>(); + + hibernateH2Config.putAll(getApplicationConfig().getTopiaProperties()); + + hibernateH2Config.put(Environment.DRIVER, org.h2.Driver.class.getName()); + hibernateH2Config.put(Environment.USER, "sa"); + hibernateH2Config.put(Environment.PASS, ""); + + File tempDirFile = SystemUtils.getJavaIoTmpDir(); + + File databaseFile = new File(tempDirFile, dataBase); + + String h2dataPath = databaseFile.getAbsolutePath() + File.separator + "h2data-test"; + + String jdbcUrl = "jdbc:h2:file:" + h2dataPath; + + hibernateH2Config.put(Environment.URL, jdbcUrl); + + if (log.isTraceEnabled()) { + log.trace("will store H2 data in " + h2dataPath); + log.trace("allJpaParameters = " + hibernateH2Config); + } + + if (log.isDebugEnabled()) { + log.debug("jdbc url is\n" + jdbcUrl); + } + + FaxToMailTopiaApplicationContext applicationContext = new FaxToMailTopiaApplicationContext(hibernateH2Config); + + if (log.isTraceEnabled()) { + log.trace("created root context " + applicationContext); + } + + return applicationContext; + } + + protected boolean isDatabaseWithReferential() { + return false; + } + + protected FaxToMailTopiaApplicationContext getApplicationContext () { + + String databaseName = UUID.randomUUID().toString(); + + if (isDatabaseWithReferential()) { + + File tempDirFile = SystemUtils.getJavaIoTmpDir(); + + File databaseRefFile = new File(tempDirFile, DATABASE_REF); + + if (!databaseRefFile.exists()) { + + if (log.isTraceEnabled()) { + log.trace("create referential data base"); + } + + FaxToMailTopiaApplicationContext applicationContext = newApplicationContext(DATABASE_REF); + + FaxToMailTopiaPersistenceContext persistenceContext; + + persistenceContext = applicationContext.newPersistenceContext(); + + if (log.isTraceEnabled()) { + log.trace("opened transaction " + persistenceContext); + } + + FaxToMailServiceContext serviceContext = new FaxToMailServiceContext(); + + serviceContext.setApplicationConfig(getApplicationConfig()); + + serviceContext.setPersistenceContext(persistenceContext); + +// serviceContext.setStorageFile(new File (tempDirFile, UUID.randomUUID().toString())); + + InitFaxToMailService initExtranetService = serviceContext.newService(InitFaxToMailService.class); + + initExtranetService.init(); + + if (log.isTraceEnabled()) { + log.trace("closing transaction " + persistenceContext); + } + + persistenceContext.closeContext(); + + if (log.isTraceEnabled()) { + log.trace("closing transaction " + applicationContext); + } + + applicationContext.closeContext(); + + File lockFile = new File(databaseRefFile, "h2data.lock.db"); + + int countWaiting = 0; + + while (lockFile.exists() && countWaiting < 150) { + try { + Thread.sleep(200); + } catch (InterruptedException e) { + throw new RuntimeException("can't wait", e); + } + countWaiting++; + } + + if (lockFile.exists()) { + throw new RuntimeException("database ref is not close after 30 seconds !"); + } + + } + + File databaseFile = new File(tempDirFile, databaseName); + + if (log.isTraceEnabled()) { + log.trace("Copy referential database to " + databaseFile.getName()); + } + + try { + FileUtil.copyAndRenameRecursively(databaseRefFile, databaseFile, false, null, null, false); + } catch (IOException e) { + throw new RuntimeException("can't copy database Ref", e); + } + + if (log.isTraceEnabled()) { + log.trace("Copy referential database : Complete"); + } + } + + return newApplicationContext(databaseName); + } + + protected FaxToMailTopiaPersistenceContext newPersistenceContext() { + + if (applicationContext == null) { + + applicationContext = getApplicationContext(); + + } + + FaxToMailTopiaPersistenceContext persistenceContext; + + persistenceContext = applicationContext.newPersistenceContext(); + + if (log.isTraceEnabled()) { + log.trace("opened transaction " + persistenceContext); + } + + openedTransactions.add(persistenceContext); + + return persistenceContext; + + } + + @After + public void tearDown() { + + for (FaxToMailTopiaPersistenceContext openedTransaction : openedTransactions) { + + if (log.isTraceEnabled()) { + log.trace("closing transaction " + openedTransaction); + } + + openedTransaction.closeContext(); + + } + + if (applicationContext != null) { + + if (log.isTraceEnabled()) { + log.trace("closing transaction " + applicationContext); + } + + applicationContext.closeContext(); + + } + + } + + protected static FaxToMailConfiguration getApplicationConfig() { + + if (applicationConfig == null) { + + applicationConfig = new FaxToMailConfiguration("faxToMail.properties"); + + } + + return applicationConfig; + + } + + protected FaxToMailServiceContext getServiceContext() { + + if (serviceContext == null) { + + FaxToMailServiceContext serviceContext = new FaxToMailServiceContext(); + + serviceContext.setApplicationConfig(getApplicationConfig()); + + FaxToMailTopiaPersistenceContext persistenceContext = newPersistenceContext(); + + serviceContext.setPersistenceContext(persistenceContext); + + this.serviceContext = serviceContext; + + } + + return serviceContext; + + } + + protected <E extends FaxToMailService> E newService(Class<E> serviceClass) { + + return getServiceContext().newService(serviceClass); + + } + +} Added: trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/MailFolderServiceTest.java =================================================================== --- trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/MailFolderServiceTest.java (rev 0) +++ trunk/faxtomail-service/src/test/java/com/franciaflex/faxtomail/services/service/MailFolderServiceTest.java 2014-04-14 16:33:11 UTC (rev 35) @@ -0,0 +1,35 @@ +package com.franciaflex.faxtomail.services.service; + +import com.franciaflex.faxtomail.persistence.entities.MailFolder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author Kevin Morin (Code Lutin) + * @since x.x + */ +public class MailFolderServiceTest extends AbstractFaxToMailServiceTest { + + private static final Log log = LogFactory.getLog(MailFolderServiceTest.class); + + protected MailFolderService service; + + @Before + public void setUp() { + service = newService(MailFolderService.class); + log.info("init sample data"); + newService(InitFaxToMailService.class).initSampleData(); + } + + @Test + public void testFindFilter() { + log.info(service.getAllMailFolders()); + MailFolder folder = service.getFolderForRecipient("fx.savtest@franciaflex.com"); + Assert.assertNotNull(folder); + log.info(folder.getName()); + } + +} Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/MailFilterJob.java =================================================================== --- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/MailFilterJob.java 2014-04-14 14:02:52 UTC (rev 34) +++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/MailFilterJob.java 2014-04-14 16:33:11 UTC (rev 35) @@ -202,7 +202,7 @@ // log.debug(content); // email.setContent(content); - MailFolder mailFolder = serviceContext.newService(MailFolderService.class).getRandomFolder(); + MailFolder mailFolder = serviceContext.newService(MailFolderService.class).getFolderForRecipient(email.getRecipient()); email.setMailFolder(mailFolder); serviceContext.newService(EmailService.class).saveEmail(email, null);
participants (1)
-
kmorin@users.forge.codelutin.com