This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository wao. See http://git.codelutin.com/wao.git commit b44b984df329b624cecb6bfac3a789ea374e584b Author: Brendan Le Ny <bleny@codelutin.com> Date: Mon Mar 2 10:47:24 2015 +0100 On contrôle la cohérence des dates de début et de fin de période à l'import du plan (termine #6731) --- .../service/csv/SamplingPlanImportExportModel.java | 10 +++-- .../csv/operations/MonthYearParserFormatter.java | 52 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/SamplingPlanImportExportModel.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/SamplingPlanImportExportModel.java index d8af8f8..d63af06 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/SamplingPlanImportExportModel.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/SamplingPlanImportExportModel.java @@ -47,6 +47,7 @@ import fr.ifremer.wao.services.service.csv.operations.DistrictNamesFormatter; import fr.ifremer.wao.services.service.csv.operations.DistrictsParserFormatter; import fr.ifremer.wao.services.service.csv.operations.FishingZonesParserFormatter; import fr.ifremer.wao.services.service.csv.operations.I18nAbleParserFormatter; +import fr.ifremer.wao.services.service.csv.operations.MonthYearParserFormatter; import fr.ifremer.wao.services.service.csv.operations.OrganisationParserFormatter; import fr.ifremer.wao.services.service.csv.operations.SampleRowCodeParserFormatter; import fr.ifremer.wao.services.service.csv.operations.SpeciesParserFormatter; @@ -115,8 +116,6 @@ public class SamplingPlanImportExportModel implements ImportExportModel<SampleRo protected static final SimpleDateFormat MONTH_YEAR_FORMAT = new SimpleDateFormat("MM/yyyy"); - protected static final ValueParserFormatter<Date> MONTH_YEAR_PARSER_FORMATTER = new Common.DateValue("MM/yyyy"); - protected final Locale locale; protected ObsProgram obsProgram; @@ -217,8 +216,11 @@ public class SamplingPlanImportExportModel implements ImportExportModel<SampleRo modelBuilder.newColumnForImportExport("PECHE_AUTRE", SampleRow.PROPERTY_FISHING_ZONES_INFOS); modelBuilder.newColumnForImportExport("PROGRAMME_CODE", SampleRow.PROPERTY_PROGRAM_NAME); - modelBuilder.newColumnForImportExport("PROGRAMME_DEBUT", SampleRow.PROPERTY_PERIOD_BEGIN, MONTH_YEAR_PARSER_FORMATTER); - modelBuilder.newColumnForImportExport("PROGRAMME_FIN", SampleRow.PROPERTY_PERIOD_END, MONTH_YEAR_PARSER_FORMATTER); + + ValueParserFormatter<Date> monthYearParserFormatter = new MonthYearParserFormatter(locale); + modelBuilder.newColumnForImportExport("PROGRAMME_DEBUT", SampleRow.PROPERTY_PERIOD_BEGIN, monthYearParserFormatter); + modelBuilder.newColumnForImportExport("PROGRAMME_FIN", SampleRow.PROPERTY_PERIOD_END, monthYearParserFormatter); + modelBuilder.newColumnForImportExport("PLAN_COMMENT", SampleRow.PROPERTY_COMMENT); for (Date month : periodDates.getMonths()) { diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/MonthYearParserFormatter.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/MonthYearParserFormatter.java new file mode 100644 index 0000000..7ba57de --- /dev/null +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/operations/MonthYearParserFormatter.java @@ -0,0 +1,52 @@ +package fr.ifremer.wao.services.service.csv.operations; + +/* + * #%L + * Wao :: Services + * %% + * Copyright (C) 2009 - 2014 Ifremer + * %% + * 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 fr.ifremer.wao.WaoUtils; +import org.nuiton.csv.Common; +import org.nuiton.i18n.I18n; + +import java.text.ParseException; +import java.util.Date; +import java.util.Locale; + +/** + * On vérifie que ce n'est pas une date absurde (l'an 14...) + */ +public class MonthYearParserFormatter extends Common.DateValue { + + protected Locale locale; + + public MonthYearParserFormatter(Locale locale) { + super("MM/yyyy"); + this.locale = locale; + } + + @Override + public Date parse(String value) throws ParseException { + Date monthYear = super.parse(value); + if (monthYear != null && ! WaoUtils.isAfterWaoCreation(monthYear)) { + throw new IllegalArgumentException(I18n.l(locale, "wao.import.failure.dateBeforeWaoCreation", value)); + } + return monthYear; + } +} -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.