Author: tchemit Date: 2012-03-27 01:04:04 +0200 (Tue, 27 Mar 2012) New Revision: 409 Url: http://forge.codelutin.com/repositories/revision/echobase/409 Log: move cs api into entites module Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractExportModel.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractImportExportModel.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractImportModel.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AssociationValueParser.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AssociationValueParserFormatter.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CellValueParser.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CsvFileImportResult.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CsvImportResult.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/EchobaseCsvUtil.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ForeignKeyValue.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ForeignKeyValueForAssociation.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ResultValueParser.java Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseFunctions.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/EchoBaseExport.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/CategoryImpl.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/MetaFilenameAware.java trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/TableMeta.java Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java 2012-03-26 23:02:10 UTC (rev 408) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseConfiguration.java 2012-03-26 23:04:04 UTC (rev 409) @@ -88,7 +88,7 @@ File dataDirectory = getDataDirectory(); String dataDirectoryPath = dataDirectory.getAbsolutePath(); if (log.isInfoEnabled()) { - log.info("Data directory = "+dataDirectoryPath); + log.info("Data directory = " + dataDirectoryPath); } if (dataDirectoryPath.endsWith(".")) { dataDirectoryPath = dataDirectory.getParentFile().getAbsolutePath(); Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseFunctions.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseFunctions.java 2012-03-26 23:02:10 UTC (rev 408) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/EchoBaseFunctions.java 2012-03-26 23:04:04 UTC (rev 409) @@ -25,6 +25,7 @@ import com.google.common.base.Function; import fr.ifremer.echobase.entities.EchoBaseEntityEnum; +import fr.ifremer.echobase.entities.data.Cell; import fr.ifremer.echobase.entities.data.DataProcessing; import fr.ifremer.echobase.entities.data.Echotype; import fr.ifremer.echobase.entities.data.Operation; @@ -305,13 +306,20 @@ } }; - public static final Function<MetaFilenameAware,EchoBaseEntityEnum> META_BY_SOURCE = new Function<MetaFilenameAware, EchoBaseEntityEnum>() { + public static final Function<MetaFilenameAware, EchoBaseEntityEnum> META_BY_SOURCE = new Function<MetaFilenameAware, EchoBaseEntityEnum>() { @Override public EchoBaseEntityEnum apply(MetaFilenameAware input) { return input.getSource(); } }; + public static final Function<Cell, String> CELL_BY_NAME = new Function<Cell, String>() { + @Override + public String apply(Cell input) { + return input.getName(); + } + }; + public static String getSpeciesCategoryKey(Species species, SizeCategory sizeCategory, SexCategory sexCategory) { String key = species.getBaracoudaCode(); if (sizeCategory != null) { Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractExportModel.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractExportModel.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractExportModel.java 2012-03-26 23:04:04 UTC (rev 409) @@ -0,0 +1,76 @@ +/* + * #%L + * EchoBase :: Entities + * + * $Id$ + * $HeadURL$ + * %% + * 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 org.nuiton.util.csv.ExportModel; +import org.nuiton.util.csv.ExportableColumn; +import org.nuiton.util.csv.ModelBuilder; +import org.nuiton.util.csv.ValueFormatter; +import org.nuiton.util.csv.ValueGetter; + +public abstract class AbstractExportModel<E> implements ExportModel<E> { + + private final char separator; + + protected final ModelBuilder<E> modelBuilder; + + public AbstractExportModel(char separator) { + this.separator = separator; + modelBuilder = new ModelBuilder<E>(); + } + + @Override + public final char getSeparator() { + return separator; + } + + @Override + public final Iterable<ExportableColumn<E, Object>> getColumnsForExport() { + return (Iterable) modelBuilder.getColumnsForExport(); + } + + public ExportableColumn<E, String> newColumnForExport(String headerName) { + return modelBuilder.newColumnForExport(headerName, headerName); + } + + public ExportableColumn<E, String> newColumnForExport(String headerName, String propertyName) { + return modelBuilder.newColumnForExport(headerName, propertyName); + } + + public ExportableColumn<E, String> newColumnForExport(String headerName, ValueGetter<E, String> eStringValueGetter) { + return modelBuilder.newColumnForExport(headerName, eStringValueGetter); + } + + public <T> ExportableColumn<E, T> newColumnForExport(String headerName, ValueFormatter<T> valueFormatter) { + return modelBuilder.newColumnForExport(headerName, headerName, valueFormatter); + } + + public <T> ExportableColumn<E, T> newColumnForExport(String headerName, String propertyName, ValueFormatter<T> valueFormatter) { + return modelBuilder.newColumnForExport(headerName, propertyName, valueFormatter); + } + + public <T> ExportableColumn<E, T> newColumnForExport(String headerName, ValueGetter<E, T> etValueGetter, ValueFormatter<T> valueFormatter) { + return modelBuilder.newColumnForExport(headerName, etValueGetter, valueFormatter); + } +} \ No newline at end of file Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractExportModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractImportExportModel.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractImportExportModel.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractImportExportModel.java 2012-03-26 23:04:04 UTC (rev 409) @@ -0,0 +1,155 @@ +/* + * #%L + * EchoBase :: Entities + * + * $Id$ + * $HeadURL$ + * %% + * 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 org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.csv.ExportableColumn; +import org.nuiton.util.csv.ImportExportModel; +import org.nuiton.util.csv.ImportableColumn; +import org.nuiton.util.csv.ImportableExportableColumn; +import org.nuiton.util.csv.ModelBuilder; +import org.nuiton.util.csv.ValueFormatter; +import org.nuiton.util.csv.ValueGetter; +import org.nuiton.util.csv.ValueGetterSetter; +import org.nuiton.util.csv.ValueParser; +import org.nuiton.util.csv.ValueParserFormatter; +import org.nuiton.util.csv.ValueSetter; + +import java.util.List; +import java.util.Map; + +public abstract class AbstractImportExportModel<E> implements ImportExportModel<E> { + + private final char separator; + + protected final ModelBuilder<E> modelBuilder; + + public AbstractImportExportModel(char separator) { + this.separator = separator; + modelBuilder = new ModelBuilder<E>(); + } + + @Override + public final char getSeparator() { + return separator; + } + + @Override + public void pushCsvHeaderNames(List<String> headerNames) { + } + + @Override + public final Iterable<ExportableColumn<E, Object>> getColumnsForExport() { + return (Iterable) modelBuilder.getColumnsForExport(); + } + + @Override + public final Iterable<ImportableColumn<E, Object>> getColumnsForImport() { + return (Iterable) modelBuilder.getColumnsForImport(); + } + + public <T> ImportableColumn<E, T> newIgnoredColumn(String headerName) { + return modelBuilder.newIgnoredColumn(headerName); + } + + public ImportableColumn<E, String> newMandatoryColumn(String headerName) { + return modelBuilder.newMandatoryColumn(headerName, headerName); + } + + public ImportableColumn<E, String> newMandatoryColumn(String headerName, String propertyName) { + return modelBuilder.newMandatoryColumn(headerName, propertyName); + } + + public <T> ImportableColumn<E, T> newMandatoryColumn(String headerName, ValueParser<T> valueParser) { + return modelBuilder.newMandatoryColumn(headerName, headerName, valueParser); + } + + public <T> ImportableColumn<E, T> newMandatoryColumn(String headerName, String propertyName, ValueParser<T> valueParser) { + return modelBuilder.newMandatoryColumn(headerName, propertyName, valueParser); + } + + public ImportableColumn<E, String> newMandatoryColumn(String headerName, ValueSetter<E, String> eStringValueSetter) { + return modelBuilder.newMandatoryColumn(headerName, eStringValueSetter); + } + + public <T> ImportableColumn<E, T> newMandatoryColumn(String headerName, ValueParser<T> valueParser, ValueSetter<E, T> etValueSetter) { + return modelBuilder.newMandatoryColumn(headerName, valueParser, etValueSetter); + } + + public ExportableColumn<E, String> newColumnForExport(String headerName) { + return modelBuilder.newColumnForExport(headerName, headerName); + } + + public ExportableColumn<E, String> newColumnForExport(String headerName, String propertyName) { + return modelBuilder.newColumnForExport(headerName, propertyName); + } + + public ExportableColumn<E, String> newColumnForExport(String headerName, ValueGetter<E, String> eStringValueGetter) { + return modelBuilder.newColumnForExport(headerName, eStringValueGetter); + } + + public <T> ExportableColumn<E, T> newColumnForExport(String headerName, ValueFormatter<T> valueFormatter) { + return modelBuilder.newColumnForExport(headerName, headerName, valueFormatter); + } + + public <T> ExportableColumn<E, T> newColumnForExport(String headerName, String propertyName, ValueFormatter<T> valueFormatter) { + return modelBuilder.newColumnForExport(headerName, propertyName, valueFormatter); + } + + public <T> ExportableColumn<E, T> newColumnForExport(String headerName, ValueGetter<E, T> etValueGetter, ValueFormatter<T> valueFormatter) { + return modelBuilder.newColumnForExport(headerName, etValueGetter, valueFormatter); + } + + public ImportableExportableColumn<E, String> newColumnForImportExport(String headerName) { + return modelBuilder.newColumnForImportExport(headerName, headerName); + } + + public ImportableExportableColumn<E, String> newColumnForImportExport(String headerName, String propertyName) { + return modelBuilder.newColumnForImportExport(headerName, propertyName); + } + + public ImportableExportableColumn<E, String> newColumnForImportExport(String headerName, ValueGetterSetter<E, String> eStringValueGetterSetter) { + return modelBuilder.newColumnForImportExport(headerName, eStringValueGetterSetter); + } + + public <T> ImportableExportableColumn<E, T> newColumnForImportExport(String headerName, ValueParserFormatter<T> valueParserFormatter) { + return modelBuilder.newColumnForImportExport(headerName, headerName, valueParserFormatter); + } + + public <T> ImportableExportableColumn<E, T> newColumnForImportExport(String headerName, String propertyName, ValueParserFormatter<T> valueParserFormatter) { + return modelBuilder.newColumnForImportExport(headerName, propertyName, valueParserFormatter); + } + + public <T> ImportableExportableColumn<E, T> newColumnForImportExport(String headerName, ValueGetterSetter<E, T> etValueGetterSetter, ValueParserFormatter<T> valueParserFormatter) { + return modelBuilder.newColumnForImportExport(headerName, etValueGetterSetter, valueParserFormatter); + } + + protected <E extends TopiaEntity> void newForeignKeyColumn(String headerName, String propertyName, Class<E> entityType, String foreignKeyName, Map<String, E> universe) { + newMandatoryColumn(headerName, propertyName, EchobaseCsvUtil.newForeignKeyValue(entityType, foreignKeyName, universe)); + } + + protected <E extends TopiaEntity> void newForeignKeyColumn(String propertyName, Class<E> entityType, String foreignKeyName, Map<String, E> universe) { + newMandatoryColumn(propertyName, propertyName, EchobaseCsvUtil.newForeignKeyValue(entityType, foreignKeyName, universe)); + } +} \ No newline at end of file Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractImportExportModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractImportModel.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractImportModel.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractImportModel.java 2012-03-26 23:04:04 UTC (rev 409) @@ -0,0 +1,96 @@ +/* + * #%L + * EchoBase :: Entities + * + * $Id$ + * $HeadURL$ + * %% + * 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 org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.csv.ImportModel; +import org.nuiton.util.csv.ImportableColumn; +import org.nuiton.util.csv.ModelBuilder; +import org.nuiton.util.csv.ValueParser; +import org.nuiton.util.csv.ValueSetter; + +import java.util.List; +import java.util.Map; + +public abstract class AbstractImportModel<E> implements ImportModel<E> { + + private final char separator; + + protected final ModelBuilder<E> modelBuilder; + + public AbstractImportModel(char separator) { + this.separator = separator; + modelBuilder = new ModelBuilder<E>(); + } + + @Override + public final char getSeparator() { + return separator; + } + + @Override + public void pushCsvHeaderNames(List<String> headerNames) { + } + + @Override + public final Iterable<ImportableColumn<E, Object>> getColumnsForImport() { + return (Iterable) modelBuilder.getColumnsForImport(); + } + + public <T> ImportableColumn<E, T> newIgnoredColumn(String headerName) { + return modelBuilder.newIgnoredColumn(headerName); + } + + public ImportableColumn<E, String> newMandatoryColumn(String headerName) { + return modelBuilder.newMandatoryColumn(headerName, headerName); + } + + public ImportableColumn<E, String> newMandatoryColumn(String headerName, String propertyName) { + return modelBuilder.newMandatoryColumn(headerName, propertyName); + } + + public <T> ImportableColumn<E, T> newMandatoryColumn(String headerName, ValueParser<T> valueParser) { + return modelBuilder.newMandatoryColumn(headerName, headerName, valueParser); + } + + public <T> ImportableColumn<E, T> newMandatoryColumn(String headerName, String propertyName, ValueParser<T> valueParser) { + return modelBuilder.newMandatoryColumn(headerName, propertyName, valueParser); + } + + public ImportableColumn<E, String> newMandatoryColumn(String headerName, ValueSetter<E, String> eStringValueSetter) { + return modelBuilder.newMandatoryColumn(headerName, eStringValueSetter); + } + + public <T> ImportableColumn<E, T> newMandatoryColumn(String headerName, ValueParser<T> valueParser, ValueSetter<E, T> etValueSetter) { + return modelBuilder.newMandatoryColumn(headerName, valueParser, etValueSetter); + } + + protected <E extends TopiaEntity> void newForeignKeyColumn(String headerName, String propertyName, Class<E> entityType, String foreignKeyName, Map<String, E> universe) { + newMandatoryColumn(headerName, propertyName, EchobaseCsvUtil.newForeignKeyValue(entityType, foreignKeyName, universe)); + } + + protected <E extends TopiaEntity> void newForeignKeyColumn(String propertyName, Class<E> entityType, String foreignKeyName, Map<String, E> universe) { + newMandatoryColumn(propertyName, propertyName, EchobaseCsvUtil.newForeignKeyValue(entityType, foreignKeyName, universe)); + } +} \ No newline at end of file Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AbstractImportModel.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AssociationValueParser.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AssociationValueParser.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AssociationValueParser.java 2012-03-26 23:04:04 UTC (rev 409) @@ -0,0 +1,37 @@ +/* + * #%L + * EchoBase :: Entities + * + * $Id$ + * $HeadURL$ + * %% + * 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 org.nuiton.util.csv.ValueParser; + +import java.text.ParseException; + +public class AssociationValueParser implements ValueParser<String[]> { + + @Override + public String[] parse(String value) throws ParseException { + String[] ids = value.split("\\|"); + return ids; + } +} \ No newline at end of file Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AssociationValueParser.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AssociationValueParserFormatter.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AssociationValueParserFormatter.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AssociationValueParserFormatter.java 2012-03-26 23:04:04 UTC (rev 409) @@ -0,0 +1,80 @@ +/* + * #%L + * EchoBase :: Entities + * + * $Id$ + * $HeadURL$ + * %% + * 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.Lists; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.StringUtil; +import org.nuiton.util.csv.ValueParserFormatter; + +import java.text.ParseException; +import java.util.Collection; +import java.util.Map; + +public class AssociationValueParserFormatter<E extends TopiaEntity> implements ValueParserFormatter<Collection<E>> { + + protected final Class<E> entityType; + + protected final Map<String, E> universe; + + public AssociationValueParserFormatter( + Class<E> entityType, + Map<String, E> universe) { + this.entityType = entityType; + this.universe = universe; + } + + @Override + public Collection<E> parse(String value) throws ParseException { + Collection<E> result = Lists.newArrayList(); + if (StringUtils.isNotBlank(value)) { + + String[] ids = value.split("\\|"); + for (String id : ids) { + E association = universe.get(id); + association.setTopiaId(id); + result.add(association); + } + } + return result; + } + + @Override + public String format(Collection<E> e) { + + String value; + if (CollectionUtils.isEmpty(e)) { + value = ""; + } else { + Collection<String> ids = Lists.newArrayList(); + for (E e1 : e) { + ids.add(e1.getTopiaId()); + } + value = StringUtil.join(ids, "|", true); + } + return value; + } +} \ No newline at end of file Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/AssociationValueParserFormatter.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CellValueParser.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CellValueParser.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CellValueParser.java 2012-03-26 23:04:04 UTC (rev 409) @@ -0,0 +1,153 @@ +/* + * #%L + * EchoBase :: Entities + * + * $Id$ + * $HeadURL$ + * %% + * 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.CellDAO; +import fr.ifremer.echobase.entities.data.Voyage; +import org.apache.commons.collections.CollectionUtils; +import org.nuiton.topia.TopiaException; +import org.nuiton.util.csv.ImportRuntimeException; +import org.nuiton.util.csv.ValueParser; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.List; +import java.util.Map; + +public class CellValueParser implements ValueParser<Cell> { + + public static final String CELLULE_DATE_FORMAT = "dd/MM/yyyy HH:mm:ss.SSSS"; + + final Voyage voyage; + +// private final Pattern ID_PATTERN = Pattern.compile("(.[^_]+)(_(.+)){0,1}"); + + private final CellDAO cellDAO; + + private final Map<String, Cell> esduCells; + + protected CellValueParser(Voyage voyage, CellDAO cellDAO) { + this.voyage = voyage; + this.cellDAO = cellDAO; + esduCells = Maps.newTreeMap(); + } + + private static final DateFormat cellDateFormatOne = new SimpleDateFormat( + "yyyy-MM-dd HH:mm:ss"); + + private static final DateFormat cellDateFormat = new SimpleDateFormat( + CELLULE_DATE_FORMAT); + + public static String reformatDate(String date) throws ParseException { + Date parse = cellDateFormatOne.parse(date); + date = cellDateFormat.format(parse); + return date; + } + + @Override + public Cell parse(String value) throws ParseException { + +// // must find it +// Matcher matcher = ID_PATTERN.matcher(value); +// if (!matcher.matches()) { +// throw new ImportRuntimeException( +// "Can not match cell id pattern with value " + value); +// } + + 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 { + +//FIXME Remove this when using same date formatter everywhere... + esduCellId = reformatDate(esduCellId); + + Cell result = esduCells.get(esduCellId); + + if (result == null) { + try { + List<Cell> cells = cellDAO.findAllByName(esduCellId); + + 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 + esduCells.put(esduCellId, result); + + } catch (TopiaException e) { + throw new ImportRuntimeException( + "Can not find esdu cell with name " + esduCellId); + } + } + return result; + } +} \ No newline at end of file Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CellValueParser.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CsvFileImportResult.java (from rev 406, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/csv/CsvFileImportResult.java) =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CsvFileImportResult.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CsvFileImportResult.java 2012-03-26 23:04:04 UTC (rev 409) @@ -0,0 +1,99 @@ +/* + * #%L + * EchoBase :: Services + * + * $Id$ + * $HeadURL$ + * %% + * 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 com.google.common.collect.Sets; +import fr.ifremer.echobase.entities.EchoBaseEntityEnum; + +import java.io.Serializable; +import java.util.Map; +import java.util.Set; + +/** + * To keep result of the import of a file. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public class CsvFileImportResult implements Serializable { + + private static final long serialVersionUID = 1L; + + /** Name of the csv file to import. */ + protected final String importFileName; + + /** type of entity to import csv datas. */ + protected final Set<EchoBaseEntityEnum> entityTypes; + + /** Count of created entities. */ + protected final Map<EchoBaseEntityEnum, Integer> numberCreated; + + /** Count of updated entities. */ + protected final Map<EchoBaseEntityEnum, Integer> numberUpdated; + + public CsvFileImportResult(String importFileName) { + this.importFileName = importFileName; + entityTypes = Sets.newHashSet(); + numberCreated = Maps.newEnumMap(EchoBaseEntityEnum.class); + numberUpdated = Maps.newEnumMap(EchoBaseEntityEnum.class); + } + + public Set<EchoBaseEntityEnum> getEntityTypes() { + return Sets.immutableEnumSet(entityTypes); + } + + public int getNumberCreated(EchoBaseEntityEnum entityType) { + return getInteger(numberCreated, entityType); + } + + public int getNumberUpdated(EchoBaseEntityEnum entityType) { + return getInteger(numberUpdated, entityType); + } + + public void incrementsNumberCreated(EchoBaseEntityEnum entityType) { + increments(numberCreated, entityType); + } + + public void incrementsNumberUpdated(EchoBaseEntityEnum entityType) { + increments(numberUpdated, entityType); + } + + protected int getInteger(Map<EchoBaseEntityEnum, Integer> map, + EchoBaseEntityEnum entityType) { + Integer result = map.get(entityType); + return result == null ? 0 : result; + } + + protected void increments(Map<EchoBaseEntityEnum, Integer> map, + EchoBaseEntityEnum entityType) { + Integer result = map.get(entityType); + if (result == null) { + + entityTypes.add(entityType); + result = 0; + } + map.put(entityType, ++result); + } +} Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CsvFileImportResult.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Copied: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CsvImportResult.java (from rev 406, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/CsvImportResult.java) =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CsvImportResult.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CsvImportResult.java 2012-03-26 23:04:04 UTC (rev 409) @@ -0,0 +1,101 @@ +/* + * #%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.csv; + +import fr.ifremer.echobase.entities.EchoBaseEntityEnum; + +import java.io.Serializable; + +/** + * A simple csv result bean just to keep the number of created or + * updated entities. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class CsvImportResult implements Serializable { + + private static final long serialVersionUID = 1L; + + /** type of entity to import csv datas. */ + protected final EchoBaseEntityEnum entityType; + + /** Name of the csv file to import. */ + protected final String importFileName; + + /** Flag to authorize to create entities not found in db. */ + protected final boolean createIfNotFound; + + /** Count of created entities. */ + protected int numberCreated; + + /** Count of updated entities. */ + protected int numberUpdated; + + public static CsvImportResult newResult(EchoBaseEntityEnum entityType, + String importFileName, + boolean createIfNotFound) { + CsvImportResult result = new CsvImportResult(entityType, importFileName, + createIfNotFound); + return result; + } + + protected CsvImportResult(EchoBaseEntityEnum entityType, + String importFileName, + boolean createIfNotFound) { + this.entityType = entityType; + this.importFileName = importFileName; + this.createIfNotFound = createIfNotFound; + } + + public EchoBaseEntityEnum getEntityType() { + return entityType; + } + + + public String getImportFileName() { + return importFileName; + } + + public int getNumberCreated() { + return numberCreated; + } + + public int getNumberUpdated() { + return numberUpdated; + } + + public boolean isCreateIfNotFound() { + return createIfNotFound; + } + + public void incrementsNumberCreated() { + numberCreated++; + } + + public void incrementsNumberUpdated() { + numberUpdated++; + } + +} Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/CsvImportResult.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/EchoBaseExport.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/EchoBaseExport.java 2012-03-26 23:02:10 UTC (rev 408) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/EchoBaseExport.java 2012-03-26 23:04:04 UTC (rev 409) @@ -41,8 +41,8 @@ public class EchoBaseExport<E> extends Export<E> { public static <E> EchoBaseExport<E> newExport(ExportModel<E> model, - Iterable<E> data, - boolean writeOnceHeader) { + Iterable<E> data, + boolean writeOnceHeader) { return new EchoBaseExport<E>(model, data, writeOnceHeader); } Copied: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/EchobaseCsvUtil.java (from rev 406, trunk/echobase-services/src/main/java/fr/ifremer/echobase/services/csv/CsvModelUtil.java) =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/EchobaseCsvUtil.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/EchobaseCsvUtil.java 2012-03-26 23:04:04 UTC (rev 409) @@ -0,0 +1,155 @@ +/* + * #%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.csv; + +import fr.ifremer.echobase.entities.data.Cell; +import fr.ifremer.echobase.entities.data.CellDAO; +import fr.ifremer.echobase.entities.data.Result; +import fr.ifremer.echobase.entities.data.Voyage; +import fr.ifremer.echobase.entities.references.DataMetadata; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.csv.Common; +import org.nuiton.util.csv.ValueFormatter; +import org.nuiton.util.csv.ValueParser; +import org.nuiton.util.csv.ValueParserFormatter; +import org.nuiton.util.csv.ValueSetter; + +import java.sql.Timestamp; +import java.text.ParseException; +import java.util.Collection; +import java.util.Date; +import java.util.Map; + +/** + * Usefull class to build csv import-export models. + * + * @author tchemit <chemit@codelutin.com> + * @since 0.2 + */ +public class EchobaseCsvUtil extends Common { + + public static final ValueParserFormatter<Date> DAY_TIME_SECOND_WITH_TIMESTAMP = + new DateValue("dd/MM/yyyy HH:mm:ss") { + + @Override + public Date parse(String value) throws ParseException { + + Date parse = super.parse(value); + if (parse != null) { + parse = new Timestamp(parse.getTime()); + } + return parse; + } + }; + + public static final ValueParser<Date> IMPORT_DAY = new DateValue("dd/MM/yy"); + + public static final ValueParser<Date> IMPORT_DAY_TIME2 = new DateValue("yyyy-MM-dd HH:mm:ss"); + + public static final String CELLULE_DATE_FORMAT = "dd/MM/yyyy HH:mm:ss.SSSS"; + + public static final ValueParser<Date> IMPORT_DAY_TIME3 = new DateValue(CELLULE_DATE_FORMAT); + + 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 ValueParser<Float> NA_TO_FLOAT_PARSER = new FloatParserFormatter(null, true) { + + @Override + protected Float parseNoneEmptyValue(String value) { + Float result = null; + if (!"NA".equals(value)) { + result = super.parseNoneEmptyValue(value); + } + return result; + } + + }; + + public static final ValueParser<Integer> NA_TO_INTEGER_PARSER = new IntegerParserFormatter(null, true) { + + @Override + protected Integer parseNoneEmptyValue(String value) { + Integer result = null; + if (!"NA".equals(value)) { + result = super.parseNoneEmptyValue(value); + } + return result; + } + + }; + + public static final AssociationValueParser ASSOCIATION_VALUE_PARSER = new AssociationValueParser(); + + public static <E extends TopiaEntity> ForeignKeyValue<E> newForeignKeyValue(Class<E> type, String propertyName, Map<String, E> universe) { + return new ForeignKeyValue<E>(type, propertyName, universe); + } + + public static <E extends TopiaEntity> ForeignKeyValue<E> create(Class<E> type, String propertyName, Map<String, E> universe) { + return new ForeignKeyValue<E>(type, propertyName, universe); + } + + public static <E extends TopiaEntity> ForeignKeyValueForAssociation<E> newForeignKeyValueAssociation(Class<E> type, String propertyName, Map<String, E> universe) { + return new ForeignKeyValueForAssociation<E>(type, propertyName, universe); + } + + public static <E extends TopiaEntity> ValueFormatter<Collection<E>> newAssociationValueFormatter() { + return new AssociationValueParserFormatter<E>(null, null); + } + + protected EchobaseCsvUtil() { + // avoid instanciation on helper class + } + + public static ValueParser<Cell> newCellValueParser(Voyage voyage, CellDAO cellDAO) { + return new CellValueParser(voyage, cellDAO); + } + + + public static interface ResultAble { + void addResult(Result value); + } + + 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) { + return new ResultValueParser(metadata); + } + +} Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/EchobaseCsvUtil.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ForeignKeyValue.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ForeignKeyValue.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ForeignKeyValue.java 2012-03-26 23:04:04 UTC (rev 409) @@ -0,0 +1,77 @@ +/* + * #%L + * EchoBase :: Entities + * + * $Id$ + * $HeadURL$ + * %% + * 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.EchoBaseTechnicalException; +import org.apache.commons.lang3.StringUtils; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.csv.ValueParserFormatter; + +import java.text.ParseException; +import java.util.Map; + +public class ForeignKeyValue<E extends TopiaEntity> implements ValueParserFormatter<E> { + + protected final String propertyName; + + protected final Class<E> entityType; + + protected final Map<String, E> universe; + + public ForeignKeyValue(Class<E> entityType, + String propertyName, + Map<String, E> universe) { + this.entityType = entityType; + this.propertyName = propertyName; + this.universe = universe; + } + + + @Override + public E parse(String value) throws ParseException { + E result = null; + if (StringUtils.isNotBlank(value)) { + + // get entity from universe + result = universe.get(value); + + if (result == null) { + + // can not find entity this is a big problem for us... + throw new EchoBaseTechnicalException( + "Could not find entity of type " + entityType.getSimpleName() + " with '" + propertyName + "' = " + value); + } + } + return result; + } + + @Override + public String format(E e) { + String value = ""; + if (e != null) { + value = e.getTopiaId(); + } + return value; + } +} \ No newline at end of file Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ForeignKeyValue.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ForeignKeyValueForAssociation.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ForeignKeyValueForAssociation.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ForeignKeyValueForAssociation.java 2012-03-26 23:04:04 UTC (rev 409) @@ -0,0 +1,69 @@ +/* + * #%L + * EchoBase :: Entities + * + * $Id$ + * $HeadURL$ + * %% + * 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.EchoBaseTechnicalException; +import org.apache.commons.lang3.StringUtils; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.util.csv.ValueParser; + +import java.text.ParseException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Map; + +public class ForeignKeyValueForAssociation<E extends TopiaEntity> implements ValueParser<Collection<E>> { + + protected final String propertyName; + + protected final Class<E> entityType; + + protected final Map<String, E> universe; + + public ForeignKeyValueForAssociation(Class<E> entityType, + String propertyName, + Map<String, E> universe) { + this.entityType = entityType; + this.propertyName = propertyName; + this.universe = universe; + } + + @Override + public Collection<E> parse(String value) throws ParseException { + E result = null; + if (StringUtils.isNotBlank(value)) { + + // get entity from universe + result = universe.get(value); + + if (result == null) { + + // can not find entity this is a big problem for us... + throw new EchoBaseTechnicalException( + "Could not find entity with '" + propertyName + "' = " + value); + } + } + return Arrays.asList(result); + } +} \ No newline at end of file Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ForeignKeyValueForAssociation.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Added: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ResultValueParser.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ResultValueParser.java (rev 0) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ResultValueParser.java 2012-03-26 23:04:04 UTC (rev 409) @@ -0,0 +1,54 @@ +/* + * #%L + * EchoBase :: Entities + * + * $Id$ + * $HeadURL$ + * %% + * 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.util.csv.ValueParser; + +import java.text.ParseException; + +/** + * TODO + * + * @author tchemit <chemit@codelutin.com> + * @since 0.3 + */ +public class ResultValueParser implements ValueParser<Result> { + + final DataMetadata metadata; + + public ResultValueParser(DataMetadata metadata) { + this.metadata = metadata; + } + + @Override + public Result parse(String value) throws ParseException { + Result result = new ResultImpl(); + result.setDataMetadata(metadata); + result.setResultValue(value); + return result; + } +} Property changes on: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/csv/ResultValueParser.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/CategoryImpl.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/CategoryImpl.java 2012-03-26 23:02:10 UTC (rev 408) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/data/CategoryImpl.java 2012-03-26 23:04:04 UTC (rev 409) @@ -29,8 +29,8 @@ @Override public String getSpeciesLabel() { - return speciesCategory == null ? "" : - speciesCategory.getSpecies().getBaracoudaCode(); + return speciesCategory == null || speciesCategory.getSpecies() == null + ? "" : speciesCategory.getSpecies().getBaracoudaCode(); } @Override Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java 2012-03-26 23:02:10 UTC (rev 408) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/AssociationMeta.java 2012-03-26 23:04:04 UTC (rev 409) @@ -103,7 +103,7 @@ return new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8); } catch (FileNotFoundException e) { - throw new EchoBaseTechnicalException("Could not find file "+file); + throw new EchoBaseTechnicalException("Could not find file " + file); } } @@ -127,7 +127,7 @@ public void setChilds(TopiaEntity entity, Collection<TopiaEntity> childs) { getOperator().addAllChild(name, entity, childs); } - + public boolean isChildEmpty(TopiaEntity entity) { boolean result = getOperator().isChildEmpty(name, entity); return result; Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/MetaFilenameAware.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/MetaFilenameAware.java 2012-03-26 23:02:10 UTC (rev 408) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/MetaFilenameAware.java 2012-03-26 23:04:04 UTC (rev 409) @@ -43,9 +43,9 @@ String getName(); String getFilename(); - + File newFile(File container); - + Writer newWriter(File container); } Modified: trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/TableMeta.java =================================================================== --- trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/TableMeta.java 2012-03-26 23:02:10 UTC (rev 408) +++ trunk/echobase-entities/src/main/java/fr/ifremer/echobase/entities/meta/TableMeta.java 2012-03-26 23:04:04 UTC (rev 409) @@ -102,7 +102,7 @@ return new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8); } catch (FileNotFoundException e) { - throw new EchoBaseTechnicalException("Could not find file "+file); + throw new EchoBaseTechnicalException("Could not find file " + file); } }