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
r215 - in trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui: . actions/dbeditor
by tchemit@users.forge.codelutin.com 26 Dec '11
by tchemit@users.forge.codelutin.com 26 Dec '11
26 Dec '11
Author: tchemit
Date: 2011-12-26 11:13:15 +0100 (Mon, 26 Dec 2011)
New Revision: 215
Url: http://forge.codelutin.com/repositories/revision/echobase/215
Log:
use new service api
Modified:
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ExportTable.java
trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ImportTable.java
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java 2011-12-26 10:12:41 UTC (rev 214)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/EchoBaseApplicationListener.java 2011-12-26 10:13:15 UTC (rev 215)
@@ -24,11 +24,9 @@
package fr.ifremer.echobase.ui;
import com.google.common.base.Supplier;
-import com.google.common.collect.Lists;
import fr.ifremer.echobase.EchoBaseConfiguration;
import fr.ifremer.echobase.EchoBaseTechnicalException;
import fr.ifremer.echobase.EchoBaseTopiaRootContextSupplierFactory;
-import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.EchoBaseUser;
import fr.ifremer.echobase.entities.EchoBaseUserImpl;
import fr.ifremer.echobase.entities.meta.DbMeta;
@@ -104,10 +102,7 @@
new EchoBaseTopiaRootContextSupplierFactory();
rootContextSupplier = factory.newDatabaseFromConfig(configuration);
applicationContext.setRootContextSupplier(rootContextSupplier);
- List<EchoBaseEntityEnum> entityEnums =
- Lists.newArrayList(EchoBaseEntityEnum.values());
-// entityEnums.remove(EchoBaseEntityEnum.EchoBaseUser);
- DbMeta dbMeta = DbMeta.newDbMeta(entityEnums);
+ DbMeta dbMeta = DbMeta.newDbMeta();
applicationContext.setDbMeta(dbMeta);
@@ -220,7 +215,7 @@
// no users in database create the admin user
if (log.isInfoEnabled()) {
log.info("No user in database, will create default " +
- "admin user (password admin).");
+ "admin user (password admin).");
}
service.createDefaultAdminUser();
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ExportTable.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ExportTable.java 2011-12-26 10:12:41 UTC (rev 214)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ExportTable.java 2011-12-26 10:13:15 UTC (rev 215)
@@ -24,7 +24,8 @@
package fr.ifremer.echobase.ui.actions.dbeditor;
import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
-import fr.ifremer.echobase.services.DbEditorService;
+import fr.ifremer.echobase.entities.meta.TableMeta;
+import fr.ifremer.echobase.services.ExportService;
import fr.ifremer.echobase.ui.actions.EchoBaseActionSupport;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -87,9 +88,10 @@
@Override
public String execute() throws Exception {
- DbEditorService service = newService(DbEditorService.class);
+ ExportService exportService = newService(ExportService.class);
- String content = service.exportDatas(service.getTableMeta(entityType));
+ TableMeta table = serviceContext.getDbMeta().getTable(entityType);
+ String content = exportService.exportDatas(table);
if (log.isDebugEnabled()) {
log.debug("file to export " + content);
Modified: trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ImportTable.java
===================================================================
--- trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ImportTable.java 2011-12-26 10:12:41 UTC (rev 214)
+++ trunk/echobase-ui/src/main/java/fr/ifremer/echobase/ui/actions/dbeditor/ImportTable.java 2011-12-26 10:13:15 UTC (rev 215)
@@ -26,7 +26,7 @@
import com.google.common.base.Throwables;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;
import fr.ifremer.echobase.services.CsvImportResult;
-import fr.ifremer.echobase.services.DbEditorService;
+import fr.ifremer.echobase.services.ImportService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -111,14 +111,14 @@
// to call input method on validation error to initialize dbeditor page
public String execute() throws Exception {
- DbEditorService dbEditorService = newService(DbEditorService.class);
+ ImportService importService = newService(ImportService.class);
try {
- result = dbEditorService.importDatas(getEntityType(),
- importFileFileName,
- importFile,
- createIfNotFound,
- getEchoBaseSession().getEchoBaseUser());
+ result = importService.importDatas(getEntityType(),
+ importFileFileName,
+ importFile,
+ createIfNotFound,
+ getEchoBaseSession().getEchoBaseUser());
} catch (Exception eee) {
String message = "Failed to import datas : ";
1
0
r214 - in trunk/echobase-tools/src: main/java/fr/ifremer/echobase/tools/loaders test/java/fr/ifremer/echobase/tools test/java/fr/ifremer/echobase/tools/loaders
by tchemit@users.forge.codelutin.com 26 Dec '11
by tchemit@users.forge.codelutin.com 26 Dec '11
26 Dec '11
Author: tchemit
Date: 2011-12-26 11:12:41 +0100 (Mon, 26 Dec 2011)
New Revision: 214
Url: http://forge.codelutin.com/repositories/revision/echobase/214
Log:
use new service apis
Modified:
trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/DataMetadataLoader.java
trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/EntityLoader.java
trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/ReferenceDatumLoader.java
trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/VoyageLoader.java
trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/AbstractToolTest.java
trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/AbstractLoaderIT.java
Modified: trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/DataMetadataLoader.java
===================================================================
--- trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/DataMetadataLoader.java 2011-12-26 10:10:04 UTC (rev 213)
+++ trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/DataMetadataLoader.java 2011-12-26 10:12:41 UTC (rev 214)
@@ -108,9 +108,9 @@
meta
);
- List<DataType> dataTypes = getDbEditorService().getEntities(DataType.class);
- List<ReferenceDatum> referenceDatums = getDbEditorService().getEntities(ReferenceDatum.class);
- List<CellMethod> cellMethods = getDbEditorService().getEntities(CellMethod.class);
+ List<DataType> dataTypes = getEntities(DataType.class);
+ List<ReferenceDatum> referenceDatums = getEntities(ReferenceDatum.class);
+ List<CellMethod> cellMethods = getEntities(CellMethod.class);
model.addForeignKeyForImport("DataTypeID", DataMetadata.PROPERTY_DATA_TYPE, DataType.class, dataTypes, EchoBaseFunctions.DATA_TYPE_NAME);
Modified: trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/EntityLoader.java
===================================================================
--- trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/EntityLoader.java 2011-12-26 10:10:04 UTC (rev 213)
+++ trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/EntityLoader.java 2011-12-26 10:12:41 UTC (rev 214)
@@ -38,10 +38,10 @@
import fr.ifremer.echobase.entities.meta.TableMeta;
import fr.ifremer.echobase.services.CsvImportResult;
import fr.ifremer.echobase.services.DbEditorService;
-import fr.ifremer.echobase.services.DbImportService;
import fr.ifremer.echobase.services.EchoBaseServiceContext;
import fr.ifremer.echobase.services.EchoBaseServiceSupport;
-import fr.ifremer.echobase.services.models.EntityAssociationImportModel;
+import fr.ifremer.echobase.services.ExportService;
+import fr.ifremer.echobase.services.ImportService;
import fr.ifremer.echobase.services.models.EntityCsvModel;
import fr.ifremer.echobase.tools.FileType;
import org.apache.commons.io.IOUtils;
@@ -82,8 +82,6 @@
private static final EchoBaseEntityEnum[] EMPTY_DEPENDENCIES_ARRAY =
new EchoBaseEntityEnum[0];
- private DbEditorService dbEditorService;
-
private final Class<E> entityClass;
private final EchoBaseEntityEnum entityType;
@@ -205,10 +203,8 @@
log.info("Import " + entityType + " from " + csvfile);
}
- DbEditorService service = getDbEditorService();
+ TableMeta meta = getTable(entityType);
- TableMeta meta = service.getTableMeta(entityType);
-
EntityCsvModel<E> csvModel = createCsvImportModel(meta);
BufferedReader bf = new BufferedReader(new FileReader(csvfile));
@@ -217,12 +213,16 @@
Import<E> importer = Import.newImport(csvModel, bf);
try {
+ DbEditorService dbEditorService =
+ getService(DbEditorService.class);
+
for (E entity : importer) {
- service.saveEntity(meta,
- "",
- entity,
- null,
- false
+
+ dbEditorService.saveEntity(meta,
+ "",
+ entity,
+ null,
+ false
);
}
} finally {
@@ -240,7 +240,7 @@
File out = getTableFile(outputDir, meta, FileType.NEW);
- getDbEditorService().exportDatas(meta, out);
+ getExportService().exportDatas(meta, out);
} finally {
if (cleanTransaction) {
serviceContext.getTransaction().rollbackTransaction();
@@ -286,7 +286,7 @@
File out = getTableFile(outputDir, meta, targetType);
- getDbEditorService().exportDatas(meta, out);
+ getExportService().exportDatas(meta, out);
}
protected void copyAndLoad(File outputDir) throws IOException, TopiaException {
@@ -338,8 +338,6 @@
boolean commit,
FileType... fileTypes) throws IOException, TopiaException {
- DbImportService service = newService(DbImportService.class);
-
for (FileType fileType : fileTypes) {
File out = getTableFile(directory, meta, fileType);
@@ -370,13 +368,14 @@
return getDAO(entityClass);
}
- protected final DbEditorService getDbEditorService() {
- if (dbEditorService == null) {
- dbEditorService = serviceContext.newService(DbEditorService.class);
- }
- return dbEditorService;
+ protected final ImportService getImportService() {
+ return getService(ImportService.class);
}
+ protected final ExportService getExportService() {
+ return getService(ExportService.class);
+ }
+
protected final char getCsvSeparator() {
return serviceContext.getConfiguration().getCsvSeparator();
}
@@ -389,7 +388,7 @@
FileType targetType,
AssociationMeta associationMeta) throws IOException {
File out = getTableFile(outputDir, associationMeta, targetType);
- getDbEditorService().exportDatas(associationMeta, out);
+ getExportService().exportDatas(associationMeta, out);
}
@@ -411,7 +410,7 @@
Reader reader,
CsvImportResult csvResult) throws IOException {
- DbEditorService service = getDbEditorService();
+ ImportService service = getImportService();
if (entry instanceof AssociationMeta) {
@@ -423,17 +422,12 @@
log.info("Will import " + meta);
}
- EchoBaseEntityEnum source = meta.getSource();
EchoBaseEntityEnum target = meta.getTarget();
List<TopiaEntity> targetEntities = getEntities(target);
Map<String, TopiaEntity> targetsById =
Maps.uniqueIndex(targetEntities, EchoBaseFunctions.TO_TOPIAID);
- ImportModel<Map<String, Object>> model =
- EntityAssociationImportModel.newImportModel(
- getConfiguration().getCsvSeparator(),
- meta
- );
+ ImportModel<Map<String, Object>> model = service.buildForImport(meta);
EchoBaseEntityEnum sourceType = meta.getSource();
Modified: trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/ReferenceDatumLoader.java
===================================================================
--- trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/ReferenceDatumLoader.java 2011-12-26 10:10:04 UTC (rev 213)
+++ trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/ReferenceDatumLoader.java 2011-12-26 10:12:41 UTC (rev 214)
@@ -89,7 +89,7 @@
);
List<ReferenceDatumType> referenceDatumTypes =
- getDbEditorService().getEntities(ReferenceDatumType.class);
+ getEntities(ReferenceDatumType.class);
model.newMandatoryColumn(ReferenceDatum.PROPERTY_ID);
model.newMandatoryColumn(ReferenceDatum.PROPERTY_MEANING);
Modified: trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/VoyageLoader.java
===================================================================
--- trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/VoyageLoader.java 2011-12-26 10:10:04 UTC (rev 213)
+++ trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/VoyageLoader.java 2011-12-26 10:12:41 UTC (rev 214)
@@ -196,7 +196,7 @@
File out = getTableFile(outputDir, associationMeta, FileType.ASSOCIATION);
- getDbEditorService().exportDatas(associationMeta, out);
+ getExportService().exportDatas(associationMeta, out);
} finally {
if (cleanTransaction) {
Modified: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/AbstractToolTest.java
===================================================================
--- trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/AbstractToolTest.java 2011-12-26 10:10:04 UTC (rev 213)
+++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/AbstractToolTest.java 2011-12-26 10:12:41 UTC (rev 214)
@@ -29,7 +29,6 @@
import fr.ifremer.echobase.entities.EchoBaseDAOHelper;
import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.meta.DbMeta;
-import fr.ifremer.echobase.services.DbEditorService;
import fr.ifremer.echobase.services.EchoBaseService;
import fr.ifremer.echobase.services.EchoBaseServiceContext;
import fr.ifremer.echobase.services.EchoBaseServiceContextImpl;
@@ -72,8 +71,6 @@
protected static EchoBaseConfiguration configuration;
- private DbEditorService service;
-
@BeforeClass
public static void beforeClass() {
@@ -120,13 +117,6 @@
return serviceContext.newService(clazz);
}
- protected DbEditorService getService() {
- if (service == null) {
- service = newService(DbEditorService.class);
- }
- return service;
- }
-
protected <E extends TopiaEntity> TopiaDAO<E> getDao(Class<E> entityClass) throws TopiaException {
TopiaDAO<E> dao = EchoBaseDAOHelper.<E, TopiaDAO<E>>getDAO(serviceContext.getTransaction(), entityClass);
return dao;
Modified: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/AbstractLoaderIT.java
===================================================================
--- trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/AbstractLoaderIT.java 2011-12-26 10:10:04 UTC (rev 213)
+++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/AbstractLoaderIT.java 2011-12-26 10:12:41 UTC (rev 214)
@@ -33,6 +33,7 @@
import fr.ifremer.echobase.entities.meta.MetaFilenameAware;
import fr.ifremer.echobase.entities.meta.TableMeta;
import fr.ifremer.echobase.services.CsvImportResult;
+import fr.ifremer.echobase.services.ImportService;
import fr.ifremer.echobase.tools.AbstractToolTest;
import fr.ifremer.echobase.tools.FileType;
import fr.ifremer.echobase.tools.TestHelper;
@@ -292,7 +293,7 @@
if (log.isInfoEnabled()) {
log.info("Import " + inFile);
}
- CsvImportResult csvImportResult = getService().importDatas(
+ CsvImportResult csvImportResult = newService(ImportService.class).importDatas(
loader.getEntityType(),
inFile.getAbsolutePath(),
inFile,
1
0
r213 - in trunk/echobase-services/src: main/java/fr/ifremer/echobase/services main/java/fr/ifremer/echobase/services/models test/java/fr/ifremer/echobase/services
by tchemit@users.forge.codelutin.com 26 Dec '11
by tchemit@users.forge.codelutin.com 26 Dec '11
26 Dec '11
Author: tchemit
Date: 2011-12-26 11:10:04 +0100 (Mon, 26 Dec 2011)
New Revision: 213
Url: http://forge.codelutin.com/repositories/revision/echobase/213
Log:
introduce two atomic servies (ImportService and Exportservice)
introduce two atomic services (for db import / export)
improve service api (add a cache of services)
Added:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationExportModel.java
Removed:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.java
Modified:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationImportModel.java
trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java
trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/DbImportExportServiceTest.java
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbEditorService.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -29,13 +29,10 @@
import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.EchoBaseUser;
import fr.ifremer.echobase.entities.EntityModificationLog;
-import fr.ifremer.echobase.entities.meta.AssociationMeta;
import fr.ifremer.echobase.entities.meta.ColumnMeta;
import fr.ifremer.echobase.entities.meta.DbMeta;
-import fr.ifremer.echobase.entities.meta.MetaFilenameAware;
import fr.ifremer.echobase.entities.meta.TableMeta;
import fr.ifremer.echobase.services.models.CsvModelUtil;
-import fr.ifremer.echobase.services.models.EntityAssociationCsvModel;
import fr.ifremer.echobase.services.models.EntityCsvModel;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
@@ -47,17 +44,10 @@
import org.nuiton.util.TimeLog;
import org.nuiton.util.beans.BeanMonitor;
import org.nuiton.util.beans.PropertyDiff;
-import org.nuiton.util.csv.Export;
-import org.nuiton.util.csv.ExportModel;
import org.nuiton.util.csv.ExportableColumn;
-import org.nuiton.util.csv.Import;
import org.nuiton.util.csv.ImportExportModel;
import org.nuiton.util.csv.ImportableColumn;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -75,13 +65,8 @@
public static final TimeLog timeLog = new TimeLog(DbEditorService.class);
- protected DecoratorService decoratorService;
-
protected DecoratorService getDecoratorService() {
- if (decoratorService == null) {
- decoratorService = newService(DecoratorService.class);
- }
- return decoratorService;
+ return getService(DecoratorService.class);
}
public <E extends TopiaEntity> List<E> getForeignDatas(Class<E> entityType) {
@@ -128,8 +113,6 @@
rows[i++] = row;
}
return rows;
-
-// return getDatas(entityType, pager, sidx, ascendantOrder, true);
}
@@ -240,104 +223,6 @@
commitTransaction("Could not commit transaction");
}
- public CsvImportResult importDatas(EchoBaseEntityEnum entityType,
- String importFileName,
- File importFile,
- boolean createIfNotFound,
- EchoBaseUser user) throws IOException {
-
- TableMeta meta = getTableMeta(entityType);
- ImportExportModel<TopiaEntity> csvModel = buildForImport(meta);
- String messagePrefix = "Import du fichier " + importFileName + " le " + newDate();
-
- CsvImportResult result = CsvImportResult.newResult(entityType,
- importFileName,
- createIfNotFound);
- BufferedReader bf = new BufferedReader(new FileReader(importFile));
- try {
-
- Import<TopiaEntity> importer = Import.newImport(csvModel, bf);
-
- try {
- for (TopiaEntity entity : importer) {
- boolean create = saveEntity(meta,
- messagePrefix,
- entity,
- user,
- createIfNotFound
- );
-
- if (create) {
-
- result.incrementsNumberCreated();
- } else {
-
- result.incrementsNumberUpdated();
- }
- }
- } finally {
-
- importer.close();
- }
-
- commitTransaction("Could not commit transaction");
- } catch (EchoBaseTechnicalException eee) {
- throw eee;
- } catch (Exception eee) {
- log.error("Failed to read import file " + importFile.getName(), eee);
- throw new EchoBaseTechnicalException(eee);
- } finally {
- bf.close();
- }
- return result;
- }
-
- public String exportDatas(TableMeta tableMeta) {
-
- Export<TopiaEntity> export = prepareExport(tableMeta);
-
- try {
- return export.startExportAsString();
- } catch (Exception eee) {
- throw new EchoBaseTechnicalException("Can not export datas", eee);
- }
- }
-
- public void exportDatas(TableMeta tableMeta, File file) {
-
- if (log.isInfoEnabled()) {
- log.info("Export table " + tableMeta + " to " + file);
- }
- long s1 = TimeLog.getTime();
- Export<TopiaEntity> export = prepareExport(tableMeta);
- timeLog.log(s1, "prepareExport");
- long s2 = TimeLog.getTime();
- try {
- export.exportToFile(file);
- } catch (Exception eee) {
- throw new EchoBaseTechnicalException("Can not export datas", eee);
- }
- timeLog.log(s2, "exportToFile");
- }
-
- public void exportDatas(AssociationMeta associationMeta, File file) {
-
- if (log.isInfoEnabled()) {
- log.info("Export association " + associationMeta + " to " + file);
- }
- long s1 = TimeLog.getTime();
- Export<TopiaEntity> export = prepareExport(associationMeta);
- timeLog.log(s1, "prepareExport");
-
- long s2 = TimeLog.getTime();
- try {
- export.exportToFile(file);
- } catch (Exception eee) {
- throw new EchoBaseTechnicalException("Can not export datas", eee);
- }
- timeLog.log(s2, "exportToFile");
- }
-
public boolean saveEntity(TableMeta tableMeta,
String messagePrefix,
TopiaEntity entity,
@@ -509,80 +394,6 @@
return row;
}
- public <E extends TopiaEntity> EntityCsvModel<E> buildForImport(MetaFilenameAware meta) {
- if (meta instanceof AssociationMeta) {
- return buildForImport((AssociationMeta) meta);
- }
- if (meta instanceof TableMeta) {
- return buildForImport((TableMeta) meta);
- }
- throw new IllegalStateException("Can't do a thing with " + meta);
- }
-
- public <E extends TopiaEntity> EntityCsvModel<E> buildForImport(TableMeta meta) {
-
- EntityCsvModel<E> model = EntityCsvModel.newModel(
- getConfiguration().getCsvSeparator(),
- meta,
- TopiaEntity.TOPIA_ID
- );
-
- for (ColumnMeta columnMeta : meta) {
- String propertyName = columnMeta.getName();
- Class<?> type = columnMeta.getType();
- if (columnMeta.isFK()) {
-
- Class<TopiaEntity> entityType = (Class<TopiaEntity>) type;
- Collection<TopiaEntity> universe = getForeignDatas(entityType);
- model.addForeignKeyForImport(propertyName, entityType, universe);
- } else {
- model.addDefaultColumn(propertyName, type);
- }
- }
- return model;
- }
-
- public <E extends TopiaEntity> ExportModel<E> buildForExport(AssociationMeta associationMeta) {
-
- ExportModel<E> model = EntityAssociationCsvModel.newExportModel(
- getConfiguration().getCsvSeparator(),
- associationMeta
- );
- return model;
- }
-
- public <E extends TopiaEntity> ExportModel<E> buildForExport(MetaFilenameAware meta) {
- if (meta instanceof AssociationMeta) {
- return buildForExport((AssociationMeta) meta);
- }
- if (meta instanceof TableMeta) {
- return buildForExport((TableMeta) meta);
- }
- throw new IllegalStateException("Can't do a thing with " + meta);
- }
-
- public <E extends TopiaEntity> ExportModel<E> buildForExport(TableMeta meta) {
-
- EntityCsvModel<E> model = EntityCsvModel.newModel(
- getConfiguration().getCsvSeparator(),
- meta,
- TopiaEntity.TOPIA_ID
- );
-
- for (ColumnMeta columnMeta : meta) {
- String propertyName = columnMeta.getName();
- Class<?> type = columnMeta.getType();
- if (columnMeta.isFK()) {
-
- Class<TopiaEntity> entityType = (Class<TopiaEntity>) type;
- model.addForeignKeyForExport(propertyName, entityType);
- } else {
- model.addDefaultColumn(propertyName, type);
- }
- }
- return model;
- }
-
protected <E extends TopiaEntity> ImportExportModel<E> buildForSave(TableMeta meta) {
EntityCsvModel<E> model = EntityCsvModel.newModel(
@@ -661,18 +472,4 @@
return model;
}
- protected Export<TopiaEntity> prepareExport(TableMeta tableMeta) {
- List<TopiaEntity> datas = getEntities(tableMeta, null, null, null, null);
- ExportModel<TopiaEntity> model = buildForExport(tableMeta);
- return Export.newExport(model, datas);
- }
-
- protected Export<TopiaEntity> prepareExport(AssociationMeta associationMeta) {
-
- TableMeta tableMeta = getTableMeta(associationMeta.getSource());
- List<TopiaEntity> datas = getEntities(tableMeta, null, null, null, "size(e." + associationMeta.getName() + ") > 0");
-
- ExportModel<TopiaEntity> model = buildForExport(associationMeta);
- return Export.newExport(model, datas);
- }
}
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbExportService.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -23,9 +23,7 @@
*/
package fr.ifremer.echobase.services;
-import com.google.common.collect.Lists;
import fr.ifremer.echobase.EchoBaseIOUtil;
-import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.EntitiesUtil;
import fr.ifremer.echobase.entities.meta.AssociationMeta;
import fr.ifremer.echobase.entities.meta.MetaFilenameAware;
@@ -36,7 +34,6 @@
import org.nuiton.util.TimeLog;
import java.io.File;
-import java.util.List;
/**
* Service to import / export a complete db.
@@ -52,8 +49,6 @@
public static final TimeLog timeLog = new TimeLog(DbEditorService.class);
- protected DbEditorService dbEditorService;
-
/**
* Export the complete db into csv files stored in a zip archive file.
*
@@ -67,20 +62,20 @@
File zipFile = new File(tempDirectory, fileName + ".zip");
- DbEditorService service = getDbEditorService();
+ ExportService exportService = getService(ExportService.class);
File dir = new File(tempDirectory, "echobase");
- MetaFilenameAware[] entries = getEntries();
+ MetaFilenameAware[] entries = EntitiesUtil.getEntries(getDbMeta());
for (MetaFilenameAware entry : entries) {
File entryFile = new File(dir, entry.getFilename());
if (entry instanceof AssociationMeta) {
AssociationMeta associationMeta = (AssociationMeta) entry;
- service.exportDatas(associationMeta, entryFile);
+ exportService.exportDatas(associationMeta, entryFile);
} else {
TableMeta meta = (TableMeta) entry;
- service.exportDatas(meta, entryFile);
+ exportService.exportDatas(meta, entryFile);
}
}
@@ -89,41 +84,4 @@
return zipFile;
}
- public MetaFilenameAware[] getEntries() {
-
- List<MetaFilenameAware> entities = Lists.newArrayList();
- List<MetaFilenameAware> associations = Lists.newArrayList();
-
- addEntries(entities, associations, EntitiesUtil.getReferenceTypesForCopy());
- addEntries(entities, associations, EntitiesUtil.getDataTypesforCopy());
- entities.addAll(associations);
- return entities.toArray(new MetaFilenameAware[entities.size()]);
- }
-
- protected TableMeta getTableMeta(EchoBaseEntityEnum tableName) {
- return getDbEditorService().getTableMeta(tableName);
- }
-
- protected void addEntries(List<MetaFilenameAware> entities,
- List<MetaFilenameAware> associations,
- EchoBaseEntityEnum[] types) {
- for (EchoBaseEntityEnum type : types) {
-
- TableMeta tableMeta = getTableMeta(type);
- entities.add(tableMeta);
-
-// for (AssociationMeta associationMeta : tableMeta.getAssociations()) {
-// associations.add(associationMeta);
-// }
- associations.addAll(tableMeta.getAssociations());
- }
- }
-
- protected DbEditorService getDbEditorService() {
- if (dbEditorService == null) {
- dbEditorService = newService(DbEditorService.class);
- }
- return dbEditorService;
- }
-
}
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportService.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportService.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -25,8 +25,6 @@
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import fr.ifremer.echobase.EchoBaseFunctions;
-import fr.ifremer.echobase.EchoBaseTechnicalException;
import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
import fr.ifremer.echobase.entities.EchoBaseUser;
import fr.ifremer.echobase.entities.EntitiesUtil;
@@ -34,17 +32,14 @@
import fr.ifremer.echobase.entities.meta.AssociationMeta;
import fr.ifremer.echobase.entities.meta.MetaFilenameAware;
import fr.ifremer.echobase.entities.meta.TableMeta;
-import fr.ifremer.echobase.services.models.EntityAssociationImportModel;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.topia.TopiaException;
-import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.util.StringUtil;
import org.nuiton.util.TimeLog;
import org.nuiton.util.csv.Import;
-import org.nuiton.util.csv.ImportExportModel;
import org.nuiton.util.csv.ImportModel;
import org.nuiton.util.csv.ImportToMap;
@@ -52,7 +47,6 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
@@ -72,39 +66,6 @@
public static final TimeLog timeLog = new TimeLog(DbImportService.class);
- protected DbEditorService dbEditorService;
-
- protected Map<MetaFilenameAware, ZipEntry> discoverEntries(File file, ZipFile zipFile) {
-
- List<String> missingEntries = Lists.newArrayList();
-
- Map<MetaFilenameAware, ZipEntry> result =
- Maps.newLinkedHashMap();
-
- MetaFilenameAware[] entries = getEntries();
-
- // check that all mandatories
- for (MetaFilenameAware entry : entries) {
- String filename = entry.getFilename();
- ZipEntry zipEntry = zipFile.getEntry("echobase/" + filename);
-
- if (zipEntry == null) {
- missingEntries.add(filename);
- } else {
- result.put(entry, zipEntry);
- }
- }
- if (!missingEntries.isEmpty()) {
-
- if (log.isWarnEnabled()) {
- log.warn("There is " + missingEntries.size() + "missing mandatory files " +
- " in import " + file + "\n" + StringUtil.join(missingEntries, "\n", false));
- }
- }
-
- return result;
- }
-
/**
* Import a complete db from the given zip file.
*
@@ -169,6 +130,38 @@
}
}
+ protected Map<MetaFilenameAware, ZipEntry> discoverEntries(File file,
+ ZipFile zipFile) {
+
+ List<String> missingEntries = Lists.newArrayList();
+
+ Map<MetaFilenameAware, ZipEntry> result =
+ Maps.newLinkedHashMap();
+
+ MetaFilenameAware[] entries = EntitiesUtil.getEntries(getDbMeta());
+
+ // check that all mandatories
+ for (MetaFilenameAware entry : entries) {
+ String filename = entry.getFilename();
+ ZipEntry zipEntry = zipFile.getEntry("echobase/" + filename);
+
+ if (zipEntry == null) {
+ missingEntries.add(filename);
+ } else {
+ result.put(entry, zipEntry);
+ }
+ }
+ if (!missingEntries.isEmpty()) {
+
+ if (log.isWarnEnabled()) {
+ log.warn("There is " + missingEntries.size() + " missing files " +
+ " in import " + file + "\n" + StringUtil.join(missingEntries, "\n", false));
+ }
+ }
+
+ return result;
+ }
+
static class MyImportToMap extends ImportToMap {
public static MyImportToMap newImport(ImportModel<Map<String, Object>> model,
@@ -176,34 +169,51 @@
return new MyImportToMap(model, reader);
}
- protected MyImportToMap(ImportModel<Map<String, Object>> model, Reader reader) {
+ protected MyImportToMap(ImportModel<Map<String, Object>> model,
+ Reader reader) {
super(model, reader);
this.reader.setSafetySwitch(false);
}
-
}
public void importFile(MetaFilenameAware entry,
Reader reader,
CsvImportResult csvResult) throws IOException, TopiaException {
-
long s0 = TimeLog.getTime();
if (log.isInfoEnabled()) {
log.info("Will import " + entry);
}
+ ImportService importService = getService(ImportService.class);
+
if (entry instanceof AssociationMeta) {
// load a association input
- importAssociationfile((AssociationMeta) entry, reader, csvResult);
+ AssociationMeta meta = (AssociationMeta) entry;
+ ImportModel<Map<String, Object>> model = importService.buildForImport(meta);
+ ImportToMap importer = MyImportToMap.newImport(model, reader);
+ try {
+ importAssociationfile(meta, importer, csvResult);
+ } finally {
+ importer.close();
+ }
+
} else {
// normal entity table import
- importEntityFile((TableMeta) entry, reader, csvResult);
+ TableMeta meta = (TableMeta) entry;
+ ImportModel<TopiaEntity> model = importService.buildForImport(meta);
+ Import<TopiaEntity> importer = Import.newImport(model, reader);
+
+ try {
+ importEntityFile(meta, importer, csvResult);
+ } finally {
+ importer.close();
+ }
}
timeLog.log(s0, "importFile::done");
@@ -215,190 +225,66 @@
timeLog.log(s0, "importFile::flushTransaction");
}
+ protected void importEntityFile(TableMeta meta,
+ Import<TopiaEntity> importer,
+ CsvImportResult csvResult) throws TopiaException {
- public MetaFilenameAware[] getEntries() {
+ TopiaDAO<TopiaEntity> dao = getDAO(meta.getSource());
+ for (TopiaEntity entity : importer) {
- List<MetaFilenameAware> entities = Lists.newArrayList();
- List<MetaFilenameAware> associations = Lists.newArrayList();
+ TopiaEntity entityToSave = dao.create(TopiaEntity.TOPIA_ID,
+ entity.getTopiaId());
- addEntries(entities, associations, EntitiesUtil.getReferenceTypesForCopy());
- addEntries(entities, associations, EntitiesUtil.getDataTypesforCopy());
- entities.addAll(associations);
- return entities.toArray(new MetaFilenameAware[entities.size()]);
- }
+ meta.copy(entity, entityToSave);
- protected void importEntityFile(TableMeta meta, Reader reader, CsvImportResult csvResult) {
-
- ImportModel<TopiaEntity> model = getDbEditorService().buildForImport(meta);
-
- Import<TopiaEntity> importer = Import.newImport(model, reader);
-
- try {
- TopiaDAO<TopiaEntity> dao = getDAO(meta.getSource());
- for (TopiaEntity entity : importer) {
-
- TopiaEntity entityToSave = dao.create(TopiaEntity.TOPIA_ID,
- entity.getTopiaId());
-
- meta.copy(entity, entityToSave);
-
- csvResult.incrementsNumberUpdated();
- }
-
- } catch (Exception eee) {
- throw new EchoBaseTechnicalException("Could not import entities of type " + meta.getSource(), eee);
- } finally {
-
- importer.close();
+ csvResult.incrementsNumberUpdated();
}
}
- protected void flushTransaction() throws TopiaException {
- TopiaContextImplementor tx = (TopiaContextImplementor) getTransaction();
- tx.getHibernate().flush();
- }
+ protected void importAssociationfile(AssociationMeta meta,
+ ImportToMap importer,
+ CsvImportResult csvResult) throws TopiaException {
- protected void importAssociationfile(AssociationMeta meta, Reader reader, CsvImportResult csvResult) {
EchoBaseEntityEnum source = meta.getSource();
EchoBaseEntityEnum target = meta.getTarget();
- ImportModel<Map<String, Object>> model =
- EntityAssociationImportModel.newImportModel(
- getConfiguration().getCsvSeparator(),
- meta
- );
-
- ImportToMap importer = MyImportToMap.newImport(model, reader);
-
StringBuilder builder = new StringBuilder();
- try {
- String updateString;
- String targetTableName = target.getContract().getSimpleName();
- String sourceTableName = source.getContract().getSimpleName();
- String table = targetTableName;
- if (source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Echotype) {
- table = targetTableName + "_" + sourceTableName;
- updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE " + meta.getName() + " ='%s';";
- } else if (source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Strata) {
- table = targetTableName + "_" + source.getContract().getSimpleName();
- updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE " + meta.getName() + " ='%s';";
- } else {
- updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE topiaId ='%s';";
- }
-
- if (log.isDebugEnabled()) {
- log.debug("Will apply " + updateString);
- }
- int compt = 0;
- for (Map<String, Object> row : importer) {
- String topiaId = (String) row.get(TopiaEntity.TOPIA_ID);
- String[] associations = (String[]) row.get("target");
- for (String association : associations) {
- builder.append(String.format(updateString, topiaId, association)).append('\n');
- compt++;
- if (compt % 10000 == 0) {
- // flush it
- getTransaction().executeSQL(builder.toString());
- builder = new StringBuilder();
- }
- }
- csvResult.incrementsNumberUpdated();
- }
- if (builder.length() > 0) {
- getTransaction().executeSQL(builder.toString());
- }
- } catch (TopiaException eee) {
- throw new EchoBaseTechnicalException(
- "Could not execute sql script", eee);
- } finally {
-
- importer.close();
+ String updateString;
+ String targetTableName = target.getContract().getSimpleName();
+ String sourceTableName = source.getContract().getSimpleName();
+ String table = targetTableName;
+ if (source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Echotype) {
+ table = targetTableName + "_" + sourceTableName;
+ updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE " + meta.getName() + " ='%s';";
+ } else if (source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Strata) {
+ table = targetTableName + "_" + source.getContract().getSimpleName();
+ updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE " + meta.getName() + " ='%s';";
+ } else {
+ updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE topiaId ='%s';";
}
- }
- protected TableMeta getTableMeta(EchoBaseEntityEnum tableName) {
- return getDbEditorService().getTableMeta(tableName);
- }
-
- protected void addEntries(List<MetaFilenameAware> entities,
- List<MetaFilenameAware> associations,
- EchoBaseEntityEnum[] types) {
- for (EchoBaseEntityEnum type : types) {
-
- TableMeta tableMeta = getTableMeta(type);
- entities.add(tableMeta);
- associations.addAll(tableMeta.getAssociations());
+ if (log.isDebugEnabled()) {
+ log.debug("Will apply " + updateString);
}
- }
-
- protected DbEditorService getDbEditorService() {
- if (dbEditorService == null) {
- dbEditorService = newService(DbEditorService.class);
- }
- return dbEditorService;
- }
-
- protected void mportEntities(TableMeta meta,
- ImportExportModel<TopiaEntity> csvModel,
- CsvImportResult result,
- Reader reader) {
-
- if (log.isInfoEnabled()) {
- log.info("Will import " + meta);
- }
- Import<TopiaEntity> importer = Import.newImport(csvModel, reader);
-
- try {
- TopiaDAO<TopiaEntity> dao = getDAO(meta.getSource());
- long s0 = TimeLog.getTime();
- for (TopiaEntity entity : importer) {
-
- TopiaEntity entityToSave = dao.create(TopiaEntity.TOPIA_ID,
- entity.getTopiaId());
-
- meta.copy(entity, entityToSave);
-
- result.incrementsNumberUpdated();
+ int compt = 0;
+ for (Map<String, Object> row : importer) {
+ String topiaId = (String) row.get(TopiaEntity.TOPIA_ID);
+ String[] associations = (String[]) row.get("target");
+ for (String association : associations) {
+ builder.append(String.format(updateString, topiaId, association)).append('\n');
+ compt++;
+ if (compt % 10000 == 0) {
+ // flush it
+ getTransaction().executeSQL(builder.toString());
+ builder = new StringBuilder();
+ }
}
- timeLog.log(s0, "importEntities");
- } catch (Exception eee) {
- throw new EchoBaseTechnicalException("Could not import entities of type " + meta.getSource(), eee);
- } finally {
-
- importer.close();
+ csvResult.incrementsNumberUpdated();
}
- }
-
- protected <E extends TopiaEntity> void mportEntityAssociation(AssociationMeta meta,
- ImportModel<E> csvModel,
- CsvImportResult result,
- Reader reader) {
- if (log.isInfoEnabled()) {
- log.info("Will import " + meta);
+ if (builder.length() > 0) {
+ getTransaction().executeSQL(builder.toString());
}
-
- EchoBaseEntityEnum sourceType = meta.getSource();
-
- Import<E> importer = Import.newImport(csvModel, reader);
- long s0;
- s0 = TimeLog.getTime();
- List<E> sourceEntities = getEntities(sourceType);
- timeLog.log(s0, "importEntityAssociation::getEntities");
- Map<String, E> sourcesById =
- Maps.uniqueIndex(sourceEntities, EchoBaseFunctions.TO_TOPIAID);
- try {
- s0 = TimeLog.getTime();
- for (E row : importer) {
- E entityToSave = sourcesById.get(row.getTopiaId());
- Collection<TopiaEntity> assoc = meta.getChilds(row);
- meta.setChilds(entityToSave, assoc);
- result.incrementsNumberUpdated();
- }
- timeLog.log(s0, "importEntityAssociation::import");
- } finally {
-
- importer.close();
- }
}
+
}
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EchoBaseServiceSupport.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -24,6 +24,7 @@
package fr.ifremer.echobase.services;
import com.google.common.base.Preconditions;
+import com.google.common.collect.Maps;
import fr.ifremer.echobase.EchoBaseConfiguration;
import fr.ifremer.echobase.EchoBaseTechnicalException;
import fr.ifremer.echobase.entities.EchoBaseDAOHelper;
@@ -33,12 +34,14 @@
import org.apache.commons.lang3.time.DateUtils;
import org.nuiton.topia.TopiaContext;
import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.persistence.TopiaDAO;
import org.nuiton.topia.persistence.TopiaEntity;
import java.util.Date;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
/**
* @author sletellier <letellier(a)codelutin.com>
@@ -48,6 +51,8 @@
protected EchoBaseServiceContext serviceContext;
+ protected Map<Class<?>, EchoBaseService> services;
+
@Override
public void setServiceContext(EchoBaseServiceContext serviceContext) {
this.serviceContext = serviceContext;
@@ -57,6 +62,7 @@
Class<E> contract = (Class<E>) entityType.getContract();
return getEntities(contract);
}
+
public <E extends TopiaEntity> List<E> getEntities(Class<E> entityType) {
Preconditions.checkNotNull(entityType);
try {
@@ -97,9 +103,16 @@
return serviceContext.getConfiguration();
}
- protected <E extends EchoBaseService> E newService(Class<E> serviceClass) {
- E e = serviceContext.newService(serviceClass);
- return e;
+ protected <E extends EchoBaseService> E getService(Class<E> serviceClass) {
+ if (services == null) {
+ services = Maps.newHashMap();
+ }
+ E service = (E) services.get(serviceClass);
+ if (service == null) {
+ service = serviceContext.newService(serviceClass);
+ services.put(serviceClass, service);
+ }
+ return service;
}
protected <E extends TopiaEntity> TopiaDAO<E> getDAO(EchoBaseEntityEnum entityEnum) throws TopiaException {
@@ -123,6 +136,11 @@
}
}
+ protected void flushTransaction() throws TopiaException {
+ TopiaContextImplementor tx = (TopiaContextImplementor) getTransaction();
+ tx.getHibernate().flush();
+ }
+
protected Date newDate() {
Date result = new Date();
DateUtils.setMilliseconds(result, 0);
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/EmbeddedApplicationService.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -204,7 +204,7 @@
// get export query service
ExportSqlService exportSqlService =
- newService(ExportSqlService.class);
+ getService(ExportSqlService.class);
// get all export queries from application
List<ExportQuery> queries = exportSqlService.getEntities(ExportQuery.class);
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -0,0 +1,150 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 Ifremer, Codelutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package fr.ifremer.echobase.services;
+
+import fr.ifremer.echobase.EchoBaseTechnicalException;
+import fr.ifremer.echobase.entities.meta.AssociationMeta;
+import fr.ifremer.echobase.entities.meta.ColumnMeta;
+import fr.ifremer.echobase.entities.meta.TableMeta;
+import fr.ifremer.echobase.services.models.EntityAssociationExportModel;
+import fr.ifremer.echobase.services.models.EntityCsvModel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.TimeLog;
+import org.nuiton.util.csv.Export;
+import org.nuiton.util.csv.ExportModel;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * To export datas from db to csv files.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class ExportService extends EchoBaseServiceSupport {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(ExportService.class);
+
+ public static final TimeLog timeLog = new TimeLog(ExportService.class);
+
+ public <E extends TopiaEntity> ExportModel<E> buildForExport(AssociationMeta associationMeta) {
+
+ ExportModel<E> model = EntityAssociationExportModel.newExportModel(
+ getConfiguration().getCsvSeparator(),
+ associationMeta
+ );
+ return model;
+ }
+
+ public <E extends TopiaEntity> ExportModel<E> buildForExport(TableMeta meta) {
+
+ EntityCsvModel<E> model = EntityCsvModel.newModel(
+ getConfiguration().getCsvSeparator(),
+ meta,
+ TopiaEntity.TOPIA_ID
+ );
+
+ for (ColumnMeta columnMeta : meta) {
+ String propertyName = columnMeta.getName();
+ Class<?> type = columnMeta.getType();
+ if (columnMeta.isFK()) {
+
+ Class<TopiaEntity> entityType = (Class<TopiaEntity>) type;
+ model.addForeignKeyForExport(propertyName, entityType);
+ } else {
+ model.addDefaultColumn(propertyName, type);
+ }
+ }
+ return model;
+ }
+
+ public String exportDatas(TableMeta tableMeta) {
+
+ Export<TopiaEntity> export = prepareExport(tableMeta);
+
+ try {
+ return export.startExportAsString();
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException("Can not export datas", eee);
+ }
+ }
+
+ public void exportDatas(TableMeta tableMeta, File file) {
+
+ if (log.isInfoEnabled()) {
+ log.info("Export table " + tableMeta + " to " + file);
+ }
+ long s1 = TimeLog.getTime();
+ Export<TopiaEntity> export = prepareExport(tableMeta);
+ timeLog.log(s1, "exportDatas::prepareExport");
+ long s2 = TimeLog.getTime();
+ try {
+ export.exportToFile(file);
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException("Can not export datas", eee);
+ }
+ timeLog.log(s2, "exportDatas::exportToFile");
+ }
+
+ public void exportDatas(AssociationMeta associationMeta, File file) {
+
+ if (log.isInfoEnabled()) {
+ log.info("Export association " + associationMeta + " to " + file);
+ }
+ long s1 = TimeLog.getTime();
+ Export<TopiaEntity> export = prepareExport(associationMeta);
+ timeLog.log(s1, "prepareExport");
+
+ long s2 = TimeLog.getTime();
+ try {
+ export.exportToFile(file);
+ } catch (Exception eee) {
+ throw new EchoBaseTechnicalException("Can not export datas", eee);
+ }
+ timeLog.log(s2, "exportToFile");
+ }
+
+ protected Export<TopiaEntity> prepareExport(TableMeta tableMeta) {
+ DbEditorService service = getService(DbEditorService.class);
+
+ List<TopiaEntity> datas = service.getEntities(tableMeta, null, null, null, null);
+ ExportModel<TopiaEntity> model = buildForExport(tableMeta);
+ return Export.newExport(model, datas);
+ }
+
+ protected Export<TopiaEntity> prepareExport(AssociationMeta associationMeta) {
+
+ DbEditorService service = getService(DbEditorService.class);
+
+ TableMeta tableMeta = service.getTableMeta(associationMeta.getSource());
+ List<TopiaEntity> datas = service.getEntities(tableMeta, null, null, null, "size(e." + associationMeta.getName() + ") > 0");
+
+ ExportModel<TopiaEntity> model = buildForExport(associationMeta);
+ return Export.newExport(model, datas);
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ExportService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Added: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportService.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportService.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -0,0 +1,147 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 Ifremer, Codelutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package fr.ifremer.echobase.services;
+
+import fr.ifremer.echobase.EchoBaseTechnicalException;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
+import fr.ifremer.echobase.entities.EchoBaseUser;
+import fr.ifremer.echobase.entities.meta.AssociationMeta;
+import fr.ifremer.echobase.entities.meta.ColumnMeta;
+import fr.ifremer.echobase.entities.meta.TableMeta;
+import fr.ifremer.echobase.services.models.EntityAssociationImportModel;
+import fr.ifremer.echobase.services.models.EntityCsvModel;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.csv.Import;
+import org.nuiton.util.csv.ImportExportModel;
+import org.nuiton.util.csv.ImportModel;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * To import datas from csv files into the db.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class ImportService extends EchoBaseServiceSupport {
+
+ /** Logger. */
+ private static final Log log = LogFactory.getLog(ImportService.class);
+
+ public <E extends TopiaEntity> EntityCsvModel<E> buildForImport(TableMeta meta) {
+
+ DbEditorService service = getService(DbEditorService.class);
+
+ EntityCsvModel<E> model = EntityCsvModel.newModel(
+ getConfiguration().getCsvSeparator(),
+ meta,
+ TopiaEntity.TOPIA_ID
+ );
+
+ for (ColumnMeta columnMeta : meta) {
+ String propertyName = columnMeta.getName();
+ Class<?> type = columnMeta.getType();
+ if (columnMeta.isFK()) {
+
+ Class<TopiaEntity> entityType = (Class<TopiaEntity>) type;
+ Collection<TopiaEntity> universe = service.getForeignDatas(entityType);
+ model.addForeignKeyForImport(propertyName, entityType, universe);
+ } else {
+ model.addDefaultColumn(propertyName, type);
+ }
+ }
+ return model;
+ }
+
+ public ImportModel<Map<String, Object>> buildForImport(AssociationMeta meta) {
+
+ ImportModel<Map<String, Object>> model =
+ EntityAssociationImportModel.newImportModel(
+ getConfiguration().getCsvSeparator(),
+ meta
+ );
+ return model;
+ }
+
+ public CsvImportResult importDatas(EchoBaseEntityEnum entityType,
+ String importFileName,
+ File importFile,
+ boolean createIfNotFound,
+ EchoBaseUser user) throws IOException {
+
+ DbEditorService service = getService(DbEditorService.class);
+
+ TableMeta meta = service.getTableMeta(entityType);
+ ImportExportModel<TopiaEntity> csvModel = buildForImport(meta);
+ String messagePrefix = "Import du fichier " + importFileName + " le " + newDate();
+
+ CsvImportResult result = CsvImportResult.newResult(entityType,
+ importFileName,
+ createIfNotFound);
+ BufferedReader bf = new BufferedReader(new FileReader(importFile));
+ try {
+
+ Import<TopiaEntity> importer = Import.newImport(csvModel, bf);
+
+ try {
+ for (TopiaEntity entity : importer) {
+ boolean create = service.saveEntity(meta,
+ messagePrefix,
+ entity,
+ user,
+ createIfNotFound
+ );
+
+ if (create) {
+
+ result.incrementsNumberCreated();
+ } else {
+
+ result.incrementsNumberUpdated();
+ }
+ }
+ } finally {
+
+ importer.close();
+ }
+
+ commitTransaction("Could not commit transaction");
+ } catch (EchoBaseTechnicalException eee) {
+ throw eee;
+ } catch (Exception eee) {
+ log.error("Failed to read import file " + importFile.getName(), eee);
+ throw new EchoBaseTechnicalException(eee);
+ } finally {
+ bf.close();
+ }
+ return result;
+ }
+}
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/ImportService.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Deleted: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -1,133 +0,0 @@
-/*
- * #%L
- * EchoBase :: Services
- *
- * $Id$
- * $HeadURL$
- * %%
- * Copyright (C) 2011 Ifremer, Codelutin
- * %%
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * #L%
- */
-package fr.ifremer.echobase.services.models;
-
-import fr.ifremer.echobase.entities.meta.AssociationMeta;
-import org.nuiton.topia.persistence.TopiaEntity;
-import org.nuiton.util.csv.ExportModel;
-import org.nuiton.util.csv.ExportableColumn;
-import org.nuiton.util.csv.ImportExportModel;
-import org.nuiton.util.csv.ImportModel;
-import org.nuiton.util.csv.ImportableColumn;
-import org.nuiton.util.csv.ModelBuilder;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
-/**
- * A model to import / export associations of entities into csv files.
- *
- * @author tchemit <chemit(a)codelutin.com>
- * @since 0.2
- */
-public class EntityAssociationCsvModel<E extends TopiaEntity> implements ImportExportModel<E> {
-
- protected final char separator;
-
- protected final AssociationMeta meta;
-
- protected ModelBuilder<E> modelBuilder;
-
- public static <E extends TopiaEntity> ImportModel<E> newImportModel(char separator,
- AssociationMeta meta,
- Map<String, TopiaEntity> targetsById
- ) {
- EntityAssociationCsvModel<E> model = new EntityAssociationCsvModel<E>(
- separator, meta);
-
- // topiaId <-> topiaId
- model.modelBuilder.newColumnForImportExport(
- TopiaEntity.TOPIA_ID,
- TopiaEntity.TOPIA_ID
- );
-
- // add association -> target
- Class<TopiaEntity> target =
- (Class<TopiaEntity>) meta.getTarget().getImplementation();
-
- model.modelBuilder.newColumnForImportExport(
- meta.getName(),
- meta.getName(),
- CsvModelUtil.newAssociationValueParserFormatter(target, targetsById)
- );
-
- return model;
- }
-
- public static <E extends TopiaEntity> ExportModel<E> newExportModel(char separator,
- AssociationMeta meta
- ) {
- EntityAssociationCsvModel<E> model = new EntityAssociationCsvModel<E>(
- separator,
- meta);
-
- // topiaId <-> topiaId
- model.modelBuilder.newColumnForExport(
- TopiaEntity.TOPIA_ID,
- TopiaEntity.TOPIA_ID
- );
-
- model.modelBuilder.newColumnForExport(
- meta.getName(),
- meta.getName(),
- CsvModelUtil.newAssociationValueFormatter()
- );
- return model;
- }
-
- @Override
- public char getSeparator() {
- return separator;
- }
-
- @Override
- public Iterable<ExportableColumn<E, Object>> getColumnsForExport() {
- return (Collection)
- modelBuilder.getColumnsForExport();
- }
-
- @Override
- public Iterable<ImportableColumn<E, Object>> getColumnsForImport() {
- return (Collection)
- modelBuilder.getColumnsForImport();
- }
-
- @Override
- public void pushCsvHeaderNames(List<String> headerNames) {
- }
-
- @Override
- public E newEmptyInstance() {
- return (E) meta.newEntity();
- }
-
- protected EntityAssociationCsvModel(char separator, AssociationMeta meta) {
- this.separator = separator;
- this.meta = meta;
- modelBuilder = new ModelBuilder<E>();
- }
-
-
-}
\ No newline at end of file
Copied: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationExportModel.java (from rev 211, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationCsvModel.java)
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationExportModel.java (rev 0)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationExportModel.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -0,0 +1,87 @@
+/*
+ * #%L
+ * EchoBase :: Services
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 Ifremer, Codelutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package fr.ifremer.echobase.services.models;
+
+import fr.ifremer.echobase.entities.meta.AssociationMeta;
+import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.csv.ExportModel;
+import org.nuiton.util.csv.ExportableColumn;
+import org.nuiton.util.csv.ModelBuilder;
+
+import java.util.Collection;
+
+/**
+ * A model to export associations of entities into csv files.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class EntityAssociationExportModel<E extends TopiaEntity> implements ExportModel<E> {
+
+ protected final char separator;
+
+ protected final AssociationMeta meta;
+
+ protected ModelBuilder<E> modelBuilder;
+
+ public static <E extends TopiaEntity> ExportModel<E> newExportModel(char separator,
+ AssociationMeta meta
+ ) {
+ EntityAssociationExportModel<E> model = new EntityAssociationExportModel<E>(
+ separator,
+ meta);
+
+ // topiaId <-> topiaId
+ model.modelBuilder.newColumnForExport(
+ TopiaEntity.TOPIA_ID,
+ TopiaEntity.TOPIA_ID
+ );
+
+ model.modelBuilder.newColumnForExport(
+ meta.getName(),
+ meta.getName(),
+ CsvModelUtil.newAssociationValueFormatter()
+ );
+ return model;
+ }
+
+ @Override
+ public char getSeparator() {
+ return separator;
+ }
+
+ @Override
+ public Iterable<ExportableColumn<E, Object>> getColumnsForExport() {
+ return (Collection)
+ modelBuilder.getColumnsForExport();
+ }
+
+ protected EntityAssociationExportModel(char separator, AssociationMeta meta) {
+ this.separator = separator;
+ this.meta = meta;
+ modelBuilder = new ModelBuilder<E>();
+ }
+
+
+}
\ No newline at end of file
Property changes on: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationExportModel.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationImportModel.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationImportModel.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/models/EntityAssociationImportModel.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -34,7 +34,7 @@
import java.util.Map;
/**
- * A model to import / export associations of entities into csv files.
+ * A model to import associations of entities into csv files.
*
* @author tchemit <chemit(a)codelutin.com>
* @since 0.2
Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/AbstractEchoBaseServiceTest.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -93,9 +93,7 @@
public DbMeta getDbMeta() {
if (dbMeta == null) {
- List<EchoBaseEntityEnum> entityEnums =
- Lists.newArrayList(EchoBaseEntityEnum.values());
- dbMeta = DbMeta.newDbMeta(entityEnums);
+ dbMeta = DbMeta.newDbMeta();
}
return dbMeta;
}
Modified: trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/DbImportExportServiceTest.java
===================================================================
--- trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/DbImportExportServiceTest.java 2011-12-26 10:02:16 UTC (rev 212)
+++ trunk/echobase-services/src/test/java/fr/ifremer/echobase/services/DbImportExportServiceTest.java 2011-12-26 10:10:04 UTC (rev 213)
@@ -120,7 +120,7 @@
@Test
public void testGetDataCopyModel() throws TopiaException {
- EchoBaseEntityEnum[] types = EntitiesUtil.getDataTypesforCopy();
+ EchoBaseEntityEnum[] types = EntitiesUtil.getDataTypesForCopy();
Set<TopiaEntityEnum> dones = Sets.newHashSet();
ReplicationModel model = new ReplicationModel(types, false);
1
0
r212 - in trunk/echobase-entities/src: main/java/fr/ifremer/echobase main/java/fr/ifremer/echobase/entities main/java/fr/ifremer/echobase/entities/meta main/xmi test/java/fr/ifremer/echobase test/java/fr/ifremer/echobase/entities
by tchemit@users.forge.codelutin.com 26 Dec '11
by tchemit@users.forge.codelutin.com 26 Dec '11
26 Dec '11
Author: tchemit
Date: 2011-12-26 11:02:16 +0100 (Mon, 26 Dec 2011)
New Revision: 212
Url: http://forge.codelutin.com/repositories/revision/echobase/212
Log:
remove OperationType entity
let's declare all copiable entities
add decorator test (to make sure there is a decorator for each type of entity)
Added:
trunk/echobase-entities/src/test/java/fr/ifremer/echobase/EchoBaseDecoratorProviderTest.java
Modified:
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java
trunk/echobase-entities/src/main/xmi/echobase.zargo
trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/EntitiesUtilTest.java
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java 2011-12-24 12:14:02 UTC (rev 211)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java 2011-12-26 10:02:16 UTC (rev 212)
@@ -67,7 +67,6 @@
import fr.ifremer.echobase.entities.references.Mission;
import fr.ifremer.echobase.entities.references.OperationEvent;
import fr.ifremer.echobase.entities.references.OperationMetadata;
-import fr.ifremer.echobase.entities.references.OperationType;
import fr.ifremer.echobase.entities.references.ReferenceDatum;
import fr.ifremer.echobase.entities.references.ReferenceDatumType;
import fr.ifremer.echobase.entities.references.ReferencingMethod;
@@ -189,9 +188,6 @@
// OperationMetadata decorator
registerJXPathDecorator(locale, OperationMetadata.class, "${name}$s");
- // OperationType decorator
- registerJXPathDecorator(locale, OperationType.class, "${name}$s");
-
// ReferenceDatum decorator
registerJXPathDecorator(locale, ReferenceDatum.class, "${id}$s");
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java 2011-12-24 12:14:02 UTC (rev 211)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/EntitiesUtil.java 2011-12-26 10:02:16 UTC (rev 212)
@@ -24,6 +24,9 @@
package fr.ifremer.echobase.entities;
import com.google.common.collect.Lists;
+import fr.ifremer.echobase.entities.meta.DbMeta;
+import fr.ifremer.echobase.entities.meta.MetaFilenameAware;
+import fr.ifremer.echobase.entities.meta.TableMeta;
import java.util.List;
@@ -64,7 +67,7 @@
* @return the entity types of data in correct order for replication
* purpose.
*/
- public static EchoBaseEntityEnum[] getDataTypesforCopy() {
+ public static EchoBaseEntityEnum[] getDataTypesForCopy() {
List<EchoBaseEntityEnum> result = Lists.newLinkedList();
@@ -115,7 +118,6 @@
result.add(EchoBaseEntityEnum.GearCharacteristicValue);
result.add(EchoBaseEntityEnum.GearMetadata);
result.add(EchoBaseEntityEnum.Calibration);
- result.add(EchoBaseEntityEnum.OperationType);
result.add(EchoBaseEntityEnum.MeasurementMetadata);
result.add(EchoBaseEntityEnum.SampleDataType);
result.add(EchoBaseEntityEnum.SampleType);
@@ -146,24 +148,19 @@
public static EchoBaseEntityEnum[] getReferenceTypesForCopy() {
List<EchoBaseEntityEnum> result = Lists.newLinkedList();
+ // with no dep
result.add(EchoBaseEntityEnum.Strata);
result.add(EchoBaseEntityEnum.SexCategory);
result.add(EchoBaseEntityEnum.AgeCategory);
result.add(EchoBaseEntityEnum.SizeCategory);
result.add(EchoBaseEntityEnum.Species);
- result.add(EchoBaseEntityEnum.SpeciesCategory);
result.add(EchoBaseEntityEnum.Calibration);
- result.add(EchoBaseEntityEnum.AcousticInstrument);
- result.add(EchoBaseEntityEnum.TSParameters);
result.add(EchoBaseEntityEnum.VesselType);
- result.add(EchoBaseEntityEnum.Vessel);
result.add(EchoBaseEntityEnum.Mission);
result.add(EchoBaseEntityEnum.DepthStratum);
result.add(EchoBaseEntityEnum.EchotypeCategory);
- result.add(EchoBaseEntityEnum.Echotype);
result.add(EchoBaseEntityEnum.AreaOfOperation);
result.add(EchoBaseEntityEnum.ReferenceDatumType);
- result.add(EchoBaseEntityEnum.ReferenceDatum);
result.add(EchoBaseEntityEnum.DataType);
result.add(EchoBaseEntityEnum.DataQuality);
result.add(EchoBaseEntityEnum.CellMethod);
@@ -171,13 +168,62 @@
result.add(EchoBaseEntityEnum.OperationEvent);
result.add(EchoBaseEntityEnum.SampleDataType);
result.add(EchoBaseEntityEnum.SampleType);
- result.add(EchoBaseEntityEnum.DataMetadata);
+ result.add(EchoBaseEntityEnum.GearCharacteristic);
+ result.add(EchoBaseEntityEnum.CategoryMeaning);
+ result.add(EchoBaseEntityEnum.CategoryType);
+ result.add(EchoBaseEntityEnum.MeasureType);
+ result.add(EchoBaseEntityEnum.MeasurementMetadata);
+ result.add(EchoBaseEntityEnum.ReferencingMethod);
+
+ // with deps
+ result.add(EchoBaseEntityEnum.AcousticInstrument);
+ result.add(EchoBaseEntityEnum.Vessel);
+ result.add(EchoBaseEntityEnum.ReferenceDatum);
result.add(EchoBaseEntityEnum.OperationMetadata);
result.add(EchoBaseEntityEnum.GearMetadata);
+ result.add(EchoBaseEntityEnum.GearCharacteristicValue);
result.add(EchoBaseEntityEnum.Gear);
result.add(EchoBaseEntityEnum.LengthAgeKey);
+
+ result.add(EchoBaseEntityEnum.SpeciesCategory);
result.add(EchoBaseEntityEnum.LengthWeightKey);
+ result.add(EchoBaseEntityEnum.TSParameters);
+ result.add(EchoBaseEntityEnum.Echotype);
+ result.add(EchoBaseEntityEnum.DataMetadata);
+ result.add(EchoBaseEntityEnum.Category);
+ result.add(EchoBaseEntityEnum.CategoryRef);
+ result.add(EchoBaseEntityEnum.Impacte);
+ result.add(EchoBaseEntityEnum.DataProtocol);
return result.toArray(new EchoBaseEntityEnum[result.size()]);
}
+ public static MetaFilenameAware[] getEntries(DbMeta dbMeta) {
+
+ List<MetaFilenameAware> entities = Lists.newArrayList();
+ List<MetaFilenameAware> associations = Lists.newArrayList();
+
+ addEntries(dbMeta, entities, associations, getReferenceTypesForCopy());
+ addEntries(dbMeta, entities, associations, getDataTypesForCopy());
+ entities.addAll(associations);
+ return entities.toArray(new MetaFilenameAware[entities.size()]);
+ }
+
+ protected static void addEntries(DbMeta dbMeta,
+ List<MetaFilenameAware> entities,
+ List<MetaFilenameAware> associations,
+ EchoBaseEntityEnum[] types) {
+ for (EchoBaseEntityEnum type : types) {
+
+ TableMeta tableMeta = getTableMeta(dbMeta, type);
+ entities.add(tableMeta);
+ associations.addAll(tableMeta.getAssociations());
+ }
+ }
+
+ protected static TableMeta getTableMeta(DbMeta dbMeta,
+ EchoBaseEntityEnum tableName) {
+ TableMeta result = dbMeta.getTable(tableName);
+ return result;
+ }
+
}
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java 2011-12-24 12:14:02 UTC (rev 211)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/DbMeta.java 2011-12-26 10:02:16 UTC (rev 212)
@@ -43,7 +43,12 @@
protected final EchoBaseEntityEnum[] entityEnums;
- public static DbMeta newDbMeta(List<EchoBaseEntityEnum> entityEnums) {
+ public static DbMeta newDbMeta() {
+ List<EchoBaseEntityEnum> entityEnums =
+ Lists.newArrayList(EchoBaseEntityEnum.values());
+ entityEnums.remove(EchoBaseEntityEnum.EchoBaseUser);
+ entityEnums.remove(EchoBaseEntityEnum.EntityModificationLog);
+ entityEnums.remove(EchoBaseEntityEnum.ExportQuery);
return newDbMeta(entityEnums.toArray(new EchoBaseEntityEnum[entityEnums.size()]));
}
Modified: trunk/echobase-entities/src/main/xmi/echobase.zargo
===================================================================
(Binary files differ)
Added: trunk/echobase-entities/src/test/java/fr/ifremer/echobase/EchoBaseDecoratorProviderTest.java
===================================================================
--- trunk/echobase-entities/src/test/java/fr/ifremer/echobase/EchoBaseDecoratorProviderTest.java (rev 0)
+++ trunk/echobase-entities/src/test/java/fr/ifremer/echobase/EchoBaseDecoratorProviderTest.java 2011-12-26 10:02:16 UTC (rev 212)
@@ -0,0 +1,78 @@
+/*
+ * #%L
+ * EchoBase :: Entities
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * Copyright (C) 2011 Ifremer, Codelutin
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * #L%
+ */
+package fr.ifremer.echobase;
+
+import com.google.common.collect.Lists;
+import fr.ifremer.echobase.entities.EchoBaseEntityEnum;
+import fr.ifremer.echobase.entities.EntitiesUtilTest;
+import fr.ifremer.echobase.entities.data.Voyage;
+import fr.ifremer.echobase.entities.references.Mission;
+import junit.framework.Assert;
+import org.junit.Test;
+import org.nuiton.util.decorator.Decorator;
+
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * To test the {@link EchoBaseDecoratorProvider}.
+ *
+ * @author tchemit <chemit(a)codelutin.com>
+ * @since 0.2
+ */
+public class EchoBaseDecoratorProviderTest {
+
+ @Test
+ public void getDecoratorForReferences() throws Exception {
+ Locale locale = Locale.FRANCE;
+ EchoBaseDecoratorProvider provider = new EchoBaseDecoratorProvider();
+ provider.loadDecorators(locale);
+ List<EchoBaseEntityEnum> expectedTypes =
+ Lists.newArrayList(EntitiesUtilTest.getContractsOf(
+ Mission.class.getPackage()));
+
+ for (EchoBaseEntityEnum type : expectedTypes) {
+ Decorator<?> decorator =
+ provider.getDecoratorByType(locale, type.getContract());
+ Assert.assertNotNull("Missing decorator for type : " + type, decorator);
+ }
+ }
+
+ @Test
+ public void getDecoratorForData() throws Exception {
+ Locale locale = Locale.FRANCE;
+ EchoBaseDecoratorProvider provider = new EchoBaseDecoratorProvider();
+ provider.loadDecorators(locale);
+ List<EchoBaseEntityEnum> expectedTypes =
+ Lists.newArrayList(EntitiesUtilTest.getContractsOf(
+ Voyage.class.getPackage()));
+
+ for (EchoBaseEntityEnum type : expectedTypes) {
+ Decorator<?> decorator =
+ provider.getDecoratorByType(locale, type.getContract());
+ Assert.assertNotNull("Missing decorator for type : " + type, decorator);
+ }
+ }
+
+}
Property changes on: trunk/echobase-entities/src/test/java/fr/ifremer/echobase/EchoBaseDecoratorProviderTest.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Added: svn:eol-style
+ native
Modified: trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/EntitiesUtilTest.java
===================================================================
--- trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/EntitiesUtilTest.java 2011-12-24 12:14:02 UTC (rev 211)
+++ trunk/echobase-entities/src/test/java/fr/ifremer/echobase/entities/EntitiesUtilTest.java 2011-12-26 10:02:16 UTC (rev 212)
@@ -60,6 +60,23 @@
}
@Test
+ public void getReferenceTypesForCopy() {
+
+ List<EchoBaseEntityEnum> types =
+ Arrays.asList(EntitiesUtil.getReferenceTypesForCopy());
+
+ List<EchoBaseEntityEnum> expectedTypes =
+ Lists.newArrayList(getContractsOf(Mission.class.getPackage()));
+
+ Assert.assertNotNull(types);
+
+ for (EchoBaseEntityEnum type : expectedTypes) {
+ Assert.assertTrue("Missing type : " + type, types.contains(type));
+ }
+ Assert.assertEquals(expectedTypes.size(), types.size());
+ }
+
+ @Test
public void getDataTypes() {
List<EchoBaseEntityEnum> types =
@@ -76,6 +93,23 @@
Assert.assertEquals(expectedTypes.size(), types.size());
}
+
+ @Test
+ public void getDataTypesForCopy() {
+
+ List<EchoBaseEntityEnum> types =
+ Arrays.asList(EntitiesUtil.getDataTypesForCopy());
+
+ List<EchoBaseEntityEnum> expectedTypes =
+ Lists.newArrayList(getContractsOf(Voyage.class.getPackage()));
+
+ Assert.assertNotNull(types);
+
+ for (EchoBaseEntityEnum type : expectedTypes) {
+ Assert.assertTrue("Missing type : " + type, types.contains(type));
+ }
+ Assert.assertEquals(expectedTypes.size(), types.size());
+ }
/**
* Used to get all contract of a package
*
1
0
r211 - in trunk/echobase-tools/src/test: java/fr/ifremer/echobase/tools/loaders resources/csv/new
by tchemit@users.forge.codelutin.com 24 Dec '11
by tchemit@users.forge.codelutin.com 24 Dec '11
24 Dec '11
Author: tchemit
Date: 2011-12-24 13:14:02 +0100 (Sat, 24 Dec 2011)
New Revision: 211
Url: http://forge.codelutin.com/repositories/revision/echobase/211
Log:
add new gear
Modified:
trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/GearLoaderIT.java
trunk/echobase-tools/src/test/resources/csv/new/input-Gear.csv
Modified: trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/GearLoaderIT.java
===================================================================
--- trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/GearLoaderIT.java 2011-12-24 12:12:33 UTC (rev 210)
+++ trunk/echobase-tools/src/test/java/fr/ifremer/echobase/tools/loaders/GearLoaderIT.java 2011-12-24 12:14:02 UTC (rev 211)
@@ -35,7 +35,7 @@
public class GearLoaderIT extends AbstractLoaderIT<Gear, GearLoader> {
public GearLoaderIT() {
- super(GearLoader.class, 112, 0);
+ super(GearLoader.class, 113, 0);
}
@Test
Modified: trunk/echobase-tools/src/test/resources/csv/new/input-Gear.csv
===================================================================
--- trunk/echobase-tools/src/test/resources/csv/new/input-Gear.csv 2011-12-24 12:12:33 UTC (rev 210)
+++ trunk/echobase-tools/src/test/resources/csv/new/input-Gear.csv 2011-12-24 12:14:02 UTC (rev 211)
@@ -1,4 +1,5 @@
CasinoGearName;ValidSince;InvalidSince;IsFishingGear;gearLabel;GearName;Description;UpdateDate;GearClassification;ParentGear;Status;IsActive;IsTowed
+47,75 x 43,75;01/01/00;;1;47,75 x 43,75;CHANGE ME 47,75 x 43,75;;;5;;;1;1
119x102;01/01/00;;1;119x102;Chalut pélagique 119/102;;;5;;;1;1
36x47;01/01/00;;1;GV3647;Chalut de fond GOV 36/47;;;5;;;1;1
57x52;01/01/00;;1;57x52;Chalut pélagique 57/52;;;5;;;1;1
1
0
r210 - trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders
by tchemit@users.forge.codelutin.com 24 Dec '11
by tchemit@users.forge.codelutin.com 24 Dec '11
24 Dec '11
Author: tchemit
Date: 2011-12-24 13:12:33 +0100 (Sat, 24 Dec 2011)
New Revision: 210
Url: http://forge.codelutin.com/repositories/revision/echobase/210
Log:
skip BXXX operation + add NP messages
Modified:
trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/OperationLoader.java
Modified: trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/OperationLoader.java
===================================================================
--- trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/OperationLoader.java 2011-12-20 14:22:50 UTC (rev 209)
+++ trunk/echobase-tools/src/main/java/fr/ifremer/echobase/tools/loaders/OperationLoader.java 2011-12-24 12:12:33 UTC (rev 210)
@@ -249,7 +249,12 @@
}
String operationId = (String) row.get("NOSTA");
+ if ("BXXX".equals(operationId)) {
+ // skip this operation
+ return null;
+ }
+
String gearId = (String) row.get("ENGIN");
if (gearId == null) {
if (log.isWarnEnabled()) {
@@ -298,10 +303,10 @@
}
Float midHauleLatitude = (Float) row.get("LATDD");
- Preconditions.checkNotNull(midHauleLatitude);
+ Preconditions.checkNotNull(midHauleLatitude, "No LATDD for operation " + operationId);
Float midHauleLongitude = (Float) row.get("LGDD");
- Preconditions.checkNotNull(midHauleLongitude);
+ Preconditions.checkNotNull(midHauleLongitude, "No LGDD for operation " + operationId);
Date shootingStartTime = (Date) row.get("DHTUDEB");
Date shootingEndTime = (Date) row.get("DHTUFIN");
1
0
r209 - trunk/echobase-entities/src/main/java/fr/ifremer/echobase
by tchemit@users.forge.codelutin.com 20 Dec '11
by tchemit@users.forge.codelutin.com 20 Dec '11
20 Dec '11
Author: tchemit
Date: 2011-12-20 15:22:50 +0100 (Tue, 20 Dec 2011)
New Revision: 209
Url: http://forge.codelutin.com/repositories/revision/echobase/209
Log:
fix some decorators
Modified:
trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java
Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java
===================================================================
--- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java 2011-12-20 09:21:01 UTC (rev 208)
+++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseDecoratorProvider.java 2011-12-20 14:22:50 UTC (rev 209)
@@ -133,7 +133,7 @@
registerJXPathDecorator(locale, CellType.class, "${name}$s");
// DataMetadata decorator
- registerJXPathDecorator(locale, DataMetadata.class, "${name}$s");
+ registerJXPathDecorator(locale, DataMetadata.class, "${name}$s - ${standardname}$s");
// DataProtocol decorator
registerJXPathDecorator(locale, DataProtocol.class, "${description}$s [ ${validSince}$td/%2$tm/%2$tY - ${invalidSince}$td/%3$tm/%3$tY ]");
@@ -160,7 +160,7 @@
registerJXPathDecorator(locale, GearCharacteristic.class, "${name}$s");
// GearMetadata decorator
- registerJXPathDecorator(locale, GearMetadata.class, "${name}$s");
+ registerJXPathDecorator(locale, GearMetadata.class, "${type}$s (${operationEvent/name}$s)");
// GearCharacteristicValue decorator
registerJXPathDecorator(locale, GearCharacteristicValue.class, "${dataValue}$s");
@@ -169,7 +169,7 @@
registerJXPathDecorator(locale, GearMetadataValue.class, "${dataValue}$s");
// Impacte decorator
- registerJXPathDecorator(locale, Impacte.class, "${measurementUnit}$s - ${species.genusSpecies}");
+ registerJXPathDecorator(locale, Impacte.class, "${measurementUnit}$s - ${species/genusSpecies}");
// LengthAgeKey decorator
registerJXPathDecorator(locale, LengthAgeKey.class, "Age ${age}$s - Length ${length}");
@@ -218,7 +218,7 @@
//TODO
// SpeciesCategory decorator
- registerJXPathDecorator(locale, SpeciesCategory.class, "${species.genusSpecies}$s - ...");
+ registerJXPathDecorator(locale, SpeciesCategory.class, "${species/genusSpecies}$s - ...");
// Strata decorator
registerJXPathDecorator(locale, Strata.class, "Latitude <${minLatitude}$s - ${maxLatitude}$s>, Longitude <${minLongitude}$s - ${maxLongitude}$s>");
@@ -234,7 +234,7 @@
registerJXPathDecorator(locale, VesselType.class, "${name}$s");
// LengthWeightKey decorator
- registerJXPathDecorator(locale, LengthWeightKey.class, "Species ${species.genusSpecies}$s - a=${aParameter}$s, b=${bParameter}$s");
+ registerJXPathDecorator(locale, LengthWeightKey.class, "Species ${species/genusSpecies}$s - a=${aParameter}$s, b=${bParameter}$s");
// Cell decorator
registerJXPathDecorator(locale, Cell.class, "${name}$s");
@@ -254,7 +254,7 @@
registerJXPathDecorator(locale, Operation.class, "${startDate}$td/%1$tm/%1$tY - ${endDate}$td/%2$tm/%2$tY");
// OperationMetadataValue decorator
- registerJXPathDecorator(locale, OperationMetadataValue.class, "${dataValue}$s - moment ${moment.name}");
+ registerJXPathDecorator(locale, OperationMetadataValue.class, "${operationMetadata/name} - ${dataValue}$s");
// Result decorator
registerJXPathDecorator(locale, Result.class, "${resultvalue}$s");
1
0
r208 - in trunk/echobase-ui/src/main/env: dev/resources prod/resources
by tchemit@users.forge.codelutin.com 20 Dec '11
by tchemit@users.forge.codelutin.com 20 Dec '11
20 Dec '11
Author: tchemit
Date: 2011-12-20 10:21:01 +0100 (Tue, 20 Dec 2011)
New Revision: 208
Url: http://forge.codelutin.com/repositories/revision/echobase/208
Log:
increase topia log levels
Modified:
trunk/echobase-ui/src/main/env/dev/resources/log4j.properties
trunk/echobase-ui/src/main/env/prod/resources/log4j.properties
Modified: trunk/echobase-ui/src/main/env/dev/resources/log4j.properties
===================================================================
--- trunk/echobase-ui/src/main/env/dev/resources/log4j.properties 2011-12-19 23:15:41 UTC (rev 207)
+++ trunk/echobase-ui/src/main/env/dev/resources/log4j.properties 2011-12-20 09:21:01 UTC (rev 208)
@@ -33,5 +33,6 @@
log4j.logger.fr.ifremer.echobase=INFO
log4j.logger.org.nuiton=WARN
log4j.logger.org.nuiton.topia.migration=INFO
+log4j.logger.org.nuiton.topia.replication=INFO
log4j.logger.com.opensymphony.xwork2.util.logging.commons.CommonsLogger=ERROR
log4j.logger.org.apache.struts2.util.TokenHelper=ERROR
Modified: trunk/echobase-ui/src/main/env/prod/resources/log4j.properties
===================================================================
--- trunk/echobase-ui/src/main/env/prod/resources/log4j.properties 2011-12-19 23:15:41 UTC (rev 207)
+++ trunk/echobase-ui/src/main/env/prod/resources/log4j.properties 2011-12-20 09:21:01 UTC (rev 208)
@@ -31,5 +31,6 @@
log4j.logger.fr.ifremer.echobase=INFO
log4j.logger.org.nuiton.topia.migration=INFO
+log4j.logger.org.nuiton.topia.replication=INFO
log4j.logger.com.opensymphony.xwork2.util.logging.commons.CommonsLogger=ERROR
log4j.logger.org.apache.struts2.util.TokenHelper=ERROR
1
0
r207 - trunk/echobase-services/src/main/java/fr/ifremer/echobase/services
by tchemit@users.forge.codelutin.com 19 Dec '11
by tchemit@users.forge.codelutin.com 19 Dec '11
19 Dec '11
Author: tchemit
Date: 2011-12-20 00:15:41 +0100 (Tue, 20 Dec 2011)
New Revision: 207
Url: http://forge.codelutin.com/repositories/revision/echobase/207
Log:
fix association loading
Modified:
trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportService.java
Modified: trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportService.java
===================================================================
--- trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportService.java 2011-12-19 21:56:39 UTC (rev 206)
+++ trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/DbImportService.java 2011-12-19 23:15:41 UTC (rev 207)
@@ -271,8 +271,22 @@
ImportToMap importer = MyImportToMap.newImport(model, reader);
StringBuilder builder = new StringBuilder();
+
try {
- String updateString = "UPDATE " + target.getContract().getSimpleName() + " SET " + source.getContract().getSimpleName() + " = '%s' WHERE topiaId ='%s';";
+ String updateString;
+ String targetTableName = target.getContract().getSimpleName();
+ String sourceTableName = source.getContract().getSimpleName();
+ String table = targetTableName;
+ if (source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Echotype) {
+ table = targetTableName + "_" + sourceTableName;
+ updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE " + meta.getName() + " ='%s';";
+ } else if (source == EchoBaseEntityEnum.Voyage && target == EchoBaseEntityEnum.Strata) {
+ table = targetTableName + "_" + source.getContract().getSimpleName();
+ updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE " + meta.getName() + " ='%s';";
+ } else {
+ updateString = "UPDATE " + table + " SET " + sourceTableName + " = '%s' WHERE topiaId ='%s';";
+ }
+
if (log.isDebugEnabled()) {
log.debug("Will apply " + updateString);
}
@@ -283,7 +297,7 @@
for (String association : associations) {
builder.append(String.format(updateString, topiaId, association)).append('\n');
compt++;
- if (compt == 10000) {
+ if (compt % 10000 == 0) {
// flush it
getTransaction().executeSQL(builder.toString());
builder = new StringBuilder();
@@ -291,6 +305,9 @@
}
csvResult.incrementsNumberUpdated();
}
+ if (builder.length() > 0) {
+ getTransaction().executeSQL(builder.toString());
+ }
} catch (TopiaException eee) {
throw new EchoBaseTechnicalException(
"Could not execute sql script", eee);
1
0
Author: tchemit
Date: 2011-12-19 22:56:39 +0100 (Mon, 19 Dec 2011)
New Revision: 206
Url: http://forge.codelutin.com/repositories/revision/echobase/206
Log:
optimize dependencies
Modified:
trunk/echobase-services/pom.xml
Modified: trunk/echobase-services/pom.xml
===================================================================
--- trunk/echobase-services/pom.xml 2011-12-19 21:45:05 UTC (rev 205)
+++ trunk/echobase-services/pom.xml 2011-12-19 21:56:39 UTC (rev 206)
@@ -102,6 +102,11 @@
<artifactId>topia-service-replication</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ </dependency>
+
<!-- test dependencies -->
<dependency>
1
0