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
June 2010
- 3 participants
- 97 discussions
[Suiviobsmer-commits] r584 - in trunk: wao-business/src/main/java/fr/ifremer/wao wao-business/src/main/java/fr/ifremer/wao/io/kml wao-business/src/main/java/fr/ifremer/wao/service wao-business/src/main/resources/i18n wao-business/src/main/xmi wao-business/src/test/java/fr/ifremer/wao wao-business/src/test/java/fr/ifremer/wao/service wao-ui/src/main/java/fr/ifremer/wao/ui/services
by fdesbois@users.labs.libre-entreprise.org 30 Jun '10
by fdesbois@users.labs.libre-entreprise.org 30 Jun '10
30 Jun '10
Author: fdesbois
Date: 2010-06-30 16:53:28 +0000 (Wed, 30 Jun 2010)
New Revision: 584
Log:
Evo #2352 : Cartography for contacts :
- Add ServiceChart
- Add method for export (not fully implemented)
- Add dependencies on ServiceChart and ServiceSynthesis to export Boat District Kml (managed in AppModule for Tapestry + Use WaoServiceFactory for tests)
- Add javadoc
Added:
trunk/wao-business/src/main/java/fr/ifremer/wao/WaoServiceFactory.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceChartEmpty.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/ServiceChartImpl.java
Modified:
trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContext.java
trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderFactory.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderJak.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderXpp3.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java
trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties
trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties
trunk/wao-business/src/main/xmi/wao.zargo
trunk/wao-business/src/test/java/fr/ifremer/wao/AbstractServiceTest.java
trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java
trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceCartographyImplTest.java
trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactInternalTest.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContext.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContext.java 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContext.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -134,9 +134,23 @@
*/
Date getCurrentDate();
+ /**
+ * Instantiate a new {@code WaoQueryBuilder} to construct queries (using filters).
+ *
+ * @return a new WaoQueryBuilder
+ */
WaoQueryBuilder newQueryBuilder();
/**
+ * Retrieve the WaoServiceFactory used to instantiate services.
+ *
+ * @return the WaoServiceFactory
+ * @see WaoServiceFactory
+ * @since 1.5
+ */
+ WaoServiceFactory getServiceFactory();
+
+ /**
* Retrieve the activityCalendarAccessLogger to manage logging for user
* which access to boat activity calendars. This method will create the
* correct appender if not already defined in the contet (1 file of 10MB
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -86,6 +86,8 @@
private org.apache.log4j.Logger activityCalendarAccessLogger;
+ private WaoServiceFactory serviceFactory;
+
@Override
public Date getCurrentDate() {
if (currentDate == null) {
@@ -99,6 +101,14 @@
return new WaoQueryBuilder();
}
+ @Override
+ public WaoServiceFactory getServiceFactory() {
+ if (serviceFactory == null) {
+ serviceFactory = new WaoServiceFactory(this);
+ }
+ return serviceFactory;
+ }
+
public void setCurrentDate(Date date) {
currentDate = date;
}
Added: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoServiceFactory.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoServiceFactory.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoServiceFactory.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -0,0 +1,140 @@
+package fr.ifremer.wao;
+
+import fr.ifremer.wao.service.ServiceBoat;
+import fr.ifremer.wao.service.ServiceBoatImpl;
+import fr.ifremer.wao.service.ServiceCartography;
+import fr.ifremer.wao.service.ServiceCartographyImpl;
+import fr.ifremer.wao.service.ServiceChart;
+import fr.ifremer.wao.service.ServiceChartEmpty;
+import fr.ifremer.wao.service.ServiceContact;
+import fr.ifremer.wao.service.ServiceContactImpl;
+import fr.ifremer.wao.service.ServiceNews;
+import fr.ifremer.wao.service.ServiceNewsImpl;
+import fr.ifremer.wao.service.ServiceReferential;
+import fr.ifremer.wao.service.ServiceReferentialImpl;
+import fr.ifremer.wao.service.ServiceSampling;
+import fr.ifremer.wao.service.ServiceSamplingImpl;
+import fr.ifremer.wao.service.ServiceSynthesis;
+import fr.ifremer.wao.service.ServiceSynthesisImpl;
+import fr.ifremer.wao.service.ServiceUser;
+import fr.ifremer.wao.service.ServiceUserImpl;
+
+/**
+ * Instantiate services and manage dependencies between them. The Factory need
+ * the WaoContext to work. Only one instance of each service will be kept when
+ * they are needed. This factory use the Lazy and IoC principles.
+ * <p />
+ * Created: 30 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ * @since 1.5
+ */
+public class WaoServiceFactory {
+
+ protected WaoContext context;
+
+ protected ServiceBoat serviceBoat;
+
+ protected ServiceReferential serviceReferential;
+
+ protected ServiceNews serviceNews;
+
+ protected ServiceSampling serviceSampling;
+
+ protected ServiceSynthesis serviceSynthesis;
+
+ protected ServiceUser serviceUser;
+
+ protected ServiceContact serviceContact;
+
+ protected ServiceCartography serviceCartography;
+
+ protected ServiceChart serviceChart;
+
+ protected WaoServiceFactory(WaoContext context) {
+ this.context = context;
+ }
+
+ public ServiceBoat getServiceBoat() {
+ if (serviceBoat == null) {
+ ServiceBoatImpl instance = new ServiceBoatImpl();
+ instance.setContext(context);
+ serviceBoat = instance;
+ }
+ return serviceBoat;
+ }
+
+ public ServiceReferential getServiceReferential() {
+ if (serviceReferential == null) {
+ ServiceReferentialImpl instance = new ServiceReferentialImpl();
+ instance.setContext(context);
+ serviceReferential = instance;
+ }
+ return serviceReferential;
+ }
+
+ public ServiceNews getServiceNews() {
+ if (serviceNews == null) {
+ ServiceNewsImpl instance = new ServiceNewsImpl();
+ instance.setContext(context);
+ serviceNews = instance;
+ }
+ return serviceNews;
+ }
+
+ public ServiceSampling getServiceSampling() {
+ if (serviceSampling == null) {
+ ServiceSamplingImpl instance = new ServiceSamplingImpl();
+ instance.setContext(context);
+ serviceSampling = instance;
+ }
+ return serviceSampling;
+ }
+
+ public ServiceSynthesis getServiceSynthesis() {
+ if (serviceSynthesis == null) {
+ ServiceSynthesisImpl instance = new ServiceSynthesisImpl();
+ instance.setContext(context);
+ serviceSynthesis = instance;
+ }
+ return serviceSynthesis;
+ }
+
+ public ServiceUser getServiceUser() {
+ if (serviceUser == null) {
+ ServiceUserImpl instance = new ServiceUserImpl();
+ instance.setContext(context);
+ serviceUser = instance;
+ }
+ return serviceUser;
+ }
+
+ public ServiceContact getServiceContact() {
+ if (serviceContact == null) {
+ ServiceContactImpl instance = new ServiceContactImpl();
+ instance.setContext(context);
+ serviceContact = instance;
+ }
+ return serviceContact;
+ }
+
+ public ServiceCartography getServiceCartography() {
+ if (serviceCartography == null) {
+ ServiceCartographyImpl instance = new ServiceCartographyImpl();
+ instance.setContext(context);
+ instance.setServiceChart(getServiceChart());
+ instance.setServiceSynthesis(getServiceSynthesis());
+ serviceCartography = instance;
+ }
+ return serviceCartography;
+ }
+
+ public ServiceChart getServiceChart() {
+ if (serviceChart == null) {
+ serviceChart = new ServiceChartEmpty();
+ }
+ return serviceChart;
+ }
+
+}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -6,12 +6,28 @@
import java.io.InputStream;
/**
- * Kml reader for BoatDistrict.
+ * Kml reader for BoatDistrict. Typical usage :
+ * <pre>
+ * BoatDistrictKmlReader reader = new ....();
+ * try {
+ * reader.init(inputStream);
+ * while (reader.hasNext()) {
+ * BoatDistrictData data = reader.readNext();
+ * // data treatment
+ * }
+ * } finally {
+ * reader.close();
+ * }
+ * </pre>
+ * Known implementations :
+ * {@link BoatDistrictKmlReaderJak} and {@link BoatDistrictKmlReaderXpp3}
* <p />
* Created: 30 juin 2010
*
* @author fdesbois <fdesbois at codelutin.com>
* @version $Id$
+ * @since 1.5
+ * @see BoatDistrictKmlReaderFactory
*/
public interface BoatDistrictKmlReader {
@@ -23,9 +39,24 @@
*/
void init(InputStream stream) throws IOException;
+ /**
+ * Test if there is next element to read.
+ *
+ * @return true if other element can be read
+ */
boolean hasNext();
+ /**
+ * Read the next BoatDistrictData element.
+ *
+ * @return the next BoatDistrictData
+ */
BoatDistrictData readNext();
+ /**
+ * Close the reader.
+ *
+ * @throws IOException for error on close
+ */
void close() throws IOException;
}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderFactory.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderFactory.java 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderFactory.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -4,6 +4,8 @@
import java.io.InputStream;
/**
+ * Factory for BoatDistrictKmlReader.
+ * <p />
* Created: 30 juin 2010
*
* @author fdesbois <fdesbois at codelutin.com>
@@ -11,6 +13,13 @@
*/
public class BoatDistrictKmlReaderFactory {
+ /**
+ * Create a new Reader using Jak.
+ *
+ * @param input InputStream for initialization
+ * @return a new instance of {@link BoatDistrictKmlReaderJak}
+ * @throws IOException for initilization errors
+ */
public static BoatDistrictKmlReader newReaderJak(InputStream input)
throws IOException {
BoatDistrictKmlReader reader = new BoatDistrictKmlReaderJak();
@@ -18,7 +27,13 @@
return reader;
}
-
+ /**
+ * Create a new Reader using Xpp3.
+ *
+ * @param input InputStream for initialization
+ * @return a new instance of {@link BoatDistrictKmlReaderXpp3}
+ * @throws IOException for initilization errors
+ */
public static BoatDistrictKmlReader newReaderXpp3(InputStream input)
throws IOException {
BoatDistrictKmlReader reader = new BoatDistrictKmlReaderXpp3();
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderJak.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderJak.java 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderJak.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -83,6 +83,7 @@
@Override
public void close() {
+ districts = null;
}
}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderXpp3.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderXpp3.java 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderXpp3.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -128,6 +128,8 @@
@Override
public void close() throws IOException {
- reader.close();
+ if (reader != null) {
+ reader.close();
+ }
}
}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -3,6 +3,8 @@
import fr.ifremer.wao.WaoContext;
import fr.ifremer.wao.WaoDAOHelper;
import fr.ifremer.wao.WaoException;
+import fr.ifremer.wao.bean.ContactStateStatistics;
+import fr.ifremer.wao.entity.Company;
import fr.ifremer.wao.io.BoatDistrictData;
import fr.ifremer.wao.io.kml.BoatDistrictKmlReader;
import fr.ifremer.wao.io.kml.BoatDistrictKmlReaderFactory;
@@ -17,6 +19,7 @@
import java.io.IOException;
import java.io.InputStream;
+import java.util.Collection;
/**
* Created: 29 juin 2010
@@ -32,10 +35,22 @@
private WaoContext context;
+ private ServiceChart serviceChart;
+
+ private ServiceSynthesis serviceSynthesis;
+
public void setContext(WaoContext context) {
this.context = context;
}
+ public void setServiceChart(ServiceChart serviceChart) {
+ this.serviceChart = serviceChart;
+ }
+
+ public void setServiceSynthesis(ServiceSynthesis serviceSynthesis) {
+ this.serviceSynthesis = serviceSynthesis;
+ }
+
@Override
protected TopiaContext beginTransaction() throws TopiaException {
return context.beginTransaction();
@@ -60,6 +75,7 @@
BoatDistrictDAO dao = WaoDAOHelper.getBoatDistrictDAO(transaction);
+ // Instantiate KmlReader for BoatDistrict
BoatDistrictKmlReader reader =
BoatDistrictKmlReaderFactory.newReaderJak(input);
@@ -76,6 +92,7 @@
" _ name = " + districtName);
}
+ // Only for no empty code
if (districtCode != null) {
BoatDistrict district = dao.findByCode(districtCode);
@@ -105,4 +122,16 @@
return results;
}
+
+ @Override
+ protected InputStream executeExportContactStatisticsKml(TopiaContext transaction,
+ Company company) {
+
+ Collection<ContactStateStatistics> data =
+ serviceSynthesis.getContactStateStatistics(company, null);
+
+ String chartUrl = serviceChart.getContactStatePieChartUrl(data);
+
+ return null;
+ }
}
Added: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceChartEmpty.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceChartEmpty.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceChartEmpty.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -0,0 +1,19 @@
+package fr.ifremer.wao.service;
+
+import fr.ifremer.wao.bean.ContactStateStatistics;
+
+import java.util.Collection;
+
+/**
+ * Created: 30 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ */
+public class ServiceChartEmpty implements ServiceChart {
+
+ @Override
+ public String getContactStatePieChartUrl(Collection<ContactStateStatistics> data) {
+ return "";
+ }
+}
Modified: trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties
===================================================================
--- trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties 2010-06-30 16:53:28 UTC (rev 584)
@@ -25,6 +25,7 @@
wao.error.serviceBoat.getShipOwnerNamesContains=
wao.error.serviceBoat.importActivityCalendarCsv=
wao.error.serviceBoat.importBoatCsv=
+wao.error.serviceCartography.exportContactStatisticsKml=
wao.error.serviceCartography.importBoatDistrictKml=
wao.error.serviceContact.exportContactCsv=
wao.error.serviceContact.getContacts=
Modified: trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties
===================================================================
--- trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-06-30 16:53:28 UTC (rev 584)
@@ -24,6 +24,7 @@
wao.error.serviceBoat.getShipOwnerNamesContains=
wao.error.serviceBoat.importActivityCalendarCsv=Probl\u00E8me d'import du fichier CSV des calendriers d'activit\u00E9
wao.error.serviceBoat.importBoatCsv=Probl\u00E8me d'import du fichier CSV. V\u00E9rifiez l'en-t\u00EAte du fichier \: [ NAVS_COD,CARN_NOM,CARN_LONGUEUR_HT,CARN_ANNEE,QUARTIER_IMMA,PER_COD,PER_NOM,PER_PRENOM,NAVS_ACTIVE ]. Voir documentation pour plus de d\u00E9tails.
+wao.error.serviceCartography.exportContactStatisticsKml=
wao.error.serviceCartography.importBoatDistrictKml=Impossible d'importer les coordonn\u00E9es des quartiers des navires. V\u00E9rifiez la documentation pour le bon format du fichier Kml.
wao.error.serviceContact.exportContactCsv=Impossible d'exporter les contacts
wao.error.serviceContact.getContacts=Impossible de filtrer la liste des contacts
Modified: trunk/wao-business/src/main/xmi/wao.zargo
===================================================================
(Binary files differ)
Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/AbstractServiceTest.java
===================================================================
--- trunk/wao-business/src/test/java/fr/ifremer/wao/AbstractServiceTest.java 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-business/src/test/java/fr/ifremer/wao/AbstractServiceTest.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -80,7 +80,7 @@
logger.debug("Start manager");
}
manager.start();
- serviceSampling = manager.getServiceSampling();
+ serviceSampling = (ServiceSamplingImpl)manager.getServiceSampling();
//initialize();
}
Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java
===================================================================
--- trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -27,7 +27,10 @@
import fr.ifremer.wao.service.ServiceBoat;
import fr.ifremer.wao.service.ServiceBoatImpl;
+import fr.ifremer.wao.service.ServiceCartography;
import fr.ifremer.wao.service.ServiceCartographyImpl;
+import fr.ifremer.wao.service.ServiceChart;
+import fr.ifremer.wao.service.ServiceChartEmpty;
import fr.ifremer.wao.service.ServiceContact;
import fr.ifremer.wao.service.ServiceContactImpl;
import fr.ifremer.wao.service.ServiceNews;
@@ -120,51 +123,39 @@
}
public ServiceBoat getServiceBoat() {
- ServiceBoatImpl instance = new ServiceBoatImpl();
- instance.setContext(getContext());
- return instance;
+ return context.getServiceFactory().getServiceBoat();
}
public ServiceReferential getServiceReferential() {
- ServiceReferentialImpl instance = new ServiceReferentialImpl();
- instance.setContext(getContext());
- return instance;
+ return context.getServiceFactory().getServiceReferential();
}
public ServiceNews getServiceNews() {
- ServiceNewsImpl instance = new ServiceNewsImpl();
- instance.setContext(getContext());
- return instance;
+ return context.getServiceFactory().getServiceNews();
}
- public ServiceSamplingImpl getServiceSampling() {
- ServiceSamplingImpl instance = new ServiceSamplingImpl();
- instance.setContext(getContext());
- return instance;
+ public ServiceSampling getServiceSampling() {
+ return context.getServiceFactory().getServiceSampling();
}
public ServiceSynthesis getServiceSynthesis() {
- ServiceSynthesisImpl instance = new ServiceSynthesisImpl();
- instance.setContext(getContext());
- return instance;
+ return context.getServiceFactory().getServiceSynthesis();
}
public ServiceUser getServiceUser() {
- ServiceUserImpl instance = new ServiceUserImpl();
- instance.setContext(getContext());
- return instance;
+ return context.getServiceFactory().getServiceUser();
}
- public ServiceContactImpl getServiceContact() {
- ServiceContactImpl instance = new ServiceContactImpl();
- instance.setContext(getContext());
- return instance;
+ public ServiceContact getServiceContact() {
+ return context.getServiceFactory().getServiceContact();
}
- public ServiceCartographyImpl getServiceCartography() {
- ServiceCartographyImpl instance = new ServiceCartographyImpl();
- instance.setContext(getContext());
- return instance;
+ public ServiceCartography getServiceCartography() {
+ return context.getServiceFactory().getServiceCartography();
}
+ public ServiceChart getServiceChart() {
+ return context.getServiceFactory().getServiceChart();
+ }
+
}
Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceCartographyImplTest.java
===================================================================
--- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceCartographyImplTest.java 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceCartographyImplTest.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -88,4 +88,12 @@
input = getClass().getResourceAsStream("/import/activity.csv");
ImportResults results = service.importBoatDistrictKml(input);
}
+
+ @Test
+ public void testExportContactStatisticsKml() {
+ /** PREPARE DATA **/
+
+ /** EXEC METHOD **/
+ service.exportContactStatisticsKml(null);
+ }
}
Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactInternalTest.java
===================================================================
--- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactInternalTest.java 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactInternalTest.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -103,7 +103,7 @@
public void setUp() throws Exception {
manager.start();
MockitoAnnotations.initMocks(this);
- service = manager.getServiceContact();
+ service = (ServiceContactImpl)manager.getServiceContact();
sampleMonth = null;
sampleRow = null;
boat = null;
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java 2010-06-30 15:34:55 UTC (rev 583)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -31,6 +31,7 @@
import fr.ifremer.wao.service.ServiceBoatImpl;
import fr.ifremer.wao.service.ServiceCartography;
import fr.ifremer.wao.service.ServiceCartographyImpl;
+import fr.ifremer.wao.service.ServiceChart;
import fr.ifremer.wao.service.ServiceContact;
import fr.ifremer.wao.service.ServiceContactImpl;
import fr.ifremer.wao.service.ServiceNews;
@@ -151,6 +152,11 @@
return instance;
}
+ public ServiceChart buildServiceChart() {
+ ServiceChartImpl instance = new ServiceChartImpl();
+ return instance;
+ }
+
public ServiceAuthentication buildServiceAuthentication(
ApplicationStateManager stateManager) {
ServiceAuthentication instance =
@@ -158,9 +164,13 @@
return instance;
}
- public ServiceCartography buildServiceCartography(WaoManager manager) {
+ public ServiceCartography buildServiceCartography(WaoManager manager,
+ ServiceChart serviceChart,
+ ServiceSynthesis serviceSynthesis) {
ServiceCartographyImpl instance = new ServiceCartographyImpl();
instance.setContext(manager.getContext());
+ instance.setServiceChart(serviceChart);
+ instance.setServiceSynthesis(serviceSynthesis);
return instance;
}
Added: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/ServiceChartImpl.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/ServiceChartImpl.java (rev 0)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/ServiceChartImpl.java 2010-06-30 16:53:28 UTC (rev 584)
@@ -0,0 +1,22 @@
+package fr.ifremer.wao.ui.services;
+
+import fr.ifremer.wao.bean.ContactStateStatistics;
+import fr.ifremer.wao.service.ServiceChart;
+
+import java.util.Collection;
+
+/**
+ * Created: 30 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ */
+public class ServiceChartImpl implements ServiceChart {
+
+ @Override
+ public String getContactStatePieChartUrl(Collection<ContactStateStatistics> data) {
+ // Create Url compatible for Google Chart API and Eastwood (JFreeChart)
+ return null;
+ }
+
+}
1
0
[Suiviobsmer-commits] r583 - in trunk: wao-business/src/main/java/fr/ifremer/wao/io/kml wao-business/src/main/resources/i18n wao-ui/src/main/java/fr/ifremer/wao/ui/components wao-ui/src/main/java/fr/ifremer/wao/ui/data wao-ui/src/main/java/fr/ifremer/wao/ui/pages wao-ui/src/main/java/fr/ifremer/wao/ui/services wao-ui/src/main/resources/fr/ifremer/wao/ui/components wao-ui/src/main/webapp
by fdesbois@users.labs.libre-entreprise.org 30 Jun '10
by fdesbois@users.labs.libre-entreprise.org 30 Jun '10
30 Jun '10
Author: fdesbois
Date: 2010-06-30 15:34:55 +0000 (Wed, 30 Jun 2010)
New Revision: 583
Log:
Evo #2352 : Cartography for contacts :
- Add import field for boatDistrict kml + rename Tapestry component and use format as parameter (KML or CSV)
Added:
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/ImportFieldSet.java
trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/ImportFieldSet.tml
Removed:
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java
trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/CsvImport.tml
Modified:
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java
trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java
trunk/wao-ui/src/main/webapp/Administration.tml
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java 2010-06-30 14:05:41 UTC (rev 582)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java 2010-06-30 15:34:55 UTC (rev 583)
@@ -6,6 +6,8 @@
import java.io.InputStream;
/**
+ * Kml reader for BoatDistrict.
+ * <p />
* Created: 30 juin 2010
*
* @author fdesbois <fdesbois at codelutin.com>
@@ -13,6 +15,12 @@
*/
public interface BoatDistrictKmlReader {
+ /**
+ * Initialize the Reader with {@code stream} as input data (kml file).
+ *
+ * @param stream Stream data from Kml file
+ * @throws IOException for error on initialization
+ */
void init(InputStream stream) throws IOException;
boolean hasNext();
Modified: trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties
===================================================================
--- trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-06-30 14:05:41 UTC (rev 582)
+++ trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-06-30 15:34:55 UTC (rev 583)
@@ -24,7 +24,7 @@
wao.error.serviceBoat.getShipOwnerNamesContains=
wao.error.serviceBoat.importActivityCalendarCsv=Probl\u00E8me d'import du fichier CSV des calendriers d'activit\u00E9
wao.error.serviceBoat.importBoatCsv=Probl\u00E8me d'import du fichier CSV. V\u00E9rifiez l'en-t\u00EAte du fichier \: [ NAVS_COD,CARN_NOM,CARN_LONGUEUR_HT,CARN_ANNEE,QUARTIER_IMMA,PER_COD,PER_NOM,PER_PRENOM,NAVS_ACTIVE ]. Voir documentation pour plus de d\u00E9tails.
-wao.error.serviceCartography.importBoatDistrictKml=
+wao.error.serviceCartography.importBoatDistrictKml=Impossible d'importer les coordonn\u00E9es des quartiers des navires. V\u00E9rifiez la documentation pour le bon format du fichier Kml.
wao.error.serviceContact.exportContactCsv=Impossible d'exporter les contacts
wao.error.serviceContact.getContacts=Impossible de filtrer la liste des contacts
wao.error.serviceContact.getNbContacts=Impossible de compter le nombre de contacts filtr\u00E9s
Deleted: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java 2010-06-30 14:05:41 UTC (rev 582)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java 2010-06-30 15:34:55 UTC (rev 583)
@@ -1,156 +0,0 @@
-/*
- * #%L
- * Wao :: Web Interface
- * %%
- * 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 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>.
- * #L%
- */
-package fr.ifremer.wao.ui.components;
-
-import fr.ifremer.wao.WaoBusinessException;
-import fr.ifremer.wao.WaoException;
-import fr.ifremer.wao.io.ImportResults;
-import fr.ifremer.wao.ui.data.ErrorReport;
-import fr.ifremer.wao.ui.data.ImportEngine;
-import fr.ifremer.wao.ui.services.WaoManager;
-import org.apache.tapestry5.BindingConstants;
-import org.apache.tapestry5.ComponentResources;
-import org.apache.tapestry5.annotations.Log;
-import org.apache.tapestry5.annotations.Parameter;
-import org.apache.tapestry5.annotations.Property;
-import org.apache.tapestry5.ioc.Messages;
-import org.apache.tapestry5.ioc.annotations.Inject;
-import org.apache.tapestry5.upload.services.UploadedFile;
-import org.slf4j.Logger;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-import java.util.zip.GZIPInputStream;
-
-/**
- * This component is used to import a {@code csvFile} using a form. The page
- * using this component must provide a {@link ImportEngine} to execute the
- * import when csv file is uploaded. An event "imported" will be triggered
- * after success. The page can use an "onImported(ErrorReport report)" method
- * to display errors and informations from import.
- *
- * Created: 18 juin 2010
- *
- * @author fdesbois <fdesbois at codelutin.com>
- * @version $Id$
- */
-public class CsvImport {
-
- /** Event triggered after form submission success */
- protected static final String EVENT_IMPORTED = "imported";
-
- protected static final String MIMETYPE_GZIP = "application/x-gzip";
-
- protected static final String MIMETYPE_CSV = "text/csv";
-
- /** Label to display on fieldset and in submit button title */
- @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
- @Property
- private String label;
-
- /** engine to execute the import */
- @Parameter(required = true)
- private ImportEngine engine;
-
- @Inject
- private WaoManager manager;
-
- @Inject
- private ComponentResources resources;
-
- @Inject
- private Messages messages;
-
- @Inject
- private Logger logger;
-
- @Property
- private UploadedFile csvFile;
-
- /**
- * ON_SUCCESS :: Callback method called when success event was triggered from
- * importCsv form submission. The import will be executed using the engine
- * in parameter. Errors will be reported in a {@link ErrorReport} object
- * to be managed after import success. An event "imported" will be triggered"
- * to manage those errors.
- */
- @Log
- void onSuccessFromImportCsv() {
- final ErrorReport errorReport = new ErrorReport();
-
- try {
- // Execute import using the engine
- ImportResults result = engine.execute(getStream());
-
- if (result != null) {
- // Add info on nbRows imported and refused
- errorReport.addInfo(result.getNbRowsImported() + " lignes importées dont " +
- result.getNbRowsImportedNew() + " nouvelles, " +
- result.getNbRowsRefused() + " refusées.");
-
- // Add import errors
- List<String> errors = result.getErrors();
- errorReport.addError(errors.toArray(new String[errors.size()]));
- }
-
- } catch (WaoBusinessException eee) {
-
- // Add fatal errors
- errorReport.addError(eee.getMessage());
- } catch (WaoException eee) {
-
- // Add unpredictable errors
- String[] errors =
- manager.getErrorMessages(eee, messages, logger);
- errorReport.addError(errors);
-
- } catch (IOException eee) {
- errorReport.addError("Erreur de format du fichier ! Seul les formats [csv, gz] sont autorisés.");
- logger.error("Error on import csv file", eee);
- }
-
- // Trigger event "imported" with ErroReport in argument
- resources.triggerEvent(EVENT_IMPORTED, new Object[] {errorReport}, null);
- }
-
- protected InputStream getStream() throws IOException {
- InputStream input = csvFile.getStream();
- String contentType = csvFile.getContentType();
-
- if (logger.isDebugEnabled()) {
- logger.debug("Content type : " + csvFile.getContentType());
- }
-
- if (contentType.equals(MIMETYPE_GZIP)) {
- if (logger.isDebugEnabled()) {
- logger.debug("Gzip file");
- }
- input = new GZIPInputStream(input);
-
- }
-// else if (!contentType.equals(MIMETYPE_CSV)) {
-// throw new IOException("unsupported format : " + contentType);
-// }
- return input;
- }
-}
Copied: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/ImportFieldSet.java (from rev 581, trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java)
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/ImportFieldSet.java (rev 0)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/ImportFieldSet.java 2010-06-30 15:34:55 UTC (rev 583)
@@ -0,0 +1,175 @@
+/*
+ * #%L
+ * Wao :: Web Interface
+ * %%
+ * 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 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>.
+ * #L%
+ */
+package fr.ifremer.wao.ui.components;
+
+import fr.ifremer.wao.WaoBusinessException;
+import fr.ifremer.wao.WaoException;
+import fr.ifremer.wao.io.ImportResults;
+import fr.ifremer.wao.ui.data.ErrorReport;
+import fr.ifremer.wao.ui.data.ImportEngine;
+import fr.ifremer.wao.ui.services.WaoManager;
+import org.apache.tapestry5.BindingConstants;
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.annotations.Log;
+import org.apache.tapestry5.annotations.Parameter;
+import org.apache.tapestry5.annotations.Property;
+import org.apache.tapestry5.ioc.Messages;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.upload.services.UploadedFile;
+import org.slf4j.Logger;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.zip.GZIPInputStream;
+
+/**
+ * This component is used to import a {@code csvFile} using a form. The page
+ * using this component must provide a {@link ImportEngine} to execute the
+ * import when csv file is uploaded. An event "imported" will be triggered
+ * after success. The page can use an "onImported(ErrorReport report)" method
+ * to display errors and informations from import.
+ *
+ * Created: 18 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ */
+public class ImportFieldSet {
+
+ /** Event triggered after form submission success */
+ protected static final String EVENT_IMPORTED = "imported";
+
+ protected static final String MIMETYPE_GZIP = "application/x-gzip";
+
+ protected static final String FORMAT_DEFAULT_VALUE = "CSV";
+
+// protected static final String MIMETYPE_CSV = "text/csv";
+
+ /** Label to display on fieldset and in submit button title */
+ @Parameter(required = true, defaultPrefix = BindingConstants.LITERAL)
+ @Property
+ private String label;
+
+ /** engine to execute the import */
+ @Parameter(required = true)
+ private ImportEngine engine;
+
+ @Parameter(value = FORMAT_DEFAULT_VALUE, defaultPrefix = BindingConstants.LITERAL)
+ @Property
+ private String format;
+
+ @Inject
+ private WaoManager manager;
+
+ @Inject
+ private ComponentResources resources;
+
+ @Inject
+ private Messages messages;
+
+ @Inject
+ private Logger logger;
+
+ @Property
+ private UploadedFile file;
+
+ /**
+ * ON_SUCCESS :: Callback method called when success event was triggered from
+ * importForm form submission. The import will be executed using the engine
+ * in parameter. Errors will be reported in a {@link ErrorReport} object
+ * to be managed after import success. An event "imported" will be triggered"
+ * to manage those errors.
+ */
+ @Log
+ void onSuccessFromImportForm() {
+ final ErrorReport errorReport = new ErrorReport();
+
+ try {
+ // Execute import using the engine
+ ImportResults result = engine.execute(getStream());
+
+ if (result != null) {
+ // Add info on nbRows imported and refused
+
+ StringBuilder info = new StringBuilder().
+ append(result.getNbRowsImported()).
+ append(" lignes importées");
+
+ if (result.getNbRowsImportedNew() > 0) {
+ info.append(" dont ").
+ append(result.getNbRowsImportedNew()).
+ append(" nouvelles");
+ }
+
+ info.append(", ").
+ append(result.getNbRowsRefused()).
+ append(" refusées.");
+
+ errorReport.addInfo(info.toString());
+
+ // Add import errors
+ List<String> errors = result.getErrors();
+ errorReport.addError(errors.toArray(new String[errors.size()]));
+ }
+
+ } catch (WaoBusinessException eee) {
+
+ // Add fatal errors
+ errorReport.addError(eee.getMessage());
+ } catch (WaoException eee) {
+
+ // Add unpredictable errors
+ String[] errors =
+ manager.getErrorMessages(eee, messages, logger);
+ errorReport.addError(errors);
+
+ } catch (IOException eee) {
+ errorReport.addError("Erreur de format du fichier ! Seul les formats [csv, gz, kml] sont autorisés.");
+ logger.error("Error on import file", eee);
+ }
+
+ // Trigger event "imported" with ErroReport in argument
+ resources.triggerEvent(EVENT_IMPORTED, new Object[] {errorReport}, null);
+ }
+
+ protected InputStream getStream() throws IOException {
+ InputStream input = file.getStream();
+ String contentType = file.getContentType();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Content type : " + file.getContentType());
+ }
+
+ if (contentType.equals(MIMETYPE_GZIP)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Gzip file");
+ }
+ input = new GZIPInputStream(input);
+
+ }
+// else if (!contentType.equals(MIMETYPE_CSV)) {
+// throw new IOException("unsupported format : " + contentType);
+// }
+ return input;
+ }
+}
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java 2010-06-30 14:05:41 UTC (rev 582)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java 2010-06-30 15:34:55 UTC (rev 583)
@@ -24,15 +24,12 @@
import fr.ifremer.wao.WaoBusinessException;
import fr.ifremer.wao.WaoException;
import fr.ifremer.wao.io.ImportResults;
-import fr.ifremer.wao.ui.components.CsvImport;
-import fr.ifremer.wao.ui.components.Layout;
+import fr.ifremer.wao.ui.components.ImportFieldSet;
import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
/**
- * This interface is used for {@link CsvImport} component to execute an import.
+ * This interface is used for {@link ImportFieldSet} component to execute an import.
* The page need to implement the {@link #execute(InputStream)} method to use
* the component.
*
@@ -45,7 +42,7 @@
/**
* Excute an import from an {@code input} stream. This method was called
- * in {@link CsvImport} when file are successfully uploaded. This method
+ * in {@link ImportFieldSet} when file are successfully uploaded. This method
* to to return an {@link ImportResults} that contains stats and errors
* from import.
*
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-06-30 14:05:41 UTC (rev 582)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-06-30 15:34:55 UTC (rev 583)
@@ -37,6 +37,7 @@
import fr.ifremer.wao.entity.CompanyImpl;
import fr.ifremer.wao.entity.WaoUser;
import fr.ifremer.wao.service.ServiceBoat;
+import fr.ifremer.wao.service.ServiceCartography;
import fr.ifremer.wao.service.ServiceReferential;
import fr.ifremer.wao.service.ServiceSampling;
import fr.ifremer.wao.service.ServiceUser;
@@ -98,7 +99,7 @@
@Inject
private Logger logger;
-
+
@Inject
private WaoManager manager;
@@ -109,6 +110,9 @@
private ServiceReferential serviceReferential;
@Inject
+ private ServiceCartography serviceCartography;
+
+ @Inject
private TypeCoercer typeCoercer;
@Inject
@@ -262,6 +266,17 @@
return manager.isActivityCalendarImportRun();
}
+ public ImportEngine getBoatDistrictImportEngine() {
+ return new ImportEngine() {
+
+ @Override
+ public ImportResults execute(InputStream input)
+ throws WaoException, WaoBusinessException {
+ return serviceCartography.importBoatDistrictKml(input);
+ }
+ };
+ }
+
@Log
void onImported(ErrorReport report) {
for (String info : report.getInfos()) {
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java 2010-06-30 14:05:41 UTC (rev 582)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/services/AppModule.java 2010-06-30 15:34:55 UTC (rev 583)
@@ -29,6 +29,8 @@
import fr.ifremer.wao.bean.ConnectedUser;
import fr.ifremer.wao.service.ServiceBoat;
import fr.ifremer.wao.service.ServiceBoatImpl;
+import fr.ifremer.wao.service.ServiceCartography;
+import fr.ifremer.wao.service.ServiceCartographyImpl;
import fr.ifremer.wao.service.ServiceContact;
import fr.ifremer.wao.service.ServiceContactImpl;
import fr.ifremer.wao.service.ServiceNews;
@@ -156,6 +158,12 @@
return instance;
}
+ public ServiceCartography buildServiceCartography(WaoManager manager) {
+ ServiceCartographyImpl instance = new ServiceCartographyImpl();
+ instance.setContext(manager.getContext());
+ return instance;
+ }
+
public static void contributeApplicationDefaults(
MappedConfiguration<String, String> configuration) {
// Contributions to ApplicationDefaults will override any contributions to
Deleted: trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/CsvImport.tml
===================================================================
--- trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/CsvImport.tml 2010-06-30 14:05:41 UTC (rev 582)
+++ trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/CsvImport.tml 2010-06-30 15:34:55 UTC (rev 583)
@@ -1,38 +0,0 @@
-<!--
- #%L
- Wao :: Web Interface
- %%
- 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 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>.
- #L%
- -->
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
-
- <div class="so-import">
- <form t:type="form" t:id="importCsv" action="post">
- <fieldset>
- <legend>Import ${label}</legend>
- <t:errors />
- <label for="csvFile">Fichier CSV ${label}</label> :
- <input t:type="upload" t:id="csvFile" t:validate="required" />
- <input t:type="submit" class="ico import" value="OK" title="Import ${label} (format CSV avec encodage UTF-8)" />
- <t:body />
- </fieldset>
- </form>
- </div>
-
-</html>
\ No newline at end of file
Copied: trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/ImportFieldSet.tml (from rev 573, trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/CsvImport.tml)
===================================================================
--- trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/ImportFieldSet.tml (rev 0)
+++ trunk/wao-ui/src/main/resources/fr/ifremer/wao/ui/components/ImportFieldSet.tml 2010-06-30 15:34:55 UTC (rev 583)
@@ -0,0 +1,38 @@
+<!--
+ #%L
+ Wao :: Web Interface
+ %%
+ 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 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>.
+ #L%
+ -->
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
+
+ <div class="so-import">
+ <form t:type="form" t:id="importForm" action="post">
+ <fieldset>
+ <legend>Import ${label}</legend>
+ <t:errors />
+ <label for="file">Fichier ${format} ${label}</label> :
+ <input t:type="upload" t:id="file" t:validate="required" />
+ <input t:type="submit" class="ico import" value="OK" title="Import ${label} (format ${format} avec encodage UTF-8)" />
+ <t:body />
+ </fieldset>
+ </form>
+ </div>
+
+</html>
\ No newline at end of file
Modified: trunk/wao-ui/src/main/webapp/Administration.tml
===================================================================
--- trunk/wao-ui/src/main/webapp/Administration.tml 2010-06-30 14:05:41 UTC (rev 582)
+++ trunk/wao-ui/src/main/webapp/Administration.tml 2010-06-30 15:34:55 UTC (rev 583)
@@ -32,18 +32,18 @@
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
<t:if t:test="currentUser.admin">
- <t:csvImport t:label="des zones de pêche" t:engine="fishingZoneImportEngine" />
+ <t:importFieldSet t:label="des zones de pêche" t:engine="fishingZoneImportEngine" />
- <t:csvImport t:label="du plan d'échantillonnage" t:engine="samplingPlanImportEngine" />
+ <t:importFieldSet t:label="du plan d'échantillonnage" t:engine="samplingPlanImportEngine" />
- <t:csvImport t:label="des navires" t:engine="boatImportEngine" />
+ <t:importFieldSet t:label="des navires" t:engine="boatImportEngine" />
<t:unless t:test="activityCalendarImportRun">
<div class="clearfix">
- <t:csvImport t:label="des calendriers d'activité" t:engine="activityCalendarImportEngine">
+ <t:importFieldSet t:label="des calendriers d'activité" t:engine="activityCalendarImportEngine">
<t:logFile t:source="activityCalendarAccessLogFile" t:title="des accès utilisateurs aux calendriers d'activité" t:icon="context:img/text-access-32px.png" />
<t:logFile t:source="activityCalendarLogFile" t:title="de l'import des calendriers d'activité" t:icon="context:img/text-32px.png" />
- </t:csvImport>
+ </t:importFieldSet>
</div>
<p:else>
<div class="fb-info">
@@ -52,6 +52,8 @@
</div>
</p:else>
</t:unless>
+
+ <t:importFieldSet t:label="des coordonnées des quartiers des navires" t:engine="boatDistrictImportEngine" t:format="KML" />
</t:if>
<t:if t:test="currentUser.admin">
1
0
[Suiviobsmer-commits] r582 - in trunk: . wao-business wao-business/src/main/java/fr/ifremer/wao/io/kml wao-business/src/main/java/fr/ifremer/wao/service
by fdesbois@users.labs.libre-entreprise.org 30 Jun '10
by fdesbois@users.labs.libre-entreprise.org 30 Jun '10
30 Jun '10
Author: fdesbois
Date: 2010-06-30 14:05:41 +0000 (Wed, 30 Jun 2010)
New Revision: 582
Log:
Evo #2352 : Cartography for contacts :
- Add KmlReader using Xpp3 (doesn't work yet) + Factory
Added:
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderFactory.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderXpp3.java
Modified:
trunk/pom.xml
trunk/wao-business/pom.xml
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderJak.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictSchemaData.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-30 10:54:53 UTC (rev 581)
+++ trunk/pom.xml 2010-06-30 14:05:41 UTC (rev 582)
@@ -62,7 +62,7 @@
<artifactId>nuiton-tapestry-extra</artifactId>
<version>${nuitonweb.version}</version>
</dependency>
- <!-- ToPIA -->
+ <!-- ToPIA -->
<dependency>
<groupId>org.nuiton.topia</groupId>
<artifactId>topia-persistence</artifactId>
@@ -146,6 +146,11 @@
<artifactId>xpp3</artifactId>
<version>1.1.4c</version>
</dependency>
+ <dependency>
+ <groupId>xpp3</groupId>
+ <artifactId>xpp3_xpath</artifactId>
+ <version>1.1.4c</version>
+ </dependency>
<!-- Csv import/export -->
<dependency>
<groupId>net.sourceforge.javacsv</groupId>
Modified: trunk/wao-business/pom.xml
===================================================================
--- trunk/wao-business/pom.xml 2010-06-30 10:54:53 UTC (rev 581)
+++ trunk/wao-business/pom.xml 2010-06-30 14:05:41 UTC (rev 582)
@@ -62,6 +62,10 @@
<groupId>xpp3</groupId>
<artifactId>xpp3</artifactId>
</dependency>
+ <dependency>
+ <groupId>xpp3</groupId>
+ <artifactId>xpp3_xpath</artifactId>
+ </dependency>
<!-- ToPIA -->
<dependency>
<groupId>org.nuiton.topia</groupId>
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java 2010-06-30 10:54:53 UTC (rev 581)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java 2010-06-30 14:05:41 UTC (rev 582)
@@ -19,5 +19,5 @@
BoatDistrictData readNext();
- void close();
+ void close() throws IOException;
}
Added: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderFactory.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderFactory.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderFactory.java 2010-06-30 14:05:41 UTC (rev 582)
@@ -0,0 +1,29 @@
+package fr.ifremer.wao.io.kml;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Created: 30 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ */
+public class BoatDistrictKmlReaderFactory {
+
+ public static BoatDistrictKmlReader newReaderJak(InputStream input)
+ throws IOException {
+ BoatDistrictKmlReader reader = new BoatDistrictKmlReaderJak();
+ reader.init(input);
+ return reader;
+ }
+
+
+ public static BoatDistrictKmlReader newReaderXpp3(InputStream input)
+ throws IOException {
+ BoatDistrictKmlReader reader = new BoatDistrictKmlReaderXpp3();
+ reader.init(input);
+ return reader;
+ }
+
+}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderJak.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderJak.java 2010-06-30 10:54:53 UTC (rev 581)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderJak.java 2010-06-30 14:05:41 UTC (rev 582)
@@ -65,28 +65,10 @@
for (SimpleData data : schemaData.getSimpleData()) {
- BoatDistrictSchemaData type =
+ BoatDistrictSchemaData districtSchemaData =
BoatDistrictSchemaData.valueOfLabel(data.getName());
- String value = data.getValue();
- switch (type) {
- case NAME:
- district.setName(value); break;
- case DESCRIPTION:
- district.setDescription(value); break;
- case OBJECTID:
- district.setObjectid(value); break;
- case LIEU_COD:
- district.setLieuCod(value); break;
- case LIEU_LIB:
- district.setLieuLib(value); break;
- case TLIEU_COD:
- district.setTlieuCod(value); break;
- case L_OCEAN:
- district.setLOcean(value); break;
- case L_PAYS:
- district.setLPays(value);
- }
+ districtSchemaData.setPropertyValue(district, data.getValue());
}
// Retrieve coordinate
Added: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderXpp3.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderXpp3.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderXpp3.java 2010-06-30 14:05:41 UTC (rev 582)
@@ -0,0 +1,133 @@
+package fr.ifremer.wao.io.kml;
+
+import fr.ifremer.wao.io.BoatDistrictData;
+import fr.ifremer.wao.io.BoatDistrictDataImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xmlpull.v1.builder.XmlCharacters;
+import org.xmlpull.v1.builder.XmlDocument;
+import org.xmlpull.v1.builder.XmlElement;
+import org.xmlpull.v1.builder.XmlInfosetBuilder;
+import org.xmlpull.v1.builder.xpath.Xb1XPath;
+import org.xmlpull.v1.builder.xpath.jaxen.XPath;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Created: 30 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ */
+public class BoatDistrictKmlReaderXpp3 implements BoatDistrictKmlReader {
+
+ private static final Logger logger = LoggerFactory.getLogger(BoatDistrictKmlReaderXpp3.class);
+
+ private static final String PATH_PLACEMARK = "/kml/Document/Folder/Placemark";
+
+ private static final String PATH_SIMPLE_DATA = "ExtendedData/SchemaData/SimpleData";
+
+ private static final String PATH_COORDINATES = "Point/coordinates";
+
+ private static final String ATTRIBUTE_SCHEMA_DATA_NAME = "name";
+
+ Iterator<XmlElement> iterator;
+
+ InputStreamReader reader;
+
+ @Override
+ public void init(InputStream stream) throws IOException {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Read stream Kml");
+ }
+
+ reader = new InputStreamReader(stream);
+
+ XPath xpath = new Xb1XPath(PATH_PLACEMARK);
+
+ XmlInfosetBuilder builder = XmlInfosetBuilder.newInstance();
+
+ XmlDocument doc = builder.parseReader(reader);
+
+ if (logger.isDebugEnabled()) {
+ Iterator it = doc.children().iterator();
+ while (it.hasNext()) {
+ logger.debug("onInit :: element : " + ((XmlElement)it.next()).getName());
+ }
+ }
+
+ List results = xpath.selectNodes(doc);
+
+ if (logger.isDebugEnabled()) {
+ for (Object element : results) {
+ logger.debug("onInit :: element : " + ((XmlElement)element).getName());
+ }
+ }
+
+ iterator = results.iterator();
+ }
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public BoatDistrictData readNext() {
+
+ BoatDistrictData district = new BoatDistrictDataImpl();
+
+ XmlElement element = iterator.next();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("element : " + element.getName());
+ }
+
+ readSchemaData(element, district);
+
+ readCoordinates(element, district);
+
+ return district;
+ }
+
+ protected void readSchemaData(XmlElement element, BoatDistrictData district) {
+ XPath xpath = new Xb1XPath(PATH_SIMPLE_DATA);
+ List<XmlElement> results = xpath.selectNodes(element);
+ for (XmlElement data : results) {
+
+ String dataLabel = data.getAttributeValue(null, ATTRIBUTE_SCHEMA_DATA_NAME);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("data : " + data.getName() + " _ label = " + dataLabel);
+ }
+
+ BoatDistrictSchemaData schemaData =
+ BoatDistrictSchemaData.valueOfLabel(dataLabel);
+
+ XmlCharacters chars = (XmlCharacters) data.children().next();
+
+ schemaData.setPropertyValue(district, chars.getText());
+ }
+ }
+
+ protected void readCoordinates(XmlElement element, BoatDistrictData district) {
+ XPath xpath = new Xb1XPath(PATH_COORDINATES);
+ XmlElement coordinatesElement = (XmlElement) xpath.selectSingleNode(element);
+ XmlCharacters chars = (XmlCharacters) coordinatesElement.children().next();
+ String[] coordinates = chars.getText().split(",");
+
+ district.setLongitude(Double.valueOf(coordinates[0]));
+ district.setLatitude(Double.valueOf(coordinates[1]));
+ }
+
+ @Override
+ public void close() throws IOException {
+ reader.close();
+ }
+}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictSchemaData.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictSchemaData.java 2010-06-30 10:54:53 UTC (rev 581)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictSchemaData.java 2010-06-30 14:05:41 UTC (rev 582)
@@ -1,5 +1,7 @@
package fr.ifremer.wao.io.kml;
+import fr.ifremer.wao.io.BoatDistrictData;
+
/**
* Created: 29 juin 2010
*
@@ -40,4 +42,26 @@
return null;
}
+ public void setPropertyValue(BoatDistrictData data,
+ String value) {
+ switch (this) {
+ case NAME:
+ data.setName(value); break;
+ case DESCRIPTION:
+ data.setDescription(value); break;
+ case OBJECTID:
+ data.setObjectid(value); break;
+ case LIEU_COD:
+ data.setLieuCod(value); break;
+ case LIEU_LIB:
+ data.setLieuLib(value); break;
+ case TLIEU_COD:
+ data.setTlieuCod(value); break;
+ case L_OCEAN:
+ data.setLOcean(value); break;
+ case L_PAYS:
+ data.setLPays(value);
+ }
+ }
+
}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java 2010-06-30 10:54:53 UTC (rev 581)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java 2010-06-30 14:05:41 UTC (rev 582)
@@ -1,20 +1,11 @@
package fr.ifremer.wao.service;
-import de.micromata.opengis.kml.v_2_2_0.Coordinate;
-import de.micromata.opengis.kml.v_2_2_0.Document;
-import de.micromata.opengis.kml.v_2_2_0.Folder;
-import de.micromata.opengis.kml.v_2_2_0.Kml;
-import de.micromata.opengis.kml.v_2_2_0.Placemark;
-import de.micromata.opengis.kml.v_2_2_0.Point;
-import de.micromata.opengis.kml.v_2_2_0.SchemaData;
-import de.micromata.opengis.kml.v_2_2_0.SimpleData;
import fr.ifremer.wao.WaoContext;
import fr.ifremer.wao.WaoDAOHelper;
import fr.ifremer.wao.WaoException;
import fr.ifremer.wao.io.BoatDistrictData;
import fr.ifremer.wao.io.kml.BoatDistrictKmlReader;
-import fr.ifremer.wao.io.kml.BoatDistrictKmlReaderJak;
-import fr.ifremer.wao.io.kml.BoatDistrictSchemaData;
+import fr.ifremer.wao.io.kml.BoatDistrictKmlReaderFactory;
import fr.ifremer.wao.io.ImportResults;
import fr.ifremer.wao.io.ImportResultsImpl;
import fr.ifremer.wao.entity.BoatDistrict;
@@ -69,8 +60,8 @@
BoatDistrictDAO dao = WaoDAOHelper.getBoatDistrictDAO(transaction);
- BoatDistrictKmlReader reader = new BoatDistrictKmlReaderJak();
- reader.init(input);
+ BoatDistrictKmlReader reader =
+ BoatDistrictKmlReaderFactory.newReaderJak(input);
int i = 0;
while (reader.hasNext()) {
@@ -112,66 +103,6 @@
reader.close();
transaction.commitTransaction();
-// Kml kml = Kml.unmarshal(input);
-//
-// Document document = (Document) kml.getFeature();
-// Folder folder = (Folder) document.getFeature().get(0);
-//
-// int size = folder.getFeature().size();
-// for (int i = 0; i < size; i++) {
-// Placemark placemark = (Placemark) folder.getFeature().get(i);
-//
-// SchemaData schemaData = placemark.getExtendedData().getSchemaData().get(0);
-//
-// String districtName = null, districtCode = null;
-//
-// for (SimpleData data : schemaData.getSimpleData()) {
-//
-// BoatDistrictSchemaData type =
-// BoatDistrictSchemaData.valueOfLabel(data.getName());
-//
-// switch (type) {
-// case DESCRIPTION:
-// districtName = data.getValue();
-// break;
-// case OBJECTID:
-// districtCode = data.getValue();
-// }
-// }
-//
-// if (logger.isDebugEnabled()) {
-// logger.debug("District : code = " + districtCode +
-// " _ name = " + districtName);
-// }
-//
-// if (districtCode != null) {
-//
-// BoatDistrict district = dao.findByCode(districtCode);
-//
-// if (district != null) {
-//
-// // Retrieve coordinate
-// Point point = (Point) placemark.getGeometry();
-// Coordinate coordinate = point.getCoordinates().get(0);
-//
-// // Update data
-// district.setLatitude(coordinate.getLatitude());
-// district.setLongitude(coordinate.getLongitude());
-// district.setName(districtName);
-//
-// dao.update(district);
-//
-// results.incNbImported();
-// } else {
-// // Reject
-// results.incNbRefused();
-// results.addError(i, "Code quartier inconnu : " + districtCode);
-// }
-// }
-// }
-//
-// transaction.commitTransaction();
-
return results;
}
}
1
0
30 Jun '10
Author: fdesbois
Date: 2010-06-30 10:54:53 +0000 (Wed, 30 Jun 2010)
New Revision: 581
Log:
Evo #2352 : Cartography for contacts :
- Reorganize io package
- Add ServiceCartography + BoatDistrictKmlReader (implementation using Jak api)
Added:
trunk/wao-business/src/main/java/fr/ifremer/wao/io/ImportResultsImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/
trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/ExportHelper.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/ImportHelper.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/SamplingExport.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/WaoCsvHeader.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderJak.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictSchemaData.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java
trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceCartographyImplTest.java
trunk/wao-business/src/test/resources/import/boat_districts.kml
Removed:
trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ImportResultsImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/ExportHelper.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/ImportHelper.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/SamplingExport.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/WaoCsvHeader.java
Modified:
trunk/pom.xml
trunk/wao-business/pom.xml
trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/io/ImportRefusedException.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ActivityCalendarImport.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java
trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties
trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties
trunk/wao-business/src/main/xmi/wao.zargo
trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java
trunk/wao-business/src/test/java/fr/ifremer/wao/io/ImportHelperTest.java
trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactInternalTest.java
trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java
trunk/wao-business/src/test/resources/log4j.properties
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java
trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/pom.xml 2010-06-30 10:54:53 UTC (rev 581)
@@ -113,18 +113,6 @@
<scope>test</scope>
</dependency>-->
<dependency>
- <groupId>com.formos.tapestry</groupId>
- <artifactId>tapestry-testify</artifactId>
- <version>1.0.2</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>1.8.4</version>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
@@ -141,12 +129,25 @@
<version>1.5.10</version>
<scope>runtime</scope>
</dependency>
+ <!-- Graphics -->
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.12</version>
- </dependency>
+ </dependency>
+ <!-- KML for Cartography -->
<dependency>
+ <groupId>de.micromata.jak</groupId>
+ <artifactId>JavaAPIforKml</artifactId>
+ <version>2.2.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>xpp3</groupId>
+ <artifactId>xpp3</artifactId>
+ <version>1.1.4c</version>
+ </dependency>
+ <!-- Csv import/export -->
+ <dependency>
<groupId>net.sourceforge.javacsv</groupId>
<artifactId>javacsv</artifactId>
<version>2.0</version>
@@ -174,6 +175,18 @@
<version>4.8.1</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>com.formos.tapestry</groupId>
+ <artifactId>tapestry-testify</artifactId>
+ <version>1.0.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.8.4</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</dependencyManagement>
Modified: trunk/wao-business/pom.xml
===================================================================
--- trunk/wao-business/pom.xml 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/pom.xml 2010-06-30 10:54:53 UTC (rev 581)
@@ -53,8 +53,17 @@
<groupId>net.sourceforge.javacsv</groupId>
<artifactId>javacsv</artifactId>
</dependency>
- <!-- ToPIA -->
+ <!-- KML lib -->
<dependency>
+ <groupId>de.micromata.jak</groupId>
+ <artifactId>JavaAPIforKml</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>xpp3</groupId>
+ <artifactId>xpp3</artifactId>
+ </dependency>
+ <!-- ToPIA -->
+ <dependency>
<groupId>org.nuiton.topia</groupId>
<artifactId>topia-persistence</artifactId>
</dependency>
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoContextImpl.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -26,7 +26,7 @@
package fr.ifremer.wao;
import fr.ifremer.wao.entity.ActivityCalendar;
-import fr.ifremer.wao.io.ImportHelper;
+import fr.ifremer.wao.io.csv.ImportHelper;
import fr.ifremer.wao.service.ServiceUser;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
Deleted: trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ImportResultsImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ImportResultsImpl.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ImportResultsImpl.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -1,64 +0,0 @@
-/*
- * #%L
- * Wao :: Business
- *
- * $Id$
- * $HeadURL$
- * %%
- * 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 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>.
- * #L%
- */
-
-package fr.ifremer.wao.bean;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * ImportResultsImpl
- *
- * Created: 11 janv. 2010
- *
- * @author fdesbois <fdesbois at codelutin.com>
- */
-public class ImportResultsImpl extends ImportResults {
-
- @Override
- public void addError(int rowNum, String msg) {
- String str = "Ligne " + rowNum + " : " + msg;
- getErrors().add(str);
- }
-
- @Override
- public List<String> getErrors() {
- if (errors == null) {
- errors = new ArrayList<String>();
- }
- return errors;
- }
-
- @Override
- public void incNbRefused() {
- nbRowsRefused++;
- }
-
- @Override
- public void incNbImported() {
- nbRowsImported++;
- }
-
-}
Deleted: trunk/wao-business/src/main/java/fr/ifremer/wao/io/ExportHelper.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/ExportHelper.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/ExportHelper.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -1,168 +0,0 @@
-/*
- * #%L
- * Wao :: Business
- *
- * $Id$
- * $HeadURL$
- * %%
- * 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 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>.
- * #L%
- */
-
-package fr.ifremer.wao.io;
-
-import com.csvreader.CsvWriter;
-import fr.ifremer.wao.io.WaoCsvHeader.IOHeader;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-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 <fdesbois at codelutin.com>
- */
-public abstract class ExportHelper<H extends IOHeader> {
-
- private static final Logger logger = LoggerFactory.getLogger(ExportHelper.class);
-
- /** 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 IOHeader} 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 IOHeader} 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++) {
- // Always use "" for headers
-// String header = null;
-//
-// if (i == 0) {
-// header = new StringBuilder("\"").
-// append(getHeaderValue(i)).
-// append("\"").
-// toString();
-// } else {
-// header = getHeaderValue(i);
-// }
-//
-// if (logger.isDebugEnabled()) {
-// logger.debug("Header " + i + " : " + getHeaderValue(i));
-// logger.debug("Header " + i + " with StringBuilder : " + header);
-// }
-
- 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();
- }
-}
Deleted: trunk/wao-business/src/main/java/fr/ifremer/wao/io/ImportHelper.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/ImportHelper.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/ImportHelper.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -1,320 +0,0 @@
-/*
- * #%L
- * Wao :: Business
- *
- * $Id$
- * $HeadURL$
- * %%
- * 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 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>.
- * #L%
- */
-
-package fr.ifremer.wao.io;
-
-import fr.ifremer.wao.*;
-import com.csvreader.CsvReader;
-import fr.ifremer.wao.io.WaoCsvHeader.ACTIVITY_CALENDAR;
-import fr.ifremer.wao.io.WaoCsvHeader.CONTACT;
-import fr.ifremer.wao.io.WaoCsvHeader.DatedHeader;
-import fr.ifremer.wao.io.WaoCsvHeader.IOHeader;
-import fr.ifremer.wao.io.WaoCsvHeader.SAMPLING;
-import java.io.IOException;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.List;
-import java.util.Locale;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.time.DurationFormatUtils;
-import org.nuiton.util.PeriodDates;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * ImportHelper
- *
- * Created: 4 janv. 2010
- *
- * @author fdesbois <fdesbois at codelutin.com>
- */
-public class ImportHelper {
-
- private static final Logger logger =
- LoggerFactory.getLogger(ImportHelper.class);
-
- protected CsvReader reader;
-
- protected static WaoContext context;
-
- // 2000 -> 2099
- public static final int CURRENT_MILLENIUM = 2000;
-
- public static final String DEFAULT_PATTERN = "dd/MM/yyyy";
- public static final String MONTH_PATTERN = "MM/yyyy";
-
- public ImportHelper(CsvReader reader) {
- this.reader = reader;
- }
-
- public static void setContext(WaoContext context) {
- ImportHelper.context = context;
- }
-
- 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, Date createDate) throws ParseException {
- Calendar time = new GregorianCalendar(Locale.FRENCH);
- if (StringUtils.isNotEmpty(code)) {
- time = new GregorianCalendar(Locale.FRENCH);
- time.setTime(CONTACT.TIME_FORMAT.parse(code));
- } else {
- // Use current date with no time as a reference if no code is set
- time.setTime(context.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 (createDate != null) {
- result.setTime(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(context.getCurrentDate());
- }
- return result.getTime();
- }
-
- public static String readSampleRowCode(CsvReader reader) throws IOException {
- String code = read(reader, SAMPLING.PLAN_CODE);
- return context.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 #readDate(CsvReader, DatedHeader)
- */
- 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)
- * @see ImportHelper#parseDate(String, String)
- */
- public static Date readDate(CsvReader reader, DatedHeader header)
- throws IOException, ParseException {
-
- String str = read(reader, header);
- if (logger.isTraceEnabled()) {
- logger.trace("Read date " + header.name() + " : " + str);
- }
- return parseDate(str, header.datePattern());
- }
-
- /**
- * Parse a date from a Csv file. Depends on pattern wanted. The default
- * pattern from OpenOffice or Excel is considered for parsing (JJ/MM/AA).
- *
- * @param value of the reading date
- * @param pattern for parsing
- * @return the parsed date
- * @throws ParseException
- */
- public static Date parseDate(String value, String pattern)
- throws ParseException {
-
- if (StringUtils.isEmpty(value)) {
- return null;
- }
-
- DateFormat dateFormat = null;
- Date result = null;
- Calendar calendar = Calendar.getInstance();
-
- // Case of MONTH_PATTERN : MM/yyyy
- if (pattern.equals(MONTH_PATTERN)) {
- dateFormat = new SimpleDateFormat(DEFAULT_PATTERN);
- try {
- // Try to parse with default_pattern (ok for default OpenOffice
- // or Excel date format)
- result = dateFormat.parse(value);
- calendar.setTime(result);
- // In this case, we must suppress the day from the date
- // Put it to 1
- calendar.set(Calendar.DAY_OF_MONTH, 1);
- } catch (ParseException eee) {
- // If the date can't be parse, it must be ok with header pattern
- logger.debug("Date parse error : " + eee.getMessage());
- dateFormat = new SimpleDateFormat(pattern);
- result = dateFormat.parse(value);
- calendar.setTime(result);
- }
- } else {
- dateFormat = new SimpleDateFormat(pattern);
- result = dateFormat.parse(value);
- calendar.setTime(result);
- }
-
- // Check if the year is correct
- int year = calendar.get(Calendar.YEAR);
- if (logger.isTraceEnabled()) {
- logger.trace("Read date year : " + year);
- }
- // If year < to the current millenium, the year is incorrect, must
- // add the millenium to the year
- // It's because of century problem : /10 must be /2010
- if (year < CURRENT_MILLENIUM) {
- calendar.add(Calendar.YEAR, CURRENT_MILLENIUM);
- }
- return calendar.getTime();
- }
-
- 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();
- }
-
- /**
- * This method is used to check if {@code reader} contains at least the
- * {@code keyHeader} in headers. Otherwise an exception will be thrown.
- *
- * @param reader CsvReader to check (headers need to be read before)
- * @param keyHeader Header to check
- * @throws WaoBusinessException if keyHeader is not found
- */
- public static void checkKeyHeader(CsvReader reader, IOHeader keyHeader)
- throws WaoBusinessException {
-
- try {
- List<String> headers = Arrays.asList(reader.getHeaders());
-
- if (!headers.contains(keyHeader.name())) {
- throw new WaoBusinessException(
- WaoBusinessException.Type.IMPORT_ERROR, null,
- "Fichier non reconnu, aucune colonne ne correspond à '" +
- keyHeader.name() + "'.");
- }
-
- } catch (IOException eee) {
- throw new WaoException("Une erreur est survenue à la lecture de" +
- " l'en-tête du fichier CSV. Veuillez vérifier votre fichier.", eee);
- }
- }
-
-}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/io/ImportRefusedException.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/ImportRefusedException.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/ImportRefusedException.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -25,7 +25,7 @@
/**
* ImportRefusedException is used to advise import service that an error occurs
* during loading data. Generally this exception is catched and messages will
- * be encapsulated in {@link fr.ifremer.wao.bean.ImportResults}.
+ * be encapsulated in {@link ImportResults}.
*
* Created: 15 avr. 2010
*
Copied: trunk/wao-business/src/main/java/fr/ifremer/wao/io/ImportResultsImpl.java (from rev 573, trunk/wao-business/src/main/java/fr/ifremer/wao/bean/ImportResultsImpl.java)
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/ImportResultsImpl.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/ImportResultsImpl.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -0,0 +1,64 @@
+/*
+ * #%L
+ * Wao :: Business
+ *
+ * $Id$
+ * $HeadURL$
+ * %%
+ * 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 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>.
+ * #L%
+ */
+
+package fr.ifremer.wao.io;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * ImportResultsImpl
+ *
+ * Created: 11 janv. 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ */
+public class ImportResultsImpl extends ImportResults {
+
+ @Override
+ public void addError(int rowNum, String msg) {
+ String str = "Ligne " + rowNum + " : " + msg;
+ getErrors().add(str);
+ }
+
+ @Override
+ public List<String> getErrors() {
+ if (errors == null) {
+ errors = new ArrayList<String>();
+ }
+ return errors;
+ }
+
+ @Override
+ public void incNbRefused() {
+ nbRowsRefused++;
+ }
+
+ @Override
+ public void incNbImported() {
+ nbRowsImported++;
+ }
+
+}
Property changes on: trunk/wao-business/src/main/java/fr/ifremer/wao/io/ImportResultsImpl.java
___________________________________________________________________
Added: svn:keywords
+ Author Date Id Revision HeadURL
Deleted: trunk/wao-business/src/main/java/fr/ifremer/wao/io/SamplingExport.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/SamplingExport.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/SamplingExport.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -1,125 +0,0 @@
-/*
- * #%L
- * Wao :: Business
- *
- * $Id$
- * $HeadURL$
- * %%
- * 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 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>.
- * #L%
- */
-
-package fr.ifremer.wao.io;
-
-import com.csvreader.CsvWriter;
-import fr.ifremer.wao.bean.ConnectedUser;
-import fr.ifremer.wao.entity.SampleMonth;
-import fr.ifremer.wao.entity.SampleRow;
-import fr.ifremer.wao.entity.WaoUser;
-import fr.ifremer.wao.io.WaoCsvHeader.SAMPLING;
-import fr.ifremer.wao.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 <fdesbois at codelutin.com>
- */
-public class SamplingExport extends ExportHelper<SamplingHeader> {
-
- private static final Logger log = LoggerFactory.getLogger(SamplingExport.class);
-
- protected ConnectedUser 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, ConnectedUser 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.isAdmin() ? 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)
- // Evo #2227 : Guest users have only access to expected values
- if (user.isAdmin() || user.isGuest()) {
- record(index, expected);
- // Other users have both expected and real values
- } else {
- record(index, expected + " (" + real + ")");
- }
- }
- }
- }
-
-}
Deleted: trunk/wao-business/src/main/java/fr/ifremer/wao/io/WaoCsvHeader.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/WaoCsvHeader.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/WaoCsvHeader.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -1,473 +0,0 @@
-/*
- * #%L
- * Wao :: Business
- *
- * $Id$
- * $HeadURL$
- * %%
- * 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 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>.
- * #L%
- */
-
-package fr.ifremer.wao.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 <fdesbois at codelutin.com>
- */
-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() {
- return getLastHeaderBeforeMonths().forSamplingCsv() + 1;
- }
-
- public static int getTotalHeaders() {
- // PLAN_COMMENT is the last column
- return PLAN_COMMENT.forSamplingCsv() + 1;
- }
-
- public static SAMPLING getLastHeaderBeforeMonths() {
- // PROGRAMME_FIN is the last column before months
- return PROGRAMME_FIN;
- }
- }
-
- /**
- * 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;
-
- public static final DateFormat DATE_FORMAT =
- new SimpleDateFormat(defaultDatePattern(), Locale.FRENCH);
-
- public static final DateFormat TIME_FORMAT =
- new SimpleDateFormat("HHmmssS", Locale.FRENCH);
-
- 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 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;
- }
-}
Added: trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/ExportHelper.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/ExportHelper.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/ExportHelper.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -0,0 +1,168 @@
+/*
+ * #%L
+ * Wao :: Business
+ *
+ * $Id: ExportHelper.java 492 2010-06-07 18:36:10Z fdesbois $
+ * $HeadURL: svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk/wao-business/src/main/j… $
+ * %%
+ * 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 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>.
+ * #L%
+ */
+
+package fr.ifremer.wao.io.csv;
+
+import com.csvreader.CsvWriter;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.IOHeader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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 <fdesbois at codelutin.com>
+ */
+public abstract class ExportHelper<H extends IOHeader> {
+
+ private static final Logger logger = LoggerFactory.getLogger(ExportHelper.class);
+
+ /** 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 IOHeader} 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 IOHeader} 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++) {
+ // Always use "" for headers
+// String header = null;
+//
+// if (i == 0) {
+// header = new StringBuilder("\"").
+// append(getHeaderValue(i)).
+// append("\"").
+// toString();
+// } else {
+// header = getHeaderValue(i);
+// }
+//
+// if (logger.isDebugEnabled()) {
+// logger.debug("Header " + i + " : " + getHeaderValue(i));
+// logger.debug("Header " + i + " with StringBuilder : " + header);
+// }
+
+ 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();
+ }
+}
Added: trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/ImportHelper.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/ImportHelper.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/ImportHelper.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -0,0 +1,320 @@
+/*
+ * #%L
+ * Wao :: Business
+ *
+ * $Id: ImportHelper.java 570 2010-06-28 14:29:55Z fdesbois $
+ * $HeadURL: svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk/wao-business/src/main/j… $
+ * %%
+ * 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 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>.
+ * #L%
+ */
+
+package fr.ifremer.wao.io.csv;
+
+import fr.ifremer.wao.*;
+import com.csvreader.CsvReader;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.ACTIVITY_CALENDAR;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.CONTACT;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.DatedHeader;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.IOHeader;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.SAMPLING;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+import java.util.Locale;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.time.DurationFormatUtils;
+import org.nuiton.util.PeriodDates;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * ImportHelper
+ *
+ * Created: 4 janv. 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ */
+public class ImportHelper {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(ImportHelper.class);
+
+ protected CsvReader reader;
+
+ protected static WaoContext context;
+
+ // 2000 -> 2099
+ public static final int CURRENT_MILLENIUM = 2000;
+
+ public static final String DEFAULT_PATTERN = "dd/MM/yyyy";
+ public static final String MONTH_PATTERN = "MM/yyyy";
+
+ public ImportHelper(CsvReader reader) {
+ this.reader = reader;
+ }
+
+ public static void setContext(WaoContext context) {
+ ImportHelper.context = context;
+ }
+
+ 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, Date createDate) throws ParseException {
+ Calendar time = new GregorianCalendar(Locale.FRENCH);
+ if (StringUtils.isNotEmpty(code)) {
+ time = new GregorianCalendar(Locale.FRENCH);
+ time.setTime(CONTACT.TIME_FORMAT.parse(code));
+ } else {
+ // Use current date with no time as a reference if no code is set
+ time.setTime(context.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 (createDate != null) {
+ result.setTime(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(context.getCurrentDate());
+ }
+ return result.getTime();
+ }
+
+ public static String readSampleRowCode(CsvReader reader) throws IOException {
+ String code = read(reader, SAMPLING.PLAN_CODE);
+ return context.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 #readDate(CsvReader, DatedHeader)
+ */
+ 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)
+ * @see ImportHelper#parseDate(String, String)
+ */
+ public static Date readDate(CsvReader reader, DatedHeader header)
+ throws IOException, ParseException {
+
+ String str = read(reader, header);
+ if (logger.isTraceEnabled()) {
+ logger.trace("Read date " + header.name() + " : " + str);
+ }
+ return parseDate(str, header.datePattern());
+ }
+
+ /**
+ * Parse a date from a Csv file. Depends on pattern wanted. The default
+ * pattern from OpenOffice or Excel is considered for parsing (JJ/MM/AA).
+ *
+ * @param value of the reading date
+ * @param pattern for parsing
+ * @return the parsed date
+ * @throws ParseException
+ */
+ public static Date parseDate(String value, String pattern)
+ throws ParseException {
+
+ if (StringUtils.isEmpty(value)) {
+ return null;
+ }
+
+ DateFormat dateFormat = null;
+ Date result = null;
+ Calendar calendar = Calendar.getInstance();
+
+ // Case of MONTH_PATTERN : MM/yyyy
+ if (pattern.equals(MONTH_PATTERN)) {
+ dateFormat = new SimpleDateFormat(DEFAULT_PATTERN);
+ try {
+ // Try to parse with default_pattern (ok for default OpenOffice
+ // or Excel date format)
+ result = dateFormat.parse(value);
+ calendar.setTime(result);
+ // In this case, we must suppress the day from the date
+ // Put it to 1
+ calendar.set(Calendar.DAY_OF_MONTH, 1);
+ } catch (ParseException eee) {
+ // If the date can't be parse, it must be ok with header pattern
+ logger.debug("Date parse error : " + eee.getMessage());
+ dateFormat = new SimpleDateFormat(pattern);
+ result = dateFormat.parse(value);
+ calendar.setTime(result);
+ }
+ } else {
+ dateFormat = new SimpleDateFormat(pattern);
+ result = dateFormat.parse(value);
+ calendar.setTime(result);
+ }
+
+ // Check if the year is correct
+ int year = calendar.get(Calendar.YEAR);
+ if (logger.isTraceEnabled()) {
+ logger.trace("Read date year : " + year);
+ }
+ // If year < to the current millenium, the year is incorrect, must
+ // add the millenium to the year
+ // It's because of century problem : /10 must be /2010
+ if (year < CURRENT_MILLENIUM) {
+ calendar.add(Calendar.YEAR, CURRENT_MILLENIUM);
+ }
+ return calendar.getTime();
+ }
+
+ 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();
+ }
+
+ /**
+ * This method is used to check if {@code reader} contains at least the
+ * {@code keyHeader} in headers. Otherwise an exception will be thrown.
+ *
+ * @param reader CsvReader to check (headers need to be read before)
+ * @param keyHeader Header to check
+ * @throws WaoBusinessException if keyHeader is not found
+ */
+ public static void checkKeyHeader(CsvReader reader, IOHeader keyHeader)
+ throws WaoBusinessException {
+
+ try {
+ List<String> headers = Arrays.asList(reader.getHeaders());
+
+ if (!headers.contains(keyHeader.name())) {
+ throw new WaoBusinessException(
+ WaoBusinessException.Type.IMPORT_ERROR, null,
+ "Fichier non reconnu, aucune colonne ne correspond à '" +
+ keyHeader.name() + "'.");
+ }
+
+ } catch (IOException eee) {
+ throw new WaoException("Une erreur est survenue à la lecture de" +
+ " l'en-tête du fichier CSV. Veuillez vérifier votre fichier.", eee);
+ }
+ }
+
+}
Added: trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/SamplingExport.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/SamplingExport.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/SamplingExport.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -0,0 +1,124 @@
+/*
+ * #%L
+ * Wao :: Business
+ *
+ * $Id: SamplingExport.java 507 2010-06-11 14:51:13Z fdesbois $
+ * $HeadURL: svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk/wao-business/src/main/j… $
+ * %%
+ * 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 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>.
+ * #L%
+ */
+
+package fr.ifremer.wao.io.csv;
+
+import com.csvreader.CsvWriter;
+import fr.ifremer.wao.bean.ConnectedUser;
+import fr.ifremer.wao.entity.SampleMonth;
+import fr.ifremer.wao.entity.SampleRow;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.SAMPLING;
+import fr.ifremer.wao.io.csv.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 <fdesbois at codelutin.com>
+ */
+public class SamplingExport extends ExportHelper<SamplingHeader> {
+
+ private static final Logger log = LoggerFactory.getLogger(SamplingExport.class);
+
+ protected ConnectedUser 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, ConnectedUser 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.isAdmin() ? 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)
+ // Evo #2227 : Guest users have only access to expected values
+ if (user.isAdmin() || user.isGuest()) {
+ record(index, expected);
+ // Other users have both expected and real values
+ } else {
+ record(index, expected + " (" + real + ")");
+ }
+ }
+ }
+ }
+
+}
Added: trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/WaoCsvHeader.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/WaoCsvHeader.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/csv/WaoCsvHeader.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -0,0 +1,473 @@
+/*
+ * #%L
+ * Wao :: Business
+ *
+ * $Id: WaoCsvHeader.java 462 2010-04-19 23:41:59Z tchemit $
+ * $HeadURL: svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk/wao-business/src/main/j… $
+ * %%
+ * 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 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>.
+ * #L%
+ */
+
+package fr.ifremer.wao.io.csv;
+
+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 <fdesbois at codelutin.com>
+ */
+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() {
+ return getLastHeaderBeforeMonths().forSamplingCsv() + 1;
+ }
+
+ public static int getTotalHeaders() {
+ // PLAN_COMMENT is the last column
+ return PLAN_COMMENT.forSamplingCsv() + 1;
+ }
+
+ public static SAMPLING getLastHeaderBeforeMonths() {
+ // PROGRAMME_FIN is the last column before months
+ return PROGRAMME_FIN;
+ }
+ }
+
+ /**
+ * 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;
+
+ public static final DateFormat DATE_FORMAT =
+ new SimpleDateFormat(defaultDatePattern(), Locale.FRENCH);
+
+ public static final DateFormat TIME_FORMAT =
+ new SimpleDateFormat("HHmmssS", Locale.FRENCH);
+
+ 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 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;
+ }
+}
Added: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReader.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -0,0 +1,23 @@
+package fr.ifremer.wao.io.kml;
+
+import fr.ifremer.wao.io.BoatDistrictData;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Created: 30 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ */
+public interface BoatDistrictKmlReader {
+
+ void init(InputStream stream) throws IOException;
+
+ boolean hasNext();
+
+ BoatDistrictData readNext();
+
+ void close();
+}
Added: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderJak.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderJak.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictKmlReaderJak.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -0,0 +1,106 @@
+package fr.ifremer.wao.io.kml;
+
+import de.micromata.opengis.kml.v_2_2_0.Coordinate;
+import de.micromata.opengis.kml.v_2_2_0.Document;
+import de.micromata.opengis.kml.v_2_2_0.Folder;
+import de.micromata.opengis.kml.v_2_2_0.Kml;
+import de.micromata.opengis.kml.v_2_2_0.Placemark;
+import de.micromata.opengis.kml.v_2_2_0.Point;
+import de.micromata.opengis.kml.v_2_2_0.SchemaData;
+import de.micromata.opengis.kml.v_2_2_0.SimpleData;
+import fr.ifremer.wao.entity.BoatDistrict;
+import fr.ifremer.wao.io.BoatDistrictData;
+import fr.ifremer.wao.io.BoatDistrictDataImpl;
+import org.apache.commons.lang.StringUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Created: 30 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ */
+public class BoatDistrictKmlReaderJak implements BoatDistrictKmlReader {
+
+ List<Placemark> districts;
+
+ Iterator<Placemark> iterator;
+
+ @Override
+ public void init(InputStream stream) throws IOException {
+ Kml kml = Kml.unmarshal(stream);
+
+ Document document = (Document) kml.getFeature();
+ Folder folder = (Folder) document.getFeature().get(0);
+
+ districts = new ArrayList<Placemark>();
+
+ int size = folder.getFeature().size();
+ for (int i = 0; i < size; i++) {
+ Placemark placemark = (Placemark) folder.getFeature().get(i);
+ districts.add(placemark);
+ }
+
+ iterator = districts.iterator();
+ }
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public BoatDistrictData readNext() {
+
+ Placemark placemark = iterator.next();
+
+ BoatDistrictData district = new BoatDistrictDataImpl();
+
+ SchemaData schemaData = placemark.getExtendedData().getSchemaData().get(0);
+
+ for (SimpleData data : schemaData.getSimpleData()) {
+
+ BoatDistrictSchemaData type =
+ BoatDistrictSchemaData.valueOfLabel(data.getName());
+
+ String value = data.getValue();
+ switch (type) {
+ case NAME:
+ district.setName(value); break;
+ case DESCRIPTION:
+ district.setDescription(value); break;
+ case OBJECTID:
+ district.setObjectid(value); break;
+ case LIEU_COD:
+ district.setLieuCod(value); break;
+ case LIEU_LIB:
+ district.setLieuLib(value); break;
+ case TLIEU_COD:
+ district.setTlieuCod(value); break;
+ case L_OCEAN:
+ district.setLOcean(value); break;
+ case L_PAYS:
+ district.setLPays(value);
+ }
+ }
+
+ // Retrieve coordinate
+ Point point = (Point) placemark.getGeometry();
+ Coordinate coordinate = point.getCoordinates().get(0);
+
+ district.setLongitude(coordinate.getLongitude());
+ district.setLatitude(coordinate.getLatitude());
+
+ return district;
+ }
+
+ @Override
+ public void close() {
+ }
+
+}
Added: trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictSchemaData.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictSchemaData.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/io/kml/BoatDistrictSchemaData.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -0,0 +1,43 @@
+package fr.ifremer.wao.io.kml;
+
+/**
+ * Created: 29 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ * @since 1.5
+ */
+public enum BoatDistrictSchemaData {
+
+ NAME("Name"),
+ DESCRIPTION("Description"),
+ OBJECTID(null),
+ LIEU_LIB(null),
+ LIEU_COD(null),
+ TLIEU_COD(null),
+ L_OCEAN(null),
+ L_PAYS(null);
+
+ String label;
+
+ BoatDistrictSchemaData(String label) {
+ this.label = label;
+ }
+
+ public String getLabel() {
+ if (label != null) {
+ return label;
+ }
+ return name();
+ }
+
+ public static BoatDistrictSchemaData valueOfLabel(String label) {
+ for (BoatDistrictSchemaData curr : values()) {
+ if (curr.getLabel().equals(label)) {
+ return curr;
+ }
+ }
+ return null;
+ }
+
+}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ActivityCalendarImport.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ActivityCalendarImport.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ActivityCalendarImport.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -37,9 +37,9 @@
import fr.ifremer.wao.entity.ActivityZoneDAO;
import fr.ifremer.wao.entity.Boat;
import fr.ifremer.wao.entity.BoatDAO;
-import fr.ifremer.wao.io.ImportHelper;
-import fr.ifremer.wao.io.WaoCsvHeader.ACTIVITY_CALENDAR;
-import fr.ifremer.wao.io.WaoCsvHeader.BOAT;
+import fr.ifremer.wao.io.csv.ImportHelper;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.ACTIVITY_CALENDAR;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.BOAT;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -30,6 +30,7 @@
import fr.ifremer.wao.*;
import fr.ifremer.wao.WaoBusinessException.Type;
import fr.ifremer.wao.bean.ConnectedUser;
+import fr.ifremer.wao.io.csv.ImportHelper;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.framework.TopiaQuery.Op;
@@ -37,10 +38,9 @@
import fr.ifremer.wao.bean.CompanyBoatInfos;
import fr.ifremer.wao.bean.CompanyBoatInfosImpl;
import fr.ifremer.wao.entity.*;
-import fr.ifremer.wao.io.ImportHelper;
-import fr.ifremer.wao.io.ExportHelper;
-import fr.ifremer.wao.io.WaoCsvHeader;
-import fr.ifremer.wao.io.WaoCsvHeader.BOAT;
+import fr.ifremer.wao.io.csv.ExportHelper;
+import fr.ifremer.wao.io.csv.WaoCsvHeader;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.BOAT;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Added: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java (rev 0)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceCartographyImpl.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -0,0 +1,177 @@
+package fr.ifremer.wao.service;
+
+import de.micromata.opengis.kml.v_2_2_0.Coordinate;
+import de.micromata.opengis.kml.v_2_2_0.Document;
+import de.micromata.opengis.kml.v_2_2_0.Folder;
+import de.micromata.opengis.kml.v_2_2_0.Kml;
+import de.micromata.opengis.kml.v_2_2_0.Placemark;
+import de.micromata.opengis.kml.v_2_2_0.Point;
+import de.micromata.opengis.kml.v_2_2_0.SchemaData;
+import de.micromata.opengis.kml.v_2_2_0.SimpleData;
+import fr.ifremer.wao.WaoContext;
+import fr.ifremer.wao.WaoDAOHelper;
+import fr.ifremer.wao.WaoException;
+import fr.ifremer.wao.io.BoatDistrictData;
+import fr.ifremer.wao.io.kml.BoatDistrictKmlReader;
+import fr.ifremer.wao.io.kml.BoatDistrictKmlReaderJak;
+import fr.ifremer.wao.io.kml.BoatDistrictSchemaData;
+import fr.ifremer.wao.io.ImportResults;
+import fr.ifremer.wao.io.ImportResultsImpl;
+import fr.ifremer.wao.entity.BoatDistrict;
+import fr.ifremer.wao.entity.BoatDistrictDAO;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Created: 29 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ * @since 1.5
+ */
+public class ServiceCartographyImpl extends ServiceCartographyAbstract {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(ServiceCartographyImpl.class);
+
+ private WaoContext context;
+
+ public void setContext(WaoContext context) {
+ this.context = context;
+ }
+
+ @Override
+ protected TopiaContext beginTransaction() throws TopiaException {
+ return context.beginTransaction();
+ }
+
+ @Override
+ protected void treateError(TopiaContext transaction, Exception eee,
+ String message, Object... args) throws WaoException {
+ context.treateError(transaction, eee, message, args);
+ }
+
+ @Override
+ protected void closeTransaction(TopiaContext transaction) {
+ context.closeTransaction(transaction);
+ }
+
+ @Override
+ protected ImportResults executeImportBoatDistrictKml(TopiaContext transaction, InputStream input)
+ throws TopiaException, IOException {
+
+ ImportResults results = new ImportResultsImpl();
+
+ BoatDistrictDAO dao = WaoDAOHelper.getBoatDistrictDAO(transaction);
+
+ BoatDistrictKmlReader reader = new BoatDistrictKmlReaderJak();
+ reader.init(input);
+
+ int i = 0;
+ while (reader.hasNext()) {
+
+ BoatDistrictData data = reader.readNext();
+
+ String districtName = data.getDescription();
+ String districtCode = data.getObjectid();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("District : code = " + districtCode +
+ " _ name = " + districtName);
+ }
+
+ if (districtCode != null) {
+
+ BoatDistrict district = dao.findByCode(districtCode);
+
+ if (district != null) {
+
+ // Update data
+ district.setLatitude(data.getLatitude());
+ district.setLongitude(data.getLongitude());
+ district.setName(districtName);
+
+ dao.update(district);
+
+ results.incNbImported();
+ } else {
+ // Reject
+ results.incNbRefused();
+ results.addError(i, "Code quartier inconnu : " + districtCode);
+ }
+ }
+
+ i++;
+ }
+
+ reader.close();
+ transaction.commitTransaction();
+
+// Kml kml = Kml.unmarshal(input);
+//
+// Document document = (Document) kml.getFeature();
+// Folder folder = (Folder) document.getFeature().get(0);
+//
+// int size = folder.getFeature().size();
+// for (int i = 0; i < size; i++) {
+// Placemark placemark = (Placemark) folder.getFeature().get(i);
+//
+// SchemaData schemaData = placemark.getExtendedData().getSchemaData().get(0);
+//
+// String districtName = null, districtCode = null;
+//
+// for (SimpleData data : schemaData.getSimpleData()) {
+//
+// BoatDistrictSchemaData type =
+// BoatDistrictSchemaData.valueOfLabel(data.getName());
+//
+// switch (type) {
+// case DESCRIPTION:
+// districtName = data.getValue();
+// break;
+// case OBJECTID:
+// districtCode = data.getValue();
+// }
+// }
+//
+// if (logger.isDebugEnabled()) {
+// logger.debug("District : code = " + districtCode +
+// " _ name = " + districtName);
+// }
+//
+// if (districtCode != null) {
+//
+// BoatDistrict district = dao.findByCode(districtCode);
+//
+// if (district != null) {
+//
+// // Retrieve coordinate
+// Point point = (Point) placemark.getGeometry();
+// Coordinate coordinate = point.getCoordinates().get(0);
+//
+// // Update data
+// district.setLatitude(coordinate.getLatitude());
+// district.setLongitude(coordinate.getLongitude());
+// district.setName(districtName);
+//
+// dao.update(district);
+//
+// results.incNbImported();
+// } else {
+// // Reject
+// results.incNbRefused();
+// results.addError(i, "Code quartier inconnu : " + districtCode);
+// }
+// }
+// }
+//
+// transaction.commitTransaction();
+
+ return results;
+ }
+}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -47,6 +47,23 @@
import fr.ifremer.wao.WaoQueryHelper;
import fr.ifremer.wao.bean.ConnectedUser;
import fr.ifremer.wao.bean.UserRole;
+import fr.ifremer.wao.entity.Boat;
+import fr.ifremer.wao.entity.Company;
+import fr.ifremer.wao.entity.Contact;
+import fr.ifremer.wao.entity.ContactDAO;
+import fr.ifremer.wao.entity.ContactImpl;
+import fr.ifremer.wao.entity.ElligibleBoat;
+import fr.ifremer.wao.entity.ElligibleBoatDAO;
+import fr.ifremer.wao.entity.FishingZone;
+import fr.ifremer.wao.entity.Profession;
+import fr.ifremer.wao.entity.SampleMonth;
+import fr.ifremer.wao.entity.SampleRow;
+import fr.ifremer.wao.entity.WaoUser;
+import fr.ifremer.wao.io.ContactInput;
+import fr.ifremer.wao.io.ImportRefusedException;
+import fr.ifremer.wao.io.csv.ExportHelper;
+import fr.ifremer.wao.io.csv.ImportHelper;
+import fr.ifremer.wao.io.csv.WaoCsvHeader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.nuiton.topia.TopiaContext;
@@ -57,11 +74,9 @@
import fr.ifremer.wao.bean.ContactStatus.NullSampleMonthException;
import fr.ifremer.wao.bean.ContactFilter;
import fr.ifremer.wao.bean.ContactState;
-import fr.ifremer.wao.bean.ImportResults;
-import fr.ifremer.wao.bean.ImportResultsImpl;
-import fr.ifremer.wao.entity.*;
-import fr.ifremer.wao.io.*;
-import fr.ifremer.wao.io.WaoCsvHeader.*;
+import fr.ifremer.wao.io.ImportResults;
+import fr.ifremer.wao.io.ImportResultsImpl;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.*;
import org.apache.commons.lang.BooleanUtils;
/**
@@ -192,7 +207,7 @@
@Override
public void executeSaveContact(TopiaContext transaction,
- Contact contact, boolean delete)
+ Contact contact, boolean delete)
throws TopiaException, NullSampleMonthException {
checkObserver(contact);
@@ -353,7 +368,7 @@
FileOutputStream output = new FileOutputStream(file);
writer = new CsvWriter(output, ',', context.getCsvCharset());
- ExportHelper<ContactHeader> export =
+ ExportHelper<ContactHeader> export =
new ExportHelper<ContactHeader>(writer,
CONTACT.getTotalHeaders()) {
@@ -629,7 +644,7 @@
* @throws ParseException from ImportHelper
* @see ImportHelper
*/
- protected void loadContactCsv(CsvReader reader, ContactInput contact,
+ protected void loadContactCsv(CsvReader reader, ContactInput contact,
boolean updateValidation) throws IOException,
TopiaException,
ImportRefusedException,
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceReferentialImpl.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -37,9 +37,8 @@
import fr.ifremer.wao.entity.FishingZoneDAO;
import fr.ifremer.wao.entity.Profession;
import fr.ifremer.wao.entity.ProfessionDAO;
-import fr.ifremer.wao.io.ImportHelper;
-import fr.ifremer.wao.io.WaoCsvHeader;
-import fr.ifremer.wao.io.WaoCsvHeader.FISHING_ZONE;
+import fr.ifremer.wao.io.csv.ImportHelper;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.FISHING_ZONE;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSamplingImpl.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -39,8 +39,8 @@
import fr.ifremer.wao.bean.ConnectedUser;
import fr.ifremer.wao.bean.FacadeRow;
import fr.ifremer.wao.bean.FacadeRowImpl;
-import fr.ifremer.wao.bean.ImportResults;
-import fr.ifremer.wao.bean.ImportResultsImpl;
+import fr.ifremer.wao.io.ImportResults;
+import fr.ifremer.wao.io.ImportResultsImpl;
import fr.ifremer.wao.bean.SamplingFilter;
import fr.ifremer.wao.bean.UserRole;
import fr.ifremer.wao.entity.Boat;
@@ -63,10 +63,10 @@
import fr.ifremer.wao.entity.SampleRowLogDAO;
import fr.ifremer.wao.entity.SampleRowLogImpl;
import fr.ifremer.wao.entity.WaoUser;
-import fr.ifremer.wao.io.ImportHelper;
-import fr.ifremer.wao.io.SamplingExport;
-import fr.ifremer.wao.io.WaoCsvHeader.FISHING_ZONE;
-import fr.ifremer.wao.io.WaoCsvHeader.SAMPLING;
+import fr.ifremer.wao.io.csv.ImportHelper;
+import fr.ifremer.wao.io.csv.SamplingExport;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.FISHING_ZONE;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.SAMPLING;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.mail.EmailException;
import org.nuiton.topia.TopiaContext;
Modified: trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties
===================================================================
--- trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/resources/i18n/wao-business-en_GB.properties 2010-06-30 10:54:53 UTC (rev 581)
@@ -25,6 +25,7 @@
wao.error.serviceBoat.getShipOwnerNamesContains=
wao.error.serviceBoat.importActivityCalendarCsv=
wao.error.serviceBoat.importBoatCsv=
+wao.error.serviceCartography.importBoatDistrictKml=
wao.error.serviceContact.exportContactCsv=
wao.error.serviceContact.getContacts=
wao.error.serviceContact.getNbContacts=
Modified: trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties
===================================================================
--- trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/main/resources/i18n/wao-business-fr_FR.properties 2010-06-30 10:54:53 UTC (rev 581)
@@ -24,6 +24,7 @@
wao.error.serviceBoat.getShipOwnerNamesContains=
wao.error.serviceBoat.importActivityCalendarCsv=Probl\u00E8me d'import du fichier CSV des calendriers d'activit\u00E9
wao.error.serviceBoat.importBoatCsv=Probl\u00E8me d'import du fichier CSV. V\u00E9rifiez l'en-t\u00EAte du fichier \: [ NAVS_COD,CARN_NOM,CARN_LONGUEUR_HT,CARN_ANNEE,QUARTIER_IMMA,PER_COD,PER_NOM,PER_PRENOM,NAVS_ACTIVE ]. Voir documentation pour plus de d\u00E9tails.
+wao.error.serviceCartography.importBoatDistrictKml=
wao.error.serviceContact.exportContactCsv=Impossible d'exporter les contacts
wao.error.serviceContact.getContacts=Impossible de filtrer la liste des contacts
wao.error.serviceContact.getNbContacts=Impossible de compter le nombre de contacts filtr\u00E9s
Modified: trunk/wao-business/src/main/xmi/wao.zargo
===================================================================
(Binary files differ)
Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java
===================================================================
--- trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/test/java/fr/ifremer/wao/TestManager.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -27,6 +27,7 @@
import fr.ifremer.wao.service.ServiceBoat;
import fr.ifremer.wao.service.ServiceBoatImpl;
+import fr.ifremer.wao.service.ServiceCartographyImpl;
import fr.ifremer.wao.service.ServiceContact;
import fr.ifremer.wao.service.ServiceContactImpl;
import fr.ifremer.wao.service.ServiceNews;
@@ -160,38 +161,10 @@
return instance;
}
-// public void prepareData() throws WaoExceptionO {
-// ServiceBoat serviceBoat = new ServiceBoatImpl();
-// ServiceReferential serviceReferential = new ServiceReferentialImpl();
-// ServiceUser serviceUser = new ServiceUserImpl();
-// ServiceSampling serviceSampling = new ServiceSamplingImpl();
-// ServiceContact serviceContact = new ServiceContactImpl();
-//
-// Company company = new CompanyImpl();
-// company.setName("TARTANPION");
-// company.setActive(true);
-// serviceUser.createUpdateCompany(company);
-//
-// WaoUser observer = new WaoUserImpl();
-// observer.setCompany(company);
-// observer.setFirstName("Jean");
-// observer.setLastName("Michmuche");
-// observer.setLogin("jmichmuche");
-// observer.setActive(true);
-// serviceUser.createUpdateUser(observer, true);
-//
-// InputStream input = getClass().getResourceAsStream("/import/navires.csv");
-// serviceBoat.importBoatCsv(input);
-//
-// input = getClass().getResourceAsStream("/import/zonesPeche.csv");
-// serviceReferential.importFishingZoneCsv(input);
-//
-// input = getClass().getResourceAsStream("/import/echantillonnage.csv");
-// serviceSampling.importSamplingPlanCsv(input);
-//
-// input = getClass().getResourceAsStream("/import/contacts.csv");
-// // user import : no activation
-// serviceContact.importContactCsv(observer, input);
-// }
+ public ServiceCartographyImpl getServiceCartography() {
+ ServiceCartographyImpl instance = new ServiceCartographyImpl();
+ instance.setContext(getContext());
+ return instance;
+ }
}
Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/io/ImportHelperTest.java
===================================================================
--- trunk/wao-business/src/test/java/fr/ifremer/wao/io/ImportHelperTest.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/test/java/fr/ifremer/wao/io/ImportHelperTest.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -27,13 +27,13 @@
import fr.ifremer.wao.*;
import com.csvreader.CsvReader;
-import fr.ifremer.wao.io.WaoCsvHeader.CONTACT;
-import fr.ifremer.wao.io.WaoCsvHeader.DatedHeader;
-import fr.ifremer.wao.io.WaoCsvHeader.SAMPLING;
+import fr.ifremer.wao.io.csv.ImportHelper;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.CONTACT;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.DatedHeader;
+import fr.ifremer.wao.io.csv.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;
Added: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceCartographyImplTest.java
===================================================================
--- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceCartographyImplTest.java (rev 0)
+++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceCartographyImplTest.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -0,0 +1,91 @@
+package fr.ifremer.wao.service;
+
+import fr.ifremer.wao.AbstractServiceTest;
+import fr.ifremer.wao.WaoBusinessException;
+import fr.ifremer.wao.WaoDAOHelper;
+import fr.ifremer.wao.entity.BoatDistrict;
+import fr.ifremer.wao.entity.BoatDistrictDAO;
+import fr.ifremer.wao.io.ImportResults;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.nuiton.topia.TopiaContext;
+import org.nuiton.topia.TopiaException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Created: 30 juin 2010
+ *
+ * @author fdesbois <fdesbois at codelutin.com>
+ * @version $Id$
+ */
+public class ServiceCartographyImplTest extends AbstractServiceTest {
+
+ private static final Logger logger =
+ LoggerFactory.getLogger(ServiceCartographyImplTest.class);
+
+ private ServiceCartography service;
+
+ @Before
+ public void initialize() {
+ logger.info("initialize ServiceCartographyImplTest");
+ service = manager.getServiceCartography();
+ }
+
+ @Test
+ public void testImportBoatDistrictKml()
+ throws WaoBusinessException, TopiaException {
+
+ /** PREPARE DATA **/
+ InputStream input = getClass().getResourceAsStream("/import/navires.csv");
+ manager.getServiceBoat().importBoatCsv(input);
+
+ /** EXEC METHOD **/
+ input = getClass().getResourceAsStream("/import/boat_districts.kml");
+ ImportResults results = service.importBoatDistrictKml(input);
+ Assert.assertEquals(3, results.getNbRowsImported());
+ Assert.assertEquals(0, results.getNbRowsRefused());
+
+ /** CHECK RESULT DATA **/
+ TopiaContext transaction = manager.getContext().beginTransaction();
+ BoatDistrictDAO dao = WaoDAOHelper.getBoatDistrictDAO(transaction);
+ try {
+
+ List<BoatDistrict> districts = dao.findAll();
+ Assert.assertEquals(3, districts.size());
+
+ Set<String> codes = new HashSet<String>();
+ for (BoatDistrict district : districts) {
+ codes.add(district.getCode());
+
+ Assert.assertNotNull(district.getLatitude());
+ Assert.assertNotNull(district.getLongitude());
+ Assert.assertNotNull(district.getName());
+ }
+
+ Assert.assertTrue(codes.contains("UN"));
+ Assert.assertTrue(codes.contains("UX"));
+ Assert.assertTrue(codes.contains("CI"));
+
+ } finally {
+ transaction.closeContext();
+ }
+ }
+
+ //@Test
+ public void testImportBoatDistrictBadKml() throws WaoBusinessException {
+ /** PREPARE DATA **/
+ InputStream input = getClass().getResourceAsStream("/import/navires.csv");
+ manager.getServiceBoat().importBoatCsv(input);
+
+ /** EXEC METHOD **/
+ input = getClass().getResourceAsStream("/import/activity.csv");
+ ImportResults results = service.importBoatDistrictKml(input);
+ }
+}
Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactInternalTest.java
===================================================================
--- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactInternalTest.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceContactInternalTest.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -28,7 +28,7 @@
import fr.ifremer.wao.WaoDAOHelper;
import fr.ifremer.wao.bean.ConnectedUser;
import fr.ifremer.wao.bean.ContactState;
-import fr.ifremer.wao.bean.ImportResults;
+import fr.ifremer.wao.bean.ContactStatus.NullSampleMonthException;
import fr.ifremer.wao.bean.UserRole;
import fr.ifremer.wao.entity.Boat;
import fr.ifremer.wao.entity.BoatDAO;
@@ -44,15 +44,10 @@
import fr.ifremer.wao.entity.WaoUserDAO;
import fr.ifremer.wao.io.ContactInput;
import fr.ifremer.wao.io.ImportRefusedException;
-import fr.ifremer.wao.io.WaoCsvHeader.BOAT;
-import fr.ifremer.wao.io.WaoCsvHeader.CONTACT;
-import fr.ifremer.wao.io.WaoCsvHeader.SAMPLING;
-import fr.ifremer.wao.bean.ContactStatus.NullSampleMonthException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.ParseException;
-import java.util.Date;
-import java.util.List;
+import fr.ifremer.wao.io.ImportResults;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.BOAT;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.CONTACT;
+import fr.ifremer.wao.io.csv.WaoCsvHeader.SAMPLING;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -65,9 +60,20 @@
import org.nuiton.util.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.mockito.Mockito.*;
-import static org.junit.Assert.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
/**
* ServiceContactImplTest
*
Modified: trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java
===================================================================
--- trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/test/java/fr/ifremer/wao/service/ServiceSamplingImplTest.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -29,10 +29,9 @@
import fr.ifremer.wao.WaoBusinessException;
import fr.ifremer.wao.WaoDAOHelper;
import fr.ifremer.wao.WaoException;
-import fr.ifremer.wao.bean.ImportResults;
+import fr.ifremer.wao.bean.FacadeRow;
import fr.ifremer.wao.bean.SamplingFilter;
import fr.ifremer.wao.bean.SamplingFilterImpl;
-import fr.ifremer.wao.bean.FacadeRow;
import fr.ifremer.wao.entity.Boat;
import fr.ifremer.wao.entity.Company;
import fr.ifremer.wao.entity.CompanyDAO;
@@ -48,13 +47,7 @@
import fr.ifremer.wao.entity.SampleRow;
import fr.ifremer.wao.entity.SampleRowDAO;
import fr.ifremer.wao.entity.SampleRowLogImpl;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.List;
+import fr.ifremer.wao.io.ImportResults;
import org.junit.Assert;
import org.junit.Test;
import org.nuiton.topia.TopiaContext;
@@ -63,8 +56,20 @@
import org.nuiton.util.PeriodDates;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.junit.Assert.*;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+
/**
* ServiceSamplingImplTest
*
Added: trunk/wao-business/src/test/resources/import/boat_districts.kml
===================================================================
--- trunk/wao-business/src/test/resources/import/boat_districts.kml (rev 0)
+++ trunk/wao-business/src/test/resources/import/boat_districts.kml 2010-06-30 10:54:53 UTC (rev 581)
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<kml xmlns="http://www.opengis.net/kml/2.2">
+ <Document>
+ <Folder>
+ <name>IFR_SIH_QUARTIER_MAR_PT</name>
+ <Schema name="IFR_SIH_QUARTIER_MAR_PT" id="IFR_SIH_QUARTIER_MAR_PT">
+ <SimpleField name="Name" type="string"></SimpleField>
+ <SimpleField name="Description" type="string"></SimpleField>
+ <SimpleField name="OBJECTID" type="int"></SimpleField>
+ <SimpleField name="LIEU_LIB" type="string"></SimpleField>
+ <SimpleField name="LIEU_COD" type="string"></SimpleField>
+ <SimpleField name="TLIEU_COD" type="int"></SimpleField>
+ <SimpleField name="L_OCEAN" type="string"></SimpleField>
+ <SimpleField name="L_PAYS" type="string"></SimpleField>
+ </Schema>
+ <Placemark>
+ <name>34</name>
+ <description>Sete</description>
+ <ExtendedData>
+ <SchemaData schemaUrl="#IFR_SIH_QUARTIER_MAR_PT">
+ <SimpleData name="Name">2</SimpleData>
+ <SimpleData name="Description">Unio</SimpleData>
+ <SimpleData name="OBJECTID">UN</SimpleData>
+ <SimpleData name="LIEU_LIB">13</SimpleData>
+ <SimpleData name="LIEU_COD">ME</SimpleData>
+ <SimpleData name="TLIEU_COD">FRA</SimpleData>
+ <SimpleData name="L_OCEAN">0</SimpleData>
+ <SimpleData name="L_PAYS">POINT</SimpleData>
+ </SchemaData>
+ </ExtendedData>
+ <Point>
+ <coordinates>3.697544304924308,43.400978635376085
+ </coordinates>
+ </Point>
+ </Placemark>
+ <Placemark>
+ <name>30</name>
+ <description>Martigues</description>
+ <ExtendedData>
+ <SchemaData schemaUrl="#IFR_SIH_QUARTIER_MAR_PT">
+ <SimpleData name="Name">30</SimpleData>
+ <SimpleData name="Description">Uxirgue</SimpleData>
+ <SimpleData name="OBJECTID">UX</SimpleData>
+ <SimpleData name="LIEU_LIB">13</SimpleData>
+ <SimpleData name="LIEU_COD">ME</SimpleData>
+ <SimpleData name="TLIEU_COD">FRA</SimpleData>
+ <SimpleData name="L_OCEAN">1</SimpleData>
+ <SimpleData name="L_PAYS">POINT</SimpleData>
+ </SchemaData>
+ </ExtendedData>
+ <Point>
+ <coordinates>5.05084975227851,43.405830559005189
+ </coordinates>
+ </Point>
+ </Placemark>
+ <Placemark>
+ <name>29</name>
+ <description>Marseille</description>
+ <ExtendedData>
+ <SchemaData schemaUrl="#IFR_SIH_QUARTIER_MAR_PT">
+ <SimpleData name="Name">29</SimpleData>
+ <SimpleData name="Description">Civik</SimpleData>
+ <SimpleData name="OBJECTID">CI</SimpleData>
+ <SimpleData name="LIEU_LIB">13</SimpleData>
+ <SimpleData name="LIEU_COD">ME</SimpleData>
+ <SimpleData name="TLIEU_COD">FRA</SimpleData>
+ <SimpleData name="L_OCEAN">2</SimpleData>
+ <SimpleData name="L_PAYS">POINT</SimpleData>
+ </SchemaData>
+ </ExtendedData>
+ <Point>
+ <coordinates>5.351948092148461,43.323330380088101
+ </coordinates>
+ </Point>
+ </Placemark>
+ </Folder>
+ </Document>
+</kml>
Modified: trunk/wao-business/src/test/resources/log4j.properties
===================================================================
--- trunk/wao-business/src/test/resources/log4j.properties 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-business/src/test/resources/log4j.properties 2010-06-30 10:54:53 UTC (rev 581)
@@ -8,6 +8,6 @@
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d [%p] %c{2} %m%n
-log4j.logger.fr.ifremer.wao=INFO
+log4j.logger.fr.ifremer.wao=DEBUG
log4j.logger.org.nuiton.util=INFO
log4j.logger.org.nuiton.util.beans.BinderProvider=ERROR
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/components/CsvImport.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -23,7 +23,7 @@
import fr.ifremer.wao.WaoBusinessException;
import fr.ifremer.wao.WaoException;
-import fr.ifremer.wao.bean.ImportResults;
+import fr.ifremer.wao.io.ImportResults;
import fr.ifremer.wao.ui.data.ErrorReport;
import fr.ifremer.wao.ui.data.ImportEngine;
import fr.ifremer.wao.ui.services.WaoManager;
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/data/ImportEngine.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -23,7 +23,7 @@
import fr.ifremer.wao.WaoBusinessException;
import fr.ifremer.wao.WaoException;
-import fr.ifremer.wao.bean.ImportResults;
+import fr.ifremer.wao.io.ImportResults;
import fr.ifremer.wao.ui.components.CsvImport;
import fr.ifremer.wao.ui.components.Layout;
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Administration.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -30,8 +30,8 @@
import fr.ifremer.wao.WaoException;
import fr.ifremer.wao.WaoProperty;
import fr.ifremer.wao.bean.ConnectedUser;
-import fr.ifremer.wao.bean.ImportResults;
-import fr.ifremer.wao.bean.ImportResultsImpl;
+import fr.ifremer.wao.io.ImportResults;
+import fr.ifremer.wao.io.ImportResultsImpl;
import fr.ifremer.wao.bean.UserRole;
import fr.ifremer.wao.entity.Company;
import fr.ifremer.wao.entity.CompanyImpl;
@@ -48,18 +48,15 @@
import fr.ifremer.wao.ui.services.WaoManager;
import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
-import java.util.zip.GZIPInputStream;
import org.apache.commons.lang.StringUtils;
import org.apache.tapestry5.EventContext;
import org.apache.tapestry5.OptionModel;
import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.SelectModel;
-import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.IncludeJavaScriptLibrary;
import org.apache.tapestry5.annotations.IncludeStylesheet;
@@ -78,8 +75,6 @@
import org.apache.tapestry5.ioc.services.PropertyAccess;
import org.apache.tapestry5.ioc.services.TypeCoercer;
import org.apache.tapestry5.services.BeanModelSource;
-import org.apache.tapestry5.services.Response;
-import org.apache.tapestry5.upload.services.UploadedFile;
import org.slf4j.Logger;
/**
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/Contacts.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -31,7 +31,7 @@
import fr.ifremer.wao.bean.ContactFilter;
import fr.ifremer.wao.bean.ContactFilterImpl;
import fr.ifremer.wao.bean.ContactState;
-import fr.ifremer.wao.bean.ImportResults;
+import fr.ifremer.wao.io.ImportResults;
import fr.ifremer.wao.bean.SamplingFilter;
import fr.ifremer.wao.bean.UserRole;
import fr.ifremer.wao.entity.Boat;
Modified: trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java
===================================================================
--- trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java 2010-06-29 14:20:31 UTC (rev 580)
+++ trunk/wao-ui/src/main/java/fr/ifremer/wao/ui/pages/SamplingPlan.java 2010-06-30 10:54:53 UTC (rev 581)
@@ -29,7 +29,7 @@
import fr.ifremer.wao.WaoException;
import fr.ifremer.wao.bean.ConnectedUser;
import fr.ifremer.wao.bean.FacadeRow;
-import fr.ifremer.wao.bean.ImportResults;
+import fr.ifremer.wao.io.ImportResults;
import fr.ifremer.wao.bean.SamplingFilter;
import fr.ifremer.wao.bean.SamplingFilterImpl;
import fr.ifremer.wao.entity.FishingZone;
1
0
[Suiviobsmer-commits] r580 - in trunk: . wao-business/src/main/java/fr/ifremer/wao wao-business/src/main/java/fr/ifremer/wao/service wao-business/src/main/xmi
by fdesbois@users.labs.libre-entreprise.org 29 Jun '10
by fdesbois@users.labs.libre-entreprise.org 29 Jun '10
29 Jun '10
Author: fdesbois
Date: 2010-06-29 14:20:31 +0000 (Tue, 29 Jun 2010)
New Revision: 580
Log:
Evo #2352 : Cartography for contacts :
- Uncomment migration + create only one query for insertion
- Resolve Warning on TopiaQuery addEquals usage
- Use EntityProperty for getLastActivityCalendar
- Change lazy managment for shipOwner and add boatDistrict
Modified:
trunk/pom.xml
trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java
trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java
trunk/wao-business/src/main/xmi/wao.properties
trunk/wao-business/src/main/xmi/wao.zargo
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-29 11:57:12 UTC (rev 579)
+++ trunk/pom.xml 2010-06-29 14:20:31 UTC (rev 580)
@@ -242,7 +242,7 @@
<nuitonutils.version>1.3.1</nuitonutils.version>
<nuitonweb.version>0.1</nuitonweb.version>
<topia.version>2.3.5-SNAPSHOT</topia.version>
- <eugene.version>2.0.3-SNAPSHOT</eugene.version>
+ <eugene.version>2.1-SNAPSHOT</eugene.version>
<tapestry.version>5.1.0.5</tapestry.version>
</properties>
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-06-29 11:57:12 UTC (rev 579)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-06-29 14:20:31 UTC (rev 580)
@@ -206,27 +206,39 @@
}
@Override
- protected Map<String, String> insertBoatDistricts_1_5c(List<String> queries, Map<String, List<String>> boatDistrictCodes) {
+ protected Map<String, String> insertBoatDistricts_1_5c(List<String> queries,
+ Map<String, List<String>> boatDistrictCodes) {
Map<String, String> boats = new HashMap<String, String>();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Set<String> codes = boatDistrictCodes.keySet();
+
+ StringBuilder query = new StringBuilder("INSERT INTO BoatDistrict VALUES ");
+ String separator = "";
+
for (String code : codes) {
// FIXME-fdesbois-2010-06-29 : Seems dangerous to use class, maybe it's better to use full qualified name 'fr.ifremer.wao.entity.BoatDistrict'
String districtId = TopiaId.create(BoatDistrict.class);
String createDate = dateFormat.format(new Date());
- queries.add(String.format(
- "INSERT INTO BoatDistrict VALUES ('%s', %d, '%s', '%s', null, null, null);",
+// queries.add(String.format(
+// "INSERT INTO BoatDistrict VALUES ('%s', %d, '%s', '%s', null, null, null);",
+// districtId, 0, createDate, code)
+// );
+ query.append(separator).append(String.format(
+ "('%s', %d, '%s', '%s', null, null, null)",
districtId, 0, createDate, code)
);
+ separator = ", ";
for (String boatId : boatDistrictCodes.get(code)) {
boats.put(boatId, districtId);
}
}
+ queries.add(query.append(';').toString());
+
return boats;
}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2010-06-29 11:57:12 UTC (rev 579)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2010-06-29 14:20:31 UTC (rev 580)
@@ -198,20 +198,20 @@
}
}
-// List<String> queries = new ArrayList <String>();
-//
-// // Create the boatDistrict table
-// createBoatDistrictTable_1_5b(queries);
-//
-// // Insert boatDistrict using the previous map.
-// // This will return boats with boatDisctrict id in value
-// Map<String, String> boats = insertBoatDistricts_1_5c(queries, boatDistrictCodes);
-//
-// // Update the Boat table with id of district (create column as foreign key)
-// updateBoatWithBoatDistrict_1_5d(queries, boats);
-//
-// String[] strings = queries.toArray(new String[queries.size()]);
-// executeSQL(tx, showSql, showProgression, strings);
+ List<String> queries = new ArrayList <String>();
+
+ // Create the boatDistrict table
+ createBoatDistrictTable_1_5b(queries);
+
+ // Insert boatDistrict using the previous map.
+ // This will return boats with boatDisctrict id in value
+ Map<String, String> boats = insertBoatDistricts_1_5c(queries, boatDistrictCodes);
+
+ // Update the Boat table with id of district (create column as foreign key)
+ updateBoatWithBoatDistrict_1_5d(queries, boats);
+
+ String[] strings = queries.toArray(new String[queries.size()]);
+ executeSQL(tx, false, false, strings);
}
}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-06-29 11:57:12 UTC (rev 579)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-06-29 14:20:31 UTC (rev 580)
@@ -182,6 +182,7 @@
}
// load data
boatInfos.getBoat().sizeActivityCalendar();
+ boatInfos.getBoat().getShipOwner();
result.setBoatInfos(boatInfos);
@@ -599,50 +600,27 @@
ActivityCalendarDAO dao = WaoDAOHelper.getActivityCalendarDAO(transaction);
- // Properties needed for query and subQuery
- String calendarAlias = WaoQueryHelper.ALIAS_ACTIVITY_CALENDAR;
- String calendarBoatProperty =
- TopiaQuery.getProperty(calendarAlias, ActivityCalendar.BOAT);
- String calendarYearProperty =
- TopiaQuery.getProperty(calendarAlias, ActivityCalendar.YEAR);
+ WaoQueryHelper.ActivityCalendarProperty calendarProperty =
+ WaoQueryHelper.newActivityCalendarProperty();
- String maxCalendarAlias = "max" + calendarAlias;
- String maxCalendarBoatProperty =
- TopiaQuery.getProperty(maxCalendarAlias, ActivityCalendar.BOAT);
- String maxCalendarYearProperty =
- TopiaQuery.getProperty(maxCalendarAlias, ActivityCalendar.YEAR);
+ WaoQueryHelper.ActivityCalendarProperty maxCalendarProperty =
+ WaoQueryHelper.newActivityCalendarProperty(
+ WaoQueryHelper.ALIAS_ACTIVITY_CALENDAR + "2");
// Prepare subQuery
- TopiaQuery subquery = dao.createQuery(maxCalendarAlias).
- setSelect(new StringBuilder("MAX(").
- append(maxCalendarYearProperty).
- append(')').
- toString()
- ).
- addWhere(new StringBuilder(maxCalendarBoatProperty).
- append(" = ").
- append(calendarBoatProperty).
- toString()
- ).
- // addWhere("$1 = $2", maxCalendarBoatProperty, calendarBoatProperty);
- addGroup(maxCalendarBoatProperty);
+ TopiaQuery subquery = dao.createQuery(maxCalendarProperty.$alias()).
+ setSelect(WaoQueryHelper.format("MAX($1)", maxCalendarProperty.year())).
+ addWhere(WaoQueryHelper.format("$1 = $2",
+ maxCalendarProperty.boat(), calendarProperty.boat())).
+ addGroup(maxCalendarProperty.boat());
// Create main query
- TopiaQuery query = dao.createQuery(calendarAlias).
- addEquals(calendarBoatProperty, boat).
- addSubQuery(calendarYearProperty + " = (?)", subquery).
- addLoad(ActivityCalendar.BOAT);
+ TopiaQuery query = dao.createQuery(calendarProperty.$alias()).
+ addEquals(calendarProperty.boat(), boat).
+ addSubQuery(WaoQueryHelper.format(
+ "$1 = (?)", calendarProperty.year()), subquery).
+ addLoad(calendarProperty.boat());
-// TopiaQuery query = dao.createQuery("A").
-// add("A." + ActivityCalendar.BOAT, boat);
-//
-// TopiaQuery subquery = dao.createQuery("B").
-// setSelect("MAX(B." + ActivityCalendar.YEAR + ")").
-// add("B." + ActivityCalendar.BOAT + " = A." + ActivityCalendar.BOAT).
-// addGroup("B." + ActivityCalendar.BOAT);
-//
-// query.add("A." + ActivityCalendar.YEAR + " = (" + subquery.fullQuery() + ")");
-
result = dao.findByQuery(query);
// load other complex data from collections
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-06-29 11:57:12 UTC (rev 579)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceUserImpl.java 2010-06-29 14:20:31 UTC (rev 580)
@@ -383,7 +383,7 @@
UserRole.getMatchCodes(UserRole.OBSERVER, UserRole.COORDINATOR);
TopiaQuery query = dao.createQuery().
- addEquals(WaoUser.ROLE, matchCodes).
+ addEquals(WaoUser.ROLE, (Integer[])matchCodes).
addOrder(WaoUser.FIRST_NAME, WaoUser.LAST_NAME);
if (company != null) {
Modified: trunk/wao-business/src/main/xmi/wao.properties
===================================================================
--- trunk/wao-business/src/main/xmi/wao.properties 2010-06-29 11:57:12 UTC (rev 579)
+++ trunk/wao-business/src/main/xmi/wao.properties 2010-06-29 14:20:31 UTC (rev 580)
@@ -23,7 +23,8 @@
fr.ifremer.wao.entity.FishingZone.attribute.sampleRow.tagvalue.orderBy=code
-fr.ifremer.wao.entity.Boat.attribute.shipOwner.tagvalue.lazy=false
+#fr.ifremer.wao.entity.Boat.attribute.shipOwner.tagvalue.lazy=false
+fr.ifremer.wao.entity.Boat.attribute.boatDistrict.tagvalue.lazy=false
fr.ifremer.wao.entity.Boat.attribute.elligibleBoat.tagvalue.orderBy=companyActive
fr.ifremer.wao.entity.ElligibleBoat.attribute.boat.tagvalue.lazy=false
Modified: trunk/wao-business/src/main/xmi/wao.zargo
===================================================================
(Binary files differ)
1
0
[Suiviobsmer-commits] r579 - in trunk: . wao-business wao-business/src/main/java/fr/ifremer/wao wao-business/src/main/java/fr/ifremer/wao/entity wao-business/src/main/java/fr/ifremer/wao/service wao-business/src/main/xmi
by fdesbois@users.labs.libre-entreprise.org 29 Jun '10
by fdesbois@users.labs.libre-entreprise.org 29 Jun '10
29 Jun '10
Author: fdesbois
Date: 2010-06-29 11:57:12 +0000 (Tue, 29 Jun 2010)
New Revision: 579
Log:
Evo #2352 : Cartography for contacts :
- Use last topia snapshot (WaoQueryHelper generation)
- Change model version to 1.5
- Implement migration of districtCode to new entity BoatDistrict
Removed:
trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryHelper.java
Modified:
trunk/pom.xml
trunk/wao-business/pom.xml
trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java
trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java
trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java
trunk/wao-business/src/main/java/fr/ifremer/wao/entity/BoatImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactDAOImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java
trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java
trunk/wao-business/src/main/xmi/wao.zargo
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-29 08:31:33 UTC (rev 578)
+++ trunk/pom.xml 2010-06-29 11:57:12 UTC (rev 579)
@@ -241,8 +241,8 @@
<i18n.version>1.2.2</i18n.version>
<nuitonutils.version>1.3.1</nuitonutils.version>
<nuitonweb.version>0.1</nuitonweb.version>
- <topia.version>2.3.4</topia.version>
- <eugene.version>2.0.2</eugene.version>
+ <topia.version>2.3.5-SNAPSHOT</topia.version>
+ <eugene.version>2.0.3-SNAPSHOT</eugene.version>
<tapestry.version>5.1.0.5</tapestry.version>
</properties>
Modified: trunk/wao-business/pom.xml
===================================================================
--- trunk/wao-business/pom.xml 2010-06-29 08:31:33 UTC (rev 578)
+++ trunk/wao-business/pom.xml 2010-06-29 11:57:12 UTC (rev 579)
@@ -137,7 +137,8 @@
org.nuiton.eugene.java.JavaBeanTransformer,
org.nuiton.topia.generator.ServiceTransformer,
org.nuiton.eugene.java.JavaInterfaceTransformer,
- org.nuiton.topia.generator.BinderHelperTransformer
+ org.nuiton.topia.generator.BinderHelperTransformer,
+ org.nuiton.topia.generator.QueryHelperTransformer
</templates>
</configuration>
<goals>
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-06-29 08:31:33 UTC (rev 578)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/PostgresMigrationCallback.java 2010-06-29 11:57:12 UTC (rev 579)
@@ -26,9 +26,22 @@
package fr.ifremer.wao;
import fr.ifremer.wao.bean.ContactState;
+import fr.ifremer.wao.entity.BoatDistrict;
+import org.hibernate.SQLQuery;
+import org.nuiton.topia.TopiaException;
+import org.nuiton.topia.framework.TopiaContextImplementor;
+import org.nuiton.topia.persistence.TopiaId;
import org.nuiton.util.Version;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* PgMigrationCallback
@@ -152,4 +165,86 @@
queries.add("ALTER TABLE Contact ADD commentAdmin TEXT;");
queries.add("ALTER TABLE Contact ADD commentCoordinator TEXT;");
}
+
+ @Override
+ protected Map<String, List<String>> retrieveBoatDistrictCodes_1_5a(TopiaContextImplementor tx) throws TopiaException {
+
+ Map<String, List<String>> boatDistrictCodes = new HashMap<String, List<String>>();
+
+ SQLQuery query = tx.getHibernate().
+ createSQLQuery("SELECT topiaId, districtCode FROM Boat");
+
+ List<Object[]> results = query.list();
+
+ for (Object[] result : results) {
+ String topiaId = (String)result[0];
+ String districtCode = (String)result[1];
+
+ List<String> boatIds = boatDistrictCodes.get(districtCode);
+ if (boatIds == null) {
+ boatIds = new ArrayList<String>();
+ boatDistrictCodes.put(districtCode, boatIds);
+ }
+ boatIds.add(topiaId);
+ }
+
+ return boatDistrictCodes;
+ }
+
+ @Override
+ protected void createBoatDistrictTable_1_5b(List<String> queries) {
+ queries.add("CREATE TABLE BoatDistrict (" +
+ "topiaId CHARACTER VARYING(255) PRIMARY KEY," +
+ "topiaVersion BIGINT NOT NULL," +
+ "topiaCreateDate TIMESTAMP WITHOUT TIME ZONE NOT NULL," +
+ "code CHARACTER VARYING(10) NOT NULL," +
+ "name TEXT," +
+ "latitude DOUBLE PRECISION," +
+ "longitude DOUBLE PRECISION," +
+ "CONSTRAINT boatDistrict_code_key UNIQUE(code)" +
+ ");");
+ }
+
+ @Override
+ protected Map<String, String> insertBoatDistricts_1_5c(List<String> queries, Map<String, List<String>> boatDistrictCodes) {
+
+ Map<String, String> boats = new HashMap<String, String>();
+
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
+
+ Set<String> codes = boatDistrictCodes.keySet();
+ for (String code : codes) {
+ // FIXME-fdesbois-2010-06-29 : Seems dangerous to use class, maybe it's better to use full qualified name 'fr.ifremer.wao.entity.BoatDistrict'
+ String districtId = TopiaId.create(BoatDistrict.class);
+ String createDate = dateFormat.format(new Date());
+ queries.add(String.format(
+ "INSERT INTO BoatDistrict VALUES ('%s', %d, '%s', '%s', null, null, null);",
+ districtId, 0, createDate, code)
+ );
+
+ for (String boatId : boatDistrictCodes.get(code)) {
+ boats.put(boatId, districtId);
+ }
+ }
+
+ return boats;
+ }
+
+ @Override
+ protected void updateBoatWithBoatDistrict_1_5d(List<String> queries, Map<String, String> boats) {
+ queries.add("ALTER TABLE Boat ADD boatDistrict CHARACTER VARYING(255)" +
+ " REFERENCES BoatDistrict (topiaId);");
+
+ for (Map.Entry<String, String> entry : boats.entrySet()) {
+ String districtId = entry.getValue();
+ String boatId = entry.getKey();
+
+ queries.add(String.format(
+ "UPDATE Boat SET boatDistrict = '%s' WHERE topiaId = '%s';",
+ districtId, boatId)
+ );
+ }
+
+ queries.add("ALTER TABLE Boat DROP COLUMN districtCode;");
+ }
}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2010-06-29 08:31:33 UTC (rev 578)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoMigrationCallBack.java 2010-06-29 11:57:12 UTC (rev 579)
@@ -27,6 +27,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.hibernate.SQLQuery;
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.framework.TopiaContextImplementor;
import org.nuiton.topia.migration.TopiaMigrationCallback;
@@ -35,6 +36,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
/**
*
@@ -68,12 +70,21 @@
protected abstract void createContactCommentColumns_1_4b(List<String> queries);
+ protected abstract Map<String, List<String>> retrieveBoatDistrictCodes_1_5a(TopiaContextImplementor tx) throws TopiaException;
+
+ protected abstract void createBoatDistrictTable_1_5b(List<String> queries);
+
+ protected abstract Map<String, String> insertBoatDistricts_1_5c(List<String> queries, Map<String, List<String>> boatDistrictCodes);
+
+ protected abstract void updateBoatWithBoatDistrict_1_5d(List<String> queries, Map<String, String> boats);
+
protected static final Version[] VERSIONS = new Version[] {
VersionUtil.valueOf("1.0"),
VersionUtil.valueOf("1.1"),
VersionUtil.valueOf("1.2"),
VersionUtil.valueOf("1.3"),
- VersionUtil.valueOf("1.4")
+ VersionUtil.valueOf("1.4"),
+ VersionUtil.valueOf("1.5")
};
@Override
@@ -169,4 +180,38 @@
String[] strings = queries.toArray(new String[queries.size()]);
executeSQL(tx, showSql, showProgression, strings);
}
+
+ public void migrateTo_1_5(TopiaContextImplementor tx,
+ boolean showSql,
+ boolean showProgression) throws TopiaException {
+ if (log.isInfoEnabled()) {
+ log.info("Migrate to version 1.5");
+ }
+
+ // Retrieve existing code (key) and its list of boat ids (value)
+ Map<String, List<String>> boatDistrictCodes = retrieveBoatDistrictCodes_1_5a(tx);
+
+ if (log.isDebugEnabled()) {
+ for (Map.Entry<String, List<String>> entry : boatDistrictCodes.entrySet()) {
+ log.debug("-- District Code = " + entry.getKey() +
+ " _ nbBoats = " + entry.getValue().size());
+ }
+ }
+
+// List<String> queries = new ArrayList <String>();
+//
+// // Create the boatDistrict table
+// createBoatDistrictTable_1_5b(queries);
+//
+// // Insert boatDistrict using the previous map.
+// // This will return boats with boatDisctrict id in value
+// Map<String, String> boats = insertBoatDistricts_1_5c(queries, boatDistrictCodes);
+//
+// // Update the Boat table with id of district (create column as foreign key)
+// updateBoatWithBoatDistrict_1_5d(queries, boats);
+//
+// String[] strings = queries.toArray(new String[queries.size()]);
+// executeSQL(tx, showSql, showProgression, strings);
+ }
+
}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java 2010-06-29 08:31:33 UTC (rev 578)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryBuilder.java 2010-06-29 11:57:12 UTC (rev 579)
@@ -25,18 +25,12 @@
import fr.ifremer.wao.entity.*;
import org.apache.commons.lang.StringUtils;
import org.nuiton.topia.framework.TopiaQuery;
-import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.util.PeriodDates;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
-import static fr.ifremer.wao.WaoQueryHelper.$;
-
-//import static fr.ifremer.wao.TopiaQueryExtra.$;
-//import static fr.ifremer.wao.TopiaQueryExtra.$P;
-
/**
* Created: 7 juin 2010
*
@@ -250,7 +244,8 @@
// Apply filter for fishingZone on subQuery
applySimpleFishingZoneFilter(filter, subquery);
- query.addSubQuery($("$1 IN (?)", sampleRowProperty.$alias()), subquery);
+ query.addSubQuery(WaoQueryHelper.format(
+ "$1 IN (?)", sampleRowProperty.$alias()), subquery);
}
}
@@ -305,7 +300,7 @@
}
if (StringUtils.isNotEmpty(boatDistrictCode)) {
- query.addEquals(boatProperty.districtCode(), boatDistrictCode.trim());
+ query.addEquals(boatProperty.boatDistrictProperty().code(), boatDistrictCode.trim());
}
if (boatImmatriculation != null) {
@@ -321,7 +316,7 @@
String input = '%' + StringUtils.upperCase(shipOwnerName) + '%';
query.addWhere(
- $("CONCAT(CONCAT($1, ' '), $2) LIKE :input",
+ WaoQueryHelper.format("CONCAT(CONCAT($1, ' '), $2) LIKE :input",
shipOwnerProperty.firstName(),
shipOwnerProperty.lastName())
).addParam("input", input);
@@ -365,7 +360,8 @@
// Company
if (company != null) {
// Test only valid ElligibleBoat for that company
- query.addWhere($("$1 = :booleanTrue OR ($1 IS NULL AND $2 = :booleanTrue)",
+ query.addWhere(WaoQueryHelper.format(
+ "$1 = :booleanTrue OR ($1 IS NULL AND $2 = :booleanTrue)",
elligibleBoatProperty.companyActive(),
elligibleBoatProperty.globalActive())
).addParam("booleanTrue", Boolean.TRUE);
@@ -427,7 +423,8 @@
// MAMMALS_OBSERVATION and MAMMALS_CAPTURE
if (mammalsObservation && mammalsCapture) {
- query.addWhere($("$1 = :mammals OR $2 = :mammals",
+ query.addWhere(WaoQueryHelper.format(
+ "$1 = :mammals OR $2 = :mammals",
contactProperty.mammalsObservation(),
contactProperty.mammalsCapture())
).addParam("mammals", Boolean.TRUE);
Deleted: trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryHelper.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryHelper.java 2010-06-29 08:31:33 UTC (rev 578)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/WaoQueryHelper.java 2010-06-29 11:57:12 UTC (rev 579)
@@ -1,541 +0,0 @@
-/*
- * #%L
- * Wao :: 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 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>.
- * #L%
- */
-package fr.ifremer.wao;
-
-import fr.ifremer.wao.entity.Boat;
-import fr.ifremer.wao.entity.Contact;
-import fr.ifremer.wao.entity.ElligibleBoat;
-import fr.ifremer.wao.entity.FishingZone;
-import fr.ifremer.wao.entity.Profession;
-import fr.ifremer.wao.entity.SampleMonth;
-import fr.ifremer.wao.entity.SampleRow;
-import fr.ifremer.wao.entity.ShipOwner;
-import fr.ifremer.wao.entity.WaoUser;
-import org.nuiton.topia.framework.TopiaQuery;
-import org.nuiton.topia.persistence.TopiaEntity;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Created: 18 juin 2010
- *
- * @author fdesbois <fdesbois at codelutin.com>
- * @version $Id$
- */
-public class WaoQueryHelper {
-
- public static String ALIAS_SHIP_OWNER = "SO";
-
- public static String ALIAS_BOAT = "B";
-
- public static String ALIAS_ELLIGIBLE_BOAT = "EB";
-
- public static String ALIAS_SAMPLE_ROW = "SR";
-
- public static String ALIAS_SAMPLE_MONTH = "SM";
-
- public static String ALIAS_PROFESSION = "P";
-
- public static String ALIAS_FISHING_ZONE = "FZ";
-
- public static String ALIAS_CONTACT = "C";
-
- public static String ALIAS_WAO_USER = "WU";
-
- public static String ALIAS_ACTIVITY_CALENDAR = "AC";
-
- public static TopiaQuery createQuery(EntityProperty property) {
- return new TopiaQuery((Class<? extends TopiaEntity>)property.getEntityClass(), property.$alias());
- }
-
- public static String $(String statement, String... properties) {
- for (int i = 1; i <= properties.length; i++) {
- statement = statement.replace("$" + i, properties[i-1]);
- }
- return statement;
- }
-
- private static <P extends EntityProperty> P newEntityProperty(Class<P> propertyClass) throws WaoException {
- return newEntityProperty(propertyClass, null);
- }
-
- private static <P extends EntityProperty> P newEntityProperty(Class<P> propertyClass, String alias) throws WaoException {
- try {
- P property = propertyClass.newInstance();
- if (alias == null) {
- alias = property.defaultAlias();
- }
- property.setAlias(alias);
- return property;
- } catch (Exception eee) {
- throw new WaoException("Error instantiate " + propertyClass.getName(), eee);
- }
- }
-
- public static SampleRowProperty newSampleRowProperty() throws WaoException {
- return newSampleRowProperty(null);
- }
-
- public static SampleRowProperty newSampleRowProperty(String alias) throws WaoException {
- return newEntityProperty(SampleRowProperty.class, alias);
- }
-
- public static SampleMonthProperty newSampleMonthProperty() throws WaoException {
- return newSampleMonthProperty(null);
- }
-
- public static SampleMonthProperty newSampleMonthProperty(String alias) throws WaoException {
- return newEntityProperty(SampleMonthProperty.class, alias);
- }
-
- public static ContactProperty newContactProperty() throws WaoException {
- return newContactProperty(null);
- }
-
- public static ContactProperty newContactProperty(String alias) throws WaoException {
- return newEntityProperty(ContactProperty.class, alias);
- }
-
- public static FishingZoneProperty newFishingZoneProperty() throws WaoException {
- return newFishingZoneProperty(null);
- }
-
- public static FishingZoneProperty newFishingZoneProperty(String alias) throws WaoException {
- return newEntityProperty(FishingZoneProperty.class, alias);
- }
-
- public static ElligibleBoatProperty newElligibleBoatProperty() throws WaoException {
- return newElligibleBoatProperty(null);
- }
-
- public static ElligibleBoatProperty newElligibleBoatProperty(String alias) throws WaoException {
- return newEntityProperty(ElligibleBoatProperty.class, alias);
- }
-
- public static BoatProperty newBoatProperty() throws WaoException {
- return newBoatProperty(null);
- }
-
- public static BoatProperty newBoatProperty(String alias) throws WaoException {
- return newEntityProperty(BoatProperty.class, alias);
- }
-
- public static ShipOwnerProperty newShipOwnerProperty() throws WaoException {
- return newShipOwnerProperty(null);
- }
-
- public static ShipOwnerProperty newShipOwnerProperty(String alias) throws WaoException {
- return newEntityProperty(ShipOwnerProperty.class, alias);
- }
-
- public static WaoUserProperty newWaoUserProperty() throws WaoException {
- return newWaoUserProperty(null);
- }
-
- public static WaoUserProperty newWaoUserProperty(String alias) throws WaoException {
- return newEntityProperty(WaoUserProperty.class, alias);
- }
-
- protected static abstract class EntityProperty<E> {
- protected String alias;
-
- protected Map<String, String> propertiesCache;
-
- public EntityProperty() {
- propertiesCache = new HashMap<String, String>();
- }
-
- protected void setAlias(String alias) {
- this.alias = alias;
- }
-
- public String $alias() {
- return alias;
- }
-
- public String $property(String propertyName) {
- String result = propertiesCache.get(propertyName);
- if (result == null) {
- result = TopiaQuery.getProperty(alias, propertyName);
- propertiesCache.put(propertyName, result);
- }
- return result;
- }
-
- public String topiaCreateDate() {
- return $property(TopiaEntity.TOPIA_CREATE_DATE);
- }
-
- public String topiaId() {
- return $property(TopiaEntity.TOPIA_ID);
- }
-
- public String topiaVersion() {
- return $property(TopiaEntity.TOPIA_VERSION);
- }
-
- public abstract Class<E> getEntityClass();
-
- public abstract String defaultAlias();
- }
-
- public static class ShipOwnerProperty extends EntityProperty<ShipOwner> {
-
- protected ShipOwnerProperty() {
- }
-
- public String firstName() {
- return $property(ShipOwner.FIRST_NAME);
- }
-
- public String lastName() {
- return $property(ShipOwner.LAST_NAME);
- }
-
- @Override
- public Class<ShipOwner> getEntityClass() {
- return ShipOwner.class;
- }
-
- @Override
- public String defaultAlias() {
- return ALIAS_SHIP_OWNER;
- }
- }
-
- public static class BoatProperty extends EntityProperty<Boat> {
-
- protected BoatProperty() {
- }
-
- public String immatriculation() {
- return $property(Boat.IMMATRICULATION);
- }
-
- public String name() {
- return $property(Boat.NAME);
- }
-
- public String districtCode() {
- return $property(Boat.DISTRICT_CODE);
- }
-
- public String boatLength() {
- return $property(Boat.BOAT_LENGTH);
- }
-
- public String buildYear() {
- return $property(Boat.BUILD_YEAR);
- }
-
- public String active() {
- return $property(Boat.ACTIVE);
- }
-
- public String shipOwner() {
- return $property(Boat.SHIP_OWNER);
- }
-
- public ShipOwnerProperty shipOwnerProperty() {
- return newShipOwnerProperty(shipOwner());
- }
-
- public String elligibleBoat() {
- return $property(Boat.ELLIGIBLE_BOAT);
- }
-
- @Override
- public Class<Boat> getEntityClass() {
- return Boat.class;
- }
-
- @Override
- public String defaultAlias() {
- return ALIAS_BOAT;
- }
- }
-
- public static class ElligibleBoatProperty extends EntityProperty<ElligibleBoat> {
-
- protected ElligibleBoatProperty() {
- }
-
- public String companyActive() {
- return $property(ElligibleBoat.COMPANY_ACTIVE);
- }
-
- public String globalActive() {
- return $property(ElligibleBoat.GLOBAL_ACTIVE);
- }
-
- public String sampleRow() {
- return $property(ElligibleBoat.SAMPLE_ROW);
- }
-
- public SampleRowProperty sampleRowProperty() {
- return newEntityProperty(SampleRowProperty.class, sampleRow());
- }
-
- @Override
- public Class<ElligibleBoat> getEntityClass() {
- return ElligibleBoat.class;
- }
-
- @Override
- public String defaultAlias() {
- return ALIAS_ELLIGIBLE_BOAT;
- }
- }
-
- public static class SampleRowProperty extends EntityProperty<SampleRow> {
-
- protected SampleRowProperty() {
- }
-
- public String programName() {
- return $property(SampleRow.PROGRAM_NAME);
- }
-
- public String code() {
- return $property(SampleRow.CODE);
- }
-
- public String periodBegin() {
- return $property(SampleRow.PERIOD_BEGIN);
- }
-
- public String periodEnd() {
- return $property(SampleRow.PERIOD_END);
- }
-
- public String profession() {
- return $property(SampleRow.PROFESSION);
- }
-
- public ProfessionProperty professionProperty() {
- return newEntityProperty(ProfessionProperty.class, profession());
- }
-
- public String company() {
- return $property(SampleRow.COMPANY);
- }
-
- public String fishingZone() {
- return $property(SampleRow.FISHING_ZONE);
- }
-
- public String sampleMonth() {
- return $property(SampleRow.SAMPLE_MONTH);
- }
-
- @Override
- public Class<SampleRow> getEntityClass() {
- return SampleRow.class;
- }
-
- @Override
- public String defaultAlias() {
- return ALIAS_SAMPLE_ROW;
- }
- }
-
- public static class SampleMonthProperty extends EntityProperty<SampleMonth> {
-
- protected SampleMonthProperty() {
- }
-
- public String periodDate() {
- return $property(SampleMonth.PERIOD_DATE);
- }
-
- public String realTidesValue() {
- return $property(SampleMonth.REAL_TIDES_VALUE);
- }
-
- public String expectedTidesValue() {
- return $property(SampleMonth.EXPECTED_TIDES_VALUE);
- }
-
- public String estimatedTidesValue() {
- return $property(SampleMonth.ESTIMATED_TIDES_VALUE);
- }
-
- public String sampleRow() {
- return $property(SampleMonth.SAMPLE_ROW);
- }
-
- public SampleRowProperty sampleRowProperty() {
- return newEntityProperty(SampleRowProperty.class, sampleRow());
- }
-
- @Override
- public Class<SampleMonth> getEntityClass() {
- return SampleMonth.class;
- }
-
- @Override
- public String defaultAlias() {
- return ALIAS_SAMPLE_MONTH;
- }
- }
-
- public static class ProfessionProperty extends EntityProperty<Profession> {
-
- protected ProfessionProperty() {
- }
-
- public String codeDCF5() {
- return $property(Profession.CODE_DCF5);
- }
-
- @Override
- public Class<Profession> getEntityClass() {
- return Profession.class;
- }
-
- @Override
- public String defaultAlias() {
- return ALIAS_PROFESSION;
- }
- }
-
- public static class FishingZoneProperty extends EntityProperty<FishingZone> {
-
- protected FishingZoneProperty() {
- }
-
- public String sectorName() {
- return $property(FishingZone.SECTOR_NAME);
- }
-
- public String facadeName() {
- return $property(FishingZone.FACADE_NAME);
- }
-
- public String districtCode() {
- return $property(FishingZone.DISTRICT_CODE);
- }
-
- public String sampleRow() {
- return $property(FishingZone.SAMPLE_ROW);
- }
-
- @Override
- public Class<FishingZone> getEntityClass() {
- return FishingZone.class;
- }
-
- @Override
- public String defaultAlias() {
- return ALIAS_FISHING_ZONE;
- }
- }
-
- public static class ContactProperty extends EntityProperty<Contact> {
-
- protected ContactProperty() {
- }
-
- public String mammalsObservation() {
- return $property(Contact.MAMMALS_OBSERVATION);
- }
-
- public String mammalsCapture() {
- return $property(Contact.MAMMALS_CAPTURE);
- }
-
- public String validationProgram() {
- return $property(Contact.VALIDATION_PROGRAM);
- }
-
- public String validationCompany() {
- return $property(Contact.VALIDATION_COMPANY);
- }
-
- public String tideBeginDate() {
- return $property(Contact.TIDE_BEGIN_DATE);
- }
-
- public String state() {
- return $property(Contact.STATE);
- }
-
- public String observer() {
- return $property(Contact.OBSERVER);
- }
-
- public WaoUserProperty observerProperty() {
- return newWaoUserProperty(observer());
- }
-
- public String sampleRow() {
- return $property(Contact.SAMPLE_ROW);
- }
-
- public SampleRowProperty sampleRowProperty() {
- return newSampleRowProperty(sampleRow());
- }
-
- public String boat() {
- return $property(Contact.BOAT);
- }
-
- public BoatProperty boatProperty() {
- return newBoatProperty(boat());
- }
-
- @Override
- public Class<Contact> getEntityClass() {
- return Contact.class;
- }
-
- @Override
- public String defaultAlias() {
- return ALIAS_CONTACT;
- }
- }
-
- public static class WaoUserProperty extends EntityProperty<WaoUser> {
-
- protected WaoUserProperty() {
- }
-
- public String company() {
- return $property(WaoUser.COMPANY);
- }
-
- @Override
- public Class<WaoUser> getEntityClass() {
- return WaoUser.class;
- }
-
- @Override
- public String defaultAlias() {
- return ALIAS_WAO_USER;
- }
- }
-}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/BoatImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/BoatImpl.java 2010-06-29 08:31:33 UTC (rev 578)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/BoatImpl.java 2010-06-29 11:57:12 UTC (rev 579)
@@ -120,5 +120,8 @@
return result;
}
-
+ @Override
+ public String getDistrictCode() {
+ return getBoatDistrict().getCode();
+ }
}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactDAOImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactDAOImpl.java 2010-06-29 08:31:33 UTC (rev 578)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/entity/ContactDAOImpl.java 2010-06-29 11:57:12 UTC (rev 579)
@@ -31,9 +31,6 @@
import org.nuiton.topia.framework.TopiaQuery;
import org.nuiton.topia.framework.TopiaQuery.Op;
-import static fr.ifremer.wao.WaoQueryHelper.$;
-
-
/**
* ContactDAOImpl
*
@@ -91,15 +88,18 @@
// Construct subquery
TopiaQuery subquery = createQuery(subContactProperty.$alias()).
- setSelect($("MAX($1)", subContactProperty.topiaCreateDate())).
- addWhere($("$1 = $2", subContactProperty.boat(), mainContactProperty.boat())).
+ setSelect(WaoQueryHelper.format(
+ "MAX($1)", subContactProperty.topiaCreateDate())).
+ addWhere(WaoQueryHelper.format(
+ "$1 = $2", subContactProperty.boat(), mainContactProperty.boat())).
addEquals(subContactProperty.observerProperty().company(), company);
// Construct mainquery
TopiaQuery query = createQuery(mainContactProperty.$alias()).
addEquals(mainContactProperty.boat(), boat).
addEquals(mainContactProperty.observerProperty().company(), company).
- addSubQuery($("$1 = (?)", mainContactProperty.topiaCreateDate()), subquery);
+ addSubQuery(WaoQueryHelper.format(
+ "$1 = (?)", mainContactProperty.topiaCreateDate()), subquery);
return query;
}
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-06-29 08:31:33 UTC (rev 578)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceBoatImpl.java 2010-06-29 11:57:12 UTC (rev 579)
@@ -59,8 +59,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static fr.ifremer.wao.WaoQueryHelper.$;
-
/**
* ServiceBoatImpl
*
@@ -329,7 +327,7 @@
TopiaQuery query = builder.
applyShipOwnerFilter(shipOwnerName).
addDistinct().
- setSelect($("CONCAT(CONCAT($1,' '), $2)",
+ setSelect(WaoQueryHelper.format("CONCAT(CONCAT($1,' '), $2)",
shipOwnerProperty.firstName(),
shipOwnerProperty.lastName())
);
@@ -370,10 +368,12 @@
BoatDAO boatDAO = WaoDAOHelper.getBoatDAO(transaction);
ShipOwnerDAO shipOwnerDAO = WaoDAOHelper.getShipOwnerDAO(transaction);
+ BoatDistrictDAO districtDAO = WaoDAOHelper.getBoatDistrictDAO(transaction);
- Map<String, ShipOwner> availableShipOwners =
- new HashMap<String, ShipOwner>();
+ Map<String, ShipOwner> availableShipOwners = new HashMap<String, ShipOwner>();
+ Map<String, BoatDistrict> availableDistricts = new HashMap<String, BoatDistrict>();
+
tic = System.currentTimeMillis();
Pattern pattern = Pattern.compile("\\d{6}");
while(reader.readRecord()) {
@@ -424,11 +424,27 @@
result[1]++;
}
boat.setName(boatName);
- boat.setDistrictCode(districtCode);
boat.setBuildYear(buildYear);
boat.setBoatLength(boatLength);
boat.setActive(active);
+ BoatDistrict district = availableDistricts.get(districtCode);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("District code : " + districtCode +
+ " _ district found : " + district);
+ }
+
+ if (district == null) {
+ district = districtDAO.findByCode(districtCode);
+ if (district == null) {
+ district = districtDAO.create(BoatDistrict.CODE, districtCode);
+ }
+ availableDistricts.put(districtCode, district);
+ }
+
+ boat.setBoatDistrict(district);
+
// Find existing shipOwner with code
ShipOwner shipOwner = availableShipOwners.get(shipOwnerCode);
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2010-06-29 08:31:33 UTC (rev 578)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceContactImpl.java 2010-06-29 11:57:12 UTC (rev 579)
@@ -38,6 +38,13 @@
import java.util.Map;
import com.csvreader.CsvReader;
import com.csvreader.CsvWriter;
+import fr.ifremer.wao.WaoBinderHelper;
+import fr.ifremer.wao.WaoBusinessException;
+import fr.ifremer.wao.WaoContext;
+import fr.ifremer.wao.WaoDAOHelper;
+import fr.ifremer.wao.WaoException;
+import fr.ifremer.wao.WaoQueryBuilder;
+import fr.ifremer.wao.WaoQueryHelper;
import fr.ifremer.wao.bean.ConnectedUser;
import fr.ifremer.wao.bean.UserRole;
import org.slf4j.Logger;
@@ -46,7 +53,6 @@
import org.nuiton.topia.TopiaException;
import org.nuiton.topia.persistence.TopiaEntity;
import org.nuiton.topia.framework.TopiaQuery;
-import fr.ifremer.wao.*;
import fr.ifremer.wao.bean.ContactStatus;
import fr.ifremer.wao.bean.ContactStatus.NullSampleMonthException;
import fr.ifremer.wao.bean.ContactFilter;
@@ -495,7 +501,7 @@
public ImportResults executeImportContactCsv(TopiaContext transaction,
ConnectedUser user, InputStream input)
throws TopiaException, IOException,
- WaoBusinessException, ParseException {
+ WaoBusinessException, ParseException {
ImportResults result = new ImportResultsImpl();
int currRow = 1;
Modified: trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java
===================================================================
--- trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-06-29 08:31:33 UTC (rev 578)
+++ trunk/wao-business/src/main/java/fr/ifremer/wao/service/ServiceSynthesisImpl.java 2010-06-29 11:57:12 UTC (rev 579)
@@ -66,8 +66,6 @@
import java.util.SortedMap;
import java.util.TreeMap;
-import static fr.ifremer.wao.WaoQueryHelper.$;
-
/**
* ServiceSynthesisImpl
*
@@ -138,8 +136,8 @@
TopiaQuery query = builder.applySamplingFilter(filter).
setSelect(sampleMonthProperty.periodDate()).
- addSelect($("SUM($1)", realTidesProperty)).
- addSelect($("SUM($1)", sampleMonthProperty.expectedTidesValue())).
+ addSelect(WaoQueryHelper.format("SUM($1)", realTidesProperty)).
+ addSelect(WaoQueryHelper.format("SUM($1)", sampleMonthProperty.expectedTidesValue())).
addBetween(sampleMonthProperty.periodDate(), period.getFromDate(), period.getThruDate()).
addGroup(sampleMonthProperty.periodDate()).
addOrder(sampleMonthProperty.periodDate());
Modified: trunk/wao-business/src/main/xmi/wao.zargo
===================================================================
(Binary files differ)
1
0
[Suiviobsmer-commits] r578 - in trunk: . wao-business wao-ui
by fdesbois@users.labs.libre-entreprise.org 29 Jun '10
by fdesbois@users.labs.libre-entreprise.org 29 Jun '10
29 Jun '10
Author: fdesbois
Date: 2010-06-29 08:31:33 +0000 (Tue, 29 Jun 2010)
New Revision: 578
Log:
start version 1.5 snapshot
Modified:
trunk/pom.xml
trunk/wao-business/pom.xml
trunk/wao-ui/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-28 15:33:24 UTC (rev 577)
+++ trunk/pom.xml 2010-06-29 08:31:33 UTC (rev 578)
@@ -15,7 +15,7 @@
<groupId>fr.ifremer</groupId>
<artifactId>wao</artifactId>
- <version>1.4.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
<modules>
<module>wao-ui</module>
Modified: trunk/wao-business/pom.xml
===================================================================
--- trunk/wao-business/pom.xml 2010-06-28 15:33:24 UTC (rev 577)
+++ trunk/wao-business/pom.xml 2010-06-29 08:31:33 UTC (rev 578)
@@ -10,7 +10,7 @@
<parent>
<groupId>fr.ifremer</groupId>
<artifactId>wao</artifactId>
- <version>1.4.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>fr.ifremer.wao</groupId>
Modified: trunk/wao-ui/pom.xml
===================================================================
--- trunk/wao-ui/pom.xml 2010-06-28 15:33:24 UTC (rev 577)
+++ trunk/wao-ui/pom.xml 2010-06-29 08:31:33 UTC (rev 578)
@@ -10,7 +10,7 @@
<parent>
<groupId>fr.ifremer</groupId>
<artifactId>wao</artifactId>
- <version>1.4.2-SNAPSHOT</version>
+ <version>1.5-SNAPSHOT</version>
</parent>
<groupId>fr.ifremer.wao</groupId>
1
0
[Suiviobsmer-commits] r577 - in trunk: . wao-business wao-ui
by fdesbois@users.labs.libre-entreprise.org 28 Jun '10
by fdesbois@users.labs.libre-entreprise.org 28 Jun '10
28 Jun '10
Author: fdesbois
Date: 2010-06-28 15:33:24 +0000 (Mon, 28 Jun 2010)
New Revision: 577
Log:
[maven-release-plugin] prepare for next development iteration
Modified:
trunk/pom.xml
trunk/wao-business/pom.xml
trunk/wao-ui/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-28 15:33:21 UTC (rev 576)
+++ trunk/pom.xml 2010-06-28 15:33:24 UTC (rev 577)
@@ -15,7 +15,7 @@
<groupId>fr.ifremer</groupId>
<artifactId>wao</artifactId>
- <version>1.4.1</version>
+ <version>1.4.2-SNAPSHOT</version>
<modules>
<module>wao-ui</module>
@@ -252,9 +252,9 @@
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/suiviobsmer/tags/wao-1.4.1</connection>
- <developerConnection>scm:svn:svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/tags/wao-1.4.1</developerConnection>
- <url>http://labs.libre-entreprise.org/scm/viewvc.php/tags/wao-1.4.1?root=suiviob…</url>
+ <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk</connection>
+ <developerConnection>scm:svn:svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk</developerConnection>
+ <url>http://labs.libre-entreprise.org/scm/viewvc.php/trunk/?root=suiviobsmer</url>
</scm>
<build>
Modified: trunk/wao-business/pom.xml
===================================================================
--- trunk/wao-business/pom.xml 2010-06-28 15:33:21 UTC (rev 576)
+++ trunk/wao-business/pom.xml 2010-06-28 15:33:24 UTC (rev 577)
@@ -10,7 +10,7 @@
<parent>
<groupId>fr.ifremer</groupId>
<artifactId>wao</artifactId>
- <version>1.4.1</version>
+ <version>1.4.2-SNAPSHOT</version>
</parent>
<groupId>fr.ifremer.wao</groupId>
@@ -178,9 +178,9 @@
</build>
<scm>
- <url>http://labs.libre-entreprise.org/scm/viewvc.php/tags/wao-1.4.1/?root=suivio…</url>
- <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/suiviobsmer/tags/wao-1.4.1/wao-business</connection>
- <developerConnection>scm:svn:svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/tags/wao-1.4.1/wao-business</developerConnection>
+ <url>http://labs.libre-entreprise.org/scm/viewvc.php/trunk/wao-business/?root=su…</url>
+ <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk/wao-business</connection>
+ <developerConnection>scm:svn:svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk/wao-business</developerConnection>
</scm>
</project>
Modified: trunk/wao-ui/pom.xml
===================================================================
--- trunk/wao-ui/pom.xml 2010-06-28 15:33:21 UTC (rev 576)
+++ trunk/wao-ui/pom.xml 2010-06-28 15:33:24 UTC (rev 577)
@@ -10,7 +10,7 @@
<parent>
<groupId>fr.ifremer</groupId>
<artifactId>wao</artifactId>
- <version>1.4.1</version>
+ <version>1.4.2-SNAPSHOT</version>
</parent>
<groupId>fr.ifremer.wao</groupId>
@@ -227,9 +227,9 @@
</repositories>
<scm>
- <url>http://labs.libre-entreprise.org/scm/viewvc.php/tags/wao-1.4.1/?root=suivio…</url>
- <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/suiviobsmer/tags/wao-1.4.1/wao-ui</connection>
- <developerConnection>scm:svn:svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/tags/wao-1.4.1/wao-ui</developerConnection>
+ <url>http://labs.libre-entreprise.org/scm/viewvc.php/trunk/wao-ui/?root=suiviobs…</url>
+ <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk/wao-ui</connection>
+ <developerConnection>scm:svn:svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk/wao-ui</developerConnection>
</scm>
</project>
1
0
Author: fdesbois
Date: 2010-06-28 15:33:21 +0000 (Mon, 28 Jun 2010)
New Revision: 576
Log:
[maven-release-plugin] copy for tag wao-1.4.1
Added:
tags/wao-1.4.1/
1
0
[Suiviobsmer-commits] r575 - in trunk: . wao-business wao-ui
by fdesbois@users.labs.libre-entreprise.org 28 Jun '10
by fdesbois@users.labs.libre-entreprise.org 28 Jun '10
28 Jun '10
Author: fdesbois
Date: 2010-06-28 15:33:18 +0000 (Mon, 28 Jun 2010)
New Revision: 575
Log:
[maven-release-plugin] prepare release wao-1.4.1
Modified:
trunk/pom.xml
trunk/wao-business/pom.xml
trunk/wao-ui/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-28 15:29:39 UTC (rev 574)
+++ trunk/pom.xml 2010-06-28 15:33:18 UTC (rev 575)
@@ -15,7 +15,7 @@
<groupId>fr.ifremer</groupId>
<artifactId>wao</artifactId>
- <version>1.4.1-SNAPSHOT</version>
+ <version>1.4.1</version>
<modules>
<module>wao-ui</module>
@@ -252,9 +252,9 @@
<!-- ************************************************************* -->
<scm>
- <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk</connection>
- <developerConnection>scm:svn:svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk</developerConnection>
- <url>http://labs.libre-entreprise.org/scm/viewvc.php/trunk/?root=suiviobsmer</url>
+ <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/suiviobsmer/tags/wao-1.4.1</connection>
+ <developerConnection>scm:svn:svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/tags/wao-1.4.1</developerConnection>
+ <url>http://labs.libre-entreprise.org/scm/viewvc.php/tags/wao-1.4.1?root=suiviob…</url>
</scm>
<build>
Modified: trunk/wao-business/pom.xml
===================================================================
--- trunk/wao-business/pom.xml 2010-06-28 15:29:39 UTC (rev 574)
+++ trunk/wao-business/pom.xml 2010-06-28 15:33:18 UTC (rev 575)
@@ -10,7 +10,7 @@
<parent>
<groupId>fr.ifremer</groupId>
<artifactId>wao</artifactId>
- <version>1.4.1-SNAPSHOT</version>
+ <version>1.4.1</version>
</parent>
<groupId>fr.ifremer.wao</groupId>
@@ -178,9 +178,9 @@
</build>
<scm>
- <url>http://labs.libre-entreprise.org/scm/viewvc.php/trunk/wao-business/?root=su…</url>
- <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk/wao-business</connection>
- <developerConnection>scm:svn:svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk/wao-business</developerConnection>
+ <url>http://labs.libre-entreprise.org/scm/viewvc.php/tags/wao-1.4.1/?root=suivio…</url>
+ <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/suiviobsmer/tags/wao-1.4.1/wao-business</connection>
+ <developerConnection>scm:svn:svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/tags/wao-1.4.1/wao-business</developerConnection>
</scm>
</project>
Modified: trunk/wao-ui/pom.xml
===================================================================
--- trunk/wao-ui/pom.xml 2010-06-28 15:29:39 UTC (rev 574)
+++ trunk/wao-ui/pom.xml 2010-06-28 15:33:18 UTC (rev 575)
@@ -10,7 +10,7 @@
<parent>
<groupId>fr.ifremer</groupId>
<artifactId>wao</artifactId>
- <version>1.4.1-SNAPSHOT</version>
+ <version>1.4.1</version>
</parent>
<groupId>fr.ifremer.wao</groupId>
@@ -227,9 +227,9 @@
</repositories>
<scm>
- <url>http://labs.libre-entreprise.org/scm/viewvc.php/trunk/wao-ui/?root=suiviobs…</url>
- <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk/wao-ui</connection>
- <developerConnection>scm:svn:svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/trunk/wao-ui</developerConnection>
+ <url>http://labs.libre-entreprise.org/scm/viewvc.php/tags/wao-1.4.1/?root=suivio…</url>
+ <connection>scm:svn:svn://anonymous at labs.libre-entreprise.org/svnroot/suiviobsmer/tags/wao-1.4.1/wao-ui</connection>
+ <developerConnection>scm:svn:svn+ssh://fdesbois at labs.libre-entreprise.org/svnroot/suiviobsmer/tags/wao-1.4.1/wao-ui</developerConnection>
</scm>
</project>
1
0