Wao-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- 2352 discussions
[Suiviobsmer-commits] r353 - trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity
by fdesbois@users.labs.libre-entreprise.org 16 Feb '10
by fdesbois@users.labs.libre-entreprise.org 16 Feb '10
16 Feb '10
Author: fdesbois
Date: 2010-02-16 10:56:02 +0000 (Tue, 16 Feb 2010)
New Revision: 353
Modified:
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleMonthImpl.java
Log:
Improve isCurrentMonth method adding year test
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-02-12 18:18:54 UTC (rev 352)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/entity/SampleMonthImpl.java 2010-02-16 10:56:02 UTC (rev 353)
@@ -103,8 +103,10 @@
int currentMonth = current.get(Calendar.MONTH);
int month = calendar.get(Calendar.MONTH);
+ int currentYear = current.get(Calendar.YEAR);
+ int year = calendar.get(Calendar.YEAR);
- return month == currentMonth;
+ return month == currentMonth && currentYear == year;
}
}
1
0
[Suiviobsmer-commits] r352 - in trunk: suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages suiviobsmer-ui/src/main/webapp
by fdesbois@users.labs.libre-entreprise.org 12 Feb '10
by fdesbois@users.labs.libre-entreprise.org 12 Feb '10
12 Feb '10
Author: fdesbois
Date: 2010-02-12 18:18:54 +0000 (Fri, 12 Feb 2010)
New Revision: 352
Modified:
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java
trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java
trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties
trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml
Log:
Evo #1985 : Add day in date format, suppress validation and use createQueryForContactDone.
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java 2010-02-12 18:01:51 UTC (rev 351)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java 2010-02-12 18:18:54 UTC (rev 352)
@@ -91,6 +91,7 @@
if (period == null || period.getFromDate() == null || period.getThruDate() == null) {
return results;
}
+ period.initDayOfMonthExtremities();
// Expected
SortedMap<Date, Integer> serie1 = new TreeMap<Date,Integer>();
@@ -369,7 +370,8 @@
"AND " + tideBeginDate + " BETWEEN :fromDate AND :thruDate)" +
" OR (" + tideBeginDate + " IS NULL " +
"AND " + createDate + " BETWEEN :fromDate AND :thruDate)");
-
+
+ period.initDayOfMonthExtremities();
query.addParam("fromDate", period.getFromDate()).
addParam("thruDate", period.getThruDate());
}
@@ -429,9 +431,12 @@
ContactDAO dao = SuiviObsmerModelDAOHelper.getContactDAO(transaction);
- String contact = "C";
- TopiaQuery query = dao.createQuery(contact);
+// String contact = "C";
+// TopiaQuery query = dao.createQuery(contact);
+
+ TopiaQuery query = dao.createQueryDoneContactsFromDate(null, period.getFromDate());
+ String contact = query.getMainAlias();
String companyKey = contact + "." + Contact.OBSERVER + "." + WaoUser.COMPANY;
String companyName = companyKey + "." + Company.NAME;
@@ -440,13 +445,14 @@
}
String tideBegin = contact + "." + Contact.TIDE_BEGIN_DATE;
- period.initDayOfMonthExtremities();
- query.add(tideBegin + " BETWEEN :fromDate AND :thruDate").
- addParam("fromDate", period.getFromDate()).
- addParam("thruDate", period.getThruDate());
+ //period.initDayOfMonthExtremities();
+ if (period.getThruDate() != null) {
+ query.add(tideBegin, Op.LE, period.getThruDate());
+ }
+
String dataInput = contact + "." + Contact.DATA_INPUT_DATE;
- query.addNotNull(dataInput);
+ //query.addNotNull(dataInput);
// FIXME-FD20100212 Hack for H2 which not managed day for date diff
// TopiaContextImplementor context = (TopiaContextImplementor)transaction;
Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java
===================================================================
--- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java 2010-02-12 18:01:51 UTC (rev 351)
+++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java 2010-02-12 18:18:54 UTC (rev 352)
@@ -473,6 +473,8 @@
contact1.setTideBeginDate(begin);
Date inputDate = DateUtils.createDate(15, 4, 2009);
contact1.setDataInputDate(inputDate);
+ contact1.setState(ContactState.BOARDING_DONE.toString());
+ contact1.setValidationCompany(Boolean.TRUE);
serviceContact.saveContact(contact1, false);
Contact contact2 = new ContactImpl();
@@ -481,6 +483,8 @@
contact2.setTideBeginDate(begin);
inputDate = DateUtils.createDate(15, 3, 2009);
contact2.setDataInputDate(inputDate);
+ contact2.setState(ContactState.BOARDING_DONE.toString());
+ contact2.setValidationCompany(Boolean.TRUE);
serviceContact.saveContact(contact2, false);
Contact contact3 = new ContactImpl();
@@ -488,6 +492,8 @@
begin = DateUtils.createDate(3, 3, 2009);
contact3.setTideBeginDate(begin);
contact3.setDataInputDate(begin);
+ contact3.setState(ContactState.BOARDING_DONE.toString());
+ contact3.setValidationCompany(Boolean.TRUE);
serviceContact.saveContact(contact3, false);
/** EXEC METHOD **/
Modified: trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties
===================================================================
--- trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties 2010-02-12 18:01:51 UTC (rev 351)
+++ trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties 2010-02-12 18:18:54 UTC (rev 352)
@@ -22,5 +22,5 @@
filtersForm-periodEnd-required-message: La date de fin est obligatoire
filterPeriodForContactStates-periodBeginForContactStates-required-message: La date de d\u00E9but est obligatoire
filterPeriodForContactStates-periodEndForContactStates-required-message: La date de fin est obligatoire
-filterPeriodForAllegroReactivity-periodBeginForAllegroReactivity-required-message: La date de d\u00E9but est obligatoire
-filterPeriodForAllegroReactivity-periodEndForAllegroReactivity-required-message: La date de fin est obligatoire
\ No newline at end of file
+#filterPeriodForAllegroReactivity-periodBeginForAllegroReactivity-required-message: La date de d\u00E9but est obligatoire
+#filterPeriodForAllegroReactivity-periodEndForAllegroReactivity-required-message: La date de fin est obligatoire
\ No newline at end of file
Modified: trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml
===================================================================
--- trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml 2010-02-12 18:01:51 UTC (rev 351)
+++ trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml 2010-02-12 18:18:54 UTC (rev 352)
@@ -144,7 +144,7 @@
<t:if t:test="user.admin">
<p>
Ces résultats concernent l'ensemble des contrats en cours
- ayant des données réelles.
+ ayant des données réelles (contacts validés).
</p>
<table class="t-data-grid">
<thead>
@@ -165,7 +165,7 @@
<p:else>
<p>
Ce résultat concerne l'ensemble des contrats en cours
- pour votre société ayant des données réelles.
+ pour votre société ayant des données réelles (contacts validés).
</p>
<div class="indicator">
<p class="number">
@@ -238,16 +238,16 @@
<h2>Réactivité de la saisie dans Allegro par rapport à la date de fin de la marée</h2>
<br />
<p>
- Ce résultat est une moyenne du nombre de jours entre la date de saisie dans Allegro et la date de fin de la marée des contacts.
+ Ce résultat est une moyenne du nombre de jours entre la date de saisie dans Allegro et la date de fin de la marée des contacts validés.
</p>
<br />
<p>
<form t:type="form" t:id="filterPeriodForAllegroReactivity">
<label>Période : </label>
<t:label t:for="periodBeginForAllegroReactivity" />
- <input t:type="datefield" class="width70" t:id="periodBeginForAllegroReactivity" t:value="periodForAllegroReactivity.fromDate" t:format="MM/yyyy" t:validate="required"/>
+ <input t:type="datefield" class="width70" t:id="periodBeginForAllegroReactivity" t:value="periodForAllegroReactivity.fromDate" />
<t:label t:for="periodEndForAllegroReactivity" />
- <input t:type="datefield" class="width70" t:id="periodEndForAllegroReactivity" t:value="periodForAllegroReactivity.thruDate" t:format="MM/yyyy" t:validate="required" />
+ <input t:type="datefield" class="width70" t:id="periodEndForAllegroReactivity" t:value="periodForAllegroReactivity.thruDate" />
<input t:type="submit" class="ico search-32px" t:id="searchForAllegroReactivity" value="Search"
title="Calcul de la moyenne du nombre de jours entre la date de saisie dans Allegro et la date de fin de marée sur la période sélectionnée"/>
</form>
1
0
[Suiviobsmer-commits] r351 - in trunk: suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services suiviobsmer-business/src/main/xmi suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services 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
by fdesbois@users.labs.libre-entreprise.org 12 Feb '10
by fdesbois@users.labs.libre-entreprise.org 12 Feb '10
12 Feb '10
Author: fdesbois
Date: 2010-02-12 18:01:51 +0000 (Fri, 12 Feb 2010)
New Revision: 351
Added:
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactAverageReactivityImpl.java
Modified:
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceBoatImpl.java
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSamplingImpl.java
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java
trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo
trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java
trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java
trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java
trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties
trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml
Log:
Ano #2103 : Problem with inPlace and GridPage when changing page and return to it : the page is not saved. The inPlace is not used anymore neither the passivate/activate for boatSelectedImmatriculation put in @Persist("flash") to preserve it in BoatInfos. The page loading is necessary to keep page change for navigation and reset boatInfos data to avoid gridDataSource problem (search a boat which is not in the dataSource).
Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactAverageReactivityImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactAverageReactivityImpl.java (rev 0)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactAverageReactivityImpl.java 2010-02-12 18:01:51 UTC (rev 351)
@@ -0,0 +1,32 @@
+
+package fr.ifremer.suiviobsmer.bean;
+
+/**
+ * ContactAverageReactivityImpl
+ *
+ * Created: 12 févr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class ContactAverageReactivityImpl extends ContactAverageReactivity {
+
+ @Override
+ public void addValue(int nbDays) {
+ nbResults++;
+ if (nbDays < 0) {
+ // Not normal, problem with some existing data (maybe from import)
+ nbDays = 0;
+ }
+ totalDays += nbDays;
+ }
+
+ @Override
+ public double getResult() {
+ return (double)totalDays / (double)nbResults;
+ }
+
+}
Property changes on: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/bean/ContactAverageReactivityImpl.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceBoatImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceBoatImpl.java 2010-02-12 17:26:04 UTC (rev 350)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceBoatImpl.java 2010-02-12 18:01:51 UTC (rev 351)
@@ -414,8 +414,8 @@
String activeStr = ImportHelper.read(reader, BOAT.NAVS_ACTIVE);
boolean active = !activeStr.equals(BOAT.getBoatInactiveCode());
- if (log.isDebugEnabled()) {
- log.debug("Active : " + active + " (" + activeStr + ")");
+ if (log.isTraceEnabled()) {
+ log.trace("Active : " + active + " (" + activeStr + ")");
}
// Find existing boat with immatriculation
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSamplingImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSamplingImpl.java 2010-02-12 17:26:04 UTC (rev 350)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSamplingImpl.java 2010-02-12 18:01:51 UTC (rev 351)
@@ -810,9 +810,9 @@
List<String> districtList = new ArrayList<String>(Arrays.asList(districts.split(FISHING_ZONE.getDistrictCodeSeparator())));
- if (log.isDebugEnabled()) {
- log.debug("FishingZone districts : " + districts);
- log.debug("FishingZone nb zones : " + districtList.size());
+ if (log.isTraceEnabled()) {
+ log.trace("FishingZone districts : " + districts);
+ log.trace("FishingZone nb zones : " + districtList.size());
}
for (String districtCode : districtList) {
FishingZone zone = dao.findByDistrictCode(districtCode.trim());
@@ -887,31 +887,7 @@
}
month.setExpectedTidesValue(monthValue);
}
-// else if (monthValue != null) {
-// // exception, outOfBounds month
-// if (log.isErrorEnabled()) {
-// log.error("Month out of bounds : value=" + monthValue + " _ monthDate=" + monthDate +
-// " _ periode=" + sampleRow.getPeriodBegin() + " au " + sampleRow.getPeriodEnd());
-// }
-// }
}
}
-// protected static final int TAB_MONTH = 0;
-// protected static final int TAB_YEAR = 1;
-
-// @Deprecated
-// protected int[] getMonthAndYear(String str) throws ParseException {
-// DateFormat dateFormat = new SimpleDateFormat("MM/yyyy");
-// int[] result = new int[2];
-//
-// Date date = dateFormat.parse(str);
-// Calendar calendar = new GregorianCalendar();
-// calendar.setTime(date);
-//
-// result[TAB_MONTH] = calendar.get(Calendar.MONTH) + 1;
-// result[TAB_YEAR] = calendar.get(Calendar.YEAR);
-// return result;
-// }
-
}
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java 2010-02-12 17:26:04 UTC (rev 350)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java 2010-02-12 18:01:51 UTC (rev 351)
@@ -24,6 +24,8 @@
import fr.ifremer.suiviobsmer.SuiviObsmerContext;
import fr.ifremer.suiviobsmer.SuiviObsmerException;
import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper;
+import fr.ifremer.suiviobsmer.bean.ContactAverageReactivityImpl;
+import fr.ifremer.suiviobsmer.bean.ContactAverageReactivity;
import fr.ifremer.suiviobsmer.bean.BoardingResult;
import fr.ifremer.suiviobsmer.bean.BoardingResultImpl;
import fr.ifremer.suiviobsmer.bean.ContactStateStatistics;
@@ -49,10 +51,10 @@
import java.util.SortedMap;
import java.util.TreeMap;
import org.nuiton.topia.TopiaContext;
-import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.framework.TopiaQuery.Op;
import org.nuiton.topia.persistence.TopiaEntity;
+import org.nuiton.util.DateUtils;
import org.nuiton.util.PeriodDates;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -416,11 +418,12 @@
}
@Override
- public Map<String, Double> getContactDataInputDateReactivity(Company company, PeriodDates period) throws SuiviObsmerException {
+ public Collection<ContactAverageReactivity> getContactDataInputDateReactivity(Company company, PeriodDates period) throws SuiviObsmerException {
TopiaContext transaction = null;
// Carefull with results, the company may not be present in the map :
// only if there is no unfinished sampleRow or no contact done
- Map<String, Double> results = new HashMap<String, Double>();
+
+ Map<String, ContactAverageReactivity> results = new HashMap<String, ContactAverageReactivity>();
try {
transaction = rootContext.beginTransaction();
@@ -428,7 +431,7 @@
String contact = "C";
TopiaQuery query = dao.createQuery(contact);
-
+
String companyKey = contact + "." + Contact.OBSERVER + "." + WaoUser.COMPANY;
String companyName = companyKey + "." + Company.NAME;
@@ -446,36 +449,67 @@
query.addNotNull(dataInput);
// FIXME-FD20100212 Hack for H2 which not managed day for date diff
- TopiaContextImplementor context = (TopiaContextImplementor)transaction;
- String dialect = context.getHibernateConfiguration().getProperty("hibernate.dialect");
+// TopiaContextImplementor context = (TopiaContextImplementor)transaction;
+// String dialect = context.getHibernateConfiguration().getProperty("hibernate.dialect");
- String avg = "AVG(day(" + dataInput + " - " + tideBegin + "))";
- if (dialect.contains("H2Dialect")) {
- avg = "AVG(" + dataInput + " - " + tideBegin + ")";
- }
+// String avg = "AVG(day(" + dataInput + " - " + tideBegin + "))";
+// if (dialect.contains("H2Dialect")) {
+// avg = "AVG(" + dataInput + " - " + tideBegin + ")";
+// }
- query.setSelect(companyName, avg).addGroup(companyName);
+ //query.setSelect(companyName, avg).addGroup(companyName);
+ query.setSelect(companyName, dataInput, tideBegin);
- if (log.isTraceEnabled()) {
- log.trace("Exec query : " + query);
+ if (log.isDebugEnabled()) {
+ log.debug("Exec query : " + query);
}
List<Object[]> res = query.execute();
for (Object[] row : res) {
String rowCompanyName = (String)row[0];
- Double rowAverage = (Double)row[1];
- if (log.isTraceEnabled()) {
- log.trace("Company : " + rowCompanyName);
- log.trace("Res : " + rowAverage.doubleValue());
+ Date rowDataInputDate = (Date)row[1];
+ Date rowTideBeginDate = (Date)row[2];
+
+ int nbDays = DateUtils.getDifferenceInDays(rowTideBeginDate, rowDataInputDate);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Company : " + rowCompanyName);
+ log.debug("tideBegin : " + rowTideBeginDate);
+ log.debug("dataInput : " + rowDataInputDate);
+ log.debug("nbDays : " + nbDays);
}
- if (rowAverage < 0) {
- rowAverage = 0.;
+
+ ContactAverageReactivity avg = results.get(rowCompanyName);
+ if (avg == null) {
+ avg = new ContactAverageReactivityImpl();
+ avg.setCompanyName(rowCompanyName);
+ results.put(rowCompanyName, avg);
}
- results.put(rowCompanyName, rowAverage);
+
+ avg.addValue(nbDays);
+
+
+
+// String rowCompanyName = (String)row[0];
+// Object rowAverage = row[1];
+// if (log.isDebugEnabled()) {
+// log.debug("Company : " + rowCompanyName);
+// log.debug("Res : " + rowAverage.getClass().getName());
+// log.debug("Res : " + rowAverage);
+// log.debug("tideBegin : " + (Date)row[3]);
+// log.debug("dataInput : " + (Date)row[2]);
+// }
+//// Double d = new Double((double)rowAverage.intValue());
+//// if (rowAverage < 0) {
+//// rowAverage = 0.;
+//// }
+// results.put(rowCompanyName, 0.);
}
+
+
} catch (Exception eee) {
String msgEnd = "";
if (company != null) {
@@ -487,7 +521,7 @@
} finally {
SuiviObsmerContext.closeTransaction(transaction);
}
- return results;
+ return results.values();
}
}
Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo
===================================================================
(Binary files differ)
Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java
===================================================================
--- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java 2010-02-12 17:26:04 UTC (rev 350)
+++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java 2010-02-12 18:01:51 UTC (rev 351)
@@ -6,6 +6,7 @@
import fr.ifremer.suiviobsmer.SuiviObsmerRunner;
import fr.ifremer.suiviobsmer.SuiviObsmerRunnerTest;
import fr.ifremer.suiviobsmer.bean.BoardingResult;
+import fr.ifremer.suiviobsmer.bean.ContactAverageReactivity;
import fr.ifremer.suiviobsmer.bean.ContactState;
import fr.ifremer.suiviobsmer.bean.ContactStateStatistics;
import fr.ifremer.suiviobsmer.entity.Boat;
@@ -27,6 +28,7 @@
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import org.nuiton.topia.TopiaContext;
import org.nuiton.util.DateUtils;
@@ -493,19 +495,24 @@
PeriodDates period = new PeriodDates(begin, begin);
// result for company TARTANPION
- Map<String, Double> results =
+ Collection<ContactAverageReactivity> results =
service.getContactDataInputDateReactivity(company, period);
assertEquals(1, results.size());
// 12 days for contact1 + 43 days for contact2 / 2 = 27.5 days
- assertEquals(28, results.get(company.getName()), 0.01);
+ ContactAverageReactivity res =
+ (ContactAverageReactivity)CollectionUtils.get(results, 0);
+ assertEquals(27., res.getResult(), 0.01);
+
// result for company BIS using admin mode (no company filtered)
results = service.getContactDataInputDateReactivity(null, period);
// 0 days for contact3 / 1 = O days
- assertEquals(0, results.get(company2.getName()), 0.01);
+ res = (ContactAverageReactivity)CollectionUtils.get(results, 0);
+
+ assertEquals(0, res.getResult(), 0.01);
}
}
\ No newline at end of file
Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java
===================================================================
--- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java 2010-02-12 17:26:04 UTC (rev 350)
+++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java 2010-02-12 18:01:51 UTC (rev 351)
@@ -728,9 +728,15 @@
/** /////////////////////// ACTIONS //////////////////////////////////// **/
+ void onSuccess() throws SuiviObsmerException {
+ if (getBoatInfos() != null) {
+ boatSelectedImmatriculation = getBoatInfos().getBoat().getImmatriculation();
+ }
+ }
+
Block onSuccessFromCompanySelectForm() throws SuiviObsmerException {
companyBoatInfos = null;
- getCompanyBoatInfos();
+ getCompanyBoatInfos();
return boatInfosZone.getBody();
}
@@ -752,7 +758,7 @@
}*/
// Set boatSelectedImmatriculation for boatInfos to reinitialize it (next getBoatInfos() call)
- //boatSelectedImmatriculation = getBoatInfos().getBoat().getImmatriculation();
+ boatSelectedImmatriculation = getBoatInfos().getBoat().getImmatriculation();
// Suppress boatInfos to get the one from serviceBoat (not updated yet)
companyBoatInfos = null;
return boatInfosZone.getBody();
@@ -782,10 +788,12 @@
// Save data
serviceBoat.createUpdateCompanyBoatInfos(companyBoatInfos);
}
+ //boatSelectedImmatriculation = getBoatInfos().getBoat().getImmatriculation();
return boatInfosZone.getBody();
}
Block onSuccessFromCalculateBoardings() throws SuiviObsmerException {
+ //boatSelectedImmatriculation = getBoatInfos().getBoat().getImmatriculation();
return boatInfosZone.getBody();
}
Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java
===================================================================
--- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java 2010-02-12 17:26:04 UTC (rev 350)
+++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java 2010-02-12 18:01:51 UTC (rev 351)
@@ -27,6 +27,7 @@
import fr.ifremer.suiviobsmer.bean.BoatFilterImpl;
import fr.ifremer.suiviobsmer.bean.ContactState;
import fr.ifremer.suiviobsmer.bean.ContactStateStatistics;
+import fr.ifremer.suiviobsmer.bean.ContactAverageReactivity;
import fr.ifremer.suiviobsmer.entity.Company;
import fr.ifremer.suiviobsmer.entity.WaoUser;
import fr.ifremer.suiviobsmer.services.ServiceSynthesis;
@@ -45,6 +46,7 @@
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.tapestry5.Block;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.IncludeStylesheet;
@@ -405,15 +407,15 @@
/********************* INDICATOR : NONCOMPLIANCEBOARDING ******************/
- private Map<String, Double> allegroReactivity;
+ private Collection<ContactAverageReactivity> allegroReactivity;
@Persist
private PeriodDates periodForAllegroReactivity;
@Property
- private Map.Entry<String, Double> allegroReactivityEntry;
+ private ContactAverageReactivity allegroReactivityEntry;
- public Map<String, Double> getAllegroReactivity()
+ public Collection<ContactAverageReactivity> getAllegroReactivity()
throws SuiviObsmerException {
if (allegroReactivity == null) {
Company company = !user.getAdmin() ? user.getCompany() : null;
@@ -431,12 +433,14 @@
}
public Double getAllegroReactivityValue() throws SuiviObsmerException {
- return getAllegroReactivity().get(user.getCompany().getName());
+ ContactAverageReactivity entry =
+ (ContactAverageReactivity) CollectionUtils.get(getAllegroReactivity(), 0);
+ return entry.getResult();
}
public String getAllegroReactivityStyle() throws SuiviObsmerException {
double value = user.getAdmin() ?
- allegroReactivityEntry.getValue() : getAllegroReactivityValue();
+ allegroReactivityEntry.getResult() : getAllegroReactivityValue();
if (value >= 15.) {
return " warn";
}
Modified: trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties
===================================================================
--- trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties 2010-02-12 17:26:04 UTC (rev 350)
+++ trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties 2010-02-12 18:01:51 UTC (rev 351)
@@ -15,4 +15,12 @@
periodEndForContactStates-label: au
periodBeginForAllegroReactivity-label: du
-periodEndForAllegroReactivity-label: au
\ No newline at end of file
+periodEndForAllegroReactivity-label: au
+
+# Validation messages
+filtersForm-periodBegin-required-message: La date de d\u00E9but est obligatoire
+filtersForm-periodEnd-required-message: La date de fin est obligatoire
+filterPeriodForContactStates-periodBeginForContactStates-required-message: La date de d\u00E9but est obligatoire
+filterPeriodForContactStates-periodEndForContactStates-required-message: La date de fin est obligatoire
+filterPeriodForAllegroReactivity-periodBeginForAllegroReactivity-required-message: La date de d\u00E9but est obligatoire
+filterPeriodForAllegroReactivity-periodEndForAllegroReactivity-required-message: La date de fin est obligatoire
\ No newline at end of file
Modified: trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml
===================================================================
--- trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml 2010-02-12 17:26:04 UTC (rev 350)
+++ trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml 2010-02-12 18:01:51 UTC (rev 351)
@@ -57,9 +57,9 @@
<div class="filterRow">
<label>Période: </label>
<t:label t:for="periodBegin" />:
- <input t:type="datefield" class="width70" t:id="periodBegin" t:value="period.fromDate" t:format="MM/yyyy"/>
+ <input t:type="datefield" class="width70" t:id="periodBegin" t:value="period.fromDate" t:format="MM/yyyy" t:validate="required"/>
<t:label t:for="periodEnd" />:
- <input t:type="datefield" class="width70" t:id="periodEnd" t:value="period.thruDate" t:format="MM/yyyy" />
+ <input t:type="datefield" class="width70" t:id="periodEnd" t:value="period.thruDate" t:format="MM/yyyy" t:validate="required"/>
</div>
<div>
<t:if t:test="user.admin">
@@ -192,9 +192,9 @@
<form t:type="form" t:id="filterPeriodForContactStates">
<label>Période : </label>
<t:label t:for="periodBeginForContactStates" />
- <input t:type="datefield" class="width70" t:id="periodBeginForContactStates" t:value="periodForContactStates.fromDate" t:format="MM/yyyy"/>
+ <input t:type="datefield" class="width70" t:id="periodBeginForContactStates" t:value="periodForContactStates.fromDate" t:format="MM/yyyy" t:validate="required"/>
<t:label t:for="periodEndForContactStates" />
- <input t:type="datefield" class="width70" t:id="periodEndForContactStates" t:value="periodForContactStates.thruDate" t:format="MM/yyyy" />
+ <input t:type="datefield" class="width70" t:id="periodEndForContactStates" t:value="periodForContactStates.thruDate" t:format="MM/yyyy" t:validate="required" />
<input t:type="submit" class="ico search-32px" t:id="searchForContactStates" value="Search"
title="Rechercher les états des contacts sur cette période"/>
</form>
@@ -245,9 +245,9 @@
<form t:type="form" t:id="filterPeriodForAllegroReactivity">
<label>Période : </label>
<t:label t:for="periodBeginForAllegroReactivity" />
- <input t:type="datefield" class="width70" t:id="periodBeginForAllegroReactivity" t:value="periodForAllegroReactivity.fromDate" t:format="MM/yyyy"/>
+ <input t:type="datefield" class="width70" t:id="periodBeginForAllegroReactivity" t:value="periodForAllegroReactivity.fromDate" t:format="MM/yyyy" t:validate="required"/>
<t:label t:for="periodEndForAllegroReactivity" />
- <input t:type="datefield" class="width70" t:id="periodEndForAllegroReactivity" t:value="periodForAllegroReactivity.thruDate" t:format="MM/yyyy" />
+ <input t:type="datefield" class="width70" t:id="periodEndForAllegroReactivity" t:value="periodForAllegroReactivity.thruDate" t:format="MM/yyyy" t:validate="required" />
<input t:type="submit" class="ico search-32px" t:id="searchForAllegroReactivity" value="Search"
title="Calcul de la moyenne du nombre de jours entre la date de saisie dans Allegro et la date de fin de marée sur la période sélectionnée"/>
</form>
@@ -261,10 +261,10 @@
</tr>
</thead>
<tbody>
- <tr t:type="loop" t:source="allegroReactivity.entrySet()" t:value="allegroReactivityEntry">
- <td class="company">${allegroReactivityEntry.key}</td>
+ <tr t:type="loop" t:source="allegroReactivity" t:value="allegroReactivityEntry">
+ <td class="company">${allegroReactivityEntry.companyName}</td>
<td class="number${allegroReactivityStyle}">
- <t:output t:value="allegroReactivityEntry.value" t:format="numberFormat" />
+ <t:output t:value="allegroReactivityEntry.result" t:format="numberFormat" />
</td>
</tr>
</tbody>
1
0
[Suiviobsmer-commits] r350 - trunk/src/site/rst/user
by jcouteau@users.labs.libre-entreprise.org 12 Feb '10
by jcouteau@users.labs.libre-entreprise.org 12 Feb '10
12 Feb '10
Author: jcouteau
Date: 2010-02-12 17:26:04 +0000 (Fri, 12 Feb 2010)
New Revision: 350
Modified:
trunk/src/site/rst/user/createAContact.rst
Log:
Add instruction on create a contact doc
Modified: trunk/src/site/rst/user/createAContact.rst
===================================================================
--- trunk/src/site/rst/user/createAContact.rst 2010-02-12 15:33:58 UTC (rev 349)
+++ trunk/src/site/rst/user/createAContact.rst 2010-02-12 17:26:04 UTC (rev 350)
@@ -21,8 +21,10 @@
Pour cela, désactivez les filtres qui ont été mis pour vous proposer les navires
de la ligne du plan (icone 'fleche' rouge) afin de rechercher le navire que vous
-souhaitez. Vous pouvez lui assigner une ligne du plan en sélectionnant la ligne
+souhaitez. Vous pouvez lui assigner une ligne du plan en éditant le navire
+(icone 'modifier') puis en sélectionnant la ligne
concernée dans la liste déroulante et en cliquant sur l'icone 'plus'.
+Enregistrez les modifications pour les rendre disponibles.
.. image:: boats_edit.png
:width: 800px
1
0
[Suiviobsmer-commits] r349 - in trunk/src/site: . rst/user
by jcouteau@users.labs.libre-entreprise.org 12 Feb '10
by jcouteau@users.labs.libre-entreprise.org 12 Feb '10
12 Feb '10
Author: jcouteau
Date: 2010-02-12 15:33:58 +0000 (Fri, 12 Feb 2010)
New Revision: 349
Added:
trunk/src/site/rst/user/createAContact.rst
Modified:
trunk/src/site/site_fr.xml
Log:
Add doc about how to create a contact
Added: trunk/src/site/rst/user/createAContact.rst
===================================================================
--- trunk/src/site/rst/user/createAContact.rst (rev 0)
+++ trunk/src/site/rst/user/createAContact.rst 2010-02-12 15:33:58 UTC (rev 349)
@@ -0,0 +1,40 @@
+Comment créer un contact ?
+==========================
+
+1. Choisir la ligne du plan d'échantillonage concernée
+------------------------------------------------------
+
+La première étape consiste à choisir la ligne du plan d'échantillonage sur
+laquelle vous souhaitez embarquer et cliquer sur l'icone 'navire' à droite de la
+ligne concernée.
+
+.. image::sampling_plan.png
+ :width: 800px
+
+2. Choisir le navire sur lequel vous souhaitez embarquer
+--------------------------------------------------------
+
+La seconde étape consiste à sélectionner le navire sur lequel vous souhaitez
+embarqué. Des navires sont associés à chaque ligne du plan. Vous pouvez choisir
+parmis ces derniers. Dans le cas ou le navire sur lequel vous souhaitez embarquer
+n'est pas présent dans la liste, il est possible de l'ajouter à la main.
+
+Pour cela, désactivez les filtres qui ont été mis pour vous proposer les navires
+de la ligne du plan (icone 'fleche' rouge) afin de rechercher le navire que vous
+souhaitez. Vous pouvez lui assigner une ligne du plan en sélectionnant la ligne
+concernée dans la liste déroulante et en cliquant sur l'icone 'plus'.
+
+.. image:: boats_edit.png
+ :width: 800px
+
+3. Créer le contact
+-------------------
+
+Une fois le navire choisi, on crée le contact en cliquant sur l'icone 'enveloppe'
+Le contact est créé. Pour gérer la contact, veuillez vous référer à la
+documentation_ ad-hoc.
+
+.. image:: boats_contact.png
+ :width: 800px
+
+.. _documentation: contacts.html
\ No newline at end of file
Modified: trunk/src/site/site_fr.xml
===================================================================
--- trunk/src/site/site_fr.xml 2010-02-12 14:51:40 UTC (rev 348)
+++ trunk/src/site/site_fr.xml 2010-02-12 15:33:58 UTC (rev 349)
@@ -49,6 +49,7 @@
<item name="La base des navires" href="user/boats.html"/>
<item name="Les contacts" href="user/contacts.html"/>
<item name="Les synthèses" href="user/syntheses.html"/>
+ <item name="Créer un contact" href="user/createAContact.html"/>
</item>
<item name="Import/Export" href="import/samplingPlan.html">
1
0
[Suiviobsmer-commits] r348 - in trunk: . suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages suiviobsmer-ui/src/main/webapp
by fdesbois@users.labs.libre-entreprise.org 12 Feb '10
by fdesbois@users.labs.libre-entreprise.org 12 Feb '10
12 Feb '10
Author: fdesbois
Date: 2010-02-12 14:51:40 +0000 (Fri, 12 Feb 2010)
New Revision: 348
Modified:
trunk/changelog.txt
trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/AbstractMappedGridDataSource.java
trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/BoatActivityCalendar.java
trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java
trunk/suiviobsmer-ui/src/main/webapp/BoatActivityCalendar.tml
trunk/suiviobsmer-ui/src/main/webapp/Boats.tml
trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml
Log:
Ano #2103 : Problem with inPlace and GridPage when changing page and return to it : the page is not saved. The inPlace is not used anymore neither the passivate/activate for boatSelectedImmatriculation put in @Persist("flash") to preserve it in BoatInfos. The page loading is necessary to keep page change for navigation and reset boatInfos data to avoid gridDataSource problem (search a boat which is not in the dataSource).
Modified: trunk/changelog.txt
===================================================================
--- trunk/changelog.txt 2010-02-12 00:58:46 UTC (rev 347)
+++ trunk/changelog.txt 2010-02-12 14:51:40 UTC (rev 348)
@@ -32,6 +32,8 @@
Anomalies
+++++++++
+
+- [fdesbois] Ano #2103 : Erreur chargement infos d'un navire
- [fdesbois] Ano #2096 : Administration : Mail incomplet lors d'un changement
de mot de passe
- [fdesbois] Ano #2095 : Administration : Les zones de pêche ayant le même
Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/AbstractMappedGridDataSource.java
===================================================================
--- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/AbstractMappedGridDataSource.java 2010-02-12 00:58:46 UTC (rev 347)
+++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/data/AbstractMappedGridDataSource.java 2010-02-12 14:51:40 UTC (rev 348)
@@ -3,12 +3,9 @@
import fr.ifremer.suiviobsmer.SuiviObsmerException;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
-import org.apache.tapestry5.PropertyConduit;
import org.apache.tapestry5.grid.ColumnSort;
import org.apache.tapestry5.grid.GridDataSource;
import org.apache.tapestry5.grid.SortConstraint;
@@ -167,4 +164,8 @@
return listResults;
}
+ public boolean contains(K key) {
+ return mapResults.containsKey(key);
+ }
+
}
Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/BoatActivityCalendar.java
===================================================================
--- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/BoatActivityCalendar.java 2010-02-12 00:58:46 UTC (rev 347)
+++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/BoatActivityCalendar.java 2010-02-12 14:51:40 UTC (rev 348)
@@ -34,6 +34,7 @@
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.tapestry5.annotations.IncludeStylesheet;
+import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionState;
@@ -183,4 +184,14 @@
}
return profession.getActivityZone().get(zoneIndex);
}
+
+ /*************************** RETURN LINK **********************************/
+
+ @InjectPage
+ private Boats boatsPage;
+
+ Object onActionFromReturnToBoats() {
+ boatsPage.setBoatSelectedImmatriculation(getBoat().getImmatriculation());
+ return boatsPage;
+ }
}
Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java
===================================================================
--- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java 2010-02-12 00:58:46 UTC (rev 347)
+++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java 2010-02-12 14:51:40 UTC (rev 348)
@@ -121,9 +121,17 @@
private String sampleRowContextId;
/** Selected boat immatriculation for showing boatInfos */
- @Property
+ @Persist("flash")
private Integer boatSelectedImmatriculation;
+ public Integer getBoatSelectedImmatriculation() {
+ return boatSelectedImmatriculation;
+ }
+
+ public void setBoatSelectedImmatriculation(Integer boatSelectedImmatriculation) {
+ this.boatSelectedImmatriculation = boatSelectedImmatriculation;
+ }
+
@InjectComponent
private FeedBack filterFeedback;
@@ -152,16 +160,16 @@
}
void onActivate(EventContext ec) {
- if (ec.getCount() > 0) {
- sampleRowContextId = ec.get(String.class, 0);
- if (ec.getCount() > 1) {
- boatSelectedImmatriculation = ec.get(Integer.class, 1);
- }
- }
+ sampleRowContextId = ec.get(String.class, 0);
+// boatSelectedImmatriculation = ec.get(Integer.class, 1);
}
- Object[] onPassivate() {
- return new Object[] { sampleRowContextId, boatSelectedImmatriculation };
+// Object[] onPassivate() {
+// return new Object[] { sampleRowContextId, boatSelectedImmatriculation };
+// }
+
+ String onPassivate() {
+ return sampleRowContextId;
}
/**************************** Import Forms ********************************/
@@ -531,6 +539,10 @@
// Suppress persistant boat informations
companyBoatInfos = null;
+ if (log.isDebugEnabled()) {
+ log.debug("Show infos for boat : " + boatImma);
+ }
+
if (user.getAdmin() && getCompany() != null) {
companySelectedId = getCompany().getTopiaId();
}
@@ -641,6 +653,10 @@
* @throws SuiviObsmerException
*/
public Boat getBoatSelected() throws SuiviObsmerException {
+ if (log.isDebugEnabled()) {
+ log.debug("selected imma : " + boatSelectedImmatriculation);
+ log.debug("exist boat ? : " + getBoats().contains(boatSelectedImmatriculation));
+ }
return getBoats().get(boatSelectedImmatriculation);
}
Modified: trunk/suiviobsmer-ui/src/main/webapp/BoatActivityCalendar.tml
===================================================================
--- trunk/suiviobsmer-ui/src/main/webapp/BoatActivityCalendar.tml 2010-02-12 00:58:46 UTC (rev 347)
+++ trunk/suiviobsmer-ui/src/main/webapp/BoatActivityCalendar.tml 2010-02-12 14:51:40 UTC (rev 348)
@@ -5,7 +5,7 @@
<t:if t:test="activityCalendar">
<h1>Calendrier d'activité ${activityCalendar.year}</h1>
<p class="acenter">
- <a t:type="pagelink" class="return" t:context="[norow,activityCalendar.boat.immatriculation]" t:page="boats" title="Retour sur ${activityCalendar.boat.name}">
+ <a t:type="actionlink" t:id="returnToBoats" class="return" title="Retour sur ${activityCalendar.boat.name}">
<img src="${asset:context:}/img/boat.png" alt="Navire"/>
Revenir sur les informations du navire
<img src="${asset:context:}/img/boat.png" alt="Navire"/>
Modified: trunk/suiviobsmer-ui/src/main/webapp/Boats.tml
===================================================================
--- trunk/suiviobsmer-ui/src/main/webapp/Boats.tml 2010-02-12 00:58:46 UTC (rev 347)
+++ trunk/suiviobsmer-ui/src/main/webapp/Boats.tml 2010-02-12 14:51:40 UTC (rev 348)
@@ -119,7 +119,7 @@
title="Exporter les ${boats.availableRows} navires avec leurs informations privées" />
</a>
</h1>
- <div t:type="grid" t:source="boats" t:row="boat" t:inPlace="true"
+ <div t:type="grid" t:source="boats" t:row="boat"
t:include="name, immatriculation, districtCode, boatLength, buildYear" t:rowClass="prop:rowStyle" t:rowsPerPage="20">
<p:nameCell>
<t:if t:test="canCreateNewContactFromList()">
Modified: trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml
===================================================================
--- trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml 2010-02-12 00:58:46 UTC (rev 347)
+++ trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml 2010-02-12 14:51:40 UTC (rev 348)
@@ -117,7 +117,7 @@
<div class="acenter">
<h2>Sollicitations des navires</h2>
<br />
- <p>Ces résultats ne concernent que les lignes du plan d'échantillonnage<br /> ayant une durée moyenne de marées inférieure ou égale à 2</p>
+ <p>Ces résultats ne concernent que les lignes du plan d'échantillonnage<br /> ayant une durée moyenne de marées inférieure ou égale à 48h</p>
<br />
<t:if t:test="user.admin">
<form t:type="form" t:id="filterCompanyForBoarding">
1
0
[Suiviobsmer-commits] r347 - in trunk: . suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services suiviobsmer-business/src/main/xmi suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services 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 suiviobsmer-ui/src/main/webapp/css suiviobsmer-ui/src/main/webapp/img
by fdesbois@users.labs.libre-entreprise.org 12 Feb '10
by fdesbois@users.labs.libre-entreprise.org 12 Feb '10
12 Feb '10
Author: fdesbois
Date: 2010-02-12 00:58:46 +0000 (Fri, 12 Feb 2010)
New Revision: 347
Added:
trunk/suiviobsmer-ui/src/main/webapp/img/synthesis-ind-allegro-reactivity.png
Modified:
trunk/changelog.txt
trunk/pom.xml
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerContext.java
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java
trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo
trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java
trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java
trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties
trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml
trunk/suiviobsmer-ui/src/main/webapp/css/synthesis.css
Log:
Evo #1985 : Indicator for allegro reactivity. Seems to be a wrong calcul using HQL method AVG(day(tideBegin - dataInput)). Moreover a hack was created for H2 which does'nt support this syntax... Must be refactor to be calculated in Java and not in HQL. It's a shame, tests are OK with H2 using only AVG(tideBegin - dataInput)... Difficult to test with Postgresql because of specificity of clear method in ToPIA for dropping database.
Modified: trunk/changelog.txt
===================================================================
--- trunk/changelog.txt 2010-02-11 20:04:33 UTC (rev 346)
+++ trunk/changelog.txt 2010-02-12 00:58:46 UTC (rev 347)
@@ -9,6 +9,8 @@
Evolutions
++++++++++
+- [fdesbois] Evo #1985 : Synthèse : indicateur nombre de jour moyen entre date
+ de saisie dans Allegro et date de fin de marée des contacts
- [fdesbois] Evo #2022 : Plan d'échantillonnage : Export CSV
- [fdesbois] Evo #1986 : Synthèse : indicateur sur les états des contacts
- [fdesbois] Evo #1984 : Synthèse : indicateur de non respect du nombre
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-02-11 20:04:33 UTC (rev 346)
+++ trunk/pom.xml 2010-02-12 00:58:46 UTC (rev 347)
@@ -222,7 +222,7 @@
<!-- libraries version -->
<nuitonutils.version>1.1.3</nuitonutils.version>
- <topia.version>2.3.0-beta-8-SNAPSHOT</topia.version>
+ <topia.version>2.3.0-beta-8</topia.version>
<eugene.version>2.0.0-beta-4</eugene.version>
<tapestry.version>5.1.0.5</tapestry.version>
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerContext.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerContext.java 2010-02-11 20:04:33 UTC (rev 346)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/SuiviObsmerContext.java 2010-02-12 00:58:46 UTC (rev 347)
@@ -219,6 +219,8 @@
public static <E extends TopiaEntity> boolean prepareTopiaId(Class<E> entityClass, E entity) {
String topiaId = entity.getTopiaId();
+ // TODO-FD20100211 : add this behavior in topia in a
+ // new method createOrUpdate
if (StringUtils.isEmpty(entity.getTopiaId())) {
topiaId = TopiaId.create(entityClass);
entity.setTopiaId(topiaId);
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java 2010-02-11 20:04:33 UTC (rev 346)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java 2010-02-12 00:58:46 UTC (rev 347)
@@ -49,6 +49,7 @@
import java.util.SortedMap;
import java.util.TreeMap;
import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.framework.TopiaQuery.Op;
import org.nuiton.topia.persistence.TopiaEntity;
@@ -414,4 +415,79 @@
return results.values();
}
+ @Override
+ public Map<String, Double> getContactDataInputDateReactivity(Company company, PeriodDates period) throws SuiviObsmerException {
+ TopiaContext transaction = null;
+ // Carefull with results, the company may not be present in the map :
+ // only if there is no unfinished sampleRow or no contact done
+ Map<String, Double> results = new HashMap<String, Double>();
+ try {
+ transaction = rootContext.beginTransaction();
+
+ ContactDAO dao = SuiviObsmerModelDAOHelper.getContactDAO(transaction);
+
+ String contact = "C";
+ TopiaQuery query = dao.createQuery(contact);
+
+ String companyKey = contact + "." + Contact.OBSERVER + "." + WaoUser.COMPANY;
+ String companyName = companyKey + "." + Company.NAME;
+
+ if (company != null) {
+ query.add(companyKey, company);
+ }
+
+ String tideBegin = contact + "." + Contact.TIDE_BEGIN_DATE;
+ period.initDayOfMonthExtremities();
+ query.add(tideBegin + " BETWEEN :fromDate AND :thruDate").
+ addParam("fromDate", period.getFromDate()).
+ addParam("thruDate", period.getThruDate());
+
+ String dataInput = contact + "." + Contact.DATA_INPUT_DATE;
+ query.addNotNull(dataInput);
+
+ // FIXME-FD20100212 Hack for H2 which not managed day for date diff
+ TopiaContextImplementor context = (TopiaContextImplementor)transaction;
+ String dialect = context.getHibernateConfiguration().getProperty("hibernate.dialect");
+
+ String avg = "AVG(day(" + dataInput + " - " + tideBegin + "))";
+ if (dialect.contains("H2Dialect")) {
+ avg = "AVG(" + dataInput + " - " + tideBegin + ")";
+ }
+
+ query.setSelect(companyName, avg).addGroup(companyName);
+
+ if (log.isTraceEnabled()) {
+ log.trace("Exec query : " + query);
+ }
+
+ List<Object[]> res = query.execute();
+
+ for (Object[] row : res) {
+ String rowCompanyName = (String)row[0];
+ Double rowAverage = (Double)row[1];
+ if (log.isTraceEnabled()) {
+ log.trace("Company : " + rowCompanyName);
+ log.trace("Res : " + rowAverage.doubleValue());
+ }
+ if (rowAverage < 0) {
+ rowAverage = 0.;
+ }
+ results.put(rowCompanyName, rowAverage);
+ }
+
+
+ } catch (Exception eee) {
+ String msgEnd = "";
+ if (company != null) {
+ msgEnd = " pour la société " + company.getName();
+ }
+ SuiviObsmerContext.serviceException(transaction,
+ "Impossible de récupérer l'indicateur de réactivité sur " +
+ "les dates de saisies dans Allegro" + msgEnd, eee);
+ } finally {
+ SuiviObsmerContext.closeTransaction(transaction);
+ }
+ return results;
+ }
+
}
Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo
===================================================================
(Binary files differ)
Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java
===================================================================
--- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java 2010-02-11 20:04:33 UTC (rev 346)
+++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java 2010-02-12 00:58:46 UTC (rev 347)
@@ -416,4 +416,96 @@
assertEquals(0, data.get(ContactState.BOAT_UNAVAILABLE).intValue());
}
+ /**
+ * Test of getBoardingBoats method, of class ServiceSynthesisImpl.
+ */
+ @Test
+ public void testGetContactDataInputDateReactivity() throws Exception {
+ log.info("getContactDataInputDateReactivity");
+ /** PREPARE DATA **/
+ InputStream input = getClass().getResourceAsStream("/import/navires.csv");
+ ServiceBoat serviceBoat = new ServiceBoatImpl();
+ serviceBoat.importBoatCsv(input);
+ List<Boat> boats = serviceBoat.getBoatsByImmatriculations("174258");
+ Boat boat = boats.get(0);
+
+ List<Boat> boats2 = serviceBoat.getBoatsByImmatriculations("177474");
+ Boat boat2 = boats2.get(0);
+
+ TopiaContext transaction = SuiviObsmerContext.getTopiaRootContext().beginTransaction();
+
+ CompanyDAO companyDAO = SuiviObsmerModelDAOHelper.getCompanyDAO(transaction);
+ Company company = companyDAO.create(Company.NAME, "TARTANPION");
+ Company company2 = companyDAO.create(Company.NAME, "BIS");
+
+ WaoUserDAO userDAO = SuiviObsmerModelDAOHelper.getWaoUserDAO(transaction);
+ WaoUser user = userDAO.create(WaoUser.FIRST_NAME,"Jean", WaoUser.LAST_NAME, "Michmuche",
+ WaoUser.COMPANY, company);
+ company.addWaoUser(user);
+ WaoUser user2 = userDAO.create(WaoUser.FIRST_NAME,"Bill", WaoUser.LAST_NAME, "Murray",
+ WaoUser.COMPANY, company2);
+ company2.addWaoUser(user2);
+
+ transaction.commitTransaction();
+
+ input = getClass().getResourceAsStream("/import/zonesPeche.csv");
+ ServiceReferential serviceReferential = new ServiceReferentialImpl();
+ serviceReferential.importFishingZoneCsv(input);
+
+ input = getClass().getResourceAsStream("/import/echantillonnage.csv");
+ ServiceSampling serviceSampling = new ServiceSamplingImpl();
+ serviceSampling.importSamplingPlanCsv(input);
+
+ SampleRowDAO rowDAO = SuiviObsmerModelDAOHelper.getSampleRowDAO(transaction);
+ SampleRow row = rowDAO.findByCode("2010_0001");
+ SampleRow row2 = rowDAO.findByCode("2009_0006");
+
+ transaction.closeContext();
+
+
+ ServiceContact serviceContact = new ServiceContactImpl();
+ // First contact : OK
+ Contact contact1 = new ContactImpl();
+ contact1.setObserver(user);
+ Date begin = DateUtils.createDate(3, 3, 2009);
+ contact1.setTideBeginDate(begin);
+ Date inputDate = DateUtils.createDate(15, 4, 2009);
+ contact1.setDataInputDate(inputDate);
+ serviceContact.saveContact(contact1, false);
+
+ Contact contact2 = new ContactImpl();
+ contact2.setObserver(user);
+ begin = DateUtils.createDate(3, 3, 2009);
+ contact2.setTideBeginDate(begin);
+ inputDate = DateUtils.createDate(15, 3, 2009);
+ contact2.setDataInputDate(inputDate);
+ serviceContact.saveContact(contact2, false);
+
+ Contact contact3 = new ContactImpl();
+ contact3.setObserver(user2);
+ begin = DateUtils.createDate(3, 3, 2009);
+ contact3.setTideBeginDate(begin);
+ contact3.setDataInputDate(begin);
+ serviceContact.saveContact(contact3, false);
+
+ /** EXEC METHOD **/
+
+ PeriodDates period = new PeriodDates(begin, begin);
+
+ // result for company TARTANPION
+ Map<String, Double> results =
+ service.getContactDataInputDateReactivity(company, period);
+
+ assertEquals(1, results.size());
+
+ // 12 days for contact1 + 43 days for contact2 / 2 = 27.5 days
+ assertEquals(28, results.get(company.getName()), 0.01);
+
+ // result for company BIS using admin mode (no company filtered)
+ results = service.getContactDataInputDateReactivity(null, period);
+
+ // 0 days for contact3 / 1 = O days
+ assertEquals(0, results.get(company2.getName()), 0.01);
+ }
+
}
\ No newline at end of file
Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java
===================================================================
--- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java 2010-02-11 20:04:33 UTC (rev 346)
+++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java 2010-02-12 00:58:46 UTC (rev 347)
@@ -126,6 +126,12 @@
return new SimpleDateFormat("dd/MM/yyyy");
}
+ public NumberFormat getNumberFormat() {
+ NumberFormat result = NumberFormat.getNumberInstance();
+ result.setMaximumFractionDigits(1);
+ return result;
+ }
+
@Log
Object onAction(String actionType, String actionValue) {
// Delegator action (menu)
@@ -397,7 +403,44 @@
return (double)getNbContactStates() / (double)contactStateStats.getTotal();
}
-// void onSuccessFromFilterPeriodForContactStates() {
-// }
+ /********************* INDICATOR : NONCOMPLIANCEBOARDING ******************/
+ private Map<String, Double> allegroReactivity;
+
+ @Persist
+ private PeriodDates periodForAllegroReactivity;
+
+ @Property
+ private Map.Entry<String, Double> allegroReactivityEntry;
+
+ public Map<String, Double> getAllegroReactivity()
+ throws SuiviObsmerException {
+ if (allegroReactivity == null) {
+ Company company = !user.getAdmin() ? user.getCompany() : null;
+ allegroReactivity =
+ serviceSynthesis.getContactDataInputDateReactivity(company, getPeriodForAllegroReactivity());
+ }
+ return allegroReactivity;
+ }
+
+ public PeriodDates getPeriodForAllegroReactivity() {
+ if (periodForAllegroReactivity == null) {
+ periodForAllegroReactivity = PeriodDates.createMonthsPeriodFromToday(-3);
+ }
+ return periodForAllegroReactivity;
+ }
+
+ public Double getAllegroReactivityValue() throws SuiviObsmerException {
+ return getAllegroReactivity().get(user.getCompany().getName());
+ }
+
+ public String getAllegroReactivityStyle() throws SuiviObsmerException {
+ double value = user.getAdmin() ?
+ allegroReactivityEntry.getValue() : getAllegroReactivityValue();
+ if (value >= 15.) {
+ return " warn";
+ }
+ return "";
+ }
+
}
Modified: trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties
===================================================================
--- trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties 2010-02-11 20:04:33 UTC (rev 346)
+++ trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties 2010-02-12 00:58:46 UTC (rev 347)
@@ -12,4 +12,7 @@
companyForBoarding-label: Soci\u00E9t\u00E9
periodBeginForContactStates-label: du
-periodEndForContactStates-label: au
\ No newline at end of file
+periodEndForContactStates-label: au
+
+periodBeginForAllegroReactivity-label: du
+periodEndForAllegroReactivity-label: au
\ No newline at end of file
Modified: trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml
===================================================================
--- trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml 2010-02-11 20:04:33 UTC (rev 346)
+++ trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml 2010-02-12 00:58:46 UTC (rev 347)
@@ -30,6 +30,12 @@
title="Indicateur sur les états des contacts" />
</a>
</li>
+ <li>
+ <a t:type="actionlink" t:context="[actionSynthesisId,'IND_ALLEGRO_REACTIVITY']" t:zone="so-synthesis-main">
+ <img src="${asset:context:}/img/synthesis-ind-allegro-reactivity.png" alt="Indicateur"
+ title="Indicateur de réactivité sur la saisie des données dans Allegro" />
+ </a>
+ </li>
</ul>
</div>
<div t:type="zone" t:id="delegator" class="fleft" t:update="show" id="so-synthesis-main">
@@ -226,4 +232,51 @@
</table>
</div>
</t:block>
+ <!-- IND3 : ALLEGRO_REACTIVITY -->
+ <t:block t:id="ind3">
+ <div class="ind-table acenter" id="so-allegroreactivity">
+ <h2>Réactivité de la saisie dans Allegro par rapport à la date de fin de la marée</h2>
+ <br />
+ <p>
+ Ce résultat est une moyenne du nombre de jours entre la date de saisie dans Allegro et la date de fin de la marée des contacts.
+ </p>
+ <br />
+ <p>
+ <form t:type="form" t:id="filterPeriodForAllegroReactivity">
+ <label>Période : </label>
+ <t:label t:for="periodBeginForAllegroReactivity" />
+ <input t:type="datefield" class="width70" t:id="periodBeginForAllegroReactivity" t:value="periodForAllegroReactivity.fromDate" t:format="MM/yyyy"/>
+ <t:label t:for="periodEndForAllegroReactivity" />
+ <input t:type="datefield" class="width70" t:id="periodEndForAllegroReactivity" t:value="periodForAllegroReactivity.thruDate" t:format="MM/yyyy" />
+ <input t:type="submit" class="ico search-32px" t:id="searchForAllegroReactivity" value="Search"
+ title="Calcul de la moyenne du nombre de jours entre la date de saisie dans Allegro et la date de fin de marée sur la période sélectionnée"/>
+ </form>
+ </p>
+ <t:if t:test="user.admin">
+ <table class="t-data-grid">
+ <thead>
+ <tr>
+ <th class="company">Société</th>
+ <th>Indicateur</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr t:type="loop" t:source="allegroReactivity.entrySet()" t:value="allegroReactivityEntry">
+ <td class="company">${allegroReactivityEntry.key}</td>
+ <td class="number${allegroReactivityStyle}">
+ <t:output t:value="allegroReactivityEntry.value" t:format="numberFormat" />
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ <p:else>
+ <div class="indicator">
+ <p class="number${allegroReactivityStyle}">
+ <t:output t:value="allegroReactivityValue" t:format="numberFormat" />
+ </p>
+ </div>
+ </p:else>
+ </t:if>
+ </div>
+ </t:block>
</t:layout>
Modified: trunk/suiviobsmer-ui/src/main/webapp/css/synthesis.css
===================================================================
--- trunk/suiviobsmer-ui/src/main/webapp/css/synthesis.css 2010-02-11 20:04:33 UTC (rev 346)
+++ trunk/suiviobsmer-ui/src/main/webapp/css/synthesis.css 2010-02-12 00:58:46 UTC (rev 347)
@@ -54,7 +54,7 @@
div#so-synthesis-menu {
border-right: 2px solid #133852;
padding-left: 15px;
- height: 406px;
+ height: 478px;
width: 10%;
}
@@ -63,7 +63,7 @@
}
div#so-synthesis-menu ul li {
- padding-bottom: 20px;
+ padding-bottom: 10px;
}
div.indicator {
@@ -147,3 +147,6 @@
text-align: center;
}
+div#so-allegroreactivity td.warn {
+ color: red;
+}
Added: trunk/suiviobsmer-ui/src/main/webapp/img/synthesis-ind-allegro-reactivity.png
===================================================================
(Binary files differ)
Property changes on: trunk/suiviobsmer-ui/src/main/webapp/img/synthesis-ind-allegro-reactivity.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
1
0
[Suiviobsmer-commits] r346 - in trunk: . suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services suiviobsmer-business/src/main/xmi suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer 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
by fdesbois@users.labs.libre-entreprise.org 11 Feb '10
by fdesbois@users.labs.libre-entreprise.org 11 Feb '10
11 Feb '10
Author: fdesbois
Date: 2010-02-11 20:04:33 +0000 (Thu, 11 Feb 2010)
New Revision: 346
Added:
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/ExportHelper.java
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/ImportHelper.java
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/SamplingExport.java
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/WaoCsvHeader.java
Removed:
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/ImportHelper.java
Modified:
trunk/changelog.txt
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ActivityCalendarImport.java
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceBoatImpl.java
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceContactImpl.java
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceReferentialImpl.java
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSamplingImpl.java
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java
trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo
trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/ImportHelperTest.java
trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.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/Boats.properties
trunk/suiviobsmer-ui/src/main/webapp/SamplingPlan.tml
Log:
- Evo #2022 : Export SamplingPlan
- Improve import/export : new ExportHelper abstract class + new io package + headers enumerations put in WaoCsvHeader class. Of course ImportHelper has less methods now.
- Note : correction of query for boats export
Modified: trunk/changelog.txt
===================================================================
--- trunk/changelog.txt 2010-02-10 22:04:27 UTC (rev 345)
+++ trunk/changelog.txt 2010-02-11 20:04:33 UTC (rev 346)
@@ -9,6 +9,8 @@
Evolutions
++++++++++
+- [fdesbois] Evo #2022 : Plan d'échantillonnage : Export CSV
+- [fdesbois] Evo #1986 : Synthèse : indicateur sur les états des contacts
- [fdesbois] Evo #1984 : Synthèse : indicateur de non respect du nombre
d'observateurs embarqués
- [fdesbois] Evo #2092 : Contacts : Ajouter filtres sur les validations du
Deleted: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/ImportHelper.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/ImportHelper.java 2010-02-10 22:04:27 UTC (rev 345)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/ImportHelper.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -1,564 +0,0 @@
-/*
- * *##%
- * SuiviObsmer :: Business
- * Copyright (C) 2009 - 2010 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;
-
-import com.csvreader.CsvReader;
-import java.io.IOException;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.Locale;
-import org.apache.commons.lang.BooleanUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.time.DurationFormatUtils;
-import org.nuiton.util.PeriodDates;
-import org.slf4j.Logger;
-
-/**
- * ImportHelper
- *
- * Created: 4 janv. 2010
- *
- * @author fdesbois
- * @version $Revision$
- *
- * Mise a jour: $Date$
- * par : $Author$
- */
-public class ImportHelper {
-
- public interface ImportHeader {
-
- int forContactCsv();
-
- String name();
-
- /**
- * Pattern for Date parsing. This pattern can be null, if no format date is necessary.
- *
- * @return a String corresponding to the date pattern
- */
- String datePattern();
- }
-
- /**
- * CSV headers for Boat
- */
- public enum BOAT implements ImportHeader {
- /** Boat immatriculation **/
- NAVS_COD(1, "Immatriculation", 20),
- /** Boat name **/
- CARN_NOM(2, "Nom", 21),
- /** Boat length **/
- CARN_LONGUEUR_HT(3, "Longueur (m)"),
- /** Boat build year **/
- CARN_ANNEE(4, "Année de construction"),
- /** Boat district code **/
- QUARTIER_IMMA(5, "Code quartier", 22),
- /** ShipOwner code **/
- PER_COD,
- /** ShipOwner last name **/
- PER_NOM,
- /** ShipOwner first name **/
- PER_PRENOM,
- /** Boat active **/
- NAVS_ACTIVE(0, "Actif/Inactif"),
- /** BoatInfos contactFirstName **/
- CONT_PRENOM(6, "Prénom du contact"),
- /** BoatInfos contactLastName **/
- CONT_NOM(7, "Nom du contact"),
- /** BoatInfos contactEmail **/
- CONT_EMAIL(8, "Email du contact"),
- /** BoatInfos contactPhoneNumber **/
- CONT_TEL(9, "Tél du contact"),
- /** BoatInfos dup **/
- NAVS_DUP(10, "Capacité d'accueil du navire en personnels spécialisés"),
- /** BoatInfos comment **/
- NAVS_COMMENT(11, "Commentaire");
-
- private int contactHeader;
-
- private int boatHeader;
-
- private String title;
-
- BOAT(int indexBoat, String title, int indexContact) {
- contactHeader = indexContact;
- boatHeader = indexBoat;
- this.title = title;
- }
-
- BOAT(int indexBoat, String title) {
- boatHeader = indexBoat;
- this.title = title;
- }
-
- BOAT() {
- contactHeader = -1;
- boatHeader = -1;
- title = name();
- }
-
- @Override
- public int forContactCsv() {
- return contactHeader;
- }
-
- public int forBoatCsv() {
- return boatHeader;
- }
-
- @Override
- public String datePattern() {
- return null;
- }
-
- @Override
- public String toString() {
- return title;
- }
- }
-
- /**
- * CSV headers for SamplingPlan
- */
- public enum SAMPLING implements ImportHeader {
- /** SampleRow code **/
- PLAN_CODE(6),
- /** Company name **/
- SOCIETE_NOM(5),
- /** Program code **/
- PROGRAMME_CODE(7),
- /** Program period begin **/
- PROGRAMME_DEBUT(8),
- /** Program period end **/
- PROGRAMME_FIN(9),
- /** FishingZone other infos **/
- PECHE_AUTRE(13),
- /** Profession code DCF5 **/
- METIER_CODE_DCF5(14),
- /** Profession mesh size **/
- METIER_MAILLAGE(15),
- /** Profession size **/
- METIER_TAILLE(16),
- /** Profession other infos **/
- METIER_AUTRE(17),
- /** Profession libelle **/
- METIER_LIBELLE(18),
- /** Profession species **/
- METIER_ESPECES(19),
- /** SampleRow nb observants **/
- PLAN_NB_OBSERV,
- /** SampleRow average tide time **/
- PLAN_DUREE_MOY,
- /** SampleRow comment **/
- PLAN_COMMENT;
-
- private int contactHeader;
-
- SAMPLING(int index) {
- this.contactHeader = index;
- }
-
- SAMPLING() {
- this.contactHeader = -1;
- }
-
- @Override
- public int forContactCsv() {
- return contactHeader;
- }
-
- @Override
- public String datePattern() {
- return defaultDatePattern();
- }
-
- public static String defaultDatePattern() {
- return "MM/yyyy";
- }
- }
-
- /**
- * CSV headers for FishingZone
- */
- public enum FISHING_ZONE implements ImportHeader {
- /** FishingZone facade **/
- PECHE_FACADE(10),
- /** FishingZone sector **/
- PECHE_ZONE(11),
- /** FishingZone district code **/
- PECHE_DIVISION(12);
-
- private int contactHeader;
-
- FISHING_ZONE(int index) {
- this.contactHeader = index;
- }
-
- @Override
- public int forContactCsv() {
- return contactHeader;
- }
-
- @Override
- public String datePattern() {
- return null;
- }
- }
-
- /**
- * CSV headers for Contact
- */
- public enum CONTACT implements ImportHeader {
- /** Contact code (create date time for existing contact) **/
- CONT_CODE(0),
- /** Contact create date **/
- CONT_CREATION(1),
- /** User id **/
- OBSERV_ID(2),
- /** User prenom **/
- OBSERV_PRENOM(3),
- /** User nom **/
- OBSERV_NOM(4),
- /** Company id **/
- //SOCIETE_ID,
- /** Contact state **/
- CONT_ETAT(23),
- /** Contact tide begin **/
- CONT_DEBUT_MAREE(24),
- /** Contact tide end **/
- CONT_FIN_MAREE(25),
- /** Contact nb observants **/
- CONT_NB_OBSERV(26),
- /** Contact mammals capture **/
- CONT_MAM_CAPT(27),
- /** Contact mammals observation **/
- CONT_MAM_OBS(28),
- /** Contact comment **/
- CONT_COMMENT(29),
- /** Contact data input **/
- CONT_ALLEGRO(30),
- /** Contact company validation **/
- CONT_SOCIETE_VALID(31),
- /** Contact program validation **/
- CONT_PROGRAM_VALID(32);
-
- private int contactHeader;
-
- CONTACT(int index) {
- this.contactHeader = index;
- }
-
- @Override
- public int forContactCsv() {
- return contactHeader;
- }
-
- @Override
- public String datePattern() {
- return "dd/MM/yyyy";
- }
- }
-
- public enum ACTIVITY_CALENDAR implements ImportHeader {
- /** ActivityCalendar year **/
- SYNA_AN,
- /** ActivityCalendar fiability **/
- INDQ_COD,
- /** ActivityMonth month **/
- SYNA_MOI,
- /** ActivityMonth harbourCode **/
- SYNA_POR_COD,
- /** ActivityMonth nbSeaDays **/
- SYNA_NOMJDM,
- /** ActivityMonth nbFishingDays **/
- SYNA_NOMJDP,
- /** ActivityMonth nbBoardingPersons **/
- SYNA_NOMHE,
- /** ActivityMonth harbourId **/
- SYNA_TPOR_COD,
- /** ActivityMonth harbourLibelle **/
- SYNA_POR_LIB,
- /** ActivityProfession professionOrder **/
- META_ORDRE,
- /** ActivityProfession code **/
- MET_COD,
- /** ActivityProfession id **/
- MET_ID,
- /** ActivityProfession libelle **/
- MET_LIB,
- /** ActivityZone code **/
- SECT_COD,
- /** ActivityZone gradiantCode **/
- GRA_COD,
- /** ActivityZone gradiantLibelle **/
- GRA_LIB,
- /** ActivityZone zoneId **/
- TSECT_COD,
- /** ActivityZone zoneLibelle **/
- SECT_LIB;
-
- @Override
- public int forContactCsv() {
- return -1;
- }
-
- @Override
- public String datePattern() {
- return "";
- }
- }
-
- public static final int CONTACT_NB_HEADERS = 33;
-
- public static final int BOAT_NB_HEADERS = 12;
-
- public static final String BOAT_INACTIVE_CODE = "I";
-
- public static String getHeaderForContactCsv(int index) {
- for (BOAT boatEnum : BOAT.values()) {
- if (boatEnum.forContactCsv() == index) {
- return boatEnum.name();
- }
- }
- for (SAMPLING samplingEnum : SAMPLING.values()) {
- if (samplingEnum.forContactCsv() == index) {
- return samplingEnum.name();
- }
- }
- for (FISHING_ZONE zoneEnum : FISHING_ZONE.values()) {
- if (zoneEnum.forContactCsv() == index) {
- return zoneEnum.name();
- }
- }
- for (CONTACT contactEnum : CONTACT.values()) {
- if (contactEnum.forContactCsv() == index) {
- return contactEnum.name();
- }
- }
- return "";
- }
-
- public static String getHeaderForBoatCsv(int index) {
- for (BOAT boatEnum : BOAT.values()) {
- if (boatEnum.forBoatCsv() == index) {
- return boatEnum.toString();
- }
- }
- return "";
- }
-
- public static String formatContactValidation(Boolean validation) {
- String valid = "";
- if (validation == null) {
- valid = "N";
- } else if (BooleanUtils.isTrue(validation)) {
- valid = "A";
- } else {
- valid = "R";
- }
- return valid;
- }
-
- public static Boolean parseContactValidation(CsvReader reader, ImportHeader header) throws IOException {
- String validation = read(reader, header);
- Boolean result = null;
- if ("A".equals(validation)) {
- result = Boolean.TRUE;
- } else if ("R".equals(validation)) {
- result = Boolean.FALSE;
- }
- return result;
- }
-
- public static String formatContactMammals(boolean mammals) {
- return mammals ? "X" : "";
- }
-
- public static boolean parseContactMammals(CsvReader reader, ImportHeader header) throws IOException {
- String mammals = read(reader, header);
- return "X".equals(mammals);
- }
-
- protected static String CONTACT_TIME_PATTERN = "HHmmssS";
-
- protected static String CONTACT_DATE_PATTERN = "dd/MM/yyyy";
-
- public static String formatContactCode(Date createDate) {
- DateFormat timeFormat = new SimpleDateFormat(CONTACT_TIME_PATTERN, Locale.FRENCH);
- String result = timeFormat.format(createDate);
- return result;
- }
-
- public static Date parseContactCreateDate(String code, String createDate) throws ParseException {
- Calendar time = new GregorianCalendar(Locale.FRENCH);
- if (StringUtils.isNotEmpty(code)) {
- DateFormat timeFormat = new SimpleDateFormat(CONTACT_TIME_PATTERN, Locale.FRENCH);
- time = new GregorianCalendar(Locale.FRENCH);
- time.setTime(timeFormat.parse(code));
- } else {
- // Use current date with no time as a reference if no code is set
- time.setTime(SuiviObsmerContext.getCurrentDate());
- time.set(Calendar.HOUR_OF_DAY, 0);
- time.set(Calendar.MINUTE, 0);
- time.set(Calendar.SECOND, 0);
- time.set(Calendar.MILLISECOND, 0);
- }
-
- Calendar result = new GregorianCalendar(Locale.FRENCH);
- if (StringUtils.isNotEmpty(createDate)) {
- DateFormat dateFormat = getContactDateFormat();
- result.setTime(dateFormat.parse(createDate));
- result.set(Calendar.HOUR_OF_DAY, time.get(Calendar.HOUR_OF_DAY));
- result.set(Calendar.MINUTE, time.get(Calendar.MINUTE));
- result.set(Calendar.SECOND, time.get(Calendar.SECOND));
- result.set(Calendar.MILLISECOND, time.get(Calendar.MILLISECOND));
- } else {
- result.setTime(SuiviObsmerContext.getCurrentDate());
- }
- return result.getTime();
- }
-
- public static String readSampleRowCode(CsvReader reader) throws IOException {
- String code = read(reader, SAMPLING.PLAN_CODE);
- return SuiviObsmerContext.prepareSampleRowCode(code);
- }
-
- public static DateFormat getContactDateFormat() {
- return new SimpleDateFormat(CONTACT_DATE_PATTERN, Locale.FRENCH);
- }
-
- public static long logTimeAndMemory(Logger log, long tic1, String msg) {
- if (log.isInfoEnabled()) {
- log.info("RUNNING... Import : " + msg);
- Runtime runtime = Runtime.getRuntime();
- long mem = (runtime.totalMemory() - runtime.freeMemory()) / 1048576;
- //long memMega = mem / 1024 / 1024;
- log.info("Memory : " + mem + " Mo");
- long tic2 = System.currentTimeMillis();
- log.info("Time : " + DurationFormatUtils.formatDurationHMS(tic2 - tic1));
- }
- return System.currentTimeMillis();
- }
-
- /**
- * Read a string value in CsvReader from {@code header} column.
- * In ActivityCalendarImport the result value can be null if the read value is "NA".
- *
- * @param reader CsvReader used to read the value
- * @param header Column header in the CsvReader
- * @return the String value read or null if set to "NA" in ActivityCalendar import.
- * @throws IOException
- */
- public static String read(CsvReader reader, ImportHeader header) throws IOException {
- String result = reader.get(header.name()).trim();
- if (header instanceof ACTIVITY_CALENDAR && "NA".equals(result)) {
- return null;
- }
- return result;
- }
-
- /**
- * Read an int value in CsvReader from {@code header} column.
- *
- * @param reader CsvReader used to read the value
- * @param header Column header in the CsvReader
- * @return the int value or -1 if the value read is null
- * @throws IOException
- * @see ImportHelper#read(CsvReader, ImportHeader)
- */
- public static int readInt(CsvReader reader, ImportHeader header) throws IOException {
- String str = read(reader, header);
- if (StringUtils.isEmpty(str)) {
- return -1;
- }
- return Integer.parseInt(str);
- }
-
- /**
- * Read an Integer value in CsvReader from {@code header} column.
- *
- * @param reader CsvReader used to read the value
- * @param header Column header in the CsvReader
- * @return the Integer value or null if the value read is null
- * @throws IOException
- * @see ImportHelper#readInt(CsvReader, ImportHeader)
- */
- public static Integer readInteger(CsvReader reader, ImportHeader header) throws IOException {
- int result = readInt(reader, header);
- return result != -1 ? result : null;
- }
-
- /**
- * Read two values in CsvReader corresponding to a period from {@code headerBegin} and {@code headEnd} column.
- *
- * @param reader CsvReader used to read the value
- * @param headerBegin Column header in the CsvReader for periodBegin
- * @param headerEnd Column header in the CsvReader for periodEnd
- * @return the PeriodDates created from periodBegin and periodEnd read from Csv file
- * @throws IOException
- * @throws ParseException
- * @throws IllegalArgumentException
- * @see ImportHelper#readDate(CsvReader, ImportHeader)
- */
- public static PeriodDates readPeriod(CsvReader reader, ImportHeader headerBegin, ImportHeader headerEnd)
- throws IOException, ParseException {
- Date end = readDate(reader, headerEnd);
- Date begin = readDate(reader, headerBegin);
- if (begin != null && end != null) {
- PeriodDates period = new PeriodDates(begin, end);
- period.initDayOfMonthExtremities();
- return period;
- }
- return null;
- }
-
- /**
- * Read a Date value in CsvReader from {@code header} column.
- *
- * @param reader CsvReader used to read the value
- * @param header Column header in the CsvReader
- * @return the Date value or null if the value read is null
- * @throws IOException
- * @throws ParseException
- * @see ImportHelper#read(CsvReader, ImportHeader)
- */
- public static Date readDate(CsvReader reader, ImportHeader header)
- throws IOException, ParseException {
- DateFormat dateFormat = new SimpleDateFormat(header.datePattern());
- String str = read(reader, header);
- if (StringUtils.isEmpty(str)) {
- return null;
- }
- // Parsing problem with Pattern dd/MM/yyyy which is valid for dd/MM/yy date
- // The length is tested to avoid accepting wrong dates
- if (str.length() != header.datePattern().length()) {
- throw new ParseException("Date error : " + str, str.length());
- }
- return dateFormat.parse(str);
- }
-
-}
Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/ExportHelper.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/ExportHelper.java (rev 0)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/ExportHelper.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -0,0 +1,125 @@
+
+package fr.ifremer.suiviobsmer.io;
+
+import com.csvreader.CsvWriter;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.IOHeader;
+import java.io.IOException;
+
+/**
+ * Helper for CSV Export. This class must be inherited to be used in services
+ * implementations. Two methods needed :
+ * <pre>
+ * - {@link #record(IOHeader, String)} : record a value in the file
+ * - {@link #getHeaderValue(int)} : get the string header value corresponding
+ * to the index value.
+ * </pre>
+ * You have to used {@link WaoCsvHeader} to manage this two methods,
+ * to retrieve good indexes and good values for printing data headers.
+ * Steps :
+ * <pre>
+ * - Instanciate {@link #ExportHelper(CsvWriter, int) }
+ * (with abstract method implementations if needed).
+ * - Call {@link #writeHeaders() } method to prepare columns and write
+ * first row in the resulting file.
+ * - In the loop data, first use {@link #newRecord() } to prepare the current
+ * record.
+ * - Then used for each column, the {@link #record(IOHeader, String) } method.
+ * - Finally call the {@link #writeRecord() } to write the record in file.
+ * </pre>
+ *
+ * Created: 11 févr. 2010
+ *
+ * @param <H>
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public abstract class ExportHelper<H extends IOHeader> {
+
+ /** Writer used to record data **/
+ protected CsvWriter writer;
+
+ /** Current record to write **/
+ protected String[] record;
+
+ /** Number of columns/headers in resulting export **/
+ protected int nbHeaders;
+
+ /**
+ * Constructor of ExportHelper. Need an existing CsvWriter ready to
+ * write data in it.
+ *
+ * @param writer the CsvWriter used for record data
+ * @param nbHeaders number of columns in the resulting file
+ * @throws IOException
+ */
+ public ExportHelper(CsvWriter writer, int nbHeaders) throws IOException {
+ this.writer = writer;
+ this.nbHeaders = nbHeaders;
+ }
+
+ /**
+ * Record a value for a header corresponding to the H generic type from
+ * {@link WaoCsvReader } class.
+ *
+ * @param header IOHeader used to record the value (column in the file)
+ * @param value the value to record
+ */
+ public abstract void record(H header, String value);
+
+ /**
+ * Return the header String value based on index. All matching integers for
+ * headers are defined in {@link WaoCsvReader } class.
+ *
+ * @param index of the header
+ * @return the String value of the header
+ * @throws IOException
+ */
+ protected abstract String getHeaderValue(int index) throws IOException;
+
+ /**
+ * Write the first header line of the file. This method uses
+ * {@link #getHeaderValue(int) } to retrieve the corresponding name of the
+ * header depends on its index.
+ *
+ * @throws IOException
+ */
+ public void writeHeaders() throws IOException {
+ for (int i = 0; i < nbHeaders; i++) {
+ String header = getHeaderValue(i);
+ writer.write(header);
+ }
+ writer.endRecord();
+ }
+
+ /**
+ * Record a value in the current record.
+ *
+ * @param index of the column
+ * @param value of the data to record
+ */
+ public void record(int index, String value) {
+ if (value != null) {
+ record[index] = value;
+ }
+ }
+
+ /**
+ * Prepare a new record (new file row).
+ */
+ public void newRecord() {
+ record = new String[nbHeaders];
+ }
+
+ /**
+ * Write the current record in the resulting file.
+ *
+ * @throws IOException
+ */
+ public void writeRecord() throws IOException {
+ writer.writeRecord(record);
+ writer.flush();
+ }
+}
Property changes on: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/ExportHelper.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Copied: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/ImportHelper.java (from rev 338, trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/ImportHelper.java)
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/ImportHelper.java (rev 0)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/ImportHelper.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -0,0 +1,225 @@
+/*
+ * *##%
+ * SuiviObsmer :: Business
+ * Copyright (C) 2009 - 2010 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.io;
+
+import fr.ifremer.suiviobsmer.*;
+import com.csvreader.CsvReader;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.ACTIVITY_CALENDAR;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.CONTACT;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.DatedHeader;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.IOHeader;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.SAMPLING;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.SamplingHeader;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import org.apache.commons.lang.BooleanUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.nuiton.util.PeriodDates;
+import org.slf4j.Logger;
+
+/**
+ * ImportHelper
+ *
+ * Created: 4 janv. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class ImportHelper {
+
+ protected CsvReader reader;
+
+ public ImportHelper(CsvReader reader) {
+ this.reader = reader;
+ }
+
+ public static Boolean parseContactValidation(CsvReader reader, IOHeader header) throws IOException {
+ String validation = read(reader, header);
+ Boolean result = null;
+ if ("A".equals(validation)) {
+ result = Boolean.TRUE;
+ } else if ("R".equals(validation)) {
+ result = Boolean.FALSE;
+ }
+ return result;
+ }
+
+ public static boolean parseContactMammals(CsvReader reader, IOHeader header) throws IOException {
+ String mammals = read(reader, header);
+ return "X".equals(mammals);
+ }
+
+ public static Date parseContactCreateDate(String code, String createDate) throws ParseException {
+ Calendar time = new GregorianCalendar(Locale.FRENCH);
+ if (StringUtils.isNotEmpty(code)) {
+ DateFormat timeFormat = CONTACT.getTimeFormat();
+ time = new GregorianCalendar(Locale.FRENCH);
+ time.setTime(timeFormat.parse(code));
+ } else {
+ // Use current date with no time as a reference if no code is set
+ time.setTime(SuiviObsmerContext.getCurrentDate());
+ time.set(Calendar.HOUR_OF_DAY, 0);
+ time.set(Calendar.MINUTE, 0);
+ time.set(Calendar.SECOND, 0);
+ time.set(Calendar.MILLISECOND, 0);
+ }
+
+ Calendar result = new GregorianCalendar(Locale.FRENCH);
+ if (StringUtils.isNotEmpty(createDate)) {
+ DateFormat dateFormat = CONTACT.getDateFormat();
+ result.setTime(dateFormat.parse(createDate));
+ result.set(Calendar.HOUR_OF_DAY, time.get(Calendar.HOUR_OF_DAY));
+ result.set(Calendar.MINUTE, time.get(Calendar.MINUTE));
+ result.set(Calendar.SECOND, time.get(Calendar.SECOND));
+ result.set(Calendar.MILLISECOND, time.get(Calendar.MILLISECOND));
+ } else {
+ result.setTime(SuiviObsmerContext.getCurrentDate());
+ }
+ return result.getTime();
+ }
+
+ public static String readSampleRowCode(CsvReader reader) throws IOException {
+ String code = read(reader, SAMPLING.PLAN_CODE);
+ return SuiviObsmerContext.prepareSampleRowCode(code);
+ }
+
+ /**
+ * Read a string value in CsvReader from {@code header} column.
+ * In ActivityCalendarImport the result value can be null if the read value is "NA".
+ *
+ * @param reader CsvReader used to read the value
+ * @param header Column header in the CsvReader
+ * @return the String value read or null if set to "NA" in ActivityCalendar import.
+ * @throws IOException
+ */
+ public static String read(CsvReader reader, IOHeader header) throws IOException {
+ String result = reader.get(header.name()).trim();
+ if (header instanceof ACTIVITY_CALENDAR && "NA".equals(result)) {
+ return null;
+ }
+ return result;
+ }
+
+ /**
+ * Read an int value in CsvReader from {@code header} column.
+ *
+ * @param reader CsvReader used to read the value
+ * @param header Column header in the CsvReader
+ * @return the int value or -1 if the value read is null
+ * @throws IOException
+ * @see ImportHelper#read(CsvReader, IOHeader)
+ */
+ public static int readInt(CsvReader reader, IOHeader header) throws IOException {
+ String str = read(reader, header);
+ if (StringUtils.isEmpty(str)) {
+ return -1;
+ }
+ return Integer.parseInt(str);
+ }
+
+ /**
+ * Read an Integer value in CsvReader from {@code header} column.
+ *
+ * @param reader CsvReader used to read the value
+ * @param header Column header in the CsvReader
+ * @return the Integer value or null if the value read is null
+ * @throws IOException
+ * @see ImportHelper#readInt(CsvReader, IOHeader)
+ */
+ public static Integer readInteger(CsvReader reader, IOHeader header) throws IOException {
+ int result = readInt(reader, header);
+ return result != -1 ? result : null;
+ }
+
+ /**
+ * Read two values in CsvReader corresponding to a period from {@code headerBegin} and {@code headEnd} column.
+ *
+ * @param reader CsvReader used to read the value
+ * @param headerBegin Column header in the CsvReader for periodBegin
+ * @param headerEnd Column header in the CsvReader for periodEnd
+ * @return the PeriodDates created from periodBegin and periodEnd read from Csv file
+ * @throws IOException
+ * @throws ParseException
+ * @throws IllegalArgumentException
+ * @see ImportHelper#readDate(CsvReader, IOHeader)
+ */
+ public static PeriodDates readPeriod(CsvReader reader, DatedHeader headerBegin, DatedHeader headerEnd)
+ throws IOException, ParseException {
+ Date end = readDate(reader, headerEnd);
+ Date begin = readDate(reader, headerBegin);
+ if (begin != null && end != null) {
+ PeriodDates period = new PeriodDates(begin, end);
+ period.initDayOfMonthExtremities();
+ return period;
+ }
+ return null;
+ }
+
+ /**
+ * Read a Date value in CsvReader from {@code header} column.
+ *
+ * @param reader CsvReader used to read the value
+ * @param header Column header in the CsvReader
+ * @return the Date value or null if the value read is null
+ * @throws IOException
+ * @throws ParseException
+ * @see ImportHelper#read(CsvReader, IOHeader)
+ */
+ public static Date readDate(CsvReader reader, DatedHeader header)
+ throws IOException, ParseException {
+ DateFormat dateFormat = new SimpleDateFormat(header.datePattern());
+ String str = read(reader, header);
+ if (StringUtils.isEmpty(str)) {
+ return null;
+ }
+ // Parsing problem with Pattern dd/MM/yyyy which is valid for dd/MM/yy date
+ // The length is tested to avoid accepting wrong dates
+ if (str.length() != header.datePattern().length()) {
+ throw new ParseException("Date error : " + str, str.length());
+ }
+ return dateFormat.parse(str);
+ }
+
+ public static long logTimeAndMemory(Logger log, long tic1, String msg) {
+ if (log.isInfoEnabled()) {
+ log.info("RUNNING... Import : " + msg);
+ Runtime runtime = Runtime.getRuntime();
+ long mem = (runtime.totalMemory() - runtime.freeMemory()) / 1048576;
+ //long memMega = mem / 1024 / 1024;
+ log.info("Memory : " + mem + " Mo");
+ long tic2 = System.currentTimeMillis();
+ log.info("Time : " + DurationFormatUtils.formatDurationHMS(tic2 - tic1));
+ }
+ return System.currentTimeMillis();
+ }
+
+}
Property changes on: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/ImportHelper.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: svn:mergeinfo
+
Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/SamplingExport.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/SamplingExport.java (rev 0)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/SamplingExport.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -0,0 +1,103 @@
+
+package fr.ifremer.suiviobsmer.io;
+
+import com.csvreader.CsvWriter;
+import fr.ifremer.suiviobsmer.entity.SampleMonth;
+import fr.ifremer.suiviobsmer.entity.SampleRow;
+import fr.ifremer.suiviobsmer.entity.WaoUser;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.SAMPLING;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.SamplingHeader;
+import java.io.IOException;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * SamplingExport
+ *
+ * Created: 11 févr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class SamplingExport extends ExportHelper<SamplingHeader> {
+
+ private static final Logger log = LoggerFactory.getLogger(SamplingExport.class);
+
+ protected WaoUser user;
+
+ protected List<String> monthHeaders;
+
+ /** Used for {@link #getHeaderValue(int)} : changed for each call to the method **/
+ protected int currMonthIndex;
+
+ /**
+ * Constructor with {@code user} and {@code monthHeaders} needed to prepare
+ * headers and record months values.
+ *
+ * @param writer CsvWriter used to write data in the resulting file.
+ * @param user WaoUser who called the export
+ * @param monthHeaders String values of months to put in header row
+ * @throws IOException
+ */
+ public SamplingExport(CsvWriter writer, WaoUser user, List<String> monthHeaders) throws IOException {
+ super(writer, SAMPLING.getTotalHeaders() + monthHeaders.size());
+ this.monthHeaders = monthHeaders;
+ this.user = user;
+ }
+
+ @Override
+ protected String getHeaderValue(int index) throws IOException {
+ int nbHeadersForMonths = monthHeaders.size();
+ String result = "";
+ if (index >= SAMPLING.getStartIndexForMonths() && currMonthIndex < nbHeadersForMonths) {
+ result = monthHeaders.get(currMonthIndex);
+ currMonthIndex++;
+ } else {
+ SamplingHeader header = WaoCsvHeader.getHeaderForSamplingCsv(index, nbHeadersForMonths);
+ // for an admin, same text as in Import (enum name)
+ // for a user, the text is complete
+ result = user.getAdmin() ? header.name() : header.toString();
+ }
+ return result;
+ }
+
+ @Override
+ public void record(SamplingHeader header, String value) {
+ int index = header.forSamplingCsv();
+ if (index >= SAMPLING.getStartIndexForMonths()) {
+ index += monthHeaders.size();
+ }
+ record(index, value);
+ }
+
+ public void recordMonths(SampleRow row) throws ParseException {
+ for (int i = 0; i < monthHeaders.size(); i++) {
+ // Get date from monthHeaders list
+ Date month = SAMPLING.getDateFormat().parse(monthHeaders.get(i));
+ // Retrieve sampleMonth corresponding
+ SampleMonth sampleMonth = row.getSampleMonth(month);
+ // Add it to the file if it exists
+ if (sampleMonth != null) {
+ // Prepare index for record
+ int index = SAMPLING.getStartIndexForMonths() + i;
+ String expected = String.valueOf(sampleMonth.getExpectedTidesValue());
+ String real = String.valueOf(sampleMonth.getRealTidesValue());
+ // The admin as only expected value (to be the same as
+ // in import)
+ if (user.getAdmin()) {
+ record(index, expected); //record[index] = expected;
+ // The user as both expected and real values
+ } else {
+ record(index, expected + " (" + real + ")");
+ }
+ }
+ }
+ }
+
+}
Property changes on: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/SamplingExport.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Added: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/WaoCsvHeader.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/WaoCsvHeader.java (rev 0)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/WaoCsvHeader.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -0,0 +1,451 @@
+
+package fr.ifremer.suiviobsmer.io;
+
+import java.text.DateFormat;
+import java.text.NumberFormat;
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+import org.apache.commons.lang.BooleanUtils;
+
+/**
+ * CsvHeader
+ *
+ * Created: 11 févr. 2010
+ *
+ * @author fdesbois
+ * @version $Revision$
+ *
+ * Mise a jour: $Date$
+ * par : $Author$
+ */
+public class WaoCsvHeader {
+
+ public interface IOHeader {
+
+ /**
+ * Name of the header. This method is automatically implemented for an
+ * enum.
+ *
+ * @return the name of the header
+ */
+ String name();
+ }
+
+ public interface DatedHeader extends IOHeader {
+
+ /**
+ * Pattern for Date parsing. This pattern can be null, if no format date is necessary.
+ *
+ * @return a String corresponding to the date pattern
+ */
+ String datePattern();
+ }
+
+ public interface ContactHeader extends IOHeader {
+
+ int forContactCsv();
+ }
+
+ public interface SamplingHeader extends IOHeader {
+
+ int forSamplingCsv();
+ }
+
+ /**
+ * CSV headers for Boat
+ */
+ public enum BOAT implements ContactHeader {
+ /** Boat immatriculation **/
+ NAVS_COD(1, "Immatriculation", 20),
+ /** Boat name **/
+ CARN_NOM(2, "Nom", 21),
+ /** Boat length **/
+ CARN_LONGUEUR_HT(3, "Longueur (m)"),
+ /** Boat build year **/
+ CARN_ANNEE(4, "Année de construction"),
+ /** Boat district code **/
+ QUARTIER_IMMA(5, "Code quartier", 22),
+ /** ShipOwner code **/
+ PER_COD,
+ /** ShipOwner last name **/
+ PER_NOM,
+ /** ShipOwner first name **/
+ PER_PRENOM,
+ /** Boat active **/
+ NAVS_ACTIVE(0, "Actif/Inactif"),
+ /** BoatInfos contactFirstName **/
+ CONT_PRENOM(6, "Prénom du contact"),
+ /** BoatInfos contactLastName **/
+ CONT_NOM(7, "Nom du contact"),
+ /** BoatInfos contactEmail **/
+ CONT_EMAIL(8, "Email du contact"),
+ /** BoatInfos contactPhoneNumber **/
+ CONT_TEL(9, "Tél du contact"),
+ /** BoatInfos dup **/
+ NAVS_DUP(10, "Capacité d'accueil du navire en personnels spécialisés"),
+ /** BoatInfos comment **/
+ NAVS_COMMENT(11, "Commentaire");
+
+ private int contactHeader;
+
+ private int boatHeader;
+
+ private String title;
+
+ BOAT(int indexBoat, String title, int indexContact) {
+ contactHeader = indexContact;
+ boatHeader = indexBoat;
+ this.title = title;
+ }
+
+ BOAT(int indexBoat, String title) {
+ boatHeader = indexBoat;
+ this.title = title;
+ contactHeader = -1;
+ }
+
+ BOAT() {
+ contactHeader = -1;
+ boatHeader = -1;
+ title = name();
+ }
+
+ @Override
+ public int forContactCsv() {
+ return contactHeader;
+ }
+
+ public int forBoatCsv() {
+ return boatHeader;
+ }
+
+ @Override
+ public String toString() {
+ return title;
+ }
+
+ public static int getTotalHeaders() {
+ // NAVS_COMMENT is the last column
+ return NAVS_COMMENT.forBoatCsv() + 1;
+ }
+
+ public static String getBoatInactiveCode() {
+ return "I";
+ }
+ }
+
+ /**
+ * CSV headers for SamplingPlan
+ */
+ public enum SAMPLING implements SamplingHeader, ContactHeader, DatedHeader {
+ /** SampleRow code **/
+ PLAN_CODE(0, "Code ligne du plan", 6),
+ /** Company name **/
+ SOCIETE_NOM(1, "Société prestataire", 5),
+ /** Program code **/
+ PROGRAMME_CODE(12, "Programme de rattachement", 7),
+ /** Program period begin **/
+ PROGRAMME_DEBUT(13, "Date de début", 8),
+ /** Program period end **/
+ PROGRAMME_FIN(14, "Date de fin", 9),
+ /** FishingZone other infos **/
+ PECHE_AUTRE(5, "Zone de pêche autres informations", 13),
+ /** Profession code DCF5 **/
+ METIER_CODE_DCF5(6, "Métier (Code DCF niveau 5)", 14),
+ /** Profession mesh size **/
+ METIER_MAILLAGE(7, "Métier maillage (mm)", 15),
+ /** Profession size **/
+ METIER_TAILLE(8, "Métier taille (m)", 16),
+ /** Profession other infos **/
+ METIER_AUTRE(9, "Métier autre information", 17),
+ /** Profession libelle **/
+ METIER_LIBELLE(10, "Métier libellé", 18),
+ /** Profession species **/
+ METIER_ESPECES(11, "Métier espèces cibles", 19),
+ /** SampleRow nb observants **/
+ PLAN_NB_OBSERV(16, "Nombre d'observateurs"),
+ /** SampleRow average tide time **/
+ PLAN_DUREE_MOY(15, "Durée moyenne d'une marée (jours)"),
+ /** SampleRow comment **/
+ PLAN_COMMENT(17, "Commentaire");
+
+ private int contactHeader;
+
+ private int samplingHeader;
+
+ private String title;
+
+ SAMPLING(int indexSampling, String title, int indexContact) {
+ this(indexSampling, title);
+ contactHeader = indexContact;
+ }
+
+ SAMPLING(int indexSampling, String title) {
+ samplingHeader = indexSampling;
+ this.title = title;
+ contactHeader = -1;
+ }
+
+ @Override
+ public int forContactCsv() {
+ return contactHeader;
+ }
+
+ @Override
+ public int forSamplingCsv() {
+ return samplingHeader;
+ }
+
+ @Override
+ public String toString() {
+ return title;
+ }
+
+ @Override
+ public String datePattern() {
+ return defaultDatePattern();
+ }
+
+ public static String defaultDatePattern() {
+ return "MM/yyyy";
+ }
+
+ public static DateFormat getDateFormat() {
+ return new SimpleDateFormat(defaultDatePattern(), Locale.FRENCH);
+ }
+
+ public static NumberFormat getNumberFormat() {
+ return NumberFormat.getNumberInstance(Locale.FRENCH);
+ }
+
+ public static int getStartIndexForMonths() {
+ // PROGRAMME_FIN is the last column before months
+ return PROGRAMME_FIN.forSamplingCsv() + 1;
+ }
+
+ public static int getTotalHeaders() {
+ // PLAN_COMMENT is the last column
+ return PLAN_COMMENT.forSamplingCsv() + 1;
+ }
+ }
+
+ /**
+ * CSV headers for FishingZone
+ */
+ public enum FISHING_ZONE implements SamplingHeader, ContactHeader {
+ /** FishingZone facade **/
+ PECHE_FACADE(2, "Zone de pêche façade", 10),
+ /** FishingZone sector **/
+ PECHE_ZONE(3, "Zone de pêche", 11),
+ /** FishingZone district code **/
+ PECHE_DIVISION(4, "Zone de pêche divisions", 12);
+
+ private int contactHeader;
+
+ private int samplingHeader;
+
+ String title;
+
+ FISHING_ZONE(int indexSampling, String title, int indexContact) {
+ contactHeader = indexContact;
+ samplingHeader = indexSampling;
+ this.title = title;
+ }
+
+ @Override
+ public int forContactCsv() {
+ return contactHeader;
+ }
+
+ @Override
+ public int forSamplingCsv() {
+ return samplingHeader;
+ }
+
+ @Override
+ public String toString() {
+ return title;
+ }
+
+ public static String getDistrictCodeSeparator() {
+ return " / ";
+ }
+ }
+
+ /**
+ * CSV headers for Contact
+ */
+ public enum CONTACT implements ContactHeader, DatedHeader {
+ /** Contact code (create date time for existing contact) **/
+ CONT_CODE(0),
+ /** Contact create date **/
+ CONT_CREATION(1),
+ /** User id **/
+ OBSERV_ID(2),
+ /** User prenom **/
+ OBSERV_PRENOM(3),
+ /** User nom **/
+ OBSERV_NOM(4),
+ /** Company id **/
+ //SOCIETE_ID,
+ /** Contact state **/
+ CONT_ETAT(23),
+ /** Contact tide begin **/
+ CONT_DEBUT_MAREE(24),
+ /** Contact tide end **/
+ CONT_FIN_MAREE(25),
+ /** Contact nb observants **/
+ CONT_NB_OBSERV(26),
+ /** Contact mammals capture **/
+ CONT_MAM_CAPT(27),
+ /** Contact mammals observation **/
+ CONT_MAM_OBS(28),
+ /** Contact comment **/
+ CONT_COMMENT(29),
+ /** Contact data input **/
+ CONT_ALLEGRO(30),
+ /** Contact company validation **/
+ CONT_SOCIETE_VALID(31),
+ /** Contact program validation **/
+ CONT_PROGRAM_VALID(32);
+
+ private int contactHeader;
+
+ CONTACT(int index) {
+ this.contactHeader = index;
+ }
+
+ @Override
+ public int forContactCsv() {
+ return contactHeader;
+ }
+
+ @Override
+ public String datePattern() {
+ return defaultDatePattern();
+ }
+
+ private static String defaultDatePattern() {
+ return "dd/MM/yyyy";
+ }
+
+ public static DateFormat getDateFormat() {
+ return new SimpleDateFormat(defaultDatePattern(), Locale.FRENCH);
+ }
+
+ public static DateFormat getTimeFormat() {
+ return new SimpleDateFormat("HHmmssS", Locale.FRENCH);
+ }
+
+ public static int getTotalHeaders() {
+ // CONT_PROGRAM_VALID is the last column
+ return CONT_PROGRAM_VALID.forContactCsv() + 1;
+ }
+
+ public static String formatValidation(Boolean validation) {
+ String valid = "";
+ if (validation == null) {
+ valid = "N";
+ } else if (BooleanUtils.isTrue(validation)) {
+ valid = "A";
+ } else {
+ valid = "R";
+ }
+ return valid;
+ }
+
+ public static String formatMammals(boolean mammals) {
+ return mammals ? "X" : "";
+ }
+ }
+
+ public enum ACTIVITY_CALENDAR implements IOHeader {
+ /** ActivityCalendar year **/
+ SYNA_AN,
+ /** ActivityCalendar fiability **/
+ INDQ_COD,
+ /** ActivityMonth month **/
+ SYNA_MOI,
+ /** ActivityMonth harbourCode **/
+ SYNA_POR_COD,
+ /** ActivityMonth nbSeaDays **/
+ SYNA_NOMJDM,
+ /** ActivityMonth nbFishingDays **/
+ SYNA_NOMJDP,
+ /** ActivityMonth nbBoardingPersons **/
+ SYNA_NOMHE,
+ /** ActivityMonth harbourId **/
+ SYNA_TPOR_COD,
+ /** ActivityMonth harbourLibelle **/
+ SYNA_POR_LIB,
+ /** ActivityProfession professionOrder **/
+ META_ORDRE,
+ /** ActivityProfession code **/
+ MET_COD,
+ /** ActivityProfession id **/
+ MET_ID,
+ /** ActivityProfession libelle **/
+ MET_LIB,
+ /** ActivityZone code **/
+ SECT_COD,
+ /** ActivityZone gradiantCode **/
+ GRA_COD,
+ /** ActivityZone gradiantLibelle **/
+ GRA_LIB,
+ /** ActivityZone zoneId **/
+ TSECT_COD,
+ /** ActivityZone zoneLibelle **/
+ SECT_LIB;
+ }
+
+ public static String getHeaderForContactCsv(int index) {
+ for (BOAT boatEnum : BOAT.values()) {
+ if (boatEnum.forContactCsv() == index) {
+ return boatEnum.name();
+ }
+ }
+ for (SAMPLING samplingEnum : SAMPLING.values()) {
+ if (samplingEnum.forContactCsv() == index) {
+ return samplingEnum.name();
+ }
+ }
+ for (FISHING_ZONE zoneEnum : FISHING_ZONE.values()) {
+ if (zoneEnum.forContactCsv() == index) {
+ return zoneEnum.name();
+ }
+ }
+ for (CONTACT contactEnum : CONTACT.values()) {
+ if (contactEnum.forContactCsv() == index) {
+ return contactEnum.name();
+ }
+ }
+ return "";
+ }
+
+ public static String getHeaderForBoatCsv(int index) {
+ for (BOAT boatEnum : BOAT.values()) {
+ if (boatEnum.forBoatCsv() == index) {
+ return boatEnum.toString();
+ }
+ }
+ return "";
+ }
+
+ public static SamplingHeader getHeaderForSamplingCsv(int index, int nbMonthHeaders) {
+ if (index > SAMPLING.getStartIndexForMonths()) {
+ index -= nbMonthHeaders;
+ }
+
+ for (SAMPLING samplingEnum : SAMPLING.values()) {
+ if (samplingEnum.forSamplingCsv() == index) {
+ return samplingEnum;
+ }
+ }
+ for (FISHING_ZONE zoneEnum : FISHING_ZONE.values()) {
+ if (zoneEnum.forSamplingCsv() == index) {
+ return zoneEnum;
+ }
+ }
+ return null;
+ }
+}
Property changes on: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/io/WaoCsvHeader.java
___________________________________________________________________
Added: svn:keywords
+ "Author Date Id Revision HeadURL"
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ActivityCalendarImport.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ActivityCalendarImport.java 2010-02-10 22:04:27 UTC (rev 345)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ActivityCalendarImport.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -23,8 +23,6 @@
import fr.ifremer.suiviobsmer.*;
import com.csvreader.CsvReader;
-import fr.ifremer.suiviobsmer.ImportHelper.ACTIVITY_CALENDAR;
-import fr.ifremer.suiviobsmer.ImportHelper.BOAT;
import fr.ifremer.suiviobsmer.entity.ActivityCalendar;
import fr.ifremer.suiviobsmer.entity.ActivityCalendarDAO;
import fr.ifremer.suiviobsmer.entity.ActivityMonth;
@@ -35,6 +33,9 @@
import fr.ifremer.suiviobsmer.entity.ActivityZoneDAO;
import fr.ifremer.suiviobsmer.entity.Boat;
import fr.ifremer.suiviobsmer.entity.BoatDAO;
+import fr.ifremer.suiviobsmer.io.ImportHelper;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.ACTIVITY_CALENDAR;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.BOAT;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
@@ -49,7 +50,6 @@
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
-import java.util.logging.Level;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.nuiton.topia.TopiaContext;
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceBoatImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceBoatImpl.java 2010-02-10 22:04:27 UTC (rev 345)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceBoatImpl.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -23,14 +23,11 @@
import com.csvreader.CsvReader;
import com.csvreader.CsvWriter;
-import fr.ifremer.suiviobsmer.ImportHelper;
-import fr.ifremer.suiviobsmer.ImportHelper.BOAT;
import fr.ifremer.suiviobsmer.SuiviObsmerBusinessException;
import fr.ifremer.suiviobsmer.SuiviObsmerBusinessException.Type;
import fr.ifremer.suiviobsmer.SuiviObsmerContext;
import fr.ifremer.suiviobsmer.SuiviObsmerException;
import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper;
-import java.util.logging.Level;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.framework.TopiaQuery.Op;
@@ -38,7 +35,10 @@
import fr.ifremer.suiviobsmer.bean.CompanyBoatInfos;
import fr.ifremer.suiviobsmer.bean.CompanyBoatInfosImpl;
import fr.ifremer.suiviobsmer.entity.*;
-import fr.ifremer.suiviobsmer.services.ServiceBoat;
+import fr.ifremer.suiviobsmer.io.ImportHelper;
+import fr.ifremer.suiviobsmer.io.ExportHelper;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.BOAT;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -91,9 +91,9 @@
query = createQueryForBoatFilter(query, filter);
- if (StringUtils.isNotEmpty(filter.getOrderBy())) {
- query.addOrder("B." + filter.getOrderBy());
- }
+// if (StringUtils.isNotEmpty(filter.getOrderBy())) {
+// query.addOrder("B." + filter.getOrderBy());
+// }
query.addLoad(Boat.ACTIVITY_CALENDAR);
@@ -154,6 +154,10 @@
}
}
+ if (StringUtils.isNotEmpty(filter.getOrderBy())) {
+ query.addOrder(main + "." + filter.getOrderBy());
+ }
+
return query;
}
@@ -408,7 +412,7 @@
String shipOwnerFirstName = ImportHelper.read(reader, BOAT.PER_PRENOM);
//String activeStr = reader.get(BOAT.NAVS_ACTIVE.name()).trim();
String activeStr = ImportHelper.read(reader, BOAT.NAVS_ACTIVE);
- boolean active = !activeStr.equals(ImportHelper.BOAT_INACTIVE_CODE);
+ boolean active = !activeStr.equals(BOAT.getBoatInactiveCode());
if (log.isDebugEnabled()) {
log.debug("Active : " + active + " (" + activeStr + ")");
@@ -484,7 +488,7 @@
@Override
public InputStream exportBoatCsv(BoatFilter filter) throws SuiviObsmerException {
- TopiaContext transaction = null;
+ TopiaContext transaction = null;
InputStream result = null;
CsvWriter writer = null;
try {
@@ -496,56 +500,62 @@
FileOutputStream output = new FileOutputStream(file);
writer = new CsvWriter(output, ',', Charset.forName("UTF-8"));
- // Headers
- for (int i = 0; i < ImportHelper.BOAT_NB_HEADERS; i++) {
- String header = ImportHelper.getHeaderForBoatCsv(i);
- if (log.isDebugEnabled()) {
- log.debug("header : " + header);
+ ExportHelper<BOAT> export = new ExportHelper<BOAT>(writer, BOAT.getTotalHeaders()) {
+ @Override
+ public String getHeaderValue(int index) throws IOException {
+ return WaoCsvHeader.getHeaderForBoatCsv(index);
}
- writer.write(header);
- }
- writer.endRecord();
+ @Override
+ public void record(BOAT header, String value) {
+ record(header.forBoatCsv(), value);
+ }
+ };
+
+ export.writeHeaders();
+
// Get boats from database filterd by filter in argument
BoatDAO dao = SuiviObsmerModelDAOHelper.getBoatDAO(transaction);
TopiaQuery query = dao.createQuery("B");
- query = filter.prepareQueryForBoat(query, "B");
+ query = createQueryForBoatFilter(query, filter);
// Reset limit : no pagination needed for results
query.resetLimit();
+
+ if (log.isDebugEnabled()) {
+ log.debug("Exec query : " + query);
+ }
List<Boat> boats = dao.findAllByQuery(query);
for (Boat boat : boats) {
- String[] record = new String[ImportHelper.BOAT_NB_HEADERS];
+ export.newRecord();
- if (log.isDebugEnabled()) {
- log.debug("add boat : " + boat.getName() + " (" + boat.getImmatriculation() + ")");
+ if (log.isTraceEnabled()) {
+ log.trace("add boat : " + boat.getName() + " (" + boat.getImmatriculation() + ")");
}
- record[BOAT.NAVS_COD.forBoatCsv()] = String.valueOf(boat.getImmatriculation());
- record[BOAT.CARN_NOM.forBoatCsv()] = boat.getName();
- record[BOAT.CARN_LONGUEUR_HT.forBoatCsv()] = String.valueOf(boat.getBoatLength());
- record[BOAT.CARN_ANNEE.forBoatCsv()] = String.valueOf(boat.getBuildYear());
- record[BOAT.QUARTIER_IMMA.forBoatCsv()] = boat.getDistrictCode();
- record[BOAT.NAVS_ACTIVE.forBoatCsv()] = !boat.getActive() ?
- ImportHelper.BOAT_INACTIVE_CODE : "";
+ export.record(BOAT.NAVS_COD, String.valueOf(boat.getImmatriculation()));
+ export.record(BOAT.CARN_NOM, boat.getName());
+ export.record(BOAT.CARN_LONGUEUR_HT, String.valueOf(boat.getBoatLength()));
+ export.record(BOAT.CARN_ANNEE, String.valueOf(boat.getBuildYear()));
+ export.record(BOAT.QUARTIER_IMMA, boat.getDistrictCode());
+ export.record(BOAT.NAVS_ACTIVE, (!boat.getActive() ? BOAT.getBoatInactiveCode() : ""));
if (filter.getCompany() != null) {
BoatInfos boatInfos = boat.getCompanyBoatInfos(filter.getCompany());
if (boatInfos != null) {
- record[BOAT.CONT_PRENOM.forBoatCsv()] = boatInfos.getContactFirstName();
- record[BOAT.CONT_NOM.forBoatCsv()] = boatInfos.getContactLastName();
- record[BOAT.CONT_EMAIL.forBoatCsv()] = boatInfos.getContactEmail();
- record[BOAT.CONT_TEL.forBoatCsv()] = boatInfos.getContactPhoneNumber();
- record[BOAT.NAVS_DUP.forBoatCsv()] = String.valueOf(boatInfos.getDup());
- record[BOAT.NAVS_COMMENT.forBoatCsv()] = boatInfos.getComment();
+ export.record(BOAT.CONT_PRENOM, boatInfos.getContactFirstName());
+ export.record(BOAT.CONT_NOM, boatInfos.getContactLastName());
+ export.record(BOAT.CONT_EMAIL, boatInfos.getContactEmail());
+ export.record(BOAT.CONT_TEL, boatInfos.getContactPhoneNumber());
+ export.record(BOAT.NAVS_DUP, String.valueOf(boatInfos.getDup()));
+ export.record(BOAT.NAVS_COMMENT, boatInfos.getComment());
}
}
- writer.writeRecord(record);
- writer.flush();
+ export.writeRecord();
}
result = new FileInputStream(file);
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceContactImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceContactImpl.java 2010-02-10 22:04:27 UTC (rev 345)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceContactImpl.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -23,8 +23,8 @@
import com.csvreader.CsvReader;
import com.csvreader.CsvWriter;
-import fr.ifremer.suiviobsmer.ImportHelper;
-import fr.ifremer.suiviobsmer.ImportHelper.*;
+import fr.ifremer.suiviobsmer.io.ImportHelper;
+import fr.ifremer.suiviobsmer.io.ImportHelper.*;
import fr.ifremer.suiviobsmer.SuiviObsmerBusinessException;
import fr.ifremer.suiviobsmer.SuiviObsmerBusinessException.Type;
import fr.ifremer.suiviobsmer.SuiviObsmerException;
@@ -52,7 +52,13 @@
import fr.ifremer.suiviobsmer.entity.SampleRowDAO;
import fr.ifremer.suiviobsmer.entity.WaoUser;
import fr.ifremer.suiviobsmer.entity.WaoUserDAO;
-import fr.ifremer.suiviobsmer.services.ServiceContact;
+import fr.ifremer.suiviobsmer.io.ExportHelper;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.BOAT;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.CONTACT;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.ContactHeader;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.FISHING_ZONE;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.SAMPLING;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -205,19 +211,30 @@
FileOutputStream output = new FileOutputStream(file);
writer = new CsvWriter(output, ',', Charset.forName("UTF-8"));
- // Headers
- for (int i = 0; i < ImportHelper.CONTACT_NB_HEADERS; i++) {
- String header = ImportHelper.getHeaderForContactCsv(i);
- writer.write(header);
- }
- writer.endRecord();
+ ExportHelper<ContactHeader> export = new ExportHelper<ContactHeader>(writer, CONTACT.getTotalHeaders()) {
+ @Override
+ public void record(ContactHeader header, String value) {
+ record(header.forContactCsv(), value);
+ }
+
+ @Override
+ protected String getHeaderValue(int index) throws IOException {
+ if (log.isDebugEnabled()) {
+ log.debug("record header : " + index + " = " + WaoCsvHeader.getHeaderForContactCsv(index));
+ }
+ return WaoCsvHeader.getHeaderForContactCsv(index);
+ }
+ };
+
+ export.writeHeaders();
- DateFormat dateFormat = ImportHelper.getContactDateFormat();
+ DateFormat dateFormat = CONTACT.getDateFormat();
// Get contacts from database
ContactDAO dao = SuiviObsmerModelDAOHelper.getContactDAO(transaction);
TopiaQuery query = dao.createQuery("C");
+ query.addOrderDesc("C." + TopiaEntity.TOPIA_CREATE_DATE);
// No page limit in this case
query = filter.prepareQueryForContact(query).resetLimit();
@@ -228,77 +245,73 @@
List<Contact> contacts = dao.findAllByQuery(query);
+ DateFormat timeFormat = CONTACT.getTimeFormat();
+
for (Contact contact : contacts) {
- String[] record = new String[ImportHelper.CONTACT_NB_HEADERS];
+ export.newRecord();
// Contact part
- record[CONTACT.CONT_CODE.forContactCsv()] = ImportHelper.formatContactCode(contact.getTopiaCreateDate());
- record[CONTACT.CONT_CREATION.forContactCsv()] = dateFormat.format(contact.getTopiaCreateDate());
- record[CONTACT.CONT_ETAT.forContactCsv()] = contact.getState();
+ export.record(CONTACT.CONT_CODE, timeFormat.format(contact.getTopiaCreateDate()));
+ export.record(CONTACT.CONT_CREATION, dateFormat.format(contact.getTopiaCreateDate()));
+ export.record(CONTACT.CONT_ETAT, contact.getState());
if (contact.getTideBeginDate() != null) {
- record[CONTACT.CONT_DEBUT_MAREE.forContactCsv()] = dateFormat.format(contact.getTideBeginDate());
+ export.record(CONTACT.CONT_DEBUT_MAREE, dateFormat.format(contact.getTideBeginDate()));
}
if (contact.getTideEndDate() != null) {
- record[CONTACT.CONT_FIN_MAREE.forContactCsv()] = dateFormat.format(contact.getTideEndDate());
+ export.record(CONTACT.CONT_FIN_MAREE, dateFormat.format(contact.getTideEndDate()));
}
- record[CONTACT.CONT_NB_OBSERV.forContactCsv()] = String.valueOf(contact.getNbObservants());
- record[CONTACT.CONT_MAM_CAPT.forContactCsv()] =
- ImportHelper.formatContactMammals(contact.getMammalsCapture());
- record[CONTACT.CONT_MAM_OBS.forContactCsv()] =
- ImportHelper.formatContactMammals(contact.getMammalsObservation());
- record[CONTACT.CONT_COMMENT.forContactCsv()] = contact.getComment();
+ export.record(CONTACT.CONT_NB_OBSERV, String.valueOf(contact.getNbObservants()));
+ export.record(CONTACT.CONT_MAM_CAPT, CONTACT.formatMammals(contact.getMammalsCapture()));
+ export.record(CONTACT.CONT_MAM_OBS, CONTACT.formatMammals(contact.getMammalsObservation()));
+ export.record(CONTACT.CONT_COMMENT, contact.getComment());
if (contact.getDataInputDate() != null) {
- record[CONTACT.CONT_ALLEGRO.forContactCsv()] = dateFormat.format(contact.getDataInputDate());
+ export.record(CONTACT.CONT_ALLEGRO, dateFormat.format(contact.getDataInputDate()));
}
- record[CONTACT.CONT_SOCIETE_VALID.forContactCsv()] =
- ImportHelper.formatContactValidation(contact.getValidationCompany());
- record[CONTACT.CONT_PROGRAM_VALID.forContactCsv()] =
- ImportHelper.formatContactValidation(contact.getValidationProgram());
+ export.record(CONTACT.CONT_SOCIETE_VALID, CONTACT.formatValidation(contact.getValidationCompany()));
+ export.record(CONTACT.CONT_PROGRAM_VALID, CONTACT.formatValidation(contact.getValidationProgram()));
// Observer part
WaoUser observer = contact.getObserver();
Company company = observer.getCompany();
- record[CONTACT.OBSERV_ID.forContactCsv()] = observer.getLogin();
- record[CONTACT.OBSERV_PRENOM.forContactCsv()] = observer.getFirstName();
- record[CONTACT.OBSERV_NOM.forContactCsv()] = observer.getLastName();
- record[SAMPLING.SOCIETE_NOM.forContactCsv()] = company.getName();
+ export.record(CONTACT.OBSERV_ID, observer.getLogin());
+ export.record(CONTACT.OBSERV_PRENOM, observer.getFirstName());
+ export.record(CONTACT.OBSERV_NOM, observer.getLastName());
+ export.record(SAMPLING.SOCIETE_NOM, company.getName());
// SampleRow part
SampleRow row = contact.getSampleRow();
- record[SAMPLING.PLAN_CODE.forContactCsv()] = row.getCode();
- record[SAMPLING.PROGRAMME_CODE.forContactCsv()] = row.getProgramName();
- record[SAMPLING.PROGRAMME_DEBUT.forContactCsv()] = dateFormat.format(row.getPeriodBegin());
- record[SAMPLING.PROGRAMME_FIN.forContactCsv()] = dateFormat.format(row.getPeriodEnd());
- record[SAMPLING.PECHE_AUTRE.forContactCsv()] = row.getFishingZonesInfos();
+ export.record(SAMPLING.PLAN_CODE, row.getCode());
+ export.record(SAMPLING.PROGRAMME_CODE, row.getProgramName());
+ export.record(SAMPLING.PROGRAMME_DEBUT, dateFormat.format(row.getPeriodBegin()));
+ export.record(SAMPLING.PROGRAMME_FIN, dateFormat.format(row.getPeriodEnd()));
+ export.record(SAMPLING.PECHE_AUTRE, row.getFishingZonesInfos());
// FishingZone part
- List<FishingZone> zones = row.getFishingZone();
- String fishingDistrict = "";
- for (FishingZone zone : zones) {
- fishingDistrict += zone.getDistrictCode() + " - ";
+ String divisions = "";
+ String separator = " - ";
+ for (FishingZone zone : row.getFishingZone()) {
+ divisions += separator + zone.getDistrictCode();
}
- fishingDistrict = fishingDistrict.substring(fishingDistrict.length() - 3);
- record[FISHING_ZONE.PECHE_FACADE.forContactCsv()] = zones.get(0).getFacadeName();
- record[FISHING_ZONE.PECHE_ZONE.forContactCsv()] = zones.get(0).getSectorName();
- record[FISHING_ZONE.PECHE_DIVISION.forContactCsv()] = fishingDistrict;
+ export.record(FISHING_ZONE.PECHE_DIVISION, divisions.substring(separator.length()));
+ export.record(FISHING_ZONE.PECHE_FACADE, row.getFacade());
+ export.record(FISHING_ZONE.PECHE_ZONE, row.getSectors());
// Profession part
Profession profession = row.getProfession();
- record[SAMPLING.METIER_CODE_DCF5.forContactCsv()] = profession.getCodeDCF5();
- record[SAMPLING.METIER_MAILLAGE.forContactCsv()] = profession.getMeshSize();
- record[SAMPLING.METIER_TAILLE.forContactCsv()] = profession.getSize();
- record[SAMPLING.METIER_AUTRE.forContactCsv()] = profession.getOther();
- record[SAMPLING.METIER_LIBELLE.forContactCsv()] = profession.getLibelle();
- record[SAMPLING.METIER_ESPECES.forContactCsv()] = profession.getSpecies();
+ export.record(SAMPLING.METIER_CODE_DCF5, profession.getCodeDCF5());
+ export.record(SAMPLING.METIER_MAILLAGE, profession.getMeshSize());
+ export.record(SAMPLING.METIER_TAILLE, profession.getSize());
+ export.record(SAMPLING.METIER_AUTRE, profession.getOther());
+ export.record(SAMPLING.METIER_LIBELLE, profession.getLibelle());
+ export.record(SAMPLING.METIER_ESPECES, profession.getSpecies());
// Boat part
Boat boat = contact.getBoat();
- record[BOAT.NAVS_COD.forContactCsv()] = String.valueOf(boat.getImmatriculation());
- record[BOAT.CARN_NOM.forContactCsv()] = boat.getName();
- record[BOAT.QUARTIER_IMMA.forContactCsv()] = boat.getDistrictCode();
+ export.record(BOAT.NAVS_COD, String.valueOf(boat.getImmatriculation()));
+ export.record(BOAT.CARN_NOM, boat.getName());
+ export.record(BOAT.QUARTIER_IMMA, boat.getDistrictCode());
- writer.writeRecord(record);
- writer.flush();
+ export.writeRecord();
}
result = new FileInputStream(file);
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceReferentialImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceReferentialImpl.java 2010-02-10 22:04:27 UTC (rev 345)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceReferentialImpl.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -22,7 +22,6 @@
package fr.ifremer.suiviobsmer.services;
import com.csvreader.CsvReader;
-import fr.ifremer.suiviobsmer.ImportHelper.FISHING_ZONE;
import fr.ifremer.suiviobsmer.SuiviObsmerException;
import fr.ifremer.suiviobsmer.SuiviObsmerModelDAOHelper;
import fr.ifremer.suiviobsmer.SuiviObsmerContext;
@@ -32,7 +31,8 @@
import fr.ifremer.suiviobsmer.entity.Profession;
import fr.ifremer.suiviobsmer.entity.ProfessionDAO;
import fr.ifremer.suiviobsmer.entity.SampleRow;
-import fr.ifremer.suiviobsmer.services.ServiceReferential;
+import fr.ifremer.suiviobsmer.io.ImportHelper;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.FISHING_ZONE;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.ArrayList;
@@ -192,9 +192,9 @@
log.trace(" " + Arrays.asList(reader.getValues()));
}
- String facadeName = reader.get(FISHING_ZONE.PECHE_FACADE.name()).trim();
- String sectorName = reader.get(FISHING_ZONE.PECHE_ZONE.name()).trim();
- String districtCode = reader.get(FISHING_ZONE.PECHE_DIVISION.name()).trim();
+ String facadeName = ImportHelper.read(reader, FISHING_ZONE.PECHE_FACADE);
+ String sectorName = ImportHelper.read(reader, FISHING_ZONE.PECHE_ZONE);
+ String districtCode = ImportHelper.read(reader, FISHING_ZONE.PECHE_DIVISION);
FishingZone zone = dao.findByDistrictCode(districtCode);
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSamplingImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSamplingImpl.java 2010-02-10 22:04:27 UTC (rev 345)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSamplingImpl.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -22,9 +22,8 @@
package fr.ifremer.suiviobsmer.services;
import com.csvreader.CsvReader;
-import fr.ifremer.suiviobsmer.ImportHelper;
-import fr.ifremer.suiviobsmer.ImportHelper.FISHING_ZONE;
-import fr.ifremer.suiviobsmer.ImportHelper.SAMPLING;
+import com.csvreader.CsvWriter;
+import fr.ifremer.suiviobsmer.io.ImportHelper;
import fr.ifremer.suiviobsmer.SuiviObsmerBusinessException;
import fr.ifremer.suiviobsmer.SuiviObsmerBusinessException.Type;
import fr.ifremer.suiviobsmer.SuiviObsmerException;
@@ -36,11 +35,20 @@
import fr.ifremer.suiviobsmer.bean.ImportResultsImpl;
import fr.ifremer.suiviobsmer.bean.SamplingFilter;
import fr.ifremer.suiviobsmer.entity.*;
-import fr.ifremer.suiviobsmer.services.ServiceSampling;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.FISHING_ZONE;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.SAMPLING;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.SamplingHeader;
+import fr.ifremer.suiviobsmer.io.ExportHelper;
+import fr.ifremer.suiviobsmer.io.ExportHelper;
+import fr.ifremer.suiviobsmer.io.SamplingExport;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.text.DateFormat;
+import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -514,6 +522,140 @@
}
@Override
+ public InputStream exportSamplingPlanCsv(WaoUser user, PeriodDates period) throws SuiviObsmerException {
+ TopiaContext transaction = null;
+ InputStream result = null;
+ CsvWriter writer = null;
+ try {
+ transaction = rootContext.beginTransaction();
+
+ File file = File.createTempFile("wao-samplingPlan-", ".csv");
+ file.deleteOnExit();
+
+ FileOutputStream output = new FileOutputStream(file);
+ writer = new CsvWriter(output, ',', Charset.forName("UTF-8"));
+
+ // Get min and max dates to have the biggest period
+// Date min = (Date)query.executeToObject("MIN(S." + SampleRow.PERIOD_BEGIN + ")");
+// Date max = (Date)query.executeToObject("MAX(S." + SampleRow.PERIOD_END + ")");
+
+// PeriodDates periodMax = new PeriodDates(min, max);
+ period.setPattern(SAMPLING.defaultDatePattern());
+ List<String> monthHeaders = period.getFormatedMonths();
+
+ SamplingExport export = new SamplingExport(writer, user, monthHeaders);
+
+ export.writeHeaders();
+
+ // Get sampleRows from database filtered by company if needed
+ // (only for user) and period
+ SampleRowDAO dao = SuiviObsmerModelDAOHelper.getSampleRowDAO(transaction);
+ TopiaQuery query = dao.createQuery("S");
+
+ if (!user.getAdmin()) {
+ query.add("S." + SampleRow.COMPANY, user.getCompany());
+ }
+
+ // Prepare period dates
+ period.initDayOfMonthExtremities();
+ query.add("S." + SampleRow.PERIOD_BEGIN, Op.LT, period.getThruDate()).
+ add("S." + SampleRow.PERIOD_END, Op.GT, period.getFromDate());
+
+ query.addOrder("S." + SampleRow.CODE);
+
+ List<SampleRow> rows = dao.findAllByQuery(query);
+
+ DateFormat dateFormat = SAMPLING.getDateFormat();
+ NumberFormat numberFormat = SAMPLING.getNumberFormat();
+
+ for (SampleRow row : rows) {
+ export.newRecord();
+
+ if (log.isDebugEnabled()) {
+ log.debug("add sampleRow : " + row.getCode());
+ }
+
+ export.record(SAMPLING.PLAN_CODE, row.getCode());
+ Company company = row.getCompany();
+ if (company != null) {
+ export.record(SAMPLING.SOCIETE_NOM, company.getName());
+ }
+
+ // Profession can't be null
+ Profession profession = row.getProfession();
+ export.record(SAMPLING.METIER_CODE_DCF5, profession.getCodeDCF5());
+ export.record(SAMPLING.METIER_MAILLAGE, profession.getMeshSize());
+ export.record(SAMPLING.METIER_TAILLE, profession.getSize());
+ export.record(SAMPLING.METIER_AUTRE, profession.getOther());
+ export.record(SAMPLING.METIER_LIBELLE, profession.getLibelle());
+ export.record(SAMPLING.METIER_ESPECES, profession.getSpecies());
+
+ export.record(SAMPLING.PROGRAMME_CODE, row.getProgramName());
+ export.record(SAMPLING.PROGRAMME_DEBUT, dateFormat.format(row.getPeriodBegin()));
+ export.record(SAMPLING.PROGRAMME_FIN, dateFormat.format(row.getPeriodEnd()));
+
+ export.record(FISHING_ZONE.PECHE_FACADE, row.getFacade());
+ export.record(FISHING_ZONE.PECHE_ZONE, row.getSectors());
+ export.record(SAMPLING.PECHE_AUTRE, row.getFishingZonesInfos());
+
+ String divisions = "";
+ String separator = FISHING_ZONE.getDistrictCodeSeparator();
+ for (FishingZone zone : row.getFishingZone()) {
+ divisions += separator + zone.getDistrictCode();
+ }
+
+ // There is at least one district in row, so no problem with substring
+ export.record(FISHING_ZONE.PECHE_DIVISION, divisions.substring(separator.length()));
+
+ export.record(SAMPLING.PLAN_NB_OBSERV, numberFormat.format(row.getNbObservants()));
+ export.record(SAMPLING.PLAN_DUREE_MOY, numberFormat.format(row.getAverageTideTime()));
+ export.record(SAMPLING.PLAN_COMMENT, String.valueOf(row.getComment()));
+
+ export.recordMonths(row);
+
+// for (int i = 0; i < monthHeaders.size(); i++) {
+// // Get date from monthHeaders list
+// Date month = dateFormat.parse(monthHeaders.get(i));
+// // Retrieve sampleMonth corresponding
+// SampleMonth sampleMonth = row.getSampleMonth(month);
+// // Add it to the file if it exists
+// if (sampleMonth != null) {
+// // Prepare index for record
+// int index = SAMPLING.getStartIndexForMonths() + i;
+// String expected = String.valueOf(sampleMonth.getExpectedTidesValue());
+// String real = String.valueOf(sampleMonth.getRealTidesValue());
+// // The admin as only expected value (to be the same as
+// // in import)
+// if (user.getAdmin()) {
+// export.record(index, expected); //record[index] = expected;
+// // The user as both expected and real values
+// } else {
+// export.record(index, expected + " (" + real + ")");
+// }
+// }
+// }
+
+ export.writeRecord();
+ }
+
+ result = new FileInputStream(file);
+
+ } catch (Exception eee) {
+ DateFormat dateFormat = SAMPLING.getDateFormat();
+ SuiviObsmerContext.serviceException(transaction,
+ "Impossible d'exporter le plan d'échantillonnage sur la période du " +
+ dateFormat.format(period.getFromDate()) + " au " +
+ dateFormat.format(period.getThruDate()), eee);
+ } finally {
+ if (writer != null) {
+ writer.close();
+ }
+ SuiviObsmerContext.closeTransaction(transaction);
+ }
+ return result;
+ }
+
+ @Override
public ImportResults importSamplingPlanCsv(InputStream input) throws SuiviObsmerException {
TopiaContext transaction = null;
ImportResults result = new ImportResultsImpl();
@@ -666,7 +808,7 @@
FishingZoneDAO dao = SuiviObsmerModelDAOHelper.getFishingZoneDAO(transaction);
- List<String> districtList = new ArrayList<String>(Arrays.asList(districts.split(" / ")));
+ List<String> districtList = new ArrayList<String>(Arrays.asList(districts.split(FISHING_ZONE.getDistrictCodeSeparator())));
if (log.isDebugEnabled()) {
log.debug("FishingZone districts : " + districts);
@@ -725,7 +867,7 @@
// Note : nbTotalColumns must be > nbFixedColumns
int lastMonthColumnId = firstMonthColumnId + nbTotalColumns - nbFixedColumns;
- DateFormat dateFormat = new SimpleDateFormat(SAMPLING.defaultDatePattern());
+ DateFormat dateFormat = SAMPLING.getDateFormat();
for (int i = firstMonthColumnId; i < lastMonthColumnId; i++) {
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java 2010-02-10 22:04:27 UTC (rev 345)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -89,7 +89,9 @@
return results;
}
+ // Expected
SortedMap<Date, Integer> serie1 = new TreeMap<Date,Integer>();
+ // Real
SortedMap<Date, Integer> serie2 = new TreeMap<Date,Integer>();
results.add(serie1);
results.add(serie2);
Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo
===================================================================
(Binary files differ)
Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/ImportHelperTest.java
===================================================================
--- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/ImportHelperTest.java 2010-02-10 22:04:27 UTC (rev 345)
+++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/ImportHelperTest.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -22,10 +22,13 @@
package fr.ifremer.suiviobsmer;
import com.csvreader.CsvReader;
-import fr.ifremer.suiviobsmer.ImportHelper.SAMPLING;
+import fr.ifremer.suiviobsmer.io.ImportHelper;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.CONTACT;
+import fr.ifremer.suiviobsmer.io.WaoCsvHeader.SAMPLING;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
+import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -127,7 +130,8 @@
calendar.set(Calendar.SECOND, 50);
calendar.set(Calendar.MILLISECOND, 260);
String expResult = "100150260";
- String result = ImportHelper.formatContactCode(calendar.getTime());
+ DateFormat timeFormat = CONTACT.getTimeFormat();
+ String result = timeFormat.format(calendar.getTime());
assertEquals(expResult, result);
}
Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java
===================================================================
--- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java 2010-02-10 22:04:27 UTC (rev 345)
+++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Boats.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -514,6 +514,9 @@
public InputStream getStream() throws IOException {
InputStream result = null;
try {
+ if (log.isDebugEnabled()) {
+ log.debug("Filter sampleRow : " + getFilter().getSampleRow());
+ }
result = serviceBoat.exportBoatCsv(getFilter());
} catch (SuiviObsmerException eee) {
throw new IOException(eee);
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 2010-02-10 22:04:27 UTC (rev 345)
+++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/SamplingPlan.java 2010-02-11 20:04:33 UTC (rev 346)
@@ -34,11 +34,15 @@
import fr.ifremer.suiviobsmer.services.ServiceSampling;
import fr.ifremer.suiviobsmer.ui.base.SuiviObsmerPage;
import fr.ifremer.suiviobsmer.ui.components.Layout;
+import fr.ifremer.suiviobsmer.ui.data.ExportStreamResponse;
+import java.io.IOException;
+import java.io.InputStream;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
+import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.annotations.IncludeStylesheet;
import org.apache.tapestry5.annotations.InjectComponent;
import org.apache.tapestry5.annotations.Log;
@@ -119,7 +123,25 @@
layout.getFeedBack().addError(eee.getMessage());
}
}
+
+ /**************************** EXPORT **************************************/
+ StreamResponse onActionFromExportSamplingPlan() {
+ return new ExportStreamResponse("wao-echantillonnage") {
+
+ @Override
+ public InputStream getStream() throws IOException {
+ InputStream result = null;
+ try {
+ result = serviceSampling.exportSamplingPlanCsv(user, getPeriod());
+ } catch (SuiviObsmerException eee) {
+ throw new IOException(eee);
+ }
+ return result;
+ }
+ };
+ }
+
/**************************** PERIOD SELECTION *****************************/
@Persist
Modified: trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Boats.properties
===================================================================
--- trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Boats.properties 2010-02-10 22:04:27 UTC (rev 345)
+++ trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Boats.properties 2010-02-11 20:04:33 UTC (rev 346)
@@ -28,4 +28,5 @@
contactEmail-label: E-mail
shipOwner-label: Armateur
fromDate-label: Sollicitations du navire depuis le
-dup-label: Capacit\u00E9 d'accueil du navire en personnels sp\u00E9cialis\u00E9s
\ No newline at end of file
+dup-label: Capacit\u00E9 d'accueil du navire en personnels sp\u00E9cialis\u00E9s
+comment-label: Commentaire
\ No newline at end of file
Modified: trunk/suiviobsmer-ui/src/main/webapp/SamplingPlan.tml
===================================================================
--- trunk/suiviobsmer-ui/src/main/webapp/SamplingPlan.tml 2010-02-10 22:04:27 UTC (rev 345)
+++ trunk/suiviobsmer-ui/src/main/webapp/SamplingPlan.tml 2010-02-11 20:04:33 UTC (rev 346)
@@ -17,7 +17,13 @@
</t:if>
<div class="clearfix mbottom10">
<div class="fleft">
- <h1>Plan d'échantillonnage</h1>
+ <h1>
+ Plan d'échantillonnage
+ <a t:type="actionlink" t:id="exportSamplingPlan">
+ <img src="${asset:context:}/img/file-export-22px.png" alt="Export CSV"
+ title="Exporter le plan d'échantillonnage du ${dateFormat.format(period.fromDate)} au ${dateFormat.format(period.thruDate)}" />
+ </a>
+ </h1>
<form t:type="form" t:id="periodForm">
<t:label t:for="periodBegin" /> : <input t:type="datefield" class="width70" t:id="periodBegin" t:format="MM/yyyy" />
<t:label t:for="periodEnd" /> : <input t:type="datefield" class="width70" t:id="periodEnd" t:format="MM/yyyy" />
1
0
[Suiviobsmer-commits] r345 - in trunk: suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services suiviobsmer-business/src/main/xmi suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services 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 suiviobsmer-ui/src/main/webapp/css suiviobsmer-ui/src/main/webapp/img
by fdesbois@users.labs.libre-entreprise.org 10 Feb '10
by fdesbois@users.labs.libre-entreprise.org 10 Feb '10
10 Feb '10
Author: fdesbois
Date: 2010-02-10 22:04:27 +0000 (Wed, 10 Feb 2010)
New Revision: 345
Added:
trunk/suiviobsmer-ui/src/main/webapp/img/synthesis-ind-contact-states.png
Modified:
trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java
trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo
trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java
trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java
trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties
trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml
trunk/suiviobsmer-ui/src/main/webapp/css/synthesis.css
Log:
Evo #1986 : Integrate indicator contact states in synthesis page
Modified: trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java
===================================================================
--- trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java 2010-02-10 15:43:48 UTC (rev 344)
+++ trunk/suiviobsmer-business/src/main/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImpl.java 2010-02-10 22:04:27 UTC (rev 345)
@@ -258,17 +258,17 @@
TopiaQuery query =
dao.createQueryDoneContactsFromDate(null, null);
- String contactKey = query.getMainAlias();
- String sampleRowKey = contactKey + "." + Contact.SAMPLE_ROW;
- String companyKey = sampleRowKey + "." + SampleRow.COMPANY;
- String companyName = companyKey + "." + Company.NAME;
+ String contact = query.getMainAlias();
+ String sampleRow = contact + "." + Contact.SAMPLE_ROW;
+ String companyProp = sampleRow + "." + SampleRow.COMPANY;
+ String companyName = companyProp + "." + Company.NAME;
// Only for unfinished sampleRows
Date current = SuiviObsmerContext.getCurrentDate();
- query.add(sampleRowKey + "." + SampleRow.PERIOD_END, Op.GE, current);
+ query.add(sampleRow + "." + SampleRow.PERIOD_END, Op.GE, current);
if (company != null) {
- query.add(companyKey, company);
+ query.add(companyProp, company);
}
// Prepare results
@@ -282,8 +282,8 @@
// Use the same query and add the constraint of non compliance
//i.e. nbObservantsReal (contact) < nbObservantsExpected (sampleRow)
- query.add(contactKey + "." + Contact.NB_OBSERVANTS + " < " +
- sampleRowKey + "." + SampleRow.NB_OBSERVANTS);
+ query.add(contact + "." + Contact.NB_OBSERVANTS + " < " +
+ sampleRow + "." + SampleRow.NB_OBSERVANTS);
if (log.isDebugEnabled()) {
log.debug("Exec query for result : " + query);
@@ -336,43 +336,44 @@
@Override
public Collection<ContactStateStatistics> getContactStateStatistics(Company company, PeriodDates period) throws SuiviObsmerException {
TopiaContext transaction = null;
- Map<Company, ContactStateStatistics> results = new HashMap<Company, ContactStateStatistics>();
+ Map<String, ContactStateStatistics> results = new HashMap<String, ContactStateStatistics>();
try {
transaction = rootContext.beginTransaction();
ContactDAO dao = SuiviObsmerModelDAOHelper.getContactDAO(transaction);
// Only for contacts not refused by the program
- String contactKey = "C";
- String validationProgramKey = contactKey + "." + Contact.VALIDATION_PROGRAM;
- TopiaQuery query = dao.createQuery(contactKey).
- add(validationProgramKey + " IS NULL " +
- "OR " + validationProgramKey + " = :booleanTrue").
+ String contact = "C";
+ String validationProgram = contact + "." + Contact.VALIDATION_PROGRAM;
+ TopiaQuery query = dao.createQuery(contact).
+ add(validationProgram + " IS NULL " +
+ "OR " + validationProgram + " = :booleanTrue").
addParam("booleanTrue", Boolean.TRUE);
- String companyKey = contactKey + "." + Contact.OBSERVER + "." + WaoUser.COMPANY;
+ String companyProp = contact + "." + Contact.OBSERVER + "." + WaoUser.COMPANY;
if (company != null) {
- query.add(companyKey, company);
+ query.add(companyProp, company);
}
if (period != null) {
// Contacts include in the period
- String tideBeginDateKey = contactKey + "." + Contact.TIDE_BEGIN_DATE;
- String createDateKey = contactKey + "." + TopiaEntity.TOPIA_CREATE_DATE;
- query.add("(" + tideBeginDateKey + " IS NOT NULL " +
- "AND " + tideBeginDateKey + " BETWEEN :fromDate AND :thruDate)" +
- " OR (" + tideBeginDateKey + " IS NULL " +
- "AND " + createDateKey + " BETWEEN :fromDate AND :thruDate)");
+ String tideBeginDate = contact + "." + Contact.TIDE_BEGIN_DATE;
+ String createDate = contact + "." + TopiaEntity.TOPIA_CREATE_DATE;
+ query.add("(" + tideBeginDate + " IS NOT NULL " +
+ "AND " + tideBeginDate + " BETWEEN :fromDate AND :thruDate)" +
+ " OR (" + tideBeginDate + " IS NULL " +
+ "AND " + createDate + " BETWEEN :fromDate AND :thruDate)");
query.addParam("fromDate", period.getFromDate()).
addParam("thruDate", period.getThruDate());
}
- String stateKey = contactKey + "." + Contact.STATE;
- query.addGroup(companyKey, stateKey).
- addOrder(companyKey).
- setSelect(companyKey, stateKey, "COUNT(*)");
+ String state = contact + "." + Contact.STATE;
+ String companyName = companyProp + "." + Company.NAME;
+ query.addGroup(companyName, state).
+ addOrder(companyName).
+ setSelect(companyName, state, "COUNT(*)");
if (log.isDebugEnabled()) {
log.debug("Exec query : " + query);
@@ -381,17 +382,17 @@
List<Object[]> res = query.execute();
for (Object[] row : res) {
- Company rowCompany = (Company)row[0];
+ String rowCompanyName = (String)row[0];
String rowState = (String)row[1];
Long rowCount = (Long)row[2];
if (log.isDebugEnabled()) {
- log.debug("res : " + rowCompany.getName() + " _ " + rowState + " _ " + rowCount);
+ log.debug("res : " + rowCompanyName + " _ " + rowState + " _ " + rowCount);
}
- ContactStateStatistics stats = results.get(rowCompany);
+ ContactStateStatistics stats = results.get(rowCompanyName);
if (stats == null) {
stats = new ContactStateStatisticsImpl();
- stats.setCompany(rowCompany);
- results.put(rowCompany, stats);
+ stats.setCompanyName(rowCompanyName);
+ results.put(rowCompanyName, stats);
}
stats.addResult(rowState, rowCount.intValue());
}
Modified: trunk/suiviobsmer-business/src/main/xmi/suiviobsmer.zargo
===================================================================
(Binary files differ)
Modified: trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java
===================================================================
--- trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java 2010-02-10 15:43:48 UTC (rev 344)
+++ trunk/suiviobsmer-business/src/test/java/fr/ifremer/suiviobsmer/services/ServiceSynthesisImplTest.java 2010-02-10 22:04:27 UTC (rev 345)
@@ -389,7 +389,7 @@
result = null;
for (ContactStateStatistics stats : results) {
- if (stats.getCompany().equals(company2)) {
+ if (stats.getCompanyName().equals(company2.getName())) {
result = stats;
break;
}
Modified: trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java
===================================================================
--- trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java 2010-02-10 15:43:48 UTC (rev 344)
+++ trunk/suiviobsmer-ui/src/main/java/fr/ifremer/suiviobsmer/ui/pages/Synthesis.java 2010-02-10 22:04:27 UTC (rev 345)
@@ -25,6 +25,8 @@
import fr.ifremer.suiviobsmer.bean.BoardingResult;
import fr.ifremer.suiviobsmer.bean.BoatFilter;
import fr.ifremer.suiviobsmer.bean.BoatFilterImpl;
+import fr.ifremer.suiviobsmer.bean.ContactState;
+import fr.ifremer.suiviobsmer.bean.ContactStateStatistics;
import fr.ifremer.suiviobsmer.entity.Company;
import fr.ifremer.suiviobsmer.entity.WaoUser;
import fr.ifremer.suiviobsmer.services.ServiceSynthesis;
@@ -37,6 +39,7 @@
import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
+import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -115,6 +118,14 @@
return ChartType.class.getName();
}
+ public NumberFormat getPercentFormat() {
+ return NumberFormat.getPercentInstance();
+ }
+
+ public DateFormat getDateFormat() {
+ return new SimpleDateFormat("dd/MM/yyyy");
+ }
+
@Log
Object onAction(String actionType, String actionValue) {
// Delegator action (menu)
@@ -275,10 +286,6 @@
return DateUtils.createDateAfterToday(0, -12, 0);
}
- public DateFormat getDateFormat() {
- return new SimpleDateFormat("dd/MM/yyyy");
- }
-
@Log
void onSuccessFromFilterCompanyForBoarding() throws SuiviObsmerException {
companyForBoarding = getCompanySelectModel().findObject(companyIdForBoarding);
@@ -286,6 +293,8 @@
/********************* INDICATOR : NONCOMPLIANCEBOARDING ******************/
+ private Map<String, Double> nonComplianceBoarding;
+
@Property
private Map.Entry<String, Double> nonComplianceBoardingEntry;
@@ -297,34 +306,98 @@
* @return a Map with companies and there values for nonComplianceBoarding
* @throws SuiviObsmerException
*/
- public Map<String, Double> getNonComplianceBoarding() throws SuiviObsmerException {
- Company company = !user.getAdmin() ? user.getCompany() : null;
- return serviceSynthesis.getNonComplianceBoardingIndicator(company);
+ public Map<String, Double> getNonComplianceBoarding()
+ throws SuiviObsmerException {
+ if (nonComplianceBoarding == null) {
+ Company company = !user.getAdmin() ? user.getCompany() : null;
+ nonComplianceBoarding =
+ serviceSynthesis.getNonComplianceBoardingIndicator(company);
+ }
+ return nonComplianceBoarding;
}
- public NumberFormat getPercentFormat() {
- return NumberFormat.getPercentInstance();
+ /**
+ * Return the value of nonComplianceBoarding indicator. Only useful for
+ * observer user.
+ *
+ * @return the value of the indicator
+ * @throws SuiviObsmerException
+ */
+ public Double getNonComplianceBoardingValue() throws SuiviObsmerException {
+ return getNonComplianceBoarding().get(user.getCompany().getName());
}
+ /********************* INDICATOR : NONCOMPLIANCEBOARDING ******************/
+
+ private Collection<ContactStateStatistics> contactStateStatistics;
+
+ @Persist
+ private PeriodDates periodForContactStates;
+
+ @Property
+ private ContactStateStatistics contactStateStats;
+
+ @Property
+ private ContactState contactState;
+
/**
- * Return the company name of the current entry (in the loop) for
- * nonComplianceBoarding indicator. Only useful for admin user.
+ * Get all existing contactStates.
*
- * @return the company name
- * @throws SuiviObsmerException
+ * @return ContactState[]
*/
-// public String getNonComplianceBoardingCompanyName() throws SuiviObsmerException {
-// return nonComplianceBoardingEntry.getKey().getName();
-// }
+ public ContactState[] getContactStates() {
+ return ContactState.values();
+ }
/**
- * Return the value of nonComplianceBoarding indicator. Only useful for
- * observer user.
+ * Get all contactStateStatistics from serviceSynthesis. There will be
+ * only one result if the current user is an observer.
*
- * @return the value of the indicator
+ * @return all contactStateStatistics depends on company and selected period
* @throws SuiviObsmerException
*/
- public Double getNonComplianceBoardingValue() throws SuiviObsmerException {
- return getNonComplianceBoarding().get(user.getCompany().getName());
+ public Collection<ContactStateStatistics> getContactStateStatistics()
+ throws SuiviObsmerException {
+ if (contactStateStatistics == null) {
+ Company company = !user.getAdmin() ? user.getCompany() : null;
+ contactStateStatistics =
+ serviceSynthesis.getContactStateStatistics(company, getPeriodForContactStates());
+ }
+ return contactStateStatistics;
}
+
+ public PeriodDates getPeriodForContactStates() {
+ if (periodForContactStates == null) {
+ periodForContactStates = PeriodDates.createMonthsPeriodFromToday(-12);
+ }
+ return periodForContactStates;
+ }
+
+ /**
+ * Get the value for current contactStateStats in table row (by company)
+ * and current contactState in table column.
+ *
+ * @return the number of contact states for the current contactState
+ */
+ public int getNbContactStates() {
+ return contactStateStats.getData().get(contactState);
+ }
+
+ /**
+ * Get the percent value for the current contactStateStats in table row
+ * (by company) and current contactState in table column.
+ *
+ * @return the percent value of contact states for the current contactState
+ */
+ public double getPercentContactStates() {
+ if (log.isDebugEnabled()) {
+ log.debug("nbContactStates : " + getNbContactStates());
+ log.debug("total : " + contactStateStats.getTotal());
+ }
+ return (double)getNbContactStates() / (double)contactStateStats.getTotal();
+ }
+
+// void onSuccessFromFilterPeriodForContactStates() {
+// }
+
}
Modified: trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties
===================================================================
--- trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties 2010-02-10 15:43:48 UTC (rev 344)
+++ trunk/suiviobsmer-ui/src/main/resources/fr/ifremer/suiviobsmer/ui/pages/Synthesis.properties 2010-02-10 22:04:27 UTC (rev 345)
@@ -9,4 +9,7 @@
company-label: Soci\u00E9t\u00E9
programName-label: Programme
-companyForBoarding-label: Soci\u00E9t\u00E9
\ No newline at end of file
+companyForBoarding-label: Soci\u00E9t\u00E9
+
+periodBeginForContactStates-label: du
+periodEndForContactStates-label: au
\ No newline at end of file
Modified: trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml
===================================================================
--- trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml 2010-02-10 15:43:48 UTC (rev 344)
+++ trunk/suiviobsmer-ui/src/main/webapp/Synthesis.tml 2010-02-10 22:04:27 UTC (rev 345)
@@ -2,73 +2,40 @@
<t:layout t:pageTitle="Synthèse et indicateurs" t:contentId="so-synthesis"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
-<!-- <div class="clearfix" id="so-synthesis-indicators">
- <div class="indicator fleft">
- <p class="title">
- <span t:type="ck/Tooltip" title="Description" t:effect="appear"
- t:value="pourcentage de marées réalisés par rapport aux prévus dans le plan
- d'échantillonnage">
- Embarquements 2009
- </span>
- </p>
- <p class="number">85 %</p>
+ <!-- MENU : delegator -->
+ <div class="clearfix">
+ <div class="fleft" id="so-synthesis-menu">
+ <ul>
+ <li>
+ <a t:type="actionlink" t:context="[actionSynthesisId,'GRAPH_SAMPLING']" t:zone="so-synthesis-main">
+ <img src="${asset:context:}/img/synthesis-graph-sampling.png" alt="Diagramme en bâtons"
+ title="Graphique des données des marées (réalisé / planifié)" />
+ </a>
+ </li>
+ <li>
+ <a t:type="actionlink" t:context="[actionSynthesisId,'GRAPH_BOARDING']" t:zone="so-synthesis-main">
+ <img src="${asset:context:}/img/synthesis-graph-boarding.png" alt="Diagramme en bâtons"
+ title="Graphique des sollicitations des navires" />
+ </a>
+ </li>
+ <li>
+ <a t:type="actionlink" t:context="[actionSynthesisId,'IND_NON_COMPLIANCE_BOARDING']" t:zone="so-synthesis-main">
+ <img src="${asset:context:}/img/synthesis-ind-non-compliance-boarding.png" alt="Indicateur"
+ title="Indicateur de non respect du nombre d'observateurs embarqués" />
+ </a>
+ </li>
+ <li>
+ <a t:type="actionlink" t:context="[actionSynthesisId,'IND_CONTACT_STATE']" t:zone="so-synthesis-main">
+ <img src="${asset:context:}/img/synthesis-ind-contact-states.png" alt="Indicateur"
+ title="Indicateur sur les états des contacts" />
+ </a>
+ </li>
+ </ul>
</div>
- <div class="indicator fleft">
- <p class="title">
- <span t:type="ck/Tooltip" title="Description" t:effect="appear"
- t:value="nombre de contacts ayant aboutis en 2009">
- Contacts 2009
- </span>
- </p>
- <p class="number">120</p>
+ <div t:type="zone" t:id="delegator" class="fleft" t:update="show" id="so-synthesis-main">
+ <t:delegate t:to="activeBlock" />
</div>
- <div class="indicator fleft">
- <p class="title">
- <span t:type="ck/Tooltip" title="Description" t:effect="appear"
- t:value="navire le plus sollicité ce mois-ci">
- Top navire déc2009
- </span>
- </p>
- <p class="number">MAYFLOWERS (18)</p>
- </div>
-
- </div>-->
-<!-- <div class="graph">
- <img src="${asset:context:}/tmp/graph1.png" alt="graphe"/>
- <p class="description">Proin eu molestie dolor. Aliquam eget ultrices lorem. Phasellus molestie iaculis eleifend.
- Aenean vehicula elit eget felis vestibulum ut tempor est congue. Ut nulla felis,
- pulvinar at faucibus nec, lacinia in justo. Aliquam erat volutpat. Curabitur
- risus libero, tincidunt eget aliquam sit amet, auctor id libero. Proin in
- lectus nunc. Proin molestie molestie augue aliquet suscipit. Sed id enim diam,
- sed rutrum libero. </p>
- </div>-->
-<div class="clearfix">
- <div class="fleft" id="so-synthesis-menu">
- <ul>
- <li>
- <a t:type="actionlink" t:context="[actionSynthesisId,'GRAPH_SAMPLING']" t:zone="so-synthesis-main">
- <img src="${asset:context:}/img/synthesis-graph-sampling.png" alt="Diagramme en bâtons"
- title="Graphique des données des marées (réalisé / planifié)" />
- </a>
- </li>
- <li>
- <a t:type="actionlink" t:context="[actionSynthesisId,'GRAPH_BOARDING']" t:zone="so-synthesis-main">
- <img src="${asset:context:}/img/synthesis-graph-boarding.png" alt="Diagramme en bâtons"
- title="Graphique des sollicitations des navires" />
- </a>
- </li>
- <li>
- <a t:type="actionlink" t:context="[actionSynthesisId,'IND_NON_COMPLIANCE_BOARDING']" t:zone="so-synthesis-main">
- <img src="${asset:context:}/img/synthesis-ind-non-compliance-boarding.png" alt="Indicateur"
- title="Indicateur de non respect du nombre d'observateurs embarqués" />
- </a>
- </li>
- </ul>
</div>
- <div t:type="zone" t:id="delegator" class="fleft" t:update="show" id="so-synthesis-main">
- <t:delegate t:to="activeBlock" />
- </div>
-</div>
<!-- GRAPH1 : DATA_SAMPLING -->
<t:block t:id="graph1">
@@ -140,7 +107,7 @@
</div>
</t:block>
<!-- GRAPH2 : BOARDING_BOAT -->
- <t:block t:id="graph2">
+ <t:block t:id="graph2">
<div class="acenter">
<h2>Sollicitations des navires</h2>
<br />
@@ -165,22 +132,19 @@
</t:block>
<!-- IND1 : NON_COMPLIANCE_BOARDING -->
<t:block t:id="ind1">
- <div class="acenter" id="so-noncomplianceboarding">
+ <div class="ind-table acenter" id="so-noncomplianceboarding">
<h2>Non respect du nombre d'observateurs embarqués</h2>
<br />
- <p>
- Ce résultat concerne l'ensemble des contrats en cours
- <t:unless t:test="user.admin">
- pour votre société
- </t:unless>
- ayant des données réelles
- </p>
<t:if t:test="user.admin">
+ <p>
+ Ces résultats concernent l'ensemble des contrats en cours
+ ayant des données réelles.
+ </p>
<table class="t-data-grid">
<thead>
<tr>
- <td class="company">Société</td>
- <td>Indicateur</td>
+ <th class="company">Société</th>
+ <th>Indicateur</th>
</tr>
</thead>
<tbody>
@@ -193,13 +157,73 @@
</tbody>
</table>
<p:else>
+ <p>
+ Ce résultat concerne l'ensemble des contrats en cours
+ pour votre société ayant des données réelles.
+ </p>
<div class="indicator">
<p class="number">
- <t:output t:value="nonComplianceBoardingValue" t:format="percentFormat"/>
+ <span t:type="output" t:value="nonComplianceBoardingValue" t:format="percentFormat">
+ ${nonComplianceBoardingValue}
+ </span>
</p>
</div>
</p:else>
</t:if>
</div>
</t:block>
+ <!-- IND2 : CONTACT_STATE -->
+ <t:block t:id="ind2">
+ <div class="ind-table acenter" id="so-contactstate">
+ <h2>Etats des contacts</h2>
+ <br />
+ <p>
+ Ces résultats concernent l'ensemble des états des contacts<br /> excepté
+ ceux qui ont été refusés par le programme.
+ </p>
+ <br />
+ <p>
+ <form t:type="form" t:id="filterPeriodForContactStates">
+ <label>Période : </label>
+ <t:label t:for="periodBeginForContactStates" />
+ <input t:type="datefield" class="width70" t:id="periodBeginForContactStates" t:value="periodForContactStates.fromDate" t:format="MM/yyyy"/>
+ <t:label t:for="periodEndForContactStates" />
+ <input t:type="datefield" class="width70" t:id="periodEndForContactStates" t:value="periodForContactStates.thruDate" t:format="MM/yyyy" />
+ <input t:type="submit" class="ico search-32px" t:id="searchForContactStates" value="Search"
+ title="Rechercher les états des contacts sur cette période"/>
+ </form>
+ </p>
+ <table class="t-data-grid">
+ <thead>
+ <tr>
+ <t:if t:test="user.admin">
+ <th class="company">Société</th>
+ </t:if>
+ <th t:type="loop" t:source="contactStates" t:value="contactState">
+ ${contactState}
+ </th>
+ <th>Total</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr t:type="loop" t:source="contactStateStatistics" t:value="contactStateStats">
+ <t:if t:test="user.admin">
+ <td class="company">${contactStateStats.companyName}</td>
+ </t:if>
+ <td t:type="loop" t:source="contactStates" t:value="contactState"
+ class="number-contactstate">
+ <t:if t:test="nbContactStates">
+ ${nbContactStates}
+ (<span t:type="output" t:value="percentContactStates" t:format="percentFormat">${percentContactStates}</span>)
+ <p:else>
+ -
+ </p:else>
+ </t:if>
+ </td>
+ <td>${contactStateStats.total}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </t:block>
</t:layout>
Modified: trunk/suiviobsmer-ui/src/main/webapp/css/synthesis.css
===================================================================
--- trunk/suiviobsmer-ui/src/main/webapp/css/synthesis.css 2010-02-10 15:43:48 UTC (rev 344)
+++ trunk/suiviobsmer-ui/src/main/webapp/css/synthesis.css 2010-02-10 22:04:27 UTC (rev 345)
@@ -54,7 +54,7 @@
div#so-synthesis-menu {
border-right: 2px solid #133852;
padding-left: 15px;
- height: 400px;
+ height: 406px;
width: 10%;
}
@@ -82,6 +82,13 @@
font-weight: bold;
}
+.number-contactstate {
+ color: #007CC2;
+ text-align: center;
+ font-size: 1em;
+ font-weight: bold;
+}
+
div#so-datasampling fieldset {
width: 70%;
margin-left: auto;
@@ -106,23 +113,37 @@
border: 1px solid #133852;
}
-div#so-noncomplianceboarding table {
+div#so-synthesis div.ind-table table {
margin-top: 20px;
- width: 60%;
margin-left: auto;
margin-right: auto;
}
-div#so-noncomplianceboarding td {
- padding: 3px;
-}
-
-div#so-noncomplianceboarding table thead tr {
+div#so-synthesis div.ind-table table thead tr {
background-color: #19a28d;
font-weight: bold;
}
-div#so-noncomplianceboarding table td.company {
+/*div#so-synthesis div.ind-table table td {
+ padding: 3px;
+}*/
+
+div#so-synthesis div.ind-table table th.company,
+div#so-synthesis div.ind-table table td.company {
text-align: left;
}
+div#so-noncomplianceboarding table {
+ width: 50%;
+}
+
+div#so-contactstate table {
+ width: 90%;
+}
+
+div#so-contactstate table thead th {
+ width: 100px;
+ white-space: normal;
+ text-align: center;
+}
+
Added: trunk/suiviobsmer-ui/src/main/webapp/img/synthesis-ind-contact-states.png
===================================================================
(Binary files differ)
Property changes on: trunk/suiviobsmer-ui/src/main/webapp/img/synthesis-ind-contact-states.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
1
0
[Suiviobsmer-commits] r344 - trunk/suiviobsmer-ui/src/main/webapp/js
by fdesbois@users.labs.libre-entreprise.org 10 Feb '10
by fdesbois@users.labs.libre-entreprise.org 10 Feb '10
10 Feb '10
Author: fdesbois
Date: 2010-02-10 15:43:48 +0000 (Wed, 10 Feb 2010)
New Revision: 344
Modified:
trunk/suiviobsmer-ui/src/main/webapp/js/wao.js
Log:
Change order for testing change comment or not
Modified: trunk/suiviobsmer-ui/src/main/webapp/js/wao.js
===================================================================
--- trunk/suiviobsmer-ui/src/main/webapp/js/wao.js 2010-02-10 14:17:59 UTC (rev 343)
+++ trunk/suiviobsmer-ui/src/main/webapp/js/wao.js 2010-02-10 15:43:48 UTC (rev 344)
@@ -14,13 +14,13 @@
var oldValue = hidden.getValue();
var newValue = $F(commentPopupId);
var img = $(imgId);
- if (oldValue != newValue) {
+ if (!newValue || (unfinishedState && oldValue == newValue)) {
+ img.setAttribute('src', context + '/img/comment-invalid-22px.png');
+ img.setAttribute('title', 'Le commentaire est obligatoire pour un échec');
+ } else if (oldValue != newValue) {
img.setAttribute('src', context + '/img/comment-valid-22px.png');
img.setAttribute('title', 'Le commentaire a bien été ajouté');
- } else if (unfinishedState && oldValue == newValue) {
- img.setAttribute('src', context + '/img/comment-invalid-22px.png');
- img.setAttribute('title', 'Le commentaire est obligatoire pour un échec');
- }
+ }
hidden.setValue(newValue);
window.close();
}
\ No newline at end of file
1
0