Author: fdesbois Date: 2009-12-13 16:15:45 +0000 (Sun, 13 Dec 2009) New Revision: 119 Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerContext.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityCalendarImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityMonthImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityProfessionImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImport.java trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImportTest.java trunk/suiviobsmer-business/src/test/resources/import/activity.csv Removed: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerUtils.java Modified: trunk/pom.xml trunk/suiviobsmer-business/pom.xml trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerGlobal.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerRunnerImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/BoatImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/CompanyImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ProgramImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/UserImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceReferentialImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceUserImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceBoatMock.java trunk/suiviobsmer-business/src/main/resources/SuiviObsmer.properties trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/SuiviObsmerUtilsTest.java trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/business/SuiviObsmerRunnerTest.java trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/SampleRowImplTest.java trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImplTest.java trunk/suiviobsmer-business/src/test/resources/TopiaContextSuiviObsmer.properties trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Administration.java Log: - Refactor SuiviObsmerUtils by SuiviObsmerContext more appropriate - Add import for ActivityCalendar (thread in background) in Business module only Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/pom.xml 2009-12-13 16:15:45 UTC (rev 119) @@ -31,6 +31,11 @@ <version>2.4</version> </dependency> <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>1.4</version> + </dependency> + <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.8.0</version> Modified: trunk/suiviobsmer-business/pom.xml =================================================================== --- trunk/suiviobsmer-business/pom.xml 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/pom.xml 2009-12-13 16:15:45 UTC (rev 119) @@ -23,6 +23,10 @@ <artifactId>commons-lang</artifactId> </dependency> <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> @@ -88,23 +92,37 @@ <version>${eugene.version}</version> <executions> <execution> + <id>Zargo to object model</id> <phase>generate-sources</phase> <configuration> + <modelType>objectmodel</modelType> + <includes> + <include>zargo</include> + </includes> + <fullPackagePath>fr.ifremer.suiviobsmer</fullPackagePath> + <!--<outputDirectory>target/generated-sources-zargo2ObjectModel</outputDirectory>--> + </configuration> + <goals> + <goal>generate-model-files</goal> + </goals> + </execution> + <execution> + <id>ObjectModel to Java</id> + <phase>generate-sources</phase> + <configuration> <reader>org.nuiton.eugene.ObjectModelReader</reader> <includes>**/*.objectmodel</includes> <templates>org.nuiton.topia.generator.TopiaMetaGenerator,org.nuiton.topia.generator.ObjectModelTransformerToJavaInterface,org.nuiton.topia.generator.ObjectModelTransformerToJavaBean</templates> - <extractedPackages>fr.ifremer.suiviobsmer</extractedPackages> - <fullPackagePath>fr.ifremer.suiviobsmer</fullPackagePath> + <!--<extractedPackages>fr.ifremer.suiviobsmer</extractedPackages> + <fullPackagePath>fr.ifremer.suiviobsmer</fullPackagePath>--> <defaultPackage>fr.ifremer.suiviobsmer</defaultPackage> <generatedPackages>fr.ifremer.suiviobsmer</generatedPackages> </configuration> <goals> - <goal>zargo2xmi</goal> - <goal>xmi2objectmodel</goal> <goal>generate</goal> </goals> </execution> - <execution> + <!--<execution> <id>generate-statemodel</id> <phase>generate-test-sources</phase> <configuration> @@ -118,7 +136,7 @@ <goal>zargo2xmi</goal> <goal>xmi2statemodel</goal> </goals> - </execution> + </execution>--> </executions> </plugin> </plugins> Copied: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerContext.java (from rev 118, trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerUtils.java) =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerContext.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerContext.java 2009-12-13 16:15:45 UTC (rev 119) @@ -0,0 +1,185 @@ +/** + * *##% + * SuiviObsmer Business + * Copyright (C) 2009 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.suiviobsmer; + + +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Date; +import java.util.Properties; +import java.util.Random; +import org.apache.commons.lang.StringUtils; +import org.hibernate.exception.SQLGrammarException; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaId; +import org.nuiton.util.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ContextUtilSuiviObsmer.java + * + * Created on 2009-11-23 + * + * @author fdesbois + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class SuiviObsmerContext { + + private static final Logger log = LoggerFactory.getLogger(SuiviObsmerContext.class); + + public static final String PROP_FILENAME_LOG_ACTIVITY = "suiviobsmer.log.activityCalendar"; + + private static SuiviObsmerRunner runner; + + private static boolean activityCalendarImport; + + public static void setRunner(SuiviObsmerRunner run) { + runner = run; + } + + public static Date getCurrentDate() { + return runner.currentDate(); + } + + public static String getProperty(String key) { + return runner.configuration().getProperty(key); + } + + public static TopiaContext getTopiaRootContext() throws SuiviObsmerException { + if (runner.configuration() == null) { + throw new SuiviObsmerException("Configuration must be set before initializing context"); + } + try { + return TopiaContextFactory.getContext(runner.configuration()); + } catch (TopiaNotFoundException eee) { + serviceException(null, eee.getMessage(), eee); + } + return null; + } + + public static void setActivityCalendarImport(boolean value) { + activityCalendarImport = value; + } + + public static boolean isActivityCalendarImportRun() { + return activityCalendarImport; + } + + /** + * Property file loading + * @param filename + * @return + * @throws java.net.URISyntaxException + * @throws java.io.IOException + */ + public static Properties loadConfiguration(String filename) + throws URISyntaxException, IOException { + Properties props = new Properties(); + URL url = Resource.getURL(filename); + if (log.isDebugEnabled()) { + log.debug(url.toString()); + } + props.load(url.openStream()); + return props; + //return PropertiesLoader.loadPropertiesFile(filename); + } + + /*public static String convertId(String id) { + return Convert.toWebId(id); + }*/ + + public static void serviceException(TopiaContext transaction, String message, Exception eee) throws SuiviObsmerException { + if (log.isErrorEnabled()) { + log.error("An error occured",eee); + } + if (!(eee instanceof SuiviObsmerException)) { + if (!(eee instanceof TopiaException)) { + try { + if (transaction != null && !transaction.isClosed()) { + if (log.isInfoEnabled()) { + log.info("Saving annulation : Transaction rollback"); + } + transaction.rollbackTransaction(); + transaction.closeContext(); + } + } catch (TopiaException eeee) { + throw new SuiviObsmerException("Fatal topia error when close context", eeee); + } + } + if (eee instanceof SQLGrammarException) { + if (log.isErrorEnabled()) { + log.error("SQL executed with error : " + ((SQLGrammarException)eee).getSQL()); + } + } + throw new SuiviObsmerException(message,eee); + } else { + throw (SuiviObsmerException)eee; + } + } + + /** + * Generate a random string of "length" character alphanumeric. + * @param length number of characters for the final string + * @return a String of "length" character + */ + public static String createRandomString(int length) { + Random random = new Random(); + StringBuilder sb = new StringBuilder(); + while (sb.length() < length) { + sb.append(Integer.toHexString(random.nextInt())); + } + return sb.toString(); + } + + public static String encodeString(String string) { + return string; + } + + public static String convertId(String topiaId) { + if (topiaId != null && !topiaId.isEmpty()) { + int index = topiaId.indexOf("#"); + String id = topiaId.replace('#', 'K'); + return id.substring(index); + } + return ""; + } + + public static <E extends TopiaEntity> boolean prepareTopiaId(Class<E> entityClass, E entity) { + String topiaId = entity.getTopiaId(); + if (StringUtils.isEmpty(entity.getTopiaId())) { + topiaId = TopiaId.create(entityClass); + entity.setTopiaId(topiaId); + return true; + } + return false; + } +} Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerGlobal.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerGlobal.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerGlobal.java 2009-12-13 16:15:45 UTC (rev 119) @@ -50,7 +50,7 @@ */ static void createDefaultAdmin() throws SuiviObsmerException { try { - TopiaContext transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + TopiaContext transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); UserDAO dao = SuiviObsmerModelDAOHelper.getUserDAO(transaction); @@ -70,7 +70,7 @@ Company company = companyDAO.create(Company.ACTIVE, false, Company.NAME, "ADMIN"); - String password = SuiviObsmerUtils.encodeString("password"); + String password = SuiviObsmerContext.encodeString("password"); User user = dao.create( User.ADMIN, true, @@ -87,7 +87,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(null, "Error during database initialization", eee); + SuiviObsmerContext.serviceException(null, "Error during database initialization", eee); } } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerRunnerImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerRunnerImpl.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerRunnerImpl.java 2009-12-13 16:15:45 UTC (rev 119) @@ -55,10 +55,10 @@ _configuration.setProperty("topia.persistence.classes", SuiviObsmerModelDAOHelper.getImplementationClassesAsString()); - SuiviObsmerUtils.setRunner(this); + SuiviObsmerContext.setRunner(this); SuiviObsmerGlobal.createDefaultAdmin(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(null, "Error during loadConfiguration from " + + SuiviObsmerContext.serviceException(null, "Error during loadConfiguration from " + "'TopiaContextSuiviObsmer.properties' file", eee); } } @@ -66,9 +66,9 @@ @Override public void stop() throws SuiviObsmerException { try { - SuiviObsmerUtils.getTopiaRootContext().closeContext(); + SuiviObsmerContext.getTopiaRootContext().closeContext(); } catch (TopiaException eee) { - SuiviObsmerUtils.serviceException(null, "Error when closing Topia root context", eee); + SuiviObsmerContext.serviceException(null, "Error when closing Topia root context", eee); } } Deleted: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerUtils.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerUtils.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerUtils.java 2009-12-13 16:15:45 UTC (rev 119) @@ -1,169 +0,0 @@ -/** - * *##% - * SuiviObsmer Business - * Copyright (C) 2009 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.suiviobsmer; - - -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.Date; -import java.util.Properties; -import java.util.Random; -import org.apache.commons.lang.StringUtils; -import org.hibernate.exception.SQLGrammarException; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaContextFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaNotFoundException; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaId; -import org.nuiton.util.Resource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * ContextUtilSuiviObsmer.java - * - * Created on 2009-11-23 - * - * @author fdesbois - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class SuiviObsmerUtils { - - private static final Logger log = LoggerFactory.getLogger(SuiviObsmerUtils.class); - - private static SuiviObsmerRunner runner; - - public static void setRunner(SuiviObsmerRunner run) { - runner = run; - } - - public static TopiaContext getTopiaRootContext() throws SuiviObsmerException { - if (runner.configuration() == null) { - throw new SuiviObsmerException("Configuration must be set before initializing context"); - } - try { - return TopiaContextFactory.getContext(runner.configuration()); - } catch (TopiaNotFoundException eee) { - serviceException(null, eee.getMessage(), eee); - } - return null; - } - - public static Date getCurrentDate() { - return runner.currentDate(); - } - - /** - * Property file loading - * @param filename - * @return - * @throws java.net.URISyntaxException - * @throws java.io.IOException - */ - public static Properties loadConfiguration(String filename) - throws URISyntaxException, IOException { - Properties props = new Properties(); - URL url = Resource.getURL(filename); - if (log.isDebugEnabled()) { - log.debug(url.toString()); - } - props.load(url.openStream()); - return props; - //return PropertiesLoader.loadPropertiesFile(filename); - } - - /*public static String convertId(String id) { - return Convert.toWebId(id); - }*/ - - public static void serviceException(TopiaContext transaction, String message, Exception eee) throws SuiviObsmerException { - if (log.isErrorEnabled()) { - log.error("An error occured",eee); - } - if (!(eee instanceof SuiviObsmerException)) { - if (!(eee instanceof TopiaException)) { - try { - if (transaction != null && !transaction.isClosed()) { - if (log.isInfoEnabled()) { - log.info("Saving annulation : Transaction rollback"); - } - transaction.rollbackTransaction(); - transaction.closeContext(); - } - } catch (TopiaException eeee) { - throw new SuiviObsmerException("Fatal topia error when close context", eeee); - } - } - if (eee instanceof SQLGrammarException) { - if (log.isErrorEnabled()) { - log.error("SQL executed with error : " + ((SQLGrammarException)eee).getSQL()); - } - } - throw new SuiviObsmerException(message,eee); - } else { - throw (SuiviObsmerException)eee; - } - } - - /** - * Generate a random string of "length" character alphanumeric. - * @param length number of characters for the final string - * @return a String of "length" character - */ - public static String createRandomString(int length) { - Random random = new Random(); - StringBuilder sb = new StringBuilder(); - while (sb.length() < length) { - sb.append(Integer.toHexString(random.nextInt())); - } - return sb.toString(); - } - - public static String encodeString(String string) { - return string; - } - - public static String convertId(String topiaId) { - if (topiaId != null && !topiaId.isEmpty()) { - int index = topiaId.indexOf("#"); - String id = topiaId.replace('#', 'K'); - return id.substring(index); - } - return ""; - } - - public static <E extends TopiaEntity> boolean prepareTopiaId(Class<E> entityClass, E entity) { - String topiaId = entity.getTopiaId(); - if (StringUtils.isEmpty(entity.getTopiaId())) { - topiaId = TopiaId.create(entityClass); - entity.setTopiaId(topiaId); - return true; - } - return false; - } -} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityCalendarImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityCalendarImpl.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityCalendarImpl.java 2009-12-13 16:15:45 UTC (rev 119) @@ -0,0 +1,31 @@ + +package fr.ifremer.suiviobsmer.entity; + +import java.io.Serializable; + +/** + * ActivityCalendarImpl + * + * Created: 11 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ActivityCalendarImpl extends fr.ifremer.suiviobsmer.entity.ActivityCalendarAbstract implements Serializable, fr.ifremer.suiviobsmer.entity.ActivityCalendar { + + private static final long serialVersionUID = 1L; + + @Override + public ActivityMonth getActivityMonth(int monthNumber) { + for (ActivityMonth month : getActivityMonth()) { + if (month.getMonth() == monthNumber) { + return month; + } + } + return null; + } + +} //ActivityCalendarImpl Property changes on: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityCalendarImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Revision Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityMonthImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityMonthImpl.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityMonthImpl.java 2009-12-13 16:15:45 UTC (rev 119) @@ -0,0 +1,30 @@ +package fr.ifremer.suiviobsmer.entity; + +import java.io.Serializable; + +/** + * ActivityMonthImpl + * + * Created: 11 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ActivityMonthImpl extends ActivityMonthAbstract implements Serializable, ActivityMonth { + + private static final long serialVersionUID = 1L; + + @Override + public ActivityProfession getActivityProfession(int professionOrder) { + for (ActivityProfession profession : getActivityProfession()) { + if (profession.getProfessionOrder() == professionOrder) { + return profession; + } + } + return null; + } + +} //ActivityProfessionImpl Property changes on: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityMonthImpl.java ___________________________________________________________________ Added: svn:keywords + Author Date Revision Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityProfessionImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityProfessionImpl.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityProfessionImpl.java 2009-12-13 16:15:45 UTC (rev 119) @@ -0,0 +1,30 @@ + +package fr.ifremer.suiviobsmer.entity; + +import java.io.Serializable; + +/** + * ActivityZoneImpl + * + * Created: 11 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ActivityProfessionImpl extends ActivityProfessionAbstract implements Serializable, ActivityProfession { + + private static final long serialVersionUID = 1L; + + @Override + public ActivityZone getActivityZone(int zoneId) { + for (ActivityZone zone : getActivityZone()) { + if (zone.getZoneId() == zoneId) { + return zone; + } + } + return null; + } +} Property changes on: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ActivityProfessionImpl.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/BoatImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/BoatImpl.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/BoatImpl.java 2009-12-13 16:15:45 UTC (rev 119) @@ -23,7 +23,7 @@ import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; import java.io.Serializable; import org.nuiton.topia.TopiaContext; import org.slf4j.Logger; @@ -56,7 +56,7 @@ throw new IllegalArgumentException("company parameter can't be null to getBoatsInfos " + "for boat '" + this.getName() + "'"); } - transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); /*CompanyDAO companyDAO = SuiviObsmerModelDAOHelper.getCompanyDAO(transaction); Company companyFromDB = companyDAO.findByTopiaId(company.getTopiaId());*/ @@ -79,7 +79,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Impossible de récupérer les informations privées du navire lié à la société " + "'" + company.getName() + "'", eee); Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/CompanyImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/CompanyImpl.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/CompanyImpl.java 2009-12-13 16:15:45 UTC (rev 119) @@ -21,7 +21,7 @@ package fr.ifremer.suiviobsmer.entity; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; import java.io.Serializable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,6 +50,6 @@ */ @Override public String getId() { - return SuiviObsmerUtils.convertId(getTopiaId()); + return SuiviObsmerContext.convertId(getTopiaId()); } } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ProgramImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ProgramImpl.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/ProgramImpl.java 2009-12-13 16:15:45 UTC (rev 119) @@ -21,7 +21,7 @@ package fr.ifremer.suiviobsmer.entity; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; import java.io.Serializable; import java.util.Calendar; import java.util.Date; @@ -56,13 +56,13 @@ @Override public boolean isStarted() { - Date current = SuiviObsmerUtils.getCurrentDate(); + Date current = SuiviObsmerContext.getCurrentDate(); return current.after(getPeriodBegin()) || current.equals(getPeriodBegin()); } @Override public boolean isFinished() { - Date current = SuiviObsmerUtils.getCurrentDate(); + Date current = SuiviObsmerContext.getCurrentDate(); return current.after(getPeriodEnd()); } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/UserImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/UserImpl.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/UserImpl.java 2009-12-13 16:15:45 UTC (rev 119) @@ -21,7 +21,7 @@ package fr.ifremer.suiviobsmer.entity; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; import java.io.Serializable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,7 +59,7 @@ */ @Override public String getId() { - return SuiviObsmerUtils.convertId(getTopiaId()); + return SuiviObsmerContext.convertId(getTopiaId()); } } Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImport.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImport.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImport.java 2009-12-13 16:15:45 UTC (rev 119) @@ -0,0 +1,281 @@ + +package fr.ifremer.suiviobsmer.impl; + +import fr.ifremer.suiviobsmer.*; +import com.csvreader.CsvReader; +import fr.ifremer.suiviobsmer.entity.ActivityCalendar; +import fr.ifremer.suiviobsmer.entity.ActivityCalendarDAO; +import fr.ifremer.suiviobsmer.entity.ActivityMonth; +import fr.ifremer.suiviobsmer.entity.ActivityMonthDAO; +import fr.ifremer.suiviobsmer.entity.ActivityProfession; +import fr.ifremer.suiviobsmer.entity.ActivityProfessionDAO; +import fr.ifremer.suiviobsmer.entity.ActivityZone; +import fr.ifremer.suiviobsmer.entity.ActivityZoneDAO; +import fr.ifremer.suiviobsmer.entity.Boat; +import fr.ifremer.suiviobsmer.entity.BoatDAO; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.Charset; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.time.DurationFormatUtils; +import org.nuiton.topia.TopiaContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ActivityCalendarImport + * + * Created: 11 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ActivityCalendarImport implements Runnable { + + private InputStream input; + + private FileWriter writer; + + private static final Logger log = LoggerFactory.getLogger(ActivityCalendarImport.class); + + public ActivityCalendarImport(InputStream input) throws IOException { + super(); + this.input = input; + String filename = + SuiviObsmerContext.getProperty(SuiviObsmerContext.PROP_FILENAME_LOG_ACTIVITY); + File file = new File(filename); + file.getParentFile().mkdirs(); + if (file.exists()) { + file.delete(); + file.createNewFile(); + } + writer = new FileWriter(filename); + } + + @Override + public void run() { + TopiaContext transaction = null; + SuiviObsmerContext.setActivityCalendarImport(true); + int currRow = 0; + try { + transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); + + CsvReader reader = new CsvReader(input, Charset.forName("UTF-8")); + + long startTime = System.currentTimeMillis(); + + reader.readHeaders(); + + int result = 0; + + while(reader.readRecord()) { + currRow++; + //result[0]++; + + if (log.isTraceEnabled()) { + log.trace(" " + Arrays.asList(reader.getValues())); + } + + int boatImmatriculation = Integer.parseInt(reader.get("NAVS_COD").trim()); + + BoatDAO boatDAO = SuiviObsmerModelDAOHelper.getBoatDAO(transaction); + + Boat boat = boatDAO.findByImmatriculation(boatImmatriculation); + + if (boat != null) { + + ActivityCalendarDAO dao = SuiviObsmerModelDAOHelper.getActivityCalendarDAO(transaction); + + + int year = Integer.parseInt(reader.get("SYNA_AN").trim()); + + ActivityCalendar calendar = dao.findByProperties( + ActivityCalendar.BOAT, boat, + ActivityCalendar.YEAR, year); + + if (calendar == null) { + int fiability = Integer.parseInt(reader.get("INDQ_COD").trim()); + + calendar = dao.create( + ActivityCalendar.BOAT, boat, + ActivityCalendar.YEAR, year, + ActivityCalendar.FIABILITY, fiability); + + calendar.setActivityMonth(new ArrayList<ActivityMonth>()); + + info("Création d'un calendrier " + year + + " pour le navire immatriculé " + boatImmatriculation, currRow); + + //transaction.commitTransaction(); + } + String calendarCode = "[ calendrier " + year + ", navire " + boatImmatriculation + " ]"; + + int monthNum = Integer.parseInt(reader.get("SYNA_MOI").trim()); + + String harbourCode = reader.get("SYNA_POR_COD").trim(); + ActivityMonth month = calendar.getActivityMonth(monthNum); + if (month == null) { + + boolean active = !harbourCode.equals("INA"); + + ActivityMonthDAO monthDAO = SuiviObsmerModelDAOHelper.getActivityMonthDAO(transaction); + month = monthDAO.create( + ActivityMonth.ACTIVITY_CALENDAR, calendar, + ActivityMonth.MONTH, monthNum, + ActivityMonth.ACTIVE, active); + + month.setActivityProfession(new ArrayList<ActivityProfession>()); + + info("Création du mois " + monthNum + " actif(" + active + ") " + calendarCode, currRow); + + if (active) { + String nbSeaDaysString = reader.get("SYNA_NOMJDM").trim(); + int nbSeaDays = Integer.parseInt(nbSeaDaysString); + int nbFishingDays = Integer.parseInt(reader.get("SYNA_NOMJDP").trim()); + int nbBoardingPersons = Integer.parseInt(reader.get("SYNA_NOMHE").trim()); + int harbourId = Integer.parseInt(reader.get("SYNA_TPOR_COD").trim()); + String harbourLibelle = reader.get("SYNA_POR_LIB").trim(); + //String harbourCode = reader.get("SYNA_POR_COD").trim(); + + month.setHarbourId(harbourId); + month.setHarbourCode(harbourCode); + month.setHarbourLibelle(harbourLibelle); + month.setNbBoardingPersons(nbBoardingPersons); + month.setNbFishingDays(nbFishingDays); + month.setNbSeaDays(nbSeaDays); + } else { + result++; + } + + calendar.addActivityMonth(month); + + //transaction.commitTransaction(); + } + + if (month.getActive()) { + + int professionOrder = Integer.parseInt(reader.get("META_ORDRE").trim()); + ActivityProfession profession = month.getActivityProfession(professionOrder); + + if (profession == null) { + String professionCode = reader.get("MET_COD").trim(); + int professionId = Integer.parseInt(reader.get("MET_ID").trim()); + String professionLibelle = reader.get("MET_LIB").trim(); + + ActivityProfessionDAO professionDAO = + SuiviObsmerModelDAOHelper.getActivityProfessionDAO(transaction); + profession = professionDAO.create( + ActivityProfession.ACTIVITY_MONTH, month, + ActivityProfession.PROFESSION_ORDER, professionOrder, + ActivityProfession.ID, professionId, + ActivityProfession.CODE, professionCode, + ActivityProfession.LIBELLE, professionLibelle); + + profession.setActivityZone(new ArrayList<ActivityZone>()); + + info("Création du métier " + professionOrder + " code(" + professionCode + ") " + + "[ mois " + monthNum + " ] " + + calendarCode, currRow); + + month.addActivityProfession(profession); + } + + int zoneId = Integer.parseInt(reader.get("TSECT_COD").trim()); + ActivityZone zone = profession.getActivityZone(zoneId); + + if (zone == null) { + + int gradiantCode = Integer.parseInt(reader.get("GRA_COD").trim()); + String gradiantLibelle = reader.get("GRA_LIB").trim(); + String zoneCode = reader.get("SECT_COD").trim(); + String zoneLibelle = reader.get("SECT_LIB").trim(); + + ActivityZoneDAO zoneDAO = + SuiviObsmerModelDAOHelper.getActivityZoneDAO(transaction); + + zone = zoneDAO.create( + ActivityZone.ACTIVITY_PROFESSION, profession, + ActivityZone.ZONE_ID, zoneId, + ActivityZone.GRADIANT_CODE, gradiantCode, + ActivityZone.GRADIANT_LIBELLE, gradiantLibelle, + ActivityZone.ZONE_CODE, zoneCode, + ActivityZone.ZONE_LIBELLE, zoneLibelle); + + info("Création de la zone " + zoneId + " [ mois " + monthNum + " ] " + + calendarCode, currRow); + + profession.addActivityZone(zone); + + transaction.commitTransaction(); + + result++; + } else { + warn("Zone déjà existante !", currRow); + } + } + } + + transaction.commitTransaction(); + } + + + long stopTime = System.currentTimeMillis(); + + String execTime = DurationFormatUtils.formatDurationHMS(stopTime - startTime); + + info("Nombre de ligne ajouté : " + result, -1); + info("Temps d'exécution : " + execTime, -1); + + transaction.closeContext(); + } catch (Exception eee) { + if (log.isErrorEnabled()) { + log.error("Problème lors de l'import du calendrier d'activité", eee); + } + try { + error("exception " + eee.getClass().getSimpleName() + " : " + eee.getMessage(), currRow); + } catch (IOException ex) { + if (log.isErrorEnabled()) { + log.error("IO error", ex); + } + } + } finally { + IOUtils.closeQuietly(writer); + } + SuiviObsmerContext.setActivityCalendarImport(false); + } + + protected void warn(String message, int numRow) throws IOException { + log("[WARN] " + message, numRow); + } + + protected void error(String message, int numRow) throws IOException { + log("[ERROR] " + message, numRow); + } + + protected void info(String message, int numRow) throws IOException { + log("[INFO] " + message, numRow); + } + + protected void log(String message, int numRow) throws IOException { + Date date = new Date(); + DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); + String dateString = dateFormat.format(date); + String ligne = numRow != -1 ? "Ligne (" + numRow + ") : " : ""; + String msg = "[" + dateString + "] " + ligne + message; + writer.write(msg + "\n"); + if (log.isDebugEnabled()) { + log.debug("write log activityCalendar : " + msg); + } + } + +} Property changes on: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImport.java ___________________________________________________________________ Added: svn:keywords + Author Date Revision Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImpl.java 2009-12-13 16:15:45 UTC (rev 119) @@ -22,7 +22,7 @@ package fr.ifremer.suiviobsmer.impl; import com.csvreader.CsvReader; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; import fr.ifremer.suiviobsmer.bean.BoatFilter; @@ -31,6 +31,7 @@ import fr.ifremer.suiviobsmer.entity.*; import fr.ifremer.suiviobsmer.entity.Boat; import fr.ifremer.suiviobsmer.services.ServiceBoat; +import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.util.ArrayList; @@ -38,6 +39,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.logging.Level; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.commons.lang.BooleanUtils; @@ -64,7 +66,7 @@ protected TopiaContext rootContext; public ServiceBoatImpl() throws SuiviObsmerException { - rootContext = SuiviObsmerUtils.getTopiaRootContext(); + rootContext = SuiviObsmerContext.getTopiaRootContext(); } @Override @@ -207,7 +209,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, "Impossible de filtrer la liste des navires", eee); + SuiviObsmerContext.serviceException(transaction, "Impossible de filtrer la liste des navires", eee); } return results; } @@ -270,7 +272,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Impossible de récupérer les informations du navire " + "immatriculé '" + boatImmatriculation + "'" + " pour la société '" + company.getName() + "'", eee); @@ -288,13 +290,13 @@ BoatInfosDAO dao = SuiviObsmerModelDAOHelper.getBoatInfosDAO(transaction); BoatInfos boatInfos = companyBoatInfos.getBoatInfos(); - SuiviObsmerUtils.prepareTopiaId(BoatInfos.class, boatInfos); + SuiviObsmerContext.prepareTopiaId(BoatInfos.class, boatInfos); dao.update(boatInfos); ElligibleBoatDAO elligibleDAO = SuiviObsmerModelDAOHelper.getElligibleBoatDAO(transaction); for (ElligibleBoat elligible : companyBoatInfos.getElligibleBoatsValues()) { - SuiviObsmerUtils.prepareTopiaId(ElligibleBoat.class, elligible); + SuiviObsmerContext.prepareTopiaId(ElligibleBoat.class, elligible); elligibleDAO.update(elligible); } @@ -306,7 +308,7 @@ transaction.commitTransaction(); transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "La chaîne d'immatriculations est incorrect ! Chaque immatriculation doit posséder 6 chiffres", eee); } } @@ -337,7 +339,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "La chaîne d'immatriculations est incorrect ! Chaque immatriculation doit posséder 6 chiffres", eee); } return boats; @@ -356,7 +358,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, "Impossible de charger le navire", eee); + SuiviObsmerContext.serviceException(transaction, "Impossible de charger le navire", eee); } return result; } @@ -374,7 +376,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, "Unable to get all boats", eee); + SuiviObsmerContext.serviceException(transaction, "Unable to get all boats", eee); } return results; } @@ -448,7 +450,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Problème d'import du fichier CSV. Vérifiez l'en-tête du fichier : [ NAVS_COD,CARN_NOM," + "CARN_LONGUEUR_HT,CARN_ANNEE,QUARTIER_IMMA,PER_COD,PER_NOM,PER_PRENOM,NAVS_ACTIVE ]"/* et l'encodage [ UTF-8 ] */ + " Voir documentation pour plus de détails.", @@ -457,4 +459,17 @@ return result; } + @Override + public void importActiviyCalendarCsv(InputStream input) throws SuiviObsmerException { + if (!SuiviObsmerContext.isActivityCalendarImportRun()) { + try { + ActivityCalendarImport calendarImport = new ActivityCalendarImport(input); + new Thread(calendarImport).start(); + } catch (IOException eee) { + SuiviObsmerContext.serviceException(null, + "Problème d'import du fichier CSV des calendriers d'activité", eee); + } + } + } + } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java 2009-12-13 16:15:45 UTC (rev 119) @@ -24,7 +24,7 @@ import fr.ifremer.suiviobsmer.DataLoader; import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; import fr.ifremer.suiviobsmer.bean.states.ContactStateEnum; import fr.ifremer.suiviobsmer.entity.Boat; import fr.ifremer.suiviobsmer.entity.Company; @@ -59,7 +59,7 @@ protected TopiaContext rootContext; public ServiceContactImpl() throws SuiviObsmerException { - rootContext = SuiviObsmerUtils.getTopiaRootContext(); + rootContext = SuiviObsmerContext.getTopiaRootContext(); } @Override @@ -88,7 +88,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Impossible de filtrer la liste des contacts", eee); } return results; @@ -122,7 +122,7 @@ ContactDAO dao = SuiviObsmerModelDAOHelper.getContactDAO(transaction); - SuiviObsmerUtils.prepareTopiaId(Contact.class, contact); + SuiviObsmerContext.prepareTopiaId(Contact.class, contact); if (delete) { dao.delete(contact); } else { @@ -132,7 +132,7 @@ transaction.commitTransaction(); transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Impossible de sauvegarder le contact", eee); } } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceReferentialImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceReferentialImpl.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceReferentialImpl.java 2009-12-13 16:15:45 UTC (rev 119) @@ -24,7 +24,7 @@ import com.csvreader.CsvReader; import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; import fr.ifremer.suiviobsmer.dto.Facade; import fr.ifremer.suiviobsmer.entity.FishingZone; import fr.ifremer.suiviobsmer.entity.FishingZoneDAO; @@ -60,7 +60,7 @@ protected TopiaContext rootContext; public ServiceReferentialImpl() throws SuiviObsmerException { - rootContext = SuiviObsmerUtils.getTopiaRootContext(); + rootContext = SuiviObsmerContext.getTopiaRootContext(); } @Override @@ -81,7 +81,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Impossible de charger la liste des métiers", eee); } return results; @@ -100,7 +100,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Impossible de charger la liste des programmes", eee); } return results; @@ -119,7 +119,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Impossible de charger la liste des zones de pêche", eee); } return results; @@ -163,7 +163,7 @@ transaction.commitTransaction(); transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Problème d'import du fichier CSV. Vérifiez l'en-tête du fichier : [ PECHE_DIVISION," + "PECHE_ZONE,PECHE_FACADE ]. Voir documentation pour plus de détails.", eee); Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImpl.java 2009-12-13 16:15:45 UTC (rev 119) @@ -24,7 +24,7 @@ import com.csvreader.CsvReader; import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; import fr.ifremer.suiviobsmer.dto.SamplingHistoricRow; import fr.ifremer.suiviobsmer.entity.*; import fr.ifremer.suiviobsmer.entity.SampleRow; @@ -68,7 +68,7 @@ protected TopiaContext rootContext; public ServiceSamplingImpl() throws SuiviObsmerException { - rootContext = SuiviObsmerUtils.getTopiaRootContext(); + rootContext = SuiviObsmerContext.getTopiaRootContext(); } @Override @@ -77,7 +77,7 @@ try { transaction = rootContext.beginTransaction(); - boolean newRow = SuiviObsmerUtils.prepareTopiaId(SampleRow.class, row); + boolean newRow = SuiviObsmerContext.prepareTopiaId(SampleRow.class, row); if (log.isDebugEnabled()) { log.debug("new sampleRow : " + newRow); @@ -88,7 +88,7 @@ if (newRow) { // Save profession : create or update ProfessionDAO professionDAO = SuiviObsmerModelDAOHelper.getProfessionDAO(transaction); - SuiviObsmerUtils.prepareTopiaId(Profession.class, row.getProfession()); + SuiviObsmerContext.prepareTopiaId(Profession.class, row.getProfession()); if (log.isDebugEnabled()) { log.debug("create or update profession : " + row.getProfession()); } @@ -98,7 +98,7 @@ // Save program : can't be create if row already exist // TODO check program.topiaId exist for an update ProgramDAO programDAO = SuiviObsmerModelDAOHelper.getProgramDAO(transaction); - boolean newProgram = SuiviObsmerUtils.prepareTopiaId(Program.class, row.getProgram()); + boolean newProgram = SuiviObsmerContext.prepareTopiaId(Program.class, row.getProgram()); if (log.isDebugEnabled()) { log.debug("create or update program : " + row.getProgram()); } @@ -107,7 +107,7 @@ // Save sampleMonth : create or update SampleMonthDAO monthDAO = SuiviObsmerModelDAOHelper.getSampleMonthDAO(transaction); for (SampleMonth month : row.getSampleMonth()) { - SuiviObsmerUtils.prepareTopiaId(SampleMonth.class, month); + SuiviObsmerContext.prepareTopiaId(SampleMonth.class, month); if (log.isDebugEnabled()) { log.debug("create or update month : " + month); } @@ -158,7 +158,7 @@ transaction.commitTransaction(); transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Impossible de sauvegarder la ligne d'échantillon", eee); } } @@ -228,7 +228,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Impossible de récupérer la liste des lignes du plan d'échantillonnage", eee); } return results; @@ -268,7 +268,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Impossible de récupérer la liste des lignes du plan d'échantillonnage", eee); } return results; @@ -297,7 +297,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Impossible de charger la ligne d'échantillon ayant pour identifiant : " + sampleRowId, eee); } @@ -317,7 +317,7 @@ transaction.commitTransaction(); transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Impossible de supprimer la ligne d'échantillon : " + sampleRow.getCode(), eee); } @@ -424,15 +424,15 @@ result[1] = nbRefused; } catch (NumberFormatException eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Erreur à la ligne " + currRow + " [CODE = " + row.getCode() + "] : " + "Le format de la durée moyenne des marées est incorrect, il doit être de la forme : 1.9 ", eee); } catch (ParseException eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Erreur à la ligne " + currRow + " [CODE = " + row.getCode() + "] : " + "Le format des dates est incorrect, il doit être de la forme : MM/AAAA", eee); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, + SuiviObsmerContext.serviceException(transaction, "Problème d'import du fichier CSV. Voir documentation pour plus de détails sur " + "les en-têtes autorisés et le format des données.", eee); Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceUserImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceUserImpl.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceUserImpl.java 2009-12-13 16:15:45 UTC (rev 119) @@ -23,7 +23,7 @@ import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; import fr.ifremer.suiviobsmer.entity.Company; import fr.ifremer.suiviobsmer.entity.CompanyDAO; import fr.ifremer.suiviobsmer.entity.User; @@ -53,7 +53,7 @@ protected TopiaContext rootContext; public ServiceUserImpl() throws SuiviObsmerException { - rootContext = SuiviObsmerUtils.getTopiaRootContext(); + rootContext = SuiviObsmerContext.getTopiaRootContext(); } @Override @@ -79,7 +79,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, "Une erreur est survenue lors de la demande de connexion", eee); + SuiviObsmerContext.serviceException(transaction, "Une erreur est survenue lors de la demande de connexion", eee); } return user; } @@ -95,8 +95,8 @@ transaction = rootContext.beginTransaction(); if (generatePassword) { - String random = SuiviObsmerUtils.createRandomString(8); - String password = SuiviObsmerUtils.encodeString(random); + String random = SuiviObsmerContext.createRandomString(8); + String password = SuiviObsmerContext.encodeString(random); if (log.isDebugEnabled()) { log.debug("show password : " + random); } @@ -105,7 +105,7 @@ UserDAO dao = SuiviObsmerModelDAOHelper.getUserDAO(transaction); - SuiviObsmerUtils.prepareTopiaId(User.class, user); + SuiviObsmerContext.prepareTopiaId(User.class, user); dao.update(user); // TODO send mail to user.getLogin() if contains @ @@ -113,7 +113,7 @@ transaction.commitTransaction(); transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, "Impossible de créer ou de mettre à jour l'utilisateur", eee); + SuiviObsmerContext.serviceException(transaction, "Impossible de créer ou de mettre à jour l'utilisateur", eee); } } @@ -129,13 +129,13 @@ CompanyDAO dao = SuiviObsmerModelDAOHelper.getCompanyDAO(transaction); - SuiviObsmerUtils.prepareTopiaId(Company.class, company); + SuiviObsmerContext.prepareTopiaId(Company.class, company); dao.update(company); transaction.commitTransaction(); transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, "Impossible de créer ou de mettre à jour la société", eee); + SuiviObsmerContext.serviceException(transaction, "Impossible de créer ou de mettre à jour la société", eee); } } @@ -159,7 +159,7 @@ transaction.closeContext(); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(transaction, "Impossible de créer ou de mettre à jour l'utilisateur", eee); + SuiviObsmerContext.serviceException(transaction, "Impossible de créer ou de mettre à jour l'utilisateur", eee); } return results; } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceBoatMock.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceBoatMock.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/mock/ServiceBoatMock.java 2009-12-13 16:15:45 UTC (rev 119) @@ -236,4 +236,9 @@ throw new UnsupportedOperationException("Not supported yet."); } + @Override + public void importActiviyCalendarCsv(InputStream input) throws SuiviObsmerException { + throw new UnsupportedOperationException("Not supported yet."); + } + } Modified: trunk/suiviobsmer-business/src/main/resources/SuiviObsmer.properties =================================================================== --- trunk/suiviobsmer-business/src/main/resources/SuiviObsmer.properties 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/main/resources/SuiviObsmer.properties 2009-12-13 16:15:45 UTC (rev 119) @@ -8,4 +8,6 @@ hibernate.connection.driver_class=org.h2.Driver hibernate.connection.url=jdbc:h2:file:~/.suiviobsmer/h2data +suiviobsmer.log.activityCalendar=log/activity.log + Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo =================================================================== (Binary files differ) Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/SuiviObsmerUtilsTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/SuiviObsmerUtilsTest.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/SuiviObsmerUtilsTest.java 2009-12-13 16:15:45 UTC (rev 119) @@ -131,7 +131,7 @@ Company company = new CompanyImpl(); - SuiviObsmerUtils.prepareTopiaId(Company.class, company); + SuiviObsmerContext.prepareTopiaId(Company.class, company); assertNotNull(company.getTopiaId()); log.debug("topiaId for Company : " + company.getTopiaId()); } Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/business/SuiviObsmerRunnerTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/business/SuiviObsmerRunnerTest.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/business/SuiviObsmerRunnerTest.java 2009-12-13 16:15:45 UTC (rev 119) @@ -24,7 +24,7 @@ import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; import fr.ifremer.suiviobsmer.SuiviObsmerRunner; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; @@ -65,9 +65,9 @@ _configuration = loadFileProperties("TopiaContextSuiviObsmer.properties"); _configuration.setProperty("topia.persistence.classes", SuiviObsmerModelDAOHelper.getImplementationClassesAsString()); - SuiviObsmerUtils.setRunner(this); + SuiviObsmerContext.setRunner(this); } catch (Exception eee) { - SuiviObsmerUtils.serviceException(null, "Error during loadConfiguration from " + + SuiviObsmerContext.serviceException(null, "Error during loadConfiguration from " + "'TopiaContextSuiviObsmer.properties' file", eee); } } @@ -78,9 +78,9 @@ log.debug("TEST STOP : clearContext"); } try { - SuiviObsmerUtils.getTopiaRootContext().clear(true); + SuiviObsmerContext.getTopiaRootContext().clear(true); } catch (TopiaException eee) { - SuiviObsmerUtils.serviceException(null, "Error during clear database", eee); + SuiviObsmerContext.serviceException(null, "Error during clear database", eee); } } Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/SampleRowImplTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/SampleRowImplTest.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/SampleRowImplTest.java 2009-12-13 16:15:45 UTC (rev 119) @@ -24,7 +24,7 @@ import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; import fr.ifremer.suiviobsmer.SuiviObsmerRunner; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; import fr.ifremer.suiviobsmer.business.SuiviObsmerRunnerTest; import org.junit.After; import org.junit.AfterClass; @@ -87,7 +87,7 @@ log.info("getSampleMonth"); /** PREPARE DATA **/ - TopiaContext transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + TopiaContext transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); SampleRowDAO dao = SuiviObsmerModelDAOHelper.getSampleRowDAO(transaction); Added: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImportTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImportTest.java (rev 0) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImportTest.java 2009-12-13 16:15:45 UTC (rev 119) @@ -0,0 +1,102 @@ + +package fr.ifremer.suiviobsmer.impl; + +import fr.ifremer.suiviobsmer.SuiviObsmerContext; +import fr.ifremer.suiviobsmer.SuiviObsmerException; +import fr.ifremer.suiviobsmer.SuiviObsmerRunner; +import fr.ifremer.suiviobsmer.business.SuiviObsmerRunnerTest; +import fr.ifremer.suiviobsmer.services.ServiceBoat; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.LineNumberReader; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import static org.junit.Assert.*; + +/** + * ActivityCalendarImport + * + * Created: 11 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ +public class ActivityCalendarImportTest { + + private static SuiviObsmerRunner runner; + + private static final Logger log = LoggerFactory.getLogger(ActivityCalendarImportTest.class); + + public ActivityCalendarImportTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + runner = new SuiviObsmerRunnerTest(); + } + + @AfterClass + public static void tearDownClass() throws Exception { + } + + @Before + public void setUp() throws SuiviObsmerException { + runner.start(); + } + + @After + public void tearDown() throws SuiviObsmerException { + runner.stop(); + } + + /** + * Test of run method, of class ActivityCalendarImport. + */ + @Test + public void testRun() throws IOException, InterruptedException, SuiviObsmerException { + log.info("run"); + + ServiceBoat serviceBoat = new ServiceBoatImpl(); + InputStream input = getClass().getResourceAsStream("/import/navires.csv"); + serviceBoat.importBoatCsv(input); + + input = getClass().getResourceAsStream("/import/activity.csv"); + + ActivityCalendarImport instance = new ActivityCalendarImport(input); + + Thread t = new Thread(instance); + t.start(); + t.join(); + + String filename = + SuiviObsmerContext.getProperty(SuiviObsmerContext.PROP_FILENAME_LOG_ACTIVITY); + + File file = new File(filename); + Assert.assertTrue(file.exists()); + FileReader reader = new FileReader(file); + LineNumberReader numberReader = new LineNumberReader(reader); + + String line; + while ((line = numberReader.readLine()) != null) { + if (numberReader.getLineNumber() == 26) { + String lastChar = line.substring(line.length()-1); + Assert.assertEquals(7, Integer.parseInt(lastChar)); + } + } + Assert.assertEquals(27, numberReader.getLineNumber()); + + //InputStream input = getClass().getResourceAsStream("/target/activity.csv"); + } + +} \ No newline at end of file Property changes on: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ActivityCalendarImportTest.java ___________________________________________________________________ Added: svn:keywords + Author Date Revision Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceBoatImplTest.java 2009-12-13 16:15:45 UTC (rev 119) @@ -24,7 +24,7 @@ import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; import fr.ifremer.suiviobsmer.SuiviObsmerRunner; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; import fr.ifremer.suiviobsmer.bean.BoatFilterImpl; import fr.ifremer.suiviobsmer.business.SuiviObsmerRunnerTest; import fr.ifremer.suiviobsmer.bean.BoatFilter; @@ -167,11 +167,11 @@ serviceSampling.importSamplingPlanCsv(input); // Import doesn't set company - TopiaContext transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + TopiaContext transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); // Create a company CompanyDAO companyDAO = SuiviObsmerModelDAOHelper.getCompanyDAO(transaction); - SuiviObsmerUtils.prepareTopiaId(Company.class, company); + SuiviObsmerContext.prepareTopiaId(Company.class, company); companyDAO.update(company); // Get two SampleRows : 2009_3 & 2010_4 Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImplTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImplTest.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/impl/ServiceSamplingImplTest.java 2009-12-13 16:15:45 UTC (rev 119) @@ -24,7 +24,7 @@ import fr.ifremer.suiviobsmer.SuiviObsmerException; import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; import fr.ifremer.suiviobsmer.SuiviObsmerRunner; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; import fr.ifremer.suiviobsmer.business.SuiviObsmerRunnerTest; import fr.ifremer.suiviobsmer.entity.Boat; import fr.ifremer.suiviobsmer.entity.Company; @@ -110,7 +110,7 @@ log.info("createUpdateSampleRow"); /** PREPARE DATA **/ - TopiaContext transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + TopiaContext transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); List<FishingZone> zones = prepareFishingZones(transaction); @@ -188,7 +188,7 @@ /** PREPARE DATA **/ - TopiaContext transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + TopiaContext transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); List<FishingZone> zones = prepareFishingZones(transaction); @@ -301,7 +301,7 @@ public void testGetSampleRowsForUser() throws Exception { log.info("getSampleRowsForUser"); /** PREPARE DATA **/ - TopiaContext transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + TopiaContext transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); FishingZoneDAO zoneDAO = SuiviObsmerModelDAOHelper.getFishingZoneDAO(transaction); FishingZone zoneIId = zoneDAO.create(FishingZone.DISTRICT_CODE, "IId"); @@ -363,7 +363,7 @@ log.info("deleteSampleRow"); /** PREPARE DATA **/ - TopiaContext transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + TopiaContext transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); FishingZoneDAO zoneDAO = SuiviObsmerModelDAOHelper.getFishingZoneDAO(transaction); FishingZone zoneIId = zoneDAO.create(FishingZone.DISTRICT_CODE, "IId"); @@ -395,7 +395,7 @@ row = rowDAO.findByCode("2010_1"); assertNull(row); - transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); ElligibleBoatDAO elligibleDAO = SuiviObsmerModelDAOHelper.getElligibleBoatDAO(transaction); List<ElligibleBoat> elligibles = elligibleDAO.findAll(); assertEquals(0, elligibles.size()); @@ -406,7 +406,7 @@ log.info("importSamplingPlanCsv"); /** PREPARE DATA **/ - TopiaContext transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + TopiaContext transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); FishingZoneDAO zoneDAO = SuiviObsmerModelDAOHelper.getFishingZoneDAO(transaction); FishingZone zoneIId = zoneDAO.create(FishingZone.DISTRICT_CODE, "IId"); @@ -426,7 +426,7 @@ assertEquals(1, result[1]); /** CHECK VALUES **/ - transaction = SuiviObsmerUtils.getTopiaRootContext().beginTransaction(); + transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); ProgramDAO programDAO = SuiviObsmerModelDAOHelper.getProgramDAO(transaction); Modified: trunk/suiviobsmer-business/src/test/resources/TopiaContextSuiviObsmer.properties =================================================================== --- trunk/suiviobsmer-business/src/test/resources/TopiaContextSuiviObsmer.properties 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-business/src/test/resources/TopiaContextSuiviObsmer.properties 2009-12-13 16:15:45 UTC (rev 119) @@ -8,4 +8,4 @@ hibernate.connection.driver_class=org.h2.Driver hibernate.connection.url=jdbc:h2:file:target/db/h2data - +suiviobsmer.log.activityCalendar=target/log/activity.log Added: trunk/suiviobsmer-business/src/test/resources/import/activity.csv =================================================================== --- trunk/suiviobsmer-business/src/test/resources/import/activity.csv (rev 0) +++ trunk/suiviobsmer-business/src/test/resources/import/activity.csv 2009-12-13 16:15:45 UTC (rev 119) @@ -0,0 +1,9 @@ +"","SYNA_DATED","SYNA_DATEF","SYNA_AN","SYNA_MOI","ENQ_ID","INDQ_COD","CATD_COD","NAVS_COD","SYNA_NOMJDM","SYNA_NOMJDP","SYNA_NOMHE","SYNA_TPOR_COD","SYNA_POR_COD","SYNA_POR_LIB","SYNA_QUA_COD","SYNA_QUA_LIB","META_ORDRE","ORII_COD","ORII_COURT_LIB","MET_ID","MET_COD","MET_LIB","GRA_COD","GRA_LIB","TSECT_COD","SECT_COD","SECT_LIB","zone","MET5","VIId" +"1286","2008-02-01 00:00:00","2008-02-29 00:00:00","2008","02","932766","2","1","273129","12","11","4","6","XGV","Le Guilvinec","GV","Le Guilvinec","1","9","CNTS/M","193","OTBGA","Chalut de fond à panneaux (1 nav.) à divers gadidés","11","Etranger","13","31E3","Rectangle 31E3","CELT","OTB_DEF",FALSE +"1287","2008-02-01 00:00:00","2008-02-29 00:00:00","2008","02","932766","2","1","273129","12","11","4","6","XGV","Le Guilvinec","GV","Le Guilvinec","1","9","CNTS/M","193","OTBGA","Chalut de fond à panneaux (1 nav.) à divers gadidés","11","Etranger","13","31E2","Rectangle 31E2","CELT","OTB_DEF",FALSE +"1288","2008-07-01 00:00:00","2008-07-31 00:00:00","2008","07","914020","1","1","177474","10","10","3","6","XGV","Le Guilvinec","GV","Le Guilvinec","1","9","CNTS/M","307","TTBLN","Chaluts jumeaux à langoustines, galathées","16","Mixte","13","24E4","Rectangle 24E4","GASC","OTT_CRU",FALSE +"24431","2008-10-01 00:00:00","2008-10-31 00:00:00","2008","10","968329","1","1","174592","15","15","4","6","ACN","Honfleur","CN","Caen","2","9","CNTS/M","211","OTBSO","Chalut de fond à panneaux (1 nav.) à soles","9","Côtier","14","27E930","Extérieur des 3 milles de Ouistreham à Villers/mer","NSEC","OTB_DEF",TRUE +"24432","2008-08-01 00:00:00","2008-08-31 00:00:00","2008","08","967774","2","1","284595","4","4","3","6","ACN","Honfleur","CN","Caen","1","9","CNTS/M","211","OTBSO","Chalut de fond à panneaux (1 nav.) à soles","9","Côtier","14","27E930","Extérieur des 3 milles de Ouistreham à Villers/mer","NSEC","OTB_DEF",TRUE +"24433","2008-09-01 00:00:00","2008-09-30 00:00:00","2008","09","966415","2","1","177474","8","8","3","6","ACN","Honfleur","CN","Caen","1","9","CNTS/M","211","OTBSO","Chalut de fond à panneaux (1 nav.) à soles","9","Côtier","14","27E930","Extérieur des 3 milles de Ouistreham à Villers/mer","NSEC","OTB_DEF",TRUE +"24434","2008-08-01 00:00:00","2008-08-31 00:00:00","2008","08","968272","1","1","978419","25","25","4","6","ACN","Honfleur","CN","Caen","1","9","CNTS/M","211","OTBSO","Chalut de fond à panneaux (1 nav.) à soles","9","Côtier","14","27E930","Extérieur des 3 milles de Ouistreham à Villers/mer","NSEC","OTB_DEF",TRUE +"43134","2008-05-01 00:00:00","2008-05-31 00:00:00","2008","05","961088","3","1","174592",NA,NA,"1","6","INA","Trentemoult (Nantes)",NA,"Nantes","1","7","ENQUETEUR","344","GNSLM","Filet maillant fixe à lamproie marine","9","Côtier","14","23E7L5","Loire domaine mixte lot 15","GASC","GNS_CAT",FALSE \ No newline at end of file Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Administration.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Administration.java 2009-12-10 16:18:20 UTC (rev 118) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Administration.java 2009-12-13 16:15:45 UTC (rev 119) @@ -18,251 +18,251 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * ##%* */ - -package fr.ifremer.suiviobsmer.ui.pages; - -import fr.ifremer.suiviobsmer.SuiviObsmerException; -import fr.ifremer.suiviobsmer.SuiviObsmerUtils; -import fr.ifremer.suiviobsmer.entity.Company; -import fr.ifremer.suiviobsmer.entity.CompanyImpl; -import fr.ifremer.suiviobsmer.entity.User; -import fr.ifremer.suiviobsmer.entity.UserImpl; -import fr.ifremer.suiviobsmer.services.ServiceReferential; -import fr.ifremer.suiviobsmer.services.ServiceUser; -import fr.ifremer.suiviobsmer.ui.base.GenericSelectModel; -import fr.ifremer.suiviobsmer.ui.base.SuiviObsmerPage; -import fr.ifremer.suiviobsmer.ui.components.Layout; -import java.util.List; -import org.apache.commons.lang.StringUtils; -import org.apache.tapestry5.EventContext; -import org.apache.tapestry5.annotations.IncludeStylesheet; -import org.apache.tapestry5.annotations.InjectComponent; -import org.apache.tapestry5.annotations.Log; -import org.apache.tapestry5.annotations.Persist; -import org.apache.tapestry5.annotations.Property; -import org.apache.tapestry5.ioc.annotations.Inject; -import org.apache.tapestry5.ioc.services.PropertyAccess; -import org.apache.tapestry5.ioc.services.TypeCoercer; -import org.apache.tapestry5.upload.services.UploadedFile; -import org.slf4j.Logger; - -/** - * Administration - * - * Created: 9 nov. 2009 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - at IncludeStylesheet("context:css/administration.css") -public class Administration implements SuiviObsmerPage { - - @Override - public boolean isOnlyForAdmin() { - return true; - } - - @Inject - private Logger log; - - @InjectComponent - private Layout layout; - - @Inject - private ServiceUser serviceUser; - - @Inject - private ServiceReferential serviceReferential; - - @Inject - private TypeCoercer typeCoercer; - - @Property - private String companyId; - - @Property - private String userId; - - @Persist - private List<Company> companies; - - @Inject - private PropertyAccess propertyAccess; - - private GenericSelectModel<Company> companiesSelectModel; - - private Company company; - - private GenericSelectModel<User> usersSelectModel; - - /** - * User is persistant cause of autobuild problem ?!? - */ - @Persist - private User user; - - @Property - private boolean generatePassword; - - @Property - private String password; - - private boolean addNewCompanySelected; - private boolean addNewUserSelected; - - void setupRender() { - companies = null; - getCompanies(); - user = null; - } - - void onActivate(EventContext ec) { - if (ec.getCount() > 0) { - companyId = ec.get(String.class, 0); - if (ec.getCount() > 1) { - userId = ec.get(String.class, 1); - } - } - } - - Object[] onPassivate() { - return new String[] {companyId, userId}; - } - - /**************************** IMPORT (ADMIN) *******************************/ - - /** - * CSV File which contains fishing zones - */ - @Property - private UploadedFile fishingZoneCsvFile; - - @Log - void onSuccessFromImportFishingZones() { - try { - int result = serviceReferential.importFishingZoneCsv(fishingZoneCsvFile.getStream()); - layout.getFeedBack().addInfo(result + " zones de pêche importés"); - } catch (SuiviObsmerException eee) { - layout.getFeedBack().addError(eee.getMessage()); - } - } - - /**************************** FORMS ****************************************/ - - public List<Company> getCompanies() { - if (companies == null) { - try { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getCompanies]"); - } - companies = serviceUser.getCompanies(); - } catch(SuiviObsmerException eee) { - // errors - } - } - return companies; - } - - public GenericSelectModel<Company> getCompaniesSelectModel() { - if (companiesSelectModel == null) { - companiesSelectModel = new GenericSelectModel<Company>(getCompanies(), Company.class, Company.NAME, "id", propertyAccess); - } - return companiesSelectModel; - } - - public Company getCompany() { - if (company == null) { - if (companyId != null) { - company = getCompaniesSelectModel().findObject(companyId); - } else { - company = new CompanyImpl(); - } - } - return company; - } - - public boolean isUsersAvailable() { - return !StringUtils.isEmpty(getCompany().getId()) && getCompany().getActive(); - } - - void onSelectedFromAddNewCompany() { - addNewCompanySelected = true; - } - - void onSuccessFromActionsForm() { - if (addNewCompanySelected) { - companyId = null; - } - userId = null; - user = null; - } - - void onSuccessFromCompany() throws SuiviObsmerException { - serviceUser.createUpdateCompany(company); - companyId = company.getId(); - } - - @Log - public GenericSelectModel<User> getUsersSelectModel() { - if (usersSelectModel == null) { - List<User> users = getCompany().getUser(); - if (log.isDebugEnabled()) { - log.debug("Nb users : " + users.size()); - } - usersSelectModel = new GenericSelectModel<User>(users, User.class, "fullName", "id", propertyAccess); - } - return usersSelectModel; - } - - @Log - public User getUser() { - if (user == null) { - if (userId != null) { - if (log.isDebugEnabled()) { - log.debug("User exist in selectModel : " + userId); - } - user = getUsersSelectModel().findObject(userId); - } else { - user = new UserImpl(); - generatePassword = true; - if (log.isDebugEnabled()) { - log.debug("Set company for new user : " + getCompany().getName()); - } - user.setCompany(getCompany()); - } - } - return user; - } - - void onSelectedFromAddNewUser() { - addNewUserSelected = true; - } - - void onSuccessFromUserActionsForm() { - if (addNewUserSelected) { - userId = null; - } - // If login already defined by an other user : - // popup : "Un autre utilisateur possède le même identifiant, voulez désactiver l'ancien compte ?" - // Technique : catch exception for alreadyExist user - } - - @Log - void onSuccessFromUser() throws SuiviObsmerException { - if (log.isDebugEnabled()) { - log.debug("User : " + user); - } - - // TODO validation : required : lastName, firstName, login - if (!StringUtils.isEmpty(password)) { - String encodedPassword = SuiviObsmerUtils.encodeString(password); - user.setPassword(encodedPassword); - } - serviceUser.createUpdateUser(user, generatePassword); - userId = user.getId(); - } - -} + +package fr.ifremer.suiviobsmer.ui.pages; + +import fr.ifremer.suiviobsmer.SuiviObsmerException; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; +import fr.ifremer.suiviobsmer.entity.Company; +import fr.ifremer.suiviobsmer.entity.CompanyImpl; +import fr.ifremer.suiviobsmer.entity.User; +import fr.ifremer.suiviobsmer.entity.UserImpl; +import fr.ifremer.suiviobsmer.services.ServiceReferential; +import fr.ifremer.suiviobsmer.services.ServiceUser; +import fr.ifremer.suiviobsmer.ui.base.GenericSelectModel; +import fr.ifremer.suiviobsmer.ui.base.SuiviObsmerPage; +import fr.ifremer.suiviobsmer.ui.components.Layout; +import java.util.List; +import org.apache.commons.lang.StringUtils; +import org.apache.tapestry5.EventContext; +import org.apache.tapestry5.annotations.IncludeStylesheet; +import org.apache.tapestry5.annotations.InjectComponent; +import org.apache.tapestry5.annotations.Log; +import org.apache.tapestry5.annotations.Persist; +import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.ioc.annotations.Inject; +import org.apache.tapestry5.ioc.services.PropertyAccess; +import org.apache.tapestry5.ioc.services.TypeCoercer; +import org.apache.tapestry5.upload.services.UploadedFile; +import org.slf4j.Logger; + +/** + * Administration + * + * Created: 9 nov. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ + at IncludeStylesheet("context:css/administration.css") +public class Administration implements SuiviObsmerPage { + + @Override + public boolean isOnlyForAdmin() { + return true; + } + + @Inject + private Logger log; + + @InjectComponent + private Layout layout; + + @Inject + private ServiceUser serviceUser; + + @Inject + private ServiceReferential serviceReferential; + + @Inject + private TypeCoercer typeCoercer; + + @Property + private String companyId; + + @Property + private String userId; + + @Persist + private List<Company> companies; + + @Inject + private PropertyAccess propertyAccess; + + private GenericSelectModel<Company> companiesSelectModel; + + private Company company; + + private GenericSelectModel<User> usersSelectModel; + + /** + * User is persistant cause of autobuild problem ?!? + */ + @Persist + private User user; + + @Property + private boolean generatePassword; + + @Property + private String password; + + private boolean addNewCompanySelected; + private boolean addNewUserSelected; + + void setupRender() { + companies = null; + getCompanies(); + user = null; + } + + void onActivate(EventContext ec) { + if (ec.getCount() > 0) { + companyId = ec.get(String.class, 0); + if (ec.getCount() > 1) { + userId = ec.get(String.class, 1); + } + } + } + + Object[] onPassivate() { + return new String[] {companyId, userId}; + } + + /**************************** IMPORT (ADMIN) *******************************/ + + /** + * CSV File which contains fishing zones + */ + @Property + private UploadedFile fishingZoneCsvFile; + + @Log + void onSuccessFromImportFishingZones() { + try { + int result = serviceReferential.importFishingZoneCsv(fishingZoneCsvFile.getStream()); + layout.getFeedBack().addInfo(result + " zones de pêche importés"); + } catch (SuiviObsmerException eee) { + layout.getFeedBack().addError(eee.getMessage()); + } + } + + /**************************** FORMS ****************************************/ + + public List<Company> getCompanies() { + if (companies == null) { + try { + if (log.isInfoEnabled()) { + log.info("BUSINESS REQUEST [getCompanies]"); + } + companies = serviceUser.getCompanies(); + } catch(SuiviObsmerException eee) { + // errors + } + } + return companies; + } + + public GenericSelectModel<Company> getCompaniesSelectModel() { + if (companiesSelectModel == null) { + companiesSelectModel = new GenericSelectModel<Company>(getCompanies(), Company.class, Company.NAME, "id", propertyAccess); + } + return companiesSelectModel; + } + + public Company getCompany() { + if (company == null) { + if (companyId != null) { + company = getCompaniesSelectModel().findObject(companyId); + } else { + company = new CompanyImpl(); + } + } + return company; + } + + public boolean isUsersAvailable() { + return !StringUtils.isEmpty(getCompany().getId()) && getCompany().getActive(); + } + + void onSelectedFromAddNewCompany() { + addNewCompanySelected = true; + } + + void onSuccessFromActionsForm() { + if (addNewCompanySelected) { + companyId = null; + } + userId = null; + user = null; + } + + void onSuccessFromCompany() throws SuiviObsmerException { + serviceUser.createUpdateCompany(company); + companyId = company.getId(); + } + + @Log + public GenericSelectModel<User> getUsersSelectModel() { + if (usersSelectModel == null) { + List<User> users = getCompany().getUser(); + if (log.isDebugEnabled()) { + log.debug("Nb users : " + users.size()); + } + usersSelectModel = new GenericSelectModel<User>(users, User.class, "fullName", "id", propertyAccess); + } + return usersSelectModel; + } + + @Log + public User getUser() { + if (user == null) { + if (userId != null) { + if (log.isDebugEnabled()) { + log.debug("User exist in selectModel : " + userId); + } + user = getUsersSelectModel().findObject(userId); + } else { + user = new UserImpl(); + generatePassword = true; + if (log.isDebugEnabled()) { + log.debug("Set company for new user : " + getCompany().getName()); + } + user.setCompany(getCompany()); + } + } + return user; + } + + void onSelectedFromAddNewUser() { + addNewUserSelected = true; + } + + void onSuccessFromUserActionsForm() { + if (addNewUserSelected) { + userId = null; + } + // If login already defined by an other user : + // popup : "Un autre utilisateur possède le même identifiant, voulez désactiver l'ancien compte ?" + // Technique : catch exception for alreadyExist user + } + + @Log + void onSuccessFromUser() throws SuiviObsmerException { + if (log.isDebugEnabled()) { + log.debug("User : " + user); + } + + // TODO validation : required : lastName, firstName, login + if (!StringUtils.isEmpty(password)) { + String encodedPassword = SuiviObsmerContext.encodeString(password); + user.setPassword(encodedPassword); + } + serviceUser.createUpdateUser(user, generatePassword); + userId = user.getId(); + } + +}