Author: tchemit Date: 2014-03-27 13:02:46 +0100 (Thu, 27 Mar 2014) New Revision: 1764 Url: http://forge.codelutin.com/projects/wao/repository/revisions/1764 Log: refs #4483 (make SamplePlan fully serializable + use it in jsp) 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/ObsMerSamplingPlanBuilder.java trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp 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-27 10:36:13 UTC (rev 1763) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java 2014-03-27 12:02:46 UTC (rev 1764) @@ -22,16 +22,18 @@ */ import fr.ifremer.wao.WaoUtils; +import fr.ifremer.wao.entity.DCF5Code; import fr.ifremer.wao.entity.FishingZone; import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.entity.SampleRows; +import fr.ifremer.wao.entity.TerrestrialLocation; +import org.apache.commons.collections4.CollectionUtils; import java.io.Serializable; import java.text.NumberFormat; -import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -45,7 +47,7 @@ protected Collection<ObsMerSamplingPlanFacadePart> facades; /** - * Statistics over the plan by month. + * Statistics of total tides over the plan by month. */ protected Map<Date, ObsMerSamplingPlanStatistics> statisticsMap; @@ -69,21 +71,18 @@ /** * ? - * FIXME Voir si on doit garder un *I*integer */ - protected Integer highTotalExpected; + protected int highTotalExpected; /** * ? - * FIXME Voir si on doit garder un *I*integer */ - protected Integer highTotalReal; + protected int highTotalReal; /** * ? - * FIXME Voir si on doit garder un *I*integer */ - protected Integer highTotalEstimated; + protected int highTotalEstimated; /** * List of month used by sample rows. @@ -95,9 +94,9 @@ public ObsMerSamplingPlan(List<Date> months, Collection<ObsMerSamplingPlanFacadePart> facadeParts, Map<Date, ObsMerSamplingPlanStatistics> statisticsMap, - Integer highTotalExpected, - Integer highTotalReal, - Integer highTotalEstimated, + int highTotalExpected, + int highTotalReal, + int highTotalEstimated, Double observationTimesInDaysTotalExpected, Long observationTimesInDaysTotalReal, Long observationTimesInDaysTotalEstimated, @@ -114,19 +113,6 @@ this.filterValues = filterValues; } - //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(); @@ -149,17 +135,17 @@ } public Integer getTotalExpectedForMonth(Date month) { - Integer result = statisticsMap.get(month).getTotalExpected(); + Integer result = statisticsMap.get(month).getNbTidesExpected(); return result; } public Integer getTotalRealForMonth(Date month) { - Integer result = statisticsMap.get(month).getTotalReal(); + Integer result = statisticsMap.get(month).getNbTidesReal(); return result; } public Integer getTotalEstimatedForMonth(Date month) { - Integer result = statisticsMap.get(month).getTotalEstimated(); + Integer result = statisticsMap.get(month).getNbTidesEstimated(); return result; } @@ -270,9 +256,9 @@ private static final long serialVersionUID = 1L; /** - * Boxed sample row. + * Nb tides by month. */ - protected SampleRow sampleRow; + protected Map<Date, ObsMerSamplingPlanStatistics> nbTidesPerMonth; /** * Total of expected tides. @@ -310,27 +296,221 @@ */ protected Long observationTimesInDaysEstimated; + protected String fishingZones; - public ObsMerSamplingPlanSampleRowPart(SampleRow sampleRow, - int totalTidesExpected, - int totalTidesReal, - int totalTidesEstimated, + protected int nbObservants; + + protected double averageTideTime; + + protected String code; + + protected String fishingZonesInfos; + + protected String comment; + + protected String programName; + + protected Date periodBegin; + + protected Date periodEnd; + + protected String terrestrialLocationInfos; + + protected Date expectedDate; + + protected String groupName; + + protected Double appliedCoverageRate; + + protected int averageObservationsCount; + + protected String professionMeshSize; + + protected String professionSize; + + protected String professionOther; + + protected String professionLibelle; + + protected String professionSpecies; + + protected String companyName; + + protected String samplingStrategy; + + protected String professionDescriptionWithoutDCF5; + + protected Map<String, String> dcf5CodesAndDescriptions; + + protected Map<String, String> terrestrialLocationNamesAndDescriptions; + + protected String sampleRowId; + + public ObsMerSamplingPlanSampleRowPart(Map<Date, ObsMerSamplingPlanStatistics> nbTidesPerMonth, + SampleRow sampleRow, Double observationTimesInDaysExpected, Long observationTimesInDaysReal, Long observationTimesInDaysEstimated) { - this.sampleRow = sampleRow; - this.totalTidesExpected = totalTidesExpected; - this.totalTidesReal = totalTidesReal; - this.totalTidesEstimated = totalTidesEstimated; this.observationTimesInDaysExpected = observationTimesInDaysExpected; this.observationTimesInDaysReal = observationTimesInDaysReal; this.observationTimesInDaysEstimated = observationTimesInDaysEstimated; + + this.nbTidesPerMonth = nbTidesPerMonth; + // compute total tides + for (ObsMerSamplingPlanStatistics obsMerSamplingPlanStatistics : nbTidesPerMonth.values()) { + Integer totalExpected = obsMerSamplingPlanStatistics.getNbTidesExpected(); + if (totalExpected != null) { + totalTidesExpected += totalExpected; + } + Integer totalEstimated = obsMerSamplingPlanStatistics.getNbTidesEstimated(); + if (totalEstimated != null) { + totalTidesEstimated += totalEstimated; + } + Integer totalReal = obsMerSamplingPlanStatistics.getNbTidesReal(); + if (totalReal != null) { + totalTidesReal += totalReal; + } + } + + fishingZones = ""; + for (FishingZone zone : sampleRow.getFishingZone()) { + fishingZones += zone.getDistrictCode() + ", "; + } + fishingZones = fishingZones.substring(0, fishingZones.length() - 2); + nbObservants = sampleRow.getNbObservants(); + averageTideTime = sampleRow.getAverageTideTime(); + fishingZonesInfos = sampleRow.getFishingZonesInfos(); + comment = sampleRow.getComment(); + programName = sampleRow.getProgramName(); + periodBegin = sampleRow.getPeriodBegin(); + periodEnd = sampleRow.getPeriodEnd(); + terrestrialLocationInfos = sampleRow.getTerrestrialLocationInfos(); + expectedDate = sampleRow.getExpectedDate(); + groupName = sampleRow.getGroupName(); + appliedCoverageRate = sampleRow.getAppliedCoverageRate(); + averageObservationsCount = sampleRow.getAverageObservationsCount(); + companyName = sampleRow.getCompany().getName(); + code = sampleRow.getCode(); + professionMeshSize = sampleRow.getProfession().getMeshSize(); + professionSize = sampleRow.getProfession().getSize(); + professionOther = sampleRow.getProfession().getOther(); + professionLibelle = sampleRow.getProfession().getLibelle(); + professionSpecies = sampleRow.getProfession().getSpecies(); + dcf5CodesAndDescriptions = new LinkedHashMap<>(); + for (DCF5Code dcf5Code : sampleRow.getdCF5Code()) { + String key = dcf5Code.getCode(); + String description = dcf5Code.getFishingGearCode() + " - " + dcf5Code.getFishingGearDCF().getI18nKey(); + if (dcf5Code.getTargetSpeciesCode() != null) { + description += " ; " + dcf5Code.getTargetSpeciesCode() + " - " + dcf5Code.getTargetSpeciesDCF().getI18nKey(); + } + dcf5CodesAndDescriptions.put(key, description); + } + terrestrialLocationNamesAndDescriptions = new LinkedHashMap<>(); + + if (CollectionUtils.isNotEmpty(sampleRow.getTerrestrialLocations())) { + for (TerrestrialLocation terrestrialLocation : sampleRow.getTerrestrialLocations()) { + String key = terrestrialLocation.getDistrictName(); + String description = terrestrialLocation.getDescription(); + dcf5CodesAndDescriptions.put(key, description); + } + } + professionDescriptionWithoutDCF5 = sampleRow.getProfessionDescriptionWithoutDCF5(); + samplingStrategy = sampleRow.getSamplingStrategy().getI18nKey(); + sampleRowId = sampleRow.getTopiaId(); } - public SampleRow getSampleRow() { - return sampleRow; + public String getSamplingStrategy() { + return samplingStrategy; } + public String getSampleRowId() { + return sampleRowId; + } + + public int getNbObservants() { + return nbObservants; + } + + public double getAverageTideTime() { + return averageTideTime; + } + + public String getCode() { + return code; + } + + public String getFishingZonesInfos() { + return fishingZonesInfos; + } + + public String getTerrestrialLocationInfos() { + return terrestrialLocationInfos; + } + + public String getProfessionSize() { + return professionSize; + } + + public Map<String, String> getDcf5CodesAndDescriptions() { + return dcf5CodesAndDescriptions; + } + + public Map<String, String> getTerrestrialLocationNamesAndDescriptions() { + return terrestrialLocationNamesAndDescriptions; + } + + public String getComment() { + return comment; + } + + public String getProgramName() { + return programName; + } + + public Date getPeriodBegin() { + return periodBegin; + } + + public Date getPeriodEnd() { + return periodEnd; + } + + public Date getExpectedDate() { + return expectedDate; + } + + public String getGroupName() { + return groupName; + } + + public Double getAppliedCoverageRate() { + return appliedCoverageRate; + } + + public int getAverageObservationsCount() { + return averageObservationsCount; + } + + public String getProfessionMeshSize() { + return professionMeshSize; + } + + public String getProfessionOther() { + return professionOther; + } + + public String getProfessionLibelle() { + return professionLibelle; + } + + public String getProfessionSpecies() { + return professionSpecies; + } + + public String getCompanyName() { + return companyName; + } + public int getTotalTidesExpected() { return totalTidesExpected; } @@ -343,25 +523,28 @@ return totalTidesEstimated; } + public String getProfessionDescriptionWithoutDCF5() { + return professionDescriptionWithoutDCF5; + } + public Integer getNbTidesExpected(Date month) { - Integer result = SampleRows.getExpectedTidesValue(sampleRow, month); + Integer result = nbTidesPerMonth.get(month).getNbTidesExpected(); return result; } public Integer getNbTidesReal(Date month) { - Integer result = SampleRows.getRealTidesValue(sampleRow, month); + Integer result = nbTidesPerMonth.get(month).getNbTidesReal(); return result; } public Integer getNbTidesEstimated(Date month) { - Integer result = SampleRows.getEstimatedTidesValue(sampleRow, month); + Integer result = nbTidesPerMonth.get(month).getNbTidesEstimated(); return result; } - //FIXME Move this in ui ? public String getTotalPercentage() { String result; - if (sampleRow.getTotalTidesExpected() > 0) { + if (totalTidesExpected > 0) { double percentage = (double) totalTidesReal / (double) totalTidesExpected; result = NumberFormat.getPercentInstance().format(percentage); } else { @@ -371,11 +554,7 @@ } public String getFishingZones() { - String result = ""; - for (FishingZone zone : sampleRow.getFishingZone()) { - result += zone.getDistrictCode() + ", "; - } - return result.substring(0, result.length() - 2); + return fishingZones; } public Double getObservationTimesInDaysExpected() { @@ -408,52 +587,46 @@ private static final long serialVersionUID = 1L; /** - * Total of expected tides. - * <p/> - * FIXME Voir si on doit garder un *I*nteger + * Number of expected tides. */ - protected Integer totalExpected; + protected Integer nbTidesExpected; /** - * Total of real tides. - * <p/> - * FIXME Voir si on doit garder un *I*nteger + * Number of real tides. */ - protected Integer totalReal; + protected Integer nbTidesReal; /** - * Total of estimated tides. - * <p/> - * FIXME Voir si on doit garder un *I*nteger + * Number of estimated tides. */ - protected Integer totalEstimated; + protected Integer nbTidesEstimated; - public ObsMerSamplingPlanStatistics(Integer totalExpected, - Integer totalReal, - Integer totalEstimated) { - this.totalExpected = totalExpected; - this.totalReal = totalReal; - this.totalEstimated = totalEstimated; + public ObsMerSamplingPlanStatistics(Integer nbTidesExpected, + Integer nbTidesReal, + Integer nbTidesEstimated) { + this.nbTidesExpected = nbTidesExpected; + this.nbTidesReal = nbTidesReal; + this.nbTidesEstimated = nbTidesEstimated; } - public Integer getTotalExpected() { - return totalExpected; + public Integer getNbTidesExpected() { + return nbTidesExpected; } - public Integer getTotalReal() { - return totalReal; + public Integer getNbTidesReal() { + return nbTidesReal; } - public Integer getTotalEstimated() { - return totalEstimated; + public Integer getNbTidesEstimated() { + return nbTidesEstimated; } //FIXME Move this in ui ? public String getRatioForMonth() { String ratio = "-"; - if (totalExpected != null && totalExpected > 0 && - totalReal != null && totalReal > 0) { - double percent = ((double) totalReal / totalExpected); + if (nbTidesExpected != null && nbTidesExpected > 0 && + nbTidesReal != null && nbTidesReal > 0) { + double percent = ((double) nbTidesReal / nbTidesExpected); ratio = NumberFormat.getPercentInstance().format(percent); } return ratio; Modified: 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 2014-03-27 10:36:13 UTC (rev 1763) +++ trunk/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java 2014-03-27 12:02:46 UTC (rev 1764) @@ -74,21 +74,21 @@ * * @see ObsMerSamplingPlan#highTotalExpected */ - protected MutableInt highTotalExpected; + protected int highTotalExpected; /** * To compute the high total real. * * @see ObsMerSamplingPlan#highTotalReal */ - protected MutableInt highTotalReal; + protected int highTotalReal; /** * To compute the high total estimated. * * @see ObsMerSamplingPlan#highTotalEstimated */ - protected MutableInt highTotalEstimated; + protected int highTotalEstimated; /** * To compute the total of expected observation times in days. @@ -114,21 +114,21 @@ /** * To compute by month the total of expected tides. * - * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#totalExpected + * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#nbTidesExpected */ protected Map<Date, MutableInt> totalExpectedForMonths; /** * To compute by month the total of expected tides. * - * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#totalEstimated + * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#nbTidesEstimated */ protected Map<Date, MutableInt> totalEstimatedForMonths; /** * To compute by month the total of real tides. * - * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#totalReal + * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#nbTidesReal */ protected Map<Date, MutableInt> totalRealForMonths; @@ -136,9 +136,6 @@ this.sampleRowsFilter = sampleRowsFilter; this.sampleRowsFilterValues = new SampleRowsFilterValues(); this.facadeMap = new TreeMap<>(); - this.highTotalExpected = new MutableInt(); - this.highTotalReal = new MutableInt(); - this.highTotalEstimated = new MutableInt(); this.observationTimesInDaysTotalExpected = new MutableDouble(); this.observationTimesInDaysTotalReal = new MutableLong(); this.observationTimesInDaysTotalEstimated = new MutableLong(); @@ -149,12 +146,6 @@ PeriodDates periodDates = new PeriodDates(sampleRowsFilter.getPeriodFrom(), sampleRowsFilter.getPeriodTo()); this.months = periodDates.getMonths(); - - for (Date month : months) { - totalExpectedForMonths.put(month, new MutableInt()); - totalRealForMonths.put(month, new MutableInt()); - totalEstimatedForMonths.put(month, new MutableInt()); - } } public ObsMerSamplingPlanBuilder addSampleRow(SampleRow sampleRow, @@ -177,18 +168,12 @@ // get sector context ServiceContext sectorPart = facadeContext.getOrAddSectorContext(sectors); - // compute nb expected tides for sample row - int totalTidesExpected = getNbTidesExpected(sampleRow); - // compute nb real tides for sample row - int totalTidesReal = getNbTidesReal(sampleRow); - // compute nb estimated tides for sample row - int totalTidesEstimated = getNbTidesEstimated(sampleRow); + // compute nb tides per month + Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> nbTidesPerMonth = computeNbTidesPerMonth(sampleRow); // add sample row sectorPart.addSampleRow(sampleRow, - totalTidesExpected, - totalTidesReal, - totalTidesEstimated, + nbTidesPerMonth, observationTimesInDaysExpected, observationTimesInDaysReal, observationTimesInDaysEstimated); @@ -236,9 +221,9 @@ ObsMerSamplingPlan result = new ObsMerSamplingPlan(months, sortedFacades, statisticsMap, - highTotalExpected.toInteger(), - highTotalReal.toInteger(), - highTotalEstimated.toInteger(), + highTotalExpected, + highTotalReal, + highTotalEstimated, observationTimesInDaysTotalExpected.toDouble(), observationTimesInDaysTotalReal.toLong(), observationTimesInDaysTotalEstimated.toLong(), @@ -246,42 +231,42 @@ return result; } - protected int getNbTidesExpected(SampleRow sampleRow) { - int result = 0; + protected Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> computeNbTidesPerMonth(SampleRow sampleRow) { + Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> result = new TreeMap<>(); for (Date month : months) { - Integer tidesValue = SampleRows.getExpectedTidesValue(sampleRow, month); - if (tidesValue != null) { - result += tidesValue; - totalExpectedForMonths.get(month).add(tidesValue); + Integer expectedTidesValue = SampleRows.getExpectedTidesValue(sampleRow, month); + if (expectedTidesValue != null) { + MutableInt mutableInt = totalExpectedForMonths.get(month); + if (mutableInt == null) { + totalExpectedForMonths.put(month, mutableInt = new MutableInt()); + } + mutableInt.add(expectedTidesValue); + highTotalExpected += expectedTidesValue; } - } - highTotalExpected.add(result); - return result; - } - - protected int getNbTidesReal(SampleRow sampleRow) { - int result = 0; - for (Date month : months) { - Integer tidesValue = SampleRows.getRealTidesValue(sampleRow, month); - if (tidesValue != null) { - result += tidesValue; - totalRealForMonths.get(month).add(tidesValue); + Integer realTidesValue = SampleRows.getRealTidesValue(sampleRow, month); + if (realTidesValue != null) { + MutableInt mutableInt = totalRealForMonths.get(month); + if (mutableInt == null) { + totalRealForMonths.put(month, mutableInt = new MutableInt()); + } + mutableInt.add(realTidesValue); + highTotalReal += realTidesValue; } - } - highTotalReal.add(result); - return result; - } - protected int getNbTidesEstimated(SampleRow sampleRow) { - int result = 0; - for (Date month : months) { - Integer tidesValue = SampleRows.getEstimatedTidesValue(sampleRow, month); - if (tidesValue != null) { - result += tidesValue; - totalEstimatedForMonths.get(month).add(tidesValue); + Integer estimatedTidesValue = SampleRows.getEstimatedTidesValue(sampleRow, month); + if (estimatedTidesValue != null) { + MutableInt mutableInt = totalEstimatedForMonths.get(month); + if (mutableInt == null) { + totalEstimatedForMonths.put(month, mutableInt = new MutableInt()); + } + mutableInt.add(estimatedTidesValue); + highTotalEstimated += estimatedTidesValue; } + result.put(month, new ObsMerSamplingPlan.ObsMerSamplingPlanStatistics(expectedTidesValue, + realTidesValue, + estimatedTidesValue)); + } - highTotalEstimated.add(result); return result; } @@ -335,22 +320,18 @@ protected ServiceContext(String sectors) { this.sectors = sectors; - rows = new ArrayList<>(); + this.rows = new ArrayList<>(); } protected ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart addSampleRow(SampleRow row, - int totalTidesExpected, - int totalTidesReal, - int totalTidesEstimated, + Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> nbTidesPerMonth, Double observationTimesInDaysExpected, Long observationTimesInDaysReal, Long observationTimesInDaysEstimated) { ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart rowPart = - new ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart(row, - totalTidesExpected, - totalTidesReal, - totalTidesEstimated, + new ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart(nbTidesPerMonth, + row, observationTimesInDaysExpected, observationTimesInDaysReal, observationTimesInDaysEstimated); @@ -363,7 +344,7 @@ Collection<ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart> sortedRows = Ordering.natural().onResultOf(new Function<ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart, String>() { public String apply(ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart input) { - return input.getSampleRow().getCode(); + return input.getCode(); } }).immutableSortedCopy(rows); ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart result = Modified: trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java =================================================================== --- trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java 2014-03-27 10:36:13 UTC (rev 1763) +++ trunk/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java 2014-03-27 12:02:46 UTC (rev 1764) @@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableSet; import fr.ifremer.wao.SampleRowsFilter; -import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.services.AbstractWaoServiceTest; import fr.ifremer.wao.services.ObsMerFixtures; import org.apache.commons.io.IOUtils; @@ -36,8 +35,11 @@ import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.List; +import static fr.ifremer.wao.services.service.ObsMerSamplingPlan.*; + public class ObsMerSamplingPlanServiceTest extends AbstractWaoServiceTest { private static final Log log = LogFactory.getLog(ObsMerSamplingPlanServiceTest.class); @@ -83,25 +85,37 @@ serviceContext.setDate(DateUtil.createDate(15, 5, 2010)); SampleRowsFilter filter = service.newSampleRowsFilter(fixtures.admin()); - List<SampleRow> samplingPlan = service.getSamplingPlan(filter).getRows(); - Assert.assertEquals(12, samplingPlan.size()); + ObsMerSamplingPlan samplingPlan = service.getSamplingPlan(filter); + assertSamplePlanRowsNumber(12, samplingPlan); filter = service.newSampleRowsFilter(fixtures.admin()); filter.setFishingGearDcfIds(ImmutableSet.of(fixtures.ptb().getTopiaId())); - samplingPlan = service.getSamplingPlan(filter).getRows(); - Assert.assertEquals(3, samplingPlan.size()); + samplingPlan = service.getSamplingPlan(filter); + assertSamplePlanRowsNumber(3, samplingPlan); filter = service.newSampleRowsFilter(fixtures.admin()); filter.setTargetSpeciesDcfIds(ImmutableSet.of(fixtures.def().getTopiaId())); - samplingPlan = service.getSamplingPlan(filter).getRows(); - Assert.assertEquals(4, samplingPlan.size()); + samplingPlan = service.getSamplingPlan(filter); + assertSamplePlanRowsNumber(4, samplingPlan ); filter = service.newSampleRowsFilter(fixtures.admin()); filter.setFishingGearDcfIds(ImmutableSet.of(fixtures.ptb().getTopiaId())); filter.setTargetSpeciesDcfIds(ImmutableSet.of(fixtures.def().getTopiaId())); - samplingPlan = service.getSamplingPlan(filter).getRows(); - Assert.assertEquals(1, samplingPlan.size()); + samplingPlan = service.getSamplingPlan(filter); + assertSamplePlanRowsNumber(1, samplingPlan ); + } + protected void assertSamplePlanRowsNumber(int expectedRowsSize, ObsMerSamplingPlan samplingPlan) { + int actualRowsSize = 0; + for (ObsMerSamplingPlanFacadePart facade : samplingPlan) { + for (ObsMerSamplingPlanSectorPart sectors : facade) { + + for (ObsMerSamplingPlanSampleRowPart row : sectors) { + actualRowsSize++; + } + } + } + Assert.assertEquals(expectedRowsSize, actualRowsSize); } @Test Modified: trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp =================================================================== --- trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp 2014-03-27 10:36:13 UTC (rev 1763) +++ trunk/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp 2014-03-27 12:02:46 UTC (rev 1764) @@ -215,80 +215,79 @@ </tr> <%--Iterate on SampleRows --%> <s:iterator value="samplingPlanSector" var="samplingPlanRow"> -<s:set var="sampleRow" value="%{#samplingPlanRow.sampleRow}"/> - <tr<s:if test="sampleRowToHighlightId.equals(#sampleRow.topiaId)"> class="highlight"</s:if>> + <tr<s:if test="sampleRowToHighlightId.equals(topiaId)"> class="highlight"</s:if>> <th> - <s:property value="#sampleRow.code" /> + <s:property value="code" /> </th> - <td><s:property value="#sampleRow.programName" /></td> + <td><s:property value="programName" /></td> <s:if test="fullView"> - <td class="only-visible-fullview"><s:property value="#sampleRow.company.name" /></td> + <td class="only-visible-fullview"><s:property value="companyName" /></td> </s:if> - <td class="only-visible-fullview"><s:property value="#samplingPlanRow.fishingZones" /></td> + <td class="only-visible-fullview"><s:property value="fishingZones" /></td> <s:if test="fullView"> - <td class="only-visible-fullview"><s:property value="#sampleRow.fishingZonesInfos" /></td> + <td class="only-visible-fullview"><s:property value="fishingZonesInfos" /></td> <td class="only-visible-fullview"> - <s:iterator value="%{#sampleRow.getdCF5Code()}" var="dcf5code"> + <s:iterator value="dcf5CodesAndDescriptions"> <span> - <s:property value="code"/> + <s:property value="key"/> </span> </s:iterator> </td> - <td class="only-visible-fullview"><s:property value="#sampleRow.profession.meshSize" /></td> - <td class="only-visible-fullview"><s:property value="#sampleRow.profession.size" /></td> - <td class="only-visible-fullview"><s:property value="#sampleRow.profession.other" /></td> - <td class="only-visible-fullview"><s:property value="#sampleRow.profession.libelle" /></td> - <td class="only-visible-fullview"><s:property value="#sampleRow.profession.species" /></td> - <td class="only-visible-fullview"><s:property value="%{formatMonth(#sampleRow.periodBegin)}" /></td> - <td class="only-visible-fullview"><s:property value="%{formatMonth(#sampleRow.periodEnd)}" /></td> + <td class="only-visible-fullview"><s:property value="professionMeshSize" /></td> + <td class="only-visible-fullview"><s:property value="professionSize" /></td> + <td class="only-visible-fullview"><s:property value="professionOther" /></td> + <td class="only-visible-fullview"><s:property value="professionLibelle" /></td> + <td class="only-visible-fullview"><s:property value="professionSpecies" /></td> + <td class="only-visible-fullview"><s:property value="%{formatMonth(periodBegin)}" /></td> + <td class="only-visible-fullview"><s:property value="%{formatMonth(periodEnd)}" /></td> </s:if> <s:else> <td class="only-visible-compactview"> - <s:iterator value="%{#sampleRow.getdCF5Code()}" var="dcf5code"> - <span> - <s:property value="code"/> - </span> + <s:iterator value="dcf5CodesAndDescriptions"> + <span> + <s:property value="key"/> + </span> </s:iterator> - <s:property value="#sampleRow.professionDescriptionWithoutDCF5" /> + <s:property value="professionDescriptionWithoutDCF5" /> </td> <td class="only-visible-compactview"> - <s:property value="#row.profession.libelle" /> + <s:property value="professionLibelle" /> </td> </s:else> <!-- Months columns --> <s:iterator value="samplingPlan.months" var="month"> <td<s:if test="@fr.ifremer.wao.WaoUtils@isCurrentMonth(#month)"> class="current-month"</s:if>> - <s:property value="%{#samplingPlanRow.getNbTidesExpected(#month)}"/> - <span<s:if test="#samplingPlanRow.hasNbTidesReal(#month) && !#authenticatedWaoUser.guest"> class="display-tides-real"</s:if>> - <em>(<s:property value="%{#samplingPlanRow.getNbTidesReal(#month)}"/>) + <s:property value="%{getNbTidesExpected(#month)}"/> + <span<s:if test="hasNbTidesReal(#month) && !#authenticatedWaoUser.guest"> class="display-tides-real"</s:if>> + <em>(<s:property value="%{getNbTidesReal(#month)}"/>) </em> </span> </td> </s:iterator> <td> <span> - <s:property value="#samplingPlanRow.totalTidesExpected" /> + <s:property value="totalTidesExpected" /> <s:if test="!authenticatedWaoUser.guest"> - <em>(<s:property value="#samplingPlanRow.totalTidesReal" />)</em> + <em>(<s:property value="totalTidesReal" />)</em> <br/> - <strong><s:property value="#samplingPlanRow.totalPercentage" /></strong> + <strong><s:property value="totalPercentage" /></strong> </s:if> </span> </td> <td> - <s:property value="#samplingPlanRow.observationTimesInDaysExpected" /> <s:text name="wao.ui.misc.day"/> + <s:property value="observationTimesInDaysExpected" /> <s:text name="wao.ui.misc.day"/> <span> - <em>(<s:property value="#samplingPlanRow.observationTimesInDaysReal" /> <s:text name="wao.ui.misc.day"/>)</em> + <em>(<s:property value="observationTimesInDaysReal" /> <s:text name="wao.ui.misc.day"/>)</em> </span> </td> - <td><s:property value="#sampleRow.averageTideTime" /></td> - <td><s:property value="#sampleRow.nbObservants" /></td> + <td><s:property value="averageTideTime" /></td> + <td><s:property value="nbObservants" /></td> <td> - <s:if test="sampleRow.appliedCoverageRate"> - <s:property value="#sampleRow.appliedCoverageRate" /> % + <s:if test="appliedCoverageRate"> + <s:property value="appliedCoverageRate" /> % </s:if> </td> - <td><s:property value="#sampleRow.comment" /></td> + <td><s:property value="comment" /></td> <td class="actions"> <div class="dropdown"> @@ -300,7 +299,7 @@ <s:if test="authenticatedWaoUser.authorizedToEditSamplingPlan"> <li> <s:url action="edit-sample-row!input" id="editSampleRowUrl"> - <s:param name="sampleRowId" value="sampleRow.topiaId" /> + <s:param name="sampleRowId" value="sampleRowId" /> </s:url> <s:a href="%{editSampleRowUrl}"> <i class="icon-edit"></i> <s:text name="wao.ui.action.edit" /> @@ -308,7 +307,7 @@ </li> <li> <s:url action="delete-sample-row" id="deleteSampleRowUrl"> - <s:param name="companyId" value="sampleRow.topiaId" /> + <s:param name="companyId" value="sampleRowId" /> </s:url> <s:a href="%{deleteSampleRowUrl}"> <i class="icon-trash"></i> <s:text name="wao.ui.action.delete" /> @@ -317,7 +316,7 @@ </s:if> <li> <s:url action="sample-row-log" id="sampleRowLogUrl"> - <s:param name="sampleRowId" value="sampleRow.topiaId" /> + <s:param name="sampleRowId" value="sampleRowId" /> </s:url> <s:a href="%{sampleRowLogUrl}"> <i class="icon-time"></i> <s:text name="wao.ui.action.viewSampleRowLog" /> @@ -325,7 +324,7 @@ </li> <li> <s:url action="boats" id="viewElligibleBoatsUrl"> - <s:param name="sampleRowIds" value="sampleRow.topiaId" /> + <s:param name="sampleRowIds" value="sampleRowId" /> </s:url> <s:a href="%{viewElligibleBoatsUrl}"> <s:text name="wao.ui.action.viewElligibleBoats" /> @@ -333,7 +332,7 @@ </li> <li> <s:url action="contacts" id="viewAssociatedContactsUrl"> - <s:param name="sampleRowIds" value="sampleRow.topiaId" /> + <s:param name="sampleRowIds" value="sampleRowId" /> </s:url> <s:a href="%{viewAssociatedContactsUrl}"> <s:text name="wao.ui.action.viewAssociatedContacts" /> @@ -342,7 +341,7 @@ <s:if test="authenticatedWaoUser.authorizedToCreateContact"> <li> <s:url action="contacts" id="createAssociatedContactUrl"> - <s:param name="sampleRowIds" value="sampleRow.topiaId" /> + <s:param name="sampleRowIds" value="sampleRowId" /> </s:url> <s:a href="%{createAssociatedContactUrl}"> <i class="icon-add"></i> <s:text name="wao.ui.action.createAssociatedContact" />