Author: fdesbois Date: 2010-04-02 09:12:15 +0000 (Fri, 02 Apr 2010) New Revision: 411 Removed: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoGlobal.java trunk/wao-business/src/test/java/fr/ifremer/wao/WaoGlobalTest.java Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/WaoUtils.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/BoatImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/BoatInfosImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleMonthImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties trunk/wao-business/src/main/xmi/wao.zargo trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java Log: - Rename methods to manage transaction and error (treateError, closeTransaction) - Use serviceUser for createDefaultAdmin method (needed to start application) - Use contributeToRegistryStartup to start application from WaoManager in tapestry Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2010-04-02 09:12:15 UTC (rev 411) @@ -23,6 +23,7 @@ package fr.ifremer.wao; import fr.ifremer.wao.io.ImportHelper; +import fr.ifremer.wao.service.ServiceUser; import java.nio.charset.Charset; import java.util.Date; import java.util.Locale; @@ -130,7 +131,7 @@ loadConfiguration(conf); } catch (ArgumentsParserException eee) { - doCatch(eee, n_("wao.error.context.parse"), DEFAULT_FILENAME); + treateError(eee, n_("wao.error.context.parse"), DEFAULT_FILENAME); } } @@ -195,9 +196,10 @@ * - Create default admin if needed (this will load the topiaRootContext). * </pre> * + * @param serviceUser to create default admin if needed */ @Override - public void start() { + public void start(ServiceUser serviceUser) { try { if (log.isInfoEnabled()) { log.info("Start Wao"); @@ -218,14 +220,14 @@ ImportHelper.setContext(this); // Create the default admin in database - WaoGlobal.createDefaultAdmin(this); + serviceUser.createDefaultAdmin(); if (log.isInfoEnabled()) { log.info("wao is started !"); } } catch (Exception eee) { - doCatch(eee, n_("wao.error.context.start")); + treateError(eee, n_("wao.error.context.start")); } } @@ -240,7 +242,7 @@ } getTopiaRootContext().closeContext(); } catch (Exception eee) { - doCatch(eee, n_("wao.error.context.stop")); + treateError(eee, n_("wao.error.context.stop")); } } @@ -249,7 +251,7 @@ return TopiaContextFactory.getContext( getConfiguration().getOptions()); } catch (TopiaNotFoundException eee) { - doCatch(eee, n_("wao.error.context.getRootContext")); + treateError(eee, n_("wao.error.context.getRootContext")); } return null; } @@ -303,13 +305,13 @@ // } @Override - public void doCatch(Exception eee, String message, Object... args) + public void treateError(Exception eee, String message, Object... args) throws WaoException { - doCatch(null, eee, message, args); + treateError(null, eee, message, args); } @Override - public void doCatch(TopiaContext transaction, Exception eee, + public void treateError(TopiaContext transaction, Exception eee, String message, Object... args) throws WaoException { if (log.isDebugEnabled()) { log.debug(_(message, args),eee); @@ -325,7 +327,7 @@ //transaction.closeContext(); } } catch (TopiaException eeee) { - doCatch(eeee, n_("wao.error.context.rollback")); + treateError(eeee, n_("wao.error.context.rollback")); } //} if (eee instanceof SQLGrammarException && log.isErrorEnabled()) { @@ -338,7 +340,7 @@ } @Override - public void doFinally(TopiaContext transaction) { + public void closeTransaction(TopiaContext transaction) { if (transaction != null) { try { transaction.closeContext(); @@ -346,7 +348,7 @@ // if (log.isErrorEnabled()) { // log.error(_("wao.error.context.close"), eee); // } - doCatch(eee, n_("wao.error.context.close")); + treateError(eee, n_("wao.error.context.close")); } } } Deleted: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoGlobal.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoGlobal.java 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoGlobal.java 2010-04-02 09:12:15 UTC (rev 411) @@ -1,102 +0,0 @@ -/* - * *##% - * Wao :: Business - * Copyright (C) 2009 - 2010 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 Lesser 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>. - * ##%* - */ - -package fr.ifremer.wao; - -import fr.ifremer.wao.bean.UserRole; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.CompanyDAO; -import fr.ifremer.wao.entity.WaoUser; -import fr.ifremer.wao.entity.WaoUserDAO; -import org.nuiton.i18n.I18n; -import org.nuiton.topia.TopiaContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * WaoGlobal - * - * Created: 27 nov. 2009 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -public class WaoGlobal { - - private static final Logger log = LoggerFactory.getLogger(WaoGlobal.class); - - /** - * Create a default admin user if no user already exist. - * - * @throws WaoException - */ - static void createDefaultAdmin(WaoContextImplementor context) - throws WaoException { - TopiaContext transaction = null; - try { - transaction = context.beginTransaction(); - - WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); - - long nbUsers = dao.size(); - - if (log.isInfoEnabled()) { - log.info("Nb existing users : " + nbUsers); - } - - if (nbUsers == 0) { - - CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); - - if (log.isInfoEnabled()) { - log.info("Create first admin : login=\"admin\" / password=\"password\""); - } - - Company company = companyDAO.create(Company.ACTIVE, false, Company.NAME, "ADMIN"); - - String password = context.encodeString("password"); - - WaoUser user = dao.create( - WaoUser.ROLE, UserRole.ADMIN.ordinal(), - WaoUser.ACTIVE, true, - WaoUser.LOGIN, "admin", - WaoUser.PASSWORD, password, - WaoUser.FIRST_NAME, "Super", - WaoUser.LAST_NAME, "Admin"); - user.setCompany(company); - - transaction.commitTransaction(); - } - - //transaction.closeContext(); - } catch (Exception eee) { - context.doCatch(transaction, eee, - I18n.n_("wao.error.global.createDefaultAdmin")); - //Error during database initialization", eee); - } finally { - context.doFinally(transaction); - } - } - -} Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoUtils.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoUtils.java 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoUtils.java 2010-04-02 09:12:15 UTC (rev 411) @@ -88,8 +88,8 @@ * * @param transaction */ - public static void doFinally(TopiaContext transaction) { - context.doFinally(transaction); + public static void closeTransaction(TopiaContext transaction) { + context.closeTransaction(transaction); } /** @@ -101,9 +101,9 @@ * @param args * @throws WaoException */ - public static void doCatch(TopiaContext transaction, + public static void treateError(TopiaContext transaction, Exception eee, String message, Object... args) throws WaoException { - context.doCatch(transaction, eee, message, args); + context.treateError(transaction, eee, message, args); } /** @@ -114,9 +114,9 @@ * @param args * @throws WaoException */ - public static void doCatch(Exception eee, String message, + public static void treateError(Exception eee, String message, Object... args) throws WaoException { - context.doCatch(eee, message, args); + context.treateError(eee, message, args); } /** Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/BoatImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/BoatImpl.java 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/BoatImpl.java 2010-04-02 09:12:15 UTC (rev 411) @@ -79,11 +79,11 @@ } } catch (Exception eee) { - WaoUtils.doCatch(transaction, eee, + WaoUtils.treateError(transaction, eee, I18n.n_("wao.error.boat.canCreateContact"), company.getName(), getName(), getImmatriculation()); } finally { - WaoUtils.doFinally(transaction); + WaoUtils.closeTransaction(transaction); } } return result; @@ -112,10 +112,10 @@ result = query.executeCount(transaction); } catch (Exception eee) { - WaoUtils.doCatch(transaction, eee, + WaoUtils.treateError(transaction, eee, I18n.n_("wao.error.boat.getNbBoarding"), fromDate); } finally { - WaoUtils.doFinally(transaction); + WaoUtils.closeTransaction(transaction); } return result; } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/BoatInfosImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/BoatInfosImpl.java 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/BoatInfosImpl.java 2010-04-02 09:12:15 UTC (rev 411) @@ -74,11 +74,11 @@ result = query.executeCount(); } catch (Exception eee) { - WaoUtils.doCatch(transaction, eee, + WaoUtils.treateError(transaction, eee, I18n.n_("wao.error.boatInfos.getNbBoardingForCompany"), fromDate, getCompany().getName()); } finally { - WaoUtils.doFinally(transaction); + WaoUtils.closeTransaction(transaction); } return result; } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleMonthImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleMonthImpl.java 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleMonthImpl.java 2010-04-02 09:12:15 UTC (rev 411) @@ -81,11 +81,11 @@ transaction.commitTransaction(); //transaction.closeContext(); } catch (Exception eee) { - WaoUtils.doCatch(transaction, eee, + WaoUtils.treateError(transaction, eee, I18n.n_("wao.error.sampleMonth.addRealTideTime"), formatMonth(), getSampleRow().getCode()); } finally { - WaoUtils.doFinally(transaction); + WaoUtils.closeTransaction(transaction); } } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java 2010-04-02 09:12:15 UTC (rev 411) @@ -320,11 +320,11 @@ // WaoContext.PROP_EMAIL_FROM } catch (Exception eee) { - WaoUtils.doCatch(transaction, eee, + WaoUtils.treateError(transaction, eee, I18n.n_("wao.error.sampleRow.saveSampleRowLog"), rowLog.getAuthor().getFullName()); } finally { - WaoUtils.doFinally(transaction); + WaoUtils.closeTransaction(transaction); } } Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-04-02 09:12:15 UTC (rev 411) @@ -355,6 +355,44 @@ return user; } + @Override + protected void executeCreateDefaultAdmin(TopiaContext transaction) + throws Exception { + WaoUserDAO dao = WaoDAOHelper.getWaoUserDAO(transaction); + long nbUsers = dao.size(); + if (log.isInfoEnabled()) { + log.info("Nb existing users : " + nbUsers); + } + + if (nbUsers == 0) { + + CompanyDAO companyDAO = WaoDAOHelper.getCompanyDAO(transaction); + + if (log.isInfoEnabled()) { + log.info("Create first admin : login=\"admin\" / " + + "password=\"password\""); + } + + Company company = companyDAO.create( + Company.ACTIVE, false, Company.NAME, "ADMIN"); + + String password = context.encodeString("password"); + + WaoUser user = dao.create( + WaoUser.ROLE, UserRole.ADMIN.ordinal(), + WaoUser.ACTIVE, true, + WaoUser.LOGIN, "admin", + WaoUser.PASSWORD, password, + WaoUser.FIRST_NAME, "Super", + WaoUser.LAST_NAME, "Admin"); + user.setCompany(company); + + transaction.commitTransaction(); + } + } + + + } Modified: trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties =================================================================== --- trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties 2010-04-02 09:12:15 UTC (rev 411) @@ -55,6 +55,7 @@ wao.error.serviceSynthesis.getDataSampling= wao.error.serviceSynthesis.getNonComplianceBoardingIndicator= wao.error.serviceUser.connect= +wao.error.serviceUser.createDefaultAdmin= wao.error.serviceUser.createUpdateCompany= wao.error.serviceUser.createUpdateUser= wao.error.serviceUser.deleteUser= Modified: trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties =================================================================== --- trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-04-02 09:12:15 UTC (rev 411) @@ -7,7 +7,6 @@ wao.error.context.rollback=Une erreur est survenue pendant l'annulation de la transaction courante wao.error.context.start=Une erreur est survenue pendant le d\u00E9marrage de l'application wao.error.context.stop=Une erreur est survenue pendant la fermeture de l'application -wao.error.global.createDefaultAdmin= wao.error.sampleMonth.addRealTideTime=Impossible d'enregistrer le nombre de mar\u00E9es r\u00E9els pour le mois de %1$s [ligne \: %2$s] wao.error.sampleRow.saveSampleRowLog=Impossible d'enregistrer le commentaire \u00E9crit par %1$s wao.error.serviceBoat.createUpdateCompanyBoatInfos=Impossible de cr\u00E9er ou modifier les informations li\u00E9s au navire %1$d pour la soci\u00E9t\u00E9 %2$s @@ -55,6 +54,7 @@ wao.error.serviceSynthesis.getDataSampling=Impossible de r\u00E9cup\u00E9rer les donn\u00E9es pour le graphique dynamique des efforts de mar\u00E9es wao.error.serviceSynthesis.getNonComplianceBoardingIndicator=Impossible de r\u00E9cup\u00E9rer l'indicateur de non respect du nombre d'observateurs embarqu\u00E9s wao.error.serviceUser.connect=Une erreur est survenue lors de la demande de connexion +wao.error.serviceUser.createDefaultAdmin=Impossible de cr\u00E9er l'administrateur par d\u00E9faut wao.error.serviceUser.createUpdateCompany=Impossible de cr\u00E9er ou de mettre \u00E0 jour la soci\u00E9t\u00E9 wao.error.serviceUser.createUpdateUser=Impossible de cr\u00E9er ou de mettre \u00E0 jour l'utilisateur wao.error.serviceUser.deleteUser=Impossible de supprimer l'utilisateur Modified: trunk/wao-business/src/main/xmi/wao.zargo =================================================================== (Binary files differ) Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java 2010-04-02 09:12:15 UTC (rev 411) @@ -85,9 +85,9 @@ Calendar calendar = new GregorianCalendar(2009, 9, 23); context.setCurrentDate(calendar.getTime()); - context.start(); + context.start(getServiceUser()); } catch (Exception eee) { - context.doCatch(eee, "Error during loadConfiguration from " + + context.treateError(eee, "Error during loadConfiguration from " + "'WaoTest.properties' file"); } } @@ -99,7 +99,7 @@ try { context.getTopiaRootContext().clear(true); } catch (TopiaException eee) { - context.doCatch(eee, "Error during clear database"); + context.treateError(eee, "Error during clear database"); } } Deleted: trunk/wao-business/src/test/java/fr/ifremer/wao/WaoGlobalTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/WaoGlobalTest.java 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/WaoGlobalTest.java 2010-04-02 09:12:15 UTC (rev 411) @@ -1,104 +0,0 @@ -/* - * *##% - * Wao :: Business - * Copyright (C) 2009 - 2010 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 Lesser 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>. - * ##%* - */ - -package fr.ifremer.wao; - -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.WaoUser; -import fr.ifremer.wao.service.ServiceUserImpl; -import fr.ifremer.wao.service.ServiceUser; -import java.util.List; -import static org.junit.Assert.*; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * WaoGlobalTest - * - * Created: 27 nov. 2009 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ -public class WaoGlobalTest { - - private static TestManager manager; - - private static final Logger log = LoggerFactory.getLogger(WaoGlobalTest.class); - - public WaoGlobalTest() { - manager = new TestManager(); - } - - @BeforeClass - public static void setUpClass() throws Exception { - - } - - @AfterClass - public static void tearDownClass() throws Exception { - - } - - @Before - public void setUp() { - manager.start(); - } - - @After - public void tearDown() { - manager.stop(); - } - - /** - * Test of initApplication method, of class WaoGlobal. - */ - @Test - public void testCreateDefaultAdmin() throws Exception { - System.out.println("createDefaultAdmin"); - - WaoGlobal.createDefaultAdmin(manager.getContext()); - - ServiceUser serviceUser = manager.getServiceUser(); - - List<Company> companies = serviceUser.getCompanies(false); - assertEquals(1, companies.size()); - - Company company = companies.get(0); - assertEquals("ADMIN", company.getName()); - - List<WaoUser> users = serviceUser.getUsersByCompany(company); - assertEquals(1, users.size()); - - WaoUser user = users.get(0); - assertEquals("admin", user.getLogin()); - - } - -} Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java =================================================================== --- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceUserImplTest.java 2010-04-02 09:12:15 UTC (rev 411) @@ -159,4 +159,29 @@ Assert.assertEquals(2, users.size()); } + /** + * Test of initApplication method, of class WaoGlobal. + */ + @Test + public void testCreateDefaultAdmin() throws Exception { + logger.info("## START ## createDefaultAdmin"); + + service.createDefaultAdmin(); + + ServiceUser serviceUser = manager.getServiceUser(); + + List<Company> companies = serviceUser.getCompanies(false); + Assert.assertEquals(1, companies.size()); + + Company company = companies.get(0); + Assert.assertEquals("ADMIN", company.getName()); + + List<WaoUser> users = serviceUser.getUsersByCompany(company); + Assert.assertEquals(1, users.size()); + + WaoUser user = users.get(0); + Assert.assertEquals("admin", user.getLogin()); + + } + } \ No newline at end of file Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java 2010-04-02 09:12:15 UTC (rev 411) @@ -26,7 +26,9 @@ import java.io.IOException; import org.apache.tapestry5.SymbolConstants; +import org.apache.tapestry5.annotations.Log; import org.apache.tapestry5.ioc.MappedConfiguration; +import org.apache.tapestry5.ioc.OrderedConfiguration; import org.apache.tapestry5.ioc.ServiceBinder; import org.apache.tapestry5.ioc.annotations.EagerLoad; import org.apache.tapestry5.ioc.services.RegistryShutdownHub; @@ -51,6 +53,13 @@ binder.bind(ContactModelFactory.class); } + /** + * Use EagerLoad to build manager at startup. The manager will control + * the application lifecycle (start and stop). + * + * @param hub to register the manager in the tapestry registry shutdown + * @return the new instance of WaoManager + */ @EagerLoad public WaoManager buildWaoManager(RegistryShutdownHub hub) { WaoManager manager = new WaoManager(new WaoContextImpl()); @@ -58,6 +67,23 @@ return manager; } + /** + * Execute WaoManager when registry startup. + * The manager will be instantiated using + * {@link #buildWaoManager(org.apache.tapestry5.ioc.services.RegistryShutdownHub) }. + * The serviceUser is needed to start the application. + * + * @param configuration to add the manager to registry startup + * @param manager to launch at startup + * @param serviceUser needed for manager start + */ + public static void contributeRegistryStartup( + OrderedConfiguration<Runnable> configuration, + WaoManager manager, ServiceUser serviceUser) { + manager.setServiceUser(serviceUser); + configuration.add("WaoStartup", manager); + } + public ServiceNews buildServiceNews(WaoManager manager) { ServiceNewsImpl instance = new ServiceNewsImpl(); instance.setContext(manager.getContext()); @@ -175,10 +201,6 @@ // return listener; // } -// public static void contributeRegistryStartup(OrderedConfiguration<Runnable> configuration) { -// configuration.add("WaoStartup", new WaoManager()); -// } - /** * Used to instanciate SessionState WaoUser when session expires. * Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java =================================================================== --- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java 2010-04-01 18:28:32 UTC (rev 410) +++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/WaoManager.java 2010-04-02 09:12:15 UTC (rev 411) @@ -23,6 +23,7 @@ import fr.ifremer.wao.WaoContextImplementor; import fr.ifremer.wao.WaoProperty; +import fr.ifremer.wao.service.ServiceUser; import java.util.Date; import org.apache.tapestry5.ioc.services.RegistryShutdownListener; import org.nuiton.util.ApplicationConfig; @@ -42,24 +43,53 @@ */ public class WaoManager implements Runnable, RegistryShutdownListener { - private static final Logger log = LoggerFactory.getLogger(WaoManager.class); + private static final Logger log = + LoggerFactory.getLogger(WaoManager.class); private WaoContextImplementor context; + private ServiceUser serviceUser; + + /** + * Constructor of WaoManager. It needs the WaoContext to start and stop. + * + * @param context used to manage application lifecycle + */ public WaoManager(WaoContextImplementor context) { this.context = context; - this.context.start(); } + /** + * ServiceUser is needed to start the application. + * + * @param serviceUser + * @see fr.ifremer.wao.WaoContext#start(fr.ifremer.wao.service.ServiceUser) + */ + void setServiceUser(ServiceUser serviceUser) { + this.serviceUser = serviceUser; + } + + /** + * Called to start the application. + */ @Override public void run() { + context.start(serviceUser); } + /** + * Called to stop the application + */ @Override public void registryDidShutdown() { context.stop(); } + /** + * Context to inject in new service instances. + * + * @return the WaoContext of the application + */ WaoContextImplementor getContext() { return context; }