Author: bleny Date: 2011-03-17 16:54:18 +0000 (Thu, 17 Mar 2011) New Revision: 1070 Log: fix unexpected validation error when contact observation begin date is a the end of the month Modified: trunk/pom.xml trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2011-03-17 15:16:54 UTC (rev 1069) +++ trunk/pom.xml 2011-03-17 16:54:18 UTC (rev 1070) @@ -312,7 +312,7 @@ <!-- libraries version --> <nuitonI18nVersion>2.3.1</nuitonI18nVersion> - <nuitonUtilsVersion>2.0</nuitonUtilsVersion> + <nuitonUtilsVersion>2.1-SNAPSHOT</nuitonUtilsVersion> <nuitonWebVersion>1.0</nuitonWebVersion> <topiaVersion>2.5.2</topiaVersion> <eugeneVersion>2.3.1</eugeneVersion> Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java 2011-03-17 15:16:54 UTC (rev 1069) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/SampleRowImpl.java 2011-03-17 16:54:18 UTC (rev 1070) @@ -79,37 +79,37 @@ */ @Override public SampleMonth getSampleMonth(Date date) { - if (getSampleMonth() == null) { - return null; - } -//// Calendar ref = new GregorianCalendar(); -//// ref.setTime(date); -// //log.info("Ref : " + date); -// for (SampleMonth curr : getSampleMonth()) { -// //log.info("Curr month : " + curr.getPeriodDate() + " : " + curr.getPeriodMonth() + " / " + curr.getPeriodYear()); -//// if (ref.get(Calendar.MONTH) == (curr.getPeriodMonth()-1) && ref.get(Calendar.YEAR) == curr.getPeriodYear()) { -//// return curr; -//// } -// Date min = DateUtil.setFirstDayOfMonth(curr.getPeriodDate()); -// Date max = DateUtil.setLastDayOfMonth(curr.getPeriodDate()); -// if (DateUtil.between(date, min, max)) { -// return curr; -// } -// } - if (sampleMonthMap != null) { - // Direct access if map is defined from prepareDataByMonth - String dateFormatted = monthFormat.format(date); - return sampleMonthMap.get(dateFormatted); - } else { - for (SampleMonth curr : getSampleMonth()) { - Date min = DateUtil.setFirstDayOfMonth(curr.getPeriodDate()); - Date max = DateUtil.setLastDayOfMonth(curr.getPeriodDate()); - if (DateUtil.between(date, min, max)) { - return curr; + // will be returned + SampleMonth sampleMonth = null; + + if (getSampleMonth() != null) { + if (sampleMonthMap == null) { + for (SampleMonth curr : getSampleMonth()) { + Date firstDayOfMonth = DateUtil.setFirstDayOfMonth(curr.getPeriodDate()); + Date lastDayOfMonth = DateUtil.setLastDayOfMonth(curr.getPeriodDate()); + + boolean dateIsInMonth = DateUtil.between(date, firstDayOfMonth, lastDayOfMonth); + if (dateIsInMonth) { + sampleMonth = curr; + } + + if (log.isDebugEnabled()) { + log.debug("date " + date + " is in month " + monthFormat.format(curr.getPeriodDate()) + + " [" + firstDayOfMonth + " ; " + lastDayOfMonth + "] : " + dateIsInMonth); + } } + } else { + // Direct access if map is defined from prepareDataByMonth + String dateFormatted = monthFormat.format(date); + return sampleMonthMap.get(dateFormatted); } } - return null; + + if (log.isDebugEnabled()) { + log.debug("sampleMonth for date " + date + " is " + (sampleMonth == null ? "null" : monthFormat.format(sampleMonth.getPeriodDate()))); + } + + return sampleMonth; } @Override Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java =================================================================== --- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2011-03-17 15:16:54 UTC (rev 1069) +++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2011-03-17 16:54:18 UTC (rev 1070) @@ -501,12 +501,18 @@ // Validation for saving contact depends on contactState ContactState contactState = contact.getContactState(); + Date observationBeginDate = contact.getObservationBeginDate(); if (log.isDebugEnabled()) { - log.debug("For state : " + contactState); + log.debug("For state : " + contactState + " and observation begin date " + observationBeginDate); } - Date observationBeginDate = contact.getObservationBeginDate(); - if (success && observationBeginDate != null && ! contact.getSampleRow().isValid(observationBeginDate)) { + boolean operationBeginDateIsValid = contact.getSampleRow().isValid(observationBeginDate); + + if (log.isDebugEnabled()) { + log.debug("operation begin data is valid : " + operationBeginDateIsValid); + } + + if (success && observationBeginDate != null && ! operationBeginDateIsValid) { success = false; message = "La date de début de la marée doit correspondre à un " + "mois valide (non vide) de la ligne " + contact.getSampleRow().getCode();