r245 - in trunk: faxtomail-persistence/src/main/java/com/franciaflex/faxtomail faxtomail-persistence/src/main/xmi faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job faxtomail-ui-web/src/main/webapp/js
Author: echatellier Date: 2014-06-20 17:34:06 +0200 (Fri, 20 Jun 2014) New Revision: 245 Url: http://forge.codelutin.com/projects/faxtomail/repository/revisions/245 Log: Gestion de tous les cas sp?\195?\169ciaux de sauvegarde compliqu?\195?\169 Modified: trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java trunk/faxtomail-persistence/src/main/xmi/faxtomail.zargo trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationService.java trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js Modified: trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java =================================================================== --- trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java 2014-06-20 15:26:54 UTC (rev 244) +++ trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfiguration.java 2014-06-20 15:34:06 UTC (rev 245) @@ -239,9 +239,13 @@ return applicationConfig.getOptionAsBoolean(FaxToMailConfigurationOption.SMTP_SSL.getKey()); } - public boolean isMailDeleteRemote() { - return applicationConfig.getOptionAsBoolean(FaxToMailConfigurationOption.MAIL_DELETE_REMOTE.getKey()); + public boolean isMailDelete() { + return applicationConfig.getOptionAsBoolean(FaxToMailConfigurationOption.MAIL_DELETE.getKey()); } + + public boolean isMailExpunge() { + return applicationConfig.getOptionAsBoolean(FaxToMailConfigurationOption.MAIL_EXPUNGE.getKey()); + } public String getLdapHost() { return applicationConfig.getOption(FaxToMailConfigurationOption.LDAP_HOST.getKey()); Modified: trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java =================================================================== --- trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java 2014-06-20 15:26:54 UTC (rev 244) +++ trunk/faxtomail-persistence/src/main/java/com/franciaflex/faxtomail/FaxToMailConfigurationOption.java 2014-06-20 15:34:06 UTC (rev 245) @@ -72,10 +72,15 @@ "Utilisation on non du mode ssl pour le stmp", "false", Boolean.class), - MAIL_DELETE_REMOTE( - "faxtomail.mail.deleteremote", - "Suppression automatique des mails sur le serveur distant (default : true)", - "true", Boolean.class), + MAIL_DELETE( + "faxtomail.mail.delete", + "Marque les mails comme étant supprimé sur le serveur", + "false", Boolean.class), + + MAIL_EXPUNGE( + "faxtomail.mail.expunge", + "Supprime définitivement les mails marqués comme supprimés", + "false", Boolean.class), DEV_MODE( "faxtomail.devMode", Modified: trunk/faxtomail-persistence/src/main/xmi/faxtomail.zargo =================================================================== (Binary files differ) Modified: trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationService.java =================================================================== --- trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationService.java 2014-06-20 15:26:54 UTC (rev 244) +++ trunk/faxtomail-service/src/main/java/com/franciaflex/faxtomail/services/service/ConfigurationService.java 2014-06-20 15:34:06 UTC (rev 245) @@ -132,13 +132,20 @@ public void save(Configuration configuration, List<DemandType> demandTypes, List<EtatAttente> etatAttentes, List<MailFolder> mailFolders, List<MailFilter> mailFilters, List<EmailAccount> emailAccounts) { + Collection<MailFolder> toDeleteMailFolder = new ArrayList<>(); + + // sauvegarde saveConfiguration(configuration); saveDemandTypes(demandTypes); - saveMailFolders(mailFolders); // save before etat d'attente to remove reference - saveEtatAttente(etatAttentes); - saveMailFilters(mailFilters); + Map<String, EtatAttente> etatAttenteCache = saveEtatAttente(etatAttentes); + Map<String, MailFolder> mailFolderCache = saveMailFolders(etatAttenteCache, mailFolders, toDeleteMailFolder); + saveMailFilters(mailFolderCache, mailFilters); saveEmailAccounts(emailAccounts); + // delete after loop + MailFolderTopiaDao mailFilterDao = getPersistenceContext().getMailFolderDao(); + mailFilterDao.deleteAll(toDeleteMailFolder); + // unique commit pour toute la conf getPersistenceContext().commit(); } @@ -172,9 +179,14 @@ } } } - - protected void saveEtatAttente(Collection<EtatAttente> etatAttentes) { + /** + * + * @param etatAttentes + */ + protected Map<String, EtatAttente> saveEtatAttente(Collection<EtatAttente> etatAttentes) { + + Map<String, EtatAttente> cache = new HashMap<>(); Binder<EtatAttente, EtatAttente> binderEtatAttente = BinderFactory.newBinder(EtatAttente.class); EtatAttenteTopiaDao etatAttenteDAO = getPersistenceContext().getEtatAttenteDao(); @@ -201,41 +213,53 @@ } else { etatAttenteDAO.create(currentEtatAttente); } + + // cache + cache.put(etatAttente.getTopiaId(), currentEtatAttente); } - // delete remaining + // delete remaining (not done here, done after reference cleaning) etatAttenteDAO.deleteAll(allEtatAttenteIndex.values()); + + return cache; } /** * Save mail folder without commit. * + * @param etatAttenteCache cache etat attente * @param newMailFolders mail folders + * @return mail folder cache with input ids */ - protected void saveMailFolders(Collection<MailFolder> newMailFolders) { + protected Map<String, MailFolder> saveMailFolders(Map<String, EtatAttente> etatAttenteCache, Collection<MailFolder> newMailFolders, Collection<MailFolder> toDeleteMailFolder) { // get current folders MailFolderTopiaDao dao = getPersistenceContext().getMailFolderDao(); List<MailFolder> mailFolders = dao.findAll(); Map<String, MailFolder> mailFolderMap = new HashMap<>(Maps.uniqueIndex(mailFolders, TopiaEntities.getTopiaIdFunction())); // recursive update - saveMailFolders(dao, mailFolderMap, null, newMailFolders); + Map<String, MailFolder> mailFolderCache = new HashMap<>(); + saveMailFolders(dao, etatAttenteCache, mailFolderMap, null, newMailFolders, mailFolderCache); // if map is not empty after recursive iteration, remaining folder must be deleted - dao.deleteAll(mailFolderMap.values()); + toDeleteMailFolder.addAll(mailFolderMap.values()); + + return mailFolderCache; } /** * Save mail folder without commit. * * @param dao + * @param etatAttenteCache * @param mailFolderMap * @param parent * @param mailFolders + * @param mailFolderCache * @return */ - protected Collection<MailFolder> saveMailFolders(MailFolderTopiaDao dao, Map<String, MailFolder> mailFolderMap, - MailFolder parent, Collection<MailFolder> mailFolders) { + protected Collection<MailFolder> saveMailFolders(MailFolderTopiaDao dao, Map<String, EtatAttente> etatAttenteCache, + Map<String, MailFolder> mailFolderMap, MailFolder parent, Collection<MailFolder> mailFolders, Map<String, MailFolder> mailFolderCache) { Collection<MailFolder> result = Lists.newArrayList(); if (mailFolders == null) { @@ -257,19 +281,32 @@ MailFolder.PROPERTY_TOPIA_CREATE_DATE, MailFolder.PROPERTY_TOPIA_VERSION, MailFolder.PROPERTY_CHILDREN, + MailFolder.PROPERTY_ETAT_ATTENTES, MailFolder.PROPERTY_PARENT); + // gestion des bonnes références des états d'attente (surtout le cas "new_") + currentMailFolder.clearEtatAttentes(); + if (mailFolder.getEtatAttentes() != null) { + for (EtatAttente etatAttente : mailFolder.getEtatAttentes()) { + // etatAttente.getTopiaId() peut retourner un id qui commence par new_ + currentMailFolder.addEtatAttentes(etatAttenteCache.get(etatAttente.getTopiaId())); + } + } + currentMailFolder.setParent(parent); if (!currentMailFolder.isPersisted()) { currentMailFolder = dao.create(currentMailFolder); } - Collection<MailFolder> children = saveMailFolders(dao, mailFolderMap, currentMailFolder, mailFolder.getChildren()); + Collection<MailFolder> children = saveMailFolders(dao, etatAttenteCache, mailFolderMap, currentMailFolder, mailFolder.getChildren(), mailFolderCache); currentMailFolder.setChildren(children); dao.update(currentMailFolder); result.add(currentMailFolder); + + // add in cache + mailFolderCache.put(mailFolder.getTopiaId(), currentMailFolder); } return result; @@ -278,9 +315,10 @@ /** * Save all mail filters without commit. * + * @param mailFolderCache mail folder cache (with corrects ids) * @param mailFilters mail filters to save */ - protected void saveMailFilters(List<MailFilter> mailFilters) { + protected void saveMailFilters(Map<String, MailFolder> mailFolderCache, List<MailFilter> mailFilters) { MailFilterTopiaDao dao = getPersistenceContext().getMailFilterDao(); int position = 0; @@ -296,7 +334,10 @@ filter = filterById.remove(mailFilter.getTopiaId()); } filter.setExpression(mailFilter.getExpression()); - filter.setMailFolder(mailFilter.getMailFolder()); + + // mailFilter.getMailFolder().getTopiaId() can start with new_ + MailFolder mailFolder = mailFolderCache.get(mailFilter.getMailFolder().getTopiaId()); + filter.setMailFolder(mailFolder); filter.setPosition(position); if (create) { @@ -304,10 +345,9 @@ } else { filter = dao.update(filter); } - position++; } - + dao.deleteAll(filterById.values()); } Modified: trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java =================================================================== --- trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java 2014-06-20 15:26:54 UTC (rev 244) +++ trunk/faxtomail-ui-web/src/main/java/com/franciaflex/faxtomail/web/job/MailFilterJob.java 2014-06-20 15:34:06 UTC (rev 245) @@ -64,7 +64,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.Decorator; -import org.nuiton.jaxx.application.ApplicationTechnicalException; import org.nuiton.util.StringUtil; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; @@ -172,9 +171,8 @@ protected void close(Folder folder) { if (folder != null && folder.isOpen()) { try { - // TODO 20140414 kmorin close(true) in production - folder.close(false); // false -> On n'efface pas les messages marqués DELETED - + boolean expunge = serviceContext.getApplicationConfig().isMailExpunge(); + folder.close(expunge); } catch (Exception e) { log.error("Error while closing the folder", e); } @@ -307,7 +305,7 @@ modifiedProperties.toArray(new String[modifiedProperties.size()])); // suppression des mails sur le serveur distant (automatique par default) - if (serviceContext.getApplicationConfig().isMailDeleteRemote()) { + if (serviceContext.getApplicationConfig().isMailDelete()) { message.setFlag(Flags.Flag.DELETED, true); } } Modified: trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js =================================================================== --- trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js 2014-06-20 15:26:54 UTC (rev 244) +++ trunk/faxtomail-ui-web/src/main/webapp/js/configuration.js 2014-06-20 15:34:06 UTC (rev 245) @@ -47,6 +47,10 @@ $scope.mailFoldersUsage = ConfigurationData.mailFoldersUsage; //{Map<MailFolder id, Array<MailFolder>>} liste des dossier (a plat, par dossier racine) $scope.flatMailFolders; + //{Array} Current mail filter list + $scope.mailFilters = ConfigurationData.mailFilters; + //{Map} Folder mail fiters + $scope.rootFolderMailFilters = {}; //{Array} All application users $scope.users = ConfigurationData.users; // {Array} All application groups @@ -95,6 +99,35 @@ }); }; $scope._updateFlatMailFolders(); + + + // replace filter instance with mailFolder filter instance to use same objects (filled with fullPathInfo) + var _updateMetaFilter = function() { + angular.forEach($scope.mailFilters, function(filter) { + // root folder + angular.forEach($scope.mailFolders, function(mailFolder) { + if (!$scope.rootFolderMailFilters.hasOwnProperty(mailFolder.topiaId)) { + $scope.rootFolderMailFilters[mailFolder.topiaId] = []; + } + angular.forEach($scope.flatMailFolders[mailFolder.topiaId], function(subFolder) { + if (subFolder.topiaId == filter.mailFolder.topiaId) { + filter.mailFolder = subFolder; + + $scope.rootFolderMailFilters[subFolder.$rootFolder.topiaId].push(filter); + } + }); + }); + }); + }; + + $scope.updateMetaFilter = function(news, olds) { + console.log("Udpate MetaFilter"); + $scope.rootFolderMailFilters = {}; + _updateMetaFilter(); + }; + + // update when root folder collection changes (and for init) + $scope.$watchCollection("mailFolders", $scope.updateMetaFilter); }]); /** @@ -177,11 +210,11 @@ $scope.deleteEtatAttente = function(etatAttente, index) { if ($window.confirm("Êtes-vous sûr de vouloir supprimer cet état d'attente ?")) { $scope.etatAttentes.splice(index, 1); + + // suppression de cet etat d'attente dans les mail folder (sinon, ca fait + // un resauvegarde d'un etat d'attente supprimé et donc un bug) + removeEtatAttenteFromMailFolder(etatAttente, $scope.mailFolders); } - - // suppression de cet etat d'attente dans les mail folder (sinon, ca fait - // un resauvegarde d'un etat d'attente supprimé et donc un bug) - removeEtatAttenteFromMailFolder(etatAttente, $scope.mailFolders); }; // suppression de cet etat d'attente dans les mail folder (sinon, ca fait @@ -326,14 +359,33 @@ // edition automatique $scope.editMailFolder(newNode); // update flat map - $scope._updateFlatMailFolders(); + $scope._updateFlatMailFolders(); } }; // suppression d'un dossier $scope.deleteFolder = function(scope) { if ($window.confirm("Êtes-vous sûr de vouloir supprimer ce dossier ?")) { + + var nodeData = scope.$modelValue; + + // suppression des filtres utilisant ce dossier comme cible + var index = -1; + var current = 0; + angular.forEach($scope.mailFilters, function(filter) { + if (filter.mailFolder.topiaId == nodeData.topiaId) { + index = current; + } + current++; + }); + if (index != -1) { + $scope.mailFilters.splice(index, 1); + } + + // remove current folder scope.remove(scope); + // update filter meta map + $scope.updateMetaFilter(); } }; @@ -838,38 +890,9 @@ */ ConfigurationModule.controller('ConfigurationFilterController', ['$scope', '$window', 'ConfigurationData', function($scope, $window, ConfigurationData) { - //{Array} Current mail filter list - $scope.mailFilters = ConfigurationData.mailFilters; - //{Map} Folder mail fiters - $scope.rootFolderMailFilters = {}; //{Object} New accout empty filter $scope.newFilter = {}; - // replace filter instance with mailFolder filter instance to use same objects (filled with fullPathInfo) - var updateMetaFilter = function() { - angular.forEach($scope.mailFilters, function(filter) { - // root folder - angular.forEach($scope.mailFolders, function(mailFolder) { - if (!$scope.rootFolderMailFilters.hasOwnProperty(mailFolder.topiaId)) { - $scope.rootFolderMailFilters[mailFolder.topiaId] = []; - } - angular.forEach($scope.flatMailFolders[mailFolder.topiaId], function(subFolder) { - if (subFolder.topiaId == filter.mailFolder.topiaId) { - filter.mailFolder = subFolder; - - $scope.rootFolderMailFilters[subFolder.$rootFolder.topiaId].push(filter); - } - }); - }); - }); - }; - // update when root folder collection changes (and for init) - $scope.$watchCollection("mailFolders", function(news, olds) { - console.log("Udpate MetaFilter"); - $scope.rootFolderMailFilters = {}; - updateMetaFilter(); - }); - // option de la configuration 'sortable' $scope.sortableOptions = { stop: function(e, ui) {
participants (1)
-
echatellier@users.forge.codelutin.com