r1737 - in trunk: wao-persistence/src/main/java/fr/ifremer/wao wao-services/src/main/java/fr/ifremer/wao/services/service wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer
Author: tchemit Date: 2014-03-25 10:15:32 +0100 (Tue, 25 Mar 2014) New Revision: 1737 Url: http://forge.codelutin.com/projects/wao/repository/revisions/1737 Log: refs-20 #4483 (add SamplingPlan Builder) Added: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/SampleRowsFilter.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java Modified: trunk/wao-persistence/src/main/java/fr/ifremer/wao/SampleRowsFilter.java =================================================================== --- trunk/wao-persistence/src/main/java/fr/ifremer/wao/SampleRowsFilter.java 2014-03-25 09:06:02 UTC (rev 1736) +++ trunk/wao-persistence/src/main/java/fr/ifremer/wao/SampleRowsFilter.java 2014-03-25 09:15:32 UTC (rev 1737) @@ -1,5 +1,26 @@ package fr.ifremer.wao; +/* + * #%L + * Wao :: Persistence + * %% + * 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.entity.ObsProgram; import fr.ifremer.wao.entity.ObservationType; import fr.ifremer.wao.entity.SamplingStrategy; @@ -47,6 +68,8 @@ protected Set<String> orderByArguments; + protected boolean estimatedTides; + public ObsProgram getObsProgram() { return obsProgram; } @@ -199,4 +222,11 @@ this.orderByArguments = orderByArguments; } + public boolean isEstimatedTides() { + return estimatedTides; + } + + public void setEstimatedTides(boolean estimatedTides) { + this.estimatedTides = estimatedTides; + } } Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java 2014-03-25 09:06:02 UTC (rev 1736) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java 2014-03-25 09:15:32 UTC (rev 1737) @@ -1,5 +1,362 @@ package fr.ifremer.wao.services.service; -public class ObsMerSamplingPlan { +/* + * #%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.entity.SampleMonth; +import fr.ifremer.wao.entity.SampleRow; + +import java.io.Serializable; +import java.text.NumberFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +public class ObsMerSamplingPlan implements Iterable<ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart>, Serializable { + + private static final long serialVersionUID = 1L; + + /** + * All facades of the sampling plan. + */ + protected List<ObsMerSamplingPlanFacadePart> facades; + + /** + * Statistics over the plan by month. + */ + protected Map<Date, ObsMerSamplingPlanStatistics> statisticsMap; + + /** + * Total of observation times in days planned. + * FIXME Voir si on doit garder un *D*ouble + */ + protected Double observationTimesInDaysTotalPlanned; + + /** + * Total of observation times in days actual. + * FIXME Voir si on doit garder un *L*ong + */ + protected Long observationTimesInDaysTotalActual; + + /** + * ? + * FIXME Voir si on doit garder un *I*integer + */ + protected Integer highTotalExpected; + + /** + * ? + * FIXME Voir si on doit garder un *I*integer + */ + protected Integer highTotalReal; + + /** + * List of month used by sample rows. + */ + protected List<Date> months; + + public ObsMerSamplingPlan(List<Date> months, + List<ObsMerSamplingPlanFacadePart> facadeParts, + Map<Date, ObsMerSamplingPlanStatistics> statisticsMap, + Integer highTotalExpected, + Integer highTotalReal, + Double observationTimesInDaysTotalPlanned, + Long observationTimesInDaysTotalActual) { + this.months = months; + this.facades = facadeParts; + this.statisticsMap = statisticsMap; + this.observationTimesInDaysTotalPlanned = observationTimesInDaysTotalPlanned; + this.observationTimesInDaysTotalActual = observationTimesInDaysTotalActual; + this.highTotalExpected = highTotalExpected; + this.highTotalReal = highTotalReal; + } + + //FIXME Remove this + public List<SampleRow> getRows() { + List<SampleRow> result = new ArrayList<>(); + for (ObsMerSamplingPlanFacadePart facade : facades) { + for (ObsMerSamplingPlanSectorPart sectors : facade) { + for (ObsMerSamplingPlanSampleRowPart row : sectors) { + result.add(row.getSampleRow()); + } + } + } + return result; + } + + @Override + public Iterator<ObsMerSamplingPlanFacadePart> iterator() { + return facades.iterator(); + } + + public List<Date> getMonths() { + return months; + } + + public Double getObservationTimesInDaysTotalPlanned() { + return observationTimesInDaysTotalPlanned; + } + + public Long getObservationTimesInDaysTotalActual() { + return observationTimesInDaysTotalActual; + } + + public Integer getTotalExpectedForMonth(Date month) { + Integer result = statisticsMap.get(month).getTotalExpected(); + return result; + } + + public Integer getTotalRealForMonth(Date month) { + Integer result = statisticsMap.get(month).getTotalReal(); + return result; + } + + public String getRatioForMonth(Date month) { + String result = statisticsMap.get(month).getRatioForMonth(); + return result; + } + + public Integer getHighTotalExpected() { + return highTotalExpected; + } + + public Integer getHighTotalReal() { + return highTotalReal; + } + + public String getHighTotalRatio() { + String ratio = ""; + if (highTotalExpected > 0) { + double percent = ((double) highTotalReal / highTotalExpected); + ratio = NumberFormat.getPercentInstance().format(percent); + } + return ratio; + } + + /** + * All sectors part for a given facade. + * <p/> + * Created on 3/24/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ + public static class ObsMerSamplingPlanFacadePart implements Iterable<ObsMerSamplingPlanSectorPart>, Serializable { + + private static final long serialVersionUID = 1L; + + protected String facade; + + /** + * All sector parts for this facade. + */ + protected Collection<ObsMerSamplingPlanSectorPart> sectors; + + public ObsMerSamplingPlanFacadePart(String facade, + Collection<ObsMerSamplingPlanSectorPart> sectors) { + this.facade = facade; + this.sectors = sectors; + } + + public String getFacade() { + return facade; + } + + @Override + public Iterator<ObsMerSamplingPlanSectorPart> iterator() { + return sectors.iterator(); + } + + } + + /** + * Contains sample rows of a same sectors. + */ + public static class ObsMerSamplingPlanSectorPart implements Iterable<ObsMerSamplingPlanSampleRowPart>, Serializable { + + private static final long serialVersionUID = 1L; + + protected String sectors; + + protected Collection<ObsMerSamplingPlanSampleRowPart> sampleRows; + + public ObsMerSamplingPlanSectorPart(String sectors, + Collection<ObsMerSamplingPlanSampleRowPart> sampleRows) { + this.sectors = sectors; + this.sampleRows = sampleRows; + } + + public String getSectors() { + return sectors; + } + + @Override + public Iterator<ObsMerSamplingPlanSampleRowPart> iterator() { + return sampleRows.iterator(); + } + } + + protected static final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/yyyy"); + + /** + * Created on 3/24/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ + public static class ObsMerSamplingPlanSampleRowPart implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * Boxed sample row. + */ + protected SampleRow sampleRow; + + /** + * Times of observation days planned. + * <p/> + * FIXME Voir si on doit garder un *D*ouble + */ + protected Double observationTimesInDaysPlanned; + + /** + * Actual times of observation in days. + * <p/> + * FIXME Voir si on doit garder un *D*ouble + */ + protected Long observationTimesInDaysActual; + + + public ObsMerSamplingPlanSampleRowPart(SampleRow sampleRow, + Double observationTimesInDaysPlanned, + Long observationTimesInDaysActual) { + this.sampleRow = sampleRow; + this.observationTimesInDaysPlanned = observationTimesInDaysPlanned; + this.observationTimesInDaysActual = observationTimesInDaysActual; + } + + public SampleRow getSampleRow() { + return sampleRow; + } + + public Integer getNbTidesExpected(Date month) { + Integer result = null; + SampleMonth sampleMonth = sampleRow.getSampleMonth(month); + if (sampleMonth != null) { + result = sampleMonth.getExpectedTidesValue(); + } + return result; + } + + public Integer getNbTidesReal(Date month, boolean estimatedTides) { + Integer result = null; + SampleMonth sampleMonth = sampleRow.getSampleMonth(month); + if (sampleMonth != null) { + // result = getFilter().getEstimatedTides() ? + result = estimatedTides ? + sampleMonth.getEstimatedTidesValue() : + sampleMonth.getRealTidesValue(); + } + return result; + } + + //FIXME Move this in ui ? + public String getTotalPercentage() { + String result; + if (sampleRow.getTotalTidesExpected() > 0) { + double percentage = (double) sampleRow.getTotalTidesReal() / (double) sampleRow.getTotalTidesExpected(); + result = NumberFormat.getPercentInstance().format(percentage); + } else { + result = "- %"; + } + return result; + } + + public Double getObservationTimesInDaysPlanned() { + return observationTimesInDaysPlanned; + } + + public Long getObservationTimesInDaysActual() { + return observationTimesInDaysActual; + } + + public boolean hasNbTidesReal(Date month, boolean estimatedTides) { + Date current = new Date(); + boolean validMonth = month.before(current) || isCurrentMonth(month); + return validMonth && getNbTidesReal(month, estimatedTides) != null; + } + + public boolean isCurrentMonth(Date month) { + String currentStr = dateFormat.format(new Date()); + String monthStr = dateFormat.format(month); + return currentStr.equals(monthStr); + } + } + + public static class ObsMerSamplingPlanStatistics implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * Total of expected tides. + * <p/> + * FIXME Voir si on doit garder un *I*nteger + */ + protected Integer totalExpected; + + /** + * Total of real tides. + * <p/> + * FIXME Voir si on doit garder un *I*nteger + */ + protected Integer totalReal; + + public ObsMerSamplingPlanStatistics(Integer totalExpected, Integer totalReal) { + this.totalExpected = totalExpected; + this.totalReal = totalReal; + } + + public Integer getTotalExpected() { + return totalExpected; + } + + public Integer getTotalReal() { + return totalReal; + } + + //FIXME Move this in ui ? + public String getRatioForMonth() { + String ratio = "-"; + if (totalExpected != null && totalExpected > 0 && + totalReal != null && totalReal > 0) { + double percent = ((double) totalReal / totalExpected); + ratio = NumberFormat.getPercentInstance().format(percent); + } + return ratio; + } + + } } Added: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java (rev 0) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java 2014-03-25 09:15:32 UTC (rev 1737) @@ -0,0 +1,278 @@ +package fr.ifremer.wao.services.service; + +/* + * #%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.SampleRowsFilter; +import fr.ifremer.wao.entity.SampleRow; +import org.apache.commons.lang3.mutable.MutableDouble; +import org.apache.commons.lang3.mutable.MutableInt; +import org.apache.commons.lang3.mutable.MutableLong; +import org.nuiton.util.PeriodDates; + +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +/** + * To build a new {@link ObsMerSamplingPlan} from a {@link SampleRowsFilter} + * and some {@link SampleRow}. + * <p/> + * Created on 3/24/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ +public class ObsMerSamplingPlanBuilder { + + /** + * Incoming filter used. + */ + protected SampleRowsFilter sampleRowsFilter; + + /** + * List of month computed from the filter. + */ + protected List<Date> months; + + /** + * Dictionnary of facades indexed by their facade name. + */ + protected LinkedHashMap<String, FacadeContext> facadeMap; + + /** + * To compute the high total expected. + * + * @see ObsMerSamplingPlan#highTotalExpected + */ + protected MutableInt highTotalExpected; + + /** + * To compute the high total real. + * + * @see ObsMerSamplingPlan#highTotalReal + */ + protected MutableInt highTotalReal; + + /** + * To compute the total of planned observation times in days. + * + * @see ObsMerSamplingPlan#observationTimesInDaysTotalPlanned + */ + protected MutableDouble observationTimesInDaysTotalPlanned; + + /** + * To compute the total of actual observation times in days. + * + * @see ObsMerSamplingPlan#observationTimesInDaysTotalActual + */ + protected MutableLong observationTimesInDaysTotalActual; + + /** + * To compute by month the total of expected tides. + * + * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#totalExpected + */ + protected Map<Date, MutableInt> totalExpectedForMonths; + + /** + * To compute by month the total of real tides. + * + * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#totalReal + */ + protected Map<Date, MutableInt> totalRealForMonths; + + public ObsMerSamplingPlanBuilder(SampleRowsFilter sampleRowsFilter) { + this.sampleRowsFilter = sampleRowsFilter; + this.facadeMap = new LinkedHashMap<>(); + this.highTotalExpected = new MutableInt(); + this.highTotalReal = new MutableInt(); + this.observationTimesInDaysTotalPlanned = new MutableDouble(); + this.observationTimesInDaysTotalActual = new MutableLong(); + + PeriodDates periodDates = new PeriodDates(sampleRowsFilter.getPeriodFrom(), + sampleRowsFilter.getPeriodTo()); + this.months = periodDates.getMonths(); + } + + public ObsMerSamplingPlanBuilder addSampleRow(SampleRow sampleRow, + Double observationTimesInDaysPlanned, + Long observationTimesInDaysActual) { + + String facade = sampleRow.getFacade(); + FacadeContext facadeContext = facadeMap.get(facade); + + if (facadeContext == null) { + + // register a new facade + facadeContext = new FacadeContext(facade); + facadeMap.put(facade, facadeContext); + } + + String sectors = sampleRow.getSectors(); + + // get sector context + ServiceContext sectorPart = facadeContext.getOrAddSectorContext(sectors); + + // add sample row + ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart sampleRowPart = + sectorPart.addSampleRow(sampleRow, + observationTimesInDaysPlanned, + observationTimesInDaysActual); + + // update totals + updateTotals(sampleRowPart); + + // Sum total observation times in days + observationTimesInDaysTotalPlanned.add(observationTimesInDaysPlanned); + observationTimesInDaysTotalActual.add(observationTimesInDaysActual); + + return this; + } + + public ObsMerSamplingPlan toPlan() { + + LinkedList<ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart> facadeParts = new LinkedList<>(); + for (FacadeContext facadeContext : facadeMap.values()) { + ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart facadePart = facadeContext.toBean(); + facadeParts.add(facadePart); + } + + TreeMap<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> statisticsMap = new TreeMap<>(); + for (Date month : months) { + + MutableInt totalExpected = totalExpectedForMonths.get(month); + MutableInt totalReal = totalRealForMonths.get(month); + ObsMerSamplingPlan.ObsMerSamplingPlanStatistics planStatistics = + new ObsMerSamplingPlan.ObsMerSamplingPlanStatistics(totalExpected.toInteger(), + totalReal.toInteger()); + statisticsMap.put(month, planStatistics); + } + + ObsMerSamplingPlan result = new ObsMerSamplingPlan(months, + facadeParts, + statisticsMap, + highTotalExpected.toInteger(), + highTotalReal.toInteger(), + observationTimesInDaysTotalPlanned.toDouble(), + observationTimesInDaysTotalActual.toLong()); + return result; + } + + protected void updateTotals(ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart sampleRowPart) { + for (Date month : months) { + + Integer expected = sampleRowPart.getNbTidesExpected(month); + Integer real = sampleRowPart.getNbTidesReal(month, sampleRowsFilter.isEstimatedTides()); + + if (expected != null) { + + MutableInt totalExpected = totalExpectedForMonths.get(month); + if (totalExpected == null) { + totalExpected = new MutableInt(); + totalExpectedForMonths.put(month, totalExpected); + } + totalExpected.add(expected); + highTotalExpected.add(totalExpected); + } + + if (real != null) { + MutableInt totalReal = totalRealForMonths.get(month); + if (totalReal == null) { + totalReal = new MutableInt(); + totalRealForMonths.put(month, totalReal); + } + totalReal.add(real); + highTotalReal.add(totalReal); + } + } + } + + protected static class FacadeContext { + + protected String facade; + + protected LinkedHashMap<String, ServiceContext> sectorMap; + + protected FacadeContext(String facade) { + this.facade = facade; + this.sectorMap = new LinkedHashMap<>(); + } + + protected ServiceContext getOrAddSectorContext(String sectors) { + ServiceContext sectorPart = sectorMap.get(sectors); + if (sectorPart == null) { + + // register a new sector + sectorPart = new ServiceContext(sectors); + sectorMap.put(sectors, sectorPart); + } + return sectorPart; + } + + protected ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart toBean() { + + LinkedList<ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart> sectorParts = new LinkedList<>(); + for (ServiceContext serviceContext : sectorMap.values()) { + ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart sectorPart = serviceContext.toBean(); + sectorParts.add(sectorPart); + } + ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart result = + new ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart(facade, sectorParts); + return result; + } + } + + protected static class ServiceContext { + + protected String sectors; + + protected LinkedList<ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart> rows; + + protected ServiceContext(String sectors) { + this.sectors = sectors; + rows = new LinkedList<>(); + } + + protected ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart addSampleRow(SampleRow row, + Double observationTimesInDaysPlanned, + Long observationTimesInDaysActual) { + + ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart rowPart = + new ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart(row, + observationTimesInDaysPlanned, + observationTimesInDaysActual); + rows.add(rowPart); + + return rowPart; + } + + protected ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart toBean() { + + ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart result = + new ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart(sectors, rows); + return result; + } + } +} Property changes on: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native Modified: trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java =================================================================== --- trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java 2014-03-25 09:06:02 UTC (rev 1736) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java 2014-03-25 09:15:32 UTC (rev 1737) @@ -1,5 +1,26 @@ package fr.ifremer.wao.services.service; +/* + * #%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 com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; @@ -216,7 +237,7 @@ for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { Boat boat = elligibleBoat.getBoat(); - boolean isNoLongerActive = ! elligibleBoats.contains(boat); + boolean isNoLongerActive = !elligibleBoats.contains(boat); if (isNoLongerActive) { if (authenticatedWaoUser.isAdmin()) { elligibleBoat.setGlobalActive(false); @@ -280,7 +301,7 @@ List<SampleRow> existingSampleRowsForTheSameCode = dao.forCodeEquals(sampleRow.getCode()).findAll(); if (existingSampleRowsForTheSameCode.size() > 1) { throw new SampleRowCodeMustBeUniqueException(); - } else if (existingSampleRowsForTheSameCode.size() == 1 && ! Iterables.getOnlyElement(existingSampleRowsForTheSameCode).equals(sampleRow)) { + } else if (existingSampleRowsForTheSameCode.size() == 1 && !Iterables.getOnlyElement(existingSampleRowsForTheSameCode).equals(sampleRow)) { throw new SampleRowCodeMustBeUniqueException(); } @@ -290,7 +311,7 @@ SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); - if ( ! updateSampleRowCommand.isCreation()) { + if (!updateSampleRowCommand.isCreation()) { SampleRowLog sampleRowLog = updateSampleRowCommand.getSampleRowLog(); getSampleRowLogDao().create(sampleRowLog); } @@ -337,7 +358,7 @@ } - public List<SampleRow> getSamplingPlan(SampleRowsFilter sampleRowsFilter) { + public List<SampleRow> getSamplingPlanRows(SampleRowsFilter sampleRowsFilter) { SampleRowTopiaDao dao = getSampleRowDao(); @@ -345,6 +366,26 @@ } + public ObsMerSamplingPlan getSamplingPlan(SampleRowsFilter sampleRowsFilter) { + + SampleRowTopiaDao dao = getSampleRowDao(); + + List<SampleRow> sampleRows = dao.findAll(sampleRowsFilter); + ObsMerSamplingPlanBuilder builder = new ObsMerSamplingPlanBuilder(sampleRowsFilter); + for (SampleRow sampleRow : sampleRows) { + //TODO Compute see ServiceSamplingImpl#executeGetObservationTimesInDays + Double observationTimesInDaysPlanned = 0d; + Long observationTimesInDaysActual = 0l; + builder.addSampleRow(sampleRow, + observationTimesInDaysPlanned, + observationTimesInDaysActual); + } + ObsMerSamplingPlan result = builder.toPlan(); + + return result; + + } + public SampleRowsFilter newSampleRowsFilter(AuthenticatedWaoUser authenticatedWaoUser) { SampleRowsFilter newFilter = new SampleRowsFilter(); @@ -484,7 +525,7 @@ ImportModel<SampleRow> samplingPlanImportModel = new ObsMerObsVenteSamplingPlanImportExportModel(obsProgram, - activeCompanies, fishingZones, terrestrialDistricts, referentialService); + activeCompanies, fishingZones, terrestrialDistricts, referentialService); return samplingPlanImportModel; Modified: trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java =================================================================== --- trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java 2014-03-25 09:06:02 UTC (rev 1736) +++ trunk/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java 2014-03-25 09:15:32 UTC (rev 1737) @@ -1,7 +1,29 @@ package fr.ifremer.wao.web.action.obsmer; +/* + * #%L + * Wao :: Web + * %% + * 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.SampleRowsFilter; import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.services.service.ObsMerSamplingPlan; import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; import fr.ifremer.wao.web.WaoJspActionSupport; @@ -11,7 +33,7 @@ protected ObsMerSamplingPlanService service; - protected List<SampleRow> samplingPlan; + protected ObsMerSamplingPlan samplingPlan; public void setService(ObsMerSamplingPlanService service) { this.service = service; @@ -29,7 +51,7 @@ } public List<SampleRow> getSamplingPlan() { - return samplingPlan; + return samplingPlan.getRows(); } public String getSampleRowToHighlightId() {
participants (1)
-
tchemit@users.forge.codelutin.com