This is an automated email from the git hooks/post-receive script. New commit to branch feature/2263 in repository wao. See http://git.codelutin.com/wao.git commit 321824f7e06ca6331d81be51c38b135eed7962a6 Author: Brendan Le Ny <bleny@codelutin.com> Date: Thu Dec 18 16:37:42 2014 +0100 Ajout des champs scléro dans le formulaire de modification d'une ligne du plan --- .../wao/services/service/SamplingPlanService.java | 18 +++- .../services/service/UpdateSampleRowCommand.java | 51 ++++++++++ .../wao/web/action/EditSampleRowAction.java | 17 +--- .../WEB-INF/content/edit-sample-row-input.jsp | 108 ++++++++++++++------- 4 files changed, 144 insertions(+), 50 deletions(-) diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java index 90e934b..f2c72a1 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/SamplingPlanService.java @@ -59,6 +59,7 @@ 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.Species; import fr.ifremer.wao.entity.TerrestrialLocation; import fr.ifremer.wao.entity.TerrestrialLocationTopiaDao; import fr.ifremer.wao.services.AuthenticatedWaoUser; @@ -288,7 +289,7 @@ public class SamplingPlanService extends WaoServiceSupport { ObsProgram obsProgram = authenticatedWaoUser.getObsProgram(); - UpdateSampleRowCommand updateSampleRowCommand = new UpdateSampleRowCommand(); + UpdateSampleRowCommand updateSampleRowCommand = new UpdateSampleRowCommand(serviceContext.getLocale()); if (optionalSampleRowId.isPresent()) { @@ -341,9 +342,11 @@ public class SamplingPlanService extends WaoServiceSupport { updateSampleRowCommand.setSampleRowLog(newSampleRowLog); updateSampleRowCommand.getSampleRow().addSampleRowLog(newSampleRowLog); + ReferentialService referentialService = getReferentialService(); + ImmutableMap<String, FishingZone> allFishingZones = Maps.uniqueIndex( - getReferentialService().getAllFishingZones(), + referentialService.getAllFishingZones(), TopiaEntities.getTopiaIdFunction() ); updateSampleRowCommand.setAllFishingZones(allFishingZones); @@ -358,18 +361,25 @@ public class SamplingPlanService extends WaoServiceSupport { ImmutableMap<String, Dcf5Code> allDcf5Codes = Maps.uniqueIndex( - getReferentialService().getAllDcf5Codes(), + referentialService.getAllDcf5Codes(), TopiaEntities.getTopiaIdFunction() ); updateSampleRowCommand.setAllDcf5Codes(allDcf5Codes); ImmutableMap<String, TerrestrialLocation> allTerrestrialDistricts = Maps.uniqueIndex( - getReferentialService().getAllTerrestrialDistricts(), + referentialService.getAllTerrestrialDistricts(), TopiaEntities.getTopiaIdFunction() ); updateSampleRowCommand.setAllTerrestrialDistricts(allTerrestrialDistricts); + ImmutableMap<String, Species> allSpecies = + Maps.uniqueIndex( + referentialService.getAllSpecies(), + TopiaEntities.getTopiaIdFunction() + ); + updateSampleRowCommand.setAllSpecies(allSpecies); + return updateSampleRowCommand; } diff --git a/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateSampleRowCommand.java b/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateSampleRowCommand.java index 2087a68..cf233e9 100644 --- a/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateSampleRowCommand.java +++ b/wao-services/src/main/java/fr/ifremer/wao/services/service/UpdateSampleRowCommand.java @@ -27,12 +27,16 @@ import com.google.common.collect.Collections2; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; +import fr.ifremer.wao.WaoUtils; import fr.ifremer.wao.entity.Company; import fr.ifremer.wao.entity.Dcf5Code; import fr.ifremer.wao.entity.FishingZone; +import fr.ifremer.wao.entity.IndividualMeasurementStrategy; import fr.ifremer.wao.entity.SampleMonth; import fr.ifremer.wao.entity.SampleRow; import fr.ifremer.wao.entity.SampleRowLog; +import fr.ifremer.wao.entity.SclerochronologySamplingContext; +import fr.ifremer.wao.entity.Species; import fr.ifremer.wao.entity.TerrestrialLocation; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -44,7 +48,9 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; +import java.util.EnumMap; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -52,6 +58,8 @@ public class UpdateSampleRowCommand implements Serializable{ private static final long serialVersionUID = 1L; + protected Locale locale; + protected DateFormat monthFormat = new SimpleDateFormat("yyyyMM"); protected boolean creation; @@ -72,11 +80,17 @@ public class UpdateSampleRowCommand implements Serializable{ protected ImmutableMap<String, TerrestrialLocation> allTerrestrialDistricts; + protected ImmutableMap<String, Species> allSpecies; + /** * La clé est un mois au format YYYY-MM */ protected Map<String, Integer> expectedObservationsByMonths; + public UpdateSampleRowCommand(Locale locale) { + this.locale = locale; + } + public Map<String, Integer> getExpectedObservationsByMonths() { if (expectedObservationsByMonths == null) { expectedObservationsByMonths = new LinkedHashMap<>(); @@ -245,4 +259,41 @@ public class UpdateSampleRowCommand implements Serializable{ public void setSampleRowMemento(SampleRow sampleRowMemento) { this.sampleRowMemento = sampleRowMemento; } + + public ImmutableMap<SclerochronologySamplingContext, String> getAllSclerochronologySamplingContexts() { + EnumMap<SclerochronologySamplingContext, String> allSclerochronologySamplingContexts = new EnumMap<>(SclerochronologySamplingContext.class); + for (SclerochronologySamplingContext sclerochronologySamplingContext : SclerochronologySamplingContext.values()) { + allSclerochronologySamplingContexts.put(sclerochronologySamplingContext, WaoUtils.l(locale, sclerochronologySamplingContext)); + } + return ImmutableMap.copyOf(allSclerochronologySamplingContexts); + } + + public ImmutableMap<IndividualMeasurementStrategy, String> getAllIndividualMeasurementStrategies() { + EnumMap<IndividualMeasurementStrategy, String> allIndividualMeasurementStrategies = new EnumMap<>(IndividualMeasurementStrategy.class); + for (IndividualMeasurementStrategy individualMeasurementStrategy : IndividualMeasurementStrategy.values()) { + allIndividualMeasurementStrategies.put(individualMeasurementStrategy, WaoUtils.l(locale, individualMeasurementStrategy)); + } + return ImmutableMap.copyOf(allIndividualMeasurementStrategies); + } + + public ImmutableMap<String, Species> getAllSpecies() { + return allSpecies; + } + + public void setAllSpecies(ImmutableMap<String, Species> allSpecies) { + this.allSpecies = allSpecies; + } + + public String getSpeciesId() { + String speciesId = null; + if (sampleRow.getSpecies() != null) { + speciesId = sampleRow.getSpecies().getTopiaId(); + } + return speciesId; + } + + public void setSpeciesId(String speciesId) { + Species species = allSpecies.get(speciesId); + sampleRow.setSpecies(species); + } } diff --git a/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java b/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java index 814f729..a03b8f9 100644 --- a/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java +++ b/wao-web/src/main/java/fr/ifremer/wao/web/action/EditSampleRowAction.java @@ -98,10 +98,6 @@ public class EditSampleRowAction extends WaoJspActionSupport implements Preparab service.validate(getAuthenticatedWaoUser(), updateSampleRowCommand); - if (sampleRow.isDcf5CodeEmpty()) { - addFieldError("updateSampleRowCommand.dcf5Codes", t("wao.ui.form.SampleRow.error.missingDcf5Codes")); - } - } catch (UnknownBoatRegistrationCodesException e) { addFieldError("updateSampleRowCommand.elligibleBoatRegistrationCodes", t("wao.ui.unknownBoatRegistrationCodes", Joiner.on(", ").join(e.getRegistrationCodes()))); } catch (SampleRowCodeMustBeUniqueException e) { @@ -126,16 +122,13 @@ public class EditSampleRowAction extends WaoJspActionSupport implements Preparab } catch (MissingDcf5CodesException e) { addFieldError("updateSampleRowCommand.dcf5Codes", t("wao.ui.form.SampleRow.error.missingDcf5Codes")); } catch (NoEffortDefinedException e) { - addFieldError("updateSampleRowCommand.dcf5Codes", t("wao.ui.form.SampleRow.error.noEffortDefined")); - } - - // TODO brendan 18/12/14 - catch (MissingIndividualMeasurementStrategyException e) { - throw new UnsupportedOperationException(); + addActionError(t("wao.ui.form.SampleRow.error.noEffortDefined")); + } catch (MissingIndividualMeasurementStrategyException e) { + addFieldError("updateSampleRowCommand.sampleRow.individualMeasurementStrategy", t("wao.ui.form.SampleRow.error.noIndividualMeasurementStrategyDefined")); } catch (MissingSclerochronologySamplingContextException e) { - throw new UnsupportedOperationException(); + addFieldError("updateSampleRowCommand.sampleRow.sclerochronologySamplingContext", t("wao.ui.form.SampleRow.error.noSclerochronologySamplingContextDefined")); } catch (MissingSpeciesException e) { - throw new UnsupportedOperationException(); + addFieldError("updateSampleRowCommand.sampleRow.species", t("wao.ui.form.SampleRow.error.noSpeciesDefined")); } } diff --git a/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp b/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp index ba792c8..ab8ccd4 100644 --- a/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp +++ b/wao-web/src/main/webapp/WEB-INF/content/edit-sample-row-input.jsp @@ -118,47 +118,85 @@ <s:hidden name="sampleRowId" value="%{sampleRowId}" /> - <fieldset> + <s:if test="updateSampleRowCommand.sampleRow.obsProgram.obsMer || updateSampleRowCommand.sampleRow.obsProgram.obsVente"> - <legend><s:text name="wao.ui.field.SampleRow.profession" /></legend> + <fieldset> - <s:textfield name="updateSampleRowCommand.sampleRow.profession.libelle" - label="%{getText('wao.ui.field.SampleRow.libelle')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - cssClass="input-xxlarge" /> + <legend><s:text name="wao.ui.field.SampleRow.profession" /></legend> - <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.libelle" + label="%{getText('wao.ui.field.SampleRow.libelle')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + cssClass="input-xxlarge" /> - <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.size" + label="%{getText('wao.ui.field.SampleRow.size')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + inputAppend="m" + 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.meshSize" + label="%{getText('wao.ui.field.SampleRow.meshSize')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + inputAppend="mm" + cssClass="input-small" /> - <s:textfield name="updateSampleRowCommand.sampleRow.profession.other" - label="%{getText('wao.ui.field.SampleRow.other')}" - disabled="updateSampleRowCommand.observationAlreadyStarted" - cssClass="input-xxlarge" /> + <s:textfield name="updateSampleRowCommand.sampleRow.profession.species" + label="%{getText('wao.ui.field.SampleRow.species')}" + 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" - /> + <s:textfield name="updateSampleRowCommand.sampleRow.profession.other" + label="%{getText('wao.ui.field.SampleRow.other')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + cssClass="input-xxlarge" /> - </fieldset> + <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> + + </s:if> + + <s:if test="updateSampleRowCommand.sampleRow.obsProgram.sclerochronology"> + + <fieldset> + + <legend><s:text name="wao.ui.field.SampleRow.profession" /></legend> + + <s:select name="updateSampleRowCommand.sampleRow.sclerochronologySamplingContext" + label="%{getText('wao.ui.field.SampleRow.sclerochronologySamplingContext')}" + list="updateSampleRowCommand.allSclerochronologySamplingContexts" + disabled="updateSampleRowCommand.observationAlreadyStarted" /> + + <s:textfield name="updateSampleRowCommand.sampleRow.sclerochronologySamplingContextInfo" + label="%{getText('wao.ui.field.SampleRow.sclerochronologySamplingContextInfo')}" + cssClass="input-xxlarge" + disabled="updateSampleRowCommand.observationAlreadyStarted" /> + + <s:select name="updateSampleRowCommand.sampleRow.individualMeasurementStrategy" + label="%{getText('wao.ui.field.SampleRow.individualMeasurementStrategy')}" + list="updateSampleRowCommand.allIndividualMeasurementStrategies" + cssClass="input-xlarge" + disabled="updateSampleRowCommand.observationAlreadyStarted" /> + + <s:select name="updateSampleRowCommand.speciesId" + label="%{getText('wao.ui.field.SampleRow.species')}" + disabled="updateSampleRowCommand.observationAlreadyStarted" + list="updateSampleRowCommand.allSpecies" + listValue="%{value.permanentCode + ' ' + value.vernacularName}" + cssClass="input-xxlarge select2" + /> + + </fieldset> + + </s:if> <fieldset> @@ -257,7 +295,9 @@ </s:if> - <s:textarea name="updateSampleRowCommand.elligibleBoatRegistrationCodes" label="%{getText('wao.ui.field.SampleRow.elligibleBoat')}" /> + <s:if test="updateSampleRowCommand.sampleRow.obsProgram.obsMer || updateSampleRowCommand.sampleRow.obsProgram.obsVente"> + <s:textarea name="updateSampleRowCommand.elligibleBoatRegistrationCodes" label="%{getText('wao.ui.field.SampleRow.elligibleBoat')}" /> + </s:if> <s:textarea name="updateSampleRowCommand.sampleRow.comment" label="%{getText('wao.ui.field.SampleRow.comment')}" /> -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.