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 cec5c7058ae40a11058b4f4430d61dcc9ef8f434 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Mar 28 08:56:53 2016 +0200 Debut de mise en place d'un export lors de l'import --- .../ifremer/echobase/csv/CellValueFormatter.java | 126 +++++++++++++++++++++ .../csv/EchoBaseImportExportModelSupport.java | 9 ++ 2 files changed, 135 insertions(+) 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 new file mode 100644 index 0000000..1605189 --- /dev/null +++ b/echobase-domain/src/main/java/fr/ifremer/echobase/csv/CellValueFormatter.java @@ -0,0 +1,126 @@ +/* + * #%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-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/EchoBaseImportExportModelSupport.java b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/EchoBaseImportExportModelSupport.java new file mode 100644 index 0000000..3e7478e --- /dev/null +++ b/echobase-services/src/main/java/fr/ifremer/echobase/services/service/importdata/csv/EchoBaseImportExportModelSupport.java @@ -0,0 +1,9 @@ +package fr.ifremer.echobase.services.service.importdata.csv; + +/** + * Created on 27/03/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class EchoBaseImportExportModelSupport { +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.