r574 - in trunk: . echobase-entities echobase-entities/src/main/java/fr/ifremer/echobase echobase-entities/src/main/java/fr/ifremer/echobase/entities echobase-entities/src/main/resources echobase-entities/src/main/resources/i18n echobase-services echobase-services/src/main/java/fr/ifremer/echobase/services echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb echobase-services/src/main/java/fr
Author: tchemit Date: 2012-08-30 18:16:04 +0200 (Thu, 30 Aug 2012) New Revision: 574 Url: http://forge.codelutin.com/repositories/revision/echobase/574 Log: refs #1016: Int?\195?\169grer les traductions anglaises (ajout du site en anglais) refs #1438: Choix d'une base de travail (ajout des base internal, to be continued) improve service packages Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseEntityHelper.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/JdbcConfiguration.java trunk/echobase-entities/src/main/resources/echobase-datadb.properties trunk/echobase-entities/src/main/resources/echobase-internaldb.properties trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationConfiguration.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportDbConfiguration.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportDbService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryCsvModel.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/GenericSQLQuery.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ImportException.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/DefaultImportStrategy.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportDbConfiguration.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportDbService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportService.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseInternalDbTransactionFilter.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseWorkingDbTransactionFilter.java trunk/src/site/en/ trunk/src/site/en/rst/ trunk/src/site/en/rst/embedded.rst trunk/src/site/en/rst/imports.rst trunk/src/site/en/rst/index.rst trunk/src/site/en/rst/install.rst trunk/src/site/en/rst/model.rst trunk/src/site/site_en.xml Removed: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DefaultImportStrategy.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationConfiguration.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbConfiguration.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportQueryService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbConfiguration.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportException.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportService.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseTopiaTransactionFilter.java trunk/echobase-ui/src/site/ trunk/src/site/resources/images/argouml-logo.png trunk/src/site/resources/images/jrst-logo.png trunk/src/site/resources/images/restructuredtext-logo.png trunk/src/site/resources/images/struts2-logo.png trunk/src/site/resources/images/topia-logo.png trunk/src/site/rst/todo.rst Modified: trunk/echobase-entities/pom.xml trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfigurationOption.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextFactory.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EchoBaseUserDAOImpl.java trunk/echobase-entities/src/main/resources/i18n/echobase-entities_en_GB.properties trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties trunk/echobase-services/pom.xml trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DefaultEchoBaseServiceContext.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceContext.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceFactory.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/UserService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportDataService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AcousticImportService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/CatchesImportService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/CommonImportService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/OperationImportService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsEsduCellImportService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsImportService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsMapCellImportService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsRegionCellImportService.java trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsVoyageImportService.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceIT.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/ExportDbServiceTest.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/ExportQueryServiceTest.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/FakeEchoBaseServiceContext.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/ImportDbServiceTest.java trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/importdata/AbstractImportDataServiceIT.java trunk/echobase-tools/pom.xml trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/EntityLoader.java trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/AbstractToolTest.java trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/AbstractLoaderIT.java trunk/echobase-ui/pom.xml trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationContext.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseSession.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractWaitAndExecAction.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/EchoBaseActionSupport.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ExportTable.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ImportTable.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/embeddedApplication/Build.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/embeddedApplication/Configure.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/embeddedApplication/Download.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Configure.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Download.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Export.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/DownloadExportQueryResult.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ExportQueryResult.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/GetExportQueryResult.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ManageExportQuery.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/NewLibreOfficeQuery.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/AbstractLaunchImport.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/Configure.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/Import.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ConnectToDbInformations.java trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/LoginAction.java trunk/echobase-ui/src/main/webapp/WEB-INF/web.xml trunk/pom.xml trunk/src/site/rst/embedded.rst trunk/src/site/rst/imports.rst trunk/src/site/rst/index.rst trunk/src/site/rst/install.rst trunk/src/site/rst/model.rst trunk/src/site/site_fr.xml Modified: trunk/echobase-entities/pom.xml =================================================================== --- trunk/echobase-entities/pom.xml 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-entities/pom.xml 2012-08-30 16:16:04 UTC (rev 574) @@ -14,7 +14,87 @@ <groupId>fr.ifremer.echobase</groupId> <artifactId>echobase-entities</artifactId> + <name>EchoBase :: Entities</name> + <description>EchoBase entities module</description> + <properties> + <!-- no site generation --> + <maven.site.skip>true</maven.site.skip> + </properties> + <build> + + <plugins> + + <plugin> + <groupId>org.nuiton.eugene</groupId> + <artifactId>eugene-maven-plugin</artifactId> + <configuration> + <defaultPackage>fr.ifremer.echobase.entities</defaultPackage> + <fullPackagePath>fr.ifremer.echobase.entities</fullPackagePath> + <resolver>org.nuiton.util.FasterCachedResourceResolver</resolver> + <templates> + org.nuiton.eugene.java.JavaInterfaceTransformer, + org.nuiton.eugene.java.JavaBeanTransformer, + org.nuiton.topia.generator.TopiaMetaTransformer + </templates> + </configuration> + <executions> + <execution> + <phase>generate-sources</phase> + <id>generate-persistence</id> + <configuration> + <inputs> + <input>src/main/xmi:echobase.zargo</input> + </inputs> + </configuration> + <goals> + <goal>generate</goal> + </goals> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.nuiton.topia</groupId> + <artifactId>topia-persistence</artifactId> + <version>${topiaVersion}</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-utils</artifactId> + <version>${nuitonUtilsVersion}</version> + <scope>compile</scope> + </dependency> + </dependencies> + </plugin> + + <plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>i18n-maven-plugin</artifactId> + <configuration> + <entries> + <entry> + <basedir>${maven.gen.dir}/java/</basedir> + <excludes> + <param>**/*DAOAbstract.java</param> + </excludes> + </entry> + </entries> + </configuration> + <executions> + <execution> + <goals> + <goal>parserJava</goal> + <goal>gen</goal> + </goals> + </execution> + </executions> + </plugin> + + </plugins> + + </build> + <dependencies> <!-- nuiton dependencies --> @@ -117,85 +197,4 @@ </dependencies> - <!-- ************************************************************* --> - <!-- *** Project Information ************************************* --> - <!-- ************************************************************* --> - - <name>EchoBase :: Entities</name> - <description>EchoBase entities module</description> - - <build> - - <plugins> - - <plugin> - <groupId>org.nuiton.eugene</groupId> - <artifactId>eugene-maven-plugin</artifactId> - <configuration> - <defaultPackage>fr.ifremer.echobase.entities</defaultPackage> - <fullPackagePath>fr.ifremer.echobase.entities</fullPackagePath> - <resolver>org.nuiton.util.FasterCachedResourceResolver</resolver> - <templates> - org.nuiton.eugene.java.JavaInterfaceTransformer, - org.nuiton.eugene.java.JavaBeanTransformer, - org.nuiton.topia.generator.TopiaMetaTransformer - </templates> - </configuration> - <executions> - <execution> - <phase>generate-sources</phase> - <id>generate-persistence</id> - <configuration> - <inputs> - <input>src/main/xmi:echobase.zargo</input> - </inputs> - </configuration> - <goals> - <goal>generate</goal> - </goals> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.nuiton.topia</groupId> - <artifactId>topia-persistence</artifactId> - <version>${topiaVersion}</version> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-utils</artifactId> - <version>${nuitonUtilsVersion}</version> - <scope>compile</scope> - </dependency> - </dependencies> - </plugin> - - <plugin> - <groupId>org.nuiton.i18n</groupId> - <artifactId>i18n-maven-plugin</artifactId> - <configuration> - <entries> - <entry> - <basedir>${maven.gen.dir}/java/</basedir> - <excludes> - <param>**/*DAOAbstract.java</param> - </excludes> - </entry> - </entries> - </configuration> - <executions> - <execution> - <goals> - <goal>parserJava</goal> - <goal>gen</goal> - </goals> - </execution> - </executions> - </plugin> - - </plugins> - - </build> - </project> Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java 2012-08-30 16:16:04 UTC (rev 574) @@ -133,6 +133,11 @@ Preconditions.checkNotNull(file); return file; } + public File getInternalDbDirectory() { + File file = applicationConfig.getOptionAsFile(EchoBaseConfigurationOption.INTERNAL_DB_DIRECTORY.key); + Preconditions.checkNotNull(file); + return file; + } public File getWarDirectory() { File file = applicationConfig.getOptionAsFile( @@ -193,6 +198,11 @@ return result != null && result; } + public boolean isUpdateSchema() { + Boolean result = applicationConfig.getOptionAsBoolean(OPTION_UPDATE_SCHEMA); + return result != null && result; + } + /** * Creates a directory given the configuration given key. * Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfigurationOption.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfigurationOption.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfigurationOption.java 2012-08-30 16:16:04 UTC (rev 574) @@ -44,6 +44,11 @@ n_("echobase.config.data.directory.description"), "/var/local/echobase", File.class), + INTERNAL_DB_DIRECTORY( + "internal.db.directory", + n_("echobase.config.internal.db.directory.description"), + "${data.directory}/internaldb", + File.class), VERSION("project.version", "Version de l'application", "", Version.class), Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseEntityHelper.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseEntityHelper.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseEntityHelper.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,132 @@ +package fr.ifremer.echobase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hibernate.Transaction; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaRuntimeException; +import org.nuiton.topia.framework.TopiaContextImplementor; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.util.Properties; + +/** + * helper about topia context and jdbc connections. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.1 + */ +public class EchoBaseEntityHelper { + + /** Logger. */ + private static final Log log = LogFactory.getLog(EchoBaseEntityHelper.class); + + public static Connection newJDBCConnection(JdbcConfiguration configuration) throws SQLException { + + String jdbcUrl = configuration.getUrl(); + String login = configuration.getLogin(); + String password = configuration.getPassword(); + + Connection conn = DriverManager.getConnection(jdbcUrl, login, password); + + if (log.isDebugEnabled()) { + log.debug("connexion reussie pour l'utilisateur " + login + + " at [" + jdbcUrl + ']'); + } + + return conn; + } + + public static TopiaContext newTransactionFromRootContext(TopiaContext otherTx) throws TopiaException { + TopiaContext tx = ((TopiaContextImplementor) otherTx).getRootContext().beginTransaction(); + return tx; + } + + public static void releaseRootContext(TopiaContext context) { + + TopiaContextImplementor rootContext = ((TopiaContextImplementor) context).getRootContext(); + + if (log.isInfoEnabled()) { + log.info("release database " + + rootContext.getConfig().get(TopiaContextFactory.CONFIG_URL)); + } + try { + releaseContext(rootContext); + } catch (TopiaException e) { + // we don't want this to throw an exception, wants to close + // all possible opened contexts + if (log.isErrorEnabled()) { + log.error("Could not close context " + rootContext, e); + } + } + } + + public static void releaseContext(TopiaContext rootContext) throws TopiaException { + if (rootContext != null && !rootContext.isClosed()) { + rootContext.closeContext(); + } + } + + public static void checkJDBCConnection(JdbcConfiguration configuration) throws SQLException { + + Connection conn = null; + try { + + conn = newJDBCConnection(configuration); + + } finally { + if (conn != null) { + try { + conn.close(); + } catch (SQLException e) { + if (log.isErrorEnabled()) { + log.error("Could not close properly connection to " + + configuration.getUrl(), e); + } + } + } + } + } + + public static JdbcConfiguration newJdbcConfiguration(Properties dbConf) { + + JdbcConfiguration result = new JdbcConfiguration(); + result.setUrl(dbConf.getProperty(TopiaContextFactory.CONFIG_URL)); + result.setLogin(dbConf.getProperty(TopiaContextFactory.CONFIG_USER)); + result.setPassword(dbConf.getProperty(TopiaContextFactory.CONFIG_PASS)); + return result; + } + + public static void closeConnection(TopiaContext transaction) { + if (transaction == null) { + if (log.isTraceEnabled()) { + log.trace("no transaction to close"); + } + } else if (transaction.isClosed()) { + if (log.isTraceEnabled()) { + log.trace("transaction " + transaction + " is already closed"); + } + } else { + if (log.isDebugEnabled()) { + log.debug("closing transaction " + transaction); + } + + try { + Transaction tx = ((TopiaContextImplementor) transaction).getHibernate().getTransaction(); + if (!tx.wasCommitted() && !tx.wasRolledBack()) { + if (log.isDebugEnabled()) { + log.debug("rollback transaction!"); + } + tx.rollback(); + } + transaction.closeContext(); + } catch (TopiaException e) { + throw new TopiaRuntimeException(e); + } + } + } +} Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseEntityHelper.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextFactory.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextFactory.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseTopiaRootContextFactory.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,6 +23,7 @@ */ package fr.ifremer.echobase; +import com.google.common.base.Charsets; import com.google.common.base.Preconditions; import com.google.common.collect.Sets; import com.google.common.io.Closeables; @@ -33,10 +34,13 @@ import org.nuiton.topia.TopiaContextFactory; import org.nuiton.topia.TopiaNotFoundException; import org.nuiton.topia.TopiaRuntimeException; +import org.nuiton.util.RecursiveProperties; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; import java.util.Properties; import java.util.Set; @@ -50,6 +54,17 @@ private static final Log log = LogFactory.getLog(EchoBaseTopiaRootContextFactory.class); + + public static final String T3_EMBEDDED_DB_PROPERTIES = + "/echobase-TopiaContextImpl.properties"; + + public static final String USER_DB_PROPERTIES = + "/echobase-workingdb.properties"; + + public static final String INTERNAL_DB_PROPERTIES = + "/echobase-internaldb.properties"; + + public TopiaContext newEmbeddedDatabase(File dir) { return newEmbeddedDatabase(dir, "/topia-h2.properties"); @@ -138,4 +153,118 @@ return rootContext; } + + /** + * Open a new topia root context from given configuration. + * + * @param configuration topia configuration + * @return the new fresh root context + */ + public TopiaContext newDb(Properties configuration) { + try { + if (log.isInfoEnabled()) { + log.info("Starts a db at : " + + configuration.get(TopiaContextFactory.CONFIG_URL)); + } + TopiaContext result = TopiaContextFactory.getContext(configuration); + return result; + } catch (TopiaNotFoundException e) { + throw new TopiaRuntimeException("Could not init db", e); + } + } + + /** + * Open a new topia root context from the given jdbc configuration. + * + * @param jdbcConfiguration jdbc configuration + * @return the new fresh root context + */ + public TopiaContext newDb(JdbcConfiguration jdbcConfiguration) { + + URL dbConfigFile = getClass().getResource(USER_DB_PROPERTIES); + + Properties result = null; + try { + InputStreamReader reader = + new InputStreamReader(dbConfigFile.openStream(), + Charsets.UTF_8); + try { + result = new RecursiveProperties(); + + result.setProperty("configuration.url", jdbcConfiguration.getUrl()); + result.setProperty("configuration.login", jdbcConfiguration.getLogin()); + result.setProperty("configuration.password", jdbcConfiguration.getPassword()); + result.load(reader); + + reloadProperty(result, TopiaContextFactory.CONFIG_URL); + reloadProperty(result, TopiaContextFactory.CONFIG_USER); + reloadProperty(result, TopiaContextFactory.CONFIG_PASS); + + result.remove("configuration.url"); + result.remove("configuration.login"); + result.remove("configuration.password"); + } finally { + reader.close(); + } + } catch (IOException e) { + throw new IllegalStateException( + "Could not load database configuration", e); + } + + // add entities mapping + result.put( + TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, + EchoBaseDAOHelper.getImplementationClassesAsString() + ); + + return newDb(result); + } + + /** + * Open a new topia root context for the internal db of t3 (this should be + * a h2 db used only for security). + * + * @param configuration application configuration where to find db directory + * @return the new fresh root context of the internal db + */ + public TopiaContext newInternalDb(EchoBaseConfiguration configuration) { + + URL dbConfigFile = getClass().getResource(INTERNAL_DB_PROPERTIES); + + File internalDbDirectory = configuration.getInternalDbDirectory(); + Properties result = null; + + try { + InputStreamReader reader = + new InputStreamReader(dbConfigFile.openStream(), + Charsets.UTF_8); + try { + result = new RecursiveProperties(); + + String key = + EchoBaseConfigurationOption.INTERNAL_DB_DIRECTORY.getKey(); + + result.setProperty(key, internalDbDirectory.getAbsolutePath()); + result.load(reader); + reloadProperty(result, TopiaContextFactory.CONFIG_URL); + result.remove(key); + } finally { + reader.close(); + } + } catch (IOException e) { + throw new IllegalStateException( + "Could not load internal database configuration", e); + } + + // add entities mapping + result.put(TopiaContextFactory.CONFIG_PERSISTENCE_CLASSES, + EchoBaseDAOHelper.getImplementationClassesAsString() + ); + return newDb(result); + } + + public static void reloadProperty(Properties properties, String propertyName) { + Object o = properties.getProperty(propertyName); + properties.put(propertyName, o); + } } Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/JdbcConfiguration.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/JdbcConfiguration.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/JdbcConfiguration.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,67 @@ +/* + * #%L + * T3 :: Domain + * $Id$ + * $HeadURL:$ + * %% + * Copyright (C) 2010 - 2012 IRD, Codelutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase; + +import java.io.Serializable; + +public class JdbcConfiguration implements Serializable { + + private static final long serialVersionUID = 1L; + + public static final String PROPERTY_URL = "url"; + + public static final String PROPERTY_LOGIN = "login"; + + public static final String PROPERTY_PASSWORD = "password"; + + protected String url; + + protected String login; + + protected String password; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getLogin() { + return login; + } + + public void setLogin(String login) { + this.login = login; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + +} Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/JdbcConfiguration.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EchoBaseUserDAOImpl.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EchoBaseUserDAOImpl.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EchoBaseUserDAOImpl.java 2012-08-30 16:16:04 UTC (rev 574) @@ -38,17 +38,11 @@ users = findAll(); } else { - computeAndAddRecordsToPager("SELECT COUNT()* FROM " + getTopiaEntityEnum().getImplementationFQN(), pager); + String fqn = getTopiaEntityEnum().getImplementationFQN(); -// //get user count -// long count = count(); -// pager.setRecords((int) count); -// PagerUtil.computeRecordIndexesAndPagesNumber(pager); - -// TopiaQuery query = createQuery("e"); -// query.setLimit(pager.getRecordStartIndex(), pager.getRecordEndIndex() - 1); - users = findAllByQuery("FROM " + getTopiaEntityEnum().getImplementationFQN(), pager); + computeAndAddRecordsToPager("SELECT COUNT()* FROM " + fqn, pager); + users = findAllByQuery("FROM " + fqn, pager); } return users; } -} //EchoBaseUserDAOImpl<E extends EchoBaseUser> +} Added: trunk/echobase-entities/src/main/resources/echobase-datadb.properties =================================================================== --- trunk/echobase-entities/src/main/resources/echobase-datadb.properties (rev 0) +++ trunk/echobase-entities/src/main/resources/echobase-datadb.properties 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,39 @@ +### +# #%L +# T3 :: Domain +# $Id$ +# $HeadURL: https://svn.mpl.ird.fr/osiris/t3/trunk/t3-domain/src/main/resources/t3-datad... $ +# %% +# Copyright (C) 2010 - 2012 IRD, Codelutin, Tony Chemit +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# #L% +### +# DB configuration +hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +hibernate.connection.driver_class=org.postgresql.Driver +hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaConnectionProvider +hibernate.show_sql=false +hibernate.format_sql=false +hibernate.use_sql_comments=false +hibernate.hbm2ddl.auto=none +hibernate.connection.username=${configuration.login} +hibernate.connection.password=${configuration.password} +hibernate.connection.url=${configuration.url} + +# Migration configuration +topia.service.migration=org.nuiton.topia.migration.TopiaMigrationEngine +topia.service.migration.callback=fr.ird.t3.services.migration.T3MigrationCallback +topia.service.migration.showSql=true + Property changes on: trunk/echobase-entities/src/main/resources/echobase-datadb.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Added: trunk/echobase-entities/src/main/resources/echobase-internaldb.properties =================================================================== --- trunk/echobase-entities/src/main/resources/echobase-internaldb.properties (rev 0) +++ trunk/echobase-entities/src/main/resources/echobase-internaldb.properties 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,32 @@ +### +# #%L +# T3 :: Domain +# $Id$ +# $HeadURL: https://svn.mpl.ird.fr/osiris/t3/trunk/t3-domain/src/main/resources/t3-inter... $ +# %% +# Copyright (C) 2010 - 2012 IRD, Codelutin, Tony Chemit +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# #L% +### +hibernate.hbm2ddl.auto=update +hibernate.show_sql=false + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaConnectionProvider +hibernate.connection.username=sa +hibernate.connection.password=sa +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:file:${internal.db.directory}/echobase-user + Property changes on: trunk/echobase-entities/src/main/resources/echobase-internaldb.properties ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/echobase-entities/src/main/resources/i18n/echobase-entities_en_GB.properties =================================================================== --- trunk/echobase-entities/src/main/resources/i18n/echobase-entities_en_GB.properties 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-entities/src/main/resources/i18n/echobase-entities_en_GB.properties 2012-08-30 16:16:04 UTC (rev 574) @@ -49,3 +49,4 @@ echobase.common.vessel= echobase.common.voyage= echobase.config.data.directory.description= +echobase.config.internal.db.directory.description= Modified: trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties =================================================================== --- trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties 2012-08-30 16:16:04 UTC (rev 574) @@ -49,3 +49,4 @@ echobase.common.vessel=Navire echobase.common.voyage=Campagne echobase.config.data.directory.description=Chemin de l'application +echobase.config.internal.db.directory.description= Modified: trunk/echobase-services/pom.xml =================================================================== --- trunk/echobase-services/pom.xml 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/pom.xml 2012-08-30 16:16:04 UTC (rev 574) @@ -3,10 +3,6 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> - <!-- ************************************************************* --> - <!-- *** POM Relationships *************************************** --> - <!-- ************************************************************* --> - <parent> <groupId>fr.ifremer</groupId> <artifactId>echobase</artifactId> @@ -15,7 +11,90 @@ <groupId>fr.ifremer.echobase</groupId> <artifactId>echobase-services</artifactId> + <name>EchoBase :: Services</name> + <description>EchoBase services module</description> + <properties> + <!-- no site generation --> + <maven.site.skip>true</maven.site.skip> + </properties> + + <build> + + <resources> + <resource> + <directory>src/main/resources</directory> + <includes> + <include>**/*</include> + </includes> + <excludes> + <exclude>echobase-config</exclude> + <exclude>embedded/*</exclude> + </excludes> + </resource> + <resource> + <directory>src/main/resources</directory> + <includes> + <include>echobase-config</include> + </includes> + <filtering>true</filtering> + </resource> + <resource> + <directory>src/main/resources/embedded</directory> + <targetPath>embedded</targetPath> + <filtering>true</filtering> + </resource> + </resources> + + <pluginManagement> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>-Xms512m -Xmx1512m</argLine> + </configuration> + </plugin> + </plugins> + </pluginManagement> + + <plugins> + + <plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>i18n-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>parserJava</goal> + <goal>gen</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>copy-dependencies</goal> + </goals> + </execution> + </executions> + <configuration> + <outputDirectory>${project.build.directory}/classes/embedded</outputDirectory> + <overWriteReleases>false</overWriteReleases> + <overWriteSnapshots>false</overWriteSnapshots> + <overWriteIfNewer>true</overWriteIfNewer> + <includeArtifactIds>h2,postgresql</includeArtifactIds> + <excludeTransitive>true</excludeTransitive> + </configuration> + </plugin> + + </plugins> + + </build> + <dependencies> <dependency> @@ -124,89 +203,6 @@ </dependencies> - <!-- ************************************************************* --> - <!-- *** Project Information ************************************* --> - <!-- ************************************************************* --> - - <name>EchoBase :: Services</name> - <description>EchoBase services module</description> - - <build> - - <resources> - <resource> - <directory>src/main/resources</directory> - <includes> - <include>**/*</include> - </includes> - <excludes> - <exclude>echobase-config</exclude> - <exclude>embedded/*</exclude> - </excludes> - </resource> - <resource> - <directory>src/main/resources</directory> - <includes> - <include>echobase-config</include> - </includes> - <filtering>true</filtering> - </resource> - <resource> - <directory>src/main/resources/embedded</directory> - <targetPath>embedded</targetPath> - <filtering>true</filtering> - </resource> - </resources> - - <pluginManagement> - <plugins> - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <argLine>-Xms512m -Xmx1512m</argLine> - </configuration> - </plugin> - </plugins> - </pluginManagement> - - <plugins> - - <plugin> - <groupId>org.nuiton.i18n</groupId> - <artifactId>i18n-maven-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>parserJava</goal> - <goal>gen</goal> - </goals> - </execution> - </executions> - </plugin> - - <plugin> - <artifactId>maven-dependency-plugin</artifactId> - <executions> - <execution> - <goals> - <goal>copy-dependencies</goal> - </goals> - </execution> - </executions> - <configuration> - <outputDirectory>${project.build.directory}/classes/embedded</outputDirectory> - <overWriteReleases>false</overWriteReleases> - <overWriteSnapshots>false</overWriteSnapshots> - <overWriteIfNewer>true</overWriteIfNewer> - <includeArtifactIds>h2,postgresql</includeArtifactIds> - <excludeTransitive>true</excludeTransitive> - </configuration> - </plugin> - - </plugins> - - </build> - <profiles> <profile> Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DefaultEchoBaseServiceContext.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DefaultEchoBaseServiceContext.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DefaultEchoBaseServiceContext.java 2012-08-30 16:16:04 UTC (rev 574) @@ -26,8 +26,10 @@ import com.google.common.base.Preconditions; import fr.ifremer.echobase.EchoBaseConfiguration; import fr.ifremer.echobase.entities.EchoBaseDbMeta; +import org.apache.commons.lang3.time.DateUtils; import org.nuiton.topia.TopiaContext; +import java.util.Date; import java.util.Locale; /** @@ -38,6 +40,8 @@ */ public class DefaultEchoBaseServiceContext implements EchoBaseServiceContext { + protected TopiaContext internalTransaction; + protected TopiaContext transaction; protected EchoBaseServiceFactory serviceFactory; @@ -50,8 +54,10 @@ public static EchoBaseServiceContext newContext( EchoBaseServiceContext serviceContext, + TopiaContext internalTransaction, TopiaContext transaction) { return newContext(serviceContext.getLocale(), + internalTransaction, transaction, serviceContext.getConfiguration(), serviceContext.getDbMeta(), @@ -61,11 +67,13 @@ public static EchoBaseServiceContext newContext( Locale locale, + TopiaContext internalTransaction, TopiaContext transaction, EchoBaseConfiguration configuration, EchoBaseDbMeta dbMeta, EchoBaseServiceFactory serviceFactory) { return new DefaultEchoBaseServiceContext(locale, + internalTransaction, transaction, configuration, dbMeta, @@ -73,11 +81,13 @@ } protected DefaultEchoBaseServiceContext(Locale locale, + TopiaContext internalTransaction, TopiaContext transaction, EchoBaseConfiguration configuration, EchoBaseDbMeta dbMeta, EchoBaseServiceFactory serviceFactory) { this.locale = locale; + this.internalTransaction = internalTransaction; this.transaction = transaction; this.configuration = configuration; this.dbMeta = dbMeta; @@ -85,6 +95,16 @@ } @Override + public TopiaContext getInternalTransaction() { + return internalTransaction; + } + + @Override + public void setInternalTransaction(TopiaContext internalTransaction) { + this.internalTransaction = internalTransaction; + } + + @Override public TopiaContext getTransaction() { Preconditions.checkNotNull(transaction); return transaction; @@ -106,6 +126,13 @@ } @Override + public Date newDate() { + Date result = new Date(); + DateUtils.setMilliseconds(result, 0); + return result; + } + + @Override public EchoBaseConfiguration getConfiguration() { return configuration; } Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DefaultImportStrategy.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DefaultImportStrategy.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DefaultImportStrategy.java 2012-08-30 16:16:04 UTC (rev 574) @@ -1,98 +0,0 @@ -package fr.ifremer.echobase.services; -/* - * #%L - * EchoBase :: Services - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 - 2012 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import fr.ifremer.echobase.entities.EchoBaseEntityEnum; -import fr.ifremer.echobase.entities.EchoBasePersistenceHelper; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.csv.in.CsvImportResult; -import org.nuiton.topia.persistence.csv.in.ImportModelFactory; -import org.nuiton.topia.persistence.csv.in.ImportStrategy; -import org.nuiton.topia.persistence.csv.in.TopiaCsvImports; -import org.nuiton.topia.persistence.metadata.AssociationMeta; -import org.nuiton.topia.persistence.metadata.TableMeta; -import org.nuiton.util.csv.Import; -import org.nuiton.util.csv.ImportToMap; - -/** - * TODO - * - * @author tchemit <chemit@codelutin.com> - * @since 1.1 - */ -public class DefaultImportStrategy implements ImportStrategy<EchoBaseEntityEnum> { - - private final TopiaContext tx; - - private final EchoBasePersistenceHelper persistenceHelper; - - private final int nbRowBuffer; - - private final ImportModelFactory<EchoBaseEntityEnum> modelFactory; - - public DefaultImportStrategy(ImportModelFactory<EchoBaseEntityEnum> modelFactory, - TopiaContext tx, - EchoBasePersistenceHelper persistenceHelper, - int nbRowBuffer) { - this.tx = tx; - this.persistenceHelper = persistenceHelper; - this.nbRowBuffer = nbRowBuffer; - this.modelFactory = modelFactory; - } - - public ImportModelFactory<EchoBaseEntityEnum> getModelFactory() { - return modelFactory; - } - - @Override - public <E extends TopiaEntity> void importTable(TableMeta<EchoBaseEntityEnum> meta, Import<E> importer, - CsvImportResult<EchoBaseEntityEnum> csvResult) throws TopiaException { - TopiaDAO<E> dao = persistenceHelper.getDAO(tx, meta.getSource()); - - TopiaCsvImports.importAllEntities(dao, meta, importer, csvResult); - } - - @Override - public void importAssociation(AssociationMeta<EchoBaseEntityEnum> meta, - ImportToMap importer, - CsvImportResult<EchoBaseEntityEnum> csvResult) throws TopiaException { - - if (getModelFactory().isNMAssociationMeta(meta)) { - TopiaCsvImports.importNMAssociation(tx, - meta, - importer, - csvResult, - nbRowBuffer); - } else { - TopiaCsvImports.importAssociation(tx, - meta, - importer, - csvResult, - nbRowBuffer); - } - - } -} Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceContext.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceContext.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceContext.java 2012-08-30 16:16:04 UTC (rev 574) @@ -28,6 +28,7 @@ import fr.ifremer.echobase.entities.EchoBaseDbMeta; import org.nuiton.topia.TopiaContext; +import java.util.Date; import java.util.Locale; /** @@ -40,8 +41,40 @@ */ public interface EchoBaseServiceContext { + /** + * Get the internal db current transaction. + * <p/> + * Internal db is the db with everything but not any echobase data + * (security, db connexion, sql queries ?). + * + * @return current internal db transaction + */ + TopiaContext getInternalTransaction(); + + /** + * Set the internal db current transaction. + * + * @param transaction internal db transaction to set + */ + void setInternalTransaction(TopiaContext transaction); + + /** + * Get the working db transaction. + * <p/> + * Working db contains echobase data, but nothing about technical + * stuff (security, connexon,...). + * <p/> + * This transaction can be {@code null} if no working db is used. + * + * @return the current working db transaction (or {@code null} if not setted) + */ TopiaContext getTransaction(); + /** + * Set the working db transaction. + * + * @param transaction working db transaction to set + */ void setTransaction(TopiaContext transaction); Locale getLocale(); @@ -54,4 +87,6 @@ <E extends EchoBaseService> E newService(Class<E> clazz); + Date newDate(); + } Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceFactory.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceFactory.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceFactory.java 2012-08-30 16:16:04 UTC (rev 574) @@ -35,7 +35,8 @@ */ public class EchoBaseServiceFactory { - public <E extends EchoBaseService> E newService(Class<E> clazz, EchoBaseServiceContext serviceContext) { + public <E extends EchoBaseService> E newService(Class<E> clazz, + EchoBaseServiceContext serviceContext) { // instantiate service using empty constructor E service; try { Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java 2012-08-30 16:16:04 UTC (rev 574) @@ -31,7 +31,6 @@ import fr.ifremer.echobase.entities.EchoBaseDbMeta; import fr.ifremer.echobase.entities.EchoBaseEntityEnum; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateUtils; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; import org.nuiton.topia.framework.TopiaContextImplementor; @@ -113,6 +112,10 @@ } } + public TopiaContext getInternalTransaction() { + return serviceContext.getInternalTransaction(); + } + protected final TopiaContext getTransaction() { return serviceContext.getTransaction(); } @@ -129,6 +132,10 @@ return serviceContext.getConfiguration(); } + protected final Date newDate() { + return serviceContext.newDate(); + } + protected char getCsvSeparator() { return getConfiguration().getCsvSeparator(); } @@ -182,10 +189,4 @@ tx.getHibernate().flush(); } - protected Date newDate() { - Date result = new Date(); - DateUtils.setMilliseconds(result, 0); - return result; - } - } Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationConfiguration.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationConfiguration.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationConfiguration.java 2012-08-30 16:16:04 UTC (rev 574) @@ -1,103 +0,0 @@ -/* - * #%L - * EchoBase :: Services - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 - 2012 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.services; - -import org.apache.commons.io.FileUtils; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; - -/** - * Configuration of a embedded application creation. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class EmbeddedApplicationConfiguration extends AbstractEchobaseActionConfiguration { - - private static final long serialVersionUID = 1L; - - /** File name of the embedded application archive (without the zip extension). */ - private String fileName; - - /** Working directory where to generate the archive of embedded application. */ - private File workingDirectory; - - /** Embedded application archive file. */ - private File embeddedApplicationFile; - - /** Location of the war file to push in embedded application. */ - private File warLocation; - - /** Ids of voyages to push in embedded application (with all their datas). */ - private String[] voyageIds; - - public String getFileName() { - return fileName; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } - - public File getWorkingDirectory() { - return workingDirectory; - } - - public void setWorkingDirectory(File workingDirectory) { - this.workingDirectory = workingDirectory; - } - - public File getEmbeddedApplicationFile() { - return embeddedApplicationFile; - } - - public void setEmbeddedApplicationFile(File embeddedApplicationFile) { - this.embeddedApplicationFile = embeddedApplicationFile; - } - - public String[] getVoyageIds() { - return voyageIds; - } - - public void setVoyageIds(String[] voyageIds) { - this.voyageIds = Arrays.copyOf(voyageIds, voyageIds.length); - } - - public File getWarLocation() { - return warLocation; - } - - public void setWarLocation(File warLocation) { - this.warLocation = warLocation; - } - - @Override - public void destroy() throws IOException { - if (workingDirectory != null) { - FileUtils.deleteDirectory(workingDirectory); - } - } -} \ No newline at end of file Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -1,363 +0,0 @@ -/* - * #%L - * EchoBase :: Services - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.services; - -import com.google.common.base.Charsets; -import com.google.common.base.Preconditions; -import fr.ifremer.echobase.EchoBaseIOUtil; -import fr.ifremer.echobase.EchoBaseTechnicalException; -import fr.ifremer.echobase.EchoBaseTopiaRootContextFactory; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.ExportQuery; -import fr.ifremer.echobase.services.exceptions.ExportQueryNameAlreadyExistException; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.util.FileUtil; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStreamWriter; -import java.net.URISyntaxException; -import java.util.List; -import java.util.Properties; - -/** - * To create embedded application. - * - * @author tchemit <chemit@codelutin.com> - * @author sletellier <letellier@codelutin.com> - * @since 0.1 - */ -public class EmbeddedApplicationService extends EchoBaseServiceSupport { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(EmbeddedApplicationService.class); - - public static final String EMBEDDED_PATH = "/embedded/"; - - public File createEmbeddedApplication(EmbeddedApplicationConfiguration model) { - - int nbSteps = computeNbSteps(model); - model.setNbSteps(nbSteps); - - String fileName = model.getFileName(); - - File tempDirectory = model.getWorkingDirectory(); - tempDirectory.deleteOnExit(); - - File zipFile = new File(tempDirectory, fileName + ".zip"); - model.setEmbeddedApplicationFile(zipFile); - - File dir = new File(tempDirectory, fileName); - - if (log.isInfoEnabled()) { - log.info("Creates embedded application to file [" + zipFile + "]"); - } - - // export db to csv - File exportZipFile = exportDb(model, tempDirectory); - - // create static archive structure - createStaticArchiveStructure(model, dir); - - model.incrementsProgression(); - - // create h2 db in /db - TopiaContext rootContext = - new EchoBaseTopiaRootContextFactory().newEmbeddedDatabase(dir); - - TopiaContext topiaContext = null; - try { - - topiaContext = rootContext.beginTransaction(); - - model.incrementsProgression(); - - // create new service context (with new transaction) - EchoBaseServiceContext newServiceContext = - DefaultEchoBaseServiceContext.newContext(serviceContext, - topiaContext); - - EchoBaseUser admin = createUsers(newServiceContext); - - model.incrementsProgression(); - - copyExportQueries(newServiceContext, admin); - - model.incrementsProgression(); - - importDb(model, newServiceContext, exportZipFile, admin); - - - } catch (Exception eee) { - rollbackTransaction( - topiaContext, - "Could not rollback h2 embedded database at " + dir); - throw new EchoBaseTechnicalException( - "Could not create h2 embedded database at " + dir, eee); - } finally { - closeContext(rootContext, - "Could not close h2 embedded database at " + dir); - } - - try { - EchoBaseIOUtil.compressZipFile(zipFile, dir); - } catch (IOException eee) { - throw new EchoBaseTechnicalException( - "Could not create zip file at " + zipFile, eee); - } - - return zipFile; - } - - protected void closeContext(TopiaContext tx, String message) { - try { - tx.closeContext(); - } catch (TopiaException eee) { - throw new EchoBaseTechnicalException(message, eee); - } - } - - protected TopiaContext beginTransaction(TopiaContext tx, String message) { - try { - return tx.beginTransaction(); - } catch (TopiaException eee) { - throw new EchoBaseTechnicalException(message, eee); - } - } - - protected void rollbackTransaction(TopiaContext tx, String message) { - try { - if (tx != null) { - tx.rollbackTransaction(); - } - } catch (TopiaException eee) { - if (log.isErrorEnabled()) { - log.error(message, eee); - } - } - } - - protected int computeNbSteps(EmbeddedApplicationConfiguration model) { - int nbSteps = 4; - - // export db steps - - nbSteps += getDbMeta().getReferenceEntriesSize(); - if (model.getVoyageIds() != null) { - nbSteps += model.getVoyageIds().length; - } - - // import db stesp - nbSteps += getDbMeta().getEntriesSize(); - return nbSteps; - } - - protected void createStaticArchiveStructure(EmbeddedApplicationConfiguration model, File dir) { - - try { - File warLocation = model.getWarLocation(); - - // create / - FileUtil.createDirectoryIfNecessary(dir); - - // copy embedded files to / - copyEmbeddedFiles(dir); - - // copy war to / - FileUtils.copyFile(warLocation, new File(dir, warLocation.getName())); - } catch (Exception eee) { - throw new EchoBaseTechnicalException("Could not create embedded zip structure at " + dir, eee); - } - } - - protected File exportDb(EmbeddedApplicationConfiguration model, - File tempDirectory) { - - try { - // create export zip file - ExportDbConfiguration exportconfiguration = - new ExportDbConfiguration(model); - exportconfiguration.setFileName("echobase-export"); - File exportTempDir = new File(tempDirectory, "exportDb"); - exportconfiguration.setWorkingDirectory(exportTempDir); - exportconfiguration.setVoyageIds(model.getVoyageIds()); - TopiaContext transaction = serviceContext.getTransaction(); - - TopiaContext newTx = beginTransaction( - transaction, - "Could not begin transaction on main db"); - try { - serviceContext.setTransaction(newTx); - ExportDbService exportDbService = - serviceContext.newService(ExportDbService.class); - exportDbService.exportPartialDb(exportconfiguration, false); - } catch (IOException eee) { - rollbackTransaction( - newTx, - "Could not rollback transaction on db"); - throw eee; - } catch (RuntimeException eee) { - rollbackTransaction( - newTx, - "Could not rollback transaction on db"); - throw eee; - } finally { - serviceContext.setTransaction(transaction); - closeContext(newTx, "Could not close transaction on main db"); - } - File exportZipFile = exportconfiguration.getExportFile(); - if (log.isInfoEnabled()) { - log.info("Export zip file = " + exportZipFile); - } - return exportZipFile; - } catch (IOException eee) { - throw new EchoBaseTechnicalException( - "Could not export db to zip", eee); - } - } - - public File getPilotsDirectory(File dataDirectory) { - File driverDir = new File(dataDirectory, "drivers"); - return driverDir; - } - - public String getH2PilotFilename(Properties config) { - String h2Version = config.getProperty("h2Version"); - return h2Version == null ? null : "h2-" + h2Version + ".jar"; - } - - public String getPostgresqlPilotFilename(Properties config) { - String pgVersion = config.getProperty("postgresqlVersion"); - return pgVersion == null ? null : "postgresql-" + pgVersion + ".jar"; - } - - protected void copyEmbeddedFiles(File zipDirectory) throws IOException, URISyntaxException { - - // config to keep the echobase-embedded values (contains h2 and pg versions) - Properties config = new Properties(); - copyEmbeddedFiles("echobase.properties", zipDirectory, config); - - copyEmbeddedFiles("startEchobase.bat", zipDirectory, null); - copyEmbeddedFiles("startEchobase.sh", zipDirectory, null); - copyEmbeddedFiles("README.txt", zipDirectory, null); - - File driverDir = getPilotsDirectory(zipDirectory); - FileUtil.createDirectoryIfNecessary(driverDir); - copyEmbeddedFiles(getH2PilotFilename(config), driverDir, null); - copyEmbeddedFiles(getPostgresqlPilotFilename(config), driverDir, null); - } - - protected void copyEmbeddedFiles(String resourceName, - File zipDirectory, - Properties config) throws IOException { - String resourcePath = EMBEDDED_PATH + resourceName; - InputStream inputStream = getClass().getResourceAsStream(resourcePath); - Preconditions.checkNotNull(inputStream, - "could not find resource " + resourcePath); - try { - if (config != null) { - config.load(inputStream); - } - File outputFile = new File(zipDirectory, resourceName); - if (log.isInfoEnabled()) { - log.info("Copy configuration to " + resourceName + " to " + outputFile); - } - OutputStreamWriter outputStream = new OutputStreamWriter( - new FileOutputStream(outputFile), Charsets.UTF_8); - try { - if (config == null) { - IOUtils.copy(inputStream, outputStream); - } else { - config.store(outputStream, null); - } - } finally { - outputStream.close(); - } - } finally { - inputStream.close(); - } - } - - protected EchoBaseUser createUsers(EchoBaseServiceContext newServiceContext) { - - // get user service from h2 db - UserService userService = - newServiceContext.newService(UserService.class); - - // create admin user - userService.createDefaultUsers(); - - // get admin from h2 db - EchoBaseUser admin = userService.getUserByEmail( - UserService.DEFAULT_ADMIN_EMAIL); - return admin; - } - - protected void copyExportQueries(EchoBaseServiceContext newServiceContext, - EchoBaseUser admin) throws TopiaException, ExportQueryNameAlreadyExistException { - - // get all export queries from application - List<ExportQuery> queries = getEntities(ExportQuery.class); - - // replicate queries - getTransaction().replicateEntities( - newServiceContext.getTransaction(), queries); - - // create export sql service from h2 db - ExportQueryService exportQueryService = - newServiceContext.newService(ExportQueryService.class); - - // get all queries from h2 db - queries = exportQueryService.getEntities(ExportQuery.class); - - // attach them to default created admin user in the db - for (ExportQuery query : queries) { - exportQueryService.createOrUpdate(query, admin); - } - } - - protected void importDb(EmbeddedApplicationConfiguration model, - EchoBaseServiceContext newServiceContext, - File exportZipFile, - EchoBaseUser admin) throws IOException, TopiaException { - ImportDbConfiguration importConfiguration = - new ImportDbConfiguration(model, getLocale()); - importConfiguration.getInput().setFile(exportZipFile); - File importTempDir = new File(model.getWorkingDirectory(), "importDb"); - importConfiguration.setWorkingDirectory(importTempDir); - - ImportDbService importDbService = - newServiceContext.newService(ImportDbService.class); - importDbService.importDb(importConfiguration, admin, false, true); - } - -} Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbConfiguration.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbConfiguration.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbConfiguration.java 2012-08-30 16:16:04 UTC (rev 574) @@ -1,96 +0,0 @@ -/* - * #%L - * EchoBase :: Services - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.services; - -import org.apache.commons.io.FileUtils; - -import java.io.File; -import java.io.IOException; - -/** - * Configuration of a complete db export. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class ExportDbConfiguration extends AbstractEchobaseActionConfiguration { - - private static final long serialVersionUID = 1L; - - private String fileName; - - private File workingDirectory; - - private File exportFile; - - /** Ids of voyages to push in embedded application (with all their datas). */ - private String[] voyageIds; - - public ExportDbConfiguration() { - } - - public ExportDbConfiguration(ProgressionModel progressionModel) { - super(progressionModel); - } - - public String getFileName() { - return fileName; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } - - public File getWorkingDirectory() { - return workingDirectory; - } - - public void setWorkingDirectory(File workingDirectory) { - this.workingDirectory = workingDirectory; - } - - public File getExportFile() { - return exportFile; - } - - public void setExportFile(File exportFile) { - this.exportFile = exportFile; - } - - public String[] getVoyageIds() { - return voyageIds; - } - - public void setVoyageIds(String... voyageIds) { - this.voyageIds = voyageIds; - } - - @Override - public void destroy() throws IOException { - if (workingDirectory != null) { - FileUtils.deleteDirectory(workingDirectory); - } - } - -} \ No newline at end of file Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -1,265 +0,0 @@ -/* - * #%L - * EchoBase :: Services - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.services; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Sets; -import fr.ifremer.echobase.EchoBaseIOUtil; -import fr.ifremer.echobase.entities.EchoBaseDbMeta; -import fr.ifremer.echobase.entities.EchoBaseEntityEnum; -import fr.ifremer.echobase.entities.data.Result; -import fr.ifremer.echobase.entities.data.Voyage; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.TopiaPersistenceHelper; -import org.nuiton.topia.persistence.csv.out.ExportEntityVisitor; -import org.nuiton.topia.persistence.csv.out.ExportModelFactory; -import org.nuiton.topia.persistence.csv.out.TopiaCsvExports; -import org.nuiton.topia.persistence.metadata.AssociationMeta; -import org.nuiton.topia.persistence.metadata.TableMeta; -import org.nuiton.util.FileUtil; -import org.nuiton.util.TimeLog; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Service to import / export a complete db. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class ExportDbService extends EchoBaseServiceSupport { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(ExportDbService.class); - - public static final TimeLog timeLog = new TimeLog(DbEditorService.class); - - /** - * Export the complete db into csv files stored in a zip archive file. - * - * @param model file name of the zip to create - * @throws IOException if could not create or write files. - */ - public void exportDb(ExportDbConfiguration model) throws IOException { - - String fileName = model.getFileName(); - - File tempDirectory = model.getWorkingDirectory(); - - File zipFile = new File(tempDirectory, fileName + ".zip"); - - if (log.isInfoEnabled()) { - log.info("Will export db to " + zipFile); - } - model.setExportFile(zipFile); - - ExportService exportService = getService(ExportService.class); - File dir = new File(tempDirectory, "echobase"); - - FileUtil.createDirectoryIfNecessary(dir); - - EchoBaseDbMeta dbMeta = getDbMeta(); - - model.setNbSteps(dbMeta.getEntriesSize()); - - for (TableMeta<EchoBaseEntityEnum> meta : dbMeta.getAllTables()) { - - model.incrementsProgression(); - - exportService.exportData(meta, new File(dir, meta.getFilename())); - } - - for (AssociationMeta<EchoBaseEntityEnum> meta : dbMeta.getAllAssociations()) { - - model.incrementsProgression(); - - exportService.exportData(meta, new File(dir, meta.getFilename())); - } - if (log.isInfoEnabled()) { - log.info("Export zip file = " + zipFile); - } - EchoBaseIOUtil.compressZipFile(zipFile, dir); - } - - /** - * Export the partial db into csv files at the given location. - * - * @param model file name of the zip to create - * @param computeSteps flag to compute stesp inside this method - * @throws IOException if could not create or write files. - */ - public void exportPartialDb(ExportDbConfiguration model, - boolean computeSteps) throws IOException { - - String fileName = model.getFileName(); - - File tempDirectory = model.getWorkingDirectory(); - File dir = new File(tempDirectory, "echobase"); - FileUtil.createDirectoryIfNecessary(dir); - - if (log.isInfoEnabled()) { - log.info("Will export to " + dir); - } - - File zipFile = new File(tempDirectory, fileName + ".zip"); - model.setExportFile(zipFile); - - ExportService exportService = getService(ExportService.class); - - // export all referentiel - List<TableMeta<EchoBaseEntityEnum>> refEntries = getDbMeta().getReferenceTables(); - List<AssociationMeta<EchoBaseEntityEnum>> refAssocEntries = getDbMeta().getReferenceAssociations(); - - boolean withVoyages = model.getVoyageIds() != null; - - if (computeSteps) { - int nbstesp = refEntries.size(); - - if (withVoyages) { - nbstesp += model.getVoyageIds().length; - } - - model.setNbSteps(nbstesp); - } - - for (TableMeta<EchoBaseEntityEnum> meta : refEntries) { - - model.incrementsProgression(); - - File entryFile = new File(dir, meta.getFilename()); - exportService.exportData(meta, entryFile); - } - - for (AssociationMeta<EchoBaseEntityEnum> associationMeta : refAssocEntries) { - - model.incrementsProgression(); - - File entryFile = new File(dir, associationMeta.getFilename()); - exportService.exportData(associationMeta, entryFile); - } - - if (withVoyages) { - List<TableMeta<EchoBaseEntityEnum>> dataEntries = - getDbMeta().getDataTables(); - List<AssociationMeta<EchoBaseEntityEnum>> dataAssociationEntries = - getDbMeta().getDataAssociations(); - - ReplicateEntityVisitor visitor = createVisitor( - exportService.getModelFactory(false), - dataEntries, - dataAssociationEntries, - dir - ); - - try { - for (String voyageId : model.getVoyageIds()) { - - model.incrementsProgression(); - - Voyage voyage = getEntityById(Voyage.class, voyageId); - visitor.export(voyage); - } - } finally { - // close visitor to close export files - visitor.close(); - } - } - - EchoBaseIOUtil.compressZipFile(zipFile, dir); - } - - public ReplicateEntityVisitor createVisitor(ExportModelFactory<EchoBaseEntityEnum> modelFactory, - List<TableMeta<EchoBaseEntityEnum>> entityMetas, - List<AssociationMeta<EchoBaseEntityEnum>> associations, - File container) { - - Preconditions.checkNotNull(modelFactory); - - Map<EchoBaseEntityEnum, TopiaCsvExports.EntityExportContext<EchoBaseEntityEnum>> contexts = TopiaCsvExports.createReplicateEntityVisitorContexts( - modelFactory, entityMetas, associations, container); - - ReplicateEntityVisitor result = new ReplicateEntityVisitor( - getDbMeta().getPersistenceHelper(), contexts); - return result; - } - - /** - * entity visitor to export data to csv files. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ - public static class ReplicateEntityVisitor extends ExportEntityVisitor<EchoBaseEntityEnum> { - - protected final Set<String> categoryIds; - - @Override - protected boolean isNoChildVisit(String propertyName, TopiaEntity entity) { - return Result.PROPERTY_CATEGORY.equals(propertyName) && - entity instanceof Result; - } - - public ReplicateEntityVisitor(TopiaPersistenceHelper<EchoBaseEntityEnum> typeProvider, - Map<EchoBaseEntityEnum, TopiaCsvExports.EntityExportContext<EchoBaseEntityEnum>> entityExporters) { - super(typeProvider, entityExporters); - categoryIds = Sets.newHashSet(); - } - - @Override - public void visit(TopiaEntity entity, String propertyName, - Class<?> type, Object value) { - if (Result.PROPERTY_CATEGORY.equals(propertyName) && - entity instanceof Result) { - - // export category - try { - TopiaEntity topiaEntity = (TopiaEntity) value; - if (categoryIds.add(topiaEntity.getTopiaId())) { - // add this new category - topiaEntity.accept(this); - } - - } catch (TopiaException e) { - if (log.isErrorEnabled()) { - log.error("Can not visit entity " + value, e); - } - } - } - } - - @Override - public void close() throws IOException { - categoryIds.clear(); - super.close(); - } - } -} Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportQueryService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportQueryService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportQueryService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -1,333 +0,0 @@ -/* - * #%L - * EchoBase :: Services - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.services; - -import com.google.common.base.Charsets; -import com.google.common.collect.Lists; -import fr.ifremer.echobase.EchoBaseTechnicalException; -import fr.ifremer.echobase.csv.EchoBaseCsvUtil; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.ExportQuery; -import fr.ifremer.echobase.entities.ExportQueryImpl; -import fr.ifremer.echobase.services.exceptions.ExportQueryNameAlreadyExistException; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.topia.framework.TopiaSQLQuery; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.util.PagerUtil; -import org.nuiton.util.csv.Export; -import org.nuiton.util.csv.ext.AbstractExportModel; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.List; -import java.util.Map; - -/** - * Service to deal with sql export. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class ExportQueryService extends EchoBaseServiceSupport { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ExportQueryService.class); - - public ExportQuery getExportQuery(String topiaId) { - ExportQuery exportQuery = getEntityById(ExportQuery.class, topiaId); - ExportQuery entityToSave = newExportQuery(); - entityToSave.setTopiaId(exportQuery.getTopiaId()); - entityToSave.setName(exportQuery.getName()); - entityToSave.setDescription(exportQuery.getDescription()); - entityToSave.setSqlQuery(exportQuery.getSqlQuery()); - entityToSave.setLastModifiedDate(exportQuery.getLastModifiedDate()); - entityToSave.setLastModifiedUser(exportQuery.getLastModifiedUser()); - return entityToSave; - } - - public ExportQuery createOrUpdate(ExportQuery exportQuery, - EchoBaseUser user) throws ExportQueryNameAlreadyExistException { - try { - TopiaDAO<ExportQuery> dao = getDAO(ExportQuery.class); - - // No id, creating new one entity - String id = exportQuery.getTopiaId(); - - boolean mustCreate = StringUtils.isEmpty(id); - - String queryName = exportQuery.getName(); - - - String hql = "FROM " + dao.getTopiaEntityEnum().getImplementationFQN() + - " WHERE " + ExportQuery.PROPERTY_NAME + " = :queryName"; - List<Object> params = Lists.<Object>newArrayList("queryName", queryName); - - if (!mustCreate) { - hql += " AND " + ExportQuery.TOPIA_ID + " = :id"; - params.add("id"); - params.add(id); - } -// TopiaQuery query = dao.createQuery(); -// query.addWhere(ExportQuery.PROPERTY_NAME, TopiaQuery.Op.EQ, queryName); -// -// if (!mustCreate) { -// query.addWhere(ExportQuery.TOPIA_ID, TopiaQuery.Op.NEQ, id); -// } - - // check query does not already exists with this name - boolean queryExists = dao.existsByQuery(hql, params.toArray()); - -// boolean queryExists = dao.existByQuery(query); - - if (queryExists) { - throw new ExportQueryNameAlreadyExistException(); - } - - ExportQuery entityToSave; - - exportQuery.setLastModifiedDate(newDate()); - exportQuery.setLastModifiedUser(user.getEmail()); - - if (mustCreate) { - entityToSave = dao.create(exportQuery); - } else { - entityToSave = dao.findByTopiaId(id); -// entityToSave.setName(queryName); - entityToSave.setDescription(exportQuery.getDescription()); - entityToSave.setSqlQuery(exportQuery.getSqlQuery()); - entityToSave.setLastModifiedDate(exportQuery.getLastModifiedDate()); - entityToSave.setLastModifiedUser(exportQuery.getLastModifiedUser()); - } - -// dao.update(entityToSave); - getTransaction().commitTransaction(); - return entityToSave; - } catch (TopiaException eee) { - throw new EchoBaseTechnicalException(eee); - } - } - - public void delete(String topiaId) { - try { - TopiaDAO<ExportQuery> dao = getDAO(ExportQuery.class); - ExportQuery entityToDelete = dao.findByTopiaId(topiaId); - dao.delete(entityToDelete); - - getTransaction().commitTransaction(); - } catch (TopiaException eee) { - throw new EchoBaseTechnicalException(eee); - } - } - - public void testSql(String sql) throws TopiaException { - - GenericSQLQuery sqlQuery = new GenericSQLQuery(sql, null); - - sqlQuery.getColumnNames(getTransaction()); - } - - public Map<String, Object>[] executeSql(String sql, PagerUtil.PagerBean pager) { - - // get a query to count all rows for the request - GenericSQLQuery sqlQuery = new GenericSQLQuery(sql, pager); - try { - List<Map<String, Object>> result = - sqlQuery.getResult(getTransaction()); - return result.toArray(new Map[result.size()]); - } catch (TopiaException eee) { - throw new EchoBaseTechnicalException( - "Could not execute sql query", eee); - } - } - - public String[] getColumnNames(String sql) { - - String limitSql = sql.trim(); - if (limitSql.endsWith(";")) { - limitSql = limitSql.substring(0, limitSql.length() - 1); - limitSql += " LIMIT 1"; - } - try { - // do a limit query to one result and obtain the column names - // from the meta data of the result set - GenericSQLQuery sqlQuery = new GenericSQLQuery(limitSql, null); - String[] result = sqlQuery.getColumnNames(getTransaction()); - return result; - } catch (TopiaException eee) { - throw new EchoBaseTechnicalException( - "Could not execute query " + limitSql + " for reason " + eee.getCause().getMessage(), eee); - } catch (Exception eee) { - throw new EchoBaseTechnicalException( - "Could not execute query " + limitSql + " for reason " + eee.getMessage(), eee); - } - } - - public String createCsvFileContent(String sql) { - - GenericSQLQuery sqlQuery = new GenericSQLQuery(sql, null); - List<Map<String, Object>> rows; - try { - rows = sqlQuery.getResult(getTransaction()); - } catch (TopiaException eee) { - throw new EchoBaseTechnicalException( - "Could not execute sql query", eee); - } - char csvSeparator = getConfiguration().getCsvSeparator(); - ExportQueryCsvModel csvModel = sqlQuery.generateCsvModel(csvSeparator); - Export<Map<String, Object>> exporter = Export.newExport(csvModel, rows); - try { - String content = exporter.toString(Charsets.UTF_8); - return content; - } catch (Exception eee) { - throw new EchoBaseTechnicalException("Could not export sql", eee); - } - } - - public ExportQuery newExportQuery() { - return new ExportQueryImpl(); - } - - public String processLibreOfficeSqlQuery(String libreOfficeQuery) { - - String result = libreOfficeQuery.replaceAll("\\\"", ""); - return result; - } - - private static class GenericSQLQuery extends TopiaSQLQuery<Map<String, Object>> { - - protected String[] columnNames; - - private final String sql; - - private final PagerUtil.PagerBean pager; - - public GenericSQLQuery(String sql, PagerUtil.PagerBean pager) { - this.sql = sql; - this.pager = pager; - } - - public String[] getColumnNames() { - return columnNames; - } - - public ExportQueryCsvModel generateCsvModel(char charSeparator) { - ExportQueryCsvModel model = new ExportQueryCsvModel( - charSeparator, - columnNames - ); - return model; - } - - public List<Map<String, Object>> getResult(TopiaContext tx) throws TopiaException { - List<Map<String, Object>> rows = - findMultipleResult((TopiaContextImplementor) tx); - return rows; - } - - public void testQuery(TopiaContext tx) throws TopiaException { - findSingleResult((TopiaContextImplementor) tx); - } - - public String[] getColumnNames(TopiaContext tx) throws TopiaException { - findSingleResult((TopiaContextImplementor) tx); - return columnNames; - } - - @Override - protected PreparedStatement prepareQuery(Connection connection) throws SQLException { - return connection.prepareStatement( - sql, - ResultSet.TYPE_SCROLL_INSENSITIVE, - ResultSet.CONCUR_READ_ONLY - ); - } - - @Override - protected void afterExecuteQuery(ResultSet set) throws SQLException { - super.afterExecuteQuery(set); - - // obtain columnNames - columnNames = getColumnNames(set); - - if (pager != null) { - - // must count rows - int nbRows = getNbRows(set); - if (log.isInfoEnabled()) { - log.info("For request " + sql + ", nb rows = " + nbRows); - } - pager.setRecords(nbRows); - PagerUtil.computeRecordIndexesAndPagesNumber(pager); - } - } - - @Override - protected Map<String, Object> prepareResult(ResultSet set) throws SQLException { - - if (pager != null) { - - // get row number (getRow() begins at 1) - int rowNumber = set.getRow() - 1; - if (rowNumber < pager.getRecordStartIndex() || - rowNumber >= pager.getRecordEndIndex()) { - - // out of pager bound, by returning null - // result will not be take in account - return null; - } - } - - Map<String, Object> result = getRowAsMap(columnNames, set); - return result; - } - - } - - /** - * Csv model to export sql in {@link ExportQueryService}. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ - public static class ExportQueryCsvModel extends AbstractExportModel<Map<String, Object>> { - - public ExportQueryCsvModel(char separator, String[] columnHeaders) { - super(separator); - for (String columnHeader : columnHeaders) { - newColumnForExport( - columnHeader, - EchoBaseCsvUtil.TO_STRING_FORMATTER - ); - } - } - - } -} Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -1,315 +0,0 @@ -/* - * #%L - * EchoBase :: Services - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.services; - -import fr.ifremer.echobase.entities.EchoBaseEntityEnum; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.csv.EntityCsvModel; -import org.nuiton.topia.persistence.csv.out.EntityAssociationExportModel; -import org.nuiton.topia.persistence.csv.out.ExportModelFactory; -import org.nuiton.topia.persistence.csv.out.PrepareDataForExport; -import org.nuiton.topia.persistence.csv.out.TopiaCsvExports; -import org.nuiton.topia.persistence.metadata.AssociationMeta; -import org.nuiton.topia.persistence.metadata.ColumnMeta; -import org.nuiton.topia.persistence.metadata.TableMeta; -import org.nuiton.util.csv.ExportModel; -import org.nuiton.util.decorator.Decorator; - -import java.io.File; -import java.util.List; - -/** - * To export datas from db to csv files. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class ExportService extends EchoBaseServiceSupport { -// -// /** Logger. */ -// private static final Log log = LogFactory.getLog(ExportService.class); -// -// public static final TimeLog TIME_LOG = new TimeLog(ExportService.class); - -// public ExportModelFactory<EchoBaseEntityEnum> getDefaultExportFactory() { -// return defaultExportFactory; -// } - -// public ExportModelFactory<EchoBaseEntityEnum> getAsSeenExportFactory() { -// return asSeenExportFactory; -// } - -// @Override -// public <E extends TopiaEntity> ExportModel<E> buildForExport(AssociationMeta<EchoBaseEntityEnum> associationMeta) { -// -// ExportModel<E> model = EntityAssociationExportModel.newExportModel( -// getConfiguration().getCsvSeparator(), -// associationMeta -// ); -// return model; -// } -// -// @Override -// public <E extends TopiaEntity> ExportModel<E> buildForExport(TableMeta<EchoBaseEntityEnum> meta, boolean asSeen) { -// -// EntityCsvModel<EchoBaseEntityEnum, E> model; -// -// if (asSeen) { -// -// // no need to have topiaId as first column -// model = EntityCsvModel.newModel( -// getConfiguration().getCsvSeparator(), -// meta -// ); -// } else { -// -// // normla export add topiaId column -// model = EntityCsvModel.newModel( -// getConfiguration().getCsvSeparator(), -// meta, -// TopiaEntity.TOPIA_ID -// ); -// } -// -// DecoratorService service = getService(DecoratorService.class); -// -// for (ColumnMeta columnMeta : meta) { -// String propertyName = columnMeta.getName(); -// Class<?> type = columnMeta.getType(); -// if (columnMeta.isFK()) { -// -// Class<TopiaEntity> entityType = (Class<TopiaEntity>) type; -// if (asSeen) { -// -// // export decorated foreign key value -// Decorator<TopiaEntity> decorator = -// service.getDecorator(getLocale(), entityType, null); -// model.addDecoratedForeignKeyForExport(propertyName, propertyName, decorator); -// } else { -// -// // export foreign key value as his topiaId -// model.addForeignKeyForExport(propertyName, entityType); -// } -// } else { -// model.addDefaultColumn(propertyName, type); -// } -// } -// return model; -// } - - public String exportDatas(TableMeta<EchoBaseEntityEnum> tableMeta, boolean asSeen) { - - String result = TopiaCsvExports.exportData(tableMeta, - getModelFactory(asSeen), - defaultPrepareDataForExport); - return result; -// -// Export<TopiaEntity> export = prepareExport(tableMeta, asSeen); -// -// try { -// return export.toString(Charsets.UTF_8); -// } catch (Exception eee) { -// throw new EchoBaseTechnicalException("Can not export datas", eee); -// } - } - - public void exportData(TableMeta<EchoBaseEntityEnum> tableMeta, File file) { - - TopiaCsvExports.exportData(tableMeta, - defaultExportFactory, - defaultPrepareDataForExport, - file); - -// if (log.isInfoEnabled()) { -// log.info("Export table " + tableMeta + " to " + file); -// } -// long s1 = TimeLog.getTime(); -// Export<TopiaEntity> export = prepareExport(tableMeta, false); -// TIME_LOG.log(s1, "exportData::prepareExport"); -// long s2 = TimeLog.getTime(); -// try { -// export.write(file, Charsets.UTF_8); -// } catch (Exception eee) { -// throw new EchoBaseTechnicalException("Can not export datas", eee); -// } -// TIME_LOG.log(s2, "exportData::exportToFile"); - } - - public void exportData(AssociationMeta<EchoBaseEntityEnum> associationMeta, File file) { - - TopiaCsvExports.exportData(associationMeta, - defaultExportFactory, - defaultPrepareDataForExport, - file); -// if (log.isInfoEnabled()) { -// log.info("Export association " + associationMeta + " to " + file); -// } -// long s1 = TimeLog.getTime(); -// Export<TopiaEntity> export = prepareExport(associationMeta); -// TIME_LOG.log(s1, "exportData::prepareExport"); -// -// long s2 = TimeLog.getTime(); -// try { -// export.write(file, Charsets.UTF_8); -// } catch (Exception eee) { -// throw new EchoBaseTechnicalException("Can not export datas", eee); -// } -// TIME_LOG.log(s2, "exportData::exportToFile"); - } - - public ExportModelFactory<EchoBaseEntityEnum> getModelFactory(boolean asSeen) { - ExportModelFactory<EchoBaseEntityEnum> result; - if (asSeen) { - result = asSeenExportFactory; - } else { - result = defaultExportFactory; - } - return result; - } - -// protected Export<TopiaEntity> prepareExport(TableMeta<EchoBaseEntityEnum> tableMeta, boolean asSeen) { -// -// List<TopiaEntity> datas = defaultPrepareDataForExport.prepareData(tableMeta); -// -// ExportModel<TopiaEntity> model; -// if (asSeen) { -// model = asSeenExportFactory.buildForExport(tableMeta); -// } else { -// model = defaultExportFactory.buildForExport(tableMeta); -// -// } -// return Export.newExport(model, datas); -// } - -// protected Export<TopiaEntity> prepareExport(AssociationMeta<EchoBaseEntityEnum> associationMeta) { -// -// List<TopiaEntity> datas = defaultPrepareDataForExport.prepareExport(associationMeta); -// ExportModel<TopiaEntity> model = defaultExportFactory.buildForExport(associationMeta); -// return Export.newExport(model, datas); -// } - - private ExportModelFactory<EchoBaseEntityEnum> defaultExportFactory = new ExportModelFactory<EchoBaseEntityEnum>() { - - @Override - public <E extends TopiaEntity> ExportModel<E> buildForExport(TableMeta<EchoBaseEntityEnum> meta) { - - // normal export add topiaId column - EntityCsvModel<EchoBaseEntityEnum, E> model = EntityCsvModel.newModel( - getConfiguration().getCsvSeparator(), - meta, - TopiaEntity.TOPIA_ID - ); - - for (ColumnMeta columnMeta : meta) { - String propertyName = columnMeta.getName(); - Class<?> type = columnMeta.getType(); - if (columnMeta.isFK()) { - - Class<TopiaEntity> entityType = (Class<TopiaEntity>) type; - - - // export foreign key value as his topiaId - model.addForeignKeyForExport(propertyName, entityType); - - } else { - model.addDefaultColumn(propertyName, type); - } - } - return model; - } - - @Override - public <E extends TopiaEntity> ExportModel<E> buildForExport(AssociationMeta<EchoBaseEntityEnum> associationMeta) { - ExportModel<E> model = EntityAssociationExportModel.newExportModel( - getConfiguration().getCsvSeparator(), - associationMeta - ); - return model; - } - }; - - private ExportModelFactory<EchoBaseEntityEnum> asSeenExportFactory = new ExportModelFactory<EchoBaseEntityEnum>() { - - @Override - public <E extends TopiaEntity> ExportModel<E> buildForExport(TableMeta<EchoBaseEntityEnum> meta) { - - - // no need to have topiaId as first column - EntityCsvModel<EchoBaseEntityEnum, E> model = EntityCsvModel.newModel( - getConfiguration().getCsvSeparator(), - meta - ); - - - DecoratorService service = getService(DecoratorService.class); - - for (ColumnMeta columnMeta : meta) { - String propertyName = columnMeta.getName(); - Class<?> type = columnMeta.getType(); - if (columnMeta.isFK()) { - - Class<TopiaEntity> entityType = (Class<TopiaEntity>) type; - - // export decorated foreign key value - Decorator<TopiaEntity> decorator = - service.getDecorator(getLocale(), entityType, null); - model.addDecoratedForeignKeyForExport(propertyName, propertyName, decorator); - - } else { - model.addDefaultColumn(propertyName, type); - } - } - return model; - } - - @Override - public <E extends TopiaEntity> ExportModel<E> buildForExport(AssociationMeta<EchoBaseEntityEnum> associationMeta) { - ExportModel<E> model = EntityAssociationExportModel.newExportModel( - getConfiguration().getCsvSeparator(), - associationMeta - ); - return model; - } - }; - - private PrepareDataForExport<EchoBaseEntityEnum> defaultPrepareDataForExport = new PrepareDataForExport<EchoBaseEntityEnum>() { - - @Override - public <E extends TopiaEntity> List<E> prepareData(TableMeta<EchoBaseEntityEnum> tableMeta) { - DbEditorService service = getService(DbEditorService.class); - - List<E> data = service.getEntities(tableMeta, null, null, null, null); - return data; - } - - @Override - public <E extends TopiaEntity> List<E> prepareData(AssociationMeta<EchoBaseEntityEnum> associationMeta) { - DbEditorService service = getService(DbEditorService.class); - - TableMeta<EchoBaseEntityEnum> tableMeta = service.getTableMeta(associationMeta.getSource()); - List<E> data = service.getEntities(tableMeta, null, null, null, "size(e." + associationMeta.getName() + ") > 0"); - return data; - } - }; -} Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbConfiguration.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbConfiguration.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbConfiguration.java 2012-08-30 16:16:04 UTC (rev 574) @@ -1,78 +0,0 @@ -/* - * #%L - * EchoBase :: Services - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.services; - -import fr.ifremer.echobase.InputFile; -import org.apache.commons.io.FileUtils; - -import java.io.File; -import java.io.IOException; -import java.util.Locale; - -import static org.nuiton.i18n.I18n.l_; - -/** - * Configuration of a import db operation. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class ImportDbConfiguration extends AbstractEchobaseActionConfiguration { - - private static final long serialVersionUID = 1L; - - protected File workingDirectory; - - protected final InputFile input; - - public ImportDbConfiguration(ProgressionModel progressionModel, - Locale locale) { - super(progressionModel); - input = InputFile.newFile(l_(locale, "echobase.common.importDbFile")); - } - - public ImportDbConfiguration(Locale locale) { - input = InputFile.newFile(l_(locale, "echobase.common.importDbFile")); - } - - public File getWorkingDirectory() { - return workingDirectory; - } - - public InputFile getInput() { - return input; - } - - public void setWorkingDirectory(File workingDirectory) { - this.workingDirectory = workingDirectory; - } - - @Override - public void destroy() throws IOException { - if (workingDirectory != null) { - FileUtils.deleteDirectory(workingDirectory); - } - } - -} Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -1,237 +0,0 @@ -/* - * #%L - * EchoBase :: Services - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.services; - -import com.google.common.collect.Lists; -import fr.ifremer.echobase.entities.EchoBaseDbMeta; -import fr.ifremer.echobase.entities.EchoBaseEntityEnum; -import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.entities.EntityModificationLog; -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.persistence.TopiaDAO; -import org.nuiton.topia.persistence.csv.in.CsvImportResult; -import org.nuiton.topia.persistence.csv.in.TopiaCsvImports; -import org.nuiton.topia.persistence.metadata.AssociationMeta; -import org.nuiton.topia.persistence.metadata.TableMeta; -import org.nuiton.util.TimeLog; - -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.List; -import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -/** - * Service to import a complete db. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class ImportDbService extends EchoBaseServiceSupport { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(ImportDbService.class); - - public static final TimeLog TIME_LOG = new TimeLog(ImportDbService.class); - - /** - * Import a complete db from the given zip file. - * - * @param model model of the db import operation - * @param user user which perform the import - * @param computeSteps flag to compute stesp inside this method - * @param commitAfterEachFile flag to commit after each imported file - * @throws IOException if any io exception while import - * @throws TopiaException if any pb while topia treatment - */ - public void importDb(ImportDbConfiguration model, - EchoBaseUser user, - boolean computeSteps, - boolean commitAfterEachFile) throws IOException, TopiaException { - - File file = model.getInput().getFile(); - - ZipFile zipFile = new ZipFile(file); - try { - - List<String> missingEntries = Lists.newArrayList(); - - EchoBaseDbMeta dbMeta = getDbMeta(); - - Map<TableMeta<EchoBaseEntityEnum>, ZipEntry> tables = TopiaCsvImports.discoverEntries( - "echobase/", dbMeta.getAllTables(), - zipFile, missingEntries); - - Map<AssociationMeta<EchoBaseEntityEnum>, ZipEntry> associations = TopiaCsvImports.discoverEntries( - "echobase/", dbMeta.getAllAssociations(), - zipFile, missingEntries); - - if (computeSteps) { - int size = tables.size() + associations.size(); - model.setNbSteps(size + missingEntries.size()); - } - - for (String missingEntry : missingEntries) { - - // skip thoses not found entries - model.incrementsProgression(); - - if (log.isInfoEnabled()) { - log.info("Skip not found entry " + missingEntry); - } - } - - DefaultImportStrategy strategy = new DefaultImportStrategy( - getService(ImportService.class), - getTransaction(), - dbMeta.getPersistenceHelper(), - 1000 - ); - - importTables(strategy, model, zipFile, tables, commitAfterEachFile); - - importAssociations(strategy, model, zipFile, associations); - - // add a log entry of import db - if (log.isInfoEnabled()) { - log.info("Import done with user " + user.getEmail()); - } - TopiaDAO<EntityModificationLog> dao = - getDAO(EntityModificationLog.class); - - dao.create( - EntityModificationLog.PROPERTY_ENTITY_TYPE, "Import db", - EntityModificationLog.PROPERTY_ENTITY_ID, "Complete db", - EntityModificationLog.PROPERTY_MODIFICATION_USER, user.getEmail(), - EntityModificationLog.PROPERTY_MODIFICATION_DATE, newDate(), - EntityModificationLog.PROPERTY_MODIFICATION_TEXT, "import db from file " + file.getName() - ); - commitTransaction("Could not commit db import from file " + file); - - } finally { - zipFile.close(); - } - } - - private void importTables(DefaultImportStrategy strategy, - ImportDbConfiguration model, - ZipFile zipFile, - Map<TableMeta<EchoBaseEntityEnum>, ZipEntry> entriestoConsume, - boolean commitAfterEachFile) throws IOException, TopiaException { - - for (Map.Entry<TableMeta<EchoBaseEntityEnum>, ZipEntry> entry : - entriestoConsume.entrySet()) { - - model.incrementsProgression(); - - TableMeta<EchoBaseEntityEnum> entryDef = entry.getKey(); - ZipEntry value = entry.getValue(); - CsvImportResult<EchoBaseEntityEnum> csvResult = CsvImportResult.newResult( - entryDef.getSource(), - value.getName(), - false - ); - - Reader reader = IOUtils.toBufferedReader(new InputStreamReader(zipFile.getInputStream(value))); - try { - - long s0 = TimeLog.getTime(); - - if (log.isInfoEnabled()) { - log.info("Will import " + entryDef); - } - TopiaCsvImports.importTable(reader, - strategy, - entryDef, - csvResult - ); - - s0 = TIME_LOG.log(s0, "importFile::done"); - - flushTransaction(); - - TIME_LOG.log(s0, "importFile::flushTransaction"); - } finally { - reader.close(); - - if (commitAfterEachFile) { - commitTransaction( - "Could not commit db import from file " + - zipFile.getName() + "#" + entryDef.getFilename()); - } - } - } - } - - private void importAssociations(DefaultImportStrategy strategy, - ImportDbConfiguration model, - ZipFile zipFile, - Map<AssociationMeta<EchoBaseEntityEnum>, ZipEntry> associations) throws IOException, TopiaException { - - for (Map.Entry<AssociationMeta<EchoBaseEntityEnum>, ZipEntry> entry : - associations.entrySet()) { - - model.incrementsProgression(); - - AssociationMeta<EchoBaseEntityEnum> entryDef = entry.getKey(); - ZipEntry value = entry.getValue(); - - CsvImportResult<EchoBaseEntityEnum> csvResult = CsvImportResult.newResult( - entryDef.getSource(), - value.getName(), - false - ); - - Reader reader = IOUtils.toBufferedReader(new InputStreamReader(zipFile.getInputStream(value))); - try { - long s0 = TimeLog.getTime(); - - if (log.isInfoEnabled()) { - log.info("Will import " + entryDef); - } - - TopiaCsvImports.importAssociation(reader, - strategy, - entryDef, - csvResult); - - s0 = TIME_LOG.log(s0, "importFile::done"); - - flushTransaction(); - - TIME_LOG.log(s0, "importFile::flushTransaction"); - } finally { - reader.close(); - } - } - } - -} Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportException.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportException.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportException.java 2012-08-30 16:16:04 UTC (rev 574) @@ -1,56 +0,0 @@ -/* - * #%L - * EchoBase :: Services - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 - 2012 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.services; - -import fr.ifremer.echobase.InputFile; -import org.nuiton.util.csv.ImportRuntimeException; - -import java.util.Locale; - -import static org.nuiton.i18n.I18n.l_; - -/** - * Exception when a import new data failed. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.3 - */ -public class ImportException extends Exception { - - private static final long serialVersionUID = 1L; - - public ImportException(String message) { - super(message); - } - - public ImportException(String message, Throwable cause) { - super(message, cause); - } - - public ImportException(Locale locale, InputFile inputfile, ImportRuntimeException importError) { - this(l_(locale, "echobase.importError.fromFile", - inputfile.getFile().getName(), - importError.getMessage()), importError); - } -} Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -1,165 +0,0 @@ -/* - * #%L - * EchoBase :: Services - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.services; - -import com.google.common.base.Charsets; -import com.google.common.io.Files; -import fr.ifremer.echobase.EchoBaseTechnicalException; -import fr.ifremer.echobase.entities.EchoBaseEntityEnum; -import fr.ifremer.echobase.entities.EchoBaseUser; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.topia.persistence.TopiaEntity; -import org.nuiton.topia.persistence.csv.EntityCsvModel; -import org.nuiton.topia.persistence.csv.in.CsvImportResult; -import org.nuiton.topia.persistence.csv.in.EntityAssociationImportModel; -import org.nuiton.topia.persistence.csv.in.ImportModelFactory; -import org.nuiton.topia.persistence.metadata.AssociationMeta; -import org.nuiton.topia.persistence.metadata.ColumnMeta; -import org.nuiton.topia.persistence.metadata.TableMeta; -import org.nuiton.util.csv.Import; -import org.nuiton.util.csv.ImportModel; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.util.Collection; -import java.util.Map; - -/** - * To import datas from csv files into the db. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.2 - */ -public class ImportService extends EchoBaseServiceSupport implements ImportModelFactory<EchoBaseEntityEnum> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ImportService.class); - - @Override - public <E extends TopiaEntity> ImportModel<E> buildForImport(TableMeta<EchoBaseEntityEnum> meta) { - - DbEditorService service = getService(DbEditorService.class); - - EntityCsvModel<EchoBaseEntityEnum, E> model = EntityCsvModel.newModel( - getConfiguration().getCsvSeparator(), - meta, - TopiaEntity.TOPIA_ID - ); - - for (ColumnMeta columnMeta : meta) { - String propertyName = columnMeta.getName(); - Class<?> type = columnMeta.getType(); - if (columnMeta.isFK()) { - - Class<TopiaEntity> entityType = (Class<TopiaEntity>) type; - Collection<TopiaEntity> universe = service.getForeignDatas(entityType); - model.addForeignKeyForImport(propertyName, entityType, universe); - } else { - model.addDefaultColumn(propertyName, type); - } - } - return model; - } - - @Override - public ImportModel<Map<String, Object>> buildForImport(AssociationMeta<EchoBaseEntityEnum> meta) { - - ImportModel<Map<String, Object>> model = - EntityAssociationImportModel.newImportModel( - getConfiguration().getCsvSeparator(), - meta - ); - return model; - } - - @Override - public boolean isNMAssociationMeta(AssociationMeta<EchoBaseEntityEnum> meta) { - EchoBaseEntityEnum source = meta.getSource(); - EchoBaseEntityEnum target = meta.getTarget(); - boolean result = false; - if (source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Echotype || - source == EchoBaseEntityEnum.Echotype && target == EchoBaseEntityEnum.Species || - source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Strata) { - result = true; - } - return result; - } - - public CsvImportResult<EchoBaseEntityEnum> importDatas(EchoBaseEntityEnum entityType, - String importFileName, - File importFile, - boolean createIfNotFound, - EchoBaseUser user) throws IOException { - - DbEditorService service = getService(DbEditorService.class); - - TableMeta<EchoBaseEntityEnum> meta = service.getTableMeta(entityType); - ImportModel<TopiaEntity> csvModel = buildForImport(meta); - String messagePrefix = "Import du fichier " + importFileName + " le " + newDate(); - - CsvImportResult<EchoBaseEntityEnum> result = CsvImportResult.newResult( - entityType, importFileName, createIfNotFound); - - BufferedReader bf = Files.newReader(importFile, Charsets.UTF_8); - try { - - Import<TopiaEntity> importer = Import.newImport(csvModel, bf); - - try { - for (TopiaEntity entity : importer) { - boolean create = service.saveEntity(meta, - messagePrefix, - entity, - user, - createIfNotFound - ); - - if (create) { - - result.incrementsNumberCreated(); - } else { - - result.incrementsNumberUpdated(); - } - } - } finally { - - importer.close(); - } - - commitTransaction("Could not commit transaction"); - } catch (EchoBaseTechnicalException eee) { - throw eee; - } catch (Exception eee) { - log.error("Failed to read import file " + importFile.getName(), eee); - throw new EchoBaseTechnicalException(eee); - } finally { - bf.close(); - } - return result; - } - -} Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/UserService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/UserService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/UserService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -101,7 +101,6 @@ userToCreateOrUpdate = dao.create( EchoBaseUser.PROPERTY_EMAIL, user.getEmail(), EchoBaseUser.PROPERTY_PASSWORD, encodePassword(password) - ); } else { userToCreateOrUpdate = getEntityById(EchoBaseUser.class, id); @@ -112,8 +111,6 @@ } } userToCreateOrUpdate.setAdmin(user.isAdmin()); - -// dao.update(userToCreateOrUpdate); commitTransaction("Could not create or update user"); } catch (TopiaException eee) { throw new EchoBaseTechnicalException(eee); Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationConfiguration.java (from rev 565, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationConfiguration.java) =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationConfiguration.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationConfiguration.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,104 @@ +/* + * #%L + * EchoBase :: Services + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.services.embeddedapplication; + +import fr.ifremer.echobase.services.AbstractEchobaseActionConfiguration; +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; + +/** + * Configuration of a embedded application creation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class EmbeddedApplicationConfiguration extends AbstractEchobaseActionConfiguration { + + private static final long serialVersionUID = 1L; + + /** File name of the embedded application archive (without the zip extension). */ + private String fileName; + + /** Working directory where to generate the archive of embedded application. */ + private File workingDirectory; + + /** Embedded application archive file. */ + private File embeddedApplicationFile; + + /** Location of the war file to push in embedded application. */ + private File warLocation; + + /** Ids of voyages to push in embedded application (with all their datas). */ + private String[] voyageIds; + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public File getWorkingDirectory() { + return workingDirectory; + } + + public void setWorkingDirectory(File workingDirectory) { + this.workingDirectory = workingDirectory; + } + + public File getEmbeddedApplicationFile() { + return embeddedApplicationFile; + } + + public void setEmbeddedApplicationFile(File embeddedApplicationFile) { + this.embeddedApplicationFile = embeddedApplicationFile; + } + + public String[] getVoyageIds() { + return voyageIds; + } + + public void setVoyageIds(String[] voyageIds) { + this.voyageIds = Arrays.copyOf(voyageIds, voyageIds.length); + } + + public File getWarLocation() { + return warLocation; + } + + public void setWarLocation(File warLocation) { + this.warLocation = warLocation; + } + + @Override + public void destroy() throws IOException { + if (workingDirectory != null) { + FileUtils.deleteDirectory(workingDirectory); + } + } +} \ No newline at end of file Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationConfiguration.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationService.java (from rev 565, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java) =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,373 @@ +/* + * #%L + * EchoBase :: Services + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.services.embeddedapplication; + +import com.google.common.base.Charsets; +import com.google.common.base.Preconditions; +import fr.ifremer.echobase.EchoBaseIOUtil; +import fr.ifremer.echobase.EchoBaseTechnicalException; +import fr.ifremer.echobase.EchoBaseTopiaRootContextFactory; +import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.entities.ExportQuery; +import fr.ifremer.echobase.services.DefaultEchoBaseServiceContext; +import fr.ifremer.echobase.services.EchoBaseServiceContext; +import fr.ifremer.echobase.services.EchoBaseServiceSupport; +import fr.ifremer.echobase.services.UserService; +import fr.ifremer.echobase.services.exceptions.ExportQueryNameAlreadyExistException; +import fr.ifremer.echobase.services.exportdb.ExportDbConfiguration; +import fr.ifremer.echobase.services.exportdb.ExportDbService; +import fr.ifremer.echobase.services.exportquery.ExportQueryService; +import fr.ifremer.echobase.services.importdb.ImportDbConfiguration; +import fr.ifremer.echobase.services.importdb.ImportDbService; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.util.FileUtil; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.net.URISyntaxException; +import java.util.List; +import java.util.Properties; + +/** + * To create embedded application. + * + * @author tchemit <chemit@codelutin.com> + * @author sletellier <letellier@codelutin.com> + * @since 0.1 + */ +public class EmbeddedApplicationService extends EchoBaseServiceSupport { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(EmbeddedApplicationService.class); + + public static final String EMBEDDED_PATH = "/embedded/"; + + public File createEmbeddedApplication(EmbeddedApplicationConfiguration model) { + + int nbSteps = computeNbSteps(model); + model.setNbSteps(nbSteps); + + String fileName = model.getFileName(); + + File tempDirectory = model.getWorkingDirectory(); + tempDirectory.deleteOnExit(); + + File zipFile = new File(tempDirectory, fileName + ".zip"); + model.setEmbeddedApplicationFile(zipFile); + + File dir = new File(tempDirectory, fileName); + + if (log.isInfoEnabled()) { + log.info("Creates embedded application to file [" + zipFile + "]"); + } + + // export db to csv + File exportZipFile = exportDb(model, tempDirectory); + + // create static archive structure + createStaticArchiveStructure(model, dir); + + model.incrementsProgression(); + + //FIXME Review this to works with internal and working db... + // create h2 db in /db + TopiaContext rootContext = + new EchoBaseTopiaRootContextFactory().newEmbeddedDatabase(dir); + + TopiaContext topiaContext = null; + try { + + topiaContext = rootContext.beginTransaction(); + + model.incrementsProgression(); + + // create new service context (with new transaction) + EchoBaseServiceContext newServiceContext = + DefaultEchoBaseServiceContext.newContext(serviceContext, + null, + topiaContext); + + EchoBaseUser admin = createUsers(newServiceContext); + + model.incrementsProgression(); + + copyExportQueries(newServiceContext, admin); + + model.incrementsProgression(); + + importDb(model, newServiceContext, exportZipFile, admin); + + } catch (Exception eee) { + rollbackTransaction( + topiaContext, + "Could not rollback h2 embedded database at " + dir); + throw new EchoBaseTechnicalException( + "Could not create h2 embedded database at " + dir, eee); + } finally { + closeContext(rootContext, + "Could not close h2 embedded database at " + dir); + } + + try { + EchoBaseIOUtil.compressZipFile(zipFile, dir); + } catch (IOException eee) { + throw new EchoBaseTechnicalException( + "Could not create zip file at " + zipFile, eee); + } + + return zipFile; + } + + protected void closeContext(TopiaContext tx, String message) { + try { + tx.closeContext(); + } catch (TopiaException eee) { + throw new EchoBaseTechnicalException(message, eee); + } + } + + protected TopiaContext beginTransaction(TopiaContext tx, String message) { + try { + return tx.beginTransaction(); + } catch (TopiaException eee) { + throw new EchoBaseTechnicalException(message, eee); + } + } + + protected void rollbackTransaction(TopiaContext tx, String message) { + try { + if (tx != null) { + tx.rollbackTransaction(); + } + } catch (TopiaException eee) { + if (log.isErrorEnabled()) { + log.error(message, eee); + } + } + } + + protected int computeNbSteps(EmbeddedApplicationConfiguration model) { + int nbSteps = 4; + + // export db steps + + nbSteps += getDbMeta().getReferenceEntriesSize(); + if (model.getVoyageIds() != null) { + nbSteps += model.getVoyageIds().length; + } + + // import db stesp + nbSteps += getDbMeta().getEntriesSize(); + return nbSteps; + } + + protected void createStaticArchiveStructure(EmbeddedApplicationConfiguration model, File dir) { + + try { + File warLocation = model.getWarLocation(); + + // create / + FileUtil.createDirectoryIfNecessary(dir); + + // copy embedded files to / + copyEmbeddedFiles(dir); + + // copy war to / + FileUtils.copyFile(warLocation, new File(dir, warLocation.getName())); + } catch (Exception eee) { + throw new EchoBaseTechnicalException("Could not create embedded zip structure at " + dir, eee); + } + } + + protected File exportDb(EmbeddedApplicationConfiguration model, + File tempDirectory) { + + try { + // create export zip file + ExportDbConfiguration exportconfiguration = + new ExportDbConfiguration(model); + exportconfiguration.setFileName("echobase-export"); + File exportTempDir = new File(tempDirectory, "exportDb"); + exportconfiguration.setWorkingDirectory(exportTempDir); + exportconfiguration.setVoyageIds(model.getVoyageIds()); + TopiaContext transaction = serviceContext.getTransaction(); + + TopiaContext newTx = beginTransaction( + transaction, + "Could not begin transaction on main db"); + try { + serviceContext.setTransaction(newTx); + ExportDbService exportDbService = + serviceContext.newService(ExportDbService.class); + exportDbService.exportPartialDb(exportconfiguration, false); + } catch (IOException eee) { + rollbackTransaction( + newTx, + "Could not rollback transaction on db"); + throw eee; + } catch (RuntimeException eee) { + rollbackTransaction( + newTx, + "Could not rollback transaction on db"); + throw eee; + } finally { + serviceContext.setTransaction(transaction); + closeContext(newTx, "Could not close transaction on main db"); + } + File exportZipFile = exportconfiguration.getExportFile(); + if (log.isInfoEnabled()) { + log.info("Export zip file = " + exportZipFile); + } + return exportZipFile; + } catch (IOException eee) { + throw new EchoBaseTechnicalException( + "Could not export db to zip", eee); + } + } + + public File getPilotsDirectory(File dataDirectory) { + File driverDir = new File(dataDirectory, "drivers"); + return driverDir; + } + + public String getH2PilotFilename(Properties config) { + String h2Version = config.getProperty("h2Version"); + return h2Version == null ? null : "h2-" + h2Version + ".jar"; + } + + public String getPostgresqlPilotFilename(Properties config) { + String pgVersion = config.getProperty("postgresqlVersion"); + return pgVersion == null ? null : "postgresql-" + pgVersion + ".jar"; + } + + protected void copyEmbeddedFiles(File zipDirectory) throws IOException, URISyntaxException { + + // config to keep the echobase-embedded values (contains h2 and pg versions) + Properties config = new Properties(); + copyEmbeddedFiles("echobase.properties", zipDirectory, config); + + copyEmbeddedFiles("startEchobase.bat", zipDirectory, null); + copyEmbeddedFiles("startEchobase.sh", zipDirectory, null); + copyEmbeddedFiles("README.txt", zipDirectory, null); + + File driverDir = getPilotsDirectory(zipDirectory); + FileUtil.createDirectoryIfNecessary(driverDir); + copyEmbeddedFiles(getH2PilotFilename(config), driverDir, null); + copyEmbeddedFiles(getPostgresqlPilotFilename(config), driverDir, null); + } + + protected void copyEmbeddedFiles(String resourceName, + File zipDirectory, + Properties config) throws IOException { + String resourcePath = EMBEDDED_PATH + resourceName; + InputStream inputStream = getClass().getResourceAsStream(resourcePath); + Preconditions.checkNotNull(inputStream, + "could not find resource " + resourcePath); + try { + if (config != null) { + config.load(inputStream); + } + File outputFile = new File(zipDirectory, resourceName); + if (log.isInfoEnabled()) { + log.info("Copy configuration to " + resourceName + " to " + outputFile); + } + OutputStreamWriter outputStream = new OutputStreamWriter( + new FileOutputStream(outputFile), Charsets.UTF_8); + try { + if (config == null) { + IOUtils.copy(inputStream, outputStream); + } else { + config.store(outputStream, null); + } + } finally { + outputStream.close(); + } + } finally { + inputStream.close(); + } + } + + protected EchoBaseUser createUsers(EchoBaseServiceContext newServiceContext) { + + // get user service from h2 db + UserService userService = + newServiceContext.newService(UserService.class); + + // create admin user + userService.createDefaultUsers(); + + // get admin from h2 db + EchoBaseUser admin = userService.getUserByEmail( + UserService.DEFAULT_ADMIN_EMAIL); + return admin; + } + + protected void copyExportQueries(EchoBaseServiceContext newServiceContext, + EchoBaseUser admin) throws TopiaException, ExportQueryNameAlreadyExistException { + + // get all export queries from application + List<ExportQuery> queries = getEntities(ExportQuery.class); + + // replicate queries + getTransaction().replicateEntities( + newServiceContext.getTransaction(), queries); + + // create export sql service from h2 db + ExportQueryService exportQueryService = + newServiceContext.newService(ExportQueryService.class); + + // get all queries from h2 db + queries = exportQueryService.getEntities(ExportQuery.class); + + // attach them to default created admin user in the db + for (ExportQuery query : queries) { + exportQueryService.createOrUpdate(query, admin); + } + } + + protected void importDb(EmbeddedApplicationConfiguration model, + EchoBaseServiceContext newServiceContext, + File exportZipFile, + EchoBaseUser admin) throws IOException, TopiaException { + ImportDbConfiguration importConfiguration = + new ImportDbConfiguration(model, getLocale()); + importConfiguration.getInput().setFile(exportZipFile); + File importTempDir = new File(model.getWorkingDirectory(), "importDb"); + importConfiguration.setWorkingDirectory(importTempDir); + + ImportDbService importDbService = + newServiceContext.newService(ImportDbService.class); + importDbService.importDb(importConfiguration, admin, false, true); + } + +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/embeddedapplication/EmbeddedApplicationService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportDbConfiguration.java (from rev 565, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbConfiguration.java) =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportDbConfiguration.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportDbConfiguration.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,98 @@ +/* + * #%L + * EchoBase :: Services + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.services.exportdb; + +import fr.ifremer.echobase.services.AbstractEchobaseActionConfiguration; +import fr.ifremer.echobase.services.ProgressionModel; +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.IOException; + +/** + * Configuration of a complete db export. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class ExportDbConfiguration extends AbstractEchobaseActionConfiguration { + + private static final long serialVersionUID = 1L; + + private String fileName; + + private File workingDirectory; + + private File exportFile; + + /** Ids of voyages to push in embedded application (with all their datas). */ + private String[] voyageIds; + + public ExportDbConfiguration() { + } + + public ExportDbConfiguration(ProgressionModel progressionModel) { + super(progressionModel); + } + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public File getWorkingDirectory() { + return workingDirectory; + } + + public void setWorkingDirectory(File workingDirectory) { + this.workingDirectory = workingDirectory; + } + + public File getExportFile() { + return exportFile; + } + + public void setExportFile(File exportFile) { + this.exportFile = exportFile; + } + + public String[] getVoyageIds() { + return voyageIds; + } + + public void setVoyageIds(String... voyageIds) { + this.voyageIds = voyageIds; + } + + @Override + public void destroy() throws IOException { + if (workingDirectory != null) { + FileUtils.deleteDirectory(workingDirectory); + } + } + +} \ No newline at end of file Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportDbConfiguration.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportDbService.java (from rev 565, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbService.java) =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportDbService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportDbService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,267 @@ +/* + * #%L + * EchoBase :: Services + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.services.exportdb; + +import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; +import fr.ifremer.echobase.EchoBaseIOUtil; +import fr.ifremer.echobase.entities.EchoBaseDbMeta; +import fr.ifremer.echobase.entities.EchoBaseEntityEnum; +import fr.ifremer.echobase.entities.data.Result; +import fr.ifremer.echobase.entities.data.Voyage; +import fr.ifremer.echobase.services.DbEditorService; +import fr.ifremer.echobase.services.EchoBaseServiceSupport; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaPersistenceHelper; +import org.nuiton.topia.persistence.csv.out.ExportEntityVisitor; +import org.nuiton.topia.persistence.csv.out.ExportModelFactory; +import org.nuiton.topia.persistence.csv.out.TopiaCsvExports; +import org.nuiton.topia.persistence.metadata.AssociationMeta; +import org.nuiton.topia.persistence.metadata.TableMeta; +import org.nuiton.util.FileUtil; +import org.nuiton.util.TimeLog; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Service to import / export a complete db. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class ExportDbService extends EchoBaseServiceSupport { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(ExportDbService.class); + + public static final TimeLog timeLog = new TimeLog(DbEditorService.class); + + /** + * Export the complete db into csv files stored in a zip archive file. + * + * @param model file name of the zip to create + * @throws IOException if could not create or write files. + */ + public void exportDb(ExportDbConfiguration model) throws IOException { + + String fileName = model.getFileName(); + + File tempDirectory = model.getWorkingDirectory(); + + File zipFile = new File(tempDirectory, fileName + ".zip"); + + if (log.isInfoEnabled()) { + log.info("Will export db to " + zipFile); + } + model.setExportFile(zipFile); + + ExportService exportService = getService(ExportService.class); + File dir = new File(tempDirectory, "echobase"); + + FileUtil.createDirectoryIfNecessary(dir); + + EchoBaseDbMeta dbMeta = getDbMeta(); + + model.setNbSteps(dbMeta.getEntriesSize()); + + for (TableMeta<EchoBaseEntityEnum> meta : dbMeta.getAllTables()) { + + model.incrementsProgression(); + + exportService.exportData(meta, new File(dir, meta.getFilename())); + } + + for (AssociationMeta<EchoBaseEntityEnum> meta : dbMeta.getAllAssociations()) { + + model.incrementsProgression(); + + exportService.exportData(meta, new File(dir, meta.getFilename())); + } + if (log.isInfoEnabled()) { + log.info("Export zip file = " + zipFile); + } + EchoBaseIOUtil.compressZipFile(zipFile, dir); + } + + /** + * Export the partial db into csv files at the given location. + * + * @param model file name of the zip to create + * @param computeSteps flag to compute stesp inside this method + * @throws IOException if could not create or write files. + */ + public void exportPartialDb(ExportDbConfiguration model, + boolean computeSteps) throws IOException { + + String fileName = model.getFileName(); + + File tempDirectory = model.getWorkingDirectory(); + File dir = new File(tempDirectory, "echobase"); + FileUtil.createDirectoryIfNecessary(dir); + + if (log.isInfoEnabled()) { + log.info("Will export to " + dir); + } + + File zipFile = new File(tempDirectory, fileName + ".zip"); + model.setExportFile(zipFile); + + ExportService exportService = getService(ExportService.class); + + // export all referentiel + List<TableMeta<EchoBaseEntityEnum>> refEntries = getDbMeta().getReferenceTables(); + List<AssociationMeta<EchoBaseEntityEnum>> refAssocEntries = getDbMeta().getReferenceAssociations(); + + boolean withVoyages = model.getVoyageIds() != null; + + if (computeSteps) { + int nbstesp = refEntries.size(); + + if (withVoyages) { + nbstesp += model.getVoyageIds().length; + } + + model.setNbSteps(nbstesp); + } + + for (TableMeta<EchoBaseEntityEnum> meta : refEntries) { + + model.incrementsProgression(); + + File entryFile = new File(dir, meta.getFilename()); + exportService.exportData(meta, entryFile); + } + + for (AssociationMeta<EchoBaseEntityEnum> associationMeta : refAssocEntries) { + + model.incrementsProgression(); + + File entryFile = new File(dir, associationMeta.getFilename()); + exportService.exportData(associationMeta, entryFile); + } + + if (withVoyages) { + List<TableMeta<EchoBaseEntityEnum>> dataEntries = + getDbMeta().getDataTables(); + List<AssociationMeta<EchoBaseEntityEnum>> dataAssociationEntries = + getDbMeta().getDataAssociations(); + + ReplicateEntityVisitor visitor = createVisitor( + exportService.getModelFactory(false), + dataEntries, + dataAssociationEntries, + dir + ); + + try { + for (String voyageId : model.getVoyageIds()) { + + model.incrementsProgression(); + + Voyage voyage = getEntityById(Voyage.class, voyageId); + visitor.export(voyage); + } + } finally { + // close visitor to close export files + visitor.close(); + } + } + + EchoBaseIOUtil.compressZipFile(zipFile, dir); + } + + public ReplicateEntityVisitor createVisitor(ExportModelFactory<EchoBaseEntityEnum> modelFactory, + List<TableMeta<EchoBaseEntityEnum>> entityMetas, + List<AssociationMeta<EchoBaseEntityEnum>> associations, + File container) { + + Preconditions.checkNotNull(modelFactory); + + Map<EchoBaseEntityEnum, TopiaCsvExports.EntityExportContext<EchoBaseEntityEnum>> contexts = TopiaCsvExports.createReplicateEntityVisitorContexts( + modelFactory, entityMetas, associations, container); + + ReplicateEntityVisitor result = new ReplicateEntityVisitor( + getDbMeta().getPersistenceHelper(), contexts); + return result; + } + + /** + * entity visitor to export data to csv files. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ + public static class ReplicateEntityVisitor extends ExportEntityVisitor<EchoBaseEntityEnum> { + + protected final Set<String> categoryIds; + + @Override + protected boolean isNoChildVisit(String propertyName, TopiaEntity entity) { + return Result.PROPERTY_CATEGORY.equals(propertyName) && + entity instanceof Result; + } + + public ReplicateEntityVisitor(TopiaPersistenceHelper<EchoBaseEntityEnum> typeProvider, + Map<EchoBaseEntityEnum, TopiaCsvExports.EntityExportContext<EchoBaseEntityEnum>> entityExporters) { + super(typeProvider, entityExporters); + categoryIds = Sets.newHashSet(); + } + + @Override + public void visit(TopiaEntity entity, String propertyName, + Class<?> type, Object value) { + if (Result.PROPERTY_CATEGORY.equals(propertyName) && + entity instanceof Result) { + + // export category + try { + TopiaEntity topiaEntity = (TopiaEntity) value; + if (categoryIds.add(topiaEntity.getTopiaId())) { + // add this new category + topiaEntity.accept(this); + } + + } catch (TopiaException e) { + if (log.isErrorEnabled()) { + log.error("Can not visit entity " + value, e); + } + } + } + } + + @Override + public void close() throws IOException { + categoryIds.clear(); + super.close(); + } + } +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportDbService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportService.java (from rev 565, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java) =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,318 @@ +/* + * #%L + * EchoBase :: Services + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.services.exportdb; + +import fr.ifremer.echobase.entities.EchoBaseEntityEnum; +import fr.ifremer.echobase.services.DbEditorService; +import fr.ifremer.echobase.services.DecoratorService; +import fr.ifremer.echobase.services.EchoBaseServiceSupport; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.csv.EntityCsvModel; +import org.nuiton.topia.persistence.csv.out.EntityAssociationExportModel; +import org.nuiton.topia.persistence.csv.out.ExportModelFactory; +import org.nuiton.topia.persistence.csv.out.PrepareDataForExport; +import org.nuiton.topia.persistence.csv.out.TopiaCsvExports; +import org.nuiton.topia.persistence.metadata.AssociationMeta; +import org.nuiton.topia.persistence.metadata.ColumnMeta; +import org.nuiton.topia.persistence.metadata.TableMeta; +import org.nuiton.util.csv.ExportModel; +import org.nuiton.util.decorator.Decorator; + +import java.io.File; +import java.util.List; + +/** + * To export datas from db to csv files. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class ExportService extends EchoBaseServiceSupport { +// +// /** Logger. */ +// private static final Log log = LogFactory.getLog(ExportService.class); +// +// public static final TimeLog TIME_LOG = new TimeLog(ExportService.class); + +// public ExportModelFactory<EchoBaseEntityEnum> getDefaultExportFactory() { +// return defaultExportFactory; +// } + +// public ExportModelFactory<EchoBaseEntityEnum> getAsSeenExportFactory() { +// return asSeenExportFactory; +// } + +// @Override +// public <E extends TopiaEntity> ExportModel<E> buildForExport(AssociationMeta<EchoBaseEntityEnum> associationMeta) { +// +// ExportModel<E> model = EntityAssociationExportModel.newExportModel( +// getConfiguration().getCsvSeparator(), +// associationMeta +// ); +// return model; +// } +// +// @Override +// public <E extends TopiaEntity> ExportModel<E> buildForExport(TableMeta<EchoBaseEntityEnum> meta, boolean asSeen) { +// +// EntityCsvModel<EchoBaseEntityEnum, E> model; +// +// if (asSeen) { +// +// // no need to have topiaId as first column +// model = EntityCsvModel.newModel( +// getConfiguration().getCsvSeparator(), +// meta +// ); +// } else { +// +// // normla export add topiaId column +// model = EntityCsvModel.newModel( +// getConfiguration().getCsvSeparator(), +// meta, +// TopiaEntity.TOPIA_ID +// ); +// } +// +// DecoratorService service = getService(DecoratorService.class); +// +// for (ColumnMeta columnMeta : meta) { +// String propertyName = columnMeta.getName(); +// Class<?> type = columnMeta.getType(); +// if (columnMeta.isFK()) { +// +// Class<TopiaEntity> entityType = (Class<TopiaEntity>) type; +// if (asSeen) { +// +// // export decorated foreign key value +// Decorator<TopiaEntity> decorator = +// service.getDecorator(getLocale(), entityType, null); +// model.addDecoratedForeignKeyForExport(propertyName, propertyName, decorator); +// } else { +// +// // export foreign key value as his topiaId +// model.addForeignKeyForExport(propertyName, entityType); +// } +// } else { +// model.addDefaultColumn(propertyName, type); +// } +// } +// return model; +// } + + public String exportData(TableMeta<EchoBaseEntityEnum> tableMeta, boolean asSeen) { + + String result = TopiaCsvExports.exportData(tableMeta, + getModelFactory(asSeen), + defaultPrepareDataForExport); + return result; +// +// Export<TopiaEntity> export = prepareExport(tableMeta, asSeen); +// +// try { +// return export.toString(Charsets.UTF_8); +// } catch (Exception eee) { +// throw new EchoBaseTechnicalException("Can not export datas", eee); +// } + } + + public void exportData(TableMeta<EchoBaseEntityEnum> tableMeta, File file) { + + TopiaCsvExports.exportData(tableMeta, + defaultExportFactory, + defaultPrepareDataForExport, + file); + +// if (log.isInfoEnabled()) { +// log.info("Export table " + tableMeta + " to " + file); +// } +// long s1 = TimeLog.getTime(); +// Export<TopiaEntity> export = prepareExport(tableMeta, false); +// TIME_LOG.log(s1, "exportData::prepareExport"); +// long s2 = TimeLog.getTime(); +// try { +// export.write(file, Charsets.UTF_8); +// } catch (Exception eee) { +// throw new EchoBaseTechnicalException("Can not export datas", eee); +// } +// TIME_LOG.log(s2, "exportData::exportToFile"); + } + + public void exportData(AssociationMeta<EchoBaseEntityEnum> associationMeta, File file) { + + TopiaCsvExports.exportData(associationMeta, + defaultExportFactory, + defaultPrepareDataForExport, + file); +// if (log.isInfoEnabled()) { +// log.info("Export association " + associationMeta + " to " + file); +// } +// long s1 = TimeLog.getTime(); +// Export<TopiaEntity> export = prepareExport(associationMeta); +// TIME_LOG.log(s1, "exportData::prepareExport"); +// +// long s2 = TimeLog.getTime(); +// try { +// export.write(file, Charsets.UTF_8); +// } catch (Exception eee) { +// throw new EchoBaseTechnicalException("Can not export datas", eee); +// } +// TIME_LOG.log(s2, "exportData::exportToFile"); + } + + public ExportModelFactory<EchoBaseEntityEnum> getModelFactory(boolean asSeen) { + ExportModelFactory<EchoBaseEntityEnum> result; + if (asSeen) { + result = asSeenExportFactory; + } else { + result = defaultExportFactory; + } + return result; + } + +// protected Export<TopiaEntity> prepareExport(TableMeta<EchoBaseEntityEnum> tableMeta, boolean asSeen) { +// +// List<TopiaEntity> datas = defaultPrepareDataForExport.prepareData(tableMeta); +// +// ExportModel<TopiaEntity> model; +// if (asSeen) { +// model = asSeenExportFactory.buildForExport(tableMeta); +// } else { +// model = defaultExportFactory.buildForExport(tableMeta); +// +// } +// return Export.newExport(model, datas); +// } + +// protected Export<TopiaEntity> prepareExport(AssociationMeta<EchoBaseEntityEnum> associationMeta) { +// +// List<TopiaEntity> datas = defaultPrepareDataForExport.prepareExport(associationMeta); +// ExportModel<TopiaEntity> model = defaultExportFactory.buildForExport(associationMeta); +// return Export.newExport(model, datas); +// } + + private ExportModelFactory<EchoBaseEntityEnum> defaultExportFactory = new ExportModelFactory<EchoBaseEntityEnum>() { + + @Override + public <E extends TopiaEntity> ExportModel<E> buildForExport(TableMeta<EchoBaseEntityEnum> meta) { + + // normal export add topiaId column + EntityCsvModel<EchoBaseEntityEnum, E> model = EntityCsvModel.newModel( + getConfiguration().getCsvSeparator(), + meta, + TopiaEntity.TOPIA_ID + ); + + for (ColumnMeta columnMeta : meta) { + String propertyName = columnMeta.getName(); + Class<?> type = columnMeta.getType(); + if (columnMeta.isFK()) { + + Class<TopiaEntity> entityType = (Class<TopiaEntity>) type; + + + // export foreign key value as his topiaId + model.addForeignKeyForExport(propertyName, entityType); + + } else { + model.addDefaultColumn(propertyName, type); + } + } + return model; + } + + @Override + public <E extends TopiaEntity> ExportModel<E> buildForExport(AssociationMeta<EchoBaseEntityEnum> associationMeta) { + ExportModel<E> model = EntityAssociationExportModel.newExportModel( + getConfiguration().getCsvSeparator(), + associationMeta + ); + return model; + } + }; + + private ExportModelFactory<EchoBaseEntityEnum> asSeenExportFactory = new ExportModelFactory<EchoBaseEntityEnum>() { + + @Override + public <E extends TopiaEntity> ExportModel<E> buildForExport(TableMeta<EchoBaseEntityEnum> meta) { + + + // no need to have topiaId as first column + EntityCsvModel<EchoBaseEntityEnum, E> model = EntityCsvModel.newModel( + getConfiguration().getCsvSeparator(), + meta + ); + + + DecoratorService service = getService(DecoratorService.class); + + for (ColumnMeta columnMeta : meta) { + String propertyName = columnMeta.getName(); + Class<?> type = columnMeta.getType(); + if (columnMeta.isFK()) { + + Class<TopiaEntity> entityType = (Class<TopiaEntity>) type; + + // export decorated foreign key value + Decorator<TopiaEntity> decorator = + service.getDecorator(getLocale(), entityType, null); + model.addDecoratedForeignKeyForExport(propertyName, propertyName, decorator); + + } else { + model.addDefaultColumn(propertyName, type); + } + } + return model; + } + + @Override + public <E extends TopiaEntity> ExportModel<E> buildForExport(AssociationMeta<EchoBaseEntityEnum> associationMeta) { + ExportModel<E> model = EntityAssociationExportModel.newExportModel( + getConfiguration().getCsvSeparator(), + associationMeta + ); + return model; + } + }; + + private PrepareDataForExport<EchoBaseEntityEnum> defaultPrepareDataForExport = new PrepareDataForExport<EchoBaseEntityEnum>() { + + @Override + public <E extends TopiaEntity> List<E> prepareData(TableMeta<EchoBaseEntityEnum> tableMeta) { + DbEditorService service = getService(DbEditorService.class); + + List<E> data = service.getEntities(tableMeta, null, null, null, null); + return data; + } + + @Override + public <E extends TopiaEntity> List<E> prepareData(AssociationMeta<EchoBaseEntityEnum> associationMeta) { + DbEditorService service = getService(DbEditorService.class); + + TableMeta<EchoBaseEntityEnum> tableMeta = service.getTableMeta(associationMeta.getSource()); + List<E> data = service.getEntities(tableMeta, null, null, null, "size(e." + associationMeta.getName() + ") > 0"); + return data; + } + }; +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportdb/ExportService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryCsvModel.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryCsvModel.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryCsvModel.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,26 @@ +package fr.ifremer.echobase.services.exportquery; + +import fr.ifremer.echobase.csv.EchoBaseCsvUtil; +import org.nuiton.util.csv.ext.AbstractExportModel; + +import java.util.Map; + +/** + * Csv model to export sql in {@link ExportQueryService}. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class ExportQueryCsvModel extends AbstractExportModel<Map<String, Object>> { + + public ExportQueryCsvModel(char separator, String[] columnHeaders) { + super(separator); + for (String columnHeader : columnHeaders) { + newColumnForExport( + columnHeader, + EchoBaseCsvUtil.TO_STRING_FORMATTER + ); + } + } + +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryCsvModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryService.java (from rev 565, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportQueryService.java) =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,216 @@ +/* + * #%L + * EchoBase :: Services + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.services.exportquery; + +import com.google.common.base.Charsets; +import com.google.common.collect.Lists; +import fr.ifremer.echobase.EchoBaseTechnicalException; +import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.entities.ExportQuery; +import fr.ifremer.echobase.entities.ExportQueryImpl; +import fr.ifremer.echobase.services.EchoBaseServiceSupport; +import fr.ifremer.echobase.services.exceptions.ExportQueryNameAlreadyExistException; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.util.PagerUtil; +import org.nuiton.util.csv.Export; + +import java.util.List; +import java.util.Map; + +/** + * Service to deal with sql export. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class ExportQueryService extends EchoBaseServiceSupport { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ExportQueryService.class); + + public ExportQuery getExportQuery(String topiaId) { + ExportQuery exportQuery = getEntityById(ExportQuery.class, topiaId); + ExportQuery entityToSave = newExportQuery(); + entityToSave.setTopiaId(exportQuery.getTopiaId()); + entityToSave.setName(exportQuery.getName()); + entityToSave.setDescription(exportQuery.getDescription()); + entityToSave.setSqlQuery(exportQuery.getSqlQuery()); + entityToSave.setLastModifiedDate(exportQuery.getLastModifiedDate()); + entityToSave.setLastModifiedUser(exportQuery.getLastModifiedUser()); + return entityToSave; + } + + public ExportQuery createOrUpdate(ExportQuery exportQuery, + EchoBaseUser user) throws ExportQueryNameAlreadyExistException { + try { + TopiaDAO<ExportQuery> dao = getDAO(ExportQuery.class); + + // No id, creating new one entity + String id = exportQuery.getTopiaId(); + + boolean mustCreate = StringUtils.isEmpty(id); + + String queryName = exportQuery.getName(); + + + String hql = "FROM " + dao.getTopiaEntityEnum().getImplementationFQN() + + " WHERE " + ExportQuery.PROPERTY_NAME + " = :queryName"; + List<Object> params = Lists.<Object>newArrayList("queryName", queryName); + + if (!mustCreate) { + hql += " AND " + ExportQuery.TOPIA_ID + " = :id"; + params.add("id"); + params.add(id); + } +// TopiaQuery query = dao.createQuery(); +// query.addWhere(ExportQuery.PROPERTY_NAME, TopiaQuery.Op.EQ, queryName); +// +// if (!mustCreate) { +// query.addWhere(ExportQuery.TOPIA_ID, TopiaQuery.Op.NEQ, id); +// } + + // check query does not already exists with this name + boolean queryExists = dao.existsByQuery(hql, params.toArray()); + +// boolean queryExists = dao.existByQuery(query); + + if (queryExists) { + throw new ExportQueryNameAlreadyExistException(); + } + + ExportQuery entityToSave; + + exportQuery.setLastModifiedDate(newDate()); + exportQuery.setLastModifiedUser(user.getEmail()); + + if (mustCreate) { + entityToSave = dao.create(exportQuery); + } else { + entityToSave = dao.findByTopiaId(id); +// entityToSave.setName(queryName); + entityToSave.setDescription(exportQuery.getDescription()); + entityToSave.setSqlQuery(exportQuery.getSqlQuery()); + entityToSave.setLastModifiedDate(exportQuery.getLastModifiedDate()); + entityToSave.setLastModifiedUser(exportQuery.getLastModifiedUser()); + } + +// dao.update(entityToSave); + getTransaction().commitTransaction(); + return entityToSave; + } catch (TopiaException eee) { + throw new EchoBaseTechnicalException(eee); + } + } + + public void delete(String topiaId) { + try { + TopiaDAO<ExportQuery> dao = getDAO(ExportQuery.class); + ExportQuery entityToDelete = dao.findByTopiaId(topiaId); + dao.delete(entityToDelete); + + getTransaction().commitTransaction(); + } catch (TopiaException eee) { + throw new EchoBaseTechnicalException(eee); + } + } + + public void testSql(String sql) throws TopiaException { + + GenericSQLQuery sqlQuery = new GenericSQLQuery(sql, null); + + sqlQuery.getColumnNames(getTransaction()); + } + + public Map<String, Object>[] executeSql(String sql, PagerUtil.PagerBean pager) { + + // get a query to count all rows for the request + GenericSQLQuery sqlQuery = new GenericSQLQuery(sql, pager); + try { + List<Map<String, Object>> result = + sqlQuery.getResult(getTransaction()); + return result.toArray(new Map[result.size()]); + } catch (TopiaException eee) { + throw new EchoBaseTechnicalException( + "Could not execute sql query", eee); + } + } + + public String[] getColumnNames(String sql) { + + String limitSql = sql.trim(); + if (limitSql.endsWith(";")) { + limitSql = limitSql.substring(0, limitSql.length() - 1); + limitSql += " LIMIT 1"; + } + try { + // do a limit query to one result and obtain the column names + // from the meta data of the result set + GenericSQLQuery sqlQuery = new GenericSQLQuery(limitSql, null); + String[] result = sqlQuery.getColumnNames(getTransaction()); + return result; + } catch (TopiaException eee) { + throw new EchoBaseTechnicalException( + "Could not execute query " + limitSql + " for reason " + eee.getCause().getMessage(), eee); + } catch (Exception eee) { + throw new EchoBaseTechnicalException( + "Could not execute query " + limitSql + " for reason " + eee.getMessage(), eee); + } + } + + public String createCsvFileContent(String sql) { + + GenericSQLQuery sqlQuery = new GenericSQLQuery(sql, null); + List<Map<String, Object>> rows; + try { + rows = sqlQuery.getResult(getTransaction()); + } catch (TopiaException eee) { + throw new EchoBaseTechnicalException( + "Could not execute sql query", eee); + } + char csvSeparator = getConfiguration().getCsvSeparator(); + ExportQueryCsvModel csvModel = sqlQuery.generateCsvModel(csvSeparator); + Export<Map<String, Object>> exporter = Export.newExport(csvModel, rows); + try { + String content = exporter.toString(Charsets.UTF_8); + return content; + } catch (Exception eee) { + throw new EchoBaseTechnicalException("Could not export sql", eee); + } + } + + public ExportQuery newExportQuery() { + return new ExportQueryImpl(); + } + + public String processLibreOfficeSqlQuery(String libreOfficeQuery) { + + String result = libreOfficeQuery.replaceAll("\\\"", ""); + return result; + } + +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/ExportQueryService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/GenericSQLQuery.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/GenericSQLQuery.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/GenericSQLQuery.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,115 @@ +package fr.ifremer.echobase.services.exportquery; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import org.nuiton.topia.framework.TopiaSQLQuery; +import org.nuiton.util.PagerUtil; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; +import java.util.Map; + +/** +* TODO +* +* @author tchemit <chemit@codelutin.com> +* @since 1.0 +*/ +public class GenericSQLQuery extends TopiaSQLQuery<Map<String, Object>> { + + /** Logger. */ + private static final Log log = LogFactory.getLog(GenericSQLQuery.class); + + protected String[] columnNames; + + private final String sql; + + private final PagerUtil.PagerBean pager; + + public GenericSQLQuery(String sql, PagerUtil.PagerBean pager) { + this.sql = sql; + this.pager = pager; + } + + public String[] getColumnNames() { + return columnNames; + } + + public ExportQueryCsvModel generateCsvModel(char charSeparator) { + ExportQueryCsvModel model = new ExportQueryCsvModel( + charSeparator, + columnNames + ); + return model; + } + + public List<Map<String, Object>> getResult(TopiaContext tx) throws TopiaException { + List<Map<String, Object>> rows = + findMultipleResult((TopiaContextImplementor) tx); + return rows; + } + + public void testQuery(TopiaContext tx) throws TopiaException { + findSingleResult((TopiaContextImplementor) tx); + } + + public String[] getColumnNames(TopiaContext tx) throws TopiaException { + findSingleResult((TopiaContextImplementor) tx); + return columnNames; + } + + @Override + protected PreparedStatement prepareQuery(Connection connection) throws SQLException { + return connection.prepareStatement( + sql, + ResultSet.TYPE_SCROLL_INSENSITIVE, + ResultSet.CONCUR_READ_ONLY + ); + } + + @Override + protected void afterExecuteQuery(ResultSet set) throws SQLException { + super.afterExecuteQuery(set); + + // obtain columnNames + columnNames = getColumnNames(set); + + if (pager != null) { + + // must count rows + int nbRows = getNbRows(set); + if (log.isInfoEnabled()) { + log.info("For request " + sql + ", nb rows = " + nbRows); + } + pager.setRecords(nbRows); + PagerUtil.computeRecordIndexesAndPagesNumber(pager); + } + } + + @Override + protected Map<String, Object> prepareResult(ResultSet set) throws SQLException { + + if (pager != null) { + + // get row number (getRow() begins at 1) + int rowNumber = set.getRow() - 1; + if (rowNumber < pager.getRecordStartIndex() || + rowNumber >= pager.getRecordEndIndex()) { + + // out of pager bound, by returning null + // result will not be take in account + return null; + } + } + + Map<String, Object> result = getRowAsMap(columnNames, set); + return result; + } + +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/exportquery/GenericSQLQuery.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportDataService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportDataService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AbstractImportDataService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -50,7 +50,6 @@ import fr.ifremer.echobase.entities.references.SpeciesCategory; import fr.ifremer.echobase.entities.references.SpeciesCategoryDAO; import fr.ifremer.echobase.services.EchoBaseServiceSupport; -import fr.ifremer.echobase.services.ImportException; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AcousticImportService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AcousticImportService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/AcousticImportService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -47,7 +47,6 @@ import fr.ifremer.echobase.entities.references.DataMetadata; import fr.ifremer.echobase.entities.references.DataQuality; import fr.ifremer.echobase.entities.references.Vessel; -import fr.ifremer.echobase.services.ImportException; import fr.ifremer.echobase.services.importdata.csv.AcousticImportModel; import fr.ifremer.echobase.services.importdata.csv.AcousticImportRow; import org.apache.commons.collections.CollectionUtils; Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/CatchesImportService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/CatchesImportService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/CatchesImportService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -45,7 +45,6 @@ import fr.ifremer.echobase.entities.references.Species; import fr.ifremer.echobase.entities.references.SpeciesCategory; import fr.ifremer.echobase.entities.references.SpeciesCategoryDAO; -import fr.ifremer.echobase.services.ImportException; import fr.ifremer.echobase.services.importdata.csv.BiometrySampleImportModel; import fr.ifremer.echobase.services.importdata.csv.BiometrySampleImportRow; import fr.ifremer.echobase.services.importdata.csv.SubSampleImportModel; Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/CommonImportService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/CommonImportService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/CommonImportService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -40,7 +40,6 @@ import fr.ifremer.echobase.entities.references.Mission; import fr.ifremer.echobase.entities.references.MissionDAO; import fr.ifremer.echobase.entities.references.Vessel; -import fr.ifremer.echobase.services.ImportException; import fr.ifremer.echobase.services.exceptions.MissionNameAlreadyExistException; import fr.ifremer.echobase.services.importdata.csv.TransectImportModel; import fr.ifremer.echobase.services.importdata.csv.TransectImportRow; Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ImportException.java (from rev 565, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportException.java) =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ImportException.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ImportException.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,56 @@ +/* + * #%L + * EchoBase :: Services + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.services.importdata; + +import fr.ifremer.echobase.InputFile; +import org.nuiton.util.csv.ImportRuntimeException; + +import java.util.Locale; + +import static org.nuiton.i18n.I18n.l_; + +/** + * Exception when a import new data failed. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public class ImportException extends Exception { + + private static final long serialVersionUID = 1L; + + public ImportException(String message) { + super(message); + } + + public ImportException(String message, Throwable cause) { + super(message, cause); + } + + public ImportException(Locale locale, InputFile inputfile, ImportRuntimeException importError) { + this(l_(locale, "echobase.importError.fromFile", + inputfile.getFile().getName(), + importError.getMessage()), importError); + } +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ImportException.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/OperationImportService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/OperationImportService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/OperationImportService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -42,7 +42,6 @@ import fr.ifremer.echobase.entities.references.GearMetadata; import fr.ifremer.echobase.entities.references.OperationMetadata; import fr.ifremer.echobase.entities.references.Vessel; -import fr.ifremer.echobase.services.ImportException; import fr.ifremer.echobase.services.importdata.csv.GearMetadataValueImportModel; import fr.ifremer.echobase.services.importdata.csv.GearMetadataValueImportRow; import fr.ifremer.echobase.services.importdata.csv.OperationImportModel; Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsEsduCellImportService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsEsduCellImportService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsEsduCellImportService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -45,7 +45,6 @@ import fr.ifremer.echobase.entities.references.Species; import fr.ifremer.echobase.entities.references.SpeciesCategory; import fr.ifremer.echobase.entities.references.SpeciesCategoryDAO; -import fr.ifremer.echobase.services.ImportException; import fr.ifremer.echobase.services.importdata.csv.EsduResultByEchotypeAndSpeciesCategoryImportModel; import fr.ifremer.echobase.services.importdata.csv.EsduResultByEchotypeAndSpeciesCategoryImportRow; import fr.ifremer.echobase.services.importdata.csv.EsduResultByEchotypeImportModel; Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsImportService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsImportService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsImportService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -32,7 +32,6 @@ import fr.ifremer.echobase.entities.data.Transit; import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.services.DecoratorService; -import fr.ifremer.echobase.services.ImportException; import org.nuiton.util.decorator.Decorator; import java.util.Map; Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsMapCellImportService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsMapCellImportService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsMapCellImportService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -46,7 +46,6 @@ import fr.ifremer.echobase.entities.references.Species; import fr.ifremer.echobase.entities.references.SpeciesCategory; import fr.ifremer.echobase.entities.references.SpeciesCategoryDAO; -import fr.ifremer.echobase.services.ImportException; import fr.ifremer.echobase.services.importdata.csv.MapCellImportModel; import fr.ifremer.echobase.services.importdata.csv.MapCellImportRow; import org.apache.commons.logging.Log; Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsRegionCellImportService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsRegionCellImportService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsRegionCellImportService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -46,7 +46,6 @@ import fr.ifremer.echobase.entities.references.Species; import fr.ifremer.echobase.entities.references.SpeciesCategory; import fr.ifremer.echobase.entities.references.SpeciesCategoryDAO; -import fr.ifremer.echobase.services.ImportException; import fr.ifremer.echobase.services.importdata.csv.RegionCellAssociationImportModel; import fr.ifremer.echobase.services.importdata.csv.RegionCellAssociationImportRow; import fr.ifremer.echobase.services.importdata.csv.RegionCellImportModel; Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsVoyageImportService.java =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsVoyageImportService.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdata/ResultsVoyageImportService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -42,7 +42,6 @@ import fr.ifremer.echobase.entities.references.SpeciesCategory; import fr.ifremer.echobase.entities.references.SpeciesCategoryDAO; import fr.ifremer.echobase.entities.references.Strata; -import fr.ifremer.echobase.services.ImportException; import fr.ifremer.echobase.services.importdata.csv.EchotypeImportModel; import fr.ifremer.echobase.services.importdata.csv.EchotypeImportRow; import fr.ifremer.echobase.services.importdata.csv.LengthAgeKeyImportModel; Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/DefaultImportStrategy.java (from rev 570, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DefaultImportStrategy.java) =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/DefaultImportStrategy.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/DefaultImportStrategy.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,98 @@ +package fr.ifremer.echobase.services.importdb; +/* + * #%L + * EchoBase :: Services + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 - 2012 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import fr.ifremer.echobase.entities.EchoBaseEntityEnum; +import fr.ifremer.echobase.entities.EchoBasePersistenceHelper; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.csv.in.CsvImportResult; +import org.nuiton.topia.persistence.csv.in.ImportModelFactory; +import org.nuiton.topia.persistence.csv.in.ImportStrategy; +import org.nuiton.topia.persistence.csv.in.TopiaCsvImports; +import org.nuiton.topia.persistence.metadata.AssociationMeta; +import org.nuiton.topia.persistence.metadata.TableMeta; +import org.nuiton.util.csv.Import; +import org.nuiton.util.csv.ImportToMap; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 1.1 + */ +public class DefaultImportStrategy implements ImportStrategy<EchoBaseEntityEnum> { + + private final TopiaContext tx; + + private final EchoBasePersistenceHelper persistenceHelper; + + private final int nbRowBuffer; + + private final ImportModelFactory<EchoBaseEntityEnum> modelFactory; + + public DefaultImportStrategy(ImportModelFactory<EchoBaseEntityEnum> modelFactory, + TopiaContext tx, + EchoBasePersistenceHelper persistenceHelper, + int nbRowBuffer) { + this.tx = tx; + this.persistenceHelper = persistenceHelper; + this.nbRowBuffer = nbRowBuffer; + this.modelFactory = modelFactory; + } + + public ImportModelFactory<EchoBaseEntityEnum> getModelFactory() { + return modelFactory; + } + + @Override + public <E extends TopiaEntity> void importTable(TableMeta<EchoBaseEntityEnum> meta, Import<E> importer, + CsvImportResult<EchoBaseEntityEnum> csvResult) throws TopiaException { + TopiaDAO<E> dao = persistenceHelper.getDAO(tx, meta.getSource()); + + TopiaCsvImports.importAllEntities(dao, meta, importer, csvResult); + } + + @Override + public void importAssociation(AssociationMeta<EchoBaseEntityEnum> meta, + ImportToMap importer, + CsvImportResult<EchoBaseEntityEnum> csvResult) throws TopiaException { + + if (getModelFactory().isNMAssociationMeta(meta)) { + TopiaCsvImports.importNMAssociation(tx, + meta, + importer, + csvResult, + nbRowBuffer); + } else { + TopiaCsvImports.importAssociation(tx, + meta, + importer, + csvResult, + nbRowBuffer); + } + + } +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/DefaultImportStrategy.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportDbConfiguration.java (from rev 565, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbConfiguration.java) =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportDbConfiguration.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportDbConfiguration.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,80 @@ +/* + * #%L + * EchoBase :: Services + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.services.importdb; + +import fr.ifremer.echobase.InputFile; +import fr.ifremer.echobase.services.AbstractEchobaseActionConfiguration; +import fr.ifremer.echobase.services.ProgressionModel; +import org.apache.commons.io.FileUtils; + +import java.io.File; +import java.io.IOException; +import java.util.Locale; + +import static org.nuiton.i18n.I18n.l_; + +/** + * Configuration of a import db operation. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class ImportDbConfiguration extends AbstractEchobaseActionConfiguration { + + private static final long serialVersionUID = 1L; + + protected File workingDirectory; + + protected final InputFile input; + + public ImportDbConfiguration(ProgressionModel progressionModel, + Locale locale) { + super(progressionModel); + input = InputFile.newFile(l_(locale, "echobase.common.importDbFile")); + } + + public ImportDbConfiguration(Locale locale) { + input = InputFile.newFile(l_(locale, "echobase.common.importDbFile")); + } + + public File getWorkingDirectory() { + return workingDirectory; + } + + public InputFile getInput() { + return input; + } + + public void setWorkingDirectory(File workingDirectory) { + this.workingDirectory = workingDirectory; + } + + @Override + public void destroy() throws IOException { + if (workingDirectory != null) { + FileUtils.deleteDirectory(workingDirectory); + } + } + +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportDbConfiguration.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportDbService.java (from rev 565, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbService.java) =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportDbService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportDbService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,238 @@ +/* + * #%L + * EchoBase :: Services + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.services.importdb; + +import com.google.common.collect.Lists; +import fr.ifremer.echobase.entities.EchoBaseDbMeta; +import fr.ifremer.echobase.entities.EchoBaseEntityEnum; +import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.entities.EntityModificationLog; +import fr.ifremer.echobase.services.EchoBaseServiceSupport; +import org.apache.commons.io.IOUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.persistence.TopiaDAO; +import org.nuiton.topia.persistence.csv.in.CsvImportResult; +import org.nuiton.topia.persistence.csv.in.TopiaCsvImports; +import org.nuiton.topia.persistence.metadata.AssociationMeta; +import org.nuiton.topia.persistence.metadata.TableMeta; +import org.nuiton.util.TimeLog; + +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.util.List; +import java.util.Map; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +/** + * Service to import a complete db. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class ImportDbService extends EchoBaseServiceSupport { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(ImportDbService.class); + + public static final TimeLog TIME_LOG = new TimeLog(ImportDbService.class); + + /** + * Import a complete db from the given zip file. + * + * @param model model of the db import operation + * @param user user which perform the import + * @param computeSteps flag to compute stesp inside this method + * @param commitAfterEachFile flag to commit after each imported file + * @throws IOException if any io exception while import + * @throws TopiaException if any pb while topia treatment + */ + public void importDb(ImportDbConfiguration model, + EchoBaseUser user, + boolean computeSteps, + boolean commitAfterEachFile) throws IOException, TopiaException { + + File file = model.getInput().getFile(); + + ZipFile zipFile = new ZipFile(file); + try { + + List<String> missingEntries = Lists.newArrayList(); + + EchoBaseDbMeta dbMeta = getDbMeta(); + + Map<TableMeta<EchoBaseEntityEnum>, ZipEntry> tables = TopiaCsvImports.discoverEntries( + "echobase/", dbMeta.getAllTables(), + zipFile, missingEntries); + + Map<AssociationMeta<EchoBaseEntityEnum>, ZipEntry> associations = TopiaCsvImports.discoverEntries( + "echobase/", dbMeta.getAllAssociations(), + zipFile, missingEntries); + + if (computeSteps) { + int size = tables.size() + associations.size(); + model.setNbSteps(size + missingEntries.size()); + } + + for (String missingEntry : missingEntries) { + + // skip thoses not found entries + model.incrementsProgression(); + + if (log.isInfoEnabled()) { + log.info("Skip not found entry " + missingEntry); + } + } + + DefaultImportStrategy strategy = new DefaultImportStrategy( + getService(ImportService.class), + getTransaction(), + dbMeta.getPersistenceHelper(), + 1000 + ); + + importTables(strategy, model, zipFile, tables, commitAfterEachFile); + + importAssociations(strategy, model, zipFile, associations); + + // add a log entry of import db + if (log.isInfoEnabled()) { + log.info("Import done with user " + user.getEmail()); + } + TopiaDAO<EntityModificationLog> dao = + getDAO(EntityModificationLog.class); + + dao.create( + EntityModificationLog.PROPERTY_ENTITY_TYPE, "Import db", + EntityModificationLog.PROPERTY_ENTITY_ID, "Complete db", + EntityModificationLog.PROPERTY_MODIFICATION_USER, user.getEmail(), + EntityModificationLog.PROPERTY_MODIFICATION_DATE, newDate(), + EntityModificationLog.PROPERTY_MODIFICATION_TEXT, "import db from file " + file.getName() + ); + commitTransaction("Could not commit db import from file " + file); + + } finally { + zipFile.close(); + } + } + + private void importTables(DefaultImportStrategy strategy, + ImportDbConfiguration model, + ZipFile zipFile, + Map<TableMeta<EchoBaseEntityEnum>, ZipEntry> entriestoConsume, + boolean commitAfterEachFile) throws IOException, TopiaException { + + for (Map.Entry<TableMeta<EchoBaseEntityEnum>, ZipEntry> entry : + entriestoConsume.entrySet()) { + + model.incrementsProgression(); + + TableMeta<EchoBaseEntityEnum> entryDef = entry.getKey(); + ZipEntry value = entry.getValue(); + CsvImportResult<EchoBaseEntityEnum> csvResult = CsvImportResult.newResult( + entryDef.getSource(), + value.getName(), + false + ); + + Reader reader = IOUtils.toBufferedReader(new InputStreamReader(zipFile.getInputStream(value))); + try { + + long s0 = TimeLog.getTime(); + + if (log.isInfoEnabled()) { + log.info("Will import " + entryDef); + } + TopiaCsvImports.importTable(reader, + strategy, + entryDef, + csvResult + ); + + s0 = TIME_LOG.log(s0, "importFile::done"); + + flushTransaction(); + + TIME_LOG.log(s0, "importFile::flushTransaction"); + } finally { + reader.close(); + + if (commitAfterEachFile) { + commitTransaction( + "Could not commit db import from file " + + zipFile.getName() + "#" + entryDef.getFilename()); + } + } + } + } + + private void importAssociations(DefaultImportStrategy strategy, + ImportDbConfiguration model, + ZipFile zipFile, + Map<AssociationMeta<EchoBaseEntityEnum>, ZipEntry> associations) throws IOException, TopiaException { + + for (Map.Entry<AssociationMeta<EchoBaseEntityEnum>, ZipEntry> entry : + associations.entrySet()) { + + model.incrementsProgression(); + + AssociationMeta<EchoBaseEntityEnum> entryDef = entry.getKey(); + ZipEntry value = entry.getValue(); + + CsvImportResult<EchoBaseEntityEnum> csvResult = CsvImportResult.newResult( + entryDef.getSource(), + value.getName(), + false + ); + + Reader reader = IOUtils.toBufferedReader(new InputStreamReader(zipFile.getInputStream(value))); + try { + long s0 = TimeLog.getTime(); + + if (log.isInfoEnabled()) { + log.info("Will import " + entryDef); + } + + TopiaCsvImports.importAssociation(reader, + strategy, + entryDef, + csvResult); + + s0 = TIME_LOG.log(s0, "importFile::done"); + + flushTransaction(); + + TIME_LOG.log(s0, "importFile::flushTransaction"); + } finally { + reader.close(); + } + } + } + +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportDbService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportService.java (from rev 565, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportService.java) =================================================================== --- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportService.java (rev 0) +++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportService.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,167 @@ +/* + * #%L + * EchoBase :: Services + * + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.services.importdb; + +import com.google.common.base.Charsets; +import com.google.common.io.Files; +import fr.ifremer.echobase.EchoBaseTechnicalException; +import fr.ifremer.echobase.entities.EchoBaseEntityEnum; +import fr.ifremer.echobase.entities.EchoBaseUser; +import fr.ifremer.echobase.services.DbEditorService; +import fr.ifremer.echobase.services.EchoBaseServiceSupport; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.csv.EntityCsvModel; +import org.nuiton.topia.persistence.csv.in.CsvImportResult; +import org.nuiton.topia.persistence.csv.in.EntityAssociationImportModel; +import org.nuiton.topia.persistence.csv.in.ImportModelFactory; +import org.nuiton.topia.persistence.metadata.AssociationMeta; +import org.nuiton.topia.persistence.metadata.ColumnMeta; +import org.nuiton.topia.persistence.metadata.TableMeta; +import org.nuiton.util.csv.Import; +import org.nuiton.util.csv.ImportModel; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.util.Collection; +import java.util.Map; + +/** + * To import datas from csv files into the db. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class ImportService extends EchoBaseServiceSupport implements ImportModelFactory<EchoBaseEntityEnum> { + + /** Logger. */ + private static final Log log = LogFactory.getLog(ImportService.class); + + @Override + public <E extends TopiaEntity> ImportModel<E> buildForImport(TableMeta<EchoBaseEntityEnum> meta) { + + DbEditorService service = getService(DbEditorService.class); + + EntityCsvModel<EchoBaseEntityEnum, E> model = EntityCsvModel.newModel( + getConfiguration().getCsvSeparator(), + meta, + TopiaEntity.TOPIA_ID + ); + + for (ColumnMeta columnMeta : meta) { + String propertyName = columnMeta.getName(); + Class<?> type = columnMeta.getType(); + if (columnMeta.isFK()) { + + Class<TopiaEntity> entityType = (Class<TopiaEntity>) type; + Collection<TopiaEntity> universe = service.getForeignDatas(entityType); + model.addForeignKeyForImport(propertyName, entityType, universe); + } else { + model.addDefaultColumn(propertyName, type); + } + } + return model; + } + + @Override + public ImportModel<Map<String, Object>> buildForImport(AssociationMeta<EchoBaseEntityEnum> meta) { + + ImportModel<Map<String, Object>> model = + EntityAssociationImportModel.newImportModel( + getConfiguration().getCsvSeparator(), + meta + ); + return model; + } + + @Override + public boolean isNMAssociationMeta(AssociationMeta<EchoBaseEntityEnum> meta) { + EchoBaseEntityEnum source = meta.getSource(); + EchoBaseEntityEnum target = meta.getTarget(); + boolean result = false; + if (source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Echotype || + source == EchoBaseEntityEnum.Echotype && target == EchoBaseEntityEnum.Species || + source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Strata) { + result = true; + } + return result; + } + + public CsvImportResult<EchoBaseEntityEnum> importDatas(EchoBaseEntityEnum entityType, + String importFileName, + File importFile, + boolean createIfNotFound, + EchoBaseUser user) throws IOException { + + DbEditorService service = getService(DbEditorService.class); + + TableMeta<EchoBaseEntityEnum> meta = service.getTableMeta(entityType); + ImportModel<TopiaEntity> csvModel = buildForImport(meta); + String messagePrefix = "Import du fichier " + importFileName + " le " + newDate(); + + CsvImportResult<EchoBaseEntityEnum> result = CsvImportResult.newResult( + entityType, importFileName, createIfNotFound); + + BufferedReader bf = Files.newReader(importFile, Charsets.UTF_8); + try { + + Import<TopiaEntity> importer = Import.newImport(csvModel, bf); + + try { + for (TopiaEntity entity : importer) { + boolean create = service.saveEntity(meta, + messagePrefix, + entity, + user, + createIfNotFound + ); + + if (create) { + + result.incrementsNumberCreated(); + } else { + + result.incrementsNumberUpdated(); + } + } + } finally { + + importer.close(); + } + + commitTransaction("Could not commit transaction"); + } catch (EchoBaseTechnicalException eee) { + throw eee; + } catch (Exception eee) { + log.error("Failed to read import file " + importFile.getName(), eee); + throw new EchoBaseTechnicalException(eee); + } finally { + bf.close(); + } + return result; + } + +} Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/importdb/ImportService.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceIT.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceIT.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/EmbeddedApplicationServiceIT.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,6 +23,8 @@ */ package fr.ifremer.echobase.services; +import fr.ifremer.echobase.services.embeddedapplication.EmbeddedApplicationConfiguration; +import fr.ifremer.echobase.services.embeddedapplication.EmbeddedApplicationService; import fr.ifremer.echobase.services.importdata.AbstractImportDataServiceIT; import org.apache.commons.io.FileUtils; import org.junit.Assert; Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/ExportDbServiceTest.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/ExportDbServiceTest.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/ExportDbServiceTest.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,6 +23,8 @@ */ package fr.ifremer.echobase.services; +import fr.ifremer.echobase.services.exportdb.ExportDbConfiguration; +import fr.ifremer.echobase.services.exportdb.ExportDbService; import fr.ifremer.echobase.services.importdata.AbstractImportDataServiceIT; import org.junit.Test; import org.nuiton.util.FileUtil; Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/ExportQueryServiceTest.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/ExportQueryServiceTest.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/ExportQueryServiceTest.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,6 +23,7 @@ */ package fr.ifremer.echobase.services; +import fr.ifremer.echobase.services.exportquery.ExportQueryService; import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/FakeEchoBaseServiceContext.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/FakeEchoBaseServiceContext.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/FakeEchoBaseServiceContext.java 2012-08-30 16:16:04 UTC (rev 574) @@ -30,6 +30,7 @@ import fr.ifremer.echobase.EchoBaseTopiaRootContextFactory; import fr.ifremer.echobase.entities.EchoBaseDbMeta; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.rules.TestWatcher; @@ -69,6 +70,8 @@ protected TopiaContext rootContext; + protected TopiaContext internalTransaction; + protected TopiaContext transaction; protected Date fakeCurrentTime; @@ -173,6 +176,14 @@ return transaction; } + public TopiaContext getInternalTransaction() { + return internalTransaction; + } + + public void setInternalTransaction(TopiaContext internalTransaction) { + this.internalTransaction = internalTransaction; + } + public TopiaContext newTransaction() throws TopiaException { return rootContext.beginTransaction(); } @@ -206,6 +217,13 @@ return serviceFactory.newService(clazz, this); } + @Override + public Date newDate() { + Date result = new Date(); + DateUtils.setMilliseconds(result, 0); + return result; + } + public void setServiceFactory(EchoBaseServiceFactory serviceFactory) { this.serviceFactory = serviceFactory; } Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/ImportDbServiceTest.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/ImportDbServiceTest.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/ImportDbServiceTest.java 2012-08-30 16:16:04 UTC (rev 574) @@ -25,6 +25,8 @@ import fr.ifremer.echobase.entities.EchoBaseUser; import fr.ifremer.echobase.entities.EchoBaseUserImpl; +import fr.ifremer.echobase.services.importdb.ImportDbConfiguration; +import fr.ifremer.echobase.services.importdb.ImportDbService; import org.junit.Assert; import org.junit.Test; import org.nuiton.topia.TopiaException; Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/importdata/AbstractImportDataServiceIT.java =================================================================== --- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/importdata/AbstractImportDataServiceIT.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/importdata/AbstractImportDataServiceIT.java 2012-08-30 16:16:04 UTC (rev 574) @@ -52,7 +52,6 @@ import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.entities.references.CellType; import fr.ifremer.echobase.services.EchoBaseTestServiceSupport; -import fr.ifremer.echobase.services.ImportException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Assert; Modified: trunk/echobase-tools/pom.xml =================================================================== --- trunk/echobase-tools/pom.xml 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-tools/pom.xml 2012-08-30 16:16:04 UTC (rev 574) @@ -20,6 +20,28 @@ <name>EchoBase :: Tools</name> <description>EchoBase tools module</description> + <properties> + <redmine.releaseFiles> + ${basedir}/target/echobase-legacyDatas-${project.version}.zip + ${basedir}/target/echobase-referentiel-${project.version}.zip + </redmine.releaseFiles> + + <!-- no site generation --> + <maven.site.skip>true</maven.site.skip> + </properties> + <build> + <pluginManagement> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <argLine>-Xms512m -Xmx1512m</argLine> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> + <dependencies> <!-- sibling dependencies --> @@ -124,25 +146,6 @@ </dependencies> - <properties> - <redmine.releaseFiles> - ${basedir}/target/echobase-legacyDatas-${project.version}.zip - ${basedir}/target/echobase-referentiel-${project.version}.zip - </redmine.releaseFiles> - </properties> - <build> - <pluginManagement> - <plugins> - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <argLine>-Xms512m -Xmx1512m</argLine> - </configuration> - </plugin> - </plugins> - </pluginManagement> - </build> - <profiles> <profile> Modified: trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/EntityLoader.java =================================================================== --- trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/EntityLoader.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/EntityLoader.java 2012-08-30 16:16:04 UTC (rev 574) @@ -36,8 +36,8 @@ import fr.ifremer.echobase.services.DbEditorService; import fr.ifremer.echobase.services.EchoBaseServiceContext; import fr.ifremer.echobase.services.EchoBaseServiceSupport; -import fr.ifremer.echobase.services.ExportService; -import fr.ifremer.echobase.services.ImportService; +import fr.ifremer.echobase.services.exportdb.ExportService; +import fr.ifremer.echobase.services.importdb.ImportService; import fr.ifremer.echobase.tools.FileType; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; Modified: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/AbstractToolTest.java =================================================================== --- trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/AbstractToolTest.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/AbstractToolTest.java 2012-08-30 16:16:04 UTC (rev 574) @@ -99,6 +99,7 @@ serviceContext = DefaultEchoBaseServiceContext.newContext( Locale.getDefault(), + null, topiaContext.beginTransaction(), configuration, EchoBaseDbMeta.newDbMeta(), Modified: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/AbstractLoaderIT.java =================================================================== --- trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/AbstractLoaderIT.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/AbstractLoaderIT.java 2012-08-30 16:16:04 UTC (rev 574) @@ -28,7 +28,7 @@ import com.google.common.collect.Sets; import com.healthmarketscience.jackcess.Database; import fr.ifremer.echobase.entities.EchoBaseEntityEnum; -import fr.ifremer.echobase.services.ImportService; +import fr.ifremer.echobase.services.importdb.ImportService; import fr.ifremer.echobase.tools.AbstractToolTest; import fr.ifremer.echobase.tools.FileType; import fr.ifremer.echobase.tools.TestHelper; Modified: trunk/echobase-ui/pom.xml =================================================================== --- trunk/echobase-ui/pom.xml 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/pom.xml 2012-08-30 16:16:04 UTC (rev 574) @@ -4,10 +4,6 @@ <modelVersion>4.0.0</modelVersion> - <!-- ************************************************************* --> - <!-- *** POM Relationships *************************************** --> - <!-- ************************************************************* --> - <parent> <groupId>fr.ifremer</groupId> <artifactId>echobase</artifactId> @@ -17,6 +13,139 @@ <groupId>fr.ifremer.echobase</groupId> <artifactId>echobase-ui</artifactId> + <name>EchoBase :: UI</name> + <description>EchoBase ui module</description> + <packaging>war</packaging> + + <properties> + + <!-- no site generation --> + <maven.site.skip>true</maven.site.skip> + + <i18n.silent>true</i18n.silent> + <i18n.bundleOutputName>echobase-i18n</i18n.bundleOutputName> + + <env>dev</env> + + <redmine.releaseFiles> + ${basedir}/target/${project.build.finalName}.war + </redmine.releaseFiles> + + <deployFiles> + ${basedir}/target/${project.build.finalName}.war + </deployFiles> + </properties> + + <build> + + <resources> + <resource> + <directory>src/main/resources</directory> + <includes> + <include>**/*</include> + </includes> + <excludes> + <exclude>echobase.properties</exclude> + </excludes> + </resource> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + <includes> + <include>echobase.properties</include> + </includes> + </resource> + <resource> + <directory>src/main/env/${env}/resources</directory> + <includes> + <include>*.properties</include> + <include>*.xml</include> + </includes> + </resource> + </resources> + + <plugins> + + <plugin> + <groupId>org.nuiton.i18n</groupId> + <artifactId>i18n-maven-plugin</artifactId> + <executions> + <execution> + <id>parseJsp</id> + <goals> + <goal>parserStruts2</goal> + </goals> + <configuration> + <acceptKeyFormat>^echobase\..*$</acceptKeyFormat> + </configuration> + </execution> + <execution> + <id>parseOthersAndGenBundle</id> + <goals> + <goal>parserValidation</goal> + <goal>parserJava</goal> + <goal>gen</goal> + <goal>bundle</goal> + </goals> + </execution> + </executions> + </plugin> + + </plugins> + + <pluginManagement> + <plugins> + <plugin> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <configuration> + <stopKey>A</stopKey> + <stopPort>1269</stopPort> + <webAppConfig> + <contextPath>/echobase</contextPath> + </webAppConfig> + <jvmArgs>-Xms512m -Xmx1512m</jvmArgs> + </configuration> + </plugin> + + <plugin> + <groupId>org.apache.tomcat.maven</groupId> + <artifactId>tomcat7-maven-plugin</artifactId> + <configuration> + <path>/echobase</path> + </configuration> + </plugin> + + <plugin> + <artifactId>maven-war-plugin</artifactId> + <configuration> + <archive> + <manifest> + <mainClass>org.nuiton.web.war.JettyLauncher</mainClass> + </manifest> + </archive> + <overlays> + <overlay> + <groupId>org.nuiton.web</groupId> + <artifactId>nuiton-web</artifactId> + <type>jar</type> + <includes> + <include>**/war/Jetty*</include> + </includes> + </overlay> + <overlay> + <groupId>org.mortbay.jetty</groupId> + <artifactId>jetty-runner</artifactId> + <type>jar</type> + </overlay> + </overlays> + </configuration> + </plugin> + + </plugins> + </pluginManagement> + </build> + <dependencies> <!-- sibling dependencies --> @@ -187,258 +316,11 @@ <artifactId>junit</artifactId> </dependency> - </dependencies> - <!-- ************************************************************* --> - <!-- *** Project Information ************************************* --> - <!-- ************************************************************* --> - - <name>EchoBase :: UI</name> - <description>EchoBase ui module</description> - <packaging>war</packaging> - - <!-- ************************************************************* --> - <!-- *** Build Settings ****************************************** --> - <!-- ************************************************************* --> - <properties> - - <i18n.silent>true</i18n.silent> - <i18n.bundleOutputName>echobase-i18n</i18n.bundleOutputName> - - <env>dev</env> - - <redmine.releaseFiles> - ${basedir}/target/${project.build.finalName}.war - </redmine.releaseFiles> - - <deployFiles>${basedir}/target/${project.build.finalName}.war</deployFiles> - </properties> - - <build> - - <resources> - <resource> - <directory>src/main/resources</directory> - <includes> - <include>**/*</include> - </includes> - <excludes> - <exclude>echobase.properties</exclude> - </excludes> - </resource> - <resource> - <directory>src/main/resources</directory> - <filtering>true</filtering> - <includes> - <include>echobase.properties</include> - </includes> - </resource> - <resource> - <directory>src/main/env/${env}/resources</directory> - <includes> - <include>*.properties</include> - <include>*.xml</include> - </includes> - </resource> - </resources> - - <plugins> - - <plugin> - <groupId>org.nuiton.i18n</groupId> - <artifactId>i18n-maven-plugin</artifactId> - <executions> - <execution> - <id>parseJsp</id> - <goals> - <goal>parserStruts2</goal> - </goals> - <configuration> - <acceptKeyFormat>^echobase\..*$</acceptKeyFormat> - </configuration> - </execution> - <execution> - <id>parseOthersAndGenBundle</id> - <goals> - <goal>parserValidation</goal> - <goal>parserJava</goal> - <goal>gen</goal> - <goal>bundle</goal> - </goals> - </execution> - </executions> - </plugin> - - </plugins> - - <pluginManagement> - <plugins> - <plugin> - <groupId>org.mortbay.jetty</groupId> - <artifactId>jetty-maven-plugin</artifactId> - <configuration> - <stopKey>A</stopKey> - <stopPort>1269</stopPort> - <webAppConfig> - <contextPath>/echobase</contextPath> - </webAppConfig> - <jvmArgs>-Xms512m -Xmx1512m</jvmArgs> - </configuration> - </plugin> - - <plugin> - <groupId>org.apache.tomcat.maven</groupId> - <artifactId>tomcat7-maven-plugin</artifactId> - <configuration> - <path>/echobase</path> - </configuration> - </plugin> - - <plugin> - <artifactId>maven-war-plugin</artifactId> - <configuration> - <archive> - <manifest> - <mainClass>org.nuiton.web.war.JettyLauncher</mainClass> - </manifest> - </archive> - <overlays> - <overlay> - <groupId>org.nuiton.web</groupId> - <artifactId>nuiton-web</artifactId> - <type>jar</type> - <includes> - <include>**/war/Jetty*</include> - </includes> - </overlay> - <overlay> - <groupId>org.mortbay.jetty</groupId> - <artifactId>jetty-runner</artifactId> - <type>jar</type> - </overlay> - </overlays> - </configuration> - </plugin> - - </plugins> - </pluginManagement> - </build> - <profiles> <profile> - <id>reporting</id> - <activation> - <property> - <name>performRelease</name> - <value>true</value> - </property> - </activation> - - <reporting> - <plugins> - - <!-- - The Project Info Reports Plugin has twelve goals: - see http://maven.apache.org/plugins/maven-project-info-reports-plugin - --> - <plugin> - <artifactId>maven-project-info-reports-plugin</artifactId> - <version>${projectInfoReportsPluginVersion}</version> - <reportSets> - <reportSet> - <reports> - <report>project-team</report> - <report>mailing-list</report> - <report>cim</report> - <report>issue-tracking</report> - <report>license</report> - <report>scm</report> - <report>dependency-convergence</report> - <report>dependency-management</report> - </reports> - </reportSet> - </reportSets> - </plugin> - - <plugin> - <groupId>org.nuiton</groupId> - <artifactId>nuiton-utils-maven-report-plugin</artifactId> - <version>${nuitonUtilsVersion}</version> - <reportSets> - <reportSet> - <reports> - <report>application-config-report</report> - </reports> - </reportSet> - </reportSets> - <configuration> - <i18nBundleName>${i18n.bundleOutputName}</i18nBundleName> - </configuration> - </plugin> - </plugins> - </reporting> - </profile> - - <profile> - <id>selenium</id> - <activation> - <property> - <name>selenium</name> - <value>true</value> - </property> - </activation> - - <build> - <defaultGoal>integration-test</defaultGoal> - <plugins> - - <plugin> - <groupId>org.mortbay.jetty</groupId> - <artifactId>jetty-maven-plugin</artifactId> - <executions> - <execution> - <phase>pre-integration-test</phase> - <goals> - <goal>run</goal> - </goals> - <configuration> - <daemon>true</daemon> - </configuration> - </execution> - </executions> - </plugin> - - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <configuration> - <!-- Skip the normal tests, we'll run them in the integration-test phase --> - <skip>true</skip> - </configuration> - <executions> - - <execution> - <phase>integration-test</phase> - <goals> - <goal>test</goal> - </goals> - <configuration> - <skip>false</skip> - <includes> - <include>**/*SIT.java</include> - </includes> - </configuration> - </execution> - </executions> - </plugin> - - </plugins> - </build> - - </profile> - - <profile> <id>add-log-to-jetty</id> <activation> <file> Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationContext.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationContext.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationContext.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,22 +23,101 @@ */ package fr.ifremer.echobase.ui; +import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; +import com.opensymphony.xwork2.ActionContext; import fr.ifremer.echobase.EchoBaseConfiguration; import fr.ifremer.echobase.entities.EchoBaseDbMeta; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.topia.TopiaContext; +import javax.servlet.ServletContext; +import java.util.Map; +import java.util.Set; + /** * @author tchemit <chemit@codelutin.com> * @since 0.1 */ public class EchoBaseApplicationContext { + /** Logger. */ + private static final Log log = + LogFactory.getLog(EchoBaseApplicationContext.class); + protected EchoBaseConfiguration configuration; protected EchoBaseDbMeta dbMeta; protected TopiaContext rootContext; + /** Key to store the single instance of the application context */ + private static final String APPLICATION_CONTEXT_PARAMETER = + "t3ApplicationContext"; + + /** Root context for the internal database. */ + protected TopiaContext internalRootContext; + + /** Set of all loggued user sessions to be close at shutdown time. */ + protected Set<EchoBaseSession> t3Sessions; + + public static EchoBaseApplicationContext getApplicationContext(ActionContext actionContext) { + Map<String, Object> application = actionContext.getApplication(); + EchoBaseApplicationContext result = + (EchoBaseApplicationContext) application.get( + APPLICATION_CONTEXT_PARAMETER); + return result; + } + + public static EchoBaseApplicationContext getApplicationContext(ServletContext servletContext) { + EchoBaseApplicationContext result = + (EchoBaseApplicationContext) servletContext.getAttribute( + APPLICATION_CONTEXT_PARAMETER); + return result; + } + + public static void setApplicationContext(ServletContext servletContext, + EchoBaseApplicationContext applicationContext) { + servletContext.setAttribute(APPLICATION_CONTEXT_PARAMETER, + applicationContext); + } + + public static void removeApplicationContext(ServletContext servletContext) { + servletContext.removeAttribute(APPLICATION_CONTEXT_PARAMETER); + } + + public Set<EchoBaseSession> getEchoBaseSessions() { + return t3Sessions; + } + + public synchronized void registerEchoBaseSession(EchoBaseSession t3Session) { + Preconditions.checkNotNull(t3Session); + Preconditions.checkNotNull(t3Session.getEchoBaseUser()); + if (t3Sessions == null) { + t3Sessions = Sets.newHashSet(); + } + if (log.isInfoEnabled()) { + log.info("Register user session for [" + + t3Session.getEchoBaseUser().getEmail() + "]"); + } + t3Sessions.add(t3Session); + } + + public synchronized void destroyEchoBaseSession(EchoBaseSession t3Session) { + Preconditions.checkNotNull(t3Session); + Preconditions.checkNotNull(t3Session.getEchoBaseUser()); + Preconditions.checkNotNull(t3Sessions); + if (log.isInfoEnabled()) { + log.info("Destroy user session for [" + + t3Session.getEchoBaseUser().getEmail() + "]"); + } + // remove session from active ones + t3Sessions.remove(t3Session); + // close session + t3Session.close(); + } + public EchoBaseConfiguration getConfiguration() { return configuration; } Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java 2012-08-30 16:16:04 UTC (rev 574) @@ -24,7 +24,7 @@ package fr.ifremer.echobase.ui; import fr.ifremer.echobase.EchoBaseConfiguration; -import fr.ifremer.echobase.EchoBaseTechnicalException; +import fr.ifremer.echobase.EchoBaseEntityHelper; import fr.ifremer.echobase.EchoBaseTopiaRootContextFactory; import fr.ifremer.echobase.entities.EchoBaseDbMeta; import fr.ifremer.echobase.entities.EchoBaseUser; @@ -33,7 +33,6 @@ import fr.ifremer.echobase.services.EchoBaseServiceContext; import fr.ifremer.echobase.services.EchoBaseServiceFactory; import fr.ifremer.echobase.services.UserService; -import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import fr.ird.converter.FloatConverter; import org.apache.commons.beanutils.ConvertUtils; import org.apache.commons.beanutils.Converter; @@ -44,14 +43,16 @@ import org.nuiton.i18n.init.DefaultI18nInitializer; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; -import org.nuiton.topia.framework.TopiaUtil; +import org.nuiton.topia.framework.TopiaContextImplementor; import org.nuiton.util.converter.ConverterUtil; +import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import java.util.Date; import java.util.List; import java.util.Locale; +import java.util.Set; /** * To listen start or end of the application. @@ -70,8 +71,6 @@ protected static final Log log = LogFactory.getLog(EchoBaseApplicationListener.class); - private TopiaContext rootContext; - @Override public void contextInitialized(ServletContextEvent sce) { @@ -85,103 +84,137 @@ i18nInitializer.setMissingKeyReturnNull(true); I18n.init(i18nInitializer, Locale.getDefault()); - EchoBaseApplicationContext applicationContext = new EchoBaseApplicationContext(); - sce.getServletContext().setAttribute(EchoBaseActionSupport.APPLICATION_CONTEXT_PARAMETER, applicationContext); + // init converters + Converter converter = ConverterUtil.getConverter(Float.class); + if (converter != null) { + ConvertUtils.deregister(Float.class); + } + ConvertUtils.register(new FloatConverter(), Float.class); // initialize configuration EchoBaseConfiguration configuration = new EchoBaseConfiguration(); + + // initialize internal root context + TopiaContext internalRootContext = + new EchoBaseTopiaRootContextFactory().newInternalDb(configuration); + + // initialize application context + EchoBaseApplicationContext applicationContext = new EchoBaseApplicationContext(); + EchoBaseApplicationContext.setApplicationContext( + sce.getServletContext(), applicationContext); + applicationContext.setConfiguration(configuration); + applicationContext.setDbMeta(EchoBaseDbMeta.newDbMeta()); + applicationContext.setRootContext(internalRootContext); + // init database (and create minimal admin user if required) + initInternalDatabase(applicationContext); + } + + @Override + public void contextDestroyed(ServletContextEvent sce) { if (log.isInfoEnabled()) { - log.info("Initializing RootContext..."); + log.info("Application is ending at " + new Date() + "..."); } - EchoBaseTopiaRootContextFactory factory = - new EchoBaseTopiaRootContextFactory(); - rootContext = factory.newDatabaseFromConfig(configuration); - applicationContext.setRootContext(rootContext); - applicationContext.setDbMeta(EchoBaseDbMeta.newDbMeta()); + ServletContext servletContext = sce.getServletContext(); - // register our not locale dependant converter - Converter converter = ConverterUtil.getConverter(Float.class); - if (converter != null) { - ConvertUtils.deregister(Float.class); + // get application context + EchoBaseApplicationContext applicationContext = + EchoBaseApplicationContext.getApplicationContext(servletContext); + + // remove application context from container + EchoBaseApplicationContext.removeApplicationContext(servletContext); + + try { + // release internal db + TopiaContext rootContext = + applicationContext.getRootContext(); + EchoBaseEntityHelper.releaseRootContext(rootContext); + } finally { + + // release all user sessions + Set<EchoBaseSession> sessions = applicationContext.getEchoBaseSessions(); + if (CollectionUtils.isNotEmpty(sessions)) { + for (EchoBaseSession session : sessions) { + applicationContext.destroyEchoBaseSession(session); + } + } } - ConvertUtils.register(new FloatConverter(), Float.class); + } - // init database (and create minimal admin user if required) + /** + * Init the internal database, says : + * <ul> + * <li>If no schema found or if asked to updateSchema using the + * {@code updateSchema} configuration option is on.</li> + * <li>If no user found is db, create a administrator user + * {@code admin/admin}</li> + * </ul> + * + * @param applicationContext application context where to store global internal db root context + */ + protected void initInternalDatabase(EchoBaseApplicationContext applicationContext) { + + EchoBaseConfiguration configuration = + applicationContext.getConfiguration(); + + TopiaContext internalRootContext = applicationContext.getRootContext(); + + EchoBaseServiceContext serviceContext = DefaultEchoBaseServiceContext.newContext( + Locale.getDefault(), + null, + null, + configuration, + applicationContext.getDbMeta(), + new EchoBaseServiceFactory() + ); + try { - boolean schemaExist = TopiaUtil.isSchemaExist( - rootContext, - EchoBaseUserImpl.class.getName() - ); - if (!schemaExist || - configuration.getOptionAsBoolean(EchoBaseConfiguration.OPTION_UPDATE_SCHEMA)) { - if (schemaExist) { + boolean schemaExist = isInternalSchemaCreated(internalRootContext); + + if (schemaExist) { + + if (configuration.isUpdateSchema()) { if (log.isInfoEnabled()) { log.info("Will update schema..."); } - rootContext.updateSchema(); - } else { - if (log.isInfoEnabled()) { - log.info("Will create schema..."); - } - rootContext.createSchema(); + internalRootContext.updateSchema(); } + } else { + if (log.isInfoEnabled()) { + log.info("Will create schema..."); + } + internalRootContext.createSchema(); } - createAdminUser(applicationContext); - } catch (TopiaException e) { - throw new EchoBaseTechnicalException("Could not init db", e); + } catch (Exception e) { + throw new IllegalStateException("could not start db", e); } - } - @Override - public void contextDestroyed(ServletContextEvent sce) { + try { + createAdminUser(serviceContext); - if (log.isInfoEnabled()) { - log.info("Application is ending at " + new Date() + "..."); + } catch (Exception e) { + throw new IllegalStateException( + "could not create default admin user", e); } - if (rootContext != null) { - if (log.isInfoEnabled()) { - log.info("Shuting down RootContext..."); - } - if (!rootContext.isClosed()) { - try { - rootContext.closeContext(); - } catch (TopiaException te) { - if (log.isErrorEnabled()) { - log.error("Could not close rootContext", te); - } - } - } - } } /** * Creates the adminsitrator ({@code admin/admin}) on the database. * - * @param applicationContext application context + * @param serviceContext service context * @throws TopiaException if could not create the user. */ - protected void createAdminUser(EchoBaseApplicationContext applicationContext) throws TopiaException { + protected void createAdminUser(EchoBaseServiceContext serviceContext) throws TopiaException { - EchoBaseConfiguration configuration = - applicationContext.getConfiguration(); - EchoBaseServiceFactory serviceFactory = new EchoBaseServiceFactory(); - TopiaContext transaction = rootContext.beginTransaction(); - + TopiaContext transaction = serviceContext.getInternalTransaction().beginTransaction(); + serviceContext.setInternalTransaction(transaction); try { - EchoBaseServiceContext serviceContext = DefaultEchoBaseServiceContext.newContext( - Locale.getDefault(), - transaction, - configuration, - applicationContext.getDbMeta(), - serviceFactory - ); UserService service = serviceFactory.newService(UserService.class, serviceContext); @@ -204,6 +237,22 @@ } /** + * Tests if the internal database schema created. + * + * @param rootContext internal root context + * @return {@code true} if the schema is already created, {@code false} + * otherwise + * @throws TopiaException if something was wrong while requesting database + */ + protected boolean isInternalSchemaCreated(TopiaContext rootContext) throws TopiaException { + + boolean schemaFound = + ((TopiaContextImplementor) rootContext).isSchemaExist(EchoBaseUserImpl.class); + + return schemaFound; + } + + /** * Try to close the given transaction. * * @param tx the transaction to close Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseInternalDbTransactionFilter.java (from rev 565, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseTopiaTransactionFilter.java) =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseInternalDbTransactionFilter.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseInternalDbTransactionFilter.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,107 @@ +/* + * #%L + * EchoBase :: UI + * + * $Id: EchoBaseTopiaTransactionFilter.java 488 2012-04-04 14:04:32Z tchemit $ + * $HeadURL: http://svn.forge.codelutin.com/svn/echobase/trunk/echobase-ui/src/main/java/... $ + * %% + * Copyright (C) 2011 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ +package fr.ifremer.echobase.ui; + +import fr.ifremer.echobase.EchoBaseEntityHelper; +import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaRuntimeException; +import org.nuiton.web.filter.TopiaTransactionFilter; + +import javax.servlet.ServletRequest; + +/** + * Inject in each request a new transaction from the internal db. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.1 + */ +public class EchoBaseInternalDbTransactionFilter extends TopiaTransactionFilter { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(EchoBaseInternalDbTransactionFilter.class); + + @Override + protected TopiaContext beginTransaction(ServletRequest request) throws TopiaRuntimeException { + EchoBaseApplicationContext applicationContext = + EchoBaseActionSupport.getEchoBaseApplicationContext(); + + TopiaContext rootContext = applicationContext.getRootContext(); + try { + TopiaContext transaction = rootContext.beginTransaction(); + if (log.isDebugEnabled()) { + log.debug("Starts a new echo transaction " + transaction); + } + return transaction; + } catch (TopiaException eee) { + throw new TopiaRuntimeException("Could not start transaction", eee); + } + } + + /** + * Hook method to close the topia transaction of the request at the end of + * the request when all filter has been consumed. + * + * @param transaction the transaction to close (can be null if transaction + * was not required while the current request) + * @since 1.0 + */ + protected void onCloseTransaction(TopiaContext transaction) { + //FIXME Check if this necessary any longer ? + EchoBaseEntityHelper.closeConnection(transaction); + } + +// public static void closeConnection(TopiaContext transaction) { +// if (transaction == null) { +// if (log.isTraceEnabled()) { +// log.trace("no transaction to close"); +// } +// } else if (transaction.isClosed()) { +// if (log.isTraceEnabled()) { +// log.trace("transaction " + transaction + " is already closed"); +// } +// } else { +// if (log.isDebugEnabled()) { +// log.debug("closing transaction " + transaction); +// } +// +// try { +// Transaction tx = ((TopiaContextImplementor) transaction).getHibernate().getTransaction(); +// if (!tx.wasCommitted() && !tx.wasRolledBack()) { +// if (log.isDebugEnabled()) { +// log.debug("rollback transaction!"); +// } +// tx.rollback(); +// } +// transaction.closeContext(); +// } catch (TopiaException e) { +// throw new TopiaRuntimeException(e); +// } +// } +// } +} Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseSession.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseSession.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseSession.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,15 +23,27 @@ */ package fr.ifremer.echobase.ui; +import com.google.common.collect.Sets; +import com.opensymphony.xwork2.ActionContext; +import fr.ifremer.echobase.EchoBaseEntityHelper; +import fr.ifremer.echobase.EchoBaseTopiaRootContextFactory; +import fr.ifremer.echobase.JdbcConfiguration; import fr.ifremer.echobase.entities.EchoBaseUser; -import fr.ifremer.echobase.services.EmbeddedApplicationConfiguration; -import fr.ifremer.echobase.services.ExportDbConfiguration; -import fr.ifremer.echobase.services.ImportDbConfiguration; +import fr.ifremer.echobase.services.embeddedapplication.EmbeddedApplicationConfiguration; +import fr.ifremer.echobase.services.exportdb.ExportDbConfiguration; import fr.ifremer.echobase.services.importdata.AbstractImportConfiguration; +import fr.ifremer.echobase.services.importdb.ImportDbConfiguration; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaContextFactory; +import org.nuiton.topia.TopiaNotFoundException; +import org.nuiton.topia.framework.TopiaContextImplementor; +import javax.servlet.http.HttpSession; +import java.io.Closeable; import java.util.Map; +import java.util.Set; import java.util.TreeMap; /** @@ -40,7 +52,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.1 */ -public class EchoBaseSession { +public class EchoBaseSession implements Closeable { /** Logger. */ private static final Log log = LogFactory.getLog(EchoBaseSession.class); @@ -57,6 +69,53 @@ /** Key to keep embedded application configuration in this session. */ protected static final String PROPERTY_EMBEDDED_APPLICATION_CONFIGURATION = "embeddedApplicationConfiguration"; + /** Key to store the {@link EchoBaseSession} instance in the session's map. */ + private static final String SESSION_PARAMETER = "echoBaseSession"; + + /** Key to set root context of working db selected by user (if any). */ + private static final String PROPERTY_ROOT_CONTEXT = "rootContext"; + + + /** + * Obtain the user T3 session. + * <p/> + * If not found in application session, then will instanciate it and + * push it in it. + * <p/> + * At the creation time the session, it will also set his T3 factory. + * + * @param actionContext where to find user session + * @return the user T3 session (never null) + */ + public static EchoBaseSession getEchoBaseSession(ActionContext actionContext) { + Map<String, Object> session = actionContext.getSession(); + EchoBaseSession t3Session = (EchoBaseSession) + session.get(SESSION_PARAMETER); + if (t3Session == null) { + // let's create it + t3Session = new EchoBaseSession(); + session.put(SESSION_PARAMETER, t3Session); + } + return t3Session; + } + + public static EchoBaseSession getEchoBaseSession(HttpSession session) { + EchoBaseSession t3Session = (EchoBaseSession) + session.getAttribute(EchoBaseSession.SESSION_PARAMETER); + if (t3Session == null) { + // let's create it + t3Session = new EchoBaseSession(); + session.setAttribute(SESSION_PARAMETER, t3Session); + } + return t3Session; + } + + public static void removeEchoBaseSession(ActionContext actionContext) { + Map<String, Object> session = actionContext.getSession(); + session.remove(EchoBaseSession.SESSION_PARAMETER); + } + + /** To store all properties in this session. */ protected Map<String, Object> store; @@ -115,6 +174,65 @@ } /** + * Gets the t3 database url selected by user. + * + * @return the t3 database url selected by user or {@code null} if not in session + */ + public String getWorkingDatabaseUrl() { + TopiaContext rootContext = getRootContext(); + String result = null; + if (rootContext != null) { + result = (String) ((TopiaContextImplementor) rootContext).getConfig().get(TopiaContextFactory.CONFIG_URL); + } + return result; + } + + public TopiaContext getRootContext() { + return get(PROPERTY_ROOT_CONTEXT, TopiaContext.class); + } + + /** + * Initialize the t3 database configuration from the given connection + * configuration. + * <p/> + * The given configuration only give the url, login and pasword to use. + * Complete configuration (for ToPIA) will be loaded interanlly and match + * only a postgresql db. + * + * @param jdbcConfiguration the connection configuration to use + * @throws TopiaNotFoundException if could not create root context + */ + public void initDatabaseConfiguration(JdbcConfiguration jdbcConfiguration) throws TopiaNotFoundException { + + // close any previous db + releaseDatabase(); + + // creates a new topia root context from configuration + EchoBaseTopiaRootContextFactory factory = new EchoBaseTopiaRootContextFactory(); + TopiaContext rootContext = factory.newDb(jdbcConfiguration); + + // store it in session + set(PROPERTY_ROOT_CONTEXT, rootContext); + if (log.isInfoEnabled()) { + log.info("User database initialized at " + + jdbcConfiguration.getUrl()); + } + + } + + public void releaseDatabase() { + + TopiaContext rootContext = getRootContext(); + + if (rootContext != null) { + + remove(PROPERTY_ROOT_CONTEXT); + + EchoBaseEntityHelper.releaseRootContext(rootContext); + } + } + + /** * Remove form this session, the object from his given key and returns it. * * @param key the key of object to remove from this session @@ -184,4 +302,29 @@ EchoBaseUser user = getEchoBaseUser(); return user != null && user.isAdmin(); } + + /** + * Release any resources contained in the user session. + * <p/> + * Will also close any service (like the databaseService which contains + * connexions to db). + * + * @since 1.1 + */ + @Override + public void close() { + + if (log.isInfoEnabled()) { + log.info("Close user session for [" + getEchoBaseUser().getEmail() + "]"); + } + try { + releaseDatabase(); + } finally { + + Set<String> keys = Sets.newHashSet(store.keySet()); + for (String key : keys) { + remove(key); + } + } + } } Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseTopiaTransactionFilter.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseTopiaTransactionFilter.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseTopiaTransactionFilter.java 2012-08-30 16:16:04 UTC (rev 574) @@ -1,107 +0,0 @@ -/* - * #%L - * EchoBase :: UI - * - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2011 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.ui; - -import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Transaction; -import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.TopiaException; -import org.nuiton.topia.TopiaRuntimeException; -import org.nuiton.topia.framework.TopiaContextImplementor; -import org.nuiton.web.filter.TopiaTransactionFilter; - -import javax.servlet.ServletRequest; - -/** - * EchoBase implementation of the {@link TopiaTransactionFilter}. - * - * @author tchemit <chemit@codelutin.com> - * @since 0.1 - */ -public class EchoBaseTopiaTransactionFilter extends TopiaTransactionFilter { - - /** Logger. */ - private static final Log log = - LogFactory.getLog(EchoBaseTopiaTransactionFilter.class); - - @Override - protected TopiaContext beginTransaction(ServletRequest request) throws TopiaRuntimeException { - EchoBaseApplicationContext applicationContext = - EchoBaseActionSupport.getEchoBaseApplicationContext(); - - TopiaContext rootContext = applicationContext.getRootContext(); - try { - TopiaContext transaction = rootContext.beginTransaction(); - if (log.isDebugEnabled()) { - log.debug("Starts a new echo transaction " + transaction); - } - return transaction; - } catch (TopiaException eee) { - throw new TopiaRuntimeException("Could not start transaction", eee); - } - } - - /** - * Hook method to close the topia transaction of the request at the end of - * the request when all filter has been consumed. - * - * @param transaction the transaction to close (can be null if transaction - * was not required while the current request) - * @since 1.9.1 - */ - protected void onCloseTransaction(TopiaContext transaction) { - closeConnection(transaction); - } - - public static void closeConnection(TopiaContext transaction) { - if (transaction == null) { - if (log.isTraceEnabled()) { - log.trace("no transaction to close"); - } - } else if (transaction.isClosed()) { - if (log.isTraceEnabled()) { - log.trace("transaction " + transaction + " is already closed"); - } - } else { - if (log.isDebugEnabled()) { - log.debug("closing transaction " + transaction); - } - - try { - Transaction tx = ((TopiaContextImplementor) transaction).getHibernate().getTransaction(); - if (!tx.wasCommitted() && !tx.wasRolledBack()) { - if (log.isDebugEnabled()) { - log.debug("rollback transaction!"); - } - tx.rollback(); - } - transaction.closeContext(); - } catch (TopiaException e) { - throw new TopiaRuntimeException(e); - } - } - } -} Added: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseWorkingDbTransactionFilter.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseWorkingDbTransactionFilter.java (rev 0) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseWorkingDbTransactionFilter.java 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,61 @@ +package fr.ifremer.echobase.ui; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.TopiaContext; +import org.nuiton.topia.TopiaException; +import org.nuiton.topia.TopiaRuntimeException; +import org.nuiton.web.filter.TopiaTransactionFilter; + +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +/** + * To inject a transaction coming from the user connected working db. + * <p/> + * If user has no working db selected, then do nothing. + * + * @author tchemit <chemit@codelutin.com> + * @since 1.1 + */ +public class EchoBaseWorkingDbTransactionFilter extends TopiaTransactionFilter { + + /** Logger. */ + private static final Log log = + LogFactory.getLog(EchoBaseWorkingDbTransactionFilter.class); + + public static final String USER_TRANSACTION = "userTransaction"; + + public static TopiaContext getTransaction(ServletRequest request) { + TopiaContext topiaContext = (TopiaContext) + request.getAttribute(USER_TRANSACTION); + return topiaContext; + } + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + super.init(filterConfig); + setRequestAttributeName(USER_TRANSACTION); + } + + @Override + public TopiaContext beginTransaction(ServletRequest request) { + + HttpSession session = ((HttpServletRequest) request).getSession(); + EchoBaseSession userSession = EchoBaseSession.getEchoBaseSession(session); + TopiaContext rootContext = userSession.getRootContext(); + try { + TopiaContext transaction = rootContext.beginTransaction(); + if (log.isDebugEnabled()) { + log.debug("Starts a new working db transaction " + transaction); + } + return transaction; + } catch (TopiaException eee) { + throw new TopiaRuntimeException("Could not start transaction", eee); + } + } + +} \ No newline at end of file Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseWorkingDbTransactionFilter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractWaitAndExecAction.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractWaitAndExecAction.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/AbstractWaitAndExecAction.java 2012-08-30 16:16:04 UTC (rev 574) @@ -25,10 +25,9 @@ import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.Preparable; +import fr.ifremer.echobase.EchoBaseEntityHelper; import fr.ifremer.echobase.services.AbstractEchobaseActionConfiguration; -import fr.ifremer.echobase.ui.EchoBaseTopiaTransactionFilter; import org.nuiton.topia.TopiaContext; -import org.nuiton.topia.framework.TopiaContextImplementor; /** * Abstract long action using the exec and wait interceptor. @@ -82,10 +81,13 @@ // we must use a standalone transaction since it will pass through // in more than one request - TopiaContextImplementor tx = - (TopiaContextImplementor) serviceContext.getTransaction(); - TopiaContextImplementor rootContext = tx.getRootContext(); - TopiaContext topiaContext = rootContext.beginTransaction(); + TopiaContext topiaContext = + EchoBaseEntityHelper.newTransactionFromRootContext(getTransaction()); + +// TopiaContextImplementor tx = +// (TopiaContextImplementor) serviceContext.getTransaction(); +// TopiaContextImplementor rootContext = tx.getRootContext(); +// TopiaContext topiaContext = rootContext.beginTransaction(); serviceContext.setTransaction(topiaContext); try { @@ -97,7 +99,7 @@ } finally { try { - EchoBaseTopiaTransactionFilter.closeConnection(topiaContext); + EchoBaseEntityHelper.closeConnection(topiaContext); } finally { closeAction(model); } Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/EchoBaseActionSupport.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/EchoBaseActionSupport.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/EchoBaseActionSupport.java 2012-08-30 16:16:04 UTC (rev 574) @@ -69,12 +69,6 @@ private static final long serialVersionUID = 1L; - /** Key to store the {@link EchoBaseSession} instance in the session's map. */ - protected static final String SESSION_PARAMETER = "echoBaseSession"; - - /** Key to store the single instance of the application context */ - public static final String APPLICATION_CONTEXT_PARAMETER = "echoBaseApplicationContext"; - /** Logger. */ private static final Log log = LogFactory.getLog(EchoBaseActionSupport.class); @@ -85,10 +79,13 @@ private transient DecoratorService decoratorService; + private static EchoBaseApplicationContext applicationContext; + public static EchoBaseApplicationContext getEchoBaseApplicationContext() { - Map<String, Object> application = getActionContext().getApplication(); - EchoBaseApplicationContext applicationContext = - (EchoBaseApplicationContext) application.get(APPLICATION_CONTEXT_PARAMETER); + if (applicationContext == null) { + applicationContext = EchoBaseApplicationContext.getApplicationContext( + getActionContext()); + } return applicationContext; } @@ -109,26 +106,25 @@ protected transient EchoBaseServiceContext serviceContext; + /** + * Working db transaction (may be {@code null} if user has not yet select a db). + * + * @since 1.1 + */ protected transient TopiaContext transaction; + /** + * Internal db transaction (can not be {@code null}). + * + * @since 1.1 + */ + protected transient TopiaContext internalTransaction; + public EchoBaseSession getEchoBaseSession() { if (echoBaseSession == null) { // load it from session - Map<String, Object> strutsSession = - getActionContext().getSession(); - EchoBaseSession session = (EchoBaseSession) - strutsSession.get(SESSION_PARAMETER); - - if (session == null) { - - // create an empty session - session = new EchoBaseSession(); - - // and store it in the struts session - strutsSession.put(SESSION_PARAMETER, session); - } - echoBaseSession = session; + echoBaseSession = EchoBaseSession.getEchoBaseSession(getActionContext()); } return echoBaseSession; } @@ -153,6 +149,7 @@ if (serviceContext == null) { serviceContext = DefaultEchoBaseServiceContext.newContext( getLocale(), + getInternalTransaction(), getTransaction(), getConfiguration(), getEchoBaseApplicationContext().getDbMeta(), @@ -191,6 +188,15 @@ return transaction; } + public TopiaContext getInternalTransaction() { + if (transaction == null) { + HttpServletRequest request = (HttpServletRequest) + getActionContext().get(StrutsStatics.HTTP_REQUEST); + transaction = TopiaTransactionFilter.getTransaction(request); + } + return transaction; + } + @Override public void setTransaction(TopiaContext transaction) { this.transaction = transaction; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ExportTable.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ExportTable.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ExportTable.java 2012-08-30 16:16:04 UTC (rev 574) @@ -24,7 +24,7 @@ package fr.ifremer.echobase.ui.actions.dbeditor; import fr.ifremer.echobase.entities.EchoBaseEntityEnum; -import fr.ifremer.echobase.services.ExportService; +import fr.ifremer.echobase.services.exportdb.ExportService; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -98,7 +98,7 @@ ExportService exportService = newService(ExportService.class); TableMeta<EchoBaseEntityEnum> table = serviceContext.getDbMeta().getTable(entityType); - String content = exportService.exportDatas(table, exportAsSeen); + String content = exportService.exportData(table, exportAsSeen); if (log.isDebugEnabled()) { log.debug("file to export " + content); Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ImportTable.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ImportTable.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ImportTable.java 2012-08-30 16:16:04 UTC (rev 574) @@ -25,7 +25,7 @@ import com.opensymphony.xwork2.interceptor.annotations.InputConfig; import fr.ifremer.echobase.entities.EchoBaseEntityEnum; -import fr.ifremer.echobase.services.ImportService; +import fr.ifremer.echobase.services.importdb.ImportService; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/embeddedApplication/Build.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/embeddedApplication/Build.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/embeddedApplication/Build.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,8 +23,8 @@ */ package fr.ifremer.echobase.ui.actions.embeddedApplication; -import fr.ifremer.echobase.services.EmbeddedApplicationConfiguration; -import fr.ifremer.echobase.services.EmbeddedApplicationService; +import fr.ifremer.echobase.services.embeddedapplication.EmbeddedApplicationConfiguration; +import fr.ifremer.echobase.services.embeddedapplication.EmbeddedApplicationService; import fr.ifremer.echobase.ui.actions.AbstractWaitAndExecAction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/embeddedApplication/Configure.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/embeddedApplication/Configure.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/embeddedApplication/Configure.java 2012-08-30 16:16:04 UTC (rev 574) @@ -26,7 +26,7 @@ import fr.ifremer.echobase.EchoBaseConfiguration; import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.services.EchoBaseServiceSupport; -import fr.ifremer.echobase.services.EmbeddedApplicationConfiguration; +import fr.ifremer.echobase.services.embeddedapplication.EmbeddedApplicationConfiguration; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.io.FileUtils; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/embeddedApplication/Download.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/embeddedApplication/Download.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/embeddedApplication/Download.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,7 +23,7 @@ */ package fr.ifremer.echobase.ui.actions.embeddedApplication; -import fr.ifremer.echobase.services.EmbeddedApplicationConfiguration; +import fr.ifremer.echobase.services.embeddedapplication.EmbeddedApplicationConfiguration; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import java.io.BufferedInputStream; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Configure.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Configure.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Configure.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,7 +23,7 @@ */ package fr.ifremer.echobase.ui.actions.exportDb; -import fr.ifremer.echobase.services.ExportDbConfiguration; +import fr.ifremer.echobase.services.exportdb.ExportDbConfiguration; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Download.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Download.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Download.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,7 +23,7 @@ */ package fr.ifremer.echobase.ui.actions.exportDb; -import fr.ifremer.echobase.services.ExportDbConfiguration; +import fr.ifremer.echobase.services.exportdb.ExportDbConfiguration; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import java.io.BufferedInputStream; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Export.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Export.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Export.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,8 +23,8 @@ */ package fr.ifremer.echobase.ui.actions.exportDb; -import fr.ifremer.echobase.services.ExportDbConfiguration; -import fr.ifremer.echobase.services.ExportDbService; +import fr.ifremer.echobase.services.exportdb.ExportDbConfiguration; +import fr.ifremer.echobase.services.exportdb.ExportDbService; import fr.ifremer.echobase.ui.actions.AbstractWaitAndExecAction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/DownloadExportQueryResult.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/DownloadExportQueryResult.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/DownloadExportQueryResult.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,7 +23,7 @@ */ package fr.ifremer.echobase.ui.actions.exportQuery; -import fr.ifremer.echobase.services.ExportQueryService; +import fr.ifremer.echobase.services.exportquery.ExportQueryService; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import java.io.ByteArrayInputStream; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ExportQueryResult.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ExportQueryResult.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ExportQueryResult.java 2012-08-30 16:16:04 UTC (rev 574) @@ -24,7 +24,7 @@ package fr.ifremer.echobase.ui.actions.exportQuery; import fr.ifremer.echobase.EchoBaseTechnicalException; -import fr.ifremer.echobase.services.ExportQueryService; +import fr.ifremer.echobase.services.exportquery.ExportQueryService; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/GetExportQueryResult.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/GetExportQueryResult.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/GetExportQueryResult.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,7 +23,7 @@ */ package fr.ifremer.echobase.ui.actions.exportQuery; -import fr.ifremer.echobase.services.ExportQueryService; +import fr.ifremer.echobase.services.exportquery.ExportQueryService; import fr.ifremer.echobase.ui.actions.AbstractJSONPaginedAction; import java.util.Map; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ManageExportQuery.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ManageExportQuery.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ManageExportQuery.java 2012-08-30 16:16:04 UTC (rev 574) @@ -26,7 +26,7 @@ import com.opensymphony.xwork2.Preparable; import fr.ifremer.echobase.entities.EchoBaseUser; import fr.ifremer.echobase.entities.ExportQuery; -import fr.ifremer.echobase.services.ExportQueryService; +import fr.ifremer.echobase.services.exportquery.ExportQueryService; import fr.ifremer.echobase.services.exceptions.ExportQueryNameAlreadyExistException; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import org.apache.commons.lang3.StringUtils; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/NewLibreOfficeQuery.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/NewLibreOfficeQuery.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/NewLibreOfficeQuery.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,7 +23,7 @@ */ package fr.ifremer.echobase.ui.actions.exportQuery; -import fr.ifremer.echobase.services.ExportQueryService; +import fr.ifremer.echobase.services.exportquery.ExportQueryService; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/AbstractLaunchImport.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/AbstractLaunchImport.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/AbstractLaunchImport.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,7 +23,7 @@ */ package fr.ifremer.echobase.ui.actions.importData; -import fr.ifremer.echobase.services.ImportException; +import fr.ifremer.echobase.services.importdata.ImportException; import fr.ifremer.echobase.services.importdata.AbstractImportConfiguration; import fr.ifremer.echobase.services.importdata.AbstractImportDataService; import fr.ifremer.echobase.ui.actions.AbstractWaitAndExecAction; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/Configure.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/Configure.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/Configure.java 2012-08-30 16:16:04 UTC (rev 574) @@ -24,7 +24,7 @@ package fr.ifremer.echobase.ui.actions.importDb; import fr.ifremer.echobase.InputFile; -import fr.ifremer.echobase.services.ImportDbConfiguration; +import fr.ifremer.echobase.services.importdb.ImportDbConfiguration; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/Import.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/Import.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/Import.java 2012-08-30 16:16:04 UTC (rev 574) @@ -23,8 +23,8 @@ */ package fr.ifremer.echobase.ui.actions.importDb; -import fr.ifremer.echobase.services.ImportDbConfiguration; -import fr.ifremer.echobase.services.ImportDbService; +import fr.ifremer.echobase.services.importdb.ImportDbConfiguration; +import fr.ifremer.echobase.services.importdb.ImportDbService; import fr.ifremer.echobase.ui.actions.AbstractWaitAndExecAction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ConnectToDbInformations.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ConnectToDbInformations.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/ConnectToDbInformations.java 2012-08-30 16:16:04 UTC (rev 574) @@ -24,7 +24,7 @@ package fr.ifremer.echobase.ui.actions.user; import fr.ifremer.echobase.EchoBaseConfiguration; -import fr.ifremer.echobase.services.EmbeddedApplicationService; +import fr.ifremer.echobase.services.embeddedapplication.EmbeddedApplicationService; import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport; import org.apache.commons.lang3.StringUtils; import org.nuiton.topia.TopiaContextFactory; Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/LoginAction.java =================================================================== --- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/LoginAction.java 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/user/LoginAction.java 2012-08-30 16:16:04 UTC (rev 574) @@ -123,7 +123,8 @@ userSession.setEchoBaseUser(null); // remove echoBaseSession from application session - ActionContext.getContext().getSession().remove(SESSION_PARAMETER); + EchoBaseSession.removeEchoBaseSession(getActionContext()); +// ActionContext.getContext().getSession().remove(EchoBaseSession.SESSION_PARAMETER); return SUCCESS; } Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/web.xml =================================================================== --- trunk/echobase-ui/src/main/webapp/WEB-INF/web.xml 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/echobase-ui/src/main/webapp/WEB-INF/web.xml 2012-08-30 16:16:04 UTC (rev 574) @@ -30,11 +30,16 @@ <display-name>EchoBase</display-name> <filter> - <filter-name>topiaTransaction</filter-name> - <filter-class>fr.ifremer.echobase.ui.EchoBaseTopiaTransactionFilter</filter-class> + <filter-name>internalDbTransaction</filter-name> + <filter-class>fr.ifremer.echobase.ui.EchoBaseInternalDbTransactionFilter</filter-class> </filter> <filter> + <filter-name>workingDbTransaction</filter-name> + <filter-class>fr.ifremer.echobase.ui.EchoBaseWorkingDbTransactionFilter</filter-class> + </filter> + + <filter> <filter-name>struts-prepare</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter @@ -54,11 +59,16 @@ </filter> <filter-mapping> - <filter-name>topiaTransaction</filter-name> + <filter-name>internalDbTransaction</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter-mapping> + <filter-name>workingDbTransaction</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <filter-mapping> <filter-name>struts-prepare</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/pom.xml 2012-08-30 16:16:04 UTC (rev 574) @@ -3,10 +3,6 @@ <modelVersion>4.0.0</modelVersion> - <!-- ************************************************************* --> - <!-- *** POM Relationships *************************************** --> - <!-- ************************************************************* --> - <parent> <groupId>org.nuiton</groupId> <artifactId>mavenpom4redmine</artifactId> @@ -24,10 +20,6 @@ <module>echobase-ui</module> </modules> - <!-- ************************************************************* --> - <!-- *** Project Information ************************************* --> - <!-- ************************************************************* --> - <name>EchoBase</name> <description>Projet EchoBase</description> <inceptionYear>2011</inceptionYear> @@ -57,7 +49,7 @@ <role>lead</role> <role>developer</role> </roles> - <timezone>>Europe/Paris</timezone> + <timezone>Europe/Paris</timezone> </developer> <developer> <id>letellier</id> @@ -73,10 +65,6 @@ </developers> - <!-- ************************************************************* --> - <!-- *** Build Environment ************************************** --> - <!-- ************************************************************* --> - <scm> <url>http://svn.forge.codelutin.com/svn/echobase/trunk</url> <connection> @@ -123,10 +111,6 @@ </pluginRepository> </pluginRepositories> - <!-- ************************************************************* --> - <!-- *** Build Settings ****************************************** --> - <!-- ************************************************************* --> - <packaging>pom</packaging> <properties> @@ -163,6 +147,9 @@ <i18n.bundles>fr_FR,en_GB</i18n.bundles> <i18n.silent>true</i18n.silent> + <!--Site configuration --> + <locales>en,fr</locales> + </properties> <dependencyManagement> @@ -487,6 +474,7 @@ <report>license</report> <report>scm</report> <report>dependencies</report> + <report>dependency-info</report> <report>dependency-convergence</report> <report>plugin-management</report> <report>plugins</report> Copied: trunk/src/site/en/rst/embedded.rst (from rev 573, trunk/src/site/rst/embedded.rst) =================================================================== --- trunk/src/site/en/rst/embedded.rst (rev 0) +++ trunk/src/site/en/rst/embedded.rst 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,170 @@ +.. - +.. * #%L +.. * EchoBase +.. * +.. * $Id$ +.. * $HeadURL$ +.. * %% +.. * Copyright (C) 2011 Ifremer, Codelutin +.. * %% +.. * This program is free software: you can redistribute it and/or modify +.. * it under the terms of the GNU Affero General Public License as published by +.. * the Free Software Foundation, either version 3 of the License, or +.. * (at your option) any later version. +.. * +.. * This program is distributed in the hope that it will be useful, +.. * but WITHOUT ANY WARRANTY; without even the implied warranty of +.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.. * GNU General Public License for more details. +.. * +.. * You should have received a copy of the GNU Affero General Public License +.. * along with this program. If not, see <http://www.gnu.org/licenses/>. +.. * #L% +.. - + +======== +Echobase +======== + +.. contents:: Table des matières + :depth: 2 + +.. sectnum:: + :start: 1 + :depth: 2 + +Création d'une application embarquée +------------------------------------ + +*TODO Translate this in english* + +L'application permet de créer une application autonome comprenant un jeu de +données sélectionné par l'utilisateur. + +Procédure de création +===================== + +- Aller dans le menu *Créer une application embarquée* +- Sélectionner la ou les campagnes à inclure (ou rien si vous voulez juste le référentiel) +- Changer si besoin est le nom de l'archive à créer +- Appuyer sur le bouton Créer l'application. + +Une fois l'archive créée (l'opération peut être longue selon la quantité de +données), elle est téléchargeable depuis une page de résultat de l'opération +(normalement l'archive se met toute seule en téléchargement). + +Architecture de l'application embarquée +======================================= + +L'archive une fois décompressé à la forme suivante : + +:: + + echobase-embedded-0.6-pelgas2010 + ├── db (1) contient la base de données au format h2. + │ └── echobase.h2.db + ├── drivers (2) contient les drivers jdbc à utiliser dans LibreOffice + │ ├── h2-1.3.165.jar + │ └── postgresql-9.1-901-1.jdbc4.jar + ├── echobase.properties (3) Fichier de configuration de l'application embarquée + ├── echobase-ui-0.6.war (4) Application embarquée (war auto-exécutable) + ├── logs (5) contient les logs de l'application + │ └── echobase.log + ├── README.txt + ├── startEchobase.bat (6) Script de démarrage (windows) + └── startEchobase.sh (7) Script de démarrage (linux) + +Utilisateurs +============ + +Deux utilisateurs sont fournis dans la base embarquée : + +- admin / admin (avec des droits d'administration) +- user / user (pour la consultation) + + +Utilisation de l'application embarquée (windows) +------------------------------------------------ + +Pré-requis +========== + +Installer un environnement java de développement (une JDK) et pas une JRE +qui ne suffit pas. + +`Page de téléchargement Oracle`_ + +Une fois la JDK téléchargée et installée, ajouter la variable d'environnement +**JDK_HOME** qui est le chemin vers où a été installé Java. + +:: + + JDK_HOME -> C:/Program Files/Java/jdk1.7.0_03 + +Installation d'echobase +======================= + +- Dézipper l'archive précédemment téléchargée du site central. + +- Ouvrir une console (Touche Windows + R , taper *cmd* , Touche Entrée) +- Se placer dans le répertoire où a été dézippée l'archive + +:: + cd Chemin vers l'archive dézippée + +- Enfin lancer le script + +:: + startEchobase.bat + +- Dans la console on doit voir l'application démarré et produire des logs +- Lorsque l'application est prête, un navigateur s'ouvre sur la page + de login. + +Utilisation de l'application embarquée (linux) +---------------------------------------------- + +Pré-requis +========== + +Installer un environnement java de développement (une JDK) et pas une JRE +qui ne suffit pas. + +`Page de téléchargement Oracle`_ + +Une fois la JDK téléchargée et installée, ajouter dans les variables +d'environnement : + +:: + + JDK_HOME -> chemin vers où a été installé la JDK + + Pour ajouter une variable d'environnement, écrire dans ton fichier /home/Utilisateur/.bashrc la ligne : + +export JDK_HOME=/path/vers/jdk + +Installation d'echobase +======================= + +- Dézipper l'archive précédemment téléchargée du site central. +- Ouvrir une console +- Se placer dans le répertoire où a été dézippée l'archive + +:: + cd Chemin vers l'archive dézippée + +- Rendre le script de démarrage exécutable + +:: + chmod +x startEchobase.sh + +- Enfin lancer le script + +:: + ./startEchobase.sh + +- Dans la console on doit voir l'application démarré et produire des logs +- Lorsque l'application est prête, un navigateur s'ouvre sur la page + de login. + +.. _Page de téléchargement Oracle: http://www.oracle.com/technetwork/java/javase/downloads/index.html Copied: trunk/src/site/en/rst/imports.rst (from rev 573, trunk/src/site/rst/imports.rst) =================================================================== --- trunk/src/site/en/rst/imports.rst (rev 0) +++ trunk/src/site/en/rst/imports.rst 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,697 @@ +.. - +.. * #%L +.. * EchoBase +.. * +.. * $Id$ +.. * $HeadURL$ +.. * %% +.. * Copyright (C) 2011 - 2012 Ifremer, Codelutin +.. * %% +.. * This program is free software: you can redistribute it and/or modify +.. * it under the terms of the GNU Affero General Public License as published by +.. * the Free Software Foundation, either version 3 of the License, or +.. * (at your option) any later version. +.. * +.. * This program is distributed in the hope that it will be useful, +.. * but WITHOUT ANY WARRANTY; without even the implied warranty of +.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.. * GNU General Public License for more details. +.. * +.. * You should have received a copy of the GNU Affero General Public License +.. * along with this program. If not, see <http://www.gnu.org/licenses/>. +.. * #L% +.. - + +======================================= +Liste des colonnes des imports EchoBase +======================================= + +.. contents:: Table des matières + :depth: 2 + +.. sectnum:: + :start: 1 + :depth: 2 + +Abstract +======== + +*TODO Translate this in english* + +Ce document donne la définition de tous les imports. + +Format des colonnes +~~~~~~~~~~~~~~~~~~~ + +- FK(XXX#yyy) désigne une clef étrangère requise (XXX sur la propriété yyy). +- (int) un entier (pas du nullité possible) +- (float) un décimal (pas de nullité possible) +- (Integer) un entier avec nullité possible +- (Integer-NA) un entier avec nullité possible (et nullité si NA) +- Float un décimale avec nullité possible +- (Float-NA) un décimale avec nullité possible (et nullité si NA) +- (date) unique format de date : *yyyy-MM-dd HH:mm:ss.SSSS* +- (esdu cell) nom de cellule esdu - elementary : esduName[_elementaryCellName] + avec esdu name au format yyyy-MM-dd HH:mm:ss.SSSS + +Note importantes +~~~~~~~~~~~~~~~~ + +- Le nom des colonnes est sensible à la casse, il faut donc bien respecter les + noms donnés dans cette page. + +- Le contenu des cellules (et aussi les nom de colonnes) peuvent être encapsulés + par des **"**. + + +Voyage / Transit / Transect +=========================== + +Voyage +~~~~~~ + +Colonnes requises +----------------- + +:: + + name;startDate;endDate;startPort;endPort + +Format des colonnes +------------------- + +- name +- startDate (date) +- endDate (date) +- startPort +- endPort + +Exemple +------- + +:: + + name;startDate;endDate;startPort;endPort + PELGAS2011;2011-04-26 08:00:00.0000;2011-06-04 17:00:01.0000;Santander;Concarneau + +Transit +~~~~~~~ + +Colonnes requises +----------------- + +:: + + voyage;description;startTime;endTime;startLocality;endLocality + +Format des colonnes +------------------- + +- voyage FK(voyage#name) +- description +- startTime (date) +- endTime (date) +- startLocality +- endLocality + +Exemple +------- + +:: + + voyage;description;startTime;endTime;startLocality;endLocality + PELGAS2011;PELGAS11CAMP1;2011-04-26 08:00:01.0000;2011-05-08 20:00:00.0000;Santander;La Rochelle + +Transect +~~~~~~~~ + +Colonnes requises +----------------- + +:: + + title;transectAbstract;stratum;comment;voyage;vesselName;dateCreated;timeCoverageStart;timeCoverageEnd;geospatialLonMin;geospatialLatMin;geospatialVerticalMin;geospatialLonMax;geospatialLatMax;geospatialVerticalMax;linestring + +Format des colonnes +------------------- + +- voyage FK(voyage#name) +- vesselName FK(Vessel#name) +- title +- transectAbstract +- stratum +- comment +- dateCreated (date) +- timeCoverageStart (date) +- timeCoverageEnd (date) +- geospatialLonMin (float) +- geospatialLonMax (float) +- geospatialLatMin (float) +- geospatialLatMax (float) +- geospatialVerticalMin (float) +- geospatialVerticalMax (float) +- linestring + +Exemple +------- + +:: + + title;transectAbstract;stratum;comment;voyage;vesselName;dateCreated;timeCoverageStart;timeCoverageEnd;geospatialLonMin;geospatialLatMin;geospatialVerticalMin;geospatialLonMax;geospatialLatMax;geospatialVerticalMax;linestring + Arlequin2 / la colombine942OBS01 SUR;942OBS;SUR;942OBS,P5001,SUR;PELGAS2011;Arlequin2 / la colombine;2011-04-27 09:10:00.0000;2011-04-27 09:10:00.0000;2011-04-27 10:39:00.0000";-1.5896666667;43.7055;110;-1.541;43.7606666667;110;"-176453.0000037 4851310.5,-171051 4857434.0000037 + +Operation / OperationMetadataValue / GearMetadataValue +====================================================== + +Operation +~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + vesselName;operationId;depthStratumId;gearShootingStartTime;midHaulLatitude;midHaulLongitude;gearShootingStartLatitude;gearShootingStartLongitude;gearShootingEndTime;gearShootingEndLatitude;gearShootingEndLongitude;gearCode + +Format des colonnes +------------------- + +- vesselName FK(Vessel#name) +- gearCode FK(Gear#casinoGearName) +- depthStratumId FK(DepthStratum#id) +- operationId +- midHaulLatitude (float) +- midHaulLongitude (float) +- gearShootingStartTime (date) +- gearShootingEndTime (date) +- gearShootingStartLatitude (float) +- gearShootingEndLatitude (float) +- gearShootingStartLongitude (float) +- gearShootingEndLongitude (float) + +Exemple +------- + +:: + + vesselName;operationId;depthStratumId;gearShootingStartTime;midHaulLatitude;midHaulLongitude;gearShootingStartLatitude;gearShootingStartLongitude;gearShootingEndTime;gearShootingEndLatitude;gearShootingEndLongitude;gearCode + THALASSA II;P0422;CLAS;2011-05-05 06:49:50.0000";45.4165605;-1.4492292;45.4029733;-1.4860902;"2011-05-05 07:42:19.0000";45.4301477;-1.4123682;"57x52 + +OperationMetadataValue +~~~~~~~~~~~~~~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + vesselName;operationId;metadataType;operationMetadataValue + +Format des colonnes +------------------- + +- vesselName FK(Vessel#name) +- operationId FK(Operation#id) +- metadataType FK(OperationMetadata#name) +- operationMetadataValue + +Exemple +------- + +:: + + vesselName;operationId;metadataType;operationMetadataValue + THALASSA II;P0422;MeanWaterDepth";43.42 + +GearMetadataValue +~~~~~~~~~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + vesselName;operationId;gearCode;metadataType;gearMetadataValue + +Format des colonnes +------------------- + +- vesselName FK(Vessel#name) +- operationId FK(Operation#id) +- metadataType FK(GearMetadata#name) +- gearCode FK(Gear#casinoGearName) +- gearMetadataValue + +Exemple +------- + +:: + + vesselName;operationId;gearCode;metadataType;gearMetadataValue + THALASSA II;P0422;57x52;CableLength";31.6666666666667 + +TotalSample / SubSample / BiometrySample +======================================== + +TotalSample +~~~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + operationId;baracoudaCode;sizeCategory;sampleWeight;numberSampled;meanLength;meanWeight;noPerKg;sortedWeight + +Format des colonnes +------------------- + +- operationId FK(Operation#id) +- baracoudaCode FK(Species#baracoudaCode) +- sizeCategory FK(SizeCategory#name) +- sampleWeight (float) +- numberSampled (Integer-NA) +- meanLength (Float-NA) +- meanWeight (Float-NA) +- noPerKg (Float-NA) +- sortedWeight (float) + +Exemple +------- + +:: + + operationId;baracoudaCode;sizeCategory;sampleWeight;numberSampled;meanLength;meanWeight;noPerKg;sortedWeight + P0435;ALLO-TEZ;0";0.21;36;6.4;6;166.66;0.03 + +SubSample +~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + operationId;baracoudaCode;sizeCategory;sexCategory;sampleWeight;numberSampled;lengthClass;numberAtLength;weightAtLength;units;round + +Format des colonnes +------------------- + +- operationId FK(Operation#id) +- baracoudaCode FK(Species#baracoudaCode) +- sizeCategory FK(SizeCategory#name) +- sexCategory FK(SexCategory#name) +- sampleWeight (float) +- numberSampled (int) +- numberAtLength (float) +- weightAtLength (Float-NA) +- lengthClass + +(colonnes ignorées) subHaul units round + +Exemple +------- + +:: + + operationId;baracoudaCode;sizeCategory;sexCategory;sampleWeight;numberSampled;lengthClass;numberAtLength;weightAtLength;units;round + P0372;ENGR-ENC";0;"N";3.37;198;12;7;0.08;0;5 + +BiometrySample +~~~~~~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + operationId;baracoudaCode;numFish;dataLabel;dataValue;name + +Format des colonnes +------------------- + +- operationId FK(Operation#id) +- baracoudaCode FK(Species#baracoudaCode) +- numFish (int) +- name FK(SampleDataType#name) +- dataLabel +- dataValue (Float-NA) + +Exemple +------- + +:: + + operationId;baracoudaCode;numFish;dataLabel;dataValue;name + P5002;ENGR-ENC";9394;NA;-1;"Age + +Acoustic +~~~~~~~~ + +Colonnes requises +----------------- + +:: + + MOVIES_EILayer;MOVIES_EILayer\sndset;MOVIES_EILayer\sndset\sndname;MOVIES_EILayer\sndset\sndident;MOVIES_EILayer\sndset\softChannelId;MOVIES_EILayer\sndset\channelName;MOVIES_EILayer\sndset\dataType;MOVIES_EILayer\sndset\beamType;MOVIES_EILayer\sndset\acousticFrequency;MOVIES_EILayer\sndset\startSample;MOVIES_EILayer\sndset\mainBeamAlongSteeringAngle;MOVIES_EILayer\sndset\mainBeamAthwartSteeringAngle;MOVIES_EILayer\sndset\absorptionCoef;MOVIES_EILayer\sndset\transmissionPower;MOVIES_EILayer\sndset\beamAlongAngleSensitivity;MOVIES_EILayer\sndset\beamAthwartAngleSensitivity;MOVIES_EILayer\sndset\beam3dBWidthAlong;MOVIES_EILayer\sndset\beam3dBWidthAthwart;MOVIES_EILayer\sndset\beamEquTwoWayAngle;MOVIES_EILayer\sndset\beamGain;MOVIES_EILayer\sndset\beamSACorrection;MOVIES_EILayer\sndset\bottomDetectionMinDepth;MOVIES_EILayer\sndset\bottomDetectionMaxDepth;MOVIES_EILayer\sndset\bottomDetectionMinLevel;MOVIES_EILayer\sndset\AlongTXRXWeightId;MOVIES_EILayer\sndset\AthwartTXRXWeightId;MOVIES_EILayer\sndset\SplitBeamAlongTXRXWeightId;MOVIES_EILayer\sndset\SplitBeamAthwartTXRXWeightId;MOVIES_EILayer\sndset\bandWidth;MOVIES_EILayer\sndset\tvgminrange;MOVIES_EILayer\sndset\tvgmaxrange;MOVIES_EILayer\sndset\pulseduration;MOVIES_EILayer\shipnav;MOVIES_EILayer\shipnav\lat;MOVIES_EILayer\shipnav\long;MOVIES_EILayer\shipnav\alt;MOVIES_EILayer\shipnav\gndspeed;MOVIES_EILayer\shipnav\gndcourse;MOVIES_EILayer\shipnav\surfspeed;MOVIES_EILayer\shipnav\surfcourse;MOVIES_EILayer\shipnav\driftspeed;MOVIES_EILayer\shipnav\driftcourse;MOVIES_EILayer\shipnav\heading;MOVIES_EILayer\shipnav\roll;MOVIES_EILayer\shipnav\pitch;MOVIES_EILayer\shipnav\heave;MOVIES_EILayer\shipnav\depth;MOVIES_EILayer\shipnav\draught;MOVIES_EILayer\cellset;MOVIES_EILayer\cellset\cellnum;MOVIES_EILayer\cellset\celltype;MOVIES_EILayer\cellset\depthstart;MOVIES_EILayer\cellset\depthend;MOVIES_EILayer\cellset\indexstart;MOVIES_EILayer\cellset\indexend;MOVIES_EILayer\cellset\datestart;MOVIES_EILayer\cellset\dateend;MOVIES_EILayer\cellset\lat;MOVIES_EILayer\cellset\long;MOVIES_EILayer\cellset\volume;MOVIES_EILayer\cellset\area;MOVIES_EILayer\cellset\diststart;MOVIES_EILayer\cellset\distend;MOVIES_EILayer\cellset\thresholdup;MOVIES_EILayer\cellset\thresholdlow;MOVIES_EILayer\eilayer;MOVIES_EILayer\eilayer\sa;MOVIES_EILayer\eilayer\sv;MOVIES_EILayer\eilayer\ni;MOVIES_EILayer\eilayer\nt;MOVIES_EILayer\boterr;MOVIES_EILayer\boterr\sa;MOVIES_EILayer\boterr\ni;MOVIES_EILayer\sndset\soundcelerity;dataQuality + +Format des colonnes +------------------- + +A faire... + +Exemple +------- + +:: + + MOVIES_EILayer;MOVIES_EILayer\sndset;MOVIES_EILayer\sndset\sndname;MOVIES_EILayer\sndset\sndident;MOVIES_EILayer\sndset\softChannelId;MOVIES_EILayer\sndset\channelName;MOVIES_EILayer\sndset\dataType;MOVIES_EILayer\sndset\beamType;MOVIES_EILayer\sndset\acousticFrequency;MOVIES_EILayer\sndset\startSample;MOVIES_EILayer\sndset\mainBeamAlongSteeringAngle;MOVIES_EILayer\sndset\mainBeamAthwartSteeringAngle;MOVIES_EILayer\sndset\absorptionCoef;MOVIES_EILayer\sndset\transmissionPower;MOVIES_EILayer\sndset\beamAlongAngleSensitivity;MOVIES_EILayer\sndset\beamAthwartAngleSensitivity;MOVIES_EILayer\sndset\beam3dBWidthAlong;MOVIES_EILayer\sndset\beam3dBWidthAthwart;MOVIES_EILayer\sndset\beamEquTwoWayAngle;MOVIES_EILayer\sndset\beamGain;MOVIES_EILayer\sndset\beamSACorrection;MOVIES_EILayer\sndset\bottomDetectionMinDepth;MOVIES_EILayer\sndset\bottomDetectionMaxDepth;MOVIES_EILayer\sndset\bottomDetectionMinLevel;MOVIES_EILayer\sndset\AlongTXRXWeightId;MOVIES_EILayer\sndset\AthwartTXRXWeightId;MOVIES_EILayer\sndset\SplitBeamAlongTXRXWeightId;MOVIES_EILayer\sndset\SplitBeamAthwartTXRXWeightId;MOVIES_EILayer\sndset\bandWidth;MOVIES_EILayer\sndset\tvgminrange;MOVIES_EILayer\sndset\tvgmaxrange;MOVIES_EILayer\sndset\pulseduration;MOVIES_EILayer\shipnav;MOVIES_EILayer\shipnav\lat;MOVIES_EILayer\shipnav\long;MOVIES_EILayer\shipnav\alt;MOVIES_EILayer\shipnav\gndspeed;MOVIES_EILayer\shipnav\gndcourse;MOVIES_EILayer\shipnav\surfspeed;MOVIES_EILayer\shipnav\surfcourse;MOVIES_EILayer\shipnav\driftspeed;MOVIES_EILayer\shipnav\driftcourse;MOVIES_EILayer\shipnav\heading;MOVIES_EILayer\shipnav\roll;MOVIES_EILayer\shipnav\pitch;MOVIES_EILayer\shipnav\heave;MOVIES_EILayer\shipnav\depth;MOVIES_EILayer\shipnav\draught;MOVIES_EILayer\cellset;MOVIES_EILayer\cellset\cellnum;MOVIES_EILayer\cellset\celltype;MOVIES_EILayer\cellset\depthstart;MOVIES_EILayer\cellset\depthend;MOVIES_EILayer\cellset\indexstart;MOVIES_EILayer\cellset\indexend;MOVIES_EILayer\cellset\datestart;MOVIES_EILayer\cellset\dateend;MOVIES_EILayer\cellset\lat;MOVIES_EILayer\cellset\long;MOVIES_EILayer\cellset\volume;MOVIES_EILayer\cellset\area;MOVIES_EILayer\cellset\diststart;MOVIES_EILayer\cellset\distend;MOVIES_EILayer\cellset\thresholdup;MOVIES_EILayer\cellset\thresholdlow;MOVIES_EILayer\eilayer;MOVIES_EILayer\eilayer\sa;MOVIES_EILayer\eilayer\sv;MOVIES_EILayer\eilayer\ni;MOVIES_EILayer\eilayer\nt;MOVIES_EILayer\boterr;MOVIES_EILayer\boterr\sa;MOVIES_EILayer\boterr\ni;MOVIES_EILayer\sndset\soundcelerity;dataQuality + 2011/06/23 10:09:00.0000";NA;NA;NA;47;38000;NA;NA;NA;NA;NA;NA;8.47;2000;21.8;21.8;NA;NA;-20.6;25.27;-0.529999;NA;NA;NA;NA;NA;NA;NA;NA;NA;NA;1.024;NA;NA;NA;NA;NA;NA;NA;NA;NA;NA;NA;NA;NA;NA;199.9;NA;NA;0;0;10;20;NA;NA;"2011-04-26 08:24:02.0000;2011-04-26 08:30:02.0000";43.666505;-3.48812666666667;NA;1;NA;NA;0;-60;NA;1.444008;NA;71;43424;NA;NA;NA;"variable";1 + +Résultats voyage +================ + +Echotype +~~~~~~~~ + +Colonnes requises +----------------- + +:: + + voyage;echotypeName;depthStratumId;meaning;baracoudaCode + +Format des colonnes +------------------- + +- echotypeName +- meaning +- voyage FK(Voyage#name) +- depthStratumId FK(DepthStratum#id) +- baracoudaCode FK(Species#baracoudaCode) + +Exemple +------- + +:: + + voyage;echotypeName;depthStratumId;meaning;baracoudaCode + PELGAS2011;D1;CLAS;Maquereaux, Chinchards et gadidés présents dans les couches à proximité du fond;COMP-LEM + +LengthWeightKey +~~~~~~~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + voyage;sizeCategory;aParameter;bParameter;baracoudaCode;strata + +Format des colonnes +------------------- + +- aParameter (float) +- bParameter (float) +- voyage FK(Voyage#name) +- sizeCategory FK(SizeCategory#name) +- baracoudaCode FK(Species#baracoudaCode) +- strata FK(Strata#name) + +Exemple +------- + +:: + + voyage;sizeCategory;aParameter;bParameter;baracoudaCode;strata + PELGAS2011";0;2.48253468289872;3.37866337729714;"ENGR-ENC;Golfe de Gascogne + +LengthAgeKey +~~~~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + voyage;baracoudaCode;age;length;percentAtAge;metadata;strata + +Format des colonnes +------------------- + +- voyage FK(Voyage#name) +- age (int) +- length (float) +- percentAtAge (float) +- metadata +- strata FK(Strata#name) +- baracoudaCode FK(Species#baracoudaCode) + +Exemple +------- + +:: + + voyage;baracoudaCode;age;length;percentAtAge;metadata;strata + PELGAS2011;ENGR-ENC";1;7.5;1;"Ifremer reading;Golfe de Gascogne + +Résultats Esdu +============== + +Esdu / Echotype +~~~~~~~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + voyage;name;echotype;NASC;ReferenceStationCatch;ReferenceStationBiometry;dataQuality + +Format des colonnes +------------------- + +- voyage FK(Voyage#name) +- name FK(esdu cell) +- echotype FK(Echotype#name) +- dataQuality FK(DataQuality#qualityDataFlagValues) +- méta-données FK(DataMetadata#name) (une colonne par méta à importer) + +Exemple +------- + +:: + + voyage;name;echotype;NASC;ReferenceStationCatch;ReferenceStationBiometry;dataQuality + PELGAS2011;2011-04-26 13:29:12.0000;D1";0;"P0379;P0379";1 + +Esdu / Echotype / Species Category +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + voyage;name;echotype;baracoudaCode;sizeCategory;ReferenceStationCatch;Biomass;MeanLength;MeanWeight;Abundance;SigmaSp;NASC;pondBiomass;pondAbundance;dataQuality + +Format des colonnes +------------------- + +- voyage FK(Voyage#name) +- name FK(esdu cell) +- echotype FK(Echotype#name) +- sizeCategory FK(SizeCategory#name) +- baracoudaCode FK(Species#baracoudaCode) +- dataQuality FK(DataQuality#qualityDataFlagValues) +- méta-données FK(DataMetadata#name) (une colonne par méta à importer) + +Exemple +------- + +:: + + voyage;name;echotype;baracoudaCode;sizeCategory;ReferenceStationCatch;Biomass;MeanLength;MeanWeight;Abundance;SigmaSp;NASC;pondBiomass;pondAbundance;dataQuality + PELGAS2011;2011-04-26 13:29:12.0000;D1;COMP-LEM;0";4;0;20;0.05;0;0.00100292822891053;0;0;0;1 + +Esdu / Species / Age Category +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + name;baracoudaCode;ageCategory;Abundance;ageCategoryMeaning;dataQuality;voyage + +Format des colonnes +------------------- + +- voyage FK(Voyage#name) +- name FK(esdu cell) +- baracoudaCode FK(Species#baracoudaCode) +- ageCategory +- ageCategoryMeaning +- dataQuality FK(DataQuality#qualityDataFlagValues) +- méta-données FK(DataMetadata#name) (une colonne par méta à importer) + +Exemple +------- + +:: + + name;baracoudaCode;ageCategory;Abundance;ageCategoryMeaning;dataQuality;voyage + 2011-04-26 13:35:19.0000;ENGR-ENC";3;3377.00492644042;"fish age-group (years)";1;"PELGAS2011 + +Esdu / Species / Size Category +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + name;baracoudaCode;sizeCategory;Biomass;Abundance;sizeCategoryMeaning;dataQuality;voyage + +Format des colonnes +------------------- + +- voyage FK(Voyage#name) +- name FK(esdu cell) +- baracoudaCode FK(Species#baracoudaCode) +- sizeCategory +- sizeCategoryMeaning +- dataQuality FK(DataQuality#qualityDataFlagValues) +- méta-données FK(DataMetadata#name) (une colonne par méta à importer) + +Exemple +------- + +:: + + name;baracoudaCode;sizeCategory;Biomass;Abundance;sizeCategoryMeaning;dataQuality;voyage + 2011-04-26 13:35:19.0000;MICR-POU";4;5190.7652880528;1297691.3220132;"mid point of 1 cm size bin";1;"PELGAS2011 + +Region +====== + +Region +~~~~~~ + +Colonnes requises +----------------- + +:: + + voyage;name;cellType;regionEnvCoordinates;surface;dataQuality + +Format des colonnes +------------------- + +- voyage FK(Voyage#name) +- cellType FK(CellType) +- dataQuality FK(DataQuality#qualityDataFlagValues) +- name +- regionEnvCoordinates +- surface (float) + +Exemple +------- + +:: + + voyage;name;cellType;regionEnvCoordinates;surface;dataQuality + PELGAS2011";1;"RegionCLAS;-1.40644893137726 43.8651260867463 50";1224.75678263326;1 + +Region Association +~~~~~~~~~~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + voyage;regionName;esduName + +Format des colonnes +------------------- + +- voyage FK(Voyage) +- regionName FK(Cell#name) +- esduName FK(Cell#name) + +Exemple +------- + +:: + + voyage;regionName;esduName + PELGAS2011";1;"2011-05-02 09:36:54.0000 + +Region results +~~~~~~~~~~~~~~ + +Colonnes requises +----------------- + +:: + + voyage;name;baracoudaCode;sizeCategory;echotype;VarianceXe;VarianceNASC;MeanXe;MeanNASC;NASCWeightedMeanXe;Nesdu;Nhauls;MeanNASCWeightedBiomassDensity;NASCWeightedEstimationVariance;NASCWeightedEstimationCV;MeanBiomassDensity;EstimationVariance;EstimationCV;TotalEstimationVariance;TotalNASCWeightedEstimationVariance;ProportionOfTotalEstimationVariance;ProportionOfNASCWeightedTotalEstimationVariance;Biomass;NASCWeightedBiomass;dataQuality + +Format des colonnes +------------------- + +- voyage FK(Voyage#name) +- name FK(Cell#name) +- baracoudaCode FK(Species#baracoudaCode) +- echotype FK(Echotype#name) +- sizeCategory FK(SizeCategory#name) +- dataQuality FK(DataQuality#qualityDataFlagValues) +- méta-données FK(DataMetadata#name) (une colonne par méta à importer) + +Exemple +------- + +:: + + voyage;name;baracoudaCode;sizeCategory;echotype;VarianceXe;VarianceNASC;MeanXe;MeanNASC;NASCWeightedMeanXe;Nesdu;Nhauls;MeanNASCWeightedBiomassDensity;NASCWeightedEstimationVariance;NASCWeightedEstimationCV;MeanBiomassDensity;EstimationVariance;EstimationCV;TotalEstimationVariance;TotalNASCWeightedEstimationVariance;ProportionOfTotalEstimationVariance;ProportionOfNASCWeightedTotalEstimationVariance;Biomass;NASCWeightedBiomass;dataQuality + PELGAS2011;6;CLUP-HAR;0;D2";NA;8963.28501789053;0.127534943481966;19.0945142790179;0.127534943481966;448;1;2.43521779939014;NA;NA;2.43521779939014;NA;NA;0;0;NA;NA;14380.2052341515;14380.2052341515;1 + + +Map +=== + +Map +~~~ + +Colonnes requises +----------------- + +:: + + voyage;name;baracoudaCode;sizeCategory;ageCategory;gridCellLongitude;gridCellLatitude;gridCellDepth;gridLongitudeLag;gridLatitudeLag;gridDepthLag;KrigedXe;dataQuality + +Format des colonnes +------------------- + +- voyage FK(Voyage#name) +- name +- baracoudaCode FK(Species#baracoudaCode) +- sizeCategory FK(SizeCategory#name) +- ageCategory FK(AgeCategory#name) +- dataQuality FK(DataQuality#qualityDataFlagValues) +- gridCellLongitude (float) +- gridCellLatitude (float) +- gridCellDepth (float) +- gridLongitudeLag (float) +- gridLatitudeLag (float) +- gridDepthLag (float) +- méta-données FK(DataMetadata#name) (une colonne par méta à importer) + +Exemple +------- + +:: + + voyage;name;baracoudaCode;sizeCategory;ageCategory;gridCellLongitude;gridCellLatitude;gridCellDepth;gridLongitudeLag;gridLatitudeLag;gridDepthLag;KrigedXe;dataQuality + PELGAS2011;-6 43.5 0;ENGR-ENC";0;;-6;43.5;0;0.25;0.25;0;0;1 Copied: trunk/src/site/en/rst/index.rst (from rev 573, trunk/src/site/rst/index.rst) =================================================================== --- trunk/src/site/en/rst/index.rst (rev 0) +++ trunk/src/site/en/rst/index.rst 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,51 @@ +.. - +.. * #%L +.. * EchoBase +.. * +.. * $Id$ +.. * $HeadURL$ +.. * %% +.. * Copyright (C) 2011 Ifremer, Codelutin +.. * %% +.. * This program is free software: you can redistribute it and/or modify +.. * it under the terms of the GNU Affero General Public License as published by +.. * the Free Software Foundation, either version 3 of the License, or +.. * (at your option) any later version. +.. * +.. * This program is distributed in the hope that it will be useful, +.. * but WITHOUT ANY WARRANTY; without even the implied warranty of +.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.. * GNU General Public License for more details. +.. * +.. * You should have received a copy of the GNU Affero General Public License +.. * along with this program. If not, see <http://www.gnu.org/licenses/>. +.. * #L% +.. - + +======== +Echobase +======== + +Présentation +------------ + +A Faire... +*TODO Translate this in english* + +Les documents +------------- + + +- La documentation d'`installation`_. + +- La description du `modèle`_. + +- La description des `imports`_. + +- Comment créer une `application embarquée`_. + +.. _installation: ./install.html +.. _modèle: ./model.html +.. _imports: ./imports.html +.. _application embarquée: ./embedded.html + Copied: trunk/src/site/en/rst/install.rst (from rev 573, trunk/src/site/rst/install.rst) =================================================================== --- trunk/src/site/en/rst/install.rst (rev 0) +++ trunk/src/site/en/rst/install.rst 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,205 @@ +.. - +.. * #%L +.. * EchoBase +.. * +.. * $Id$ +.. * $HeadURL$ +.. * %% +.. * Copyright (C) 2011 Ifremer, Codelutin +.. * %% +.. * This program is free software: you can redistribute it and/or modify +.. * it under the terms of the GNU Affero General Public License as published by +.. * the Free Software Foundation, either version 3 of the License, or +.. * (at your option) any later version. +.. * +.. * This program is distributed in the hope that it will be useful, +.. * but WITHOUT ANY WARRANTY; without even the implied warranty of +.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.. * GNU General Public License for more details. +.. * +.. * You should have received a copy of the GNU Affero General Public License +.. * along with this program. If not, see <http://www.gnu.org/licenses/>. +.. * #L% +.. - + +======== +Echobase +======== + +.. contents:: Table des matières + :depth: 2 + +.. sectnum:: + :start: 1 + :depth: 2 + +Installation d'EchoBase sur un serveur +-------------------------------------- + +*TODO Translate this in english* + +Nous préconisons toujours d'utiliser les valeurs par défaut fournies pour une +meilleur réactivité si un problème d'installation survient. + +Nous préconisons aussi l'utilisation d'un serveur linux de type debian :)... + +L'installation se déroule en 2 étapes : + +- création de la base de données +- installation de l'application + +Installation de la base de données +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Pré-requis : + - **postgres** doit être installé sur la machine (exemple pour un système + Debian : **sudo apt-get install postgresql**) + - être connecté avec l'utilisateur (postgres par défaut) qui a les droits + d'administrer cette base de donnée dans une console shell. + +1. Création de l'utilisateur Postgres + +:: + + createuser -U postgres -sdRP echobase + +2. Création de la base de donnée "echobase" + +:: + + createdb -U postgres -E UTF-8 -O echobase echobase + +3. Donner les droits d'acces à l'utilisateur echobase (cela varie d'un système + à l'autre, donc se référer à la documentation du système). Cela fonctionne + lorsqu'on peut accéder à la base via cette commande : + +:: + + psql -h localhost -U echobase echobase + +Préparation première installation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Il faut être loggué sur une console avec l'utilisateur root. + +On suppose ici que tomcat a été installé dans le répertoire */opt/tomcat* . + +Toutes les données de l'application (et sa configuration) seront placées dans +le répertoire **/var/local/echobase** + +- Créer les répertoires + +:: + + mkdir /var/local/echobase + mkdir /var/local/echobase/war + +- Placer le war à utiliser dans **/var/local/echobase/war** + +- Ajouter une lien symoblique vers le war à utiliser + +:: + + ln -s /var/local/echobase/war/echobase-ui-XXX.var /var/local/echobase/echobase.war + +- Ajouter un lien symbolique dans le répertoire **webapps** de tomcat vers ce + lien symbolique + +:: + + ln -s /var/local/echobase/echobase.war /opt/tomcat/webapps/echobase.war + +- Copier le fichier de configuration echobase.properties_ de l'application + dans **/var/local/echobase/** + +- Editer ce fichier pour adapter le mot de passe de l'utilisateur et peut-être + aussi l'url de connexion. Voici un exemple fichier modifié + +:: + + hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect + hibernate.connection.driver_class=org.postgresql.Driver + hibernate.connection.url=jdbc:postgresql://monNomDeMachine/echobase + hibernate.connection.username=echobase + hibernate.connection.password=motDePasseModifie + +- Ajouter un lien symbolique ver le fichier de configuration dans */etc* + +:: + + ln -s /var/local/echobase/echobase.properties /etc/echobase.properties + +Le répertoire au final devrait ressembler à ça : + +:: + + /var/local/echobase/ + ├── echobase.properties (configuration) + ├── echobase.war -> war/echobase-ui-1.0.war (war actuellement utilisé) + ├── logs (répertoire des logs) + └── war (répertoire des wars) + └── echobase-ui-1.0.war + +Une fois le serveur tomcat démarré, vous pouvez accéder à l'application à +l'adresse suivante : + +:: + + http://localhost:8080/echobase + + +Mettre à jour le war de l'application +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Il faut être loggué sur une console avec l'utilisateur root. + +On suppose ici que tomcat a été installé dans le répertoire */opt/tomcat* . + +Pour utiliser une nouvelle version de l'application, c'est en 5 étapes : + +1. Arrêter le serveur tomcat +2. Supprimer les répertoires suivants : + +:: + + rm -rf /opt/tomcat/webapps/echobase + rm -rf /opt/tomcat/work/Catalina/localhost/echobase + +3. Copier le nouveau war dans **/var/local/echobase/war** +4. Changer le lien symbolique **/var/local/echobase/echobase.war** + +:: + + ln -fvs /var/local/echobasewar/echobase-ui-XXX.war /var/local/echobase/echobase.war + +5. Relancer le serveur tomcat + +Divers +------ + +Gestion des logs de l'application +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Avant de lancer l'application, il faut avoir positionner une variable +**echobase.log.dir** de jvm qui définit le répertoire où positionner les logs +de l'application.:: + + JAVA_OPTS="$JAVA_OPTS -Dechobase.log.dir=/var/local/echobase/logs" + +ou:: + + CATALINA_OPTS="$CATALINA_OPTS -Dechobase.log.dir=/var/local/echobase/logs" + +Première utilisation +~~~~~~~~~~~~~~~~~~~~ + +Deux utilisateurs sont créés si la base est vide (première utilisation):: + + login / password : admin / admin + login / password : user / user + +Pour des raisons de sécurité, il est conseillé de modifier le mot de passe via +l'interface de gestion des utilisateurs. + +.. _echobase.properties: echobase.properties + Copied: trunk/src/site/en/rst/model.rst (from rev 573, trunk/src/site/rst/model.rst) =================================================================== --- trunk/src/site/en/rst/model.rst (rev 0) +++ trunk/src/site/en/rst/model.rst 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,94 @@ +.. - +.. * #%L +.. * echobase +.. * +.. * $Id$ +.. * $HeadURL$ +.. * %% +.. * Copyright (C) 2011 Ifremer, Codelutin +.. * %% +.. * This program is free software: you can redistribute it and/or modify +.. * it under the terms of the GNU Affero General Public License as published by +.. * the Free Software Foundation, either version 3 of the License, or +.. * (at your option) any later version. +.. * +.. * This program is distributed in the hope that it will be useful, +.. * but WITHOUT ANY WARRANTY; without even the implied warranty of +.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.. * GNU General Public License for more details. +.. * +.. * You should have received a copy of the GNU Affero General Public License +.. * along with this program. If not, see <http://www.gnu.org/licenses/>. +.. * #L% +.. - + +=============== +Modèle Echobase +=============== + +.. contents:: Table des matières + :depth: 2 + +.. sectnum:: + :start: 1 + :depth: 2 + +Présentation +------------ + +*TODO Translate this in english* +On donne ici des explications sur le modèle. + +Le modèle conçu sous argoUML est téléchargeable `ici`_ . + +Modèle du référentiel +--------------------- + +- `Vue générale du référentiel`_ +- `Référentiel AcousticInstrument`_ +- `Référentiel AreaOfOperation`_ +- `Référentiel DataMetadata`_ +- `Référentiel DepthStratum`_ +- `Référentiel Echotype`_ +- `Référentiel Gear`_ +- `Référentiel Mission`_ +- `Référentiel ReferenceDatum`_ +- `Référentiel TSParameter`_ +- `Référentiel Vessel`_ + +Modèle thématique +----------------- + +Partie commune +~~~~~~~~~~~~~~ + +- `Partie commune des données thématiques`_ + + +Sous modèle acoustique +~~~~~~~~~~~~~~~~~~~~~~ + +- `Sous modèle acoustique`_ + +Sous modèle pêcherie +~~~~~~~~~~~~~~~~~~~~ + +- `Sous modèle pêcherie`_ + +.. _ici: http://svn.forge.codelutin.com/svn/echobase/trunk/echobase-entities/src/main... + +.. _Vue générale du référentiel: model/referenceAll.png +.. _Référentiel AcousticInstrument: model/referenceAcousticInstrument.png +.. _Référentiel AreaOfOperation: model/referenceAreaOfOperation.png +.. _Référentiel DataMetadata: model/referenceDataMetadata.png +.. _Référentiel DepthStratum: model/referenceDepthStratum.png +.. _Référentiel Echotype: model/referenceEchotype.png +.. _Référentiel Gear: model/referenceGear.png +.. _Référentiel Mission: model/referenceMission.png +.. _Référentiel ReferenceDatum: model/referenceReferenceDatum.png +.. _Référentiel TSParameter: model/referenceTSParameter.png +.. _Référentiel Vessel: model/referenceVessel.png + +.. _Partie commune des données thématiques: model/dataCommon.png +.. _Sous modèle acoustique: model/dataAcoustic.png +.. _Sous modèle pêcherie: model/dataCatches.png Deleted: trunk/src/site/resources/images/argouml-logo.png =================================================================== (Binary files differ) Deleted: trunk/src/site/resources/images/jrst-logo.png =================================================================== (Binary files differ) Deleted: trunk/src/site/resources/images/restructuredtext-logo.png =================================================================== (Binary files differ) Deleted: trunk/src/site/resources/images/struts2-logo.png =================================================================== (Binary files differ) Deleted: trunk/src/site/resources/images/topia-logo.png =================================================================== (Binary files differ) Modified: trunk/src/site/rst/embedded.rst =================================================================== --- trunk/src/site/rst/embedded.rst 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/src/site/rst/embedded.rst 2012-08-30 16:16:04 UTC (rev 574) @@ -21,6 +21,7 @@ .. * along with this program. If not, see <http://www.gnu.org/licenses/>. .. * #L% .. - + ======== Echobase ======== Modified: trunk/src/site/rst/imports.rst =================================================================== --- trunk/src/site/rst/imports.rst 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/src/site/rst/imports.rst 2012-08-30 16:16:04 UTC (rev 574) @@ -21,9 +21,10 @@ .. * along with this program. If not, see <http://www.gnu.org/licenses/>. .. * #L% .. - -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +======================================= Liste des colonnes des imports EchoBase -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +======================================= .. contents:: Table des matières :depth: 2 @@ -343,7 +344,7 @@ P5002;ENGR-ENC";9394;NA;-1;"Age Acoustic -======== +~~~~~~~~ Colonnes requises ----------------- @@ -657,6 +658,9 @@ Map === +Map +~~~ + Colonnes requises ----------------- Modified: trunk/src/site/rst/index.rst =================================================================== --- trunk/src/site/rst/index.rst 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/src/site/rst/index.rst 2012-08-30 16:16:04 UTC (rev 574) @@ -21,6 +21,7 @@ .. * along with this program. If not, see <http://www.gnu.org/licenses/>. .. * #L% .. - + ======== Echobase ======== Modified: trunk/src/site/rst/install.rst =================================================================== --- trunk/src/site/rst/install.rst 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/src/site/rst/install.rst 2012-08-30 16:16:04 UTC (rev 574) @@ -21,6 +21,7 @@ .. * along with this program. If not, see <http://www.gnu.org/licenses/>. .. * #L% .. - + ======== Echobase ======== @@ -130,15 +131,11 @@ :: -tchemit@tc:~/projets/forge/echobase$ tree /var/local/echobase/ /var/local/echobase/ ├── echobase.properties (configuration) ├── echobase.war -> war/echobase-ui-1.0.war (war actuellement utilisé) ├── logs (répertoire des logs) └── war (répertoire des wars) - ├── echobase-ui-0.2.war - ├── echobase-ui-0.4.war - ├── echobase-ui-0.6.war └── echobase-ui-1.0.war Une fois le serveur tomcat démarré, vous pouvez accéder à l'application à @@ -148,7 +145,6 @@ http://localhost:8080/echobase - Mettre à jour le war de l'application ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Modified: trunk/src/site/rst/model.rst =================================================================== --- trunk/src/site/rst/model.rst 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/src/site/rst/model.rst 2012-08-30 16:16:04 UTC (rev 574) @@ -21,6 +21,7 @@ .. * along with this program. If not, see <http://www.gnu.org/licenses/>. .. * #L% .. - + =============== Modèle Echobase =============== @@ -40,7 +41,7 @@ Le modèle conçu sous argoUML est téléchargeable `ici`_ . Modèle du référentiel ---------------------- +===================== - `Vue générale du référentiel`_ - `Référentiel AcousticInstrument`_ @@ -55,7 +56,7 @@ - `Référentiel Vessel`_ Modèle thématique ------------------ +================= Partie commune ~~~~~~~~~~~~~~ Deleted: trunk/src/site/rst/todo.rst =================================================================== --- trunk/src/site/rst/todo.rst 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/src/site/rst/todo.rst 2012-08-30 16:16:04 UTC (rev 574) @@ -1,38 +0,0 @@ -.. - -.. * #%L -.. * EchoBase -.. * -.. * $Id$ -.. * $HeadURL$ -.. * %% -.. * Copyright (C) 2011 Ifremer, Codelutin -.. * %% -.. * This program is free software: you can redistribute it and/or modify -.. * it under the terms of the GNU Affero General Public License as published by -.. * the Free Software Foundation, either version 3 of the License, or -.. * (at your option) any later version. -.. * -.. * This program is distributed in the hope that it will be useful, -.. * but WITHOUT ANY WARRANTY; without even the implied warranty of -.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -.. * GNU General Public License for more details. -.. * -.. * You should have received a copy of the GNU Affero General Public License -.. * along with this program. If not, see <http://www.gnu.org/licenses/>. -.. * #L% -.. - -======== -Echobase -======== - -.. contents:: Table des matières - :depth: 2 - -.. sectnum:: - :start: 1 - :depth: 2 - -TODO -==== - -- Completer la documentation \ No newline at end of file Copied: trunk/src/site/site_en.xml (from rev 573, trunk/src/site/site_fr.xml) =================================================================== --- trunk/src/site/site_en.xml (rev 0) +++ trunk/src/site/site_en.xml 2012-08-30 16:16:04 UTC (rev 574) @@ -0,0 +1,132 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + EchoBase + + $Id$ + $HeadURL$ + %% + Copyright (C) 2011 Ifremer, Codelutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + #L% + --> + +<project name="${project.name}"> + + <skin> + <groupId>org.apache.maven.skins</groupId> + <artifactId>maven-fluido-skin</artifactId> + <version>1.2.1</version> + </skin> + + <custom> + <fluidoSkin> + <topBarEnabled>false</topBarEnabled> + <googleSearch/> + <sideBarEnabled>true</sideBarEnabled> + <searchEnabled>true</searchEnabled> + <sourceLineNumbersEnabled>true</sourceLineNumbersEnabled> + </fluidoSkin> + </custom> + + <bannerLeft> + <name>${project.name}</name> + <src>${project.url}/images/echobase-logo.png</src> + <href>${project.url}/en/index.html</href> + </bannerLeft> + + <publishDate position="right" format="yyyy-MM-dd"/> + <version position="right" /> + + <poweredBy> + <logo href="http://maven.apache.org" name="Maven" + img="http://maven-site.chorem.org/public/images/logos/maven-feather.png"/> + + <logo href="http://struts.apache.org/" name="Struts 2" + img="http://maven-site.chorem.org/public/images/logos/struts2-logo.png"/> + + <logo href="http://docutils.sourceforge.net/rst.html" + name="ReStructuredText" + img="http://maven-site.chorem.org/public/images/logos/restructuredtext-logo.png"/> + + <logo href="http://maven-site.nuiton.org/jrst" name="JRst" + img="http://maven-site.chorem.org/public/images/logos/jrst-logo.png"/> + + <logo href="http://maven-site.nuiton.org/topia" name="ToPIA" + img="http://maven-site.chorem.org/public/images/logos/topia-logo.png"/> + + <logo href="http://argouml.tigris.org/" name="ArgoUML" + img="http://maven-site.chorem.org/public/images/logos/argouml-logo.png"/> + + </poweredBy> + + <body> + + <head> + <script type="text/javascript" + src="http://maven-site.chorem.org/public/js/maven-site-chorem.org.js"> + </script> + + <link rel="stylesheet" type="text/css" + href="http://maven-site.chorem.org/public/css/maven-site-chorem.org.css"/> + </head> + + <links> + <item name="Forge" href="http://www.forge.codelutin.com"/> + <item name="CodeLutin" href="http://codelutin.com"/> + <item name="Libre-Entreprise" href="http://www.libre-entreprise.org/"/> + </links> + + <breadcrumbs> + <item name="${project.name}" + href="${project.url}/en/index.html"/> + </breadcrumbs> + + <menu name="Language"> + <item name="Version Française" href="../index.html"/> + <item name="English Version" href="./index.html"/> + </menu> + + <menu name="Utilisateur"> + <item name="Accueil" href="index.html"/> + <item name="Installation" href="install.html"/> + <item name="Application embarquée" href="embedded.html"/> + <item name="Les imports" href="imports.html"/> + <item name="Téléchargement" + href="http://forge.codelutin.com/projects/echobase/files"/> + <item name="Roadmap" + href="http://forge.codelutin.com/projects/echobase/roadmap"/> + + <item name="Historique des versions" href="changes-report.html"/> + </menu> + + <menu ref="reports"/> + + <footer> + + <div id='projectMetas' + projectversion='${project.version}' + platform='${project.platform}' + projectid='${project.projectId}' + scm='${project.scm.developerConnection}' + scmwebeditorenabled='${project.scmwebeditorEnabled}' + scmwebeditorurl='${project.scmwebeditorUrl}' + siteSourcesType='${project.siteSourcesType}' + piwikEnabled='${project.piwikEnabled}' + piwikId='${project.piwikId}'> + </div> + </footer> + </body> +</project> Modified: trunk/src/site/site_fr.xml =================================================================== --- trunk/src/site/site_fr.xml 2012-08-29 20:38:56 UTC (rev 573) +++ trunk/src/site/site_fr.xml 2012-08-30 16:16:04 UTC (rev 574) @@ -33,9 +33,9 @@ <custom> <fluidoSkin> - <topBarEnabled>true</topBarEnabled> + <topBarEnabled>false</topBarEnabled> <googleSearch/> - <sideBarEnabled>false</sideBarEnabled> + <sideBarEnabled>true</sideBarEnabled> <searchEnabled>true</searchEnabled> <sourceLineNumbersEnabled>true</sourceLineNumbersEnabled> </fluidoSkin> @@ -43,44 +43,62 @@ <bannerLeft> <name>${project.name}</name> - <src>./images/echobase-logo.png</src> - <href>index.html</href> + <src>${project.url}/images/echobase-logo.png</src> + <href>${project.url}/index.html</href> </bannerLeft> - <publishDate position="right" /> + <publishDate position="right" format="dd/MM/yyyy"/> <version position="right" /> + <poweredBy> <logo href="http://maven.apache.org" name="Maven" - img="${project.url}/images/logos/maven-feather.png"/> + img="http://maven-site.chorem.org/public/images/logos/maven-feather.png"/> <logo href="http://struts.apache.org/" name="Struts 2" - img="${project.url}/images/struts2-logo.png"/> + img="http://maven-site.chorem.org/public/images/logos/struts2-logo.png"/> <logo href="http://docutils.sourceforge.net/rst.html" name="ReStructuredText" - img="${project.url}/images/restructuredtext-logo.png"/> + img="http://maven-site.chorem.org/public/images/logos/restructuredtext-logo.png"/> <logo href="http://maven-site.nuiton.org/jrst" name="JRst" - img="${project.url}/images/jrst-logo.png"/> + img="http://maven-site.chorem.org/public/images/logos/jrst-logo.png"/> <logo href="http://maven-site.nuiton.org/topia" name="ToPIA" - img="${project.url}/images/topia-logo.png"/> + img="http://maven-site.chorem.org/public/images/logos/topia-logo.png"/> <logo href="http://argouml.tigris.org/" name="ArgoUML" - img="${project.url}/images/argouml-logo.png"/> + img="http://maven-site.chorem.org/public/images/logos/argouml-logo.png"/> </poweredBy> <body> + + <head> + <script type="text/javascript" + src="http://maven-site.chorem.org/public/js/maven-site-chorem.org.js"> + </script> + + <link rel="stylesheet" type="text/css" + href="http://maven-site.chorem.org/public/css/maven-site-chorem.org.css"/> + </head> + <links> <item name="Forge" href="http://www.forge.codelutin.com"/> + <item name="CodeLutin" href="http://codelutin.com"/> + <item name="Libre-Entreprise" href="http://www.libre-entreprise.org/"/> </links> <breadcrumbs> <item name="${project.name}" - href="http://maven-site.forge.codelutin.com/echobase/index.html"/> + href="${project.url}/index.html"/> </breadcrumbs> + <menu name="Language"> + <item name="Version Française" href="./index.html"/> + <item name="English Version" href="./en/index.html"/> + </menu> + <menu name="Utilisateur"> <item name="Accueil" href="index.html"/> <item name="Installation" href="install.html"/> @@ -94,26 +112,15 @@ <item name="Historique des versions" href="changes-report.html"/> </menu> - - <menu name="Développeur"> - <item name="A faire" href="todo.html"/> - </menu> - <menu ref="reports"/> - <!--menu ref="modules"/--> - <footer> - <script type="text/javascript" - src="http://maven-site.forge.codelutin.com/public/js/maven-site-forge.codelutin.com.js"> - </script> - <div id='projectMetas' projectversion='${project.version}' platform='${project.platform}' projectid='${project.projectId}' - scm='${project.scm.connection}' + scm='${project.scm.developerConnection}' scmwebeditorenabled='${project.scmwebeditorEnabled}' scmwebeditorurl='${project.scmwebeditorUrl}' siteSourcesType='${project.siteSourcesType}'
participants (1)
-
tchemit@users.forge.codelutin.com