This is an automated email from the git hooks/post-receive script. New commit to branch feature/8170 in repository echobase. See https://gitlab.nuiton.org/codelutin/echobase.git commit de7958cef8bb6a5698fc52dc7e128e7d08905fcd Author: Tony CHEMIT <chemit@codelutin.com> Date: Thu Mar 31 04:45:43 2016 +0200 Suppression du domaine de tout ce qui concerne les csv (on retrouve ça partie service) --- echobase-domain/pom.xml | 10 +- .../ifremer/echobase/csv/CellValueFormatter.java | 126 --------------- .../fr/ifremer/echobase/csv/CellValueParser.java | 126 --------------- .../fr/ifremer/echobase/csv/ChainValueParser.java | 75 --------- .../fr/ifremer/echobase/csv/EchoBaseCsvUtil.java | 175 --------------------- .../fr/ifremer/echobase/csv/ResultValueParser.java | 60 ------- .../echobase/entities/data/CellTopiaDao.java | 6 - .../EchoBaseMigrationCallBackResolver.java | 2 +- .../echobase/persistence/EchoBaseDbMetaTest.java | 2 +- 9 files changed, 9 insertions(+), 573 deletions(-) diff --git a/echobase-domain/pom.xml b/echobase-domain/pom.xml index e12787a..c530866 100644 --- a/echobase-domain/pom.xml +++ b/echobase-domain/pom.xml @@ -126,7 +126,11 @@ </dependency> <dependency> <groupId>org.nuiton</groupId> - <artifactId>nuiton-csv</artifactId> + <artifactId>nuiton-converter</artifactId> + </dependency> + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-version</artifactId> </dependency> <!-- comons dependencies --> @@ -171,10 +175,10 @@ <groupId>org.nuiton.topia</groupId> <artifactId>topia-service-migration</artifactId> </dependency> - <dependency> + <!--dependency> <groupId>org.nuiton.topia</groupId> <artifactId>topia-service-csv</artifactId> - </dependency> + </dependency--> <dependency> <groupId>org.hibernate</groupId> diff --git a/echobase-domain/src/main/java/fr/ifremer/echobase/csv/CellValueFormatter.java b/echobase-domain/src/main/java/fr/ifremer/echobase/csv/CellValueFormatter.java deleted file mode 100644 index 1605189..0000000 --- a/echobase-domain/src/main/java/fr/ifremer/echobase/csv/CellValueFormatter.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * #%L - * EchoBase :: Domain - * %% - * Copyright (C) 2011 - 2012 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.csv; - -import com.google.common.collect.Maps; -import fr.ifremer.echobase.entities.data.Cell; -import fr.ifremer.echobase.entities.data.CellTopiaDao; -import fr.ifremer.echobase.entities.data.Voyage; -import org.apache.commons.collections4.CollectionUtils; -import org.nuiton.csv.ImportRuntimeException; -import org.nuiton.csv.ValueParser; -import org.nuiton.topia.persistence.TopiaException; - -import java.text.ParseException; -import java.util.List; -import java.util.Map; - -public class CellValueFormatter implements ValueParser<Cell> { - - final Voyage voyage; - - private final Map<String, Cell> esduCellMap; - - private CellTopiaDao cellDAO; - - public CellValueFormatter(Voyage voyage, CellTopiaDao cellDAO) { - this.voyage = voyage; - this.esduCellMap = Maps.newTreeMap(); - this.cellDAO = cellDAO; - } - - protected CellValueFormatter(Voyage voyage, Map<String, Cell> esduCellMap) { - this.voyage = voyage; - this.esduCellMap = esduCellMap; - } - - @Override - public Cell parse(String value) throws ParseException { - - int separatorIndex = value.indexOf("_"); - - String esduCellId; - String elementaryCellId; - - if (separatorIndex == -1) { - - // just esdu cell in value - - esduCellId = value; - elementaryCellId = null; - } else { - - // esdu and elementary cell in value - - esduCellId = value.substring(0, separatorIndex); - elementaryCellId = value.substring(separatorIndex + 1); - } - - // get esdu cell - Cell result = getEsduCell(esduCellId); - - if (result == null) { - throw new ImportRuntimeException( - "Can not found esdu cell [" + esduCellId + "]"); - } - - if (elementaryCellId != null) { - - // using a elementary cell - - result = result.getChildByName(elementaryCellId); - if (result == null) { - throw new ImportRuntimeException( - "Can not found elementary cell [" + - elementaryCellId + "] for esdu cell [" + - esduCellId + "]"); - } - } - return result; - } - - protected Cell getEsduCell(String esduCellId) throws ParseException { - - Cell result = esduCellMap.get(esduCellId); - - if (result == null && cellDAO != null) { - try { - List<Cell> cells = cellDAO.forNameEquals(esduCellId).findAll(); - - if (CollectionUtils.isEmpty(cells)) { - throw new ImportRuntimeException( - "Can not find esdu cell with name " + esduCellId); - } - - //TODO Should check this cell is in voyage ? - result = cells.get(0); - - // store it in cache - esduCellMap.put(esduCellId, result); - - } catch (TopiaException e) { - throw new ImportRuntimeException( - "Can not find esdu cell with name " + esduCellId); - } - } - return result; - } -} diff --git a/echobase-domain/src/main/java/fr/ifremer/echobase/csv/CellValueParser.java b/echobase-domain/src/main/java/fr/ifremer/echobase/csv/CellValueParser.java deleted file mode 100644 index 2f91d9b..0000000 --- a/echobase-domain/src/main/java/fr/ifremer/echobase/csv/CellValueParser.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * #%L - * EchoBase :: Domain - * %% - * Copyright (C) 2011 - 2012 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.csv; - -import com.google.common.collect.Maps; -import fr.ifremer.echobase.entities.data.Cell; -import fr.ifremer.echobase.entities.data.CellTopiaDao; -import fr.ifremer.echobase.entities.data.Voyage; -import org.apache.commons.collections4.CollectionUtils; -import org.nuiton.csv.ImportRuntimeException; -import org.nuiton.csv.ValueParser; -import org.nuiton.topia.persistence.TopiaException; - -import java.text.ParseException; -import java.util.List; -import java.util.Map; - -public class CellValueParser implements ValueParser<Cell> { - - final Voyage voyage; - - private final Map<String, Cell> esduCellMap; - - private CellTopiaDao cellDAO; - - public CellValueParser(Voyage voyage, CellTopiaDao cellDAO) { - this.voyage = voyage; - this.esduCellMap = Maps.newTreeMap(); - this.cellDAO = cellDAO; - } - - protected CellValueParser(Voyage voyage, Map<String, Cell> esduCellMap) { - this.voyage = voyage; - this.esduCellMap = esduCellMap; - } - - @Override - public Cell parse(String value) throws ParseException { - - int separatorIndex = value.indexOf("_"); - - String esduCellId; - String elementaryCellId; - - if (separatorIndex == -1) { - - // just esdu cell in value - - esduCellId = value; - elementaryCellId = null; - } else { - - // esdu and elementary cell in value - - esduCellId = value.substring(0, separatorIndex); - elementaryCellId = value.substring(separatorIndex + 1); - } - - // get esdu cell - Cell result = getEsduCell(esduCellId); - - if (result == null) { - throw new ImportRuntimeException( - "Can not found esdu cell [" + esduCellId + "]"); - } - - if (elementaryCellId != null) { - - // using a elementary cell - - result = result.getChildByName(elementaryCellId); - if (result == null) { - throw new ImportRuntimeException( - "Can not found elementary cell [" + - elementaryCellId + "] for esdu cell [" + - esduCellId + "]"); - } - } - return result; - } - - protected Cell getEsduCell(String esduCellId) throws ParseException { - - Cell result = esduCellMap.get(esduCellId); - - if (result == null && cellDAO != null) { - try { - List<Cell> cells = cellDAO.forNameEquals(esduCellId).findAll(); - - if (CollectionUtils.isEmpty(cells)) { - throw new ImportRuntimeException( - "Can not find esdu cell with name " + esduCellId); - } - - //TODO Should check this cell is in voyage ? - result = cells.get(0); - - // store it in cache - esduCellMap.put(esduCellId, result); - - } catch (TopiaException e) { - throw new ImportRuntimeException( - "Can not find esdu cell with name " + esduCellId); - } - } - return result; - } -} diff --git a/echobase-domain/src/main/java/fr/ifremer/echobase/csv/ChainValueParser.java b/echobase-domain/src/main/java/fr/ifremer/echobase/csv/ChainValueParser.java deleted file mode 100644 index 8f36a97..0000000 --- a/echobase-domain/src/main/java/fr/ifremer/echobase/csv/ChainValueParser.java +++ /dev/null @@ -1,75 +0,0 @@ -package fr.ifremer.echobase.csv; - -/* - * #%L - * EchoBase :: Domain - * %% - * Copyright (C) 2011 - 2012 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ - -import com.google.common.collect.Lists; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.ValueParser; - -import java.text.ParseException; -import java.util.Iterator; -import java.util.List; - -/** - * To chain some {@link ValueParser} (different format supported). - * - * @author Tony Chemit - chemit@codelutin.com - * @since 1.3 - */ -public class ChainValueParser<E> implements ValueParser<E> { - - /** Logger. */ - private static final Log log = LogFactory.getLog(ChainValueParser.class); - - final List<ValueParser<E>> parsers = Lists.newArrayList(); - - public ChainValueParser<E> addParser(ValueParser<E> parser) { - this.parsers.add(parser); - return this; - } - - @Override - public E parse(String value) throws ParseException { - E result = null; - Iterator<ValueParser<E>> iterator = parsers.iterator(); - while (iterator.hasNext()) { - ValueParser<E> parser = iterator.next(); - try { - result = parser.parse(value); - break; - } catch (Exception e) { - if (log.isErrorEnabled()) { - log.error("Could not parse value " + value, e); - } - } - } - - if (result == null && !iterator.hasNext()) { - - // all parsers were used and no one gives a good result - throw new ParseException( - "Could not parse value " + value + " with any parsers", 0); - } - return result; - } -} diff --git a/echobase-domain/src/main/java/fr/ifremer/echobase/csv/EchoBaseCsvUtil.java b/echobase-domain/src/main/java/fr/ifremer/echobase/csv/EchoBaseCsvUtil.java deleted file mode 100644 index 1976ce7..0000000 --- a/echobase-domain/src/main/java/fr/ifremer/echobase/csv/EchoBaseCsvUtil.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * #%L - * EchoBase :: Domain - * %% - * 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.csv; - -import fr.ifremer.echobase.entities.data.Cell; -import fr.ifremer.echobase.entities.data.Result; -import fr.ifremer.echobase.entities.data.Voyage; -import fr.ifremer.echobase.entities.references.DataMetadata; -import fr.ifremer.echobase.entities.references.DataQuality; -import fr.ifremer.echobase.entities.references.Species; -import org.nuiton.csv.ValueFormatter; -import org.nuiton.csv.ValueParser; -import org.nuiton.csv.ValueParserFormatter; -import org.nuiton.csv.ValueSetter; -import org.nuiton.topia.service.csv.TopiaCsvCommons; - -import java.util.Date; -import java.util.List; -import java.util.Map; - -/** - * Usefull class to build csv import-export models. - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.2 - */ -public class EchoBaseCsvUtil extends TopiaCsvCommons { - - public static final String CELLULE_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSSS"; - - public static final ValueParser<Date> IMPORT_DAY_TIME_ECHOBASE = new DateValue(CELLULE_DATE_FORMAT); - - public static final ValueParser<Date> IMPORT_DAY_TIME_ECHOBASE2 = new DateValue("dd/MM/yyyy HH:mm:ss.SSSS"); - - public static final ValueFormatter<Species> SPECIES_TO_COSER_CODE = new ValueFormatter<Species>() { - @Override - public String format(Species value) { - return value.getBaracoudaCode().replaceAll("-", ""); - } - }; - - public static final ValueParser<Boolean> INT_TO_BOOLEAN_PARSER = new ValueParser<Boolean>() { - - @Override - public Boolean parse(String value) { - return "1".equals(value); - } - }; - - public static final ValueParserFormatter<Float> NA_TO_FLOAT_PARSER_FORMATTER = new FloatParserFormatter(null, true) { - - @Override - public String format(Float value) { - return value == null ? NA : super.format(value); - } - - @Override - protected Float parseNoneEmptyValue(String value) { - Float result = null; - if (!NA.equals(value)) { - result = super.parseNoneEmptyValue(value); - } - return result; - } - - }; - - public static final ValueParser<Float> NA_TO_PRIMITIVE_FLOAT_PARSER = new FloatParserFormatter(0f, false) { - - @Override - protected Float parseNoneEmptyValue(String value) { - Float result; - if (!NA.equals(value)) { - result = super.parseNoneEmptyValue(value); - } else { - result = defaultValue; - } - return result; - } - - }; - - public static final ValueParserFormatter<Integer> NA_TO_INTEGER_PARSER_FORMATTER = new IntegerParserFormatter(null, true) { - - @Override - public String format(Integer value) { - return value == null ? NA : super.format(value); - } - - @Override - protected Integer parseNoneEmptyValue(String value) { - Integer result = null; - if (!NA.equals(value)) { - result = super.parseNoneEmptyValue(value); - } - return result; - } - - }; - - public static final ValueParser<Date> DATE_TIME_VALUE_PARSER = new ChainValueParser<Date>(). - addParser(TopiaCsvCommons.DAY_TIME_SECOND_WITH_TIMESTAMP). - addParser(TopiaCsvCommons.DAY_TIME_SECOND). - addParser(TopiaCsvCommons.DAY_TIME). - addParser(TopiaCsvCommons.DAY); - - public static final String CELL_NAME = "name"; - - public static final String OPERATION_ID = "operationId"; - - public static final String VESSEL_NAME = "vesselName"; - - public static final String GEAR_CODE = "gearCode"; - - public static final String DEPTH_STRATUM_ID = "depthStratumId"; - - public static final String NA = "NA"; - - protected EchoBaseCsvUtil() { - // avoid instanciation on helper class - } - - public static ValueParser<Cell> newCellValueParser(Voyage voyage, - Map<String, Cell> esduCellMap) { - return new CellValueParser(voyage, esduCellMap); - } - - public static interface ResultAble { - - void addResult(Result value); - - List<Result> getResult(); - - DataQuality getDataQuality(); - - void setDataQuality(DataQuality dataQuality); - - } - - public static <B extends ResultAble> ValueSetter<B, Result> newResultValueSetter() { - return new ResultValueSetter<B>(); - } - - private static class ResultValueSetter<B extends ResultAble> implements ValueSetter<B, Result> { - - @Override - public void set(B object, Result value) throws Exception { - object.addResult(value); - } - } - - public static ValueParser<Result> newResultValueParser( - DataMetadata metadata, boolean useFillValue) { - return new ResultValueParser(metadata, useFillValue); - } - -} diff --git a/echobase-domain/src/main/java/fr/ifremer/echobase/csv/ResultValueParser.java b/echobase-domain/src/main/java/fr/ifremer/echobase/csv/ResultValueParser.java deleted file mode 100644 index 53e17a9..0000000 --- a/echobase-domain/src/main/java/fr/ifremer/echobase/csv/ResultValueParser.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * #%L - * EchoBase :: Domain - * %% - * Copyright (C) 2011 - 2012 Ifremer, Codelutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * #L% - */ -package fr.ifremer.echobase.csv; - -import fr.ifremer.echobase.entities.data.Result; -import fr.ifremer.echobase.entities.data.ResultImpl; -import fr.ifremer.echobase.entities.references.DataMetadata; -import org.nuiton.csv.ValueParser; - -import java.text.ParseException; - -/** - * TODO - * - * @author Tony Chemit - chemit@codelutin.com - * @since 0.3 - */ -public class ResultValueParser implements ValueParser<Result> { - - final DataMetadata metadata; - - final boolean useFillValue; - - public ResultValueParser(DataMetadata metadata, boolean useFillValue) { - this.metadata = metadata; - this.useFillValue = useFillValue; - } - - @Override - public Result parse(String value) throws ParseException { - - Result result = new ResultImpl(); - result.setDataMetadata(metadata); - result.setResultValue(value); - if (EchoBaseCsvUtil.NA.equals(value) && useFillValue) { - - // use metadata fillValue - result.setResultValue(String.valueOf(metadata.getFillValue())); - } - return result; - } -} diff --git a/echobase-domain/src/main/java/fr/ifremer/echobase/entities/data/CellTopiaDao.java b/echobase-domain/src/main/java/fr/ifremer/echobase/entities/data/CellTopiaDao.java index 5ebf017..87f1d39 100644 --- a/echobase-domain/src/main/java/fr/ifremer/echobase/entities/data/CellTopiaDao.java +++ b/echobase-domain/src/main/java/fr/ifremer/echobase/entities/data/CellTopiaDao.java @@ -21,8 +21,6 @@ package fr.ifremer.echobase.entities.data; * #L% */ -import fr.ifremer.echobase.csv.CellValueParser; -import org.nuiton.csv.ValueParser; import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.support.TopiaSqlQuery; @@ -55,10 +53,6 @@ public class CellTopiaDao extends AbstractCellTopiaDao<Cell> { return topiaSqlSupport.findMultipleResult(query); } - public ValueParser<Cell> newCellValueParser(Voyage voyage) { - return new CellValueParser(voyage, this); - } - protected TopiaSqlQuery<Long> newCountVoyageOrphanCellsQuery(final Voyage voyage) { return new TopiaSqlQuery<Long>() { @Override diff --git a/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/EchoBaseMigrationCallBackResolver.java b/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/EchoBaseMigrationCallBackResolver.java index 47d42c2..ba5f91c 100644 --- a/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/EchoBaseMigrationCallBackResolver.java +++ b/echobase-domain/src/main/java/fr/ifremer/echobase/persistence/migration/EchoBaseMigrationCallBackResolver.java @@ -46,7 +46,7 @@ public class EchoBaseMigrationCallBackResolver<C extends TopiaMigrationCallbackB LogFactory.getLog(EchoBaseMigrationCallBackResolver.class); public static <C extends TopiaMigrationCallbackByClassNG.MigrationCallBackForVersion<?>> EchoBaseMigrationCallBackResolver<C> newResolver(Class<C> resolverType) { - return new EchoBaseMigrationCallBackResolver<C>(resolverType); + return new EchoBaseMigrationCallBackResolver<>(resolverType); } protected final Map<Version, C> versionMigrationMapping; diff --git a/echobase-domain/src/test/java/fr/ifremer/echobase/persistence/EchoBaseDbMetaTest.java b/echobase-domain/src/test/java/fr/ifremer/echobase/persistence/EchoBaseDbMetaTest.java index 65f08d2..3397721 100644 --- a/echobase-domain/src/test/java/fr/ifremer/echobase/persistence/EchoBaseDbMetaTest.java +++ b/echobase-domain/src/test/java/fr/ifremer/echobase/persistence/EchoBaseDbMetaTest.java @@ -91,7 +91,7 @@ public class EchoBaseDbMetaTest { */ public static EchoBaseUserEntityEnum[] getContractsOf(Package entitiesPackage) { EchoBaseUserEntityEnum[] echoBaseEntityEnums = EchoBaseUserEntityEnum.values(); - List<EchoBaseUserEntityEnum> refClasses = new ArrayList<EchoBaseUserEntityEnum>(); + List<EchoBaseUserEntityEnum> refClasses = new ArrayList<>(); for (EchoBaseUserEntityEnum echoBaseEntityEnum : echoBaseEntityEnums) { // Get all entities in package fr.ifremer.echobase.entities.references -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.