This is an automated email from the git hooks/post-receive script. New commit to branch feature/#8171 in repository echobase. See https://gitlab.nuiton.org/codelutin/echobase.git commit 3df68fd7ce7f7834b5f2a51dadee236646892ede Author: Julien Ruchaud <julien.ruchaud@debux.org> Date: Wed May 11 17:22:14 2016 +0200 Fix import for the voyage entity --- .../echobase/entities/references/Ports.java | 39 +++++++++++++++++++++ .../migration/workingDb/3.905-1-insert-ports.sql | 4 +-- .../echobase/services/csv/EchoBaseCsvUtil.java | 12 +++++++ .../services/service/UserDbPersistenceService.java | 4 +-- .../contexts/ImportDataContextSupport.java | 10 ++++++ .../csv/VoyageCommonsVoyageImportExportModel.java | 9 ++--- .../resources/import-data/common/voyage.csv.gz | Bin 126 -> 117 bytes 7 files changed, 70 insertions(+), 8 deletions(-) diff --git a/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/Ports.java b/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/Ports.java new file mode 100644 index 0000000..ade1934 --- /dev/null +++ b/echobase-domain/src/main/java/fr/ifremer/echobase/entities/references/Ports.java @@ -0,0 +1,39 @@ +package fr.ifremer.echobase.entities.references; + +/* + * #%L + * EchoBase :: Domain + * %% + * Copyright (C) 2011 - 2015 Ifremer, Codelutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * #L% + */ + +import com.google.common.base.Function; + +/** + * Created on 1/21/15. + * + * @author Julien Ruchaud - ruchaud@codelutin.com + * @since XXX + */ +public class Ports { + public static final Function<Port, String> PORT_CODE = new Function<Port, String>() { + @Override + public String apply(Port input) { + return input.getCode(); + } + }; +} diff --git a/echobase-domain/src/main/resources/migration/workingDb/3.905-1-insert-ports.sql b/echobase-domain/src/main/resources/migration/workingDb/3.905-1-insert-ports.sql index 675f0ee..44c1f6f 100644 --- a/echobase-domain/src/main/resources/migration/workingDb/3.905-1-insert-ports.sql +++ b/echobase-domain/src/main/resources/migration/workingDb/3.905-1-insert-ports.sql @@ -4896,8 +4896,8 @@ insert into port (topiaId, topiaVersion, topiaCreateDate, code, name, shortName, insert into port (topiaId, topiaVersion, topiaCreateDate, code, name, shortName, lastModification) values ('fr.ifremer.echobase.entities.references.Port#5553610280597#0.93226150254894', 0, '2016-04-29 00:00:00.000', 'BSH99', 'Istanbul', 'Istanbul', '2007-08-02 00:00:00.000'); -- Change ports name -update voyage v SET (startPort) = (select p.topiaId from port p where upper(p.name) = upper(v.startPortName)); -update voyage v SET (endPort) = (select p.topiaId from port p where upper(p.name) = upper(v.endPortName)); +update voyage v SET (startPort) = (select p.topiaId from port p where upper(p.name) = upper(v.startPortName) limit 1); +update voyage v SET (endPort) = (select p.topiaId from port p where upper(p.name) = upper(v.endPortName) limit 1); alter table voyage drop column startPortName; alter table voyage drop column endPortName; diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/csv/EchoBaseCsvUtil.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/csv/EchoBaseCsvUtil.java index 8fbe18a..7846696 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/csv/EchoBaseCsvUtil.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/csv/EchoBaseCsvUtil.java @@ -35,6 +35,7 @@ import fr.ifremer.echobase.entities.references.DepthStratum; import fr.ifremer.echobase.entities.references.Gear; import fr.ifremer.echobase.entities.references.GearMetadata; import fr.ifremer.echobase.entities.references.OperationMetadata; +import fr.ifremer.echobase.entities.references.Port; import fr.ifremer.echobase.entities.references.SampleDataType; import fr.ifremer.echobase.entities.references.SexCategory; import fr.ifremer.echobase.entities.references.SizeCategory; @@ -234,6 +235,15 @@ public class EchoBaseCsvUtil extends TopiaCsvCommons { } } ); + public static final ValueFormatter<Port> PORT_FORMATTER = newValueFormatterByFunction( + new Function<Port, String>() { + + @Override + public String apply(Port input) { + return input.getCode(); + } + } + ); public static <E> ValueFormatter<E> newValueFormatterByFunction(Function<E, String> function) { return new ValueFormatterByFunction<>(function); @@ -333,6 +343,8 @@ public class EchoBaseCsvUtil extends TopiaCsvCommons { public static final String OPERATION_ID = "operationId"; public static final String VESSEL_NAME = "vesselName"; + + public static final String PORT_CODE = "portCode"; public static final String GEAR_CODE = "gearCode"; diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java index e76de7a..332441d 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/UserDbPersistenceService.java @@ -942,8 +942,8 @@ public class UserDbPersistenceService extends EchoBaseServiceSupport { } public <E extends TopiaEntity, K> Map<K, E> getEntitiesMap(Class<E> entityType, Function<E, K> function) { - List<E> allVoyages = persistenceContext.getDao(entityType).findAll(); - return Maps.uniqueIndex(allVoyages, function); + List<E> entities = persistenceContext.getDao(entityType).findAll(); + return Maps.uniqueIndex(entities, function); } public void executeSQL(String sqlScript) { diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/contexts/ImportDataContextSupport.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/contexts/ImportDataContextSupport.java index 5a9065f..8cb7129 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/contexts/ImportDataContextSupport.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/contexts/ImportDataContextSupport.java @@ -21,6 +21,8 @@ import fr.ifremer.echobase.entities.references.GearMetadatas; import fr.ifremer.echobase.entities.references.Gears; import fr.ifremer.echobase.entities.references.OperationMetadata; import fr.ifremer.echobase.entities.references.OperationMetadatas; +import fr.ifremer.echobase.entities.references.Port; +import fr.ifremer.echobase.entities.references.Ports; import fr.ifremer.echobase.entities.references.SampleDataType; import fr.ifremer.echobase.entities.references.SampleDataTypes; import fr.ifremer.echobase.entities.references.SexCategories; @@ -75,6 +77,7 @@ public abstract class ImportDataContextSupport<C extends ImportDataConfiguration private Map<String, Strata> stratasByName; private Map<String, CellType> regionCellTypesById; private Map<String, AgeCategory> ageCategoriesByName; + private Map<String, Port> portsByCode; private CellType esduCellType; private CellType elementaryCellType; @@ -218,6 +221,13 @@ public abstract class ImportDataContextSupport<C extends ImportDataConfiguration return vesselsByName; } + public final Map<String, Port> getPortByCode() { + if (portsByCode == null) { + portsByCode = persistenceService.getEntitiesMap(Port.class, Ports.PORT_CODE); + } + return portsByCode; + } + public final Map<String, DataMetadata> getDataMetadatasByName() { if (dataMetadatasByName == null) { dataMetadatasByName = persistenceService.getEntitiesMap(DataMetadata.class, DataMetadatas.DATA_METADATA_NAME); diff --git a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageCommonsVoyageImportExportModel.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageCommonsVoyageImportExportModel.java index 33e526b..b7cb0c4 100644 --- a/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageCommonsVoyageImportExportModel.java +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/VoyageCommonsVoyageImportExportModel.java @@ -22,6 +22,7 @@ package fr.ifremer.echobase.services.service.importdata.csv; import fr.ifremer.echobase.entities.data.Voyage; import fr.ifremer.echobase.entities.data.VoyageImpl; +import fr.ifremer.echobase.entities.references.Port; import fr.ifremer.echobase.services.csv.EchoBaseCsvUtil; import fr.ifremer.echobase.services.service.importdata.contexts.VoyageCommonsImportDataContext; @@ -43,8 +44,8 @@ public class VoyageCommonsVoyageImportExportModel extends EchoBaseImportExportMo model.newMandatoryColumn(Voyage.PROPERTY_NAME); model.newMandatoryColumn(Voyage.PROPERTY_START_DATE, EchoBaseCsvUtil.IMPORT_DAY_TIME_ECHOBASE); model.newMandatoryColumn(Voyage.PROPERTY_END_DATE, EchoBaseCsvUtil.IMPORT_DAY_TIME_ECHOBASE); - model.newMandatoryColumn(Voyage.PROPERTY_START_PORT); - model.newMandatoryColumn(Voyage.PROPERTY_END_PORT); + model.newForeignKeyColumn(Voyage.PROPERTY_START_PORT, Voyage.PROPERTY_START_PORT, Port.class, Port.PROPERTY_CODE, importDataContext.getPortByCode()); + model.newForeignKeyColumn(Voyage.PROPERTY_END_PORT, Voyage.PROPERTY_END_PORT, Port.class, Port.PROPERTY_CODE, importDataContext.getPortByCode()); return model; } @@ -55,8 +56,8 @@ public class VoyageCommonsVoyageImportExportModel extends EchoBaseImportExportMo model.newColumnForExport(Voyage.PROPERTY_NAME); model.newColumnForExport(Voyage.PROPERTY_START_DATE, EchoBaseCsvUtil.IMPORT_DAY_TIME_ECHOBASE); model.newColumnForExport(Voyage.PROPERTY_END_DATE, EchoBaseCsvUtil.IMPORT_DAY_TIME_ECHOBASE); - model.newColumnForExport(Voyage.PROPERTY_START_PORT); - model.newColumnForExport(Voyage.PROPERTY_END_PORT); + model.newColumnForExport(Voyage.PROPERTY_START_PORT, Voyage.PROPERTY_START_PORT, EchoBaseCsvUtil.PORT_FORMATTER); + model.newColumnForExport(Voyage.PROPERTY_END_PORT, Voyage.PROPERTY_END_PORT, EchoBaseCsvUtil.PORT_FORMATTER); return model; } diff --git a/echobase-services/src/test/resources/import-data/common/voyage.csv.gz b/echobase-services/src/test/resources/import-data/common/voyage.csv.gz index 8163876..e5280fa 100644 Binary files a/echobase-services/src/test/resources/import-data/common/voyage.csv.gz and b/echobase-services/src/test/resources/import-data/common/voyage.csv.gz differ -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.