[Suiviobsmer-commits] r122 - in trunk: . suiviobsmer-business suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity suiviobsmer-business/src/main/xmi suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages suiviobsmer-ui/src/main/webapp suiviob
Author: fdesbois Date: 2009-12-15 16:03:30 +0000 (Tue, 15 Dec 2009) New Revision: 122 Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactState.java Removed: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/DateUtils.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/PeriodDates.java Modified: trunk/pom.xml trunk/suiviobsmer-business/pom.xml trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleMonthImpl.java trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/SampleRowImplTest.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SampleRowForm.java trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Contacts.properties trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml trunk/suiviobsmer-ui/src/main/webapp/css/contacts.css trunk/suiviobsmer-ui/src/main/webapp/js/dialog.js Log: - Use DateUtils and PeriodDates from Nuiton-utils 1.1.2-SNAPSHOT - Refactor ContactState to use it properly in UI + Add state managment in contact form - Add calcul for realTidesTime Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/pom.xml 2009-12-15 16:03:30 UTC (rev 122) @@ -238,7 +238,7 @@ <labs.id>154</labs.id> <!-- libraries version --> - <nuitonutils.version>1.1.1</nuitonutils.version> + <nuitonutils.version>1.1.2-SNAPSHOT</nuitonutils.version> <topia.version>2.3.0-beta-2-SNAPSHOT</topia.version> <license.version>2.0.0</license.version> <helper.version>1.1.0</helper.version> Modified: trunk/suiviobsmer-business/pom.xml =================================================================== --- trunk/suiviobsmer-business/pom.xml 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/suiviobsmer-business/pom.xml 2009-12-15 16:03:30 UTC (rev 122) @@ -27,6 +27,10 @@ <artifactId>commons-io</artifactId> </dependency> <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-utils</artifactId> + </dependency> + <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> Deleted: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/DateUtils.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/DateUtils.java 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/DateUtils.java 2009-12-15 16:03:30 UTC (rev 122) @@ -1,113 +0,0 @@ -package fr.ifremer.suiviobsmer; - -/** - * *##% - * SuiviObsmer Business - * Copyright (C) 2009 Ifremer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * ##%* - */ - - - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; - -/** - * DateUtils.java - * - * @author fdesbois - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class DateUtils { - - //private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy"); - - public static final String DEFAULT_PATTERN = "dd/MM/yyyy"; - - public static final String MONTH_PATTERN = "MM/yyyy"; - - public static String formatDate(Date date, String pattern) - { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); - return simpleDateFormat.format(date); - } - - public static Date parseDate(String date, String pattern) { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); - Date result = null; - try { - result = simpleDateFormat.parse(date); - } catch (ParseException eee) { - } - return result; - } - - public static Date createDate(int dd, int mm, int yy) { - Calendar calendar = new GregorianCalendar(yy,mm-1,dd); - return calendar.getTime(); - } - - public static Date createDateAfterToday(int ddStep, int mmStep, int yyStep) { - Calendar calendar = new GregorianCalendar(); - calendar.setTime(new Date()); - calendar.add(Calendar.DAY_OF_MONTH, ddStep); - calendar.add(Calendar.MONTH,mmStep); - calendar.add(Calendar.YEAR, yyStep); - return calendar.getTime(); - } - - public static Date setLastDayOfMonth(Date date) { - Calendar calendar = new GregorianCalendar(); - calendar.setTime(date); - int maximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); - calendar.set(Calendar.DAY_OF_MONTH, maximum); - return calendar.getTime(); - } - - public static Date setFirstDayOfMonth(Date date) { - Calendar calendar = new GregorianCalendar(); - calendar.setTime(date); - calendar.set(Calendar.DAY_OF_MONTH, 1); - return calendar.getTime(); - } - - public static boolean between(Date myDate, Date beforeDate, Date afterDate) { - if (myDate == null) { - return false; - } - boolean result = true; - result &= myDate.after(beforeDate) || myDate.equals(beforeDate); - result &= afterDate == null || myDate.before(afterDate) || myDate.equals(afterDate); - return result; - } - - public static boolean currentPeriod(Date beforeDate, Date afterDate) { - return between(new Date(), beforeDate, afterDate); - } - - public static int getMonth(Date date) { - Calendar calendar = new GregorianCalendar(); - calendar.setTime(date); - return calendar.get(Calendar.MONTH); - } -} Deleted: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/PeriodDates.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/PeriodDates.java 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/PeriodDates.java 2009-12-15 16:03:30 UTC (rev 122) @@ -1,216 +0,0 @@ -package fr.ifremer.suiviobsmer; - -/** - * *##% - * SuiviObsmer Business - * Copyright (C) 2009 Ifremer - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/gpl-3.0.html>. - * ##%* - */ - - - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * PeriodDates.java - * - * Created on 2009-08-13 - * - * @author fdesbois - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class PeriodDates { - - private static final Log log = LogFactory.getLog(PeriodDates.class); - - private String pattern; - - private Date fromDate; - - private Calendar fromCalendar; - - private Date thruDate; - - private Calendar thruCalendar; - - public PeriodDates() { - } - - public PeriodDates(Date fromDate, Date thruDate) { - this.fromCalendar = new GregorianCalendar(); - setFromDate(fromDate); - - this.thruCalendar = new GregorianCalendar(); - setThruDate(thruDate); - - this.pattern = DateUtils.DEFAULT_PATTERN; - } - - public PeriodDates(Calendar fromCalendar, Calendar thruCalendar) { - this.fromDate = fromCalendar.getTime(); - this.fromCalendar = fromCalendar; - - this.thruDate = thruCalendar.getTime(); - this.thruCalendar = thruCalendar; - - this.pattern = DateUtils.DEFAULT_PATTERN; - } - - public static PeriodDates createMonthsPeriodFromToday(int monthAfter) { - Calendar calendarFrom = new GregorianCalendar(); - Calendar calendarThru = new GregorianCalendar(); - - calendarFrom.set(Calendar.DAY_OF_MONTH, 1); - calendarFrom.set(Calendar.AM_PM, Calendar.AM); - calendarFrom.set(Calendar.HOUR, 0); - calendarFrom.set(Calendar.MINUTE, 0); - calendarFrom.set(Calendar.SECOND, 0); - calendarFrom.set(Calendar.MILLISECOND, 0); - - calendarThru.setTime(calendarFrom.getTime()); - calendarThru.add(Calendar.MONTH, monthAfter); - int maximum = calendarThru.getActualMaximum(Calendar.DAY_OF_MONTH); - calendarThru.set(Calendar.DAY_OF_MONTH, maximum); - - PeriodDates period = new PeriodDates(calendarFrom, calendarThru); - period.setPattern(DateUtils.MONTH_PATTERN); - return period; - } - - public String getPattern() { - return pattern; - } - - public void setPattern(String pattern) { - this.pattern = pattern; - } - - public void setFromDate(Date fromDate) { - this.fromDate = fromDate; - if (fromDate != null) { - if (fromCalendar == null) { - fromCalendar = new GregorianCalendar(); - } - this.fromCalendar.setTime(fromDate); - } else { - this.fromCalendar = null; - } - } - - public Date getFromDate() { - return this.fromDate; - } - - public int getFromMonth() { - return this.fromCalendar.get(Calendar.MONTH); - } - - public void setThruDate(Date thruDate) { - this.thruDate = thruDate; - if (thruDate != null) { - if (thruCalendar == null) { - thruCalendar = new GregorianCalendar(); - } - this.thruCalendar.setTime(thruDate); - } else { - this.thruCalendar = null; - } - } - - public Date getThruDate() { - return this.thruDate; - } - - public List<Date> getMonths() { - List<Date> months = new ArrayList<Date>(); - if (fromCalendar == null || thruCalendar == null) { - return months; - } - - /*int mFrom = fromCalendar.get(Calendar.MONTH); - int mThru = thruCalendar.get(Calendar.MONTH); - int yFrom = fromCalendar.get(Calendar.YEAR); - int yThru = thruCalendar.get(Calendar.YEAR); - - int nbYears = yThru - yFrom; - int monthRatio = nbYears * 12; - - int y = yFrom; - for(int i = mFrom; i <= mThru + monthRatio; i++) { - Calendar result = new GregorianCalendar(y, i%12, 1); - months.add(result.getTime()); - if (i != 0 && i%11 == 0) { - y++; - } - }*/ - - Calendar current = (Calendar) fromCalendar.clone(); - current.set(Calendar.DAY_OF_MONTH, 1); - Calendar end = (Calendar) thruCalendar.clone(); - end.set(Calendar.DAY_OF_MONTH, 1); - while (!current.equals(end)) { - months.add(current.getTime()); - current.add(Calendar.MONTH, 1); - } - months.add(current.getTime()); - - return months; - } - - public List<String> getFormatedMonths() { - List<String> results = new ArrayList<String>(); - for (Date date : getMonths()) { - String str = DateUtils.formatDate(date, pattern); - results.add(str); - } - return results; - } - - public boolean beforeEnd(Calendar calendar) { - return calendar.before(thruCalendar) || calendar.equals(thruCalendar); - } - - public boolean afterEnd(Calendar calendar) { - return calendar.after(thruCalendar); - } - - public boolean afterBegin(Calendar calendar) { - return calendar.after(fromCalendar) || calendar.equals(fromCalendar); - } - - public boolean between(Calendar calendar) { - return beforeEnd(calendar) && afterBegin(calendar); - } - - - @Override - public String toString() { - String fromStr = DateUtils.formatDate(fromDate, pattern); - String thruStr = DateUtils.formatDate(thruDate, pattern); - return "[ " + fromDate + " (pattern: " + fromStr + ") -> " + thruDate + " (pattern: " + thruStr + ") ]"; - } - -} Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactState.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactState.java (rev 0) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactState.java 2009-12-15 16:03:30 UTC (rev 122) @@ -0,0 +1,92 @@ +/* + * *##% + * SuiviObsmer Business + * Copyright (C) 2009 Ifremer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * ##%* + */ + +package fr.ifremer.suiviobsmer.bean; + +import fr.ifremer.suiviobsmer.bean.states.*; + +/** + * ContactState + * + * Created: 3 déc. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author: fdesbois $ + */ +public enum ContactState { + CONTACT_START("Contact pris", false, false), + + BOARDING_EXPECTED("Embarquement prévu", false, false), + + BOARDING_DONE("Embarquement réalisé", true, false), + + BOAT_UNAVAILABLE("Non abouti", true, true), + + BOAT_REFUSED("Refus", true ,true), + + BOAT_DEFINITIVE_REFUSED("Refus définitif", true, true); + + private String value; + + private boolean finalState; + + private boolean unfinishedState; + + ContactState(String value, boolean finalState, boolean unfinishedState) { + this.value = value; + this.finalState = finalState; + this.unfinishedState = unfinishedState; + } + + @Override + public String toString() { + return this.value; + } + + public boolean isFinalState() { + return this.finalState; + } + + public boolean isUnfinishedState() { + return this.unfinishedState; + } + + public static ContactState createContactStateEnum(String value) { + if (value.equals(CONTACT_START.toString())) { + return CONTACT_START; + } else if (value.equals(BOARDING_EXPECTED.toString())) { + return BOARDING_EXPECTED; + } else if (value.equals(BOARDING_DONE.toString())) { + return BOARDING_DONE; + } else if (value.equals(BOAT_UNAVAILABLE.toString())) { + return BOAT_UNAVAILABLE; + } else if (value.equals(BOAT_REFUSED.toString())) { + return BOAT_REFUSED; + } else if (value.equals(BOAT_DEFINITIVE_REFUSED.toString())) { + return BOAT_DEFINITIVE_REFUSED; + } + return null; + } + +} Property changes on: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactState.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL" Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleMonthImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleMonthImpl.java 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleMonthImpl.java 2009-12-15 16:03:30 UTC (rev 122) @@ -21,10 +21,14 @@ package fr.ifremer.suiviobsmer.entity; +import fr.ifremer.suiviobsmer.SuiviObsmerContext; +import fr.ifremer.suiviobsmer.SuiviObsmerException; +import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import org.nuiton.topia.TopiaContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,4 +57,42 @@ setPeriodYear(calendar.get(Calendar.YEAR)); } + /** + * Method could be use to add some time for realTidesValue or + * remove time with a negative nbDays. + * If nbDays is negative and superior to the current value, + * the real tides value will be set to 0. + * @param nbDays to add or remove (if negative) + * @throws SuiviObsmerException for saving problem + */ + @Override + public void addRealTideTime(int nbDays) throws SuiviObsmerException { + int result = getRealTidesValue() + nbDays; + if (result < 0) { + result = 0; + } + TopiaContext transaction = null; + try { + transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); + + // sux this.setTopiaContext(transaction) not allowed... +// this.setTopiaContext(transaction); +// setRealTidesValue(result); + + SampleMonthDAO dao = SuiviObsmerModelDAOHelper.getSampleMonthDAO(transaction); + SampleMonth month = dao.findByTopiaId(this.getTopiaId()); + month.setRealTidesValue(result); + if (log.isDebugEnabled()) { + log.debug("Change realTideTime from " + getRealTidesValue() + " to " + result); + } + + transaction.commitTransaction(); + transaction.closeContext(); + } catch (Exception eee) { + SuiviObsmerContext.serviceException(transaction, + "Impossible d'enregistrer le nombre de marées réels pour le mois de " + + this.getPeriodMonth() + "/" + this.getPeriodYear() + " [ligne : " + this.getSampleRow().getCode() + "]", eee); + } + } + } Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java =================================================================== --- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java 2009-12-15 16:03:30 UTC (rev 122) @@ -21,12 +21,14 @@ package fr.ifremer.suiviobsmer.entity; +import fr.ifremer.suiviobsmer.SuiviObsmerException; import java.io.Serializable; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Iterator; import java.util.List; +import org.nuiton.util.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -171,4 +173,33 @@ return false; } + @Override + public void addRealTideTime(Contact contact) throws SuiviObsmerException { + int nbDays = getDifferenceDays(contact); + SampleMonth month = getSampleMonth(contact.getTideBeginDate()); + if (log.isDebugEnabled()) { + log.debug("Add tide time " + nbDays + " for " + + month.getPeriodMonth() + "/" + month.getPeriodYear() + " [" + this.getCode() + "]"); + } + month.addRealTideTime(nbDays); + } + + @Override + public void removeRealTideTime(Contact contact) throws SuiviObsmerException { + int nbDays = getDifferenceDays(contact); + SampleMonth month = getSampleMonth(contact.getTideBeginDate()); + if (log.isDebugEnabled()) { + log.debug("Remove tide time " + nbDays + " for " + + month.getPeriodMonth() + "/" + month.getPeriodYear() + " [" + this.getCode() + "]"); + } + month.addRealTideTime(-nbDays); + } + + protected int getDifferenceDays(Contact contact) { + int nbDays = DateUtils.getDifferenceInDays(contact.getTideBeginDate(), contact.getTideEndDate()); + // difference nbDays + 1 for the first day + nbDays++; + return nbDays; + } + } Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo =================================================================== (Binary files differ) Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/SampleRowImplTest.java =================================================================== --- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/SampleRowImplTest.java 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/entity/SampleRowImplTest.java 2009-12-15 16:03:30 UTC (rev 122) @@ -26,6 +26,7 @@ import fr.ifremer.suiviobsmer.SuiviObsmerRunner; import fr.ifremer.suiviobsmer.SuiviObsmerContext; import fr.ifremer.suiviobsmer.business.SuiviObsmerRunnerTest; +import java.util.Date; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -33,6 +34,7 @@ import org.junit.Test; import org.nuiton.topia.TopiaContext; import org.nuiton.topia.TopiaException; +import org.nuiton.util.DateUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.junit.Assert.*; @@ -76,24 +78,14 @@ runner.stop(); } - - /** - * Test of getSampleMonth method, of class SampleRowImpl. - * @throws SuiviObsmerException - * @throws TopiaException - */ - @Test - public void testGetSampleMonth() throws SuiviObsmerException, TopiaException { - log.info("getSampleMonth"); - - /** PREPARE DATA **/ + private SampleRow prepareData() throws SuiviObsmerException, TopiaException { TopiaContext transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); SampleRowDAO dao = SuiviObsmerModelDAOHelper.getSampleRowDAO(transaction); SampleRow row = dao.create(); row.setCode("2010_1"); - + SampleMonthDAO monthDAO = SuiviObsmerModelDAOHelper.getSampleMonthDAO(transaction); SampleMonth month = monthDAO.create(SampleMonth.SAMPLE_ROW, row); @@ -101,12 +93,34 @@ month.setPeriodYear(2009); row.addSampleMonth(month); - transaction.commitTransaction(); - - /** EXEC METHOD **/ + transaction.commitTransaction(); SampleRow myRow = dao.findByCode("2010_1"); transaction.closeContext(); - + return myRow; + } + + private SampleRow getRowFromContext() throws SuiviObsmerException, TopiaException { + TopiaContext transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction(); + SampleRowDAO dao = SuiviObsmerModelDAOHelper.getSampleRowDAO(transaction); + SampleRow resultRow = dao.findByCode("2010_1"); + transaction.closeContext(); + return resultRow; + } + + + /** + * Test of getSampleMonth method, of class SampleRowImpl. + * @throws SuiviObsmerException + * @throws TopiaException + */ + @Test + public void testGetSampleMonth() throws SuiviObsmerException, TopiaException { + log.info("getSampleMonth"); + + /** PREPARE DATA **/ + SampleRow myRow = prepareData(); + + /** EXEC METHOD **/ SampleMonth res = myRow.getSampleMonth(4, 2009); assertNotNull(res); @@ -114,4 +128,66 @@ assertNull(res); } + @Test + public void testAddRealTideTime() throws Exception { + log.info("addRealTideTime"); + + /** PREPARE DATA **/ + SampleRow row = prepareData(); + + Contact contact = new ContactImpl(); + Date beginDate = DateUtils.createDate(12, 4, 2009); + Date endDate = DateUtils.createDate(12, 4, 2009); + contact.setTideBeginDate(beginDate); + contact.setTideEndDate(endDate); + + /** EXEC METHOD **/ + row.addRealTideTime(contact); + SampleMonth result = getRowFromContext().getSampleMonth(beginDate); + assertEquals(1, result.getRealTidesValue()); + + // Reinit result for next test + result.addRealTideTime(-1); + + // Test with a more than one day interval dates from contact + endDate = DateUtils.createDate(18, 4, 2009); + contact.setTideEndDate(endDate); + + getRowFromContext().addRealTideTime(contact); + result = getRowFromContext().getSampleMonth(beginDate); + assertEquals(7, result.getRealTidesValue()); + } + + @Test + public void testRemoveRealTideTime() throws Exception { + log.info("addRealTideTime"); + + /** PREPARE DATA **/ + SampleRow row = prepareData(); + + Contact contact = new ContactImpl(); + Date beginDate = DateUtils.createDate(12, 4, 2009); + Date endDate = DateUtils.createDate(12, 4, 2009); + contact.setTideBeginDate(beginDate); + contact.setTideEndDate(endDate); + + /** EXEC METHOD **/ + row.removeRealTideTime(contact); + SampleMonth result = getRowFromContext().getSampleMonth(beginDate); + // result stay at 0, can't remove 1 day from 0 + assertEquals(0, result.getRealTidesValue()); + + // Reinit result for next test + result.addRealTideTime(12); + + // Test with a more than one day interval dates from contact + endDate = DateUtils.createDate(18, 4, 2009); + contact.setTideEndDate(endDate); + + getRowFromContext().removeRealTideTime(contact); + result = getRowFromContext().getSampleMonth(beginDate); + // result put to 5 : 12 - 7 (diff) + assertEquals(5, result.getRealTidesValue()); + } + } \ No newline at end of file Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java 2009-12-15 16:03:30 UTC (rev 122) @@ -22,10 +22,11 @@ package fr.ifremer.suiviobsmer.ui.pages; import fr.ifremer.suiviobsmer.SuiviObsmerException; -import fr.ifremer.suiviobsmer.bean.states.ContactStateEnum; +import fr.ifremer.suiviobsmer.bean.ContactState; import fr.ifremer.suiviobsmer.entity.Boat; import fr.ifremer.suiviobsmer.entity.Company; import fr.ifremer.suiviobsmer.entity.Contact; +import fr.ifremer.suiviobsmer.entity.SampleMonth; import fr.ifremer.suiviobsmer.entity.SampleRow; import fr.ifremer.suiviobsmer.entity.User; import fr.ifremer.suiviobsmer.services.ServiceBoat; @@ -37,26 +38,23 @@ import fr.ifremer.suiviobsmer.ui.services.ContactModelFactory; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.List; +import java.util.Date; import java.util.Map; import org.apache.commons.lang.BooleanUtils; +import org.apache.commons.lang.StringUtils; import org.apache.tapestry5.ComponentResources; -import org.apache.tapestry5.EventContext; -import org.apache.tapestry5.OptionModel; -import org.apache.tapestry5.SelectModel; +import org.apache.tapestry5.Field; import org.apache.tapestry5.annotations.IncludeStylesheet; import org.apache.tapestry5.annotations.InjectComponent; -import org.apache.tapestry5.annotations.Log; import org.apache.tapestry5.annotations.Persist; import org.apache.tapestry5.annotations.Property; import org.apache.tapestry5.annotations.SessionState; import org.apache.tapestry5.beaneditor.BeanModel; -import org.apache.tapestry5.internal.OptionModelImpl; -import org.apache.tapestry5.internal.SelectModelImpl; +import org.apache.tapestry5.corelib.components.Form; import org.apache.tapestry5.ioc.annotations.Inject; import org.apache.tapestry5.services.BeanModelSource; import org.slf4j.Logger; +import org.nuiton.util.DateUtils; /** * Contacts @@ -99,75 +97,11 @@ @Persist("flash") private String editableContactId; - @Property - private String sampleRowId; - - @Property - private String boatId; - void setupRender() throws SuiviObsmerException { contacts = null; getContacts(); } - void onActivate(EventContext ec) { - if (ec.getCount() > 0) { - boatId = ec.get(String.class, 0); - if (ec.getCount() > 1) { - sampleRowId = ec.get(String.class, 1); - } - } - } - - Object[] onPassivate() { - return new String[] {boatId, sampleRowId}; - } - - /**************************** NEW CONTACT *********************************/ - - private Contact newContact; - - private Boat boat; - - private SampleRow sampleRow; - - public Boat getBoat() throws SuiviObsmerException { - if (boat == null && boatId != null) { - boat = serviceBoat.getBoat(boatId); - } - return boat; - } - - public SampleRow getSampleRow() throws SuiviObsmerException { - if (sampleRow == null && sampleRowId != null) { - sampleRow = serviceSampling.getSampleRow(sampleRowId); - } - return sampleRow; - } - - public Contact getNewContact() throws SuiviObsmerException { - if (newContact == null) { - newContact = serviceContact.getNewContact(user, getSampleRow(), getBoat()); - } - return newContact; - } - - public boolean isSampleRowExists() { - return sampleRowId != null; - } - - public boolean isBoatExists() { - return boatId != null; - } - - public boolean canCreate() { - return isSampleRowExists() && isBoatExists(); - } - - void onSelectedFromAddContact() { - contact = newContact; - } - /**************************** CONTACT LIST ********************************/ @Inject @@ -186,13 +120,11 @@ private Contact contact; private BeanModel<Contact> contactModel; + + private ContactState contactState; - private SelectModel stateSelectModel; - private boolean even = true; -// private ContactContext contactContext; - public Map<String, Contact> getContacts() throws SuiviObsmerException { if (contacts == null) { if (log.isInfoEnabled()) { @@ -213,28 +145,18 @@ return contactModel; } -// public ContactContext getContactContext() throws ContactStateException { -// if (contactContext == null) { -// contactContext = new ContactContextImpl(contact); -// } -// return contactContext; -// } -// -// public List<ContactStateEnum> getContactStateAvailables() throws ContactStateException { -// return getContactContext().getAvailableNextStatesAsEnum(); -// } - - public SelectModel getStateSelectModel() { - if (stateSelectModel == null) { - List<OptionModel> options = new ArrayList<OptionModel>(); - for (ContactStateEnum state : ContactStateEnum.values()) { - options.add(new OptionModelImpl(state.getStringValue(), state.getStringValue())); - } - stateSelectModel = new SelectModelImpl(null, options); + public ContactState getContactState() { + if (contactState == null) { + // initialization + this.contactState = ContactState.createContactStateEnum(contact.getState()); } - return stateSelectModel; + return this.contactState; } + public void setContactState(ContactState contactState) { + this.contactState = contactState; + } + public String getSampleRowDescription() { return BusinessUtils.getTooltipSampleRow(contact.getSampleRow()); } @@ -275,25 +197,26 @@ /**************************** CONTACT ROW ACTION **************************/ + /** + * Flag to know if it's only edition (=true) or save action (=false) + */ private boolean contactEdited; private boolean contactDeleted; public boolean hasActions() { - // pour un non admin : affichage si aucune des deux validations ont été effectuées + return !user.getAdmin() && contact.getValidationCompany() == null; + } + + public boolean canValidate() { + ContactState state = ContactState.createContactStateEnum(contact.getState()); + boolean boardingDone = state.equals(ContactState.BOARDING_DONE) && contact.getDataInputDate() != null; if (!user.getAdmin()) { - return contact.getValidationCompany() == null && - contact.getValidationProgram() == null; + return contact.getValidationCompany() == null && (state.isUnfinishedState() || boardingDone); } -// if (!user.getAdmin()) { -// return getContactStateAvailables().contains(ContactStateEnum.COMPANY_UNLOCKED); -// } - // pour un admin : affichage uniquement si la compagnie a validé la ligne - return BooleanUtils.isTrue(contact.getValidationCompany()); -// return getContactStateAvailables().contains(ContactStateEnum.PROGRAM_UNLOCKED); + return contact.getValidationProgram() == null && BooleanUtils.isTrue(contact.getValidationCompany()); } - @Log public boolean canUnvalidate() { if (!user.getAdmin()) { return contact.getValidationCompany() != null && @@ -303,23 +226,41 @@ } void onSelectedFromAcceptContact(String contactId) throws SuiviObsmerException { - changeValidation(contactId, Boolean.TRUE); + contact = getContacts().get(contactId); + if (user.getAdmin()) { + contact.setValidationProgram(Boolean.TRUE); + } else { + // For company accepted, addRealTideTime + contact.getSampleRow().addRealTideTime(contact); + contact.setValidationCompany(Boolean.TRUE); + } } void onSelectedFromRefuseContact(String contactId) throws SuiviObsmerException { - changeValidation(contactId, Boolean.FALSE); + contact = getContacts().get(contactId); + if (user.getAdmin()) { + // For program refused, removeRealTideTime + contact.getSampleRow().removeRealTideTime(contact); + contact.setValidationProgram(Boolean.FALSE); + } else { + contact.setValidationCompany(Boolean.FALSE); + } } void onSelectedFromUnvalidateContact(String contactId) throws SuiviObsmerException { - changeValidation(contactId, null); - } - - private void changeValidation(String contactId, Boolean value) throws SuiviObsmerException { contact = getContacts().get(contactId); if (user.getAdmin()) { - contact.setValidationProgram(value); + // For program unvalidate from previous refused validation, addRealTideTime + if (BooleanUtils.isFalse(contact.getValidationProgram())) { + contact.getSampleRow().addRealTideTime(contact); + } + contact.setValidationProgram(null); } else { - contact.setValidationCompany(value); + // For company unvalidate from previous accepted validation, removeRealTideTime + if (BooleanUtils.isTrue(contact.getValidationCompany())) { + contact.getSampleRow().removeRealTideTime(contact); + } + contact.setValidationCompany(null); } } @@ -335,7 +276,17 @@ } void onSelectedFromSaveContact(String contactId) throws SuiviObsmerException { - contact = getContacts().get(contactId); + contact = getContacts().get(contactId); + contact.setState(contactState.toString()); + contactsForm.clearErrors(); + if (!validateState()) { + if (log.isDebugEnabled()) { + log.debug("Contact can't be saved with errors"); + } + // The contact is not saved, the contact must be editable to show form and correct errors + contactEdited = true; + editableContactId = contact.getTopiaId(); + } } void onSelectedFromCancelEditContact() throws SuiviObsmerException { @@ -347,8 +298,23 @@ @Persist("flash") private String contactSelectedId; + @InjectComponent + private Form contactsForm; + + @InjectComponent + private Field beginDate; + + @InjectComponent + private Field endDate; + + @InjectComponent + private Field nbObservants; + + @InjectComponent + private Field comment; + void onSuccessFromContactsForm() { - if (!contactEdited) { + if (!contactEdited) { try { if (log.isDebugEnabled()) { log.debug("Contact save : " + contact); @@ -361,6 +327,44 @@ } } + private boolean validateState() { + if (log.isInfoEnabled()) { + log.info("STATE SET : " + contactState); + } + // Non abouti, Refus ou Refus Définitif + if (contactState.isUnfinishedState()) { + if (!StringUtils.isEmpty(contact.getComment())) { + // RAZ des champs + contact.setTideBeginDate(null); + contact.setTideEndDate(null); + contact.setNbObservants(0); + contact.setMammalsCapture(false); + contact.setMammalsObservation(false); + } else { + contactsForm.recordError(comment, "Le commentaire est obligatoire pour l'état '" + contactState + "'"); + } + // Embarquement Réalisé + } else if (contactState.equals(ContactState.BOARDING_DONE)) { + Date begin = contact.getTideBeginDate(); + Date end = contact.getTideEndDate(); + // TODO check program period borns for begin and end ???? + if (begin == null) { + contactsForm.recordError(beginDate, "La date de début de marée est obligatoire pour l'état '" + contactState + "'"); + } + if (end != null) { + if (begin != null && end.before(begin)) { + contactsForm.recordError(endDate, "La date de fin de la marée ne peut être antérieure à celle de début"); + } + } else { + contactsForm.recordError(endDate, "La date de fin de marée est obligatoire pour l'état '" + contactState + "'"); + } + if (contact.getNbObservants() == 0) { + contactsForm.recordError(nbObservants, "Il ne peut y avoir aucun observateur pour l'état '" + contactState + "'"); + } + } + return !contactsForm.getHasErrors(); + } + public void createNewContact(Boat boat, SampleRow sampleRow) throws SuiviObsmerException { contact = serviceContact.getNewContact(user, sampleRow, boat); serviceContact.saveContact(contact, Boolean.FALSE); 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 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SampleRowForm.java 2009-12-15 16:03:30 UTC (rev 122) @@ -18,425 +18,425 @@ * <http://www.gnu.org/licenses/gpl-3.0.html>. * ##%* */ - -package fr.ifremer.suiviobsmer.ui.pages; - -import fr.ifremer.suiviobsmer.PeriodDates; -import fr.ifremer.suiviobsmer.SuiviObsmerException; -import fr.ifremer.suiviobsmer.entity.Boat; -import fr.ifremer.suiviobsmer.entity.Company; -import fr.ifremer.suiviobsmer.entity.FishingZone; -import fr.ifremer.suiviobsmer.entity.Profession; -import fr.ifremer.suiviobsmer.entity.ProfessionImpl; -import fr.ifremer.suiviobsmer.entity.Program; -import fr.ifremer.suiviobsmer.entity.ProgramImpl; -import fr.ifremer.suiviobsmer.entity.SampleMonth; -import fr.ifremer.suiviobsmer.entity.SampleRow; -import fr.ifremer.suiviobsmer.services.ServiceBoat; -import fr.ifremer.suiviobsmer.services.ServiceReferential; -import fr.ifremer.suiviobsmer.services.ServiceSampling; -import fr.ifremer.suiviobsmer.services.ServiceUser; -import fr.ifremer.suiviobsmer.ui.base.GenericSelectModel; -import fr.ifremer.suiviobsmer.ui.base.SuiviObsmerPage; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import org.apache.commons.lang.StringUtils; -import org.apache.tapestry5.Block; -import org.apache.tapestry5.EventContext; -import org.apache.tapestry5.annotations.IncludeStylesheet; -import org.apache.tapestry5.annotations.InjectComponent; -import org.apache.tapestry5.annotations.Log; -import org.apache.tapestry5.annotations.Persist; -import org.apache.tapestry5.annotations.Property; -import org.apache.tapestry5.corelib.components.Zone; -import org.apache.tapestry5.ioc.annotations.Inject; -import org.apache.tapestry5.ioc.services.PropertyAccess; -import org.slf4j.Logger; - -/** - * SampleRowForm - * - * Created: 26 nov. 2009 - * - * @author fdesbois - * @version $Revision$ - * - * Mise a jour: $Date$ - * par : $Author$ - */ - at IncludeStylesheet("context:css/sampling.css") -public class SampleRowForm implements SuiviObsmerPage { - - @Override - public boolean isOnlyForAdmin() { - return true; - } - - @Inject - private Logger log; - - @Inject - private ServiceSampling serviceSampling; - - @Inject - private ServiceReferential serviceReferential; - - @Inject - private ServiceUser serviceUser; - - @Inject - private ServiceBoat serviceBoat; - - @Inject - private PropertyAccess propertyAccess; - - private boolean edited; - - void onActivate(EventContext ec) { - if (ec.getCount() > 0) { - sampleRowId = ec.get(String.class, 0); - } - } - - String onPassivate() { - return sampleRowId; - } - - 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(); - // initialize companyId if exist for companySelect - Company company = getSampleRow().getCompany(); - if (company != null) { - companyId = company.getTopiaId(); - } - immatriculations = getSampleRow().getMainElligibleBoatsAsString(); - // Initialize fishingZones, programPeriod and sampleMonths for edition - fishingZones = null; - getFishingZones(); - period = null; - getPeriod(); - sampleMonths = null; - getSampleMonths(); - } - - /*************************** PROFESSION ***********************************/ - - @Persist - private GenericSelectModel<Profession> professionSelectModel; - - @Property - private String professionId; - - @InjectComponent - private Zone professionZone; - - public GenericSelectModel<Profession> getProfessionSelectModel() throws SuiviObsmerException { - if (professionSelectModel == null) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getProfessions]"); - } - List<Profession> professions = serviceReferential.getProfessions(); - professionSelectModel = new GenericSelectModel<Profession>(professions, Profession.class, - "code", "topiaId", propertyAccess); - } - return professionSelectModel; - } - - void onSelectedFromSearchProfession() throws SuiviObsmerException { - if (log.isDebugEnabled()) { - log.debug("professionId : " + professionId); - } - Profession professionSelected = getProfessionSelectModel().findObject(professionId); - sampleRow.setProfession(professionSelected); - } - - void onSelectedFromAddNewProfession() { - if (log.isDebugEnabled()) { - log.debug("Add new profession"); - } - sampleRow.setProfession(new ProfessionImpl()); - professionId = null; - } - - Block onSuccessFromProfessionForm() throws SuiviObsmerException { - return professionZone.getBody(); - } - - /*************************** FISHING ZONE *********************************/ - - @Persist - private GenericSelectModel<FishingZone> fishingZoneSelectModel; - - @Property - private String fishingZoneId; - - @InjectComponent - private Zone fishingZoneZone; - - @Property - private FishingZone fishingZone; - - @Persist - private List<FishingZone> fishingZones; - - @Property - private int indexFishingZone; - - public GenericSelectModel<FishingZone> getFishingZoneSelectModel() throws SuiviObsmerException { - if (fishingZoneSelectModel == null) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getFishingZones]"); - } - List<FishingZone> fishingZones = serviceReferential.getFishingZones(); - fishingZoneSelectModel = new GenericSelectModel<FishingZone>(fishingZones, FishingZone.class, - "code", "topiaId", propertyAccess); - } - return fishingZoneSelectModel; - } - - public List<FishingZone> getFishingZones() { - if (fishingZones == null) { - fishingZones = sampleRow.getFishingZone(); - } - return fishingZones; - } - - void onSelectedFromAddFishingZone() throws SuiviObsmerException { - fishingZone = getFishingZoneSelectModel().findObject(fishingZoneId); - if (!getFishingZones().contains(fishingZone)) { - if (log.isDebugEnabled()) { - log.debug("Add new fishingZone"); - } - getFishingZones().add(fishingZone); - } - edited = true; - } - - void onSelectedFromRemoveFishingZone(int index) { - if (log.isDebugEnabled()) { - log.debug("Remove fishingZone at position : " + index); - } - getFishingZones().remove(index); - edited = true; - } - - Block onSuccessFromFishingZoneForm() { - if (!edited) { - sampleRow.setFishingZone(fishingZones); - } - return fishingZoneZone.getBody(); - } - - /*************************** PROGRAM & MONTHS *****************************/ - - @Persist - private GenericSelectModel<Program> programSelectModel; - - @Property - private String programName; - - @Property - private String programId; - - @InjectComponent - private Zone periodZone; - - private Program program; - - @Property - private Date month; - - @Persist - private PeriodDates period; - - @Persist - private List<SampleMonth> sampleMonths; - - @Property - private SampleMonth sampleMonth; - - public GenericSelectModel<Program> getProgramSelectModel() throws SuiviObsmerException { - if (programSelectModel == null) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getPrograms]"); - } - List<Program> programs = serviceReferential.getPrograms(); - programSelectModel = new GenericSelectModel<Program>(programs, Program.class, - "name", "topiaId", propertyAccess); - } - return programSelectModel; - } - - public List<Date> getMonths() throws SuiviObsmerException { - return period.getMonths(); - } - - public PeriodDates getPeriod() throws SuiviObsmerException { - if (period == null) { - program = getSampleRow().getProgram(); - if (program.getPeriodBegin() != null && program.getPeriodEnd() != null) { - period = new PeriodDates(program.getPeriodBegin(), program.getPeriodEnd()); - } else { - period = new PeriodDates(); - } - } - return period; - } - - public List<SampleMonth> getSampleMonths() throws SuiviObsmerException { - if (sampleMonths == null) { - sampleMonths = new ArrayList<SampleMonth>(); - for (Date currMonth : getMonths()) { - SampleMonth curr = getSampleRow().getSampleMonth(currMonth); - if (curr == null) { - curr = serviceSampling.getNewSampleMonth(currMonth, getSampleRow()); - } - sampleMonths.add(curr); - } - } - return sampleMonths; - } - - public DateFormat getDateFormat() { - return new SimpleDateFormat("MM/yyyy"); - } - - void onSelectedFromSearchProgram() throws SuiviObsmerException { - // Reset programName - programName = null; - // Reset period to get the one from selected program - period = null; - // Reset sampleMonths for new period - sampleMonths = null; - edited = true; - } - - void onSelectedFromRefreshMonths() throws SuiviObsmerException { - // Reset sampleMonths cause of period modification - sampleMonths = null; - edited = true; - } - - Block onSuccessFromPeriodForm() throws SuiviObsmerException { - // New program - if (isCreateMode()) { - // Name not empty : suppress programId for select - if (!StringUtils.isEmpty(programName)) { - programId = null; - } - - Program currentProgram = getSampleRow().getProgram(); - // Name changed : init new program with current periodBegin and periodEnd - if (!StringUtils.isEmpty(programName) && !programName.equals(currentProgram.getName())) { - program = new ProgramImpl(); - program.setName(programName); - // ProgramId not empty in select : find program with id in selectModel - } else if (!StringUtils.isEmpty(programId)) { - program = getProgramSelectModel().findObject(programId); - // Nor programId neither programName : reinit program object - } else { - program = new ProgramImpl(); - } - // Set program to session with sampleRow - getSampleRow().setProgram(program); - } - // Save sampleMonth - if (sampleMonths != null) { - getSampleRow().setSampleMonth(sampleMonths); - } - if (!edited) { - // Save period dates - program = getSampleRow().getProgram(); - program.setPeriodBegin(period.getFromDate()); - program.setPeriodEnd(period.getThruDate()); - } - - return periodZone.getBody(); - } - - - /*************************** SAMPLE ROW ***********************************/ - - private String sampleRowId; - - @Persist - private SampleRow sampleRow; - - @Property - private String updateComment; - - @Property - private String immatriculations; - - @Property - private String companyId; - - private GenericSelectModel<Company> companySelectModel; - - public SampleRow getSampleRow() throws SuiviObsmerException { - if (sampleRow == null) { - if (!StringUtils.isEmpty(sampleRowId)) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getSampleRow]"); - } - sampleRow = serviceSampling.getSampleRow(sampleRowId); - } else { - sampleRow = serviceSampling.getNewSampleRow(); - } - } - return sampleRow; - } - - public GenericSelectModel<Company> getCompanySelectModel() throws SuiviObsmerException { - if (companySelectModel == null) { - if (log.isInfoEnabled()) { - log.info("BUSINESS REQUEST [getCompanies]"); - } - List<Company> companies = serviceUser.getCompanies(); - companySelectModel = new GenericSelectModel<Company>(companies, Company.class, - "name", "topiaId", propertyAccess); - } - return companySelectModel; - } - - public boolean isCreateMode() throws SuiviObsmerException { - return StringUtils.isEmpty(getSampleRow().getTopiaId()); - } - - void onSelectedFromCancelSave() { - edited = true; - } - - @Log - Object onSuccessFromSampleRowForm() throws SuiviObsmerException { - if (!edited) { - - Company company = getCompanySelectModel().findObject(companyId); - getSampleRow().setCompany(company); - - List<Boat> boats = serviceBoat.getBoats(immatriculations); - - serviceSampling.createUpdateSampleRow(sampleRow, boats); - - return SamplingPlan.class; - - } else { - sampleRow = null; - } - return null; - } - - -} + +package fr.ifremer.suiviobsmer.ui.pages; + +import org.nuiton.util.PeriodDates; +import fr.ifremer.suiviobsmer.SuiviObsmerException; +import fr.ifremer.suiviobsmer.entity.Boat; +import fr.ifremer.suiviobsmer.entity.Company; +import fr.ifremer.suiviobsmer.entity.FishingZone; +import fr.ifremer.suiviobsmer.entity.Profession; +import fr.ifremer.suiviobsmer.entity.ProfessionImpl; +import fr.ifremer.suiviobsmer.entity.Program; +import fr.ifremer.suiviobsmer.entity.ProgramImpl; +import fr.ifremer.suiviobsmer.entity.SampleMonth; +import fr.ifremer.suiviobsmer.entity.SampleRow; +import fr.ifremer.suiviobsmer.services.ServiceBoat; +import fr.ifremer.suiviobsmer.services.ServiceReferential; +import fr.ifremer.suiviobsmer.services.ServiceSampling; +import fr.ifremer.suiviobsmer.services.ServiceUser; +import fr.ifremer.suiviobsmer.ui.base.GenericSelectModel; +import fr.ifremer.suiviobsmer.ui.base.SuiviObsmerPage; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import org.apache.commons.lang.StringUtils; +import org.apache.tapestry5.Block; +import org.apache.tapestry5.EventContext; +import org.apache.tapestry5.annotations.IncludeStylesheet; +import org.apache.tapestry5.annotations.InjectComponent; +import org.apache.tapestry5.annotations.Log; +import org.apache.tapestry5.annotations.Persist; +import org.apache.tapestry5.annotations.Property; +import org.apache.tapestry5.corelib.components.Zone; +import org.apache.tapestry5.ioc.annotations.Inject; +import org.apache.tapestry5.ioc.services.PropertyAccess; +import org.slf4j.Logger; + +/** + * SampleRowForm + * + * Created: 26 nov. 2009 + * + * @author fdesbois + * @version $Revision$ + * + * Mise a jour: $Date$ + * par : $Author$ + */ + at IncludeStylesheet("context:css/sampling.css") +public class SampleRowForm implements SuiviObsmerPage { + + @Override + public boolean isOnlyForAdmin() { + return true; + } + + @Inject + private Logger log; + + @Inject + private ServiceSampling serviceSampling; + + @Inject + private ServiceReferential serviceReferential; + + @Inject + private ServiceUser serviceUser; + + @Inject + private ServiceBoat serviceBoat; + + @Inject + private PropertyAccess propertyAccess; + + private boolean edited; + + void onActivate(EventContext ec) { + if (ec.getCount() > 0) { + sampleRowId = ec.get(String.class, 0); + } + } + + String onPassivate() { + return sampleRowId; + } + + 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(); + // initialize companyId if exist for companySelect + Company company = getSampleRow().getCompany(); + if (company != null) { + companyId = company.getTopiaId(); + } + immatriculations = getSampleRow().getMainElligibleBoatsAsString(); + // Initialize fishingZones, programPeriod and sampleMonths for edition + fishingZones = null; + getFishingZones(); + period = null; + getPeriod(); + sampleMonths = null; + getSampleMonths(); + } + + /*************************** PROFESSION ***********************************/ + + @Persist + private GenericSelectModel<Profession> professionSelectModel; + + @Property + private String professionId; + + @InjectComponent + private Zone professionZone; + + public GenericSelectModel<Profession> getProfessionSelectModel() throws SuiviObsmerException { + if (professionSelectModel == null) { + if (log.isInfoEnabled()) { + log.info("BUSINESS REQUEST [getProfessions]"); + } + List<Profession> professions = serviceReferential.getProfessions(); + professionSelectModel = new GenericSelectModel<Profession>(professions, Profession.class, + "code", "topiaId", propertyAccess); + } + return professionSelectModel; + } + + void onSelectedFromSearchProfession() throws SuiviObsmerException { + if (log.isDebugEnabled()) { + log.debug("professionId : " + professionId); + } + Profession professionSelected = getProfessionSelectModel().findObject(professionId); + sampleRow.setProfession(professionSelected); + } + + void onSelectedFromAddNewProfession() { + if (log.isDebugEnabled()) { + log.debug("Add new profession"); + } + sampleRow.setProfession(new ProfessionImpl()); + professionId = null; + } + + Block onSuccessFromProfessionForm() throws SuiviObsmerException { + return professionZone.getBody(); + } + + /*************************** FISHING ZONE *********************************/ + + @Persist + private GenericSelectModel<FishingZone> fishingZoneSelectModel; + + @Property + private String fishingZoneId; + + @InjectComponent + private Zone fishingZoneZone; + + @Property + private FishingZone fishingZone; + + @Persist + private List<FishingZone> fishingZones; + + @Property + private int indexFishingZone; + + public GenericSelectModel<FishingZone> getFishingZoneSelectModel() throws SuiviObsmerException { + if (fishingZoneSelectModel == null) { + if (log.isInfoEnabled()) { + log.info("BUSINESS REQUEST [getFishingZones]"); + } + List<FishingZone> fishingZones = serviceReferential.getFishingZones(); + fishingZoneSelectModel = new GenericSelectModel<FishingZone>(fishingZones, FishingZone.class, + "code", "topiaId", propertyAccess); + } + return fishingZoneSelectModel; + } + + public List<FishingZone> getFishingZones() { + if (fishingZones == null) { + fishingZones = sampleRow.getFishingZone(); + } + return fishingZones; + } + + void onSelectedFromAddFishingZone() throws SuiviObsmerException { + fishingZone = getFishingZoneSelectModel().findObject(fishingZoneId); + if (!getFishingZones().contains(fishingZone)) { + if (log.isDebugEnabled()) { + log.debug("Add new fishingZone"); + } + getFishingZones().add(fishingZone); + } + edited = true; + } + + void onSelectedFromRemoveFishingZone(int index) { + if (log.isDebugEnabled()) { + log.debug("Remove fishingZone at position : " + index); + } + getFishingZones().remove(index); + edited = true; + } + + Block onSuccessFromFishingZoneForm() { + if (!edited) { + sampleRow.setFishingZone(fishingZones); + } + return fishingZoneZone.getBody(); + } + + /*************************** PROGRAM & MONTHS *****************************/ + + @Persist + private GenericSelectModel<Program> programSelectModel; + + @Property + private String programName; + + @Property + private String programId; + + @InjectComponent + private Zone periodZone; + + private Program program; + + @Property + private Date month; + + @Persist + private PeriodDates period; + + @Persist + private List<SampleMonth> sampleMonths; + + @Property + private SampleMonth sampleMonth; + + public GenericSelectModel<Program> getProgramSelectModel() throws SuiviObsmerException { + if (programSelectModel == null) { + if (log.isInfoEnabled()) { + log.info("BUSINESS REQUEST [getPrograms]"); + } + List<Program> programs = serviceReferential.getPrograms(); + programSelectModel = new GenericSelectModel<Program>(programs, Program.class, + "name", "topiaId", propertyAccess); + } + return programSelectModel; + } + + public List<Date> getMonths() throws SuiviObsmerException { + return period.getMonths(); + } + + public PeriodDates getPeriod() throws SuiviObsmerException { + if (period == null) { + program = getSampleRow().getProgram(); + if (program.getPeriodBegin() != null && program.getPeriodEnd() != null) { + period = new PeriodDates(program.getPeriodBegin(), program.getPeriodEnd()); + } else { + period = new PeriodDates(); + } + } + return period; + } + + public List<SampleMonth> getSampleMonths() throws SuiviObsmerException { + if (sampleMonths == null) { + sampleMonths = new ArrayList<SampleMonth>(); + for (Date currMonth : getMonths()) { + SampleMonth curr = getSampleRow().getSampleMonth(currMonth); + if (curr == null) { + curr = serviceSampling.getNewSampleMonth(currMonth, getSampleRow()); + } + sampleMonths.add(curr); + } + } + return sampleMonths; + } + + public DateFormat getDateFormat() { + return new SimpleDateFormat("MM/yyyy"); + } + + void onSelectedFromSearchProgram() throws SuiviObsmerException { + // Reset programName + programName = null; + // Reset period to get the one from selected program + period = null; + // Reset sampleMonths for new period + sampleMonths = null; + edited = true; + } + + void onSelectedFromRefreshMonths() throws SuiviObsmerException { + // Reset sampleMonths cause of period modification + sampleMonths = null; + edited = true; + } + + Block onSuccessFromPeriodForm() throws SuiviObsmerException { + // New program + if (isCreateMode()) { + // Name not empty : suppress programId for select + if (!StringUtils.isEmpty(programName)) { + programId = null; + } + + Program currentProgram = getSampleRow().getProgram(); + // Name changed : init new program with current periodBegin and periodEnd + if (!StringUtils.isEmpty(programName) && !programName.equals(currentProgram.getName())) { + program = new ProgramImpl(); + program.setName(programName); + // ProgramId not empty in select : find program with id in selectModel + } else if (!StringUtils.isEmpty(programId)) { + program = getProgramSelectModel().findObject(programId); + // Nor programId neither programName : reinit program object + } else { + program = new ProgramImpl(); + } + // Set program to session with sampleRow + getSampleRow().setProgram(program); + } + // Save sampleMonth + if (sampleMonths != null) { + getSampleRow().setSampleMonth(sampleMonths); + } + if (!edited) { + // Save period dates + program = getSampleRow().getProgram(); + program.setPeriodBegin(period.getFromDate()); + program.setPeriodEnd(period.getThruDate()); + } + + return periodZone.getBody(); + } + + + /*************************** SAMPLE ROW ***********************************/ + + private String sampleRowId; + + @Persist + private SampleRow sampleRow; + + @Property + private String updateComment; + + @Property + private String immatriculations; + + @Property + private String companyId; + + private GenericSelectModel<Company> companySelectModel; + + public SampleRow getSampleRow() throws SuiviObsmerException { + if (sampleRow == null) { + if (!StringUtils.isEmpty(sampleRowId)) { + if (log.isInfoEnabled()) { + log.info("BUSINESS REQUEST [getSampleRow]"); + } + sampleRow = serviceSampling.getSampleRow(sampleRowId); + } else { + sampleRow = serviceSampling.getNewSampleRow(); + } + } + return sampleRow; + } + + public GenericSelectModel<Company> getCompanySelectModel() throws SuiviObsmerException { + if (companySelectModel == null) { + if (log.isInfoEnabled()) { + log.info("BUSINESS REQUEST [getCompanies]"); + } + List<Company> companies = serviceUser.getCompanies(); + companySelectModel = new GenericSelectModel<Company>(companies, Company.class, + "name", "topiaId", propertyAccess); + } + return companySelectModel; + } + + public boolean isCreateMode() throws SuiviObsmerException { + return StringUtils.isEmpty(getSampleRow().getTopiaId()); + } + + void onSelectedFromCancelSave() { + edited = true; + } + + @Log + Object onSuccessFromSampleRowForm() throws SuiviObsmerException { + if (!edited) { + + Company company = getCompanySelectModel().findObject(companyId); + getSampleRow().setCompany(company); + + List<Boat> boats = serviceBoat.getBoats(immatriculations); + + serviceSampling.createUpdateSampleRow(sampleRow, boats); + + return SamplingPlan.class; + + } else { + sampleRow = null; + } + return null; + } + + +} Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java =================================================================== --- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java 2009-12-15 16:03:30 UTC (rev 122) @@ -43,7 +43,7 @@ import org.apache.tapestry5.annotations.SessionState; import org.apache.tapestry5.ioc.annotations.Inject; import org.apache.tapestry5.upload.services.UploadedFile; -import fr.ifremer.suiviobsmer.PeriodDates; +import org.nuiton.util.PeriodDates; import fr.ifremer.suiviobsmer.entity.Program; import org.slf4j.Logger; @@ -245,9 +245,9 @@ } public boolean hasNbTidesReal() { - // test with current month ???? Date current = new Date(); - return month.before(current) && !isCurrentMonth() && getNbTidesReal() != null; + boolean validMonth = month.before(current) || isCurrentMonth(); + return validMonth && getNbTidesReal() != null; } public int getTotalTidesExpected() { Modified: trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Contacts.properties =================================================================== --- trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Contacts.properties 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Contacts.properties 2009-12-15 16:03:30 UTC (rev 122) @@ -19,3 +19,12 @@ mammals-label: Observations et captures accidentelles dataInputDate-label: Saisie des donn\u00E9es dans Allegro comment-label: Commentaire + +# Form labels +contactsForm-errors-banner: Le contact n'a pas \u00E9t\u00E9 sauvegard\u00E9 \u00E0 cause des erreurs suivantes : +ContactState.BOAT_UNAVAILABLE: Non abouti +ContactState.BOAT_DEFINITIVE_REFUSED: Refus d\u00E9finitif +ContactState.BOAT_REFUSED: Refus +ContactState.BOARDING_DONE: Embarquement r\u00E9alis\u00E9 +ContactState.BOARDING_EXPECTED: Embarquement pr\u00E9vu +ContactState.CONTACT_START: Contact pris Modified: trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml 2009-12-15 16:03:30 UTC (rev 122) @@ -3,7 +3,9 @@ xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter"> <!--t:include="creationDate, lastState, boatName, boatImmatriculation, boatDistrictCode, beginTideDate, endTideDate, nbObservants, mammals, editDate, comment, validation"--> + <form t:type="form" t:id="contactsForm"> + <t:errors id="so-contact-form-errors" t:banner="message:contactsForm-errors-banner"/> <div t:type="grid" t:source="contacts.values()" t:row="contact" class="t-data-grid ${gridClass}" t:model="contactModel" t:rowClass="prop:rowClass" t:rowsPerPage="20"> <p:sampleRowCell> @@ -21,25 +23,25 @@ </p:boatCell> <p:stateCell> <t:if t:test="editionMode"> - <input t:type="select" t:model="stateSelectModel" value="contact.state" /> + <input t:type="select" t:id="contactState" t:validate="required"/> <p:else>${contact.state}</p:else> </t:if> </p:stateCell> <p:tideBeginDateCell> <t:if t:test="editionMode"> - <input t:type="datefield" class="date" value="contact.tideBeginDate" /> + <input t:type="datefield" t:id="beginDate" class="date" value="contact.tideBeginDate" /> <p:else><t:output value="contact.tideBeginDate" format="dateFormat" /></p:else> </t:if> </p:tideBeginDateCell> <p:tideEndDateCell> <t:if t:test="editionMode"> - <input t:type="datefield" class="date" value="contact.tideEndDate" /> + <input t:type="datefield" t:id="endDate" class="date" value="contact.tideEndDate" /> <p:else><t:output value="contact.tideEndDate" format="dateFormat" /></p:else> </t:if> </p:tideEndDateCell> <p:nbObservantsCell> <t:if t:test="editionMode"> - <input t:type="textfield" class="nbObservants" value="contact.nbObservants" /> + <input t:type="textfield" t:id="nbObservants" class="nbObservants" value="contact.nbObservants" /> <p:else>${contact.nbObservants}</p:else> </t:if> </p:nbObservantsCell> @@ -71,13 +73,13 @@ </p:validationCell> <p:dataInputDateCell> <t:if t:test="editionMode"> - <input t:type="datefield" class="date" value="contact.dataInputDate" /> + <input t:type="datefield" t:id="inputDate" class="date" value="contact.dataInputDate" /> <p:else><t:output value="contact.dataInputDate" format="dateFormat" /></p:else> </t:if> </p:dataInputDateCell> <p:commentCell> <t:if t:test="editionMode"> - <input t:type="textarea" cols="20" rows="2" value="contact.comment" /> + <input t:type="textarea" t:id="comment" cols="20" rows="2" value="contact.comment" /> <p:else> ${contact.comment} </p:else> @@ -85,25 +87,25 @@ </p:commentCell> <p:actionsCell> <t:if t:test="hasActions()"> - <t:unless t:test="user.admin"> - <t:if t:test="editionMode"> - <input t:type="submit" t:id="cancelEditContact" class="ico22px undo22px" value="Undo" - title="Annuler les modifications" /> - <input t:type="submitContext" t:id="saveContact" class="ico22px save22px" value="Save" - t:context="contact.topiaId" title="Enregistrer le contact" /> - <p:else> - <input t:type="submitContext" t:id="editContact" class="ico edit" value="Edit" - t:context="contact.topiaId" title="Modifier le contact" /> - <input t:type="submitContext" t:id="deleteContact" class="ico22px delete" value="Delete" - t:context="contact.topiaId" title="Supprimer le contact" - t:mixins="confirm" t:message="Etes-vous sûr de vouloir supprimer définitivement ce contact ?" /> - </p:else> - </t:if> - </t:unless> + <t:if t:test="editionMode"> + <input t:type="submit" t:id="cancelEditContact" class="ico22px undo22px" value="Undo" + title="Annuler les modifications" /> + <input t:type="submitContext" t:id="saveContact" class="ico22px save22px" value="Save" + t:context="contact.topiaId" title="Enregistrer le contact" /> + <p:else> + <input t:type="submitContext" t:id="editContact" class="ico edit" value="Edit" + t:context="contact.topiaId" title="Modifier le contact" /> + <input t:type="submitContext" t:id="deleteContact" class="ico22px delete" value="Delete" + t:context="contact.topiaId" title="Supprimer le contact" + t:mixins="confirm" t:message="Etes-vous sûr de vouloir supprimer définitivement ce contact ?" /> + </p:else> + </t:if> + </t:if> + <t:if t:test="canValidate()"> <input t:type="submitContext" t:id="acceptContact" class="ico22px accept" value="Accept" - t:context="contact.topiaId" title="Valider le contact" /> + t:context="contact.topiaId" title="Valider le contact" /> <input t:type="submitContext" t:id="refuseContact" class="ico22px refuse" value="Refuse" - t:context="contact.topiaId" title="Refuser le contact" /> + t:context="contact.topiaId" title="Refuser le contact" /> </t:if> <t:if t:test="canUnvalidate()"> <input t:type="submitContext" t:id="unvalidateContact" class="ico22px unvalidate" value="Unvalidate" Modified: trunk/suiviobsmer-ui/src/main/webapp/css/contacts.css =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/css/contacts.css 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/suiviobsmer-ui/src/main/webapp/css/contacts.css 2009-12-15 16:03:30 UTC (rev 122) @@ -50,13 +50,13 @@ div#so-contacts table.t-data-grid thead tr th.dataInputDate, div#so-contacts table.t-data-grid thead tr th.tideEndDate, div#so-contacts table.t-data-grid thead tr th.tideBeginDate { - width: 100px; + width: 120px; white-space: normal; text-align: center; } div#so-contacts table.t-data-grid thead tr th.nbObservants { - width: 20px; + width: 40px; white-space: normal; text-align: center; } @@ -76,18 +76,25 @@ } /** FORM **/ +div#so-contacts div.t-error { + width: 60%; + margin: 5px auto; +} + +div#so-contacts div.t-error li { + margin-left: 20px; +} + div#so-contacts-edit { width: 40%; margin-left: auto; margin-right: auto; } -input.date, /* TEMP */ -div#so-contacts-edit div.t-beaneditor input.date { +input.date { width: 70px; } -input.nbObservants, /* TEMP */ -div#so-contacts-edit div.t-beaneditor input.nbObservants { +input.nbObservants { width: 18px; } Modified: trunk/suiviobsmer-ui/src/main/webapp/js/dialog.js =================================================================== --- trunk/suiviobsmer-ui/src/main/webapp/js/dialog.js 2009-12-15 10:16:12 UTC (rev 121) +++ trunk/suiviobsmer-ui/src/main/webapp/js/dialog.js 2009-12-15 16:03:30 UTC (rev 122) @@ -8,12 +8,12 @@ */ initialize: function(element, message) { this.message = message; - Tapestry.debug('click ' + element); Event.observe($(element), 'click', this.doConfirm.bindAsEventListener(this)); }, doConfirm: function(e) { + //Tapestry.debug('click ' + element); if(! confirm(this.message)) { - Tapestry.debug('STOP ' + e); + //Tapestry.debug('STOP ' + e); Event.stop(e); } }
participants (1)
-
fdesbois@users.labs.libre-entreprise.org