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 2f6ddd2bf51920abe7a5242ecdf582b45d2f75bd Author: Brendan Le Ny <bleny@codelutin.com> Date: Tue Jan 27 15:58:05 2015 +0100 Export du réalisé depuis le plan scléro (fixes #6543) --- .../wao/services/service/SamplingPlanService.java | 16 +++ .../SclerochronologySamplingPlanService.java | 44 ++++++++ .../SclerochronologySamplingPlanExportModel.java | 116 +++++++++++++++++++++ .../ExportSamplingPlanWithStatisticsAction.java | 9 +- .../WEB-INF/content/obsmer/sampling-plan.jsp | 2 +- .../content/sclerochronology/sampling-plan.jsp | 6 ++ 6 files changed, 187 insertions(+), 6 deletions(-) diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java index 8dc23e5..978fc9a 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java @@ -831,4 +831,20 @@ public class SamplingPlanService extends WaoServiceSupport { return contacts; } + + public InputStream exportSamplingPlanWithStatistics(AuthenticatedWaoUser authenticatedWaoUser, SampleRowsFilter filter) { + + InputStream csv; + if (filter.getObsProgram().isObsMer()) { + ObsMerSamplingPlanService obsMerSamplingPlanService = newService(ObsMerSamplingPlanService.class); + csv = obsMerSamplingPlanService.exportSamplingPlanWithStatistics(authenticatedWaoUser, filter); + } else if (filter.getObsProgram().isSclerochronology()) { + SclerochronologySamplingPlanService sclerochronologySamplingPlanService = newService(SclerochronologySamplingPlanService.class); + csv = sclerochronologySamplingPlanService.exportSamplingPlanWithStatistics(authenticatedWaoUser, filter); + } else { + throw new UnsupportedOperationException(filter.getObsProgram() + " is not supported"); + } + return csv; + + } } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanService.java index 22666bb..145a1d6 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SclerochronologySamplingPlanService.java @@ -21,16 +21,24 @@ package fr.ifremer.wao.services.service; * #L% */ +import com.google.common.base.Charsets; import com.google.common.base.Optional; import com.google.common.cache.Cache; import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.WaoTechnicalException; import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.entity.ContactTopiaDao; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.SampleRowTopiaDao; import fr.ifremer.wao.services.AuthenticatedWaoUser; +import fr.ifremer.wao.services.service.csv.SclerochronologySamplingPlanExportModel; +import org.apache.commons.io.IOUtils; +import org.nuiton.csv.Export; +import org.nuiton.csv.ExportModel; +import java.io.InputStream; import java.util.Collection; +import java.util.LinkedHashSet; import java.util.List; public class SclerochronologySamplingPlanService extends SamplingPlanService { @@ -90,4 +98,40 @@ public class SclerochronologySamplingPlanService extends SamplingPlanService { } + public InputStream exportSamplingPlanWithStatistics(AuthenticatedWaoUser authenticatedWaoUser, SampleRowsFilter filter) { + + SclerochronologySamplingPlan samplingPlan = getSamplingPlan(authenticatedWaoUser, filter); + + Collection<SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart> sampleRows = new LinkedHashSet<>(); + for (SamplingPlan.SamplingPlanFacadePart facade : samplingPlan) { + for (SamplingPlan.SamplingPlanSectorPart<SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart> sector : facade) { + for (SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart SclerochronologySampleRowPart : sector) { + sampleRows.add(SclerochronologySampleRowPart); + } + } + } + + ExportModel<SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart> exportModel = + new SclerochronologySamplingPlanExportModel( + getLocale(), + filter.getPeriodFrom(), + filter.getPeriodTo()); + + Export<SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart> export = + Export.newExport(exportModel, sampleRows); + + try { + + String csvContent = export.toString(Charsets.UTF_8); + + InputStream csvInputStream = IOUtils.toInputStream(csvContent, Charsets.UTF_8); + + return csvInputStream; + + } catch (Exception e) { + throw new WaoTechnicalException(e); + } + + } + } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/SclerochronologySamplingPlanExportModel.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/SclerochronologySamplingPlanExportModel.java new file mode 100644 index 0000000..dda6fe0 --- /dev/null +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/SclerochronologySamplingPlanExportModel.java @@ -0,0 +1,116 @@ +package fr.ifremer.wao.services.service.csv; + +/* + * #%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 fr.ifremer.wao.services.service.SclerochronologySamplingPlan; +import org.nuiton.csv.Common; +import org.nuiton.csv.ValueGetter; +import org.nuiton.csv.ext.AbstractExportModel; +import org.nuiton.util.PeriodDates; + +import java.util.Collection; +import java.util.Date; +import java.util.Locale; + +public class SclerochronologySamplingPlanExportModel extends AbstractExportModel<SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart> { + + public SclerochronologySamplingPlanExportModel(Locale locale, Date periodFrom, Date periodTo) { + + super(';'); + + Common.DateValue monthYearFormatter = + new Common.DateValue(WaoUtils.getMonthPattern(locale)); + + modelBuilder.newColumnForExport("PLAN_CODE", "code"); + modelBuilder.newColumnForExport("ORGANISATION_NOM", "organisationFullName"); + modelBuilder.newColumnForExport("PROGRAMME_CODE", "programName"); + modelBuilder.newColumnForExport("PROGRAMME_DEBUT", "periodBegin", monthYearFormatter); + modelBuilder.newColumnForExport("PROGRAMME_DEBUT", "periodEnd", monthYearFormatter); + modelBuilder.newColumnForExport("PECHE_FACADE", "facade"); + modelBuilder.newColumnForExport("PECHE_ZONE", "sectors"); + modelBuilder.newColumnForExport("ZONES_PECHE", "fishingZones"); + modelBuilder.newColumnForExport("ZONES_PECHE_INFOS", "fishingZonesInfos"); + modelBuilder.newColumnForExport("ZONES_PECHE_INFOS", "fishingZonesInfos"); + modelBuilder.newColumnForExport("ESPECE_CIBLE", "species"); + modelBuilder.newColumnForExport("CONTEXTE", "samplingContext"); + modelBuilder.newColumnForExport("CONTEXTE_COMPLEMENT", "samplingContextInfo"); + modelBuilder.newColumnForExport("MESURES", "individualMeasurementStrategy"); + + Collection<Date> months = new PeriodDates(periodFrom, periodTo).getMonths(); + + for (Date month : months) { + String headerName = monthYearFormatter.format(month); + modelBuilder.newColumnForExport(headerName + "_EFFORT_INDIVIDUS", new ExpectedIndividualsValueGetter(month), Common.INTEGER); + modelBuilder.newColumnForExport(headerName + "_ESTIME_INDIVIDUS", new EstimatedIndividualsValueGetter(month), Common.INTEGER); + modelBuilder.newColumnForExport(headerName + "_REALISE_INDIVIDUS", new RealIndividualsValueGetter(month), Common.INTEGER); + } + + modelBuilder.newColumnForExport("TOTAL_EFFORT", "totalIndividuals.expected", Common.INTEGER); + modelBuilder.newColumnForExport("TOTAL_ESTIME", "totalIndividuals.estimated", Common.INTEGER); + modelBuilder.newColumnForExport("TOTAL_REALISE", "totalIndividuals.real", Common.INTEGER); + + } + + protected static class ExpectedIndividualsValueGetter implements ValueGetter<SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart, Integer> { + + protected Date month; + + public ExpectedIndividualsValueGetter(Date month) { + this.month = month; + } + + @Override + public Integer get(SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart sampleRowPart) { + return sampleRowPart.getEffortInIndividualsPerMonths().get(month).getExpected(); + } + } + + protected static class EstimatedIndividualsValueGetter implements ValueGetter<SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart, Integer> { + + protected Date month; + + public EstimatedIndividualsValueGetter(Date month) { + this.month = month; + } + + @Override + public Integer get(SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart sampleRowPart) { + return sampleRowPart.getEffortInIndividualsPerMonths().get(month).getEstimated(); + } + } + + protected static class RealIndividualsValueGetter implements ValueGetter<SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart, Integer> { + + protected Date month; + + public RealIndividualsValueGetter(Date month) { + this.month = month; + } + + @Override + public Integer get(SclerochronologySamplingPlan.SclerochronologySamplingPlanSampleRowPart sampleRowPart) { + return sampleRowPart.getEffortInIndividualsPerMonths().get(month).getReal(); + } + } + +} diff --git a/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportSamplingPlanWithStatisticsAction.java b/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportSamplingPlanWithStatisticsAction.java similarity index 85% rename from wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportSamplingPlanWithStatisticsAction.java rename to wao-web/src/main/java/fr/ifremer/wao/web/action/ExportSamplingPlanWithStatisticsAction.java index d6e5422..8efa03a 100644 --- a/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportSamplingPlanWithStatisticsAction.java +++ b/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportSamplingPlanWithStatisticsAction.java @@ -1,4 +1,4 @@ -package fr.ifremer.wao.web.action.obsmer; +package fr.ifremer.wao.web.action; /* * #%L @@ -23,8 +23,7 @@ package fr.ifremer.wao.web.action.obsmer; import com.opensymphony.xwork2.Preparable; import fr.ifremer.wao.SampleRowsFilter; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.web.action.AbstractDownloadCsvAction; +import fr.ifremer.wao.services.service.SamplingPlanService; import java.io.InputStream; import java.util.Date; @@ -33,11 +32,11 @@ public class ExportSamplingPlanWithStatisticsAction extends AbstractDownloadCsvA private static final long serialVersionUID = 1L; - protected transient ObsMerSamplingPlanService service; + protected transient SamplingPlanService service; protected SampleRowsFilter filter; - public void setService(ObsMerSamplingPlanService service) { + public void setService(SamplingPlanService service) { this.service = service; } diff --git a/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp b/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp index bc7bc74..f846885 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp @@ -175,7 +175,7 @@ </s:if> <s:if test="authenticatedWaoUser.authorizedToExportSamplingPlanWithStatistics"> - <s:submit namespace="/obsmer" action="export-sampling-plan-with-statistics" type="button" cssClass="btn"> + <s:submit action="export-sampling-plan-with-statistics" type="button" cssClass="btn"> <i class="icon-download"></i> <s:text name="wao.ui.action.exportSamplingPlanCsvWithStatistics" /> </s:submit> </s:if> diff --git a/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp b/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp index 72da63c..ea2e8a1 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/sclerochronology/sampling-plan.jsp @@ -155,6 +155,12 @@ </s:submit> </s:if> + <s:if test="authenticatedWaoUser.authorizedToExportSamplingPlanWithStatistics"> + <s:submit action="export-sampling-plan-with-statistics" type="button" cssClass="btn"> + <i class="icon-download"></i> <s:text name="wao.ui.action.exportSamplingPlanCsvWithStatistics" /> + </s:submit> + </s:if> + </div> </s:form> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.