Echobase-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
December 2011
- 2 participants
- 86 discussions
r218 - trunk/echobase-services/src/main/java/fr/ifremer/echobase/services
by tchemit@users.forge.codelutin.com 27 Dec '11
by tchemit@users.forge.codelutin.com 27 Dec '11
27 Dec '11
Author: tchemit
Date: 2011-12-27 11:22:13 +0100 (Tue, 27 Dec 2011)
New Revision: 218
Url: http://forge.codelutin.com/repositories/revision/echobase/218
Log:
try to improve export via hibernate
Modified:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java 2011-12-26 19:47:00 UTC (rev 217)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java 2011-12-27 10:22:13 UTC (rev 218)
@@ -31,6 +31,7 @@
import fr.ifremer.echobase.entities.meta.TableMeta;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.TopiaException;
import org.nuiton.util.FileUtil;
import org.nuiton.util.TimeLog;
@@ -60,7 +61,7 @@
* @return the zip archive file
* @throws IOException if could not create or write files.
*/
- public File exportDb(ExportDbConfiguration model) throws IOException {
+ public File exportDb(ExportDbConfiguration model) throws IOException, TopiaException {
String fileName = model.getFileName();
@@ -100,6 +101,9 @@
TableMeta meta = (TableMeta) entry;
exportService.exportDatas(meta, entryFile);
}
+
+ //TODO Test this : this will refresh the hibernate session ? try this to improve export times...
+ getTransaction().rollbackTransaction();
}
EchoBaseIOUtil.compressZipFile(zipFile, dir);
1
0
26 Dec '11
Author: tchemit
Date: 2011-12-26 20:47:00 +0100 (Mon, 26 Dec 2011)
New Revision: 217
Url: http://forge.codelutin.com/repositories/revision/echobase/217
Log:
create exportQuery namespace
implements exportDb
Added:
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/
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/DownloadExport.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/LaunchExport.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/
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/resources/config/struts-exportDb.xml
trunk/echobase-ui/src/main/resources/config/struts-exportQuery.xml
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/configure.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/progress.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/result.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportQuery/
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportQuery/exportQuery.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportQuery/exportQueryResult.jsp
Removed:
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlResult.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/GetSqlResult.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportSql.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportSqlResult.jsp
Modified:
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseSession.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/LaunchImport.java
trunk/echobase-ui/src/main/resources/config/struts-export.xml
trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties
trunk/echobase-ui/src/main/resources/struts.xml
trunk/echobase-ui/src/main/webapp/WEB-INF/decorators.xml
trunk/echobase-ui/src/main/webapp/WEB-INF/includes/header.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importDb/progress.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importDb/result.jsp
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 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseSession.java 2011-12-26 19:47:00 UTC (rev 217)
@@ -24,6 +24,7 @@
package fr.ifremer.echobase.ui;
import fr.ifremer.echobase.entities.EchoBaseUser;
+import fr.ifremer.echobase.services.ExportDbConfiguration;
import fr.ifremer.echobase.services.ImportDataConfiguration;
import fr.ifremer.echobase.services.ImportDbConfiguration;
import org.apache.commons.logging.Log;
@@ -52,6 +53,9 @@
/** Key to keep import db configuration in this session. */
protected static final String PROPERTY_IMPORT_DB_CONFIGURATION = "importDbConfiguration";
+ /** Key to keep export db configuration in this session. */
+ protected static final String PROPERTY_EXPORT_DB_CONFIGURATION = "exportDbConfiguration";
+
/** To store all properties in this session. */
protected Map<String, Object> store;
@@ -89,6 +93,14 @@
set(PROPERTY_IMPORT_DB_CONFIGURATION, configuration);
}
+ public ExportDbConfiguration getExportDbConfiguration() {
+ return get(PROPERTY_EXPORT_DB_CONFIGURATION, ExportDbConfiguration.class);
+ }
+
+ public void setExportDbConfiguration(ExportDbConfiguration configuration) {
+ set(PROPERTY_EXPORT_DB_CONFIGURATION, configuration);
+ }
+
/**
* Remove form this session, the object from his given key and returns it.
*
@@ -133,7 +145,7 @@
if (o != null && !type.isInstance(o)) {
throw new ClassCastException(
"parameter " + key + " should be of type " +
- type.getName() + " but was " + o.getClass().getName());
+ type.getName() + " but was " + o.getClass().getName());
}
return (T) o;
}
Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java 2011-12-26 19:47:00 UTC (rev 217)
@@ -1,93 +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.actions.export;
-
-import fr.ifremer.echobase.services.ExportSqlService;
-import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-
-/**
- * Download the result of sql request in csv format.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.1
- */
-public class DownloadExportSqlResult extends EchoBaseActionSupport {
-
- private static final long serialVersionUID = 1L;
-
- /** Sql request to execute. */
- protected String sql;
-
- /** Input stream of the file to download. */
- protected transient InputStream inputStream;
-
- /** File name of the download. */
- protected String fileName;
-
- /** Length of the file to download. */
- protected int contentLength;
-
- /** Content type of the file to download. */
- protected String contentType;
-
- public void setSql(String sql) {
- this.sql = sql;
- }
-
- public void setFileName(String fileName) {
- this.fileName = fileName;
- }
-
- public InputStream getInputStream() {
- return inputStream;
- }
-
- public String getFileName() {
- return fileName;
- }
-
- public int getContentLength() {
- return contentLength;
- }
-
- public String getContentType() {
- return contentType;
- }
-
- @Override
- public String execute() throws Exception {
-
- ExportSqlService service = newService(ExportSqlService.class);
-
- contentType = "text/csv";
- String content = service.createCsvFileContent(sql);
- contentLength = content.length();
- inputStream = new ByteArrayInputStream(content.getBytes());
-
- return SUCCESS;
- }
-}
Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlResult.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlResult.java 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlResult.java 2011-12-26 19:47:00 UTC (rev 217)
@@ -1,83 +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.actions.export;
-
-import fr.ifremer.echobase.EchoBaseTechnicalException;
-import fr.ifremer.echobase.services.ExportSqlService;
-import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
-
-/**
- * Load export sql result fragment page.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.1
- */
-public class ExportSqlResult extends EchoBaseActionSupport {
-
- private static final long serialVersionUID = 1L;
-
- /** Sql request to execute. */
- protected String sql;
-
- /** Default file name for export. */
- protected String fileName;
-
- /** names of columns from the executed sql request. */
- protected String[] columnNames;
-
- public String getSql() {
- return sql;
- }
-
- public String[] getColumnNames() {
- return columnNames;
- }
-
- public String getFileName() {
- return fileName;
- }
-
- public void setSql(String sql) {
- this.sql = sql;
- }
-
- @Override
- public String execute() throws Exception {
-
- // obtain columNames from the request
- ExportSqlService service = newService(ExportSqlService.class);
-
- try {
- columnNames = service.getColumnNames(sql);
- } catch (EchoBaseTechnicalException e) {
- //TODO add a real nice message
- addActionError(e.getMessage());
- }
-
- // create default file name
-
- fileName = "export.csv";
- return SUCCESS;
- }
-}
Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/GetSqlResult.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/GetSqlResult.java 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/GetSqlResult.java 2011-12-26 19:47:00 UTC (rev 217)
@@ -1,81 +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.actions.export;
-
-import fr.ifremer.echobase.services.ExportSqlService;
-import fr.ifremer.echobase.ui.actions.AbstractJSONPaginedAction;
-
-import java.util.Map;
-
-/**
- * Obtains result of a sql query.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.1
- */
-public class GetSqlResult extends AbstractJSONPaginedAction {
-
- private static final long serialVersionUID = 1L;
-
- /** Sql request to execute. */
- protected String sql;
-
- /** Datas of the given table. */
- protected Map<?, ?>[] datas;
-
- public void setSql(String sql) {
- this.sql = sql;
- }
-
- public Map<?, ?>[] getDatas() {
- return datas;
- }
-
- @Override
- public Integer getRows() {
- return pager.getPageSize();
- }
-
- @Override
- public Integer getPage() {
- return pager.getPageNumber();
- }
-
- @Override
- public Integer getTotal() {
- return pager.getPageCount();
- }
-
- @Override
- public Integer getRecords() {
- return pager.getRecords();
- }
-
- @Override
- public String execute() throws Exception {
- ExportSqlService service = newService(ExportSqlService.class);
- datas = service.executeSql(sql, pager);
- return SUCCESS;
- }
-}
Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java 2011-12-26 19:47:00 UTC (rev 217)
@@ -1,125 +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.actions.export;
-
-import com.opensymphony.xwork2.Preparable;
-import fr.ifremer.echobase.entities.ExportQuery;
-import fr.ifremer.echobase.entities.ExportQueryImpl;
-import fr.ifremer.echobase.services.ExportSqlService;
-import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
-import org.apache.commons.lang3.StringUtils;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * To manage {@link ExportQuery}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.1
- */
-public class ManageExportQuery extends EchoBaseActionSupport implements Preparable {
-
- private static final long serialVersionUID = 1L;
-
- /** All available queries from database. */
- protected Map<String, String> queries;
-
- /** Selected query loaded from database if his id is not empty. */
- protected ExportQuery query;
-
- public ExportQuery getQuery() {
- if (query == null) {
- query = new ExportQueryImpl();
- }
- return query;
- }
-
- public Map<String, String> getQueries() {
- return queries;
- }
-
- public Map<String, String> getTableNames() {
- return queries;
- }
-
- public String saveQuery() throws Exception {
-
- //TODO : do validation
- ExportSqlService service = newService(ExportSqlService.class);
-
- query = service.createOrUpdate(getQuery(),
- getEchoBaseSession().getEchoBaseUser()
- );
- return SUCCESS;
- }
-
- public String cloneQuery() throws Exception {
-
- //TODO : do validation
- ExportSqlService service = newService(ExportSqlService.class);
-
- getQuery().setTopiaId(null);
- query = service.createOrUpdate(getQuery(),
- getEchoBaseSession().getEchoBaseUser()
- );
- return SUCCESS;
- }
-
- public String deleteQuery() throws Exception {
-
- //TODO : do validation
- ExportSqlService service = newService(ExportSqlService.class);
- service.delete(getQuery().getTopiaId());
- query = null;
- return SUCCESS;
- }
-
- @Override
- public void prepare() throws Exception {
- ExportSqlService service = newService(ExportSqlService.class);
-
- Collection<ExportQuery> sqlQueries =
- service.getEntities(ExportQuery.class);
- queries = sortAndDecorate(sqlQueries, null);
-
- if (sqlQueries.isEmpty()) {
- // no query saved
- addActionMessage(_("echobase.info.no.sqlQuery.saved"));
- } else {
-
- String selectedQueryId = getQuery().getTopiaId();
-
- if (StringUtils.isEmpty(selectedQueryId)) {
-
- // no query selected
- addActionMessage(_("echobase.info.no.sqlQuery.selected"));
- } else {
-
- // load query from database
- query = service.getEntityById(ExportQuery.class, selectedQueryId);
- }
- }
- }
-}
\ No newline at end of file
Added: 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 (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Configure.java 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,89 @@
+/*
+ * #%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.actions.exportDb;
+
+import fr.ifremer.echobase.services.ExportDbConfiguration;
+import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.FileUtil;
+
+import java.io.File;
+
+/**
+ * Configure the complete db export.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class Configure extends EchoBaseActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(Configure.class);
+
+ protected ExportDbConfiguration model;
+
+ public ExportDbConfiguration getModel() {
+ if (model == null) {
+ model = new ExportDbConfiguration();
+ model.setFileName("echobase");
+ }
+ return model;
+ }
+
+ public void setFileName(String fileName) {
+ getModel().setFileName(fileName);
+ }
+
+ @Override
+ public String input() throws Exception {
+
+ // always remove configuration from session anytime coming here
+ getEchoBaseSession().setExportDbConfiguration(null);
+ return INPUT;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ ExportDbConfiguration configuration = getModel();
+
+ File tempDirectory = FileUtils.getTempDirectory();
+ File dataDirectory = new File(
+ tempDirectory,
+ "echobase-exportDb-" + System.currentTimeMillis());
+ FileUtil.createDirectoryIfNecessary(dataDirectory);
+ configuration.setWorkingDirectory(dataDirectory);
+ if (log.isInfoEnabled()) {
+ log.info("Temporary directory to use : " + dataDirectory);
+ }
+
+ // store configuration in session
+ getEchoBaseSession().setExportDbConfiguration(configuration);
+ return SUCCESS;
+ }
+}
\ No newline at end of file
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/Configure.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/DownloadExport.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/DownloadExport.java (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/DownloadExport.java 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,96 @@
+/*
+ * #%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.actions.exportDb;
+
+import fr.ifremer.echobase.services.ExportDbConfiguration;
+import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+
+/**
+ * Download the result of the complete db export.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class DownloadExport extends EchoBaseActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Input stream of the file to download. */
+ protected transient InputStream inputStream;
+
+ /** File name of the download. */
+ protected String fileName;
+
+ /** Length of the file to download. */
+ protected long contentLength;
+
+ /** Content type of the file to download. */
+ protected String contentType;
+
+ public InputStream getInputStream() {
+ return inputStream;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public long getContentLength() {
+ return contentLength;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ ExportDbConfiguration model =
+ getEchoBaseSession().getExportDbConfiguration();
+
+ if (model == null) {
+ addActionError(_("echobase.error.no.dbExport.configurationFound"));
+ return ERROR;
+ }
+
+ File exportFile = model.getExportFile();
+ if (exportFile == null) {
+ addActionError(_("echobase.error.no.dbExport.exportFileFound"));
+ return ERROR;
+ }
+
+ fileName = exportFile.getName();
+ contentType = "zip";
+ contentLength = exportFile.length();
+ inputStream = new BufferedInputStream(new FileInputStream(exportFile));
+
+ return SUCCESS;
+ }
+}
\ No newline at end of file
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/DownloadExport.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/LaunchExport.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/LaunchExport.java (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/LaunchExport.java 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,125 @@
+/*
+ * #%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.actions.exportDb;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.Preparable;
+import fr.ifremer.echobase.services.CsvImportResult;
+import fr.ifremer.echobase.services.DbExportService;
+import fr.ifremer.echobase.services.ExportDbConfiguration;
+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.framework.TopiaContextImplementor;
+
+import java.util.Date;
+
+/**
+ * Launch the complete db export.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class LaunchExport extends EchoBaseActionSupport implements Preparable {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(LaunchExport.class);
+
+ /** Configuration of the export action. */
+ protected ExportDbConfiguration model;
+
+ /** Result of import. */
+ protected CsvImportResult importResult;
+
+ /** service to execute the export. */
+ protected transient DbExportService service;
+
+ /** Shared actionContext to reuse all invocation of this same action. */
+ protected ActionContext actionContext;
+
+ public ExportDbConfiguration getModel() {
+ return model;
+ }
+
+ @Override
+ public void prepare() throws Exception {
+
+ if (actionContext == null) {
+
+ // keep it since exec and wait then use another thread
+ actionContext = ActionContext.getContext();
+ } else {
+
+ // having the action context here means we already came here,
+ // now we need to propagate it
+ ActionContext.setContext(actionContext);
+ }
+ model = getEchoBaseSession().getExportDbConfiguration();
+
+ service = newService(DbExportService.class);
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ model.setStartTime(new Date());
+
+ // having the action context here means we already came here,
+ // now we need to propagate it
+ ActionContext.setContext(actionContext);
+
+ // 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();
+ serviceContext.setTransaction(topiaContext);
+ try {
+
+ if (log.isInfoEnabled()) {
+ log.info("Start export to file " + model.getFileName());
+ }
+
+ service.exportDb(model);
+ model.setEndTime(new Date());
+
+ return SUCCESS;
+ } finally {
+
+ topiaContext.closeContext();
+
+// // clean configuration
+// model.destroy();
+
+ // remove configuration from session
+// getEchoBaseSession().setExportDbConfiguration(null);
+ }
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportDb/LaunchExport.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/DownloadExportQueryResult.java (from rev 211, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/DownloadExportSqlResult.java)
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/DownloadExportQueryResult.java (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/DownloadExportQueryResult.java 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,93 @@
+/*
+ * #%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.actions.exportQuery;
+
+import fr.ifremer.echobase.services.ExportQueryService;
+import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+/**
+ * Download the result of sql request in csv format.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.1
+ */
+public class DownloadExportQueryResult extends EchoBaseActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Sql request to execute. */
+ protected String sql;
+
+ /** Input stream of the file to download. */
+ protected transient InputStream inputStream;
+
+ /** File name of the download. */
+ protected String fileName;
+
+ /** Length of the file to download. */
+ protected int contentLength;
+
+ /** Content type of the file to download. */
+ protected String contentType;
+
+ public void setSql(String sql) {
+ this.sql = sql;
+ }
+
+ public void setFileName(String fileName) {
+ this.fileName = fileName;
+ }
+
+ public InputStream getInputStream() {
+ return inputStream;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public int getContentLength() {
+ return contentLength;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ ExportQueryService service = newService(ExportQueryService.class);
+
+ contentType = "text/csv";
+ String content = service.createCsvFileContent(sql);
+ contentLength = content.length();
+ inputStream = new ByteArrayInputStream(content.getBytes());
+
+ return SUCCESS;
+ }
+}
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/DownloadExportQueryResult.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ExportQueryResult.java (from rev 211, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ExportSqlResult.java)
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ExportQueryResult.java (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ExportQueryResult.java 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,91 @@
+/*
+ * #%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.actions.exportQuery;
+
+import fr.ifremer.echobase.EchoBaseTechnicalException;
+import fr.ifremer.echobase.services.ExportQueryService;
+import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Load export sql result fragment page.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.1
+ */
+public class ExportQueryResult extends EchoBaseActionSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(ExportQueryResult.class);
+
+ /** Sql request to execute. */
+ protected String sql;
+
+ /** Default file name for export. */
+ protected String fileName;
+
+ /** names of columns from the executed sql request. */
+ protected String[] columnNames;
+
+ public String getSql() {
+ return sql;
+ }
+
+ public String[] getColumnNames() {
+ return columnNames;
+ }
+
+ public String getFileName() {
+ return fileName;
+ }
+
+ public void setSql(String sql) {
+ this.sql = sql;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ // obtain columNames from the request
+ ExportQueryService service = newService(ExportQueryService.class);
+
+ try {
+ columnNames = service.getColumnNames(sql);
+ } catch (EchoBaseTechnicalException e) {
+ //TODO add a real nice message
+ addActionError(e.getMessage());
+ if (log.isErrorEnabled()) {
+ log.error("coudl not execute query " + sql, e);
+ }
+ }
+
+ // create default file name
+
+ fileName = "export.csv";
+ return SUCCESS;
+ }
+}
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ExportQueryResult.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/GetExportQueryResult.java (from rev 211, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/GetSqlResult.java)
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/GetExportQueryResult.java (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/GetExportQueryResult.java 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,81 @@
+/*
+ * #%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.actions.exportQuery;
+
+import fr.ifremer.echobase.services.ExportQueryService;
+import fr.ifremer.echobase.ui.actions.AbstractJSONPaginedAction;
+
+import java.util.Map;
+
+/**
+ * Obtains result of a sql query.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.1
+ */
+public class GetExportQueryResult extends AbstractJSONPaginedAction {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Sql request to execute. */
+ protected String sql;
+
+ /** Datas of the given table. */
+ protected Map<?, ?>[] datas;
+
+ public void setSql(String sql) {
+ this.sql = sql;
+ }
+
+ public Map<?, ?>[] getDatas() {
+ return datas;
+ }
+
+ @Override
+ public Integer getRows() {
+ return pager.getPageSize();
+ }
+
+ @Override
+ public Integer getPage() {
+ return pager.getPageNumber();
+ }
+
+ @Override
+ public Integer getTotal() {
+ return pager.getPageCount();
+ }
+
+ @Override
+ public Integer getRecords() {
+ return pager.getRecords();
+ }
+
+ @Override
+ public String execute() throws Exception {
+ ExportQueryService service = newService(ExportQueryService.class);
+ datas = service.executeSql(sql, pager);
+ return SUCCESS;
+ }
+}
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/GetExportQueryResult.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ManageExportQuery.java (from rev 211, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/export/ManageExportQuery.java)
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ManageExportQuery.java (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ManageExportQuery.java 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,125 @@
+/*
+ * #%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.actions.exportQuery;
+
+import com.opensymphony.xwork2.Preparable;
+import fr.ifremer.echobase.entities.ExportQuery;
+import fr.ifremer.echobase.entities.ExportQueryImpl;
+import fr.ifremer.echobase.services.ExportQueryService;
+import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * To manage {@link ExportQuery}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.1
+ */
+public class ManageExportQuery extends EchoBaseActionSupport implements Preparable {
+
+ private static final long serialVersionUID = 1L;
+
+ /** All available queries from database. */
+ protected Map<String, String> queries;
+
+ /** Selected query loaded from database if his id is not empty. */
+ protected ExportQuery query;
+
+ public ExportQuery getQuery() {
+ if (query == null) {
+ query = new ExportQueryImpl();
+ }
+ return query;
+ }
+
+ public Map<String, String> getQueries() {
+ return queries;
+ }
+
+ public Map<String, String> getTableNames() {
+ return queries;
+ }
+
+ public String saveQuery() throws Exception {
+
+ //TODO : do validation
+ ExportQueryService service = newService(ExportQueryService.class);
+
+ query = service.createOrUpdate(getQuery(),
+ getEchoBaseSession().getEchoBaseUser()
+ );
+ return SUCCESS;
+ }
+
+ public String cloneQuery() throws Exception {
+
+ //TODO : do validation
+ ExportQueryService service = newService(ExportQueryService.class);
+
+ getQuery().setTopiaId(null);
+ query = service.createOrUpdate(getQuery(),
+ getEchoBaseSession().getEchoBaseUser()
+ );
+ return SUCCESS;
+ }
+
+ public String deleteQuery() throws Exception {
+
+ //TODO : do validation
+ ExportQueryService service = newService(ExportQueryService.class);
+ service.delete(getQuery().getTopiaId());
+ query = null;
+ return SUCCESS;
+ }
+
+ @Override
+ public void prepare() throws Exception {
+ ExportQueryService service = newService(ExportQueryService.class);
+
+ Collection<ExportQuery> sqlQueries =
+ service.getEntities(ExportQuery.class);
+ queries = sortAndDecorate(sqlQueries, null);
+
+ if (sqlQueries.isEmpty()) {
+ // no query saved
+ addActionMessage(_("echobase.info.no.sqlQuery.saved"));
+ } else {
+
+ String selectedQueryId = getQuery().getTopiaId();
+
+ if (StringUtils.isEmpty(selectedQueryId)) {
+
+ // no query selected
+ addActionMessage(_("echobase.info.no.sqlQuery.selected"));
+ } else {
+
+ // load query from database
+ query = service.getExportQuery(selectedQueryId);
+ }
+ }
+ }
+}
\ No newline at end of file
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/exportQuery/ManageExportQuery.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/LaunchImport.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/LaunchImport.java 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importDb/LaunchImport.java 2011-12-26 19:47:00 UTC (rev 217)
@@ -34,6 +34,8 @@
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.framework.TopiaContextImplementor;
+import java.util.Date;
+
/**
* Start the import db.
*
@@ -71,7 +73,7 @@
actionContext = ActionContext.getContext();
} else {
- // having the action cotnext here means we laready came here,
+ // having the action context here means we already came here,
// now we need to propagate it
ActionContext.setContext(actionContext);
}
@@ -83,7 +85,9 @@
@Override
public String execute() throws Exception {
- // having the action cotnext here means we laready came here,
+ model.setStartTime(new Date());
+
+ // having the action context here means we already came here,
// now we need to propagate it
ActionContext.setContext(actionContext);
@@ -103,6 +107,7 @@
}
service.importDb(model, getEchoBaseSession().getEchoBaseUser());
+ model.setEndTime(new Date());
return SUCCESS;
} finally {
topiaContext.closeContext();
Modified: trunk/echobase-ui/src/main/resources/config/struts-export.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/config/struts-export.xml 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/resources/config/struts-export.xml 2011-12-26 19:47:00 UTC (rev 217)
@@ -31,76 +31,12 @@
<package name="export" extends="loggued" namespace="/export">
- <result-types>
- <result-type name="redirectExportSql"
- class="org.apache.struts2.dispatcher.ServletActionRedirectResult">
- <param name="actionName">exportSql</param>
- <param name="namespace">export</param>
- <param name="query.topiaId">${query.topiaId}</param>
- </result-type>
-
- </result-types>
-
- <!-- Display export sql main page -->
- <action name="exportSql" method="input"
- class="fr.ifremer.echobase.ui.actions.export.ManageExportQuery">
- <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
- <result name="input">/WEB-INF/jsp/export/exportSql.jsp</result>
- </action>
-
- <!-- Display the result of the sql query execution -->
- <action name="exportSqlResult"
- class="fr.ifremer.echobase.ui.actions.export.ExportSqlResult">
- <result>/WEB-INF/jsp/export/exportSqlResult.jsp</result>
- </action>
-
<!-- Display the create embedded application main page -->
<action name="createEmbeddedApplication"
class="fr.ifremer.echobase.ui.actions.export.CreateEmbeddedApplication">
<result>/WEB-INF/jsp/export/createEmbeddedApplication.jsp</result>
</action>
- <!-- Get result of the sql query execution -->
- <action name="getExportSqlResult"
- class="fr.ifremer.echobase.ui.actions.export.GetSqlResult">
- <result type="json"/>
- </action>
-
- <!-- Clone the sql query -->
- <action name="cloneExportQuery" method="cloneQuery"
- class="fr.ifremer.echobase.ui.actions.export.ManageExportQuery">
- <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
- <result name="input">/WEB-INF/jsp/export/exportSql.jsp</result>
- <result type="redirectExportSql"/>
- </action>
-
- <!-- Save the sql query -->
- <action name="saveExportQuery" method="saveQuery"
- class="fr.ifremer.echobase.ui.actions.export.ManageExportQuery">
- <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
- <result name="input">/WEB-INF/jsp/export/exportSql.jsp</result>
- <result type="redirectExportSql"/>
- </action>
-
- <!-- Delete the sql query -->
- <action name="deleteExportQuery" method="deleteQuery"
- class="fr.ifremer.echobase.ui.actions.export.ManageExportQuery">
- <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
- <result name="input">/WEB-INF/jsp/export/exportSql.jsp</result>
- <result type="redirectExportSql"/>
- </action>
-
- <!-- Download the sql query csv file -->
- <action name="downloadExportSqlResult"
- class="fr.ifremer.echobase.ui.actions.export.DownloadExportSqlResult">
- <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
- <result type="stream">
- <param name="contentType">${contentType}</param>
- <param name="contentLength">${contentLength}</param>
- <param name="contentDisposition">filename="${fileName}"</param>
- </result>
- </action>
-
<!-- Download the embedded application zip file -->
<action name="downloadEmbeddedApplication"
class="fr.ifremer.echobase.ui.actions.export.DownloadEmbeddedApplication">
Added: trunk/echobase-ui/src/main/resources/config/struts-exportDb.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/config/struts-exportDb.xml (rev 0)
+++ trunk/echobase-ui/src/main/resources/config/struts-exportDb.xml 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ #%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%
+ -->
+<!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+ "http://struts.apache.org/dtds/struts-2.1.7.dtd">
+
+<struts>
+
+ <package name="exportDb" extends="loggued" namespace="/exportDb">
+
+ <!-- Configure export -->
+ <action name="configureExport"
+ class="fr.ifremer.echobase.ui.actions.exportDb.Configure">
+ <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
+ <result name="input">/WEB-INF/jsp/exportDb/configure.jsp</result>
+ <result type="redirectAction">
+ <param name="namespace">/exportDb</param>
+ <param name="actionName">doExport</param>
+ </result>
+ </action>
+
+ <!-- Starts export -->
+ <action name="doExport"
+ class="fr.ifremer.echobase.ui.actions.exportDb.LaunchExport"
+ method="execute">
+ <interceptor-ref name="basicStackLoggued"/>
+ <interceptor-ref name="execAndWait"/>
+ <result name="wait">/WEB-INF/jsp/exportDb/progress.jsp</result>
+ <result>/WEB-INF/jsp/exportDb/result.jsp</result>
+ </action>
+
+ <!-- Download the export -->
+ <action name="downloadExport"
+ class="fr.ifremer.echobase.ui.actions.exportDb.DownloadExport">
+ <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
+ <result type="stream">
+ <param name="contentType">${contentType}</param>
+ <param name="contentLength">${contentLength}</param>
+ <param name="contentDisposition">filename="${fileName}"</param>
+ </result>
+ </action>
+
+ </package>
+
+</struts>
+
Property changes on: trunk/echobase-ui/src/main/resources/config/struts-exportDb.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-ui/src/main/resources/config/struts-exportQuery.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/config/struts-exportQuery.xml (rev 0)
+++ trunk/echobase-ui/src/main/resources/config/struts-exportQuery.xml 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ #%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%
+ -->
+
+<!DOCTYPE struts PUBLIC
+ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+ "http://struts.apache.org/dtds/struts-2.1.7.dtd">
+
+<struts>
+
+ <package name="exportQuery" extends="loggued" namespace="/exportQuery">
+
+ <result-types>
+ <result-type name="redirectExportQuery"
+ class="org.apache.struts2.dispatcher.ServletActionRedirectResult">
+ <param name="actionName">manageExportQuery</param>
+ <param name="namespace">export</param>
+ <param name="query.topiaId">${query.topiaId}</param>
+ </result-type>
+
+ </result-types>
+
+ <!-- Display export query main page -->
+ <action name="manageExportQuery" method="input"
+ class="fr.ifremer.echobase.ui.actions.exportQuery.ManageExportQuery">
+ <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
+ <result name="input">/WEB-INF/jsp/exportQuery/exportQuery.jsp</result>
+ </action>
+
+ <!-- Display the result of the export query execution -->
+ <action name="exportQueryResult"
+ class="fr.ifremer.echobase.ui.actions.exportQuery.ExportQueryResult">
+ <result>/WEB-INF/jsp/exportQuery/exportQueryResult.jsp</result>
+ </action>
+
+ <!-- Get result of the export query execution -->
+ <action name="getExportQueryResult"
+ class="fr.ifremer.echobase.ui.actions.exportQuery.GetExportQueryResult">
+ <result type="json"/>
+ </action>
+
+ <!-- Clone the export query -->
+ <action name="cloneExportQuery" method="cloneQuery"
+ class="fr.ifremer.echobase.ui.actions.exportQuery.ManageExportQuery">
+ <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
+ <result name="input">/WEB-INF/jsp/exportQuery/exportQuery.jsp</result>
+ <result type="redirectExportQuery"/>
+ </action>
+
+ <!-- Save the export query -->
+ <action name="saveExportQuery" method="saveQuery"
+ class="fr.ifremer.echobase.ui.actions.exportQuery.ManageExportQuery">
+ <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
+ <result name="input">/WEB-INF/jsp/exportQuery/exportQuery.jsp</result>
+ <result type="redirectExportQuery"/>
+ </action>
+
+ <!-- Delete the export query -->
+ <action name="deleteExportQuery" method="deleteQuery"
+ class="fr.ifremer.echobase.ui.actions.exportQuery.ManageExportQuery">
+ <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
+ <result name="input">/WEB-INF/jsp/exportQuery/exportQuery.jsp</result>
+ <result type="redirectExportQuery"/>
+ </action>
+
+ <!-- Download the sql query csv file -->
+ <action name="downloadExportQueryResult"
+ class="fr.ifremer.echobase.ui.actions.exportQuery.DownloadExportQueryResult">
+ <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
+ <result type="stream">
+ <param name="contentType">${contentType}</param>
+ <param name="contentLength">${contentLength}</param>
+ <param name="contentDisposition">filename="${fileName}"</param>
+ </result>
+ </action>
+
+ </package>
+
+</struts>
+
Property changes on: trunk/echobase-ui/src/main/resources/config/struts-exportQuery.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties
===================================================================
--- trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties 2011-12-26 19:47:00 UTC (rev 217)
@@ -5,6 +5,8 @@
echobase.action.createEmbeddedApplication=Créer l'application
echobase.action.delete=Suppression
echobase.action.deleteSqlQuery=Supprimer la requête
+echobase.action.downloadExportDbFile=Télécharger le fichier d'export de la base complête
+echobase.action.export=Exporter
echobase.action.exportSqlData=Exporter les données
echobase.action.exportTable=Exporter
echobase.action.import=Importer
@@ -50,6 +52,8 @@
echobase.error.login.password.requiredstring=Le mot de passe est obligatoire
echobase.error.login.unknown=Utilisateur inconnu
echobase.error.login.wrongLogin=Le login est déjà utilisé
+echobase.error.no.dbExport.configurationFound=
+echobase.error.no.dbExport.exportFileFound=
echobase.error.required.email=L'email est obligatoire
echobase.error.required.password=Le mot de passe est obligatoire
echobase.error.warlocation.notFound=L'application n'a pas été trouvé à l'emplacement suivant %s
@@ -63,6 +67,7 @@
echobase.label.createIfNotFound=Créer les entités non trouvées en base
echobase.label.embeddedApplicationFileName=Nom de l'archive à télécharger
echobase.label.embeddedWarFileName=Nom du war à utiliser
+echobase.label.exportDbFileName=Nom du fichier d'export
echobase.label.exportFileName=Nom du fichier d'export
echobase.label.import.access=Base access
echobase.label.import.accoustique=Fichier accoustique
@@ -86,6 +91,7 @@
echobase.label.voyageToSelect=Voyage à exporter
echobase.legend.dbeditor.edit=Edition de '%s'
echobase.legend.embeddedApplication.configuration=Configuration de l'application embarquée
+echobase.legend.exportDb.configuration.files=Configuration de l'export
echobase.legend.importData.configuration.files=Choix des fichiers d'import
echobase.legend.importData.configuration.mission=Configurer la mission
echobase.legend.importData.configuration.mission.resume=Résumé de la mission à utiliser
@@ -97,6 +103,7 @@
echobase.menu.createEmbeddedApplication=Créer une application embarquée
echobase.menu.dbeditor=Modifier les données
echobase.menu.export=Exporter des données
+echobase.menu.exportDb=Exporter une base complête
echobase.menu.importData=Importer des données
echobase.menu.importDb=Importer une base complête
echobase.menu.logs=Visualiser les modifications
@@ -105,6 +112,7 @@
echobase.message.modified.property=Propriété '%s', ancienne valeur \: %s, nouvelle valeur \: %s
echobase.message.no.row.selected=Aucune donnée sélectionnée
echobase.message.noEntrySelection=Aucune entrée sélectionnée
+echobase.message.warnExportInProgress=Merci de ne pas fermer la fenêtre pour pouvoir accéder aux résultats de l'export.
echobase.message.warnImportInProgress=Merci de ne pas fermer la fenêtre pour pouvoir accéder aux résultats de l'import.
echobase.title.admin.user.create=Création d'un utilisateur
echobase.title.admin.user.delete=Suppression d'un utilisateur
@@ -115,6 +123,9 @@
echobase.title.dbEditor=Modification de la base
echobase.title.entityModificationLogs=Journal des modifications
echobase.title.export=Export
+echobase.title.exportDb=Export complet de la base
+echobase.title.exportDbProgress=Export complêt de la base de données en cours
+echobase.title.exportDbResult=Résultat de l'export complêt de la base de données
echobase.title.exportTable=Exporter une table
echobase.title.importData=Import de données
echobase.title.importData.configuration=Configuration d'un import de données
Modified: trunk/echobase-ui/src/main/resources/struts.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/struts.xml 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/resources/struts.xml 2011-12-26 19:47:00 UTC (rev 217)
@@ -132,8 +132,11 @@
<include file="config/struts-dbeditor.xml"/>
<include file="config/struts-user.xml"/>
<include file="config/struts-importData.xml"/>
- <include file="config/struts-importDb.xml"/>
<include file="config/struts-export.xml"/>
+ <include file="config/struts-exportQuery.xml"/>
+ <include file="config/struts-importDb.xml"/>
+ <include file="config/struts-exportDb.xml"/>
+
</struts>
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/decorators.xml
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/decorators.xml 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/decorators.xml 2011-12-26 19:47:00 UTC (rev 217)
@@ -31,7 +31,7 @@
<pattern>/index*</pattern>
<pattern>/dbeditor/getForeignEntities*</pattern>
<pattern>/dbeditor/doExport*</pattern>
- <pattern>/export/exportSqlResult*</pattern>
+ <pattern>/exportQuery/exportQueryResult*</pattern>
</excludes>
<decorator name="layout-default" page="layout-default.jsp">
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/includes/header.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/includes/header.jsp 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/includes/header.jsp 2011-12-26 19:47:00 UTC (rev 217)
@@ -59,13 +59,17 @@
<s:a action="configureImport" namespace="/importDb" method="input">
<s:text name="echobase.menu.importDb"/></s:a>
</li>
+ <li>
+ <s:a action="configureExport" namespace="/exportDb" method="input">
+ <s:text name="echobase.menu.exportDb"/></s:a>
+ </li>
</s:if>
<li>
<s:a action="configureMission" namespace="/importData" method="input">
<s:text name="echobase.menu.importData"/></s:a>
</li>
<li>
- <s:a action="exportSql" namespace="/export">
+ <s:a action="manageExportQuery" namespace="/exportQuery">
<s:text name="echobase.menu.export"/>
</s:a>
</li>
Deleted: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportSql.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportSql.jsp 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportSql.jsp 2011-12-26 19:47:00 UTC (rev 217)
@@ -1,136 +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%
- --%>
-<%@page contentType="text/html" pageEncoding="UTF-8" %>
-<%@ taglib prefix="s" uri="/struts-tags" %>
-<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
-
-<s:url id="reloadUrl" action='exportSql' namespace='/export'/>
-<s:url id="exportSqlResultUrl" action="exportSqlResult" namespace="/export"/>
-<s:set var="noError" value="!hasErrors()"/>
-<script type="text/javascript">
-
- function reloadQuery() {
- var queryId = $('[name="query.topiaId"]').val();
- var url = "${reloadUrl}?" + $.param({ 'query.topiaId':queryId});
- window.location = url;
- return false;
- }
-
- function loadGridData() {
- // get sql query
- var sqlQuery = "${exportSqlResultUrl}?" +
- $.param({ sql :$('[name="query.sqlQuery"]').val()});
-
- $.ajax(sqlQuery, {
- success: function(data, textStatus, jqXHR) {
- $('#resultGrid').html(data);
- }
- });
- return false;
- }
-
- jQuery(document).ready(function () {
-
- $('[name="query.topiaId"]').change(function(event) {
- var url = "${reloadUrl}?" + $.param({ 'query.topiaId':this.value});
- window.location = url;
- });
-
- var queryId = $('[name="query.topiaId"]').val();
- if (queryId && ${noError}) {
- // auto launch query
- loadGridData();
- }
-
- });
-
-
-</script>
-
-<title><s:text name="echobase.title.export"/></title>
-
-<s:set var="queryExists" value="query.topiaId != null && query.topiaId != ''"/>
-
-<s:form id="exportQueryForm" namespace="/export">
-
- <s:select key="query.topiaId" label="%{getText('echobase.label.sqlQueries')}"
- list="queries" headerKey="" headerValue=""/>
-
- <br/>
-
- <fieldset>
- <legend><s:text name="echobase.legend.sqlQuery.configuration"/></legend>
-
- <s:textarea key="query.name" required="true" cols="160" rows="1"
- label="%{getText('echobase.label.query.name')}"/>
-
- <s:textarea key="query.description" required="true" cols="160" rows="2"
- label="%{getText('echobase.label.query.description')}"/>
-
- <s:textarea key="query.sqlQuery" required="true" cols="160" rows="4"
- label="%{getText('echobase.label.query.sql')}"/>
-
- <s:if test="queryExists">
-
- <s:label value="%{query.lastModifiedDate}" readonly="true"
- label="%{getText('echobase.common.lastModifiedDate')}"/>
-
- <s:label value="%{query.lastModifiedUser}" readonly="true"
- label="%{getText('echobase.common.lastModifiedUser')}"/>
-
- </s:if>
-
-
- <ul class="toolbar floatRight">
- <s:if test="queryExists">
- <li>
- <s:submit onclick="return reloadQuery();" theme="simple"
- key="echobase.action.reloadSqlQuery"/>
- </li>
- <li>
- <s:submit action="cloneExportQuery" theme="simple"
- key="echobase.action.cloneSqlQuery"/>
- </li>
- <li>
- <s:submit action="deleteExportQuery" theme="simple"
- key="echobase.action.deleteSqlQuery"/>
- </li>
- </s:if>
- <li>
- <s:submit action="saveExportQuery" theme="simple"
- key="echobase.action.saveSqlQuery"/>
- </li>
- <li>
- <s:submit key="echobase.action.applySqlQuery" theme="simple"
- onclick="return loadGridData();"/>
- </li>
- </ul>
- </fieldset>
-</s:form>
-
-<br/>
-
-<div id="resultGrid" class="cleanBoth"></div>
-
-
Deleted: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportSqlResult.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportSqlResult.jsp 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportSqlResult.jsp 2011-12-26 19:47:00 UTC (rev 217)
@@ -1,72 +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%
- --%>
-<%@page contentType="text/html" pageEncoding="UTF-8" %>
-<%@ taglib prefix="s" uri="/struts-tags" %>
-<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
-<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags" %>
-
-<s:if test="hasActionErrors()">
- <div class="info_error">
- <s:actionerror/>
- </div>
-</s:if>
-<s:else>
- <s:url id="loadUrl" action="getExportSqlResult" namespace="/export"
- escapeAmp="false">
- <s:param name="sql" value="%{sql}"/>
- </s:url>
-
- <s:form action="downloadExportSqlResult" namespace="/export">
-
- <fieldset>
- <legend><s:text name="echobase.legend.sqlQuery.result"/></legend>
-
- <s:hidden key="sql" label=""/>
- <s:textfield key="fileName" required="true" size="100"
- label="%{getText('echobase.label.exportFileName')}"/>
- <s:submit value="%{getText('echobase.action.exportSqlData')}" align="left"/>
- <br/>
- <sjg:grid id="rows" caption="%{getText('echobase.header.request.result')}"
- dataType="json" href="%{loadUrl}" gridModel="datas"
- pager="true" pagerButtons="true" pagerInput="true"
- navigator="true" autowidth="true" rownumbers="false"
- navigatorEdit="false" navigatorDelete="false"
- navigatorSearch="false" navigatorRefresh="false"
- navigatorAdd="false" rowList="10,15,20,50" rowNum="10"
- viewrecords="true">
-
- <s:iterator value="columnNames" var="name" status="status">
-
- <sjg:gridColumn name="%{#name}" title="%{#name}" sortable="false"/>
-
- </s:iterator>
-
- </sjg:grid>
- </fieldset>
- </s:form>
-</s:else>
-
-
-
-
Added: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/configure.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/configure.jsp (rev 0)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/configure.jsp 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,47 @@
+<%--
+ #%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%
+ --%>
+<%@page contentType="text/html" pageEncoding="UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<title><s:text name="echobase.title.exportDb"/></title>
+
+<s:form namespace="/exportDb" method="POST">
+
+ <fieldset>
+ <legend>
+ <s:text name="echobase.legend.exportDb.configuration.files"/>
+ </legend>
+
+ <s:textfield key="model.fileName" required="true" size="100"
+ label="%{getText('echobase.label.exportDbFileName')} (*)"/>
+
+ </fieldset>
+ <br/>
+ <s:submit action="configureExport"
+ value='%{getText("echobase.action.export")}'/>
+
+ <div>(*) Il s'agit du nom de l'archive, l'extension <strong>.zip</strong>
+ sera automatiquement rajoutée.</div>
+
+</s:form>
\ No newline at end of file
Property changes on: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/configure.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/progress.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/progress.jsp (rev 0)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/progress.jsp 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,40 @@
+<%--
+ #%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%
+ --%>
+<%@page contentType="text/html" pageEncoding="UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
+
+<s:url id="url" action="doExport" namespace="/exportDb"/>
+<meta http-equiv="refresh" content="5;url=${url}"/>
+
+<title><s:text name="echobase.title.exportDbProgress"/></title>
+
+<%-- TODO letellier 20111104 : Add warn icon --%>
+<p><s:text name="echobase.message.warnExportInProgress"/></p>
+
+<br/>
+
+<div>
+ <sj:progressbar value="%{model.progression}"/>
+</div>
\ No newline at end of file
Property changes on: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/progress.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/result.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/result.jsp (rev 0)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/result.jsp 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,39 @@
+<%--
+ #%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%
+ --%>
+<%@page contentType="text/html" pageEncoding="UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+
+<title><s:text name="echobase.title.exportDbResult"/></title>
+
+<div>
+ L'export de la base complête a réussi en <s:property value="model.actionTime"/>.
+ Vous pouvez désormais télécharger l'archive le contenant.
+</div>
+
+<br/>
+
+<s:a namespace="/exportDb" action="downloadExport">
+ <s:text name="echobase.action.downloadExportDbFile"/>
+</s:a>
+
Property changes on: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportDb/result.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportQuery/exportQuery.jsp (from rev 211, trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportSql.jsp)
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportQuery/exportQuery.jsp (rev 0)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportQuery/exportQuery.jsp 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,136 @@
+<%--
+ #%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%
+ --%>
+<%@page contentType="text/html" pageEncoding="UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
+
+<s:url id="reloadUrl" action='manageExportQuery' namespace='/exportQuery'/>
+<s:url id="exportSqlResultUrl" action="exportQueryResult" namespace="/exportQuery"/>
+<s:set var="noError" value="!hasErrors()"/>
+<script type="text/javascript">
+
+ function reloadQuery() {
+ var queryId = $('[name="query.topiaId"]').val();
+ var url = "${reloadUrl}?" + $.param({ 'query.topiaId':queryId});
+ window.location = url;
+ return false;
+ }
+
+ function loadGridData() {
+ // get sql query
+ var sqlQuery = "${exportSqlResultUrl}?" +
+ $.param({ sql :$('[name="query.sqlQuery"]').val()});
+
+ $.ajax(sqlQuery, {
+ success: function(data, textStatus, jqXHR) {
+ $('#resultGrid').html(data);
+ }
+ });
+ return false;
+ }
+
+ jQuery(document).ready(function () {
+
+ $('[name="query.topiaId"]').change(function(event) {
+ var url = "${reloadUrl}?" + $.param({ 'query.topiaId':this.value});
+ window.location = url;
+ });
+
+ var queryId = $('[name="query.topiaId"]').val();
+ if (queryId && ${noError}) {
+ // auto launch query
+ loadGridData();
+ }
+
+ });
+
+
+</script>
+
+<title><s:text name="echobase.title.export"/></title>
+
+<s:set var="queryExists" value="query.topiaId != null && query.topiaId != ''"/>
+
+<s:form id="exportQueryForm" namespace="/export">
+
+ <s:select key="query.topiaId" label="%{getText('echobase.label.sqlQueries')}"
+ list="queries" headerKey="" headerValue=""/>
+
+ <br/>
+
+ <fieldset>
+ <legend><s:text name="echobase.legend.sqlQuery.configuration"/></legend>
+
+ <s:textarea key="query.name" required="true" cols="160" rows="1"
+ label="%{getText('echobase.label.query.name')}"/>
+
+ <s:textarea key="query.description" required="true" cols="160" rows="2"
+ label="%{getText('echobase.label.query.description')}"/>
+
+ <s:textarea key="query.sqlQuery" required="true" cols="160" rows="4"
+ label="%{getText('echobase.label.query.sql')}"/>
+
+ <s:if test="queryExists">
+
+ <s:label value="%{query.lastModifiedDate}" readonly="true"
+ label="%{getText('echobase.common.lastModifiedDate')}"/>
+
+ <s:label value="%{query.lastModifiedUser}" readonly="true"
+ label="%{getText('echobase.common.lastModifiedUser')}"/>
+
+ </s:if>
+
+
+ <ul class="toolbar floatRight">
+ <s:if test="queryExists">
+ <li>
+ <s:submit onclick="return reloadQuery();" theme="simple"
+ key="echobase.action.reloadSqlQuery"/>
+ </li>
+ <li>
+ <s:submit action="cloneExportQuery" theme="simple"
+ key="echobase.action.cloneSqlQuery"/>
+ </li>
+ <li>
+ <s:submit action="deleteExportQuery" theme="simple"
+ key="echobase.action.deleteSqlQuery"/>
+ </li>
+ </s:if>
+ <li>
+ <s:submit action="saveExportQuery" theme="simple"
+ key="echobase.action.saveSqlQuery"/>
+ </li>
+ <li>
+ <s:submit key="echobase.action.applySqlQuery" theme="simple"
+ onclick="return loadGridData();"/>
+ </li>
+ </ul>
+ </fieldset>
+</s:form>
+
+<br/>
+
+<div id="resultGrid" class="cleanBoth"></div>
+
+
Property changes on: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportQuery/exportQuery.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportQuery/exportQueryResult.jsp (from rev 211, trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/export/exportSqlResult.jsp)
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportQuery/exportQueryResult.jsp (rev 0)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportQuery/exportQueryResult.jsp 2011-12-26 19:47:00 UTC (rev 217)
@@ -0,0 +1,72 @@
+<%--
+ #%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%
+ --%>
+<%@page contentType="text/html" pageEncoding="UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
+<%@ taglib prefix="sjg" uri="/struts-jquery-grid-tags" %>
+
+<s:if test="hasActionErrors()">
+ <div class="info_error">
+ <s:actionerror/>
+ </div>
+</s:if>
+<s:else>
+ <s:url id="loadUrl" action="getExportQueryResult" namespace="/exportQuery"
+ escapeAmp="false">
+ <s:param name="sql" value="%{sql}"/>
+ </s:url>
+
+ <s:form action="downloadExportQueryResult" namespace="/exportQuery">
+
+ <fieldset>
+ <legend><s:text name="echobase.legend.sqlQuery.result"/></legend>
+
+ <s:hidden key="sql" label=""/>
+ <s:textfield key="fileName" required="true" size="100"
+ label="%{getText('echobase.label.exportFileName')}"/>
+ <s:submit value="%{getText('echobase.action.exportSqlData')}" align="left"/>
+ <br/>
+ <sjg:grid id="rows" caption="%{getText('echobase.header.request.result')}"
+ dataType="json" href="%{loadUrl}" gridModel="datas"
+ pager="true" pagerButtons="true" pagerInput="true"
+ navigator="true" autowidth="true" rownumbers="false"
+ navigatorEdit="false" navigatorDelete="false"
+ navigatorSearch="false" navigatorRefresh="false"
+ navigatorAdd="false" rowList="10,15,20,50" rowNum="10"
+ viewrecords="true">
+
+ <s:iterator value="columnNames" var="name" status="status">
+
+ <sjg:gridColumn name="%{#name}" title="%{#name}" sortable="false"/>
+
+ </s:iterator>
+
+ </sjg:grid>
+ </fieldset>
+ </s:form>
+</s:else>
+
+
+
+
Property changes on: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/exportQuery/exportQueryResult.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importDb/progress.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importDb/progress.jsp 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importDb/progress.jsp 2011-12-26 19:47:00 UTC (rev 217)
@@ -26,7 +26,7 @@
<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
<s:url id="url" action="doImport" namespace="/importDb"/>
-<meta http-equiv="refresh" content="5;url=${url};"/>
+<meta http-equiv="refresh" content="5;url=${url}"/>
<title><s:text name="echobase.title.importDbProgress"/></title>
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importDb/result.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importDb/result.jsp 2011-12-26 19:07:07 UTC (rev 216)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importDb/result.jsp 2011-12-26 19:47:00 UTC (rev 217)
@@ -26,18 +26,14 @@
<title><s:text name="echobase.title.importDbResult"/></title>
-<fieldset>
- <legend>
- <s:text name="echobase.legend.importFileResult">
- <s:param><strong><s:property
- value="%{model.input.label}"/></strong></s:param>
- </s:text>
- </legend>
+<div>
+ L'import de la base complête a réussi en <s:property
+ value="model.actionTime"/>.
+</div>
+<div>
+ EchoBase possède désormais un référentiel et les campagnes contenues dans
+ la sauvegarde importée.
+</div>
- <s:label value="%{model.input.fileName}"
- label="%{getText('echobase.label.importFile')}"/>
-
-</fieldset>
-
<div>TODO</div>
1
0
r216 - in trunk/echobase-services/src/main/java/fr/ifremer/echobase/services: . models
by tchemit@users.forge.codelutin.com 26 Dec '11
by tchemit@users.forge.codelutin.com 26 Dec '11
26 Dec '11
Author: tchemit
Date: 2011-12-26 20:07:07 +0100 (Mon, 26 Dec 2011)
New Revision: 216
Url: http://forge.codelutin.com/repositories/revision/echobase/216
Log:
- rename ExportSql to Exportquery
- implements DbExportService
- introduce a nive abstract long action configuration class
Added:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/AbstractEchobaseActionConfiguration.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbConfiguration.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportQueryService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportQueryCsvModel.java
Removed:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportSqlCsvModel.java
Modified:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataConfiguration.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbConfiguration.java
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/AbstractEchobaseActionConfiguration.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/AbstractEchobaseActionConfiguration.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/AbstractEchobaseActionConfiguration.java 2011-12-26 19:07:07 UTC (rev 216)
@@ -0,0 +1,97 @@
+/*
+ * #%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.nuiton.util.StringUtil;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * Abstract long action configuration.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public abstract class AbstractEchobaseActionConfiguration implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private int nbSteps;
+
+ private float stepIncrement;
+
+ private float progression;
+
+ private Date startTime;
+ private Date endTime;
+
+ public final int getNbSteps() {
+ return nbSteps;
+ }
+
+ public final float getProgression() {
+ return progression;
+ }
+
+ public final void setProgression(float progression) {
+ this.progression = progression;
+ }
+
+ public final void incrementsProgression() {
+ setProgression(progression + stepIncrement);
+ }
+
+ public final void setNbSteps(int nbSteps) {
+
+ this.nbSteps = nbSteps;
+ stepIncrement = 100f / nbSteps;
+ }
+
+ public final Date getStartTime() {
+ return startTime;
+ }
+
+ public final void setStartTime(Date startTime) {
+ this.startTime = startTime;
+ }
+
+ public final Date getEndTime() {
+ return endTime;
+ }
+
+ public final void setEndTime(Date endTime) {
+ this.endTime = endTime;
+ }
+
+ public String getActionTime() {
+ Date sTime = getStartTime();
+ Date eTime = getEndTime();
+ return StringUtil.convertTime(eTime.getTime() - sTime.getTime());
+ }
+
+ public void destroy() throws IOException {
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/AbstractEchobaseActionConfiguration.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/DbExportService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java 2011-12-26 10:13:15 UTC (rev 215)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java 2011-12-26 19:07:07 UTC (rev 216)
@@ -24,16 +24,20 @@
package fr.ifremer.echobase.services;
import fr.ifremer.echobase.EchoBaseIOUtil;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.EntitiesUtil;
import fr.ifremer.echobase.entities.meta.AssociationMeta;
import fr.ifremer.echobase.entities.meta.MetaFilenameAware;
import fr.ifremer.echobase.entities.meta.TableMeta;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.nuiton.util.FileUtil;
import org.nuiton.util.TimeLog;
import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
/**
* Service to import / export a complete db.
@@ -52,24 +56,43 @@
/**
* Export the complete db into csv files stored in a zip archive file.
*
- * @param fileName file name of the zip to create
+ * @param model file name of the zip to create
* @return the zip archive file
+ * @throws IOException if could not create or write files.
*/
- public File exportDb(String fileName) {
- File tempDirectory = new File(FileUtils.getTempDirectory(),
- "echobase-exportDb_" + System.nanoTime());
- tempDirectory.deleteOnExit();
+ public File 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);
+
MetaFilenameAware[] entries = EntitiesUtil.getEntries(getDbMeta());
+
+ model.setNbSteps(entries.length);
+
+ List<EchoBaseEntityEnum> referenceTypes =
+ Arrays.asList(EntitiesUtil.getReferenceTypes());
for (MetaFilenameAware entry : entries) {
+ model.incrementsProgression();
+
+// if (!referenceTypes.contains(entry.getSource())) {
+// //TODO remove this when tests are ok.
+// continue;
+// }
File entryFile = new File(dir, entry.getFilename());
-
if (entry instanceof AssociationMeta) {
AssociationMeta associationMeta = (AssociationMeta) entry;
exportService.exportDatas(associationMeta, entryFile);
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2011-12-26 10:13:15 UTC (rev 215)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2011-12-26 19:07:07 UTC (rev 216)
@@ -203,11 +203,11 @@
UserService.DEFAULT_ADMIN_EMAIL);
// get export query service
- ExportSqlService exportSqlService =
- getService(ExportSqlService.class);
+ ExportQueryService exportQueryService =
+ getService(ExportQueryService.class);
// get all export queries from application
- List<ExportQuery> queries = exportSqlService.getEntities(ExportQuery.class);
+ List<ExportQuery> queries = exportQueryService.getEntities(ExportQuery.class);
// remove link to application user
for (ExportQuery query : queries) {
@@ -218,15 +218,15 @@
getTransaction().replicateEntities(topiaContext, queries);
// create export sql service from h2 db
- exportSqlService =
- newServiceContext.newService(ExportSqlService.class);
+ exportQueryService =
+ newServiceContext.newService(ExportQueryService.class);
// get all queries from h2 db
- queries = exportSqlService.getEntities(ExportQuery.class);
+ queries = exportQueryService.getEntities(ExportQuery.class);
// attach them to default created admin user in the db
for (ExportQuery query : queries) {
- exportSqlService.createOrUpdate(query, admin);
+ exportQueryService.createOrUpdate(query, admin);
}
// replicate referentiel to new h2 db
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbConfiguration.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbConfiguration.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportDbConfiguration.java 2011-12-26 19:07:07 UTC (rev 216)
@@ -0,0 +1,78 @@
+/*
+ * #%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(a)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;
+
+ 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;
+ }
+
+ @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/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/ExportQueryService.java (from rev 211, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java)
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportQueryService.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportQueryService.java 2011-12-26 19:07:07 UTC (rev 216)
@@ -0,0 +1,253 @@
+/*
+ * #%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.EchoBaseTechnicalException;
+import fr.ifremer.echobase.entities.EchoBaseUser;
+import fr.ifremer.echobase.entities.ExportQuery;
+import fr.ifremer.echobase.entities.ExportQueryImpl;
+import fr.ifremer.echobase.services.models.ExportQueryCsvModel;
+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.csv.Export;
+
+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(a)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 = new ExportQueryImpl();
+ 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) {
+ try {
+ TopiaDAO<ExportQuery> dao = getDAO(ExportQuery.class);
+ ExportQuery entityToSave;
+
+ // No id, creating new one entity
+ String id = exportQuery.getTopiaId();
+ if (StringUtils.isEmpty(id)) {
+ entityToSave = dao.create();
+ } else {
+ entityToSave = dao.findByTopiaId(id);
+ }
+
+ entityToSave.setName(exportQuery.getName());
+ entityToSave.setDescription(exportQuery.getDescription());
+ entityToSave.setSqlQuery(exportQuery.getSqlQuery());
+ entityToSave.setLastModifiedDate(newDate());
+ entityToSave.setLastModifiedUser(user.getEmail());
+
+ 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 Map<String, Object>[] executeSql(String sql, Pager 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.startExportAsString();
+ return content;
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException("Could not export sql", eee);
+ }
+ }
+
+ private static class GenericSQLQuery extends TopiaSQLQuery<Map<String, Object>> {
+
+ protected String[] columnNames;
+
+ private final String sql;
+
+ private final Pager pager;
+
+ public GenericSQLQuery(String sql, Pager 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 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);
+ pager.computeIndexesAndPageCount();
+ }
+ }
+
+ @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.getStartIndex() ||
+ rowNumber >= pager.getEndIndex()) {
+
+ // 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/ExportQueryService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java 2011-12-26 10:13:15 UTC (rev 215)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java 2011-12-26 19:07:07 UTC (rev 216)
@@ -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 fr.ifremer.echobase.EchoBaseTechnicalException;
-import fr.ifremer.echobase.entities.EchoBaseUser;
-import fr.ifremer.echobase.entities.ExportQuery;
-import fr.ifremer.echobase.services.models.ExportSqlCsvModel;
-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.csv.Export;
-
-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(a)codelutin.com>
- * @since 0.1
- */
-public class ExportSqlService extends EchoBaseServiceSupport {
-
- /** Logger. */
- private static final Log log = LogFactory.getLog(ExportSqlService.class);
-
- public ExportQuery createOrUpdate(ExportQuery exportQuery,
- EchoBaseUser user) {
- try {
- TopiaDAO<ExportQuery> dao = getDAO(ExportQuery.class);
- ExportQuery entityToSave;
-
- // No id, creating new one entity
- String id = exportQuery.getTopiaId();
- if (StringUtils.isEmpty(id)) {
- entityToSave = dao.create();
- } else {
- entityToSave = dao.findByTopiaId(id);
- }
-
- entityToSave.setName(exportQuery.getName());
- entityToSave.setDescription(exportQuery.getDescription());
- entityToSave.setSqlQuery(exportQuery.getSqlQuery());
- entityToSave.setLastModifiedDate(newDate());
- entityToSave.setLastModifiedUser(user.getEmail());
-
- 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 Map<String, Object>[] executeSql(String sql, Pager 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, 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();
- ExportSqlCsvModel csvModel = sqlQuery.generateCsvModel(csvSeparator);
- Export<Map<String, Object>> exporter = Export.newExport(csvModel, rows);
- try {
- String content = exporter.startExportAsString();
- return content;
- } catch (Exception eee) {
- throw new EchoBaseTechnicalException("Could not export sql", eee);
- }
- }
-
- private static class GenericSQLQuery extends TopiaSQLQuery<Map<String, Object>> {
-
- protected String[] columnNames;
-
- private final String sql;
-
- private final Pager pager;
-
- public GenericSQLQuery(String sql, Pager pager) {
- this.sql = sql;
- this.pager = pager;
- }
-
- public String[] getColumnNames() {
- return columnNames;
- }
-
- public ExportSqlCsvModel generateCsvModel(char charSeparator) {
- ExportSqlCsvModel model = new ExportSqlCsvModel(
- 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 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);
- pager.computeIndexesAndPageCount();
- }
- }
-
- @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.getStartIndex() ||
- rowNumber >= pager.getEndIndex()) {
-
- // 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;
- }
-
- }
-}
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataConfiguration.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataConfiguration.java 2011-12-26 10:13:15 UTC (rev 215)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataConfiguration.java 2011-12-26 19:07:07 UTC (rev 216)
@@ -29,7 +29,6 @@
import java.io.File;
import java.io.IOException;
-import java.io.Serializable;
import java.util.Locale;
import static org.nuiton.i18n.I18n.l_;
@@ -40,7 +39,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.2
*/
-public class ImportDataConfiguration implements Serializable {
+public class ImportDataConfiguration extends AbstractEchobaseActionConfiguration {
private static final long serialVersionUID = 1L;
@@ -61,12 +60,6 @@
protected InputFile typeEchoSpeciesFile;
- protected int nbSteps;
-
- private float stepIncrement;
-
- protected float progression;
-
public ImportDataConfiguration(Locale locale) {
acousticFile = InputFile.newFile(
l_(locale, "echobase.common.acousticImport"));
@@ -112,14 +105,6 @@
return typeEchoSpeciesFile;
}
- public int getNbSteps() {
- return nbSteps;
- }
-
- public float getProgression() {
- return progression;
- }
-
public void setImportDataMode(ImportDataMode importDataMode) {
this.importDataMode = importDataMode;
}
@@ -132,26 +117,21 @@
this.mission = mission;
}
- public void setProgression(float progression) {
- this.progression = progression;
- }
-
- public void incrementsProgression() {
- setProgression(progression + stepIncrement);
- }
-
public void computeSteps() {
- nbSteps = 0;
+ int nbSteps = 0;
switch (importDataMode) {
case ALL:
nbSteps = 5;
+ break;
case ACOUSTIC:
nbSteps = 1;
+ break;
default:
}
- stepIncrement = 100f / nbSteps;
+ setNbSteps(nbSteps);
}
+ @Override
public void destroy() throws IOException {
if (workingDirectory != null) {
FileUtils.deleteDirectory(workingDirectory);
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbConfiguration.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbConfiguration.java 2011-12-26 10:13:15 UTC (rev 215)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDbConfiguration.java 2011-12-26 19:07:07 UTC (rev 216)
@@ -28,7 +28,6 @@
import java.io.File;
import java.io.IOException;
-import java.io.Serializable;
import java.util.Locale;
import static org.nuiton.i18n.I18n.l_;
@@ -39,7 +38,7 @@
* @author tchemit <chemit(a)codelutin.com>
* @since 0.2
*/
-public class ImportDbConfiguration implements Serializable {
+public class ImportDbConfiguration extends AbstractEchobaseActionConfiguration {
private static final long serialVersionUID = 1L;
@@ -47,12 +46,6 @@
protected InputFile input;
- protected int nbSteps;
-
- private float stepIncrement;
-
- protected float progression;
-
public ImportDbConfiguration(Locale locale) {
input = InputFile.newFile(
l_(locale, "echobase.common.importDbFile"));
@@ -66,32 +59,11 @@
return input;
}
- public int getNbSteps() {
- return nbSteps;
- }
-
- public float getProgression() {
- return progression;
- }
-
public void setWorkingDirectory(File workingDirectory) {
this.workingDirectory = workingDirectory;
}
- public void setProgression(float progression) {
- this.progression = progression;
- }
-
- public void incrementsProgression() {
- setProgression(progression + stepIncrement);
- }
-
- public void setNbSteps(int nbSteps) {
-
- this.nbSteps = nbSteps;
- stepIncrement = 100f / nbSteps;
- }
-
+ @Override
public void destroy() throws IOException {
if (workingDirectory != null) {
FileUtils.deleteDirectory(workingDirectory);
Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportQueryCsvModel.java (from rev 211, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportSqlCsvModel.java)
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportQueryCsvModel.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportQueryCsvModel.java 2011-12-26 19:07:07 UTC (rev 216)
@@ -0,0 +1,86 @@
+/*
+ * #%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.models;
+
+import fr.ifremer.echobase.services.ExportQueryService;
+import org.nuiton.util.csv.ExportableColumn;
+import org.nuiton.util.csv.ImportExportModel;
+import org.nuiton.util.csv.ImportableColumn;
+import org.nuiton.util.csv.ModelBuilder;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Csv model to export sql in {@link ExportQueryService}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class ExportQueryCsvModel implements ImportExportModel<Map<String, Object>> {
+
+
+ protected final char separator;
+
+ protected final ModelBuilder<?> modelBuilder;
+
+ public ExportQueryCsvModel(char separator, String[] columnHeaders) {
+ this.separator = separator;
+ modelBuilder = new ModelBuilder<Object>();
+ for (String columnHeader : columnHeaders) {
+ modelBuilder.newColumnForExport(
+ columnHeader,
+ columnHeader,
+ CsvModelUtil.TO_STRING_FORMATTER
+ );
+ }
+ }
+
+ @Override
+ public char getSeparator() {
+ return separator;
+ }
+
+ @Override
+ public Collection<ExportableColumn<Map<String, Object>, Object>> getColumnsForExport() {
+ return (Collection) modelBuilder.getColumnsForExport();
+ }
+
+ @Override
+ public Collection<ImportableColumn<Map<String, Object>, Object>> getColumnsForImport() {
+ // never do import from this model
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void pushCsvHeaderNames(List<String> headerNames) {
+ }
+
+ @Override
+ public Map<String, Object> newEmptyInstance() {
+ // never do import from this model
+ throw new UnsupportedOperationException();
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportQueryCsvModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportSqlCsvModel.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportSqlCsvModel.java 2011-12-26 10:13:15 UTC (rev 215)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportSqlCsvModel.java 2011-12-26 19:07:07 UTC (rev 216)
@@ -1,86 +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.models;
-
-import fr.ifremer.echobase.services.ExportSqlService;
-import org.nuiton.util.csv.ExportableColumn;
-import org.nuiton.util.csv.ImportExportModel;
-import org.nuiton.util.csv.ImportableColumn;
-import org.nuiton.util.csv.ModelBuilder;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Csv model to export sql in {@link ExportSqlService}.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.2
- */
-public class ExportSqlCsvModel implements ImportExportModel<Map<String, Object>> {
-
-
- protected final char separator;
-
- protected final ModelBuilder<?> modelBuilder;
-
- public ExportSqlCsvModel(char separator, String[] columnHeaders) {
- this.separator = separator;
- modelBuilder = new ModelBuilder<Object>();
- for (String columnHeader : columnHeaders) {
- modelBuilder.newColumnForExport(
- columnHeader,
- columnHeader,
- CsvModelUtil.TO_STRING_FORMATTER
- );
- }
- }
-
- @Override
- public char getSeparator() {
- return separator;
- }
-
- @Override
- public Collection<ExportableColumn<Map<String, Object>, Object>> getColumnsForExport() {
- return (Collection) modelBuilder.getColumnsForExport();
- }
-
- @Override
- public Collection<ImportableColumn<Map<String, Object>, Object>> getColumnsForImport() {
- // never do import from this model
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void pushCsvHeaderNames(List<String> headerNames) {
- }
-
- @Override
- public Map<String, Object> newEmptyInstance() {
- // never do import from this model
- throw new UnsupportedOperationException();
- }
-}
1
0
r215 - in trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui: . actions/dbeditor
by tchemit@users.forge.codelutin.com 26 Dec '11
by tchemit@users.forge.codelutin.com 26 Dec '11
26 Dec '11
Author: tchemit
Date: 2011-12-26 11:13:15 +0100 (Mon, 26 Dec 2011)
New Revision: 215
Url: http://forge.codelutin.com/repositories/revision/echobase/215
Log:
use new service api
Modified:
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.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
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 2011-12-26 10:12:41 UTC (rev 214)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java 2011-12-26 10:13:15 UTC (rev 215)
@@ -24,11 +24,9 @@
package fr.ifremer.echobase.ui;
import com.google.common.base.Supplier;
-import com.google.common.collect.Lists;
import fr.ifremer.echobase.EchoBaseConfiguration;
import fr.ifremer.echobase.EchoBaseTechnicalException;
import fr.ifremer.echobase.EchoBaseTopiaRootContextSupplierFactory;
-import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.EchoBaseUser;
import fr.ifremer.echobase.entities.EchoBaseUserImpl;
import fr.ifremer.echobase.entities.meta.DbMeta;
@@ -104,10 +102,7 @@
new EchoBaseTopiaRootContextSupplierFactory();
rootContextSupplier = factory.newDatabaseFromConfig(configuration);
applicationContext.setRootContextSupplier(rootContextSupplier);
- List<EchoBaseEntityEnum> entityEnums =
- Lists.newArrayList(EchoBaseEntityEnum.values());
-// entityEnums.remove(EchoBaseEntityEnum.EchoBaseUser);
- DbMeta dbMeta = DbMeta.newDbMeta(entityEnums);
+ DbMeta dbMeta = DbMeta.newDbMeta();
applicationContext.setDbMeta(dbMeta);
@@ -220,7 +215,7 @@
// no users in database create the admin user
if (log.isInfoEnabled()) {
log.info("No user in database, will create default " +
- "admin user (password admin).");
+ "admin user (password admin).");
}
service.createDefaultAdminUser();
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 2011-12-26 10:12:41 UTC (rev 214)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ExportTable.java 2011-12-26 10:13:15 UTC (rev 215)
@@ -24,7 +24,8 @@
package fr.ifremer.echobase.ui.actions.dbeditor;
import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
-import fr.ifremer.echobase.services.DbEditorService;
+import fr.ifremer.echobase.entities.meta.TableMeta;
+import fr.ifremer.echobase.services.ExportService;
import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -87,9 +88,10 @@
@Override
public String execute() throws Exception {
- DbEditorService service = newService(DbEditorService.class);
+ ExportService exportService = newService(ExportService.class);
- String content = service.exportDatas(service.getTableMeta(entityType));
+ TableMeta table = serviceContext.getDbMeta().getTable(entityType);
+ String content = exportService.exportDatas(table);
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 2011-12-26 10:12:41 UTC (rev 214)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ImportTable.java 2011-12-26 10:13:15 UTC (rev 215)
@@ -26,7 +26,7 @@
import com.google.common.base.Throwables;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
import fr.ifremer.echobase.services.CsvImportResult;
-import fr.ifremer.echobase.services.DbEditorService;
+import fr.ifremer.echobase.services.ImportService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -111,14 +111,14 @@
// to call input method on validation error to initialize dbeditor page
public String execute() throws Exception {
- DbEditorService dbEditorService = newService(DbEditorService.class);
+ ImportService importService = newService(ImportService.class);
try {
- result = dbEditorService.importDatas(getEntityType(),
- importFileFileName,
- importFile,
- createIfNotFound,
- getEchoBaseSession().getEchoBaseUser());
+ result = importService.importDatas(getEntityType(),
+ importFileFileName,
+ importFile,
+ createIfNotFound,
+ getEchoBaseSession().getEchoBaseUser());
} catch (Exception eee) {
String message = "Failed to import datas : ";
1
0
r214 - in trunk/echobase-tools/src: main/java/fr/ifremer/echobase/tools/loaders test/java/fr/ifremer/echobase/tools test/java/fr/ifremer/echobase/tools/loaders
by tchemit@users.forge.codelutin.com 26 Dec '11
by tchemit@users.forge.codelutin.com 26 Dec '11
26 Dec '11
Author: tchemit
Date: 2011-12-26 11:12:41 +0100 (Mon, 26 Dec 2011)
New Revision: 214
Url: http://forge.codelutin.com/repositories/revision/echobase/214
Log:
use new service apis
Modified:
trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/DataMetadataLoader.java
trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/EntityLoader.java
trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/ReferenceDatumLoader.java
trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/VoyageLoader.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
Modified: trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/DataMetadataLoader.java
===================================================================
--- trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/DataMetadataLoader.java 2011-12-26 10:10:04 UTC (rev 213)
+++ trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/DataMetadataLoader.java 2011-12-26 10:12:41 UTC (rev 214)
@@ -108,9 +108,9 @@
meta
);
- List<DataType> dataTypes = getDbEditorService().getEntities(DataType.class);
- List<ReferenceDatum> referenceDatums = getDbEditorService().getEntities(ReferenceDatum.class);
- List<CellMethod> cellMethods = getDbEditorService().getEntities(CellMethod.class);
+ List<DataType> dataTypes = getEntities(DataType.class);
+ List<ReferenceDatum> referenceDatums = getEntities(ReferenceDatum.class);
+ List<CellMethod> cellMethods = getEntities(CellMethod.class);
model.addForeignKeyForImport("DataTypeID", DataMetadata.PROPERTY_DATA_TYPE, DataType.class, dataTypes, EchoBaseFunctions.DATA_TYPE_NAME);
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 2011-12-26 10:10:04 UTC (rev 213)
+++ trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/EntityLoader.java 2011-12-26 10:12:41 UTC (rev 214)
@@ -38,10 +38,10 @@
import fr.ifremer.echobase.entities.meta.TableMeta;
import fr.ifremer.echobase.services.CsvImportResult;
import fr.ifremer.echobase.services.DbEditorService;
-import fr.ifremer.echobase.services.DbImportService;
import fr.ifremer.echobase.services.EchoBaseServiceContext;
import fr.ifremer.echobase.services.EchoBaseServiceSupport;
-import fr.ifremer.echobase.services.models.EntityAssociationImportModel;
+import fr.ifremer.echobase.services.ExportService;
+import fr.ifremer.echobase.services.ImportService;
import fr.ifremer.echobase.services.models.EntityCsvModel;
import fr.ifremer.echobase.tools.FileType;
import org.apache.commons.io.IOUtils;
@@ -82,8 +82,6 @@
private static final EchoBaseEntityEnum[] EMPTY_DEPENDENCIES_ARRAY =
new EchoBaseEntityEnum[0];
- private DbEditorService dbEditorService;
-
private final Class<E> entityClass;
private final EchoBaseEntityEnum entityType;
@@ -205,10 +203,8 @@
log.info("Import " + entityType + " from " + csvfile);
}
- DbEditorService service = getDbEditorService();
+ TableMeta meta = getTable(entityType);
- TableMeta meta = service.getTableMeta(entityType);
-
EntityCsvModel<E> csvModel = createCsvImportModel(meta);
BufferedReader bf = new BufferedReader(new FileReader(csvfile));
@@ -217,12 +213,16 @@
Import<E> importer = Import.newImport(csvModel, bf);
try {
+ DbEditorService dbEditorService =
+ getService(DbEditorService.class);
+
for (E entity : importer) {
- service.saveEntity(meta,
- "",
- entity,
- null,
- false
+
+ dbEditorService.saveEntity(meta,
+ "",
+ entity,
+ null,
+ false
);
}
} finally {
@@ -240,7 +240,7 @@
File out = getTableFile(outputDir, meta, FileType.NEW);
- getDbEditorService().exportDatas(meta, out);
+ getExportService().exportDatas(meta, out);
} finally {
if (cleanTransaction) {
serviceContext.getTransaction().rollbackTransaction();
@@ -286,7 +286,7 @@
File out = getTableFile(outputDir, meta, targetType);
- getDbEditorService().exportDatas(meta, out);
+ getExportService().exportDatas(meta, out);
}
protected void copyAndLoad(File outputDir) throws IOException, TopiaException {
@@ -338,8 +338,6 @@
boolean commit,
FileType... fileTypes) throws IOException, TopiaException {
- DbImportService service = newService(DbImportService.class);
-
for (FileType fileType : fileTypes) {
File out = getTableFile(directory, meta, fileType);
@@ -370,13 +368,14 @@
return getDAO(entityClass);
}
- protected final DbEditorService getDbEditorService() {
- if (dbEditorService == null) {
- dbEditorService = serviceContext.newService(DbEditorService.class);
- }
- return dbEditorService;
+ protected final ImportService getImportService() {
+ return getService(ImportService.class);
}
+ protected final ExportService getExportService() {
+ return getService(ExportService.class);
+ }
+
protected final char getCsvSeparator() {
return serviceContext.getConfiguration().getCsvSeparator();
}
@@ -389,7 +388,7 @@
FileType targetType,
AssociationMeta associationMeta) throws IOException {
File out = getTableFile(outputDir, associationMeta, targetType);
- getDbEditorService().exportDatas(associationMeta, out);
+ getExportService().exportDatas(associationMeta, out);
}
@@ -411,7 +410,7 @@
Reader reader,
CsvImportResult csvResult) throws IOException {
- DbEditorService service = getDbEditorService();
+ ImportService service = getImportService();
if (entry instanceof AssociationMeta) {
@@ -423,17 +422,12 @@
log.info("Will import " + meta);
}
- EchoBaseEntityEnum source = meta.getSource();
EchoBaseEntityEnum target = meta.getTarget();
List<TopiaEntity> targetEntities = getEntities(target);
Map<String, TopiaEntity> targetsById =
Maps.uniqueIndex(targetEntities, EchoBaseFunctions.TO_TOPIAID);
- ImportModel<Map<String, Object>> model =
- EntityAssociationImportModel.newImportModel(
- getConfiguration().getCsvSeparator(),
- meta
- );
+ ImportModel<Map<String, Object>> model = service.buildForImport(meta);
EchoBaseEntityEnum sourceType = meta.getSource();
Modified: trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/ReferenceDatumLoader.java
===================================================================
--- trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/ReferenceDatumLoader.java 2011-12-26 10:10:04 UTC (rev 213)
+++ trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/ReferenceDatumLoader.java 2011-12-26 10:12:41 UTC (rev 214)
@@ -89,7 +89,7 @@
);
List<ReferenceDatumType> referenceDatumTypes =
- getDbEditorService().getEntities(ReferenceDatumType.class);
+ getEntities(ReferenceDatumType.class);
model.newMandatoryColumn(ReferenceDatum.PROPERTY_ID);
model.newMandatoryColumn(ReferenceDatum.PROPERTY_MEANING);
Modified: trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/VoyageLoader.java
===================================================================
--- trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/VoyageLoader.java 2011-12-26 10:10:04 UTC (rev 213)
+++ trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/VoyageLoader.java 2011-12-26 10:12:41 UTC (rev 214)
@@ -196,7 +196,7 @@
File out = getTableFile(outputDir, associationMeta, FileType.ASSOCIATION);
- getDbEditorService().exportDatas(associationMeta, out);
+ getExportService().exportDatas(associationMeta, out);
} finally {
if (cleanTransaction) {
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 2011-12-26 10:10:04 UTC (rev 213)
+++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/AbstractToolTest.java 2011-12-26 10:12:41 UTC (rev 214)
@@ -29,7 +29,6 @@
import fr.ifremer.echobase.entities.EchoBaseDAOHelper;
import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.meta.DbMeta;
-import fr.ifremer.echobase.services.DbEditorService;
import fr.ifremer.echobase.services.EchoBaseService;
import fr.ifremer.echobase.services.EchoBaseServiceContext;
import fr.ifremer.echobase.services.EchoBaseServiceContextImpl;
@@ -72,8 +71,6 @@
protected static EchoBaseConfiguration configuration;
- private DbEditorService service;
-
@BeforeClass
public static void beforeClass() {
@@ -120,13 +117,6 @@
return serviceContext.newService(clazz);
}
- protected DbEditorService getService() {
- if (service == null) {
- service = newService(DbEditorService.class);
- }
- return service;
- }
-
protected <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityClass) throws TopiaException {
TopiaDAO<E> dao = EchoBaseDAOHelper.<E, TopiaDAO<E>>getDAO(serviceContext.getTransaction(), entityClass);
return dao;
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 2011-12-26 10:10:04 UTC (rev 213)
+++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/AbstractLoaderIT.java 2011-12-26 10:12:41 UTC (rev 214)
@@ -33,6 +33,7 @@
import fr.ifremer.echobase.entities.meta.MetaFilenameAware;
import fr.ifremer.echobase.entities.meta.TableMeta;
import fr.ifremer.echobase.services.CsvImportResult;
+import fr.ifremer.echobase.services.ImportService;
import fr.ifremer.echobase.tools.AbstractToolTest;
import fr.ifremer.echobase.tools.FileType;
import fr.ifremer.echobase.tools.TestHelper;
@@ -292,7 +293,7 @@
if (log.isInfoEnabled()) {
log.info("Import " + inFile);
}
- CsvImportResult csvImportResult = getService().importDatas(
+ CsvImportResult csvImportResult = newService(ImportService.class).importDatas(
loader.getEntityType(),
inFile.getAbsolutePath(),
inFile,
1
0
r213 - in trunk/echobase-services/src: main/java/fr/ifremer/echobase/services main/java/fr/ifremer/echobase/services/models test/java/fr/ifremer/echobase/services
by tchemit@users.forge.codelutin.com 26 Dec '11
by tchemit@users.forge.codelutin.com 26 Dec '11
26 Dec '11
Author: tchemit
Date: 2011-12-26 11:10:04 +0100 (Mon, 26 Dec 2011)
New Revision: 213
Url: http://forge.codelutin.com/repositories/revision/echobase/213
Log:
introduce two atomic servies (ImportService and Exportservice)
introduce two atomic services (for db import / export)
improve service api (add a cache of services)
Added:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationExportModel.java
Removed:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.java
Modified:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationImportModel.java
trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java
trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/DbImportExportServiceTest.java
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -29,13 +29,10 @@
import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.EchoBaseUser;
import fr.ifremer.echobase.entities.EntityModificationLog;
-import fr.ifremer.echobase.entities.meta.AssociationMeta;
import fr.ifremer.echobase.entities.meta.ColumnMeta;
import fr.ifremer.echobase.entities.meta.DbMeta;
-import fr.ifremer.echobase.entities.meta.MetaFilenameAware;
import fr.ifremer.echobase.entities.meta.TableMeta;
import fr.ifremer.echobase.services.models.CsvModelUtil;
-import fr.ifremer.echobase.services.models.EntityAssociationCsvModel;
import fr.ifremer.echobase.services.models.EntityCsvModel;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
@@ -47,17 +44,10 @@
import org.nuiton.util.TimeLog;
import org.nuiton.util.beans.BeanMonitor;
import org.nuiton.util.beans.PropertyDiff;
-import org.nuiton.util.csv.Export;
-import org.nuiton.util.csv.ExportModel;
import org.nuiton.util.csv.ExportableColumn;
-import org.nuiton.util.csv.Import;
import org.nuiton.util.csv.ImportExportModel;
import org.nuiton.util.csv.ImportableColumn;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -75,13 +65,8 @@
public static final TimeLog timeLog = new TimeLog(DbEditorService.class);
- protected DecoratorService decoratorService;
-
protected DecoratorService getDecoratorService() {
- if (decoratorService == null) {
- decoratorService = newService(DecoratorService.class);
- }
- return decoratorService;
+ return getService(DecoratorService.class);
}
public <E extends TopiaEntity> List<E> getForeignDatas(Class<E> entityType) {
@@ -128,8 +113,6 @@
rows[i++] = row;
}
return rows;
-
-// return getDatas(entityType, pager, sidx, ascendantOrder, true);
}
@@ -240,104 +223,6 @@
commitTransaction("Could not commit transaction");
}
- public CsvImportResult importDatas(EchoBaseEntityEnum entityType,
- String importFileName,
- File importFile,
- boolean createIfNotFound,
- EchoBaseUser user) throws IOException {
-
- TableMeta meta = getTableMeta(entityType);
- ImportExportModel<TopiaEntity> csvModel = buildForImport(meta);
- String messagePrefix = "Import du fichier " + importFileName + " le " + newDate();
-
- CsvImportResult result = CsvImportResult.newResult(entityType,
- importFileName,
- createIfNotFound);
- BufferedReader bf = new BufferedReader(new FileReader(importFile));
- try {
-
- Import<TopiaEntity> importer = Import.newImport(csvModel, bf);
-
- try {
- for (TopiaEntity entity : importer) {
- boolean create = 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;
- }
-
- public String exportDatas(TableMeta tableMeta) {
-
- Export<TopiaEntity> export = prepareExport(tableMeta);
-
- try {
- return export.startExportAsString();
- } catch (Exception eee) {
- throw new EchoBaseTechnicalException("Can not export datas", eee);
- }
- }
-
- public void exportDatas(TableMeta tableMeta, File file) {
-
- if (log.isInfoEnabled()) {
- log.info("Export table " + tableMeta + " to " + file);
- }
- long s1 = TimeLog.getTime();
- Export<TopiaEntity> export = prepareExport(tableMeta);
- timeLog.log(s1, "prepareExport");
- long s2 = TimeLog.getTime();
- try {
- export.exportToFile(file);
- } catch (Exception eee) {
- throw new EchoBaseTechnicalException("Can not export datas", eee);
- }
- timeLog.log(s2, "exportToFile");
- }
-
- public void exportDatas(AssociationMeta associationMeta, File file) {
-
- if (log.isInfoEnabled()) {
- log.info("Export association " + associationMeta + " to " + file);
- }
- long s1 = TimeLog.getTime();
- Export<TopiaEntity> export = prepareExport(associationMeta);
- timeLog.log(s1, "prepareExport");
-
- long s2 = TimeLog.getTime();
- try {
- export.exportToFile(file);
- } catch (Exception eee) {
- throw new EchoBaseTechnicalException("Can not export datas", eee);
- }
- timeLog.log(s2, "exportToFile");
- }
-
public boolean saveEntity(TableMeta tableMeta,
String messagePrefix,
TopiaEntity entity,
@@ -509,80 +394,6 @@
return row;
}
- public <E extends TopiaEntity> EntityCsvModel<E> buildForImport(MetaFilenameAware meta) {
- if (meta instanceof AssociationMeta) {
- return buildForImport((AssociationMeta) meta);
- }
- if (meta instanceof TableMeta) {
- return buildForImport((TableMeta) meta);
- }
- throw new IllegalStateException("Can't do a thing with " + meta);
- }
-
- public <E extends TopiaEntity> EntityCsvModel<E> buildForImport(TableMeta meta) {
-
- EntityCsvModel<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 = getForeignDatas(entityType);
- model.addForeignKeyForImport(propertyName, entityType, universe);
- } else {
- model.addDefaultColumn(propertyName, type);
- }
- }
- return model;
- }
-
- public <E extends TopiaEntity> ExportModel<E> buildForExport(AssociationMeta associationMeta) {
-
- ExportModel<E> model = EntityAssociationCsvModel.newExportModel(
- getConfiguration().getCsvSeparator(),
- associationMeta
- );
- return model;
- }
-
- public <E extends TopiaEntity> ExportModel<E> buildForExport(MetaFilenameAware meta) {
- if (meta instanceof AssociationMeta) {
- return buildForExport((AssociationMeta) meta);
- }
- if (meta instanceof TableMeta) {
- return buildForExport((TableMeta) meta);
- }
- throw new IllegalStateException("Can't do a thing with " + meta);
- }
-
- public <E extends TopiaEntity> ExportModel<E> buildForExport(TableMeta meta) {
-
- EntityCsvModel<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;
- model.addForeignKeyForExport(propertyName, entityType);
- } else {
- model.addDefaultColumn(propertyName, type);
- }
- }
- return model;
- }
-
protected <E extends TopiaEntity> ImportExportModel<E> buildForSave(TableMeta meta) {
EntityCsvModel<E> model = EntityCsvModel.newModel(
@@ -661,18 +472,4 @@
return model;
}
- protected Export<TopiaEntity> prepareExport(TableMeta tableMeta) {
- List<TopiaEntity> datas = getEntities(tableMeta, null, null, null, null);
- ExportModel<TopiaEntity> model = buildForExport(tableMeta);
- return Export.newExport(model, datas);
- }
-
- protected Export<TopiaEntity> prepareExport(AssociationMeta associationMeta) {
-
- TableMeta tableMeta = getTableMeta(associationMeta.getSource());
- List<TopiaEntity> datas = getEntities(tableMeta, null, null, null, "size(e." + associationMeta.getName() + ") > 0");
-
- ExportModel<TopiaEntity> model = buildForExport(associationMeta);
- return Export.newExport(model, datas);
- }
}
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -23,9 +23,7 @@
*/
package fr.ifremer.echobase.services;
-import com.google.common.collect.Lists;
import fr.ifremer.echobase.EchoBaseIOUtil;
-import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.EntitiesUtil;
import fr.ifremer.echobase.entities.meta.AssociationMeta;
import fr.ifremer.echobase.entities.meta.MetaFilenameAware;
@@ -36,7 +34,6 @@
import org.nuiton.util.TimeLog;
import java.io.File;
-import java.util.List;
/**
* Service to import / export a complete db.
@@ -52,8 +49,6 @@
public static final TimeLog timeLog = new TimeLog(DbEditorService.class);
- protected DbEditorService dbEditorService;
-
/**
* Export the complete db into csv files stored in a zip archive file.
*
@@ -67,20 +62,20 @@
File zipFile = new File(tempDirectory, fileName + ".zip");
- DbEditorService service = getDbEditorService();
+ ExportService exportService = getService(ExportService.class);
File dir = new File(tempDirectory, "echobase");
- MetaFilenameAware[] entries = getEntries();
+ MetaFilenameAware[] entries = EntitiesUtil.getEntries(getDbMeta());
for (MetaFilenameAware entry : entries) {
File entryFile = new File(dir, entry.getFilename());
if (entry instanceof AssociationMeta) {
AssociationMeta associationMeta = (AssociationMeta) entry;
- service.exportDatas(associationMeta, entryFile);
+ exportService.exportDatas(associationMeta, entryFile);
} else {
TableMeta meta = (TableMeta) entry;
- service.exportDatas(meta, entryFile);
+ exportService.exportDatas(meta, entryFile);
}
}
@@ -89,41 +84,4 @@
return zipFile;
}
- public MetaFilenameAware[] getEntries() {
-
- List<MetaFilenameAware> entities = Lists.newArrayList();
- List<MetaFilenameAware> associations = Lists.newArrayList();
-
- addEntries(entities, associations, EntitiesUtil.getReferenceTypesForCopy());
- addEntries(entities, associations, EntitiesUtil.getDataTypesforCopy());
- entities.addAll(associations);
- return entities.toArray(new MetaFilenameAware[entities.size()]);
- }
-
- protected TableMeta getTableMeta(EchoBaseEntityEnum tableName) {
- return getDbEditorService().getTableMeta(tableName);
- }
-
- protected void addEntries(List<MetaFilenameAware> entities,
- List<MetaFilenameAware> associations,
- EchoBaseEntityEnum[] types) {
- for (EchoBaseEntityEnum type : types) {
-
- TableMeta tableMeta = getTableMeta(type);
- entities.add(tableMeta);
-
-// for (AssociationMeta associationMeta : tableMeta.getAssociations()) {
-// associations.add(associationMeta);
-// }
- associations.addAll(tableMeta.getAssociations());
- }
- }
-
- protected DbEditorService getDbEditorService() {
- if (dbEditorService == null) {
- dbEditorService = newService(DbEditorService.class);
- }
- return dbEditorService;
- }
-
}
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportService.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportService.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -25,8 +25,6 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import fr.ifremer.echobase.EchoBaseFunctions;
-import fr.ifremer.echobase.EchoBaseTechnicalException;
import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.EchoBaseUser;
import fr.ifremer.echobase.entities.EntitiesUtil;
@@ -34,17 +32,14 @@
import fr.ifremer.echobase.entities.meta.AssociationMeta;
import fr.ifremer.echobase.entities.meta.MetaFilenameAware;
import fr.ifremer.echobase.entities.meta.TableMeta;
-import fr.ifremer.echobase.services.models.EntityAssociationImportModel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.util.StringUtil;
import org.nuiton.util.TimeLog;
import org.nuiton.util.csv.Import;
-import org.nuiton.util.csv.ImportExportModel;
import org.nuiton.util.csv.ImportModel;
import org.nuiton.util.csv.ImportToMap;
@@ -52,7 +47,6 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
@@ -72,39 +66,6 @@
public static final TimeLog timeLog = new TimeLog(DbImportService.class);
- protected DbEditorService dbEditorService;
-
- protected Map<MetaFilenameAware, ZipEntry> discoverEntries(File file, ZipFile zipFile) {
-
- List<String> missingEntries = Lists.newArrayList();
-
- Map<MetaFilenameAware, ZipEntry> result =
- Maps.newLinkedHashMap();
-
- MetaFilenameAware[] entries = getEntries();
-
- // check that all mandatories
- for (MetaFilenameAware entry : entries) {
- String filename = entry.getFilename();
- ZipEntry zipEntry = zipFile.getEntry("echobase/" + filename);
-
- if (zipEntry == null) {
- missingEntries.add(filename);
- } else {
- result.put(entry, zipEntry);
- }
- }
- if (!missingEntries.isEmpty()) {
-
- if (log.isWarnEnabled()) {
- log.warn("There is " + missingEntries.size() + "missing mandatory files " +
- " in import " + file + "\n" + StringUtil.join(missingEntries, "\n", false));
- }
- }
-
- return result;
- }
-
/**
* Import a complete db from the given zip file.
*
@@ -169,6 +130,38 @@
}
}
+ protected Map<MetaFilenameAware, ZipEntry> discoverEntries(File file,
+ ZipFile zipFile) {
+
+ List<String> missingEntries = Lists.newArrayList();
+
+ Map<MetaFilenameAware, ZipEntry> result =
+ Maps.newLinkedHashMap();
+
+ MetaFilenameAware[] entries = EntitiesUtil.getEntries(getDbMeta());
+
+ // check that all mandatories
+ for (MetaFilenameAware entry : entries) {
+ String filename = entry.getFilename();
+ ZipEntry zipEntry = zipFile.getEntry("echobase/" + filename);
+
+ if (zipEntry == null) {
+ missingEntries.add(filename);
+ } else {
+ result.put(entry, zipEntry);
+ }
+ }
+ if (!missingEntries.isEmpty()) {
+
+ if (log.isWarnEnabled()) {
+ log.warn("There is " + missingEntries.size() + " missing files " +
+ " in import " + file + "\n" + StringUtil.join(missingEntries, "\n", false));
+ }
+ }
+
+ return result;
+ }
+
static class MyImportToMap extends ImportToMap {
public static MyImportToMap newImport(ImportModel<Map<String, Object>> model,
@@ -176,34 +169,51 @@
return new MyImportToMap(model, reader);
}
- protected MyImportToMap(ImportModel<Map<String, Object>> model, Reader reader) {
+ protected MyImportToMap(ImportModel<Map<String, Object>> model,
+ Reader reader) {
super(model, reader);
this.reader.setSafetySwitch(false);
}
-
}
public void importFile(MetaFilenameAware entry,
Reader reader,
CsvImportResult csvResult) throws IOException, TopiaException {
-
long s0 = TimeLog.getTime();
if (log.isInfoEnabled()) {
log.info("Will import " + entry);
}
+ ImportService importService = getService(ImportService.class);
+
if (entry instanceof AssociationMeta) {
// load a association input
- importAssociationfile((AssociationMeta) entry, reader, csvResult);
+ AssociationMeta meta = (AssociationMeta) entry;
+ ImportModel<Map<String, Object>> model = importService.buildForImport(meta);
+ ImportToMap importer = MyImportToMap.newImport(model, reader);
+ try {
+ importAssociationfile(meta, importer, csvResult);
+ } finally {
+ importer.close();
+ }
+
} else {
// normal entity table import
- importEntityFile((TableMeta) entry, reader, csvResult);
+ TableMeta meta = (TableMeta) entry;
+ ImportModel<TopiaEntity> model = importService.buildForImport(meta);
+ Import<TopiaEntity> importer = Import.newImport(model, reader);
+
+ try {
+ importEntityFile(meta, importer, csvResult);
+ } finally {
+ importer.close();
+ }
}
timeLog.log(s0, "importFile::done");
@@ -215,190 +225,66 @@
timeLog.log(s0, "importFile::flushTransaction");
}
+ protected void importEntityFile(TableMeta meta,
+ Import<TopiaEntity> importer,
+ CsvImportResult csvResult) throws TopiaException {
- public MetaFilenameAware[] getEntries() {
+ TopiaDAO<TopiaEntity> dao = getDAO(meta.getSource());
+ for (TopiaEntity entity : importer) {
- List<MetaFilenameAware> entities = Lists.newArrayList();
- List<MetaFilenameAware> associations = Lists.newArrayList();
+ TopiaEntity entityToSave = dao.create(TopiaEntity.TOPIA_ID,
+ entity.getTopiaId());
- addEntries(entities, associations, EntitiesUtil.getReferenceTypesForCopy());
- addEntries(entities, associations, EntitiesUtil.getDataTypesforCopy());
- entities.addAll(associations);
- return entities.toArray(new MetaFilenameAware[entities.size()]);
- }
+ meta.copy(entity, entityToSave);
- protected void importEntityFile(TableMeta meta, Reader reader, CsvImportResult csvResult) {
-
- ImportModel<TopiaEntity> model = getDbEditorService().buildForImport(meta);
-
- Import<TopiaEntity> importer = Import.newImport(model, reader);
-
- try {
- TopiaDAO<TopiaEntity> dao = getDAO(meta.getSource());
- for (TopiaEntity entity : importer) {
-
- TopiaEntity entityToSave = dao.create(TopiaEntity.TOPIA_ID,
- entity.getTopiaId());
-
- meta.copy(entity, entityToSave);
-
- csvResult.incrementsNumberUpdated();
- }
-
- } catch (Exception eee) {
- throw new EchoBaseTechnicalException("Could not import entities of type " + meta.getSource(), eee);
- } finally {
-
- importer.close();
+ csvResult.incrementsNumberUpdated();
}
}
- protected void flushTransaction() throws TopiaException {
- TopiaContextImplementor tx = (TopiaContextImplementor) getTransaction();
- tx.getHibernate().flush();
- }
+ protected void importAssociationfile(AssociationMeta meta,
+ ImportToMap importer,
+ CsvImportResult csvResult) throws TopiaException {
- protected void importAssociationfile(AssociationMeta meta, Reader reader, CsvImportResult csvResult) {
EchoBaseEntityEnum source = meta.getSource();
EchoBaseEntityEnum target = meta.getTarget();
- ImportModel<Map<String, Object>> model =
- EntityAssociationImportModel.newImportModel(
- getConfiguration().getCsvSeparator(),
- meta
- );
-
- ImportToMap importer = MyImportToMap.newImport(model, reader);
-
StringBuilder builder = new StringBuilder();
- try {
- String updateString;
- String targetTableName = target.getContract().getSimpleName();
- String sourceTableName = source.getContract().getSimpleName();
- String table = targetTableName;
- if (source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Echotype) {
- table = targetTableName + "_" + sourceTableName;
- updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE " + meta.getName() + " ='%s';";
- } else if (source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Strata) {
- table = targetTableName + "_" + source.getContract().getSimpleName();
- updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE " + meta.getName() + " ='%s';";
- } else {
- updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE topiaId ='%s';";
- }
-
- if (log.isDebugEnabled()) {
- log.debug("Will apply " + updateString);
- }
- int compt = 0;
- for (Map<String, Object> row : importer) {
- String topiaId = (String) row.get(TopiaEntity.TOPIA_ID);
- String[] associations = (String[]) row.get("target");
- for (String association : associations) {
- builder.append(String.format(updateString, topiaId, association)).append('\n');
- compt++;
- if (compt % 10000 == 0) {
- // flush it
- getTransaction().executeSQL(builder.toString());
- builder = new StringBuilder();
- }
- }
- csvResult.incrementsNumberUpdated();
- }
- if (builder.length() > 0) {
- getTransaction().executeSQL(builder.toString());
- }
- } catch (TopiaException eee) {
- throw new EchoBaseTechnicalException(
- "Could not execute sql script", eee);
- } finally {
-
- importer.close();
+ String updateString;
+ String targetTableName = target.getContract().getSimpleName();
+ String sourceTableName = source.getContract().getSimpleName();
+ String table = targetTableName;
+ if (source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Echotype) {
+ table = targetTableName + "_" + sourceTableName;
+ updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE " + meta.getName() + " ='%s';";
+ } else if (source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Strata) {
+ table = targetTableName + "_" + source.getContract().getSimpleName();
+ updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE " + meta.getName() + " ='%s';";
+ } else {
+ updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE topiaId ='%s';";
}
- }
- protected TableMeta getTableMeta(EchoBaseEntityEnum tableName) {
- return getDbEditorService().getTableMeta(tableName);
- }
-
- protected void addEntries(List<MetaFilenameAware> entities,
- List<MetaFilenameAware> associations,
- EchoBaseEntityEnum[] types) {
- for (EchoBaseEntityEnum type : types) {
-
- TableMeta tableMeta = getTableMeta(type);
- entities.add(tableMeta);
- associations.addAll(tableMeta.getAssociations());
+ if (log.isDebugEnabled()) {
+ log.debug("Will apply " + updateString);
}
- }
-
- protected DbEditorService getDbEditorService() {
- if (dbEditorService == null) {
- dbEditorService = newService(DbEditorService.class);
- }
- return dbEditorService;
- }
-
- protected void mportEntities(TableMeta meta,
- ImportExportModel<TopiaEntity> csvModel,
- CsvImportResult result,
- Reader reader) {
-
- if (log.isInfoEnabled()) {
- log.info("Will import " + meta);
- }
- Import<TopiaEntity> importer = Import.newImport(csvModel, reader);
-
- try {
- TopiaDAO<TopiaEntity> dao = getDAO(meta.getSource());
- long s0 = TimeLog.getTime();
- for (TopiaEntity entity : importer) {
-
- TopiaEntity entityToSave = dao.create(TopiaEntity.TOPIA_ID,
- entity.getTopiaId());
-
- meta.copy(entity, entityToSave);
-
- result.incrementsNumberUpdated();
+ int compt = 0;
+ for (Map<String, Object> row : importer) {
+ String topiaId = (String) row.get(TopiaEntity.TOPIA_ID);
+ String[] associations = (String[]) row.get("target");
+ for (String association : associations) {
+ builder.append(String.format(updateString, topiaId, association)).append('\n');
+ compt++;
+ if (compt % 10000 == 0) {
+ // flush it
+ getTransaction().executeSQL(builder.toString());
+ builder = new StringBuilder();
+ }
}
- timeLog.log(s0, "importEntities");
- } catch (Exception eee) {
- throw new EchoBaseTechnicalException("Could not import entities of type " + meta.getSource(), eee);
- } finally {
-
- importer.close();
+ csvResult.incrementsNumberUpdated();
}
- }
-
- protected <E extends TopiaEntity> void mportEntityAssociation(AssociationMeta meta,
- ImportModel<E> csvModel,
- CsvImportResult result,
- Reader reader) {
- if (log.isInfoEnabled()) {
- log.info("Will import " + meta);
+ if (builder.length() > 0) {
+ getTransaction().executeSQL(builder.toString());
}
-
- EchoBaseEntityEnum sourceType = meta.getSource();
-
- Import<E> importer = Import.newImport(csvModel, reader);
- long s0;
- s0 = TimeLog.getTime();
- List<E> sourceEntities = getEntities(sourceType);
- timeLog.log(s0, "importEntityAssociation::getEntities");
- Map<String, E> sourcesById =
- Maps.uniqueIndex(sourceEntities, EchoBaseFunctions.TO_TOPIAID);
- try {
- s0 = TimeLog.getTime();
- for (E row : importer) {
- E entityToSave = sourcesById.get(row.getTopiaId());
- Collection<TopiaEntity> assoc = meta.getChilds(row);
- meta.setChilds(entityToSave, assoc);
- result.incrementsNumberUpdated();
- }
- timeLog.log(s0, "importEntityAssociation::import");
- } finally {
-
- importer.close();
- }
}
+
}
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 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -24,6 +24,7 @@
package fr.ifremer.echobase.services;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
import fr.ifremer.echobase.EchoBaseConfiguration;
import fr.ifremer.echobase.EchoBaseTechnicalException;
import fr.ifremer.echobase.entities.EchoBaseDAOHelper;
@@ -33,12 +34,14 @@
import org.apache.commons.lang3.time.DateUtils;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
import java.util.Date;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
/**
* @author sletellier <letellier(a)codelutin.com>
@@ -48,6 +51,8 @@
protected EchoBaseServiceContext serviceContext;
+ protected Map<Class<?>, EchoBaseService> services;
+
@Override
public void setServiceContext(EchoBaseServiceContext serviceContext) {
this.serviceContext = serviceContext;
@@ -57,6 +62,7 @@
Class<E> contract = (Class<E>) entityType.getContract();
return getEntities(contract);
}
+
public <E extends TopiaEntity> List<E> getEntities(Class<E> entityType) {
Preconditions.checkNotNull(entityType);
try {
@@ -97,9 +103,16 @@
return serviceContext.getConfiguration();
}
- protected <E extends EchoBaseService> E newService(Class<E> serviceClass) {
- E e = serviceContext.newService(serviceClass);
- return e;
+ protected <E extends EchoBaseService> E getService(Class<E> serviceClass) {
+ if (services == null) {
+ services = Maps.newHashMap();
+ }
+ E service = (E) services.get(serviceClass);
+ if (service == null) {
+ service = serviceContext.newService(serviceClass);
+ services.put(serviceClass, service);
+ }
+ return service;
}
protected <E extends TopiaEntity> TopiaDAO<E> getDAO(EchoBaseEntityEnum entityEnum) throws TopiaException {
@@ -123,6 +136,11 @@
}
}
+ protected void flushTransaction() throws TopiaException {
+ TopiaContextImplementor tx = (TopiaContextImplementor) getTransaction();
+ tx.getHibernate().flush();
+ }
+
protected Date newDate() {
Date result = new Date();
DateUtils.setMilliseconds(result, 0);
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -204,7 +204,7 @@
// get export query service
ExportSqlService exportSqlService =
- newService(ExportSqlService.class);
+ getService(ExportSqlService.class);
// get all export queries from application
List<ExportQuery> queries = exportSqlService.getEntities(ExportQuery.class);
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -0,0 +1,150 @@
+/*
+ * #%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.EchoBaseTechnicalException;
+import fr.ifremer.echobase.entities.meta.AssociationMeta;
+import fr.ifremer.echobase.entities.meta.ColumnMeta;
+import fr.ifremer.echobase.entities.meta.TableMeta;
+import fr.ifremer.echobase.services.models.EntityAssociationExportModel;
+import fr.ifremer.echobase.services.models.EntityCsvModel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.TimeLog;
+import org.nuiton.util.csv.Export;
+import org.nuiton.util.csv.ExportModel;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * To export datas from db to csv files.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class ExportService extends EchoBaseServiceSupport {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(ExportService.class);
+
+ public static final TimeLog timeLog = new TimeLog(ExportService.class);
+
+ public <E extends TopiaEntity> ExportModel<E> buildForExport(AssociationMeta associationMeta) {
+
+ ExportModel<E> model = EntityAssociationExportModel.newExportModel(
+ getConfiguration().getCsvSeparator(),
+ associationMeta
+ );
+ return model;
+ }
+
+ public <E extends TopiaEntity> ExportModel<E> buildForExport(TableMeta meta) {
+
+ EntityCsvModel<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;
+ model.addForeignKeyForExport(propertyName, entityType);
+ } else {
+ model.addDefaultColumn(propertyName, type);
+ }
+ }
+ return model;
+ }
+
+ public String exportDatas(TableMeta tableMeta) {
+
+ Export<TopiaEntity> export = prepareExport(tableMeta);
+
+ try {
+ return export.startExportAsString();
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException("Can not export datas", eee);
+ }
+ }
+
+ public void exportDatas(TableMeta tableMeta, File file) {
+
+ if (log.isInfoEnabled()) {
+ log.info("Export table " + tableMeta + " to " + file);
+ }
+ long s1 = TimeLog.getTime();
+ Export<TopiaEntity> export = prepareExport(tableMeta);
+ timeLog.log(s1, "exportDatas::prepareExport");
+ long s2 = TimeLog.getTime();
+ try {
+ export.exportToFile(file);
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException("Can not export datas", eee);
+ }
+ timeLog.log(s2, "exportDatas::exportToFile");
+ }
+
+ public void exportDatas(AssociationMeta associationMeta, File file) {
+
+ if (log.isInfoEnabled()) {
+ log.info("Export association " + associationMeta + " to " + file);
+ }
+ long s1 = TimeLog.getTime();
+ Export<TopiaEntity> export = prepareExport(associationMeta);
+ timeLog.log(s1, "prepareExport");
+
+ long s2 = TimeLog.getTime();
+ try {
+ export.exportToFile(file);
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException("Can not export datas", eee);
+ }
+ timeLog.log(s2, "exportToFile");
+ }
+
+ protected Export<TopiaEntity> prepareExport(TableMeta tableMeta) {
+ DbEditorService service = getService(DbEditorService.class);
+
+ List<TopiaEntity> datas = service.getEntities(tableMeta, null, null, null, null);
+ ExportModel<TopiaEntity> model = buildForExport(tableMeta);
+ return Export.newExport(model, datas);
+ }
+
+ protected Export<TopiaEntity> prepareExport(AssociationMeta associationMeta) {
+
+ DbEditorService service = getService(DbEditorService.class);
+
+ TableMeta tableMeta = service.getTableMeta(associationMeta.getSource());
+ List<TopiaEntity> datas = service.getEntities(tableMeta, null, null, null, "size(e." + associationMeta.getName() + ") > 0");
+
+ ExportModel<TopiaEntity> model = buildForExport(associationMeta);
+ return Export.newExport(model, datas);
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/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/ImportService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportService.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportService.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -0,0 +1,147 @@
+/*
+ * #%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.EchoBaseTechnicalException;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
+import fr.ifremer.echobase.entities.EchoBaseUser;
+import fr.ifremer.echobase.entities.meta.AssociationMeta;
+import fr.ifremer.echobase.entities.meta.ColumnMeta;
+import fr.ifremer.echobase.entities.meta.TableMeta;
+import fr.ifremer.echobase.services.models.EntityAssociationImportModel;
+import fr.ifremer.echobase.services.models.EntityCsvModel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.csv.Import;
+import org.nuiton.util.csv.ImportExportModel;
+import org.nuiton.util.csv.ImportModel;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * To import datas from csv files into the db.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class ImportService extends EchoBaseServiceSupport {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(ImportService.class);
+
+ public <E extends TopiaEntity> EntityCsvModel<E> buildForImport(TableMeta meta) {
+
+ DbEditorService service = getService(DbEditorService.class);
+
+ EntityCsvModel<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;
+ }
+
+ public ImportModel<Map<String, Object>> buildForImport(AssociationMeta meta) {
+
+ ImportModel<Map<String, Object>> model =
+ EntityAssociationImportModel.newImportModel(
+ getConfiguration().getCsvSeparator(),
+ meta
+ );
+ return model;
+ }
+
+ public CsvImportResult importDatas(EchoBaseEntityEnum entityType,
+ String importFileName,
+ File importFile,
+ boolean createIfNotFound,
+ EchoBaseUser user) throws IOException {
+
+ DbEditorService service = getService(DbEditorService.class);
+
+ TableMeta meta = service.getTableMeta(entityType);
+ ImportExportModel<TopiaEntity> csvModel = buildForImport(meta);
+ String messagePrefix = "Import du fichier " + importFileName + " le " + newDate();
+
+ CsvImportResult result = CsvImportResult.newResult(entityType,
+ importFileName,
+ createIfNotFound);
+ BufferedReader bf = new BufferedReader(new FileReader(importFile));
+ 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/ImportService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -1,133 +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.models;
-
-import fr.ifremer.echobase.entities.meta.AssociationMeta;
-import org.nuiton.topia.persistence.TopiaEntity;
-import org.nuiton.util.csv.ExportModel;
-import org.nuiton.util.csv.ExportableColumn;
-import org.nuiton.util.csv.ImportExportModel;
-import org.nuiton.util.csv.ImportModel;
-import org.nuiton.util.csv.ImportableColumn;
-import org.nuiton.util.csv.ModelBuilder;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * A model to import / export associations of entities into csv files.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.2
- */
-public class EntityAssociationCsvModel<E extends TopiaEntity> implements ImportExportModel<E> {
-
- protected final char separator;
-
- protected final AssociationMeta meta;
-
- protected ModelBuilder<E> modelBuilder;
-
- public static <E extends TopiaEntity> ImportModel<E> newImportModel(char separator,
- AssociationMeta meta,
- Map<String, TopiaEntity> targetsById
- ) {
- EntityAssociationCsvModel<E> model = new EntityAssociationCsvModel<E>(
- separator, meta);
-
- // topiaId <-> topiaId
- model.modelBuilder.newColumnForImportExport(
- TopiaEntity.TOPIA_ID,
- TopiaEntity.TOPIA_ID
- );
-
- // add association -> target
- Class<TopiaEntity> target =
- (Class<TopiaEntity>) meta.getTarget().getImplementation();
-
- model.modelBuilder.newColumnForImportExport(
- meta.getName(),
- meta.getName(),
- CsvModelUtil.newAssociationValueParserFormatter(target, targetsById)
- );
-
- return model;
- }
-
- public static <E extends TopiaEntity> ExportModel<E> newExportModel(char separator,
- AssociationMeta meta
- ) {
- EntityAssociationCsvModel<E> model = new EntityAssociationCsvModel<E>(
- separator,
- meta);
-
- // topiaId <-> topiaId
- model.modelBuilder.newColumnForExport(
- TopiaEntity.TOPIA_ID,
- TopiaEntity.TOPIA_ID
- );
-
- model.modelBuilder.newColumnForExport(
- meta.getName(),
- meta.getName(),
- CsvModelUtil.newAssociationValueFormatter()
- );
- return model;
- }
-
- @Override
- public char getSeparator() {
- return separator;
- }
-
- @Override
- public Iterable<ExportableColumn<E, Object>> getColumnsForExport() {
- return (Collection)
- modelBuilder.getColumnsForExport();
- }
-
- @Override
- public Iterable<ImportableColumn<E, Object>> getColumnsForImport() {
- return (Collection)
- modelBuilder.getColumnsForImport();
- }
-
- @Override
- public void pushCsvHeaderNames(List<String> headerNames) {
- }
-
- @Override
- public E newEmptyInstance() {
- return (E) meta.newEntity();
- }
-
- protected EntityAssociationCsvModel(char separator, AssociationMeta meta) {
- this.separator = separator;
- this.meta = meta;
- modelBuilder = new ModelBuilder<E>();
- }
-
-
-}
\ No newline at end of file
Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationExportModel.java (from rev 211, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.java)
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationExportModel.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationExportModel.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -0,0 +1,87 @@
+/*
+ * #%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.models;
+
+import fr.ifremer.echobase.entities.meta.AssociationMeta;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.csv.ExportModel;
+import org.nuiton.util.csv.ExportableColumn;
+import org.nuiton.util.csv.ModelBuilder;
+
+import java.util.Collection;
+
+/**
+ * A model to export associations of entities into csv files.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class EntityAssociationExportModel<E extends TopiaEntity> implements ExportModel<E> {
+
+ protected final char separator;
+
+ protected final AssociationMeta meta;
+
+ protected ModelBuilder<E> modelBuilder;
+
+ public static <E extends TopiaEntity> ExportModel<E> newExportModel(char separator,
+ AssociationMeta meta
+ ) {
+ EntityAssociationExportModel<E> model = new EntityAssociationExportModel<E>(
+ separator,
+ meta);
+
+ // topiaId <-> topiaId
+ model.modelBuilder.newColumnForExport(
+ TopiaEntity.TOPIA_ID,
+ TopiaEntity.TOPIA_ID
+ );
+
+ model.modelBuilder.newColumnForExport(
+ meta.getName(),
+ meta.getName(),
+ CsvModelUtil.newAssociationValueFormatter()
+ );
+ return model;
+ }
+
+ @Override
+ public char getSeparator() {
+ return separator;
+ }
+
+ @Override
+ public Iterable<ExportableColumn<E, Object>> getColumnsForExport() {
+ return (Collection)
+ modelBuilder.getColumnsForExport();
+ }
+
+ protected EntityAssociationExportModel(char separator, AssociationMeta meta) {
+ this.separator = separator;
+ this.meta = meta;
+ modelBuilder = new ModelBuilder<E>();
+ }
+
+
+}
\ No newline at end of file
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationExportModel.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/models/EntityAssociationImportModel.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationImportModel.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationImportModel.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -34,7 +34,7 @@
import java.util.Map;
/**
- * A model to import / export associations of entities into csv files.
+ * A model to import associations of entities into csv files.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 0.2
Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -93,9 +93,7 @@
public DbMeta getDbMeta() {
if (dbMeta == null) {
- List<EchoBaseEntityEnum> entityEnums =
- Lists.newArrayList(EchoBaseEntityEnum.values());
- dbMeta = DbMeta.newDbMeta(entityEnums);
+ dbMeta = DbMeta.newDbMeta();
}
return dbMeta;
}
Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/DbImportExportServiceTest.java
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/DbImportExportServiceTest.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/DbImportExportServiceTest.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -120,7 +120,7 @@
@Test
public void testGetDataCopyModel() throws TopiaException {
- EchoBaseEntityEnum[] types = EntitiesUtil.getDataTypesforCopy();
+ EchoBaseEntityEnum[] types = EntitiesUtil.getDataTypesForCopy();
Set<TopiaEntityEnum> dones = Sets.newHashSet();
ReplicationModel model = new ReplicationModel(types, false);
1
0
r212 - in trunk/echobase-entities/src: main/java/fr/ifremer/echobase main/java/fr/ifremer/echobase/entities main/java/fr/ifremer/echobase/entities/meta main/xmi test/java/fr/ifremer/echobase test/java/fr/ifremer/echobase/entities
by tchemit@users.forge.codelutin.com 26 Dec '11
by tchemit@users.forge.codelutin.com 26 Dec '11
26 Dec '11
Author: tchemit
Date: 2011-12-26 11:02:16 +0100 (Mon, 26 Dec 2011)
New Revision: 212
Url: http://forge.codelutin.com/repositories/revision/echobase/212
Log:
remove OperationType entity
let's declare all copiable entities
add decorator test (to make sure there is a decorator for each type of entity)
Added:
trunk/echobase-entities/src/test/java/fr/ifremer/echobase/EchoBaseDecoratorProviderTest.java
Modified:
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java
trunk/echobase-entities/src/main/xmi/echobase.zargo
trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/EntitiesUtilTest.java
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java 2011-12-24 12:14:02 UTC (rev 211)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java 2011-12-26 10:02:16 UTC (rev 212)
@@ -67,7 +67,6 @@
import fr.ifremer.echobase.entities.references.Mission;
import fr.ifremer.echobase.entities.references.OperationEvent;
import fr.ifremer.echobase.entities.references.OperationMetadata;
-import fr.ifremer.echobase.entities.references.OperationType;
import fr.ifremer.echobase.entities.references.ReferenceDatum;
import fr.ifremer.echobase.entities.references.ReferenceDatumType;
import fr.ifremer.echobase.entities.references.ReferencingMethod;
@@ -189,9 +188,6 @@
// OperationMetadata decorator
registerJXPathDecorator(locale, OperationMetadata.class, "${name}$s");
- // OperationType decorator
- registerJXPathDecorator(locale, OperationType.class, "${name}$s");
-
// ReferenceDatum decorator
registerJXPathDecorator(locale, ReferenceDatum.class, "${id}$s");
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java 2011-12-24 12:14:02 UTC (rev 211)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java 2011-12-26 10:02:16 UTC (rev 212)
@@ -24,6 +24,9 @@
package fr.ifremer.echobase.entities;
import com.google.common.collect.Lists;
+import fr.ifremer.echobase.entities.meta.DbMeta;
+import fr.ifremer.echobase.entities.meta.MetaFilenameAware;
+import fr.ifremer.echobase.entities.meta.TableMeta;
import java.util.List;
@@ -64,7 +67,7 @@
* @return the entity types of data in correct order for replication
* purpose.
*/
- public static EchoBaseEntityEnum[] getDataTypesforCopy() {
+ public static EchoBaseEntityEnum[] getDataTypesForCopy() {
List<EchoBaseEntityEnum> result = Lists.newLinkedList();
@@ -115,7 +118,6 @@
result.add(EchoBaseEntityEnum.GearCharacteristicValue);
result.add(EchoBaseEntityEnum.GearMetadata);
result.add(EchoBaseEntityEnum.Calibration);
- result.add(EchoBaseEntityEnum.OperationType);
result.add(EchoBaseEntityEnum.MeasurementMetadata);
result.add(EchoBaseEntityEnum.SampleDataType);
result.add(EchoBaseEntityEnum.SampleType);
@@ -146,24 +148,19 @@
public static EchoBaseEntityEnum[] getReferenceTypesForCopy() {
List<EchoBaseEntityEnum> result = Lists.newLinkedList();
+ // with no dep
result.add(EchoBaseEntityEnum.Strata);
result.add(EchoBaseEntityEnum.SexCategory);
result.add(EchoBaseEntityEnum.AgeCategory);
result.add(EchoBaseEntityEnum.SizeCategory);
result.add(EchoBaseEntityEnum.Species);
- result.add(EchoBaseEntityEnum.SpeciesCategory);
result.add(EchoBaseEntityEnum.Calibration);
- result.add(EchoBaseEntityEnum.AcousticInstrument);
- result.add(EchoBaseEntityEnum.TSParameters);
result.add(EchoBaseEntityEnum.VesselType);
- result.add(EchoBaseEntityEnum.Vessel);
result.add(EchoBaseEntityEnum.Mission);
result.add(EchoBaseEntityEnum.DepthStratum);
result.add(EchoBaseEntityEnum.EchotypeCategory);
- result.add(EchoBaseEntityEnum.Echotype);
result.add(EchoBaseEntityEnum.AreaOfOperation);
result.add(EchoBaseEntityEnum.ReferenceDatumType);
- result.add(EchoBaseEntityEnum.ReferenceDatum);
result.add(EchoBaseEntityEnum.DataType);
result.add(EchoBaseEntityEnum.DataQuality);
result.add(EchoBaseEntityEnum.CellMethod);
@@ -171,13 +168,62 @@
result.add(EchoBaseEntityEnum.OperationEvent);
result.add(EchoBaseEntityEnum.SampleDataType);
result.add(EchoBaseEntityEnum.SampleType);
- result.add(EchoBaseEntityEnum.DataMetadata);
+ result.add(EchoBaseEntityEnum.GearCharacteristic);
+ result.add(EchoBaseEntityEnum.CategoryMeaning);
+ result.add(EchoBaseEntityEnum.CategoryType);
+ result.add(EchoBaseEntityEnum.MeasureType);
+ result.add(EchoBaseEntityEnum.MeasurementMetadata);
+ result.add(EchoBaseEntityEnum.ReferencingMethod);
+
+ // with deps
+ result.add(EchoBaseEntityEnum.AcousticInstrument);
+ result.add(EchoBaseEntityEnum.Vessel);
+ result.add(EchoBaseEntityEnum.ReferenceDatum);
result.add(EchoBaseEntityEnum.OperationMetadata);
result.add(EchoBaseEntityEnum.GearMetadata);
+ result.add(EchoBaseEntityEnum.GearCharacteristicValue);
result.add(EchoBaseEntityEnum.Gear);
result.add(EchoBaseEntityEnum.LengthAgeKey);
+
+ result.add(EchoBaseEntityEnum.SpeciesCategory);
result.add(EchoBaseEntityEnum.LengthWeightKey);
+ result.add(EchoBaseEntityEnum.TSParameters);
+ result.add(EchoBaseEntityEnum.Echotype);
+ result.add(EchoBaseEntityEnum.DataMetadata);
+ result.add(EchoBaseEntityEnum.Category);
+ result.add(EchoBaseEntityEnum.CategoryRef);
+ result.add(EchoBaseEntityEnum.Impacte);
+ result.add(EchoBaseEntityEnum.DataProtocol);
return result.toArray(new EchoBaseEntityEnum[result.size()]);
}
+ public static MetaFilenameAware[] getEntries(DbMeta dbMeta) {
+
+ List<MetaFilenameAware> entities = Lists.newArrayList();
+ List<MetaFilenameAware> associations = Lists.newArrayList();
+
+ addEntries(dbMeta, entities, associations, getReferenceTypesForCopy());
+ addEntries(dbMeta, entities, associations, getDataTypesForCopy());
+ entities.addAll(associations);
+ return entities.toArray(new MetaFilenameAware[entities.size()]);
+ }
+
+ protected static void addEntries(DbMeta dbMeta,
+ List<MetaFilenameAware> entities,
+ List<MetaFilenameAware> associations,
+ EchoBaseEntityEnum[] types) {
+ for (EchoBaseEntityEnum type : types) {
+
+ TableMeta tableMeta = getTableMeta(dbMeta, type);
+ entities.add(tableMeta);
+ associations.addAll(tableMeta.getAssociations());
+ }
+ }
+
+ protected static TableMeta getTableMeta(DbMeta dbMeta,
+ EchoBaseEntityEnum tableName) {
+ TableMeta result = dbMeta.getTable(tableName);
+ return result;
+ }
+
}
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java 2011-12-24 12:14:02 UTC (rev 211)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java 2011-12-26 10:02:16 UTC (rev 212)
@@ -43,7 +43,12 @@
protected final EchoBaseEntityEnum[] entityEnums;
- public static DbMeta newDbMeta(List<EchoBaseEntityEnum> entityEnums) {
+ public static DbMeta newDbMeta() {
+ List<EchoBaseEntityEnum> entityEnums =
+ Lists.newArrayList(EchoBaseEntityEnum.values());
+ entityEnums.remove(EchoBaseEntityEnum.EchoBaseUser);
+ entityEnums.remove(EchoBaseEntityEnum.EntityModificationLog);
+ entityEnums.remove(EchoBaseEntityEnum.ExportQuery);
return newDbMeta(entityEnums.toArray(new EchoBaseEntityEnum[entityEnums.size()]));
}
Modified: trunk/echobase-entities/src/main/xmi/echobase.zargo
===================================================================
(Binary files differ)
Added: trunk/echobase-entities/src/test/java/fr/ifremer/echobase/EchoBaseDecoratorProviderTest.java
===================================================================
--- trunk/echobase-entities/src/test/java/fr/ifremer/echobase/EchoBaseDecoratorProviderTest.java (rev 0)
+++ trunk/echobase-entities/src/test/java/fr/ifremer/echobase/EchoBaseDecoratorProviderTest.java 2011-12-26 10:02:16 UTC (rev 212)
@@ -0,0 +1,78 @@
+/*
+ * #%L
+ * EchoBase :: Entities
+ *
+ * $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;
+
+import com.google.common.collect.Lists;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
+import fr.ifremer.echobase.entities.EntitiesUtilTest;
+import fr.ifremer.echobase.entities.data.Voyage;
+import fr.ifremer.echobase.entities.references.Mission;
+import junit.framework.Assert;
+import org.junit.Test;
+import org.nuiton.util.decorator.Decorator;
+
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * To test the {@link EchoBaseDecoratorProvider}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class EchoBaseDecoratorProviderTest {
+
+ @Test
+ public void getDecoratorForReferences() throws Exception {
+ Locale locale = Locale.FRANCE;
+ EchoBaseDecoratorProvider provider = new EchoBaseDecoratorProvider();
+ provider.loadDecorators(locale);
+ List<EchoBaseEntityEnum> expectedTypes =
+ Lists.newArrayList(EntitiesUtilTest.getContractsOf(
+ Mission.class.getPackage()));
+
+ for (EchoBaseEntityEnum type : expectedTypes) {
+ Decorator<?> decorator =
+ provider.getDecoratorByType(locale, type.getContract());
+ Assert.assertNotNull("Missing decorator for type : " + type, decorator);
+ }
+ }
+
+ @Test
+ public void getDecoratorForData() throws Exception {
+ Locale locale = Locale.FRANCE;
+ EchoBaseDecoratorProvider provider = new EchoBaseDecoratorProvider();
+ provider.loadDecorators(locale);
+ List<EchoBaseEntityEnum> expectedTypes =
+ Lists.newArrayList(EntitiesUtilTest.getContractsOf(
+ Voyage.class.getPackage()));
+
+ for (EchoBaseEntityEnum type : expectedTypes) {
+ Decorator<?> decorator =
+ provider.getDecoratorByType(locale, type.getContract());
+ Assert.assertNotNull("Missing decorator for type : " + type, decorator);
+ }
+ }
+
+}
Property changes on: trunk/echobase-entities/src/test/java/fr/ifremer/echobase/EchoBaseDecoratorProviderTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/EntitiesUtilTest.java
===================================================================
--- trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/EntitiesUtilTest.java 2011-12-24 12:14:02 UTC (rev 211)
+++ trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/EntitiesUtilTest.java 2011-12-26 10:02:16 UTC (rev 212)
@@ -60,6 +60,23 @@
}
@Test
+ public void getReferenceTypesForCopy() {
+
+ List<EchoBaseEntityEnum> types =
+ Arrays.asList(EntitiesUtil.getReferenceTypesForCopy());
+
+ List<EchoBaseEntityEnum> expectedTypes =
+ Lists.newArrayList(getContractsOf(Mission.class.getPackage()));
+
+ Assert.assertNotNull(types);
+
+ for (EchoBaseEntityEnum type : expectedTypes) {
+ Assert.assertTrue("Missing type : " + type, types.contains(type));
+ }
+ Assert.assertEquals(expectedTypes.size(), types.size());
+ }
+
+ @Test
public void getDataTypes() {
List<EchoBaseEntityEnum> types =
@@ -76,6 +93,23 @@
Assert.assertEquals(expectedTypes.size(), types.size());
}
+
+ @Test
+ public void getDataTypesForCopy() {
+
+ List<EchoBaseEntityEnum> types =
+ Arrays.asList(EntitiesUtil.getDataTypesForCopy());
+
+ List<EchoBaseEntityEnum> expectedTypes =
+ Lists.newArrayList(getContractsOf(Voyage.class.getPackage()));
+
+ Assert.assertNotNull(types);
+
+ for (EchoBaseEntityEnum type : expectedTypes) {
+ Assert.assertTrue("Missing type : " + type, types.contains(type));
+ }
+ Assert.assertEquals(expectedTypes.size(), types.size());
+ }
/**
* Used to get all contract of a package
*
1
0
r211 - in trunk/echobase-tools/src/test: java/fr/ifremer/echobase/tools/loaders resources/csv/new
by tchemit@users.forge.codelutin.com 24 Dec '11
by tchemit@users.forge.codelutin.com 24 Dec '11
24 Dec '11
Author: tchemit
Date: 2011-12-24 13:14:02 +0100 (Sat, 24 Dec 2011)
New Revision: 211
Url: http://forge.codelutin.com/repositories/revision/echobase/211
Log:
add new gear
Modified:
trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/GearLoaderIT.java
trunk/echobase-tools/src/test/resources/csv/new/input-Gear.csv
Modified: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/GearLoaderIT.java
===================================================================
--- trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/GearLoaderIT.java 2011-12-24 12:12:33 UTC (rev 210)
+++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/GearLoaderIT.java 2011-12-24 12:14:02 UTC (rev 211)
@@ -35,7 +35,7 @@
public class GearLoaderIT extends AbstractLoaderIT<Gear, GearLoader> {
public GearLoaderIT() {
- super(GearLoader.class, 112, 0);
+ super(GearLoader.class, 113, 0);
}
@Test
Modified: trunk/echobase-tools/src/test/resources/csv/new/input-Gear.csv
===================================================================
--- trunk/echobase-tools/src/test/resources/csv/new/input-Gear.csv 2011-12-24 12:12:33 UTC (rev 210)
+++ trunk/echobase-tools/src/test/resources/csv/new/input-Gear.csv 2011-12-24 12:14:02 UTC (rev 211)
@@ -1,4 +1,5 @@
CasinoGearName;ValidSince;InvalidSince;IsFishingGear;gearLabel;GearName;Description;UpdateDate;GearClassification;ParentGear;Status;IsActive;IsTowed
+47,75 x 43,75;01/01/00;;1;47,75 x 43,75;CHANGE ME 47,75 x 43,75;;;5;;;1;1
119x102;01/01/00;;1;119x102;Chalut pélagique 119/102;;;5;;;1;1
36x47;01/01/00;;1;GV3647;Chalut de fond GOV 36/47;;;5;;;1;1
57x52;01/01/00;;1;57x52;Chalut pélagique 57/52;;;5;;;1;1
1
0
r210 - trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders
by tchemit@users.forge.codelutin.com 24 Dec '11
by tchemit@users.forge.codelutin.com 24 Dec '11
24 Dec '11
Author: tchemit
Date: 2011-12-24 13:12:33 +0100 (Sat, 24 Dec 2011)
New Revision: 210
Url: http://forge.codelutin.com/repositories/revision/echobase/210
Log:
skip BXXX operation + add NP messages
Modified:
trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/OperationLoader.java
Modified: trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/OperationLoader.java
===================================================================
--- trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/OperationLoader.java 2011-12-20 14:22:50 UTC (rev 209)
+++ trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/OperationLoader.java 2011-12-24 12:12:33 UTC (rev 210)
@@ -249,7 +249,12 @@
}
String operationId = (String) row.get("NOSTA");
+ if ("BXXX".equals(operationId)) {
+ // skip this operation
+ return null;
+ }
+
String gearId = (String) row.get("ENGIN");
if (gearId == null) {
if (log.isWarnEnabled()) {
@@ -298,10 +303,10 @@
}
Float midHauleLatitude = (Float) row.get("LATDD");
- Preconditions.checkNotNull(midHauleLatitude);
+ Preconditions.checkNotNull(midHauleLatitude, "No LATDD for operation " + operationId);
Float midHauleLongitude = (Float) row.get("LGDD");
- Preconditions.checkNotNull(midHauleLongitude);
+ Preconditions.checkNotNull(midHauleLongitude, "No LGDD for operation " + operationId);
Date shootingStartTime = (Date) row.get("DHTUDEB");
Date shootingEndTime = (Date) row.get("DHTUFIN");
1
0
r209 - trunk/echobase-entities/src/main/java/fr/ifremer/echobase
by tchemit@users.forge.codelutin.com 20 Dec '11
by tchemit@users.forge.codelutin.com 20 Dec '11
20 Dec '11
Author: tchemit
Date: 2011-12-20 15:22:50 +0100 (Tue, 20 Dec 2011)
New Revision: 209
Url: http://forge.codelutin.com/repositories/revision/echobase/209
Log:
fix some decorators
Modified:
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java 2011-12-20 09:21:01 UTC (rev 208)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java 2011-12-20 14:22:50 UTC (rev 209)
@@ -133,7 +133,7 @@
registerJXPathDecorator(locale, CellType.class, "${name}$s");
// DataMetadata decorator
- registerJXPathDecorator(locale, DataMetadata.class, "${name}$s");
+ registerJXPathDecorator(locale, DataMetadata.class, "${name}$s - ${standardname}$s");
// DataProtocol decorator
registerJXPathDecorator(locale, DataProtocol.class, "${description}$s [ ${validSince}$td/%2$tm/%2$tY - ${invalidSince}$td/%3$tm/%3$tY ]");
@@ -160,7 +160,7 @@
registerJXPathDecorator(locale, GearCharacteristic.class, "${name}$s");
// GearMetadata decorator
- registerJXPathDecorator(locale, GearMetadata.class, "${name}$s");
+ registerJXPathDecorator(locale, GearMetadata.class, "${type}$s (${operationEvent/name}$s)");
// GearCharacteristicValue decorator
registerJXPathDecorator(locale, GearCharacteristicValue.class, "${dataValue}$s");
@@ -169,7 +169,7 @@
registerJXPathDecorator(locale, GearMetadataValue.class, "${dataValue}$s");
// Impacte decorator
- registerJXPathDecorator(locale, Impacte.class, "${measurementUnit}$s - ${species.genusSpecies}");
+ registerJXPathDecorator(locale, Impacte.class, "${measurementUnit}$s - ${species/genusSpecies}");
// LengthAgeKey decorator
registerJXPathDecorator(locale, LengthAgeKey.class, "Age ${age}$s - Length ${length}");
@@ -218,7 +218,7 @@
//TODO
// SpeciesCategory decorator
- registerJXPathDecorator(locale, SpeciesCategory.class, "${species.genusSpecies}$s - ...");
+ registerJXPathDecorator(locale, SpeciesCategory.class, "${species/genusSpecies}$s - ...");
// Strata decorator
registerJXPathDecorator(locale, Strata.class, "Latitude <${minLatitude}$s - ${maxLatitude}$s>, Longitude <${minLongitude}$s - ${maxLongitude}$s>");
@@ -234,7 +234,7 @@
registerJXPathDecorator(locale, VesselType.class, "${name}$s");
// LengthWeightKey decorator
- registerJXPathDecorator(locale, LengthWeightKey.class, "Species ${species.genusSpecies}$s - a=${aParameter}$s, b=${bParameter}$s");
+ registerJXPathDecorator(locale, LengthWeightKey.class, "Species ${species/genusSpecies}$s - a=${aParameter}$s, b=${bParameter}$s");
// Cell decorator
registerJXPathDecorator(locale, Cell.class, "${name}$s");
@@ -254,7 +254,7 @@
registerJXPathDecorator(locale, Operation.class, "${startDate}$td/%1$tm/%1$tY - ${endDate}$td/%2$tm/%2$tY");
// OperationMetadataValue decorator
- registerJXPathDecorator(locale, OperationMetadataValue.class, "${dataValue}$s - moment ${moment.name}");
+ registerJXPathDecorator(locale, OperationMetadataValue.class, "${operationMetadata/name} - ${dataValue}$s");
// Result decorator
registerJXPathDecorator(locale, Result.class, "${resultvalue}$s");
1
0