[Suiviobsmer-commits] r183 - trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages
Author: fdesbois Date: 2010-01-11 17:32:18 +0000 (Mon, 11 Jan 2010) New Revision: 183 Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SampleRowForm.java Log: Ano #1989 and #1990 : Refactor validation to use onValidateForm method + resolve issue on changing dates period Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SampleRowForm.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SampleRowForm.java 2010-01-11 15:18:44 UTC (rev 182) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SampleRowForm.java 2010-01-11 17:32:18 UTC (rev 183) @@ -118,14 +118,6 @@ } void setupRender() throws SuiviObsmerException { - // load models for select -// professionSelectModel = null; -// getProfessionSelectModel(); -// programSelectModel = null; -// getProgramSelectModel(); -// fishingZoneSelectModel = null; -// getFishingZoneSelectModel(); - // load main sampleRow (use of sampleRowId in url) sampleRow = null; getSampleRow(); @@ -145,13 +137,6 @@ } immatriculations = getSampleRow().getMainElligibleBoatsAsString(); - // Initialize fishingZones, programPeriod and sampleMonths for edition -// fishingZones = null; -// getFishingZones(); -// period = null; -// getPeriod(); -// sampleMonths = null; -// getSampleMonths(); } /*************************** PROFESSION ***********************************/ @@ -172,10 +157,6 @@ @Inject private ComponentResources resources; - /** Field codeDCF5 for validation : must be provided **/ -// @InjectComponent -// private BeanEditor professionEditor; - /** * Get SelectModel for profession input Select. The select contains all existing professions. * @@ -317,6 +298,9 @@ private PeriodDates period; + @Persist + private List<Date> months; + private List<SampleMonth> sampleMonths; @Property @@ -346,7 +330,15 @@ } public List<Date> getMonths() throws SuiviObsmerException { - return getPeriod().getMonths(); + if (months == null) { + if (log.isDebugEnabled()) { + log.debug("Reset months list"); + } + months = getPeriod().getMonths(); + sampleMonths = null; + getSampleMonths(); + } + return months; } public Program getProgram() throws SuiviObsmerException { @@ -385,25 +377,19 @@ * The program will be set from the one selected. If no selection, a new one will be set. * @throws SuiviObsmerException */ + @Log void onSelectedFromSearchProgram() throws SuiviObsmerException { Program sampleRowProgram = new ProgramImpl(); if (!StringUtils.isEmpty(programId)) { sampleRowProgram = getProgramSelectModel().findObject(programId); programName = null; period = null; - sampleMonths = null; + months = null; // Period will be reinitialized from program params getSampleRow().setProgram(sampleRowProgram); - - // Update sampleRowCode from program - if (isCreateMode()) { - String rowCode = sampleRowProgram.getNewSampleRowCode(); - getSampleRow().setCode(rowCode); - } - - validateProgram(); + //validateProgram(); } - edited = true; + programChanged = true; } /** @@ -421,62 +407,54 @@ sampleRowProgram.setName(programName); getSampleRow().setProgram(sampleRowProgram); programId = null; - } else { - sampleRowProgram = getSampleRow().getProgram(); } - sampleRowProgram.setPeriodBegin(period.getFromDate()); - sampleRowProgram.setPeriodEnd(period.getThruDate()); - - // Update sampleRowCode from program - if (isCreateMode()) { - String rowCode = sampleRowProgram.getNewSampleRowCode(); - getSampleRow().setCode(rowCode); - } - validateProgram(); - edited = true; + months = null; + getProgram().setPeriodBegin(period.getFromDate()); + getProgram().setPeriodEnd(period.getThruDate()); + programChanged = true; } - @Log - protected boolean validateProgram() throws SuiviObsmerException { - sampleRowForm.clearErrors(); - if (StringUtils.isEmpty(getProgram().getName())) { - sampleRowForm.recordError(program, - "Vous devez choisir un programme existant ou en créer un nouveau"); - } +// @Log +// protected boolean validateProgram() throws SuiviObsmerException { +// sampleRowForm.clearErrors(); +// if (StringUtils.isEmpty(getProgram().getName())) { +// sampleRowForm.recordError(program, +// "Vous devez choisir un programme existant ou en créer un nouveau"); +// } +// +// Date periodBegin = getProgram().getPeriodBegin(); +// Date periodEnd = getProgram().getPeriodEnd(); +// +// // Validation for period dates +// if (periodBegin == null) { +// sampleRowForm.recordError(programPeriodBegin, +// "Vous ne pouvez pas rafraîchir les mois avec une date de début de programme vide"); +// } +// if (periodEnd == null) { +// sampleRowForm.recordError(programPeriodEnd, +// "Vous ne pouvez pas rafraîchir les mois avec une date de fin de programme vide"); +// } +// +// if (periodBegin != null && periodEnd != null) { +// +// int size = getSampleMonths().size(); +// +// SampleMonth firstMonth = getSampleMonths().get(0); +// SampleMonth lastMonth = getSampleMonths().get(size-1); +// +// Date firstDate = DateUtils.createDate( +// 1, firstMonth.getPeriodMonth(), firstMonth.getPeriodYear()); +// +// if (periodBegin.after(firstDate) && firstMonth.getRealTidesValue() != 0) { +// sampleRowForm.recordError(programPeriodBegin, +// "Vous ne pouvez pas réduire la période du programme. " + +// "Il existe des enregistrements de marées réels."); +// } +// } +// return !sampleRowForm.getHasErrors(); +// } - Date periodBegin = getProgram().getPeriodBegin(); - Date periodEnd = getProgram().getPeriodEnd(); - - // Validation for period dates - if (periodBegin == null) { - sampleRowForm.recordError(programPeriodBegin, - "Vous ne pouvez pas rafraîchir les mois avec une date de début de programme vide"); - } - if (periodEnd == null) { - sampleRowForm.recordError(programPeriodEnd, - "Vous ne pouvez pas rafraîchir les mois avec une date de fin de programme vide"); - } - - if (periodBegin != null && periodEnd != null) { - - int size = getSampleMonths().size(); - - SampleMonth firstMonth = getSampleMonths().get(0); - SampleMonth lastMonth = getSampleMonths().get(size-1); - - Date firstDate = DateUtils.createDate( - 1, firstMonth.getPeriodMonth(), firstMonth.getPeriodYear()); - - if (periodBegin.after(firstDate) && firstMonth.getRealTidesValue() != 0) { - sampleRowForm.recordError(programPeriodBegin, - "Vous ne pouvez pas réduire la période du programme. " + - "Il existe des enregistrements de marées réels."); - } - } - return !sampleRowForm.getHasErrors(); - } - /*************************** SAMPLE ROW ***********************************/ private String sampleRowId; @@ -498,6 +476,8 @@ @Property private String companyId; + private List<Boat> boats; + private GenericSelectModel<Company> companySelectModel; private boolean cancel; @@ -547,78 +527,134 @@ } @Log + void onValidateFormFromSampleRowForm() throws SuiviObsmerException { + sampleRowForm.clearErrors(); + try { + // Only for save or programChanged (refreshMonths or searchProgram) + if (!cancel && !edited) { + if (StringUtils.isEmpty(getProgram().getName())) { + sampleRowForm.recordError(program, + "Vous devez choisir un programme existant ou en créer un nouveau"); + } + + Date periodBegin = getProgram().getPeriodBegin(); + Date periodEnd = getProgram().getPeriodEnd(); + + // Validation for period dates + if (periodBegin == null) { + sampleRowForm.recordError(programPeriodBegin, + "Vous ne pouvez pas rafraîchir les mois avec une date de début de programme vide"); + } + if (periodEnd == null) { + sampleRowForm.recordError(programPeriodEnd, + "Vous ne pouvez pas rafraîchir les mois avec une date de fin de programme vide"); + } + + if (periodBegin != null && periodEnd != null) { + + int size = getSampleMonths().size(); + + SampleMonth firstMonth = getSampleMonths().get(0); + SampleMonth lastMonth = getSampleMonths().get(size-1); + + Date firstDate = DateUtils.createDate( + 1, firstMonth.getPeriodMonth(), firstMonth.getPeriodYear()); + + if (periodBegin.after(firstDate) && firstMonth.getRealTidesValue() != 0) { + sampleRowForm.recordError(programPeriodBegin, + "Vous ne pouvez pas réduire la période du programme. " + + "Il existe des enregistrements de marées réels."); + } + } + + // Save profession, fishingZone and boats (from immatriculations) if no programChanged + if (!programChanged) { + + Profession profession = getSampleRow().getProfession(); + if (StringUtils.isEmpty(profession.getCodeDCF5())) { + sampleRowForm.recordError( + "Le métier doit obligatoirement avoir un Code DCF niveau 5"); + } + int nbZones = getSampleRow().sizeFishingZone(); + if (nbZones == 0) { + sampleRowForm.recordError(fishingZoneSelect, + "Vous devez ajouter au moins une zone de pêche à la ligne"); + } + + boats = serviceBoat.getBoats(immatriculations); + // Update sampleRowCode from program only if changed + } else if (isCreateMode()) { + String rowCode = getProgram().getNewSampleRowCode(); + getSampleRow().setCode(rowCode); + } + } + } catch (SuiviObsmerBusinessException eee) { + sampleRowForm.recordError(eee.getMessage()); + log.error("BUSINESS ERROR : " + eee.getType() + " depuis " + eee.getServiceName() + + " : " + eee.getMessage()); + } + + if (log.isDebugEnabled()) { + log.debug("SampleMonths : " + getSampleMonths()); + } + } + + @Log Object onSuccessFromSampleRowForm() throws SuiviObsmerException { if (cancel) { return this; } - if (!edited) { - if (validateProgram()) { - sampleRowForm.clearErrors(); - Profession profession = getSampleRow().getProfession(); - if (StringUtils.isEmpty(profession.getCodeDCF5())) { - sampleRowForm.recordError( - "Le métier doit obligatoirement avoir un Code DCF niveau 5"); - } - int nbZones = getSampleRow().sizeFishingZone(); - if (nbZones == 0) { - sampleRowForm.recordError(fishingZoneSelect, - "Vous devez ajouter au moins une zone de pêche à la ligne"); - } - if (sampleRowForm.getHasErrors()) { - return sampleRowForm; - } + if (!edited && !programChanged) { +// if (validateProgram()) { +// sampleRowForm.clearErrors(); +// Profession profession = getSampleRow().getProfession(); +// if (StringUtils.isEmpty(profession.getCodeDCF5())) { +// sampleRowForm.recordError( +// "Le métier doit obligatoirement avoir un Code DCF niveau 5"); +// } +// int nbZones = getSampleRow().sizeFishingZone(); +// if (nbZones == 0) { +// sampleRowForm.recordError(fishingZoneSelect, +// "Vous devez ajouter au moins une zone de pêche à la ligne"); +// } +// if (sampleRowForm.getHasErrors()) { +// return sampleRowForm; +// } // Save company Company company = getCompanySelectModel().findObject(companyId); getSampleRow().setCompany(company); // Save sampleMonths + + if (log.isDebugEnabled()) { + log.debug("SampleMonths : " + getSampleMonths()); + } + getSampleRow().setSampleMonth(getSampleMonths()); - try { - List<Boat> boats = serviceBoat.getBoats(immatriculations); +// try { +// List<Boat> boats = serviceBoat.getBoats(immatriculations); - serviceSampling.createUpdateSampleRow(sampleRow, boats); + serviceSampling.createUpdateSampleRow(sampleRow, boats); - return SamplingPlan.class; - } catch (SuiviObsmerBusinessException eee) { - sampleRowForm.recordError(eee.getMessage()); - log.error("BUSINESS ERROR : " + eee.getType() + " depuis " + eee.getServiceName()); - } - } - //sampleRow.setFishingZone(fishingZones); USEFUL ? - - // Save period dates - //program = getSampleRow().getProgram(); - //program.setPeriodBegin(period.getFromDate()); - //program.setPeriodEnd(period.getThruDate()); - //return null; -// Company company = getCompanySelectModel().findObject(companyId); -// getSampleRow().setCompany(company); -// -// List<Boat> boats = serviceBoat.getBoats(immatriculations); -// -// serviceSampling.createUpdateSampleRow(sampleRow, boats); -// -// return SamplingPlan.class; + return SamplingPlan.class; +// } catch (SuiviObsmerBusinessException eee) { +// sampleRowForm.recordError(eee.getMessage()); +// log.error("BUSINESS ERROR : " + eee.getType() + " depuis " + eee.getServiceName()); +// } +// } } else { // Reinitialize professionId for select to avoid selection from existing Profession professionId = null; - -// String programTopiaId = program.getTopiaId(); -// // Reinitialize programId for select if it's not the current one -// if (programTopiaId != null && !programTopiaId.equals(programId)) { -// programId = null; -// } - // Reinitialize programName, period and sampleMonths if it's the one selected -// } else { -// programName = null; -// period = null; -// sampleMonths = null; -// } } return sampleRowForm; } + @Log + Object onFailureFromSampleRowForm() { + return sampleRowForm; + } + }
participants (1)
-
fdesbois@users.labs.libre-entreprise.org