Author: fdesbois
Date: 2010-01-08 15:02:58 +0000 (Fri, 08 Jan 2010)
New Revision: 178
Modified:
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/ImportHelper.java
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/java/fr/ifremer/suiviobsmer/entity/UserImpl.java
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSynthesisImpl.java
trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo
trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java
trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml
Log:
- Add validation for contact (on dataInputDate)
- Improve Imports with helper (using enums)
- Add synthese service first method to have data on realTides and expectedTides
- WARNING !! Add periodDate field in SampleMonth entity (put deprecated periodMonth and periodYear)
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/ImportHelper.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/ImportHelper.java 2010-01-07 16:15:13 UTC (rev 177)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/ImportHelper.java 2010-01-08 15:02:58 UTC (rev 178)
@@ -21,6 +21,8 @@
package fr.ifremer.suiviobsmer;
+import com.csvreader.CsvReader;
+import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -46,10 +48,17 @@
*/
public class ImportHelper {
+ public interface ImportHeader {
+
+ int forContactCsv();
+
+ String name();
+ }
+
/**
* CSV headers for Boat
*/
- public static enum BOAT {
+ public static enum BOAT implements ImportHeader {
/** Boat immatriculation **/
NAVS_COD(20),
/** Boat name **/
@@ -75,6 +84,7 @@
this.contactHeader = index;
}
+ @Override
public int forContactCsv() {
return contactHeader;
}
@@ -83,7 +93,7 @@
/**
* CSV headers for SamplingPlan
*/
- public static enum SAMPLING {
+ public static enum SAMPLING implements ImportHeader {
/** SampleRow code **/
PLAN_CODE(6),
/** Company name **/
@@ -119,6 +129,7 @@
this.contactHeader = index;
}
+ @Override
public int forContactCsv() {
return contactHeader;
}
@@ -127,7 +138,7 @@
/**
* CSV headers for FishingZone
*/
- public static enum FISHING_ZONE {
+ public static enum FISHING_ZONE implements ImportHeader {
/** FishingZone facade **/
PECHE_FACADE(10),
/** FishingZone sector **/
@@ -141,6 +152,7 @@
this.contactHeader = index;
}
+ @Override
public int forContactCsv() {
return contactHeader;
}
@@ -149,7 +161,7 @@
/**
* CSV headers for Contact
*/
- public static enum CONTACT {
+ public static enum CONTACT implements ImportHeader {
/** Contact code (create date time for existing contact) **/
CONT_CODE(0),
/** Contact create date **/
@@ -189,6 +201,7 @@
this.contactHeader = index;
}
+ @Override
public int forContactCsv() {
return contactHeader;
}
@@ -245,7 +258,8 @@
return mammals ? "X" : "";
}
- public static boolean parseContactMammals(String mammals) {
+ public static boolean parseContactMammals(CsvReader reader, ImportHeader header) throws IOException {
+ String mammals = read(reader, header);
return mammals.equals("X");
}
@@ -300,4 +314,13 @@
return System.currentTimeMillis();
}
+ public static String read(CsvReader reader, ImportHeader header) throws IOException {
+ return reader.get(header.name().trim());
+ }
+
+ public static int readInt(CsvReader reader, ImportHeader header) throws IOException {
+ String str = read(reader, header);
+ return Integer.parseInt(str);
+ }
+
}
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 2010-01-07 16:15:13 UTC (rev 177)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleMonthImpl.java 2010-01-08 15:02:58 UTC (rev 178)
@@ -50,14 +50,73 @@
private static final long serialVersionUID = 1L;
@Override
+ @Deprecated
public void setPeriod(Date date) {
+ setPeriodDate(date);
+ }
+
+// @Override
+// public void setPeriodDate(Date date) {
+// periodDate = date;
+// periodMonth = getCalendar().get(Calendar.MONTH) +1;
+// periodYear = getCalendar().get(Calendar.YEAR);
+// }
+
+ protected Calendar getCalendar() {
Calendar calendar = new GregorianCalendar();
- calendar.setTime(date);
- setPeriodMonth(calendar.get(Calendar.MONTH));
- setPeriodYear(calendar.get(Calendar.YEAR));
+ if (getPeriodDate() != null) {
+ calendar.setTime(getPeriodDate());
+ }
+ return calendar;
}
/**
+ * @since 0.0.3 new attribute periodDate
+ * @deprecated
+ */
+ @Override
+ @Deprecated
+ public int getPeriodMonth() {
+ return getCalendar().get(Calendar.MONTH) + 1;
+ }
+
+ /**
+ * @since 0.0.3 new attribute periodDate
+ * @deprecated
+ */
+ @Override
+ @Deprecated
+ public int getPeriodYear() {
+ return getCalendar().get(Calendar.YEAR);
+ }
+
+ /**
+ * @since 0.0.3 new attribute periodDate
+ * @param month
+ * @deprecated
+ */
+ @Override
+ @Deprecated
+ public void setPeriodMonth(int month) {
+ Calendar calendar = getCalendar();
+ calendar.set(Calendar.MONTH, month - 1);
+ setPeriodDate(calendar.getTime());
+ }
+
+ /**
+ * @since 0.0.3 new attribute periodDate
+ * @param year
+ * @deprecated
+ */
+ @Override
+ @Deprecated
+ public void setPeriodYear(int year) {
+ Calendar calendar = getCalendar();
+ calendar.set(Calendar.YEAR, year);
+ setPeriodDate(calendar.getTime());
+ }
+
+ /**
* 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,
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 2010-01-07 16:15:13 UTC (rev 177)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleRowImpl.java 2010-01-08 15:02:58 UTC (rev 178)
@@ -80,7 +80,9 @@
}
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;
}
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/UserImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/UserImpl.java 2010-01-07 16:15:13 UTC (rev 177)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/UserImpl.java 2010-01-08 15:02:58 UTC (rev 178)
@@ -49,7 +49,9 @@
*/
@Override
public String getFullName() {
- return getFirstName() + " " + getLastName();
+ String name = getFirstName() != null ? getFirstName() : "";
+ name += getLastName() != null ? " " + getLastName() : "";
+ return name;
}
/**
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java 2010-01-07 16:15:13 UTC (rev 177)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceContactImpl.java 2010-01-08 15:02:58 UTC (rev 178)
@@ -368,8 +368,8 @@
while(reader.readRecord()) {
currRow++;
- String observerId = reader.get(CONTACT.OBSERV_ID.name());
- String state = reader.get(CONTACT.CONT_ETAT.name());
+ String observerId = ImportHelper.read(reader, CONTACT.OBSERV_ID);
+ String state = ImportHelper.read(reader, CONTACT.CONT_ETAT);
ContactState contactState = ContactState.createContactStateEnum(state);
@@ -395,12 +395,12 @@
}
if (company != null) {
- String rowCode = reader.get(SAMPLING.PLAN_CODE.name().trim());
+ String rowCode = ImportHelper.read(reader, SAMPLING.PLAN_CODE);
SampleRow row = rowDAO.findByProperties(SampleRow.CODE, rowCode, SampleRow.COMPANY, company);
if (row != null) {
- int boatImmatriculation = Integer.parseInt(reader.get(BOAT.NAVS_COD.name().trim()));
+ int boatImmatriculation = ImportHelper.readInt(reader, BOAT.NAVS_COD);
Boat boat = boatDAO.findByImmatriculation(boatImmatriculation);
@@ -439,10 +439,10 @@
Contact contact = null;
// Check if createDate exist
- String createDateString = reader.get(CONTACT.CONT_CREATION.name().trim());
+ String createDateString = ImportHelper.read(reader, CONTACT.CONT_CREATION);
//Date createDate = !StringUtils.isEmpty(createDateString) ? dateFormat.parse(createDateString) : null;
- String contactCode = reader.get(CONTACT.CONT_CODE.name().trim());
+ String contactCode = ImportHelper.read(reader, CONTACT.CONT_CODE);
Date createDate = ImportHelper.parseContactCreateDate(contactCode, createDateString);
if (log.isDebugEnabled()) {
log.debug("Ligne " + currRow + " : Create date : " + createDate);
@@ -467,17 +467,17 @@
Contact.BOAT, boat);
}
- String tideBeginString = reader.get(CONTACT.CONT_DEBUT_MAREE.name().trim());
- String tideEndString = reader.get(CONTACT.CONT_FIN_MAREE.name().trim());
- String nbObservantsString = reader.get(CONTACT.CONT_NB_OBSERV.name().trim());
+ String tideBeginString = ImportHelper.read(reader, CONTACT.CONT_DEBUT_MAREE);
+ String tideEndString = ImportHelper.read(reader, CONTACT.CONT_FIN_MAREE);
+ String nbObservantsString = ImportHelper.read(reader, CONTACT.CONT_NB_OBSERV);
Date tideBegin = !StringUtils.isEmpty(tideBeginString) ? dateFormat.parse(tideBeginString) : null;
Date tideEnd = !StringUtils.isEmpty(tideEndString) ? dateFormat.parse(tideEndString) : null;
int nbObservants = !StringUtils.isEmpty(nbObservantsString) ? Integer.parseInt(nbObservantsString) : 0;
boolean mammalsCapture =
- ImportHelper.parseContactMammals(reader.get(CONTACT.CONT_MAM_CAPT.name().trim()));
+ ImportHelper.parseContactMammals(reader, CONTACT.CONT_MAM_CAPT);
boolean mammalsObsv =
- ImportHelper.parseContactMammals(reader.get(CONTACT.CONT_MAM_OBS.name().trim()));
+ ImportHelper.parseContactMammals(reader, CONTACT.CONT_MAM_OBS);
contact.setState(state);
contact.setTideBeginDate(tideBegin);
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSynthesisImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSynthesisImpl.java 2010-01-07 16:15:13 UTC (rev 177)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/impl/ServiceSynthesisImpl.java 2010-01-08 15:02:58 UTC (rev 178)
@@ -1,12 +1,24 @@
package fr.ifremer.suiviobsmer.impl;
+import fr.ifremer.suiviobsmer.SuiviObsmerContext;
import fr.ifremer.suiviobsmer.SuiviObsmerException;
+import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper;
+import fr.ifremer.suiviobsmer.entity.SampleMonth;
+import fr.ifremer.suiviobsmer.entity.SampleRow;
+import fr.ifremer.suiviobsmer.entity.SampleRowDAO;
import fr.ifremer.suiviobsmer.services.ServiceSynthesis;
+import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.framework.TopiaQuery;
+import org.nuiton.topia.framework.TopiaQuery.Op;
import org.nuiton.util.PeriodDates;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* ServiceSynthesisImpl
@@ -21,9 +33,59 @@
*/
public class ServiceSynthesisImpl implements ServiceSynthesis {
+ private static final Logger log = LoggerFactory.getLogger(ServiceSynthesisImpl.class);
+
+ protected TopiaContext rootContext;
+
+ public ServiceSynthesisImpl() throws SuiviObsmerException {
+ rootContext = SuiviObsmerContext.getTopiaRootContext();
+ }
+
@Override
- public List<Map<Date, Integer>> getDataSampling(PeriodDates period) throws SuiviObsmerException {
- throw new UnsupportedOperationException("Not supported yet.");
+ public List<SortedMap<Date, Integer>> getDataSampling(PeriodDates period) throws SuiviObsmerException {
+ TopiaContext transaction = null;
+ List<SortedMap<Date, Integer>> results = new ArrayList<SortedMap<Date, Integer>>();
+ try {
+ transaction = rootContext.beginTransaction();
+
+ if (period.getFromDate() == null || period.getThruDate() == null) {
+ return results;
+ }
+
+ SortedMap<Date, Integer> serie1 = new TreeMap<Date,Integer>();
+ SortedMap<Date, Integer> serie2 = new TreeMap<Date,Integer>();
+ results.add(serie1);
+ results.add(serie2);
+
+ // Prepare results
+ for (Date month : period.getMonths()) {
+ serie1.put(month, 0);
+ serie2.put(month, 0);
+ }
+
+ SampleRowDAO dao = SuiviObsmerModelDAOHelper.getSampleRowDAO(transaction);
+ TopiaQuery<SampleRow> query = dao.createQuery("S").
+ addFrom(SampleMonth.class.getName() + " M").add("M IN elements(S)").
+ add("M.periodDate", Op.GE, period.getFromDate()).
+ add("M.periodDate", Op.LE, period.getThruDate()).
+ addGroup("M.periodDate").addOrder("M.periodDate");
+
+ List<Object[]> res =
+ (List<Object[]>)query.setSelect("M.periodDate, SUM(M.realTidesValue), SUM(M.expectedTidesValue)").execute();
+
+ for (Object[] tab : res) {
+ Date date = (Date)tab[0];
+ int sumReal = (Integer)tab[1];
+ int sumExpected = (Integer)tab[2];
+ serie1.put(date, sumExpected);
+ serie2.put(date, sumReal);
+ }
+
+ transaction.closeContext();
+ } catch (Exception eee) {
+
+ }
+ return results;
}
}
Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo
===================================================================
(Binary files differ)
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 2010-01-07 16:15:13 UTC (rev 177)
+++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Contacts.java 2010-01-08 15:02:58 UTC (rev 178)
@@ -227,7 +227,7 @@
@Log
public Object onChangeFromFacadeName(String value) throws SuiviObsmerException {
- if (!StringUtils.isEmpty(value)) {
+ if (!StringUtils.isEmpty(value.trim())) {
// Reset contactFilter to avoid strange behavior (cause of no form submit)
contactFilter = null;
// set facadeName selected in contactFilter
@@ -527,6 +527,9 @@
@InjectComponent
private Field comment;
+ @InjectComponent
+ private Field inputDate;
+
@Log
void onValidateFormFromContactsForm() {
contactsForm.clearErrors();
@@ -538,6 +541,7 @@
Date begin = contact.getTideBeginDate();
Date end = contact.getTideEndDate();
+ Date input = contact.getDataInputDate();
Program program = contact.getSampleRow().getProgram();
DateFormat dateFormat = new SimpleDateFormat("MM/yyyy");
@@ -563,6 +567,14 @@
contactsForm.recordError(endDate, "La date de fin de la marée ne peut pas être postérieure à la date du jour");
}
+ if (end != null && input != null && end.after(input)) {
+ contactsForm.recordError(inputDate, "La date de saisie des données ne peut pas être antérieure à la date de fin de la marée");
+ }
+
+ if (input != null && input.after(current)) {
+ contactsForm.recordError(inputDate, "La date de saisie des données ne peut pas être postérieure à la date du jour");
+ }
+
// Non abouti, Refus ou Refus Définitif
if (contactState.isUnfinishedState()) {
if (!StringUtils.isEmpty(contact.getComment())) {
Modified: trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml
===================================================================
--- trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml 2010-01-07 16:15:13 UTC (rev 177)
+++ trunk/suiviobsmer-ui/src/main/webapp/Contacts.tml 2010-01-08 15:02:58 UTC (rev 178)
@@ -54,11 +54,11 @@
<input t:type="checkbox" t:id="companyAccepted" value="contactFilter.companyAccepted" />
<t:label t:for="companyAccepted">
<img src="${asset:context:}/img/true-22px.png" title="Accepté par la société" />
- </t:label>
+ </t:label>
<input t:type="checkbox" t:id="companyRefused" value="contactFilter.companyRefused" />
<t:label t:for="companyRefused">
<img src="${asset:context:}/img/false-22px.png" title="Refusé par la société" />
- </t:label>
+ </t:label>
<input t:type="checkbox" t:id="companyUndefined" value="contactFilter.companyUndefined" />
<t:label t:for="companyUndefined">
<img src="${asset:context:}/img/help-22px.png" title="Non validé par la société" />
@@ -68,11 +68,11 @@
<input t:type="checkbox" t:id="programAccepted" value="contactFilter.programAccepted" />
<t:label t:for="programAccepted">
<img src="${asset:context:}/img/true-22px.png" title="Accepté par le programme" />
- </t:label>
+ </t:label>
<input t:type="checkbox" t:id="programRefused" value="contactFilter.programRefused" />
<t:label t:for="programRefused">
<img src="${asset:context:}/img/false-22px.png" title="Refusé par le programme" />
- </t:label>
+ </t:label>
<input t:type="checkbox" t:id="programUndefined" value="contactFilter.programUndefined" />
<t:label t:for="programUndefined">
<img src="${asset:context:}/img/help-22px.png" title="Non validé par le programme" />