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
- 1820 discussions
r142 - in trunk/echobase-services/src: main/java/fr/ifremer/echobase/services main/java/fr/ifremer/echobase/services/models main/resources test/java/fr/ifremer/echobase test/java/fr/ifremer/echobase/services test/resources
by tchemit@users.forge.codelutin.com 05 Dec '11
by tchemit@users.forge.codelutin.com 05 Dec '11
05 Dec '11
Author: tchemit
Date: 2011-12-05 09:24:55 +0100 (Mon, 05 Dec 2011)
New Revision: 142
Url: http://forge.codelutin.com/repositories/revision/echobase/142
Log:
-Introduce models package
-remove dummy db configuration file
-begin of implementation of import/export of global db
-use same code for import/export of a entity and load/save it
Added:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportExportService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/CsvModelUtil.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityCsvModel.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportSqlCsvModel.java
trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/DbImportExportServiceTest.java
Removed:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvModelUtil.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorCsvModel.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlCsvModel.java
trunk/echobase-services/src/main/resources/echobase-db.properties
trunk/echobase-services/src/test/resources/echobase.properties
Modified:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvImportResult.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DecoratorService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceContextImpl.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/ExportSqlService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportHistoricalService.java
trunk/echobase-services/src/test/java/fr/ifremer/echobase/TestHelper.java
trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvImportResult.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvImportResult.java 2011-12-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvImportResult.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -39,21 +39,35 @@
private static final long serialVersionUID = 1L;
/** type of entity to import csv datas. */
- protected EchoBaseEntityEnum entityType;
+ protected final EchoBaseEntityEnum entityType;
/** Name of the csv file to import. */
- protected String importFileName;
+ protected final String importFileName;
+ /** Flag to authorize to create entities not found in db. */
+ protected final boolean createIfNotFound;
+
/** Count of created entities. */
-
protected int numberCreated;
/** Count of updated entities. */
protected int numberUpdated;
- /** Flag to authorize to create entities not found in db. */
- protected boolean createIfNotFound;
+ public static CsvImportResult newResult(EchoBaseEntityEnum entityType,
+ String importFileName,
+ boolean createIfNotFound) {
+ CsvImportResult result = new CsvImportResult(entityType, importFileName,
+ createIfNotFound);
+ return result;
+ }
+ protected CsvImportResult(EchoBaseEntityEnum entityType,
+ String importFileName,
+ boolean createIfNotFound) {
+ this.entityType = entityType;
+ this.importFileName = importFileName;
+ this.createIfNotFound = createIfNotFound;
+ }
public EchoBaseEntityEnum getEntityType() {
return entityType;
@@ -84,15 +98,4 @@
numberUpdated++;
}
- public void setEntityType(EchoBaseEntityEnum entityType) {
- this.entityType = entityType;
- }
-
- public void setImportFileName(String importFileName) {
- this.importFileName = importFileName;
- }
-
- public void setCreateIfNotFound(boolean createIfNotFound) {
- this.createIfNotFound = createIfNotFound;
- }
}
Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvModelUtil.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvModelUtil.java 2011-12-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvModelUtil.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -1,134 +0,0 @@
-/*
- * #%L
- * EchoBase :: Services
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 Ifremer, Codelutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package fr.ifremer.echobase.services;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Maps;
-import fr.ifremer.echobase.EchoBaseTechnicalException;
-import org.apache.commons.lang3.StringUtils;
-import org.nuiton.topia.persistence.TopiaEntity;
-import org.nuiton.util.csv.Common;
-import org.nuiton.util.csv.ValueFormatter;
-import org.nuiton.util.csv.ValueParserFormatter;
-
-import java.text.ParseException;
-import java.util.Collection;
-import java.util.Locale;
-import java.util.Map;
-
-/**
- * Usefull class to build csv import-export models.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.2
- */
-public class CsvModelUtil extends Common {
-
- public static <E extends TopiaEntity> ForeignKeyValue<E> newForeignKeyValue(Class<E> type) {
- return new ForeignKeyValue<E>(type);
- }
-
- public static <E extends TopiaEntity> ForeignKeyValue<E> newForeignKeyValue(Class<E> type, Collection<E> entitites) {
- return new ForeignKeyValue<E>(type, entitites);
- }
-
- public static <E extends TopiaEntity> ForeignKeyDecoratedValue<E> newForeignKeyDecoratedValue(Class<E> entityType, DecoratorService decoratorService, Locale locale) {
- return new ForeignKeyDecoratedValue<E>(entityType, decoratorService, locale);
- }
-
- public static class ForeignKeyValue<E extends TopiaEntity> implements ValueParserFormatter<E> {
-
- protected final Class<E> entityType;
-
- protected final Map<String, E> universe;
-
- public ForeignKeyValue(Class<E> entityType, Collection<E> entitites) {
- this.entityType = entityType;
- universe = Maps.uniqueIndex(entitites, new Function<E, String>() {
- @Override
- public String apply(E input) {
- return input.getTopiaId();
- }
- });
- }
-
- public ForeignKeyValue(Class<E> entityType) {
- this.entityType = entityType;
- universe = Maps.newHashMap();
- }
-
- @Override
- public E parse(String value) throws ParseException {
- E result = null;
- if (StringUtils.isNotBlank(value)) {
-
- // get entity from universe
- result = universe.get(value);
-
- if (result == null) {
-
- // can not find entity this is a big problem for us...
- throw new EchoBaseTechnicalException(
- "Could not find entity with name " + value);
- }
- }
- return result;
- }
-
- @Override
- public String format(E e) {
- String value = "";
- if (e != null) {
- value = e.getTopiaId();
- }
- return value;
- }
- }
-
- public static class ForeignKeyDecoratedValue<E extends TopiaEntity> implements ValueFormatter<E> {
-
- protected final Class<E> entityType;
-
- protected final DecoratorService decoratorService;
-
- protected final Locale locale;
-
- public ForeignKeyDecoratedValue(Class<E> entityType, DecoratorService decoratorService, Locale locale) {
- this.entityType = entityType;
- this.decoratorService = decoratorService;
- this.locale = locale;
-
- }
-
- @Override
- public String format(E e) {
- String value = "";
- if (e != null) {
-
- value = decoratorService.decorate(locale, e, null);
- }
- return value;
- }
- }
-}
Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorCsvModel.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorCsvModel.java 2011-12-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorCsvModel.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -1,159 +0,0 @@
-/*
- * #%L
- * EchoBase :: Services
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 Ifremer, Codelutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package fr.ifremer.echobase.services;
-
-import fr.ifremer.echobase.entities.meta.TableMeta;
-import org.nuiton.topia.persistence.TopiaEntity;
-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.Date;
-import java.util.List;
-
-/**
- * Import/Export csv model.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.2
- */
-public class DbEditorCsvModel<E extends TopiaEntity> implements ImportExportModel<E> {
-
- protected final char separator;
-
- protected final TableMeta tableMeta;
-
- protected ModelBuilder<E> modelBuilder;
-
- public DbEditorCsvModel(char separator, TableMeta tableMeta) {
- this.separator = separator;
- this.tableMeta = tableMeta;
- modelBuilder = new ModelBuilder<E>();
- }
-
- @Override
- public char getSeparator() {
- return separator;
- }
-
- @Override
- public Collection<ExportableColumn<E, Object>> getColumnsForExport() {
- return (Collection)
- modelBuilder.getColumnsForExport();
- }
-
- @Override
- public Collection<ImportableColumn<E, Object>> getColumnsForImport() {
- return (Collection)
- modelBuilder.getColumnsForImport();
- }
-
- @Override
- public void pushCsvHeaderNames(List<String> headerNames) {
- }
-
- @Override
- public E newEmptyInstance() {
- return (E) tableMeta.newEntity();
- }
-
- public void addForeignKeyForExport(String propertyName,
- Class<TopiaEntity> entityType) {
-
- modelBuilder.newColumnForExport(
- propertyName,
- propertyName,
- CsvModelUtil.newForeignKeyValue(entityType)
- );
- }
-
- public void addForeignKeyForImport(String propertyName,
- Class<TopiaEntity> entityType,
- Collection<TopiaEntity> universe) {
-
- modelBuilder.newMandatoryColumn(
- propertyName,
- propertyName,
- CsvModelUtil.newForeignKeyValue(entityType, universe)
- );
- }
-
- public <E extends TopiaEntity> void addDefaultColumn(String propertyName,
- Class<?> type) {
-
- if (Date.class.equals(type)) {
- modelBuilder.newColumnForImportExport(
- propertyName,
- propertyName,
- CsvModelUtil.DAY_TIME_SECOND
- );
- } else if (float.class.equals(type)) {
- modelBuilder.newColumnForImportExport(
- propertyName,
- propertyName,
- CsvModelUtil.PRIMITIVE_FLOAT
- );
- } else if (Float.class.equals(type)) {
- modelBuilder.newColumnForImportExport(
- propertyName,
- propertyName,
- CsvModelUtil.FLOAT
- );
- } else if (int.class.equals(type)) {
- modelBuilder.newColumnForImportExport(
- propertyName,
- propertyName,
- CsvModelUtil.PRIMITIVE_INTEGER
- );
- } else if (Integer.class.equals(type)) {
- modelBuilder.newColumnForImportExport(
- propertyName,
- propertyName,
- CsvModelUtil.INTEGER
- );
- } else if (boolean.class.equals(type)) {
- modelBuilder.newColumnForImportExport(
- propertyName,
- propertyName,
- CsvModelUtil.PRIMITIVE_BOOLEAN
- );
- } else if (Boolean.class.equals(type)) {
- modelBuilder.newColumnForImportExport(
- propertyName,
- propertyName,
- CsvModelUtil.BOOLEAN
- );
- } else {
-
- // string
- modelBuilder.newColumnForImportExport(
- propertyName,
- propertyName
- );
- }
- }
-
-}
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-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -32,7 +32,8 @@
import fr.ifremer.echobase.entities.meta.ColumnMeta;
import fr.ifremer.echobase.entities.meta.DbMeta;
import fr.ifremer.echobase.entities.meta.TableMeta;
-import org.apache.commons.io.IOUtils;
+import fr.ifremer.echobase.services.models.CsvModelUtil;
+import fr.ifremer.echobase.services.models.EntityCsvModel;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -42,17 +43,13 @@
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.util.beans.BeanMonitor;
import org.nuiton.util.beans.PropertyDiff;
-import org.nuiton.util.csv.Export;
-import org.nuiton.util.csv.ExportableColumn;
-import org.nuiton.util.csv.Import;
-import org.nuiton.util.csv.ImportableColumn;
-import org.nuiton.util.csv.ModelBuilder;
+import org.nuiton.util.csv.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
+import java.io.IOException;
import java.util.Collection;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -88,7 +85,7 @@
}
}
- public TableMeta getTableMetas(EchoBaseEntityEnum tableName) {
+ public TableMeta getTableMeta(EchoBaseEntityEnum tableName) {
DbMeta dbMeta = getDbMeta();
TableMeta result = dbMeta.getTable(tableName);
return result;
@@ -111,9 +108,9 @@
List<E> result;
EchoBaseEntityEnum entityEnum = tableMeta.getEntityEnum();
- Class<? extends TopiaEntity> contract = entityEnum.getContract();
+ Class<E> contract = (Class<E>) entityEnum.getContract();
try {
- TopiaDAO dao = getDAO(contract);
+ TopiaDAO<E> dao = getDAO(contract);
// first query to count datas
TopiaQuery countQuery = dao.createQuery("e");
@@ -163,18 +160,17 @@
Boolean ascendantOrder,
boolean addDecorated) {
- TableMeta tableMeta = getTableMetas(entityType);
+ TableMeta meta = getTableMeta(entityType);
- List<TopiaEntity> entities = getEntities(tableMeta,
- pager,
- sidx,
- ascendantOrder
+ List<TopiaEntity> entities = getEntities(meta,
+ pager,
+ sidx,
+ ascendantOrder
);
Map<?, ?>[] rows = new Map[entities.size()];
- DbEditorCsvModel<TopiaEntity> model =
- buildForLoad(tableMeta, addDecorated);
+ ImportExportModel<TopiaEntity> model = buildForLoad(meta, addDecorated);
int i = 0;
for (Object o : entities) {
@@ -191,23 +187,21 @@
try {
TopiaDAO<?> dao = getDAO(entityEnum.getContract());
TopiaEntity entity = dao.findByTopiaId(topiaId);
- DbEditorCsvModel<TopiaEntity> model = buildForLoad(tableMeta, true);
+ ImportExportModel<TopiaEntity> model = buildForLoad(tableMeta, true);
return loadRow(entity, model);
} catch (TopiaException eee) {
throw new EchoBaseTechnicalException("Could not obtain data", eee);
}
}
- public void saveEntity(TableMeta tableMeta,
- String id,
+ public void saveEntity(TableMeta meta,
Map<String, String> properties,
EchoBaseUser user) {
// transform properties entity
- DbEditorCsvModel<TopiaEntity> model = buildForSave(tableMeta);
+ ImportExportModel<TopiaEntity> model = buildForSave(meta);
TopiaEntity entity = model.newEmptyInstance();
- entity.setTopiaId(id);
for (ImportableColumn<TopiaEntity, Object> column : model.getColumnsForImport()) {
String propertyName = column.getHeaderName();
@@ -221,12 +215,12 @@
try {
column.setValue(entity, o);
} catch (Exception e) {
- throw new EchoBaseTechnicalException("Could not set property [" + propertyName + "] with value " + stringValue + " to entity " + entity);
+ throw new EchoBaseTechnicalException(
+ "Could not set property [" + propertyName + "] with value " + stringValue + " to entity " + entity);
}
}
- saveEntity(
- tableMeta,
+ saveEntity(meta,
"Modification utilisateur",
entity,
user,
@@ -239,31 +233,28 @@
String importFileName,
File importFile,
boolean createIfNotFound,
- EchoBaseUser user) {
- TableMeta tableMeta = getTableMetas(entityType);
- DbEditorCsvModel<TopiaEntity> csvModel = buildForImport(tableMeta);
+ EchoBaseUser user) throws IOException {
+
+ TableMeta meta = getTableMeta(entityType);
+ ImportExportModel<TopiaEntity> csvModel = buildForImport(meta);
String messagePrefix = "Import du fichier " + importFileName + " le " + newDate();
- CsvImportResult result = new CsvImportResult();
- result.setImportFileName(importFileName);
- result.setEntityType(entityType);
- BufferedReader bf = null;
+ CsvImportResult result = CsvImportResult.newResult(entityType,
+ importFileName,
+ createIfNotFound);
+ BufferedReader bf = new BufferedReader(new FileReader(importFile));
try {
- bf = new BufferedReader(new FileReader(importFile));
Import<TopiaEntity> importer = Import.newImport(csvModel, bf);
- Iterator<TopiaEntity> iterator = importer.startImport();
-
try {
- while (iterator.hasNext()) {
- TopiaEntity entity = iterator.next();
- boolean create = saveEntity(tableMeta,
- messagePrefix,
- entity,
- user,
- createIfNotFound
+ for (TopiaEntity entity : importer) {
+ boolean create = saveEntity(meta,
+ messagePrefix,
+ entity,
+ user,
+ createIfNotFound
);
if (create) {
@@ -276,7 +267,7 @@
}
} finally {
- importer.stopImport();
+ importer.close();
}
commitTransaction("Could not commit transaction");
@@ -286,19 +277,18 @@
log.error("Failed to read import file " + importFile.getName(), eee);
throw new EchoBaseTechnicalException(eee);
} finally {
- IOUtils.closeQuietly(bf);
+ bf.close();
}
-
return result;
}
public String exportDatas(EchoBaseEntityEnum entityType) {
- TableMeta tableMeta = getTableMetas(entityType);
+ TableMeta tableMeta = getTableMeta(entityType);
List<TopiaEntity> datas = getEntities(tableMeta, null, null, null);
- DbEditorCsvModel<TopiaEntity> model = buildForExport(tableMeta);
+ ImportExportModel<TopiaEntity> model = buildForExport(tableMeta);
Export<TopiaEntity> export = Export.newExport(model, datas);
@@ -314,7 +304,6 @@
TopiaEntity entity,
EchoBaseUser user,
boolean createIfNotFound) {
-
String[] columnNames = tableMeta.getColumnNamesAsArray();
BeanMonitor monitor = null;
@@ -340,7 +329,8 @@
if (!createIfNotFound) {
// this is an error
- throw new EchoBaseTechnicalException("Could not found entity with id " + id);
+ throw new EchoBaseTechnicalException(
+ "Could not found entity with id " + id);
} else {
entityToSave = dao.create(TopiaEntity.TOPIA_ID, id);
create = true;
@@ -358,7 +348,7 @@
tableMeta.copy(entity, entityToSave);
PropertyDiff[] propertyDiffs = monitor == null ? null :
- monitor.getPropertyDiffs();
+ monitor.getPropertyDiffs();
createEntityModificationLog(
tableMeta,
@@ -392,7 +382,7 @@
buffer = new StringBuilder(messagePrefix + "\n");
if (create) {
- buffer.append("Une entité à été crée d'identifiant ").append(topiaId);
+ buffer.append("Une entité a été crée d'identifiant ").append(topiaId);
} else {
int length = propertyDiffs.length;
@@ -423,9 +413,9 @@
}
}
buffer.append(String.format("\n Propriété '%s', ancienne valeur : %s, nouvelle valeur : %s",
- propertyName,
- sourceValue,
- targetValue
+ propertyName,
+ sourceValue,
+ targetValue
));
}
}
@@ -436,7 +426,7 @@
dao.create(
EntityModificationLog.PROPERTY_ENTITY_TYPE, tableMeta.getEntityEnum().name(),
EntityModificationLog.PROPERTY_ENTITY_ID, topiaId,
- EntityModificationLog.PROPERTY_MODIFICATION_USER, user,
+ EntityModificationLog.PROPERTY_MODIFICATION_USER, user.getEmail(),
EntityModificationLog.PROPERTY_MODIFICATION_DATE, newDate(),
EntityModificationLog.PROPERTY_MODIFICATION_TEXT, buffer.toString()
);
@@ -444,7 +434,7 @@
protected <E extends TopiaEntity> Map<String, Object> loadRow(
E entity,
- DbEditorCsvModel<E> loadModel) {
+ ImportExportModel<E> loadModel) {
Map<String, Object> row = Maps.newLinkedHashMap();
@@ -459,7 +449,7 @@
} catch (Exception eee) {
throw new EchoBaseTechnicalException(
"Could not obtain property [" + propertyName +
- "] value ", eee);
+ "] value ", eee);
}
String formatedValue = column.formatValue(value);
row.put(propertyName, formatedValue);
@@ -468,19 +458,15 @@
return row;
}
- protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForImport(TableMeta tableMetas) {
+ public <E extends TopiaEntity> ImportExportModel<E> buildForImport(TableMeta meta) {
- DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvSeparator(),
- tableMetas);
-
- ModelBuilder<E> modelBuilder = model.modelBuilder;
-
- modelBuilder.newColumnForImportExport(
- TopiaEntity.TOPIA_ID,
+ EntityCsvModel<E> model = EntityCsvModel.newModel(
+ getConfiguration().getCsvSeparator(),
+ meta,
TopiaEntity.TOPIA_ID
);
- for (ColumnMeta columnMeta : model.tableMeta) {
+ for (ColumnMeta columnMeta : meta) {
String propertyName = columnMeta.getName();
Class<?> type = columnMeta.getType();
if (columnMeta.isFK()) {
@@ -495,30 +481,22 @@
return model;
}
- protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForSave(TableMeta tableMetas) {
+ public <E extends TopiaEntity> ImportExportModel<E> buildForExport(TableMeta meta) {
- DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvSeparator(),
- tableMetas);
-
- ModelBuilder<E> modelBuilder = model.modelBuilder;
-
- modelBuilder.newColumnForExport(
- TopiaEntity.TOPIA_ID,
+ EntityCsvModel<E> model = EntityCsvModel.newModel(
+ getConfiguration().getCsvSeparator(),
+ meta,
TopiaEntity.TOPIA_ID
);
- for (ColumnMeta columnMeta : model.tableMeta) {
+
+ 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);
-
- // translate foreign key to his id
- model.addForeignKeyForImport(propertyName, entityType, universe);
-
+ model.addForeignKeyForExport(propertyName, entityType);
} else {
model.addDefaultColumn(propertyName, type);
}
@@ -526,25 +504,25 @@
return model;
}
- protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForExport(TableMeta tableMetas) {
+ protected <E extends TopiaEntity> ImportExportModel<E> buildForSave(TableMeta meta) {
- DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvSeparator(),
- tableMetas);
-
- ModelBuilder<E> modelBuilder = model.modelBuilder;
-
- modelBuilder.newColumnForImportExport(
- TopiaEntity.TOPIA_ID,
+ EntityCsvModel<E> model = EntityCsvModel.newModel(
+ getConfiguration().getCsvSeparator(),
+ meta,
TopiaEntity.TOPIA_ID
);
- for (ColumnMeta columnMeta : model.tableMeta) {
+ 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);
+ Collection<TopiaEntity> universe = getForeignDatas(entityType);
+
+ // translate foreign key to his id
+ model.addForeignKeyForImport(propertyName, entityType, universe);
+
} else {
model.addDefaultColumn(propertyName, type);
}
@@ -552,20 +530,16 @@
return model;
}
- protected <E extends TopiaEntity> DbEditorCsvModel<E> buildForLoad(TableMeta tableMetas,
- boolean addDecorated) {
+ protected <E extends TopiaEntity> ImportExportModel<E> buildForLoad(TableMeta meta,
+ boolean addDecorated) {
- DbEditorCsvModel<E> model = new DbEditorCsvModel<E>(getConfiguration().getCsvSeparator(),
- tableMetas);
-
- ModelBuilder<E> modelBuilder = model.modelBuilder;
-
- modelBuilder.newColumnForImportExport(
- "id",
- TopiaEntity.TOPIA_ID
+ EntityCsvModel<E> model = EntityCsvModel.newModel(
+ getConfiguration().getCsvSeparator(),
+ meta,
+ "id"
);
- for (ColumnMeta columnMeta : model.tableMeta) {
+ for (ColumnMeta columnMeta : meta) {
String propertyName = columnMeta.getName();
Class<?> type = columnMeta.getType();
if (columnMeta.isFK()) {
@@ -578,7 +552,7 @@
if (addDecorated) {
// translate foreign key to his decorated value
- modelBuilder.newColumnForExport(
+ model.addNewColumnForExport(
propertyName + "_lib",
propertyName,
CsvModelUtil.newForeignKeyDecoratedValue(
@@ -594,5 +568,4 @@
}
return model;
}
-
}
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportExportService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportExportService.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportExportService.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -0,0 +1,441 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 Ifremer, Codelutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package fr.ifremer.echobase.services;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import fr.ifremer.echobase.EchoBaseTechnicalException;
+import fr.ifremer.echobase.entities.EchoBaseDAOHelper;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
+import fr.ifremer.echobase.entities.EchoBaseUser;
+import fr.ifremer.echobase.entities.EntitiesUtil;
+import fr.ifremer.echobase.entities.meta.AssociationMeta;
+import fr.ifremer.echobase.entities.meta.TableMeta;
+import fr.ifremer.echobase.services.models.EntityAssociationCsvModel;
+import org.apache.commons.io.FileUtils;
+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.TopiaQuery;
+import org.nuiton.topia.persistence.TopiaDAO;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.FileUtil;
+import org.nuiton.util.csv.Export;
+import org.nuiton.util.csv.Import;
+import org.nuiton.util.csv.ImportExportModel;
+
+import java.io.File;
+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;
+import java.util.zip.ZipFile;
+
+/**
+ * Service to import / export a complete db.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class DbImportExportService extends EchoBaseServiceSupport {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(DbImportExportService.class);
+
+ protected DbEditorService dbEditorService;
+
+ /**
+ * Import a complete db from the given zip file.
+ *
+ * @param file zip file where all csv files are located
+ * @param user user which perform the import
+ * @throws IOException if any io exception while import
+ */
+ public void importDb(File file, EchoBaseUser user) throws IOException {
+
+ ZipFile zipFile = new ZipFile(file);
+ try {
+ FileEntry[] entries = getEntries();
+
+ List<String> missingEntries = Lists.newArrayList();
+
+ Map<FileEntry, ZipEntry> entriestoConsume = Maps.newLinkedHashMap();
+
+ // check that all mandatories
+ for (FileEntry entry : entries) {
+ String filename = entry.getFilename();
+ ZipEntry zipEntry = zipFile.getEntry(filename);
+
+ if (zipEntry == null) {
+ missingEntries.add(filename);
+ } else {
+ entriestoConsume.put(entry, zipEntry);
+ }
+ }
+
+ if (!missingEntries.isEmpty()) {
+
+ // there is some missing file entries
+ throw new EchoBaseTechnicalException(
+ "There is some missing mandatory files " +
+ missingEntries + " in import " + file);
+ }
+
+ // consume all found entries
+ for (Map.Entry<FileEntry, ZipEntry> entry :
+ entriestoConsume.entrySet()) {
+
+ FileEntry entryDef = entry.getKey();
+ ZipEntry value = entry.getValue();
+ CsvImportResult csvResult = CsvImportResult.newResult(
+ entryDef.getSource(),
+ value.getName(),
+ false
+ );
+ Reader reader =
+ new InputStreamReader(zipFile.getInputStream(value));
+ try {
+ importFile(entryDef, reader, csvResult);
+ } finally {
+ reader.close();
+ }
+ }
+
+ // add a log entry of import db
+ if (log.isInfoEnabled()) {
+ log.info("Import done with user " + user.getEmail());
+ }
+ commitTransaction("Could not commit db import " + file);
+ } finally {
+ zipFile.close();
+ }
+ }
+
+ /**
+ * Export the complete db into csv files stored in a zip archive file.
+ *
+ * @param fileName file name of the zip to create
+ * @return the zip archive file
+ */
+ public File exportDb(String fileName) {
+ File tempDirectory = new File(FileUtils.getTempDirectory(),
+ "echobase-exportDb_" + System.nanoTime());
+ tempDirectory.deleteOnExit();
+
+ File zipFile = new File(tempDirectory, fileName + ".zip");
+
+ FileEntry[] entries = getEntries();
+ for (FileEntry entry : entries) {
+
+ EchoBaseEntityEnum source = entry.getSource();
+
+ File entryFile = new File(tempDirectory, entry.getFilename());
+
+ List<TopiaEntity> entities = entry.getDatas(getTransaction());
+ if (log.isInfoEnabled()) {
+ log.info("Export " + entities + " entities of type " +
+ source + " to " + entryFile);
+ }
+
+ exportFile(entry, entryFile, entities);
+ }
+
+ compressZipFile(zipFile, tempDirectory);
+
+ return zipFile;
+ }
+
+ protected void importFile(FileEntry entry,
+ Reader reader,
+ CsvImportResult csvResult) throws IOException {
+
+ EchoBaseEntityEnum source = entry.getSource();
+
+ DbEditorService service = getDbEditorService();
+
+ TableMeta tableMeta = getTableMeta(source);
+
+ if (entry.isAssociation()) {
+
+ // load a association input
+
+ AssociationMeta associationMeta =
+ tableMeta.getAssociations(entry.getPropertyName());
+
+ ImportExportModel<TopiaEntity> model =
+ EntityAssociationCsvModel.newModel(
+ getConfiguration().getCsvSeparator(),
+ associationMeta
+ );
+
+ importEntityAssociation(associationMeta, model, csvResult, reader);
+
+ } else {
+
+ // normal entity table import
+
+ ImportExportModel<TopiaEntity> model = service.buildForImport(tableMeta);
+
+ importEntities(tableMeta, model, csvResult, reader);
+ }
+ }
+
+ protected void exportFile(FileEntry entry,
+ File entryFile,
+ List<TopiaEntity> entities) {
+ ImportExportModel<TopiaEntity> model;
+
+ TableMeta meta = getTableMeta(entry.getSource());
+
+ if (entry.isAssociation()) {
+ AssociationMeta associationMeta =
+ meta.getAssociations(entry.getPropertyName());
+
+ model = EntityAssociationCsvModel.newModel(
+ getConfiguration().getCsvSeparator(),
+ associationMeta
+ );
+
+ } else {
+
+ model = getDbEditorService().buildForExport(meta);
+ }
+
+ Export<TopiaEntity> export = Export.newExport(model, entities);
+
+ try {
+ String entryFileContent = export.startExportAsString();
+ FileUtil.writeString(entryFile, entryFileContent, "utf-8");
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException("Can not export datas", eee);
+ }
+ }
+
+
+ protected TableMeta getTableMeta(EchoBaseEntityEnum tableName) {
+ return getDbEditorService().getTableMeta(tableName);
+ }
+
+ public FileEntry[] getEntries() {
+
+ List<FileEntry> result = Lists.newArrayList();
+
+ addEntries(result, EntitiesUtil.getReferenceTypesForCopy());
+ addEntries(result, EntitiesUtil.getDataTypesforCopy());
+ return result.toArray(new FileEntry[result.size()]);
+ }
+
+ protected void addEntries(List<FileEntry> result, EchoBaseEntityEnum[] types) {
+ for (EchoBaseEntityEnum type : types) {
+
+ TableMeta tableMeta = getTableMeta(type);
+
+ result.add(FileEntry.newEntry(tableMeta));
+
+ for (AssociationMeta associationMeta : tableMeta.getAssociations()) {
+ result.add(FileEntry.newEntry(associationMeta));
+ }
+
+ }
+ }
+
+ protected DbEditorService getDbEditorService() {
+ if (dbEditorService == null) {
+ dbEditorService = newService(DbEditorService.class);
+ }
+ return dbEditorService;
+ }
+
+ public void importEntities(TableMeta meta,
+ ImportExportModel<TopiaEntity> csvModel,
+ CsvImportResult result,
+ Reader reader) {
+
+ Import<TopiaEntity> importer = Import.newImport(csvModel, reader);
+
+
+ try {
+ TopiaDAO<TopiaEntity> dao = getDAO(meta.getEntityEnum());
+
+ for (TopiaEntity entity : importer) {
+
+
+ TopiaEntity entityToSave = dao.create(TopiaEntity.TOPIA_ID,
+ entity.getTopiaId());
+
+ meta.copy(entity, entityToSave);
+
+ result.incrementsNumberUpdated();
+ }
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException("Could not import entities of type " + meta.getEntityEnum(), eee);
+ } finally {
+
+ importer.close();
+ }
+ }
+
+ protected <E extends TopiaEntity> void importEntityAssociation(AssociationMeta meta,
+ ImportExportModel<E> csvModel,
+ CsvImportResult result,
+ Reader reader) {
+
+ try {
+
+ EchoBaseEntityEnum sourceType = meta.getSource();
+ EchoBaseEntityEnum targetType = meta.getTarget();
+
+ Import<E> importer = Import.newImport(csvModel, reader);
+ TopiaDAO<TopiaEntity> sourceDAO = getDAO(sourceType);
+ TopiaDAO<TopiaEntity> targetDAO = getDAO(targetType);
+
+ try {
+ for (E row : importer) {
+
+ TopiaEntity entityToSave =
+ sourceDAO.findByTopiaId(row.getTopiaId());
+
+ // check entity exits ?
+ if (entityToSave == null) {
+ throw new EchoBaseTechnicalException(
+ "Could not find entity with id " + row.getTopiaId());
+ }
+ Collection<TopiaEntity> assoc = meta.getChilds(row);
+ Collection<TopiaEntity> associationToSave = Lists.newArrayList();
+ for (TopiaEntity topiaEntity : assoc) {
+ TopiaEntity byTopiaId = targetDAO.findByTopiaId(topiaEntity.getTopiaId());
+ if (byTopiaId == null) {
+ throw new EchoBaseTechnicalException(
+ "Could not find entity with id " + topiaEntity.getTopiaId());
+ }
+ associationToSave.add(byTopiaId);
+ result.incrementsNumberUpdated();
+ }
+ meta.setChilds(entityToSave, associationToSave);
+ }
+ } finally {
+
+ importer.close();
+ }
+
+ commitTransaction("Could not commit transaction");
+ } catch (TopiaException eee) {
+ throw new EchoBaseTechnicalException(eee);
+ }
+ }
+
+ public static class FileEntry {
+
+ public static FileEntry newEntry(TableMeta tableMeta) {
+ return newEntry(tableMeta.getEntityEnum(), null, null);
+ }
+
+ public static FileEntry newEntry(AssociationMeta tableMeta) {
+ return newEntry(tableMeta.getSource(), tableMeta.getTarget(), tableMeta.getName());
+ }
+
+ public static FileEntry newEntry(EchoBaseEntityEnum source,
+ EchoBaseEntityEnum target,
+ String propertyName) {
+ return new FileEntry(source, target, propertyName);
+ }
+
+ final EchoBaseEntityEnum source;
+
+ final EchoBaseEntityEnum target;
+
+ final String propertyName;
+
+ protected CsvImportResult importResult;
+
+ FileEntry(EchoBaseEntityEnum source,
+ EchoBaseEntityEnum target,
+ String propertyName) {
+
+ this.source = source;
+ this.target = target;
+ this.propertyName = propertyName;
+ }
+
+ public EchoBaseEntityEnum getSource() {
+ return source;
+ }
+
+ public EchoBaseEntityEnum getTarget() {
+ return target;
+ }
+
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ public boolean isAssociation() {
+ return target != null && propertyName != null;
+ }
+
+ public String getFilename() {
+ String result;
+ if (isAssociation()) {
+ result = source.name() + "_" + propertyName + "_" + target.name();
+ } else {
+ result = source.name();
+ }
+ return result + ".csv";
+ }
+
+ public CsvImportResult getImportResult() {
+ return importResult;
+ }
+
+ public void setImportResult(CsvImportResult importResult) {
+ this.importResult = importResult;
+ }
+
+ public List<TopiaEntity> getDatas(TopiaContext transaction) {
+
+ try {
+ TopiaDAO<TopiaEntity> dao = EchoBaseDAOHelper.<TopiaEntity, TopiaDAO<TopiaEntity>>getDAO(transaction, (Class<TopiaEntity>) source.getContract());
+
+ List<TopiaEntity> result;
+ if (isAssociation()) {
+
+ // filter only entities with some data in the association
+ TopiaQuery query = dao.createQuery("e");
+ query.addWhere("size(e." + propertyName + ") > 0");
+ result = dao.findAllByQuery(query);
+ } else {
+ result = dao.findAll();
+ }
+ return result;
+ } catch (TopiaException eee) {
+ throw new EchoBaseTechnicalException("Could not obtain datas for " + this, eee);
+ }
+ }
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportExportService.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/DecoratorService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DecoratorService.java 2011-12-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DecoratorService.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -64,7 +64,7 @@
Preconditions.checkNotNull(
decorator,
"Could not find decorator for type " + type +
- " and context " + context
+ " and context " + context
);
return decorator;
}
@@ -107,7 +107,7 @@
Preconditions.checkNotNull(
decorator,
"Could not find decorator for type " + object.getClass() +
- " and context " + context
+ " and context " + context
);
DecoratorUtil.sort((JXPathDecorator<O>) decorator, list, 0);
}
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceContextImpl.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceContextImpl.java 2011-12-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceContextImpl.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -52,10 +52,10 @@
EchoBaseServiceContext serviceContext,
TopiaContext transaction) {
return newContext(serviceContext.getLocale(),
- transaction,
- serviceContext.getConfiguration(),
- serviceContext.getDbMeta(),
- serviceContext.getServiceFactory()
+ transaction,
+ serviceContext.getConfiguration(),
+ serviceContext.getDbMeta(),
+ serviceContext.getServiceFactory()
);
}
@@ -66,10 +66,10 @@
DbMeta dbMeta,
EchoBaseServiceFactory serviceFactory) {
return new EchoBaseServiceContextImpl(locale,
- transaction,
- configuration,
- dbMeta,
- serviceFactory);
+ transaction,
+ configuration,
+ dbMeta,
+ serviceFactory);
}
protected EchoBaseServiceContextImpl(Locale locale,
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-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -35,7 +35,11 @@
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.FileUtil;
+import org.nuiton.util.ZipUtil;
+import java.io.File;
+import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Locale;
@@ -73,7 +77,7 @@
} catch (TopiaException eee) {
throw new EchoBaseTechnicalException(
"Could not obtain data of id [" + id + "] for type " +
- entityType, eee);
+ entityType, eee);
}
}
@@ -125,4 +129,15 @@
return result;
}
+ protected void compressZipFile(File zipFile, File directory) {
+ try {
+ ZipUtil.compress(zipFile, directory);
+ } catch (IOException eee) {
+ throw new EchoBaseTechnicalException(
+ "Can not create zip file " + zipFile, eee);
+ } finally {
+ FileUtil.deleteRecursively(directory);
+ }
+ }
+
}
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-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -39,13 +39,8 @@
import org.nuiton.topia.replication.TopiaReplicationService;
import org.nuiton.topia.replication.model.ReplicationModel;
import org.nuiton.util.FileUtil;
-import org.nuiton.util.ZipUtil;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import java.io.*;
import java.net.URISyntaxException;
import java.util.List;
@@ -88,7 +83,7 @@
File warLocation = getConfiguration().getWarLocation();
File tempDirectory = new File(FileUtils.getTempDirectory(),
- "echobase-embedded_" + System.nanoTime());
+ "echobase-embedded_" + System.nanoTime());
tempDirectory.deleteOnExit();
File zipDirectory = new File(tempDirectory, fileName);
@@ -97,7 +92,7 @@
if (log.isInfoEnabled()) {
log.info("Creates zip file [" + zipFile + "] from directory " +
- zipDirectory);
+ zipDirectory);
}
try {
// create /
@@ -118,19 +113,11 @@
} catch (Exception eee) {
throw new EchoBaseTechnicalException(
"Could not create zip structure at location " +
- zipDirectory, eee);
+ zipDirectory, eee);
}
+ compressZipFile(zipFile, zipDirectory);
- try {
- ZipUtil.compress(zipFile, zipDirectory);
- } catch (IOException eee) {
- throw new EchoBaseTechnicalException(
- "Can not create zip file " + zipFile, eee);
- } finally {
- FileUtil.deleteRecursively(zipDirectory);
- }
-
return zipFile;
}
@@ -193,7 +180,7 @@
// create new service context (with new transaction)
EchoBaseServiceContext newServiceContext =
EchoBaseServiceContextImpl.newContext(serviceContext,
- topiaContext);
+ topiaContext);
// get user service from h2 db
UserService userService =
Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlCsvModel.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlCsvModel.java 2011-12-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlCsvModel.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -1,85 +0,0 @@
-/*
- * #%L
- * EchoBase :: Services
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 Ifremer, Codelutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package fr.ifremer.echobase.services;
-
-import org.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();
- }
-}
Modified: 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-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlService.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -26,6 +26,7 @@
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;
@@ -72,7 +73,7 @@
entityToSave.setDescription(exportQuery.getDescription());
entityToSave.setSqlQuery(exportQuery.getSqlQuery());
entityToSave.setLastModifiedDate(newDate());
- entityToSave.setLastModifiedUser(user);
+ entityToSave.setLastModifiedUser(user.getEmail());
dao.update(entityToSave);
getTransaction().commitTransaction();
@@ -103,7 +104,8 @@
sqlQuery.getResult(getTransaction());
return result.toArray(new Map[result.size()]);
} catch (TopiaException eee) {
- throw new EchoBaseTechnicalException("Could not execute sql query", eee);
+ throw new EchoBaseTechnicalException(
+ "Could not execute sql query", eee);
}
}
@@ -121,7 +123,8 @@
String[] result = sqlQuery.getColumnNames(getTransaction());
return result;
} catch (TopiaException eee) {
- throw new EchoBaseTechnicalException("Could not execute query " + limitSql, eee);
+ throw new EchoBaseTechnicalException(
+ "Could not execute query " + limitSql, eee);
}
}
@@ -132,7 +135,8 @@
try {
rows = sqlQuery.getResult(getTransaction());
} catch (TopiaException eee) {
- throw new EchoBaseTechnicalException("Could not execute sql query", eee);
+ throw new EchoBaseTechnicalException(
+ "Could not execute sql query", eee);
}
char csvSeparator = getConfiguration().getCsvSeparator();
ExportSqlCsvModel csvModel = sqlQuery.generateCsvModel(csvSeparator);
@@ -217,7 +221,7 @@
// get row number (getRow() begins at 1)
int rowNumber = set.getRow() - 1;
if (rowNumber < pager.getStartIndex() ||
- rowNumber >= pager.getEndIndex()) {
+ rowNumber >= pager.getEndIndex()) {
// out of pager bound, by returning null
// result will not be take in account
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataService.java 2011-12-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataService.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -49,7 +49,7 @@
try {
Mission result = getDAO(Mission.class).create(mission);
commitTransaction("Could not create mission " +
- mission.getMissionName());
+ mission.getMissionName());
return result;
} catch (TopiaException eee) {
throw new EchoBaseTechnicalException(eee);
@@ -72,7 +72,7 @@
default:
throw new IllegalStateException(
"Can not know what to do with importDataMode " +
- importDataMode);
+ importDataMode);
}
@@ -90,7 +90,7 @@
if (log.isInfoEnabled()) {
log.info("Starts data import with mission " +
- mission.getMissionName());
+ mission.getMissionName());
}
InputFile acousticFile = configuration.getAcousticFile();
@@ -118,7 +118,7 @@
if (log.isInfoEnabled()) {
log.info("Starts data import with mission " +
- mission.getMissionName());
+ mission.getMissionName());
}
InputFile acousticFile = configuration.getAcousticFile();
@@ -208,9 +208,9 @@
InputFile importFile) {
if (log.isInfoEnabled()) {
log.info("Starts " + importFile.getLabel() + " with file " +
- importFile.getFile());
+ importFile.getFile());
}
- CsvImportResult result = new CsvImportResult();
+ CsvImportResult result = CsvImportResult.newResult(null, importFile.getFileName(), false);
prepareImport();
return result;
}
@@ -219,9 +219,9 @@
InputFile importFile) {
if (log.isInfoEnabled()) {
log.info("Starts " + importFile.getLabel() + " with file " +
- importFile.getFile());
+ importFile.getFile());
}
- CsvImportResult result = new CsvImportResult();
+ CsvImportResult result = CsvImportResult.newResult(null, importFile.getFileName(), false);
prepareImport();
return result;
}
@@ -230,9 +230,9 @@
InputFile importFile) {
if (log.isInfoEnabled()) {
log.info("Starts " + importFile.getLabel() + " with file " +
- importFile.getFile());
+ importFile.getFile());
}
- CsvImportResult result = new CsvImportResult();
+ CsvImportResult result = CsvImportResult.newResult(null, importFile.getFileName(), false);
prepareImport();
return result;
}
@@ -241,9 +241,9 @@
InputFile importFile) {
if (log.isInfoEnabled()) {
log.info("Starts " + importFile.getLabel() + " with file " +
- importFile.getFile());
+ importFile.getFile());
}
- CsvImportResult result = new CsvImportResult();
+ CsvImportResult result = CsvImportResult.newResult(null, importFile.getFileName(), false);
prepareImport();
return result;
}
@@ -252,9 +252,9 @@
InputFile importFile) {
if (log.isInfoEnabled()) {
log.info("Starts " + importFile.getLabel() + " with file " +
- importFile.getFile());
+ importFile.getFile());
}
- CsvImportResult result = new CsvImportResult();
+ CsvImportResult result = CsvImportResult.newResult(null, importFile.getFileName(), false);
prepareImport();
return result;
}
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportHistoricalService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportHistoricalService.java 2011-12-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportHistoricalService.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -50,7 +50,7 @@
if (log.isInfoEnabled()) {
log.info("Starts historical import with file " +
- input.getFileName());
+ input.getFileName());
}
try {
@@ -65,7 +65,7 @@
protected CsvImportResult doImport(InputFile input) {
- CsvImportResult result = new CsvImportResult();
+ CsvImportResult result = CsvImportResult.newResult(null, input.getFileName(), false);
prepareImport();
return result;
}
Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/CsvModelUtil.java (from rev 139, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvModelUtil.java)
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/CsvModelUtil.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/CsvModelUtil.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -0,0 +1,185 @@
+/*
+ * #%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 com.google.common.base.Function;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import fr.ifremer.echobase.EchoBaseTechnicalException;
+import fr.ifremer.echobase.services.DecoratorService;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.ObjectUtil;
+import org.nuiton.util.StringUtil;
+import org.nuiton.util.csv.Common;
+import org.nuiton.util.csv.ValueFormatter;
+import org.nuiton.util.csv.ValueParserFormatter;
+
+import java.text.ParseException;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * Usefull class to build csv import-export models.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class CsvModelUtil extends Common {
+
+ public static <E extends TopiaEntity> ForeignKeyValue<E> newForeignKeyValue(Class<E> type) {
+ return new ForeignKeyValue<E>(type);
+ }
+
+ public static <E extends TopiaEntity> ForeignKeyValue<E> newForeignKeyValue(Class<E> type, Collection<E> entitites) {
+ return new ForeignKeyValue<E>(type, entitites);
+ }
+
+ public static <E extends TopiaEntity> ForeignKeyDecoratedValue<E> newForeignKeyDecoratedValue(Class<E> entityType,
+ DecoratorService decoratorService, Locale locale) {
+ return new ForeignKeyDecoratedValue<E>(entityType, decoratorService, locale);
+ }
+
+ public static <E extends TopiaEntity> AssociationValueParserFormatter<E> newAssociationValueParserFormatter(Class<E> type) {
+ return new AssociationValueParserFormatter<E>(type);
+ }
+
+ public static class AssociationValueParserFormatter<E extends TopiaEntity> implements ValueParserFormatter<Collection<E>> {
+
+ protected final Class<E> entityType;
+
+ public AssociationValueParserFormatter(Class<E> entityType) {
+ this.entityType = entityType;
+ }
+
+ @Override
+ public Collection<E> parse(String value) throws ParseException {
+ Collection<E> result = Lists.newArrayList();
+ if (StringUtils.isNotBlank(value)) {
+
+ String[] ids = value.split("|");
+ for (String id : ids) {
+ E association = ObjectUtil.newInstance(entityType);
+ association.setTopiaId(id);
+ result.add(association);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String format(Collection<E> e) {
+ if (CollectionUtils.isEmpty(e)) {
+ return "";
+ }
+ Collection<String> ids = Lists.newArrayList();
+ for (E e1 : e) {
+ ids.add(e1.getTopiaId());
+ }
+ String value = StringUtil.join(ids, "|", true);
+ return value;
+ }
+ }
+
+ public static class ForeignKeyValue<E extends TopiaEntity> implements ValueParserFormatter<E> {
+
+ protected final Class<E> entityType;
+
+ protected final Map<String, E> universe;
+
+ public ForeignKeyValue(Class<E> entityType, Collection<E> entitites) {
+ this.entityType = entityType;
+ universe = Maps.uniqueIndex(entitites, new Function<E, String>() {
+ @Override
+ public String apply(E input) {
+ return input.getTopiaId();
+ }
+ });
+ }
+
+ public ForeignKeyValue(Class<E> entityType) {
+ this.entityType = entityType;
+ universe = Maps.newHashMap();
+ }
+
+ @Override
+ public E parse(String value) throws ParseException {
+ E result = null;
+ if (StringUtils.isNotBlank(value)) {
+
+ // get entity from universe
+ result = universe.get(value);
+
+ if (result == null) {
+
+ // can not find entity this is a big problem for us...
+ throw new EchoBaseTechnicalException(
+ "Could not find entity with name " + value);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public String format(E e) {
+ String value = "";
+ if (e != null) {
+ value = e.getTopiaId();
+ }
+ return value;
+ }
+ }
+
+ public static class ForeignKeyDecoratedValue<E extends TopiaEntity> implements ValueFormatter<E> {
+
+ protected final Class<E> entityType;
+
+ protected final DecoratorService decoratorService;
+
+ protected final Locale locale;
+
+ public ForeignKeyDecoratedValue(Class<E> entityType, DecoratorService decoratorService, Locale locale) {
+ this.entityType = entityType;
+ this.decoratorService = decoratorService;
+ this.locale = locale;
+
+ }
+
+ @Override
+ public String format(E e) {
+ String value = "";
+ if (e != null) {
+
+ value = decoratorService.decorate(locale, e, null);
+ }
+ return value;
+ }
+ }
+
+ protected CsvModelUtil() {
+ // avoid instanciation on helper class
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/CsvModelUtil.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/models/EntityAssociationCsvModel.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -0,0 +1,102 @@
+/*
+ * #%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.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;
+
+/**
+ * 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> EntityAssociationCsvModel<E> newModel(char separator,
+ AssociationMeta meta) {
+ return new EntityAssociationCsvModel<E>(separator, meta);
+ }
+
+ @Override
+ public char getSeparator() {
+ return separator;
+ }
+
+ @Override
+ public Collection<ExportableColumn<E, Object>> getColumnsForExport() {
+ return (Collection)
+ modelBuilder.getColumnsForExport();
+ }
+
+ @Override
+ public Collection<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>();
+
+ // topiaId <-> topiaId
+ modelBuilder.newColumnForImportExport(
+ TopiaEntity.TOPIA_ID,
+ TopiaEntity.TOPIA_ID
+ );
+
+ // add association -> target
+ modelBuilder.newColumnForImportExport(
+ meta.getName(),
+ meta.getName(),
+ CsvModelUtil.newAssociationValueParserFormatter(meta.getTarget().getImplementation())
+ );
+ }
+
+
+}
\ No newline at end of file
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.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/models/EntityCsvModel.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityCsvModel.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityCsvModel.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -0,0 +1,184 @@
+/*
+ * #%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.TableMeta;
+import org.nuiton.topia.persistence.TopiaEntity;
+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.Date;
+import java.util.List;
+
+/**
+ * A model to import / export entities into csv files.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class EntityCsvModel<E extends TopiaEntity> implements ImportExportModel<E> {
+
+ protected final char separator;
+
+ protected final TableMeta tableMeta;
+
+ protected ModelBuilder<E> modelBuilder;
+
+ public static <E extends TopiaEntity> EntityCsvModel<E> newModel(
+ char separator,
+ TableMeta tableMeta,
+ String idHeader
+ ) {
+ return new EntityCsvModel<E>(separator, tableMeta, idHeader);
+ }
+
+ @Override
+ public char getSeparator() {
+ return separator;
+ }
+
+ @Override
+ public Collection<ExportableColumn<E, Object>> getColumnsForExport() {
+ return (Collection)
+ modelBuilder.getColumnsForExport();
+ }
+
+ @Override
+ public Collection<ImportableColumn<E, Object>> getColumnsForImport() {
+ return (Collection)
+ modelBuilder.getColumnsForImport();
+ }
+
+ @Override
+ public void pushCsvHeaderNames(List<String> headerNames) {
+ }
+
+ @Override
+ public E newEmptyInstance() {
+ return (E) tableMeta.newEntity();
+ }
+
+ public void addForeignKeyForExport(String propertyName,
+ Class<TopiaEntity> entityType) {
+
+ modelBuilder.newColumnForExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.newForeignKeyValue(entityType)
+ );
+ }
+
+ public void addForeignKeyForImport(String propertyName,
+ Class<TopiaEntity> entityType,
+ Collection<TopiaEntity> universe) {
+
+ modelBuilder.newMandatoryColumn(
+ propertyName,
+ propertyName,
+ CsvModelUtil.newForeignKeyValue(entityType, universe)
+ );
+ }
+
+ public void addNewColumnForExport(String headerName,
+ String propertyName,
+ CsvModelUtil.ForeignKeyDecoratedValue<TopiaEntity> topiaEntityForeignKeyDecoratedValue) {
+ modelBuilder.newColumnForExport(
+ headerName,
+ propertyName,
+ topiaEntityForeignKeyDecoratedValue
+ );
+ }
+
+ public void addDefaultColumn(String propertyName,
+ Class<?> type) {
+
+ if (Date.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.DAY_TIME_SECOND
+ );
+ } else if (float.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.PRIMITIVE_FLOAT
+ );
+ } else if (Float.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.FLOAT
+ );
+ } else if (int.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.PRIMITIVE_INTEGER
+ );
+ } else if (Integer.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.INTEGER
+ );
+ } else if (boolean.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.PRIMITIVE_BOOLEAN
+ );
+ } else if (Boolean.class.equals(type)) {
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName,
+ CsvModelUtil.BOOLEAN
+ );
+ } else {
+
+ // string
+ modelBuilder.newColumnForImportExport(
+ propertyName,
+ propertyName
+ );
+ }
+ }
+
+ protected EntityCsvModel(char separator,
+ TableMeta tableMeta,
+ String idHeader) {
+ this.separator = separator;
+ this.tableMeta = tableMeta;
+ modelBuilder = new ModelBuilder<E>();
+ modelBuilder.newColumnForImportExport(
+ idHeader,
+ TopiaEntity.TOPIA_ID
+ );
+ }
+
+
+}
\ No newline at end of file
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityCsvModel.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/models/ExportSqlCsvModel.java (from rev 139, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportSqlCsvModel.java)
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportSqlCsvModel.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportSqlCsvModel.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -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.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();
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/ExportSqlCsvModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/echobase-services/src/main/resources/echobase-db.properties
===================================================================
--- trunk/echobase-services/src/main/resources/echobase-db.properties 2011-12-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/main/resources/echobase-db.properties 2011-12-05 08:24:55 UTC (rev 142)
@@ -1,41 +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%
-###
-###
-# DB configuration
-hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
-hibernate.connection.driver_class=org.postgresql.Driver
-hibernate.connection.provider_class=org.nuiton.topia.framework.TopiaConnectionProvider
-hibernate.show_sql=false
-hibernate.format_sql=false
-hibernate.use_sql_comments=false
-hibernate.hbm2ddl.auto=none
-hibernate.connection.username=${configuration.login}
-hibernate.connection.password=${configuration.password}
-hibernate.connection.url=${configuration.url}
-
-# Migration configuration
-topia.service.migration=org.nuiton.topia.migration.TopiaMigrationEngine
-topia.service.migration.callback=fr.ifremer.echobase.services.migration.EchoBaseMigrationCallback
-topia.service.migration.showSql=true
-
Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/TestHelper.java
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/TestHelper.java 2011-12-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/TestHelper.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -23,10 +23,16 @@
*/
package fr.ifremer.echobase;
+import com.google.common.base.Supplier;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import org.apache.commons.io.FileUtils;
import org.junit.Ignore;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.persistence.TopiaEntity;
import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
/**
* Utility methods for tests
@@ -39,6 +45,8 @@
protected static File basedir;
+ protected static final long timestamp = System.currentTimeMillis();
+
public static File getBasedir() {
//FIXME : No we do not want to go in tmp directory :( We want to stay
// inside of the project. So a mvn clean will remove all tests data.
@@ -53,4 +61,38 @@
return basedir;
}
+ public static File getTestBasedir(Class<?> testClass) {
+ File result = new File(getBasedir(), testClass.getName() + "_" + timestamp);
+ return result;
+ }
+
+ public static TopiaContext getRootContext(File dbDir) {
+ EchoBaseTopiaRootContextSupplierFactory factory =
+ new EchoBaseTopiaRootContextSupplierFactory();
+
+ Supplier<TopiaContext> topiaContextSupplier =
+ factory.newEmbeddedDatabase(dbDir);
+ return topiaContextSupplier.get();
+ }
+
+ /**
+ * Used to get all contract of a package
+ *
+ * @param entitiesPackage package contening desired entities
+ * @return contracts contained in entitiesPackage
+ */
+ public static EchoBaseEntityEnum[] getContractsOf(Package entitiesPackage) {
+ EchoBaseEntityEnum[] echoBaseEntityEnums = EchoBaseEntityEnum.values();
+ List<EchoBaseEntityEnum> refClasses = new ArrayList<EchoBaseEntityEnum>();
+ for (EchoBaseEntityEnum echoBaseEntityEnum : echoBaseEntityEnums) {
+
+ // Get all entities in package fr.ifremer.echobase.entities.references
+ Class<? extends TopiaEntity> contract = echoBaseEntityEnum.getContract();
+ if (entitiesPackage.equals(contract.getPackage())) {
+ refClasses.add(echoBaseEntityEnum);
+ }
+ }
+ return refClasses.toArray(new EchoBaseEntityEnum[refClasses.size()]);
+ }
+
}
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-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -50,8 +50,11 @@
public abstract class AbstractEchoBaseServiceTest extends Assert {
protected TopiaContext transaction;
+
protected EchoBaseConfiguration config;
+
protected EchoBaseServiceFactory serviceFactory;
+
protected DbMeta dbMeta;
@After
@@ -92,7 +95,7 @@
if (dbMeta == null) {
List<EchoBaseEntityEnum> entityEnums =
Lists.newArrayList(EchoBaseEntityEnum.values());
- dbMeta = new DbMeta(entityEnums.toArray(new EchoBaseEntityEnum[entityEnums.size()]));
+ dbMeta = DbMeta.newDbMeta(entityEnums);
}
return dbMeta;
}
Added: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/DbImportExportServiceTest.java
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/DbImportExportServiceTest.java (rev 0)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/DbImportExportServiceTest.java 2011-12-05 08:24:55 UTC (rev 142)
@@ -0,0 +1,161 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 Ifremer, Codelutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package fr.ifremer.echobase.services;
+
+import com.google.common.collect.Sets;
+import fr.ifremer.echobase.TestHelper;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
+import fr.ifremer.echobase.entities.EntitiesUtil;
+import junit.framework.Assert;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.persistence.TopiaEntityEnum;
+import org.nuiton.topia.replication.TopiaReplicationModelBuilder;
+import org.nuiton.topia.replication.model.ReplicationModel;
+import org.nuiton.topia.replication.model.ReplicationNode;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Test the {@link DbImportExportService}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class DbImportExportServiceTest {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(DbImportExportServiceTest.class);
+
+ @Rule
+ public TestName testName = new TestName();
+
+ protected File testdir;
+
+ protected TopiaContext rootContext;
+
+ @Before
+ public void setUp() throws Exception {
+ testdir = new File(TestHelper.getTestBasedir(getClass()),
+ testName.getMethodName());
+ if (log.isInfoEnabled()) {
+ log.info("Test directory = " + testdir);
+ }
+// rootContext = TestHelper.getRootContext(testdir);
+ }
+
+ @Test
+ public void testGetReferentielCopyModel() throws TopiaException {
+
+ EchoBaseEntityEnum[] types = EntitiesUtil.getReferenceTypesForCopy();
+ Set<TopiaEntityEnum> dones = Sets.newHashSet();
+
+ ReplicationModel model = new ReplicationModel(types, false);
+ new TopiaReplicationModelBuilder().initModel(model, false);
+ List<ReplicationNode> order = model.getOrder();
+
+ StringBuilder buffer = new StringBuilder();
+ for (ReplicationNode node : order) {
+ TopiaEntityEnum type = node.getContract();
+ Assert.assertTrue(type + " was already treated.", dones.add(type));
+ Collection<ReplicationNode> dependencies = node.getDependencies().values();
+ for (ReplicationNode dependency : node.getDependencies().values()) {
+ TopiaEntityEnum dependencyType = dependency.getContract();
+ Assert.assertTrue(dependencyType +
+ " was detected as a dependency of node " +
+ type + " but was not still registred",
+ dones.contains(dependencyType));
+ }
+ Collection<ReplicationNode> assocations = node.getAssociations().values();
+ for (ReplicationNode assocation : assocations) {
+ TopiaEntityEnum assocationType = assocation.getContract();
+ Assert.assertTrue(assocationType +
+ " was detected as a association of node " +
+ type + " but was not still registred",
+ dones.contains(assocationType));
+ }
+ buffer.append('\n');
+ buffer.append(type);
+ buffer.append(" - ");
+ buffer.append(dependencies);
+ buffer.append(" - ");
+ buffer.append(assocations);
+ }
+ if (log.isInfoEnabled()) {
+ log.info(buffer.toString());
+ }
+ }
+
+ @Test
+ public void testGetDataCopyModel() throws TopiaException {
+
+ EchoBaseEntityEnum[] types = EntitiesUtil.getDataTypesforCopy();
+ Set<TopiaEntityEnum> dones = Sets.newHashSet();
+
+ ReplicationModel model = new ReplicationModel(types, false);
+ new TopiaReplicationModelBuilder().initModel(model, false);
+ List<ReplicationNode> order = model.getOrder();
+
+ StringBuilder buffer = new StringBuilder();
+ for (ReplicationNode node : order) {
+ TopiaEntityEnum type = node.getContract();
+ Assert.assertTrue(type + " was already treated.", dones.add(type));
+ Collection<ReplicationNode> dependencies = node.getDependencies().values();
+ for (ReplicationNode dependency : node.getDependencies().values()) {
+ TopiaEntityEnum dependencyType = dependency.getContract();
+ Assert.assertTrue(dependencyType +
+ " was detected as a dependency of node " +
+ type + " but was not still registred",
+ dones.contains(dependencyType));
+ }
+ Collection<ReplicationNode> assocations = node.getAssociations().values();
+ for (ReplicationNode assocation : assocations) {
+ TopiaEntityEnum assocationType = assocation.getContract();
+ Assert.assertTrue(assocationType +
+ " was detected as a association of node " +
+ type + " but was not still registred",
+ dones.contains(assocationType));
+ }
+ buffer.append('\n');
+ buffer.append(type);
+ buffer.append(" - ");
+ buffer.append(dependencies);
+ buffer.append(" - ");
+ buffer.append(assocations);
+ }
+ if (log.isInfoEnabled()) {
+ log.info(buffer.toString());
+ }
+ }
+}
Property changes on: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/DbImportExportServiceTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/echobase-services/src/test/resources/echobase.properties
===================================================================
--- trunk/echobase-services/src/test/resources/echobase.properties 2011-12-05 08:22:27 UTC (rev 141)
+++ trunk/echobase-services/src/test/resources/echobase.properties 2011-12-05 08:24:55 UTC (rev 142)
@@ -1,24 +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%
-###
-data.directory=${java.io.tmpdir}
\ No newline at end of file
1
0
r141 - in trunk/echobase-entities/src: main/java/fr/ifremer/echobase/entities main/java/fr/ifremer/echobase/entities/meta main/resources main/xmi test/resources
by tchemit@users.forge.codelutin.com 05 Dec '11
by tchemit@users.forge.codelutin.com 05 Dec '11
05 Dec '11
Author: tchemit
Date: 2011-12-05 09:22:27 +0100 (Mon, 05 Dec 2011)
New Revision: 141
Url: http://forge.codelutin.com/repositories/revision/echobase/141
Log:
-add AssociationMeta
-denormalize ExportSql and ModificationLog entities (no more FK on EchoBaseUser)
-add replication service configuration (but may not be used...)
-add entities order to import/export global db
Added:
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java
Removed:
trunk/echobase-entities/src/test/resources/echobase.properties
Modified:
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntityModificationLogImpl.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/ExportQueryImpl.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/ColumnMeta.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/TableMeta.java
trunk/echobase-entities/src/main/resources/topia-h2.properties
trunk/echobase-entities/src/main/xmi/echobase.zargo
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-05 06:42:35 UTC (rev 140)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java 2011-12-05 08:22:27 UTC (rev 141)
@@ -55,62 +55,115 @@
result.add(EchoBaseEntityEnum.Result);
result.add(EchoBaseEntityEnum.Operation);
result.add(EchoBaseEntityEnum.OperationMetadataValue);
- result.add(EchoBaseEntityEnum.Individual);
result.add(EchoBaseEntityEnum.OperationGearMetadataValue);
result.add(EchoBaseEntityEnum.Sample);
result.add(EchoBaseEntityEnum.SampleData);
- result.add(EchoBaseEntityEnum.SampleAge);
return result.toArray(new EchoBaseEntityEnum[result.size()]);
}
/**
+ * @return the entity types of data in correct order for replication
+ * purpose.
+ */
+ public static EchoBaseEntityEnum[] getDataTypesforCopy() {
+
+ List<EchoBaseEntityEnum> result = Lists.newLinkedList();
+
+ result.add(EchoBaseEntityEnum.SampleData);
+ result.add(EchoBaseEntityEnum.Sample);
+
+ result.add(EchoBaseEntityEnum.OperationMetadataValue);
+ result.add(EchoBaseEntityEnum.OperationGearMetadataValue);
+ result.add(EchoBaseEntityEnum.Operation);
+
+ result.add(EchoBaseEntityEnum.Data);
+ result.add(EchoBaseEntityEnum.Result);
+ result.add(EchoBaseEntityEnum.Cell);
+ result.add(EchoBaseEntityEnum.DataProcessing);
+ result.add(EchoBaseEntityEnum.DataAcquisition);
+ result.add(EchoBaseEntityEnum.TransectAcousticInstrument);
+ result.add(EchoBaseEntityEnum.Transect);
+ result.add(EchoBaseEntityEnum.TransitVessel);
+ result.add(EchoBaseEntityEnum.Transit);
+ result.add(EchoBaseEntityEnum.Voyage);
+
+ return result.toArray(new EchoBaseEntityEnum[result.size()]);
+ }
+
+ /**
* @return the entity types of reference in correct order for replication
* purpose.
*/
public static EchoBaseEntityEnum[] getReferenceTypes() {
List<EchoBaseEntityEnum> result = Lists.newLinkedList();
- result.add(EchoBaseEntityEnum.Mission);
- result.add(EchoBaseEntityEnum.Echotype);
- result.add(EchoBaseEntityEnum.TSParameters);
+ result.add(EchoBaseEntityEnum.MeasureType);
+ result.add(EchoBaseEntityEnum.DataType);
+ result.add(EchoBaseEntityEnum.ReferenceDatumType);
+ result.add(EchoBaseEntityEnum.VesselType);
result.add(EchoBaseEntityEnum.EchotypeCategory);
+ result.add(EchoBaseEntityEnum.Localisation);
+ result.add(EchoBaseEntityEnum.CellMethod);
result.add(EchoBaseEntityEnum.AcousticInstrument);
- result.add(EchoBaseEntityEnum.AreaOfOperation);
- result.add(EchoBaseEntityEnum.Calibration);
- result.add(EchoBaseEntityEnum.Category);
+ result.add(EchoBaseEntityEnum.CategoryType);
+ result.add(EchoBaseEntityEnum.GearType);
result.add(EchoBaseEntityEnum.CategoryMeaning);
- result.add(EchoBaseEntityEnum.CategoryRef);
- result.add(EchoBaseEntityEnum.CategoryType);
- result.add(EchoBaseEntityEnum.CellMethod);
- result.add(EchoBaseEntityEnum.CellType);
- result.add(EchoBaseEntityEnum.DataMetadata);
- result.add(EchoBaseEntityEnum.DataType);
- result.add(EchoBaseEntityEnum.DataQuality);
- result.add(EchoBaseEntityEnum.DepthStratum);
+ result.add(EchoBaseEntityEnum.Species);
result.add(EchoBaseEntityEnum.DepthStratumType);
- result.add(EchoBaseEntityEnum.Gear);
result.add(EchoBaseEntityEnum.GearCaracteristic);
+ result.add(EchoBaseEntityEnum.ReferenceDatum);
+ result.add(EchoBaseEntityEnum.DepthStratum);
+ result.add(EchoBaseEntityEnum.Category);
+ result.add(EchoBaseEntityEnum.ReferencingMethod);
+ result.add(EchoBaseEntityEnum.GearMetadataValue);
result.add(EchoBaseEntityEnum.GearMetadata);
- result.add(EchoBaseEntityEnum.GearMetadataValue);
- result.add(EchoBaseEntityEnum.GearType);
+ result.add(EchoBaseEntityEnum.Calibration);
+ result.add(EchoBaseEntityEnum.OperationType);
+ result.add(EchoBaseEntityEnum.MeasurementMetadata);
+ result.add(EchoBaseEntityEnum.SampleDataType);
+ result.add(EchoBaseEntityEnum.Vessel);
+ result.add(EchoBaseEntityEnum.SampleRatioType);
+ result.add(EchoBaseEntityEnum.Echotype);
+ result.add(EchoBaseEntityEnum.DataMetadata);
+ result.add(EchoBaseEntityEnum.CellType);
result.add(EchoBaseEntityEnum.Impacte);
- result.add(EchoBaseEntityEnum.Localisation);
- result.add(EchoBaseEntityEnum.MeasurementMetadata);
- result.add(EchoBaseEntityEnum.MeasureType);
+ result.add(EchoBaseEntityEnum.Mission);
result.add(EchoBaseEntityEnum.OperationMetadata);
- result.add(EchoBaseEntityEnum.OperationType);
- result.add(EchoBaseEntityEnum.ReferenceDatum);
- result.add(EchoBaseEntityEnum.ReferenceDatumType);
- result.add(EchoBaseEntityEnum.ReferencingMethod);
+ result.add(EchoBaseEntityEnum.Station);
+ result.add(EchoBaseEntityEnum.AreaOfOperation);
+ result.add(EchoBaseEntityEnum.CategoryRef);
+ result.add(EchoBaseEntityEnum.DataQuality);
result.add(EchoBaseEntityEnum.SampleTag);
- result.add(EchoBaseEntityEnum.SampleDataType);
- result.add(EchoBaseEntityEnum.SampleRatioType);
+ result.add(EchoBaseEntityEnum.TSParameters);
+ result.add(EchoBaseEntityEnum.Gear);
+ return result.toArray(new EchoBaseEntityEnum[result.size()]);
+ }
+
+ /**
+ * @return the entity types of reference in correct order for copy
+ * purpose (says import / export of all a database.
+ */
+ public static EchoBaseEntityEnum[] getReferenceTypesForCopy() {
+ List<EchoBaseEntityEnum> result = Lists.newLinkedList();
+
result.add(EchoBaseEntityEnum.Species);
- result.add(EchoBaseEntityEnum.Station);
+ result.add(EchoBaseEntityEnum.Calibration);
+ result.add(EchoBaseEntityEnum.AcousticInstrument);
+ result.add(EchoBaseEntityEnum.TSParameters);
+ result.add(EchoBaseEntityEnum.VesselType);
result.add(EchoBaseEntityEnum.Vessel);
- result.add(EchoBaseEntityEnum.VesselType);
+ result.add(EchoBaseEntityEnum.Mission);
+ result.add(EchoBaseEntityEnum.DepthStratumType);
+ 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.CellMethod);
+ result.add(EchoBaseEntityEnum.DataMetadata);
return result.toArray(new EchoBaseEntityEnum[result.size()]);
}
-
}
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntityModificationLogImpl.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntityModificationLogImpl.java 2011-12-05 06:42:35 UTC (rev 140)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntityModificationLogImpl.java 2011-12-05 08:22:27 UTC (rev 141)
@@ -40,7 +40,7 @@
result.setEntityId(getEntityId());
result.setModificationDate(getModificationDate());
result.setModificationText(getModificationText());
- result.setModificationUser(getModificationUser().toDTO());
+ result.setModificationUser(getModificationUser());
return result;
}
}
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/ExportQueryImpl.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/ExportQueryImpl.java 2011-12-05 06:42:35 UTC (rev 140)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/ExportQueryImpl.java 2011-12-05 08:22:27 UTC (rev 141)
@@ -39,7 +39,7 @@
dto.setDescription(getDescription());
dto.setId(getTopiaId());
dto.setLastModifiedDate(getLastModifiedDate());
- dto.setLastModifiedUser(getLastModifiedUser().toDTO());
+ dto.setLastModifiedUser(getLastModifiedUser());
dto.setName(getName());
dto.setSqlQuery(getSqlQuery());
return dto;
Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java (rev 0)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java 2011-12-05 08:22:27 UTC (rev 141)
@@ -0,0 +1,110 @@
+/*
+ * #%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.entities.meta;
+
+import fr.ifremer.echobase.entities.EchoBaseDAOHelper;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.topia.persistence.util.EntityOperator;
+import org.nuiton.util.ObjectUtil;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+/**
+ * Define the meta data of a entity association field.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class AssociationMeta implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Association source entity type. */
+ protected EchoBaseEntityEnum source;
+
+ /** Association target entity type. */
+ protected EchoBaseEntityEnum target;
+
+ /** Name fo the association. */
+ protected String name;
+
+ /** Operator of the source entity used to get / set associations. */
+ protected transient EntityOperator<TopiaEntity> operator;
+
+ protected static AssociationMeta newMeta(EchoBaseEntityEnum source,
+ EchoBaseEntityEnum target,
+ String name) {
+ return new AssociationMeta(source, target, name);
+ }
+
+ public AssociationMeta(EchoBaseEntityEnum source,
+ EchoBaseEntityEnum target,
+ String name) {
+ this.source = source;
+ this.target = target;
+ this.name = name;
+ }
+
+ public EchoBaseEntityEnum getSource() {
+ return source;
+ }
+
+ public EchoBaseEntityEnum getTarget() {
+ return target;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public TopiaEntity newEntity() {
+ return ObjectUtil.newInstance(source.getImplementation());
+ }
+
+ public Object newAssociation() {
+ return ObjectUtil.newInstance(target.getImplementation());
+ }
+
+ public Collection<TopiaEntity> getChilds(TopiaEntity entity) {
+ Object o = getOperator().get(name, entity);
+ return (Collection<TopiaEntity>) o;
+ }
+
+ public void setChilds(TopiaEntity entity, Collection<TopiaEntity> childs) {
+ getOperator().addAllChild(name, entity, childs);
+ }
+
+ public EntityOperator<TopiaEntity> getOperator() {
+ if (operator == null) {
+ operator =
+ (EntityOperator<TopiaEntity>)
+ EchoBaseDAOHelper.getOperator(
+ source.getContract());
+ }
+
+ return operator;
+ }
+}
Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/ColumnMeta.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/ColumnMeta.java 2011-12-05 06:42:35 UTC (rev 140)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/ColumnMeta.java 2011-12-05 08:22:27 UTC (rev 141)
@@ -23,52 +23,35 @@
*/
package fr.ifremer.echobase.entities.meta;
-import org.hibernate.mapping.Column;
import org.nuiton.topia.persistence.TopiaEntity;
import java.io.Serializable;
import java.util.Date;
/**
- * Define the meta data.
+ * Define the meta data of a entity field.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 0.1
*/
public class ColumnMeta implements Serializable {
- protected static ColumnMeta newMeta(String name, String label, Class<?> type) {
- return new ColumnMeta(name, label, type);
+ protected static ColumnMeta newMeta(String name, Class<?> type) {
+ return new ColumnMeta(name, type);
}
private static final long serialVersionUID = 1L;
+ /** Name of the column. */
protected String name;
- protected String i18nKey;
-
- protected Column hibernateColumn;
-
+ /** Type of the column. */
protected Class<?> type;
- public ColumnMeta(String name, Class<?> type) {
- this(name, name, type);
- }
-
- public ColumnMeta(String name, String i18nKey, Class<?> type) {
- this.name = name;
- this.i18nKey = i18nKey;
- this.type = type;
- }
-
public String getName() {
return name;
}
- public String getI18nKey() {
- return i18nKey;
- }
-
public Class<?> getType() {
return type;
}
@@ -99,7 +82,9 @@
return boolean.class.equals(type);
}
- public Column getHibernateColumn() {
- return hibernateColumn;
+ protected ColumnMeta(String name, Class<?> type) {
+ this.name = name;
+ this.type = type;
}
+
}
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-05 06:42:35 UTC (rev 140)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java 2011-12-05 08:22:27 UTC (rev 141)
@@ -43,8 +43,8 @@
protected final EchoBaseEntityEnum[] entityEnums;
- public DbMeta(EchoBaseEntityEnum[] entityEnums) {
- this.entityEnums = entityEnums;
+ public static DbMeta newDbMeta(List<EchoBaseEntityEnum> entityEnums) {
+ return new DbMeta(entityEnums.toArray(new EchoBaseEntityEnum[entityEnums.size()]));
}
public List<String> getTableNames() {
@@ -59,7 +59,7 @@
if (tables == null) {
tables = Lists.newArrayList();
for (EchoBaseEntityEnum entityEnum : entityEnums) {
- TableMeta tableMeta = new TableMeta(entityEnum);
+ TableMeta tableMeta = TableMeta.newMeta(entityEnum);
tables.add(tableMeta);
}
}
@@ -82,4 +82,8 @@
public Iterator<TableMeta> iterator() {
return getTables().iterator();
}
+
+ protected DbMeta(EchoBaseEntityEnum[] entityEnums) {
+ this.entityEnums = entityEnums;
+ }
}
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/TableMeta.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/TableMeta.java 2011-12-05 06:42:35 UTC (rev 140)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/TableMeta.java 2011-12-05 08:22:27 UTC (rev 141)
@@ -33,7 +33,6 @@
import org.nuiton.util.beans.Binder;
import org.nuiton.util.beans.BinderModelBuilder;
-import java.beans.Introspector;
import java.io.Serializable;
import java.util.Iterator;
import java.util.List;
@@ -48,25 +47,22 @@
private static final long serialVersionUID = 1L;
- protected final String i18nKey;
+ public static TableMeta newMeta(EchoBaseEntityEnum entityEnum) {
+ return new TableMeta(entityEnum);
+ }
- protected final EntityOperator<?> operator;
-
+ /** Type of the entity. */
protected final EchoBaseEntityEnum entityEnum;
+ /** List of columns of the entity. */
protected List<ColumnMeta> columns;
+ /** List of associations of the entity. */
+ protected List<AssociationMeta> associations;
+
+ /** Binder used to copy entities (lazy loaded). */
protected Binder<TopiaEntity, TopiaEntity> binder;
- public TableMeta(EchoBaseEntityEnum entityEnum) {
- Preconditions.checkNotNull(entityEnum);
- this.entityEnum = entityEnum;
- Class<? extends TopiaEntity> contract = entityEnum.getContract();
- i18nKey = "echobase.common." +
- Introspector.decapitalize(contract.getSimpleName());
- operator = EchoBaseDAOHelper.getOperator(contract);
- }
-
public String getName() {
return entityEnum.name();
}
@@ -79,14 +75,6 @@
return entityEnum.getContract();
}
- public String getI18nKey() {
- return i18nKey;
- }
-
- public EntityOperator<?> getOperator() {
- return operator;
- }
-
public ColumnMeta getColumns(String columnName) {
Preconditions.checkNotNull(columnName);
ColumnMeta result = null;
@@ -113,20 +101,22 @@
}
public List<ColumnMeta> getColumns() {
- if (columns == null) {
- columns = Lists.newLinkedList();
- Class<? extends TopiaEntity> contract = entityEnum.getContract();
- EntityOperator<? extends TopiaEntity> operator =
- EchoBaseDAOHelper.getOperator(contract);
- List<String> properties = operator.getProperties();
- for (String property : properties) {
- Class<?> propertyType = operator.getPropertyType(property);
- String i18nKey = "echobase.common." + property;
- ColumnMeta tableMeta = ColumnMeta.newMeta(property, i18nKey, propertyType);
- columns.add(tableMeta);
+ return columns;
+ }
+
+ public List<AssociationMeta> getAssociations() {
+ return associations;
+ }
+
+ public AssociationMeta getAssociations(String name) {
+ AssociationMeta result = null;
+ for (AssociationMeta meta : getAssociations()) {
+ if (name.equals(meta.getName())) {
+ result = meta;
+ break;
}
}
- return columns;
+ return result;
}
public void copy(TopiaEntity source, TopiaEntity target) {
@@ -160,4 +150,46 @@
}
return binder;
}
+
+ protected TableMeta(EchoBaseEntityEnum entityEnum) {
+ Preconditions.checkNotNull(entityEnum);
+ this.entityEnum = entityEnum;
+
+ Class<? extends TopiaEntity> contract = entityEnum.getContract();
+ EntityOperator<? extends TopiaEntity> operator =
+ EchoBaseDAOHelper.getOperator(contract);
+
+ associations = Lists.newArrayList();
+ columns = Lists.newLinkedList();
+
+ // fill associations
+ List<String> associationProperties = operator.getAssociationProperties();
+ for (String property : associationProperties) {
+ Class<?> propertyType = operator.getPropertyType(property);
+ if (TopiaEntity.class.isAssignableFrom(propertyType)) {
+
+ // only use it for entity
+ EchoBaseEntityEnum targetEnum =
+ EchoBaseEntityEnum.valueOf(propertyType);
+
+ AssociationMeta meta = AssociationMeta.newMeta(entityEnum,
+ targetEnum,
+ property
+ );
+ associations.add(meta);
+ }
+ }
+
+ // fill properties (remove all asociations)
+ List<String> properties = Lists.newArrayList(operator.getProperties());
+ properties.removeAll(associationProperties);
+ for (String property : properties) {
+ Class<?> propertyType = operator.getPropertyType(property);
+ ColumnMeta meta = ColumnMeta.newMeta(property,
+ propertyType);
+ columns.add(meta);
+ }
+
+
+ }
}
Modified: trunk/echobase-entities/src/main/resources/topia-h2.properties
===================================================================
--- trunk/echobase-entities/src/main/resources/topia-h2.properties 2011-12-05 06:42:35 UTC (rev 140)
+++ trunk/echobase-entities/src/main/resources/topia-h2.properties 2011-12-05 08:22:27 UTC (rev 141)
@@ -24,6 +24,9 @@
hibernate.hbm2ddl.auto=update
hibernate.show_sql=false
+# Replication configuration
+topia.service.replication=org.nuiton.topia.replication.TopiaReplicationServiceImpl
+
hibernate.dialect=org.hibernate.dialect.H2Dialect
hibernate.connection.username=sa
hibernate.connection.password=sa
Modified: trunk/echobase-entities/src/main/xmi/echobase.zargo
===================================================================
(Binary files differ)
Deleted: trunk/echobase-entities/src/test/resources/echobase.properties
===================================================================
--- trunk/echobase-entities/src/test/resources/echobase.properties 2011-12-05 06:42:35 UTC (rev 140)
+++ trunk/echobase-entities/src/test/resources/echobase.properties 2011-12-05 08:22:27 UTC (rev 141)
@@ -1,34 +0,0 @@
-###
-# #%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%
-###
-hibernate.hbm2ddl.auto=update
-hibernate.show_sql=false
-hibernate.dialect=org.hibernate.dialect.H2Dialect
-
-hibernate.connection.driver_class=org.h2.Driver
-hibernate.connection.url=jdbc:h2:file:${data.directory}/echobase/h2data
-hibernate.connection.username=sa
-hibernate.connection.password=sa
-
-war.directory=${data.directory}/war
-war.location=${war.directory}/echobase-ui-${project.version}.war
\ No newline at end of file
1
0
Author: tchemit
Date: 2011-12-05 07:42:35 +0100 (Mon, 05 Dec 2011)
New Revision: 140
Url: http://forge.codelutin.com/repositories/revision/echobase/140
Log:
update dependencies
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-11-29 12:08:00 UTC (rev 139)
+++ trunk/pom.xml 2011-12-05 06:42:35 UTC (rev 140)
@@ -20,6 +20,7 @@
<modules>
<module>echobase-entities</module>
<module>echobase-services</module>
+ <module>echobase-tools</module>
<module>echobase-ui</module>
</modules>
@@ -107,16 +108,16 @@
<eugenePluginVersion>2.4.1</eugenePluginVersion>
<topiaVersion>2.6.4</topiaVersion>
- <nuitonUtilsVersion>2.4-SNAPSHOT</nuitonUtilsVersion>
+ <nuitonUtilsVersion>2.4</nuitonUtilsVersion>
<nuitonI18nVersion>2.4.1</nuitonI18nVersion>
- <nuitonWebVersion>1.6</nuitonWebVersion>
+ <nuitonWebVersion>1.8</nuitonWebVersion>
<msaccessImporterVersion>1.4.1</msaccessImporterVersion>
<struts2Version>2.2.3.1</struts2Version>
<jqueryPluginVersion>3.2.0</jqueryPluginVersion>
- <seleniumVersion>2.5.0</seleniumVersion>
- <h2Version>1.3.157</h2Version>
- <postgresqlVersion>9.0-801.jdbc4</postgresqlVersion>
- <slf4jVersion>1.6.1</slf4jVersion>
+ <seleniumVersion>2.14.0</seleniumVersion>
+ <h2Version>1.3.162</h2Version>
+ <postgresqlVersion>9.1-901.jdbc4</postgresqlVersion>
+ <slf4jVersion>1.6.4</slf4jVersion>
<jettyVersion>7.5.3.v20111011</jettyVersion>
<!-- This version does not work (missing javax.el api in overlay) -->
<!--<jettyVersion>8.0.1.v20110908</jettyVersion>-->
@@ -298,7 +299,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
- <version>10.0</version>
+ <version>10.0.1</version>
</dependency>
<!-- librairies web -->
1
0
r139 - in trunk/echobase-entities/src/main: java/fr/ifremer/echobase/entities xmi
by tchemit@users.forge.codelutin.com 29 Nov '11
by tchemit@users.forge.codelutin.com 29 Nov '11
29 Nov '11
Author: tchemit
Date: 2011-11-29 13:08:00 +0100 (Tue, 29 Nov 2011)
New Revision: 139
Url: http://forge.codelutin.com/repositories/revision/echobase/139
Log:
fix model
Modified:
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
trunk/echobase-entities/src/main/xmi/echobase.zargo
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-11-29 11:53:35 UTC (rev 138)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java 2011-11-29 12:08:00 UTC (rev 139)
@@ -55,14 +55,11 @@
result.add(EchoBaseEntityEnum.Result);
result.add(EchoBaseEntityEnum.Operation);
result.add(EchoBaseEntityEnum.OperationMetadataValue);
- result.add(EchoBaseEntityEnum.OperationMeasurementMetadataValue);
result.add(EchoBaseEntityEnum.Individual);
result.add(EchoBaseEntityEnum.OperationGearMetadataValue);
result.add(EchoBaseEntityEnum.Sample);
+ result.add(EchoBaseEntityEnum.SampleData);
result.add(EchoBaseEntityEnum.SampleAge);
- result.add(EchoBaseEntityEnum.SampleLength);
- result.add(EchoBaseEntityEnum.SampleAggregation);
- result.add(EchoBaseEntityEnum.AggregationLevel);
return result.toArray(new EchoBaseEntityEnum[result.size()]);
}
@@ -92,6 +89,7 @@
result.add(EchoBaseEntityEnum.DepthStratum);
result.add(EchoBaseEntityEnum.DepthStratumType);
result.add(EchoBaseEntityEnum.Gear);
+ result.add(EchoBaseEntityEnum.GearCaracteristic);
result.add(EchoBaseEntityEnum.GearMetadata);
result.add(EchoBaseEntityEnum.GearMetadataValue);
result.add(EchoBaseEntityEnum.GearType);
@@ -104,6 +102,9 @@
result.add(EchoBaseEntityEnum.ReferenceDatum);
result.add(EchoBaseEntityEnum.ReferenceDatumType);
result.add(EchoBaseEntityEnum.ReferencingMethod);
+ result.add(EchoBaseEntityEnum.SampleTag);
+ result.add(EchoBaseEntityEnum.SampleDataType);
+ result.add(EchoBaseEntityEnum.SampleRatioType);
result.add(EchoBaseEntityEnum.Species);
result.add(EchoBaseEntityEnum.Station);
result.add(EchoBaseEntityEnum.Vessel);
Modified: trunk/echobase-entities/src/main/xmi/echobase.zargo
===================================================================
(Binary files differ)
1
0
r138 - in trunk: . echobase-entities/src/main/resources/i18n echobase-entities/src/main/xmi src/doc/reunions src/site/resources src/site/resources/model src/site/rst
by tchemit@users.forge.codelutin.com 29 Nov '11
by tchemit@users.forge.codelutin.com 29 Nov '11
29 Nov '11
Author: tchemit
Date: 2011-11-29 12:53:35 +0100 (Tue, 29 Nov 2011)
New Revision: 138
Url: http://forge.codelutin.com/repositories/revision/echobase/138
Log:
add site + CR of last meeting
Added:
trunk/src/doc/reunions/reunion-2011-11-28.txt
trunk/src/site/resources/model/
trunk/src/site/resources/model/Transverse.png
trunk/src/site/resources/model/dataAcoustic.png
trunk/src/site/resources/model/dataCatches.png
trunk/src/site/resources/model/dataCommon.png
trunk/src/site/resources/model/referenceAcousticInstrument.png
trunk/src/site/resources/model/referenceAll.png
trunk/src/site/resources/model/referenceAreaOfOperation.png
trunk/src/site/resources/model/referenceDataMetadata.png
trunk/src/site/resources/model/referenceDataQuality.png
trunk/src/site/resources/model/referenceDepthStratum.png
trunk/src/site/resources/model/referenceEchotype.png
trunk/src/site/resources/model/referenceGear.png
trunk/src/site/resources/model/referenceMission.png
trunk/src/site/resources/model/referenceReferenceDatum.png
trunk/src/site/resources/model/referenceTSParameter.png
trunk/src/site/resources/model/referenceVessel.png
trunk/src/site/rst/model.rst
Modified:
trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties
trunk/echobase-entities/src/main/xmi/echobase.zargo
trunk/pom.xml
trunk/src/site/rst/index.rst
Modified: trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties
===================================================================
--- trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties 2011-11-28 22:23:24 UTC (rev 137)
+++ trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties 2011-11-29 11:53:35 UTC (rev 138)
@@ -58,6 +58,7 @@
echobase.common.dateCreated=
echobase.common.datum=datum
echobase.common.datumType=
+echobase.common.defaultAggregationLevel=
echobase.common.depthStratum=depthStratum
echobase.common.depthStratumId=
echobase.common.depthStratumMeaning=
@@ -90,6 +91,8 @@
echobase.common.flagMeanings=
echobase.common.frequency=
echobase.common.gear=
+echobase.common.gearCaracteristic=
+echobase.common.gearCaracteristicName=
echobase.common.gearMetadata=
echobase.common.gearMetadataName=
echobase.common.gearMetadataValue=
@@ -113,6 +116,7 @@
echobase.common.imo=
echobase.common.impacte=
echobase.common.individual=
+echobase.common.individualId=
echobase.common.individualValue=
echobase.common.institution=Institution
echobase.common.keywords=Môts clefs
@@ -120,6 +124,7 @@
echobase.common.lastModifiedDate=Date de dernière modification
echobase.common.lastModifiedUser=Utilisateur de dernière modification
echobase.common.length=
+echobase.common.level=
echobase.common.licence=
echobase.common.linestring=
echobase.common.litteratureReference=
@@ -148,7 +153,9 @@
echobase.common.modificationUser=Utilisateur
echobase.common.mz=
echobase.common.name=Nom
+echobase.common.newAttr=
echobase.common.notes=
+echobase.common.number=
echobase.common.numberAtAge=
echobase.common.numberAtLength=
echobase.common.numberSampled=
@@ -175,6 +182,7 @@
echobase.common.processingTemplate=
echobase.common.project=Projet
echobase.common.qualityDataFlagValues=
+echobase.common.ratio=
echobase.common.referenceDatum=referenceDatum
echobase.common.referenceDatumId=
echobase.common.referenceDatumType=
@@ -187,7 +195,12 @@
echobase.common.sample=
echobase.common.sampleAge=
echobase.common.sampleAggregation=
+echobase.common.sampleData=
+echobase.common.sampleDataType=
echobase.common.sampleLength=
+echobase.common.sampleMetadata=
+echobase.common.sampleRatioType=
+echobase.common.sampleTag=
echobase.common.sampleWeight=
echobase.common.scaleFactor=
echobase.common.seafloorSubstrate=
@@ -245,6 +258,7 @@
echobase.common.transitStartLocality=
echobase.common.transitStartTime=
echobase.common.transitVessel=
+echobase.common.type=
echobase.common.units=
echobase.common.validMax=
echobase.common.validMin=
Modified: trunk/echobase-entities/src/main/xmi/echobase.zargo
===================================================================
(Binary files differ)
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-11-28 22:23:24 UTC (rev 137)
+++ trunk/pom.xml 2011-11-29 11:53:35 UTC (rev 138)
@@ -15,7 +15,7 @@
<groupId>fr.ifremer</groupId>
<artifactId>echobase</artifactId>
- <version>0.2-rev-120-SNAPSHOT</version>
+ <version>0.2-SNAPSHOT</version>
<modules>
<module>echobase-entities</module>
Added: trunk/src/doc/reunions/reunion-2011-11-28.txt
===================================================================
--- trunk/src/doc/reunions/reunion-2011-11-28.txt (rev 0)
+++ trunk/src/doc/reunions/reunion-2011-11-28.txt 2011-11-29 11:53:35 UTC (rev 138)
@@ -0,0 +1,160 @@
+projet echobase
+---------------
+
+Lundi 15-11-2011 (Ifremer)
+
+Présents : Mathieu, Vincent, Benjamin, Tony, Franck (téléphone)
+
+Planning
+--------
+
+- détail du modèle pêcherie
+- scénarii d'import
+- import historique
+
+Modele peche
+------------
+
+Fait nouveau pour nous de découvrir que le moèdle peche proposé est un nouveau
+modèle et non pas un existant.
+
+Mathieu et Vincent s'interrogent sur le modèle actuel et cela concerne deux
+points :
+
+- les échantillons individuels qui ne sont pas uniformes avec les échantillons
+ non individuels, ce qui complexifie beaucoup le modèle.
+
+- la représentation des aggrégations d'échantillons hiérarchisés qui ne convient
+ pas.
+
+On a appelé Franck pour essayer d'éclaircir ces deux points et il est d'accord
+sur ces deux points.
+
+On essaye de trouver une meilleure modélisation.
+
+Les solutions retenues sont décrites dans les sections suivantes (à voir si
+cela permettra de bien prendre en compte tous les cas possibles et souhaités).
+
+Gestion des échantillons individuels
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+On supprime du modèle toute la partie sur les échantillons individuels,
+on introduit une notion de type des donnée échantillonnée qui convient et pour
+les échantillons groupés (il s'agit pour le moment uniquement d'un type de
+données taille) et pour les échantillons individuels.
+
+Cela permet d'avoir une grande felxibilité sur les données échantillonnées.
+
+On ajoute sur l'éntitié échantillon un entier qui est nulle lors d'un
+échantillon non individuel et qui représente l'identifiant de l'individu dans
+le cas d'un échantillon individuel.
+
+Gestion des aggregations d'échantillons
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Les échantillons peuvent être aggrégés et donc on voudrait pouvoir stoquer une
+information de type arbre.
+Plusieurs problématiques entrent en jeu lorsqu'on veut écrire un tel modèle :
+
+- le modèle sera-t-il reflexible ?
+- le modèle sera-t-il efficace à intérroger ?
+- le modèle sera-t-il facilement représentable sous forme d'arbre ?
+
+Nous partons sur une solution dite *labélisée*.
+
+Un échantilon possèdera plusieurs labels qui représentent en fait les noeuds de
+l'arbre d'échantillonage.
+
+Par exemple, un label *Gros* ou *Male* ou encore *Gros* et *Male*.
+
+A chaque label possible on associe un niveau de hiérarchie qui permettra
+ensuite de pouvoir gérer la cohérence de l'arbre d'échantillon.
+
+Par exemple si on a un tel arbre :
+
+G
+GM
+
+on ne peut pas avoir un nouveau noeud F car F est de niveau 2 et G de niveau ,
+il faut obligatoirement mettre un noeud GF.
+
+Inversement si on a
+
+M
+
+On ne peut pas directement ajouter un noued GF car le niveau G n'existe pas, il
+faudrait alors ajouter le noeud G, puis GM et GF.
+
+Le modèle que nous proposons est très flexible et peut très facilement rendre
+les hiérarchies incohérentes si on n'a pas de règles de gestion bien conçues.
+
+Il faudra alors bien penser à cela lors de la création d'un outil de saisie.
+
+On pourra mieux expliquer le fonctionnement lors de la prochaine réunion.
+
+Une question reste en suspens :
+
+ A quoi correspond aggregationLevelSampledWeight et
+ aggregationLevelObservedWeight dans l'ancien SampleAggregation ?
+
+ Il nous faudrait les formules utilisés pour les élévations selon ces deux
+ champs.
+
+Divers
+~~~~~~
+
+- Correction de la modélisation des engins (dans la version que j'ai du modèle
+ il y avait une liaison entre paramètre engin et type engin qui n' pas lieu
+ d'être).
+
+- On a remarqué que la table *captures* qui n'est rattaché à rien ! (dans le
+ modèle MS-ACCESS), il faut tiré cela au clair.
+
+Import historique
+-----------------
+
+Cet import sera réalisé par nos soins et donc cette fonctionnalité ne sera pas
+présente dans la version web.
+
+Nous fournirons donc une version finale de l'application avec une base déjà
+constituée des données historiques.
+
+Modèle acoustic
+---------------
+
+- suppression de l'entité supplémentaire Voyage_echotype car non utile.
+
+Scénarii d'import
+-----------------
+
+- non traité
+
+Disponibilité du modèle
+-----------------------
+
+Le modèle est sur le dépôt svn et est accessible au téléchargement pour tous
+à cette adresse :
+
+http://svn.forge.codelutin.com/svn/echobase/trunk/echobase-entities/src/main/xmi/echobase.zargo
+
+A faire
+-------
+
+- faire une procédure d'import des données peches historiques vers le nouveau
+ modèle. (Ifremer)
+- faire une procédure d'import des données accoustiques vers le nouveau modèle. (Ifremer)
+- fournir les données 2011 à importer (idéalement au format csv) (Ifremer)
+- coder l'import des données du référentiel (Codelutin)
+- regarder comment on peut exporter toute une base sql (dump sql) (Codelutin)
+- pouvoir supprimer lors d'un réimport les données précédemment importer (via la clef métier sur Voyage) (Codelutin)
+- mettre à disposition le modèle dans le compte rendu (Tony)
+
+- Prochaine réunion lundi 5 décembre 2011 à 10h00 (Ifremer).
+
+
+
+
+
+
+
+
Property changes on: trunk/src/doc/reunions/reunion-2011-11-28.txt
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/src/site/resources/model/Transverse.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/Transverse.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/dataAcoustic.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/dataAcoustic.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/dataCatches.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/dataCatches.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/dataCommon.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/dataCommon.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/referenceAcousticInstrument.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/referenceAcousticInstrument.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/referenceAll.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/referenceAll.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/referenceAreaOfOperation.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/referenceAreaOfOperation.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/referenceDataMetadata.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/referenceDataMetadata.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/referenceDataQuality.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/referenceDataQuality.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/referenceDepthStratum.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/referenceDepthStratum.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/referenceEchotype.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/referenceEchotype.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/referenceGear.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/referenceGear.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/referenceMission.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/referenceMission.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/referenceReferenceDatum.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/referenceReferenceDatum.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/referenceTSParameter.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/referenceTSParameter.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: trunk/src/site/resources/model/referenceVessel.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/site/resources/model/referenceVessel.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: svn:keywords
+ Author Date Id Revision HeadURL
Modified: trunk/src/site/rst/index.rst
===================================================================
--- trunk/src/site/rst/index.rst 2011-11-28 22:23:24 UTC (rev 137)
+++ trunk/src/site/rst/index.rst 2011-11-29 11:53:35 UTC (rev 138)
@@ -42,4 +42,9 @@
Les documents
-------------
-TODO
+- La documentation d'`installation`_.
+- La description du `modèle`_.
+
+.. _installation: install.html
+.. _modèle: model.html
+
Added: trunk/src/site/rst/model.rst
===================================================================
--- trunk/src/site/rst/model.rst (rev 0)
+++ trunk/src/site/rst/model.rst 2011-11-29 11:53:35 UTC (rev 138)
@@ -0,0 +1,94 @@
+.. -
+.. * #%L
+.. * echobase
+.. *
+.. * $Id$
+.. * $HeadURL$
+.. * %%
+.. * Copyright (C) 2011 Ifremer, Codelutin
+.. * %%
+.. * This program is free software: you can redistribute it and/or modify
+.. * it under the terms of the GNU Affero General Public License as published by
+.. * the Free Software Foundation, either version 3 of the License, or
+.. * (at your option) any later version.
+.. *
+.. * This program is distributed in the hope that it will be useful,
+.. * but WITHOUT ANY WARRANTY; without even the implied warranty of
+.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+.. * GNU General Public License for more details.
+.. *
+.. * You should have received a copy of the GNU Affero General Public License
+.. * along with this program. If not, see <http://www.gnu.org/licenses/>.
+.. * #L%
+.. -
+===============
+Modèle Echobase
+===============
+
+:Authors: Tony Chemit <chemit(a)codelutin.com>
+
+.. contents:: Table des matières
+ :depth: 2
+
+.. sectnum::
+ :start: 1
+ :depth: 2
+
+Présentation
+------------
+
+On donne ici des explications sur le modèle.
+
+Le modèle conçu sous argoUML est téléchargeable `ici`_ .
+
+Modèle du référentiel
+---------------------
+
+- `Vue générale du référentiel`_
+- `Référentiel AcousticInstrument`_
+- `Référentiel AreaOfOperation`_
+- `Référentiel DataMetadata`_
+- `Référentiel DepthStratum`_
+- `Référentiel Echotype`_
+- `Référentiel Gear`_
+- `Référentiel Mission`_
+- `Référentiel ReferenceDatum`_
+- `Référentiel TSParameter`_
+- `Référentiel Vessel`_
+
+Modèle thématique
+-----------------
+
+Partie commune
+~~~~~~~~~~~~~~
+
+- `Partie commune des données thématiques`_
+
+
+Sous modèle acoustique
+~~~~~~~~~~~~~~~~~~~~~~
+
+- `Sous modèle acoustique`_
+
+Sous modèle pêcherie
+~~~~~~~~~~~~~~~~~~~~
+
+- `Sous modèle pêcherie`_
+
+.. _ici: http://svn.forge.codelutin.com/svn/echobase/trunk/echobase-entities/src/mai…
+
+.. _Vue générale du référentiel: model/referenceAll.png
+.. _Référentiel AcousticInstrument: model/referenceAcousticInstrument.png
+.. _Référentiel AreaOfOperation: model/referenceAreaOfOperation.png
+.. _Référentiel DataMetadata: model/referenceDataMetadata.png
+.. _Référentiel DepthStratum: model/referenceDepthStratum.png
+.. _Référentiel Echotype: model/referenceEchotype.png
+.. _Référentiel Gear: model/referenceGear.png
+.. _Référentiel Mission: model/referenceMission.png
+.. _Référentiel ReferenceDatum: model/referenceReferenceDatum.png
+.. _Référentiel TSParameter: model/referenceTSParameter.png
+.. _Référentiel Vessel: model/referenceVessel.png
+
+.. _Partie commune des données thématiques: model/dataCommon.png
+.. _Sous modèle acoustique: model/dataAcoustic.png
+.. _Sous modèle pêcherie: model/dataCatches.png
Property changes on: trunk/src/site/rst/model.rst
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
Author: maven-release
Date: 2011-11-28 23:23:24 +0100 (Mon, 28 Nov 2011)
New Revision: 137
Url: http://forge.codelutin.com/repositories/revision/echobase/137
Log:
Update mavenpom4redmine to 3.0.6.
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2011-11-27 10:09:45 UTC (rev 136)
+++ trunk/pom.xml 2011-11-28 22:23:24 UTC (rev 137)
@@ -10,12 +10,12 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>3.0.5</version>
+ <version>3.0.6</version>
</parent>
<groupId>fr.ifremer</groupId>
<artifactId>echobase</artifactId>
- <version>0.2-SNAPSHOT</version>
+ <version>0.2-rev-120-SNAPSHOT</version>
<modules>
<module>echobase-entities</module>
1
0
27 Nov '11
Author: tchemit
Date: 2011-11-27 11:09:45 +0100 (Sun, 27 Nov 2011)
New Revision: 136
Url: http://forge.codelutin.com/repositories/revision/echobase/136
Log:
- mise en place suqelette import historique
- mise en place mode d'import
- validation sur les import de donn?\195?\169es
- suppression package import
- renommage ImportMode en SelectedMissionMode
Added:
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/SelectedMissionMode.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importHistorical/
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importHistorical/Configure.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importHistorical/LaunchImport.java
trunk/echobase-ui/src/main/resources/config/struts-importHistorical.xml
trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importHistorical/
trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importHistorical/Configure-validation.xml
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/progress.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/result.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importHistorical/
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importHistorical/configure.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importHistorical/progress.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importHistorical/result.jsp
Removed:
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ImportMode.java
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/import/
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importProgress.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importResult.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/EchoBaseActionSupport.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntity.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureMission.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchImport.java
trunk/echobase-ui/src/main/resources/config/struts-importData.xml
trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles-validation.xml
trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureMission-validation.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/resources/validators.xml
trunk/echobase-ui/src/main/webapp/WEB-INF/includes/header.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/configureFiles.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/configureMission.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-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseSession.java 2011-11-27 10:09:45 UTC (rev 136)
@@ -25,6 +25,7 @@
import fr.ifremer.echobase.entities.EchoBaseUser;
import fr.ifremer.echobase.services.ImportDataConfiguration;
+import fr.ifremer.echobase.services.ImportHistoricalConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -45,9 +46,12 @@
/** Key to set User connected in this session. */
protected static final String PROPERTY_ECHO_BASE_USER = "echobaseUser";
- /** Key to keep import configuration in this session. */
+ /** Key to keep import data configuration in this session. */
protected static final String PROPERTY_IMPORT_DATA_CONFIGURATION = "importDataConfiguration";
+ /** Key to keep historical import configuration in this session. */
+ protected static final String PROPERTY_IMPORT_HISTORICAL_CONFIGURATION = "importHistoricalConfiguration";
+
/** To store all properties in this session. */
protected Map<String, Object> store;
@@ -77,6 +81,14 @@
set(PROPERTY_IMPORT_DATA_CONFIGURATION, configuration);
}
+ public ImportHistoricalConfiguration getImportHistoricalConfiguration() {
+ return get(PROPERTY_IMPORT_HISTORICAL_CONFIGURATION, ImportHistoricalConfiguration.class);
+ }
+
+ public void setImportHistoricalConfiguration(ImportHistoricalConfiguration configuration) {
+ set(PROPERTY_IMPORT_HISTORICAL_CONFIGURATION, configuration);
+ }
+
/**
* Remove form this session, the object from his given key and returns it.
*
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/EchoBaseActionSupport.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/EchoBaseActionSupport.java 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/EchoBaseActionSupport.java 2011-11-27 10:09:45 UTC (rev 136)
@@ -25,6 +25,7 @@
import com.opensymphony.xwork2.ActionContext;
import fr.ifremer.echobase.EchoBaseConfiguration;
+import fr.ifremer.echobase.InputFile;
import fr.ifremer.echobase.services.DecoratorService;
import fr.ifremer.echobase.services.EchoBaseService;
import fr.ifremer.echobase.services.EchoBaseServiceContext;
@@ -32,6 +33,9 @@
import fr.ifremer.echobase.services.EchoBaseServiceFactory;
import fr.ifremer.echobase.ui.EchoBaseApplicationContext;
import fr.ifremer.echobase.ui.EchoBaseSession;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.struts2.StrutsStatics;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.framework.TopiaTransactionAware;
@@ -40,6 +44,8 @@
import org.nuiton.web.struts2.BaseAction;
import javax.servlet.http.HttpServletRequest;
+import java.io.File;
+import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
@@ -66,6 +72,10 @@
/** Key to store the single instance of the application context */
public static final String APPLICATION_CONTEXT_PARAMETER = "echoBaseApplicationContext";
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(EchoBaseActionSupport.class);
+
private SimpleDateFormat dateFormat;
private SimpleDateFormat monthFormat;
@@ -219,4 +229,21 @@
protected static ActionContext getActionContext() {
return ActionContext.getContext();
}
+
+ protected void copyFile(InputFile inputFile,
+ File dataDirectory) throws IOException {
+ File source = inputFile.getFile();
+ if (source != null) {
+
+ File target = new File(dataDirectory, inputFile.getFileName());
+ if (log.isInfoEnabled()) {
+ log.info("Copy file " + source + " to " + target);
+ }
+ FileUtils.copyFile(source, target);
+
+ // keep target (source file will be removed at the end of this action)
+ inputFile.setFile(target);
+ }
+
+ }
}
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntity.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntity.java 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/GetEntity.java 2011-11-27 10:09:45 UTC (rev 136)
@@ -77,7 +77,7 @@
DbEditorService service = newService(DbEditorService.class);
TableMeta table = serviceContext.getDbMeta().getTable(entityType);
-
+
datas = service.getData(table, id);
List<ColumnMeta> columnMetas = table.getColumns();
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles.java 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles.java 2011-11-27 10:09:45 UTC (rev 136)
@@ -23,11 +23,12 @@
*/
package fr.ifremer.echobase.ui.actions.importData;
+import com.google.common.collect.Maps;
import com.opensymphony.xwork2.Preparable;
-import fr.ifremer.echobase.InputFile;
import fr.ifremer.echobase.entities.references.Mission;
import fr.ifremer.echobase.services.EchoBaseServiceSupport;
import fr.ifremer.echobase.services.ImportDataConfiguration;
+import fr.ifremer.echobase.services.ImportDataMode;
import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
@@ -35,7 +36,7 @@
import org.nuiton.util.FileUtil;
import java.io.File;
-import java.io.IOException;
+import java.util.Map;
/**
* Action to load input files to import.
@@ -56,10 +57,17 @@
/** Id of selected voyage used in import. */
protected String missionId;
+ /** Universe of possible import modes. */
+ protected Map<String, String> importDataModes;
+
public void setMissionId(String missionId) {
this.missionId = missionId;
}
+ public void setImportDataMode(ImportDataMode importDataMode) {
+ getModel().setImportDataMode(importDataMode);
+ }
+
public void setAcoustic(File file) {
getModel().getAcousticFile().setFile(file);
}
@@ -124,6 +132,10 @@
return missionId;
}
+ public ImportDataMode getImportDataMode() {
+ return getModel().getImportDataMode();
+ }
+
public ImportDataConfiguration getModel() {
if (model == null) {
model = new ImportDataConfiguration(getLocale());
@@ -131,6 +143,10 @@
return model;
}
+ public Map<String, String> getImportDataModes() {
+ return importDataModes;
+ }
+
@Override
public String input() throws Exception {
@@ -147,8 +163,9 @@
File tempDirectory = FileUtils.getTempDirectory();
File dataDirectory = new File(
tempDirectory,
- "echobase-import" + System.currentTimeMillis());
+ "echobase-importData-" + System.currentTimeMillis());
FileUtil.createDirectoryIfNecessary(dataDirectory);
+ importModel.setWorkingDirectory(dataDirectory);
if (log.isInfoEnabled()) {
log.info("Temporary directory to use : " + dataDirectory);
}
@@ -169,23 +186,21 @@
newService(EchoBaseServiceSupport.class);
Mission mission = service.getEntityById(Mission.class, missionId);
- getModel().setMission(mission);
- }
+ ImportDataConfiguration configuration = getModel();
+ configuration.setMission(mission);
- protected void copyFile(InputFile inputFile,
- File dataDirectory) throws IOException {
- File source = inputFile.getFile();
- if (source != null) {
+ importDataModes = Maps.newLinkedHashMap();
+ for (ImportDataMode mode : ImportDataMode.values()) {
+ importDataModes.put(mode.name(), _(mode.getI18nKey()));
+ }
- File target = new File(dataDirectory, inputFile.getFileName());
- if (log.isInfoEnabled()) {
- log.info("Copy file " + source + " to " + target);
- }
- FileUtils.copyFile(source, target);
-
- // keep target (source file will be removed at the end of this action)
- inputFile.setFile(target);
+ if (log.isInfoEnabled()) {
+ log.info("Incoming importDataMode " +
+ configuration.getImportDataMode());
}
+ if (configuration.getImportDataMode() == null) {
+ configuration.setImportDataMode(ImportDataMode.ALL);
+ }
+ }
- }
}
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureMission.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureMission.java 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ConfigureMission.java 2011-11-27 10:09:45 UTC (rev 136)
@@ -56,7 +56,7 @@
protected Map<String, String> importModes;
/** Selected import mode. */
- protected ImportMode importMode;
+ protected SelectedMissionMode importMode;
/** mission to use. */
protected Mission mission;
@@ -76,23 +76,23 @@
return missions;
}
- public ImportMode getImportMode() {
+ public SelectedMissionMode getImportMode() {
return importMode;
}
- public void setImportMode(ImportMode importMode) {
+ public void setImportMode(SelectedMissionMode importMode) {
this.importMode = importMode;
}
@Override
public String input() throws Exception {
importModes = Maps.newLinkedHashMap();
- for (ImportMode mode : ImportMode.values()) {
+ for (SelectedMissionMode mode : SelectedMissionMode.values()) {
importModes.put(mode.name(), _(mode.getI18nKey()));
}
if (importMode == null) {
- importMode = ImportMode.USE_EXISTING_MISSION;
+ importMode = SelectedMissionMode.USE_EXISTING_MISSION;
}
EchoBaseServiceSupport service =
@@ -111,7 +111,7 @@
@Override
public String execute() throws Exception {
- if (importMode == ImportMode.CREATE_NEW_MISSION) {
+ if (importMode == SelectedMissionMode.CREATE_NEW_MISSION) {
// create voyage in db
ImportDataService service = newService(ImportDataService.class);
Deleted: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ImportMode.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ImportMode.java 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ImportMode.java 2011-11-27 10:09:45 UTC (rev 136)
@@ -1,49 +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.importData;
-
-import static org.nuiton.i18n.I18n.n_;
-
-/**
- * Define import mode (use an existing voayge, or create a new one.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.2
- */
-public enum ImportMode {
-
- CREATE_NEW_MISSION(n_("echobase.common.importMode.createNewMission")),
- USE_EXISTING_MISSION(n_("echobase.common.importMode.useExistingMission"));
-
-
- private final String i18nKey;
-
- ImportMode(String i18nKey) {
- this.i18nKey = i18nKey;
- }
-
- public String getI18nKey() {
- return i18nKey;
- }
-}
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchImport.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchImport.java 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/LaunchImport.java 2011-11-27 10:09:45 UTC (rev 136)
@@ -52,7 +52,7 @@
protected Map<InputFile, CsvImportResult> importResult;
- transient ImportDataService service;
+ protected transient ImportDataService service;
public ImportDataConfiguration getModel() {
return model;
@@ -83,6 +83,9 @@
return SUCCESS;
} finally {
+ // clean configuration
+ model.destroy();
+
// remove configuration from session
getEchoBaseSession().setImportDataConfiguration(null);
}
Copied: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/SelectedMissionMode.java (from rev 132, trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/ImportMode.java)
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/SelectedMissionMode.java (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/SelectedMissionMode.java 2011-11-27 10:09:45 UTC (rev 136)
@@ -0,0 +1,48 @@
+/*
+ * #%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.importData;
+
+import static org.nuiton.i18n.I18n.n_;
+
+/**
+ * Define import mode (use an existing voayge, or create a new one.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public enum SelectedMissionMode {
+
+ CREATE_NEW_MISSION(n_("echobase.common.importMode.createNewMission")),
+ USE_EXISTING_MISSION(n_("echobase.common.importMode.useExistingMission"));
+
+ private final String i18nKey;
+
+ SelectedMissionMode(String i18nKey) {
+ this.i18nKey = i18nKey;
+ }
+
+ public String getI18nKey() {
+ return i18nKey;
+ }
+}
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importData/SelectedMissionMode.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/importHistorical/Configure.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importHistorical/Configure.java (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importHistorical/Configure.java 2011-11-27 10:09:45 UTC (rev 136)
@@ -0,0 +1,101 @@
+/*
+ * #%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.importHistorical;
+
+import fr.ifremer.echobase.InputFile;
+import fr.ifremer.echobase.services.ImportHistoricalConfiguration;
+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 an historical import.
+ *
+ * @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);
+
+ /** Configuration of the historical import. */
+ protected ImportHistoricalConfiguration model;
+
+ public ImportHistoricalConfiguration getModel() {
+ if (model == null) {
+ model = new ImportHistoricalConfiguration(getLocale());
+ }
+ return model;
+ }
+
+ public void setInputFileName(String fileName) {
+ getModel().getInput().setFileName(fileName);
+ }
+
+ public void setInput(File file) {
+ getModel().getInput().setFile(file);
+ }
+
+ public void setInputContentType(String contentType) {
+ getModel().getInput().setContentType(contentType);
+ }
+
+ @Override
+ public String input() throws Exception {
+
+ // always remove configuration from session anytime coming here
+ getEchoBaseSession().setImportHistoricalConfiguration(null);
+ return INPUT;
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ ImportHistoricalConfiguration configuration = getModel();
+
+ File tempDirectory = FileUtils.getTempDirectory();
+ File dataDirectory = new File(
+ tempDirectory,
+ "echobase-importHistorical-" + System.currentTimeMillis());
+ FileUtil.createDirectoryIfNecessary(dataDirectory);
+ configuration.setWorkingDirectory(dataDirectory);
+ if (log.isInfoEnabled()) {
+ log.info("Temporary directory to use : " + dataDirectory);
+ }
+
+ InputFile input = configuration.getInput();
+ copyFile(input, dataDirectory);
+
+ // store configuration in session
+ getEchoBaseSession().setImportHistoricalConfiguration(configuration);
+ return SUCCESS;
+ }
+}
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importHistorical/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/importHistorical/LaunchImport.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importHistorical/LaunchImport.java (rev 0)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importHistorical/LaunchImport.java 2011-11-27 10:09:45 UTC (rev 136)
@@ -0,0 +1,94 @@
+/*
+ * #%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.importHistorical;
+
+import com.opensymphony.xwork2.Preparable;
+import fr.ifremer.echobase.services.CsvImportResult;
+import fr.ifremer.echobase.services.ImportHistoricalConfiguration;
+import fr.ifremer.echobase.services.ImportHistoricalService;
+import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * To starts the historical import.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class LaunchImport extends EchoBaseActionSupport implements Preparable {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(LaunchImport.class);
+
+ /** Configuration of the historical import. */
+ protected ImportHistoricalConfiguration model;
+
+ /** Result of import. */
+ protected CsvImportResult importResult;
+
+ /** service to execute the import. */
+ protected transient ImportHistoricalService service;
+
+ public ImportHistoricalConfiguration getModel() {
+ return model;
+ }
+
+ public CsvImportResult getImportResult() {
+ return importResult;
+ }
+
+ @Override
+ public void prepare() throws Exception {
+
+ model = getEchoBaseSession().getImportHistoricalConfiguration();
+
+ service = newService(ImportHistoricalService.class);
+ }
+
+ @Override
+ public String execute() throws Exception {
+
+ try {
+
+ if (log.isInfoEnabled()) {
+ log.info("Start imports with file " +
+ model.getInput().getFileName());
+ }
+
+ importResult = service.startImport(model);
+ return SUCCESS;
+ } finally {
+
+ // clean configuration
+ model.destroy();
+
+ // remove configuration from session
+ getEchoBaseSession().setImportHistoricalConfiguration(null);
+ }
+ }
+
+}
Property changes on: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/importHistorical/LaunchImport.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-ui/src/main/resources/config/struts-importData.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/config/struts-importData.xml 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/resources/config/struts-importData.xml 2011-11-27 10:09:45 UTC (rev 136)
@@ -30,7 +30,7 @@
<struts>
- <package name="import" extends="loggued" namespace="/importData">
+ <package name="importData" extends="loggued" namespace="/importData">
<!-- Configure import mission -->
<action name="configureMission"
@@ -62,8 +62,8 @@
method="execute">
<interceptor-ref name="basicStackLoggued"/>
<interceptor-ref name="execAndWait"/>
- <result name="wait">/WEB-INF/jsp/importData/importProgress.jsp</result>
- <result>/WEB-INF/jsp/importData/importResult.jsp</result>
+ <result name="wait">/WEB-INF/jsp/importData/progress.jsp</result>
+ <result>/WEB-INF/jsp/importData/result.jsp</result>
</action>
</package>
Added: trunk/echobase-ui/src/main/resources/config/struts-importHistorical.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/config/struts-importHistorical.xml (rev 0)
+++ trunk/echobase-ui/src/main/resources/config/struts-importHistorical.xml 2011-11-27 10:09:45 UTC (rev 136)
@@ -0,0 +1,59 @@
+<?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="importHistorical" extends="loggued" namespace="/importHistorical">
+
+ <!-- Configure import -->
+ <action name="configureImport"
+ class="fr.ifremer.echobase.ui.actions.importHistorical.Configure">
+ <interceptor-ref name="paramsPrepareParamsStackLoggued"/>
+ <result name="input">/WEB-INF/jsp/importHistorical/configure.jsp</result>
+ <result type="redirectAction">
+ <param name="namespace">/importHistorical</param>
+ <param name="actionName">doImport</param>
+ </result>
+ </action>
+
+ <!-- Starts import -->
+ <action name="doImport"
+ class="fr.ifremer.echobase.ui.actions.importHistorical.LaunchImport"
+ method="execute">
+ <interceptor-ref name="basicStackLoggued"/>
+ <interceptor-ref name="execAndWait"/>
+ <result name="wait">/WEB-INF/jsp/importHistorical/progress.jsp</result>
+ <result>/WEB-INF/jsp/importHistorical/result.jsp</result>
+ </action>
+
+ </package>
+
+</struts>
+
Property changes on: trunk/echobase-ui/src/main/resources/config/struts-importHistorical.xml
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles-validation.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles-validation.xml 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureFiles-validation.xml 2011-11-27 10:09:45 UTC (rev 136)
@@ -26,10 +26,56 @@
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
- <field name="missionId">
- <field-validator type="requiredstring">
- <message key="echobase.error.import.voyage.required"/>
+ <field name="model.mission">
+ <field-validator type="required">
+ <message key="echobase.error.import.mission.required"/>
</field-validator>
</field>
+ <field name="importDataMode">
+ <field-validator type="required">
+ <message key="echobase.error.import.importDataMode.required"/>
+ </field-validator>
+ </field>
+
+ <field name="acoustic">
+ <field-validator type="nfieldexpression">
+ <param name="expression">model.acousticFile.file != null</param>
+ <param name="skip">importDataMode.name() != "ALL" && importDataMode.name() != "ACOUSTIC"</param>
+ <message key="echobase.error.import.acousticFile.required"/>
+ </field-validator>
+ </field>
+
+ <field name="capture">
+ <field-validator type="nfieldexpression">
+ <param name="expression">model.captureFile.file != null</param>
+ <param name="skip">importDataMode.name() != "ALL"</param>
+ <message key="echobase.error.import.captureFile.required"/>
+ </field-validator>
+ </field>
+
+ <field name="lectureAgeGen">
+ <field-validator type="nfieldexpression">
+ <param name="expression">model.lectureAgeGenFile.file != null</param>
+ <param name="skip">importDataMode.name() != "ALL"</param>
+ <message key="echobase.error.import.lectureAgeGenFile.required"/>
+ </field-validator>
+ </field>
+
+ <field name="events">
+ <field-validator type="nfieldexpression">
+ <param name="expression">model.eventsFile.file != null</param>
+ <param name="skip">importDataMode.name() != "ALL"</param>
+ <message key="echobase.error.import.eventsFile.required"/>
+ </field-validator>
+ </field>
+
+ <field name="typeEchoSpecies">
+ <field-validator type="nfieldexpression">
+ <param name="expression">model.typeEchoSpeciesFile.file != null</param>
+ <param name="skip">importDataMode.name() != "ALL"</param>
+ <message key="echobase.error.import.typeEchoSpeciesFile.required"/>
+ </field-validator>
+ </field>
+
</validators>
\ No newline at end of file
Modified: trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureMission-validation.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureMission-validation.xml 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importData/ConfigureMission-validation.xml 2011-11-27 10:09:45 UTC (rev 136)
@@ -33,21 +33,21 @@
</field>
<field name="mission.topiaId">
- <field-validator type="requiredstring">
+ <field-validator type="nrequiredstring">
<param name="skip">importMode.name() != "USE_EXISTING_MISSION"</param>
<message key="echobase.error.import.mission.required"/>
</field-validator>
</field>
<field name="mission.missionName">
- <field-validator type="requiredstring">
+ <field-validator type="nrequiredstring">
<param name="skip">importMode.name() != "CREATE_NEW_MISSION"</param>
<message key="echobase.error.import.missionName.required"/>
</field-validator>
</field>
<field name="mission.missionAbstract">
- <field-validator type="requiredstring">
+ <field-validator type="nrequiredstring">
<param name="skip">importMode.name() != "CREATE_NEW_MISSION"</param>
<message key="echobase.error.import.missionAbstract.required"/>
</field-validator>
Added: trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importHistorical/Configure-validation.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importHistorical/Configure-validation.xml (rev 0)
+++ trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importHistorical/Configure-validation.xml 2011-11-27 10:09:45 UTC (rev 136)
@@ -0,0 +1,36 @@
+<!--
+ #%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 validators PUBLIC
+ "-//OpenSymphony Group//XWork Validator 1.0.2//EN"
+ "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
+<validators>
+
+ <field name="input">
+ <field-validator type="fieldexpression">
+ <param name="expression">model.input.file != null</param>
+ <message key="echobase.error.importHistorical.input.required"/>
+ </field-validator>
+ </field>
+
+</validators>
\ No newline at end of file
Property changes on: trunk/echobase-ui/src/main/resources/fr/ifremer/echobase/ui/actions/importHistorical/Configure-validation.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-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/resources/i18n/echobase-ui_fr_FR.properties 2011-11-27 10:09:45 UTC (rev 136)
@@ -23,6 +23,7 @@
echobase.common.comment=Commentaire
echobase.common.email=Email
echobase.common.entityType=Type d'entité
+echobase.common.importDataMode=Type d'import
echobase.common.importMode=Type de mission
echobase.common.importMode.createNewMission=Créer une nouvelle mission
echobase.common.importMode.useExistingMission=Utiliser une mission existante
@@ -45,6 +46,7 @@
echobase.error.import.missionName.required=Le nom de la mission est obligatoire
echobase.error.importArgument=
echobase.error.importFile.required=Fichier d'import obligatoire
+echobase.error.importHistorical.input.required=Le fichier d'import est obligatoire
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é
@@ -84,18 +86,19 @@
echobase.label.voyageToSelect=Voyage à exporter
echobase.legend.dbeditor.edit=Edition de '%s'
echobase.legend.embeddedApplication.configuration=Configuration de l'application embarquée
-echobase.legend.import=Import configuration
-echobase.legend.import.configuration.files=Choix des fichiers d'import
-echobase.legend.import.configuration.mission=Configurer la mission
-echobase.legend.import.configuration.mission.resume=Résumé de la mission à utiliser
+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
echobase.legend.importFileResult=Résultat de l'import %s
+echobase.legend.importHistorical.configuration.files=Choix du fichier d'import de données historiques
echobase.legend.sqlQuery.configuration=Configuration de la requête
echobase.legend.sqlQuery.result=Résultats de la requête
echobase.menu.connectToDbInformations=Se connecter à la base
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.import=Importer des données
+echobase.menu.importData=Importer des données
+echobase.menu.importHistorical=Importer les données historiques
echobase.menu.logs=Visualiser les modifications
echobase.menu.users=Gérer les utilisateurs
echobase.message.askAdministratorPassword=Demander à un administrateur le mot de passe pour l'utilisateur donné
@@ -113,10 +116,14 @@
echobase.title.entityModificationLogs=Journal des modifications
echobase.title.export=Export
echobase.title.exportTable=Exporter une table
-echobase.title.import=Imports
-echobase.title.import.configuration=Configuration d'un import
-echobase.title.importProgress=Import en cours
-echobase.title.importResult=Résultats de l'import
+echobase.title.importData=Import de données
+echobase.title.importData.configuration=Configuration d'un import de données
+echobase.title.importDataProgress=Import de données en cours
+echobase.title.importDataResult=Résultats de l'import de données
+echobase.title.importHistorical=Import de données historiques
+echobase.title.importHistorical.configuration=Configuration d'un import de données historiques
+echobase.title.importHistoricalProgress=Import de données historiques en cours
+echobase.title.importHistoricalResult=Résultats de l'import de données historiques
echobase.title.importTable=Importer une table
echobase.title.login=Connexion
echobase.title.modification.detail=Détail de la modification
Modified: trunk/echobase-ui/src/main/resources/struts.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/struts.xml 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/resources/struts.xml 2011-11-27 10:09:45 UTC (rev 136)
@@ -132,6 +132,7 @@
<include file="config/struts-dbeditor.xml"/>
<include file="config/struts-user.xml"/>
<include file="config/struts-importData.xml"/>
+ <include file="config/struts-importHistorical.xml"/>
<include file="config/struts-export.xml"/>
</struts>
Modified: trunk/echobase-ui/src/main/resources/validators.xml
===================================================================
--- trunk/echobase-ui/src/main/resources/validators.xml 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/resources/validators.xml 2011-11-27 10:09:45 UTC (rev 136)
@@ -37,11 +37,13 @@
<validator name="fieldexpression" class="com.opensymphony.xwork2.validator.validators.FieldExpressionValidator"/>
<validator name="conversion" class="com.opensymphony.xwork2.validator.validators.ConversionErrorFieldValidator"/>
<validator name="stringlength" class="com.opensymphony.xwork2.validator.validators.StringLengthFieldValidator"/>
+ <validator name="required" class="com.opensymphony.xwork2.validator.validators.RequiredFieldValidator"/>
+ <validator name="requiredstring" class="com.opensymphony.xwork2.validator.validators.RequiredStringValidator"/>
<!-- default nuiton-validator validators -->
- <validator name="fieldexpressionwithparams" class="org.nuiton.validator.xwork2.field.FieldExpressionWithParamsValidator"/>
- <validator name="required" class="org.nuiton.validator.xwork2.field.SkipableRequiredFieldValidator"/>
- <validator name="requiredstring" class="org.nuiton.validator.xwork2.field.SkipableRequiredStringFieldValidator"/>
+ <validator name="nfieldexpression" class="org.nuiton.validator.xwork2.field.NuitonFieldExpressionValidator"/>
+ <validator name="nrequired" class="org.nuiton.validator.xwork2.field.SkipableRequiredFieldValidator"/>
+ <validator name="nrequiredstring" class="org.nuiton.validator.xwork2.field.SkipableRequiredStringFieldValidator"/>
<!-- EchoBase validators -->
<validator name="login" class="fr.ifremer.echobase.ui.validators.LoginValidator"/>
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/includes/header.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/includes/header.jsp 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/includes/header.jsp 2011-11-27 10:09:45 UTC (rev 136)
@@ -55,8 +55,12 @@
<div class="cleanBoth">
<ul>
<li>
+ <s:a action="configureImport" namespace="/importHistorical" method="input">
+ <s:text name="echobase.menu.importHistorical"/></s:a>
+ </li>
+ <li>
<s:a action="configureMission" namespace="/importData" method="input">
- <s:text name="echobase.menu.import"/></s:a>
+ <s:text name="echobase.menu.importData"/></s:a>
</li>
<li>
<s:a action="exportSql" namespace="/export">
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/configureFiles.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/configureFiles.jsp 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/configureFiles.jsp 2011-11-27 10:09:45 UTC (rev 136)
@@ -24,13 +24,38 @@
<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
-<title><s:text name="echobase.title.import"/></title>
+<title><s:text name="echobase.title.importData"/></title>
+<script type="text/javascript">
+
+ function updateMode(newValue) {
+ switch (newValue) {
+ case "ALL":
+ $('[class="inputFile"]').show();
+ break;
+ case "ACOUSTIC":
+ $('[class="inputFile"]').hide();
+ $('#acousticFile').show();
+ break;
+ }
+ }
+
+ jQuery(document).ready(function () {
+
+
+ $('[name="importDataMode"]').change(function(event) {
+ updateMode(this.value);
+ });
+ var val = $('[name="importDataMode"][checked="checked"]').val();
+ updateMode(val);
+ });
+</script>
+
<s:form namespace="/importData" method="POST" enctype="multipart/form-data">
<fieldset>
<legend>
- <s:text name="echobase.legend.import.configuration.mission.resume"/>
+ <s:text name="echobase.legend.importData.configuration.mission.resume"/>
</legend>
<s:label value="%{model.mission.missionName}"
key='echobase.common.missionName'/>
@@ -42,29 +67,39 @@
<hr/>
<fieldset>
<legend>
- <s:text name="echobase.legend.import.configuration.files"/>
+ <s:text name="echobase.legend.importData.configuration.files"/>
</legend>
<s:hidden key="missionId" label=''/>
- <s:file name="acoustic"
- key="echobase.label.import.accoustique"/>
+ <s:radio key='importDataMode' list="importDataModes"
+ label='%{getText("echobase.common.importDataMode")}'
+ required="true"/>
+ <hr/>
+ <div class="inputFile" id="acousticFile">
+ <s:file id="acoustic" name="acoustic" required="true"
+ key="echobase.label.import.accoustique"/>
+ </div>
+ <div class="inputFile" id="captureFile">
+ <s:file name="capture" required="true"
+ key="echobase.label.import.pecherie"/>
+ </div>
+ <div class="inputFile" id="lectureAgeGenFile">
+ <s:file name="lectureAgeGen" required="true"
+ key="echobase.label.import.lectureAgeGen"/>
+ </div>
+ <div class="inputFile" id="eventsFile">
+ <s:file name="events" required="true"
+ key="echobase.label.import.events"/>
+ </div>
+ <div class="inputFile" id="typeEchoSpeciesFile">
+ <s:file name="typeEchoSpecies" required="true"
+ key="echobase.label.import.typeEchoSpecies"/>
- <s:file name="capture"
- key="echobase.label.import.pecherie"/>
-
- <s:file name="lectureAgeGen"
- key="echobase.label.import.lectureAgeGen"/>
-
- <s:file name="events"
- key="echobase.label.import.events"/>
-
- <s:file name="typeEchoSpecies"
- key="echobase.label.import.typeEchoSpecies"/>
-
+ </div>
</fieldset>
<br/>
- <s:submit id="addFilesSubmit" action="configureFiles"
+ <s:submit action="configureFiles"
value='%{getText("echobase.action.import")}'/>
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/configureMission.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/configureMission.jsp 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/configureMission.jsp 2011-11-27 10:09:45 UTC (rev 136)
@@ -38,13 +38,13 @@
$("#" + val).show();
});
</script>
-<title><s:text name="echobase.title.import.configuration"/></title>
+<title><s:text name="echobase.title.importData.configuration"/></title>
<s:form id="importForm" namespace="/importData" method="POST">
<fieldset>
<legend>
- <s:text name="echobase.legend.import.configuration.mission"/>
+ <s:text name="echobase.legend.importData.configuration.mission"/>
</legend>
<s:radio key='importMode' list="importModes"
Deleted: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importProgress.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importProgress.jsp 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importProgress.jsp 2011-11-27 10:09:45 UTC (rev 136)
@@ -1,40 +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="url" action="doImport" namespace="/importData"/>
-<meta http-equiv="refresh" content="1;url=${url}"/>
-
-<title><s:text name="echobase.title.importProgress"/></title>
-
-<%-- TODO letellier 20111104 : Add warn icon --%>
-<p><s:text name="echobase.message.warnImportInProgress"/></p>
-
-<br/>
-
-<div>
- <sj:progressbar value="%{model.progression}"/>
-</div>
\ No newline at end of file
Deleted: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importResult.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importResult.jsp 2011-11-27 10:06:33 UTC (rev 135)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importResult.jsp 2011-11-27 10:09:45 UTC (rev 136)
@@ -1,60 +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" %>
-
-<title><s:text name="echobase.title.importResult"/></title>
-
-<fieldset>
- <legend>
- <s:text name="echobase.legend.import.configuration.mission.resume"/>
- </legend>
- <s:label value="%{model.mission.missionName}"
- key='echobase.common.missionName'/>
-
- <s:label value="%{model.mission.missionAbstract}"
- key='echobase.common.missionAbstract'/>
-</fieldset>
-<br/>
-<s:iterator value="importResult" var="entry">
- <s:set var="inputFile" value="%{#entry.key}"/>
- <s:set var="result" value="%{#entry.value}"/>
- <fieldset>
- <legend>
- <s:text name="echobase.legend.importFileResult">
- <s:param><strong><s:property
- value="%{#inputFile.label}"/></strong></s:param>
- </s:text>
- </legend>
-
- <s:label value="%{#inputFile.fileName}"
- label="%{getText('echobase.label.importFile')}"/>
-
- <s:label value="%{#result.numberCreated}"
- label="%{getText('echobase.label.numberOfCreatedEntities')}"/>
-
- <s:label value="%{#result.numberUpdated}"
- label="%{getText('echobase.label.numberOfUpdatedEntities')}"/>
- </fieldset>
-</s:iterator>
Copied: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/progress.jsp (from rev 132, trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importProgress.jsp)
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/progress.jsp (rev 0)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/progress.jsp 2011-11-27 10:09:45 UTC (rev 136)
@@ -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="doImport" namespace="/importData"/>
+<meta http-equiv="refresh" content="1;url=${url}"/>
+
+<title><s:text name="echobase.title.importDataProgress"/></title>
+
+<%-- TODO letellier 20111104 : Add warn icon --%>
+<p><s:text name="echobase.message.warnImportInProgress"/></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/importData/progress.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Copied: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/result.jsp (from rev 133, trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importResult.jsp)
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/result.jsp (rev 0)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/result.jsp 2011-11-27 10:09:45 UTC (rev 136)
@@ -0,0 +1,60 @@
+<%--
+ #%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.importDataResult"/></title>
+
+<fieldset>
+ <legend>
+ <s:text name="echobase.legend.importData.configuration.mission.resume"/>
+ </legend>
+ <s:label value="%{model.mission.missionName}"
+ key='echobase.common.missionName'/>
+
+ <s:label value="%{model.mission.missionAbstract}"
+ key='echobase.common.missionAbstract'/>
+</fieldset>
+<br/>
+<s:iterator value="importResult" var="entry">
+ <s:set var="inputFile" value="%{#entry.key}"/>
+ <s:set var="result" value="%{#entry.value}"/>
+ <fieldset>
+ <legend>
+ <s:text name="echobase.legend.importFileResult">
+ <s:param><strong><s:property
+ value="%{#inputFile.label}"/></strong></s:param>
+ </s:text>
+ </legend>
+
+ <s:label value="%{#inputFile.fileName}"
+ label="%{getText('echobase.label.importFile')}"/>
+
+ <s:label value="%{#result.numberCreated}"
+ label="%{getText('echobase.label.numberOfCreatedEntities')}"/>
+
+ <s:label value="%{#result.numberUpdated}"
+ label="%{getText('echobase.label.numberOfUpdatedEntities')}"/>
+ </fieldset>
+</s:iterator>
Property changes on: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/result.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importHistorical/configure.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importHistorical/configure.jsp (rev 0)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importHistorical/configure.jsp 2011-11-27 10:09:45 UTC (rev 136)
@@ -0,0 +1,45 @@
+<%--
+ #%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.importHistorical"/></title>
+
+<s:form namespace="/importHistorical" method="POST" enctype="multipart/form-data">
+
+ <fieldset>
+ <legend>
+ <s:text name="echobase.legend.importHistorical.configuration.files"/>
+ </legend>
+
+ <s:file name="input" required="true"
+ key="echobase.common.importHistoricalFile"/>
+
+ </fieldset>
+ <br/>
+ <s:submit action="configureImport"
+ value='%{getText("echobase.action.import")}'/>
+
+
+</s:form>
\ No newline at end of file
Property changes on: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importHistorical/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/importHistorical/progress.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importHistorical/progress.jsp (rev 0)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importHistorical/progress.jsp 2011-11-27 10:09:45 UTC (rev 136)
@@ -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="doImport" namespace="/importHistorical"/>
+<meta http-equiv="refresh" content="1;url=${url}"/>
+
+<title><s:text name="echobase.title.importHistoricalProgress"/></title>
+
+<%-- TODO letellier 20111104 : Add warn icon --%>
+<p><s:text name="echobase.message.warnImportInProgress"/></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/importHistorical/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/importHistorical/result.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importHistorical/result.jsp (rev 0)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importHistorical/result.jsp 2011-11-27 10:09:45 UTC (rev 136)
@@ -0,0 +1,48 @@
+<%--
+ #%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.importHistoricalResult"/></title>
+
+<fieldset>
+ <legend>
+ <s:text name="echobase.legend.importFileResult">
+ <s:param><strong><s:property
+ value="%{model.input.label}"/></strong></s:param>
+ </s:text>
+ </legend>
+
+ <s:label value="%{model.input.fileName}"
+ label="%{getText('echobase.label.importFile')}"/>
+
+ <s:label value="%{importResult.numberCreated}"
+ label="%{getText('echobase.label.numberOfCreatedEntities')}"/>
+
+ <s:label value="%{importResult.numberUpdated}"
+ label="%{getText('echobase.label.numberOfUpdatedEntities')}"/>
+</fieldset>
+
+<div>TODO</div>
+
Property changes on: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importHistorical/result.jsp
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
1
0
r135 - trunk/echobase-entities/src/main/resources/i18n
by tchemit@users.forge.codelutin.com 27 Nov '11
by tchemit@users.forge.codelutin.com 27 Nov '11
27 Nov '11
Author: tchemit
Date: 2011-11-27 11:06:33 +0100 (Sun, 27 Nov 2011)
New Revision: 135
Url: http://forge.codelutin.com/repositories/revision/echobase/135
Log:
clean i18n
Modified:
trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties
Modified: trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties
===================================================================
--- trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties 2011-11-27 10:06:07 UTC (rev 134)
+++ trunk/echobase-entities/src/main/resources/i18n/echobase-entities_fr_FR.properties 2011-11-27 10:06:33 UTC (rev 135)
@@ -38,7 +38,6 @@
echobase.common.categoryValue=
echobase.common.cell=cell
echobase.common.cellMethod=
-echobase.common.cellMethods=
echobase.common.cellName=
echobase.common.cellType=
echobase.common.citation=
@@ -51,13 +50,9 @@
echobase.common.dataCentre=Centre de données
echobase.common.dataCentreEmail=Courriel du centre de données
echobase.common.dataMetadata=
-echobase.common.dataMetadataName=
echobase.common.dataName=
echobase.common.dataProcessing=dataProcessing
echobase.common.dataQuality=dataQuality
-echobase.common.dataQualityFlagMeaning=
-echobase.common.dataQualityFlagNote=
-echobase.common.dataQualityFlagValue=
echobase.common.dataType=
echobase.common.dataValue=
echobase.common.dateCreated=
@@ -78,8 +73,6 @@
echobase.common.echotype=
echobase.common.echotypeCategory=
echobase.common.echotypeCategoryName=
-echobase.common.echotypeDepthStratum=
-echobase.common.echotypeGeniusSpecies=
echobase.common.echotypeLengthCategory=
echobase.common.echotypeMeaning=
echobase.common.echotypeName=
@@ -116,7 +109,6 @@
echobase.common.geospatialVerticalMin=
echobase.common.geospatialVerticalPositive=
echobase.common.history=
-echobase.common.iMO=
echobase.common.id=Identifiant
echobase.common.imo=
echobase.common.impacte=
@@ -141,7 +133,6 @@
echobase.common.loggedDataFormat=
echobase.common.longName=
echobase.common.m=
-echobase.common.meaning=
echobase.common.measureType=
echobase.common.measurementBinSize=
echobase.common.measurementMetadata=
@@ -189,8 +180,6 @@
echobase.common.referenceDatumType=
echobase.common.referenceDatumTypeName=
echobase.common.referenceMeaning=
-echobase.common.referenceType=
-echobase.common.referenceValue=
echobase.common.referencingMethod=
echobase.common.relatedActivity=
echobase.common.result=
1
0
r134 - in trunk/echobase-services/src/main: java/fr/ifremer/echobase java/fr/ifremer/echobase/services resources/i18n
by tchemit@users.forge.codelutin.com 27 Nov '11
by tchemit@users.forge.codelutin.com 27 Nov '11
27 Nov '11
Author: tchemit
Date: 2011-11-27 11:06:07 +0100 (Sun, 27 Nov 2011)
New Revision: 134
Url: http://forge.codelutin.com/repositories/revision/echobase/134
Log:
- ajout type d'import de donn?\195?\169es (enum ImportDataMode)
- mise en place squelette import historique
Added:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataMode.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportHistoricalConfiguration.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportHistoricalService.java
Modified:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/InputFile.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataConfiguration.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataService.java
trunk/echobase-services/src/main/resources/i18n/echobase-services_fr_FR.properties
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/InputFile.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/InputFile.java 2011-11-26 11:02:53 UTC (rev 133)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/InputFile.java 2011-11-27 10:06:07 UTC (rev 134)
@@ -48,7 +48,11 @@
/** Label of the import. */
protected String label;
- public InputFile(String label) {
+ public static InputFile newFile(String label) {
+ return new InputFile(label);
+ }
+
+ protected InputFile(String label) {
this.label = label;
}
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-11-26 11:02:53 UTC (rev 133)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataConfiguration.java 2011-11-27 10:06:07 UTC (rev 134)
@@ -25,7 +25,10 @@
import fr.ifremer.echobase.InputFile;
import fr.ifremer.echobase.entities.references.Mission;
+import org.apache.commons.io.FileUtils;
+import java.io.File;
+import java.io.IOException;
import java.io.Serializable;
import java.util.Locale;
@@ -44,6 +47,10 @@
/** Mission used for the import (may not be in db if needed to be created). */
protected Mission mission;
+ protected ImportDataMode importDataMode;
+
+ protected File workingDirectory;
+
protected InputFile acousticFile;
protected InputFile captureFile;
@@ -61,13 +68,26 @@
protected float progression;
public ImportDataConfiguration(Locale locale) {
- acousticFile = new InputFile(l_(locale, "echobase.common.acousticImport"));
- captureFile = new InputFile(l_(locale, "echobase.common.captureImport"));
- lectureAgeGenFile = new InputFile(l_(locale, "echobase.common.lectureAgeGenImport"));
- eventsFile = new InputFile(l_(locale, "echobase.common.eventsImport"));
- typeEchoSpeciesFile = new InputFile(l_(locale, "echobase.common.typeEchoSpeciesImport"));
+ acousticFile = InputFile.newFile(
+ l_(locale, "echobase.common.acousticImport"));
+ captureFile = InputFile.newFile(
+ l_(locale, "echobase.common.captureImport"));
+ lectureAgeGenFile = InputFile.newFile(
+ l_(locale, "echobase.common.lectureAgeGenImport"));
+ eventsFile = InputFile.newFile(
+ l_(locale, "echobase.common.eventsImport"));
+ typeEchoSpeciesFile = InputFile.newFile(
+ l_(locale, "echobase.common.typeEchoSpeciesImport"));
}
+ public ImportDataMode getImportDataMode() {
+ return importDataMode;
+ }
+
+ public File getWorkingDirectory() {
+ return workingDirectory;
+ }
+
public Mission getMission() {
return mission;
}
@@ -100,6 +120,14 @@
return progression;
}
+ public void setImportDataMode(ImportDataMode importDataMode) {
+ this.importDataMode = importDataMode;
+ }
+
+ public void setWorkingDirectory(File workingDirectory) {
+ this.workingDirectory = workingDirectory;
+ }
+
public void setMission(Mission mission) {
this.mission = mission;
}
@@ -114,21 +142,19 @@
public void computeSteps() {
nbSteps = 0;
- if (acousticFile.getFile() != null) {
- nbSteps++;
+ switch (importDataMode) {
+ case ALL:
+ nbSteps = 5;
+ case ACOUSTIC:
+ nbSteps = 1;
+ default:
}
- if (captureFile.getFile() != null) {
- nbSteps++;
- }
- if (lectureAgeGenFile.getFile() != null) {
- nbSteps++;
- }
- if (eventsFile.getFile() != null) {
- nbSteps++;
- }
- if (typeEchoSpeciesFile.getFile() != null) {
- nbSteps++;
- }
stepIncrement = 100f / nbSteps;
}
+
+ public void destroy() throws IOException {
+ if (workingDirectory != null) {
+ FileUtils.deleteDirectory(workingDirectory);
+ }
+ }
}
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataMode.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataMode.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataMode.java 2011-11-27 10:06:07 UTC (rev 134)
@@ -0,0 +1,50 @@
+/*
+ * #%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 static org.nuiton.i18n.I18n.n_;
+
+/**
+ * To define the mode of import data (says files to be imported).
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public enum ImportDataMode {
+
+ /** Import only acoustic file. */
+ ACOUSTIC(n_("echobase.common.importDataMode.acoustic")),
+ /** Import all files. */
+ ALL(n_("echobase.common.importDataMode.all"));
+
+ private final String i18nKey;
+
+ ImportDataMode(String i18nKey) {
+ this.i18nKey = i18nKey;
+ }
+
+ public String getI18nKey() {
+ return i18nKey;
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataMode.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/ImportDataService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataService.java 2011-11-26 11:02:53 UTC (rev 133)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportDataService.java 2011-11-27 10:06:07 UTC (rev 134)
@@ -60,6 +60,29 @@
Map<InputFile, CsvImportResult> result = Maps.newHashMap();
+
+ ImportDataMode importDataMode = configuration.getImportDataMode();
+ switch (importDataMode) {
+ case ACOUSTIC:
+ doImportAcoustic(configuration, result);
+ break;
+ case ALL:
+ doImportAll(configuration, result);
+ break;
+ default:
+ throw new IllegalStateException(
+ "Can not know what to do with importDataMode " +
+ importDataMode);
+
+ }
+
+
+ return result;
+ }
+
+ protected void doImportAcoustic(ImportDataConfiguration configuration,
+ Map<InputFile, CsvImportResult> result) {
+
Mission mission = configuration.getMission();
// compute nb step to treate (means nb imports to do)
@@ -83,7 +106,35 @@
deleteFile(acousticFile);
}
}
+ }
+ protected void doImportAll(ImportDataConfiguration configuration,
+ Map<InputFile, CsvImportResult> result) {
+
+ Mission mission = configuration.getMission();
+
+ // compute nb step to treate (means nb imports to do)
+ configuration.computeSteps();
+
+ if (log.isInfoEnabled()) {
+ log.info("Starts data import with mission " +
+ mission.getMissionName());
+ }
+
+ InputFile acousticFile = configuration.getAcousticFile();
+ if (acousticFile.getFile() != null) {
+
+ // do acoustic import
+ try {
+ CsvImportResult importResult =
+ importAcoustic(mission, acousticFile);
+ configuration.incrementsProgression();
+ result.put(acousticFile, importResult);
+ } finally {
+ deleteFile(acousticFile);
+ }
+ }
+
InputFile captureFile = configuration.getCaptureFile();
if (captureFile.getFile() != null) {
@@ -139,8 +190,6 @@
deleteFile(typeEchoSpeciesFile);
}
}
-
- return result;
}
protected void deleteFile(InputFile input) {
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportHistoricalConfiguration.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportHistoricalConfiguration.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportHistoricalConfiguration.java 2011-11-27 10:06:07 UTC (rev 134)
@@ -0,0 +1,102 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 Ifremer, Codelutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package fr.ifremer.echobase.services;
+
+import fr.ifremer.echobase.InputFile;
+import org.apache.commons.io.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Locale;
+
+import static org.nuiton.i18n.I18n.l_;
+
+/**
+ * Configuration of an historical import.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class ImportHistoricalConfiguration implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ protected File workingDirectory;
+
+
+ protected InputFile input;
+
+ protected int nbSteps;
+
+ private float stepIncrement;
+
+ protected float progression;
+
+ public ImportHistoricalConfiguration(Locale locale) {
+ input = InputFile.newFile(
+ l_(locale, "echobase.common.importHistoricalFile"));
+ }
+
+ public File getWorkingDirectory() {
+ return workingDirectory;
+ }
+
+ public InputFile getInput() {
+ 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 computeSteps() {
+ nbSteps = 0;
+
+ stepIncrement = 100f / nbSteps;
+ }
+
+ 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/ImportHistoricalConfiguration.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/ImportHistoricalService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportHistoricalService.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportHistoricalService.java 2011-11-27 10:06:07 UTC (rev 134)
@@ -0,0 +1,94 @@
+/*
+ * #%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.InputFile;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.io.File;
+
+/**
+ * To import historical datas (from access database).
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class ImportHistoricalService extends EchoBaseServiceSupport {
+
+ /** Logger. */
+ private static final Log log =
+ LogFactory.getLog(ImportHistoricalService.class);
+
+ public CsvImportResult startImport(ImportHistoricalConfiguration configuration) {
+
+ CsvImportResult result;
+
+ InputFile input = configuration.getInput();
+
+ if (log.isInfoEnabled()) {
+ log.info("Starts historical import with file " +
+ input.getFileName());
+ }
+
+ try {
+
+ result = doImport(input);
+
+ } finally {
+ deleteFile(input);
+ }
+ return result;
+ }
+
+ protected CsvImportResult doImport(InputFile input) {
+
+ CsvImportResult result = new CsvImportResult();
+ prepareImport();
+ return result;
+ }
+
+ protected void deleteFile(InputFile input) {
+ File file = input.getFile();
+
+ if (log.isInfoEnabled()) {
+ log.info("Will delete import file " + file);
+ }
+ boolean wasDel = file.delete();
+ if (!wasDel) {
+ throw new EchoBaseTechnicalException("Could not delete file " + file);
+ }
+ }
+
+
+ protected void prepareImport() {
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ }
+
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportHistoricalService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-services/src/main/resources/i18n/echobase-services_fr_FR.properties
===================================================================
--- trunk/echobase-services/src/main/resources/i18n/echobase-services_fr_FR.properties 2011-11-26 11:02:53 UTC (rev 133)
+++ trunk/echobase-services/src/main/resources/i18n/echobase-services_fr_FR.properties 2011-11-27 10:06:07 UTC (rev 134)
@@ -1,5 +1,8 @@
echobase.common.acousticImport=Import Acoustique
echobase.common.captureImport=Import Pêcherie
echobase.common.eventsImport=Import Evènements
+echobase.common.importDataMode.acoustic=Import Acoustic
+echobase.common.importDataMode.all=Import globale
+echobase.common.importHistoricalFile=Fichier MS-ACCESS de données historiques
echobase.common.lectureAgeGenImport=Import Lecture Agen Gen
echobase.common.typeEchoSpeciesImport=Import Type EchoSpecies
1
0
r133 - trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData
by tchemit@users.forge.codelutin.com 26 Nov '11
by tchemit@users.forge.codelutin.com 26 Nov '11
26 Nov '11
Author: tchemit
Date: 2011-11-26 12:02:53 +0100 (Sat, 26 Nov 2011)
New Revision: 133
Url: http://forge.codelutin.com/repositories/revision/echobase/133
Log:
fix import data
Modified:
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/configureFiles.jsp
trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importResult.jsp
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/configureFiles.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/configureFiles.jsp 2011-11-26 10:50:09 UTC (rev 132)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/configureFiles.jsp 2011-11-26 11:02:53 UTC (rev 133)
@@ -45,7 +45,7 @@
<s:text name="echobase.legend.import.configuration.files"/>
</legend>
- <s:hidden key="voyageId" label=''/>
+ <s:hidden key="missionId" label=''/>
<s:file name="acoustic"
key="echobase.label.import.accoustique"/>
Modified: trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importResult.jsp
===================================================================
--- trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importResult.jsp 2011-11-26 10:50:09 UTC (rev 132)
+++ trunk/echobase-ui/src/main/webapp/WEB-INF/jsp/importData/importResult.jsp 2011-11-26 11:02:53 UTC (rev 133)
@@ -26,13 +26,25 @@
<title><s:text name="echobase.title.importResult"/></title>
+<fieldset>
+ <legend>
+ <s:text name="echobase.legend.import.configuration.mission.resume"/>
+ </legend>
+ <s:label value="%{model.mission.missionName}"
+ key='echobase.common.missionName'/>
+
+ <s:label value="%{model.mission.missionAbstract}"
+ key='echobase.common.missionAbstract'/>
+</fieldset>
+<br/>
<s:iterator value="importResult" var="entry">
<s:set var="inputFile" value="%{#entry.key}"/>
<s:set var="result" value="%{#entry.value}"/>
<fieldset>
<legend>
<s:text name="echobase.legend.importFileResult">
- <s:param><strong><s:property value="%{#inputFile.label}"/></strong></s:param>
+ <s:param><strong><s:property
+ value="%{#inputFile.label}"/></strong></s:param>
</s:text>
</legend>
1
0