Author: bleny Date: 2014-06-21 13:01:33 +0200 (Sat, 21 Jun 2014) New Revision: 2081 Url: http://forge.codelutin.com/projects/wao/repository/revisions/2081 Log: refs #4484 obsvente sampling plan Added: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlan.java branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanBuilder.java branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanService.java branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlan.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/AbstractSamplingPlanAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/CommentSampleRowAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteSampleRowAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportSamplingPlanAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportSamplingPlanAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowLogAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowsFilterValuesJsonAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsvente/ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsvente/SamplingPlanAction.java branches/wao-4.0-obsvente/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsvente/ branches/wao-4.0-obsvente/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsvente/SamplingPlanAction-conversion.properties branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/import-contacts-input.jsp branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/import-sampling-plan-input.jsp branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsvente/ branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsvente/sampling-plan.jsp branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/sample-row-log.jsp Removed: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CommentSampleRowAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/DeleteSampleRowAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditSampleRowAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportSamplingPlanAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ImportSamplingPlanAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowLogAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowsFilterValuesJsonAction.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-sample-row-input.jsp branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts-input.jsp branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-sampling-plan-input.jsp branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/sample-row-log.jsp Modified: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/DefaultWaoServiceContext.java branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/WaoApplicationContext.java branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/WaoServiceContext.java branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java branches/wao-4.0-obsvente/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/CacheInvalidationTopiaEntityListener.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/DefaultWaoApplicationContext.java branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/WaoJspActionSupport.java branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp branches/wao-4.0-obsvente/wao-web/src/main/webapp/endpoints-js.jsp Modified: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/DefaultWaoServiceContext.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/DefaultWaoServiceContext.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/DefaultWaoServiceContext.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -29,6 +29,7 @@ import fr.ifremer.wao.services.service.BoatsFilterValues; import fr.ifremer.wao.services.service.BoatsFilterValuesCacheKey; import fr.ifremer.wao.services.service.ObsMerSamplingPlan; +import fr.ifremer.wao.services.service.SamplingPlan; import fr.ifremer.wao.services.service.Synthesis; import fr.ifremer.wao.services.service.SamplingPlanCacheKey; @@ -123,7 +124,7 @@ } @Override - public Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> getSamplingPlansCache() { + public Cache<SamplingPlanCacheKey, SamplingPlan> getSamplingPlansCache() { return waoApplicationContext.getSamplingPlansCache(); } Modified: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/WaoApplicationContext.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/WaoApplicationContext.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/WaoApplicationContext.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -6,9 +6,9 @@ import fr.ifremer.wao.WaoTopiaPersistenceContext; import fr.ifremer.wao.services.service.BoatsFilterValues; import fr.ifremer.wao.services.service.BoatsFilterValuesCacheKey; -import fr.ifremer.wao.services.service.ObsMerSamplingPlan; +import fr.ifremer.wao.services.service.SamplingPlan; +import fr.ifremer.wao.services.service.SamplingPlanCacheKey; import fr.ifremer.wao.services.service.Synthesis; -import fr.ifremer.wao.services.service.SamplingPlanCacheKey; import java.util.Date; import java.util.Locale; @@ -35,7 +35,7 @@ void close(); - Cache<SamplingPlanCacheKey,ObsMerSamplingPlan> getSamplingPlansCache(); + Cache<SamplingPlanCacheKey,SamplingPlan> getSamplingPlansCache(); Cache<BoatsFilterValuesCacheKey, BoatsFilterValues> getBoatsFilterValuesCache(); Modified: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/WaoServiceContext.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/WaoServiceContext.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/WaoServiceContext.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -27,9 +27,9 @@ import fr.ifremer.wao.WaoTopiaPersistenceContext; import fr.ifremer.wao.services.service.BoatsFilterValues; import fr.ifremer.wao.services.service.BoatsFilterValuesCacheKey; -import fr.ifremer.wao.services.service.ObsMerSamplingPlan; +import fr.ifremer.wao.services.service.SamplingPlan; +import fr.ifremer.wao.services.service.SamplingPlanCacheKey; import fr.ifremer.wao.services.service.Synthesis; -import fr.ifremer.wao.services.service.SamplingPlanCacheKey; import java.util.Date; import java.util.Locale; @@ -56,7 +56,7 @@ String newUuid(); - Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> getSamplingPlansCache(); + Cache<SamplingPlanCacheKey, SamplingPlan> getSamplingPlansCache(); Cache<BoatsFilterValuesCacheKey, BoatsFilterValues> getBoatsFilterValuesCache(); Modified: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ContactsService.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -770,7 +770,7 @@ throw new IllegalDeletionException(allUsages); } - ObsMerSamplingPlanService samplingPlanService = newService(ObsMerSamplingPlanService.class); + SamplingPlanService samplingPlanService = newService(SamplingPlanService.class); samplingPlanService.recomputeSampleRowEstimatedAndRealTides(contact.getSampleRow()); @@ -786,7 +786,7 @@ ContactTopiaDao dao = getContactDao(); - ObsMerSamplingPlanService samplingPlanService = newService(ObsMerSamplingPlanService.class); + SamplingPlanService samplingPlanService = newService(SamplingPlanService.class); if (updateContactCommand.isCreation()) { Modified: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -21,49 +21,20 @@ * #L% */ -import fr.ifremer.wao.WaoUtils; -import fr.ifremer.wao.entity.DCF5Code; -import fr.ifremer.wao.entity.FishingZone; -import fr.ifremer.wao.entity.SampleMonth; import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.entity.SampleRowLog; -import fr.ifremer.wao.entity.TerrestrialLocation; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.nuiton.util.DateUtil; -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.Locale; import java.util.Map; import java.util.Set; -public class ObsMerSamplingPlan implements Iterable<ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart>, Serializable { +public class ObsMerSamplingPlan extends SamplingPlan { private static final long serialVersionUID = 1L; /** - * All facades of the sampling plan. - */ - protected Collection<ObsMerSamplingPlanFacadePart> facades; - - /** - * Total tides over the plan by month. - */ - protected Map<Date, ObsMerSamplingPlanStatistics> totalsPerMonth; - - /** - * High total over the hole plan. - */ - protected ObsMerSamplingPlanStatistics highTotals; - - /** * Total of observation times in days expected. * <p/> * <strong>Note:</strong> can be null. @@ -84,54 +55,21 @@ */ protected Long observationTimesInDaysTotalEstimated; - /** - * List of month used by sample rows. - */ - protected List<Date> months; - - /** - * Universe of filter values. - */ - protected SampleRowsFilterValues filterValues; - - /** - * Ids of all the sample rows included in this sampling plan. - */ - protected Set<String> sampleRowIds; - public ObsMerSamplingPlan(List<Date> months, - Collection<ObsMerSamplingPlanFacadePart> facadeParts, - Map<Date, ObsMerSamplingPlanStatistics> totalsPerMonth, - ObsMerSamplingPlanStatistics highTotals, + Collection<SamplingPlanFacadePart> facadeParts, + Map<Date, SamplingPlanStatistics> totalsPerMonth, + SamplingPlanStatistics highTotals, Double observationTimesInDaysTotalExpected, Long observationTimesInDaysTotalReal, Long observationTimesInDaysTotalEstimated, SampleRowsFilterValues filterValues, Set<String> sampleRowIds) { - this.months = months; - this.facades = facadeParts; - this.totalsPerMonth = totalsPerMonth; - this.highTotals = highTotals; + super(months, facadeParts, totalsPerMonth, highTotals, filterValues, sampleRowIds); this.observationTimesInDaysTotalExpected = observationTimesInDaysTotalExpected; this.observationTimesInDaysTotalReal = observationTimesInDaysTotalReal; this.observationTimesInDaysTotalEstimated = observationTimesInDaysTotalEstimated; - this.filterValues = filterValues; - this.sampleRowIds = sampleRowIds; } - public Set<String> getSampleRowIds() { - return sampleRowIds; - } - - @Override - public Iterator<ObsMerSamplingPlanFacadePart> iterator() { - return facades.iterator(); - } - - public List<Date> getMonths() { - return months; - } - public Double getObservationTimesInDaysTotalExpected() { return observationTimesInDaysTotalExpected; } @@ -144,140 +82,17 @@ return observationTimesInDaysTotalEstimated; } - public Integer getTotalExpected(Date month) { - Integer result = totalsPerMonth.get(month).getNbTidesExpected(); - return result; - } - - public Integer getTotalReal(Date month) { - Integer result = totalsPerMonth.get(month).getNbTidesReal(); - return result; - } - - public Integer getTotalEstimated(Date month) { - Integer result = totalsPerMonth.get(month).getNbTidesEstimated(); - return result; - } - - public String getTotalRealRatio(Date month) { - String result = totalsPerMonth.get(month).getRealRatio("-"); - return result; - } - - public String getTotalEstimatedRatio(Date month) { - String result = totalsPerMonth.get(month).getEstimatedRatio("-"); - return result; - } - - public Integer getHighTotalExpected() { - return highTotals.getNbTidesExpected(); - } - - public Integer getHighTotalReal() { - return highTotals.getNbTidesReal(); - } - - public Integer getHighTotalEstimated() { - return highTotals.getNbTidesEstimated(); - } - - public String getHighTotalRealRatio() { - String ratio = highTotals.getRealRatio(""); - return ratio; - } - - public String getHighTotalEstimatedRatio() { - String ratio = highTotals.getEstimatedRatio(""); - return ratio; - } - - public SampleRowsFilterValues getFilterValues() { - return filterValues; - } - /** - * 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 { + public static class ObsMerSamplingPlanSampleRowPart extends SamplingPlanSampleRowPart { 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(); - } - } - - /** - * 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; - - /** - * Nb tides by month. - */ - protected Map<Date, ObsMerSamplingPlanStatistics> nbTidesPerMonth; - - /** - * Total of tides. - */ - protected ObsMerSamplingPlanStatistics totalTides; - - /** * Expected Times of observation days. * <p/> * <strong>Note:</strong> can be null. @@ -302,107 +117,23 @@ protected Integer observationTimesInDaysRealPercentage; - protected String fishingZones; - 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; - - /** - * Date of the latest sample log. - */ - protected Date latestSampleLogCreateDate; - - /** - * First sample month date. - */ - protected Date firstSampleMonthDate; - - /** - * Last sample month date. - */ - protected Date lastSampleMonthDate; - - /** - * Last sample month end of month. - */ - protected Date lastSampleMonthEndOfMonth; - - protected boolean elligibleBoatsProvided; - public ObsMerSamplingPlanSampleRowPart(Locale locale, - Map<Date, ObsMerSamplingPlanStatistics> nbTidesPerMonth, + Map<Date, SamplingPlanStatistics> nbTidesPerMonth, SampleRow sampleRow, Double observationTimesInDaysExpected, Long observationTimesInDaysReal, Long observationTimesInDaysEstimated) { + super(locale, nbTidesPerMonth, sampleRow); this.observationTimesInDaysExpected = observationTimesInDaysExpected; this.observationTimesInDaysReal = observationTimesInDaysReal; this.observationTimesInDaysEstimated = observationTimesInDaysEstimated; - this.nbTidesPerMonth = nbTidesPerMonth; - // compute total tides - int totalTidesExpected = 0; - int totalTidesEstimated = 0; - int totalTidesReal = 0; - 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; - } - } if (observationTimesInDaysExpected != null && observationTimesInDaysExpected > 0) { if (observationTimesInDaysEstimated != null) { @@ -412,220 +143,14 @@ observationTimesInDaysRealPercentage = (int) Math.round((observationTimesInDaysReal / observationTimesInDaysExpected) * 100); } } - totalTides = new ObsMerSamplingPlanStatistics(totalTidesExpected, totalTidesReal, totalTidesEstimated); - 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() + " - " + WaoUtils.l(locale, dcf5Code.getFishingGearDCF()); - if (dcf5Code.getTargetSpeciesCode() != null) { - description += " ; " + dcf5Code.getTargetSpeciesCode() + " - " + WaoUtils.l(locale, dcf5Code.getTargetSpeciesDCF()); - } - 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(); - terrestrialLocationNamesAndDescriptions.put(key, description); - } - } - professionDescriptionWithoutDCF5 = sampleRow.getProfessionDescriptionWithoutDCF5(); - //FIXME Is this ok? - samplingStrategy = WaoUtils.l(locale,sampleRow.getSamplingStrategy()); - sampleRowId = sampleRow.getTopiaId(); - // consider a recently created sample row as recently updated - latestSampleLogCreateDate = sampleRow.getTopiaCreateDate(); - // compute lastSampleLogCreateDate - if (sampleRow.isSampleRowLogNotEmpty()) { - for (SampleRowLog sampleRowLog : sampleRow.getSampleRowLog()) { - if (sampleRowLog.getCreateDate().after(latestSampleLogCreateDate)) { - latestSampleLogCreateDate = sampleRowLog.getCreateDate(); - } - } - } - - // compute sampleRowPeriod - // TODO brendan 15/04/14 use treeset - List<SampleMonth> sampleMonth = new ArrayList<>(sampleRow.getSampleMonth()); - firstSampleMonthDate = sampleMonth.get(0).getPeriodDate(); - lastSampleMonthDate = sampleMonth.get(sampleMonth.size() - 1).getPeriodDate(); - - lastSampleMonthEndOfMonth = WaoUtils.getEndOfMonth(lastSampleMonthDate); - elligibleBoatsProvided = sampleRow.isElligibleBoatNotEmpty(); } - public String getSamplingStrategy() { - return samplingStrategy; - } - - public String getSampleRowId() { - return sampleRowId; - } - - public Date getFirstSampleMonthDate() { - return firstSampleMonthDate; - } - - public Date getLastSampleMonthDate() { - return lastSampleMonthDate; - } - - 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 totalTides.getNbTidesExpected(); - } - - public int getTotalTidesReal() { - return totalTides.getNbTidesReal(); - } - - public int getTotalTidesEstimated() { - return totalTides.getNbTidesEstimated(); - } - - public String getProfessionDescriptionWithoutDCF5() { - return professionDescriptionWithoutDCF5; - } - - public Integer getNbTidesExpected(Date month) { - Integer result = nbTidesPerMonth.get(month).getNbTidesExpected(); - return result; - } - - public Integer getNbTidesReal(Date month) { - Integer result = nbTidesPerMonth.get(month).getNbTidesReal(); - return result; - } - - public Integer getNbTidesEstimated(Date month) { - Integer result = nbTidesPerMonth.get(month).getNbTidesEstimated(); - return result; - } - - public String getTotalRealPercentage() { - String result = totalTides.getRealRatio("-"); - return result; - } - - public String getTotalEstimatedPercentage() { - String result = totalTides.getEstimatedRatio("-"); - return result; - } - - public String getFishingZones() { - return fishingZones; - } - public Double getObservationTimesInDaysExpected() { return observationTimesInDaysExpected; } @@ -646,86 +171,16 @@ return observationTimesInDaysEstimatedPercentage; } - public boolean isElligibleBoatsProvided() { - return elligibleBoatsProvided; + public Double getAppliedCoverageRate() { + return appliedCoverageRate; } - public boolean isRecentlyUpdated() { - boolean isRecentlyUpdated = latestSampleLogCreateDate != null - && DateUtil.getDifferenceInDays(latestSampleLogCreateDate, new Date()) <= 2 * 7; - return isRecentlyUpdated; + public int getNbObservants() { + return nbObservants; } - public boolean isNewContactCreatable() { - boolean isNewContactCreatable = new Date().before(lastSampleMonthEndOfMonth); - return isNewContactCreatable; + public double getAverageTideTime() { + return averageTideTime; } } - - public static class ObsMerSamplingPlanStatistics implements Serializable { - - private static final long serialVersionUID = 1L; - - /** - * Number of expected tides. - */ - protected Integer nbTidesExpected; - - /** - * Number of real tides. - */ - protected Integer nbTidesReal; - - /** - * Number of estimated tides. - */ - protected Integer nbTidesEstimated; - - public ObsMerSamplingPlanStatistics(Integer nbTidesExpected, - Integer nbTidesReal, - Integer nbTidesEstimated) { - this.nbTidesExpected = nbTidesExpected; - this.nbTidesReal = nbTidesReal; - this.nbTidesEstimated = nbTidesEstimated; - } - - public Integer getNbTidesExpected() { - return nbTidesExpected; - } - - public Integer getNbTidesReal() { - return nbTidesReal; - } - - public Integer getNbTidesEstimated() { - return nbTidesEstimated; - } - - public String getRealRatio(String defaultValue) { - String ratio = defaultValue; - if (nbTidesExpected != null && nbTidesExpected > 0 && - nbTidesReal != null && nbTidesReal > 0) { - double percent = ((double) nbTidesReal / nbTidesExpected); - ratio = NumberFormat.getPercentInstance().format(percent); - } - return ratio; - } - - public String getEstimatedRatio(String defaultValue) { - String ratio = defaultValue; - if (nbTidesExpected != null && nbTidesExpected > 0 && - nbTidesEstimated != null && nbTidesEstimated > 0) { - double percent = ((double) nbTidesEstimated / nbTidesExpected); - ratio = NumberFormat.getPercentInstance().format(percent); - } - return ratio; - } - - @Override - public String toString() { - String toString = ToStringBuilder.reflectionToString(this); - return toString; - } - - } } Modified: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -124,21 +124,21 @@ /** * To compute by month the total of expected tides. * - * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#nbTidesExpected + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan.SamplingPlanStatistics#nbTidesExpected */ protected Map<Date, MutableInt> totalExpectedForMonths; /** * To compute by month the total of expected tides. * - * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#nbTidesEstimated + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan.SamplingPlanStatistics#nbTidesEstimated */ protected Map<Date, MutableInt> totalEstimatedForMonths; /** * To compute by month the total of real tides. * - * @see ObsMerSamplingPlan.ObsMerSamplingPlanStatistics#nbTidesReal + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan.SamplingPlanStatistics#nbTidesReal */ protected Map<Date, MutableInt> totalRealForMonths; @@ -182,7 +182,7 @@ SectorContext sectorPart = facadeContext.getOrAddSectorContext(sectors); // compute nb tides per month - Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> nbTidesPerMonth = computeNbTidesPerMonth(sampleRow); + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> nbTidesPerMonth = computeNbTidesPerMonth(sampleRow); // add sample row sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), @@ -207,34 +207,34 @@ public ObsMerSamplingPlan toPlan() { // Get facade parts - Collection<ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart> facadeParts = new ArrayList<>(); + Collection<SamplingPlan.SamplingPlanFacadePart> facadeParts = new ArrayList<>(); for (FacadeContext facadeContext : facadeMap.values()) { - ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart facadePart = facadeContext.toBean(); + SamplingPlan.SamplingPlanFacadePart facadePart = facadeContext.toBean(); facadeParts.add(facadePart); } // Sort them - Collection<ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart> sortedFacades = Ordering.natural().onResultOf(new Function<ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart, String>() { - public String apply(ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart input) { + Collection<SamplingPlan.SamplingPlanFacadePart> sortedFacades = Ordering.natural().onResultOf(new Function<SamplingPlan.SamplingPlanFacadePart, String>() { + public String apply(SamplingPlan.SamplingPlanFacadePart input) { return input.getFacade(); } }).immutableSortedCopy(facadeParts); // Get statistics - Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> statisticsMap = new TreeMap<>(); + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> statisticsMap = new TreeMap<>(); for (Date month : months) { MutableInt totalExpected = totalExpectedForMonths.get(month); MutableInt totalReal = totalRealForMonths.get(month); MutableInt totalEstimated = totalEstimatedForMonths.get(month); - ObsMerSamplingPlan.ObsMerSamplingPlanStatistics planStatistics = - new ObsMerSamplingPlan.ObsMerSamplingPlanStatistics(totalExpected == null ? null : totalExpected.toInteger(), + ObsMerSamplingPlan.SamplingPlanStatistics planStatistics = + new ObsMerSamplingPlan.SamplingPlanStatistics(totalExpected == null ? null : totalExpected.toInteger(), totalReal == null ? null : totalReal.toInteger(), totalEstimated == null ? null : totalEstimated.toInteger()); statisticsMap.put(month, planStatistics); } - ObsMerSamplingPlan.ObsMerSamplingPlanStatistics highTotals = new ObsMerSamplingPlan.ObsMerSamplingPlanStatistics(highTotalExpected, highTotalReal, highTotalEstimated); + ObsMerSamplingPlan.SamplingPlanStatistics highTotals = new ObsMerSamplingPlan.SamplingPlanStatistics(highTotalExpected, highTotalReal, highTotalEstimated); ObsMerSamplingPlan result = new ObsMerSamplingPlan(months, sortedFacades, @@ -248,8 +248,8 @@ return result; } - protected Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> computeNbTidesPerMonth(SampleRow sampleRow) { - Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> result = new TreeMap<>(); + protected Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> computeNbTidesPerMonth(SampleRow sampleRow) { + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> result = new TreeMap<>(); for (Date month : months) { Integer expectedTidesValue = SampleRows.getExpectedTidesValue(sampleRow, month); if (expectedTidesValue != null) { @@ -279,7 +279,7 @@ mutableInt.add(estimatedTidesValue); highTotalEstimated += estimatedTidesValue; } - result.put(month, new ObsMerSamplingPlan.ObsMerSamplingPlanStatistics(expectedTidesValue, + result.put(month, new ObsMerSamplingPlan.SamplingPlanStatistics(expectedTidesValue, realTidesValue, estimatedTidesValue)); @@ -309,22 +309,22 @@ return sectorPart; } - protected ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart toBean() { + protected SamplingPlan.SamplingPlanFacadePart toBean() { // get sector parts - Collection<ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart> sectorParts = new ArrayList<>(); + Collection<SamplingPlan.SamplingPlanSectorPart> sectorParts = new ArrayList<>(); for (SectorContext sectorContext : sectorMap.values()) { - ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart sectorPart = sectorContext.toBean(); + SamplingPlan.SamplingPlanSectorPart sectorPart = sectorContext.toBean(); sectorParts.add(sectorPart); } // sort them - Collection<ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart> sortedSectors = Ordering.natural().onResultOf(new Function<ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart, String>() { - public String apply(ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart input) { + Collection<SamplingPlan.SamplingPlanSectorPart> sortedSectors = Ordering.natural().onResultOf(new Function<SamplingPlan.SamplingPlanSectorPart, String>() { + public String apply(SamplingPlan.SamplingPlanSectorPart input) { return input.getSectors(); } }).immutableSortedCopy(sectorParts); - ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart result = - new ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart(facade, sortedSectors); + SamplingPlan.SamplingPlanFacadePart result = + new SamplingPlan.SamplingPlanFacadePart(facade, sortedSectors); return result; } } @@ -340,9 +340,9 @@ this.rows = new ArrayList<>(); } - protected ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart addSampleRow(Locale locale, + protected ObsMerSamplingPlan.SamplingPlanSampleRowPart addSampleRow(Locale locale, SampleRow row, - Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> nbTidesPerMonth, + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> nbTidesPerMonth, Double observationTimesInDaysExpected, Long observationTimesInDaysReal, Long observationTimesInDaysEstimated) { @@ -359,15 +359,15 @@ return rowPart; } - protected ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart toBean() { + protected SamplingPlan.SamplingPlanSectorPart toBean() { Collection<ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart> sortedRows = Ordering.natural().onResultOf(new Function<ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart, String>() { public String apply(ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart input) { return input.getCode(); } }).immutableSortedCopy(rows); - ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart result = - new ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart(sectors, sortedRows); + SamplingPlan.SamplingPlanSectorPart result = + new SamplingPlan.SamplingPlanSectorPart(sectors, sortedRows); return result; } } Modified: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanService.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -21,358 +21,33 @@ * #L% */ -import com.google.common.base.Charsets; import com.google.common.base.Optional; -import com.google.common.base.Preconditions; import com.google.common.cache.Cache; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; import com.google.common.collect.Range; import com.google.common.collect.Sets; import fr.ifremer.wao.ContactsFilter; import fr.ifremer.wao.SampleRowsFilter; -import fr.ifremer.wao.WaoTechnicalException; import fr.ifremer.wao.WaoUtils; -import fr.ifremer.wao.entity.Boat; -import fr.ifremer.wao.entity.Boats; -import fr.ifremer.wao.entity.Company; -import fr.ifremer.wao.entity.CompanyTopiaDao; import fr.ifremer.wao.entity.Contact; import fr.ifremer.wao.entity.ContactState; -import fr.ifremer.wao.entity.DCF5Code; -import fr.ifremer.wao.entity.ElligibleBoat; -import fr.ifremer.wao.entity.ElligibleBoatImpl; -import fr.ifremer.wao.entity.ElligibleBoatTopiaDao; -import fr.ifremer.wao.entity.FishingZone; -import fr.ifremer.wao.entity.FishingZoneTopiaDao; -import fr.ifremer.wao.entity.LocationType; -import fr.ifremer.wao.entity.ObsProgram; -import fr.ifremer.wao.entity.Profession; -import fr.ifremer.wao.entity.ProfessionImpl; -import fr.ifremer.wao.entity.ProfessionTopiaDao; import fr.ifremer.wao.entity.SampleMonth; -import fr.ifremer.wao.entity.SampleMonthImpl; -import fr.ifremer.wao.entity.SampleMonthTopiaDao; import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.entity.SampleRowImpl; -import fr.ifremer.wao.entity.SampleRowLog; -import fr.ifremer.wao.entity.SampleRowLogImpl; -import fr.ifremer.wao.entity.SampleRowLogTopiaDao; import fr.ifremer.wao.entity.SampleRowTopiaDao; -import fr.ifremer.wao.entity.SamplingStrategy; -import fr.ifremer.wao.entity.TerrestrialLocation; -import fr.ifremer.wao.entity.TerrestrialLocationTopiaDao; import fr.ifremer.wao.services.AuthenticatedWaoUser; -import fr.ifremer.wao.services.service.administration.ReferentialService; -import fr.ifremer.wao.services.service.administration.UnknownBoatImmatriculationsException; -import fr.ifremer.wao.services.service.csv.ObsMerObsVenteSamplingPlanImportExportModel; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.csv.Export; -import org.nuiton.csv.ExportModel; -import org.nuiton.csv.Import; -import org.nuiton.csv.ImportModel; -import org.nuiton.csv.ImportRuntimeException; -import org.nuiton.topia.persistence.TopiaEntities; -import org.nuiton.topia.persistence.TopiaEntity; -import java.io.InputStream; -import java.text.ParseException; -import java.util.Calendar; import java.util.Collection; import java.util.Date; -import java.util.GregorianCalendar; -import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Set; public class ObsMerSamplingPlanService extends SamplingPlanService { private static final Log log = LogFactory.getLog(ObsMerSamplingPlanService.class); - public UpdateSampleRowCommand newUpdateSampleRowCommand(AuthenticatedWaoUser authenticatedWaoUser, Optional<String> optionalSampleRowId) { - - Preconditions.checkState(authenticatedWaoUser.isAuthorizedToCreateSampleRow()); - - UpdateSampleRowCommand updateSampleRowCommand = new UpdateSampleRowCommand(); - - if (optionalSampleRowId.isPresent()) { - - String sampleRowId = optionalSampleRowId.get(); - - SampleRowTopiaDao sampleRowDao = getSampleRowDao(); - - SampleRow sampleRowMemento = sampleRowDao.findByTopiaId(sampleRowId); - sampleRowDao.detach(sampleRowMemento); - updateSampleRowCommand.setSampleRowMemento(sampleRowMemento); - - SampleRow sampleRow = sampleRowDao.findByTopiaId(sampleRowId); - updateSampleRowCommand.setSampleRow(sampleRow); - - updateSampleRowCommand.setCreation(false); - - SampleRowLogImpl newSampleRowLog = new SampleRowLogImpl(); - newSampleRowLog.setAuthor(authenticatedWaoUser.getWaoUser()); - newSampleRowLog.setFromAdmin(authenticatedWaoUser.isAdmin()); - updateSampleRowCommand.setSampleRowLog(newSampleRowLog); - sampleRow.addSampleRowLog(newSampleRowLog); - - Set<Boat> elligibleBoats = new HashSet<>(); - for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { - boolean boatIsElligibleForUser = - authenticatedWaoUser.isAdmin() && elligibleBoat.isGlobalActive() || - authenticatedWaoUser.isCoordinator() && BooleanUtils.isTrue(elligibleBoat.getCompanyActive()); - if (boatIsElligibleForUser) { - elligibleBoats.add(elligibleBoat.getBoat()); - } - } - String elligibleBoatImmatriculations = Boats.toImmatriculations(elligibleBoats); - updateSampleRowCommand.setElligibleBoatImmatriculations(elligibleBoatImmatriculations); - - } else { - - SampleRow newSampleRow = new SampleRowImpl(); - - newSampleRow.setObsProgram(ObsProgram.OBSMER); - newSampleRow.setProfession(new ProfessionImpl()); - newSampleRow.setFishingZone(new HashSet<FishingZone>()); - newSampleRow.setSampleMonth(new HashSet<SampleMonth>()); - newSampleRow.setSamplingStrategy(SamplingStrategy.SIMULTANEOUS_ALL_SPECIES); - - String newSampleRowCode = getNewSampleRowCode(ObsProgram.OBSMER); - newSampleRow.setCode(newSampleRowCode); - - updateSampleRowCommand.setSampleRow(newSampleRow); - - updateSampleRowCommand.setCreation(true); - - } - - ImmutableMap<String, FishingZone> allFishingZones = - Maps.uniqueIndex( - getReferentialService().getAllFishingZones(), - TopiaEntities.getTopiaIdFunction() - ); - updateSampleRowCommand.setAllFishingZones(allFishingZones); - - ImmutableMap<String, Company> allCompanies = - Maps.uniqueIndex( - getCompaniesService().getAllCompanies(), - TopiaEntities.getTopiaIdFunction() - ); - updateSampleRowCommand.setAllCompanies(allCompanies); - - ImmutableMap<String, DCF5Code> allDcf5Codes = - Maps.uniqueIndex( - getReferentialService().getAllDcf5Codes(), - TopiaEntities.getTopiaIdFunction() - ); - updateSampleRowCommand.setAllDcf5Codes(allDcf5Codes); - - return updateSampleRowCommand; - - } - - /** - * On va rechercher en base pour générer un code qui n'existe pas déjà. - */ - protected String getNewSampleRowCode(ObsProgram obsProgram) { - - // On pré-définit un code pour la nouvelle ligne. - // au moment de la création d'une nouvelle ligne, on a aucune info donc - // on suppose que c'est pour l'année en cours - - Calendar begin = new GregorianCalendar(); - begin.setTime(getNow()); - int year = begin.get(Calendar.YEAR); - - String newSampleRowCodePrefix = year + "_" + obsProgram.getShortCode(); - - SampleRowTopiaDao dao = getSampleRowDao(); - - Optional<String> optionalMaxSampleRowCode = dao.findMaxSampleRowCode(newSampleRowCodePrefix); - int maxSampleRowCodeSequence; - if (optionalMaxSampleRowCode.isPresent()) { - String maxSampleRowCode = optionalMaxSampleRowCode.get(); - if (log.isDebugEnabled()) { - log.debug("max code found : " + maxSampleRowCode); - } - String sequenceStr = StringUtils.removeStart(maxSampleRowCode, newSampleRowCodePrefix); - maxSampleRowCodeSequence = Integer.parseInt(sequenceStr); - } else { - maxSampleRowCodeSequence = 0; - } - - maxSampleRowCodeSequence += 1; - - String newSampleRowCodeSuffix = StringUtils.leftPad(String.valueOf(maxSampleRowCodeSequence), 4, "0"); - - String newSampleRowCode = newSampleRowCodePrefix + newSampleRowCodeSuffix; - - if (log.isInfoEnabled()) { - log.info("new sample row code for " + obsProgram + " is " + newSampleRowCode); - } - - return newSampleRowCode; - - } - - public void preValidate(AuthenticatedWaoUser authenticatedWaoUser, UpdateSampleRowCommand updateSampleRowCommand) - throws UnknownBoatImmatriculationsException, SampleRowCodeMustBeUniqueException { - - SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); - - SampleRowTopiaDao dao = getSampleRowDao(); - 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)) { - throw new SampleRowCodeMustBeUniqueException(); - } - - String elligibleBoatImmatriculations = updateSampleRowCommand.getElligibleBoatImmatriculations(); - - List<Boat> elligibleBoats = getReferentialService().getBoatsFromImmatriculations(elligibleBoatImmatriculations); - ElligibleBoatTopiaDao elligibleBoatDao = getElligibleBoatDao(); - - for (Boat boat : elligibleBoats) { - ElligibleBoat elligibleBoat = sampleRow.getElligibleBoatByBoat(boat); - if (elligibleBoat == null) { - elligibleBoat = new ElligibleBoatImpl(); - elligibleBoat.setSampleRow(sampleRow); - elligibleBoat.setBoat(boat); - elligibleBoatDao.create(elligibleBoat); - } - if (authenticatedWaoUser.isAdmin()) { - elligibleBoat.setGlobalActive(true); - } else if (authenticatedWaoUser.isCoordinator()) { - elligibleBoat.setCompanyActive(true); - } - elligibleBoatDao.update(elligibleBoat); - } - - if (sampleRow.isElligibleBoatNotEmpty()) { - for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { - Boat boat = elligibleBoat.getBoat(); - boolean isNoLongerActive = !elligibleBoats.contains(boat); - if (isNoLongerActive) { - if (authenticatedWaoUser.isAdmin()) { - elligibleBoat.setGlobalActive(false); - } else if (authenticatedWaoUser.isCoordinator()) { - elligibleBoat.setCompanyActive(null); - } - } - } - } - - SampleMonthTopiaDao sampleMonthDao = getSampleMonthDao(); - - Set<SampleMonth> sampleMonthsToRemove = new HashSet<>(sampleRow.getSampleMonth()); - Map<String, Integer> expectedObservationsByMonths = updateSampleRowCommand.getExpectedObservationsByMonths(); - for (Map.Entry<String, Integer> entry : expectedObservationsByMonths.entrySet()) { - Date month; - try { - month = updateSampleRowCommand.monthFormat.parse(entry.getKey()); - } catch (ParseException e) { - throw new IllegalArgumentException(expectedObservationsByMonths.toString(), e); - } - SampleMonth sampleMonth = sampleRow.getSampleMonth(month); - Integer expectedObservations = entry.getValue(); - if (expectedObservations == null) { - if (sampleMonth != null) { - // rien à faire, il va être supprimé - } - } else { - if (sampleMonth == null) { - sampleMonth = new SampleMonthImpl(); - sampleMonth.setPeriodDate(month); - sampleRow.addSampleMonth(sampleMonth); - sampleMonthDao.create(sampleMonth); - if (log.isTraceEnabled()) { - log.trace("created sample month " + sampleMonth); - } - } else { - sampleMonthsToRemove.remove(sampleMonth); - if (log.isTraceEnabled()) { - log.trace("will keep " + sampleMonth); - } - } - sampleMonth.setExpectedTidesValue(expectedObservations); - sampleMonthDao.update(sampleMonth); - } - } - - for (SampleMonth sampleMonth : sampleMonthsToRemove) { - if (log.isTraceEnabled()) { - log.trace("will remove " + sampleMonth); - } - sampleRow.removeSampleMonth(sampleMonth); - sampleMonthDao.delete(sampleMonth); - } - - } - - public void save(UpdateSampleRowCommand updateSampleRowCommand) { - - SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); - - if (!updateSampleRowCommand.isCreation()) { - SampleRowLog sampleRowLog = updateSampleRowCommand.getSampleRowLog(); - getSampleRowLogDao().create(sampleRowLog); - sampleRowLog.setLogText(updateSampleRowCommand.getSampleRowMemento(), sampleRow); - } - - ElligibleBoatTopiaDao elligibleBoatDao = getElligibleBoatDao(); - if (sampleRow.isElligibleBoatNotEmpty()) { - for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { - if (elligibleBoat.isPersisted()) { - elligibleBoatDao.update(elligibleBoat); - } else { - elligibleBoatDao.create(elligibleBoat); - } - } - } - - ProfessionTopiaDao professionDao = getProfessionDao(); - Profession profession = sampleRow.getProfession(); - if (profession.isPersisted()) { - professionDao.update(profession); - } else { - professionDao.create(profession); - } - - SampleRowTopiaDao dao = getSampleRowDao(); - if (sampleRow.isPersisted()) { - dao.update(sampleRow); - } else { - dao.create(sampleRow); - } - commit(); - - } - - public void commentSampleRow(AuthenticatedWaoUser authenticatedWaoUser, String sampleRowId, String comment) { - - SampleRow sampleRow = getSampleRow(sampleRowId); - - SampleRowLog sampleRowLog = new SampleRowLogImpl(); - sampleRowLog.setFromAdmin(authenticatedWaoUser.isAdmin()); - sampleRowLog.setComment(comment); - sampleRowLog.setAuthor(authenticatedWaoUser.getWaoUser()); - - sampleRow.addSampleRowLog(sampleRowLog); - - commit(); - - } - public ObsMerSamplingPlan getSamplingPlan( AuthenticatedWaoUser authenticatedWaoUser, SampleRowsFilter sampleRowsFilter) { @@ -388,10 +63,10 @@ optionalCompanyId, sampleRowsFilter); - Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> samplingPlansCache = + Cache<SamplingPlanCacheKey, SamplingPlan> samplingPlansCache = serviceContext.getSamplingPlansCache(); - ObsMerSamplingPlan result = samplingPlansCache.getIfPresent(samplingPlanCacheKey); + ObsMerSamplingPlan result = (ObsMerSamplingPlan) samplingPlansCache.getIfPresent(samplingPlanCacheKey); if (result == null) { @@ -441,109 +116,6 @@ } - public void importSamplingPlan(AuthenticatedWaoUser authenticatedWaoUser, InputStream csv) throws ImportErrorException { - - ImportModel<SampleRow> samplingPlanImportModel = - newSamplingPlanImportModel(authenticatedWaoUser); - - Import<SampleRow> samplingPlanImport = - Import.newImport(samplingPlanImportModel, csv); - - SampleRowTopiaDao dao = getSampleRowDao(); - - try { - - for (SampleRow sampleRow : samplingPlanImport) { - - if (StringUtils.isBlank(sampleRow.getCode())) { - - String newSampleRowCode = getNewSampleRowCode(ObsProgram.OBSMER); - - sampleRow.setCode(newSampleRowCode); - - } else { - - // TODO brendan 18/03/14 - - } - - getProfessionDao().create(sampleRow.getProfession()); - - dao.create(sampleRow); - - } - - } catch (ImportRuntimeException e) { - throw new ImportErrorException(e); - } - - commit(); - - } - - protected ImportModel<SampleRow> newSamplingPlanImportModel(AuthenticatedWaoUser authenticatedWaoUser) { - - ObsProgram obsProgram = authenticatedWaoUser.getObsProgram(); - - CompanyTopiaDao companyDao = getCompanyDao(); - List<Company> activeCompanies = companyDao.forActiveEquals(true).findAll(); - - TerrestrialLocationTopiaDao terrestrialLocationDao = getTerrestrialLocationDao(); - List<TerrestrialLocation> terrestrialDistricts = - terrestrialLocationDao.forLocationTypeEquals(LocationType.DISTRICT).findAll(); - - FishingZoneTopiaDao fishingZoneDao = getFishingZoneDao(); - List<FishingZone> fishingZones = fishingZoneDao.findAll(); - - ReferentialService referentialService = getReferentialService(); - - ImportModel<SampleRow> samplingPlanImportModel = - new ObsMerObsVenteSamplingPlanImportExportModel(getLocale(), - obsProgram, - activeCompanies, - fishingZones, - terrestrialDistricts, - referentialService); - - return samplingPlanImportModel; - - } - - public InputStream exportSamplingPlan(SampleRowsFilter filter) { - - Preconditions.checkArgument(filter.getPeriodFrom() != null); - Preconditions.checkArgument(filter.getPeriodTo() != null); - - // ignore pagination when exporting - filter.setOrderByArguments(ImmutableSet.of(SampleRow.PROPERTY_CODE)); - - SampleRowTopiaDao dao = getSampleRowDao(); - - List<SampleRow> sampleRows = dao.findAll(filter); - - ExportModel<SampleRow> exportModel = - new ObsMerObsVenteSamplingPlanImportExportModel( - getLocale(), - filter.getPeriodFrom(), - filter.getPeriodTo(), - ObsProgram.OBSMER); - - Export<SampleRow> 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); - } - - } - /** * Récupérer l'effort d'observation en nombre de jours plannifié poru * le sample row donné pendant la période donnée. @@ -553,9 +125,9 @@ * @param sampleRow la ligne à filtrer * @return l'effort plannifié calculé */ - public double getObservationTimesInDayExpected(Date periodFrom, - Date periodTo, - SampleRow sampleRow) { + protected double getObservationTimesInDayExpected(Date periodFrom, + Date periodTo, + SampleRow sampleRow) { Range<Date> period = Range.closed(periodFrom, periodTo); @@ -587,7 +159,7 @@ * @param periodTo la date jusqu'à laquelle on compte les contacts * @return la paire (effort réalisé - effort estimé) calculée */ - public Pair<Long, Long> getSampleRowObservationTimesInDayRealAndEstimated(String sampleRowId, Date periodFrom, Date periodTo) { + protected Pair<Long, Long> getSampleRowObservationTimesInDayRealAndEstimated(String sampleRowId, Date periodFrom, Date periodTo) { // D'abord, on a besoin de récupérer toutes les observations réalisées // pour cette ligne du plan @@ -637,96 +209,4 @@ return Pair.of(real, estimated); } - public void deleteSampleRow(String sampleRowId) throws IllegalDeletionException { - - SampleRowTopiaDao dao = getSampleRowDao(); - - SampleRow sampleRow = dao.findByTopiaId(sampleRowId); - - SampleMonthTopiaDao sampleMonthDao = getSampleMonthDao(); - for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { - sampleMonthDao.delete(sampleMonth); - } - sampleRow.clearSampleMonth(); - - SampleRowLogTopiaDao sampleRowLogDao = getSampleRowLogDao(); - for (SampleRowLog sampleRowLog : sampleRow.getSampleRowLog()) { - sampleRowLogDao.delete(sampleRowLog); - } - sampleRow.clearSampleRowLog(); - - ElligibleBoatTopiaDao elligibleBoatDao = getElligibleBoatDao(); - for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { - elligibleBoatDao.delete(elligibleBoat); - } - sampleRow.clearElligibleBoat(); - - sampleRow.clearFishingZone(); - - if (sampleRow.getProfession() != null) { - ProfessionTopiaDao professionDao = getProfessionDao(); - professionDao.delete(sampleRow.getProfession()); - sampleRow.setProfession(null); - } - - Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> allUsages = dao.findAllUsages(sampleRow); - - if (allUsages.isEmpty()) { - dao.delete(sampleRow); - } else { - throw new IllegalDeletionException(allUsages); - } - - commit(); - - } - - public void recomputeSampleRowEstimatedAndRealTides(SampleRow sampleRow) { - - //---- - // Reset des tides de la ligne - //---- - - for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { - sampleMonth.setEstimatedTidesValue(0); - sampleMonth.setRealTidesValue(0); - } - - //---- - // Recuperation de tous les contacts de la ligne - //---- - - ContactsFilter contactFilter = new ContactsFilter(); - - contactFilter.setFilterOnObservationBeginDate(true); - contactFilter.getSampleRowFilter().setSampleRowIds(Sets.newHashSet(sampleRow.getTopiaId())); - - contactFilter.setContactStates(ImmutableSet.of(ContactState.OBSERVATION_DONE)); - // on exclue les contacts qui sont invalidés par le programme - contactFilter.setProgramAcceptations(Sets.newHashSet(true, null)); - // on exclue les contacts invalidés par la société - contactFilter.setCompanyAcceptations(Sets.newHashSet(true, null)); - - Collection<Contact> contacts = getContactDao().forFilter(contactFilter, false).findAll(); - - //---- - // Recalcul des tides - //---- - - for (Contact contact : contacts) { - - Date observationBeginDate = contact.getObservationBeginDate(); - - SampleMonth month = sampleRow.getSampleMonth(observationBeginDate); - - month.setEstimatedTidesValue(month.getEstimatedTidesValue() + 1); - - if (BooleanUtils.isTrue(contact.getValidationCompany())) { - month.setRealTidesValue(month.getRealTidesValue() + 1); - } - - } - - } - } Copied: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlan.java (from rev 2075, branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlan.java) =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlan.java (rev 0) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlan.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,77 @@ +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.entity.SampleRow; +import fr.ifremer.wao.entity.TerrestrialLocation; +import org.apache.commons.collections4.CollectionUtils; + +import java.util.Collection; +import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +public class ObsVenteSamplingPlan extends SamplingPlan implements Iterable<SamplingPlan.SamplingPlanFacadePart> { + + public ObsVenteSamplingPlan(List<Date> months, Collection<SamplingPlanFacadePart> facadeParts, Map<Date, SamplingPlanStatistics> totalsPerMonth, SamplingPlanStatistics highTotals, SampleRowsFilterValues filterValues, Set<String> sampleRowIds) { + super(months, facadeParts, totalsPerMonth, highTotals, filterValues, sampleRowIds); + } + + public static class ObsVenteSamplingPlanSampleRowPart extends SamplingPlanSampleRowPart { + + protected Map<String, String> terrestrialLocationNamesAndDescriptions; + + protected String terrestrialLocationInfos; + + protected int averageObservationsCount; + + public ObsVenteSamplingPlanSampleRowPart(Locale locale, Map<Date, SamplingPlanStatistics> nbTidesPerMonth, SampleRow sampleRow) { + super(locale, nbTidesPerMonth, sampleRow); + terrestrialLocationInfos = sampleRow.getTerrestrialLocationInfos(); + terrestrialLocationNamesAndDescriptions = new LinkedHashMap<>(); + if (CollectionUtils.isNotEmpty(sampleRow.getTerrestrialLocations())) { + for (TerrestrialLocation terrestrialLocation : sampleRow.getTerrestrialLocations()) { + String key = terrestrialLocation.getDistrictName(); + String description = terrestrialLocation.getDescription(); + terrestrialLocationNamesAndDescriptions.put(key, description); + } + } + averageObservationsCount = sampleRow.getAverageObservationsCount(); + } + + public String getTerrestrialLocationInfos() { + return terrestrialLocationInfos; + } + + public Map<String, String> getTerrestrialLocationNamesAndDescriptions() { + return terrestrialLocationNamesAndDescriptions; + } + + public int getAverageObservationsCount() { + return averageObservationsCount; + } + } + +} \ No newline at end of file Copied: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanBuilder.java (from rev 2075, branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanBuilder.java) =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanBuilder.java (rev 0) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanBuilder.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,322 @@ +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.Function; +import com.google.common.base.Optional; +import com.google.common.collect.Ordering; +import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SampleRows; +import org.apache.commons.lang3.mutable.MutableInt; +import org.nuiton.util.PeriodDates; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +/** + * @since 4.0 + */ +public class ObsVenteSamplingPlanBuilder { + + /** + * Incoming filter used. + */ + protected SampleRowsFilter sampleRowsFilter; + + /** + * Bean to hold all values that user can select to fill {@link fr.ifremer.wao.SampleRowsFilter}. + */ + protected SampleRowsFilterValues sampleRowsFilterValues; + + /** + * Ids of all the sample rows included in this sampling plan. + */ + protected Set<String> sampleRowIds; + + /** + * List of month computed from the filter. + */ + protected List<Date> months; + + /** + * Dictionnary of facades indexed by their facade name. + */ + protected Map<String, FacadeContext> facadeMap; + + /** + * To compute the high total expected. + * + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan#highTotals + */ + protected int highTotalExpected; + + /** + * To compute the high total real. + * + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan#highTotals + */ + protected int highTotalReal; + + /** + * To compute the high total estimated. + * + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan#highTotals + */ + protected int highTotalEstimated; + + /** + * To compute by month the total of expected tides. + * + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan.SamplingPlanStatistics#nbTidesExpected + */ + protected Map<Date, MutableInt> totalExpectedForMonths; + + /** + * To compute by month the total of expected tides. + * + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan.SamplingPlanStatistics#nbTidesEstimated + */ + protected Map<Date, MutableInt> totalEstimatedForMonths; + + /** + * To compute by month the total of real tides. + * + * @see fr.ifremer.wao.services.service.ObsMerSamplingPlan.SamplingPlanStatistics#nbTidesReal + */ + protected Map<Date, MutableInt> totalRealForMonths; + + public ObsVenteSamplingPlanBuilder(Locale locale, + Optional<String> optionalCompanyId, + SampleRowsFilter sampleRowsFilter) { + this.sampleRowsFilter = sampleRowsFilter; + this.sampleRowsFilterValues = new SampleRowsFilterValues(locale, ObsProgram.OBSMER, optionalCompanyId); + this.sampleRowIds = new HashSet<>(); + this.facadeMap = new TreeMap<>(); + this.totalExpectedForMonths = new TreeMap<>(); + this.totalRealForMonths = new TreeMap<>(); + this.totalEstimatedForMonths = new TreeMap<>(); + + PeriodDates periodDates = new PeriodDates(sampleRowsFilter.getPeriodFrom(), + sampleRowsFilter.getPeriodTo()); + this.months = periodDates.getMonths(); + } + + public ObsVenteSamplingPlanBuilder addSampleRow(SampleRow sampleRow) { + + 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 + SectorContext sectorPart = facadeContext.getOrAddSectorContext(sectors); + + // compute nb tides per month + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> nbTidesPerMonth = computeNbTidesPerMonth(sampleRow); + + // add sample row + sectorPart.addSampleRow(sampleRowsFilterValues.getLocale(), + sampleRow, + nbTidesPerMonth); + + sampleRowsFilterValues.addSampleRow(sampleRow); + + sampleRowIds.add(sampleRow.getTopiaId()); + + return this; + } + + public ObsVenteSamplingPlan toPlan() { + + // Get facade parts + Collection<SamplingPlan.SamplingPlanFacadePart> facadeParts = new ArrayList<>(); + for (FacadeContext facadeContext : facadeMap.values()) { + SamplingPlan.SamplingPlanFacadePart facadePart = facadeContext.toBean(); + facadeParts.add(facadePart); + } + + // Sort them + Collection<SamplingPlan.SamplingPlanFacadePart> sortedFacades = Ordering.natural().onResultOf(new Function<SamplingPlan.SamplingPlanFacadePart, String>() { + public String apply(SamplingPlan.SamplingPlanFacadePart input) { + return input.getFacade(); + } + }).immutableSortedCopy(facadeParts); + + // Get statistics + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> statisticsMap = new TreeMap<>(); + for (Date month : months) { + + MutableInt totalExpected = totalExpectedForMonths.get(month); + MutableInt totalReal = totalRealForMonths.get(month); + MutableInt totalEstimated = totalEstimatedForMonths.get(month); + ObsMerSamplingPlan.SamplingPlanStatistics planStatistics = + new ObsMerSamplingPlan.SamplingPlanStatistics(totalExpected == null ? null : totalExpected.toInteger(), + totalReal == null ? null : totalReal.toInteger(), + totalEstimated == null ? null : totalEstimated.toInteger()); + statisticsMap.put(month, planStatistics); + } + + ObsMerSamplingPlan.SamplingPlanStatistics highTotals = new ObsMerSamplingPlan.SamplingPlanStatistics(highTotalExpected, highTotalReal, highTotalEstimated); + + ObsVenteSamplingPlan result = new ObsVenteSamplingPlan(months, + sortedFacades, + statisticsMap, + highTotals, + sampleRowsFilterValues, + sampleRowIds); + return result; + } + + protected Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> computeNbTidesPerMonth(SampleRow sampleRow) { + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> result = new TreeMap<>(); + for (Date month : months) { + 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; + } + 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; + } + + 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.SamplingPlanStatistics(expectedTidesValue, + realTidesValue, + estimatedTidesValue)); + + } + return result; + } + + protected static class FacadeContext { + + protected String facade; + + protected Map<String, SectorContext> sectorMap; + + protected FacadeContext(String facade) { + this.facade = facade; + this.sectorMap = new TreeMap<>(); + } + + protected SectorContext getOrAddSectorContext(String sectors) { + SectorContext sectorPart = sectorMap.get(sectors); + if (sectorPart == null) { + + // register a new sector + sectorPart = new SectorContext(sectors); + sectorMap.put(sectors, sectorPart); + } + return sectorPart; + } + + protected SamplingPlan.SamplingPlanFacadePart toBean() { + + // get sector parts + Collection<SamplingPlan.SamplingPlanSectorPart> sectorParts = new ArrayList<>(); + for (SectorContext sectorContext : sectorMap.values()) { + SamplingPlan.SamplingPlanSectorPart sectorPart = sectorContext.toBean(); + sectorParts.add(sectorPart); + } + // sort them + Collection<SamplingPlan.SamplingPlanSectorPart> sortedSectors = Ordering.natural().onResultOf(new Function<SamplingPlan.SamplingPlanSectorPart, String>() { + public String apply(SamplingPlan.SamplingPlanSectorPart input) { + return input.getSectors(); + } + }).immutableSortedCopy(sectorParts); + SamplingPlan.SamplingPlanFacadePart result = + new SamplingPlan.SamplingPlanFacadePart(facade, sortedSectors); + return result; + } + } + + protected static class SectorContext { + + protected String sectors; + + protected Collection<ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart> rows; + + protected SectorContext(String sectors) { + this.sectors = sectors; + this.rows = new ArrayList<>(); + } + + protected ObsMerSamplingPlan.SamplingPlanSampleRowPart addSampleRow(Locale locale, + SampleRow row, + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> nbTidesPerMonth) { + + ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart rowPart = + new ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart(locale, + nbTidesPerMonth, + row); + rows.add(rowPart); + + return rowPart; + } + + protected SamplingPlan.SamplingPlanSectorPart toBean() { + + Collection<ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart> sortedRows = Ordering.natural().onResultOf(new Function<ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart, String>() { + public String apply(ObsVenteSamplingPlan.ObsVenteSamplingPlanSampleRowPart input) { + return input.getCode(); + } + }).immutableSortedCopy(rows); + SamplingPlan.SamplingPlanSectorPart result = + new SamplingPlan.SamplingPlanSectorPart(sectors, sortedRows); + return result; + } + } +} Added: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanService.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanService.java (rev 0) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/ObsVenteSamplingPlanService.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,70 @@ +package fr.ifremer.wao.services.service; + +import com.google.common.base.Optional; +import com.google.common.cache.Cache; +import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.WaoUtils; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SampleRowTopiaDao; +import fr.ifremer.wao.services.AuthenticatedWaoUser; + +import java.util.Date; +import java.util.List; + +public class ObsVenteSamplingPlanService extends SamplingPlanService { + + public ObsVenteSamplingPlan getSamplingPlan( + AuthenticatedWaoUser authenticatedWaoUser, + SampleRowsFilter sampleRowsFilter) { + + Optional<String> optionalCompanyId = Optional.absent(); + if (authenticatedWaoUser.isCoordinatorOrObserver()) { + optionalCompanyId = Optional.of(authenticatedWaoUser.getCompany().getTopiaId()); + } + + SamplingPlanCacheKey samplingPlanCacheKey = + new SamplingPlanCacheKey( + serviceContext.getLocale(), + optionalCompanyId, + sampleRowsFilter); + + Cache<SamplingPlanCacheKey, SamplingPlan> samplingPlansCache = + serviceContext.getSamplingPlansCache(); + + ObsVenteSamplingPlan result = (ObsVenteSamplingPlan) samplingPlansCache.getIfPresent(samplingPlanCacheKey); + + if (result == null) { + + SampleRowTopiaDao dao = getSampleRowDao(); + + // recuperation des lignes du plan + List<SampleRow> sampleRows = dao.findAll(sampleRowsFilter); + + // creation du plan d'echantillonnage + ObsVenteSamplingPlanBuilder builder = new ObsVenteSamplingPlanBuilder( + serviceContext.getLocale(), + optionalCompanyId, + sampleRowsFilter); + + // begin of month + Date periodFrom = sampleRowsFilter.getPeriodFrom(); + // end of month + Date periodTo = WaoUtils.getEndOfMonth(sampleRowsFilter.getPeriodTo()); + + for (SampleRow sampleRow : sampleRows) { + + // ajout de la ligne au build de plan + builder.addSampleRow(sampleRow); + + } + result = builder.toPlan(); + + samplingPlansCache.put(samplingPlanCacheKey, result); + + } + + return result; + + } + +} Added: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlan.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlan.java (rev 0) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlan.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,542 @@ +package fr.ifremer.wao.services.service; + +import fr.ifremer.wao.WaoUtils; +import fr.ifremer.wao.entity.DCF5Code; +import fr.ifremer.wao.entity.FishingZone; +import fr.ifremer.wao.entity.SampleMonth; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SampleRowLog; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.nuiton.util.DateUtil; + +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.Locale; +import java.util.Map; +import java.util.Set; + +public abstract class SamplingPlan implements Iterable<SamplingPlan.SamplingPlanFacadePart>, Serializable { + + /** + * List of month used by sample rows. + */ + protected List<Date> months; + + /** + * All facades of the sampling plan. + */ + protected Collection<SamplingPlanFacadePart> facades; + + /** + * Total tides over the plan by month. + */ + protected Map<Date, SamplingPlanStatistics> totalsPerMonth; + + /** + * High total over the hole plan. + */ + protected SamplingPlanStatistics highTotals; + + /** + * Universe of filter values. + */ + protected SampleRowsFilterValues filterValues; + + /** + * Ids of all the sample rows included in this sampling plan. + */ + protected Set<String> sampleRowIds; + + public SamplingPlan(List<Date> months, + Collection<SamplingPlanFacadePart> facadeParts, + Map<Date, SamplingPlanStatistics> totalsPerMonth, + SamplingPlanStatistics highTotals, + SampleRowsFilterValues filterValues, + Set<String> sampleRowIds) { + this.months = months; + this.facades = facadeParts; + this.totalsPerMonth = totalsPerMonth; + this.highTotals = highTotals; + this.filterValues = filterValues; + this.sampleRowIds = sampleRowIds; + } + + public static class SamplingPlanStatistics implements Serializable { + + private static final long serialVersionUID = 1L; + + /** + * Number of expected tides. + */ + protected Integer nbTidesExpected; + + /** + * Number of real tides. + */ + protected Integer nbTidesReal; + + /** + * Number of estimated tides. + */ + protected Integer nbTidesEstimated; + + public SamplingPlanStatistics(Integer nbTidesExpected, + Integer nbTidesReal, + Integer nbTidesEstimated) { + this.nbTidesExpected = nbTidesExpected; + this.nbTidesReal = nbTidesReal; + this.nbTidesEstimated = nbTidesEstimated; + } + + public Integer getNbTidesExpected() { + return nbTidesExpected; + } + + public Integer getNbTidesReal() { + return nbTidesReal; + } + + public Integer getNbTidesEstimated() { + return nbTidesEstimated; + } + + public String getRealRatio(String defaultValue) { + String ratio = defaultValue; + if (nbTidesExpected != null && nbTidesExpected > 0 && + nbTidesReal != null && nbTidesReal > 0) { + double percent = ((double) nbTidesReal / nbTidesExpected); + ratio = NumberFormat.getPercentInstance().format(percent); + } + return ratio; + } + + public String getEstimatedRatio(String defaultValue) { + String ratio = defaultValue; + if (nbTidesExpected != null && nbTidesExpected > 0 && + nbTidesEstimated != null && nbTidesEstimated > 0) { + double percent = ((double) nbTidesEstimated / nbTidesExpected); + ratio = NumberFormat.getPercentInstance().format(percent); + } + return ratio; + } + + @Override + public String toString() { + String toString = ToStringBuilder.reflectionToString(this); + return toString; + } + + } + + public SampleRowsFilterValues getFilterValues() { + return filterValues; + } + + /** + * 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 SamplingPlanFacadePart implements Iterable<SamplingPlanSectorPart>, Serializable { + + private static final long serialVersionUID = 1L; + + protected String facade; + + /** + * All sector parts for this facade. + */ + protected Collection<SamplingPlanSectorPart> sectors; + + public SamplingPlanFacadePart(String facade, + Collection<SamplingPlanSectorPart> sectors) { + this.facade = facade; + this.sectors = sectors; + } + + public String getFacade() { + return facade; + } + + @Override + public Iterator<SamplingPlanSectorPart> iterator() { + return sectors.iterator(); + } + } + + /** + * Contains sample rows of a same sectors. + */ + public static class SamplingPlanSectorPart<T extends SamplingPlanSampleRowPart> implements Iterable<T>, Serializable { + + private static final long serialVersionUID = 1L; + + protected String sectors; + + protected Collection<T> sampleRows; + + public SamplingPlanSectorPart(String sectors, + Collection<T> sampleRows) { + this.sectors = sectors; + this.sampleRows = sampleRows; + } + + public String getSectors() { + return sectors; + } + + @Override + public Iterator<T> iterator() { + return sampleRows.iterator(); + } + } + + public Integer getTotalExpected(Date month) { + Integer result = totalsPerMonth.get(month).getNbTidesExpected(); + return result; + } + + public Integer getTotalReal(Date month) { + Integer result = totalsPerMonth.get(month).getNbTidesReal(); + return result; + } + + public Integer getTotalEstimated(Date month) { + Integer result = totalsPerMonth.get(month).getNbTidesEstimated(); + return result; + } + + public String getTotalRealRatio(Date month) { + String result = totalsPerMonth.get(month).getRealRatio("-"); + return result; + } + + public String getTotalEstimatedRatio(Date month) { + String result = totalsPerMonth.get(month).getEstimatedRatio("-"); + return result; + } + + public Integer getHighTotalExpected() { + return highTotals.getNbTidesExpected(); + } + + public Integer getHighTotalReal() { + return highTotals.getNbTidesReal(); + } + + public Integer getHighTotalEstimated() { + return highTotals.getNbTidesEstimated(); + } + + public String getHighTotalRealRatio() { + String ratio = highTotals.getRealRatio(""); + return ratio; + } + + public String getHighTotalEstimatedRatio() { + String ratio = highTotals.getEstimatedRatio(""); + return ratio; + } + + public Set<String> getSampleRowIds() { + return sampleRowIds; + } + + @Override + public Iterator<SamplingPlanFacadePart> iterator() { + return facades.iterator(); + } + + public List<Date> getMonths() { + return months; + } + + + /** + * Created on 3/24/14. + * + * @author Tony Chemit <chemit@codelutin.com> + * @since 4.0 + */ + public abstract static class SamplingPlanSampleRowPart implements Serializable { + + /** + * Nb tides by month. + */ + protected Map<Date, SamplingPlanStatistics> nbTidesPerMonth; + + /** + * Total of tides. + */ + protected SamplingPlanStatistics totalTides; + + protected String fishingZones; + + protected String code; + + protected String fishingZonesInfos; + + protected String comment; + + protected String programName; + + protected Date periodBegin; + + protected Date periodEnd; + + 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 String sampleRowId; + + /** + * Date of the latest sample log. + */ + protected Date latestSampleLogCreateDate; + + /** + * First sample month date. + */ + protected Date firstSampleMonthDate; + + /** + * Last sample month date. + */ + protected Date lastSampleMonthDate; + + /** + * Last sample month end of month. + */ + protected Date lastSampleMonthEndOfMonth; + + protected boolean elligibleBoatsProvided; + + public SamplingPlanSampleRowPart(Locale locale, + Map<Date, SamplingPlanStatistics> nbTidesPerMonth, + SampleRow sampleRow) { + this.nbTidesPerMonth = nbTidesPerMonth; + // compute total tides + int totalTidesExpected = 0; + int totalTidesEstimated = 0; + int totalTidesReal = 0; + for (SamplingPlanStatistics samplingPlanStatistics : nbTidesPerMonth.values()) { + Integer totalExpected = samplingPlanStatistics.getNbTidesExpected(); + if (totalExpected != null) { + totalTidesExpected += totalExpected; + } + Integer totalEstimated = samplingPlanStatistics.getNbTidesEstimated(); + if (totalEstimated != null) { + totalTidesEstimated += totalEstimated; + } + Integer totalReal = samplingPlanStatistics.getNbTidesReal(); + if (totalReal != null) { + totalTidesReal += totalReal; + } + } + totalTides = new SamplingPlanStatistics(totalTidesExpected, totalTidesReal, totalTidesEstimated); + fishingZones = ""; + for (FishingZone zone : sampleRow.getFishingZone()) { + fishingZones += zone.getDistrictCode() + ", "; + } + fishingZones = fishingZones.substring(0, fishingZones.length() - 2); + fishingZonesInfos = sampleRow.getFishingZonesInfos(); + comment = sampleRow.getComment(); + programName = sampleRow.getProgramName(); + periodBegin = sampleRow.getPeriodBegin(); + periodEnd = sampleRow.getPeriodEnd(); + 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() + " - " + WaoUtils.l(locale, dcf5Code.getFishingGearDCF()); + if (dcf5Code.getTargetSpeciesCode() != null) { + description += " ; " + dcf5Code.getTargetSpeciesCode() + " - " + WaoUtils.l(locale, dcf5Code.getTargetSpeciesDCF()); + } + dcf5CodesAndDescriptions.put(key, description); + } + + professionDescriptionWithoutDCF5 = sampleRow.getProfessionDescriptionWithoutDCF5(); + samplingStrategy = WaoUtils.l(locale, sampleRow.getSamplingStrategy()); + sampleRowId = sampleRow.getTopiaId(); + + // consider a recently created sample row as recently updated + latestSampleLogCreateDate = sampleRow.getTopiaCreateDate(); + // compute lastSampleLogCreateDate + if (sampleRow.isSampleRowLogNotEmpty()) { + for (SampleRowLog sampleRowLog : sampleRow.getSampleRowLog()) { + if (sampleRowLog.getCreateDate().after(latestSampleLogCreateDate)) { + latestSampleLogCreateDate = sampleRowLog.getCreateDate(); + } + } + } + + // compute sampleRowPeriod + // TODO brendan 15/04/14 use treeset + List<SampleMonth> sampleMonth = new ArrayList<>(sampleRow.getSampleMonth()); + firstSampleMonthDate = sampleMonth.get(0).getPeriodDate(); + lastSampleMonthDate = sampleMonth.get(sampleMonth.size() - 1).getPeriodDate(); + + lastSampleMonthEndOfMonth = WaoUtils.getEndOfMonth(lastSampleMonthDate); + elligibleBoatsProvided = sampleRow.isElligibleBoatNotEmpty(); + } + + public String getSamplingStrategy() { + return samplingStrategy; + } + + public String getSampleRowId() { + return sampleRowId; + } + + public Date getFirstSampleMonthDate() { + return firstSampleMonthDate; + } + + public Date getLastSampleMonthDate() { + return lastSampleMonthDate; + } + + public String getCode() { + return code; + } + + public String getFishingZonesInfos() { + return fishingZonesInfos; + } + + public String getProfessionSize() { + return professionSize; + } + + public Map<String, String> getDcf5CodesAndDescriptions() { + return dcf5CodesAndDescriptions; + } + + public String getComment() { + return comment; + } + + public String getProgramName() { + return programName; + } + + public Date getPeriodBegin() { + return periodBegin; + } + + public Date getPeriodEnd() { + return periodEnd; + } + + 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 totalTides.getNbTidesExpected(); + } + + public int getTotalTidesReal() { + return totalTides.getNbTidesReal(); + } + + public int getTotalTidesEstimated() { + return totalTides.getNbTidesEstimated(); + } + + public String getProfessionDescriptionWithoutDCF5() { + return professionDescriptionWithoutDCF5; + } + + public Integer getNbTidesExpected(Date month) { + Integer result = nbTidesPerMonth.get(month).getNbTidesExpected(); + return result; + } + + public Integer getNbTidesReal(Date month) { + Integer result = nbTidesPerMonth.get(month).getNbTidesReal(); + return result; + } + + public Integer getNbTidesEstimated(Date month) { + Integer result = nbTidesPerMonth.get(month).getNbTidesEstimated(); + return result; + } + + public String getTotalRealPercentage() { + String result = totalTides.getRealRatio("-"); + return result; + } + + public String getTotalEstimatedPercentage() { + String result = totalTides.getEstimatedRatio("-"); + return result; + } + + public String getFishingZones() { + return fishingZones; + } + + public boolean isElligibleBoatsProvided() { + return elligibleBoatsProvided; + } + + public boolean isRecentlyUpdated() { + boolean isRecentlyUpdated = latestSampleLogCreateDate != null + && DateUtil.getDifferenceInDays(latestSampleLogCreateDate, new Date()) <= 2 * 7; + return isRecentlyUpdated; + } + + public boolean isNewContactCreatable() { + boolean isNewContactCreatable = new Date().before(lastSampleMonthEndOfMonth); + return isNewContactCreatable; + } + } + +} Modified: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -1,19 +1,74 @@ package fr.ifremer.wao.services.service; +import com.google.common.base.Charsets; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; +import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import fr.ifremer.wao.ContactsFilter; import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.WaoTechnicalException; +import fr.ifremer.wao.entity.Boat; +import fr.ifremer.wao.entity.Boats; +import fr.ifremer.wao.entity.Company; +import fr.ifremer.wao.entity.CompanyTopiaDao; +import fr.ifremer.wao.entity.Contact; +import fr.ifremer.wao.entity.ContactState; +import fr.ifremer.wao.entity.DCF5Code; +import fr.ifremer.wao.entity.ElligibleBoat; +import fr.ifremer.wao.entity.ElligibleBoatImpl; +import fr.ifremer.wao.entity.ElligibleBoatTopiaDao; +import fr.ifremer.wao.entity.FishingZone; +import fr.ifremer.wao.entity.FishingZoneTopiaDao; +import fr.ifremer.wao.entity.LocationType; +import fr.ifremer.wao.entity.ObsProgram; +import fr.ifremer.wao.entity.Profession; +import fr.ifremer.wao.entity.ProfessionImpl; +import fr.ifremer.wao.entity.ProfessionTopiaDao; +import fr.ifremer.wao.entity.SampleMonth; +import fr.ifremer.wao.entity.SampleMonthImpl; +import fr.ifremer.wao.entity.SampleMonthTopiaDao; import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.entity.SampleRowImpl; +import fr.ifremer.wao.entity.SampleRowLog; +import fr.ifremer.wao.entity.SampleRowLogImpl; +import fr.ifremer.wao.entity.SampleRowLogTopiaDao; import fr.ifremer.wao.entity.SampleRowTopiaDao; +import fr.ifremer.wao.entity.SamplingStrategy; +import fr.ifremer.wao.entity.TerrestrialLocation; +import fr.ifremer.wao.entity.TerrestrialLocationTopiaDao; import fr.ifremer.wao.services.AuthenticatedWaoUser; +import fr.ifremer.wao.services.service.administration.ReferentialService; +import fr.ifremer.wao.services.service.administration.UnknownBoatImmatriculationsException; +import fr.ifremer.wao.services.service.csv.ObsMerObsVenteSamplingPlanImportExportModel; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.csv.Export; +import org.nuiton.csv.ExportModel; +import org.nuiton.csv.Import; +import org.nuiton.csv.ImportModel; +import org.nuiton.csv.ImportRuntimeException; +import org.nuiton.topia.persistence.TopiaEntities; +import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.util.DateUtil; +import java.io.InputStream; +import java.text.ParseException; import java.util.Calendar; +import java.util.Collection; import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashSet; import java.util.List; +import java.util.Map; +import java.util.Set; public class SamplingPlanService extends WaoServiceSupport { @@ -27,6 +82,50 @@ } + /** + * On va rechercher en base pour générer un code qui n'existe pas déjà. + */ + protected String getNewSampleRowCode(ObsProgram obsProgram) { + + // On pré-définit un code pour la nouvelle ligne. + // au moment de la création d'une nouvelle ligne, on a aucune info donc + // on suppose que c'est pour l'année en cours + + Calendar begin = new GregorianCalendar(); + begin.setTime(getNow()); + int year = begin.get(Calendar.YEAR); + + String newSampleRowCodePrefix = year + "_" + obsProgram.getShortCode(); + + SampleRowTopiaDao dao = getSampleRowDao(); + + Optional<String> optionalMaxSampleRowCode = dao.findMaxSampleRowCode(newSampleRowCodePrefix); + int maxSampleRowCodeSequence; + if (optionalMaxSampleRowCode.isPresent()) { + String maxSampleRowCode = optionalMaxSampleRowCode.get(); + if (log.isDebugEnabled()) { + log.debug("max code found : " + maxSampleRowCode); + } + String sequenceStr = StringUtils.removeStart(maxSampleRowCode, newSampleRowCodePrefix); + maxSampleRowCodeSequence = Integer.parseInt(sequenceStr); + } else { + maxSampleRowCodeSequence = 0; + } + + maxSampleRowCodeSequence += 1; + + String newSampleRowCodeSuffix = StringUtils.leftPad(String.valueOf(maxSampleRowCodeSequence), 4, "0"); + + String newSampleRowCode = newSampleRowCodePrefix + newSampleRowCodeSuffix; + + if (log.isInfoEnabled()) { + log.info("new sample row code for " + obsProgram + " is " + newSampleRowCode); + } + + return newSampleRowCode; + + } + public SampleRowsFilter newSampleRowsFilter(AuthenticatedWaoUser authenticatedWaoUser) { // all users can see only rows for the program they are logged for @@ -93,4 +192,432 @@ return unfinishedSampleRows; } + + public void commentSampleRow(AuthenticatedWaoUser authenticatedWaoUser, String sampleRowId, String comment) { + + SampleRow sampleRow = getSampleRow(sampleRowId); + + SampleRowLog sampleRowLog = new SampleRowLogImpl(); + sampleRowLog.setFromAdmin(authenticatedWaoUser.isAdmin()); + sampleRowLog.setComment(comment); + sampleRowLog.setAuthor(authenticatedWaoUser.getWaoUser()); + + sampleRow.addSampleRowLog(sampleRowLog); + + commit(); + + } + + public void deleteSampleRow(String sampleRowId) throws IllegalDeletionException { + + SampleRowTopiaDao dao = getSampleRowDao(); + + SampleRow sampleRow = dao.findByTopiaId(sampleRowId); + + SampleMonthTopiaDao sampleMonthDao = getSampleMonthDao(); + for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { + sampleMonthDao.delete(sampleMonth); + } + sampleRow.clearSampleMonth(); + + SampleRowLogTopiaDao sampleRowLogDao = getSampleRowLogDao(); + for (SampleRowLog sampleRowLog : sampleRow.getSampleRowLog()) { + sampleRowLogDao.delete(sampleRowLog); + } + sampleRow.clearSampleRowLog(); + + ElligibleBoatTopiaDao elligibleBoatDao = getElligibleBoatDao(); + for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { + elligibleBoatDao.delete(elligibleBoat); + } + sampleRow.clearElligibleBoat(); + + sampleRow.clearFishingZone(); + + if (sampleRow.getProfession() != null) { + ProfessionTopiaDao professionDao = getProfessionDao(); + professionDao.delete(sampleRow.getProfession()); + sampleRow.setProfession(null); + } + + Map<Class<? extends TopiaEntity>, List<? extends TopiaEntity>> allUsages = dao.findAllUsages(sampleRow); + + if (allUsages.isEmpty()) { + dao.delete(sampleRow); + } else { + throw new IllegalDeletionException(allUsages); + } + + commit(); + + } + + public UpdateSampleRowCommand newUpdateSampleRowCommand(AuthenticatedWaoUser authenticatedWaoUser, Optional<String> optionalSampleRowId) { + + Preconditions.checkState(authenticatedWaoUser.isAuthorizedToCreateSampleRow()); + + UpdateSampleRowCommand updateSampleRowCommand = new UpdateSampleRowCommand(); + + if (optionalSampleRowId.isPresent()) { + + String sampleRowId = optionalSampleRowId.get(); + + SampleRowTopiaDao sampleRowDao = getSampleRowDao(); + + SampleRow sampleRowMemento = sampleRowDao.findByTopiaId(sampleRowId); + sampleRowDao.detach(sampleRowMemento); + updateSampleRowCommand.setSampleRowMemento(sampleRowMemento); + + SampleRow sampleRow = sampleRowDao.findByTopiaId(sampleRowId); + updateSampleRowCommand.setSampleRow(sampleRow); + + updateSampleRowCommand.setCreation(false); + + SampleRowLogImpl newSampleRowLog = new SampleRowLogImpl(); + newSampleRowLog.setAuthor(authenticatedWaoUser.getWaoUser()); + newSampleRowLog.setFromAdmin(authenticatedWaoUser.isAdmin()); + updateSampleRowCommand.setSampleRowLog(newSampleRowLog); + sampleRow.addSampleRowLog(newSampleRowLog); + + Set<Boat> elligibleBoats = new HashSet<>(); + for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { + boolean boatIsElligibleForUser = + authenticatedWaoUser.isAdmin() && elligibleBoat.isGlobalActive() || + authenticatedWaoUser.isCoordinator() && BooleanUtils.isTrue(elligibleBoat.getCompanyActive()); + if (boatIsElligibleForUser) { + elligibleBoats.add(elligibleBoat.getBoat()); + } + } + String elligibleBoatImmatriculations = Boats.toImmatriculations(elligibleBoats); + updateSampleRowCommand.setElligibleBoatImmatriculations(elligibleBoatImmatriculations); + + } else { + + SampleRow newSampleRow = new SampleRowImpl(); + + newSampleRow.setObsProgram(ObsProgram.OBSMER); + newSampleRow.setProfession(new ProfessionImpl()); + newSampleRow.setFishingZone(new HashSet<FishingZone>()); + newSampleRow.setSampleMonth(new HashSet<SampleMonth>()); + + ObsProgram obsProgram = authenticatedWaoUser.getObsProgram(); + if (obsProgram.isObsMer()) { + newSampleRow.setSamplingStrategy(SamplingStrategy.SIMULTANEOUS_ALL_SPECIES); + } + + String newSampleRowCode = getNewSampleRowCode(obsProgram); + newSampleRow.setCode(newSampleRowCode); + + updateSampleRowCommand.setSampleRow(newSampleRow); + + updateSampleRowCommand.setCreation(true); + + } + + ImmutableMap<String, FishingZone> allFishingZones = + Maps.uniqueIndex( + getReferentialService().getAllFishingZones(), + TopiaEntities.getTopiaIdFunction() + ); + updateSampleRowCommand.setAllFishingZones(allFishingZones); + + ImmutableMap<String, Company> allCompanies = + Maps.uniqueIndex( + getCompaniesService().getAllCompanies(), + TopiaEntities.getTopiaIdFunction() + ); + updateSampleRowCommand.setAllCompanies(allCompanies); + + ImmutableMap<String, DCF5Code> allDcf5Codes = + Maps.uniqueIndex( + getReferentialService().getAllDcf5Codes(), + TopiaEntities.getTopiaIdFunction() + ); + updateSampleRowCommand.setAllDcf5Codes(allDcf5Codes); + + return updateSampleRowCommand; + + } + + public void preValidate(AuthenticatedWaoUser authenticatedWaoUser, UpdateSampleRowCommand updateSampleRowCommand) + throws UnknownBoatImmatriculationsException, SampleRowCodeMustBeUniqueException { + + SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); + + SampleRowTopiaDao dao = getSampleRowDao(); + 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)) { + throw new SampleRowCodeMustBeUniqueException(); + } + + String elligibleBoatImmatriculations = updateSampleRowCommand.getElligibleBoatImmatriculations(); + + List<Boat> elligibleBoats = getReferentialService().getBoatsFromImmatriculations(elligibleBoatImmatriculations); + ElligibleBoatTopiaDao elligibleBoatDao = getElligibleBoatDao(); + + for (Boat boat : elligibleBoats) { + ElligibleBoat elligibleBoat = sampleRow.getElligibleBoatByBoat(boat); + if (elligibleBoat == null) { + elligibleBoat = new ElligibleBoatImpl(); + elligibleBoat.setSampleRow(sampleRow); + elligibleBoat.setBoat(boat); + elligibleBoatDao.create(elligibleBoat); + } + if (authenticatedWaoUser.isAdmin()) { + elligibleBoat.setGlobalActive(true); + } else if (authenticatedWaoUser.isCoordinator()) { + elligibleBoat.setCompanyActive(true); + } + elligibleBoatDao.update(elligibleBoat); + } + + if (sampleRow.isElligibleBoatNotEmpty()) { + for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { + Boat boat = elligibleBoat.getBoat(); + boolean isNoLongerActive = !elligibleBoats.contains(boat); + if (isNoLongerActive) { + if (authenticatedWaoUser.isAdmin()) { + elligibleBoat.setGlobalActive(false); + } else if (authenticatedWaoUser.isCoordinator()) { + elligibleBoat.setCompanyActive(null); + } + } + } + } + + SampleMonthTopiaDao sampleMonthDao = getSampleMonthDao(); + + Set<SampleMonth> sampleMonthsToRemove = new HashSet<>(sampleRow.getSampleMonth()); + Map<String, Integer> expectedObservationsByMonths = updateSampleRowCommand.getExpectedObservationsByMonths(); + for (Map.Entry<String, Integer> entry : expectedObservationsByMonths.entrySet()) { + Date month; + try { + month = updateSampleRowCommand.monthFormat.parse(entry.getKey()); + } catch (ParseException e) { + throw new IllegalArgumentException(expectedObservationsByMonths.toString(), e); + } + SampleMonth sampleMonth = sampleRow.getSampleMonth(month); + Integer expectedObservations = entry.getValue(); + if (expectedObservations == null) { + if (sampleMonth != null) { + // rien à faire, il va être supprimé + } + } else { + if (sampleMonth == null) { + sampleMonth = new SampleMonthImpl(); + sampleMonth.setPeriodDate(month); + sampleRow.addSampleMonth(sampleMonth); + sampleMonthDao.create(sampleMonth); + if (log.isTraceEnabled()) { + log.trace("created sample month " + sampleMonth); + } + } else { + sampleMonthsToRemove.remove(sampleMonth); + if (log.isTraceEnabled()) { + log.trace("will keep " + sampleMonth); + } + } + sampleMonth.setExpectedTidesValue(expectedObservations); + sampleMonthDao.update(sampleMonth); + } + } + + for (SampleMonth sampleMonth : sampleMonthsToRemove) { + if (log.isTraceEnabled()) { + log.trace("will remove " + sampleMonth); + } + sampleRow.removeSampleMonth(sampleMonth); + sampleMonthDao.delete(sampleMonth); + } + + } + + public void save(UpdateSampleRowCommand updateSampleRowCommand) { + + SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); + + if (!updateSampleRowCommand.isCreation()) { + SampleRowLog sampleRowLog = updateSampleRowCommand.getSampleRowLog(); + getSampleRowLogDao().create(sampleRowLog); + sampleRowLog.setLogText(updateSampleRowCommand.getSampleRowMemento(), sampleRow); + } + + ElligibleBoatTopiaDao elligibleBoatDao = getElligibleBoatDao(); + if (sampleRow.isElligibleBoatNotEmpty()) { + for (ElligibleBoat elligibleBoat : sampleRow.getElligibleBoat()) { + if (elligibleBoat.isPersisted()) { + elligibleBoatDao.update(elligibleBoat); + } else { + elligibleBoatDao.create(elligibleBoat); + } + } + } + + ProfessionTopiaDao professionDao = getProfessionDao(); + Profession profession = sampleRow.getProfession(); + if (profession.isPersisted()) { + professionDao.update(profession); + } else { + professionDao.create(profession); + } + + SampleRowTopiaDao dao = getSampleRowDao(); + if (sampleRow.isPersisted()) { + dao.update(sampleRow); + } else { + dao.create(sampleRow); + } + commit(); + + } + + public InputStream exportSamplingPlan(SampleRowsFilter filter) { + + Preconditions.checkArgument(filter.getPeriodFrom() != null); + Preconditions.checkArgument(filter.getPeriodTo() != null); + + // ignore pagination when exporting + filter.setOrderByArguments(ImmutableSet.of(SampleRow.PROPERTY_CODE)); + + SampleRowTopiaDao dao = getSampleRowDao(); + + List<SampleRow> sampleRows = dao.findAll(filter); + + ExportModel<SampleRow> exportModel = + new ObsMerObsVenteSamplingPlanImportExportModel( + getLocale(), + filter.getPeriodFrom(), + filter.getPeriodTo(), + filter.getObsProgram()); + + Export<SampleRow> 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); + } + + } + + public void importSamplingPlan(AuthenticatedWaoUser authenticatedWaoUser, InputStream csv) throws ImportErrorException { + + ImportModel<SampleRow> samplingPlanImportModel = + newSamplingPlanImportModel(authenticatedWaoUser); + + Import<SampleRow> samplingPlanImport = + Import.newImport(samplingPlanImportModel, csv); + + SampleRowTopiaDao dao = getSampleRowDao(); + + try { + + for (SampleRow sampleRow : samplingPlanImport) { + + if (StringUtils.isBlank(sampleRow.getCode())) { + + String newSampleRowCode = getNewSampleRowCode(ObsProgram.OBSMER); + + sampleRow.setCode(newSampleRowCode); + + } + + getProfessionDao().create(sampleRow.getProfession()); + + dao.create(sampleRow); + + } + + } catch (ImportRuntimeException e) { + throw new ImportErrorException(e); + } + + commit(); + + } + + protected ImportModel<SampleRow> newSamplingPlanImportModel(AuthenticatedWaoUser authenticatedWaoUser) { + + ObsProgram obsProgram = authenticatedWaoUser.getObsProgram(); + + CompanyTopiaDao companyDao = getCompanyDao(); + List<Company> activeCompanies = companyDao.forActiveEquals(true).findAll(); + + TerrestrialLocationTopiaDao terrestrialLocationDao = getTerrestrialLocationDao(); + List<TerrestrialLocation> terrestrialDistricts = + terrestrialLocationDao.forLocationTypeEquals(LocationType.DISTRICT).findAll(); + + FishingZoneTopiaDao fishingZoneDao = getFishingZoneDao(); + List<FishingZone> fishingZones = fishingZoneDao.findAll(); + + ReferentialService referentialService = getReferentialService(); + + ImportModel<SampleRow> samplingPlanImportModel = + new ObsMerObsVenteSamplingPlanImportExportModel(getLocale(), + obsProgram, + activeCompanies, + fishingZones, + terrestrialDistricts, + referentialService); + + return samplingPlanImportModel; + + } + + public void recomputeSampleRowEstimatedAndRealTides(SampleRow sampleRow) { + + //---- + // Reset des tides de la ligne + //---- + + for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { + sampleMonth.setEstimatedTidesValue(0); + sampleMonth.setRealTidesValue(0); + } + + //---- + // Recuperation de tous les contacts de la ligne + //---- + + ContactsFilter contactFilter = new ContactsFilter(); + + contactFilter.setFilterOnObservationBeginDate(true); + contactFilter.getSampleRowFilter().setSampleRowIds(Sets.newHashSet(sampleRow.getTopiaId())); + + contactFilter.setContactStates(ImmutableSet.of(ContactState.OBSERVATION_DONE)); + // on exclue les contacts qui sont invalidés par le programme + contactFilter.setProgramAcceptations(Sets.newHashSet(true, null)); + // on exclue les contacts invalidés par la société + contactFilter.setCompanyAcceptations(Sets.newHashSet(true, null)); + + Collection<Contact> contacts = getContactDao().forFilter(contactFilter, false).findAll(); + + //---- + // Recalcul des tides + //---- + + for (Contact contact : contacts) { + + Date observationBeginDate = contact.getObservationBeginDate(); + + SampleMonth month = sampleRow.getSampleMonth(observationBeginDate); + + month.setEstimatedTidesValue(month.getEstimatedTidesValue() + 1); + + if (BooleanUtils.isTrue(contact.getValidationCompany())) { + month.setRealTidesValue(month.getRealTidesValue() + 1); + } + + } + + } + } Modified: branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-services/src/main/java/fr/ifremer/wao/services/service/csv/ObsMerObsVenteSamplingPlanImportExportModel.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -35,11 +35,15 @@ import fr.ifremer.wao.entity.SampleMonthImpl; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.SampleRowImpl; +import fr.ifremer.wao.entity.SamplingStrategy; import fr.ifremer.wao.entity.TerrestrialLocation; import fr.ifremer.wao.services.service.administration.ReferentialService; import fr.ifremer.wao.services.service.csv.operations.CompanyParserFormatter; import fr.ifremer.wao.services.service.csv.operations.DCF5CodesParserFormatter; +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.SampleRowCodeParserFormatter; import org.nuiton.csv.Common; import org.nuiton.csv.ExportableColumn; @@ -224,14 +228,12 @@ } if (obsProgram == ObsProgram.OBSVENTE) { - throw new UnsupportedOperationException(); - // FIXME brendan 24/03/14 on ne peut plus utiliser ToStringParserFormatter -// modelBuilder.newColumnForImportExport("PLAN_STRATEGIE", "samplingStrategy", new Common.ToStringParserFormatter<>(SamplingStrategy.values())); -// modelBuilder.newColumnForImportExport("PLAN_LIEU_CODE", SampleRow.PROPERTY_TERRESTRIAL_LOCATIONS, new DistrictsParserFormatter(terrestrialDistricts)); -// modelBuilder.newColumnForExport("PLAN_LIEU_NOM", SampleRow.PROPERTY_TERRESTRIAL_LOCATIONS, new DistrictNamesFormatter()); -// modelBuilder.newIgnoredColumn("PLAN_LIEU_NOM"); -// modelBuilder.newColumnForImportExport("PLAN_LIEU_COMMENT", SampleRow.PROPERTY_TERRESTRIAL_LOCATION_INFOS); -// modelBuilder.newColumnForImportExport("PLAN_NOMBRE_OBSERVATIONS", SampleRow.PROPERTY_AVERAGE_OBSERVATIONS_COUNT, Common.PRIMITIVE_INTEGER); + modelBuilder.newColumnForImportExport("PLAN_STRATEGIE", "samplingStrategy", new I18nAbleParserFormatter<>(locale, SamplingStrategy.values())); + modelBuilder.newColumnForImportExport("PLAN_LIEU_CODE", SampleRow.PROPERTY_TERRESTRIAL_LOCATIONS, new DistrictsParserFormatter(locale, terrestrialDistricts)); + modelBuilder.newColumnForExport("PLAN_LIEU_NOM", SampleRow.PROPERTY_TERRESTRIAL_LOCATIONS, new DistrictNamesFormatter()); + modelBuilder.newIgnoredColumn("PLAN_LIEU_NOM"); + modelBuilder.newColumnForImportExport("PLAN_LIEU_COMMENT", SampleRow.PROPERTY_TERRESTRIAL_LOCATION_INFOS); + modelBuilder.newColumnForImportExport("PLAN_NOMBRE_OBSERVATIONS", SampleRow.PROPERTY_AVERAGE_OBSERVATIONS_COUNT, Common.PRIMITIVE_INTEGER); } if (log.isDebugEnabled()) { Modified: branches/wao-4.0-obsvente/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java =================================================================== --- branches/wao-4.0-obsvente/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-services/src/test/java/fr/ifremer/wao/services/service/ObsMerSamplingPlanServiceTest.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -42,9 +42,7 @@ import java.util.HashMap; import java.util.Map; -import static fr.ifremer.wao.services.service.ObsMerSamplingPlan.ObsMerSamplingPlanFacadePart; import static fr.ifremer.wao.services.service.ObsMerSamplingPlan.ObsMerSamplingPlanSampleRowPart; -import static fr.ifremer.wao.services.service.ObsMerSamplingPlan.ObsMerSamplingPlanSectorPart; public class ObsMerSamplingPlanServiceTest extends AbstractWaoServiceTest { @@ -113,8 +111,8 @@ protected void assertSamplePlanRowsNumber(int expectedRowsSize, ObsMerSamplingPlan samplingPlan) { int actualRowsSize = 0; - for (ObsMerSamplingPlanFacadePart facade : samplingPlan) { - for (ObsMerSamplingPlanSectorPart sectors : facade) { + for (SamplingPlan.SamplingPlanFacadePart facade : samplingPlan) { + for (SamplingPlan.SamplingPlanSectorPart sectors : facade) { for (ObsMerSamplingPlanSampleRowPart row : sectors) { actualRowsSize++; @@ -171,10 +169,10 @@ SampleRow sampleRow = serviceContext.getPersistenceContext().getSampleRowDao().forCodeEquals("2010_M0011").findUnique(); - Map<Date, ObsMerSamplingPlan.ObsMerSamplingPlanStatistics> oldStats = new HashMap<>(); + Map<Date, ObsMerSamplingPlan.SamplingPlanStatistics> oldStats = new HashMap<>(); for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { - ObsMerSamplingPlan.ObsMerSamplingPlanStatistics stats = new ObsMerSamplingPlan.ObsMerSamplingPlanStatistics( + ObsMerSamplingPlan.SamplingPlanStatistics stats = new ObsMerSamplingPlan.SamplingPlanStatistics( sampleMonth.getExpectedTidesValue(), sampleMonth.getRealTidesValue(), sampleMonth.getEstimatedTidesValue() @@ -185,7 +183,7 @@ for (SampleMonth sampleMonth : sampleRow.getSampleMonth()) { - ObsMerSamplingPlan.ObsMerSamplingPlanStatistics oldMonth = oldStats.get(sampleMonth.getPeriodDate()); + ObsMerSamplingPlan.SamplingPlanStatistics oldMonth = oldStats.get(sampleMonth.getPeriodDate()); int expectedTidesValue = sampleMonth.getExpectedTidesValue(); int realTidesValue = sampleMonth.getRealTidesValue(); int estimatedTidesValue = sampleMonth.getEstimatedTidesValue(); Modified: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/CacheInvalidationTopiaEntityListener.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/CacheInvalidationTopiaEntityListener.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/CacheInvalidationTopiaEntityListener.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -8,9 +8,9 @@ import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.services.service.BoatsFilterValues; import fr.ifremer.wao.services.service.BoatsFilterValuesCacheKey; -import fr.ifremer.wao.services.service.ObsMerSamplingPlan; +import fr.ifremer.wao.services.service.SamplingPlan; +import fr.ifremer.wao.services.service.SamplingPlanCacheKey; import fr.ifremer.wao.services.service.Synthesis; -import fr.ifremer.wao.services.service.SamplingPlanCacheKey; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -32,7 +32,7 @@ private static final Log log = LogFactory.getLog(CacheInvalidationTopiaEntityListener.class); - protected Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> samplingPlansCache; + protected Cache<SamplingPlanCacheKey, SamplingPlan> samplingPlansCache; protected Cache<BoatsFilterValuesCacheKey, BoatsFilterValues> boatsFilterValuesCache; @@ -51,7 +51,7 @@ protected boolean invalidateAllContacts = false; public CacheInvalidationTopiaEntityListener( - Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> samplingPlansCache, + Cache<SamplingPlanCacheKey, SamplingPlan> samplingPlansCache, Cache<BoatsFilterValuesCacheKey, BoatsFilterValues> boatsFilterValuesCache, Cache<ContactsFilter, Synthesis> synthesesCache) { this.samplingPlansCache = samplingPlansCache; @@ -123,7 +123,7 @@ synthesesCache.invalidateAll(); } else { Set<SamplingPlanCacheKey> samplingPlansCacheKeysToInvalidate = new HashSet<>(); - for (Map.Entry<SamplingPlanCacheKey, ObsMerSamplingPlan> entry : samplingPlansCache.asMap().entrySet()) { + for (Map.Entry<SamplingPlanCacheKey, SamplingPlan> entry : samplingPlansCache.asMap().entrySet()) { if (CollectionUtils.containsAny(entry.getValue().getSampleRowIds(), dirtySampleRowIds)) { samplingPlansCacheKeysToInvalidate.add(entry.getKey()); } Modified: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/DefaultWaoApplicationContext.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/DefaultWaoApplicationContext.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/DefaultWaoApplicationContext.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -36,6 +36,7 @@ import fr.ifremer.wao.services.service.BoatsFilterValuesCacheKey; import fr.ifremer.wao.services.service.InitWaoService; import fr.ifremer.wao.services.service.ObsMerSamplingPlan; +import fr.ifremer.wao.services.service.SamplingPlan; import fr.ifremer.wao.services.service.Synthesis; import fr.ifremer.wao.services.service.SamplingPlanCacheKey; import org.apache.commons.logging.Log; @@ -67,7 +68,7 @@ protected Random random; - protected Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> samplingPlansCache; + protected Cache<SamplingPlanCacheKey, SamplingPlan> samplingPlansCache; protected Cache<BoatsFilterValuesCacheKey, BoatsFilterValues> boatsFilterValuesCache; @@ -116,7 +117,7 @@ } @Override - public Cache<SamplingPlanCacheKey, ObsMerSamplingPlan> getSamplingPlansCache() { + public Cache<SamplingPlanCacheKey, SamplingPlan> getSamplingPlansCache() { if (samplingPlansCache == null) { samplingPlansCache = newCacheBuilder(100).expireAfterAccess(30, TimeUnit.DAYS).build(); } Modified: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/WaoJspActionSupport.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/WaoJspActionSupport.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/WaoJspActionSupport.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -24,7 +24,7 @@ import fr.ifremer.wao.WaoUtils; import fr.ifremer.wao.entity.ObsProgram; import fr.ifremer.wao.services.AuthenticatedWaoUser; -import fr.ifremer.wao.web.action.obsmer.SamplingPlanAction; +import fr.ifremer.wao.web.action.AbstractSamplingPlanAction; import org.apache.commons.lang3.time.DateUtils; import org.nuiton.util.pagination.PaginationResult; @@ -70,7 +70,7 @@ public String getText(String aTextName, String defaultValue) { String text = super.getText(aTextName, defaultValue); if ("invalid.fieldvalue.filter.periodFrom".equals(aTextName)) { - if (this instanceof SamplingPlanAction) { + if (this instanceof AbstractSamplingPlanAction) { text = getText("wao.ui.invalidMonthFormat"); } else { text = getText("wao.ui.invalidDateFormat"); Copied: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/AbstractSamplingPlanAction.java (from rev 2075, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java) =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/AbstractSamplingPlanAction.java (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/AbstractSamplingPlanAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,131 @@ +package fr.ifremer.wao.web.action; + +/* + * #%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 com.google.common.base.Objects; +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.services.service.SampleRowsFilterValues; +import fr.ifremer.wao.services.service.SamplingPlan; +import fr.ifremer.wao.services.service.SamplingPlanService; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.commons.lang3.time.DateUtils; + +import java.text.SimpleDateFormat; +import java.util.Date; + +public abstract class AbstractSamplingPlanAction extends WaoJspActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + protected transient SamplingPlanService samplingPlanService; + + public void setSamplingPlanService(SamplingPlanService samplingPlanService) { + this.samplingPlanService = samplingPlanService; + } + + protected SampleRowsFilter filter; + + protected SamplingPlan samplingPlan; + + public SampleRowsFilter getFilter() { + if (filter == null) { + prepare(); + } + return filter; + } + + @Override + public void prepare() { + + if (filter == null) { + filter = samplingPlanService.newSampleRowsFilter(getAuthenticatedWaoUser()); + } + + } + + @Override + public String execute() { + + filter = Objects.firstNonNull(session.getSampleRowsFilter(), filter); + + return applyFilter(); + + } + + public String resetFilter() { + + filter = samplingPlanService.newSampleRowsFilter(getAuthenticatedWaoUser()); + + return applyFilter(); + + } + + public String applyFilter() { + + getSession().setSampleRowsFilter(filter); + + samplingPlan = samplingPlan(); + + return SUCCESS; + + } + + protected abstract SamplingPlan samplingPlan(); + + public SamplingPlan getSamplingPlan() { + return samplingPlan; + } + + public String getSampleRowToHighlightId() { + return getSession().getSampleRowToHighlightId(); + } + + public SampleRowsFilterValues getFilterValues() { + SampleRowsFilterValues filterValues = getSamplingPlan().getFilterValues(); + return filterValues; + } + + public boolean isFullView() { + boolean fullView = getAuthenticatedWaoUser().isAdmin() || getAuthenticatedWaoUser().isProfessional(); + return fullView; + } + + protected SimpleDateFormat dateFormat = new SimpleDateFormat("MM/yyyy"); + + public boolean isCurrentMonth(Date month) { + + String currentStr = dateFormat.format(getNow()); + String monthStr = dateFormat.format(month); + return currentStr.equals(monthStr); + } + + public String getFilterPeriodFromPlaceholder() { + String placeholder = formatMonth(DateUtils.addMonths(getNow(), 1)); + return placeholder; + } + + public String getFilterPeriodToPlaceholder() { + String placeholder = formatMonth(DateUtils.addYears(getNow(), 1)); + return placeholder; + } +} Copied: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/CommentSampleRowAction.java (from rev 2075, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CommentSampleRowAction.java) =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/CommentSampleRowAction.java (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/CommentSampleRowAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,74 @@ +package fr.ifremer.wao.web.action; + +/* + * #%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 com.google.common.base.Preconditions; +import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; +import fr.ifremer.wao.services.service.SamplingPlanService; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.commons.lang3.StringUtils; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +@Results({ + @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) +}) +public class CommentSampleRowAction extends WaoJspActionSupport { + + private static final long serialVersionUID = 1L; + + protected transient SamplingPlanService service; + + protected String sampleRowId; + + protected String comment; + + public void setService(ObsMerSamplingPlanService service) { + this.service = service; + } + + public void setSampleRowId(String sampleRowId) { + this.sampleRowId = sampleRowId; + } + + public void setComment(String comment) { + this.comment = comment; + } + + @Override + public String execute() { + + Preconditions.checkState(getAuthenticatedWaoUser().isAuthorizedToCommentSampleRow()); + + if (StringUtils.isNotBlank(comment)) { + + service.commentSampleRow(getAuthenticatedWaoUser(), sampleRowId, comment); + + session.addMessage(t("wao.ui.form.addComment.success")); + + } + + return SUCCESS; + + } + +} Copied: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteSampleRowAction.java (from rev 2075, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/DeleteSampleRowAction.java) =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteSampleRowAction.java (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/DeleteSampleRowAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,77 @@ +package fr.ifremer.wao.web.action; + +/* + * #%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.services.service.IllegalDeletionException; +import fr.ifremer.wao.services.service.SamplingPlanService; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +@Results({ + @Result(name="error", type="redirectAction", params = { "actionName", "edit-sample-row!input", "sampleRowId", "%{sampleRowId}" }), + @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) +}) +public class DeleteSampleRowAction extends WaoJspActionSupport { + + private static final long serialVersionUID = 1L; + + protected transient SamplingPlanService service; + + protected String sampleRowId; + + public void setService(SamplingPlanService service) { + this.service = service; + } + + public void setSampleRowId(String sampleRowId) { + this.sampleRowId = sampleRowId; + } + + @Override + public String execute() { + + String sampleRowCode = service.getSampleRow(sampleRowId).getCode(); + + try { + + service.deleteSampleRow(sampleRowId); + + session.addMessage(t("wao.ui.action.deleteSampleRow.success", sampleRowCode)); + + return SUCCESS; + + } catch (IllegalDeletionException e) { + + session.addErrorMessages(t("wao.ui.action.deleteSampleRow.failure", sampleRowCode)); + session.addErrorMessages(e.getExplanation(getLocale())); + + return ERROR; + + } + + } + + public String getSampleRowId() { + return sampleRowId; + } +} \ No newline at end of file Copied: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java (from rev 2075, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditSampleRowAction.java) =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,158 @@ +package fr.ifremer.wao.web.action; + +/* + * #%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 com.google.common.base.Joiner; +import com.google.common.base.Optional; +import com.google.common.base.Strings; +import com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.WaoUtils; +import fr.ifremer.wao.entity.SampleRow; +import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; +import fr.ifremer.wao.services.service.SampleRowCodeMustBeUniqueException; +import fr.ifremer.wao.services.service.SamplingPlanService; +import fr.ifremer.wao.services.service.UpdateSampleRowCommand; +import fr.ifremer.wao.services.service.administration.UnknownBoatImmatriculationsException; +import fr.ifremer.wao.web.WaoJspActionSupport; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +import java.util.Map; + +@Results({ + @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) +}) +public class EditSampleRowAction extends WaoJspActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + private static final Log log = LogFactory.getLog(EditSampleRowAction.class); + + protected transient SamplingPlanService service; + + protected Optional<String> optionalSampleRowId = Optional.absent(); + + protected UpdateSampleRowCommand updateSampleRowCommand; + + public void setService(ObsMerSamplingPlanService service) { + this.service = service; + } + + public String getSampleRowId() { + return optionalSampleRowId.orNull(); + } + + public void setSampleRowId(String sampleRowId) { + this.optionalSampleRowId = Optional.fromNullable(Strings.emptyToNull(sampleRowId)); + } + + @Override + public void prepare() { + + updateSampleRowCommand = service.newUpdateSampleRowCommand(getAuthenticatedWaoUser(), optionalSampleRowId); + + } + + @Override + public void validate() { + + SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); + + try { + + service.preValidate(getAuthenticatedWaoUser(), updateSampleRowCommand); + + if (CollectionUtils.isEmpty(sampleRow.getdCF5Code())) { + addFieldError("updateSampleRowCommand.dcf5Codes", t("wao.ui.form.SampleRow.error.missingDcf5Codes")); + } + + } catch (UnknownBoatImmatriculationsException e) { + addFieldError("updateSampleRowCommand.elligibleBoatImmatriculations", t("wao.ui.unknownBoatImmatriculations", Joiner.on(", ").join(e.getImmatriculations()))); + } catch (SampleRowCodeMustBeUniqueException e) { + addFieldError("updateSampleRowCommand.code", t("wao.ui.form.SampleRow.error.codeMustBeUnique")); + } + + if (updateSampleRowCommand.isCreation()) { + if ( ! WaoUtils.getSampleRowCodePattern(sampleRow.getObsProgram()).matcher(sampleRow.getCode()).matches()) { + addFieldError("updateSampleRowCommand.code", t("wao.import.sampleRow.failure.wrongSampleRowCodeFormat", sampleRow.getCode())); + } + } else { + if (StringUtils.isBlank(updateSampleRowCommand.getSampleRowLog().getComment())) { + addFieldError("updateSampleRowCommand.sampleRowLog.comment", t("wao.ui.form.SampleRow.error.missingLogComment")); + } + } + + if (StringUtils.isBlank(sampleRow.getProgramName())) { + addFieldError("updateSampleRowCommand.sampleRow.programName", t("wao.ui.form.SampleRow.error.missingProgramName")); + } + + if (sampleRow.getPeriodBegin() == null) { + addFieldError("updateSampleRowCommand.sampleRow.periodBegin", t("wao.ui.form.SampleRow.error.missingPeriodBegin")); + } + + if (sampleRow.getPeriodEnd() == null) { + addFieldError("updateSampleRowCommand.sampleRow.periodEnd", t("wao.ui.form.SampleRow.error.missingPeriodEnd")); + } + + if (CollectionUtils.isEmpty(sampleRow.getFishingZone())) { + addFieldError("updateSampleRowCommand.fishingZones", t("wao.ui.form.SampleRow.error.missingFishingZones")); + } + + if (sampleRow.getSamplingStrategy().isSpecificStock() && StringUtils.isEmpty(sampleRow.getProfession().getSpecies())) { + addFieldError("updateSampleRowCommand.sampleRow.samplingStrategy", t("wao.ui.form.SampleRow.error.missingProfessionSpecies")); + } + + } + + @Override + public String execute() { + + service.save(updateSampleRowCommand); + + session.addMessage(t("wao.ui.form.updateSampleRowCommand.success", updateSampleRowCommand.getSampleRow().getCode())); + + session.setSampleRowToHighlightId(updateSampleRowCommand.getSampleRow().getTopiaId()); + + return SUCCESS; + + } + + public UpdateSampleRowCommand getUpdateSampleRowCommand() { + if (updateSampleRowCommand == null) { + prepare(); + } + return updateSampleRowCommand; + } + + public Map<String, Integer> getExpectedObservationsByMonths() { + return getUpdateSampleRowCommand().getExpectedObservationsByMonths(); + } + + public void setExpectedObservationsByMonths(Map<String, Integer> expectedObservationsByMonths) { + getUpdateSampleRowCommand().setExpectedObservationsByMonths(expectedObservationsByMonths); + } + +} \ No newline at end of file Copied: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportSamplingPlanAction.java (from rev 2075, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportSamplingPlanAction.java) =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportSamplingPlanAction.java (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ExportSamplingPlanAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,71 @@ +package fr.ifremer.wao.web.action; + +/* + * #%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 com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.services.service.SamplingPlanService; + +import java.io.InputStream; +import java.util.Date; + +public class ExportSamplingPlanAction extends AbstractDownloadCsvAction implements Preparable { + + private static final long serialVersionUID = 1L; + + protected transient SamplingPlanService service; + + protected SampleRowsFilter filter; + + public void setService(SamplingPlanService service) { + this.service = service; + } + + public SampleRowsFilter getFilter() { + if (filter == null) { + prepare(); + } + return filter; + } + + @Override + public void prepare() { + + filter = service.newSampleRowsFilter(getAuthenticatedWaoUser()); + + } + + @Override + public String getFileName() { + + return "plan_" + getObsProgram().name() + "_" + dateFormat.format(new Date()) + ".csv"; + + } + + @Override + public InputStream getInputStream() { + + return service.exportSamplingPlan(filter); + + } + +} Copied: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportSamplingPlanAction.java (from rev 2075, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ImportSamplingPlanAction.java) =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportSamplingPlanAction.java (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/ImportSamplingPlanAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,55 @@ +package fr.ifremer.wao.web.action; + +/* + * #%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.services.service.ImportErrorException; +import fr.ifremer.wao.services.service.SamplingPlanService; +import org.apache.struts2.convention.annotation.Result; +import org.apache.struts2.convention.annotation.Results; + +import java.io.InputStream; + +@Results({ + @Result(name="error", type="redirectAction", params = { "actionName", "import-sampling-plan!input" }) , + @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) +}) +public class ImportSamplingPlanAction extends AbstractImportCsvAction { + + private static final long serialVersionUID = 1L; + + protected transient SamplingPlanService samplingPlanService; + + public void setService(SamplingPlanService samplingPlanService) { + this.samplingPlanService = samplingPlanService; + } + + @Override + protected void importCsv(InputStream csvInputStream) throws ImportErrorException { + samplingPlanService.importSamplingPlan(getAuthenticatedWaoUser(), csvInputStream); + } + + @Override + protected String getSuccessMessage() { + return t("wao.ui.import.samplingPlan.success"); + } + +} Copied: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowLogAction.java (from rev 2075, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowLogAction.java) =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowLogAction.java (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowLogAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,62 @@ +package fr.ifremer.wao.web.action; + +/* + * #%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.entity.SampleRow; +import fr.ifremer.wao.services.service.SamplingPlanService; +import fr.ifremer.wao.web.WaoJspActionSupport; + +public class SampleRowLogAction extends WaoJspActionSupport { + + private static final long serialVersionUID = 1L; + + protected transient SamplingPlanService service; + + protected String sampleRowId; + + protected SampleRow sampleRow; + + public void setService(SamplingPlanService service) { + this.service = service; + } + + public void setSampleRowId(String sampleRowId) { + this.sampleRowId = sampleRowId; + } + + @Override + public String execute() { + + sampleRow = service.getSampleRow(sampleRowId); + + return SUCCESS; + } + + public SampleRow getSampleRow() { + return sampleRow; + } + + public String getSampleRowId() { + return sampleRowId; + } + +} Copied: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowsFilterValuesJsonAction.java (from rev 2075, branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowsFilterValuesJsonAction.java) =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowsFilterValuesJsonAction.java (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/SampleRowsFilterValuesJsonAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,105 @@ +package fr.ifremer.wao.web.action; + +/* + * #%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 com.opensymphony.xwork2.Preparable; +import fr.ifremer.wao.SampleRowsFilter; +import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; +import fr.ifremer.wao.services.service.ObsVenteSamplingPlanService; +import fr.ifremer.wao.services.service.SampleRowsFilterValues; +import fr.ifremer.wao.services.service.SamplingPlan; +import fr.ifremer.wao.web.WaoJsonActionSupport; +import org.apache.commons.lang3.StringUtils; + +public class SampleRowsFilterValuesJsonAction extends WaoJsonActionSupport implements Preparable { + + private static final long serialVersionUID = 1L; + + protected transient ObsMerSamplingPlanService obsMerSamplingPlanService; + + protected transient ObsVenteSamplingPlanService obsVenteSamplingPlanService; + + protected SampleRowsFilter filter; + + protected SampleRowsFilterValues filterValues; + + protected String filterValuesField; + + public void setObsMerSamplingPlanService(ObsMerSamplingPlanService obsMerSamplingPlanService) { + this.obsMerSamplingPlanService = obsMerSamplingPlanService; + } + + public void setObsMerSamplingPlanService(ObsVenteSamplingPlanService obsVenteSamplingPlanService) { + this.obsVenteSamplingPlanService = obsVenteSamplingPlanService; + } + + public SampleRowsFilter getFilter() { + if (filter == null) { + prepare(); + } + return filter; + } + + public void setFilterValuesField(String filterValuesField) { + this.filterValuesField = filterValuesField; + } + + @Override + public void prepare() { + + filter = obsMerSamplingPlanService.newSampleRowsFilter(session.getAuthenticatedWaoUser()); + + } + + @Override + public String execute() { + + SamplingPlan samplingPlan; + if (filter.getObsProgram().isObsMer()) { + samplingPlan = obsMerSamplingPlanService.getSamplingPlan(session.getAuthenticatedWaoUser(), filter); + } else if (filter.getObsProgram().isObsVente()) { + samplingPlan = obsVenteSamplingPlanService.getSamplingPlan(session.getAuthenticatedWaoUser(), filter); + } else { + throw new UnsupportedOperationException(); + } + filterValues = samplingPlan.getFilterValues(); + + if (StringUtils.isNotBlank(filterValuesField)) { + + // le client ne demande qu'un seul champ, on peut éviter de retourner l'objet complet + + filterValues = filterValues.getCopyWithSingleProperty(filterValuesField); + + } + + return SUCCESS; + } + + public String getFilterValuesField() { + return filterValuesField; + } + + public SampleRowsFilterValues getFilterValues() { + return filterValues; + } + +} Deleted: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CommentSampleRowAction.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CommentSampleRowAction.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/CommentSampleRowAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -1,73 +0,0 @@ -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 com.google.common.base.Preconditions; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.commons.lang3.StringUtils; -import org.apache.struts2.convention.annotation.Result; -import org.apache.struts2.convention.annotation.Results; - -@Results({ - @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) -}) -public class CommentSampleRowAction extends WaoJspActionSupport { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService service; - - protected String sampleRowId; - - protected String comment; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public void setSampleRowId(String sampleRowId) { - this.sampleRowId = sampleRowId; - } - - public void setComment(String comment) { - this.comment = comment; - } - - @Override - public String execute() { - - Preconditions.checkState(getAuthenticatedWaoUser().isAuthorizedToCommentSampleRow()); - - if (StringUtils.isNotBlank(comment)) { - - service.commentSampleRow(getAuthenticatedWaoUser(), sampleRowId, comment); - - session.addMessage(t("wao.ui.form.addComment.success")); - - } - - return SUCCESS; - - } - -} Deleted: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/DeleteSampleRowAction.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/DeleteSampleRowAction.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/DeleteSampleRowAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -1,77 +0,0 @@ -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.services.service.IllegalDeletionException; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.struts2.convention.annotation.Result; -import org.apache.struts2.convention.annotation.Results; - -@Results({ - @Result(name="error", type="redirectAction", params = { "actionName", "edit-sample-row!input", "sampleRowId", "%{sampleRowId}" }), - @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) -}) -public class DeleteSampleRowAction extends WaoJspActionSupport { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService service; - - protected String sampleRowId; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public void setSampleRowId(String sampleRowId) { - this.sampleRowId = sampleRowId; - } - - @Override - public String execute() { - - String sampleRowCode = service.getSampleRow(sampleRowId).getCode(); - - try { - - service.deleteSampleRow(sampleRowId); - - session.addMessage(t("wao.ui.action.deleteSampleRow.success", sampleRowCode)); - - return SUCCESS; - - } catch (IllegalDeletionException e) { - - session.addErrorMessages(t("wao.ui.action.deleteSampleRow.failure", sampleRowCode)); - session.addErrorMessages(e.getExplanation(getLocale())); - - return ERROR; - - } - - } - - public String getSampleRowId() { - return sampleRowId; - } -} \ No newline at end of file Deleted: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditSampleRowAction.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditSampleRowAction.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/EditSampleRowAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -1,157 +0,0 @@ -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 com.google.common.base.Joiner; -import com.google.common.base.Optional; -import com.google.common.base.Strings; -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.WaoUtils; -import fr.ifremer.wao.entity.SampleRow; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.services.service.SampleRowCodeMustBeUniqueException; -import fr.ifremer.wao.services.service.UpdateSampleRowCommand; -import fr.ifremer.wao.services.service.administration.UnknownBoatImmatriculationsException; -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.struts2.convention.annotation.Result; -import org.apache.struts2.convention.annotation.Results; - -import java.util.Map; - -@Results({ - @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) -}) -public class EditSampleRowAction extends WaoJspActionSupport implements Preparable { - - private static final long serialVersionUID = 1L; - - private static final Log log = LogFactory.getLog(EditSampleRowAction.class); - - protected transient ObsMerSamplingPlanService service; - - protected Optional<String> optionalSampleRowId = Optional.absent(); - - protected UpdateSampleRowCommand updateSampleRowCommand; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public String getSampleRowId() { - return optionalSampleRowId.orNull(); - } - - public void setSampleRowId(String sampleRowId) { - this.optionalSampleRowId = Optional.fromNullable(Strings.emptyToNull(sampleRowId)); - } - - @Override - public void prepare() { - - updateSampleRowCommand = service.newUpdateSampleRowCommand(getAuthenticatedWaoUser(), optionalSampleRowId); - - } - - @Override - public void validate() { - - SampleRow sampleRow = updateSampleRowCommand.getSampleRow(); - - try { - - service.preValidate(getAuthenticatedWaoUser(), updateSampleRowCommand); - - if (CollectionUtils.isEmpty(sampleRow.getdCF5Code())) { - addFieldError("updateSampleRowCommand.dcf5Codes", t("wao.ui.form.SampleRow.error.missingDcf5Codes")); - } - - } catch (UnknownBoatImmatriculationsException e) { - addFieldError("updateSampleRowCommand.elligibleBoatImmatriculations", t("wao.ui.unknownBoatImmatriculations", Joiner.on(", ").join(e.getImmatriculations()))); - } catch (SampleRowCodeMustBeUniqueException e) { - addFieldError("updateSampleRowCommand.code", t("wao.ui.form.SampleRow.error.codeMustBeUnique")); - } - - if (updateSampleRowCommand.isCreation()) { - if ( ! WaoUtils.getSampleRowCodePattern(sampleRow.getObsProgram()).matcher(sampleRow.getCode()).matches()) { - addFieldError("updateSampleRowCommand.code", t("wao.import.sampleRow.failure.wrongSampleRowCodeFormat", sampleRow.getCode())); - } - } else { - if (StringUtils.isBlank(updateSampleRowCommand.getSampleRowLog().getComment())) { - addFieldError("updateSampleRowCommand.sampleRowLog.comment", t("wao.ui.form.SampleRow.error.missingLogComment")); - } - } - - if (StringUtils.isBlank(sampleRow.getProgramName())) { - addFieldError("updateSampleRowCommand.sampleRow.programName", t("wao.ui.form.SampleRow.error.missingProgramName")); - } - - if (sampleRow.getPeriodBegin() == null) { - addFieldError("updateSampleRowCommand.sampleRow.periodBegin", t("wao.ui.form.SampleRow.error.missingPeriodBegin")); - } - - if (sampleRow.getPeriodEnd() == null) { - addFieldError("updateSampleRowCommand.sampleRow.periodEnd", t("wao.ui.form.SampleRow.error.missingPeriodEnd")); - } - - if (CollectionUtils.isEmpty(sampleRow.getFishingZone())) { - addFieldError("updateSampleRowCommand.fishingZones", t("wao.ui.form.SampleRow.error.missingFishingZones")); - } - - if (sampleRow.getSamplingStrategy().isSpecificStock() && StringUtils.isEmpty(sampleRow.getProfession().getSpecies())) { - addFieldError("updateSampleRowCommand.sampleRow.samplingStrategy", t("wao.ui.form.SampleRow.error.missingProfessionSpecies")); - } - - } - - @Override - public String execute() { - - service.save(updateSampleRowCommand); - - session.addMessage(t("wao.ui.form.updateSampleRowCommand.success", updateSampleRowCommand.getSampleRow().getCode())); - - session.setSampleRowToHighlightId(updateSampleRowCommand.getSampleRow().getTopiaId()); - - return SUCCESS; - - } - - public UpdateSampleRowCommand getUpdateSampleRowCommand() { - if (updateSampleRowCommand == null) { - prepare(); - } - return updateSampleRowCommand; - } - - public Map<String, Integer> getExpectedObservationsByMonths() { - return getUpdateSampleRowCommand().getExpectedObservationsByMonths(); - } - - public void setExpectedObservationsByMonths(Map<String, Integer> expectedObservationsByMonths) { - getUpdateSampleRowCommand().setExpectedObservationsByMonths(expectedObservationsByMonths); - } - -} \ No newline at end of file Deleted: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportSamplingPlanAction.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportSamplingPlanAction.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ExportSamplingPlanAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -1,72 +0,0 @@ -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 com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.SampleRowsFilter; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.web.action.AbstractDownloadCsvAction; - -import java.io.InputStream; -import java.util.Date; - -public class ExportSamplingPlanAction extends AbstractDownloadCsvAction implements Preparable { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService service; - - protected SampleRowsFilter filter; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public SampleRowsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - @Override - public void prepare() { - - filter = service.newSampleRowsFilter(getAuthenticatedWaoUser()); - - } - - @Override - public String getFileName() { - - return "plan_" + getObsProgram().name() + "_" + dateFormat.format(new Date()) + ".csv"; - - } - - @Override - public InputStream getInputStream() { - - return service.exportSamplingPlan(filter); - - } - -} Deleted: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ImportSamplingPlanAction.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ImportSamplingPlanAction.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/ImportSamplingPlanAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -1,56 +0,0 @@ -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.services.service.ImportErrorException; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.web.action.AbstractImportCsvAction; -import org.apache.struts2.convention.annotation.Result; -import org.apache.struts2.convention.annotation.Results; - -import java.io.InputStream; - -@Results({ - @Result(name="error", type="redirectAction", params = { "actionName", "import-sampling-plan!input" }) , - @Result(name="success", type="redirectAction", params = { "actionName", "sampling-plan" }) -}) -public class ImportSamplingPlanAction extends AbstractImportCsvAction { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService samplingPlanService; - - public void setService(ObsMerSamplingPlanService samplingPlanService) { - this.samplingPlanService = samplingPlanService; - } - - @Override - protected void importCsv(InputStream csvInputStream) throws ImportErrorException { - samplingPlanService.importSamplingPlan(getAuthenticatedWaoUser(), csvInputStream); - } - - @Override - protected String getSuccessMessage() { - return t("wao.ui.import.samplingPlan.success"); - } - -} Deleted: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowLogAction.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowLogAction.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowLogAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -1,62 +0,0 @@ -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.entity.SampleRow; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.web.WaoJspActionSupport; - -public class SampleRowLogAction extends WaoJspActionSupport { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService service; - - protected String sampleRowId; - - protected SampleRow sampleRow; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public void setSampleRowId(String sampleRowId) { - this.sampleRowId = sampleRowId; - } - - @Override - public String execute() { - - sampleRow = service.getSampleRow(sampleRowId); - - return SUCCESS; - } - - public SampleRow getSampleRow() { - return sampleRow; - } - - public String getSampleRowId() { - return sampleRowId; - } - -} Deleted: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowsFilterValuesJsonAction.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowsFilterValuesJsonAction.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SampleRowsFilterValuesJsonAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -1,92 +0,0 @@ -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 com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.SampleRowsFilter; -import fr.ifremer.wao.services.service.ObsMerSamplingPlan; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.services.service.SampleRowsFilterValues; -import fr.ifremer.wao.web.WaoJsonActionSupport; -import org.apache.commons.lang3.StringUtils; - -public class SampleRowsFilterValuesJsonAction extends WaoJsonActionSupport implements Preparable { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService service; - - protected SampleRowsFilter filter; - - protected SampleRowsFilterValues filterValues; - - protected String filterValuesField; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public SampleRowsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - public void setFilterValuesField(String filterValuesField) { - this.filterValuesField = filterValuesField; - } - - @Override - public void prepare() { - - filter = service.newSampleRowsFilter(session.getAuthenticatedWaoUser()); - - } - - @Override - public String execute() { - - ObsMerSamplingPlan samplingPlan = service.getSamplingPlan(session.getAuthenticatedWaoUser(), filter); - - filterValues = samplingPlan.getFilterValues(); - - if (StringUtils.isNotBlank(filterValuesField)) { - - // le client ne demande qu'un seul champ, on peut éviter de retourner l'objet complet - - filterValues = filterValues.getCopyWithSingleProperty(filterValuesField); - - } - - return SUCCESS; - } - - public String getFilterValuesField() { - return filterValuesField; - } - - public SampleRowsFilterValues getFilterValues() { - return filterValues; - } - -} Deleted: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -1,129 +0,0 @@ -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 com.google.common.base.Objects; -import com.opensymphony.xwork2.Preparable; -import fr.ifremer.wao.SampleRowsFilter; -import fr.ifremer.wao.services.service.ObsMerSamplingPlan; -import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; -import fr.ifremer.wao.services.service.SampleRowsFilterValues; -import fr.ifremer.wao.web.WaoJspActionSupport; -import org.apache.commons.lang3.time.DateUtils; - -import java.text.SimpleDateFormat; -import java.util.Date; - -public class SamplingPlanAction extends WaoJspActionSupport implements Preparable { - - private static final long serialVersionUID = 1L; - - protected transient ObsMerSamplingPlanService service; - - protected SampleRowsFilter filter; - - protected ObsMerSamplingPlan samplingPlan; - - public void setService(ObsMerSamplingPlanService service) { - this.service = service; - } - - public SampleRowsFilter getFilter() { - if (filter == null) { - prepare(); - } - return filter; - } - - @Override - public void prepare() { - - if (filter == null) { - filter = service.newSampleRowsFilter(getAuthenticatedWaoUser()); - } - - } - - @Override - public String execute() { - - filter = Objects.firstNonNull(session.getSampleRowsFilter(), filter); - - return applyFilter(); - - } - - public String resetFilter() { - - filter = service.newSampleRowsFilter(getAuthenticatedWaoUser()); - - return applyFilter(); - - } - - public String applyFilter() { - - getSession().setSampleRowsFilter(filter); - - samplingPlan = service.getSamplingPlan(getAuthenticatedWaoUser(), filter); - - return SUCCESS; - - } - - public ObsMerSamplingPlan getSamplingPlan() { - return samplingPlan; - } - - public String getSampleRowToHighlightId() { - return getSession().getSampleRowToHighlightId(); - } - - public SampleRowsFilterValues getFilterValues() { - SampleRowsFilterValues filterValues = getSamplingPlan().getFilterValues(); - return filterValues; - } - - public boolean isFullView() { - boolean fullView = getAuthenticatedWaoUser().isAdmin() || getAuthenticatedWaoUser().isProfessional(); - return fullView; - } - - protected SimpleDateFormat dateFormat = new SimpleDateFormat("MM/yyyy"); - - public boolean isCurrentMonth(Date month) { - - String currentStr = dateFormat.format(getNow()); - String monthStr = dateFormat.format(month); - return currentStr.equals(monthStr); - } - - public String getFilterPeriodFromPlaceholder() { - String placeholder = formatMonth(DateUtils.addMonths(getNow(), 1)); - return placeholder; - } - - public String getFilterPeriodToPlaceholder() { - String placeholder = formatMonth(DateUtils.addYears(getNow(), 1)); - return placeholder; - } -} Added: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsmer/SamplingPlanAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,21 @@ +package fr.ifremer.wao.web.action.obsmer; + +import fr.ifremer.wao.services.service.ObsMerSamplingPlanService; +import fr.ifremer.wao.services.service.SamplingPlan; +import fr.ifremer.wao.web.action.AbstractSamplingPlanAction; + +public class SamplingPlanAction extends AbstractSamplingPlanAction { + + protected transient ObsMerSamplingPlanService service; + + public void setService(ObsMerSamplingPlanService service) { + this.service = service; + } + + @Override + protected SamplingPlan samplingPlan() { + + return service.getSamplingPlan(getAuthenticatedWaoUser(), filter); + + } +} Added: branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsvente/SamplingPlanAction.java =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsvente/SamplingPlanAction.java (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/java/fr/ifremer/wao/web/action/obsvente/SamplingPlanAction.java 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,22 @@ +package fr.ifremer.wao.web.action.obsvente; + +import fr.ifremer.wao.services.service.ObsVenteSamplingPlanService; +import fr.ifremer.wao.services.service.SamplingPlan; +import fr.ifremer.wao.web.action.AbstractSamplingPlanAction; + +public class SamplingPlanAction extends AbstractSamplingPlanAction { + + protected transient ObsVenteSamplingPlanService service; + + public void setService(ObsVenteSamplingPlanService service) { + this.service = service; + } + + @Override + protected SamplingPlan samplingPlan() { + + return service.getSamplingPlan(getAuthenticatedWaoUser(), filter); + + } + +} Added: branches/wao-4.0-obsvente/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsvente/SamplingPlanAction-conversion.properties =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsvente/SamplingPlanAction-conversion.properties (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/resources/fr/ifremer/wao/web/action/obsvente/SamplingPlanAction-conversion.properties 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1 @@ +filter=org.nuiton.web.struts2.converters.JsonConverter Copied: branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp (from rev 2075, branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-sample-row-input.jsp) =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,271 @@ +<%-- + #%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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + <head> + <title> + <s:if test="updateSampleRowCommand.creation"> + <s:text name="wao.ui.sampleRow.creation" /> + </s:if> + <s:else> + <s:property value="t('wao.ui.sampleRow.edition', updateSampleRowCommand.sampleRow.code)" /> + </s:else> + </title> + <script> + + $(document).ready(function() { + + var expectedObservationsByMonths = <s:property value="updateSampleRowCommand.expectedObservationsByMonths" escapeHtml="false" />; + + var $expectedObservationsByMonthsTable = $('#expectedObservationsByMonthsTable'); + var $expectedObservationsByMonthsTableHead = $expectedObservationsByMonthsTable.find('thead'); + var $expectedObservationsByMonthsTableBody = $expectedObservationsByMonthsTable.find('tbody'); + var $periodBeginInput = $('input[name="updateSampleRowCommand.sampleRow.periodBegin"]'); + var $periodEndInput = $('input[name="updateSampleRowCommand.sampleRow.periodEnd"]'); + + var updateExpectedObservationsByMonthsTable = function() { + $expectedObservationsByMonthsTableHead.empty(); + $expectedObservationsByMonthsTableBody.empty(); + var periodBegin = moment($periodBeginInput.val(), 'MM/YYYY'); + var periodEnd = moment($periodEndInput.val(), 'MM/YYYY'); + if (periodBegin.isValid() && periodEnd.isValid()) { + if (periodBegin > periodEnd) { + $periodEndInput.val($periodBeginInput.val()); + periodEnd = moment($periodEndInput.val(), 'MM/YYYY'); + } + var months = []; + do { + months.push(periodBegin.format('YYYYMM')); + periodBegin.add('months', 1); + } while (periodBegin <= periodEnd); + $expectedObservationsByMonthsTableHead.append('<tr></tr>'); + $expectedObservationsByMonthsTableBody.append('<tr></tr>'); + $(months).each(function (index, month) { + var newInput = ' <td>' + + ' ' + moment(month, 'YYYYMM').format('MM/YYYY') + + ' </td>'; + $expectedObservationsByMonthsTableHead.find('tr').append(newInput); + }); + $(months).each(function (index, month) { + var value = ""; + if (expectedObservationsByMonths[month]) { + value = expectedObservationsByMonths[month]; + } + var newInput = ' <td>' + + ' <input type="number" name="expectedObservationsByMonths[\'' + month + '\']" value="' + value + '" class="input-small" />' + + ' </td>'; + $expectedObservationsByMonthsTableBody.find('tr').append(newInput); + }); + } + } + + updateExpectedObservationsByMonthsTable(); + + $periodBeginInput.change(updateExpectedObservationsByMonthsTable); + $periodEndInput.change(updateExpectedObservationsByMonthsTable); + + }); + + </script> + + <content tag="mainClass">form</content> + </head> + + + <s:if test="updateSampleRowCommand.observationAlreadyStarted"> + <div class="alert"> + <s:text name="wao.ui.form.SampleRow.warn.observationAlreadyStarted" /> + </div> + </s:if> + + <s:form> + + <h1> + <s:if test="updateSampleRowCommand.creation"> + <s:text name="wao.ui.sampleRow.creation" /> + </s:if> + <s:else> + <s:property value="t('wao.ui.sampleRow.edition', updateSampleRowCommand.sampleRow.code)" /> + </s:else> + </h1> + + <s:hidden name="sampleRowId" value="%{sampleRowId}" /> + + <fieldset> + + <legend><s:text name="wao.ui.field.SampleRow.profession" /></legend> + + <s:textfield name="updateSampleRowCommand.sampleRow.profession.libelle" + label="%{getText('wao.ui.field.SampleRow.libelle')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + cssClass="input-xxlarge" /> + + <s:textfield name="updateSampleRowCommand.sampleRow.profession.size" + label="%{getText('wao.ui.field.SampleRow.size')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + inputAppend="m" + cssClass="input-small" /> + + <s:textfield name="updateSampleRowCommand.sampleRow.profession.meshSize" + label="%{getText('wao.ui.field.SampleRow.meshSize')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + inputAppend="mm" + cssClass="input-small" /> + + <s:textfield name="updateSampleRowCommand.sampleRow.profession.species" + label="%{getText('wao.ui.field.SampleRow.species')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + cssClass="input-xxlarge" /> + + <s:textfield name="updateSampleRowCommand.sampleRow.profession.other" + label="%{getText('wao.ui.field.SampleRow.other')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + cssClass="input-xxlarge" /> + + <s:select name="updateSampleRowCommand.dcf5CodesIds" + label="%{getText('wao.ui.field.SampleRow.dcf5Codes')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + list="updateSampleRowCommand.allDcf5Codes" + listValue="%{value.code}" + cssClass="input-xxlarge select2" + multiple="true" + /> + + </fieldset> + + <fieldset> + + <legend><s:text name="wao.ui.field.SampleRow.fishingZones" /></legend> + + <s:select name="updateSampleRowCommand.fishingZoneIds" + label="%{getText('wao.ui.field.SampleRow.fishingZones')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + list="updateSampleRowCommand.allFishingZones" + listValue="%{value.code}" + multiple="true" + cssClass="input-xxlarge" + /> + + <s:textfield name="updateSampleRowCommand.sampleRow.fishingZonesInfos" label="%{getText('wao.ui.field.SampleRow.fishingZonesInfos')}" cssClass="input-xxlarge" /> + + </fieldset> + + <fieldset> + + <legend><s:text name="wao.ui.form.SampleRow.program" /></legend> + + <s:textfield name="updateSampleRowCommand.sampleRow.programName" + label="%{getText('wao.ui.field.SampleRow.programName')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" /> + <s:textfield name="updateSampleRowCommand.sampleRow.periodBegin" + label="%{getText('wao.ui.field.SampleRow.periodBegin')}" + placeholder="04/2014" + cssClass="input-small" /> + <s:textfield name="updateSampleRowCommand.sampleRow.periodEnd" + label="%{getText('wao.ui.field.SampleRow.periodEnd')}" + placeholder="03/2015" + cssClass="input-small" /> + + + <div class="control-group"> + <label class="control-label"><s:text name="wao.ui.samplingPlan.effort" /></label> + <div class="controls"> + <table id="expectedObservationsByMonthsTable"> + <thead> + </thead> + <tbody> + </tbody> + </table> + </div> + </div> + + + </fieldset> + + <fieldset> + + <legend><s:text name="wao.ui.form.SampleRow.others" /></legend> + + <s:if test="updateSampleRowCommand.creation"> + <s:textfield name="updateSampleRowCommand.code" + label="%{getText('wao.ui.field.SampleRow.code')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + cssClass="input-small" /> + </s:if> + + <s:select name="updateSampleRowCommand.companyId" + label="%{getText('wao.ui.field.SampleRow.company')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + list="updateSampleRowCommand.allCompanies" + listValue="%{value.name}" + cssClass="input-xxlarge" + /> + + <s:textfield type="number" name="updateSampleRowCommand.sampleRow.nbObservants" label="%{getText('wao.ui.field.SampleRow.nbObservants')}" inputAppend="%{getText('wao.ui.unit.observers')}" cssClass="input-small"/> + + <%-- XXX brendan 19/05/14 ne pas mettre type="number" car avec le formatter qui mets la valeur avec ',' on a pas la valeur quand on modifie une ligne --%> + <s:textfield name="updateSampleRowCommand.sampleRow.averageTideTime" label="%{getText('wao.ui.field.SampleRow.averageTideTime')}" inputAppend="%{getText('wao.ui.unit.days')}" cssClass="input-small"/> + <s:textfield name="updateSampleRowCommand.sampleRow.appliedCoverageRate" label="%{getText('wao.ui.field.SampleRow.appliedCoverageRate')}" inputAppend="%" cssClass="input-small"/> + + <s:textarea name="updateSampleRowCommand.elligibleBoatImmatriculations" label="%{getText('wao.ui.field.SampleRow.elligibleBoat')}" /> + + <s:textarea name="updateSampleRowCommand.sampleRow.comment" label="%{getText('wao.ui.field.SampleRow.comment')}" /> + + </fieldset> + + <s:if test=" ! updateSampleRowCommand.creation"> + + <fieldset> + + <legend><s:text name="wao.ui.form.editComment" /></legend> + + <s:text name="wao.ui.form.editionAuthor" /> <s:property value="updateSampleRowCommand.sampleRowLog.author.fullName" /> + + <s:textarea name="updateSampleRowCommand.sampleRowLog.comment" label="%{getText('wao.ui.form.editComment')}" requiredLabel="true" /> + + </fieldset> + + </s:if> + + <div class="form-actions"> + <s:url namespace="/obsmer" action="sampling-plan" id="samplingPlanUrl" /> + <s:a href="%{samplingPlanUrl}" cssClass="btn"> + <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.cancel" /> + </s:a> + <s:submit type="button" cssClass="btn"> + <i class="icon-hdd"></i> <s:text name="wao.ui.action.save" /> + </s:submit> + <s:if test=" ! updateSampleRowCommand.creation"> + <s:url action="delete-sample-row" id="deleteSampleRowUrl"> + <s:param name="sampleRowId" value="sampleRowId" /> + </s:url> + <s:a href="%{deleteSampleRowUrl}" cssClass="btn pull-right"> + <i class="icon-trash"></i> <s:text name="wao.ui.action.deleteSampleRow" /> + </s:a> + </s:if> + </div> + + </s:form> + +</html> + Copied: branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/import-contacts-input.jsp (from rev 2075, branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts-input.jsp) =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/import-contacts-input.jsp (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/import-contacts-input.jsp 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,55 @@ +<%-- + #%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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + +<head> + <title><s:text name="wao.ui.import.contacts" /></title> + <content tag="mainClass">form</content> +</head> + +<s:form action="import-contacts" method="POST" enctype="multipart/form-data"> + + <h1><s:text name="wao.ui.import.contacts" /></h1> + + <div class="alert alert-info"> + <s:text name="wao.ui.import.disclaimer" /> + </div> + + <fieldset> + <legend> + <s:text name="wao.ui.import.contacts" /> + </legend> + + <s:file name="csvFile" /> + + <div class="form-actions"> + <s:submit type="button" cssClass="btn"> + <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport"/> + </s:submit> + </div> + </fieldset> + +</s:form> + +</html> \ No newline at end of file Copied: branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/import-sampling-plan-input.jsp (from rev 2075, branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-sampling-plan-input.jsp) =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/import-sampling-plan-input.jsp (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/import-sampling-plan-input.jsp 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,55 @@ +<%-- + #%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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + + <head> + <title><s:text name="wao.ui.import.samplingPlan" /></title> + <content tag="mainClass">form</content> + </head> + + <s:form action="import-sampling-plan" method="POST" enctype="multipart/form-data"> + + <h1><s:text name="wao.ui.import.samplingPlan" /></h1> + + <div class="alert alert-info"> + <s:text name="wao.ui.import.disclaimer" /> + </div> + + <fieldset> + <legend> + <s:text name="wao.ui.import.samplingPlan" /> + </legend> + + <s:file name="csvFile" /> + + <div class="form-actions"> + <s:submit type="button" cssClass="btn"> + <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport"/> + </s:submit> + </div> + </fieldset> + + </s:form> + +</html> Deleted: branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-sample-row-input.jsp =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-sample-row-input.jsp 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/edit-sample-row-input.jsp 2014-06-21 11:01:33 UTC (rev 2081) @@ -1,271 +0,0 @@ -<%-- - #%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% - --%> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> -<%@taglib uri="/struts-tags" prefix="s" %> - -<html> - <head> - <title> - <s:if test="updateSampleRowCommand.creation"> - <s:text name="wao.ui.sampleRow.creation" /> - </s:if> - <s:else> - <s:property value="t('wao.ui.sampleRow.edition', updateSampleRowCommand.sampleRow.code)" /> - </s:else> - </title> - <script> - - $(document).ready(function() { - - var expectedObservationsByMonths = <s:property value="updateSampleRowCommand.expectedObservationsByMonths" escapeHtml="false" />; - - var $expectedObservationsByMonthsTable = $('#expectedObservationsByMonthsTable'); - var $expectedObservationsByMonthsTableHead = $expectedObservationsByMonthsTable.find('thead'); - var $expectedObservationsByMonthsTableBody = $expectedObservationsByMonthsTable.find('tbody'); - var $periodBeginInput = $('input[name="updateSampleRowCommand.sampleRow.periodBegin"]'); - var $periodEndInput = $('input[name="updateSampleRowCommand.sampleRow.periodEnd"]'); - - var updateExpectedObservationsByMonthsTable = function() { - $expectedObservationsByMonthsTableHead.empty(); - $expectedObservationsByMonthsTableBody.empty(); - var periodBegin = moment($periodBeginInput.val(), 'MM/YYYY'); - var periodEnd = moment($periodEndInput.val(), 'MM/YYYY'); - if (periodBegin.isValid() && periodEnd.isValid()) { - if (periodBegin > periodEnd) { - $periodEndInput.val($periodBeginInput.val()); - periodEnd = moment($periodEndInput.val(), 'MM/YYYY'); - } - var months = []; - do { - months.push(periodBegin.format('YYYYMM')); - periodBegin.add('months', 1); - } while (periodBegin <= periodEnd); - $expectedObservationsByMonthsTableHead.append('<tr></tr>'); - $expectedObservationsByMonthsTableBody.append('<tr></tr>'); - $(months).each(function (index, month) { - var newInput = ' <td>' - + ' ' + moment(month, 'YYYYMM').format('MM/YYYY') - + ' </td>'; - $expectedObservationsByMonthsTableHead.find('tr').append(newInput); - }); - $(months).each(function (index, month) { - var value = ""; - if (expectedObservationsByMonths[month]) { - value = expectedObservationsByMonths[month]; - } - var newInput = ' <td>' - + ' <input type="number" name="expectedObservationsByMonths[\'' + month + '\']" value="' + value + '" class="input-small" />' - + ' </td>'; - $expectedObservationsByMonthsTableBody.find('tr').append(newInput); - }); - } - } - - updateExpectedObservationsByMonthsTable(); - - $periodBeginInput.change(updateExpectedObservationsByMonthsTable); - $periodEndInput.change(updateExpectedObservationsByMonthsTable); - - }); - - </script> - - <content tag="mainClass">form</content> - </head> - - - <s:if test="updateSampleRowCommand.observationAlreadyStarted"> - <div class="alert"> - <s:text name="wao.ui.form.SampleRow.warn.observationAlreadyStarted" /> - </div> - </s:if> - - <s:form> - - <h1> - <s:if test="updateSampleRowCommand.creation"> - <s:text name="wao.ui.sampleRow.creation" /> - </s:if> - <s:else> - <s:property value="t('wao.ui.sampleRow.edition', updateSampleRowCommand.sampleRow.code)" /> - </s:else> - </h1> - - <s:hidden name="sampleRowId" value="%{sampleRowId}" /> - - <fieldset> - - <legend><s:text name="wao.ui.field.SampleRow.profession" /></legend> - - <s:textfield name="updateSampleRowCommand.sampleRow.profession.libelle" - label="%{getText('wao.ui.field.SampleRow.libelle')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - cssClass="input-xxlarge" /> - - <s:textfield name="updateSampleRowCommand.sampleRow.profession.size" - label="%{getText('wao.ui.field.SampleRow.size')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - inputAppend="m" - cssClass="input-small" /> - - <s:textfield name="updateSampleRowCommand.sampleRow.profession.meshSize" - label="%{getText('wao.ui.field.SampleRow.meshSize')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - inputAppend="mm" - cssClass="input-small" /> - - <s:textfield name="updateSampleRowCommand.sampleRow.profession.species" - label="%{getText('wao.ui.field.SampleRow.species')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - cssClass="input-xxlarge" /> - - <s:textfield name="updateSampleRowCommand.sampleRow.profession.other" - label="%{getText('wao.ui.field.SampleRow.other')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - cssClass="input-xxlarge" /> - - <s:select name="updateSampleRowCommand.dcf5CodesIds" - label="%{getText('wao.ui.field.SampleRow.dcf5Codes')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - list="updateSampleRowCommand.allDcf5Codes" - listValue="%{value.code}" - cssClass="input-xxlarge select2" - multiple="true" - /> - - </fieldset> - - <fieldset> - - <legend><s:text name="wao.ui.field.SampleRow.fishingZones" /></legend> - - <s:select name="updateSampleRowCommand.fishingZoneIds" - label="%{getText('wao.ui.field.SampleRow.fishingZones')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - list="updateSampleRowCommand.allFishingZones" - listValue="%{value.code}" - multiple="true" - cssClass="input-xxlarge" - /> - - <s:textfield name="updateSampleRowCommand.sampleRow.fishingZonesInfos" label="%{getText('wao.ui.field.SampleRow.fishingZonesInfos')}" cssClass="input-xxlarge" /> - - </fieldset> - - <fieldset> - - <legend><s:text name="wao.ui.form.SampleRow.program" /></legend> - - <s:textfield name="updateSampleRowCommand.sampleRow.programName" - label="%{getText('wao.ui.field.SampleRow.programName')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" /> - <s:textfield name="updateSampleRowCommand.sampleRow.periodBegin" - label="%{getText('wao.ui.field.SampleRow.periodBegin')}" - placeholder="04/2014" - cssClass="input-small" /> - <s:textfield name="updateSampleRowCommand.sampleRow.periodEnd" - label="%{getText('wao.ui.field.SampleRow.periodEnd')}" - placeholder="03/2015" - cssClass="input-small" /> - - - <div class="control-group"> - <label class="control-label"><s:text name="wao.ui.samplingPlan.effort" /></label> - <div class="controls"> - <table id="expectedObservationsByMonthsTable"> - <thead> - </thead> - <tbody> - </tbody> - </table> - </div> - </div> - - - </fieldset> - - <fieldset> - - <legend><s:text name="wao.ui.form.SampleRow.others" /></legend> - - <s:if test="updateSampleRowCommand.creation"> - <s:textfield name="updateSampleRowCommand.code" - label="%{getText('wao.ui.field.SampleRow.code')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - cssClass="input-small" /> - </s:if> - - <s:select name="updateSampleRowCommand.companyId" - label="%{getText('wao.ui.field.SampleRow.company')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - list="updateSampleRowCommand.allCompanies" - listValue="%{value.name}" - cssClass="input-xxlarge" - /> - - <s:textfield type="number" name="updateSampleRowCommand.sampleRow.nbObservants" label="%{getText('wao.ui.field.SampleRow.nbObservants')}" inputAppend="%{getText('wao.ui.unit.observers')}" cssClass="input-small"/> - - <%-- XXX brendan 19/05/14 ne pas mettre type="number" car avec le formatter qui mets la valeur avec ',' on a pas la valeur quand on modifie une ligne --%> - <s:textfield name="updateSampleRowCommand.sampleRow.averageTideTime" label="%{getText('wao.ui.field.SampleRow.averageTideTime')}" inputAppend="%{getText('wao.ui.unit.days')}" cssClass="input-small"/> - <s:textfield name="updateSampleRowCommand.sampleRow.appliedCoverageRate" label="%{getText('wao.ui.field.SampleRow.appliedCoverageRate')}" inputAppend="%" cssClass="input-small"/> - - <s:textarea name="updateSampleRowCommand.elligibleBoatImmatriculations" label="%{getText('wao.ui.field.SampleRow.elligibleBoat')}" /> - - <s:textarea name="updateSampleRowCommand.sampleRow.comment" label="%{getText('wao.ui.field.SampleRow.comment')}" /> - - </fieldset> - - <s:if test=" ! updateSampleRowCommand.creation"> - - <fieldset> - - <legend><s:text name="wao.ui.form.editComment" /></legend> - - <s:text name="wao.ui.form.editionAuthor" /> <s:property value="updateSampleRowCommand.sampleRowLog.author.fullName" /> - - <s:textarea name="updateSampleRowCommand.sampleRowLog.comment" label="%{getText('wao.ui.form.editComment')}" requiredLabel="true" /> - - </fieldset> - - </s:if> - - <div class="form-actions"> - <s:url namespace="/obsmer" action="sampling-plan" id="samplingPlanUrl" /> - <s:a href="%{samplingPlanUrl}" cssClass="btn"> - <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.cancel" /> - </s:a> - <s:submit type="button" cssClass="btn"> - <i class="icon-hdd"></i> <s:text name="wao.ui.action.save" /> - </s:submit> - <s:if test=" ! updateSampleRowCommand.creation"> - <s:url action="delete-sample-row" id="deleteSampleRowUrl"> - <s:param name="sampleRowId" value="sampleRowId" /> - </s:url> - <s:a href="%{deleteSampleRowUrl}" cssClass="btn pull-right"> - <i class="icon-trash"></i> <s:text name="wao.ui.action.deleteSampleRow" /> - </s:a> - </s:if> - </div> - - </s:form> - -</html> - Deleted: branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts-input.jsp =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts-input.jsp 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-contacts-input.jsp 2014-06-21 11:01:33 UTC (rev 2081) @@ -1,55 +0,0 @@ -<%-- - #%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% - --%> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> -<%@taglib uri="/struts-tags" prefix="s" %> - -<html> - -<head> - <title><s:text name="wao.ui.import.contacts" /></title> - <content tag="mainClass">form</content> -</head> - -<s:form action="import-contacts" method="POST" enctype="multipart/form-data"> - - <h1><s:text name="wao.ui.import.contacts" /></h1> - - <div class="alert alert-info"> - <s:text name="wao.ui.import.disclaimer" /> - </div> - - <fieldset> - <legend> - <s:text name="wao.ui.import.contacts" /> - </legend> - - <s:file name="csvFile" /> - - <div class="form-actions"> - <s:submit type="button" cssClass="btn"> - <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport"/> - </s:submit> - </div> - </fieldset> - -</s:form> - -</html> \ No newline at end of file Deleted: branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-sampling-plan-input.jsp =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-sampling-plan-input.jsp 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/import-sampling-plan-input.jsp 2014-06-21 11:01:33 UTC (rev 2081) @@ -1,55 +0,0 @@ -<%-- - #%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% - --%> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> -<%@taglib uri="/struts-tags" prefix="s" %> - -<html> - - <head> - <title><s:text name="wao.ui.import.samplingPlan" /></title> - <content tag="mainClass">form</content> - </head> - - <s:form action="import-sampling-plan" method="POST" enctype="multipart/form-data"> - - <h1><s:text name="wao.ui.import.samplingPlan" /></h1> - - <div class="alert alert-info"> - <s:text name="wao.ui.import.disclaimer" /> - </div> - - <fieldset> - <legend> - <s:text name="wao.ui.import.samplingPlan" /> - </legend> - - <s:file name="csvFile" /> - - <div class="form-actions"> - <s:submit type="button" cssClass="btn"> - <i class="icon-upload"></i> <s:text name="wao.ui.action.csvImport"/> - </s:submit> - </div> - </fieldset> - - </s:form> - -</html> Deleted: branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/sample-row-log.jsp =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/sample-row-log.jsp 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/sample-row-log.jsp 2014-06-21 11:01:33 UTC (rev 2081) @@ -1,98 +0,0 @@ -<%-- - #%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% - --%> -<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> -<%@taglib uri="/struts-tags" prefix="s" %> - -<html> - - <head> - <title> - <s:property value="%{t('wao.ui.sampleRowLog.title', sampleRow.code)}" /> - </title> - </head> - - <h1> - <s:property value="%{t('wao.ui.sampleRowLog.title', sampleRow.code)}" /> - </h1> - - <s:iterator value="sampleRow.sampleRowLog" var="sampleRowLogEntry"> - - <article> - <h2> - <s:if test="fromAdmin"> - <s:text name="wao.ui.misc.changeOn" /> - </s:if> - <s:else> - <s:text name="wao.ui.misc.commentAddedOn" /> - </s:else> - <s:property value="topiaCreateDate" /> - <s:text name="wao.ui.misc.by" /> - <s:property value="author.fullName" /> - </h2> - - <s:property value="logText" /> - - <s:property value="comment" /> - - </article> - - </s:iterator> - - <s:if test="authenticatedWaoUser.authorizedToCommentSampleRow"> - - <s:form action="comment-sample-row"> - - <fieldset> - <legend><s:text name="wao.ui.form.addComment" /></legend> - - <s:hidden name="sampleRowId" value="%{sampleRowId}" /> - - <s:textarea name="comment" label="%{getText('wao.ui.misc.comment')}" /> - - <div class="form-actions"> - <s:url namespace="/obsmer" action="sampling-plan" id="samplingPlanUrl" /> - <s:a href="%{samplingPlanUrl}" cssClass="btn"> - <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.goBackToSamplingPlan" /> - </s:a> - - <s:submit type="button" cssClass="btn"> - <i class="icon-hdd"></i> <s:text name="wao.ui.action.save" /> - </s:submit> - </div> - - </fieldset> - - </s:form> - - </s:if> - - <s:else> - - <div class="form-actions"> - <s:url namespace="/obsmer" action="sampling-plan" id="samplingPlanUrl" /> - <s:a href="%{samplingPlanUrl}" cssClass="btn"> - <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.goBackToSamplingPlan" /> - </s:a> - </div> - - </s:else> - -</html> Modified: branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/sampling-plan.jsp 2014-06-21 11:01:33 UTC (rev 2081) @@ -32,7 +32,7 @@ $(document).ready(function () { - // var sampleRowsFilterController = new FilterController(WAO.OBSMER_SAMPLE_ROWS_FILTER_VALUES_JSON_URL, $('#sampling-plan-filters-form')); + // var sampleRowsFilterController = new FilterController(WAO.SAMPLE_ROWS_FILTER_VALUES_JSON_URL, $('#sampling-plan-filters-form')); // sampleRowsFilterController.init(); var sampleRowsFilterMappings = [ @@ -77,7 +77,7 @@ filter = <s:property value="filter" escapeHtml="false"/>; - sampleRowsFilterController2 = new FilterController2(sampleRowsFilterMappings, filter, WAO.OBSMER_SAMPLE_ROWS_FILTER_VALUES_JSON_URL, $('#sampling-plan-filters-form fieldset.extra-filters')); + sampleRowsFilterController2 = new FilterController2(sampleRowsFilterMappings, filter, WAO.SAMPLE_ROWS_FILTER_VALUES_JSON_URL, $('#sampling-plan-filters-form fieldset.extra-filters')); sampleRowsFilterController2.init(); $('#switch-estimated-real').click(function () { Added: branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsvente/sampling-plan.jsp =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsvente/sampling-plan.jsp (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsvente/sampling-plan.jsp 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,574 @@ +<%-- + #%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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + + <head> + <title> + <s:text name="wao.ui.page.SamplingPlan.title" /> + </title> + + <script> + + $(document).ready(function () { + + // var sampleRowsFilterController = new FilterController(WAO.SAMPLE_ROWS_FILTER_VALUES_JSON_URL, $('#sampling-plan-filters-form')); + // sampleRowsFilterController.init(); + + var sampleRowsFilterMappings = [ + <s:if test="authenticatedWaoUser.authorizedToViewOtherCompanies"> + { + filterName: 'companyIds', + filterLabel: "<s:text name="wao.ui.entity.Company"/>", + filterValuesField: 'companies', + }, + </s:if> + { + filterName: 'programNames', + filterLabel: "<s:text name="wao.ui.field.SampleRow.programName"/>", + filterValuesField: 'programNames', + }, + { + filterName: 'sampleRowCodes', + filterLabel: "<s:text name="wao.ui.field.SampleRow.code"/>", + filterValuesField: 'sampleRowCodes', + }, + { + filterName: 'fishingZoneFacadeNames', + filterLabel: "<s:text name="wao.ui.field.FishingZone.facadeName"/>", + filterValuesField: 'fishingZoneFacadeNames', + }, + { + filterName: 'fishingZoneSectorNames', + filterLabel: "<s:text name="wao.ui.field.FishingZone.sectorName"/>", + filterValuesField: 'fishingZoneSectorNames', + }, + { + filterName: 'fishingGearDcfIds', + filterLabel: "<s:text name="wao.ui.entity.fishingGearDCF"/>", + filterValuesField: 'fishingGearDcfs', + }, + { + filterName: 'targetSpeciesDcfIds', + filterLabel: "<s:text name="wao.ui.entity.targetSpeciesDCF"/>", + filterValuesField: 'targetSpeciesDcfs', + }, + { + filterName: 'terrestrialDistrictIds', + filterLabel: "<s:text name="wao.ui.field.SampleRow.terrestrialLocation"/>", + filterValuesField: 'terrestrialDistricts' + }, + { + filterName: 'samplingStrategies', + filterLabel: "<s:text name="wao.ui.field.SampleRow.samplingStrategy"/>", + filterValuesField: 'samplingStrategies' + } + ]; + + filter = <s:property value="filter" escapeHtml="false"/>; + + sampleRowsFilterController2 = new FilterController2(sampleRowsFilterMappings, filter, WAO.SAMPLE_ROWS_FILTER_VALUES_JSON_URL, $('#sampling-plan-filters-form fieldset.extra-filters')); + sampleRowsFilterController2.init(); + + $('#switch-estimated-real').click(function () { + $('#switch-estimated-real').toggleClass('show-estimated').toggleClass('show-real'); + $('table.sampling-plan').toggleClass('show-estimated').toggleClass('show-real'); + $('.estimated-differ-from-real').effect( "highlight", "slow" ) + }); + + $('#switch-compact-full-view').click(function () { + $('#switch-compact-full-view').toggleClass('full-view').toggleClass('compact-view'); + $('table.sampling-plan').toggleClass('full-view').toggleClass('compact-view'); + }); + + }); + + </script> + + </head> + + <content tag="mainClass">large</content> + <content tag="samplingPlanMenuItemClass">active</content> + + <s:if test="authenticatedWaoUser.authorizedToEditSamplingPlan"> + <content tag="administrationMenuOtherOptions"> + <li> + <s:url action="edit-sample-row!input" id="createSampleRow"/> + <s:a href="%{createSampleRow}"> + <i class="icon-plus"></i> <s:text name="wao.ui.action.createSampleRow"/> + </s:a> + </li> + </content> + </s:if> + + <s:form method="GET" id="sampling-plan-filters-form" cssClass="filters-form"> + + <fieldset class="filters-group"> + + <s:textfield name="filter.periodFrom" + label="%{getText('wao.ui.form.periodFrom')}" + placeholder="%{getFilterPeriodFromPlaceholder()}" + cssClass="input-small" /> + + <s:textfield name="filter.periodTo" + label="%{getText('wao.ui.form.period.to')}" + placeholder="%{getFilterPeriodToPlaceholder()}" + cssClass="input-small" /> + + </fieldset> + + <fieldset class="extra-filters"> + + </fieldset> + + <div class="form-actions"> + + <s:submit type="button" action="sampling-plan!applyFilter" cssClass="btn btn-primary"> + <i class="icon-filter"></i> <s:text name="wao.ui.action.filter" /> + </s:submit> + + <s:submit type="button" action="sampling-plan!resetFilter" cssClass="btn"> + <i class="icon-trash"></i> <s:text name="wao.ui.action.reset"/> + </s:submit> + + <s:submit action="export-sampling-plan" type="button" cssClass="btn"> + <i class="icon-download"></i> <s:text name="wao.ui.action.csvExport" /> + </s:submit> + + </div> + + </s:form> + + <div class="sticky-buttons"> + <button type="button" id="switch-compact-full-view" class="btn <s:if test="fullView">full-view</s:if><s:else>compact-view</s:else>"> + <span class="only-in-compact-view"> + <i class="fa fa-expand"></i><span class="only-on-hover"> <s:text name="wao.ui.action.switchToFullView" /></span> + </span> + <span class="only-in-full-view"> + <i class="fa fa-compress"></i><span class="only-on-hover"> <s:text name="wao.ui.action.switchToCompactView" /></span> + </span> + </button> + + <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> + <button type="button" id="switch-estimated-real" class="btn show-estimated"> + <span class="estimated"> + <i class="fa fa-adjust"></i><span class="only-on-hover"> <s:text name="wao.ui.action.viewReal" /></span> + </span> + <span class="real"> + <i class="fa fa-adjust"></i><span class="only-on-hover"> <s:text name="wao.ui.action.viewEstimated" /></span> + </span> + </button> + </s:if> + </div> + +<s:set var="estimatedTides" value="true" /> +<s:set var="fullView" value="%{fullView}" /> +<s:set var="displayTidesReal" value="true" /> + +<s:if test="authenticatedWaoUser.authorizedToViewOtherCompanies"> + <s:set var="nbColumnsForProfessionInFullView" value="16" /> +</s:if> +<s:else> + <s:set var="nbColumnsForProfessionInFullView" value="15" /> +</s:else> +<s:set var="nbColumnsForProfessionInCompactView" value="8" /> +<s:set var="nbColumnsForMonths" value="%{samplingPlan.months.size() + 1}" /> +<s:set var="nbColumnsForOther" value="3" /> +<s:set var="nbColumnsTotalInFullView" value="%{#nbColumnsForProfessionInFullView + #nbColumnsForMonths + #nbColumnsForOther}" /> +<s:set var="nbColumnsTotalInCompactView" value="%{#nbColumnsForProfessionInCompactView + #nbColumnsForMonths + #nbColumnsForOther}" /> + + <table id="sampling-plan" class="large-table sampling-plan show-estimated <s:if test="fullView">full-view</s:if><s:else>compact-view</s:else>"> + <thead> + <tr> + <th colspan="<s:property value="#nbColumnsForProfessionInFullView" />" class="only-in-full-view firstline"> + <s:text name="wao.ui.samplingPlan.sampledProfessions" /> + </th> + <th colspan="<s:property value="#nbColumnsForProfessionInCompactView" />" class="only-in-compact-view firstline"> + <s:text name="wao.ui.samplingPlan.sampledProfessions" /> + </th> + <th colspan="${nbColumnsForMonths}" class="firstline"> + <s:text name="wao.ui.samplingPlan.effort" /> + + <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> + [ + <span class="estimated"> + (<s:text name="wao.ui.samplingPlan.actual" /> + <s:text name="wao.ui.samplingPlan.estimated" />) + </span> + <span class="real"> + <s:text name="wao.ui.samplingPlan.actual" /> + </span> + / + <s:text name="wao.ui.samplingPlan.expected" /> + ] + </s:if> + </th> + <th colspan="${nbColumnsForOther}" class="firstline"><s:text name="wao.ui.misc.others" /></th> + </tr> + <tr> + <!-- Profession columns --> + <th><s:text name="wao.ui.field.SampleRow.code"/></th> + <th><s:text name="wao.ui.samplingPlan.program"/></th> + <s:if test="authenticatedWaoUser.authorizedToViewOtherCompanies"> + <th class="only-in-full-view"> + <s:text name="wao.ui.entity.Company"/> + </th> + </s:if> + <th><s:text name="wao.ui.entity.FishingZone"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.samplingPlan.fishingZoneInfo"/></th> + <th><s:text name="wao.ui.field.SampleRow.terrestrialLocations"/></th> + <th><s:text name="wao.ui.field.SampleRow.terrestrialLocationInfos"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.misc.METIER"/> <br/> <s:text name="wao.ui.field.SampleRow.dcf5Code"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.misc.METIER"/> <br/> <s:text name="wao.ui.field.SampleRow.meshSize"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.misc.METIER"/> <br/> <s:text name="wao.ui.field.SampleRow.size"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.misc.METIER"/> <br/> <s:text name="wao.ui.field.SampleRow.other"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.misc.METIER"/> <br/> <s:text name="wao.ui.field.SampleRow.libelle"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.misc.METIER"/> <br/> <s:text name="wao.ui.field.SampleRow.species"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.periodBegin"/></th> + <th class="only-in-full-view"><s:text name="wao.ui.field.SampleRow.periodEnd"/></th> + <th class="only-in-compact-view"><s:text name="wao.ui.misc.METIER"/> <br/> <s:text name="wao.ui.field.SampleRow.dcf5Code"/></th> + <th class="only-in-compact-view"><s:text name="wao.ui.misc.METIER"/> <br/> <s:text name="wao.ui.field.SampleRow.libelle"/></th> + <th><s:text name="wao.ui.field.SampleRow.samplingStrategy"/></th> + + <!-- Months columns --> + <s:iterator value="samplingPlan.months" var="month"> + <th class="effort <s:if test="isCurrentMonth(#month)"> now</s:if>"> + <span class="month"><s:property value="%{formatDateMonth(#month)}"/></span> + <span class="year"><s:property value="%{formatDateYear(#month)}"/></span> + </th> + </s:iterator> + <th><s:text name="wao.ui.misc.total"/></th> + <!-- Other columns --> + <th> + <s:text name="wao.ui.samplingPlan.averageObservationsCount"/> + </th> + <th><s:text name="wao.ui.misc.comment"/></th> + <th><s:text name="wao.ui.samplingPlan.actions"/></th> + </tr> + </thead> + <tbody> + +<%--Iterate on Facades--%> +<s:iterator value="samplingPlan" var="samplingPlanFacade"> + <tr class="facade-row"> + <th colspan="${nbColumnsTotalInFullView}" class="facade only-in-full-view"> + <s:property value="%{#samplingPlanFacade.facade}"/> + </th> + <th colspan="${nbColumnsTotalInCompactView}" class="facade only-in-compact-view"> + <s:property value="%{#samplingPlanFacade.facade}"/> + </th> + </tr> +<%--Iterate on Sectors --%> +<s:iterator value="samplingPlanFacade" var="samplingPlanSector"> + <tr class="sector-row"> + <th colspan="${nbColumnsTotalInFullView}" class="sector only-in-full-view"> + <s:property value="%{#samplingPlanSector.sectors}"/> + </th> + </tr> + <tr class="sector-row"> + <th colspan="${nbColumnsTotalInCompactView}" class="sector only-in-compact-view"> + <s:property value="%{#samplingPlanSector.sectors}"/> + </th> + </tr> +<%--Iterate on SampleRows --%> +<s:iterator value="samplingPlanSector" var="samplingPlanRow"> + <tr class="sample-row-row<s:if test="sampleRowId.equals(sampleRowToHighlightId)"> highlight</s:if>"> + <th> + <s:property value="code" /> + <s:if test="recentlyUpdated"> + <span class="label label-important"> + <s:text name="wao.ui.misc.recentUpdate" /> + </span> + </s:if> + </th> + <td><s:property value="programName" /></td> + <s:if test="authenticatedWaoUser.authorizedToViewOtherCompanies"> + <td class="only-in-full-view"> + <s:property value="companyName" /> + </td> + </s:if> + <td class="only-in-full-view"><s:property value="fishingZones" /></td> + <td class="only-in-compact-view"> + <s:if test="fishingZonesInfos == null"> + <s:property value="fishingZones"/> + </s:if> + <s:else> + <span data-original-title="<s:property value="fishingZonesInfos" escapeHtml="false"/>" data-toggle="tooltip" data-placement="left"> + <s:property value="fishingZones"/> + </span> + </s:else> + </td> + <td class="only-in-full-view"> + <s:property value="fishingZonesInfos" /> + </td> + <td> + <ul> + <s:iterator value="terrestrialLocationNamesAndDescriptions"> + <li title="<s:property value="value"/>"> + <s:property value="key"/> + </li> + </s:iterator> + </ul> + </td> + <td> + <s:property value="terrestrialLocationInfos"/> + </td> + <td class="only-in-full-view"> + <s:iterator value="dcf5CodesAndDescriptions"> + <abbr title="<s:property value="value"/>"><s:property value="key"/></abbr> + </s:iterator> + </td> + <td class="only-in-full-view"><s:property value="professionMeshSize" /></td> + <td class="only-in-full-view"><s:property value="professionSize" /></td> + <td class="only-in-full-view"><s:property value="professionOther" /></td> + <td class="only-in-full-view"><s:property value="professionLibelle" /></td> + <td class="only-in-full-view"><s:property value="professionSpecies" /></td> + <td class="only-in-full-view"><s:property value="%{formatMonth(periodBegin)}" /></td> + <td class="only-in-full-view"><s:property value="%{formatMonth(periodEnd)}" /></td> + <td class="only-in-compact-view"> + <s:iterator value="dcf5CodesAndDescriptions"> + <abbr title="<s:property value="value"/>"><s:property value="key"/></abbr> + </s:iterator> + <s:property value="professionDescriptionWithoutDCF5" /> + </td> + <td class="only-in-compact-view"> + <s:if test="professionSpecies == null"> + <s:property value="professionLibelle"/> + </s:if> + <s:else> + <span data-original-title="<s:property value="professionSpecies" escapeHtml="false"/>" data-toggle="tooltip" data-placement="left"> + <s:property value="professionLibelle"/> + </span> + </s:else> + </td> + <td> + <s:property value="samplingStrategy"/> + </td> + <!-- Months columns --> +<s:iterator value="samplingPlan.months" var="month"> + <s:set var="expected" value="%{getNbTidesExpected(#month)}"/> + <s:set var="estimated" value="%{getNbTidesEstimated(#month)}"/> + <s:set var="real" value="%{getNbTidesReal(#month)}"/> + <td class="effort <s:if test="isCurrentMonth(#month)"> now</s:if><s:if test="#estimated != #real"> estimated-differ-from-real</s:if>"> + <s:if test="#expected != null"> + <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> + <span class="estimated<s:if test="#estimated < #expected"> lower-than-expected</s:if><s:if test="#estimated > #expected"> higher-than-expected</s:if>"> + <s:property value="#estimated"/> + </span> + <span class="real<s:if test="#real < #expected"> lower-than-expected</s:if><s:if test="#real > #expected"> higher-than-expected</s:if>"> + <s:property value="#real"/> + </span> + / + </s:if> + <s:property value="#expected"/> + </s:if> + </td> +</s:iterator> + <td class="effort"> + <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> + <span class="estimated<s:if test="totalTidesEstimated < totalTidesExpected"> lower-than-expected</s:if><s:if test="totalTidesEstimated > totalTidesExpected"> higher-than-expected</s:if>"> + <s:property value="totalTidesEstimated" /> + </span> + <span class="real<s:if test="totalTidesReal < totalTidesExpected"> lower-than-expected</s:if><s:if test="totalTidesReal > totalTidesExpected"> higher-than-expected</s:if>"> + <s:property value="totalTidesReal" /> + </span> + / + </s:if> + <s:property value="totalTidesExpected" /> + + <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> + <span class="estimated"> + (<s:property value="totalEstimatedPercentage" />) + </span> + <span class="real"> + (<s:property value="totalRealPercentage" />) + </span> + </s:if> + </td> + <td> + <s:property value="averageObservationsCount"/> + </td> + <td> + <s:if test=" ! comment.empty"> + <i title="<s:property value="comment" escapeHtml="false"/>" class="fa fa-comment"></i> + </s:if> + </td> + + <td class="actions"> + <div class="dropdown"> + <a class="btn dropdown-toggle" data-toggle="dropdown" href="#"> + <s:text name="wao.ui.actions" /> + <b class="caret"></b> + </a> + <ul class="dropdown-menu"> + <s:if test="authenticatedWaoUser.authorizedToEditSamplingPlan"> + <li> + <s:url action="edit-sample-row!input" id="editSampleRowUrl"> + <s:param name="sampleRowId" value="sampleRowId" /> + </s:url> + <s:a href="%{editSampleRowUrl}"> + <i class="icon-edit"></i> <s:text name="wao.ui.action.editOrDeleteSampleRow" /> + </s:a> + </li> + </s:if> + <li> + <s:url action="sample-row-log" id="sampleRowLogUrl"> + <s:param name="sampleRowId" value="sampleRowId" /> + </s:url> + <s:a href="%{sampleRowLogUrl}"> + <i class="icon-time"></i> <s:text name="wao.ui.action.viewSampleRowLog" /> + </s:a> + </li> + <li> + <s:url action="sampling-plan" id="sampleRowZoomUrl"> + <s:param name="filter.periodFrom" value="%{formatMonth(firstSampleMonthDate)}"/> + <s:param name="filter.periodTo" value="%{formatMonth(lastSampleMonthDate)}"/> + <s:param name="filter.companyIds" value="%{filter.companyIds}"/> + <s:param name="filter.programNames" value="%{filter.programNames}"/> + <s:param name="filter.sampleRowCodes" value="%{filter.sampleRowCodes}"/> + <s:param name="filter.fishingZoneFacadeNames" value="%{filter.targetSpeciesDcfIds}"/> + <s:param name="filter.fishingZoneSectorNames" value="%{filter.targetSpeciesDcfIds}"/> + <s:param name="filter.fishingGearDcfIds" value="%{filter.targetSpeciesDcfIds}"/> + <s:param name="filter.targetSpeciesDcfIds" value="%{filter.targetSpeciesDcfIds}"/> + </s:url> + <s:a href="%{sampleRowZoomUrl}"> + <i class="icon-filter"></i> <s:text name="wao.ui.action.zoomOnSampleRowPeriod" /> + </s:a> + </li> + <s:if test="elligibleBoatsProvided"> + <li> + <s:url action="boats" id="viewElligibleBoatsUrl"> + <s:param name="filter.elligibleForSampleRowsFilter.sampleRowCodes" value="code" /> + </s:url> + <s:a href="%{viewElligibleBoatsUrl}"> + <i class="fa fa-anchor"></i> <s:text name="wao.ui.action.viewElligibleBoats" /> + </s:a> + </li> + </s:if> + <li> + <s:url action="contacts" id="viewAssociatedContactsUrl"> + <s:param name="filter.sampleRowFilter.sampleRowCodes" value="code" /> + <s:param name="filter.periodFrom" /> + <s:param name="filter.periodTo" /> + </s:url> + <s:a href="%{viewAssociatedContactsUrl}"> + <i class="fa fa-stack-exchange"></i> <s:text name="wao.ui.action.viewAssociatedContacts" /> + </s:a> + </li> + <s:if test="authenticatedWaoUser.authorizedToCreateContact && newContactCreatable"> + <li> + <s:url action="boats" id="createAssociatedContactUrl"> + <s:param name="startBoatSelectionForSampleRowId" value="sampleRowId" /> + </s:url> + <s:a href="%{createAssociatedContactUrl}"> + <i class="icon-plus"></i> <s:text name="wao.ui.action.createAssociatedContact" /> + </s:a> + </li> + </s:if> + </ul> + </div> + </td> + </tr> +<%--Iterate on SampleRows --%> +</s:iterator> +<%--Iterate on Sectors --%> +</s:iterator> +<%--Iterate on Facades--%> +</s:iterator> + + </todby> + <tfoot> + <th colspan="<s:property value="#nbColumnsForProfessionInFullView" />" class="only-in-full-view"> + <s:text name="wao.ui.misc.totals" /> + </th> + <th colspan="<s:property value="#nbColumnsForProfessionInCompactView" />" class="only-in-compact-view"> + <s:text name="wao.ui.misc.totals" /> + </th> + <!-- Months columns --> + <s:iterator value="samplingPlan.months" var="month"> + <td class="effort<s:if test="isCurrentMonth(#month)"> now</s:if>"> + <s:set var="expected" value="%{samplingPlan.getTotalExpected(#month)}"/> + <s:set var="estimated" value="%{samplingPlan.getTotalEstimated(#month)}"/> + <s:set var="real" value="%{samplingPlan.getTotalReal(#month)}"/> + <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> + <span class="estimated<s:if test="#estimated < #expected"> lower-than-expected</s:if><s:if test="#estimated > #expected"> higher-than-expected</s:if>"> + <s:property value="#estimated"/> + </span> + <span class="real<s:if test="#real < #expected"> lower-than-expected</s:if><s:if test="#real > #expected"> higher-than-expected</s:if>"> + <s:property value="#real"/> + </span> + / + </s:if> + <s:property value="#expected"/> + <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> + <span class="estimated"> + (<s:property value="samplingPlan.getTotalEstimatedRatio(#month)"/>) + </span> + <span class="real"> + (<s:property value="samplingPlan.getTotalRealRatio(#month)"/>) + </span> + </s:if> + </td> + </s:iterator> + <td class="effort"> + <s:set var="expected" value="%{samplingPlan.highTotalExpected}"/> + <s:set var="estimated" value="%{samplingPlan.highTotalEstimated}"/> + <s:set var="real" value="%{samplingPlan.highTotalReal}"/> + <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> + <span class="estimated<s:if test="#estimated < #expected"> lower-than-expected</s:if><s:if test="#estimated > #expected"> higher-than-expected</s:if>"> + <s:property value="#estimated"/> + </span> + <span class="real<s:if test="#real < #expected"> lower-than-expected</s:if><s:if test="#real > #expected"> higher-than-expected</s:if>"> + <s:property value="#real"/> + </span> + / + </s:if> + <s:property value="#expected"/> + <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> + <span class="estimated"> + (<s:property value="samplingPlan.highTotalEstimatedRatio"/>) + </span> + <span class="real"> + (<s:property value="samplingPlan.highTotalRealRatio"/>) + </span> + </s:if> + </td> + <td class="effort"> + <s:set var="expected" value="%{samplingPlan.observationTimesInDaysTotalExpected}"/> + <s:set var="estimated" value="%{samplingPlan.observationTimesInDaysTotalEstimated}"/> + <s:set var="real" value="%{samplingPlan.observationTimesInDaysTotalReal}"/> + <s:if test="authenticatedWaoUser.authorizedToViewSamplingPlanReal"> + <span class="estimated<s:if test="#estimated < #expected"> lower-than-expected</s:if><s:if test="#estimated > #expected"> higher-than-expected</s:if>"> + <s:property value="#estimated"/> <s:text name="wao.ui.misc.day"/> + </span> + <span class="real<s:if test="#real < #expected"> lower-than-expected</s:if><s:if test="#real > #expected"> higher-than-expected</s:if>"> + <s:property value="#real"/> <s:text name="wao.ui.misc.day"/> + </span> + / + </s:if> + <s:property value="#expected"/> <s:text name="wao.ui.misc.day"/> + </td> + <th colspan="${nbColumnsForOther}"></th> + </tfoot> + </table> + +</html> Copied: branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/sample-row-log.jsp (from rev 2075, branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/obsmer/sample-row-log.jsp) =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/sample-row-log.jsp (rev 0) +++ branches/wao-4.0-obsvente/wao-web/src/main/webapp/WEB-INF/content/sample-row-log.jsp 2014-06-21 11:01:33 UTC (rev 2081) @@ -0,0 +1,98 @@ +<%-- + #%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% + --%> +<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> +<%@taglib uri="/struts-tags" prefix="s" %> + +<html> + + <head> + <title> + <s:property value="%{t('wao.ui.sampleRowLog.title', sampleRow.code)}" /> + </title> + </head> + + <h1> + <s:property value="%{t('wao.ui.sampleRowLog.title', sampleRow.code)}" /> + </h1> + + <s:iterator value="sampleRow.sampleRowLog" var="sampleRowLogEntry"> + + <article> + <h2> + <s:if test="fromAdmin"> + <s:text name="wao.ui.misc.changeOn" /> + </s:if> + <s:else> + <s:text name="wao.ui.misc.commentAddedOn" /> + </s:else> + <s:property value="topiaCreateDate" /> + <s:text name="wao.ui.misc.by" /> + <s:property value="author.fullName" /> + </h2> + + <s:property value="logText" /> + + <s:property value="comment" /> + + </article> + + </s:iterator> + + <s:if test="authenticatedWaoUser.authorizedToCommentSampleRow"> + + <s:form action="comment-sample-row"> + + <fieldset> + <legend><s:text name="wao.ui.form.addComment" /></legend> + + <s:hidden name="sampleRowId" value="%{sampleRowId}" /> + + <s:textarea name="comment" label="%{getText('wao.ui.misc.comment')}" /> + + <div class="form-actions"> + <s:url namespace="/obsmer" action="sampling-plan" id="samplingPlanUrl" /> + <s:a href="%{samplingPlanUrl}" cssClass="btn"> + <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.goBackToSamplingPlan" /> + </s:a> + + <s:submit type="button" cssClass="btn"> + <i class="icon-hdd"></i> <s:text name="wao.ui.action.save" /> + </s:submit> + </div> + + </fieldset> + + </s:form> + + </s:if> + + <s:else> + + <div class="form-actions"> + <s:url namespace="/obsmer" action="sampling-plan" id="samplingPlanUrl" /> + <s:a href="%{samplingPlanUrl}" cssClass="btn"> + <i class="icon-chevron-left"></i> <s:text name="wao.ui.action.goBackToSamplingPlan" /> + </s:a> + </div> + + </s:else> + +</html> Modified: branches/wao-4.0-obsvente/wao-web/src/main/webapp/endpoints-js.jsp =================================================================== --- branches/wao-4.0-obsvente/wao-web/src/main/webapp/endpoints-js.jsp 2014-06-20 19:35:09 UTC (rev 2080) +++ branches/wao-4.0-obsvente/wao-web/src/main/webapp/endpoints-js.jsp 2014-06-21 11:01:33 UTC (rev 2081) @@ -27,7 +27,7 @@ $(document).ready(function () { // json - WAO.OBSMER_SAMPLE_ROWS_FILTER_VALUES_JSON_URL = '<s:url namespace="/obsmer" action="sample-rows-filter-values-json"/>'; + WAO.SAMPLE_ROWS_FILTER_VALUES_JSON_URL = '<s:url namespace="/" action="sample-rows-filter-values-json"/>'; WAO.UPDATE_BOAT_INFOS_JSON_URL = '<s:url namespace="/" action="update-boat-infos-json"/>'; WAO.BOATS_FILTER_VALUES_JSON_URL = '<s:url namespace="/" action="boats-filter-values-json"/>';