Author: nrannou Date: 2009-08-19 17:48:01 +0200 (Wed, 19 Aug 2009) New Revision: 2736 Modified: trunk/README.txt trunk/pollen-business/src/main/java/org/chorem/pollen/business/business/PreventRuleManager.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPreventRuleConverter.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PreventRuleDTO.java trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/business/PreventRuleManagerTest.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceChoiceImplTest.java trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Chart.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FeedBack.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Image.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java trunk/pollen-ui/src/main/resources/pollen.properties trunk/todo.txt Log: correction recherche de sondages en cours + mails de rappel Modified: trunk/README.txt =================================================================== --- trunk/README.txt 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/README.txt 2009-08-19 15:48:01 UTC (rev 2736) @@ -39,6 +39,9 @@ # Répertoire des flux de syndication (Atom) feedDir=/tmp/pollen/feeds + + # Adresse du site (utilisée pour les emails de rappel) + siteUrl=http://www.site.org/pollen/ Pour une base PostgreSQL on aura : Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/business/PreventRuleManager.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/business/PreventRuleManager.java 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/business/PreventRuleManager.java 2009-08-19 15:48:01 UTC (rev 2736) @@ -33,6 +33,8 @@ */ public class PreventRuleManager { + /** Représente l'action qui ne fait rien. */ + public static final String NULL_ACTION = "nullAction"; /** Représente l'action qui écrit sur la sortie standard. */ public static final String PRINT_ACTION = "printAction"; /** Représente l'action qui envoi un email de notification. */ @@ -103,6 +105,20 @@ * @return true si la méthode à été exécutée, false sinon. */ public boolean execute(String scope, Integer value, Object data) { + + // Si la règle n'est pas active, on ne fait rien + if (!preventRule.isActive()) { + log.debug("Règle non active"); + return false; + } + + // Si la règle est à exécution unique, on la désactive + if (preventRule.isOneTime()) { + log.debug("Règle à exécution unique : désactivation"); + preventRule.setActive(false); + } + + // Si la règle est répétitive (exécution tous les n), on met à jour la valeur if (value != null && preventRule.isRepeated() && preventRule.getSensibility() != 0) { value = value % preventRule.getSensibility() @@ -133,6 +149,13 @@ } /** + * Action qui ne fait rien. + */ + public static void nullAction(Object data) { + // ne fait rien + } + + /** * Action qui écrit sur la sortie standard. */ public static void printAction(Object data) { Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPreventRuleConverter.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPreventRuleConverter.java 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/converters/DataPreventRuleConverter.java 2009-08-19 15:48:01 UTC (rev 2736) @@ -46,6 +46,8 @@ PreventRule ePreventRule) throws TopiaException { ePreventRule.setScope(preventRuleDTO.getScope()); ePreventRule.setSensibility(preventRuleDTO.getSensibility()); + ePreventRule.setActive(preventRuleDTO.isActive()); + ePreventRule.setOneTime(preventRuleDTO.isOneTime()); ePreventRule.setRepeated(preventRuleDTO.isRepeated()); ePreventRule.setMethod(preventRuleDTO.getMethod()); @@ -68,6 +70,8 @@ preventRuleDTO.setId(preventRule.getTopiaId()); preventRuleDTO.setScope(preventRule.getScope()); preventRuleDTO.setSensibility(preventRule.getSensibility()); + preventRuleDTO.setActive(preventRule.getActive()); + preventRuleDTO.setOneTime(preventRule.getOneTime()); preventRuleDTO.setRepeated(preventRule.getRepeated()); preventRuleDTO.setMethod(preventRule.getMethod()); Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PreventRuleDTO.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PreventRuleDTO.java 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/dto/PreventRuleDTO.java 2009-08-19 15:48:01 UTC (rev 2736) @@ -35,6 +35,10 @@ private int sensibility = 0; + private boolean active = true; + + private boolean oneTime = false; + private boolean repeated = false; private String method = ""; @@ -97,6 +101,22 @@ this.sensibility = sensibility; } + public boolean isActive() { + return active; + } + + public void setActive(boolean active) { + this.active = active; + } + + public boolean isOneTime() { + return oneTime; + } + + public void setOneTime(boolean oneTime) { + this.oneTime = oneTime; + } + public boolean isRepeated() { return repeated; } Modified: trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java =================================================================== --- trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/pollen-business/src/main/java/org/chorem/pollen/business/services/ServicePollImpl.java 2009-08-19 15:48:01 UTC (rev 2736) @@ -418,12 +418,14 @@ pollEntities = transaction .find("from " + Poll.class.getName() - + " as poll where poll.endDate is not null and poll.endDate > current_timestamp()"); + + " as poll where (poll.endDate is not null and poll.endDate > current_timestamp())" + + " and (poll.beginDate is null or poll.beginDate < current_timestamp())"); } else { pollEntities = transaction .find("from " + Poll.class.getName() - + " as poll where poll.endDate is null or poll.endDate > current_timestamp()"); + + " as poll where (poll.endDate is null or poll.endDate > current_timestamp())" + + " and (poll.beginDate is null or poll.beginDate < current_timestamp())"); } converter.setTransaction(transaction); Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/business/PreventRuleManagerTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/business/PreventRuleManagerTest.java 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/business/PreventRuleManagerTest.java 2009-08-19 15:48:01 UTC (rev 2736) @@ -92,4 +92,24 @@ assertFalse(manager.execute(1)); assertFalse(manager.execute(5)); } + + /** + * Test of execute method, of class PreventRuleManager. Using PRINT_ACTION + * oneTime execution. + */ + @Test + public void testPrintActionOneTime() { + PreventRuleDTO preventRule = new PreventRuleDTO("test", 2, false, + PreventRuleManager.PRINT_ACTION); + preventRule.setOneTime(true); + manager = new PreventRuleManager(preventRule); + + assertTrue(manager.execute(2)); + assertFalse(manager.execute(2)); + + preventRule.setActive(true); + + assertTrue(manager.execute(2)); + assertFalse(manager.execute(2)); + } } \ No newline at end of file Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceChoiceImplTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceChoiceImplTest.java 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServiceChoiceImplTest.java 2009-08-19 15:48:01 UTC (rev 2736) @@ -68,7 +68,7 @@ } /** - * Test of createChoice method, of class ChoiceImpl. + * Test of createChoice method, of class ServiceChoiceImpl. */ @Test public void testCreateChoice() { @@ -85,7 +85,7 @@ } /** - * Test of createChoices method, of class ChoiceImpl. + * Test of createChoices method, of class ServiceChoiceImpl. */ @Test public void testCreateChoices() { @@ -101,7 +101,7 @@ } /** - * Test of updateChoice method, of class ChoiceImpl. + * Test of updateChoice method, of class ServiceChoiceImpl. */ @Test public void testUpdateChoice() { @@ -117,7 +117,7 @@ } /** - * Test of deleteChoice method, of class ChoiceImpl. + * Test of deleteChoice method, of class ServiceChoiceImpl. */ @Test public void testDeleteChoice() { @@ -132,7 +132,7 @@ } /** - * Test of findChoiceById method, of class ChoiceImpl. + * Test of findChoiceById method, of class ServiceChoiceImpl. */ @Test public void testFindChoiceById() { @@ -147,7 +147,7 @@ } /** - * Test of selectChoices method, of class ChoiceImpl. + * Test of selectChoices method, of class ServiceChoiceImpl. */ @Test public void testSelectChoices() { Modified: trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java =================================================================== --- trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/pollen-business/src/test/java/org/chorem/pollen/business/services/ServicePollImplTest.java 2009-08-19 15:48:01 UTC (rev 2736) @@ -224,6 +224,12 @@ poll3.setEndDate(new Date(now.getTime() - 100000)); instance.createPoll(poll3); + // sondage pas commencé + PollDTO poll4 = new PollDTO(); + poll4.setTitle("Test_findRunningPolls4"); + poll4.setBeginDate(new Date(now.getTime() + 100000)); + instance.createPoll(poll4); + List<PollDTO> result1 = instance.findRunningPolls(true); List<PollDTO> result2 = instance.findRunningPolls(false); assertTrue(result2.size() > result1.size()); Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Chart.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Chart.java 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Chart.java 2009-08-19 15:48:01 UTC (rev 2736) @@ -52,10 +52,8 @@ * <pre> * Utilisation : * <t:chart width="210" height="190" values="choice" title="title" type="1"/> - * * - choice est une liste de chaînes représentant les labels et leur valeurs respectives. ({"val1", "20", "val2", "10"}...) * - type est le type de représentation du diagramme (1:PIE, 2:PIE3D...) - * * Pour généraliser à d'autres types de graphes il faudrait passer un JFreeChart : * Persist Parameter(required=true) * private JFreeChart _chart; Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FeedBack.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FeedBack.java 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/FeedBack.java 2009-08-19 15:48:01 UTC (rev 2736) @@ -36,7 +36,6 @@ * <pre> * Utilisation : * <t:feedback t:id="feedback"/> - * * @Component(id = "feedback") private FeedBack feedback; * feedback.addInfo("message d'info"); * feedback.addError("message d'erreur"); Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Image.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Image.java 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/components/Image.java 2009-08-19 15:48:01 UTC (rev 2736) @@ -43,7 +43,6 @@ * <pre> * Utilisation : * <t:image src="/img/image.png" /> - * * Pour afficher une image statique il est préférable d'utiliser : * <img src="${asset:context:img}/image.png" /> * </pre> Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/AppModule.java 2009-08-19 15:48:01 UTC (rev 2736) @@ -20,6 +20,7 @@ import org.apache.tapestry5.SymbolConstants; import org.apache.tapestry5.ioc.MappedConfiguration; +import org.apache.tapestry5.ioc.Messages; import org.apache.tapestry5.ioc.OrderedConfiguration; import org.apache.tapestry5.ioc.ServiceBinder; import org.apache.tapestry5.ioc.annotations.EagerLoad; @@ -28,6 +29,7 @@ import org.apache.tapestry5.ioc.services.RegistryShutdownHub; import org.apache.tapestry5.ioc.services.RegistryShutdownListener; import org.apache.tapestry5.ioc.services.SymbolProvider; +import org.apache.tapestry5.services.ComponentSource; import org.apache.tapestry5.services.Request; import org.apache.tapestry5.services.RequestFilter; import org.apache.tapestry5.services.RequestHandler; @@ -71,10 +73,6 @@ binder.bind(ServicePollAccount.class); binder.bind(ServiceResults.class); binder.bind(ServiceVote.class); - - // UI specific services - //binder.bind(Configuration.class); - //binder.bind(BackgroundWorker.class).eagerLoad(); } public static void contributeApplicationDefaults( @@ -161,14 +159,14 @@ * This is the BackgroundWorker service definition. It build the service * giving a Messages object for localization in the service. */ - /*@EagerLoad + @EagerLoad public static BackgroundWorker buildBackgroundWorker( ComponentSource componentSource, Configuration configuration, ServicePoll servicePoll) { Messages messages = componentSource.getPage("LocalMessages") .getComponentResources().getMessages(); return new BackgroundWorkerImpl(messages, configuration, servicePoll); - }*/ + } /** * Make configuration from a Properties file available as symbols. Modified: trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java =================================================================== --- trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/pollen-ui/src/main/java/org/chorem/pollen/ui/services/BackgroundWorkerImpl.java 2009-08-19 15:48:01 UTC (rev 2736) @@ -32,6 +32,8 @@ import org.chorem.pollen.business.dto.PreventRuleDTO; import org.chorem.pollen.business.dto.VotingListDTO; import org.chorem.pollen.business.services.ServicePoll; +import org.chorem.pollen.business.services.ServicePreventRule; +import org.chorem.pollen.business.services.ServicePreventRuleImpl; /** * Implémentation du service BackgroundWorker. @@ -74,7 +76,13 @@ * Lancement des tâches en arrière-plan. */ public void executeTasks() { - timer.schedule(new MailingTask(), 10000, 10000); + if ("".equals(conf.getProperty("siteUrl"))) { + log + .warn("No property siteUrl. Reminder emails would not contain it"); + } + + // Exécution de la tâche toutes les 10 min + timer.schedule(new MailingTask(), 600000, 600000); } /** @@ -97,6 +105,8 @@ // Parcours des preventRules de chaque sondage // envoi d'un email si endDate-nowDate <= preventRuleSensibility if (poll.getEndDate() != null) { + + // timeValue = endDate-nowDate Long timeValue = poll.getEndDate().getTime() - now.getTime(); @@ -107,9 +117,6 @@ } // envoi des mails avec une sensibilité de l'ordre de l'heure - if (log.isInfoEnabled()) { - log.info("Sending reminder emails..."); - } sendMailNotification(poll, timeValue / 3600000); } } @@ -130,21 +137,37 @@ data.put("from", conf.getProperty("email_from")); // Mails aux votants - for (VotingListDTO list : poll.getVotingListDTOs()) { - for (PollAccountDTO account : list.getPollAccountDTOs()) { - if (account.getEmail() != null) { - data.put("to", account.getEmail()); - data.put("title", messages.format("reminderEmail_subject", - poll.getTitle())); - data.put("msg", messages.format("reminderEmail_msg", poll - .getTitle(), account.getVotingId(), voteURL)); + for (PreventRuleDTO rule : poll.getPreventRuleDTOs()) { + if (rule.isActive()) { + Boolean hasRun = false; + PreventRuleManager manager = new PreventRuleManager(rule); + for (VotingListDTO list : poll.getVotingListDTOs()) { + for (PollAccountDTO account : list.getPollAccountDTOs()) { + if (account.getEmail() != null) { + String accountVoteURL = voteURL + ":" + + account.getAccountId(); - for (PreventRuleDTO rule : poll.getPreventRuleDTOs()) { - PreventRuleManager manager = new PreventRuleManager( - rule); - manager.execute("rappel", timeValue.intValue(), data); + data.put("to", account.getEmail()); + data.put("title", messages.format( + "reminderEmail_subject", poll.getTitle())); + data.put("msg", messages.format( + "reminderEmail_msg", poll.getTitle(), + account.getVotingId(), accountVoteURL)); + + // Exécution de la règle avec une valeur +1 + // Sensibilité de 2h : 2h05 KO, 1h55 OK + hasRun = manager.execute("rappel", timeValue + .intValue() + 1, data); + } } } + + // désactivation de la règle de rappel pour éviter qu'elle soit réexécutée + if (hasRun) { + rule.setActive(false); + ServicePreventRule spr = new ServicePreventRuleImpl(); + spr.updatePreventRule(rule); + } } } } Modified: trunk/pollen-ui/src/main/resources/pollen.properties =================================================================== --- trunk/pollen-ui/src/main/resources/pollen.properties 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/pollen-ui/src/main/resources/pollen.properties 2009-08-19 15:48:01 UTC (rev 2736) @@ -46,8 +46,8 @@ ## Répertoire des flux de syndication (Atom) feedDir=/tmp/pollen/feeds -## Adresse du site -siteUrl=http://localhost:8090/pollen-ui/ +## Adresse du site (utilisée pour les emails de rappel) +siteUrl= ## Version de l'application version=${project.version} \ No newline at end of file Modified: trunk/todo.txt =================================================================== --- trunk/todo.txt 2009-08-19 08:50:33 UTC (rev 2735) +++ trunk/todo.txt 2009-08-19 15:48:01 UTC (rev 2736) @@ -1,6 +1,5 @@ TODO -envoi emails de rappel amélioration des tests